akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

typedef struct{
	int*data,size,max_size;
}vector;

void init(vector*v){
	v->data=(int*)malloc(sizeof(int)*(v->max_size=1));
	v->size=0;
}

void push(vector*v,int x){
	if(v->size==v->max_size){
		v->data=(int*)realloc(v->data,sizeof(int)*(v->max_size<<=1));
	}
	v->data[v->size++]=x;
}

vector v[100001];

int max(int a,int b){return a>b?a:b;}
int cmp(const void*a,const void*b){return*(int*)b-*(int*)a;}

int f(int x){
	int n=v[x].size;
	int t[n];
	for(int i=0;i<n;++i){
		t[i]=f(v[x].data[i]);
	}
	qsort(t,n,sizeof(int),cmp);
	int r=0;
	for(int i=0;i<n;++i){
		r=max(r,t[i]+i+1);
	}
	return r;
}

int main(){
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;++i){
		init(&v[i]);
	}
	for(int i=2;i<=N;++i){
		int a;
		scanf("%d",&a);
		push(&v[a],i);
	}
	printf("%d\n",f(1));
	return 0;
}


Measured memory_bytes: 15744
inf = 10 ** 18
P = 10 ** 9 + 7

N = int(input())
p = list(map(int, input().split()))

cnt = 0
for i, pi in enumerate(p):
    if pi != i + 1:
        cnt += 1

if cnt == 0 or cnt == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
N = int(input())
data = [[] for i in range(N)]

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

stack = [0]
d = [-1] * N
d[0] = 0

while stack:
    x = stack.pop()
    for y in data[x]:
        if d[y] != -1:
            continue
        d[y] = d[x] + 1
        stack.append(y)

mod = [[],[]]
for i in range(N):
    mod[d[i]%2].append(i)

ans = [0]*N

p = 1
q = 2
r = 3
if len(mod[0]) > N//3 and len(mod[1]) > N//3:
    for k in mod[0]:
        if p <= N:
            ans[k] = p
            p += 3
        else:
            ans[k] = r
            r += 3
    for l in mod[1]:
        if q <= N:
            ans[l] = q
            q += 3
        else:
            ans[l] = r
            r += 3
    
elif len(mod[0]) > N//3:
    for k in mod[0]:
        if p <= N:
            ans[k] = p
            p += 3
        elif q <= N:
            ans[k] = q
            q += 3
        else:
            ans[k] = r
            r += 3
    for l in mod[1]:
        ans[l] = r
        r += 3

else:
    for k in mod[1]:
        if p <= N:
            ans[k] = p
            p += 3
        elif q <= N:
            ans[k] = q
            q += 3
        else:
            ans[k] = r
            r += 3
    for l in mod[0]:
        ans[l] = r
        r += 3

print(" ".join(map(str,ans)))


    



Measured memory_bytes: 72464
import java.util.Scanner;

public class Main {	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double A = sc.nextInt();
		double B = sc.nextInt();
		double C = sc.nextInt();
		double D = sc.nextInt();
		double E = sc.nextInt();
		double F = sc.nextInt();
		
		double water = 0;
		double suger = 0;
		double watmax = 0;
		double sugmax = 0;
		double maxnodo = 100 * E / (100 + E);
		double nodo = 0;
		double nodomax = 0;
	
		for(int a = 0; a <= F / 100; a += A) {
			for(int b = 0; b <= F / 100; b += B) {
				for(int c = 0; c <= F; c += C) {
					for(int d = 0; d <= F; d += D) {
						water = 100 * a + 100 * b;
						suger = c + d;
						if(water == 0 || water + suger > F) {
							break;
						}
						nodo = 100 * suger / (water + suger);
						if( nodo >= nodomax && nodo <= maxnodo) {
							watmax = water;
							sugmax = suger;
							nodomax = nodo;
						}
					}
				}
			}
		}
		System.out.println((int)watmax + (int)sugmax + " " + (int)sugmax);
	}
}


Measured memory_bytes: 25172
import math

# input
D, G = map(int, input().split())
Problems = [list(map(int, input().split())) for _ in range(D)]

ans = float('inf')

for i in range(1 << D): # bit全探索
    solved = [a for a in range(D)] # 全て解く＝ボーナス点をもらう問題群
    count = 0
    point = 0
    for j in range(D): # 全て解く＝ボーナス点をもらう問題群の点数合計
        if i & (1 << j): # (j + 1) * 100 点の問題を全て解く場合
            count += Problems[j][0]
            point += Problems[j][0] * (j + 1) * 100 + Problems[j][1]
            solved.remove(j) # (j + 1) * 100 点の問題は全て解答済
    if point < G and len(solved) > 0:
        k = max(solved)
        if math.ceil((G - point) / ((k + 1) * 100)) > Problems[k][0] - 1:
            continue
        else:
            count += math.ceil((G - point) / ((k + 1) * 100))
            ans = min(ans, count)
    else:
        ans = min(ans, count)

print(ans)

    





Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)

bool dp[82][82][30000];

int a[82][82];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z,h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];   
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>x;
            a[i][j]-=x;   
        }
    }
    dp[0][0][15000+a[0][0]]=true;
    dp[0][0][15000-a[0][0]]=true;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i||j){
                for(int k=0;k<30000;k++){
                    x = k-a[i][j];
                    if(x>=0){
                        if(i)
                            dp[i][j][k]|=dp[i-1][j][x];
                        if(j)
                            dp[i][j][k]|=dp[i][j-1][x];
                    }
                    x = k+a[i][j];
                    if(x<30000){
                        if(i)
                            dp[i][j][k]|=dp[i-1][j][x];
                        if(j)
                            dp[i][j][k]|=dp[i][j-1][x];
                    }
                }
            }
        }
    }
    int ans = INTMAX;
    for(int i=0;i<30000;i++){
        if(dp[h-1][w-1][i]){
            ans = min(ans,abs(15000-i));
        }
    }
    cout<<ans;
    
    

    return 0;
}

Measured memory_bytes: 192768
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
	// your code goes here
	int a,b;
	cin>>a>>b;
	int aa = a+a-1;
	int bb = b+b-1;
	int cc = a+b;
	cout<<max(aa,max(bb,cc))<<endl;
	
	return 0;
}


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

#define ll long long

using namespace std;
const int MX = 200'000 + 5; // check bounds!

int main() {
    ll x;
    cin >> x;

    for (ll a = -1000; a <= 1000; ++a)
        for (ll b = -1000; b <= 1000; ++b)
            if (a*a*a*a*a - b*b*b*b*b == x) {
                cout << a << " " << b;
                return 0;
            }

    return 0;
}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, T;
    int c[100], t[100];
    cin >> n >> T;
    for (int i = 0; i < n; i++)
    {
        cin >> c[i] >> t[i];
    }
    int cost = INF;
    for (int i = 0; i < n; i++)
    {
        if (t[i] <= T)
        {
            if (cost > c[i])
            {
                cost = c[i];
            }
        }
    }
    if (cost < INF)
        cout << cost << endl;
    else
        cout << "TLE" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    double n; cin>>n;
    double cnt = 0;

    for (int i = 1; i <= n; ++i) {
        if((i%2) == 1) cnt++;
    }

    double ans = cnt/n;
    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}


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

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

const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        while(a % 2 == 0){
            a /= 2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
sum = 1
flag = 1
limit = 1000000000000000000
nums = list(map(int, input().split()))
for num in nums:
  if num == 0:
    sum = 0
    break;
  if flag == 1:
    sum *= num
  if sum > limit or sum == -1:
    flag = 2
    sum = -1
print(sum)

Measured memory_bytes: 21572
import static java.lang.System.out;
import java.util.Scanner;

class XCubic {
    public void run() {
        int input = new Scanner( System.in).nextInt();
        out.println( power( input, 3));
    }

    private int power( int num, int index) {
        if ( index < 2) {
            return num;
        }
        return num * power( num, index -1);
    }
}

public class Main {
    public static void main( String... args) {
        XCubic test = new XCubic();
        test.run();
    }
}

Measured memory_bytes: 26276
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    char x, y;
    cin >> x >> y;
    if(x > y) cout << '>' << endl;
    else if(x == y) cout << '=' << endl;
    else cout << '<' << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

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

        int n = cin.nextInt();
        int[] d = new int[n];
        for(int i=0;i<n;i++) d[i] = cin.nextInt();
        long sum = 0;
        for(int i=0;i<n;i++) {
            for(int j=i+1;j<n;j++) {
                sum += d[i] * d[j];
            }
        }

        cout.println(sum);
        cout.close();
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;;
  vector<vector<int>> p(101000);
  int a,b;
  rep(i,N){
    cin >> a >> b;
    p[a].pb(b);
  }
  
  int ans=0;
  priority_queue<int> q;
  for(int i=1;i<=M;i++){
    for(int j=0;j<(int)p[i].size();j++){
      q.push(p[i][j]);
    }
    if(!q.empty()){
      ans += q.top();
      q.pop();
    }
  }

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


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

int main() {
    int a,b;
    cin>>a>>b;
    if(a+b==3){
        cout<<3<<endl;
    }
    if(a+b==4){
        cout<<2<<endl;
    }
    if(a+b==5){
        cout<<1<<endl;
    }
  

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 199
void initialize(void);
int isEmpty(void);
int isFull(void);
void push(int x);
int pop(void);
int top;
int S[MAX];
int main(){
  int y1,y2;
  char x[100];
  initialize();
  while(scanf("%s",x)!=EOF){
    if ( x[0] == '+' ){
      y1=pop();
      y2=pop();
      push(y1+y2);
    } else if ( x[0] == '-' ){
      y2=pop();
      y1=pop();
      push(y1-y2);
      
    } else if( x[0] == '*' ){
      y1=pop();
      y2=pop();
      push(y1*y2);
    }
    else {
      y1=atoi(x);
      push(y1);
    }
  }
  printf("%d\n",pop());
  return 0;
}
void initialize(void){
  top=0;
}

int isEmpty(void){
  if(top==0) return 1;
  else return 0;
}
int isFull(void){
  if(top>=MAX-1) return 1;
  return 0;
}
void push(int x){
  
  if(isFull()==1){
    fprintf(stderr,"??¨??????????????????????????????)\n");
    exit(1);
    }
  top++;
  S[top]=x;
}
int pop(void){
  
  if(isEmpty()==1){
    fprintf(stderr,"??¨???????????¢?????????????????????\n");
    exit(1);
    return 0;
    }
  top--;
  return S[top+1];
}

Measured memory_bytes: 2756
mod = 10**9+7
fac = [1]
for i in range(1,10**5+10):
	fac.append(fac[-1]*i%mod)
n,m = map(int,raw_input().split())
if abs(n-m) > 1:
	print "0"
elif abs(n-m) == 1:
	print fac[n]*fac[m]%mod
else:
	print 2*fac[n]*fac[m]%mod



Measured memory_bytes: 36716
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
	
		Scanner stdIn = new Scanner(System.in);
		
		int[] s = new int[10000];
		
		s[0] = stdIn.nextInt();
		
		for (int i = 0; ;i++) {
		
			if (s[i] % 2 == 0) {
				s[i + 1] = s[i] / 2;
			}
			
			else {
				s[i + 1] = 3 * s[i] + 1; 
			}
			
			for (int j = 0; j < i; j++) {
				if (s[i] == s[j]) {
					System.out.println(i + 1);
					return;
				}
			}
		}

	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	ll D = getint();
	ll kotae = (N - 1) * D;
	int A[200001];
	ll C[200001];
	C[0] = 1e18;
	rep1(i, N) {
		A[i] = getint();
		kotae += A[i];
		C[i] = min(C[i - 1] + D, (ll)A[i]);
	}
	ll mae = 1e18;
	for (int i = N - 1; i > 1; i--) {
		mae = min(mae + D, (ll)A[i + 1]);
		ll kari = min(mae, C[i - 1]) + D;
		kotae += min((ll)A[i], kari);
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 2688
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#pragma comment(linker, "/STACK:836777216")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-7
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(n) ((n) * (n))
#define N 35

int a[N];

int main(void) {
  int w;
  scanf("%d", &w);
  REP(i, w) {
    a[i] = i + 1;
  }
  int n;
  scanf("%d", &n);
  REP(i, n) {
    int x,y;
    scanf("%d,%d", &x, &y);
    x--,y--;
    swap(a[x],a[y]);
  }

  REP(i, w) {
    printf("%d\n", a[i]);
  }
}

Measured memory_bytes: 3132
//
// Created by moono on 2018/10/27.
//

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;



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

    //
    int T[N];
    for (int i = 0; i < N; ++i) {
        cin >> T[i];
    }

    //
    cin >> M;
    int p, x;
    for (int i = 0; i < M; ++i) {
        cin >> p >> x;

        p -=1 ;
        int sum = 0;
        for (int j = 0; j < N; ++j) {
            if(j == p ) sum += x;
            else sum += T[j];
        }
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
   int n,i,j,a,b,c,d,x,y,sum=0;
   while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
   {
   	sum=0;
	if(a<b)
		sum+=a;
	else
		sum+=b;
	if(c<d)
		sum+=c;
	else
		sum+=d;
	}
   printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
/*  ex4_3
    yy8332  */

#include <stdio.h>
int total(int num);


int main(void){
  int num1, num2, ans;

  //入力読み取り
  scanf("%d %d", &num1, &num2);

  ans = total(num2 - num1) - num2;


  //出力
  printf("%d",ans);


  return 0;
}

int total(int num){
  int sum;

  sum = ((1 + num) * num) / 2;

  return(sum);
}


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

typedef long long ll;

int main()
{
    ll i,j;
    double l;
    cin >> l;
    double tmp = l/3.0;
    double ans = pow(tmp, 3.0);
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int main(void)
{
	int A, B, C;
	cin >> A >> B >> C;
	int ans = 0;
	while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0){
		if(A == B && B == C){
			PrintLn(-1);
			return 0;
		}
		int a = A / 2;
		int b = B / 2;
		int c = C / 2;
		A = b + c;
		B = c + a;
		C = a + b;
		ans++;
	}
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    char N[6];
    int n;
    gets(N);
    sscanf(N, "%d", &n);
    if(n % 1000 == 0){
        printf("0");
        return 0;
    }
    printf("%d",1000 - (n % 1000));
    return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  
  vector<ll> a1(N); rep(i, N) cin >> a1[i];
  vector<ll> a2(N); rep(i, N) cin >> a2[i];
  ll ans = 0;
  // bool ok = false;

  vector<ll> s1(N), s2(N);
  s1[0] = a1[0];
  s2[N - 1] = a2[N - 1]; 
  rep1(i, N - 1) {
    s1[i] = s1[i - 1] + a1[i];
    s2[N - 1 - i] = s2[N - i] + a2[N - 1 - i];
  }
  /*
  rep(i, N) cout << s1[i] << " ";
  cout << endl;
  rep(i, N) cout << s2[i] << " ";
  cout << endl;
  */
  
  rep(i, N) {
    ll s = s1[i] + s2[i];
    chmax(ans, s);
  }
  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <vector>
#include <set>
using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

const ll MAX_N = 1e5 + 5, MOD = 1e9 + 7;
ll n, k;
ll par[MAX_N];
ll len[MAX_N];
vector <pii> ans;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> k;
	if ((n - 1) * (n - 2) / 2 < k) {
		cout << "-1\n";
		return 0;
	}

	for (int i = 1; i < n; i++)
		ans.push_back({0, i});

	k = (n - 1) * (n - 2) / 2 - k;
	for (int i = 1; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if (k) {
				ans.push_back({i, j});
				k--;
			}

	cout << ans.size() << "\n";
	for (pii p: ans)
		cout << p.first + 1 << " " << p.second + 1 << "\n";
	return 0;
}

Measured memory_bytes: 512
n = int(input())
A = list(map(int, input().split()))

M = max(A)
m = min(A)
for i, a in enumerate(A):
    if a == M:
        max_id = i
    if a == m:
        min_id = i

ans = []
if m >= 0:
    for i in range(n-1):
        ans.append((i+1, i+2))
elif M <= 0:
    for i in reversed(range(1, n)):
        ans.append((i+1, i))
else:
    if abs(M) >= abs(m):
        for i, a in enumerate(A):
            if a < 0:
                ans.append((max_id+1, i+1))
        for i in range(n-1):
            ans.append((i+1, i+2))
    else:
        for i, a in enumerate(A):
            if a > 0:
                ans.append((min_id+1, i+1))
        for i in reversed(range(1, n)):
            ans.append((i+1, i))
print(len(ans))
for i in range(len(ans)):
    print(*ans[i])


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

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

int main(){
    ll N, L;
    cin >> N >> L;
    vector<P> ls, imos;
    for(int i=0;i<N;i++){
        ll l, r;
        cin >> l >> r;
        ls.push_back(P(l,r));
        imos.push_back(P(l,+1));
        imos.push_back(P(r,-1));
    }
    sort(ls.begin(), ls.end());
    sort(imos.begin(), imos.end());
    ll x = 0;
    for(ll rmax = 0, i=0; rmax < L;){
        ll tmp = rmax;
        while(i<N && ls[i].first <= rmax){
            tmp = max(tmp, ls[i].second);
            i++;
        }
        x++;
        rmax = tmp;
    }
    ll sum = 0, smin = INT_MAX;
    for(int i=0;i<N*2-1;i++){
        sum += imos[i].second;
        if(imos[i].first != imos[i+1].first){
            smin = min(sum, smin);
        }
    }
    ll y = N - smin + 1;
    cout << x << " " << y << endl;
    return 0;

}


Measured memory_bytes: 13268
#include<stdio.h>
int main()
{
	int n,p[10],i,m=-1,x=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
		x+=p[i];
		if(m<p[i]) m=p[i];
	}
	printf("%d\n",(x-m)+m/2);
	return 0;
}


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

int n,a,b,c,d;
string s;
int dist, ano, g_d, g_a, fail;

void fundis(bool* b){
    while(!*b){
        if((dist+1)<n && s[dist+1]=='.'){
            s[dist]='.';
            dist++;
            s[dist]='D';
        }else if((dist+2)<n && s[dist+2]=='.'){
        	s[dist]='.';
            dist+=2;
            s[dist]='D';
        }else{
            fail++;
            break;
        }
        if(dist==g_d)
            *b = true;
    }if(*b) fail++;
}
void funano(bool* b){
    if(!*b){
        if((ano+1)<n && s[ano+1]=='.'){
        	s[ano]='.';
            ano++;
            s[ano]='N';
        }else if((ano+2)<n && s[ano+2]=='.'){
        	s[ano]='.';
            ano+=2;
            s[ano]='N';
        }else{
            fail++;
        }
        if(ano==g_a)
            *b = true;
    }else fail++;
}
int main(){
    cin>>n>>a>>b>>c>>d;
    cin>>s;
    if(c>d){
        dist = a-1; ano=b-1;
        s[dist]='D'; s[ano]='N';
        g_d = c-1; g_a = d-1;
    }else{
        dist = b-1; ano=a-1;
        s[dist]='D'; s[ano]='N';
        g_d = d-1; g_a = c-1;
    }
    bool isgoald = false, isgoala = false;
    while(fail<2){
        fail=0;
        //cout<<s<<"\n";
        fundis(&isgoald);
        funano(&isgoala);
    }
    if(isgoald&&isgoala)
        cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	static Main main = new Main();
	static HashMap<String, Item> itemTable = new HashMap<String, Item>();

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0")) {
			int m = 0, n = 0;
			String target;

			n = Integer.parseInt(line);
			for (int i = 0; i < n; i++) {
				Item item = getItemInstance(br.readLine());
				itemTable.put(item.name, item);
			}

			m = Integer.parseInt(br.readLine());
			for (int i = 0; i < m; i++) {
				setRecipe(br.readLine());
			}

			target = br.readLine();
			System.out.println(itemTable.get(target).getMinCost());
		}
	}

	class Item {
		String name;
		int price;
		int recipeCount = 0;
		ArrayList<Item> recipe;

		Item(String name, int price) {
			this.name = name;
			this.price = price;
		}

		int getMinCost() {
			int min = 0;
			if (recipeCount == 0) {
				min = price;
			} else {
				for (Item i : recipe) {
					if (i != null)
						min += i.getMinCost();
				}
			}
			return min < price ? min : price;
		}
	}

	static Item getItemInstance(String info) {
		int n = info.indexOf(' ');
		String name = info.substring(0, n);
		int price = Integer.parseInt(info.substring(n + 1));
		return main.new Item(name, price);
	}

	static void setRecipe(String info) {
		StringTokenizer st = new StringTokenizer(info);
		Item item = itemTable.get(st.nextToken());
		item.recipeCount = Integer.parseInt(st.nextToken());
		item.recipe = new ArrayList<Item>();
		while (st.countTokens() > 0) {
			item.recipe.add(itemTable.get(st.nextToken()));
		}
	}
}

Measured memory_bytes: 21652
import math

n, k = map(int, input().split(" "))
r, s, p = map(int, input().split(" "))
t = input()

w = {"r": p, "s": r, "p": s}

li = [0 for _ in range(n)]
for i in range(len(t)):
    wp = w[t[i]]
    if not (i - k >= 0 and li[i - k] == wp and t[i] == t[i - k]):
        li[i] = wp

print(sum(li))

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

int main(){
	int i,cnt=0,ans=0;
	string s;
	cin>>s;
	if(s=="SSS"){
		cout<<0;
		return 0;
	}
	if(s=="RRR") cout<<3;
	else if(s=="RRS"||s=="SRR") cout<<2;
	else cout<<1;
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
const int N = 3001;
const long long INF = (long long)1e13;

int n;

int a[N];
long long memo[N][N]; // max X - Y that TARO can obtain from seq i --- j

long long dp (int st, int end) {
	if ((st + 1) == end) {
		memo[st][end] = abs(a[st] - a[end]);
		return memo[st][end];
	}
	if (st == end) {
		memo[st][end] = a[st];
		return a[st];
	}
	if (memo[st][end] != -INF) {
		return memo[st][end];
	}
	long long beg = dp(st + 1, end);
	long long lst = dp(st, end - 1);
	if ((a[st] - beg) > (a[end] - lst))
		memo[st][end] = a[st] - beg;
	else
		memo[st][end] = a[end] - lst;
	return memo[st][end];
}

int main () {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			memo[i][j] = -INF;
	cout << dp(0, n - 1) << "\n";
	return 0;
}

Measured memory_bytes: 70784
//ABC110B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include<stdio.h>
#include<climits>
#include<cfloat>
using namespace std;

int main(){
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	vector<int>a(n), b(m);
	for(int i=0;i<n;i++){
		cin >> a.at(i);
	}
	for(int i=0;i<m;i++){
		cin >> b.at(i);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	if(a.at(n-1)<b.at(0) && x<y){
		for(int i=a.at(n-1)+1;i<=b.at(0);i++){
			if(x<i && i<=y){
				cout << "No War" << endl;
				return 0;
			}
		}
	}
	cout << "War" << endl;
	return 0;
}

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

#define mp make_pair
#define fi first
#define se second
#define forn(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) forn(i, 0, (n))
#define all(x) x.begin(), x.end()
#define len(x) (int)x.size()
#define endl '\n'

#define int long long
#define vc vector
#define pq priority_queue
#define uset unordered_set
#define umap unordered_map
#define vi vc<int>
#define pii pair<int, int>
#define vii vc<pii>

inline void FASTIO(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

void solve(){
    return;
}

int a[2019]{1}, b[2019], ans;

signed main(){
    FASTIO();
    string s; cin >> s;
    for(auto i : s){
        int x = i - '0';
        rep(j, 2019){
            b[(j * 10 + x) % 2019] = a[j];
        }
        rep(j, 2019){
            a[j] = b [j];
        }
        ans += a[0];
        a[0]++;
    }
    cout << ans;
}


Measured memory_bytes: 3736
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

const int N = 5;
int c[N];

bool isStraight() {
  if(c[0] == 1 && c[1] == 10 &&
     c[2] == 11 && c[3] == 12 && c[4] == 13) return true;
  for(int i = 1; i < N; ++i) {
    if(c[i-1]+1 !=  c[i]) return false;
  }
  return true;
}

bool isTwoPair() {
  int num = 0;
  for(int i = i; i < N; ++i) {
    if(c[i-1] == c[i]) {
      ++num;
      while(c[i-1] == c[i]) ++i;
    }
  }
  return num == 2;
}

int main() {
  string s;
  while(cin >> s) {
    replace(s.begin(), s.end(), ',', ' ');
    stringstream ss(s);
    for(int i = 0; i < N; ++i) ss >> c[i];
    sort(c,c+N);
    if(c[0] == c[3] || c[1] == c[4]) {
      cout << "four card" << endl;
    } else if(c[0] == c[2] && c[3] == c[4] ||
	      c[0] == c[1] && c[2] == c[4]) {
      cout << "full house" << endl;
    } else if(isStraight()) {
      cout << "straight" << endl;
    } else if(c[0] == c[2] || c[1] == c[3] || c[2] == c[4]) {
      cout << "three card" << endl;
    } else if(isTwoPair()) {
      cout << "two pair" << endl;
    } else if(c[0] == c[1] || c[1] == c[2] || c[2] == c[3] || c[3] == c[4]) {
      cout << "one pair" << endl;
    } else {
      cout << "null" << endl;
    }
  }
 return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<int,int> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<vector<P>> g(n+1);
    vector<int> dp(n+1,0);
    rep(i,m){
      int a,b,c;
      cin>>a>>b>>c;
      g[a].push_back(P(b,c));
    }
    queue<int> que;
    que.push(0);
    while(!que.empty()){
      int v=que.front();
      que.pop();
      for(auto itr:g[v]){
        if(dp[itr.fi]<dp[v]+itr.se){
          dp[itr.fi]=dp[v]+itr.se;
          que.push(itr.fi);
        }
      }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 3236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");

    int n = Integer.parseInt(sl[0]);

    int a[] = new int[101];

    s = r.readLine();
    sl = s.split(" ");
    for(int i = 0; i < n; i++)
    {
    	a[i + 1] = Integer.parseInt(sl[i]);
    }

    int v = 0;
    for(int i = 100; i > 0; i--)
    {
    	boolean b = false;
        for(int j = 0; j <= n; j++)
        {
        	if(i <= a[j] && !b)
        	{
        		v++;
        		b = true;
        	}
        	else if(a[j] < i)
        	{
        		b = false;
        	}
        }
    }

    System.out.println(v);
  }

}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;

int n;
long a, b;
long h[100010];

bool check(long mid){
  long cnt = 0;
  rep(i, n)if(h[i]-b*mid > 0) cnt += (h[i]-b*mid-1)/(a-b) + 1;
  return cnt <= mid;
}

int main(){
  cin >> n >> a >> b;
  rep(i, n) cin >> h[i];
  long ok = 1000000010;
  long ng = 0;
  while(ok - ng > 1){
    long mid = (ok + ng) / 2;
    if(check(mid)) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int64_t x;
    cin >> x;
    int64_t counter=0,prop=100;
    while(prop<x){
        prop += prop/100;
        counter++;
    }
    cout << counter << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;
import java.math.BigInteger;

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

    BigInteger a = new BigInteger(sc.next());
    BigInteger b = new BigInteger(sc.next());

    if(a.equals(b)){
      System.out.println("EQUAL");
    }
    else if(a.compareTo(b) > 0){
      System.out.println("GREATER");
    }
    else{
      System.out.println("LESS");
    }
  }
}


Measured memory_bytes: 23892
#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;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
double eps =000000000.1;
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;
map<ll,int> mp;
int main()
{
    Khela
    ll  a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx,A,B;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n)
    {
        int sum[n+2];
        for(i=1;i<=n;i++){
            cin>>x;
            if(x==i) sum[i]=1;
            else sum[i]=0;
        }
        
        int tot=0;
        int last=0;
        for(i=1;i<=n;i++){
            if(sum[i]==1) ++last;
            else{
                if(last>0){
                    tot+=(int)(ceil((double)(last)/2.00));
                }
                last=0;
            }
        }
                    if(last>0){
                    tot+=(int)(ceil((double)(last)/2.00));
                    }
                   last=0;
                   cout<<tot<<endl;
    }




}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  string S1;
  string S2;
  
  int ans_cout = 0;
  
  for(int i=1; i<N-1; i++){
    S1 = S.substr(0,i);
    S2 = S.substr(i,S.size()-1);
    
    sort(S1.begin(), S1.end());
    sort(S2.begin(), S2.end());
    
    for(int l = 0; l<S1.size()-1; l++){
      if(S1.at(l) == S1.at(l+1)){
        S1.erase(S1.begin()+l);
        l--;
      }
    }
    for(int m = 0; m<S2.size()-1; m++){
      if(S2.at(m) == S2.at(m+1)){
        S2.erase(S2.begin()+m);
        m--;
      }
    }
    
    int ans = 0;
    for(int j=0; j<S1.size(); j++){
      for(int k=0; k<S2.size(); k++){
        if(S1.at(j) == S2.at(k)){
          ans++;
        }
      }
      ans_cout = max(ans,ans_cout);
    }
  }  
   cout << ans_cout << endl;
}

Measured memory_bytes: 256
n = int(input())
k = int(input())
x = list(map(int,input().split()))
a = 0
b = 0
c = 0

for i in range(n):
    a = x[i] * 2
    b = abs(x[i] - k) * 2
    c += min(a,b)
    
print(c)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define vec_rep(itr,v) for(auto itr = v.begin(); itr != v.end(); ++itr)
const int MOD = 998244353;

int main(void){
    int N,S;
    cin >> N >> S;
    ll dp[N+1][S+1];
    int A[N];
    rep(i,N)cin >> A[i];
    rep(i,N+1)rep(j,S+1)dp[i][j] = 0;
    dp[0][0] = 1;
    ll ans = 0;
    rep(i,N){
        rep(j,S)(dp[i+1][j] += dp[i][j]) %= MOD;
        if(A[i] <= S)dp[i+1][A[i]] += i+1;
        rep1(j,S){
            if(A[i] + j <= S)(dp[i+1][A[i]+j] += dp[i][j]) %= MOD;
            if(A[i] + j == S)(ans += (dp[i][j] * (N-i)) % MOD) %= MOD;
        }
        if(A[i] == S)ans+=(i+1)*(N-i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70656
import java.util.*;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

    static int N;
    static int A;
    static long B;
    static long C;
    static long[] x = new long[1000];
    static long[] y = new long[1000];
    static long[] z = new long[1000];





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

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        for (int i = 0; i < N; i++) {
            x[i] = scanner.nextLong();
            y[i] = scanner.nextLong();
            z[i] = scanner.nextLong();
        }


        int[][] tukau = {{1,1,1}, {1,1,-1}, {1,-1,1}, {1,-1,-1}, {-1,1,1}
                , {-1,1,-1}, {-1,-1,1}, {-1,-1,-1}};

        long ret = 0;
        long[] use = new long[N];
        for (int i = 0; i <= 7; i++) {
            for (int j = 0; j < N; j++) {
                use[j] = x[j] * tukau[i][0] + y[j] * tukau[i][1] + z[j] * tukau[i][2];
            }
            Arrays.sort(use);

            long ans = 0;
            for (int j = 0; j < M; j++) {
                ans += use[N - j - 1];
            }
//            System.out.println(ans);
            ret = Math.max(ans, ret);
        }

        System.out.println(ret);




    }

//    public static void itter()

}



Measured memory_bytes: 27080
// B - TAKOYAKI FESTIVAL 2019

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

int main(){
	int N;
	int d[50];

	cin >> N;

	for (int i=0; i<N; i++) {
		cin >> d[i];
	}

	int ans = 0;
	for (int i=0; i<N-1; i++) {
		for (int j=i+1; j<N; j++) {
			ans += d[i] * d[j];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cstdlib>
#include<map>
#include<vector>
#include<complex>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P complex<int>
#define X real()
#define Y imag()

void toCenter(vector<P> &v){
    P m(v[0].X * -1, v[0].Y * -1);
    REP(i, v.size()) v[i] += m;
}

bool isSame(vector<P> zero, vector<P> v){
    if(zero == v) return true;
    reverse(v.begin(), v.end());
    if(zero == v) return true;
    return false;
}

void disp(vector<P> v){
    REP(i, v.size()) cout <<v[i] <<", ";
    cout <<endl;
}

int main(){
    int n;
    while(cin >>n && n){
        int m, a, b;
        vector< vector<P> > v(n, vector<P>());
        vector<P> zero;
        cin >>m;
        REP(i, m){
            cin >>a >>b;
            zero.push_back( P(a, b) );
        }
        toCenter(zero);
        REP(i, n){
            cin >>m;
            REP(j, m){
                cin >>a >>b;
                v[i].push_back( P(a, b) );
            }
            toCenter(v[i]);
        }

        vector<int> ans;
        REP(i, n){
            REP(j, 4){
                //回転
                REP(k, v[i].size()){
                    swap(v[i][k].Y, v[i][k].X);
                    v[i][k].Y *= -1;
                }
                //普通の方向
                if(isSame(zero, v[i])) ans.push_back(i + 1);
                //今までしっぽだったやつを先頭にして再度中心調整
                reverse(v[i].begin(), v[i].end());
                toCenter(v[i]);
                if(isSame(zero, v[i])) ans.push_back(i + 1);
                //元に戻す
                reverse(v[i].begin(), v[i].end());
                toCenter(v[i]);
            }
        }
        REP(i, (int)ans.size()) cout <<ans[i] <<endl;
        cout <<"+++++" <<endl;
    }
    return 0;
}

Measured memory_bytes: 1228
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define coyes cout << "Yes" << endl;
#define cono cout << "No" << endl;
#define coYes cout << "YES" << endl;
#define coNo cout << "NO" << endl;
using namespace std;
using ll = long long int;
string large_al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string small_al = "abcdefghijklmnopqrstuvwxyz";
using Graph = vector<vector<int>>;
using i64 = int64_t;


int main() {
  i64 n, a, b;
  cin >> n >> a >> b;
  if (n % (a + b) <= a) {
    cout << a * (n / (a + b)) + n % (a + b) << endl;
  }
  else {
    cout << a * (n / (a + b)) + a << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

struct State{
  //TODO: 作成
  vector<int> type;

  /// \brief 現在のstateからscoreを得る
  /// \return score
  lint CalcScore(vector<int>& c, vector<vector<int>>& s){
    //TODO: 実装
    lint result=0;
    vector<int> last(27, 0);
    for(int d=1;d<=365;d++){
      result+=s[d][type[d]];
      last[type[d]]=d;
      for(int i=1;i<=26;i++){
        result-=c[i]*(d-last[i]);
      }
      cerr<<result<<endl;
    }
    return result;
  }
};

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int d;
  cin>>d;
  vector<int> c(27);
  vector<vector<int>> s(d+1, vector<int>(27));

  for(int i=1;i<=26;i++){
    cin>>c[i];
  }

  for(int i=1;i<=d;i++){
    for(int j=1;j<=26;j++){
      cin>>s[i][j];
    }
  }

  vector<int> v(d+1);
  for(int i=1;i<=d;i++){
    cin>>v[i];
  }

  lint result=0;
  vector<int> last(27, 0);
  for(int di=1;di<=d;di++){
    result+=s[di][v[di]];
    last[v[di]]=di;
    for(int i=1;i<=26;i++){
      result-=c[i]*(di-last[i]);
    }
    cout<<result<<endl;
  }


  return 0;
}




Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int x;
  rep(i, 5) {
    cin >> x;
    if(x == 0) cout << i+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3620
N, M = map(int, input().split())
K = []
S = []
ans = 0
for _ in range(M):
    tmp = list(map(int, input().split()))
    k, s = tmp[0], tmp[1:]
    K.append(k)
    S.append(s)
P = [int(p) for p in input().split()]
for i in range(2**N):
    cnt = [0]*M
    f = 0
    for m, s in enumerate(S):
        for j in s:
            if ((i >> (j-1)) & 1):
                cnt[m] += 1
        for m in range(M):
            if cnt[m] % 2 != P[m]:
                f = 0
                break
            f = 1
    if f:
        ans += 1
    
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>

int main (void)
{
    long long N, H, W, A[1000], B[1000];
    int i, ans;

    scanf("%lld %lld %lld", &N, &H, &W);

    for (i = 0; i < N; i++) {
        scanf("%lld %lld", &A[i], &B[i]);
        if ((A[i] >= H) && (B[i] >= W)) ans++;
    }

    printf("%d\n", ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;


class UnionFind{
	static const int gmax_n = 505;

	int par[gmax_n]; //???
	int depth[gmax_n];//??¨?????±???

	public:
	void init(int n){
		rep(i,n){
			par[i] = i;
			depth[i] = 0;
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else {
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(depth[x] < depth[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(depth[x] == depth[y]) depth[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

struct Edge{
	int u, v, cost, id;
	Edge() {}
	Edge(int u, int v, int cost) : u(u), v(v), cost(cost) {}

	bool operator < ( const Edge &right ) const {
		if(cost < right.cost){
			return 1;
		}else if(cost == right.cost){
			if(u < right.u){
				return 1;
			}else if(u == right.u){
				if(v == right.v){
					return 1;
				}else {
					return 0;
				}
			}else{
				return 0;
			}
		}else{
			return 0;
		}
	}
};

class Kruskal{
	private:
		static const int MAX_E = 50005;
		UnionFind unionFind;
	public:
		vector<Edge> edge;
		vector<int> mst; //edge[ mst[i] ] := ????°???¨?????¨????§??????????i????????????
		int solve(int v, int e, int d = -1){
			if(d == -1) sort(all(edge));
			if(d == -1){
				//for(auto i : edge){ cout << i.u << ' ' << i.v << ' ' << i.cost << endl; }
			}
			unionFind.init(v);
			int res = 0;
			rep(i,e){
				if(d == i) continue;
				Edge c = edge[i];
				if(not unionFind.same(c.u, c.v)){
					unionFind.unite(c.u, c.v);
					//cout << i << ' ';
					res += c.cost;
					if(d == -1) mst.emplace_back(i);
				}
			}
				//cout << endl;
			rep(i,v){
				if(not unionFind.same(0,i)) return INF;
			}
			return res;
		}
};


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

	Kruskal krus;
	rep(i,m){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		a--; b--;
		krus.edge.emplace_back(Edge{a,b,c});
	}

	int mini = krus.solve(n,m);

	int cnt = 0, cost = 0;
	rep(i,n - 1){
		if(mini < krus.solve(n,m, krus.mst[i])){
			cnt++;
			cost += krus.edge[ krus.mst[i] ].cost;
		}
	}
	printf("%d %d\n", cnt, cost);
}

Measured memory_bytes: 3884
n = int(input())

abn = [list(map(int,input().split())) for _ in range(n)]


#abn.sort()
abn.sort(key = lambda x:x[1])


#print(abn)

ts = 0 # time_stamp
enable = True
for abi in abn:
    a, b = abi

    if not ts + a <= b:
        enable = False
        break
    else:
        ts += a

print('Yes' if enable else 'No')

Measured memory_bytes: 53600
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=1e6+10;
int cn[maxn];
int n;
char s[maxn];
bool check2()
{
	for(int i=0;i<n;i++)if(s[i]=='2')return 0;
	int c2=0;
	for(int i=0;i<n;i++)
	{
		if(cn[i]&&(s[i]=='1'))c2^=1;
	}
	return c2;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	int sum=0;
	for(int i=0;i<n;i++)
	{
		cn[i]=((n-1)&i)==i;
		if(cn[i]&&(s[i]!='2'))sum^=1;
	}
	if(sum==1)
	{
		printf("1\n");
	}
	else
	{
		if(check2())printf("2\n");
		else printf("0\n");
	}
	return 0;
	
}

Measured memory_bytes: 5120