akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
using namespace std;
struct JWE{bool f;int x;int y;};

int main(){
bool ma[22][22]={};
JWE JW[21];
int n1,n2,x1,y1,k,x=10,y=10;
char ch;

for(int i=0;i<22;i++)
for(int j=0;j<22;j++)
ma[i][j]=false;

while(scanf("%d",&n1)!=EOF){
	if(n1==0)break;
for(int i=0;i<n1;i++){
cin>>x1>>y1;
JW[i].x=x1;JW[i].y=y1;
}
x=10,y=10;
scanf("%d",&n2);
for(int ii=0;ii<n2;ii++){
cin>>ch>>k;

if(ch=='N'){
for(int j=y;j<=y+k;j++)
ma[x][j]=true;y=y+k;
}
else if(ch=='S'){
for(int j=y;j>=y-k;j--)
ma[x][j]=true;y=y-k;
}
else if(ch=='E'){
for(int j=x;j<=x+k;j++)
ma[j][y]=true;x=x+k;
}
else if(ch=='W'){
for(int j=x;j>=x-k;j--)
ma[j][y]=true;x=x-k;
}

}

int sum=0;
for(int i=0;i<n1;i++)
{if(ma[JW[i].x][JW[i].y]==true)sum++;}
if(n1==sum)printf("Yes\n");
else printf("No\n");

for(int i=0;i<22;i++)
for(int j=0;j<22;j++)
ma[i][j]=false;

/*
for(int i=0;i<21;i++){
for(int j=0;j<21;j++)
{cout<<" ";
if(ma[j][i]==false)cout<<"*";
else cout<<"1";}
cout<<endl;
}
*/
}
return 0;
}

Measured memory_bytes: 1204
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if((a+11)%13>(b+11)%13){
    cout<<"Alice"<<endl;
  }
  else if((a+11)%13<(b+11)%13){
    cout<<"Bob"<<endl;
  }
  else{
    cout<<"Draw"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define ll long long
#define f(i,l,n) for(int i=l;i<n;i++)
#define E "\n"
#define Outerloop int q;cin>>q;while(q--)
#define Mod 1000000007

    int32_t main()
    {
	 int n,m;
	 cin >> n >> m;
	 
	 int dp[n+1][m+1];
	 memset(dp,0,sizeof dp);
	 dp[1][0]=1;
	 f(i,1,n+1)
	 {
	 	string s;
	 	cin >> s;
	 f(j,1,m+1)
	 {
		if(s[j-1]=='#') dp[i][j]=0;
		else dp[i][j]=(dp[i-1][j]%Mod+dp[i][j-1]%Mod)%Mod;
	//	cout<<dp[i][j]<<" ";
	 }
	 //cout<<E;
	 }
		cout<<dp[n][m];	 
    return 0;
    }
    
    
    

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

int m,a,b;

vector<int>prime;
void solve(){
        int x=0,y=0;
        int ub=prime.size(),lb=0;
        while(ub-lb>1){
            int mid=(ub+lb)/2;
            if(m/prime[mid]<prime[mid])ub=mid;
            else lb=mid;
        }
        for(int i=lb;i<prime.size();i++){
            int q=prime[i];
            ub=i;lb=0;
            while(ub-lb>1){
                int mid=(ub+lb)/2;
                int p=prime[mid];
                if(b*p<a*q)lb=mid;
                else ub=mid;
            }
            if(prime[ub]>(m+q-1)/q)continue;
            for(int j=ub;j<=i;j++){
                int p=prime[j];
                if(p*q>m)break;
                if(p*q>x*y){
                    x=p;y=q;
                }
            }
        }
        printf("%d %d\n",x,y);
}

int main(){
    bool f[50000];fill_n(f,50000,true);
    f[0]=f[1]=true;
    for(int i=2;i<50000;i++){
        if(!f[i])continue;
        for(int j=i+i;j<50000;j+=i)f[j]=false;
    }
    for(int i=2;i<50000;i++)if(f[i])prime.push_back(i);

    while(scanf("%d%d%d",&m,&a,&b),m||a||b)solve();
    return 0;
}

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

int n;
int m;
vector<int> buf(3);
vector<int> ans;

void dfs(int i, const int range_start, const int range_end)
{
    if (i == 3) {
        // ここで所望の作業を行う
        if (buf[0] + buf[1] + buf[2] <= m+2) {
            int t = buf[0] * buf[0] + buf[1] * buf[1] + buf[2] * buf[2] + buf[0] * buf[1] + buf[1] * buf[2] + buf[2] * buf[0];
            if (t<n+1)
                ++ans[t];
        }
    }
    else {
        for (int j = range_start; j <= range_end; ++j) {
            buf[i] = j;
            dfs(i + 1, range_start, range_end);
        }
    }
}

int main(void)
{
    cin >> n;
    m= sqrt(n / 6) * 3-2;
    int range_start = 1;
    int range_end = m;
    ans.resize(n+1);
    dfs(0, range_start, range_end);

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

    return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<functional>
#include<list>
#include<bitset>
#include<numeric>
#include<utility>
#define INF (int)1e9
#define DINF (double)1e9
#define MOD 1000000007
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> p;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	auto max_itr = max_element(a.begin(), a.end());
	double mid = (double)*max_itr / 2.0;
	int x = INF;
	double sa = DINF;
	for (auto itr = a.begin(); itr != a.end(); itr++) {
		if (itr == max_itr) {
			continue;
		}
		double s = abs((double)*itr - mid);
		if (s < sa) {
			x = *itr;
			sa = s;
		}
	}
	cout << *max_itr << " " << x;
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
	vector<int> p[3];
int main(){
	int n,t1,t2,t3;
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&t1,&t2,&t3);
		p[0].push_back(t1);
		p[1].push_back(t2);
		p[2].push_back(t3);
	}
	int a[3],b[3];
	b[0]=a[0]=p[0][0];
	b[1]=a[1]=p[1][0];
	b[2]=a[2]=p[2][0];
	for(int i=1;i<n;i++){
		a[0]=p[0][i]+max(b[1],b[2]);
		a[1]=p[1][i]+max(b[0],b[2]);
		a[2]=p[2][i]+max(b[0],b[1]);
		b[0]=a[0];b[1]=a[1];b[2]=a[2];
	}
	cout<<max(a[0],max(a[1],a[2]));
	return 0;
}


Measured memory_bytes: 1772
#include <iostream>

int main(){
	int n;
	int q1, q2, r1, r2;
	int s;
	int cand;
	std::cin >> n;

	for(int x = 1; x <= n - 1; ++x){
		int y = n - x;
		s = 0;
		//use do-while sentence
		q1 = x;
		do{
			r1 = q1 % 10;	
			q1 = q1 / 10;
			s += r1;
		}while(q1 != 0);

		q2 = y;
		do{
			r2 = q2 % 10;
			q2 = q2 / 10;
			s += r2;
		}while(q2 != 0);
		
		//std::cout << x << " " << y << " " << s << std::endl;

		if(s < cand || x == 1){
			cand = s;
		}
	}

	std::cout << cand << std::endl;

	return 0;
}


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

int main()
{
  int x, n, p[100];
  bool f = true, g;
  cin >> x >> n;
    
  for (int i=0; i<n; i++)
  {
    cin >> p[i];
    
    if (x == p[i])
      f = false;
  }
  
  if (f)
  {
    cout << x;
    return 0;
  }
  
  for (int i=1; true; i++)
  {
    f = true;
    g = true;
    for (int j=0; j<n; j++)
    {
      if (x-i == p[j])
        f = false;
      
      if (x+i == p[j])
        g = false;
    }
    
    if (f)
    {
      cout << x-i;
      return 0;
    }
    if (g)
    {
      cout << x+i;
      return 0;
    }
  }
  
  return 0;
}

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

int main() {
	int k, s, x;
	int count = 0;
	cin >> k >> s;
	for (int i = 0;i <= k;++i) {
		for (int j = 0;j <= k;++j) {
			x = s - i - j;
			if (x <= k&&x>=0) ++count;

		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,x[130],mi = INF;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> x[i];
	for(int i = 1;i <= 100;i++){
		int sum = 0;
		for(int j = 0;j < n;j++) sum += (x[j] - i) * (x[j] - i);
		chmin(mi,sum);
	}
	cout << mi << endl;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
an = 0
for i in range(A+1):
    for t in range(B+1):
        for u in range(C+1):
         if 500*i + 100*t + 50*u == X:
             an += 1
print(an)

Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int N=9,S=100;
	vvi dp(N+1,vi(S+1));
	dp[0][0]=dp[1][0]=1;
	loop(x,1,10)for(int i=N-1;i>=0;i--)for(int j=S;j>=0;j--)if(j+x<=100){
		dp[i+1][j+x]+=dp[i][j];
	}
	int n,s;
	while(cin>>n>>s,n+s){
		cout<<dp[n][s]<<endl;
	}
}

Measured memory_bytes: 3008
s = input()
A = False
C = False
X = 0
if(s[0] == 'A'):
    A = True
for c in s[2:-1]:
    if(c == 'C'):
        C = True
for c in s:
    if(c.isupper()):
        X += 1
if(A and C and X == 2):
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
vector<string> Bubble(vector<string> s, int n){
  for(int i=0; i<n; i++){
    for(int j = n-1; j>=i+1; j--){
      if( s[j][1]-'0' < s[j-1][1]-'0' ) swap(s[j], s[j-1]);
    }
  }
  return s;
}
vector<string> Select(vector<string> s, int n){
  for(int i=0; i<n; i++){
    int minj = i;
    for(int j = i; j<n; j++){
      if( s[j][1]-'0' < s[minj][1]-'0' ) minj = j;
    }
    swap(s[i], s[minj]);
  }
  return s;
}
int main(void) {
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; i++) cin >> s[i];
  vector<string> a = Bubble(s, n);
  vector<string> b = Select(s, n);
  for(int i=0; i<n-1; i++) cout << a[i] << " ";
  cout << a[n-1] << endl;
  cout << "Stable" << endl;
  for(int i=0; i<n-1; i++) cout << b[i] << " ";
  cout << b[n-1] << endl;
  cout << ( a == b ? "Stable" : "Not stable" ) << endl;
  return 0;
}





// EOF

Measured memory_bytes: 3164
#include<iostream>
#include<string>
#include<algorithm> 
using namespace std;
int main(){
  int n,a[100005]={0},x,sum=0;
  cin>>n;
  for(int i=2;i<=n+1;i++){
    cin>>x;
    a[x]++;
    a[x-1]++;
    a[x+1]++;
  }
  for(int i=0;i<100005;i++){
    sum=max(sum,a[i]);
  }
  cout<<sum<<endl;
  return 0;
}

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

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795;

int main()
{
	int n, k, a = 1;
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
	{
		if(a * 2 >= a + k){
			a += k;
		}else{
			a *= 2;
		}
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
inp = gets.chomp.split(' ').map { |i| i.to_i }
if (inp[0] + inp[1])  == inp[2] || (inp[0] + inp[2])  == inp[1] || (inp[1] + inp[2])  == inp[0]
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
H, W, D = map(int, input().split())
px = [0]*(H*W+1)
py = [0]*(H*W+1)
dp = [0]*(H*W+1)
for i in range(H):
  inf = input().split()
  for j in range(W):
    a = int(inf[j])
    py[a] = i
    px[a] = j
for i in range(D+1, H*W+1):
  dp[i] = dp[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D])

Q = int(input())
for i in range(Q):
  L, R = map(int, input().split())
  print(dp[R]-dp[L])

Measured memory_bytes: 57564
chomp($n = <>);
@x = split(/ /, <>);
@y = split(/ /, <>);

@x = reverse(@x);
@y = reverse(@y);

$r = 0;

for (0 .. ($n - 1)){
	if($y[$_] > $x[$_]){
		$r += $x[$_];
		$y[$_] -= $x[$_];
		if($y[$_] > $x[$_ + 1]){
			$r += $x[$_ + 1];
			$x[$_ + 1] = 0;
		}else{
			$r += $y[$_];
			$x[$_ + 1] -= $y[$_];
		}
	}else{
		$r += $y[$_];
	}
}

print "$r\n";


Measured memory_bytes: 23144
A,B,K = map(int,input().split())
ans = set()

l1 = min(B,A+K-1)
for i in range(A,l1+1):
    ans.add(i)
l2 = max(A,B-K+1)
for i in range(l2,B+1):
    ans.add(i)

ans = sorted(ans)
for a in ans:
    print(a)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

struct UnionFind{
    vector<ll> link;
    UnionFind(ll n):link(n,-1){}
    ll find(ll v){
        if(link[v]<0) return v;
        else return link[v]=find(link[v]);
    }
    bool unite(ll v,ll w){
        v=find(v),w=find(w);
        if(v==w) return 0;
        if(link[v]>link[w]) swap(v,w);
        link[v]+=link[w];
        link[w]=v;
        return 1;
    }
    bool same(ll v,ll w){
        return find(v)==find(w);
    }
};

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> a(m),b(m),ans(m);
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
    }
    UnionFind uf(n);
    ans[m-1]=n*(n-1)/2;
    for(ll i=m-1;i>=1;i--){
        if(uf.same(a[i],b[i])) ans[i-1]=ans[i];
        else ans[i-1]=ans[i]-uf.link[uf.find(a[i])]*uf.link[uf.find(b[i])];
        uf.unite(a[i],b[i]);
    }
    rep(i,m) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 6424
N, M = map(int, input().split())
ps = [input().split() for _ in range(M)]

correct = [0] * N
penalty = [0] * N
for p, s in ps:
    p = int(p)
    if correct[p-1] == 1:
        continue
    if s == 'AC':
        correct[p-1] = 1
    else:
        penalty[p-1] += 1
print(sum(correct), sum([p*c for p, c in zip(penalty, correct)]))

Measured memory_bytes: 40264
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a1[4],a2[4];
int main()
{
	scanf("%s ",a1);
	
	scanf("%s",a2);
	if(a1[0]==a2[2]&&a1[1]==a2[1]&&a1[2]==a2[0])
	printf("YES\n");
	else printf("NO\n");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF (2e9)

int main() {
  int n; cin >> n;
  int A[1000];
  int s = 10000;

  for(int i = 0; i < n; ++i){
    cin >> A[i];
    s = min(s, A[i]);
  }

  int B[1000];
  bool V[1000];
  for(int i = 0; i < n; ++i){
    B[i] = A[i];
    V[i] = false;
  }

  sort(B, B+n);

  int T[10001];
  for(int i = 0; i < n; ++i){
    T[B[i]] = i;
  }

  int ans = 0;
  for(int i = 0; i < n; ++i){
    if(V[i]) continue;
    int an = 0;
    int m = 10000;
    int S = 0;
    int cur = i;

    while(1){
      V[cur] = true;
      an++;
      int v = A[cur];
      m = min(m, v);
      S += v;
      cur = T[v];
      if(V[cur]) break;
    }
    ans += min(S+(an-2)*m, m+S+(an+1)*s);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3164
<?php
while($line=fgets(STDIN)){
    $line = rtrim($line);
    $data = explode(" ", $line);
    if ($data[0] < $data[1] && $data[1] < $data[2]) {
        echo "Yes". PHP_EOL;
    } else {
        echo "No" . PHP_EOL;
    }
}

Measured memory_bytes: 15280
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

	vector<int> p(n);
	vector<long long> c(n);

	for (int i = 0; i < n; ++i) {
		cin >> p[i];
		--p[i];
	}

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

	long long res = c[0];

	vector<int> used(n);

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

		vector<int> path;
		vector<long long> sum;
		long long csum = 0;
		int pscur = i;
		pscur = p[pscur];
		while (true) {
			if (used[pscur]) {
				break;
			}
			path.push_back(pscur);
			csum += c[pscur];
			sum.push_back(csum);
			used[pscur] = 1;
			pscur = p[pscur];
		}

		vector<long long> mx(sum.size());
		mx[0] = sum[0];
		for (int i = 1; i < mx.size(); ++i) {
			mx[i] = max(mx[i - 1], sum[i]);
		}

		if (k <= path.size()) {
			res = max(res, mx[k - 1]);
		} else {
			res = max(res, mx[(int)(path.size()) - 1]);
			int dofull = k / (int)(path.size());
			int rem = k % (int)(path.size());

			long long cadd = (rem == 0) ? 0 : mx[rem - 1];
			
			long long add = csum;
			res = max(res, csum * dofull + cadd);
			res = max(res, csum * (dofull - 1) + mx[(int)(path.size()) - 1]);
		}
	}
	cout << res << endl;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);

	int t;
	//cin >> t;
	t = 1;

	for (int tt = 0; tt < t; ++tt) {
		solve();
	}



	return 0;
}

Measured memory_bytes: 3864
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    N = int(input())
    Cs = [A-1 for A in map(int, input().split())]
    adjL = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        adjL[a].append(b)
        adjL[b].append(a)

    sizeSubtrees = [1] * N
    numVs = [0] * N
    anss = [0] * N

    def dfs(vNow, vPar, clrPar):
        clrNow = Cs[vNow]
        numVNow = numVs[clrNow]
        numVPar = numVs[clrPar]
        for v2 in adjL[vNow]:
            if v2 == vPar: continue
            dfs(v2, vNow, clrNow)
            sizeSubtrees[vNow] += sizeSubtrees[v2]
        numVs[clrNow] = numVNow + sizeSubtrees[vNow]
        if clrPar != -1:
            k = sizeSubtrees[vNow] - (numVs[clrPar]-numVPar)
            anss[clrPar] += k*(k+1)//2

    dfs(0, -1, -1)

    for clr in range(N):
        if clr == Cs[0]: continue
        k = N - numVs[clr]
        anss[clr] += k*(k+1)//2

    numAll = N*(N+1)//2
    anss = [numAll-ans for ans in anss]

    print('\n'.join(map(str, anss)))


solve()


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

const int MAX_N=105, MAX_K=1e5+2;

int N, K;
int a[MAX_N];
bool dp[MAX_K]; //whether player whose turn is next can win

void solve()
{
	dp[0] = false;
	for(int i=1; i<=K; ++i){
		dp[i] = false;
		for(int j=0; j < N; ++j){
			dp[i] |= a[j] <= i && !dp[i-a[j]];
		}
	}
	if(dp[K]) cout << "First" << endl;
	else cout << "Second" << endl;
}

int main()
{
	cin >> N >> K;
	for(int i=0; i<N; ++i) cin >> a[i];
	solve();
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    int N, A, sum = 0;
    cin >> N;
    rep(i, N) {
        cin >> A;
        sum += A - 1;
    }
    cout << sum << endl;
}


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

int main()
{
	int M,D;
	cin >> M >> D;
	int ans = 0;

	for (int i = 1; i <= M; ++i)
	{
		for (int j = 10; j <= D; ++j)
		{
			int a = j / 10;
			int b = j % 10;

			if ((a >= 2) && (b >= 2) && (i == a * b))
			{
				ans++;
				//cout << i << " " << j << endl;
			}
		}
	}

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

Measured memory_bytes: 256
import sys

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    table.sort(reverse=True)
    return table

def resolve():
    lines = sys.stdin.readlines()
    n, k = tuple(map(int, lines[0].split(' ')))
    a = list(map(int, lines[1].split(' ')))
    divs = divisor(sum(a))

    for div in divs:
        a_mod = list(map(lambda x: x % div, a))
        sum_mod = sum(a_mod)
        a_mod.sort(reverse=True)
        loop = sum_mod//div
        for i in range(loop):
            a_mod[i] = 0
        sum_e_mod = sum(a_mod)
        if k >= sum_e_mod:
            print(div)
            return
    print(1)

resolve()

Measured memory_bytes: 74024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> p;
  for(int i = 0; n > i; i++){
    int tmp;cin>>tmp;
    p.push_back(tmp);
  }
  sort(p.begin(),p.end(),greater<int>());
  int ret = 0;
  for(int i = 0; n > i; i++){
    if(i % 2 == 0)ret+=p[i];
    else ret-=p[i];
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 998244353;
const int N = 3010;
ll a[N];
ll n,s;
ll dp[N][N];

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main()
{
    quickread();
    cin >> n >> s;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    dp[0][0] = 1;
    for(int i = 1; i <= n; i ++) dp[i][0] = 2*dp[i-1][0] % mod;
    for(int i = 1; i <= n; i ++) {
        for(int j = 1; j <= s; j ++) {
            dp[i][j] = 2*dp[i-1][j];
            dp[i][j] %= mod;
            if(j >= a[i]) dp[i][j] += dp[i-1][j-a[i]];
            dp[i][j] %= mod;
            //cout << i << " " << j << ": " << dp[i][j] << endl;
        }
    }
    cout << dp[n][s] << endl;
    return 0;
}


Measured memory_bytes: 74220
#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>

using namespace std;

#define p 1000000007

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while(t--){
        int h,w;
        cin >> h >> w;
        vector<vector<char>> a(h,vector<char>(w));
        for(int i=0 ; i<h ; i++){
            for(int j=0 ; j<w ; j++){
                cin >> a[i][j];
            }
        }
        vector<vector<int>> dp(h,vector<int>(w,0));
        dp[0][0] = 1;
        for(int i=1 ; i<h ; i++){
            if(a[i][0]=='.')
                dp[i][0] = dp[i-1][0];
            else break;
        }
        for(int j=1 ; j<w ; j++){
            if(a[0][j]=='.')
                dp[0][j] = dp[0][j-1];
            else break;
        }

        for(int i=1 ; i<h ; i++){
            for(int j=1 ; j<w ; j++){
                if(a[i][j]=='.')
                    dp[i][j] = (dp[i-1][j] + dp[i][j-1])%p;
            }
        }
        cout << dp[h-1][w-1] << "\n";
    }
    return 0;
}



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


int main()
{
  int n,a[2][100];
  cin >> n;
  for(int i = 0;i < 2;i++){
    for(int j = 0;j < n;j++){
      cin >> a[i][j];
    }
  }
  int sum = 0;
  int max1 = -100000;

  for(int i = 0;i < n;i++){
    int i1 = 0;
    for(int j = 0;j < n;j++){
      if(j == i){
        i1 = 1;
        sum += a[0][j];
      }
      sum += a[i1][j];
    }
    max1 = max(max1,sum);
    sum = 0;
  }
  cout << max1 << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

func step(n int, a []int, mem []int) (ret int) {
  div := 1000000007

  if n == 0 {
    mem[0] = 1
    return 1
  }
  if n < 0 {
    return 0
  }
  ret = 0
  if a[n - 1] == 0 {
    if mem[n - 1] == -1 {
      ret += step(n - 1, a, mem) % div
    } else {
      ret += mem[n - 1]
    }
  }
  if n >= 2 {
    if a[n - 2] == 0 {
      if mem[n - 2] == -1 {
        ret += step(n - 2, a, mem) % div
      } else {
        ret += mem[n - 2]
      }
    }
  }

  ret %= div
  mem[n] = ret
  return
}

func main() {
  a := make([]int, 100002)
  mem := make([]int, 100002)

  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())

  sc.Scan()
  m, _ := strconv.Atoi(sc.Text())

  for i := 0; i < m; i++ {
    sc.Scan()
    input, _ := strconv.Atoi(sc.Text())
    a[input]++
  }

  for i := 0; i < n; i++ {
    mem[i] = -1
  }


  fmt.Println(step(n, a, mem))

}


Measured memory_bytes: 28928
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long ans = 0;
	string s;
	cin >> s;

	int n = s.length();
	int numB = 0;
	for(int i = 0; i < n; i++){
		string stone = s.substr(i, 1);
		if(stone == "B") numB++;
		else ans += numB;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 3752
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int dai[] = new int[n+1];
        boolean gDai[] = new boolean[n+1];
        int count = 0;

        for(int i = 1; i < n + 1; i++) {
            dai[i] = scan.nextInt();
            gDai[i] = true;
        }

        for(int i = 0; i < m; i++){
            int a = scan.nextInt();
            int b = scan.nextInt();
            if(!gDai[a] && !gDai[b]) continue;

            if(dai[a] > dai[b]) gDai[b] = false;
            else if(dai[a] < dai[b]) gDai[a] = false;
            else{gDai[a] = false; gDai[b] = false;}
        }

        scan.close();

        for(int i = 1; i < n + 1; i++) {
            if(gDai[i]) count++;
        }

        System.out.println(count);


    }
}

Measured memory_bytes: 59540
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.10lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};

int main(){
    int s,w;
    cin>>s>>w;
    if(w>=s)
        return cout<<"unsafe"<<endl,0;
    cout<<"safe"<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <stdio.h>
#include <tuple>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <stack>
#include <set>
//#include <complex>
#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222
#define fauto(it, c) for(__typeof((c).begin())  it=(c).begin();it!=(c).end();it++)

using namespace std;
//using namespace __gnu_pbds;
 
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}
 
//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

ll a[N], b[N], c[N];
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n + 1; i ++)
		cin >> a[i], c[i] = a[i];
	for(int i = 1; i <= n; i ++)
	{
		cin >> b[i];
	}		
	for(int i = 1; i <= n; i ++)
	{
		if(c[i] <= b[i])
		{
			b[i] -= c[i];
			c[i] = 0;

		}
		else
		{
			c[i] -= b[i];
			b[i] = 0;		
		}
		if(b[i] > 0)
		{
			if(c[i + 1] <= b[i])
			{
				b[i] -= c[i + 1];
				
				c[i + 1] = 0;
			}
			else
			{
				c[i + 1] -= b[i];
				b[i] = 0;
			}
		}
	}
	ll ans= 0;
	for(int i = 1; i <= n+1; i ++)
		ans += (a[i] - c[i]);
	cout << ans;


		

}

















Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int t,n,s,f;
	int sum;
	
	while(scanf("%d",&t)){
		if(t==0)
		break;
		scanf("%d",&n);
		sum=0;
		for(int i=0;i<n;i++){
			scanf("%d %d",&s,&f);
			sum+=f-s;
		}
		if(sum>=t)
		printf("OK\n");
		else
		printf("%d\n",t-sum);
	}
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  string s;
  int n,k;
  cin >> n >> k >> s;

  if(s[k-1] == 'A'){
    s[k-1]= 'a';
  }
  if(s[k-1] == 'B'){
    s[k-1]= 'b';
  }
  if(s[k-1] == 'C'){
    s[k-1]= 'c';
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
int N;
ll A[Nmax], X;

int main(){
	cin >> N >> X;
	for(int i=0; i<N; i++) cin >> A[i];

	ll ans = 0;
	for(int i=0; i<N-1; i++){
		if(A[i]+A[i+1]<=X) continue;
		ll t = min(A[i+1], A[i+1]+A[i]-X);
		ans += t;
		A[i+1] -= t;
		//cout << t << endl;
		if(A[i]+A[i+1] > X){
			t = A[i]+A[i+1]-X;
			ans += t;
			A[i] -= t;
			//cout << " " << t << endl;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
/* Author : Pranav Deshmukh
            PICT,Pune
   Purpose: Atcoder Contest ABC172
*/

#include<bits/stdc++.h>
using namespace std;

#define int             long long
#define dip(type,var)   type var; cin>>var;
#define w(x)            int x; cin>>x; while(x--)
#define mka(arr,n,type) type *arr=new type[n];
#define foi(i,n)		for(int i=0;i<n;i++)
#define mod             pow(10,9)+7
#define inf             1e18
#define endl			"\n"
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >

void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


int32_t main() {
	c_p_c();
	dip(int, a);
	cout << a + pow(a, 2) + pow(a, 3) << endl;
	return 0;
}


Measured memory_bytes: 4236
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define ll          long long
#define pii         pair<int, int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int, int>
#define mii         map<pii, int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define lb          lower_bound
#define ub          upper_bound

#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
 
#define track(x)                 cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
 
#define ed(i)       i.end()
#define mem(a)	    memset(a, 0, sizeof(a))

#define MOD         1000000007
int mult(int a,int b, int p=MOD){return ((a%p)*(b%p))%p;}
int add(int a, int b, int p=MOD){return (a + b + p)%p;}
int fpow(int n, int k, int p = MOD) {int r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int b) {a = max(a, b); }
void self_min(int &a, int b) {a = min(a, b); }
void self_add(int &a, int b, int p = MOD) { a += b; if(a >= p) a -= p;}
void self_sub(int &a, int b, int p = MOD) { a -= b; if(a < 0) a += p;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
const int INF = 1e9 + 5;
#define N	    	400001

int ans[N];
void solve(){
    int n, m;
    cin>>n>>m;
    int height[n+1];
    rep(i, 1, n+1)
        cin>>height[i];
    rep(i, 0, m) {
        int a, b;
        cin>>a>>b;
        if(height[a] > height[b]) 
            ans[b] = true;
        else if(height[a] < height[b])
            ans[a] = true;
        else
            ans[a] = ans[b] = true;
    }
    int cnt = 0;
    rep(i, 1, n+1)
        if(!ans[i])
            cnt++;
    cout<<cnt<<endl;

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


Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n,a,b;cin>>n>>a>>b;
  vector<int> p(n);
  rep(i,n)cin>>p[i];
  int cnt1=0,cnt2=0,cnt3=0;
  rep(i,n){
    if(p[i]<=a)cnt1++;
    else if(a<p[i]&&p[i]<=b)cnt2++;
    else cnt3++;
  }
  int ans=min({cnt1,cnt2,cnt3});
  cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX = 10 + 10;
char arr[MAX];
char tmp[MAX];
int main(){
  scanf("%s", arr);
  int len = strlen(arr);
  long long ans = 0;
  for(int i = 0 ; i < (1<<(len-1)) ; i++){
    memset(tmp, 0, sizeof(tmp));
    int now = 0;
    for(int j = 0 ; j < len ; j++){
      tmp[now++] = arr[j];
      if (i&(1<<j)) {
        tmp[now++] = ' ';
      }
    }
    long long t;
    int sum = 0, n = 0;
    while(~sscanf(tmp+sum, "%lld%n", &t, &n)) {
      ans += t;
      sum += n;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,s,s1;
long long js(long long x)
{
	long long ans;
	ans=b/x-a/x;
	if(a%x==0)ans++;
	return ans;
}
long long gcd(int x,int y)
{
	if(x%y==0)return y;
	return gcd(y,x%y);	
}
int main()
{
	cin>>a>>b>>c>>d;
	s=b-a+1;
	s=s-js(c)-js(d)+js(c*d/gcd(c,d));
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))




vector<vector<int>> get_forest_size(const vector<int> &u,const vector<int> &v){
	// 木で、ある頂点を除いた時にできる森の各木のサイズを出力 0-index
	// out[i][j] := 頂点iを取り除いてできた森のうちj個目の木のサイズ
	// 辺集合が引数
	vector<vector<int>> forest;//出力用
	int N = u.size() + 1;

	vector<int> us(N-1,0),vs(N-1,0);
	// us[i] := i番目の辺のv[i]側から見たu[i]側にある頂点数
	// vs[i] := i番目の辺のu[i]側から見たv[i]側にある頂点数

	set<int> connect[N];
	vector<int> num(N,0);
	vector<int> did(N-1,0);//1->uでやった 2->vでやった
	for(int i=0;i<N-1;i++){
		connect[u[i]].insert(i);
		connect[v[i]].insert(i);
	}
	queue<int> Q;//辺の番号が入る
	for(int i=0;i<N;++i){
		if(connect[i].size() == 1){
			Q.push( *connect[i].begin() );
		}
	}
	//葉の接続してる辺から取り除いていき、また葉ができら取り除いていく
	while( Q.size() ){
		int ie = Q.front();
		Q.pop();
		if(connect[u[ie]].size() == 1){
			us[ie] = num[u[ie]] + 1;
			num[v[ie]] += us[ie];
			connect[u[ie]].clear();
			connect[v[ie]].erase(ie);
			if(connect[v[ie]].size()==1){
				Q.push( *connect[v[ie]].begin() );
			}
			if(not did[ie]) did[ie] = 1;
		}else{
			vs[ie] = num[v[ie]] + 1;
			num[u[ie]] += vs[ie];
			connect[v[ie]].clear();
			connect[u[ie]].erase(ie);
			if(connect[u[ie]].size()==1){
				Q.push( *connect[u[ie]].begin() );
			}
			if(not did[ie]) did[ie] = 2;
		}
	}
	forest.resize(N);
	for(int i=0;i<N-1;i++){
		if(did[i]==1){
			vs[i] = N - us[i];
		}else{
			us[i] = N - vs[i];
		}
		forest[u[i]].push_back(vs[i]);
		forest[v[i]].push_back(us[i]);
	}
	return forest;
}



ll calc(ll a,ll b,ll p){//a^(b) mod p   
	if(b==0)return 1;
	ll y = calc(a,b/2,p);y=(y*y)%p;
	if(b & 1) y = (y * a) % p;
	return y;
}

int main(){
	ll N;
	cin >> N;
	vector<int> u(N-1),v(N-1);
	FOR(i,0,N-1){
		cin >> u[i] >> v[i];
		u[i]--;
		v[i]--;
	}
	auto fs = get_forest_size(u,v);
	ll ans = 0;
	FOR(i,0,N){
		ll sum = 0;
		for(auto s : fs[i]){
			sum += s;
			(ans += MOD - calc(2,s,MOD) + 1 ) %= MOD;
		}
		(ans += calc(2,sum,MOD)) %= MOD;
		(ans += MOD - 1) %= MOD;
	}
	(ans *= calc(calc(2,N,MOD),MOD-2,MOD)) %= MOD;
	cout << ans << endl;
}


Measured memory_bytes: 33536
n=int(input())

x=[list(map(int,input().split())) for _ in range(n)]

for i in range(101):
	for j in range(101):
		for k in range(n):
			if x[k][2]>0:
				h=x[k][2]+abs(i-x[k][0])+abs(j-x[k][1])
				break
		chk=0
		for k in range(n): 
			if x[k][2]!=max(h-abs(i-x[k][0])-abs(j-x[k][1]),0):
				chk=1
				break
		if chk==0:
			res=[i,j,h]
			break
	if chk==0:
		break

print(*res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,a[10000],cnt = 0,sum = 0;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++){
		int b;
		cin >> b;
		if(a[i] > b) sum += a[i] - b;
		else if(a[i] < b) cnt += (b - a[i]) / 2;
	}
	if(sum <= cnt) Yes();
	else No();
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;
const long long MOD = 1e9 + 7;

long long mfact(int n) {
    if (n == 1) return 1;
    else return n*mfact(n - 1)%MOD;
}

int main() {
    int N, M;
    cin >> N >> M;

    long long ans;
    if (N == M) {
        ans = 2*mfact(N)*mfact(M)%MOD;
    } else if (N == M + 1 || M == N + 1) {
        ans = mfact(N)*mfact(M)%MOD;
    } else {
        ans = 0;
    }

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

Measured memory_bytes: 1792
#include <iostream>
#include <bitset>
#include <algorithm>

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	const int MAX_VALUES = 101;
	bitset<101> bits;
	bitset<101> reversed;
	bits.flip();
	reversed.flip();
	int x, n, t;
	cin >> x >> n;
	if (n == 0) {
		cout << x;
		exit(0);
	}
	for (int i = 0; i < n; i++) {
		cin >> t;
		bits._Unchecked_reset(t);
		reversed._Unchecked_reset(MAX_VALUES - 1 - t);
	}
	if (bits[x]) {
		cout << x;
		exit(0);
	}
	int rV = bits._Find_next(x);
	int lV = MAX_VALUES - 1 - reversed._Find_next(MAX_VALUES - 1 - x);
	int d1 = abs(rV - x);
	int d2 = abs(lV - x);
	if (d1 < d2) {
		cout << rV;
	} else if (d2 < d1) {
		cout << lV;
	} else {
		cout << min(rV, lV);
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll x,y,z,a=0,b=0,c=0,d=0,sum,ans,total,cnt,n,m,k,p,kase,i;
string s1,s2;
#define N 100001
#define MX 1000000001
vector <ll> v;
map<ll,ll> mp;
set<ll> s;
map<ll,ll> :: iterator itr1, ptr1;
set<ll> :: iterator itr, ptr;


int main()
{

      cin>>a>>b>>d;


      x=min(a,b);
      y=max(a,b);
      c=0;
      for(i=x;i<=y;i++){
        if(i%d==0)c++;
      }

      cout<<c;




    return 0;
}
// Happy Coding  (:


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

#define P(s) cout<<s<<endl
#define All(c) c.begin(),c.end()

vector<int64_t> tbl;
vector<int64_t> r;

void MakeTbl(int n) {
    int64_t a = 1, b = 1;
    tbl.resize(n);
    r.resize(n);
    for (auto i=0; i<n; ++i) {
        tbl[i] = accumulate(All(tbl), 0) + a;
        r[i] = b;
        a *= 10;
        b *= 2;
    }
}

int main() {
    string s;
    cin >> s;
    int size = s.size();
    MakeTbl(size);
    
    int64_t sum = 0;
    for (auto i=0,ri=size-1; i<size; ++i,--ri) {
        sum += tbl[i] * (s[ri] - '0') * r[ri];
    }
    
    P(sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 250010
#define halt return puts("No"),0
inline int read() {
    int x=0;
    char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x;
}
int p[N],c[N],a[N];
int main() {
    int n=read();
    for (int i=1;i<=n;i++) p[i]=read();
    for (int i=1;i<=n*n;i++) {
        for (int j=1;j<=n;j++) if (p[j]==i) {
            if ((++c[j])!=j) halt; a[i]=j; break;
        }
        if (a[i]) continue;
        int Min=0;
        for (int j=1;j<=n;j++)
            if (c[j]<j-1 && (!Min || p[j]<p[Min])) Min=j;
        if (Min) {c[a[i]=Min]++;continue;}
        for (int j=1;j<=n;j++) 
            if (c[j]<n && p[j]<i) {c[a[i]=j]++;break;}
        if (!a[i]) halt;
    }
    puts("Yes");
    for (int i=1;i<=n*n;i++) printf("%d ",a[i]);
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define sz(v) (v).size()
#define debug(x) cerr << #x << "_=_" << x << "\n";
#define sum(n) ((n)*((n)+1)>>1)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;

const int MAXN = 1e5+5;
bool dp[MAXN], check[MAXN];
int a[MAXN];
int n, k;

bool f(int cnt){
    if(!cnt) return 0;
    if(check[cnt]) return dp[cnt];

    bool st=0;
    for (int i=0; i<n; i++){
        if(cnt-a[i]>=0)
            st |= !f(cnt-a[i]);
    }
    check[cnt]=1;
    return dp[cnt] = st;
}

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



    cin >> n >> k;
    for (int i=0; i<n; i++)
        cin >> a[i];

    memset(dp, -1, sizeof dp);

    if(f(k))
        cout << "First\n";
    else cout << "Second\n";




    return 0;
}

/*
1
9 3
111100000
 */

Measured memory_bytes: 5120
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] a = new int[3][3];
		boolean[][] af = new boolean[3][3];
		boolean flag = false;
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int n = sc.nextInt();
		int[] b = new int[n];
		for(int i = 0; i < n; i++) {
			b[i] = sc.nextInt();
			for(int j = 0; j < 3; j++) {
				for(int k = 0; k < 3; k++) {
					if(a[j][k] == b[i])af[j][k] = true;
				}
			}
		}
		for(int i = 0; i < 3; i++) {
			if(af[i][0]&&af[i][1]&&af[i][2])flag = true;
			if(af[0][i]&&af[1][i]&&af[2][i])flag = true;
		}
		if(af[0][0]&&af[1][1]&&af[2][2])flag = true;
		if(af[2][0]&&af[1][1]&&af[0][2])flag = true;

		if(flag)System.out.println("Yes");
		if(!flag)System.out.println("No");
	}

}


Measured memory_bytes: 21972
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>
using namespace std;

//long long a[100000];
//long long b[100000];

using namespace std;
 

//int cost[100000][100000];
int main(){
    string S;
    cin >> S;
    int ans = 1000;
    for(int i = 0; i < S.size() - 2; i++){
        string t = S.substr(i, 3);
        ans = min(ans, abs(753 - atoi(t.c_str())));
    }   
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    
    h = []
    for i in range(n):
        height = int(input())
        h.append(height)

    h.sort()

    minh = 10000000000
    for i in range(n - k + 1):
        d = h[i + k - 1] - h[i] 
        if d == 0:
            print(0)
            return
        
        if d < minh:
            minh = d
    
    print(minh)

if __name__ == '__main__':
    main()
    

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

int main(void){
   int r,c,sum;
   cin >> r >> c;
   int spread[100][100] = {{}};
   int sum1[100] = {};
   int sum2[100] = {};
   for (int i = 0; i < r; i++){
      for (int j = 0; j < c; j++){
         cin >> spread[i][j];
         sum1[i] += spread[i][j];
         sum2[j] += spread[i][j];
      }
   }
   for (int i = 0; i < r; i++){
      for (int j = 0; j < c; j++){
         cout << spread[i][j] << " ";
      }
      cout << sum1[i] << endl;
   }
   sum = 0;
   for (int k = 0; k < c; k++){
      cout << sum2[k] << " ";
      sum += sum2[k];
   }
   cout << sum << endl;
}



Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

void solve(){
  long long n, k, ans = 0, cnt = 0; cin >> n >> k;
  string s; cin >> s;
  for(int i = 0; i < n - 1; i++){
    if(s[i] == s[i + 1]) ans++;
  }
  for(int i = 1; i < n; i++){
    if(s[i] != s[i - 1]){
      cnt++;
      if(cnt % 2 == 0){
        ans += 2;
        if(cnt / 2 >= k) break;
      }
    }
  }
  if(cnt % 2 == 1) ans++;
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;

int main()
{
    int s[] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
    int x, y;
    cin >> x >> y;
    cout << (s[x] == s[y] ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define int long long

using namespace std;

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

    int n;
    cin >> n;
    if (n % 2 == 1) {
        cout << 0 << "\n";
        return 0;
    }
    n /= 2;

    int x = 5, res = 0;
    while (x <= n) {
        res += n / x;
        x *= 5;
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256