fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const unsigned long long MOD = 1e9 + 7;
  5. const int INF = (int)2e9 + 7;
  6. const long long LINF = (long long)1e18;
  7. const unsigned long long mod1 = 183453789;
  8. const unsigned long long mod2 = 1234567891;
  9. const int P1 = 337, P2 = 263;
  10.  
  11. template<typename T>
  12. T input(){
  13. T ans = 0, m = 1; char c = ' ';
  14. while (!((c >= '0' && c <= '9') || c == '-')) c = getchar();
  15. if (c == '-') m = -1, c = getchar();
  16. while (c >= '0' && c <= '9') ans = ans * 10 + (c - '0'), c = getchar();
  17. return ans * m;
  18. }
  19.  
  20. string nextString(bool flag = false){
  21. char ch; string ans = "";
  22. do { ch = getchar(); } while(ch <= ' ');
  23. while(1) {
  24. ans += ch; ch = getchar();
  25. if ( (!flag && ch <= ' ') || (flag && ch < ' ') ) break;
  26. }
  27. return ans;
  28. }
  29. char nextChar(){
  30. char ch;
  31. do {ch = getchar(); } while(ch <= ' ');
  32. return ch;
  33. }
  34. void read(string& s){ s = nextString(); }
  35. void read(char& c){ c = nextChar(); }
  36. template<typename T> void read(T& a){ a = input<T>(); }
  37. template<typename T, typename... R> void read(T& a, R&... r){ read(a); read(r...); }
  38.  
  39. int32_t main(){
  40. ios_base::sync_with_stdio(0); cin.tie(0);
  41. #ifdef LOCAL
  42. freopen("in.txt", "r", stdin);
  43. freopen("out.txt", "w", stdout);
  44. #else
  45. freopen("pairs.in", "r", stdin);
  46. freopen("pairs.out", "w", stdout);
  47. #endif
  48. long long n, k;
  49. read(n, k);
  50. long long l;
  51. if (k & 1){
  52. l = (k - 1) / 2;
  53. } else {
  54. l = k / 2;
  55. }
  56. cout << max(0LL, min(l - (k % 2 == 0), n - l));
  57. }
Time limit exceeded #stdin #stdout 5s 3460KB
stdin
Standard input is empty
stdout
Standard output is empty