akhauriyash/Code-Regression huggingface dataset:
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
sys.setrecursionlimit(10000000)
N = int(input())
from collections import defaultdict
MOD = 10**9 + 7

# T = defaultdict(list)
T = [set() for _ in range(N+1)]
for i in range(N-1):
    x,y = map(int, input().split())
    # T[x] += [y]
    # T[y] += [x]
    T[x].add(y)
    T[y].add(x)

def dfs(n,oya):
    b,w = 1,1
    for child_n in T[n]:
        if child_n == oya:
            continue
        child_b, child_w = dfs(child_n, n)
        b *= child_w % MOD
        w *= (child_b+child_w)%MOD
    return b%MOD, w%MOD
print( sum(dfs(1,None)) % MOD) 



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

using namespace std;

int Tree[1<<12],m;
map<int,int> mp;
vector<int> order;
string::iterator it;

vector<int> getOrder(int x,int m){
    vector<int> res;
    while(x > 0){
        res.push_back(x%3);
        x /= 3;
    }
    while((int)res.size() != m){
        res.push_back(0);
    }
    return res;
}

int getBit(int v,vector<int> &bit){
    if(Tree[v] != -1){
        return bit[Tree[v]];
    }
    int S = -1;
    int l = getBit(2*v+1, bit);
    int r = getBit(2*v+2, bit);
    switch(order[mp[v]]){
    case 0:
        S = l & r;
        break;
    case 1:
        S = l | r;
        break;
    case 2:
        S = (l | r) - (l & r);
        break;
    };
    return S;
}

bool check(vector<int> &bit){
    return (getBit(0,bit) == (1<<4)-1);
}

int makeTree(int v){
    if(*it == '('){
        ++it;
        char cl = *it;
        int l = makeTree(2*v+1);
        if(isdigit(cl)){
            Tree[2*v+1] = l;
        }
        ++it;
        char cr = *it;
        int r = makeTree(2*v+2);
        if(isdigit(cr)){
            Tree[2*v+2] = r;
        }
        ++it;
    }else if(isdigit(*it)){
        int num = ((*it - '0') - 1);
        ++it;
        return num;
    }
    return -1;
}

void dfs(int v){
    if(Tree[v] == -1){
        mp[v] = m++;
        dfs(2*v+1);
        dfs(2*v+2);
    }
}

int main(){
    string s;
    while(getline(cin,s), s != "END"){
        int N,x;
        cin >> N;
        vector<int> bit(N, 0);
        for(int i = 0 ; i < N ; i++){
            for(int j = 0 ; j < 4 ; j++){
                cin >> x;
                if(x == 1) bit[i] |= 1<<j;
            }
        }
        int res = 0;
        memset(Tree,-1,sizeof(Tree));
        it = s.begin();
        makeTree(0); m = 0; dfs(0);
        int n = pow(3., m);
        for(int i = 0 ; i < n ; i++){
            order = getOrder(i, m);
            if(check(bit)) res++;
        }
        cout << res << endl;
        cin.ignore();
    }
    return 0;
}

Measured memory_bytes: 1256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
void sor(vel &v) { sort(v.begin(), v.end()); }
int zero() { return 0; }
int gcd(int a, int b) {
	if (a < b) return gcd(b, a);
	if (b == 0) return a;
	int r = a % b;
	return gcd(b, r);
}
int ord(int a,int p) {
	if (a%p != 0) return 0;
	return 1 + ord(a / p,p);
}
int rui(int a, int n) {
	if (n == 0) {
		return 1;
	}
	return a * rui(a, n - 1);
}
int nibl(vel &v, int ser) {
	int up = v.size() - 1;
	int lo = 0;
	if (v[up] <= ser) {
		return up;
	}
	while (up - lo > 1) {
		int mi = (up + lo) / 2;
		if (ser < v[mi]) {
			up = mi;
		}
		else {
			lo = mi;
		}
	}
	return lo;
}
signed main() {
	int n; cin >> n;
	vel qa(n);
	vel qb(n);
	vel a(n);
	vel b(n);
	for (int i = 0; i < n; i++) {
		cin >> qa[i] >> qb[i];
	}
	vel qqa=qa;
	sor(qqa);
	vel su(n+1,0);
	vel sma(n);
	vel mi(n, 0);
	for (int i = 0; i < n; i++) {
		int num = nibl(qqa, qa[i]);
		num -= mi[num];
		mi[num]++;
		b[num] = qb[i];
	}
	a = qqa;
	for (int i = 0; i < n; i++) {
		su[i + 1] = su[i] + b[i];
		sma[i] = su[i + 1] - a[i];
	}
	vel msma(n);
	msma[n - 1] = sma[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		msma[i] = max(sma[i], msma[i + 1]);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		mmax(ans, msma[i] - su[i] + a[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 38016
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
vector<pii>g[110000];
int n,m;
bool used[110000];
bool vis[110000];
ll d[110000];
bool dfs(int x)
{
    vis[x]=1;
    used[x]=1;
    rep(i,g[x].size())
    {
        int a=g[x][i].X;
        int b=g[x][i].Y;
        if(d[a]>d[x]+b)
        {
            if(vis[a])return 0;
            d[a]=d[x]+b;
            if(!dfs(a))return 0;
        }
    }
    vis[x]=0;
    return 1;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m;
	rep(i,m)
	{
		int a,b,c;
		cin>>a>>b>>c;
		g[a].pb(m_p(b,c));
		g[b].pb(m_p(a,-c));
	}
	rep(i,n+1)
		d[i]=2e9;
	rep(i,n)
	{
		if(!used[i])
			
			{
			d[i]=0;
			if(!dfs(i))
				{
				cout<<"No\n";
				return 0;
				}
		}
	}
	cout<<"Yes\n";
	return 0;
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N,M,K;
    cin >> N >> M >> K;
    vector<ll> A,B;



    rep(i,N) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    ll now = 0;
    rep(i,M) {
        int b;
        cin >> b;
        B.push_back(b);
        now += b;
    }

    int ans = 0;
    int j = M;
    rep(i,N+1) {
        while(j>0 && now>K) {
            j--;
            now -= B[j];
        }
        if (j==0 and now>K) break;
        ans = max(ans,i+j);
        if (i==N) break;
        now+=A[i];
    }

    cout << ans << endl;


}

Measured memory_bytes: 7996
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
   int N, K;
   std::cin >> N >> K;

   std::vector<int> l(N);
   for(int i=0; i<N; ++i)
      std::cin >> l[i];

   std::sort(l.begin(),l.end());
   int ans = 0;
   for(int i=0; i<K; ++i)
      ans += l[N-1-i];

   std::cout << ans << std::endl;
   return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int bingo[3][3];
	int i,j,k;
	int n;
	//input	
	for (i = 0; i < 3;++i) {
		for (j = 0; j < 3;++j) {
			scanf("%d", &bingo[i][j]);
		}
	}
	//n	
	scanf("%d", &n);
	int b[n];
	for (i = 0; i < n;++i) {
		scanf("%d", &b[i]);
	
		for (j = 0; j < 3;++j) {
			for (k = 0; k < 3;++k) {
				if (bingo[j][k] == b[i])
					bingo[j][k] = 0;
			}
		}
	}
		//yokodake
		for (j = 0; j < 3;++j) {
				if(bingo[j][0] == 0)
					if(bingo[j][1] == 0)
						if(bingo[j][2] == 0) {
							puts("Yes");
							return 0;
						}
		}
		//tatedake
		for (j = 0; j < 3;++j) {
			if(bingo[0][j] == 0)
				if(bingo[1][j] == 0)
					if(bingo[2][j] == 0) {
						puts("Yes");
						return 0;
					}
		}
		if (bingo[0][0] == 0 && bingo[1][1] == 0 && bingo[2][2] == 0) {
			puts("Yes");
			return 0;
		}
		if (bingo[2][0] == 0 && bingo[1][1] == 0 && bingo[2][0] == 0) {
			puts("Yes");
			return 0;
		}
		puts("No");

	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n, m, k;
  cin >> n >> m >> k;

  vector<int> a(n), b(m);
  vector<ll> c(n+1), d(m+1);
  rep(i,n) cin >> a[i];
  rep(j,m) cin >> b[j];
  for (int i = 0; i < n; ++i) c[i+1] = c[i] + a[i];
  for (int i = 0; i < m; ++i) d[i+1] = d[i] + b[i];
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    ll rm = k-c[i];
    if (rm < 0) break;
    // cout << rm << endl;
    int l = -1, r = m+1;
    while (r - l > 1) {
      int mid = (r+l) / 2;
      if (d[mid] <= rm) l = mid;
      else r = mid;
    }
    // cout << l << endl;
    ans = max(ans, i+l);
  }
  cout << ans << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;

ll divceil(ll x, ll y) {
    assert(y!=0);
    return (x+y-1)/y;
}

ll K, X, Y;

ll xx = 1, yy = 1;

vector<pair<ll,ll>> ans;

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

    cin>>K>>X>>Y;

    if ((X+Y)%2) {
	if (K%2==0) out(-1);
    }


    // transpose to make goal in Q1
    if (X<0) {
	X = -X;
	xx = -1;
    }

    if (Y<0) {
	Y = -Y;
	yy = -1;
    }

    // A: positive movement
    // B: negative movement
    // N: min moves

    // NK = A+B
    // A-B = X+Y

    // A = (NK+X+Y)/2
    // B = (NK-X-Y)/2

    // B implies:
    // NK >= X+Y ----------> N = ceil((X+Y)/K)
    // (NK = X+Y)mod2 -----> if (X+Y) is odd, K cannot be even

    // Also if N=1, then K=X+Y. This is implied by the problem statement itself
    

    
    ll N = divceil(X+Y, K);
    while (N*K-X-Y < 0) N++;
    if (N==1 && X+Y!=K) N++;
    while ((N*K+X+Y)%2!=0) N++;

    ll B = (N*K-X-Y)/2;
    //ll A = (N*K+X+Y)/2;



    ll x = 0;
    ll y = 0;

    // Get rid of negative motion
    // While we have >= K, just burn them in any direction
    // Once B < K, we should burn the rest of it in the dimension that
    // we are closer to, then use the rest of it productively.
    
    // Proof
    // Before this last move, let dx=abs(x-X) and dy=abs(y-Y).
    // This means so far, we'll need something like dx/K moves dedicated
    // purely in x direction, and dy/K moves purely in y direction.
    // At the moment, we have B<K of negative movement left.
    // If dx<dy, it make sense to burn the rest of B on dx because
    // it has the least risk of incrementing global N by 1. This would happen
    // if (dx+B)/K > dx/K.

    while (B>0) {
	if (B-K >= 0) {
	    x -= K;
	    ans.push_back({x,y});
	    B -= K;
	} else {
	    ll rest = B;
	    ll rem = K - rest;
	    if (abs(x-X) < abs(y-Y)) {
		x -= rest;
		y += rem;
	    } else {
		y -= rest;
		x += rem;
	    }
	    ans.push_back({x,y});
	    B -= rest;
	}
    }

    while (x < X) {
	ll go = min(X-x, K);
	ll rest = K - go;
	x += go;
	y += rest;
	ans.push_back({x,y});
    }

    assert(abs(Y-y)%K == 0);
    while (y < Y) {
	y += K;
	ans.push_back({x,y});
    }


    assert((int)ans.size() == N);
    cout<<N<<"\n";
    for (auto p: ans) {
	cout<<(xx*p.first)<<" "<<(yy*p.second)<<"\n";
    }

    
    return 0;
}


Measured memory_bytes: 7284
#入力
A = input().split()

#A,B ＝　数値化　M,m　＝　初期化
A[0] = int(A[0])
A[1] = int(A[1])
m = 0

#K探し
m = ( A[0] + A[1] ) / 2

#K判定
if m.is_integer():
    print( '%d' %m)
else :
    print('IMPOSSIBLE')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed
int main()
{
   ios;
   int n;
   cin >> n;
   map<int, int> mp;
   for (int i = 0, a; i < n; ++i)
      cin >> a, mp[a]++;
   int ans = 0;
   for (auto i : mp)
   {
      if (i.ff != i.ss)
      {
         if (i.ss > i.ff)
            ans += abs(i.ff - i.ss);
         else
            ans += i.ss;
      }
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 7952
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n; cin >> n;
    ll ac = 0, wa = 0, tle = 0, re = 0;
    rep(i,n){
        string s; cin >> s;
        if(s == "AC") ac++;
        if(s == "WA") wa++;
        if(s == "TLE") tle++;
        if(s == "RE") re++;
    }
    printf("AC x %lld\n", ac);
    printf("WA x %lld\n", wa);
    printf("TLE x %lld\n", tle);
    printf("RE x %lld\n", re);
    return 0;
}

Measured memory_bytes: 3724
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
 
int main()  {

  int T,X;
  // 空白文字で区切られた数字を 3 つ取得
  std::cin >> T >> X;
  printf("%f\n",(float)T/X);
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define ALL(a) (a).begin(),a.end()
#define MAXE(a) *max_element(ALL(a))
#define MINE(a) *min_element(ALL(a))

int main(){
	ll n;
	cin >> n;
	ll a[300000];
	REP(i,n) cin >> a[i];
	vl b;
	if(n == 1){
		cout << a[0] << endl;
		return 0;
	}
	if(n%2 == 0){
		for(int i=n-1;i>0;i-=2){
			cout << a[i] << " ";
		}
		for(int i=0;i<n;i+=2){
			cout << a[i];
			if(i == n-2) break;
			cout << " ";
		}
		cout << endl;
	}
	else{
		for(int i=n-1;i>=0;i-=2){
			cout << a[i] << " ";
		}
		for(int i=1;i<n;i+=2){
			cout << a[i];
			if(i == n-2) break;
			cout << " ";
		}
		cout << endl;
	}


}

Measured memory_bytes: 3712
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i > 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t int64;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 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; }

using namespace std;


class C {
	int n;
	vector<int> h;
public:
	C()
	{
		cin >> n;
		h.resize(n);
		REP(i, n)
			cin >> h[i];
	}
	void solve()
	{
		int ans{ 0 };
		int streak{ 0 };
		int i{ 0 };

		while (i < n - 1)
		{
			if (h[i] >= h[i + 1])
			{
				streak++;
				i++;
				chmax(ans, streak);
			}

			else
			{
				streak = 0;
				i++;
			}
		}

		cout << ans << endl;
	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;

typedef long long ll;

/*
  let's try computer shogi!!!
 */


std::vector<int> find_all(const std::string str, const std::string subStr) {
  std::vector<int> result;

  int subStrSize = subStr.size();
  int pos = str.find(subStr);

  while (pos != std::string::npos) {
    result.push_back(pos);
    pos = str.find(subStr, pos + subStrSize);
  }

  return result;
}

int main(){
  ll n;
  string s[20000];
  cin >> n;
  int abcnt = 0;
  int bstart = 0;
  int aend = 0;
  int both = 0;
  for(int i=0;i<n;++i){
    cin >> s[i];
    int ab = find_all(s[i],"AB").size();
    cerr<<ab<<",";
    abcnt += ab;
    bool b = false;
    bool a = false;
    if(s[i][0] == 'B'){
      b = true;
    }
    if(s[i][s[i].length()-1] == 'A'){
      a = true;
    }
    if(a && b){
      both += 1;
    }else{
      if(a){
	aend += 1;
      }
      if(b){
	bstart += 1;
      }	
    }
  }
  cerr<<endl;
  cerr<<aend<<","<<bstart<<","<<both<<endl;
  if (aend == 0){
    bstart -= 1;
  }
  cout<<abcnt + max(0, min(both+aend,bstart+both))<<endl;
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> E(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		E[max(a - 1, b - 1)]++;
		E[min(a - 1, b - 1)]--;
	}
	bool ans = true;
	int now = E[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		if (now % 2 != 0) ans = false;
		now += E[i];
	}
	cout << (ans ? "YES" : "NO") << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//関数ここから

int gcd(int num1, int num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}

int lcm(int num1, int num2){
    return num1 * num2 / gcd(num1, num2);
}

//32bit整数型に収まらない時は"全ての"intをlong long intに置き換えること(ABC131Cを忘れるな)
//以下サンプル
int main(){
    int A=2,B;
    cin >> B;
    cout << lcm(A,B) << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
D = defaultdict(list)
d = set()
P = {}
for i in range(N):
    s, p = input().split()
    p = int(p)
    D[s].append(p)
    d.add(s)
    P[p] = i

d = sorted(list(d))
for i in d:
    k = sorted(D[i], reverse=True)
    for j in k:
        print(P[j] + 1)




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

using namespace std;

int main() {
    //forItachi
    int a,b;
    cin>>a>>b;
    int max,other;
    if(a>b){
        max = a;
        other = b;
    }
    else{
        max = b;
        other = a;
    }
    int i;
    for( i =0 ; i<max;i++){
        cout<<other;
    }
    cout<<endl;
    
}

Measured memory_bytes: 256
import numpy as np


def main():
    N = int(input())
    TXY = [[int(x) for x in input().split()] for _ in range(N)]
    TXY.insert(0, [0, 0, 0])
    d = np.diff(TXY, 1, 0)
    dd = d[:, 0] - np.abs(d[:, 1]) - np.abs(d[:, 2])
    b1 = np.any(dd < 0)
    b2 = np.any(dd % 2 != 0)
    if b1 or b2:
        print('No')
    else:
        print('Yes')


main()


Measured memory_bytes: 34808
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF 1000000000
    #define MOD 1000000007
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;
    //vector<tuple<long long, long long, long long>>vec;

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

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


    int main()
    {
        int n;
        cin >> n;
        deque<int> d;
        for(int i = 0; i < n; i++){
            int a;
            cin >> a;
            if(n%2==0){
                if(i%2==0) d.push_back(a);
                else d.push_front(a);
            }else{
                if(i%2==0) d.push_front(a);
                else d.push_back(a);
            }
        }
        for(int i = 0; i < n; i++) cout << d[i] << " ";
        cout << endl;
    }

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int w, h;
string sl[50], sr[50];
bool vis[50][50][50][50];
P ls, rs, lg, rg;
int dxl[] = {1, 0, -1, 0};
int dxr[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

bool range(int x, int y) {
    return 0 <= x && x < w && 0 <= y && y < h;
}

bool dfs(P l, P r) {
    deque<PP> q;
    q.pb(PP(l, r));
    while(!q.empty()) {
        PP p = q.back(); q.pop_back();

        if (p.fi == lg && p.se == rg) return true;
        else if (p.fi == lg || p.se == rg) continue;

        vis[p.fi.fi][p.fi.se][p.se.fi][p.se.se] = true;
        rep(i, 4) {
            int lx = p.fi.se + dxl[i], ly = p.fi.fi + dy[i];
            if (!range(lx, ly) || (range(lx, ly) && sl[ly][lx] == '#')) lx = p.fi.se, ly = p.fi.fi;
            int rx = p.se.se + dxr[i], ry = p.se.fi + dy[i];
            if (!range(rx, ry) || (range(lx, ly) && sr[ry][rx] == '#')) rx = p.se.se, ry = p.se.fi;
            if (!vis[ly][lx][ry][rx]) {
                q.pb(PP(P(ly, lx), P(ry, rx)));
                vis[ly][lx][ry][rx] = true;
            }
        }
    }
    return false;
}

int main(){
    cin.sync_with_stdio(false);
    while(cin >> w >> h, w | h) {
        memset(vis, 0, sizeof(vis));

        rep(i, h) {
            cin >> sl[i] >> sr[i];
            rep(j, w) {
                if (sl[i][j] == 'L') ls = P(i, j);
                if (sr[i][j] == 'R') rs = P(i, j);
                if (sl[i][j] == '%') lg = P(i, j);
                if (sr[i][j] == '%') rg = P(i, j);
            }
        }

        cout << (dfs(ls, rs) ? "Yes" : "No") << endl;
    }

    return 0;
}

Measured memory_bytes: 12052
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int x;
	cin>>x;
	if(x%7==2)cout<<"sat"<<endl;
	if(x%7==3)cout<<"sun"<<endl;
	if(x%7==4)cout<<"mon"<<endl;
	if(x%7==5)cout<<"tue"<<endl;
	if(x%7==6)cout<<"wed"<<endl;
	if(x%7==0)cout<<"thu"<<endl;
	if(x%7==1)cout<<"fri"<<endl;
    return 0;
    }


Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 2e5 + 5;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;
ll gcd(ll a, ll b) {
	if (b == 0LL) return a;
	return gcd(b, a % b);
}
pair<int, int> A[MAXN];
pair<int, int> B[MAXN];

int main()
{
	int i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; ++i) {
		scanf("%d%d", &A[i].first, &A[i].second);
		B[i].first = A[i].second;
		B[i].second = A[i].first;
	}
	sort(A + 1, A + 1 + N);
	sort(B + 1, B + 1 + N);
	if (N & 1) {
		int l = A[(N + 1) / 2].first;
		int r = B[(N + 1) / 2].first;
		printf("%d", r - l + 1);
	}
	else {
		int l = A[N / 2].first + A[N / 2 + 1].first;
		int r = B[N / 2].first + B[N / 2 + 1].first;
		printf("%d", r - l + 1);
	}
}

Measured memory_bytes: 6952
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()

typedef unsigned long long ll;

int main(){
   int N; cin >> N;
   int cnt = 0;
   for(int i = 1; i <= N; i++){
       if(to_string(i).length() % 2 == 1){
           cnt++;
       }

  }
  cout << cnt << endl;
}



Measured memory_bytes: 256
def solve(a, b):
    return xor(a-1) ^ xor(b)


def xor(num):
    if num % 2 == 0:
        if (num + 1) // 2 % 2 == 0:
            return num
        else:
            return 1 ^ num
    else:
        if (num + 1) // 2 % 2 == 0:
            return 0
        else:
            return 1


def main():
    a, b = map(int, input().split())

    ans = solve(a, b)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,ans=0;
  cin>>n;
  
  vector<map<ll,ll>> v(n,map<ll,ll>());
  rep(i,n){
    ll a;
    cin>>a;
    rep(j,a){
      ll b,c;
      cin>>b>>c;
      v[i][b-1]=c;
    }
  }
  for(ll i=1;i<(1<<n);i++){
    bool t[n]={false};
    ll tmp=0;
    bool flag=true;
    rep(j,n){
      if(i&(1<<j)) t[j]=true;
    }
    
    
    rep(j,n){
      if(i&(1<<j)){
        //j番目の発言を見る
        for(auto c:v[j]){
          if(c.second==1 && t[c.first]!=true || c.second==0 && t[c.first]!=false){
            //おわた
            flag=false;
          }
        }
      }else{
        if(t[j]==true) flag=false;
      }
      
    }
    if(flag){
      rep(k,n){
        if(t[k]) tmp++;
      }
      ans=max(ans,tmp);
    }
    
    
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int k, s;
  cin >> k >> s;
  ll res = 0;
  for(int i = 0; i <= k; i++){
    for(int j = 0; j <= k; j++){
      if(s - i - j >= 0 && s - i - j <= k)res++;
    }
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int a[20],b[20];
int f[(1<<18)+5][20],cnt[(1<<18)+5];
int n;
int main()
{
	n=read();
	for(int i=0;i<n;i++)
		a[i]=read();
	for(int i=0;i<n;i++)
		b[i]=read();
	memset(f,0x3f,sizeof(f));
	cnt[0]=0;
	for(int S=1;S<1<<n;S++){
		cnt[S]=cnt[S>>1]+(S&1);
		if(cnt[S]==1){
			for(int i=0;i<n;i++)
				if(S&(1<<i))f[S][i]=0;
			continue;
		}
		for(int i=0;i<n;i++)
			if(S&(1<<i)){
				int val=0;
				for(int j=0;j<n;j++)
					if(S&(1<<j))val+=(j>i);
				int cur=(((cnt[S]-1)-i)&1)?b[i]:a[i];
				for(int j=0;j<n;j++)
					if((i!=j)&&(S&(1<<j))){
						int last=(((cnt[S]-2)-j)&1)?b[j]:a[j];
						if(cur>=last)f[S][i]=std::min(f[S][i],f[S^(1<<i)][j]+val);
					}
			}
	}
	int ans=inf;
	for(int i=0;i<n;i++)
		ans=std::min(ans,f[(1<<n)-1][i]);
	if(ans<inf)writeln(ans);
	else puts("-1");
	return 0;
}

Measured memory_bytes: 21632
n,m=map(int,input().split())
li=[]
L=[]
M=[]
for i in range(m):
    l,m=map(int,input().split())
    L.append(l)
    M.append(m)

if max(L)<=min(M):
    print(min(M)-max(L)+1)
else:
    print(0)


Measured memory_bytes: 11052
#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;
vector<char> key[10];

void Init(){
  int index=0;
  key[1].push_back('.');key[1].push_back(',');key[1].push_back('!');key[1].push_back('?');key[1].push_back(' ');
  for(int i=2;i<=9;i++){
    if(i == 7 || i == 9){
      for(int j=0;j<4;j++){
	key[i].push_back((char)('a'+index));
	index++;
      }	
    }else{
      for(int j=0;j<3;j++){
	key[i].push_back((char)('a'+index));
	index++;
      }
    }
  }
  key[0].push_back('_');
  /*
  for(int i=0;i<=9;i++){
    for(int j=0;j<key[i].size();j++){
      cout << key[i][j] << " ";
    }
    cout << endl;
  }
  */
}


int main(){
  Init();
  int T,div,cnt;
  string s;
  char th;
  bool zcnt;
  cin >> T;
  while(T-- > 0){
    cin >> s;
  
    char p = s[0];
    int cnt = 0;
    for(int i=0;i<s.length();i++){
      if(s[i] == '0'){
	//cout << "p = "<< p << ",cnt = " << cnt << endl;
	cnt--;
	int Size = key[p-'0'].size();
	if(p != '0')cout << key[p-'0'][cnt%Size];
	cnt = 0;
	p = s[i+1];
	continue;
      }
      cnt++;
    }cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
class Dictionary_class:
    def __init__(self):
        self.dic = set()

    def insert(self, str):
        self.dic.add(str)

    def find(self, str):
        if str in self.dic:
            return True
        else:
            return False

n = int(input())
answer = ""
dic = Dictionary_class()
for i in range(n):
    instruction = input().split()
    if instruction[0] == "insert":
        dic.insert(instruction[1])
    elif instruction[0] == "find":
        if dic.find(instruction[1]):
            answer += "yes\n"
        else:
            answer += "no\n"
print(answer, end = "")

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

using namespace std;

bool allA(string s){
    for(char c : s){
        if(c != 'a')return false;
    }
    return true;
}

int main() {
    string s ; cin>>s;
    int n ; cin>>n;
    int m = s.size();
    for(int i = 0 ; i < m; ++i){
        int pos = s[i] - 'a';
        if(26 - pos <= n && s[i] != 'a'){
            n -= (26 - pos);
            s[i] = 'a';
        }
    }
    if(allA(s)){
        int norm = n % 26;
        while(norm--){
            s[m - 1] = char(s[m - 1] + 1);
        }
        cout<<s<<"\n";
        return 0;
    }
    int norm = n % 26;
    for(;norm--;){
        s[m - 1]++;
        if(s[m - 1] > 'z')s[m - 1] = 'a';
    }
    cout<<s<<"\n";
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
    int h,w;
    int i,j;
    while(1){
        scanf( "%d %d" , &h , &w );
        if( h == 0 && w == 0 ) break;
        for( i = 0; i < h ; i++ ){
            for( j = 0 ; j < w ; j++ ){
                if( j == w - 1 || j == 0 || i == h -1 || i == 0 ){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2040
import math
import itertools
N = int(input())
X = []
Y = []

for _ in range(N):
	x, y = map(int, input().split())
	X.append(x)
	Y.append(y)
ret = 0	

for lst in itertools.permutations(range(N)):
	for i in range(1, N):
		ret += math.sqrt((X[lst[i]] - X[lst[i - 1]]) ** 2 + (Y[lst[i]] - Y[lst[i - 1]]) ** 2)
		
print(ret / math.factorial(N))

Measured memory_bytes: 40556
n = int(input())
p_lis = list(map(int, input().split()))
org = list(range(1, n+1, 1))

c = 0
for i in range(n):
      if p_lis[i]== org[i]:
            pass
      else:
            c += 1
if c >=3:
      print("NO")
else:
      print("YES")

Measured memory_bytes: 3060
import math


def koch(m, p1, p2):
    if m == 0:
        return

    s = [(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3]
    t = [(p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3]
    u = [(t[0] - s[0]) * math.cos(math.pi / 3) - (t[1] - s[1]) * math.sin(math.pi / 3) + s[0],
         (t[0] - s[0]) * math.sin(math.pi / 3) + (t[1] - s[1]) * math.cos(math.pi / 3) + s[1]]

    koch(m-1, p1, s)
    print(s[0], s[1])
    koch(m-1, s, u)
    print(u[0], u[1])
    koch(m-1, u, t)
    print(t[0], t[1])
    koch(m-1, t, p2)


n = int(input())
print(0, 0)
koch(n, [0, 0], [100, 0])
print(100, 0)

Measured memory_bytes: 8052
import java.util.Arrays;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++)
            a[i] = sc.nextInt();

        Arrays.sort(a);
        long ans = a[0] + a[1];
        for(int i = 2; i < n; i++) {
            ans += a[i] * Math.pow(2, i - 1);
        }

        System.out.println((double)(ans / Math.pow(2, n - 1)));
    }

}


Measured memory_bytes: 36000
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int K, S, res;
    res = 0;
	cin >> K >> S;
    for (int X = 0; X <= K; X++) {
        for (int Y = 0; Y <= K; Y++) {
            int Z = S - X - Y;
            if (Z >= 0 && Z <= K) {
                res++;
            }
        }
    }
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<vector<ll>> dp(n + 1, vector<ll>(2));
	dp[0][0] = 0;
	dp[0][1] = -linf;
	rep(i, n) {
		dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
		dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
	}
	cout << dp[n][0] << endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 998244353
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef unsigned long long ull;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n,h,w;	cin>>n>>h>>w;
	cout<<(n-h+1)*(n-w+1)<<'\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i) 
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so sort
#define rev reverse
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin >> n >> m;
  vector<int> canGoFrom1;
  vector<int> canGoToN;
  REP(i,m){
    int a,b;
    cin >> a >> b;
    if((a == 1 && b == n)||(a == n && b == 1)){
      cout << "POSSIBLE" << endl;
      return 0;
    }
    if(a == n || b == 1)swap(a,b);
    if(a == 1)
      canGoFrom1.pub(b);
    if(b == n)
      canGoToN.pub(a);
  }
  so(ALL(canGoFrom1));
  so(ALL(canGoToN));
  canGoToN.pub(200001);
  REP(i,SZ(canGoFrom1)){
    DUMP(canGoFrom1[i]);
    DUMP(*lower_bound(ALL(canGoFrom1),canGoFrom1[i]));
    if(canGoFrom1[i] == *lower_bound(ALL(canGoToN),canGoFrom1[i])){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 1276
l = []
for i in range(5):
    a = int(input())
    l.append(a)

total = 0
for e in l:
    if e % 10 == 0:
        total += e
    else:
        total += (int(e / 10)) * 10 + 10

mi = 10
for e in l:
    if e % 10 == 0:
        continue
    mi = min( mi, e % 10 )

print(total - 10 + mi)


Measured memory_bytes: 3064
import java.util.*;
    public class Main {
        static boolean find(String s) {
            Stack<Character> ch = new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            }
            return ch.isEmpty();
        }

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int x=0;
           x+=(n/500)*1000;
           n=n%500;
           x+=(n/5)*5;
            System.out.println(x);
        }
    }


Measured memory_bytes: 35648
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
string S;
// main solution goes here:
void execute(int test_number)
{
    cin>>S;
    if (S== "ABC") cout<<"ARC";
    else cout<<"ABC";
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Measured memory_bytes: 3660
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;
 
int main(int argc, char *argv[])
{
    int N, M;
    std::cin >> N >> M;

    std::vector<int> X(M);
    for (int i = 0; i < M; i++) {
        std::cin >> X[i];
    }

    int ans = 0;
    if (N >= M) {
        ans = 0;
    } else {
        std::sort(X.begin(), X.end());
        std::vector<int> diff(M-1);
        for (int i = 0; i < M-1; i++) {
            diff[i] = X[i+1] - X[i];
        }

        std::sort(diff.begin(), diff.end());
        for (int i = 0; i < M-N; i++) {
            ans += diff[i];
        }
    }

    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int GoGo = 100000000;
int main(){
  int N, T;
  int ans = GoGo;
  cin >> N >> T;
  vector<int> c(N);
  vector<int> t(N);
  for(int i = 0; i < N; i++){
    cin >> c[i] >> t[i];
  }

  for(int i = 0; i < N; i++){
    if(t[i] <= T){
      ans = min(ans,c[i]);
    }
  }
  if(ans < GoGo){
    cout << ans << endl;
  } else {
    cout << "TLE" << endl;
  }
  return 0;
}

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


int main(int argc, char const *argv[]) {
    ll N;
    string S;
    cin >> N >> S;

    map<char, vector<ll>> count;
    for (int i = 0LL; i <= N; i++) {
        if (i == 0LL) {
            count['R'].push_back(0);
            count['G'].push_back(0);
            count['B'].push_back(0);
        } else {
            if (S[i - 1] == 'R') {
                count['R'].push_back(count['R'][i - 1] + 1LL);
                count['G'].push_back(count['G'][i - 1]);
                count['B'].push_back(count['B'][i - 1]);
            }
            else if (S[i - 1] == 'G') {
                count['R'].push_back(count['R'][i - 1]);
                count['G'].push_back(count['G'][i - 1] + 1LL);
                count['B'].push_back(count['B'][i - 1]);
            }
            if (S[i - 1] == 'B') {
                count['R'].push_back(count['R'][i - 1]);
                count['G'].push_back(count['G'][i - 1]);
                count['B'].push_back(count['B'][i - 1] + 1LL);
            }
        }
    }
    ll ans = 0LL;
    for (ll i = 0LL; i < N; i++) {
        for (ll k = i + 2; k < N; k++) {
            if (S[i] == S[k]) {
                continue;
            }
            char s;
            if ((S[i] == 'R' && S[k] == 'B') || (S[i] == 'B' && S[k] == 'R')) {
                s = 'G';
            } else if ((S[i] == 'R' && S[k] == 'G') || (S[i] == 'G' && S[k] == 'R')) {
                s = 'B';
            } else if ((S[i] == 'G' && S[k] == 'B') || (S[i] == 'B' && S[k] == 'G')) {
                s = 'R';
            }
            ll c = count[s][k + 1] - count[s][i];

            if ((i + k) % 2 == 0) {
                if (S[(i + k) / 2] == s) {
                    c -= 1LL;
                }
            }
            ans += c;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; ++i){
        cin >> l[i];
    }
    
    sort(l.begin(), l.end());
    ll res = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            int lb = abs(l[i] - l[j]);
            int ub = l[i] + l[j];
            
            int tmp = 0;
            tmp += lower_bound(l.begin(), l.begin() + i, ub) - upper_bound(l.begin(), l.begin() + i, lb);
            tmp += lower_bound(l.begin() + i + 1, l.begin() + j, ub) - upper_bound(l.begin() + i + 1, l.begin() + j, lb);
            tmp += lower_bound(l.begin() + j + 1, l.end(), ub) - upper_bound(l.begin() + j + 1, l.end(), lb);
            res += tmp;
        }
    }
    
    cout << res / 3 << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct node {
    int key;
    node *left;
    node *right;
};

void walkInOrder(node *cur) {
    if (cur == nullptr) return;
    walkInOrder(cur->left);
    printf(" %d", cur->key);
    walkInOrder(cur->right);
}

void walkPreOrder(node *cur) {
    if (cur == nullptr) return;
    printf(" %d", cur->key);
    walkPreOrder(cur->left);
    walkPreOrder(cur->right);
}

struct binaryTree {
    node *root;

    binaryTree() {
        root = nullptr;
    }

    void insert(int x) {
        node **v = &root;
        node *nodeX = (node *) malloc(sizeof(node));
        nodeX->key = x;
        nodeX->left = nodeX->right = nullptr;
        while (*v != nullptr) {
            if ((*v)->key <= x) v = &(*v)->right;
            else v = &(*v)->left;
        }
        *v = nodeX;
    }

    bool find(int x) {
        node *v = root;
        while (v != nullptr) {
            if (x < v->key) v = v->left;
            else if (v->key < x) v = v->right;
            else return true;
        }
        return false;
    }

    void print() {
        walkInOrder(root);
        printf("\n");
        walkPreOrder(root);
        printf("\n");
    }
};

int main() {
    int n;
    binaryTree tree;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string op;
        int x;
        cin >> op;
        if (op == "print") tree.print();
        else {
            cin >> x;
            if (op == "insert") tree.insert(x);
            else if (op == "find") cout << (tree.find(x) ? "yes" : "no") << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 15720