akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = 2e5 + 10;
int n, a[N], ascending;

bool good(int b) {
    if (b == 1) return ascending;

    vector<pii> num;
    forn(i,n-1) {
        if (0) {
            int j = 0;
            forn(i,a[i]) {
                while (j < si(num) && num[j].first < i) ++j;
                if (j < si(num) && num[j].first == i) cerr << num[j].second;
                else cerr << 0;
            }
            cerr << endl;
        }

        if (a[i+1] <= a[i]) {
            int pos = a[i+1]-1;
            while (!num.empty() && num.back().first > pos) num.pop_back();

            while (!num.empty() && num.back() == mp(pos,b-1)) {
                num.pop_back();
                pos--;
            }
            if (pos < 0) return 0;
            if (!num.empty() && num.back().first == pos) num.back().second++;
            else num.eb(pos,1);
        }
    }
    return 1;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    forn(i,n) cin >> a[i];

    ascending = 1;
    forn(i,n-1) ascending &= a[i] < a[i+1];

    int lo = 0, hi = n+2;
    while (lo+1 < hi) {
        auto mi = (lo+hi)/2;
        if (good(mi)) hi = mi; else lo = mi;
    }
    cout << hi << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    //整数の入力
    int N = sc.nextInt();
    
    int x = 0;
    int y = 0;
    
    x = 800 * N;
    y = 200 * (N / 15);
    //x-yの出力
    System.out.println(x - y);
  }
}

Measured memory_bytes: 20948
import math

s = raw_input()

memory = [i for i in range(30, 121, 10)]
r = ''
r += ''.join(['+'*i+'>' for i in range(30, 121, 10)])
r += '<' * 10

point = 0
for c in s:
    c = ord(c)
    n = c / 10 - 3
    d = int(math.fabs(point - n))
    if point < n:
        r += '>' * d
    else:
        r += '<' * d
    point = n

    l = int(math.fabs(memory[point] - c))
    if memory[point] < c:
        r += '+' * l
    else:
        r += '-' * l
    memory[point] = c

    r += '.'

print r

Measured memory_bytes: 4408
#include <bits/stdc++.h>

using namespace std;

#define i64 int64_t
#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1;} return 0;}

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> B;
    rep(i, n) {
        int b;
        cin >> b;
        B.push_back(b);
    }

    reverse(all(B));
    vector<int> ans;
    rep(i, n) {
        int check = ans.size();
        int index = B.size();
        stl_rep(itr, B) {
        if (*itr == index) {
            ans.push_back(*itr);
            B.erase(itr);
            break;
        }

        --index;
        }
        if (ans.size() == check) {
            cout << -1 << endl;
            return 0;
        }
    }

    reverse(all(ans));
    stl_rep(i, ans) {
        cout << *i << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<map>
using namespace std;

#define N 3
#define N2 9

struct Puzzle
{
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const
  {
    for(int i=0;i<N2;i++)
      {
	if(f[i]==p.f[i]) continue;
	return f[i] > p.f[i];
      }
    return false;
  }
};


static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};

bool isTarget(Puzzle p)
{
  for(int i=0;i<N2;i++)
  
    if(p.f[i]!=(i+1)) return false;
  return true;
}

string bfs(Puzzle s)
{
  queue<Puzzle>Q;
  map<Puzzle, bool>V;
  Puzzle u,v;
  s.path="";
  Q.push(s);
  V[s]=true;

  while(!Q.empty())
    {
      u=Q.front();Q.pop();
      if(isTarget(u)) return u.path;
      int sx=u.space/N;
      int sy=u.space%N;
      for(int r=0;r<4;r++)
	{
	  int tx=sx+dx[r];
	  int ty=sy+dy[r];
	  if(tx<0||ty<0||tx>=N||ty>=N) continue;
	  v=u;
	  swap(v.f[u.space],v.f[tx*N+ty]);
	  v.space=tx*N+ty;
	  if(!V[v])
	    {
	      V[v]=true;
	      v.path += dir[r];
	      Q.push(v);
	    }
	}
    }
  return "unsolvable";
}

int main()
{
  Puzzle in;

  for(int i=0;i<N2;i++)
    {
      cin>>in.f[i];
      if(in.f[i]==0)
	{
	  in.f[i]=N2;
	  in.space=i;
	}
    }
  string ans=bfs(in);
  cout<<ans.size()<<endl;

  return 0;
}
	    



Measured memory_bytes: 30528
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad
import Data.Char(toLower)


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [n,k] <- r'
    str <- U.fromList <$> getLine

    putStrLn $ U.toList $ str U.// [(k-1, toLower (str U.!(k-1)))]


Measured memory_bytes: 508
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return true;}return false;}

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(s);
  Yes(s.size() >= 4 && s.substr(0,4)=="YAKI");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n, m;
		Scanner src = new Scanner(System.in);

		while(true) {
			n = src.nextInt();
			m = src.nextInt();
			if(n == 0 && m == 0)	break;
			int[] item = new int[1100];	// 全アイテム
			int[][] vertex = new int[1100][1100];
			int maxSum = 0;

			//	アイテムを入力
			for(int i = 0; n > i; i++) {
				item[i] = src.nextInt();
			}

			//	組み合わせの決定（表を作る）
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					if(i == j)	continue;	// 同じものは表中で0になる
					vertex[j][i] = item[j] + item[i];
				}
			}

			//	合計金額の最大値を求める
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					if(m >= vertex[j][i] && maxSum < vertex[j][i]) {
						//	最大値の更新
						maxSum = vertex[j][i];
					}
				}
			}
			//	NONEの判定
			if(maxSum == 0) {
				System.out.println("NONE");
				continue;
			}
			System.out.println(maxSum);
		}

	}

}



Measured memory_bytes: 404520
#include <iostream>
using namespace std;

int main(){
	int N,K,X,Y,sum=0;
	cin >> N >> K >> X >> Y;
	if(N > K){
		sum += (K*X+(N-K)*Y);
	}else{
		sum += N*X;
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

#define MOD 924844033

using namespace std;
typedef long long ll;


int l[2][2005];
int sg;
long long fct[2005];

int tp[2005];

ll dpc[2005][2005];

long long dp(int ng, int nf) {
    if (nf < 0) return 0ll;
    if (ng == 0) {
        return nf == 0 ? 1 : 0;
    }
    if (dpc[ng][nf] != -1) return dpc[ng][nf];

    long long res = 0;
    FO(i,0,sg+1+tp[ng]) {
        res += dp(ng-1, nf - i) * l[tp[ng]][i];
        res %= MOD;
    }

    return dpc[ng][nf] = res;
}

ll fc[2005][2005][2][2];

ll f(int i, int nc, int cp, int cpr) {
    if (i == sg) {
        return nc == 0 && cp == 0 && cpr == 0 ? 1 : 0;
    }
    if (nc < 0) return 0;
    if (fc[i][nc][cp][cpr] != -1) return fc[i][nc][cp][cpr];
    ll res = 0;
    FO(np,0,2) FO(npr,0,2) {
        if (cpr && np) continue;
        if (cp && npr) continue;
        ll prt = (np+npr)%2 ? MOD-1 : 1;
        if ((cpr+np == 0 && cp + npr == 1) || cpr+np+cp+npr == 0) {
            res += prt * f(i+1, nc-1, np, npr);
        } else {
            res += prt * f(i+1, nc, np, npr);
        }
    }
    res %= MOD;
    return fc[i][nc][cp][cpr] = res;
}

int main() {
    fct[0] = 1;
    FO(i,1,2005) fct[i] = i * fct[i-1] % MOD;

    int n, k;
    scanf("%d %d", &n, &k);
    sg = n/k;

    FO(t,0,2) {
        memset(fc,-1,sizeof fc);
        FO(i,0,sg+1) {
            l[t][i] += f(0,i,0,0);
            if (l[t][i] >= MOD) l[t][i] -= MOD;
            //printf("l[%d][%d]=%d\n", t, i, l[t][i]);
        }
        sg++;
    }
    sg = n/k;

    FO(i,0,n%k) tp[i+1] = 1;
    FO(i,n%k,k) tp[i+1] = 0;

    memset(dpc,-1,sizeof dpc);
    long long r = 0;
    for (int i = n; i >= 0; i--) {
        r += dp(k,i) * fct[i];
        r %= MOD;
    }
    printf("%lld\n", r);
}



Measured memory_bytes: 157568
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		String s = scanner.next();
		int b = scanner.nextInt();

		if(s.equals("+")){
			System.out.println(a+b);
		}else{
			System.out.println(a-b);
		}
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
vector<vector<int> > A;
typedef pair<int,int> P;

bool bfs(){
  sort(A.begin(),A.end());
  A.erase(unique(A.begin(),A.end()),A.end());
  int n = A.size();
  for(int i=0;i<n;i++)
    for(int j=0,used[10]={};j<A[i].size();j++)if(used[A[i][j]]++) return 1;
  
  queue<P> Q;
  vector<vector<int> >D(1<<10,vector<int>(1<<10,INF));
  D[0][0] = 0;
  Q.push(P(0,0));

  while(!Q.empty()){
    P t = Q.front();Q.pop();
    int I = t.first,J = t.second;
    if(I&&J&&__builtin_popcount(I&J) == D[I][J]) return 1;
    if(D[I][J]==10) continue;    

    for(int i=0;i<n;i++){
      for(int l=0,ni=I;l<(int)A[i].size();l++){
	int num = A[i][l],nj =(J|1<<num);
	if(l&&D[ni][nj]==INF)D[ni][nj] = D[I][J]+1,Q.push(P(ni,nj));
	if(I&(1<<num))break;
	ni |= (1<<num);
	if(D[ni][J]==INF)D[ni][J] = D[I][J] + 1,Q.push(P(ni,J));
      }
    }
  }
  return 0;
}

int main(){
  int n;
  while(cin>>n,n){
    string str;
    cin>>str;
    A.clear();
    for(int i=0;i<str.size();i++){
      A.push_back(vector<int>());
      while(str[i]!='u') A.back().push_back(str[i++]-'0');
    }
    cout<<(bfs()? "UN":"")<<"SAFE"<<endl;
  }
  return 0;
}

Measured memory_bytes: 7732
import heapq

N = int(input())
A = list(map(int,input().split()))
C = A[N:(2*N)]

L = []
R = []
for i in range(N):
  heapq.heappush(L,A[i]) #左側にAの左側からN個を追加
  heapq.heappush(R,-A[-1-i]) #右側数列にAの右側からN個を追加。多いほうから取り出すので-1倍

#左側の総和を求める。
ansL = [sum(L)]
for i in range(N):
  heapq.heappush(L,C[i])
  rmv = heapq.heappop(L)
  temp = ansL[i] + C[i] - rmv #一つ前の答え＋今新しく加えた数－最小値
  ansL.append(temp)
  #ansL.append(sum(L)) #sum(L)がO(N)かかっている？

ansR = [sum(R)]
for i in range(N):
  heapq.heappush(R,-C[-1-i])
  rmv = heapq.heappop(R)
  temp = ansR[i] - C[-1-i] - rmv
  ansR.append(temp)
  #ansR.append(sum(R)) #sum(R)がO(N)かかっている？

ans = -float('inf')
for i in range(N+1):
  temp = ansL[i]+ansR[-1-i]
  ans = max(ans,temp)
#print(ansL,ansR)
print(ans)

Measured memory_bytes: 37212
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,m;
  cin >> n>> m;
  vector<vector<ll>> v;
  for(int i=0;i<n;i++){
    ll a,b;
    cin >> a >> b;
    v.push_back({a,b});
  }
  v.push_back({inf,inf});

  sort(v.begin(),v.end());
  
  priority_queue<ll, vector<ll>, less<ll>> q;

  ll k=0;
  ll s=0,l;
  for(int i=1;i<=m;i++){
    l=0;
    while(v[k][0]<=i){
      q.push(v[k][1]);
      k++;
    }
    if(!q.empty())l=q.top();
    s+=l;
    if(!q.empty())q.pop();
  }

  cout << s << endl;
  
}

Measured memory_bytes: 10252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

    int n; cin >> n;
    vel a(n), check(n+1,0), check2(n+1, 0); rep(i,n) cin >> a[i];

    ll ans = 0, ans2 = 0;
    rep(i,n) {
        if(i % 2 == 0) {
            if(check[i] + a[i] > 0) check[i+1] = check[i] + a[i];
            else {ans += -a[i] - check[i] + 1; check[i+1] = 1;}
        }
        else {
            if(check[i] + a[i] < 0) check[i+1] = check[i] + a[i];
            else {ans += 1 + check[i] + a[i]; check[i+1] = -1;}
        }
    }

    rep(i,n) {
        if(i % 2 == 0) {
           if(check2[i] + a[i] < 0) check2[i+1] = check2[i] + a[i];
            else {ans2 += check2[i] + a[i] + 1; check2[i+1] = -1;}
        }
        else {
            if(check2[i] + a[i] > 0) check2[i+1] = check2[i] + a[i];
            else {ans2 += -check2[i] - a[i] + 1; check2[i+1] = 1;}
        }
    }
    cout << min(ans, ans2) << endl;
    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, A, B;
  cin >> N >> A >> B;
  int dig = 0, num, ans = 0;
  for (int i = 1; i <= N; i++) {
    num = i;
    dig = 0;
    while (num != 0) {
      dig += num % 10;
      num /= 10;
    }
    if (dig >= A && dig <= B) ans += i; 
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 



int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int A, B; cin >> A >> B;

rep(i, 1, 10000000){
    int a = 0.08 * i, b = 0.1 * i;
    if (a && b && a == A && b == B){
        cout << i << "\n";
        return 0;
    }
}
cout << "-1\n";
return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
import sys
from math import sqrt
input = sys.stdin.readline
N = int(input())
sq = sqrt(N)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
#print(make_divisors(N))
res = 0
div = make_divisors(N)
for i in range(len(div)):
  if div[i] - 1 > sq: res += div[i] - 1
print(res)

Measured memory_bytes: 39280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main (){
    int X, Y;
    cin >> X >> Y;
    int i;
    bool ans = false;
    for(i=0;i<=X;i++){
        if(i * 2 + (X - i) * 4 == Y){
            ans = true;
            break;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N;
    cin >> N;
    cout << N / 3 << endl;
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N, K; cin >> N >> K;
  long long count=0;
  int base;
  for(int i=K+1; i<=N; i++){
    count+=((N/i)*(i-K));
    if(N%i){
      if(K==0){
        count+=N%i;
      }else{
        count+=max(0,(N%i-K+1));
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, m, q,l,r,p;
	cin >> n >> m >> q;
	vector<vector<int>> rail,ios;
	rail = vector<vector<int>>(n, vector<int>(n, 0));
	ios = vector<vector<int>>(n, vector<int>(n, 0));
	for (int i = 0; i < m; i++) {
		cin >> l >> r;
		rail[l - 1][r - 1] += 1;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == 0 && j == 0)ios[0][0] = rail[0][0];
			else if (i == 0)ios[0][j] = ios[0][j - 1] + rail[0][j];
			else if (j == 0)ios[i][0] = ios[i - 1][0] + rail[i][0];
			else{
				ios[i][j] = ios[i - 1][j] + ios[i][j - 1] + rail[i][j] - ios[i - 1][j - 1];
			}
		}
	}
	n = q;
	for (int i = 0; i < n; i++) {
		cin >> p >> q;
		if (p == 1)cout << ios[q - 1][q - 1] << endl;
		else cout << ios[q - 1][q - 1] - ios[q - 1][p - 2] - ios[p - 2][q - 1] + ios[p - 2][p - 2] << endl;
	}
}

Measured memory_bytes: 2944
module Geometry
  EPS = 1e-11
  COUNTER_CLOCKWISE = 1
  CLOCKWISE = -1
  ONLINE_BACK = 2
  ONLINE_FRONT = -2
  ON_SEGMENT = 0

  Point = Struct.new(:y, :x) do
    def +(point)
      Point.new(y + point.y, x + point.x)
    end

    def -(point)
      Point.new(y - point.y, x - point.x)
    end
  end

  Circle = Struct.new(:c, :r)
  Line = Struct.new(:p1, :p2)

  def norm(v)
    v.x ** 2 + v.y ** 2
  end

  def abs(v)
    Math.sqrt(norm(v))
  end

  def dot(v1, v2)
    v1.x * v2.x + v1.y * v2.y
  end 
  def cross(v1, v2)
    v1.x * v2.y - v1.y * v2.x
  end

  def arg(v)
    Math.atan2(v.y, v.x)
  end

  def polar(a, r)
    Point.new(Math.sin(r) * a, Math.cos(r) * a)
  end

  def ccw(p0, p1, p2)
    a = p1 - p0
    b = p2 - p0

    return COUNTER_CLOCKWISE if cross(a, b) > EPS
    return CLOCKWISE if cross(a, b) < -EPS
    return ONLINE_BACK if dot(a, b) < -EPS
    return ONLINE_FRONT if norm(a) < norm(b)

    ON_SEGMENT
  end

  def intersect(p1, p2, p3, p4)
    ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0
  end

  def get_circle_cross_point(c1, c2)
    d = abs(c1.c - c2.c)
    # a = Math.acos(Rational(c1.r ** 2 + d ** 2 - c2.r ** 2, 2 * c1.r * d))
    a = Math.acos([1.0, Rational(c1.r ** 2 + d ** 2 - c2.r ** 2, 2 * c1.r * d)].min)
    t = arg(c2.c - c1.c)
    [c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)]
  end
end

include Geometry

N = gets.to_i
P = N.times.map { gets.split.map(&:to_i) }

def f(r)
  circles = P.map { |x, y| Circle.new(Point.new(y, x), r) }
  cross_points = []

  0.upto(N - 2) do |i|
    c1 = circles[i]

    (i + 1).upto(N - 1) do |j|
      c2 = circles[j]

      dy = c2.c.y - c1.c.y
      dx = c2.c.x - c1.c.x
      d = Math.sqrt(dy ** 2 + dx ** 2)

      return false if d - 2 * r > 0

      cross_points << get_circle_cross_point(c1, c2)
    end
  end

  cross_points = cross_points.flatten.uniq

  cross_points.any? { |p1|
    P.all? { |x, y|
      dy = p1.y - y
      dx = p1.x - x

      Math.sqrt(dy ** 2 + dx ** 2) <= r + EPS
    }
  }
end

loop_cnt = 100
ok = 10_000
ng = 0

while loop_cnt > 0
  mid = (ok + ng) / 2.0

  if f(mid)
    ok = mid
  else
    ng = mid
  end

  loop_cnt -= 1
end

puts ok


Measured memory_bytes: 4988
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<queue>
#define re register 
#define rep(i,s,t) for(re int i=s;i<=t;++i)
using namespace std;
const int N=1e6+11;
int n,k,q,cnt,ans;
int a[N],b[N],c[N],bl[N],sz[N],id[N];
inline bool cmp(int x,int y){
	return a[x]<a[y];
}
inline void build(){
	cnt=1;
	rep(i,1,n)
		sz[i]=0;
	rep(i,1,n)
		if(c[i])
			++cnt;
		else{
			bl[i]=cnt;
			++sz[cnt];
		}
}
int main(){
	scanf("%d%d%d",&n,&k,&q);
	rep(i,1,n)
		scanf("%d",a+i),id[i]=i;
	ans=1e9+1;
	sort(id+1,id+n+1,cmp);
	rep(i,1,n){
		build();
		int top=i,j;
		for(j=1;j<=q;++j){
			while(top<=n&&sz[bl[id[top]]]<k)
				++top;
			if(top>n)break;
			--sz[bl[id[top]]];
			++top;
		}
		--top;
		//printf("%d %d %d\n",top,a[id[top]],a[id[i]]);
		if(j==q+1&&top<=n){
			
			ans=min(ans,a[id[top]]-a[id[i]]);
		}
		c[id[i]]=1;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 8448
a, b = map(int, input().split())
c = input()
d = list("1234567890")
for i in range(a):
    if c[i] not in d:
        print("No")
        exit()
if c[a] != "-":
    print("No")
    exit()
for i in range(a+1, a+b+1):
    if c[i] not in d:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 3060
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let s: String = read();
    println!("{}", s.replace(",", " "))
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,m,vis[100005],dp[100005];
vi v,a[100005];
void dfs(int node){
    vis[node]=1;
    for(auto i:a[node]){
        if(!vis[i]) dfs(i);
    }
    v.pb(node);
}
void solve(){
    cin>>n>>m;
    rep(i,1,m+1){
        int x,y;
        cin>>x>>y;
        a[x].pb(y);
    }
    rep(i,1,n+1){
        if(vis[i]==0){
            dfs(i);
        }
    }
    int ans=0;
    for(auto i:v){
        for(auto j:a[i]){
            dp[i]=max(dp[i],dp[j]+1);
        }
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 9080
#include <stdio.h>

int henkan(char,char);

main(){
  char h1, h2, m1, m2;
  int h, m, n, i;
  int kh, km, sa;

  scanf("%d", &n);

  for(i=0;i<n;i++){
    getchar();
    scanf("%c%c:%c%c", &h1, &h2, &m1, &m2);

    h=henkan(h1,h2);
    m=henkan(m1,m2);
    h*=10;
    m*=10;
    kh = h*30+m/2.0;
    km = m*6;

    if(kh>=km) sa=kh-km;
    else sa=km-kh;

    if(sa>1800) sa=3600-sa;

    if(sa>=0 && sa<300) printf("alert\n");
    else if(sa>=900 && sa<=1800) printf("safe\n");
    else printf("warning\n");
  }
  return 0;
}

int henkan(char a, char b){
  if(a=='0') return b-'0';
  else return (a-'0')*10+b-'0';
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

signed main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		cout << a + b << endl;
	}
	else {
		cout << max(a, b) * 2 - 1 << endl;
	}

	END;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>

#define REP(i,m,n) for(int i = (int)(m) ; i < (int) (n) ; ++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    for (int i = 0; i < X; ++i) cin >> A[i];
    for (int i = 0; i < Y; ++i) cin >> B[i];
    for (int i = 0; i < Z; ++i) cin >> C[i];
    vector<ll> AB(X * Y);
    for (int i = 0; i < X; ++i) {
        for (int j = 0; j < Y; ++j) {
            AB[i * X + j] = A[i] + B[j];
        }
    }
    sort(AB.begin(), AB.end(), greater<ll>());
    vector<ll> ABC;
    for (int i = 0; i < min(K, X * Y); ++i) {
        for (int j = 0; j < Z; ++j) {
            ABC.push_back(AB[i] + C[j]);
        }
    }
    sort(ABC.begin(), ABC.end(), greater<ll>());
    for (int i = 0; i < K; ++i) cout << ABC[i] << endl;
}

Measured memory_bytes: 42984
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
*/
import java.util.*;
import java.io.*;

   public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[4];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[Integer.parseInt(st.nextToken())]++;
         double[][][] dp = new double[N+1][N+1][N+1];
         for(int i=0; i <= N; i++)
            for(int j=0; j <= N; j++)
               Arrays.fill(dp[i][j], -1.0);
         recur(dp, arr[1], arr[2], arr[3], N);
         System.out.println(dp[arr[1]][arr[2]][arr[3]]);
      }
      public static double recur(double[][][] dp, int a, int b, int c, int N)
      {
         if(dp[a][b][c] >= 0.0)
            return dp[a][b][c];
         double calc = 0.0;
         double addend = 1.0*N/(a+b+c);
         if(a > 0)
            calc += ((1.0*a)/(a+b+c))*(recur(dp, a-1, b, c, N)+addend);
         if(b > 0)
            calc += ((1.0*b)/(a+b+c))*(recur(dp, a+1, b-1, c, N)+addend);
         if(c > 0)
            calc += ((1.0*c)/(a+b+c))*(recur(dp, a, b+1, c-1, N)+addend);
         dp[a][b][c] = calc;
         return dp[a][b][c];
      }
   }

Measured memory_bytes: 305620
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	a := make([]int, N)

	for i := 0; i < N; i++ {
		a[i] = scanInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	result := 0
	for i := 0; i < N; i++ {
		if i%2 == 0 {
			result += a[i]
		} else {
			result -= a[i]
		}
	}
	fmt.Println(result)

}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

bool isOk(vector<pair<ll,ll>>& A){
    ll cnt=0;
    for(auto p : A){
        ll b = cnt + p.ff;
        if(b <  0)
            return false;
        cnt += p.ss;
    }
    return true;
}

void solve(){
    ll n;
    cin >> n;
    vector<pair<ll,ll>> l , r;
    ll tot=0;
    for(ll i=0;i<n;i++){
        string s;
        cin >> s;
        ll b=0,h=0;
        for(auto ch : s){
            if(ch == '(')
                h++;
            else h--;
            b = min(b,h);            
        }
        if( h > 0) l.pb({b,h});
        else r.pb({b-h,-h});
        tot += h;
    }
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    sort(r.begin(),r.end());
    reverse(r.begin(),r.end());

    if( isOk(l) and isOk(r) and tot==0 )
        cout << "Yes\n";
    else cout << "No\n";
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 19088
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    string S, T;
    cin >> S >> T;
    T.pop_back();
    if (S == T) {
        cout << "Yes" << '\n';
    }else {
        cout << "No" << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;


int main()
{
    int N;
    cin >> N;
    vector<int> A(N+1,0);
    int ans=0;
    for(int i=1; i<=N; i++){
        cin >> A[i];
        if(i%2==1 && A[i]%2==1) ans++;
    }
    cout << ans << endl;




    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
#define REP(i,b,e) for(int i=b;i<(int)e;i++)
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
ll INF=1e18;
int inf=1e9+1000;
 
string alpha="abcdefghijklmnopqrstuwvxyz";

int K;

ll pow(ll n){
    if(n==0) return 1;
    else if(n%2==0) return pow(n/2)*pow(n/2);
    else return 10*pow(n/2)*pow(n/2);
}

ll keta(ll n){
    for(int i=16;i>=0;i--){
        if(n/pow(i)>0){
            return i+1;
        }
    }
    return -1;
}

ll S(ll n){
    ll ret=0;
    for(int i=16;i>=0;i--){
        ret+=n/pow(i);
        n-=((n/pow(i))*pow(i));
    }
    return ret;
}

deque<ll> ans;

int main(){
    cin>>K;
    ll bgn=10e15;
	bgn-=1;
    ll n=bgn;
    ans.push_front(n);
    ll k=keta(bgn)-4;
    bgn-=pow(k);
    while(bgn>=1){
        if(S(n)*bgn<=n*S(bgn)){
            ans.push_front(bgn);
            n=bgn;
        }
        k=keta(bgn)-4;
        if(k>=0){
            bgn-=pow(k);
        }
        else bgn-=1;
    }
    Rep(i,K){
        if(i!=(K-1)){
            cout<<ans[i]<<" ";
        }
        else cout<<ans[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int main(){
	
	int n, d, x;
	cin >> n >> d >> x;
	
	int p[20][20];
	
	for(int i = 0; i < d; i++){
		for(int j = 0; j < n; j++){
			cin >> p[i][j];
		}
	}
	
	int W = x;
	for(int i = 0; i < d - 1; i++){
		int DP[110000] = {};
		for(int j = 0; j < n; j++){
			int w = p[i][j];
			int v = p[i + 1][j] - p[i][j];
			for(int k = w; k <= W; k++){
				DP[k] = max(DP[k], DP[k - w] + v);
			}
		}
		W += DP[W];
	}
	
	cout << W << endl;
	
	return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 100 + 10;
const int C = 1e5 + 10;

struct Data {
    int w, v;
} a[N];

ll dp[N][C];

int main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    int n, c;
    cin >> n >> c;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].w >> a[i].v;
    }
    for (int i = 1; i <= n; i++) {
        for (int w = 1; w <= c; w++) {
            if (a[i].w > w) {
                dp[i][w] = dp[i - 1][w];
            } else {
                dp[i][w] = max(a[i].v * 1LL + dp[i - 1][w - a[i].w], dp[i - 1][w]);
            }
        }
    }
    cout << dp[n][c] << '\n';
}

Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1000000000
int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    int rest = N % 10; N /= 10;
    ans += rest;
    while(N > 0){
        int pre_rest = rest;
        rest = N % 10;
        if(pre_rest == 9)
            ans += rest;
        else{
            N--;
            rest = N%10;
            ans += (rest + 9 - pre_rest);
            
        }
        N /= 10;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << ": " << x << '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    vec[i] = a - 1;
  }
  int a = 0, b, ans = -1;
  for (int i = 0; i < n; i++) {
    b = vec[a];
    a = b;
    if (a == 1) {
      ans = i + 1;
      break;
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 640
#include<bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 10;

int n, a[MAXN], ans;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)	cin >> a[i];
	for (int i = 0; i < n;){
		ans++;
		int j = i;
		while (j < n && a[j] == a[i]) j++;

		if (j < n){
			bool fl = a[j] > a[i];
			while (j < n && ((fl && a[j] >= a[j - 1]) || (!fl && a[j] <= a[j - 1]))) j++;
		}
		i = j;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 640
N, M = map(int,input().split())
maxL = 0
minR = 10 ** 9
for i in range(M):
  L, R = map(int,input().split())
  maxL = max(maxL,L)
  minR = min(minR,R)
print(max(0,minR - maxL + 1))  

Measured memory_bytes: 45672
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,l;
    cin>>n>>l;
    ll arr[n];
    ll s=0;
    for(int i=1;i<=n;i++)
    {
        arr[i-1]=l+i-1;
        s+=arr[i-1];
    }
    ll ans=INT_MAX,sum=s,res;
    for(int i=0;i<n;i++)
    {
        sum-=arr[i];
        if(abs(s-sum)<ans)
        {
            ans=abs(s-sum);
            res=arr[i];
        }
        sum=s;
    }
    res=s-res;
    cout<<res;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void Swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){

	int data[3]={1,0,0};

	char tmp[2];
	char unko;

	int num[2];
	int i;


	while(cin>>tmp[0]){
		cin>>unko;
		cin>>tmp[1];

		for(int i=0;i<2;i++){
			num[i] = tmp[i] - 'A';
		}

		Swap(&data[num[0]],&data[num[1]]);
	}

	for(i=0;i<3;i++){
		if(data[i]==1){
			break;
		}
	}

	if(i==0){
		cout<<"A"<<endl;
	}
	else if(i==1){
		cout<<"B"<<endl;
	}
	else{
		cout<<"C"<<endl;
	}
	return 0;
}

/*
B,C
A,C
C,B
A,B
C,B
*/

Measured memory_bytes: 1136
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
	std::ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	if(2*n>m){
		cout<<m/2;
	}
	else{
		cout<<n+(m-2*n)/4;
	}
	return 0;
}


Measured memory_bytes: 256
def main():
  n = int(input())
  a_s = list(map(int, input().split(' ')))
  b_s = list(map(int, input().split(' ')))
  c_s = list(map(int, input().split(' ')))
  ans = 0
  for i in range(n):
    ans += (b_s[a_s[i]-1] + c_s[a_s[i]-1]) if (i != n-1 and a_s[i+1]) == (a_s[i] + 1) else b_s[a_s[i]-1]
  print(ans)


if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main() {
	int n, s = 1;
	cin >> n;
	while (2 * s <= n) {
		s += s;
	}
	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int x = 7 % N;
    set<int> s;
    int count = 1;
    if(N % 2 == 0 && N % 5 == 0){
        cout << "-1" << endl;
        return 0;
    }
    while(s.count(x) == 0){
        if(x == 0) {
            cout << count << endl;
            return 0;
        }
        s.insert(x);
        x = (x * 10 + 7) % N;
        count++;
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 50468
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn solve(i: usize, m: i16, a: &Vec<i16>) -> bool {
    if m == 0 {
        return true;
    }
    if i >= a.len() {
        return false;
    }
    return solve(i + 1, m, a) || solve(i + 1, m - a[i], a);
}

fn main() {
    let n: usize = read();
    let a: Vec<i16> = (0..n)
        .map(|_| {
            let number: i16 = read();
            number
        })
        .collect();
    let q: usize = read();
    let m: Vec<i16> = (0..q)
        .map(|_| {
            let number: i16 = read();
            number
        })
        .collect();
    for m_number in m {
        if solve(0, m_number, &a) {
            println!("yes");
        } else {
            println!("no");
        }
    }
}



Measured memory_bytes: 5028
import sys
def calc(a, b):
    c = a - b
    d = a**4 + a**3 * b + a**2 * b**2 + a * b**3 + b**4
    
    return c * d

X = int(input())

for i in range(-10**3, 10**3 + 1):
    for j in range(-10**3, 10**3 + 1):
        if calc(i, j) == X:
            print(f"{i} {j}")
            sys.exit()

Measured memory_bytes: 67908
#include <iostream>
#include <algorithm>
using namespace std;
int T,N,K,X[100000+10],A[100000+10];
int main() {
  cin >> T;
  for(int t=0; t<T; ++t) {
    cin >> N >> K;
    for(int i=0;i<N; ++i) cin >> X[i];
    for(int i=0;i+1<N; ++i) A[i] = X[i+1] - X[i];
    sort(A,A+N-1);
    int sum = 0;
    for(int i=0;i < N-1-(K-1); ++i) {
      sum += A[i];
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll inputLValue(){
    ll a;
    cin >> a;
    return a;
};

long long gcd(long long a, long long b){
  long long r = a % b;
  if(r == 0){
    return b;
  }
  return gcd(b, r);
}

int main()
{
    int N = inputValue();
    int ans = 0;
    int blk = 1;
    int pos = -1;
    REP(i,N){
        int a = inputValue();
        if(a==blk){
            ans += i - pos - 1;
            pos = i;
            blk++;
        }
    }
    if(pos >= 0){
        ans += N - pos - 1;
    }else{
        ans = -1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N;
    cin >> N;

    vector<int> L(N);
    REP(i, N) cin >> L[i];
    
    sort(ALL(L));

    // REP(i, N) cout << L[i] << endl;

    int a, ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            a = L[i] + L[j];
            int cnt = 0;
            for (int k = j+1; k < N; k++) {
                if (a <= L[k]) break;
                else cnt++;
            }
            ans += cnt;
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int a[100010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	int ans=0;
	for(int i=1;i<=n;i++)if(a[a[i]]==i)ans++;
	printf("%d",ans/2);
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
def main():
   N = int(input())
   T = [list(map(int, input().split())) for i in range(N)] 
   S = [[b, a] for a,b in T]
   U = sorted(S)
   time = 0
   for b, a  in U:
        time += a
        if time > b:
           print('No')
           return
   print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 63796
from collections import deque
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
q=deque([])
dist=[[-1 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            dist[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,1,-1]
while(len(q)>0):
    x,y=q.popleft()
    for k in range(4):
        nx=x+dx[k]
        ny=y+dy[k]
        if not(0<=nx<H and 0<=ny<W):
            continue
        if dist[nx][ny]==-1:
            dist[nx][ny]=dist[x][y]+1
            q.append((nx,ny))
print(max([max(i) for i in dist]))


Measured memory_bytes: 122716