akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int main()
{
	int high[10] = { };
	int first = 0, second = 0, third = 0;
	
	for(int i = 0; i < 10; i++){
		cin >> high[i];
		
		if(first <= high[i]){
			third = second;
			second = first;
			first = high[i];
		}
		else if(second <= high[i]){
			third = second;
			second = high[i];
		}
		else if(third <= high[i])
			third = high[i];
	}
	
	cout << first << endl << second << endl << third << endl;
	
	
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;

int main() {
  //
  ll n, d;
  cin >> n >> d;
  ll x = 2 * d + 1;
  if (n % x == 0) {
    cout << n / x << endl;
  } else {
    cout << n / x + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#!/usr/bin/env python3
#ABC140 B

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = LI()
c = LI()
ans = 0
tmp = a[0]-1
ans += b[a[0]-1]
for i in range(1,n):
    ans += b[a[i]-1]
    if tmp + 1 == a[i]-1:
        ans += c[tmp]
    tmp = a[i]-1
print(ans)


Measured memory_bytes: 38256
def main():
    N, K, C = map(int, input().split())
    S = input()

    i = 0
    c = 0
    p = [-1] * N
    while c < K:
        if S[i] == 'o':
            p[i] = c
            c += 1
            i += C
        i += 1

    i = N - 1
    c = K - 1
    q = [-1] * N
    while c >= 0:
        if S[i] == 'o':
            q[i] = c
            c -= 1
            i -= C
        i -= 1

    for i in range(N):
        if ~p[i] and p[i] == q[i]:
            print(i + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24948
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <map>
#include <deque>
#include <queue>
#include <set>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<min(a,b)+min(c,d)<<endl;
	return 0;
}


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

vector<int> adj[200000];
queue<int> qu;
int parent[200000], N, a, b, k,dist,dist_r,root,count_w, p, q;

int main() {
	scanf("%d", &N);
	for (int i = 0; i<N - 1; i++) {
		scanf("%d %d", &a, &b);
		adj[a-1].push_back(b-1);
		adj[b-1].push_back(a-1);
	}
	
	for (int i = 0; i<N; i++) {
		parent[i] = -2;
	}
	parent[0] = -1;
	qu.push(0);
	while (qu.empty() == 0) {
		p = qu.front();
		qu.pop();
		for (int i = 0; i < adj[p].size(); i++) {
			q = adj[p][i];
			if (parent[q] == -2) {
				qu.push(q);
				parent[q] = p;
			}
		}
	}

	/*1番とN番の頂点の最短経路の長さを調べる*/
	dist = 0;
	p = N-1;
	while (parent[p] != -1) {
		dist++;
		p = parent[p];
	}

	if (dist % 2 == 1) {
		dist_r = (dist - 1) / 2;
	}
	else {
		dist_r = (dist - 2) / 2;
	}

	p = N - 1;
	for (int i = 0; i < dist_r; i++) {
		p = parent[p];
	}
	root = p;

	/*rootの下にある頂点の数を数える*/
	count_w = 0;
	qu.push(root);
	while (qu.empty() == 0) {
		p = qu.front();
		qu.pop();
		for (int i = 0; i < adj[p].size(); i++) {
			q = adj[p][i];
			if (parent[p] != q) {
				qu.push(q);
			}
		}
		count_w++;
	}
	if (N - count_w > count_w) {
		printf("Fennec\n");
	}
	else {
		printf("Snuke\n");
	}
}

Measured memory_bytes: 8576
#include<iostream>
#include<queue>
#include<string>
using namespace std;

int main(){
    int n,q,t;
    string name;
    queue<pair<string,int> >Q;
    cin>>n>>q;
    for(int  i=0;i<n;i++){
        cin>>name>>t;
        Q.push(make_pair(name,t));
    }
    pair<string,int>u;
    int elaps=0,a;
    while(!Q.empty()){
        u=Q.front();Q.pop();
        a=min(u.second,q);
        u.second-=a;
        elaps+=a;
        if(u.second>0){
          Q.push(u);
        }else{
            cout<<u.first<<" "<<elaps<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 6376
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

long long power[1 << 18], X;

int main() {
	for (int i = -5000; i <= 5000; i++) {
		power[i + 5000] = 1LL * i * i * i * i * i;
	}
	cin >> X;
	for (int i = -5000; i <= 5000; i++) {
		for (int j = -5000; j <= i; j++) {
			if (power[i + 5000] - power[j + 5000] == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
 
int main()
{
	ios_base::sync_with_stdio(false);
	ll n,m,k,i,maxrow=0,maxcol=0;
	cin>>n>>m>>k;
	vector <pll> v;
	ll row[n+2]={0}, col[m+2]={0};
	set <pll> s;
	for(i=0;i<k;i++)
	{
		ll x,y;
		cin>>x>>y;
		row[--x]++;
		col[--y]++;
		s.insert({x,y});
	} 
	set <ll> idrow, idcol;
	for(i=0;i<n;i++)
	{
		maxrow = max(maxrow, row[i]);
	}
	for(i=0;i<m;i++)
	{
		maxcol = max(maxcol, col[i]);
	}
	for(i=0;i<n;i++)
	{
		if(row[i]==maxrow)
			idrow.insert(i);
	}
	for(i=0;i<m;i++)
	{
		if(col[i]==maxcol)
			idcol.insert(i);
	}
	// ll count = 0;
	// for(i=0;i<k;i++)
	// {
	// 	if(idrow.find(v[i].ff)!=idrow.end() && idcol.find(v[i].ss)!=idcol.end())
	// 	{
	// 		count++;
	// 	}
	// }
	ll f=0;
	for(auto it:idrow)
	{
		for(auto it2:idcol)
		{
			if(s.find({it,it2})==s.end())
			{
				f=1;
			}
		}
		if(f==1)
			break;
	}
	if(f==0)
		cout<<maxrow+maxcol-1<<nl;
	else
		cout<<maxrow+maxcol<<nl;
	return 0;
}

Measured memory_bytes: 55128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  if(s=="abc" || s=="acb" || s=="bac" || s=="bca" || s=="cab" || s=="cba"){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

int main()
{
    string s ;
    cin>>s ;
    if(s[0]=='R')
    {
       if(s[1]=='R')
       {
           if(s[2]=='R')
            cout<<3<<endl ;
            else
            cout<<2<<endl ;
       }
       else
       {
         cout<<1<<endl ;  
       }
    }
    else
    {
        if(s[1]=='R')
       {
           if(s[2]=='R')
            cout<<2<<endl ;
            else
            cout<<1<<endl ;
       }
       else
       {
         if(s[2]=='R')
            cout<<1<<endl ;
            else
            cout<<0<<endl ;
       } 
    }
    return 0;
}


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

#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vi >
#define vpii vector<pii >
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define LL long long
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;

template<typename T>
inline int getplc(T x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}

LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
    LL res=1;
    for(;b;b>>=1,a=a*a%_MOD){
    if(b&1)res=res*a%_MOD;
    }
    return res;
}

template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) {
    return max(a, Smax(args...));
}
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) {
    return min(a, Smin(args...));
}

template <typename T>
#define errorl(args...) {  \
    string _s = #args;   \
    replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    errl(_it, args);  \
}
void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    errl(++it, args...);
}
#define error(args...) {  \
    string _s = #args;  \
    replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    err(_it, args);  \
    cerr<<endl; \
}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << "=" << a << " # ";
    err(++it, args...);
}

LL n;
int cost;
vpii op;
map<LL, LL> dp;

LL dfs(LL x) {
    if (x <= 1) return x * cost;

    if (dp[x]) return dp[x];

    LL mn = INF_LL;
    if (cost <= mn / x) mn = (LL) cost * x;
    for (auto v : op) {
        int p = v.fi, t = v.se;
        mn = min(mn, (LL) cost * (x % p) + t + dfs(x / p));
        if (x % p != 0) mn = min(mn, (LL) cost * (p - x % p) + t + dfs(x / p + 1));
    }

    return dp[x] = mn;
}

void Solve() {
    int cas;
    cin >> cas;
    for (int i = 1; i <= cas; i++) {
        cin >> n;
        int a, b, c;
        cin >> a >> b >> c >> cost;

        op.pb({2, a});
        op.pb({3, b});
        op.pb({5, c});

        cout << dfs(n) << endl;
        op.clear(); dp.clear();
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//  freopen("o1.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    Solve();
    return 0;
}

Measured memory_bytes: 4472
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair <long long,long long> ii;
// typedef complex<long double> point;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    ll n = s.size()+1;
    vector <ll> arr(n);
    ll mini = 0;
    for (int z=1;z<n;z++){
        if (s[z-1] == '<'){
            arr[z] = arr[z-1]+1;
        } else {
            arr[z] = arr[z-1]-1;
        }
        mini = min(mini,arr[z]);
    }
    ll ans = 0;
    for (int z=0;z<n;z++){
        arr[z] -= mini;
    }
    for (int z=0;z<n-1;z++){
        if (s[z] == '<' && z == 0){
            arr[z] = 0;
        }
        else if (z == 0){
            arr[z] = arr[z+1]+1;
        }
        else {
            if (s[z] == '>' && s[z-1] == '<'){
                arr[z] = max(arr[z-1],arr[z+1])+1;
            }
            else if (s[z] == '>' && s[z-1] == '>'){
                arr[z] = arr[z+1]+1;
            }
            else if (s[z] == '<' && s[z-1] == '<'){
                arr[z] = arr[z-1]+1;
            }
            else {
               arr[z] = 0;
            }
        }
    }
    for (int z=n-1;z>0;z--){
        if (s[z-1] == '<' && z == n-1){
            arr[z] = arr[z-1]+1;
        }
        else if (z == n-1){
            arr[z] = 0;
        }
        else {
            if (s[z] == '>' && s[z-1] == '<'){
                arr[z] = max(arr[z-1],arr[z+1])+1;
            }
            else if (s[z] == '>' && s[z-1] == '>'){
                arr[z] = arr[z+1]+1;
            }
            else if (s[z] == '<' && s[z-1] == '<'){
                arr[z] = arr[z-1]+1;
            }
            else {
               arr[z] = 0;
            }
        }
    }
    for (int z=0;z<n-1;z++){
        if (s[z] == '<' && z == 0){
            arr[z] = 0;
        }
        else if (z == 0){
            arr[z] = arr[z+1]+1;
        }
        else {
            if (s[z] == '>' && s[z-1] == '<'){
                arr[z] = max(arr[z-1],arr[z+1])+1;
            }
            else if (s[z] == '>' && s[z-1] == '>'){
                arr[z] = arr[z+1]+1;
            }
            else if (s[z] == '<' && s[z-1] == '<'){
                arr[z] = arr[z-1]+1;
            }
            else {
               arr[z] = 0;
            }
        }
    }
    for (int z=0;z<n;z++){
        // if (z != n-1) cout << arr[z] << " " << s[z] << " ";
        // else cout << arr[z] << endl;
        ans += arr[z];
    }
    cout << ans << endl;
}
 
 

Measured memory_bytes: 4764
#include <stdio.h>
#include <stdlib.h>

int main()
{
	char s[200001];
	scanf("%s", s);
	
	int i, j;
	for (i = 0; s[i] != 'A'; i++);
	for (j = 0; s[j] != 0; j++);
	for (; s[j] != 'Z'; j--);
	
	printf("%d\n", j - i + 1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int h, n;
	scanf("%d %d", &h, &n);
	VI a(n);
	VI b(n);
	REP(i, n) { scanf("%d %d", &a[i], &b[i]); }
	VI2D dp(n + 1, VI(h, INF));
	REP(i, n) {
		REP(j, h) {
			if(j >= a[i]) {
				dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
			} else {
				dp[i + 1][j] = min(dp[i][j], b[i]);
			}
		}
	}
	printf("%d\n", dp[n][h - 1]);
	return 0;
}

Measured memory_bytes: 39424
N, M = map(int, input().split())

import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans = 0

if N >= 2:
    ans += combinations_count(N, 2)

if M >= 2:
    ans += combinations_count(M, 2)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll; 

using namespace std;

struct S { ll val, dist; };

int main() {
	ll N, C;
	cin >> N >> C;
	vector<ll> x(N);
	vector<ll> v(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> v[i];
	}

	vector<ll> d1(N + 1, 0);
	vector<ll> d2(N + 1, 0);
	for (int i = 1; i < d1.size(); i++) {
		d1[i] = d1[i - 1] + v[i - 1];
		d2[i] = d2[i - 1] + v[N - i];
	}

	vector<S> val1(N + 1);
	vector<S> val2(N + 1);
	val1[0].val = 0;
	val1[0].dist = 0;
	val2[0].val = 0;
	val2[0].dist = 0;
	for (int i = 1; i < val1.size(); i++) {
		if (val1[i - 1].val < (d1[i] - x[i - 1])) {
			val1[i].val = d1[i] - x[i - 1];
			val1[i].dist = x[i - 1];
		} else {
			val1[i].val = val1[i - 1].val;
			val1[i].dist = val1[i - 1].dist;
		}

		if (val2[i - 1].val < (d2[i] - (C - x[N - i]))) {
			val2[i].val = d2[i] - (C - x[N - i]);
			val2[i].dist = C - x[N - i];
		} else {
			val2[i].val = val2[i - 1].val;
			val2[i].dist = val2[i - 1].dist;
		}
	}

	ll res = 0;
	for (int i = 0; i <= N; i++) {
		ll min_dist = min(val1[i].dist, val2[N - i].dist);
		res = max(res, val1[i].val + val2[N - i].val - min_dist);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <string>

using namespace std;

int main() {
    string num;
    cin >> num;
    for(int i= 0; i < num.length(); i++) {
        if(num[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3592
#!/usr/bin/env python

import sys
sys.setrecursionlimit(10 ** 6)
from collections import deque
input = sys.stdin.buffer.readline
INF = float("inf")

def main():
    N,M = map(int,input().split())
    G = [[] for _ in range(N)]
    AB = [tuple(map(int,input().split())) for _ in range(M)]
    for a,b in AB:
        G[a-1].append(b-1)

    Ans = [1]*(N+1)
    
    # 全ての頂点から, 閉路が存在しないかを確認する
    for s in range(N):
        prev = [-1]*N
        dist = [-1]*N
        dist[s] = 0
        dq = deque([s])
        while dq:
            v = dq.popleft()
            for nv in G[v]:
                if dist[nv] == -1:
                    dist[nv] = dist[v] + 1
                    prev[nv] = v
                    dq.append(nv)
                # 次が 0番目(開始地点) なら閉路あり
                if dist[nv] == 0:
                    prev[nv] = v

        # 開始地点の前 が -1でない => 閉路あり
        if prev[s] != -1:
            v = prev[s]
            ans = set()
            for _ in range(max(dist)+1):
                ans.add(prev[v])
                v = prev[v]
            if len(Ans) > len(ans):
                Ans = list(ans)
    
    if len(Ans) == N+1:
        print(-1)
    else:
        print(len(Ans))
        Ans.sort()
        for v in Ans:
            print(v+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl
int gcd(int x, int y){
    if ((x==1)||(y==1)) {
        return 1;
    }
    if (x>y) {
        if (x%y==0) {
            return y;
        }else{
            return gcd(y, x%y);
        }
    }else{
        if (y%x==0) {
            return x;
        }else{
            return gcd(x, y%x);
        }
    }
}
int main() {
    IN(int, n);
    IN(int, m);
    int sum = 0;
    REP(i, m){
        IN(int, k);
        sum += k;
    }
    if (sum>n) {
        COUT(-1);
    }else{
        COUT(n-sum);
    }
}




Measured memory_bytes: 3636
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main(void) {
        // code
        int n;
        cin >> n;
        ll a[n];
        REP(i, n) { cin >> a[i]; }

        ll ans = 0;
        REP(i, n) { ans += a[i] - 1; }

        cout << ans << endl;

        return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

using ll = long long;

vector<ll> get_divisors(ll n) {
  vector<ll> ans;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ans.push_back(i);
      if (i * i != n) {
        ans.push_back(n / i);
      }
    }
  }

  return ans;
}

ll divsub(ll n, ll k) {
  ll mod = n % k;
  return mod == 0 ? divsub(n / k, k) : mod;
}

int main(int argc, const char *argv[])
{
  ll n;
  cin >> n;

  ll ans = get_divisors(n - 1).size() - 1;
  auto divisors = get_divisors(n);
  for (auto divisor : divisors) {
    if (divisor != 1 && divsub(n, divisor) == 1) {
      ans++;
    }
  }

  cout << ans << "\n";
  return 0;
}

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

int main() {
	double n, d, x, ans = 0.00;
	scanf("%lf%lf%lf", &n, &d, &x);
	for (d += (n - 0.5) * x; n; n--) {
		ans += d;
		d += d / n;
	}
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int x;
    int sum = 0;
    for(int i = 0;i<n;i++){
	x = sc.nextInt();
	if(x < Math.abs(x-k)){
	    sum += x*2;
	}else{
	    sum += Math.abs(x-k)*2;
	}
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 21972
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <vector>
#include <set>
#include <algorithm>
#include <tuple>

typedef std::pair<int64_t, int64_t> year_index_t;

int main()
{
    int64_t n, m;
    scanf("%" PRId64 " %" PRId64, &n, &m);

    std::vector<year_index_t> yearIndex;
    std::vector<int64_t> indexToPref(m, 0);
    std::vector<int64_t> prefToNextCity(n, 1);
    std::vector<int64_t> indexToCity(m, 0);

    for (int64_t i = 0; i < m; i++)
    {
        int64_t p, y;
        scanf("%" PRId64 " %" PRId64, &p, &y);

        yearIndex.push_back(std::make_pair(y, i));
        indexToPref[i] = p;
    }

    std::sort(yearIndex.begin(), yearIndex.end());
    for (auto yi : yearIndex)
    {
        auto i = yi.second;
        auto p = indexToPref[i];
        indexToCity[i] = prefToNextCity[p - 1];
        prefToNextCity[p - 1]++;
    }

    for (int64_t i = 0; i < m; i++)
    {
        printf("%06" PRId64 "%06" PRId64 "\n", indexToPref[i], indexToCity[i]);
    }
    return 0;
}


Measured memory_bytes: 5616
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	ln, _, _ := r.ReadLine()

	nums := strings.Split(string(ln), " ")
	win, _ := strconv.Atoi(nums[0])
	curt, _ := strconv.Atoi(nums[1])

	t := curt * 2
	diff := win - t
	if diff < 0 {
		fmt.Println(0)
	} else {
		fmt.Println(diff)
	}
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

#define SENTINEL 1e9
#define N 100000

typedef struct{
	char c;
	int num;
} Card;

Card card1[N];
Card card2[N];

void merge(int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	Card L[n1], R[n2];
	int i, j, k;

	for (i = 0; i <= n1 - 1; i++)
		L[i] = card2[left + i];
	for (i = 0; i <= n2 - 1; i++)
		R[i] = card2[mid + i];

	L[n1].num = R[n2].num = SENTINEL;
	L[n1].c = R[n2].c = ' ';
	i = j = 0;

	for (k = left; k <= right - 1; k++) {
		if (L[i].num <= R[j].num) {
			card2[k] = L[i];
			i++;
		} else {
			card2[k] = R[j];
			j++;
		}
	}
}

void mergeSort(int left, int right) {
	int mid;

	if (left + 1 < right) {
		mid = (left + right) / 2;
		mergeSort(left, mid);
		mergeSort(mid, right);
		merge(left, mid, right);
	}

}

void swapOfInt(int *a, int *b) {
	int tmp;

	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swapOfChar(char *a, char *b) {
	char tmp;

	tmp = *a;
	*a = *b;
	*b = tmp;
}

int partition(int p, int r) {
	int x, i, j;

	x = card1[r].num;
	i = p - 1;

	for (j = p; j < r; ++j) {
		if (card1[j].num <= x) {
			i++;
			swapOfInt(&card1[i].num, &card1[j].num);
			swapOfChar(&card1[i].c, &card1[j].c);
		}
	}
	swapOfInt(&card1[i + 1].num, &card1[r].num);
	swapOfChar(&card1[i + 1].c, &card1[r].c);
	return i + 1;
}

void quickSort(int p, int r) {
	int q;

	if (p < r) {
		q = partition(p, r);
		quickSort(p, q - 1);
		quickSort(q + 1, r);
	}
}

int main() {
	int i, n, flag = 0;
	char ch;

	scanf("%d%c", &n, &ch);

	for (i = 0; i < n; ++i) {
		scanf("%c%d%c", &card1[i].c, &card1[i].num, &ch);
		card2[i] = card1[i];
	}

	quickSort(0, n - 1);
	mergeSort(0, n);

	for (i = 0; i < n; i++) {
		if (strcmp(&card1[i].c, &card2[i].c)) flag = 1;
	}

	if (flag) printf("Not stable\n");
	else printf("Stable\n");

	for (i = 0; i < n; ++i) {
		printf("%c %d\n", card1[i].c, card1[i].num);
	}

	return 0;
}

Measured memory_bytes: 2952
//author: #theinfiniteboy aka @shaswatkumar362
#include <bits/stdc++.h>

//#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
#define ll long long int
#define bigint int64_t
#define endl '\n'
#define vll vector<ll>
#define it vector<ll>::iterator
#define pb push_back
#define mp make_pair
#define BAYBAY ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define test ll T;cin>>T;while(T--)
#define dbg(x) cout << #x << ":" << x << "\t";
#define deb(t) for(auto x: t) { cout << x << " "; } cout << "\t";
#define maxi(v) *max_element(v.begin(),v.end())
#define mini(v) *min_element(v.begin(), v.end())
#define F first
#define S second
#define fo(i,n) for(i=0;i<n;i++)

/*template<typename... T>
void read(T&...args) {
    ((cin>>args), ...);
}

template<typename... T>
void write(T&&... args) {
    ((cout << args << " "), ...);
}*/

ll fib(ll n) { 
  double phi = (1 + sqrt(5)) / 2; 
  return round(pow(phi, n) / sqrt(5)); 
}

void SieveOfEratosthenes(ll n, vector<ll> &v) 
{  
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        {  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          v.pb(p); 
} 

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    BAYBAY;
    int n; cin>>n;
    string s;
    cin>>s;
    int l = s.length();
    if (l <= n)
    {
    	cout << s;
    } else
    {
    	for (int i = 0; i < n; ++i)
    	{
    		cout << s[i];
    	} cout << "...";
    }
	return 0;
} // farewell....

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define pb push_back
#define mp make_pair
#define err(x) cout<<#x<<"= "<<x<<endl;
#define rep(i,n) for(int i =0; i< n; i++)
#define ff first
#define ss second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 309

int main(){
	ios::sync_with_stdio(false);
	int ans,n,m,A[SIZE][SIZE],idx[SIZE] = {0},done[SIZE]={0};
	cin>>n>>m;
	ans = n;
	rep(i,n){
		rep(j,m){
			cin>>A[i][j];A[i][j]--;
		}
	}
	
	rep(i,m-1){
		int mx = 0,stor=-1;
		int cnt[SIZE] = {0};
		rep(j,n){
			cnt[A[j][idx[j]]]++;
			if(stor==-1){
				stor = A[j][idx[j]];
			}
			else {
				cnt[A[j][idx[j]]]>cnt[stor]?stor=A[j][idx[j]]:1;
			}
		}
		mx = cnt[stor];
		ans = min(ans, mx);
		done[stor]=1;
		rep(i,n)
			while(done[A[i][idx[i]]])
				idx[i]++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

multimap<int, int> num;
int check(int now){
  auto itr = num.lower_bound(now);
  int count = 0;
  multiset<int> ans;
  while(itr!=num.end()&&(*itr).first==now){
    count++;
    ans.insert(check((*itr).second));
    itr++;
  }
  int ret = 0;
  auto it = ans.begin();
  for(int i=0;i<ans.size();i++){
    ret = max((*it)-i, ret);
    it++;
  }
  return count + ret;
}
int main(int argc, char const *argv[]) {
  int N, x;
  std::cin >> N;
  for(int i=2;i<=N;i++) {
    std::cin >> x;
    num.emplace(x, i);
  }
  std::cout << check(1) << '\n';
  return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        char s;
        cin >> s;
        if(s == 'Y') {
            cout << "Four" << endl;
            exit(0);
        }
    }
    cout << "Three" << endl;
}

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

    int s;
    cin >> s;

    vector<long long int> a;

    a.push_back(s);

    ll i=1;
    while(1){
        ll t;
        if(a[i-1]%2==0) a.push_back(a[i-1]/2);
        else a.push_back(a[i-1]*3+1);

        for(ll j=0;j<i-1;j++){
            if(a[j]==a[i]){
                cout << i+1 << endl;
                return 0;
            }
        }
        i++;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char s[11];
    scanf("%s", &s);
    int year = (s[0]-48)*1000 + (s[1]-48)*100 + (s[2]-48)*10 + s[3]-48;
    int month = (s[5]-48)*10 + s[6]-48;
    int day = (s[8]-48)*10 + s[9]-48;
    if(year < 2019)printf("Heisei");
    else if(year == 2019 && month < 5)printf("Heisei");
    else printf("TBD");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int a[N],b[N],l,f[N],n;
void up(int x){
	if (x==1)return;
	if (b[f[x]]>b[f[x/2]]){
		swap(f[x],f[x/2]);
		up(x/2);
	}
} 
void down(int x){
	int i=x;
	if (x*2<=l&&b[f[x]]<b[f[x*2]])i=x*2;
	if (x*2<l&&b[f[i]]<b[f[x*2+1]])i=x*2+1;
	if (i!=x){
		swap(f[x],f[i]);
		down(i);
	}
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)scanf("%d",&b[i]),f[i]=i;
	for (int i=1;i<=n;i++)
		if (b[i]<a[i]){
			puts("-1");
			return 0;
		}
	l=n;
	for (int i=n;i;i--)down(i);
	long long ans=0;
	while (l){
		int k=f[1];
		if (b[k]==a[k]){
			f[1]=f[l--];
			down(1);
			continue; 
		}
		int num=b[k==1?n:k-1]+b[k==n?1:k+1];
		int p=(b[k]-a[k])/num;
		if (!p){
			puts("-1");
			return 0;
		}
		b[k]-=p*num;down(1);
		ans+=p;
	} 
	printf("%lld\n",ans);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll a,b,c;cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>

using std::endl;

#define ll long long int
#define FOR(a, s, n) for(int a = s; a < n; ++a)
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define MOD 1000000007
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std
#define asn ans

struct edge
{
	ll min;
	ll max;
};

int ans, buf;

int main()
{

	scanf("%1d", &buf);
	ans += buf;
	scanf("%1d", &buf);
	ans += buf;
	scanf("%1d", &buf);
	ans += buf;

	OUT << ans << endl;

	return 0;
}

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

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

int main() {
    int H, N;
    cin >> H >> N;
    vector<pair<int, int>> pairs(N);
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    const int INF = 1e9;
    vector<int> dp(2 * H, INF);
    dp[0] = 0;
    rep(h, H) rep(i, N) {
        if(dp[h] == INF) continue;
        int nh = min(h + pairs[i].first, H);
        chmin(dp[nh], dp[h] + pairs[i].second);
    }
    cout << dp[H] << '\n';
    return 0;
}

// overflow
// corner cases


Measured memory_bytes: 384
#include <iostream>

#ifdef _MSC_VER
#define getchar_unlocked _getchar_nolock
#define printf printf_s
#endif

#define ll long long

int * vec;
ll ans = 0;
int n;
int * per;
ll * r;
ll * l;

void read_int_unlocked(int * out)
{
	static int c;
	*out = 0;
	c = getchar_unlocked();
	for (; '0' <= c && c <= '9'; c = getchar_unlocked())
		*out = (*out) * 10 + c - '0';
}

int main()
{
	read_int_unlocked(&n);
	vec = new int[n];
	int * start = vec;
	int * end = vec + n;
	for (int * i = start; i < end; i++)
		read_int_unlocked(i);
	
	per = new int[n];
	for (int * i = start; i < start + n; i++)
		*(per + (*i) - 1) = i - vec;

	r = new ll[n];
	for (auto i = r; i < r + n; i++)
		*i = 0;
	l = new ll[n];
	for (auto i = l; i < l + n; i++)
		*i = 0;

	int vsp, right, left;
	for (auto i = per; i < per + n - 1; i++)
	{
		vsp = *i;
		#define right (vsp + r[vsp] + 1)
		#define left (vsp - l[vsp] - 1)
		if (left == -1)
		{
			ans += vec[vsp] * ((r[right] + 1) * (1 + l[vsp]));
			l[right] = right;
		}
		else if (right == n)
		{
			ans += vec[vsp] * ((l[left] + 1) * (1 + r[vsp]));
			r[left] = n - left - 1;
		}
		else
		{
			ans += vec[vsp] * ((l[vsp] + 1) * (r[right] + 1) + (r[vsp] + 1) * (l[left] + 1));
			r[left] = l[right] = r[vsp] + l[vsp] + 1;
		}
	}
	printf("%llu", ans);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

//最短経路（負閉路検出）
void BellmanFord(Graph& G, ll s, Array& d, Array& negative) {//O(|E||V|)
	d.resize(G.size());
	negative.resize(G.size());
	REP(i, d.size())d[i] = INF;
	REP(i, d.size())negative[i] = false;
	d[s] = 0;
	REP(k, G.size() - 1) {
		REP(i, G.size()) {
			REP(j, G[i].size()) {
				if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {
					d[G[i][j].to] = d[i] + G[i][j].cap;
				}
			}
		}
	}
	REP(k, G.size() - 1) {
		REP(i, G.size()) {
			REP(j, G[i].size()) {
				if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {
					d[G[i][j].to] = d[i] + G[i][j].cap;
					negative[G[i][j].to] = true;
				}
				if (negative[i] == true)negative[G[i][j].to] = true;
			}
		}
	}
}

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


	ll n, m;
	cin >> n >> m;
	Graph g(n);

	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		add_edge(g,a, b, -c,false,0);
	}

	Array d, negative;
	BellmanFord(g, 0, d, negative);

	if (negative[n - 1] == true) {
		cout << "inf" << endl;
	}
	else {
		cout << -d[n - 1] << endl;
	}


	return 0;
}

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

int t,m,n,ok,s;

void solve(){
    ok=0;
    for (int i=0;i*i<=m*m+n*n;++i){
        for (int j=i;i*i+j*j<=m*m+n*n;++j){
            s=i*i+j*j;
            if (s<2||(i==abs(m)&&j==abs(n))) continue;
            if ((m*m+n*n)%s!=0) continue;
            if ((m*i+n*j)%s==0&&(n*i-m*j)%s==0) ok=1;
            if ((-m*i+n*j)%s==0&&(-n*i-m*j)%s==0) ok=1;
        }
    }
    cout << (ok?'C':'P') << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> t;
    for (;t--;){
        cin >> m >> n;
        if (abs(n)<abs(m)) swap(m,n);
        solve();
    }
}


Measured memory_bytes: 3048
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>

using namespace std;



int n,x,re;
int main()
{
    cin>>n;
    vector<int>v; 
    while(n--)
    {
        cin>>x;
        if(x%2==0)
        v.push_back(x);
    }
    for(int i=0;i<v.size();i++)
    {
        while(v[i]%2==0)
        {v[i]=v[i]/2;
        re++;}
    }
    cout<<re;
    //system("pause");
    return 0;
}  

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;

ll po[POW_MAX + 2];

ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}

ll comb(int n, int r) {
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}

int const N_MAX = 10;

int N;
int p[N_MAX + 1];

int main() {
  scanf("%d", &N);
  int max_pay = 0;
  rep(i, N) {
    scanf("%d", &p[i]);
    max_pay = max(max_pay, p[i]);
  }
  int sum = - max_pay / 2;
  rep(i, N) {
    sum += p[i];
  }
  printf("%d\n", sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
const int N = 575;
int n;
int w[N][N];
int dis[N][N];
int dx[4] = {0, -1, 1, 0};
int dy[4] = {-1, 0, 0, 1};

void dfs(int y, int x){
	int d = dis[y][x] + w[y][x];
	for(int k=0;k<4;k++){
		int i = y + dy[k], j = x + dx[k];
		if(i < 0 || i >= n || j < 0 || j >= n) continue;
		if(dis[i][j] > d){
			dis[i][j] = d;
			dfs(i, j);
		}
	}
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int ans = 0, p;
    cin >> n;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++){
    	dis[i][j] = min({i, j, n-i-1, n-j-1});
    	w[i][j] = 1;
    }
    int m = n * n;
    for(int i=0;i<m;i++){
    	cin >> p; p--;
    	int y = p / n;
    	int x = p % n;
    	ans += dis[y][x];
    	w[y][x] = 0;
    	dfs(y, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 24884
#include<stdio.h>
int main(){
  int i,j,count=0,n,q,key;
  int a[10000],b[10000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d",&a[i]);
}
scanf("%d",&q);
for(i=0;i<q;i++){
scanf("%d",&b[i]);
}
for(j=0;j<q;j++){
  i=0;
  key=b[j];
  a[n]=key;
while(1){
  if(a[i]==b[j]){
    count++;
    break;
  }
  i++;
  if(i==n){
    break;
  }
}
}
printf("%d\n",count);
return 0;
}



Measured memory_bytes: 2088
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

    cin >> n >> k;

    if(n > k) n %= k;

    while(abs(k - n) < n) n = abs(k - n);

    cout << n << endl;
}

Measured memory_bytes: 3508
def shiritori():
    n = int(input())
    words = [input() for _ in range(n)]

    for word in words:
        count = 0
        for w in words:
            if w == word:
                count += 1
        if count > 1:
            print('No')
            exit()
    
    for i in range(n):
        if i + 1 <= n - 1:
            x = words[i+1][0]
            y = words[i][-1]
            if x == y:
                continue
            else:
                print('No')
                exit()
    
    print('Yes')


if __name__ == '__main__':
    shiritori()


Measured memory_bytes: 3064
#include<iostream>
#include<vector>

using ull = unsigned long long;
using ui = unsigned int;



int main() {
	ui n;
	std::cin >> n;

	std::vector<ull> v;
	v.resize(n);

	for (auto&e : v)
		std::cin >> e;
		
	/*
		A => 配列。subscriptable。
		p => パーティションしたい配列の先頭
		r => 基準値
	*/
	auto partition = [](auto& A,ui p,ui r) {
		auto& x = A[r-1];
		ui i = p-1;
		/*
			基準値より小さいものを前に送って
			その個数（位置）を++する( = i )
		*/
		for (ui j{ p }; j < r-1; ++j) 
			if (A[j] <= x) {
				++i;
				std::swap(A[i], A[j]);
			}

		/*
			この時点で[p,i)には基準値以下、
			[i,r]には基準値以上しかない。
			最後に基準値を[i,r]の先頭(=i)に持ってくれば
			仕切りにできる。
		*/
		++i;
		std::swap(A[i], A[r-1]);

		return i;
		
	};

	auto x = partition(v, 0, v.size());
//	std::cout << x << "\n";
	ui i = 0;
	for (auto&e : v) {
		if (i == x)
			std::cout << "[" << e << "]";
		else
			std::cout << e;

		++i;
		std::cout << (i < n ? " " : "\n");
	}


	return 0;
}


Measured memory_bytes: 3576
N, Q = map(int, input().split(" "))
S = input().strip()

check = [0 for i in range(N+1)]

tmp = 0
for i in range(N):
    check[i+1] = tmp
    if S[i:i+2] == "AC":
        tmp += 1

ans = [0 for i in range(Q)]

for i in range(Q):
    l, r = map(int, input().split())
    ans[i] = check[r] - check[l]

for i in range(Q):
    print(ans[i])


Measured memory_bytes: 10316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    map<int,int> mp;
    rep(i,3) {
        int a, b; cin >> a >> b;
        mp[a]++; mp[b]++;
    }
    int n_1 = 0, n_2 = 0;
    for (P p : mp) {
        if (p.second == 1) n_1++;
        if (p.second == 2) n_2++;
    }
    if (n_1 == 2 && n_2 == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int q[1 << 17];

void f(int *p, int n, int a, int b) {
    if (n == 1) {
        p[0] = a;
        p[1] = b;
        return;
    }
    int l = 1 << (n - 1);
    if ((a & l) == (b & l)) {
        f(p + l, n - 1, a, b);
        f(p + 1, n - 1, l ^ a, l ^ p[l + 1]);
        p[0] = a;
    } else {
        int c = a ^ 1;
        f(p, n - 1, a, c);
        f(p + l, n - 1, l ^ c, b);
    }
}

int popcnt(int k) {
    int c = 0;
    for (int i = 0; i < 30; i++) {
        c += k >> i & 1;
    }
    return c;
}

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

    int n, a, b;
    cin >> n >> a >> b;

    int x = popcnt(a ^ b) % 2 == 1;
    cout << (x ? "YES" : "NO") << endl;
    if (!x) exit(0);

    f(q, n, a, b);

    int n1 = 1 << n;
    for (int i = 0; i < n1; i++) {
        cout << q[i] << " \n"[i == n1 - 1];
    }
    cout << flush;

    //C 奇数回遷移するのでpopcntの偶奇が異なっていればできる？

    return 0;
}

Measured memory_bytes: 1536
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();
        int c = sc.nextInt();
        // 文字列の入力
        int r1 = a * b;

        // 出力
        if (r1 <= c) {
            System.out.println(r1);
        } else {
            System.out.println(c);
        }


    }
}

Measured memory_bytes: 21844
n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]
t.sort(reverse=True)

t_b = t[0]
cnt = 0
ans = 0

for i in t:
    # print(i, t_b, cnt, ans)
    if t_b - i <= k and cnt + 1 <= c: # 差がk以下で人数に余裕がある
        cnt += 1
        continue
    else:
        t_b = i
        cnt = 1
        ans += 1

print(ans + 1)

Measured memory_bytes: 7416
#include <iostream>

using namespace std;

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

const int mod = (int)1e9 + 7;

int pow(int k, int n) {
  if(n <= 0) return 1;
  int m = pow(k, n / 2);
  return (n % 2 ? k : 1) * m % mod * m % mod;
}

int comb(int n, int a) {
  int p = 1, q = 1;
  rep(i,a) p = p * (n-i) % mod;
  rep(i,a) q = q * (i+1) % mod;
  return p * pow(q, mod-2) % mod;
}

signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << (pow(2,n) - 1 + (mod - comb(n,a)) + (mod - comb(n,b))) % mod << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

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;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / (b))
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))
//#define int long long int //dont forget to change int to signed

const int INT_INF = 1000000007;

int main() {
	lli A, B, C, K;
	cin >> A >> B >> C >> K;
	if (K % 2) cout << B - A << endl;
	else cout << A - B << endl;
	return 0;
}


Measured memory_bytes: 256