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

#define endl '\n'
#define int long long

const int N = 1e5 + 9;
int n, k;
int memo[N], h[N];

int dp(int id) {
	if(id >= n) return 1e9;
	if(id == n - 1) return 0;
	int &ans = memo[id];
	if(ans != -1) return ans;
	ans = 1e9;
	for(int i = 1; i <= k and i + id <= n; i ++)
	ans = min(dp(id + i) + abs(h[id + i] - h[id]), ans);
	return ans;
}

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

	memset(memo, -1, sizeof memo);
	cin >> n >> k;
	for(int i = 0; i < n; i ++) cin >> h[i];
	cout << dp(0) << endl;


	return 0;
}

Measured memory_bytes: 9828
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin >> a >> b >> k;
  int cnt = 0;
  for (int i=min(a,b);i>=1;i--)
    if (a % i == 0 && b % i == 0){
      cnt ++;
      if (cnt == k) cout << i << endl;
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5;
ll dp[N];
int dis[N];
const ll oo=2e18;
struct node{
	ll v;
	int x;
	node(){}
	node(ll vv,int xx){
		v=vv;x=xx;}
	bool operator <(const node &b)const{
		return v>b.v;}
};
priority_queue<node> Dui;
int main(){
	dp[0]=0;
	int n,e,t;
	scanf("%d%d%d",&n,&e,&t);
	for (int i=1;i<=n;i++) scanf("%d",&dis[i]);
	int l=0;
	Dui.push(node(dp[0],0));
	ll nowmin=oo;
	for (int i=1;i<=n;i++)
	{
		while (((dis[i]-dis[l+1])*2)>=t)
		{
			l++;
			nowmin=min(dp[l-1]-2*dis[l],nowmin);
		}
	//	printf("%d %d %lld\n",i,l,nowmin);
		dp[i]=nowmin+2*dis[i];
		if (!Dui.empty())
		{
			node P=Dui.top();
			while (!Dui.empty() && P.x<l)
			{
				Dui.pop();
				P=Dui.top();
			}		
			if (!Dui.empty())
				dp[i]=min(dp[i],P.v+t);
		}
		Dui.push(node(dp[i],i));
	}/*
	for (int i=1;i<=n;i++)
		printf("%lld ",dp[i]);
	printf("\n");*/
	printf("%lld\n",e+dp[n]);
}
		
		
		
		
		
		
		
		
		
		
		

Measured memory_bytes: 6232
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int n,m,c,A[30][30],B[30];
  cin >> n >> m >> c;

  for(int i = 0; i < m; i++) 
    cin >> B[i];
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++)
      cin >> A[i][j];
  }

  int num = 0;
  for(int i = 0; i < n; i++) {
    int sum = 0;
    for(int j = 0; j < m; j++)
      sum += A[i][j]*B[j];
    if(sum + c > 0) num++;
  }

  cout << num << endl; 
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define il inline
#define Max 3005
#define int long long
#define Mod 1000000007
using namespace std;
il int read()
{
	char c=getchar();
	int x=0,f=1;
	while(c>'9'||c<'0')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
char s[Max];
int n,m,r[Max],l[Max],cnt;
int f[Max][Max];
signed main()
{
	n=read(),m=read();
	scanf("%s",s+1);
	for(int i=1;i<=n+1;i++)
	{
		l[i]=l[i-1]+(s[i]=='1');
		r[i]=i;
		cnt+=(s[i]=='1');
	}
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		r[x]=max(y,r[x]);
	}
	for(int i=1;i<=n;i++) r[i]=max(r[i],r[i-1]);
	f[1][l[r[1]]]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(f[i][j])
			{
				int a=l[r[i]],b=l[r[i+1]];
				if(r[i]-i+1-j) (f[i+1][j+b-a]+=f[i][j])%=Mod;//,puts("qwq1");
				if(j) (f[i+1][j+b-a-1]+=f[i][j])%=Mod;//,puts("qwq2");
				//cout<<i<<' '<<j<<endl;
			}
		}
	}
	cout<<(f[n+1][0]+Mod)%Mod<<endl;
}

Measured memory_bytes: 68352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define mp  make_pair
int main(){
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	int D,G;
	cin>>D>>G;
	pii arr[D];
	for(int i=0;i<D;++i){
		ll a,b;
		cin>>a>>b;
		arr[i]=mp(a,b);
	}
	int ans=2000;
	for(int i=0;i<(1<<D);++i){
		int score=0,temp=0;
		for(int j=0;j<D;++j){
			if(((i>>j)&1)!=0){
				score+=(j+1)*100*arr[j].first+arr[j].second;
				temp+=arr[j].first;

			}
		}
		// cout<<score<<" "<<temp<<":";
		if(score<G){
			for(int j=D-1;j>=0;--j){
				int used=0;
				// cout<<((i>>j)&1)<<" "<<i<<","<<j<<" ";
				if(((i>>j)&1)==0){
					while(score<G&&used<arr[j].first){
						score+=(j+1)*100;
						used++;
					}
					temp+=used;
					if(used==arr[j].first){
						score+=arr[j].second;
					}
					else{
						break;
					}
					// cout<<score<<endl;
				}
			}
			// cout<<score<<" "<<G<<endl;
		}
		// cout<<":"<<score<<" "<<temp<<endl;
		ans=min(temp,ans);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int INF=1e9;
int n;
int t[301][301];
int u[301][301];
 
int sum(int ai,int aj,int bi,int bj){
  ai--,aj--;
  return u[bi][bj]-u[ai][bj]-u[bi][aj]+u[ai][aj];
}
 
int calc(int ah,int bh){
  int res=-INF;
  int maxm=0;
  for(int i=1;i<=n;i++){
    res=max(res,maxm+sum(ah,i,bh,i));
    int d=t[ah][i]+t[bh][i];
    if(ah==bh)d/=2;
    maxm=max(maxm+d,sum(ah,i,bh,i));
  }
  return res;
}
 
int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      cin>>t[i][j];
      u[i][j]=t[i][j]+u[i-1][j]+u[i][j-1]-u[i-1][j-1];
    }
  }
  int ans=-INF;
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j++){
      ans=max(ans,calc(i,j));
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  ll x;
  cin >> N >> x;
  vector<ll> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  
  if(a[0] > x){
    a[1] += a[0] - x;
    a[0] = x;
  }

  ll ans = 0;
  for(int i = 0; i < N-1; i++){
    if(a[i] + a[i+1] > x){
      ans += (a[i] + a[i+1]) - x;
      a[i+1] -= (a[i] + a[i+1]) - x;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
import numpy as np
N,S=map(int,input().split())
As=list(map(int,input().split()))

MOD=998244353

#d = [[0]*3001 for _ in range(3001)]
d=np.zeros((3001,3001))
d[0,0]=1

for i in range(1,N+1):
    Ai=As[i-1]
    d[i] += 2*d[i-1]
    d[i,Ai:] += d[i-1][:-Ai]
    d[i] %= MOD
print(int(d[N][S]))

Measured memory_bytes: 97396
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
  string s;
  cin >> s;
  int ans = 0;
  int n = s.size();
  int i = 0;
  int cnt = 0;
  int k =0;
  for(int i = k; i < n; i++ ){
    if(s.at(i) == 'R'){
      int num = 1;
      for(int j = i +1; j < n; j++){
        if(s.at(j) == 'R') num++;
        else {
          k = j;
          break; 
        }
      }
      if(num > ans) ans = num;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
from sys import stderr, setrecursionlimit
from functools import reduce
from operator import add
from collections import Counter
from collections import Counter
setrecursionlimit(2147483647)
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)


n = int(input())
v = f()
debug(v)
ans = 0
even = Counter(v[0::2])
odd = Counter(v[1::2])

most_even = even.most_common(2)
most_odd = odd.most_common(2)

# 数字は2種類じゃないとダメ
if most_even[0][0] == most_odd[0][0]:
    if most_even[0][1] == most_odd[0][1]:
        # 2つ目が多い方を2つ目に  
        if len(most_even) != 1 and len(most_even) != 1:
            if most_even[1][1] < most_odd[1][1]:
                ans = (n//2 - most_even[0][1]) +  (n//2 - most_odd[1][1])
            else:
                ans = (n//2 - most_odd[0][1]) +  (n//2 - most_even[1][1])
        elif len(most_even) == 1 and len(most_odd) != 1:
            # most_evenの2番目は'0'
            ans = (n//2 - most_even[0][1]) + (n//2 - most_odd[1][1])
        elif len(most_even) != 1 and len(most_odd) == 1:
            # most_oddの2番目は'0'
            ans = (n//2 - most_even[1][1]) +  (n//2 - most_odd[0][1])
        else:
            ans = (n//2 - most_even[0][1]) + (n//2)
    # 総合結果から判断
    else:
        if len(most_even) != 1 and len(most_odd) != 1:
            # そのまま計算
            if most_even[0][1] + most_odd[1][1] < most_even[1][1] + most_odd[0][1]:
                ans = (n//2 - most_even[1][1]) +  (n//2 - most_odd[0][1])
            else:
                ans = (n//2 - most_even[0][1]) +  (n//2 - most_odd[1][1])
        elif len(most_even) == 1 and len(most_odd) != 1:
            # most_evenの2番目は"0"
            if most_even[0][1] + most_odd[1][1] < (n//2 - most_even[0][1]) + most_odd[0][1]:
                ans = most_even[0][1] + (n//2 - most_odd[0][1])
            else:
                ans = (n//2 - most_even[0][1]) + (n//2 - most_odd[1][1])
        elif len(most_even) != 1 and len(most_odd) == 1:
            # most_oddの2番目は"0"
            if most_even[0][1] + (n//2 - most_odd[0][1]) < most_even[1][1] + most_odd[0][1]:
                ans = (n//2 - most_even[1][1]) + (n//2 - most_odd[0][1])
            else:
                ans = (n//2 - most_odd[0][1]) + most_even[0][1]
        else:
            # どっちも2番目は"0"
            if most_even[0][1] < most_odd[0][1]:
                ans = (n//2 - most_odd[0][1]) + n//2
            else:
                ans = n//2 + (n//2 - most_even[0][1])
else:
    ans = n - most_even[0][1] - most_odd[0][1]

print(ans)


Measured memory_bytes: 18616
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
 
using namespace std;
 
double EPS = 1e-10;
 
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}
 
struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}
 
  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }
 
  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }
};
 
struct segment{
  point a,b;
};
 
struct circle{
  point p;
  double r;
};
 
double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}
 
double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}
 
int ccw(point p0, point p1, point p2){
  point a = p1 - p0;
  point b = p2 - p0;
  if(cross(a,b)>EPS)return +1;
  if(cross(a,b)<EPS)return -1;
  if(dot(a,b)<-EPS)return +2;
  if(a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y)return -2;
  return 0;
}
 
double vec_abs(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}
 
double distance_ls_p(point a, point b, point c) {
  if ( dot(b-a, c-a) < EPS ) return vec_abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return vec_abs(c-b);
  return abs(cross(b-a, c-a)) / vec_abs(b-a);
}
 
double dist(point a,point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
 
int crossCS(point a, point b, circle c){
  double res=distance_ls_p(a,b,c.p);
  double ac=dist(a,c.p);
  double bc=dist(b,c.p);
 
  if(res>c.r || (ac<c.r && bc<c.r))return 0;
  else if(c.r-res<EPS ||(ac<c.r && bc>=c.r)||(ac>=c.r && bc<c.r))return 1;
  else return 2;
}
 
vector<segment> construct_edge(point* p, int n){
  vector<segment>seg,seg2;
  segment temp;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
    temp.a=p[i];
    temp.b=p[j];
    seg.push_back(temp);
      }
    }
  }
 
  int t=seg.size();
  for(int i=0;i<t;i++){
    int fg=0;
    for(int j=0;j<t;j++){
      if(i!=j && vec_abs(seg[i].b-seg[j].a)<=EPS){
    if(ccw(seg[i].a,seg[i].b,seg[j].b)==1){
      fg=1;
      break;
    }
      }
    }
    if(!fg)seg2.push_back(seg[i]);
  }
  return seg2;
}
 
int point_contain(vector<segment> ps, point p, int n){
  int cnt=ccw(ps[0].a,ps[0].b,p);
 
  for(int i=0;i<n;i++)
    if(cnt!=ccw(ps[i].a,ps[i].b,p))return 0;
   
  return 1;
}
 
int main(void){
  point p[3];
  vector<segment> t;
  circle C;
 
  while(true){
    for(int i=0;i<3;i++){
      cin >> p[i].x >> p[i].y;
      if(p[i].x==0 && p[i].y==0)return 0;
    }
    cin >> C.p.x >> C.p.y >> C.r;
 
    double ans=0;
    for(int i=0;i<3;i++){
    int tmp=dist(p[i],C.p);
    if(tmp>ans)ans=tmp;
    }
    if(C.r>=ans){
      cout <<'b'<<endl;
      continue;
    }
     
    t=construct_edge(p,3);
    int res1=point_contain(t,C.p,3);
    double res2=100000000;
    for(int i=0;i<3;i++)
      res2=min(res2,distance_ls_p(t[i].a,t[i].b,C.p));
 
    if(res1 && C.r<=res2)cout <<'a'<< endl;
    else if(!res1 && C.r<res2)cout <<'d'<< endl;
    else cout <<'c'<< endl;
     
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

const int N = 1000000;

int num[N];

void init() {
	num[0] = num[1] = 0;
	for (int i=2; i<N; ++i) num[i] = 1;
	for (int i=2; i<1000; ++i) {//素数&#31579;&#36873; 
		if (num[i * i]) {
			int j = i + i;
			for (;j < N; num[j] = 0, j += i); 
		}
	}
	for (int i=1; i<N; ++i) num[i] += num[i-1];
}

int main() {
	int n;
	init();
	while (scanf("%d", &n) != EOF) {
		printf ("%d\n", num[n]);
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
	int n,m,a[1000],b[1000],c,i,k;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		b[i]=0;
	}
	for(i=0;i<m;i++){
		scanf("%d",&c);
		for(k=0;k<n;k++){
			if(a[k]<=c){
				b[k]++;
				break;
			}
		}
	}
	k=0;
	for(i=1;i<n;i++){
		if(b[k]<b[i]){
			k=i;
		}
	}
	k++;
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
struct edge{ int to,cost,x;};
#define INF (1<<26)
#define MAX_N 10005
int n,m;
vector<edge> G[MAX_N];
int d[MAX_N],k[MAX_N];

void init(){
  for(int i=0;i<MAX_N;i++){
    G[i].clear();
    d[i]=INF;
    k[i]=INF;
  }
}

int main(){
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    init();
    for(int i=0;i<m;i++){
      int a,b,c,d;
      scanf("%d %d %d %d",&a,&b,&c,&d);
      G[a].push_back((edge){b,c,d});
      G[b].push_back((edge){a,c,d});
    }
    priority_queue< P , vector<P> , greater<P> > Q;
    d[1]=k[1]=0;
    Q.push(P(0,1));
    int ans=0;
    while(!Q.empty()){
      P p=Q.top();Q.pop();
      int pos=p.second,cost=p.first;
      if(cost>d[pos])continue;
      ans+=k[pos];
      for(int i=0;i<(int)G[pos].size();i++){
        edge e=G[pos][i];
        if(d[e.to]>cost+e.cost){
          k[e.to]=e.x;
          d[e.to]=cost+e.cost;
          Q.push(P(d[e.to],e.to));
        }else if(d[e.to]==cost+e.cost){
          k[e.to]=min(k[e.to],e.x); 
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3364
cards = {}
cards["a"] = gets.chomp.split("")
cards["b"] = gets.chomp.split("")
cards["c"] = gets.chomp.split("")
turn = "a"
win = "x"
while true do 
  turn = cards[turn].shift
  if cards[turn].empty?
    win = turn
    break
  end
end
puts win.upcase

Measured memory_bytes: 1788
import sys
input = sys.stdin.readline


def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1


n, m = map(int, input().split())
py = [list(map(int, input().split())) for i in range(m)]
check = sorted(py)
memo = py[0][0]
cnt = [0] * m
cnt_memo = 0

for i in range(m):
    if memo != check[i][0]:
        memo = check[i][0]
        cnt_memo = 0
    cnt_memo += 1
    cnt[i] = cnt_memo

for i in range(m):
    number = str(cnt[binary_search(check, py[i])])
    p = str(py[i][0])
    print((6 - len(p)) * '0' + p + (6 - len(number)) * '0' + number)


Measured memory_bytes: 66524
#include <cstdio>
#include <algorithm>
#define MAXN 100005
using namespace std;

typedef long long ll;

int parent[MAXN];
int Rank[MAXN];
ll sizee[MAXN];
int n;
ll ans;

inline ll calc(int n) { return 1ll * n * (n - 1) / 2; }

void init(){
    for (int i = 1; i <= n; ++i) parent[i] = i, sizee[i] = 1ll;
}

int Find(int x){
    // path halving
    while (parent[x] != x){
        parent[x] = parent[parent[x]];
        x = parent[x];
    }
    return x;
}

void unite(int x, int y){
    int rx = Find(x), ry = Find(y);
    if (rx == ry) return;
    if (Rank[rx] < Rank[ry]) swap(rx, ry);
    parent[ry] = rx;
    ans += calc(sizee[rx]);
    ans += calc(sizee[ry]);
    sizee[rx] += sizee[ry];
    ans -= calc(sizee[rx]);
    if (Rank[rx] == Rank[ry]) ++Rank[rx];
}

bool in_same(int x, int y){
    return Find(x) == Find(y);
}

ll anss[MAXN];

struct edge {
    int u, v;
} e[MAXN];

int main() {
    int m;
    scanf("%d%d", &n, &m);
    init();
    ans = calc(n);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &e[i].u, &e[i].v);
    }
    for (int i = m - 1; ~i; --i) {
        anss[i] = ans;
        unite(e[i].u, e[i].v);
    }
    for (int i = 0; i < m; ++i) printf("%lld\n", anss[i]);
    return 0;
}

Measured memory_bytes: 4480
n = int(input())
a = list(map(int, input().split()))

cum_sum = [0] * (n+1)
for i in range(n):
    cum_sum[i+1] = cum_sum[i] + a[i]

INF = 10**18
ans = INF
for i in range(1, n):
    ans = min(ans, abs(cum_sum[i]-(cum_sum[-1]-cum_sum[i])))

print(ans)


Measured memory_bytes: 24800
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i;i<n;++i) cin>>a[i];
  vector<int>lm(n);
  vector<int>rm(n);
  for(int i=1;i<n;i++) lm[i]=max(lm[i-1],a[i-1]);
  for(int i=n-2;i>=0;i--) rm[i]=max(rm[i+1],a[i+1]);
  for(int i=0;i<n;i++){
    cout<<max(lm[i],rm[i])<<endl;
  }
  return 0;
}


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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))
#define MAX 2009
int dx[]= {0,0,1,-1};
int dy[]= {1,-1,0,0};

int n,m,k;

int  valid(int x,int y)
{
    if((x>=0 && x<n) && (y>=0 && y<m) )
    {
        return 1;
    }
    return 0;
}

int main()
{
    int i,j,l,r;

    cin >> n >> m >> k;

    int dis[n+10][m+10];
    char s[n+10][m+10];
    int vis[n+10][m+10];


    int x1,x2,y1,y2;

    cin >> x1 >> y1 >> x2 >> y2;
    x1--,x2--,y1--,y2--;


    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            cin >> s[i][j];
            vis[i][j] = 0;
            dis[i][j]= 200000000;
        }
    }

    queue<pii>q;

    dis[x1][y1] = 0;

    q.push({x1,y1});
    int paise = 0;
    while(!q.empty())
    {
        pii pp = q.front();

        q.pop();

        if(vis[pp.F][pp.S])continue;

        vis[pp.F][pp.S] = 1;

        for(i=0; i<4; i++)
        {

            for(j=1; j<=k; j++)
            {
                int x,y;


                x = pp.F + dx[i]*j;
                y = pp.S + dy[i]*j;

                if(!valid(x,y) || s[x][y] == '@' || dis[x][y]<=dis[pp.F][pp.S])break;


                if(dis[x][y] > (1 + dis[pp.F][pp.S]))dis[x][y] = 1 + dis[pp.F][pp.S],q.push({x,y});
            }

        }


    }


    if(dis[x2][y2] != 200000000)cout << dis[x2][y2] << endl;
    else cout << -1 << endl;


}


Measured memory_bytes: 12992
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var m     = int.Parse(spl[1]);

        var tbl = new int[n];

        for(int i=0; i<m; i++) {
            spl   = input.ReadLine().Split(' ');
            var a     = int.Parse(spl[0]);
            var b     = int.Parse(spl[1]);

            tbl[a-1]++;
            tbl[b-1]++;
        }

        foreach(var x in tbl) {
            Console.WriteLine(x);
        }
        return null;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }

}


Measured memory_bytes: 27360
def main():
    N = int(input())
    X = []
    a = -float('inf') # x + y の最大
    b = float('inf') # x + y の最小
    c = -float('inf') # x - y の最大
    d = float('inf') # x - y の最小
    e = -float('inf') # -x+yの最大
    f = float('inf') # -x + yの最小
    g = -float('inf') # -x - yの最大
    h = float('inf') # -x - yの最小

    for _ in range(N):
        x, y = map(int, input().split())
        a = max(a, x + y)
        b = min(b, x + y)
        c = max(c, x - y)
        d = min(d, x - y)
        e = max(e, -x + y)
        f = min(f, -x + y)
        g = max(g, -x - y)
        h = min(h, -x - y)
    ans = a - b
    ans = max(ans, c-d)
    ans = max(ans, e-f)
    ans = max(ans, g-h)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 69816
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		String S = sc.next();
		System.out.println(S.contains("A") && S.contains("B") ? "Yes" : "No");
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21716
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NM = Console.ReadLine().Split(' ');
            int N = int.Parse(NM[0]);
            int M = int.Parse(NM[1]);
            string[] Astr = Console.ReadLine().Split(' ');
            int[] A = new int[N];
            for (int i = 0; i < N; i++) A[i] = int.Parse(Astr[i]);
            int Sum = A.Sum();
            int min = Sum / 4 / M;
            if (Sum % (4 * M) > 0) min++;
            int count = 0;
            for(int i = 0; i < N; i++)
            {
                if (A[i] >= min) count++;
            }
            if (count < M) Console.WriteLine("No");
            else Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
#include<string.h>
int main(void)
{
  char s[11],t[11],u[11];
  int a,b;
  scanf("%s %s",s,t);
  scanf("%d %d %s",&a,&b,u);
  if(!strcmp(s,u)){
    printf("%d %d\n",a-1,b);
  }else if(!strcmp(t,u)){
    printf("%d %d\n",a,b-1);
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        if(s.charAt(0) != '1'){
            System.out.println(s.charAt(0));
            return;
        }
        int cnt = 1;
        for(int i = 1;i < s.length();i++){
            if(s.charAt(i) == '1'){
                cnt++;
                continue;
            }
            break;
        }
        if(k <= cnt){
            System.out.println(1);
            return;
        }
        System.out.println(s.charAt(cnt));
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n;
	std::cin >> n;
	std::vector<uint32> d(n);
	rep(i, 0, n)
		std::cin >> d[i];
	std::sort(ALL(d));
	uint32 ans = n;
	rep(i, 1, n) {
		if (d[i] == d[i - 1]) {
			--ans;
		}
	}
	std::cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

		int[] accum = new int[N];
		boolean flag = false;
		if(S.charAt(0) == 'A') flag = true;

		for(int i=1;i<N;i++) {
			if(S.charAt(i) == 'A') {
				flag = true;
				accum[i] = accum[i-1];
			}else if(S.charAt(i) == 'C') {
				if(flag) {
					flag = false;
					accum[i] = accum[i-1] + 1;
				}else {
					accum[i] = accum[i-1];
				}
			}else {
				if(flag) flag = false;
				accum[i] = accum[i-1];
			}
		}

		int[] ans = new int[Q];
		for(int i=0;i<Q;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			ans[i] = accum[r-1] - accum[l-1];
		}

		for(int i=0;i<Q;i++) {
			System.out.println(ans[i]);
		}
	}
}


Measured memory_bytes: 79644
#include<stdio.h>

int main(){
	int a,c;
	scanf("%d",&a);
	int b=a,d=a;
	if(a>=900){
		d=a-900+100;
		b=b-900;
		a=a-900;
	}
	if(a>=100){
		d=a-100+900;
		b=b-100;
	}
	if(b>=90){
		d=d-90+10;
		c=b-90;
		b=b-90;
	}
	if(b>=10){
		c=b-10;
		d=d-10+90;
	}
	if(c==9){
		d=d-9+1;
	}
	if(c==1){
		d=d-1+9;
	}
	printf("%d\n",d);
return 0;
}

Measured memory_bytes: 128
#include<cmath>
#include<algorithm>
using namespace std;
int hyo[7][7]={
	{0,300,500,600,700,1350,1650},
	{6,0,350,450,600,1150,1500},
	{13,7,0,250,400,1000,1350},
	{18,12,5,0,250,850,1300},
	{23,17,10,5,0,600,1150},
	{43,37,30,25,20,0,500},
	{58,52,45,40,35,15,0}
};
int main(){
	int s,g, h,m,H,M, c;
	while(cin>>s,s){
		cin>>h>>m>>g>>H>>M;
		if(s>g)swap(s,g);
		c=hyo[s-1][g-1];
		if(hyo[g-1][s-1]<=40 &&( (1050<=h*60+m&&h*60+m<=1170)||(1050<=H*60+M&&H*60+M<=1170) ) )
		c=((int)ceil((c/2/50.0)))*50;
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, M; cin >> N >> M;
  vector<pair<ll, ll>> id(M);
  vector<vector<ll>> tmp(N + 1);
  REP(i, M) {
    ll p, y; cin >> p >> y;
    id[i] = make_pair(p, y);
  }
  REP(i, M) {
    tmp[id[i].first].push_back(id[i].second);
  }
  REP(i, N + 1) {
    sort(all(tmp[i]));
  }
  for(ll i = 0; i < M; ++i) {
    int ans = lower_bound(all(tmp[id[i].first]), id[i].second) - tmp[id[i].first].begin();
    cout << setw(6) << setfill('0') << id[i].first << setw(6) << setfill('0') << (ans + 1) << endl;
  }
}

Measured memory_bytes: 10216
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
	string s; cin >> s;
	ll n = s.size();
	
	/*
	map<string, int> mp;
	
	rep3(i, 0, n-2){
	    rep3(j, i+1, n-1){
	        string ss;
	        string t = s.substr(i, j-i+1);
	        reverse(all(t));
	        if(i-1 >= 0) ss = s.substr(0, i);
	        ss += t;
	        if(j + 1 < n) ss += s.substr(j+1);
	        // cout << i << "," << j << ": " << ss << endl;
	        mp[ss]++;
	    }
	}
    
    cout << mp.size() << endl;
    for(auto [k, v] : mp){
        if(v > 1) cout << k << " " << v << endl;
    }
    */
    
    map<char, ll> mp;
    ll ans = n * (n-1) / 2;
    
    rep(i, n){
        mp[s[i]]++;
    }
    for(auto [k, v] : mp){
        if(v > 1) ans -= v * (v-1) / 2;
    }
    cout << ans + 1 << endl;
	return;
}

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

Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  
  vector<int> V(N);
  for(int i = 0;i < N;i++) cin >> V.at(i);
  vector<int> C(N);
  for(int i = 0;i < N;i++) cin >> C.at(i);
  
  int ans = 0;
  for(int i = 0;i < N;i++) ans += max(0, V.at(i) - C.at(i));
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3628
N,Q=map(int,input().split())
S=input()

s=[0]

for i in range(len(S)):
    s.append(s[-1]+(1 if(S[i:i+2]=="AC") else 0))

for i in range(Q):
    l,r=list(map(int,input().split()))
    print(s[r-1]-s[l-1])


Measured memory_bytes: 7700
import math
N = int(input())
ans = 0
n_max = int(math.sqrt(N))
for n in range(1,n_max+1):
	if N%n == 0:
		a = N//n
		if a+1 < n:
			ans += n-1
		elif n+1 < a:
			ans += a-1
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int h, w;
char s[401][400];
ll a[2];

void fill(int i, int j, char c) {
    if (s[i][j] != c) return;
    a[(i + j) % 2]++;
    s[i][j] = '@';
    if (i > 0) fill(i - 1, j, c);
    if (i < h - 1) fill(i + 1, j, c);
    if (j > 0) fill(i, j - 1, c);
    if (j < w - 1) fill(i, j + 1, c);
}

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

    cin >> h >> w;

    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if ((i + j) % 2) s[i][j] ^= '#' ^ '.';
        }
    }

    ll r = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '@') continue;
            a[0] = a[1] = 0;
            fill(i, j, s[i][j]);
            r += a[0] * a[1];
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 5376
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 

int main() {
  int x;
  cin >> x;
  if(x == 0){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }

}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = inf;
    rep(i,n-k+1) {
        int now = min(abs(x[i]),abs(x[i+k-1]))+(x[i+k-1]-x[i]);
        chmin(ans,now);
    }
    cout << ans << endl;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	int ans = a-b;
	if(ans<0){ans=0;}
	printf("%d\n",ans);
	return 0;
};

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007


int main(){
    ll N, P; cin >> N >> P;
    map<ll, ll> M;
    for(ll i=2; i*i<=P; i++){
        while(P%i==0){
            M[i]++;
            P/=i;
        }
    }
    if(P>1LL) M[P]++;
    
    ll ans = 1;
    for(auto m:M){
        for(ll i=0; i<m.second/N; i++){
            ans *= m.first;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define MAX_N 101

int route[MAX_N];

int main()
{
    int a,b=1;
    int n=0;
    bool flag=false;
   
    while (cin >> a && cin >> b)
    {
        route[a]++;//頂点 a の次数を増やす;
        route[b]++;//頂点 b の次数を増やす;
        n++;
        if (a == 0)
        {
            //始点から終点に一筆書き出来るか?
            
            //(条件)
            //頂点番号 1 と 2 の字数が奇数,かつ,
            //頂点番号 3 以上の頂点の次数が全て偶数
            
            if(route[1] % 2 == 0 || route[2] % 2 == 0){ flag=true; }
            for(int i=3; i<=n; i++){
                if(route[i]%2==1){ flag=true; }
            }
                
            if(flag){
                cout << "NG" << endl;
            }else{
                cout << "OK" << endl;
            }
            
            //次のテストケースのために,全ての頂点の次数を 0 に戻す + 初期化
            for(int i=0; i < MAX_N; i++){route[i]=0;}
            n=0; flag=false;
        }
    }
}

Measured memory_bytes: 1156
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

#n,x = [int(i) for i in readline().split()]
#h,w = [int(i) for i in readline().split()]
n = int(input())
a = [int(i) for i in readline().split()]

from itertools import accumulate
acc = list(accumulate([0]+a))

j = 1
k = 3
ans = 10**18
for i in range(2,n):
    c = acc[i]//2
    while j < i-1 and acc[j] < c:
        j += 1

    c = (acc[-1]-acc[i])//2
    while k < n-1 and acc[k]-acc[i] < c:
        k += 1

    for jj in range(2):
        for kk in range(2):
            l = (acc[j-jj],acc[i]-acc[j-jj], acc[-1]-acc[k-kk], acc[k-kk]-acc[i])
            res = max(l) - min(l)
            ans = min(ans, res)

    
print(ans)   
    
    
    
    






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

using namespace std;

/*-------------------------------*/
#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 rep(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;

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

int main(void)
{
  int a, b = 0;
  rep(i, 5){
    cin >> a;
    if (a < 40) a = 40;
    b += a;
  }

  cout << b / 5 << endl;

  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;
const ll mod = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    ll h, n; cin >> h >> n;
    vector<ll> a(n);
    ll atk_sum = 0;
    for(ll i=0; i<n; i++){
        cin >> a[i];
        atk_sum += a[i];
    }
    if(atk_sum >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 1024
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int n;
    string a;
    map<string, int>mp;
    cin >> n;
    rep(i, n) {
        cin >> a;
        mp[a]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}


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

int main(){
  int N, d[120];
  cin >> N;
  for(int i = 0 ; i < N ; i++) cin >> d[i];

  int num[110] = {0}; //バケット
  for(int i=0 ; i < N ; i++){
    num[d[i]]++; //d[i] が1個増える
  }

  int res = 0 ;
  for(int i = 1; i <= 100; i++){
    if(num[i]){
      res++;
    }
  }
  cout <<res;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int i = 0;
string str;

string takeout(char a) {
    if ( i != 0) i++;
    stringstream tmp;
    while (str[i] != a) {
        tmp << str[i];
        i++;
    }
    return tmp.str(); 
}

string change(string str, char a) {
    int j = 0;
    while(str[j] != '\0') {
        if (str[j] == 'X') str[j] = a;
        j++;
    }
    return str;
}

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

    while(cin >> str){
        i = 0;
        string L = takeout('+');
        string R = takeout('=');
        string ANS = takeout('\0');

        int flag = 0;
        int j;
        for (int i = 9; i >= 0; i--){
            string tmp1, tmp2, tmp3;
            tmp1 = change(L, '0' + i);
            tmp2 = change(R, '0' + i);
            tmp3 = change(ANS, '0' + i);
            if (i == 0) {
                //dump(R.length());
                if (L.length() > 1) {
                    if (L[0] == 'X') break;
                } 
                if (R.length() > 1) {
                    //dump(R[0]);
                    if (R[0] == 'X') break;
                }
                if (ANS.length() > 1) {
                    if (ANS[0] == 'X') break;
                }
            }
            
            int movesup = 0;
            int len1 = tmp1.length()-1;
            int len2 = tmp2.length()-1;
            int len3 = tmp3.length()-1;
            int MAX_len = max(len1, max(len2, len3))+1;
            //dump(MAX_len);
            j = 0;
            while (len1 >= 0 || len2 >= 0 || len3 >= 0) {
                int tmpL = 0, tmpR = 0, tmpA = movesup;
                if (len1 >= 0) tmpL = tmp1[len1] - '0';
                if (len2 >= 0) tmpR = tmp2[len2] - '0';
                if (len3 >= 0) tmpA = tmp3[len3] - '0'-movesup;
                /*
                dump(j)
                dump(tmpL);
                dump(tmpR);
                dump(tmpA);
                */
                if (tmpL + tmpR == tmpA) {
                    j++; 
                    movesup = 0; 
                } else if (tmpL + tmpR == 10 + tmpA) {
                    j++;
                    movesup = 1;
                } else if (tmpL + tmpR == 20 + tmpA) {
                    j++;
                    movesup = 2;
                } else break;           
                len1 = tmp1.length()-j-1;
                len2 = tmp2.length()-j-1;
                len3 = tmp3.length()-j-1;
            }
            if (j == MAX_len) {
                cout << i << endl;
                flag = 1;
                break;
            }
        }
        if (flag == 0) cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vi a(n);
    REP(i, n) cin >> a[i];
    int x = 0;
    REP(i, n) x ^= a[i];
    REP(i, n) cout << (x ^ a[i]) << (i == n - 1 ? '\n' : ' ');
}


Measured memory_bytes: 3972
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main(){
    int N,x,y,z,sum;
    ll Y;
    bool flag = false;
    cin >> N >> Y;
    for(x=N;x>=0;x--){
        for(y=N-x;y>=0;y--){
            z = N - x - y;
            sum = 10000*x + 5000*y + 1000*z;
            if(sum == Y && z >= 0){
                cout << x <<" "<< y << " " << z << endl;
                flag = true;
                break;
            }
        }
        if(sum == Y && z >= 0) break;
    }
    if(!flag){
        x=y=z=-1;
        cout << x <<" "<< y << " " << z << endl;
    }
}

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

int main() {

    int A, B, C;

    cin >> A >> B >> C;

    if (B/A >= C) {
        cout << C << endl;
    }
    else if (B/A < C) {
        cout << B/A << endl;
    }
    else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second

const int maxn = 200010;

struct Segment {
  int n, t[maxn * 2];
  void init(int n) {
    fill(t, t + maxn * 2, INT_MAX);
    this->n = n;
  }
  void set(int x, int v) {
      t[x + n] = v;
  }
  void build() {
    for (int i = n - 1; i; --i)
      t[i] = min(t[i<<1], t[i<<1|1]);
  }
  int query(int l, int r) {
    r++;
    int ret = INT_MAX;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l&1) ret = min(ret, t[l++]);
      if (r&1) ret = min(ret, t[--r]);
    }
    return ret;
  }
} s[2];
int n, a[maxn], rev[maxn];

PII query(int l, int r) {
  int a = s[l & 1].query(l, r);
  int p = rev[a];
  int b = s[~l & 1].query((p + 1), r);
  return {a, b};
}

int main() {
  scanf("%d", &n);
  s[0].init(n);
  s[1].init(n);
  REP(i, n) {
    scanf("%d", &a[i]);
    s[i & 1].set(i, a[i]);
    rev[a[i]] = i;
  }
  s[0].build();
  s[1].build();
  using T = tuple<PII, int, int>;
  priority_queue<T, vector<T>, greater<T>> q;
  q.push((T){query(0, n - 1), 0, n - 1});
  vector<int> ans;
  while (q.size()) {
    PII tp;
    int l, r;
    tie(tp, l, r) = q.top(); q.pop();
    ans.PB(tp.F);
    ans.PB(tp.S);
    int ll = rev[tp.F];
    int rr = rev[tp.S];
    if (ll > l) q.push((T){query(l, ll - 1), l, ll - 1});
    if (rr < r) q.push((T){query(rr + 1, r), rr + 1, r});
    if (ll + 1 <= rr - 1) q.push((T){query(ll + 1, rr - 1), ll + 1, rr - 1});
  }
  REP(i, n) printf("%d%c", ans[i], " \n"[i + 1 == n]);
  return 0;
}



Measured memory_bytes: 7668
n,m = map(int,input().split())
x = list(map(int,input().split()))

x.sort()
i = 0
a = [0]*(m-1)
for i in range(m-1):
    a[i] = x[i+1]-x[i]
a.sort()
if n == 1:
    print(sum(a))
else:
    print(sum(a[:-(n-1)]))

Measured memory_bytes: 13968
let n, h, w = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let ab_s = Array.init n @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a, b
let _ = Array.fold_left (fun c (a, b) -> c + if a >= h && b >= w then 1 else 0) 0 ab_s |> Printf.printf "%d\n"

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

int main(){
  int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;
  if(max({a,b,c,d,e})-min({a,b,c,d,e}) <= k) cout << "Yay!";
  else cout << ":(";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<int> a(n);
  ll o = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] % 2 == 0) {
      o *= 2;
    }
  }

  ll total = pow(3, n);

  ll ans = total - o;

  cout << ans << ln;

  return 0;
}

/*
o * o = o
o * e = e
e * e = e
*/

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


int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    cout << (100 * (n - m) + 1900 * m) * (1 << m);
}















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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}
const int MOD = (int)1e9 + 7;

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

    int n, m;
    cin >> n >> m;
    if (abs(n - m) > 1) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> F(100100, 1);
    for (int i = 1; i < 100100; i++){
        F[i] = F[i-1] * i % MOD;
    }
    ll res = F[n] * F[m];
    if (n == m) res *= 2;
    res %= MOD;
    cout << res << endl;
}


Measured memory_bytes: 1024