akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N;
  while(cin>>N,N){
	VI P(N), T(N);
	REP(i,N) cin >> P[i] >> T[i];
	if(P[0] > T[0]){
	  cout << "NG 1" << endl;
	  continue;
	}

	int dp[2][4];
	int crt = 0, nxt = 1;
	fill(dp[crt], dp[crt]+4, -1);
	dp[crt][1] = P[0];

	int NG = -1;
	for(int i=1;i<N;++i){
	  fill((int*)dp[nxt], (int*)dp[nxt]+4, -1);
	  for(int k=0;k<3;++k){
		if(dp[crt][k] < 0) continue;
		int dist = abs(P[i] - P[i-1]);
		int t = dist * (k+1);
		if(T[i-1] + t <= T[i])
		  dp[nxt][k+1] = dp[crt][k] + dist;
	  }
	  for(int k=1;k<4;++k){
		if(dp[crt][k] < 0) continue;
		int t1 = P[i-1] * (k+1), t2 = P[i] * 1;
		if(T[i-1] + t1 + t2 <= T[i]){
		  if(dp[nxt][1] < 0)
			dp[nxt][1] = dp[crt][k] + P[i-1] + P[i];
		  else
			dp[nxt][1] = min(dp[nxt][1], dp[crt][k] + P[i-1] + P[i]);
		}
	  }
	  swap(crt, nxt);

	  int j;
	  for(j=0;j<4;++j)
		if(dp[crt][j] >= 0) break;
	  if(j == 4){
		NG = i+1;
		break;
	  }
	}

	if(NG > 0) cout << "NG " << NG << endl;
	else{
	  int ans = 123456789;
	  for(int k=0;k<4;++k){
		if(dp[crt][k] < 0) continue;
		ans = min(ans, dp[crt][k] + P[N-1]);
	  }
	  cout << "OK " << ans << endl;
	}
  }
  
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n;
    cin >> n;
    map<string, ll> vote;
    string s;
    rep1(i, n){
        cin >> s;
        vote[s]++;
    }
    ll maxi = 0;
    for (auto& m: vote) maxi = max(maxi, m.second);
    for (auto& m: vote){
        if (m.second == maxi) cout << m.first << endl;
    }
}

Measured memory_bytes: 19260
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int childNo = sc.nextInt();
		int candy = 0;

		for (int i = 0; i < childNo; i++) {
			candy += i + 1;
		}
		System.out.println(candy);
		sc.close();
	}
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  int M;
  int X;
  int Y;
  cin >>N>>M>>X>>Y;
  
  vector<int> x(N+1);
  rep(i,N) {
cin >>x.at(i);
  }
  x.at(N)=X;
  vector<int> y(M+1);
  rep(i,M) {
    cin >>y.at(i);
  }
  y.at(M)=Y;
  sort(all(x));
  sort(all(y));
  int a=x.at(N);
  int b=y.at(0);
  if(b>a) {
cout <<"No War"<< endl;
  }
else {
cout <<"War"<< endl;
}
}
 

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

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> costs(n);
  for (auto& cost : costs) {
    cin >> cost;
  }
  vector<int> acc_cost(n);
  acc_cost.back() = 0;
  for (auto idx(n-2); idx >= 0; --idx) {
  	vector<int> sub_acc_cost(min(k, n - 1 - idx));
    for (auto gap(1); gap <= k; ++gap) {
      if (idx + gap >= n) {
          break;
      }
      sub_acc_cost[gap-1] = acc_cost[idx + gap] + abs(costs[idx] - costs[idx + gap]);
    }
    acc_cost[idx] = *min_element(sub_acc_cost.begin(), sub_acc_cost.end());
  }
  cout << acc_cost[0] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b >= c) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  switch(n){
  case 0: cout << 1 << endl; break;
  case 1: cout << 2 << endl; break;
  case 2: cout << 1 << endl; break;
  default: cout << 0 << endl; break;
  }
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#define ll long long
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;

ll p[20];
int dx1[20],dx2[20];
vector<ll> v;
ll d,tim;

void dfs(ll s,ll e,vector<pair<ll,ll> > &w,ll val,ll cnt)
{
	if(s==e)
	{
		w.push_back(make_pair(val,cnt));
		return;
	}
	for(int i=-9;i<=9;i++)
		dfs(s+1,e,w,val+i*v[s],cnt*(s==0?dx2[i+10]:dx1[i+10]));
}

int solve(int l)
{
	v.clear();
	ll ans=0;
	for(int i=0;l-i-1>i;i++)
		v.push_back(p[l-i-1]-p[i]);
	//for(auto u:v)cout<<u<<endl;
	vector<pair<ll,ll> > v1,v2;
	dfs(0,(v.size()+1)/2,v1,0,1);
	dfs((v.size()+1)/2,v.size(),v2,0,1);
	//for(auto i:v1)cout<<i.first<<" "<<i.second<<endl;
	map<ll,ll> mp;
	for(auto i:v2)mp[i.first]+=i.second;
	for(auto i:v1)ans+=mp[i.first+d]*i.second;
	if(l%2)ans*=10;
	return ans;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>d;
	p[0]=1;
	for(int i=1;i<20;i++)p[i]=p[i-1]*10;
	REP(i,10)REP(j,10)
		dx1[i-j+10]++;
	for(int i=1;i<10;i++)REP(j,10)
		dx2[i-j+10]++;
	ll ans=0;
	for(int i=2;i<=18;i++)ans+=solve(i);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 207048
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
limit = T[0]
answer = 1
counter = 1
for i in range(1,N):
    if T[i] - limit > K or counter == C:
        limit = T[i]
        counter = 1
        answer += 1
    else:
        counter += 1
print(answer)

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

#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200'005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

int a,b,c;

int x,y;

int A[MAXN], B[MAXN], C[MAXN];

priority_queue<int,vector<int>, greater<int>> q;

int main(){
    x=read();y=read();
    a=read();b=read();c=read();

    for(int i=1;i<=a;++i)A[i]=read();
    for(int i=1;i<=b;++i)B[i]=read();
    for(int i=1;i<=c;++i)C[i]=read();

    sort(A+1,A+1+a);
    sort(B+1,B+1+b);
    sort(C+1,C+1+c);

    LL ans=0;

    for(int i=a;i>=a-x+1;--i)q.push(A[i]), ans+=A[i];
    for(int i=b;i>=b-y+1;--i)q.push(B[i]), ans+=B[i];

    for(int i=c;i>=1;--i){
        if(C[i]>q.top()){
            ans-=q.top();
            q.pop();
            q.push(C[i]);
            ans+=C[i];
        }
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 2680
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);

		//??°????????????
		String line = sc.nextLine();
		String[] list = line.split(" ");
		//
		int dice[] = new int[6];
		//????????????????????????????´?
		for(int i = 0; i<6; i++){
			dice[i] = Integer.parseInt(list[i]);
			//System.out.println(dice[i]);
		}

		//??????????????°?????????
		int n = sc.nextInt();
		for(int i=0; i < n; i++){
			//Top?????¢?????????
			int top= sc.nextInt();
			//Front?????¢?????????
			int front = sc.nextInt();

			char[] action = {'N','N','N','E','N','N','N'};
			for(int j= 0; j<7; j++){
				//????????????????????¨????????¢????????´
				if(dice[1]==front){
					break;
				}
				//roll???????????? ???????????????1?????????
				roll(action[j], dice);

			}
			//?????????????????£??¢??????????????¨???
			//System.out.println("front=" +dice[1]);

			char[] action2 ={'E','E','E'};
			for(int k =0; k<3;k++){
				if(dice[0]==top){
				break;
			}
			//roll???????????? ???????????????1?????????
			roll(action2[k],dice);
			}
			//???????????????top??????????????¨???
			//System.out.println("top=" +dice[0]);
			//????????????????????´??????????????¨???
			System.out.println(dice[2]);
		}
	}
	//roll????????????  ????§? ???????????????
	public static  void  roll(char  action , int[] dice){
		//?????????????????¢??????
		int temp;
		switch(action){
			case'N':
				temp = dice[0];
				dice[0]= dice[1];
				dice[1]=dice[5];
				dice[5]= dice[4];
				dice[4] = temp;
				break;
			case'W':
				temp = dice[0];
				dice[0]= dice[2];
				dice[2]= dice[5];
				dice[5]= dice[3];
				dice[3]= temp;
				break;
			case'E':
				temp = dice[0];
				dice[0]= dice[3];
				dice[3]= dice[5];
				dice[5]= dice[2];
				dice[2]= temp;
				break;
			case'S':
				temp = dice[0];
				dice[0]= dice[4];
				dice[4]= dice[5];
				dice[5]= dice[1];
				dice[1]= temp;
				break;
		}
	}
}

Measured memory_bytes: 26140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

#define MAX 500
int maze[MAX][MAX];
bool isFriend2[MAX];
int n;

int dfs(int cur,int rem){
  if(rem==0) return 0;
  rep(i,n){
    if(maze[cur][i]){
      isFriend2[i] = true;
      dfs(i,rem-1);
    }
  }
}


int main(void){
  while(true){
    int m;
    cin>> n >> m;
    if(n+m == 0)break;
    rep(i,n){
      rep(j,n){
	maze[i][j] = 0;
      }
      isFriend2[i] = false;
    }
    rep(i,m){
      int a,b;
      cin >> a >> b ;
      --a,--b;
      maze[a][b] = maze[b][a] = 1;
    }
    dfs(0,2);
    int count = 0;
    loop(i,1,n)
      if(isFriend2[i]) count ++;
    cout<<count<<endl;
  }
}

Measured memory_bytes: 2136
#include<stdio.h>
int a[100050];
int main()
{
    int n,s1,s2,sum,minn;
    while(~scanf("%d",&n))
    {
        s1=0,s2=0,minn=10000000;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=0; i<n-1; i++)
        {
            s1+=a[i];
            s2=0;
            for(int j=n-1; j>i; j--)
            {
                s2+=a[j];
            }
            if(s1>=s2)
                sum=s1-s2;
            else sum=s2-s1;
            if(minn>sum)
                minn=sum;
        }
        printf("%d\n",minn);
    }
}


Measured memory_bytes: 128
a,b = map(int,input().split())

def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')
def cal(t):
    if 1<= t <10:
        return 1
    else:return 0

if cal(a)*cal(b):
    print(a*b)
else:
    print(-1)


Measured memory_bytes: 3060
N,K =map(int,input().split())
ans = []

if K > (N-1)*(N-2)//2:
    print(-1)
else:
    for i in range(N-1):
        ans.append([i+1,N])
    maco = (N-1)*(N-2)//2 -K
    count = 0
    s =False
    for i in range(N-1):
        i += 1
        if s:
            break
        for j in range(i-1):
            j+= 1
            if count == maco:
                s = True
            if s:
                break
            ans.append([i,j])
            count += 1
    print(N-1+count)
    anstr ="\n".join(["{} {}".format(i,j)for i,j in ans])
    print(anstr)



Measured memory_bytes: 3828
#include <stdio.h>
int partition(int, int);
int A[100000];
 
int main(){
  int i, p, n, c;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  p=0;
  c=partition(p, n-1);
  for(i=0; i<n; i++){
    if(i!=0) printf(" ");
    if(c==i) printf("[%d]", A[i]);
    else printf("%d", A[i]);
    }
  printf("\n");

  return 0;
}

int partition(int p, int r)
{
  int t, x, i, j;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++){
    if (A[j] <= x){
	  i = i+1;
	  t = A[i];
	  A[i] = A[j];
	  A[j] = t;
	}
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i+1;
}

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


int main () {

    long long  H ,W;
    cin >> H >> W;

    if(H == 1 || W == 1){
        cout << 1 << endl;
    }
    else if (H % 2 == 0 || W % 2 == 0){
        cout << H * W / 2 << endl;
    }else{
        cout << (H * W + 1)/2 << endl;
    }
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long int

#define MAX 100000

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    int N, a[MAX], r;
    cin>>N;
    for(int i = 0; i < MAX; i++){
        a[i] = 0;
    }
    for(int i = 0; i < N; i++){
        int n; cin>>n;
        a[n]++;
    }
    for(int i = 0; i < MAX-2; i++){
        int tmp = a[i]+a[i+1]+a[i+2];
        if(tmp>r) r = tmp;
    }
    cout<<r<<endl;
    return 0;
}

Measured memory_bytes: 640
N=int(input())

ans=[]
a=ord("a")
tmp=0
while N>0:
    tmp+=1
    if tmp==1:
        chrr=N%26-1
        if chrr<0:
            chrr+=26
        ans.append(chr(a+chrr))
    else:
        chrr=((N-1)//(26**(tmp-1)))%26
        if chrr<0:
            chrr+=26
        ans.append(chr(a+chrr))
    N-=26**tmp

print("".join(ans[::-1]))

Measured memory_bytes: 8992
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
using namespace std;
int tree[(int)2e5] = {0};
int MaxIdx;
int read(int idx){
    int sum = 0;
    while (idx > 0){
        sum += tree[idx];
        idx -= (idx & -idx);
    }
    return sum;
}


void update(int idx, int val){
    while (idx <= MaxIdx){
        tree[idx] += val;
        idx += (idx & -idx);
    }
    //FOR1(i, 5)cout << tree[i] << " ";cout << endl;

}

int readSingle(int idx){
    int sum = tree[idx]; // this sum will be decreased
    if (idx > 0){ // the special case
        int z = idx - (idx & -idx);
        idx--; // idx is not important anymore, so instead y, you can use idx
        while (idx != z){ // at some iteration idx (y) will become z
            sum -= tree[idx]; 
// substruct tree frequency which is between y and "the same path"
            idx -= (idx & -idx);
        }
    }   
    return sum;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n, m;cin >> n>> m;
    MaxIdx = m;
    vii ranges(n);
    FOR(i, n){
        cin >> ranges[i].first >> ranges[i].second; 
    }
    sort(ranges.begin(), ranges.end(), [](pii& a, pii& b){return a.second - a.first > b.second - b.first;});
    vi sum(m + 1);
    for(int i = 1; i <=m ;i++){
        while(!ranges.empty() && ranges.back().second - ranges.back().first + 1 <= i){
            update(ranges.back().first, 1);
            update(ranges.back().second +1, -1);
            ranges.pop_back();
        }
        int ans = 0;
        for(int j = i; j <=m; j+= i){
            ans += read(j);
//            cout << ans << " ";
        } 
        ans += ranges.size();
        cout << ans << endl;
    }
}




Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
#define  ll  long long
const int N=1e5+2;
ll wt[101],val[101],dp[101][N];
void KS(ll n,ll m)
{
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=m;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(wt[i-1]>j)
            {
                dp[i][j]=dp[i-1][j];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i-1]]+val[i-1]);
            }
        }
    }
    cout<<dp[n][m]<<"\n";
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t,i,j,n,m,l,r,k;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
    }
    KS(n,k);
    return 0;
}

Measured memory_bytes: 79232
Scanf.scanf "%d %d %d %d" (fun n m s t ->
    let s = s - 1 in
    let t = t - 1 in
    let yen = Array.make n [] in
    let snk = Array.make n [] in
    for i = 1 to m do
        Scanf.scanf " %d %d %d %d" (fun u v a b ->
            let u = u - 1 in let v = v - 1 in
            yen.(u) <- (a, v) :: yen.(u);
            yen.(v) <- (a, u) :: yen.(v);
            snk.(u) <- (b, v) :: snk.(u);
            snk.(v) <- (b, u) :: snk.(v);
        )
    done;
    let sentinel = max_int in

    let module S = Set.Make (struct type t = int * int let compare = compare end) in
    let dijkstra_from s nei =
        let dist = Array.make n sentinel in
        let rec loop set =
            if S.is_empty set then () else
                let ((cost, node) as elt) = S.min_elt set in
                let set = S.remove elt set in
                let set = List.fold_left (fun acc (c, next) ->
                    if dist.(next) > cost + c then (
                        dist.(next) <- cost + c;
                        S.add (cost + c, next) acc
                    ) else acc) set nei.(node)
                in
                loop set
        in
        dist.(s) <- 0;
        loop (S.singleton (0, s));
        dist
    in

    let d1 = dijkstra_from s yen in 
    let d2 = dijkstra_from t snk in 

    let maxes = Array.make n 0 in

    let rec loop i mx =
        if i < 0 then mx else
            let d = d1.(i) in
            let e = d2.(i) in
            if d = sentinel || e = sentinel then loop (i - 1) mx else
                let c = 1_000_000_000_000_000 - d - e in
                let m = max mx c in
                let () = maxes.(i) <- m in
                loop (i - 1) m
    in
    let _ = loop (n - 1) 0 in
    Array.iter (Printf.printf "%d\n") maxes;
)

Measured memory_bytes: 46844
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
#include <cstdlib>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}


int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s, t;
    cin>>s>>t;
    t.pop_back();
    if (s==t){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }

    return 0;
}





Measured memory_bytes: 3096
def prepare(n, MOD):
 
    # n! の計算
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f
     
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return fn, invs
X,Y = map(int,input().split())
A = X * 2 - Y
B = Y * 2 - X

if A < 0 or A % 3 != 0 or B % 3 != 0 or B < 0:
    print(0)
else:
    AB = (A + B) // 3
    M = max(A,B) // 3
    N,r = prepare(AB,10**9+7)
    print((N * r[M]*r[AB-M]) % (10 ** 9 + 7))

Measured memory_bytes: 29300
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define SORT(x) (sort(x.begin(),x.end()))
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;}   
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll dp[13][100007];

int main(){
    char s[100007];
    cin >> s;
    if(s[0]=='?'){
        rep(i,10){
            dp[i][0]=1;
        }
    }
    else{
        dp[ctoi(s[0])][0]=1;
    }
    if(strlen(s)>=2){
        rep(i,strlen(s)-1){
            if(s[i+1]=='?'){
                rep(k,10){
                    rep(j,13){                   
                        dp[(j*10+k)%13][i+1]+=dp[j][i];
                        dp[(j*10+k)%13][i+1]%=MOD;
                    }   
                }
            }
            else{
                rep(j,13){
                    dp[(j*10+ctoi(s[i+1]))%13][i+1]+=dp[j][i];
                    dp[(j*10+ctoi(s[i+1]))%13][i+1]%=MOD;
                }
            }
        }
    }
    cout << dp[5][strlen(s)-1] << endl;
}

Measured memory_bytes: 10496
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
int h,w;
int a[33];

int main(void){
  cin >> h >> w;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      char c;
      cin >> c;
      a[c-'a']--;
    }
  }
  sort(a,a+33);

  int a4 = (h/2)*(w/2);
  int a2 = (h%2)*(w/2) + (h/2)*(w%2);
  int a1 = (h%2)*(w%2);

  for(int i = 0; i < 33; i++){
    int x = -a[i];
    int f = min(a4,x/4);
    a4-=f;
    x-=f*4;
    
    f = min(a2,x/2);
    a2-=f;
    x-=f*2;    
    
    f = min(a1,x/1);
    a1-=f;
    x-=f*1;
    
    if(x){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    stack <char> s;
    while(n)
    {
        n--;
        int cur=(n)%26;
        s.push((char)(cur+'a'));
        n/=26;
    }
    while(!s.empty())
    {
        cout<<s.top();
        s.pop();
    }
}

Measured memory_bytes: 3628
s = input()
Aans = 0
Bans = 0
A=[]
B=[]
for i in range(len(s)):
    if i%2 == 0:
        A.append(0)
        B.append(1)
    else:
        A.append(1)
        B.append(0)

for i in range(len(s)):
    if int(s[i]) != A[i] :
        Aans += 1
    elif int(s[i]) != B[i] :
        Bans += 1
print(min(Aans,Bans))

Measured memory_bytes: 4848
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
	int x=0,f=1;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')    f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<1)+(x<<3)+ch-'0';
	return x*f;
}
inline void print(int x){
	if (x>=10)     print(x/10);
	putchar(x%10+'0');
}
int main(){
	int a=read(),b=read(),c=read(),k=read();
	int T=max(a,max(b,c));
	printf("%d\n",a+b+c-T+T*(1<<k));
	return 0;
}

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

int n,a[N];

int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}

bool solve(){
	int t=0;
	for (int i=1;i<=n;i++) t+=a[i]&1;
	if ((n-t)&1) return 1;
	if (t>1) return 0;
	for (int i=1;i<=n;i++){
		if (a[i]==1) return 0;
		a[i]&=0x7ffffffe;
	}
	t=a[1];
	for (int i=2;i<=n;i++) t=gcd(t,a[i]);
	for (int i=1;i<=n;i++) a[i]/=t;
	return !solve();
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	printf(solve()?"First\n":"Second\n");
	return 0;
}

Measured memory_bytes: 640
class Queue:
    def __init__(self, data=[]):
        self.data = data

    def enqueue(self, x):
        self.data.append(x)

    def dequeue(self):
        return self.data.pop(0)  # 先頭を取り出す

    def is_Empty(self):
        if len(self.data) == 0:
            return True
        else:
            return False


def bfs(cnt, t):
    adjacent = [(1, 0), (0, 1), (1, 1), (-1, 0), (0, -1), (-1, -1)]
    cnt = {}
    while not queue.is_Empty():
        cx, cy = queue.dequeue()

        cnt.setdefault((cx, cy), 0)
        if cnt[(cx, cy)] >= t:
            continue

        for a, b in adjacent:
            # if 0 > cx+a or 0 > cy+b:
            #     continue
            # if abs(cx+a) >= 61 or abs(cy+b) >= 61:
            #     continue
            if visited[cx+a][cy+b] == 1 or visited[cx+a][cy+b] == -1:
                continue
            cnt[(cx+a, cy+b)] = cnt[(cx, cy)] + 1
            queue.enqueue((cx+a, cy+b))
            visited[cx+a][cy+b] = 1


while True:
    t, n = map(int, input().split())  # ターン数t, 障害物の個数n
    if n == 0 and t == 0:
        break
    obstacles = [list(map(int, input().split())) for _ in range(n)]
    cx, cy = map(int, input().split())  # 初期位置

    visited = [[0]*121 for _ in range(121)]
    visited[cx+60][cy+60] = 1
    for x, y in obstacles:
        visited[x+60][y+60] = -1

    queue = Queue()
    queue.enqueue((cx+60, cy+60))
    bfs(0, t)
    ans = 0
    for row in visited:
        for x in row:
            if x >= 0:
                ans += x

    print(ans)
    # 非対象の座標もある



Measured memory_bytes: 6308
#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 RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N,M,K;
LL A[200001];
LL B[200001];
LL S[200001];
LL T[200001];
int main(){
	cin>>N>>M>>K;
	REP(i,N){
		cin>>A[i];
		if(i==0){
			S[i]=A[i];
		}else{
			S[i]=A[i]+S[i-1];
		}
	}
	REP(i,M){
		cin>>B[i];
		if(i==0){
			T[i]=B[i];
		}else{
			T[i]=B[i]+T[i-1];
		}
	}
	int ans=0;
	int now=0;
	for(int i=N-1;i>=0;i--){
		if(S[i]>K)continue;
		while(1){
			if(now==M)break;
			if(S[i]+T[now]<=K){
				now++;
			}else{
				break;
			}
		}
		ans=max(ans,i+1+now);
	}
	REP(i,M){
		if(T[i]<=K){
			ans=max(ans,i+1);
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

bool g[101][101];

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

    vector<ll> A(N),B(N);
    REP(i,N) cin >> A[i] >> B[i];

    reverse(all(A));
    reverse(all(B));

    ll ans=0;
    REP(i,N){
        A[i] += ans;
        ll j=(A[i]!=0?(A[i]+B[i]-1)/B[i]:0);
        ans += B[i]*j-A[i];
    }

    pl(ans)

    return 0;
}


Measured memory_bytes: 1792
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

A = list(map(int, input().split()))

minus_cnt = 0
for i in range(N):
    if A[i] < 0:
        minus_cnt += 1

ans = 0
min_val = 10**10
if minus_cnt % 2 == 0:
    for i in range(N):
        ans += abs(A[i])
else:
    for i in range(N):
        ans += abs(A[i])
        min_val = min(min_val, abs(A[i]))
    ans -= min_val * 2

print(ans)

Measured memory_bytes: 64752
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long long int> VLL;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    io;
    int x, y;
    cin >> x >> y;
    FOR (i, 0, x+1) {
        if (i*2 + (x-i)*4 == y) {
            goto good;
        }
    }
    cout << "No" << "\n";
    return 0;
    good: cout << "Yes" << "\n";
}
//check for edge cases in limits
//printing double may print 1.223232e9 like values, beware of that


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#define ll long long 
using namespace std;
ll N[100005];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>N[i];
	sort(N,N+n);
	cout<<N[n-1]<<" ";
	ll temp=(N[n-1]+1)/2;
	ll min1=1e9;
	int j=0;
	for(int i=0;i<n-1;i++)
	{
		if(abs(N[i]-temp)<min1)
		   {
		   	min1=abs(N[i]-temp);
		   	j=i;
		   }
	}
	cout<<N[j]<<endl;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, a, b, c);
    int ans = 0;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
        tie(a, b, c) = make_tuple<int, int, int>((b+c)/2, (c+a)/2, (a+b)/2);
        if(a == b && b == c){ ans = -1; break; }
        ans ++;
    }
    Cout(ans);
}


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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> penalty(N);
  int AC = 0;
  int WA = 0;
  for(int i = 0; i < M; i++){
    int p;
    cin >> p;
    p--;
    string S;
    cin >> S;
    if(S == "WA"){
      if(penalty[p] != -1){
	penalty[p]++;
      }
    }else{
      if(penalty[p] != -1){
	AC++;
	WA += penalty[p];
	penalty[p] = -1;
      }
    }
  }
  cout << AC << " " << WA << endl;
}


Measured memory_bytes: 640
import sys

A, B, C, D = list(input())

op = ["+", "-"]

for i in range(2):
    for j in range(2):
        for k in range(2):
            f = A + op[i] + B + op[j] + C + op[k] + D
            # print(f)
            if eval(f) == 7:
                print(f, "=7", sep="")
                sys.exit()


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeMap;
class Main{


	static final int MOD = 1000000007;


	static ArrayList<ArrayList<Pair>> map;
	static TreeMap<Integer,Integer> ans; 
	static int maxnum;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();

		double[] a = new double[n];
		double sum = 0;
		
		
		for(int i = 0;i < n;i++){
			a[i] = sc.nextDouble();
		}
		Arrays.sort(a);
		sum = a[0];
		for(int i = 1;i < n;i++){
			sum = (a[i] + sum)/2;
		}
		System.out.println(sum);

	}





	static int upperbond(int k,int min,int[] data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int max = data.length;
		//		if(min == data.length-1){
		//			if(data[min] > k){
		//				return min;
		//			}
		//		}

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}

		return max;
	}

	static int lowerbond(int k,int min,int[] data){		//kより大きい最小の値をdataの中から探し、返す二分探索
		int max = data.length;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return min;
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}

class Town{
	int index;
	int x ;
	int y;
	public Town(int index,int x,int y) {
		this.index = index;
		this.x = x;
		this.y = y;
		// TODO 自動生成されたコンストラクター・スタブ
	}


}


class Edge  implements Comparable{

	int index;
	HashSet<Integer> hen;
	HashSet<Integer> used;
	HashMap<Integer, Integer> map;
	int size;


	public Edge(int index) {
		// TODO 自動生成されたコンストラクター・スタブ
		this.index = index;
		hen = new HashSet();
		used = new HashSet<Integer>();
		map = new HashMap<Integer,Integer>();
	}

	public int compareTo(Object other) {
		Edge otherpair = (Edge)other;

		return   otherpair.hen.size() - hen.size();
	}
}

class Food implements Comparable{

	int minits;
	int score;
	double cospa;

	public Food(int from,int end,double c) {
		this.minits = from;
		this.score = end;
		this.cospa = c;
		// TODO 自動生成されたコンストラクター・スタブ
	}

	@Override
	public int compareTo(Object other) {
		Food otherpair = (Food)other;
		int dif = Double.compare(otherpair.cospa, cospa);
		return   dif;
	}

}

class Pair implements Comparable{
	int from;
	int end;
	public Pair(int from,int end) {
		this.from = from;
		this.end = end;
		// TODO 自動生成されたコンストラクター・スタブ
	}

	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  from - otherpair.from;
	}








}






Measured memory_bytes: 23380
import itertools

if __name__ == '__main__':

    n = int(input())
 

    town = [[]for i in range(n)]

    for i in range(n):
        x,y = map(int,input().split()) 
        town[i].append(x)
        town[i].append(y)
    

    p = [i for i in range(n)]
  

    p_list = list(itertools.permutations(p))

    total = 0
    for i in range(len(p_list)):
        sum = 0
    
        for j in range(n-1):
            x1,y1 = int(town[p_list[i][j]][0]), int(town[p_list[i][j]][1])
            x2,y2 = int(town[p_list[i][j+1]][0]), int(town[p_list[i][j+1]][1])
    
            sum = sum + ((x2-x1)**2+(y2-y1)**2)**0.5
       

        total = total + sum
       

    
    print(total/float(len(p_list)))

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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a, b;
	cin >> a >> b;
	if(a + b == 15) cout << "+\n";
	else if(a * b == 15) cout << "*\n";
	else cout << "x\n";
	return 0;
}


Measured memory_bytes: 256
/*In the name of ALLAH, Most Gracious, Most Merciful*/
#include<bits/stdc++.h>

#define ll                      long long int
#define ull                     unsigned long long int
#define PI                      2*acos(0.0)
#define sqr(x)                  (x)*(x)
#define EPS                     10E-10
#define MOD                     1000000007
#define longlimit               92233720368547758
#define infinity                (1<<28)
#define setbits                 __builtin_popcount
#define zerobits                __builtin_ctzll
#define pb(a)                   emplace_back(a)
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define gcd(a, b)               __gcd(a,b)
#define lcm(a, b)               ((a)*(b))/gcd(a,b)
#define watch(x)                cout << (#x) << " is " << (x) << endl
#define FOR(x,n)                for (ll i=x,j=x,k=x;i<n,j<n,k<n;i++,j++,k++)
#define FORR(n,x)               for (ll i=n-1,j=n-1,k=n-1;i>=x,j>=x,k>=x;i--,j--,k--)
#define TEST_CASES()            ll t;cin>>t;while (t--)
#define PRECISION(a,x)          fixed<<setprecision(x)<<a<<endl;
#define all(a)                  (a.begin()),(a.end())
#define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
#define DELETE(X)               (X).erase (remove (all(X)),(X).end())
#define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define FAST_IO()               ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FILE_IO()               freopen("output.txt", "w", stdout);freopen("input.txt", "r", stdin)
using namespace std;
ll tc=1;
int cnt[100005];
void solve()
{
   ll n,sum=0;
   cin>>n;
   while (n--)
   {
       ll a;cin>>a;
       cnt[a]++;
       sum+=a;
   }
   ll q;cin>>q;
   while (q--)
   {
       ll t,r;
       cin>>t>>r;
       if (cnt[t]>0)
       {
           ll num=cnt[t];
           sum-=(t*num);
           sum+=(r*num);
           cnt[r]+=num;
           cnt[t]=0;
           cout<<sum<<endl;
       }
       else cout<<sum<<endl;
   }
}

int32_t main()
{
    FAST_IO();
   // TEST_CASES()
        solve();
}

Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int count=0;
  int N=S.length();
//  cout << N << endl;
  for(int i=0;i<N;i++){
//  cout << S[i]-'0' << endl;
    if(S[i]-'0'==i%2){
      count++;
    }
  }
  if(count>N-count){
    cout << N-count << endl;
  }else{
    cout << count << endl;
  }
}


Measured memory_bytes: 512
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c;
    
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if(b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if(b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if(c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    else
        cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	int x;
	for(int i=1;i<=5;i++)
    {
        cin>>x;
        if(0==x)
        	cout<<i<<endl;
    }
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){

	int N, A[100010];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int cnt[100010];
	for (int i = 0; i < 100010; i++) {
		cnt[i] = 0;
	}
	for (int i = 0; i < N; i++){
		cnt[A[i]]++;
		cnt[A[i]+1 ]++;
		cnt[A[i]-1]++;
	}

	sort(cnt, cnt+100010,greater<int>());

	cout << cnt[0] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define TEST ll t;cin>>t;while(t--)
ll sizes[100001];
ll arr[100001];

bool ok=true;
ll A[100001];
pll B[100001];

ll root(ll i){
    while(i!=arr[i]) i=arr[i];
    return(i);
}
void Union(ll i,ll j){
    ll root_i=root(i),root_j=root(j);
    if(root_i==root_j) return;
    if(sizes[root_i]>sizes[root_j]) swap(root_i,root_j);
    sizes[root_j]+=sizes[root_i];
    arr[root_i]=arr[root_j];
    return;
}
bool prime[10000000];
vector<ll> v;
void era(){
    memset(prime,true,sizeof prime);
    for(int p=2;p*p<=10000000;p++){
        if(prime[p]){
            if(p%5==1) v.push_back(p);
            for(int q=p*p;q<=10000000;q+=p){
                prime[q]=false;
            }
        }
    }
    return;
}
ll power[11];
ll dif(string s,string p){
    ll a=(s[0]-'0')*100+(s[1]-'0')*10+(s[2]-'0');
    ll b=(p[0]-'0')*100+(p[1]-'0')*10+(p[2]-'0');
    return(abs(a-b));
}
int main(){
    IO
    string s;
    cin>>s;
    string p="753";
    ll minn=1000000;
    for(ll i=0;i+2<s.size();i++){
        string q="";
        q=s[i];
        q+=s[i+1];
        q+=s[i+2];

        minn=min(minn,dif(q,p));
    }
    cout<<minn;
    return(0);
}


Measured memory_bytes: 256