akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int b[n];
  for(int i=0;i<n;i++){
    if(a[i]==i+1){
      b[i]=1;
    }
    else{
      b[i]=0;
    }
  }
  for(int i=0;i<n-1;i++){
    if(b[i]==1&&b[i+1]==1){
      b[i+1]=2;
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(b[i]==1){
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main(){
  int h1, h2, k1, k2, a, b, c, d, H, K;

  cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;
  H = h1*a + (h1/10)*c + h2*b + (h2/20)*d;
  K = k1*a + (k1/10)*c + k2*b + (k2/20)*d;

  if ( H > K ) cout << "hiroshi" << endl;
  else if ( H < K ) cout << "kenjiro" << endl;
  else cout << "even" << endl;

  return 0;
}


Measured memory_bytes: 3076
#include<stdio.h>
int main(void)
{
	int h,w,c=0,i,j;
	char s[51][51];
	scanf("%d %d", &h, &w);
	for(i=0; i<h; i++)
	scanf("%s", &s[i]);
	for(i=0; i<h; i++)
	{
		for(j=0; j<w; j++)
		{
			if(s[i][j]=='#')
			{
				if(s[i][j-1]=='.'&&s[i][j+1]=='.'&&s[i-1][j]=='.'&&s[i+1][j]=='.')
				c=1;
			}
		}
	}
	if(c==0)
	printf("Yes\n");
	else
	printf("No\n");
	
	return 0;
}

Measured memory_bytes: 128
from math import *
import fractions
import sys
import collections
import itertools
import pprint
from collections import deque
from heapq import *
input=sys.stdin.readline
H,W,M=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(M)]
tate=[]
yoko=[]
for i in range(M):
    h,m=l[i]
    tate.append(h)
    yoko.append(m)
#print(tate,yoko)
t=collections.Counter(tate)
y=collections.Counter(yoko)
#print(t.most_common())
#print(y.most_common())
tmost=t.most_common()
ymost=y.most_common()
maxt=tmost[0][1]
maxy=ymost[0][1]
tkouho={}
ykouho={}
cntt=0
cnty=0
cnt=0
for i in range(len(tmost)):
    if tmost[i][1]==maxt:
        tkouho[tmost[i][0]]=1
        cntt=cntt+1
    else:
        break
for i in range(len(ymost)):
    if ymost[i][1]==maxy:
        ykouho[ymost[i][0]]=1
        cnty=cnty+1
    else:
        break
#print(tkouho,ykouho)
flag=0
for i in range(M):
    if (tkouho.get(l[i][0])!=None)and(ykouho.get(l[i][1])!=None):
        cnt=cnt+1
if cnty*cntt==cnt:
    print(maxt+maxy-1)
else:
    print(maxt+maxy)
"""
tatecount=0
yokocount=0
ans=0
maxt=tmost[0][1]
maxy=ymost[0][1]
tmosts=[]
ymosts=[]
for i in range(len(tmost)):
    if tmost[i][1]>=maxt-1:
        tmosts.append(tmost[i])
for i in range(len(ymost)):
    if ymost[i][1]>=maxy-1:
        ymosts.append(ymost[i])
print(tmosts,ymosts)

print(maxt,maxy)
ans=0
for tatecount in range(len(tmosts)):
    for yokocount in range(len(ymosts)):
        if d.get(tmost[tatecount][0])==None:
            ans = max(ans, tmost[tatecount][1] + ymost[yokocount][1])
            flag=1
            break
        elif d[tmost[tatecount][0]].get(ymost[yokocount][0])==None:
            ans = max(ans, tmost[tatecount][1] + ymost[yokocount][1])
            flag = 1
            break
        else:
            ans=max(ans,tmost[tatecount][1]+ymost[yokocount][1]-1)

print(ans)
"""

Measured memory_bytes: 236580
#include <iostream>
#define INF -99999999

using namespace std;

int N;
int a[10];

bool solve()
{
	bool flag = true;
	int b[11], c[11];
	b[0] = INF + 1;
	c[0] = INF;
	int p1 = 0,p2 = 0;
	for(int i = 0; i < 10; i++){
		if(a[i] > b[p1]){
			if(a[i] > c[p2]){
				if(b[p1] > c[p2])
					b[++p1] = a[i];
				else
					c[++p2] = a[i];
			}
			b[++p1] = a[i];
		}
		else if(a[i] > c[p2])
			c[++p2] = a[i];
		else{
			flag = false;
			break;
		}
	}
	return flag;
}

int main()
{
	cin >> N;
	while(N--){
		for(int i = 0; i < 10; i++)
			cin >> a[i];
		if(solve())
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e3+7;
char g[15][maxn];

int count1(int x)
{
    int ans = 0;
    for(int i=0;i<31;++i)if(x>>i&1)ans++;
    return ans;
}
int solve(int H,int W,int K)
{
    int ans = INT_MAX;
    for(int i=0;i<1<<(H-1);++i)
    {
        int now = 0;
        vector<int> acc(count1(i)+1,0);
        bool complete_fail = false;
        for(int j=1;j<=W;++j)
        {
            vector<int> add(count1(i)+1,0);
            bool flag = false;
            int p = 0;
            for(int k=1;k<=H;++k)
            {
                add[p] += g[k][j] == '1';
                if(acc[p] + add[p] > K) flag = true;
                if(add[p] > K) complete_fail = true;
                if(i>>(k-1)&1)
                    p++;
            }
            if(complete_fail)
            {
                break;
            }
            if(flag)
            {
                now++;
                for(int t=0;t<acc.size();++t)acc[t] = add[t];
            }else
            {
                for(int t=0;t<acc.size();++t)acc[t] += add[t];
            }
        }
        if(!complete_fail)
        {
            ans = min(ans,now+count1(i));
        }
    }
    return ans;
}
int main()
{
    int H,W,K;
    cin>>H>>W>>K;
    for(int i=1;i<=H;++i)cin>>g[i]+1;
    cout<<solve(H,W,K)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
using namespace std;

int W,H,i,j,k,l,p,m[3]={0,1,-1},h,w,sh,sw;
char D[10][21];
string T,R;
map<string,int> S;
int main()
{
	for(;scanf("%d%d\n",&H,&W),H;)
	{
		S.clear();
		R="0";
		for(i=k=0,l=1;i<H;i++)gets(D[i]);
		for(sh=0;sh<H;sh++)
			for(sw=0;sw<W;sw++)
				for(i=0;i<3;i++)
					for(j=0;j<3;j++)
					{
						if(i==0&&j==0)continue;
						T.clear();
						for(h=sh,w=sw,p=0;!(p!=0&&h==sh&&w==sw);h=(h+m[i]+H)%H,w=(w+m[j]+W)%W,p++)
						{
							T+=D[h][w];
							if(S.find(T)!=S.end())
							{
								if(R.length()<T.length()||(R.length()==T.length()&&R>T))
									R=T;
							}
							else
								S.insert(map<string,int>::value_type(T,1));
						}
					}
		cout<<R<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  double_t h;

  int count=0;
  int64_t ans=0;
  cin >> h;
  while(h>=1){
    h=h/2;
    count++;
    //cout <<  count << " " << h << endl;
  }
  for(int i=0;i<count;i++){
    ans = ans + pow(2,i);
    //cout << i << "   " << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools

s = input()
rlc = [len(list(itr)) for _, itr in itertools.groupby(s)]
for i in range(s[0] == '>', len(rlc) - 1, 2):
    if rlc[i] < rlc[i + 1]:
        rlc[i] -= 1
    else:
        rlc[i + 1] -= 1

print(sum(l * (l + 1) // 2 for l in rlc))


Measured memory_bytes: 8328
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k;
	scanf("%d",&k);
	if(k%2==0||k%5==0)printf("-1");
	else{
		if(k%7==0)k/=7;
		int r=1,s=r%k,l=1;
		while(s){
			r=r*10%k;
			s=(s+r)%k;
			l++;
		}
		printf("%d",l);
	}
} 

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define pb push_back
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define endl "\n"
#define pii pair<int,int>
#define mii map<int,int>
#define int long long int
#define fbo find_by_order
#define ook order_of_key
#define in insert
#define F first
#define S second
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a) for(auto ws: a)cout<<ws<<" "; cout<<endl
#define print1(a,b) for(int ws=0;ws<b;ws++) {cout<<a[ws]<<" ";} cout<<endl
#define all(a) a.begin(), a.end()
#define si set<int>
#define print2(a) for(auto ws: a)cout<<"("<<ws.F<<","<<ws.S<<") "; cout<<endl

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
const int N = 1e5 + 1;
bool vis[N];
vi g[N];
void init(int n, int e)
{
	for (int i = 0; i <= n; ++i)
	{
		vis[i] = false;
		g[i].clear();
	}
	for (int i = 0; i < e; ++i)
	{
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
	}
}
int longestpathfrom[N];
int dfs(int x)
{
	vis[x] = true;
	int path = 0;
	for (int i = 0; i < g[x].size(); ++i)
	{
		if (!vis[g[x][i]])
		{
			path = max(1 + dfs(g[x][i]), path);
		}
		else
		{
			path = max(1 + longestpathfrom[g[x][i]], path);
		}
	}
	return longestpathfrom[x] = path;
}
void solve()
{
	int n, m;
	cin >> n >> m;
	init(n, m);
	for (int i = 1; i <= n; ++i)
	{
		if (!vis[i])dfs(i);
	}
	cout << *max_element(longestpathfrom, longestpathfrom + n + 1) << endl;
}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt",  "r",  stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << setprecision(9) << fixed;
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 12652
N=int(input())
A=[int(x) for x in input().split()]
A.sort(reverse=True)
result=1
if 0 in A:
    print(0)

else:
    for i in A:
        result*=i
        if result>10**18:
            print(-1)
            break
    else:
        print(result)

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

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

    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    vector<ll> b(n);
    ll t = 0;
    ll m = 1e9;
    for (int i = n - 1; i >= 0; --i)
    {
        t += a[i];
        t %= (m + 7);
        b[i] = t;
    }

    ll ans = 0;
    for (int i = 0; i < n - 1; ++i)
    {
        ans += (a[i] * b[i + 1]);
        ans %= (m + 7);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6428
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
int b[4][4];
int c[4][4];
int t[30][7];
set<int>S;
int sz=24;
int pat[24][6]={
{1,2,3,4,5,6},
{1,3,5,2,4,6},
{1,4,2,5,3,6},
{1,5,4,3,2,6},
{2,6,3,4,1,5},
{2,3,1,6,4,5},
{2,1,4,3,6,5},
{2,4,6,1,3,5},
{3,1,2,5,6,4},
{3,2,6,1,5,4},
{3,6,5,2,1,4},
{3,5,1,6,2,4},
{4,2,1,6,5,3},
{4,1,5,2,6,3},
{4,5,6,1,2,3},
{4,6,2,5,1,3},
{5,1,3,4,6,2},
{5,3,6,1,4,2},
{5,6,4,3,1,2},
{5,4,1,6,3,2},
{6,4,5,2,3,1},
{6,2,4,3,5,1},
{6,3,2,5,4,1},
{6,5,3,4,2,1}
};
void solve(int a){
	if(a==27){
		int ret=0;
		for(int i=0;i<9;i++){
			ret+=t[i*3+2][2];
		}
		S.insert(ret);return;
	}
	for(int i=0;i<sz;i++){
		if(a<9&&b[2-a/3][a%3]&&b[2-a/3][a%3]!=pat[i][0])continue;
		if(a%9/3==0&&c[a/9][a%3]&&c[a/9][a%3]!=pat[i][1])continue;
		if(a%3&&pat[i][3]+t[a-1][2]!=7)continue;
		if(a%9/3&&pat[i][1]+t[a-3][4]!=7)continue;
		if(a/9&&pat[i][0]+t[a-9][5]!=7)continue;
		for(int j=0;j<6;j++)t[a][j]=pat[i][j];
		solve(a+1);
	}
}
int perm[6];
int main(){
	int T;scanf("%d",&T);

	while(T--){
		for(int i=0;i<3;i++)for(int j=0;j<3;j++)scanf("%d",&b[i][j]);
		for(int i=0;i<3;i++)for(int j=0;j<3;j++)scanf("%d",&c[i][j]);
		S.clear();
		solve(0);
		if(!S.size())printf("0\n");
		else{
			bool fi=false;
			for(set<int>::iterator it=S.begin();it!=S.end();it++){
				if(fi)printf(" ");
				fi=true;
				printf("%d",(*it));
			}
			printf("\n");
		}
	}
}

Measured memory_bytes: 1048
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
     	String s = sc.next();
      	int ans = 0;
      	for(int i=0;i<s.length();i++){
          int num = s.charAt(i)-48;
          ans = ( ans + num ) % 9 ;
        }
      	if( ans % 9 == 0 ){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
	}
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;

  if(a == b) cout << "Draw" << endl;
  else if(a == 1) cout << "Alice" << endl;
  else if(b == 1) cout << "Bob" << endl;
  else if(a > b) cout << "Alice" << endl;
  else cout << "Bob" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n;
  scanf("%d",&n);
  char a[n+1],b[n+1];
  scanf("%s",a);
  scanf("%s",b);
  for(int i=0;i<n;i++)
    printf("%c%c",a[i],b[i]);
  return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vec L(N);
    rep(i, N) cin >> L[i];
    sort(all(L));

    ll res=0;
    rep(i, N){
        Rep(j, i+1, N){
            int d = abs(L[i] - L[j]);
            // if(d > min(L[i], L[j])) continue;
            auto it = upper_bound(all(L), d);
            int dd = distance(L.begin(), it);
            if(i > dd) res += i - dd;
        }
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int h,w,n;
int mh[200005];
int main() {
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=h;i++) mh[i] = h+1;
	for(int i=1;i<=n;i++) {
		int x,y; scanf("%d%d",&x,&y);
		mh[x] = min(mh[x],y);
	}
	int rr=1;
	if(rr>=mh[2]) {
		puts("1"); return 0;
	}
	for(int i=2;i<=h;i++) {
		if(rr<=mh[i]-2) rr++;
		if(rr>=mh[i+1]) {
			printf("%d",i); return 0;
		}
	}
	printf("%d",h);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N;
  cin>>N;
  map<ll,ll>A;
  ll sum=0;
  for(ll i=0;i<N;i++){
    ll x;
    cin>>x;
    sum+=x;
    A[x]++;
  }
  ll Q;
  cin>>Q;
  ll COPY=sum;
  for(ll i=0;i<Q;i++){
    ll B,C;
    cin>>B>>C;
    if(A.find(B) != A.end()){
      sum-=B*A[B];
      //cout<<sum<<"on"<<endl;
      sum+=C*A[B];
      cout<<sum<<endl;
      A[C]+=A[B];
      A[B]=0;
      continue;
    }else{
      cout<<sum<<endl;  
    }
  }
}

Measured memory_bytes: 8564
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  cout << 48 - n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const ll INF = ll(2e18);
const int C = 550;
string s = "FESTIVA";

ll dp[C+1][7];
ll cnt[C+1];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll x; cin>>x;
	for(int i = 0; i < 7; i++) dp[1][i] = 1;
	for(int i = 2; i <= C; i++)
	{
		dp[i][0] = i;
		for(int j = 1; j < 7; j++)
		{
			dp[i][j] = dp[i-1][j]+dp[i][j-1];
			if(dp[i][j]>=INF) dp[i][j]=INF;
		}
	}
	ll ext = 5000 - C*7;
	for(int i = C; i >= 1; i--)
	{
		ll r = x/dp[i][6];
		ext-=r;
		cnt[i] = r;
		x -= r*dp[i][6];
	}
	for(int i = 1; i <= C; i++)
	{
		cout<<s;
		for(int j = 0; j < cnt[i]; j++)
		{
			cout<<"L";
		}
	}
	cout<<'\n';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
int main(){
    string s;
    cin>>s;
    string ans;
    if(s.compare("Sunny")==0)ans="Cloudy";
    else if(s.compare("Cloudy")==0)ans="Rainy";
    else ans="Sunny";
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll X = in<ll>();
    ll answer = 0;
    answer += (X/500)*1000;
    X %= 500;
    answer += (X/5)*5;
    cout << answer << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, a, b;
	cin >> a >> b;
	if (a <= b)
		printf("unsafe\n");
	else
		printf("safe\n");
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, a, b;std::cin >> n >> a >> b;
  string s;std::cin >> s;
  ll ok = 0;
  ll f = 0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='a'&&ok<a+b){
      ok++;
      std::cout << "Yes" << '\n';
    }else if(s[i]=='b'&&ok<a+b&&f<b){
      ok++, f++;
      std::cout << "Yes" << '\n';
    }else{
      std::cout << "No" << '\n';
    }
  }
}


Measured memory_bytes: 1080
#include<bits/stdc++.h>
using namespace std;
int a[55],n,k,sum,i;
bool cmp(int a,int b){
	return a>b;
}
int main(){
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=k;i++)
		sum+=a[i];
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 10

int n;
char s[MAXN+1];
long dp[MAXN+1][2];

int input() {
	if (scanf("%s", s) < 0) return 0;
	return 1;
}

void init() {
	memset(dp, 0, sizeof(dp));
	n = strlen(s);
	for (int i=0; i<n; i++) s[i] -= '0';
}

long solve() {
	dp[0][0] = 1;
	for (int i=0; i<n; i++) {
		long x = 0;
		for (int j=i; j<n; j++) {
			x = x*10 + s[j];
			dp[j+1][0] += dp[i][0];
			dp[j+1][1] += dp[i][1] + dp[i][0] * x;
		}
	}
	return dp[n][1];
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

VI tree_diameter(VVI &e){
    int n = e.size();
    VI dist(n, -1);
    queue<int> que;
    que.push(0);
    dist[0] = 0;
    while (!que.empty()){
        int x = que.front();
        que.pop();
        for (int y : e[x]){
            if (dist[y] == -1){
                dist[y] = dist[x] + 1;
                que.push(y);
            }
        }
    }
    int r = max_element(ALL(dist)) - dist.begin();
    dist.assign(n, -1);
    que.push(r);
    dist[r] = 0;
    while (!que.empty()){
        int x = que.front();
        que.pop();
        for (int y : e[x]){
            if (dist[y] == -1){
                dist[y] = dist[x] + 1;
                que.push(y);
            }
        }
    }
    int s = max_element(ALL(dist)) - dist.begin();
    VI ret;
    while (s != r){
        ret.push_back(s);
        for (int x : e[s]){
            if (dist[x] == dist[s] - 1){
                s = x;
                break;
            }
        }
    }
    ret.push_back(r);
    return ret;
}

int main() {
    int n;
    cin >> n;
    VVI e(n);
    REP(i,n-1){
        int u = in() - 1, v = in() - 1;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    VI ds = tree_diameter(e);
    int d = ds.size();

    cout << (d % 3 == 2 ? "Second" : "First") << endl;

    return 0;
}


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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);

    int k;
    long long sum = 0;
    cin >> k;
    for(int a = 1; a <= k; a ++){
        for(int b = 1; b <= k; b ++){
            for(int c = 1; c <= k; c ++){
                sum += __gcd(__gcd(a, b), c);
            }
        }
    }
    cout << sum << "\n";
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
#define ll long long
ll a,b;
int aa[maxn];
int bb[maxn];
int n;
ll len(ll l,ll r)
{
    return max(0LL,r-l+1);
}
int main()
{
    cin>>a>>b;
    if(a==b)
    {
        puts("1");
        exit(0);
    }
    while(b>0)
    {
        bb[n++]=b&1;
        b>>=1;
    }
    reverse(bb,bb+n);
    for(int i=0;i<n;++i)
    {
        aa[i]=a&1;
        a>>=1;
    }
    reverse(aa,aa+n);
    int now=0;
    while(now<n&&aa[now]==bb[now]) ++now;
    ll bas=1;
    a=b=0;
    for(int i=n-1;i>=now;--i)
    {
        a+=aa[i]*bas;
        b+=bb[i]*bas;
        bas<<=1;
    }
    ll T=bas/2;
    ll ans=T-a;
    int n1=now+1;
    while(n1<n&&bb[n1]==0) ++n1;
    ll S=1;
    for(int i=n-1;i>=n1;--i) S<<=1;
    //printf("a=%I64d,b=%I64d,T=%I64d,S=%I64d,n1=%d\n",a,b,T,S,n1);
    ans+=len(a+T,2*T-1)+len(T,T+S-1)-len(a+T,T+S-1);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int X = sc.nextInt();
        int T = sc.nextInt();
        int count = 1;
      
        while (N > X) {
        	N -= X;
        	count++;
        }
      
        T = T * count;
        System.out.println(T);
    }
}

Measured memory_bytes: 35368
#include <iostream>

 using namespace std;

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   m = i / 60 - h * 60;
   s = i % 60;
   cout << h << ":" << m << ":" << s << endl;

   return 0;
}


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

int main() {
  long long x;
  cin >> x;
  long long ans = 0;
  if (x % 11 >= 7 || x % 11 == 0) {
    ans += 2;
  } else {
    ans++;
  }
  if (x % 11 == 0) {
    ans += 2 * (x / 11) - 2;
  } else {
    ans += 2 * (x / 11);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for (int i = 0; i < t; i++)
		{
			int clime = 0, down = 0;
			int pre = -1;
			int n = sc.nextInt();
			for (int j = 0; j < n; j++)
			{
				if (pre == -1)
				{
					pre = sc.nextInt();
				}
				else
				{
					int now = sc.nextInt();
					clime = Math.max(clime, now - pre);
					down = Math.min(down, now - pre);
					pre = now;
				}
			}
			System.out.printf("%d %d\n", clime, -down);
		}
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 22;
const int MAXM = 1000010;
const int MAXK = 100010;
const int MAXQ = 200010;

int n, a[MAXN][MAXN];
ll dp[MAXN][2100000];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) FOR(j,1,n) cin >> a[i][j];
    dp[0][0] = 1;
    FOR(i,1,n)
        FOR(mask,1,(1<<n)-1) {
            if (__builtin_popcount(mask) != i) continue;
            FOR(j,1,n)
                if (mask & (1<<(j-1)))
                    if (a[i][j]) {
                        int mask2 = mask ^ (1<<(j-1));
                        dp[i][mask] = (dp[i][mask] + dp[i-1][mask2]) % MODBASE;
                    }
        }
    cout << dp[n][(1<<n)-1];
    return 0;
}


Measured memory_bytes: 309504
#include <bits/stdc++.h>
#define  f first
#define s second
#define vi vector<int>
#define pb emplace_back
#define ll long long int
#define vll vector<long long int>
#define vpi vector<pair<int,int>>
#define bit(x) __builtin_popcount(x)
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i=0 ; i<n ; ++i)
#define deb(x) cout << #x << " - " << x << endl;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;
const ll MAX_N = 1e5 + 7;

using namespace std;

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

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdint>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= M; j++) {
            if(i * M + j * N - 2 * (i * j) == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <cassert> 
#include <vector> 
#include <cmath> 
#include <ctime> 
#include <cstdlib> 
#include <fstream> 
#include <string> 
#include <sstream> 
#include <iterator> 
#include <map> 
#include <algorithm> 
#include <memory> 
#include <iomanip> 
#include <limits> 
#include <typeinfo> 
#include <queue> 

//------------------------

#include <stdio.h> 
#include <string.h> 


using namespace std;

int main()
{
   int X,Y,Z;
   int space;

   cin >> X >> Y >> Z;

   space = (int)(X-Z)/(Y+Z);

   cout << space << endl;

   return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    int h, w;
    char[][] cs;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        h = sc.nextInt();
        w = sc.nextInt();
        cs = new char[h][];
        sc.nextLine();
        for (int i = 0; i < h; i++) {
            cs[i] = sc.nextLine().toCharArray();
        }
    }

    private void solve() {
        int[][] ans = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int cnt = 0;
                for (int dx = -1; dx <= 1; dx++) {
                    for (int dy = -1; dy <= 1; dy++) {
                        if (dx == dy && dx == 0)
                            continue;
                        int x = dx + j;
                        int y = dy + i;
                        if (x >= 0 && x < w && y >= 0 && y < h) {
                            if (cs[y][x] == '#')
                                cnt++;
                        }
                    }
                }
                ans[i][j] = cnt;
            }
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (cs[i][j] == '#')
                    System.out.print('#');
                else
                    System.out.printf("%d", ans[i][j]);
            }
            System.out.println();
        }
    }
}


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

int main() {
  int N, K; cin >> N >> K;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
  ll ans {};
  int mask {};
  K++;
  for (int b = 30; b >= 0; b--) {
    mask ^= (1 << b);
    if (K & (1 << b)) {
      ll sum {};
      for (int i = 0; i < N; i++) {
          if ((A[i] & mask) == 0) sum += B[i];
      }
      ans = max(ans, sum);
      mask ^= (1 << b);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void doIt() {
		sB();
	}

	void sB() {
		int N = sc.nextInt();
		int jpy = 0;
		double btc = 0.0;
		for(int i = 0; i < N; i++) {
			String xs = sc.next();
			if(sc.next().equals("JPY")) {
				jpy += Integer.parseInt(xs);
			}
			else btc += Double.parseDouble(xs);
		}
		double ans = jpy + btc * 380000;
		System.out.println(ans);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> B(M);
  
  for(int m=0;m<M;m++){
    cin >> B.at(m);
  }
  
  int ans=0;
  vector<vector<int>> data(N, vector<int>(M));
  for(int n=0;n<N;n++){
    for(int m=0;m<M;m++){
      cin >> data.at(n).at(m);
    }
  }
  
  int check=0;
   for(int n=0;n<N;n++){
    for(int m=0;m<M;m++){
     check+= data.at(n).at(m)*B.at(m);
    }
     check+=C;
     if(check>0){ans++;}
     check=0;
   }
  cout <<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] d = new int[n];
    int count = n;

    for (int i = 0; i < n; i++) {
      d[i] = sc.nextInt();
    }

    Arrays.sort(d);

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

    System.out.println(count);


  }

}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

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

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)

#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N;


int main(){
  cin >> N;
  int D = 61;
  ll dp0[D], dp1[D], dp2[D];
  dp0[D - 1] = 1;
  dp1[D - 1] = 0;
  dp2[D - 1] = 0;
  RREP(i, D - 1) {
    int crt = (N >> i) & 1 ;
    if(crt == 1) {
      dp0[i] = dp0[i + 1];
      dp1[i] = (dp0[i + 1] + dp1[i + 1]) % MOD;
      dp2[i] = (dp1[i + 1] * 2 % MOD + dp2[i + 1] * 3 % MOD) % MOD;
    } else {
      dp0[i] = (dp0[i + 1] + dp1[i + 1]) % MOD;
      dp1[i] = dp1[i + 1];
      dp2[i] = (dp1[i + 1] + dp2[i + 1] * 3 % MOD) % MOD;
    }
  }
  
  cout << ((dp0[0] + dp1[0]) % MOD + dp2[0]) % MOD << endl;


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <unordered_map>
#include <assert.h>
using namespace std;

#define ran(i, a, b) for ((i) = (a); (i) < (b); (i)++)
#define rep(i, a) ran ((i), 0, (a))
#define rep1(i, a) ran ((i), 1, (a)+1)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
#define _0 first
#define _1 second
#define _pb(x) push_back(x)
#define _mp(x, y) make_pair(x, y)
#if defined(SHIROKO1_LOCAL) && !defined(NDEBUG)
#define DEBUG(...) fprintf(stderr, "[DEBUG] " __VA_ARGS__)
#else
#define DEBUG(...) ((void)0)
#endif



int main()
{
	if (getchar() == '9' || getchar() == '9')
		puts("Yes");
	else
		puts("No");
	return 0;
}


Measured memory_bytes: 256
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#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(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) (a)<=(i) && (i)<(b)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;

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

  int n;
  cin >> n;

  int ans = 0;
  REP(i,4){
    if(n % 10 == 2) ans++;
    n /= 10;
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n+1),b(n);
    cins(all(a));
    cins(all(b));
    ll cnt = 0;
    rep(i,n){
        if (a[i] >= b[i]){
            cnt += b[i];
        }
        else{
            b[i] -= a[i];
            cnt += a[i];
            if (a[i+1] >= b[i]){
                cnt += b[i];
                a[i+1] -= b[i];
            }
            else{
                cnt += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    PRINT(cnt);
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int alice = 0, bob = 0;
    rep(i, n) {
        if (i%2==0) alice += a[i];
        else bob += a[i];
    }
    cout << alice - bob << endl;
    return 0;
}


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

const int md = (1.0e+9) + 7;
vector<int> vec(101, -1);
vector<int> vecg(101, -1);

long long calc(int N);
long long calcg(int N);

long long calc(int N) {
	if (N < 0) return 0;
	if (vec[N] != -1) return vec[N];

	long long ans;
	ans = 4 * calc(N - 1) - 2 * calc(N - 3) - 3 * calc(N - 4) - calcg(N - 2) + calcg(N - 3);

	while (ans < 0) ans += md;
	ans %= md;
	vec[N] = ans;
	return ans;
}

long long calcg(int N) {
	if (N < 0) return 0;
	if (vecg[N] != -1) return vecg[N];

	long long ans;
	ans = calc(N - 1) - calc(N - 3) + calcg(N - 3);

	while (ans < 0) ans += md;
	ans %= md;
	vecg[N] = ans;
	return ans;
}

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

	vec[0] = 1;
	vecg[0] = 0;

	cout << calc(N) << endl;
}

Measured memory_bytes: 256
iter_num = int(input())
num = input().split()
num = sorted([int(i) for i in num])

num_bin = [format(int(i),'b') for i in num]
max_len = len(num_bin[-1])

num_bin = [format(i, '0>{}'.format(max_len)) for i in num_bin]

tmp = []
for i in range(len(num_bin[0])):
  tmp_num = 0
  for j in num_bin:
    tmp_num += int(j[i])
  if tmp_num%2==0: tmp_num=0
  tmp.append(tmp_num)

flg = 0
for i in tmp:
  if i==0: pass
  else:
    flg = 1
    print('No')
    break
if flg == 0: print('Yes')
  

Measured memory_bytes: 19588
#include <stdio.h>
int main()
{
  int A[100], i, j, N, v=0, t=0;

  scanf("%d",&N);
  for(i=0 ; i<N ; i++)
    scanf("%d",&A[i]);
  while(1){
    printf("%d",A[t]);
    t++;
    if(t == N)break; 
    printf(" ");
    }
    t = 0;
    printf("\n");

  for(i=1 ; i<N ; i++){
    v = A[i];
    j = i-1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    while(1){
      printf("%d",A[t]);
      t++;
      if(t == N)break; 
      printf(" ");
    }
    t = 0;
    printf("\n");
    }
    return 0;
  }

Measured memory_bytes: 604
import sys
from itertools import accumulate

readline=sys.stdin.readline
read=sys.stdin.read

def main():
  q,*lr=map(int,read().split())
  n=10**5
  ansl=[]
  sieve=[1]*(n+1)
  sieve[0],sieve[1]=0,0
  for i in range(2,n):
    if sieve[i]:
      sieve[2*i::i]=[0 for _ in range(2*i,n+1,i)]
  ans=[0]*(n+1)
  for i in range(3,n):
    if sieve[i]==1 and sieve[(i+1)//2]==1:
      ans[i]=1
      #ans[i]=ans[i-1]+1
    #else:
      #ans[i]=ans[i-1]
  
  ans=list(accumulate(ans))
  for l,r in zip(*[iter(lr)]*2):
    print(ans[r]-ans[l-1])

if __name__=='__main__':
  main()


Measured memory_bytes: 31912
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  char c[6];
  bool flag = true;
  for(int i = 0; i < 3; i++) cin>>c[i];
  for(int i = 0; i < 3; i++) cin>>c[i+3];
  for(int i = 0; i < 3; i++){
    if(c[i]!=c[5-i]) flag = false;
  }
  if(flag) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    Bottle[] bottles = new Bottle[N];
    for (int i = 0; i < N; i++) bottles[i] = new Bottle(scanner.nextInt(), scanner.nextInt());
    Arrays.sort(bottles, Comparator.comparingInt(bottle -> bottle.price));

    long left = -1;
    long right = 100_000_000_000_000L;
    while (right - left > 1) {
      long mid = (left + right) / 2;
      long k = mid;
      int n = 0;
      for (int i = 0; i < N; i++) {
        if ((long) bottles[i].price * bottles[i].cap < k) {
          n += bottles[i].cap;
          k -= (long) bottles[i].price * bottles[i].cap;
        } else {
          n += k / bottles[i].price;
          break;
        }
      }
      if (n >= M) {
        right = mid;
      } else {
        left = mid;
      }
    }
    System.out.println(right);
  }

  private static class Bottle {
    private final int price;
    private final int cap;

    private Bottle(int price, int cap) {
      this.price = price;
      this.cap = cap;
    }
  }
}


Measured memory_bytes: 94232