akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	LLI n, k;
	cin >> n >> k;
	n %= k;
	cout << _min(k - n, n);
	return 0;
}

Measured memory_bytes: 256
// AOJ 1141 "ディリクレの算術級数定理" (ICPC国内予選 2006 Problem A)
import java.util.Scanner;
import java.util.BitSet;

public class Main {
    static BitSet isNotPrime; // 素数でないならtrue
    static final int MAX_N = 1000000;
    
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        isNotPrime = new BitSet(MAX_N);
        sieve();
        while (true) {
            int a = sc.nextInt();
            int d = sc.nextInt();
            int n = sc.nextInt();
            if (a == 0) {
                break;
            }
            
            int num = 0; // 素数が現れた個数
            for (int i = a; i < MAX_N; i += d) {
                if (!isNotPrime.get(i)) {
                    num++;
                    if (num == n) {
                        System.out.println(i);
                        break;
                    }
                }
            }
        }
    }
    
    public static void sieve() {
        isNotPrime.set(0);
        isNotPrime.set(1);
        for (int i = 2; i < MAX_N; i++) {
            if (!isNotPrime.get(i)) {
                for (int j = i * 2; j <= MAX_N * 2; j += i) {
                    isNotPrime.set(j);
                }
            }
        }
    }
}

Measured memory_bytes: 23452
#include<bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second
 
#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
using namespace std;
/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main()
{
	kira;
    lli T=1;
    //cin>>T;
    while(T--)
    {
    	lli a,b,h[3]={0};
        cin>>a>>b;
        h[a-1]=1;
        h[b-1]=1;
        for(int i = 0; i<3; i++)
            if(!h[i])
                cout<<i+1<<endl;
        
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define max 32

int main()
{
    long int N, H, all, count;
    
    scanf("%lld %lld", &N, &H);
    
    if(N==1||H==1){
        printf("%d", 1);
        return 0;
    }
    
    all=N*H;
    
    if(all%2==0)
        count=all/2;
    else
        count=all/2+1;
    
    printf("%lld", count);
    
    return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**9)

n, m = map(int, input().split())
edges = [[]*n for _ in range(n)]
#DAGみたらDPを考える！

#メモ化再帰
visited = [False]*n
memo = [0]*n
def dp(v):
    if visited[v]:
        return memo[v]
    ret = 0
    for child in edges[v]:
        ret = max(ret, dp(child)+1)
    visited[v] = True
    memo[v] = ret
    return ret


for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    edges[x].append(y)

ans = 0
for i in range(n):
    ans = max(ans, dp(i))
print(ans)
#print(memo)

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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i=0;
    int arr[n+1];
    arr[0]=0;
    for(int x=0; x<n; x++){
        if(s.at(x)=='I'){
            i++;
        }
        else{
            i--;
        }
        arr[x+1]=i;
    }
    int ans=0;
    for(int x=0; x<=n;x++){
        if(arr[x]>ans){
            ans=arr[x];
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 888
num = int(input())
sum = 0.0
for i in range(num):
  row = input().split()
  crr = row[1]
  if (crr == "BTC"):
    val = float(row[0])
    val *= 380000.0
  else:
    val = int(row[0])
  sum = sum+val
print(sum)

Measured memory_bytes: 3060
N = int(input())
A = [input() for _ in [0]*N]

for i,a in enumerate(A):
    b = a.split(".")
    if len(b)==1:
        A[i] = int(a)*10**9
        continue
    c = b[1]
    n = len(c)
    c += "0"*(9-n)
    A[i] = int(b[0] + c)

cnt = [[0]*20 for _ in [0]*20]
B = [(0,0)]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    i = min(19,i)
    j = min(19,j)
    B[k] = (i,j)
    cnt[i][j] += 1

for i in range(1,20):
    i = 19-i
    for j in range(20):
        j = 19-j
        cnt[i][j] += cnt[i+1][j]

for i in range(20):
    i = 19-i
    for j in range(1,20):
        j = 19-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    ans += cnt[max(0,18-i)][max(0,18-j)]-me

print(ans//2)

Measured memory_bytes: 30876
n = int(input())
a = list(map(int,input().split()))
q = int(input())

table = {}
sum = 0


for i in range(n):
    sum += a[i]
    if a[i] not in table.keys():
        table[a[i]] = 1
    else:
        table[a[i]] += 1
for i in range(q):
    b,c = map(int,input().split())
    if b in table.keys():
        sum -= b * table[b]
        sum += c * table[b]
        
        if c not in table.keys():
            table[c] = table[b]
        else:
            table[c] += table[b]
        table[b] = 0    
    print(sum)    


Measured memory_bytes: 20820
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
A = l.shift() * 1
B = l.shift() * 1
C = l.shift() * 1
if (A == B && A != C
   || A == C && A != B
   || B == C && A != B) {
  console.log("Yes")
} else {
  console.log("No")
}


Measured memory_bytes: 21064
import sys

# sys.stdin = open('input.txt')

N = 100 + 1

p = [0] * N
m = [[0] * N for _ in range(N)]

n = int(input())

for i in range(1, n+1):
    p[i-1], p[i] = map(int, input().split())
for i in range(1, n+1):
    m[i][i] = 0

for l in range(2, n+1):
    for i in range(1, n-l+1+1):
        j = i + l - 1
        m[i][j] = (1 << 21)
        for k in range(i, j-1+1):
            m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j])

print(m[1][n])


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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        '''
        要素xが属するグループの根を返す
        '''
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        '''
        要素xが属するグループと要素yが属するグループとを併合する
        '''
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        '''
        要素xが属するグループのサイズ（要素数）を返す
        '''
        return -self.parents[self.find(x)]

    def same(self, x, y):
        '''
        要素x, yが同じグループに属するかどうかを返す
        '''
        return self.find(x) == self.find(y)

    def members(self, x):
        '''
        要素xが属するグループに属する要素をリストで返す
        '''
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        '''
        各要素の親要素の番号を格納するリスト
        '''
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        '''
        グループの数を返す
        '''
        return len(self.roots())

    def all_group_members(self):
        '''
        {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        '''
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


G = UnionFind(N)

for i in range(M):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    G.union(A, B)

ans = 0
for r in G.roots():
    ans = max(ans, G.size(r))
print(ans)


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

string n;

long long solve();

int main() {
  cin >> n;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, len = n.size(), sum = 0;
  for (int i = 0; i < len; ++i) {
    sum += n[i] - '0';
    res = max(res, sum - 1 + 9 * (len - 1 - i));
  }
  return max(res, sum);
}

Measured memory_bytes: 256
//{{{
#define DEF
#ifdef DEF
#include <iostream>
#include <algorithm>
#include <functional>
#include <stack>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <cstring>
#include <cmath>
#include <set>
#include <deque>

//-----------------------------------------------------
#define mrepp(i,n,x)  for(int i = n-1; i >= x; i--)
#define mrep(i,n) mrepp(i,n,0)
#define repp(i,x,n)  for(int i = x; i < n; i++)
#define rep(i,n) repp(i,0,n)

using namespace std;
typedef pair<int, int> Pii;
typedef long long int llint;

template<typename T>
void display(T &t, int start_x, int start_y, int end_x, int end_y) {
	cout << "===================" << endl;
	repp(i,start_y,end_y) {
		repp(j,start_x,end_x)
			printf("%4d:", t[i][j]);
		cout << endl;
	}
	cout << "===================" << endl;
}

//-----------------------------------------------------
#endif
//}}}

char moji[10][6] = {
		{},
		{5,'.',',','!','?',' '},
		{3,'a','b','c'},
		{3,'d','e','f'},
		{3,'g','h','i'},
		{3,'j','k','l'},
		{3,'m','n','o'},
		{4,'p','q','r','s'},
		{3,'t','u','v'},
		{4,'w','x','y','z'},
};

void solve() {

}

int main(void) {

	int n;
	cin >> n;
	rep(g,n){
		string s;
		cin >> s;
		int flag = 0;
		int count = -1;
		int a;
		rep(h,(int)s.size()){
			if(s[h]=='0' && !flag)continue;
			if(s[h]=='0' && flag){
				flag = 0;
				count = count % moji[a][0] + 1;
				cout << moji[a][count] << flush;
				count = -1;
			}
			else{
				a = s[h]-'0';
				count++;
				flag = 1;
			}
		}
		cout << endl;
	}

	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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


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

	while(true) {
		int n,m;
		map<char,char> mp;
		cin>>n;
		if(n==0) break;
		REP(i,n) {
			char a,b;cin>>a>>b;
			mp[a]=b;
		}
		cin>>m;
		while(m--) {
			char ch;
			cin>>ch;
			if(mp.count(ch)) cout<<mp[ch];
			else cout<<ch;
		}
		cout<<endl;
	}

	return 0;
}



Measured memory_bytes: 3100
#include<stdio.h>
 
int main(){
	int i,j;
	int n,a,b,c,x;
	int y[100];
 
	while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&x),n){
		for(i = 0;i < n;i++){
			scanf("%d",&y[i]);
		}

		for(i = 0,j = 0;i < 10001;i++){
			if(x == y[j]){
				j++;
			}
			if(n == j)break;
			x = (a * x + b) % c;
		}
		if(i==10001)i = -1;
		printf("%d\n",i);
	}
	return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
/*
Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}
*/

void insert(int k){
	Node y = NIL;
	Node x = root;
	Node z;

	z = malloc(sizeof(struct node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while( x != NIL ){
		y = x;
		if( z->key < x->key ){ x = x->left; }
		else{ x = x->right; }
	}
	z->parent = y;
	if( y == NIL ){ root = z; }
	else{
		if( z->key < y->key ){ y->left = z; }
		else{ y->right = z; }
	}
}

void inorder(Node u){
	if( u == NIL ){ return; }
	inorder( u->left );
	printf(" %d", u->key);
	inorder( u->right );
}
void preorder(Node u){
	if( u == NIL ){ return; }
	printf(" %d", u->key);
	preorder( u->left );
	preorder( u->right );
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
      if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 25176
#include <stdio.h>

int main(void)
{
    int t, s = 0, i;
    for (i = 0; i < 4; i++) {
        scanf("%d", &t);
        s += t;
    }
    
    printf("%d\n%d\n", s/60, s%60);
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll frac[3000000];

ll comb(ll a, ll b) {
  ll ue = frac[a];
  ll shita1=1, shita2=1;
  ll two, tmpshita1, tmpshita2;
  ll h = mod - 2;
  while(h>0) {
    two = 1;
    tmpshita1 = frac[a-b];
    tmpshita2 = frac[b];
    while(2*two<=h) {
      two *= 2;
      tmpshita1 *= tmpshita1;
      tmpshita2 *= tmpshita2;
      tmpshita1 %= mod;
      tmpshita2 %= mod;
    }
    h -= two;
    shita1 *= tmpshita1;
    shita1 %= mod;
    shita2 *= tmpshita2;
    shita2 %= mod;
  }
  return ue*shita1%mod*shita2%mod;
}

int main() {
  frac[0] = 1;
  for(ll i=1;i<3000000;++i) {
    frac[i] = frac[i-1]*i%mod;
  }
  ll r1, c1, r2, c2;
  cin>>r1>>c1>>r2>>c2;
  ll ans = 0;
  for(ll i=r1;i<=r2;++i) {
    ans += (comb(i+c2+1, i+1) - comb(i+c1, i+1))%mod;
    ans = (ans + mod) %mod;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 27056
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  ll n;
  cin >> n;
  string a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  REP(i, n){
    int p = 0;
    if(a[i] == b[i]) p++;
    if(b[i] == c[i]) p++;
    if(c[i] == a[i]) p++;
    if(p == 0) ans += 2;
    else if(p == 1) ans += 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# import numpy as np

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

# N = int(input())
N,K,Q = list(map(int, input().split()))
As = []

thres = Q - K

id2point = {}
for i in range(Q):
    a = int(input())-1
    if a in id2point:
        id2point[a] += 1
    else:
        id2point[a] = 1

if thres < 0:
    for i in range(N):
        print("Yes")
    exit()

for i in range(N):
    if i in id2point:
        if id2point[i] > thres:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

# for i in range(N):


Measured memory_bytes: 9060
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int a[3]={},c=0;
	FOR(i,0,3)cin>>a[i];
	while(1){
		if(a[0]&1==1||a[1]&1==1||a[2]&1==1)break;
		c++;
		if(a[0]==a[1]&&a[1]==a[2]){
			cout<<-1<<endl;
			return 0;
		}
		int tmp[3];
		FOR(i,0,3)tmp[i]=a[i];
		a[0]=(tmp[1]+tmp[2])/2;
		a[1]=(tmp[0]+tmp[2])/2;
		a[2]=(tmp[1]+tmp[0])/2;

	}
	cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a>b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD =1e9 + 7;



int main(){
	int n;
    vector<P>v[101010];
    cin>>n;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        v[a].push_back(P(b,i));
        v[b].push_back(P(a,i));
    }
    int k=0;
    bool f[101010]={};
    int ans[101010]={};
    queue<P> q;
    q.push(P(1,0));
    while(q.size()){
        P p=q.front();
        q.pop();
        f[p.F]=1;
        MAX(k,v[p.F].size());
        int c=1;
        for(auto au:v[p.F]){
            if(ans[au.S]==c)c++;
            if(f[au.F])continue;
            if(c==p.S)c++;
            ans[au.S]=c;
            q.push(P(au.F,c));
            c++;
        }

    }
    cout<<k<<endl;
    rep(i,n-1)cout<<ans[i]<<endl;


}

Measured memory_bytes: 7168
//minmaxsum.cc
#if 0
    ???????????????30???????¨??????§?????£??????
    C++???????????¨????????????long int?????¨int??????????????????????????????
#endif
#include<iostream>
using namespace std;
int N,A[100000];
int min(int n,int a[])
{
  int i;
  int min=a[0];
  for(i=1;i<n;i++)
    {
      if(a[i]<min)
	{
	  min=a[i];
	}
    }
  return min;
}
int max(int n,int a[])
{
  int i;
  int max=a[0];
  for(i=1;i<n;i++)
    {
      if(a[i]>max)
	{
	  max=a[i];
	}
    }
  return max;
}
long int sum(int n,int a[])
{
  int i;
  long int sum=0;
  for(i=0;i<n;i++)
    {
      sum+=a[i];
    }
  return sum;
}
int main()
{
  cin>>N;
  for(int i=0;i<N;i++)
    {
      cin>>A[i];
    }
  cout<<min(N,A)<<' '<<max(N,A)<<' '<<sum(N,A)<<endl;
}

Measured memory_bytes: 3084
import java.util.Scanner;

/**
 * Created by dezhonger on 2019/4/13
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        long r = 0;
        if (a > b) {
            r += a;
            a--;

        } else {
            r+= b;
            b--;
        }
        r += Math.max(a, b);
        System.out.println(r);
    }
}


Measured memory_bytes: 21204
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	cout<<"ABC"<<s<<endl;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    cin >> a;
    cout << 3 * a * a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C;
int a[N];
int main(){
#ifdef LOCAL
	freopen("C.in","r",stdin);//freopen("C.out","w",stdout);
#endif
	scanf("%d",&n);rep(i,1,n)scanf("%d",&t),a[t]++;
	int ans=0;
	rep(i,1,100000)MAX(ans,a[i-1]+a[i]+a[i+1]);
	printf("%d\n",ans);
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  double sum = 0.0;
  rep(i, n){
  	double x;
    string u;
    cin >> x >> u;
    if(u == "JPY"){
    	sum += x;
    }else{
    	sum += x * 380000;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

    vector<ll> sum_D(N + 2, 0), sum_kD(N + 2, 0);
    for (ll i = 0; i <= N; i++) {
        sum_D[i + 1] = sum_D[i] + D[i];
        sum_kD[i + 1] = sum_kD[i] + i * D[i];
    }

    vector<ll> f(N + 1);
    for (ll X = 1; X <= N; X++) {
        f[X] = (sum_kD[X + 1] + X * (sum_D[N + 1] - sum_D[X + 1])) / X;
    }

    for (ll K = 1; K <= N; K++) {
        ll ok = 0, ng = N + 1;
        while (ng - ok != 1) {
            ll mid = (ok + ng) / 2;
            (K <= f[mid] ? ok = mid : ng = mid);
        }
        cout << ok << endl;
    }
}

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

int main(){

int map[10000];
int dice[10000];
int mapN,diceN;
while(1){
cin >> mapN >> diceN;
if(mapN==0 && diceN==0){
	return 0;
}

for(int i=0 ; i<mapN ; i++){
	cin >> map[i];
}
for(int i=0 ; i<diceN ; i++){
	cin >> dice[i];
}

int me = 0;
int ans = 0;
for(int i=0 ; i<diceN ; i++){
	me+=dice[i];
	if(me>=mapN && ans==0){
		ans = i;
	}
	me += map[me];
	if(me>=mapN-1 && ans==0){
		ans = i;
	}
}
	cout << ans+1 << endl;
}
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,x[100005][3];
ll dp[100005][3];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) rep(j,3) cin>>x[i][j];
	rep(j,3) dp[1][j] = x[1][j];
	for(int i=2;i<=n;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(j == k) continue;
				dp[i][j] = max(dp[i][j],dp[i-1][k]+x[i][j]);
			}
		}
	}
	ll ans = 0;
	rep(j,3)ans=max(ans,dp[n][j]);
	cout<<ans<<endl;
}

Measured memory_bytes: 3712
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#define maxn 100005
using namespace std;

char s[maxn];

int main() {
	scanf("%s", s);
	int len = strlen(s);
	int flag = 0;
	if (s[len - 1] == '1' || s[0] != '1' || s[len - 2] != '1')		flag = 1;
	for (int i = 1; i < len / 2; i++) if (s[i] != s[len - 2 - i])	flag = 1;
	if (flag)	printf("-1\n");
	else {
		int cnt = 1, cur = len;
		for (int i = 0; i < len / 2 + len % 2; i++) {
			if (s[i] == '1') {
				printf("%d %d\n", cnt, cnt + 1);
				cnt++;
			}
			else {
				printf("%d %d\n", cnt, cur);
				cur--;
			}
		}
		while (cnt < cur) {
			printf("%d %d\n", cnt, cur);
			cur--;
		}
	}
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=100005;
//i_am_noob
int n;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	print1(n*(n-1)/2);
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
ll dp[MAXN];

int main()
{
    fill(dp, dp + MAXN, 0);
    int n, w;
    scanf("%d %d", &n, &w);
    for (int i = 0; i < n; i++) {
        int wi, vi;
        scanf("%d %d", &wi, &vi);
        for (int j = w - wi; j >= 0; j--)
            if (dp[j] != 0 || j == 0)
                dp[j + wi] = max(dp[j + wi], dp[j] + vi);
    }
    prl(*max_element(dp, dp + w + 1));
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

const lint MOD = (lint) 1e9 + 7;
lint N, X, S[205], dp[205][100005];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N >> X;
    for(int i=0;i<N;i++) cin >> S[i];

    sort(S, S+N); reverse(S, S+N);

    dp[0][X] = 1;
    for(int i=0;i<N;i++){
        for(int j=0;j<=X;j++){
            dp[i+1][j%S[i]] = (dp[i+1][j%S[i]]+dp[i][j]) % MOD;
            dp[i+1][j] = (dp[i+1][j]+dp[i][j]*(N-i-1)) % MOD;
        }
    }

    lint ans = 0;
    for(int i=0;i<=X;i++) ans = (ans+i*dp[N][i]) % MOD;

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

Measured memory_bytes: 157184
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int N = 20000 + 5, mod = 1000000007;
inline int add (int u, int v) { return u + v >= mod ? u + v - mod : u + v; }
inline int mns (int u, int v) { return u - v < 0 ? u - v + mod : u - v; }
inline int mul (int u, int v) { return 1LL * u * v % mod; }
inline int qpow (int u, int v) {
	int tot = 1, base = u % mod;
	while (v) {
		if (v & 1) tot = mul (tot, base);
		base = mul (base, base);
		v >>= 1;
	}
	return tot;
}
int n, k, a[N], cnt;

int main () {
	scanf ("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i) {
		scanf ("%d", &a[i]);
		for (int j = 1; j < i; ++j) {
			if (a[j] > a[i]) {
				cnt++;
			}
		}
	}
	sort (a + 1, a + n + 1);
	int lastpos = 0, tans = 0;
	for (int i = 1; i <= n; ++i) {
		if (i != 1 && a[i] != a[i - 1]) lastpos = i - 1;
		tans += lastpos;
	}
	int ans = add (mul (cnt, k), mul (tans, mul (k, mul (k - 1, qpow (2, mod - 2)))));
	printf ("%d\n", ans);
	return 0;
}


/*int tree[N];
inline int lowbit (int u) { return u & (-u); }
inline void ins (int u, int v) {
	while (u <= N - 5) {
		tree[u] = add(tree[u], v);
		u += lowbit (u);
	}
}
inline int query (int u) {
	int res = 0;
	while (u) {
		res = add (res, tree[u]);
		u -= lowbit (u);
	}
	return res;
}

int n, k, a[N], u[N], d[N];

int main () {
	#ifdef chitongz
//	freopen ("x.in", "w", stdin);
	#endif
	scanf ("%d%d", &n, &k);
	if (n == 1) {
		puts ("0\n");
		return 0;
	}
	for (int i = 1; i <= n; ++i) scanf ("%d", &a[i]);
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		cnt = add (cnt, mns (query (2000), query (a[i])));
		ins (a[i], 1);
	}
	int lastpos = 0, tans = 0;
	for (int i = 1; i <= n; ++i) {
		if (i == 1 || a[i] != a[i - 1]) lastpos = i - 1;
		tans = add (tans, lastpos);
	}
	int ans = add (mul (cnt, k), mul (tans, mul (k, mul (k - 1, qpow (2, mod - 2)))));
	printf ("%d\n", ans);
	return 0;
}*/



























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

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

#define LOG(variable) cerr << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cerr << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  int n; cin >> n;
  int counter = 1;
  while((n*counter) % 360) {
    ++counter;
  }
  cout << counter;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

int main(){
  ll a,b,i;
  char c,d;
  string e,f;
  cin >> a >> b;
  c='0' + a;
  d='0' +b;
  e=c;
  f=d;
  for(i=1;i<a;i++){
    f+=d;
  }
  for(i=1;i<b;i++){
    e+=c;
  }
  if(f<=e){
    cout << f;
  }
  else{
    cout << e;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll INF=1e18;



int main(){
  int a,b,c;
  cin >>a>>b>>c;
  int a2=max(a,max(b,c));
  int c2=min(a,min(b,c));
  int b2=(a+b+c)-(a2+c2);
  int ans=0;
  if((b2+c2)%2==0){// 最終到達a2の場合
    int ybc=a2-b2;
    ans= ybc+(a2-c2-ybc)/2;
    cout<<ans<<endl;
    return 0;
    
    
    
  }else{//最終到達a2+1の場合
    int ybc=(a2+1)-b2;
    ans= ybc+1+(a2-c2-ybc)/2;
    cout<<ans<<endl;
    return 0;
  }
  

}

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

int c[1000001];
char s[1000001];

int main(void){
	int i,j;
	int n,m,ans;

	while(scanf("%d",&n) && n){
		memset(c,0,sizeof(c));

		scanf("%d%s",&m,s);
		for(i=m-1;i>1;i--){
			if(s[i] == 'I' && s[i-1] == 'O' && s[i-2] == 'I'){
				c[i-2] = c[i] + 1;
			}
		}

		ans = 0;
		for(i=0;i<m;i++){
			if(c[i] >= n){
				ans++;
			}
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String a[] = br.readLine().split(" ");
        Arrays.sort(a);
        for(int i=0;i<a.length;i++){
            if(i!=a.length-1){
                System.out.print(a[i]+" ");
            }else{
                System.out.println(a[i]);
            }
        }
    }
}

Measured memory_bytes: 24240
x, y = map(int, input().split())
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]
if x in g1 and y in g1:
    print("Yes")
elif x in g2 and y in g2:
    print("Yes")
elif x in g3 and y in g3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
from collections import defaultdict
n, m = map(int, input().split())
bridges = [list(map(int, input().split())) for _ in range(m)]
first_bridge = []
second_bridge = []
bri_dict = defaultdict(list)
for bridge in bridges:
  bri_dict[bridge[0]].append(bridge[1])
  bri_dict[bridge[1]].append(bridge[0])
for bridge in bridges:
  if bridge[1] == n:
    second_bridge.append(bridge[0])

flag = False
for island in second_bridge:
  if 1 in bri_dict[island]:
    flag = True
  
if flag:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Measured memory_bytes: 80784
A, B, C, X, Y = map(int, input().split())

cost = 0
if A + B > 2 * C:
    n_purchase_surplus = 2 * max(X, Y)
    cost_surplus = n_purchase_surplus * C
    if X >= Y:
        n_purchase = 2 * Y
        cost = n_purchase * C
        n_remaining = X - Y
        cost += n_remaining * A
    else:
        n_purchase = 2 * X
        cost = n_purchase * C
        n_remaining = Y - X
        cost += n_remaining * B
    # select minimum cost
    cost = min(cost_surplus, cost)
else:
    cost = (X * A) + (Y * B)
print(cost)

Measured memory_bytes: 3064
s = input()
q = int(input())
is_reverse = 0
left = ''
for i in range(q):
    query = input()
    if query[0] == '1':
        is_reverse = (is_reverse+1) % 2
    else:
        _, f, c = query.split()
        if (is_reverse+int(f))%2 == 0:
            s += c
        else:
            left += c
s = left[::-1] + s
if is_reverse:
    print(s[::-1])
else:
    print(s)

Measured memory_bytes: 4280
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX=1e5+5;
int a[MAX];
int main()
{
	int n;
	int ans=0;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=n;){
		int t=a[i];
		int index=i;
		while(index<=n&&a[index]==t) index++;
		if(index>n){
			ans++;
		}
		else if(a[index]>t){
			while(index<=n&&a[index]>=a[index-1]) index++;
			ans++;
		}
		else{
			while(index<=n&&a[index]<=a[index-1]) index++;
			ans++;
		}
		i=index;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ppb pop_back()
#define fi first
#define se second
#define pi pair<int, int>
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define REP(i, a, n) for(int i = a; i < n; i++)
#define Y "YES"
#define N "NO"
using namespace std;

ll x, k, d;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> x >> k >> d;
	if (x < 0) x = -x;
	ll q = min(k, x/d);
	x -= q * d;
	k -= q;
	if (k % 2 == 0) cout << x;
	else cout << d-x;
}

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

class Program {
	int[,] dp = new int[50, 2501];
    static void Main(string[] args) {
        new Calc().calc();
        return;
    }

    public class Calc {
        public void calc() {
			int N = ReadLine<int>();
			var a = ReadLine<int>(' ');
			var ave = a.Average();
			int upper = (int)Math.Ceiling(ave), lower = (int)ave;
			int[] sums = new int[2] { 0, 0 };
			foreach (var item in a) {
				sums[0] += (item - upper) * (item - upper);
				sums[1] += (item - lower) * (item - lower);
			}
			Math.Min(sums[0], sums[1]).WL();
			return;
        }
    }
	

    public static T[] ReadLine<T>(params char[] separators) {
        return Console.ReadLine()
            .Split(separators)
            .Where(_ => _.Length > 0)
            .Select(_ => (T)Convert.ChangeType(_, typeof(T)))
            .ToArray();
    }
	public static T ReadLine<T>() {
		return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
	}
    public static List<T> ReadLines<T>(int N) {
        List<T> rt = new List<T>();
        for (int i = 0; i < N; i++) {
            T item = (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
            rt.Add(item);
        }
        return rt;
    }
}
public static class Utils {
    public static void WL(this object obj) {
        Console.WriteLine(obj);
    }
	public static string Docking<T>(this IEnumerable<T> collection,Func<T,string> filter = null) {
		StringBuilder sb = new StringBuilder();
		foreach (var item in collection) {
			string str = filter != null ? filter(item) : item.ToString();
			sb.Append(str);
		}
		return sb.ToString();
	}
	public static string RangeDocking<T>(this IEnumerable<T> collection,
		int start,int end,Func<T,string> filter = null) {
		if (start > collection.Count()) throw new IndexOutOfRangeException();
		if (end < 0) throw new IndexOutOfRangeException();
		StringBuilder sb = new StringBuilder();
		for (int i = start; i < end; i++) {
			string str = filter != null ? filter(collection.ElementAt(i)) : collection.ElementAt(i).ToString();
			sb.Append(str);
		}
		return sb.ToString();
	}
	public static void WriteLineAll<T>(this IEnumerable<T> collection) {
		foreach (var item in collection) {
			item.WL();
		}
	}
}


Measured memory_bytes: 13396
N = int(input())
d = []
i = 0
while i < N:
	d.append(input())
	i += 1

d.sort()

j = 1
ans = 1

while j < N:
	if d[j-1] >= d[j]:
		j += 1
	else:
		ans += 1
		j += 1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x; cin >> x;
    cout << (x >= 30 ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 3640
use proconio::{input, fastout};

#[fastout]
fn main() {
  
  input! {
    n: usize,
    a: [usize; n-1],
  }
  
  let mut ans = vec![0_usize; n];
  
  for i in a {
    ans[i - 1] += 1;
  }
  
  for i in ans {
  	println!("{}", i);
  }
  
}

Measured memory_bytes: 6316
#include <iostream>
#include <algorithm>

using namespace std;

const int MX = 300001;
bool chck[MX];
int idx[MX];
 
int main()
{
    int n, q, inp, lim;
 
    cin >> n >> q;
    lim = 0;
    while (n--) {
        cin >> inp;
        chck[inp] = true;
        lim = max(lim, inp);
    }
     
    int pre = 0;
    for (int i = 1; i <= lim; i++) {
        if (chck[i]) {
            idx[i] = pre;
            pre = i;
        }
        else
            idx[i] = pre;
    }
         
 
    while (q--) {
        int s = lim;
        int ans = 0;
        cin >> inp;
 
        if (inp > s) 
            cout << s << endl;
        else {
            while (s > 0) {
                ans = max(ans, s % inp);
             
                if (s < inp)
                    break;
                s = idx[s - (s % inp)];
            }
            cout << ans << endl;
        }
    }
 
    return 0;
}

Measured memory_bytes: 2624
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
#include <map>
#include <string>
using namespace std;
typedef long long ll;


int main(void){
   
    string s;
    int id[100005];
    vector<char> v;

    cin >> s;

    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'x') continue;
        v.push_back(s[i]);
    }

    for (int i = 0; i < v.size(); i++){
        if (v[i] != v[v.size() - i - 1]){
            cout << -1 << endl;
            return 0;
        }
    }

    int count = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'x')continue;
        id[++count] = i;
    }

    int lx = 0, rx = 0;
    int ans = 0;
    
    //cout<<s.size()<<endl;

    for (int i = 1; i <= count / 2 + 1; i++){

        if (count % 2 == 0 && i == count / 2 + 1) break;

        if (i == 1){
            lx = id[i];
            rx = s.size() - id[count] - 1;
            ans += max(lx - rx, rx - lx);
            //cout<<'('<<lx<<','<<rx<<')'<<' ';
        }
        else{
            lx = id[i] - id[i - 1] - 1;
            rx = id[count - i + 2] - id[count - i + 1] - 1;
            ans += max(lx - rx, rx - lx);
            //cout<<'('<<lx<<','<<rx<<')'<<' ';
        }
    }


    cout << ans << endl;


}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int n,a,b,c;
    scanf("%d%d%d",&n,&a,&b);
    c=n*a;
    if(c>b)
        printf("%d",b);
    else
        printf("%d",c);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ANS =[0 for _ in range(n)]
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            if x**2 + y**2 + z**2 + x*y + y*z + z*x > n:
                continue
            ANS[(x**2 + y**2 + z**2 + x*y + y*z + z*x) - 1] += 1
for i in ANS:
    print(i)

Measured memory_bytes: 9124
#include <cstdio>
int main()
{
	// freopen("ARC091-F.in", "r", stdin); 
	int n, ans = 0; 
	scanf("%d", &n); 
	while (n--)
	{
		int a, k; 
		scanf("%d%d", &a, &k); 
		if (k <= 1e4)
		{
			while (a >= k && a % k)
				a -= a / k + 1; 
			ans ^= a / k; 
		}
		else
		{
			while (a >= k)
			{
				int x = a / k, y = a % k; 
				if (!y)
				{
					ans ^= x; 
					break; 
				}
				a -= ((y - 1) / (x + 1) + 1) * (x + 1); 
			}
		}
	}
	puts(ans ? "Takahashi" : "Aoki"); 
	return 0; 
}


Measured memory_bytes: 128