akhauriyash/Code-Regression huggingface dataset:
from collections import Counter

n = int(input())

nums = tuple(map(int, input().split()))

count = Counter(nums)
s = sum(nums)

answers = []
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    s = s + (c - b) * count[b]
    count[c] += count[b]
    count[b] = 0
    answers.append(s)
    
for answer in answers:
    print(answer)

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



int main()
{
  vector<int> A;
  int N;
  int sw = 0;

  cin >> N;
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    A.push_back(a);
  }

  for (int i = 0; i < N-1; i++)
  {
    for (int j = N-1; j >= i+1; j--)
    {
      if (A[j] < A[j-1])
      {
        sw++;
        int tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
      }
    }
  }

  for (int i = 0; i < N; i++)
  {
    cout << A[i];
    if (i != N-1) cout << ' ';
  }
  cout << endl;
  cout << sw << endl;
}

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

int main(void) {
	int n;
	cin >> n;
	vector<long long> h(n);
	for(int i = 0; i < n; ++i) cin >> h[i];

	bool is_possible = true;
	for(int i = 1; i < n; ++i) {
		if(h[i] > h[i-1]) --h[i];
		else if(h[i] < h[i-1]) {
			is_possible = false;
			break;
		}
	}

	cout << (is_possible ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


int a, b;
bool grid[114][114];
signed main() {
	cin >> a >> b;
	rep(i, 50)rep(j, 100)grid[i + 50][j] = 1;
	rep(i, a - 1) {
		grid[99 - i / 50 * 2][i % 50 * 2] = 0;
	}
	rep(i, b - 1) {
		grid[i / 50 * 2][i % 50 * 2] = 1;
	}
	cout << 100 << " " << 100 << endl;
	rep(i, 100) {
		rep(j, 100) {
			cout << (grid[i][j] ? "#" : ".");
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    rep(i, n) if (i % 2 == 0) cout << s[i];
    cout << endl;
    return 0;
}

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

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

const int INF = 1000000007;

int main(void){
	int n; cin>>n;
	int a[100010] = {0};
	for(int i=0;i<n;i++) cin>>a[i];

	int cnt_i[100010+2] = {0}, minus1[100010], plus1[100010];
	fill(minus1, minus1 + 100010, -1); fill(plus1, plus1 + 100010, -1);
	for(int i=0;i<n;i++) {
		if(a[i] != 0) minus1[i] = a[i] - 1;
		plus1[i] = a[i] + 1;
	}

	//cout<< " inus1[i]" <<endl;
	//for(int i=0;i<n;i++) cout<< minus1[i] <<endl;

	for(int i=0;i<n;i++) {
		if(minus1[i] != -1) {
			cnt_i[minus1[i]]++;
			cnt_i[a[i]]++;
			cnt_i[plus1[i]]++;
		}
		else {
			cnt_i[a[i]]++;
			cnt_i[plus1[i]]++;
		}
	}

	sort(cnt_i, cnt_i + 100005, greater<int>());

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

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

using namespace std;

int main() {
    int N, total;
    cin >> N;
    int t = N;
    while (t > 0) {
        total += t % 10;
        t /= 10;
    }
    if (N % total == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int N, M, C; cin >> N >> M >> C;
  vector<int> B(M);
  int A[N][M];
  for(int i = 0; i < M; ++i) {
    cin >> B[i];
  }
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < M; ++j) {
      cin >> A[i][j];
    }
  }
  int cnt = 0;
  for(int i = 0; i < N; ++i) {
    int tmp=0;
    for(int j = 0; j < M; ++j) {
      tmp += A[i][j]*B[j];
    }
    if(tmp + C > 0) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
import bisect


def six_nine(n):
    if n < 6:
        return n
    else:
        six = six_list[bisect.bisect_right(six_list, n) - 1]
        nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
        return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))


if __name__ == '__main__':
    x = int(input())
    six_list = [6 ** i for i in range(7)]
    nine_list = [9 ** i for i in range(6)]
    print(six_nine(x))

Measured memory_bytes: 42200
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
int main(){
	string s;
	int n;

	int eb = 0; // # of black on even
	int ew = 0; // # of white on even
	int ob = 0; // # of black on odd
	int ow = 0; // # of white on odd

	// read values
	cin >> s;
	n = s.length();

	// some processing here
	for (size_t i = 0; i < n; ++i) {
		if (i % 2 == 0) {
			if(s.at(i) == '0') {
				eb++;
			} else {
				ew++;
			}
		} else {
			if(s.at(i) == '0') {
				ob++;
			} else {
				ow++;
			}
		}
	}

	int return_value = 0;
	if (eb >= ew && ow >= ob) {
		return_value = ew + ob;
	} else if (ew >= eb && ob >= ow) {
		return_value = eb + ow;
	} else { // 両方白が多いか黒が多い
		if (ew > eb) { // 両方白が多い
			if (ew > ow) { // 偶数の白が多い
				return_value = ow + eb;
			} else if (ew == ow) {
				return_value = ob > eb ? ow + eb : ob + ew;
			} else {
				return_value = ew + ob;
			}
		} else { //両方黒が多い
			if (eb > ob) {
				return_value = ob + ew;
			} else if (eb == ob) {
				return_value = ow > ew ? ob + ew : eb + ow;
			} else {
				return_value = eb + ob;
			}
		}
	}

	cout << return_value << endl;
	
	return 0;
}

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

for i in range(N-M+1):
    for j in range(N-M+1):
        ok = True
        for y in range(M):
            for x in range(M):
                if A[i+y][j+x] != B[y][x]:
                    ok = False
                    break
        if ok:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 9116
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
const ll MOD = 1e9+7;
struct Unionfind{
    vector<int> data;
    Unionfind(int size):data(size, -1) {}
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if(data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    int root(int x){
        return (data[x] < 0) ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n,m; cin >> n >> m;
    Unionfind uni(n);
    int c;
    rep(i,m){
        int a,b;cin >> a >> b >> c;
        a--; b--;
        uni.unite(a,b);
    }
    vector<bool> ok(n,0);
    int ans=0;
    rep(i,n){
        int x=uni.root(i);
        if(!ok[x]){
            ok[x]=1;
            ans++;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3724
n, m = map(int, input().split())
inputs = []
for i in range(m):
  p, y = map(int, input().split())
  inputs.append([i, p, y, 0])

inputs = sorted(inputs, key = lambda i:i[2])
count = [0 for i in range(n)]
for i in inputs:
  count[i[1]-1] += 1
  i[3] = count[i[1]-1]

inputs = sorted(inputs, key = lambda i:i[0])

for i in inputs:
  print('{0[1]:06}{0[3]:06}'.format(i))

Measured memory_bytes: 30612
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		if(x%2){
			cout<<"first";
			exit(0);
		}
	}
	cout<<"second";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
    solve();		
}


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

int main() {
int n;cin>>n;int k=1,out;
  int x[n+1],d[n];for(int i=0;i<n+1;i++)cin>>x[i];
 sort(x,x+n+1);for(int i=0;i<n;i++)d[i]=x[i+1]-x[i];sort(d,d+n);out=d[0];
//  for(int i=0;i<n+1;i++)cout<<x[i]<<endl;

while(k){
  for(int i=0;i<n;i++){
    if(d[i]%out!=0){
      out--; break;
    }
    else if(d[i]%out==0 && i==n-1){
      k=0;break;
    }
  }
}
  
  cout<<out<<endl;
  
}



Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
typedef long long LL;
const int N=2;
const int M=1e6+50;
const int mod=998244353;
struct mat{
    LL c[N][N];
    void clear(){memset(c,0,sizeof(c));}
}a,t;
mat operator * (mat a,mat b){
    mat c;c.clear();
    for(int k=0;k<N;++k)
    for(int i=0;i<N;++i)
    for(int j=0;j<N;++j)
    if(a.c[i][k]&&b.c[k][j])
    c.c[i][j]=(c.c[i][j]+1ll*a.c[i][k]*b.c[k][j]%mod)%mod;
    return c;
}
int get(long long v){
	a.c[0][0]=t.c[0][0]=t.c[0][1]=t.c[1][0]=1;
    while(v){
        if(v&1)a=a*t;
        t=t*t;v>>=1; 
    }
    return a.c[0][1];
}
int n,Ans_1,Ans_2,f[M],g[M],inv[M];
LL m;
int main(){
    scanf("%d%lld",&n,&m);
    Ans_1=get(m+2*(n-1));
	m%=mod;f[1]=g[1]=inv[1]=Ans_2=1;
	for(int i=2;i<=n;i++){
    	f[i]=(f[i-1]+f[i-2])%mod;
		g[i]=1ll*g[i-1]*m%mod;
		inv[i]=(mod-1ll*(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=n+1;i<=2*n;i++)
	f[i]=(f[i-1]+f[i-2])%mod;
	for(int i=2;i<n;i++){
		Ans_1=(Ans_1-1ll*Ans_2*f[2*n+2-i*2]%mod+mod)%mod;
		Ans_2=1ll*Ans_2*m%mod*inv[i-1]%mod;
		m++;
	}
	if(n!=1)Ans_1=(Ans_1-Ans_2+mod)%mod;
	printf("%d\n",Ans_1);
}

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

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    int count = 0;
    for(int i = 0;i < N;i++){
        cin >> vec.at(i);
    }
for(int i = 1;i < N-1;i++){
    if(vec.at(i-1)<vec.at(i+1)&&vec.at(i-1)<vec.at(i)&&vec.at(i)<vec.at(i+1)){
        count++;
    }else if(vec.at(i-1)>vec.at(i+1)&&vec.at(i-1)>vec.at(i)&&vec.at(i)>vec.at(i+1)){
        count++;
    }
}
cout << count << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()




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

	int x;
	cin >> x;

	cout << (1999 - x) / 200 + 1 << endl;


	return 0;
}


Measured memory_bytes: 3644
X = int(input())

i=X
isSosu=False
while True:
  if i==2:
    print(i)
    break

  j=2
  while j*j<=i:
    if i%j==0:
      break
    j+=1

    if j*j>i :
      print(i)
      isSosu=True
      break

  i+=1
  if isSosu:
    break

Measured memory_bytes: 3060
S = input()
F = int(S[0:2])
B = int(S[2:4])

if 0 < F and F < 13:
    if 0 < B and B < 13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 0 < B and B < 13:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
//Compiler optimization
#pragma GCC optimize("Ofast")

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

//typedef
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;

//macro
#define reverse(a) reverse(a.begin(),a.end())
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define each(x, v) for (auto &x : v)
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 (a>b) { a=b; return 1; } return 0; }
ll pow(ll a,ll n, ll m){
    ll ret=1;
    for(;n>0;n>>=1,a=a*a%m){
        if(n%2==1){
        ret=ret*a%m;
        }
    }
    return ret;
}

//abbreviation
#define pb push_back
#define elif else if
#define mp make_pair
#define endl '\n'

//debug
#define debug(x) cerr << #x << ": " << x << endl
#define v_debug(v) cerr << #v << endl;fr(i,v.size()) cerr << i << ": " << v[i] << endl

//const
const  ll INF = 1e18;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(20);
    S s,t;cin >> s >> t;
    ll ans = t.size();
    fr(i,s.size()-t.size()+1){
        ll tmp = 0;
        fr(j,t.size()){
            if(s[i+j] != t[j])tmp++;
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

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

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];

int main()
{
	long long N, tmp, ans = 0, Max = 0, Min = 1000000001;
	vector<long long> a;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> tmp;
		a.push_back(tmp);
	}


	for (int i = 0; i < N; i++) {
		Max = max(a[i], Max);
		Min = min(a[i], Min);
	}

	cout << Max - Min << endl;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = long.Parse(Console.ReadLine());
        long[] nd = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nd[0];
        var d = nd[1];

        long ans = 0;
        for (int i = 0; i < n; i++)
        {
            long[] tmp = Console.ReadLine().Split().Select(long.Parse).ToArray();
            if (d * d >= (tmp[0] * tmp[0] + tmp[1] * tmp[1])) ans++;
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 41356
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(a*n,b)<<endl;
    return 0;
}

Measured memory_bytes: 256
# dfs(深さ優先探索)

N, Q = map(int, input().split(' '))

num_list = [0] * (N+1)

tree_list = [[] for _ in range(N+1)]

for _ in range(N-1):
    a, b = map(int, input().split())
    tree_list[a].append(b)
    tree_list[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    num_list[p] += x

q = [1]
checked = [0] * (N+1)

while q:
    v=q.pop()
    checked[v] = 1
    for u in tree_list[v]:
        if checked[u] == 1:
            continue
        num_list[u] += num_list[v]
        q.append(u)

print(*num_list[1:])

Measured memory_bytes: 55828
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int i, j, p[8], box[8], min;
	int c[8][8] = {1,2,1,2,1,4,1,4,
					1,2,1,4,1,4,1,2,
					1,4,1,2,1,2,1,4,
					1,4,1,4,1,2,1,2,
					2,1,2,1,4,1,4,1,
					2,1,4,1,4,1,2,1,
					4,1,2,1,2,1,4,1,
					4,1,4,1,2,1,2,1,
					};

	while(scanf("%d%d%d%d%d%d%d%d",&p[0],&p[1],&p[2],&p[3],&p[4],&p[5],&p[6],&p[7]) != EOF){
		
		for(i=0; i<8; i++)
			box[i] = 0;

		for(i=0; i<8; i++){
			for(j=0; j<8; j++){
				if(p[j] - c[i][j] > 0){
					box[i] += p[j] - c[i][j];
				}
			}
		}

		min = box[0];
		for(i=0; i<8; i++){
			if(min > box[i])
				min = box[i];
		}

		for(i=0; i<8; i++){
			if(box[i] == min){
				box[i] = -1;
			}
		}

		for(i=0; i<8; i++){
			if(box[i] == -1){
				for(j=0; j<8; j++){
					if(j == 0)
						printf("%d", c[i][j]);
					else
						printf(" %d", c[i][j]);
				}
				break;
			}
		}
		printf("\n");

	}

	return 0;

}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	if(c=='-')f=-1,c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
ll n,k,mx;
ll a[1000010];
bool check(ll m){
	ll cut=0;
	f(i,1,n){
		cut+=(a[i]%m==0)?(a[i]/m-1):(a[i]/m);
		if(cut>k)return 0;
	}
	return 1;
}
int main(){
	n=d,k=d;
	f(i,1,n)a[i]=d,mx=max(mx,a[i]);
	ll l=0,r=mx,mid;
	while(l+1<r){
		mid=(l+r)/2;
		if(check(mid))r=mid;
		else l=mid;
	}
	cout<<r;
	return 0;
}

Measured memory_bytes: 5028
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

void _main(istream &inp){
	ll C,D;
	inp >> C >> D;
	cout << abs(C-2)*abs(D-2) << endl;

}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 2
#define pi 3.1415926535
using namespace std;
struct __INIT{
    __INIT(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(15);
    }
}__init;

ll dp[1004732];
ll dp2[1004732];

int main(void){
    vl sikaku;
    vl skisu;
    ll N=185;
    rep(n,N){
        sikaku.push_back((n*(n+1)*(n+2))/6);
    }
    rep(i,1004732){
        dp2[i] = inf;
        dp[i] = inf;
    }
    dp2[0] = 0;
    dp[0] = 0;
    rep(i,185) rep(j,1004732){
        if(j < sikaku[i]) continue;
        dp2[j] = min(dp2[j],dp2[j-sikaku[i]]+1);
        if(sikaku[i]%2 == 1) dp[j] = min(dp[j],dp[j-sikaku[i]]+1);
    }
    while(true){
        ll n;
        cin>>n;
        if(n == 0) break;
        cout<<dp2[n]<<" "<<dp[n]<<endl;;
    }
}


Measured memory_bytes: 18836
#include<stdio.h>
#include<algorithm>
using namespace std;
int calc(int a,int b){
	int ret=0;
	for(int i=0;i<30;i++){
		if(a&(1<<i)){
			ret++;
			a+=(1<<i);
		}
		if(b&(1<<i)){
			ret++;
			b-=(1<<i);
		}
		if(a==b)break;
	}
	return ret;
}
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		int s,t;
		scanf("%d%d",&s,&t);
		if(t<0){
			int S=-t;
			t=-s;
			s=S;
		}
		if(s<0)printf("%d\n",calc(0,-s)+calc(0,t));
		else printf("%d\n",calc(s,t));
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;
int M;
vector<int> a,b,c;

struct edge{
  int to;
  i64 cost;
};


vector<vector<i64>> dist;

int main(){
  cin >> N >> M;
  a.resize(M);
  c.resize(M);
  b.resize(M);
  dist.resize(N,vector<i64>(N,1e18));

  rep(i,0,M - 1){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }

  rep(k,0,N - 1) rep(i,0,N - 1) rep(j,0,N - 1)
    dist[i][j] = min(dist[i][j] , dist[i][k] + dist[k][j]);
  int ans = 0;
  rep(i,0,M - 1){
    if(dist[a[i]][b[i]] < c[i]){
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main() {
  int n;
  cin>>n;
  vector<vector<int>> a(n,vector<int>(2));
  rep(i,n){
    cin>>a[i][0];
    a[i][1]=i+1;
  }
  sort(a.begin(),a.end());
  rep(i,n){
    cout<<a[i][1]<<" ";
  }
}

Measured memory_bytes: 8780
s=input()
t=0

if len(s)%2==0:
  for i in range(int(len(s)/2)):
    
    if s[i]==s[-i-1]:
      t=t
    else:
      t=t+1         
else:
  for i in range(int((len(s)-1)/2)):
     if s[i]==s[-i-1]:
      t=t
     else:
      t=t+1 
print(t)

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

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

  for(int j=0;j<=M;j++){
  for(int i=0;i<=D;i++){
   	int d_10 = i/10;
   	int d_1 = i%10;
    if(d_10 >= 2 && d_1 >= 2){
      if( d_1*d_10 == j){
        count++;
      }
    }
  }
  }
  
  cout << count << endl;
  
  return 0;
}

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


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

Measured memory_bytes: 256
/*
   Created by Rahul Goel.
*/
/*******************************************************************************/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
/*******************************************************************************/
using namespace std;
using ll = long long;
using ld = long double;
ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
/*
.-.. . -. -.- .- / .. ... / .-.. --- ...- . -.-.--
 */
/* For PBDS */
/*Two new methods X.order_of_key() and X.find_by_order()*/
/*
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*******************************************************************************/
ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_prod() { return 1LL; }
template<typename T, typename... Args>
T mod_prod(T a, Args... args) { return (a*mod_prod(args...))%mod; }
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/

/*
    Code begins after this.
*/


ll solve(){
    ll n;
    cin >> n;
    map < string, ll > mp;
    mp["AC"] = 0;
    mp["WA"] = 0;
    mp["RE"] = 0;
    mp["TLE"] = 0;
    for(ll i=0; i<n; i++){
        string str;
        cin >> str;
        mp[str]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    return 0;
}


signed main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}

/*******************************************************************************/
// Remeber - In a custom comparator cmp(a, b) a==b must always return to false.



Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define PI acos(-1)
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define mem(a,b) memset(a,b,sizeof(a))
#define MX 100005
#define MXX 10000
#define  s second
#define f first
#define mod 1000000007
#define inf 1e9
#define err 1e9
//int ex[]={1,-1,0,0};
//int wye[]={0,0,1,-1};
using namespace std;
ll dp[5005][55],n,p,a[55];
ll process(ll sum,ll now)
{
    if(dp[sum][now]!=-1) return dp[sum][now];
    else if(now==n && (sum%2LL)==p) return dp[sum][now]=1;
    else if(now==n) return dp[sum][now]=0;
    ll tmp=0;
    tmp+=(process(sum+a[now+1],now+1));
    tmp+=process(sum,now+1);
    return dp[sum][now]=tmp;
}
int main()
{
    fast();
    scanf("%lld%lld",&n,&p);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    mem(dp,-1);
    printf("%lld\n",process(0,0));
    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int l;
  cin >> l;
  vector<pair<int, int> > e1x; // to, cost;
  int processed = 0;
  REP(i, 18) {
    int b = (1 << i);
    if(l&b) {
      e1x.emplace_back(20 - i, processed);
      processed += b;
    }
  }
  while(processed < l) {
    int b = (1 << 18);
    e1x.emplace_back(2, processed);
    processed += b;
  }
  cout << 20 << " " << e1x.size() + 36 << endl;
  REP(i, 18) {
    cout << 19 - i << " " << 20 - i << " " << (1<<i) << endl;
    cout << 19 - i << " " << 20 - i << " " << 0 << endl;
  }
  for(auto tc : e1x) {
    cout << 1 << " " << tc.first << " " << tc.second << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main()
{
    int a[100];
    int n,m,x,y,i,sum=0,count=0;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        sum=sum+a[i];
    }
    y=sum%2;
    x=sum/(4*m)+y;


    for(i=0;i<n;i++)
    {
        if(a[i]>=x)
        {
            count++;
        }

    }
    if(count>=m)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    int A[N];
    int p;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (A[i] == 1)
            p = i;
    }

    int cnt = 0;
    int i = 0;
    for (i = p; i > 0; i -= (K - 1))
    {
        cnt++;
    }
    int d = abs(i);
    for (i = p + d; i < (N - 1); i += (K - 1))
    {
        cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();
		int ans1=(H%A)*W+(W%B)*H-(H%A)*(W%B);
		pl(ans1);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}


Measured memory_bytes: 24444
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long r,d;
  vector<long long> x(10);
  cin>>r>>d>>x[0];
  for(int i=1;i<11;i++){
    x[i]=r*x[i-1]-d;
    cout<<x[i]<<endl;
  }
  
  
}

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

const int SIZE=2510;
const int INF=1e9;
struct edge{int from,to,cost;};

int N,M,P;
vector<edge> es;
int dist[SIZE];
bool negative[SIZE];

void shortest_path(int s)
{
    for(int i=0;i<N;i++) dist[i]=INF;
    dist[s]=0;
    for(int i=0;i<N-1;i++){
        for(edge e:es){
            if(dist[e.from]!=INF){
                dist[e.to]=min(dist[e.to],dist[e.from]+e.cost);
            }
        }
    }
}

bool find_negative_loop()
{
    for(int i=0;i<N;i++) negative[i]=false;
    for(int i=0;i<N;i++){
        for(edge e:es){            
            if(dist[e.from]!=INF and dist[e.to]>dist[e.from]+e.cost){
                dist[e.to]=dist[e.from]+e.cost;
                negative[e.to]=true;
            }
            if(negative[e.from]) negative[e.to]=true;
        }
    }
    return negative[N-1];
}

int main()
{
    cin>>N>>M>>P;
    for(int i=0;i<M;i++){
        int a,b,c; cin>>a>>b>>c;
        a--; b--;
        es.push_back({a,b,P-c});
    }
    shortest_path(0);
    if(find_negative_loop()){
        cout<<-1<<endl;
    }else{
        cout<<max(-dist[N-1],0)<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif


vvll g;
ll memo[110000];
bool done[110000];
ll dfs(ll v) {
    if(done[v]) return memo[v];

    ll ret = 0;
    for(auto to : g[v]) {
        chmax(ret, dfs(to) + 1);
    }
    done[v] = true;
    memo[v] = ret;
    return memo[v];
}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N, M; cin >> N >> M;
    g.resize(N);
    rep(i, M) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        g[x].push_back(y);
    }

    ll ans = 0;
    rep(i, N) chmax(ans, dfs(i));
    cout << ans << endl;
}


Measured memory_bytes: 8704
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b>c+d) {
    cout << "Left" << endl;
  }
  else if(a+b<c+d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long ll;

ll f(int i, const string s)
{
  ll ans = 0;
  ll cache = s[0] - '0';
  for(int j = 1; j < s.length(); j++, i /= 2)
  {
	if(i % 2 == 0)
	{
	  // cout << "state = " << s[j] << " 1: " << cache << " -> " << cache * 10 + (s[j] - '0') << endl;
	  cache = cache * 10 + (s[j] - '0');
	}
	else
	{
	  // cout << "state = " << s[j] << " 2: " << cache << endl;
	  ans += cache;
	  cache = s[j] - '0';
	}
  }
  // cout << "3: " << cache << endl;
  ans += cache;
  return ans;
}

int main()
{
  string s;
  getline(cin, s);

  const int N = s.length() - 1;
  ll sum = 0;
  for(int i = 0; i < (1 << N); i++)
  {
	sum += f(i, s);
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

ll a[11];
ll ans, aux;

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%lld%lld%lld%lld%lld%lld%lld", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6]);

    aux = min(a[0], min(a[3], a[4]));
    ans = a[1] + 3 * aux + 2 * ((a[0] - aux) / 2) + 2 * ((a[3] - aux) / 2) + 2 * ((a[4] - aux) / 2);

    aux = max(0LL, aux - 1);
    ans = max(ans, a[1] + 3 * aux + 2 * ((a[0] - aux) / 2) + 2 * ((a[3] - aux) / 2) + 2 * ((a[4] - aux) / 2));

    printf("%lld", ans);


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
 
   
int main(){
 double n,d;
 cin >> n >> d;
 double sum=0;
 vector<double> x(n),y(n);
 rep(i,n)cin >> x.at(i) >> y.at(i);
 rep(i,n){
   double dis=x.at(i)*x.at(i)+y.at(i)*y.at(i);
   if(dis<=d*d)sum++;
 }
 cout << sum << endl; 
}

Measured memory_bytes: 6488
N = int(input())
S = input()
m = [0,0]

for i in range(N):
    if S[i] =='(':
        m[0] += 1
    else:
        if m[0] == 0:
            m[1] += 1
        else:
            m[0] -= 1

for i in range(m[0]):
    S += ')'
for i in range(m[1]):
    S = '(' + S

print(S)


Measured memory_bytes: 3060
s = input()
k = int(input())

a = list(s)
a = [ord(i) for i in a]
b = sorted(set(a))
c = []
INF = 97+26
for m in b:
    a1 = [i for i in range(len(s)) if a[i] == m]

    for i in a1:
        j = 0
        for j in range(k):
            if i + j >= len(s):
                break
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
                c.sort()
            if len(c) > 5:
                del c[-1]

    if len(c) >= k:
        break

print(c[k-1])


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

int main()
{
    int n, k;
    cin >> n >> k;
    set<int> a;
    rep(i,k) {
        int d;
        cin >> d;
        rep(i,d) {
            int b;
            cin >> b;
            a.insert(b);
        }
    }
    int sum = 0;
    rep(i,n) {
        if (find(a.begin(), a.end(), i+1) == a.end())
            sum++;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,count=0;
  while(scanf("%d",&n)!=EOF){
    int data[n+1];
    for(int i=2;i<=n;i++){
      data[i]=0;
    }
    for(int i=2;i<=n;i++){
      if(data[i]!=-1){
	count++;
	for(int j=i;j<=n;j+=i){
	  if(data[j]!=-1){
	  data[j]=-1;
	  }
	}
      }
    }
    cout << count << endl;
    count=0;
  }
  return(0);
}
  

Measured memory_bytes: 5112
#include <bits/stdc++.h>
using  namespace std;
long long keta(long long n){
    long long keta;
    while(n!=0){
        keta = n%10;
        n=n/10;
    }
    return keta;
}
int main(){
    long long n, ans=0, check=0, num =0;
    cin >> n;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            check = 0;
            num = 0;
            for(long long k=1;k<=n;k++){
                if(k%10==i){
                    if(keta(k) == j){
                        num++;
                    }
                }
            }
            for(long long k=1;k<=n;k++){
                if(k%10==j){
                    if(keta(k) == i){
                        check++;
                    }
                }
            }
            ans += check * num;
        }
    }
    cout << ans << endl;
    return 0;
 
}


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

using namespace std;

#define LL long long
#define FOE(i, s, t) for (int i = s; i <= t; i++)

int n, c, k;
int last, cnt;
int ret = 1;

#define K 600001

int a[K];

int main(){
        scanf("%d%d%d", &n, &c, &k);
        FOE(i, 1, n) scanf("%d", &a[i]);
        sort(a + 1, a + n + 1);

        last = a[1];
        cnt = 1;
        FOE(i, 2, n){
                if (cnt == c || last + k < a[i]){
                        ret++;
                        cnt = 0;
                        last = a[i];
                }
                cnt++;
        }
        printf("%d\n", ret);
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void){
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  if(a<b){
    printf("a < b\n");
  }
 if(a>b){
    printf("a > b\n");
  }
 if(a==b){
    printf("a == b\n");
  }
  return 0;
}

Measured memory_bytes: 580
import java.io.PrintWriter

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val s = readLine()!!
    println(s.take(3))
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


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

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  string s;
  cin >> s;
  bool flag = true;
  
  if (s.at(0) != 'A') flag = false;
  // if (s.at(2) != 'C' || s.at(s.size()-3) != 'C') flag = false;
  int cnt = 0;
  rep(i, s.size()){
    if (i == 0) continue;
    if ((2 <= i && i <= s.size()-2) && s.at(i)=='C') cnt++;
    else if (s[i] < 'a' || 'z' < s[i]) flag = false;
  }
  if (cnt != 1) flag = false;
  
  if (flag) cout << "AC" << endl;
  else cout << "WA" << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX_N 200000

int main(){
	int i,j;
	int n,maxv,min;
	int r[MAX_N];
	scanf("%d",&n);
	for(i=0; i<n; i++) scanf("%d",&r[i]);

	min  = r[0];
	maxv = r[1] - min;
	for(j=1; j<n; j++){
		if(maxv < r[j] - min) maxv = r[j] - min;
		if(min > r[j]) min = r[j];
	}

	printf("%d\n",maxv);

	return 0;
}

Measured memory_bytes: 1376
n = int(input())
al = list(map(int,input().split()))

import itertools
al_ac = list(itertools.accumulate(al))

ans = 0
init = 1

fix = 0
for a in al_ac:
    a += fix
    if init == 1:
        if a >= 1:
            init *= -1
            continue
        else:
            ans += abs(init - a)
            fix += init - a
            init *= -1
    else:
        if a <= -1:
            init *= -1
            continue
        else:
            ans += abs(init - a)
            fix += init - a
            init *= -1
ans2 = 0
init = -1

fix = 0
for a in al_ac:
    a += fix
    if init == 1:
        if a >= 1:
            init *= -1
            continue
        else:
            ans2 += abs(init - a)
            fix += init - a
            init *= -1
    else:
        if a <= -1:
            init *= -1
            continue
        else:
            ans2 += abs(init - a)
            fix += init - a
            init *= -1

print(min(ans, ans2))

Measured memory_bytes: 14468
#include <iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main() {

	ll();
	
	int x, dev=0,s=0;
	cin >> x;
	dev = x / 15;
	x *= 800;
	while (dev)
	{
		x -= 200;
		dev--;
	}
	cout << x << endl;

}

Measured memory_bytes: 3632
n,y=map(int,input().split())
y = y // 1000

ans=''
for m in range(n+1):
    for g in range(n+1-m):
        if y - 10*m - 5*g == n-m-g:
            ans=str(m)+' '+str(g)+' '+str(n-m-g)
            break
    if ans!='':
        break

print(ans if ans!='' else '-1 -1 -1')



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

long long func(long long a, long long b){
    if(a > b) swap(a, b);
    /*
    if(a != b){
        ans += 2 * a;
        return func(b - a, a);
    }else{
        ans += a;
        return 0;
    }
    */  
    if(b % a == 0) return 2 * a * (b / a) - a;   
    else return 2 * a * (b / a) + func(b % a, a);
}


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

    long long n, x;
    cin >> n >> x;

    cout << func(n - x, x) + n << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int log2int(int n)
{
    int res = 0;
    while (n > 0)
    {
        res++;
        n /= 2;
    }
    return res;
}

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

    cout << int(pow(2, int(log2(n)))) << endl;
}

Measured memory_bytes: 4068