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

int main() {
    int n;
    cin >> n;
    int ans = 0;
    vector<int> v(n), c(n);
    for (auto& e : v) cin >> e;
    for (auto& e : c) cin >> e; 
    for (int i=0; i<n; i++) {
        if (v[i] - c[i] > 0) ans += v[i] - c[i];
    }
    cout << ans << endl;
    return 0;
}


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

typedef pair<int,int> P;
int main(){
  int n,m;
  cin >> n >> m;
  vector<P> ba;
  for(int i = 0;i < n;i++){
    int a,b;
    cin >> a >> b;
    ba.push_back({b,-a});
  }
  sort(ba.begin(),ba.end());
  reverse(ba.begin(),ba.end());
  for(int i = 0;i < n;i++){
    ba.at(i).second *= -1;
  }
  vector<int> movenum(m+1),ans(m+1);
  for(int i = 0;i < n;i++){
    int curday = m-ba.at(i).second+1;
    while(curday > 0){
      if(ans.at(curday) == 0){
        ans.at(curday) = ba.at(i).first;
        movenum.at(curday)++;
        break;
      }
      else{
        int x = curday;
        curday -= movenum.at(curday);
        movenum.at(x)++;
      }
    }
  }
  int result = 0;
  for(int i = 1;i <= m;i++){
    result += ans.at(i);
  }
  cout << result << endl;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define sz size()
#define S second
#define F first
#define all(x) x.begin(), x.end()

typedef pair < int, int > pii;
typedef vector < int >  vi;
typedef vector < vector < int > >  vvi;

void solve(){
    int x;
    cin >> x;
    if(x >= 30){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

signed main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}




Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main() {

	int n, x, y; cin >> n >> x >> y;

	// グラフ入力受取 (ここでは無向グラフを想定)
	Graph G(n);
	for (int i = 0; i < n - 1; ++i) {
		G[i].push_back(i + 1);
		G[i + 1].push_back(i);
		if (i == x - 1) G[i].push_back(y - 1);
		if (i == y - 1) G[i].push_back(x - 1);
	}

	vector<int> num(n, 0);

	for (int i = 0; i < n; i++) {

		// BFS のためのデータ構造
		vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
		queue<int> que;

		// 初期条件 (頂点 i を初期ノードとする)
		dist[i] = 0;
		que.push(i); // i を橙色頂点にする

		// BFS 開始 (キューが空になるまで探索を行う)
		while (!que.empty()) {
			int v = que.front(); // キューから先頭頂点を取り出す
			que.pop();

			// v から辿れる頂点をすべて調べる
			for (int nv : G[v]) {
				if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

				// 新たな白色頂点 nv について距離情報を更新してキューに追加する
				dist[nv] = dist[v] + 1;
				que.push(nv);
			}
		}

		for (int j = 0; j < n; j++) {
			if (i < j)  num[dist[j]]++;
		}

	}

	for (int i = 1; i < n; i++){
		cout << num[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=12010,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,mod,tot,f[N][N];ll inv[N],jc;//f[i][j]��ʾi����,j��ʾ1�ĸ���-2�ĸ��� 
void upd(int &x) {x+=x>>31&mod;}
void upd(ll &x)  {x+=x>>63&mod;}

int main() {
	qr(n); qr(mod); tot=3*n+1; 
	f[0][tot]=1;
	inv[1]=jc=1; for(int i=2;i<tot;i++) inv[i]=inv[mod%i]*(mod-mod/i)%mod,jc=jc*i%mod;
	for(int i=1;i<tot;i++) 
		for(int j=-i+tot;j<=i+tot;j++) {
			f[i][j]=f[i-1][j-1]*inv[i]%mod;
			if(i>=2)upd(f[i][j]+=f[i-2][j+1]*inv[i]%mod-mod);
			if(i>=3)upd(f[i][j]+=f[i-3][j  ]*inv[i]%mod-mod);
		}
	ll ans=0; 
	for(int i=tot;i<=tot*2;i++) ans+=f[tot-1][i];
	ans%=mod; pr2(ans*jc%mod);
	return 0;
}



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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int H,W,S,T;
struct edge{
	int to,cap,rev;
};
vector<edge> E [2] [10002];
bool used [2] [10002];
const int dx [] = {0,1,0,-1};
const int dy [] = {-1,0,1,0};
const int INF = 1e9;
const int MAX_ANS = 10000;

bool in_range(int y,int x)
{
	return y >= 0 && y < H && x >= 0 && x < W;
}

int dfs(bool b,int curr,int T,int f)
{
	if(curr == T) return f;
	used [b] [curr] = true;
	for(auto&& it : E [b] [curr]){
		if(used [!b] [it.to] == false && it.cap > 0){
			int d = dfs(!b,it.to,T,min(f,it.cap));
			if(d > 0){
				it.cap -= d;
				E [!b] [it.to] [it.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow()
{
	int flow = 0;
	while(true){
		memset(used,0,sizeof(used));
		int f = dfs(1,S,T,INF);
		if(f == 0) return flow;
		else if(f >= MAX_ANS) return -1;
		flow += f;
	}
}

void add_edge(int from,int to,bool b,int cap)
{
	E [b] [from].push_back({to,cap,(int) E [!b] [to].size()});
	E [!b] [to].push_back({from,0,(int) E [b] [from].size() - 1});
}

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

	cin >> H >> W;
	vector<string> field(H);
	FOR(i,0,H){
		cin >> field [i];
	}
	S = H * W,T = H * W + 1;

	FOR(i,0,H){
		FOR(j,0,W){
			bool flag = false;
			FOR(k,0,4){
				int y = i + dy [k],x = j + dx [k];
				if(in_range(y,x)){
					add_edge(i * W + j,y * W + x,1,INF);
				}
				else{
					flag = true;
				}
			}
			if(flag){
				add_edge(i * W + j,T,1,INF);
			}
			if(field [i] [j] == 'X'){
				add_edge(S,i * W + j,1,INF);
				add_edge(i * W + j,i * W + j,0,INF);
			}
			else{
				add_edge(i * W + j,i * W + j,0,1);
			}
		}
	}

	cout << max_flow() << endl;

	return 0;
}


Measured memory_bytes: 4608
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(void){
	int n, a[101], i, j, max = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0; i < n - 1; i++) {
		for (j = i + 1; j < n; j++) {
			if (abs(a[i] - a[j]) >= max) {
				max = abs(a[i] - a[j]);
			}
		}
	}
	printf("%d\n", max);
}

Measured memory_bytes: 128
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 1e6 + 111;
        
using namespace std;          

int n, k, ans;

void solve(){             
	cin >> n >> k;

	int x = n / k;
	x *= k;
	x = n - x;

	ans = x;
	ans = min(abs(x - k), ans);

	cout << ans;
}                              
      
main(){
    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

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

int main() {
  string N;
  cin >> N;
  int f = 0, num;
  rep(i,N.size()) f += (N.at(i) - '0');
  num = atoi(N.c_str());
  if(num % f == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define M 1000000
using namespace std;

//vector<ll> ;

void answer(){
    ll n,m=0,ans=0,x;
    cin>>n>>m>>x;
    swap(n,m);
    swap(n,x);
    cout<<n<<" "<<m<<" "<<" "<<x;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int q;
    //cin>>q; while(q--)
        answer();
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

N, M, Q = map(int, input().split())
D = [[0]*N for i in range(N)]
E = [[-1]*N for i in range(N)]

for i in range(M):
    l, r = map(int, input().split())
    D[l-1][r-1] += 1

def dfs(l, r):
    if not l <= r:
        return 0
    if l == r:
        return D[l][r]
    if E[l][r] != -1:
        return E[l][r]
    E[l][r] = res = D[l][r] + dfs(l+1, r) + dfs(l, r-1) - dfs(l+1, r-1)
    return res

ans = []
for i in range(Q):
    p, q = map(int, input().split())
    ans.append(dfs(p-1, q-1))
print(*ans, sep='\n')


Measured memory_bytes: 14292
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define vi vector < ll  int >
#define CLR(a) memset((a),0,sizeof(a))
#define mp make_pair
#define hell 1000000007
using namespace std;
ll dist[1001][1001];
void solve()
{
 ll i,j=0,r=200,p,q,k=0,d,y=0,n,h=100000000000000,flag=0,m=0,a=hell,b=hell,id,h1,h2,a1,b1,a2,w,x,u,f,l,c=0,e,ans=0;
 cin>>n;
 i=n;
 while(true)
 {  bool ff=0;
     for(j=2;j*j<=i;j++)
     {
         if(i%j==0) ff=1;
     }
     if(!ff) {cout<<i; return;} i++;
 }



}



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

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define ll long long 
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(void){
    ll n ;
    cin >> n ;
    ll a[n] , b[n - 1] ;
    ll all=0;
    rep(i , n -1){
        cin >> b[i] ;
    }
    
    all += b[0];
    all += b[n-2];
    for(int i=1;i<=n-2;i++){
        all += min(b[i-1],b[i]);
    }
  
  cout << all << endl;



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
#include <stdio.h>

int main(void){
  int x;
  std::cin >> x;
  if(x>=30){
    std::cout << "Yes";
  }else{
    std::cout << "No";
  }
}

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

using namespace std;

struct tree
{
    int x, y;
    int size;
    long long sum = 0;
    tree *l, *r;

    tree(int _x) {
        x = _x;
        y = rand();
        l = r = 0;
        size = 1;
        sum = x;
    }
};

typedef tree *ptree;

inline int si(ptree r)
{
    return r ? r->size : 0;
}

inline long long sum(ptree r) {
    return r ? r->sum : 0ll;
}

inline void update(ptree r)
{
    if (!r) {
        return;
    }
    r->size = si(r->l) + si(r->r) + 1;
    r->sum = sum(r->l) + sum(r->r) + r->x;
}

ptree merge(ptree l, ptree r)
{
    if (!l) {
        return r;
    }
    if (!r) {
        return l;
    }
    if (l->y > r->y) {
        l->r = merge(l->r, r);
        update(l);
        return l;
    } else {
        r->l = merge(l, r->l);
        update(r);
        return r;
    }
}

void split(ptree root, ptree &l, ptree &r, int key)
{
    if (!root) {
        return (void)(l = r = 0);
    }

    if (root->x > key) {
        split(root->l, l, root->l, key);
        r = root;
    } else {
        split(root->r, root->r, r, key);
        l = root;
    }
    update(l);
    update(r);
}

inline void add_to_tree(ptree &root, int x)
{
    ptree l, r;
    split(root, l, r, x);
    root = merge(l, merge(new tree(x), r));
}


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

    int n;

    vector<long long> a;
    cin >> n;
    a.resize(n);
    vector<long long> result(n, 0);

    vector<long long> b_l, b_r;
    vector<bool> check_p;

    int cur_max = 0;
    int prev_max = 0;
    b_l.resize(n);
    b_r.resize(n);
    check_p.assign(n, false);
    for (int i = 0; i < a.size(); i++) {
        cin >> a[i];
        if (a[i] > cur_max) {
            prev_max = cur_max;
            cur_max = a[i];
            check_p[i] = true;
        }
        b_l[i] = prev_max;
        b_r[i] = cur_max;
    }

    ptree root = 0;
    for (int i = n - 1; i >= 0; i--) {
        add_to_tree(root, a[i]);

        if (check_p[i]) {
            ptree l1, r1, l2, r2;
            split(root, l1, r1, b_l[i]);
            split(r1, l2, r2, b_r[i]);

            result[i] += sum(l2) - b_l[i] * si(l2);
            result[i] += (b_r[i] - b_l[i]) * si(r2);

            root = merge(l1, merge(l2, r2));
        }
    }

    for (int i = 0; i < n; i++) {
        cout << result[i] << '\n';
    }
}


Measured memory_bytes: 8960
# Vector 2018/06/02
# job hunting (*_*)

class Vector(object):
    def __init__(self):
        self.A = list()

    def pushBack(self, x):
        self.A.append(x)

    def randomAccess(self, p):
        print self.A[p]

    def popBack(self):
        del self.A[-1]

A = Vector()
q = int(raw_input())
for i in range(q):
    line = [int(i) for i in raw_input().split()]
    if line[0] == 0:
        A.pushBack(line[1])
    elif line[0] == 1:
        A.randomAccess(line[1])
    else:
        A.popBack()


Measured memory_bytes: 17244
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
char s[110], t[110];
int n;
int main(){
	scanf("%s%s", s + 1, t + 1);
	int n = strlen(s + 1);
	for(int i = 1; i <= n; ++i){
		bool flag = 1;
		for(int j = 1; j <= n; ++j) if(s[j] != t[j]) flag = 0;
		if(flag) return puts("Yes") & 0;
		char ch = s[n];
		for(int j = n - 1; j >= 1; --j) s[j + 1] = s[j];
		s[1] = ch;
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void)
{
    int n;
    int now, start, end;
    int i, j;
    char input[2000];
    char train[1000];

    scanf("%d", &n);

    for (i = 0; i < n; i++){
        scanf("%s", input);

        now = 500;
        start = 500;
        end = 500;
        
        for (j = 0; ; j += 3){
            train[now] = input[j];
            
            if (input[j + 1] == '\0'){
                break;
            }
            
            if (input[j + 1] == '-'){
                now++;
            }
            else {
                now--;
            }

            if (now < start){
                start = now;
            }
            if (now > end){
                end = now;
            }
        }

        for (j = start; j <= end; j++){
            printf("%c", train[j]);
        }
        
        printf("\n");

    }

    return 0;
}
        

Measured memory_bytes: 0
#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 main()
{
	int a, b;
	char op;
	cin >> a >> op >> b;

	if (op == '+') cout << a + b << endl;
	else cout << a - b << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define eb emplace_back
const int nax = 405;
const lli INF = 1e18L + 5; // 10^18+5
lli dp[nax][nax];
// dp[i][j] - the minimum total cost of combining interval [i,j] into one vertex

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for(int& x : a) {
        scanf("%d", &x);
    }
    auto sum = [&](int L, int R) {
        lli s = 0;
        for(int i = L; i <= R; ++i) {
            s += a[i];
        }
        return s;
    };
    for(int L = n - 1; L >= 0; --L) {
        for(int R = L; R < n; ++R) {
            if(L == R) {
                dp[L][R] = 0;
            }
            else {
                dp[L][R] = INF;
                lli s = sum(L, R);
                for(int i = L; i <= R - 1; ++i) {
                    dp[L][R] = min(dp[L][R], dp[L][i] + dp[i+1][R] + s);
                }
            }
        }
    }
    //int i,j;
    //for(i=0;i<n;i++)
    //{
    //    printf("\n");
    //    for(j=0;j<n;j++)
            printf("%lld\t",dp[0][n-1]);
    //}
}


Measured memory_bytes: 1536
#include <iostream>
using namespace std;
#define mod 1000000007
#define int long long int
int power(int a, int b)
{
    int res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % mod;
        b /= 2;
        a = (a * a) % mod;
    }
    return res;
}
int inv(int num)
{
    return power(num, mod - 2);
}
int ncr(int n, int r)
{
    int ans = 1;
    int divide = 1;
    if (r > (n - r))
        r = n - r;
    for (int i = 0; i < r; i++)
        ans = (ans * (n - i)) % mod;
    for (int i = 1; i <= r; i++)
        divide = (divide * i) % mod;
    return (ans * inv(divide)) % mod;
}
signed main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int ans = power(2, n);
    ans--;
    ans = (ans - ncr(n, a) + mod) % mod;
    ans = (ans - ncr(n, b) + mod) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        v.push_back(x);
    }
    int q;
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        int k;
        cin >> k;
        auto it1 = lower_bound(v.begin(), v.end(), k);
        auto it2 = upper_bound(v.begin(), v.end(), k);
        cout << it1 - v.begin() << " " << it2 - v.begin() << endl;
    }
    return 0;
}




Measured memory_bytes: 3572
package main

import (
	"fmt"
)

var debug = false

func main() {
	var a, b, c, x int
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)
	fmt.Scanf("%d", &c)
	fmt.Scanf("%d", &x)
	res := GetAnswer(a, b, c, x)
	fmt.Printf("%v\n", res)
}

// GetAnswer ...
func GetAnswer(a, b, c, x int) int {
	prt("inputs: a:%d, b:%d, c:%d, x:%d\n", a, b, c, x)
	a500 := a
	if 500*a > x {
		a500 = x / 500
	}
	b100 := b
	if 100*b > x {
		b100 = x / 100
	}
	c50 := c
	if 50*c > x {
		c50 = x / 50
	}
	result := 0
	for i := 0; i <= a500; i++ {
		for j := 0; j <= b100; j++ {
			for k := 0; k <= c50; k++ {
				total := (500 * i) + (100 * j) + (50 * k)
				prt("loop count a:%d b:%d c:%d total:%d\n", i, j, k, total)
				if total == x {
					result++
				}
			}
		}
	}
	prt("%v\n", result)
	return result
}

func prt(format string, inputs ...interface{}) {
	if debug {
		fmt.Printf(format, inputs...)
	}
}

Measured memory_bytes: 3968
import io.{StdIn => in}

object Main extends App {
  val Array(n, m, x, y) = in.readLine.split(" ").map(_.toInt)
  val xi = in.readLine.split(" ").map(_.toInt).max
  val yi = in.readLine.split(" ").map(_.toInt).min

  val z = yi
  val ans = if(x<z && xi < z && z < y) "No War" else "War"
  println(ans)
}


Measured memory_bytes: 25660
import collections
import sys
N=int(input())
S=[input() for i in range(N)]
c = collections.Counter(S).most_common()
c.sort()
c.sort(key=lambda c:c[1],reverse=True)
max_count=c[0][1]
for _ in c:
  if _[1]==max_count:
    print(_[0])
  else:
    sys.exit()


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

int main() {
  
  int n;
  string s;
  cin >> n >> s;
  int tmp = 0;
  for(int i = 1; i < n; i++) {
    int t = i - 1;
    if(s.at(t) == s.at(i)) {
      tmp++;
    }
  }
  int ans = s.size() - tmp;
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int n, W;
int w[110], v[110];
long long dp[100100];

long long max(long long a, long long b) {
    return (a > b ? a : b);
}

int main() {
    scanf("%d%d", &n, &W);
    for (int i = 0; i < n; i++) scanf("%d%d", &w[i], &v[i]);

    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = W; j >= w[i]; j--) {
            dp[j] = max(dp[j], dp[j - w[i]] + 1ll * v[i]);
        }
    }

    long long ans = 0;
    for (int i = 0; i <= W; i++) ans = max(ans, dp[i]);
    printf("%lld\n", ans);
}

Measured memory_bytes: 1024
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// solution 
use std::cmp;
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        Y: usize,
    }

    for man in 0..N+1 {
        for gosen in 0..(N-man)+1 {
            let sen = N-man-gosen;
            if 10000*man + 5000*gosen + 1000*sen == Y {
                    println!("{} {} {}", man, gosen, sen);
                    return
            }
        }
    }
    println!("-1 -1 -1");
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
     
    #define REP(i,num) for(int i=0;i<(num);++i)
     
    using namespace std;
    using ll = long long;
     
    template<typename T=int>
    T in(){T x; cin >> x; return (x);}
     
    int main(){
      cin.tie(0);
      ios::sync_with_stdio(false);
     
      int N=in();
      vector<ll> A(N);
      REP(i,N) A[i]=in();
      
      vector<array<ll,2>> dp(N+1);
      dp[0][0]=0;
      dp[0][1]=-1e12;
      for(int i=0;i<N;i++){
        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: 2560
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        while(!isPrime(n)) {
        	n++;
        }
        System.out.println(n);
    }

    private static boolean isPrime(int n) {
    	if(n <= 1) return false;
    	for(int i = 2; i * i <= n; i++) {
    		if(n % i == 0)
    			return false;
    	}
    	return true;
    }
}


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

int cnt[233];

int main(){
	char s[5];cin>>s;
	for(int i=0;s[i];++i)cnt[s[i]]++;
	for(char c='A';c<='Z';++c)
	if(cnt[c]==1||cnt[c]==4){
		cout<<"No";
		return 0;
	}
	cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void xin(){
	#ifndef ONLINE_JUDGE 
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}
int f[100005];


int main()
{
  	xin();
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n;
    cin>>n;
    vector<int> v(n+1);
    for(int i=1;i<=100;i++)
    {
    	for(int j=1;j<=100;j++)
    	{
    		for(int k=1;k<=100;k++)
    		{
    			int temp = i*i + j*j + k*k + j*k + k*i + i*j;
    			if(temp <n+1)
    				v[temp]++;

    		}
    	}
    }
    for(int i=1;i<=n;i++)
    	cout<<v[i]<<endl;

   
 
 }

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VL vector<LL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    /*
    int t,n;
    cin>>t;
    loop(t1,1,t+1)
    {
        int a[n];
        loop(i,0,n) cin>>a[i];
    }
    */

    int h1,h2,m1,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    //VI a(n);
    //loop(i,0,n) cin>>a[i];

    int tot;
    if(h1 == h2) tot = m2 - m1;
    else
    {
        tot = 60 - m1;
        ++h1;
        tot += (h2 - h1) * 60;
        tot += (m2 + 60) % 60;
    }

    int ans = tot - k;

    cout<<ans<<'\n';

    /*
    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
  int key;
  struct node *p, *l, *r;
}T_node;
T_node *rt;
void n_insert(T_node *, int);
void n_print(T_node *);
void preo(T_node *);
void ino(T_node *);
void psto(T_node *);
int main(){
  int n;
  scanf("%d", &n);
  char *buf;
  buf = (char *)malloc(sizeof(char) * 256);
  int key;
  rt = NULL;
  int i;
  for(i = n - 1; i >= 0; i--){
    scanf("%s", buf);
    if(!strcmp(buf, "insert")){
      scanf("%d", &key);
      n_insert(rt, key);
    }
    else if(!strcmp(buf, "print"))
      n_print(rt);
  }
  //free(buf);
  return 0;
}

void n_insert(T_node *x, int key){
  T_node *y;
  y = NULL;
  while(x != NULL){
    y = x;
    if(key < x->key)
      x = x->l;
    else
      x = x->r;
  }
  T_node *new;
  new = (T_node *)malloc(sizeof(T_node));
  new->p = x;
  new->key = key;
  new->l = NULL;
  new->r = NULL;
  
  if(y == NULL)
    rt = new;
  else if(key < y->key)
    y->l = new;
  else
    y->r = new;
}

void n_print(T_node *rt){
  if(rt != NULL){
    ino(rt);
    printf("\n");
    preo(rt);
    printf("\n");
  }
}

void preo(T_node *t){
  printf(" %d", t->key);
  if(t->l != NULL)
    preo(t->l);
  if(t->r != NULL)
    preo(t->r);
}
void ino(T_node *t){
  if(t->l != NULL)
    ino(t->l);
  printf(" %d", t->key);
  if(t->r != NULL)
    ino(t->r);
}
void psto(T_node *t){
  if(t->l != NULL)
    psto(t->l);
  if(t->r != NULL)
    psto(t->r);
  printf(" %d", t->key);
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int H, W; scanf("%d %d", &H, &W);
  vector<string> B(H);
  int whites = 0;
  for (int i = 0; i < H; ++i) {
    cin >> B[i];
    whites += count(B[i].begin(), B[i].end(), '.');
  }

  vector<vector<int>> seen(H, vector<int>(W, 0));
  queue<pair<int, pair<int, int>>> que;
  que.push(make_pair(1, make_pair(0, 0)));
  int dist = -1;
  while (not que.empty()) {
    pair<int, pair<int, int>> p = que.front(); que.pop();
    int d = p.first;
    int r = p.second.first, c = p.second.second;
    if (r == H - 1 and c == W - 1) {
      dist = d;
      break;
    }
    for (int dr = -1; dr <= 1; ++dr) {
      for (int dc = -1; dc <= 1; ++dc) {
        if (abs(dr) + abs(dc) != 1) { continue; }
        int nr = r + dr, nc = c + dc;
        if (0 <= nr and nr < H and 0 <= nc and nc < W and
            (not seen[nr][nc]) and B[nr][nc] == '.') {
          seen[nr][nc] = 1;
          que.push(make_pair(d + 1, make_pair(nr, nc)));
        }
      }
    }
  }
  int ans = (dist == -1) ? -1 : whites - dist;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 51
using namespace std;
int h,w,p=0;
string A,mp[N];
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
int x,y,dir;
void start();

void Forward(){
  int nx = x+dx[dir],ny = y+dy[dir];
  if(nx>=0&&ny>=0&&nx<w&&ny<h&&mp[ny][nx]!='#') x=nx,y=ny;
}
 
void Back(){
  int nx = x+dx[(dir+2)%4],ny = y+dy[(dir+2)%4];
  if(nx>=0&&ny>=0&&nx<w&&ny<h&&mp[ny][nx]!='#') x=nx,y=ny;
}
 
void getIdx(){
  char ch = A[p];
  int cnt=0;
  while(1){
    if(ch=='{')cnt+=(A[p]=='{')-(A[p]=='}');
    if(ch=='[')cnt+=(A[p]=='[')-(A[p]==']');
    p++;
    if(cnt==0) return;
  } 
}

bool kabe(){
  int nx = x+dx[dir],ny = y+dy[dir];
  if(nx<0||ny<0||nx>=w||ny>=h) return 1;
  return mp[ny][nx] == '#';
}
 
int getCheck(){
  char P = A[p];
  if(P=='N')return dir == 0;
  if(P=='E')return dir == 1;
  if(P=='S')return dir == 2;
  if(P=='W')return dir == 3;
  if(P=='C')return kabe();
  if(P=='T')return 1;
}

void While(){
  int sp = p;
  int f = A[++p]=='~';p+=f;
  int l = p;
  while(1){
    bool con = getCheck();p++;
    if(f) con = !con;
    if(con==0) break;
    start();
    p = l;
  }
  p = sp;
  getIdx();
}
 
void If(){
  assert(A[p]=='[');
  int sp = p;
  int f = A[++p]=='~';p+=f;
  bool con = getCheck();p++;
  if(f) con = !con;
  if(con) start();
  p = sp;
  getIdx();
}
 
int ans,cnt;
void start(){
  while(1){
    if(cnt++>1e7)cout<<-1<<endl,exit(0);
    char P = A[p];
    if(P == '{') While();      
    else if(P == '[')If();
    else if(P =='^'||P=='v'){
      (P=='^')? Forward():Back(),ans++,p++;
      if(mp[y][x] == 'g')cout<<ans<<endl,exit(0);
    }
    else if(P=='<'||P=='>') dir=(P=='>')?(dir+1)%4:(dir+3)%4,ans++,p++;
    else return;
  }
}
 
int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++)cin>>mp[i];
  cin>>A;

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++) if(mp[i][j] == 's')y = i,x = j;

  start();
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a) for (int i = 0; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 300;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    vi a(n);
    in(a);

    vi dp(n, INF);
    dp[0] = 0;

    for (int j = 1; j < n; ++j) {
        for (int i = 1; i <= k && j - i >= 0; ++i) {
            dp[j] = min(dp[j], dp[j - i] + abs(a[j - i] - a[j]));
        }
    }

    cout << dp[n - 1];
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    int ans = 3*n*n;
    
    cout << ans << endl;  
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc134.contest.atcoder.jp/tasks/abc134_b

Measured memory_bytes: 256
#include<bits/stdc++.h>
int n,p,f[6003][9003],ans;
int main(){
	std::cin>>n>>p;
	f[0][3*n]=1;
	for(int i=0;i<3*n;i++)for(int j=0;j<=4*n;j++){
		(f[i+1][j-1]+=f[i][j])%=p;
		(f[i+2][j+1]+=1ll*f[i][j]*(i+1)%p)%=p;
		(f[i+3][j]+=1ll*f[i][j]*(i+1)%p*(i+2)%p)%=p;
	}
	for(int j=0;j<=3*n;j++)(ans+=f[3*n][j])%=p;
	std::cout<<ans<<std::endl;
}

Measured memory_bytes: 211456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n) cin>>a[i];
    int ans[n];
    for(int i=n-1;i>=0;i--){
        int tmp=0;
        for(int j=i+i+1;j<n;j+=i+1){
            tmp+=ans[j];
        }
        if(a[i]==0){
            if(tmp%2==0) ans[i]=0;
            else ans[i]=1;
        }
        else{
            if(tmp%2==0) ans[i]=1;
            else ans[i]=0;
        }
    }
    vector<int> res;
    rep(i,n){
        if(ans[i]==1) res.push_back(i+1);
    }
 
    cout<<res.size()<<endl;
    rep(i,res.size()){
        cout<<res[i]<<endl;
    }
}


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

int n, m, q;
vector<vector<int>> test;

void DFS(vector<int> &t){
    int size = t.size();
    if(size == n) test.push_back(t);
    else{
        for(int i=t[size-1]; i<=m; i++){
            vector<int> u = t;
            u.push_back(i);
            DFS(u);
        }
    }
    return ;
}

int main(){
    cin >> n >> m >> q;

    vector<int> a(q), b(q), c(q), d(q);
    for(int i=0; i<q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i] -= 1;
        b[i] -= 1;
    }

    for(int i=1; i<=m; i++){
        vector<int> init = {i};
        DFS(init);
    }

    int ans = 0;
    for(auto t : test){
        //for(int i=0; i<n; i++) cout << t[i] << " ";
        //cout << endl;

        int score = 0;
        for(int i=0; i<q; i++){
            if(t[b[i]] - t[a[i]] == c[i]) score += d[i];
        }
        ans = max(ans, score);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9868
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
struct node{
	int x,y;
	long long t;
}f[N];
int n;
inline bool mycmp(node x,node y) {return x.t>y.t;}
inline int read()
{
	int Num=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9') {Num=(Num<<1)+(Num<<3)+ch-'0'; ch=getchar();}
	return Num*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		f[i].x=read(),f[i].y=read();
		f[i].t=f[i].x+f[i].y;
	}
	sort(f+1,f+1+n,mycmp);
	long long ans=(long long)abs(f[1].x-f[n].x)+abs(f[1].y-f[n].y);
	for(int i=1;i<=n;i++)
	{
		f[i].x=abs(f[i].x-1000000000);f[i].t=f[i].x+f[i].y;
	}
	sort(f+1,f+1+n,mycmp);
	 ans=max((long long)abs(f[1].x-f[n].x)+abs(f[1].y-f[n].y),ans);
	printf("%lld",ans);
	return 0;
}

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

int main(){
  long long a,d,c;
  cin >> a >> d >> c;
  a = abs(a);
  long long step = min(d,a/c);
  d -= step;
  a -= step*c;
  if (d%2==0)cout << a << endl;
  else cout << c-a << endl;
}

Measured memory_bytes: 3644
N = int(input())
Ai = list(map(int,input().split()))
Aisort = sorted(Ai) + [-1]
Aidic = {}
cnt = 1
for i in range(1,N+1):
    if Aisort[i] != Aisort[i-1]:
        Aidic.update([(str(Aisort[i-1]), cnt)])
        cnt = 1
    else:
        cnt = cnt + 1

cnt = 0
for i, indx in enumerate(Aidic):
    num = int(Aidic[indx])
    cnt = cnt + num*(num-1)//2


for A in Ai:
    num = int(Aidic[str(A)])
    num = cnt - (num-1)
    print(num)

Measured memory_bytes: 30544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  cin >> A >> B;
  
  /*
  10000 < A <= B <= 99999
  count kaibun int number between A and B  
  */
  int count = 0;
  int num;
  for (int i=0; i < B - A +1; i++) {
    num = A + i;
    if (num/10000 == num%10 && num%10000/1000 == num%100/10) 
        count++;
	
  }
  cout << count << endl;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  
  cout << d.at(N/2) - d.at(N/2 - 1) << endl;
  
  return 0;
}

Measured memory_bytes: 640
/* Coached by rainboy */
#include <stdio.h>

#define K 2000
#define N 2000
#define MD 1000000007

int main() {
	static int choose[N + 1][N + 1];
	int n, k, i, j;

	scanf("%d%d", &n, &k);
	choose[0][0] = 1;
	for (i = 1; i <= n; i++) {
		choose[i][0] = 1;
		for (j = 1; j <= i; j++)
			choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % MD;
	}
	for (i = 1; i <= k; i++)
		printf("%lld\n", (long long) choose[n - k + 1][i] * choose[k - 1][i - 1] % MD);
	return 0;
}


Measured memory_bytes: 14976
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

int main(){
  int N;
  VI v;

  cin >> N;

  REP(i, 0, N){
    int t;
    cin >> t;
    v.push_back(t-1);
  }

  VI a(N);
  VI b(N);
  REP(i, 0, N){
    a[i] = i * (N+1) + N + 1;
    b[N-i-1] = i * (N+1) + N + 1;
  }

  int cnt = N;
  REP(i, 0, N){
    int index = v[i];
    a[index] -= cnt;
    cnt--;
  }

  REP(i, 0, N){
    cout << a[i] << " ";
  }
  cout << endl;
  REP(i, 0, N){
    cout << b[i] << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int main()
{
	int n;
	int beft=0, befx=0, befy=0;
	read(n);
	for(;n--;){
		int t, x, y; read(t, x, y);
		if((befx+befy+x+y)%2 == (beft+t)%2 && abs(befx-x)+abs(befy-y) <= t-beft){
			beft=t;
			befx=x;
			befy=y;
		} else {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M, Q = map(int, input().split())
    lines = np.zeros((N + 1, N + 1)).astype(np.int32)

    for _ in range(M):
        l, r = map(int, input().split())
        lines[l, r] += 1

    lines = np.cumsum(lines, axis=0)
    lines = np.cumsum(lines, axis=1)

    for _ in range(Q):
        p, q = map(int, input().split())
        # 終点がq以下のものの総数から，始点がp-1以下で終点がq以下のものをひく
        print(lines[-1][q] - lines[p - 1][q])


if __name__ == "__main__":
    main()


Measured memory_bytes: 18652
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int R = 1, B = 2, Y = 3;

long long n, a, b;
int k;

int main()
{
    cin >> n >> k;
    REP(k)
    {
        cin >> a >> b;
        a = min(a, n + 1 - a);
        b = min(b, n + 1 - b);

        //cout << "a:" << a << " b:" << b << endl;
        int c = (int)(min(a, b) % 3);
        if(c == 0) cout << Y << endl;
        else cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main() {
    int cnt = 0;

    int N;
    scanf("%d", &N);
    int a[N], b[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &a[i]);
        b[i] = 0;
    }
    
    int x = 0;
    while (1) {
        if (x == 1) {
            break;
        }
        if (b[x]) {
            cnt = -1;
            break;
        }
        cnt++;
        b[x] = 1;
        x = a[x] - 1;
    }
    
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 896
#include<stdio.h>

int main()
{
  int n = 0;
  int m = 0;
  int sol = 0;
  scanf("%d %d",&n,&m);
  
  if(n >= 2)
  {
    sol += n*(n-1)/2;
  }
  
  if(m >= 2)
  {
        sol += m*(m-1)/2;
  }
  
  printf("%d",sol);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int MOD = (int) 1e9 + 7;

void sadd(int &a, int b)
{
    a += b;
    if (a >= MOD)
        a -= MOD;
}
int add(int a, int b)
{
    sadd(a, b);
    return a;
}
void ssub(int &a, int b)
{
    a -= b;
    if (a < 0)
        a += MOD;
}
int sub(int a, int b)
{
    ssub(a, b);
    return a;
}
int mul(int a, int b)
{
    return (a * 1LL * b) % MOD;
}


const int N = 2005;
const int X = N * N;

int fact[X], ri[X], rfact[X];

void init()
{
    ri[1] = 1;
    fact[0] = 1;
    rfact[0] = 1;

    for (int i = 1; i < X; i++)
    {
        if (i != 1)
            ri[i] = sub(0, mul(ri[MOD % i], MOD / i));
        fact[i] = mul(fact[i - 1], i);
        rfact[i] = mul(rfact[i - 1], ri[i]);
    }
}

int C(int n, int k)
{
    //eprintf("get C : %d %d\n", n, k);
    if (k < 0 || k > n)
        return 0;
    return mul(fact[n], mul(rfact[k],rfact[n - k]));
}

int dp[N][N];

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

    init();

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

    if (k == 1)
    {
        printf("1\n");
        return 0;
    }

    dp[0][0] = 1;
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= i; j++)
        {
            int cur = dp[i][j];
      //      eprintf("i = %d, j = %d : %d\n", i, j, dp[i][j]);

            if (i < n)
            {
                int cnt = (i + 1) * (k - 1) + j;
                int nx = mul(cur, C(cnt - 1, k - 2));
                sadd(dp[i + 1][j], nx);
            }
            if (j < i)
            {
                sadd(dp[i][j + 1], cur);
            }
        }
    printf("%d\n", mul(dp[n][n], fact[n]));



	return 0;
}




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

int GCD(int a, int b)
{
	if(b == 0)
	{
		return a;
	}
	
	return GCD(b, a % b);
}

int LCM(int a, int b)
{
	return a * b / GCD(a, b);
}

int main()
{
	int N, num[128], lcm;
	cin >> N;
	for(int i = 0; i < N; ++i)
	{
		cin >> num[i];
		
		if(i == 0)
		{
			lcm = num[i];
		}
		else
		{
			lcm = LCM(lcm, num[i]);
		}
	}
	
	cout << lcm << endl;

    return 0;
}



Measured memory_bytes: 3104
package main

import (
	"fmt"
)

func main() {
	var d, t, s int
	fmt.Scan(&d, &t, &s)
	if s*t >= d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1768
from itertools import permutations as perms

n = int(input().strip())
xys = [tuple(map(int, input().split())) for _ in range(n)]
lis = [i for i in range(n)]

numerator = 0
denominator = 0
for elem in perms(lis, n):
    denominator += 1
    for i in range(len(elem) - 1):
        numerator += ((xys[elem[i + 1]][0] - xys[elem[i]][0]) ** 2 + (xys[elem[i + 1]][1] - xys[elem[i]][1]) ** 2) ** (1 / 2)
print(numerator / denominator)


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

using namespace std;

typedef long long ll;

int main()
{
    string str;
    ll wcnt = 0;
    ll bcnt = 0;
    ll ans = 0;

    cin >> str;

    for (ll i = 0; i < str.size(); i++) {
        if (str[i] == 'B') {
            bcnt++;
        } else {
            wcnt++;
            ans += bcnt;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
import fractions

a, b = map(int, input().split())
m = fractions.gcd(a,b)

pf={}
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
print(len(pf) + 1)

Measured memory_bytes: 5304
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#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 ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  while(true){
    vector<string> s;
    while(true){
      string tmp;
      getline(cin,tmp);
      s.push_back(tmp);
      if(tmp[tmp.size()-1] == '.')break;
    }
    //    REP(i,s.size())
    //    cout << s[i] <<endl;
    if(s.size()==1&&s[0][0]=='.')break;
    stack<int> st;
    bool is_theory = true;
    REP(i,s.size()){
      REP(j,s[i].size()){
	if(s[i][j] == '(')st.push(1);
	if(s[i][j] == '[')st.push(-1);
      if(s[i][j] == ')')
	if(!st.empty() && st.top() == 1)st.pop();
	else {is_theory = false;break;}
      if(s[i][j] == ']')
	if(!st.empty() && st.top() == -1)st.pop();
	else {is_theory = false;break;}
      }
    }
    if(is_theory && st.empty())cout << "yes" << endl;
    else cout << "no" << endl;
  }
	

  return 0;
}

Measured memory_bytes: 3132
// Ivan Carvalho
// Problem E - Educational Dynamic Programming Contest - AtCoder
// Link : https://atcoder.jp/contests/dp
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;

ll dp[MAXV];
int N,W,V,wi[MAXN],vi[MAXN];

int main(){

	cin >> N >> W;
	for(int i = 1;i<=N;i++){
		cin >> wi[i] >> vi[i];
		V += vi[i];
	}

	for(int i = 1;i<=V;i++) dp[i] = INF;
	dp[0] = 0;
	
	for(int item = 1;item<=N;item++){
		int w = wi[item], v = vi[item];
		for(int i = V;i>=v;i--){
			dp[i] = min(dp[i],dp[i - v] + w);
		}
	}

	for(int i = V;i>=0;i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}

	return 0;

}

Measured memory_bytes: 4384
import numpy as np


def solve(N, M, py):
    ans = np.zeros(M, dtype=object)
    rank = [1]*(N+1)

    py.sort()

    for pyi in py:
        pi = pyi[1]
        ans[pyi[2]] = str(pi).zfill(6) + str(rank[pi]).zfill(6)
        rank[pi] += 1

    return ans


if __name__ == "__main__":
    _p, _y = 0, 0
    py = []

    N, M = map(int, input().split())
    for i in range(M):
        _p, _y = map(int, input().split())
        py.append((_y, _p, i))

    ans = solve(N, M, py)
    for a in ans:
        print(a)


Measured memory_bytes: 46476
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    string p[1];
    for(int i=0;i<s.length()+1;i++){
        s=s.back()+s.substr(0,s.length()-1);
        if(s==t){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256