akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q; cin >> Q;
    priority_queue<int> queL;
    priority_queue<int, vector<int>, greater<int>> queR;
    int k = 0;
    int sumL = 0, sumR = 0;
    while(Q--) {
        int t; cin >> t;
        if(t == 1) {
            int a, b;
            cin >> a >> b;
            if (queR.empty()) {queR.push(a); sumR += a;}
            else if (queL.empty()) {
                queL.push(a); sumL += a;
                if(queL.top() > queR.top()) {
                    int tmpL = queL.top(); queL.pop();
                    int tmpR = queR.top(); queR.pop();
                    queL.push(tmpR);
                    queR.push(tmpL);
                    swap(sumL, sumR);
                }
            }
            else if (queL.top() < a) {queR.push(a); sumR += a;}
            else  {queL.push(a); sumL += a;}
            while((int)queR.size() - (int)queL.size() > 1) {
                sumL += queR.top();
                sumR -= queR.top();
                queL.push(queR.top()); queR.pop();
            }
            while(queL.size() > queR.size()) {
                sumL -= queL.top();
                sumR += queL.top();
                queR.push(queL.top()); queL.pop();
            }          
            k += b;
        } else {
            //cout << "*" << queL.size() << " " << queR.size() << endl;
            int c = 0;
            if (queR.size() != queL.size()) c = queR.top();
            if (queL.size() < queR.size())
                cout << queR.top()  << " " <<(sumR-c) - sumL+k << endl;
            else
                cout << queL.top()  << " " << (sumR-c) - sumL+k << endl;
        }
    }

    return 0;
}
// |X - (-3)| + |X - 4|


Measured memory_bytes: 3828
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
bool f[1000001];
int main(){
	int n,a,b,s,t;
	while(cin>>n>>a>>b,n){
		rep(i,n+1)f[i]=1;
		rep(j,a)for(t=b*j;t<=n;t+=a)f[t]=0;
		s=0; rep(i,n)s+=f[i+1];
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, W;
  string DE[4] = {"maerd","esare","resare","remaerd"};
  int L, N, K;
  cin >> S;
  L = S.size();
  N = L;
  bool H = true;
  reverse(S.begin(), S.end());
  
  
  while(H){
     W = "";
     if(N == 0){
     break;
     }
     if(N < 5){
     H = false;
     break;
     }
    
     if(S.at(L - N) == 'm' || S.at(L - N) == 'e'){
     K = 0;
     }
     else if(S.at(L - N) == 'r'){
        if(S.at(L - N + 2) == 's'){
        K = 1;
        }
        else if(S.at(L - N + 2) == 'm'){
        K = 2;
        }
     }
        
     for(int i = 0;i < 5 + K;i++){
     W = W + S.at(L - N + i);
     }
 
     if(W == DE[0] || W == DE[1] || W == DE[2] || W == DE[3]){
     N = N - 5 - K;
     }
     else{
     H = false;
     }
  }
 
  if(H) cout << "YES" << endl;
  else  cout << "NO" << endl;
}

Measured memory_bytes: 512
N = int(input())
x = 0
 
for i in range(1,N+1):
 
    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()


Measured memory_bytes: 5868
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

vector<int> g[200100];

int main(){
	int n, m; cin >> n >> m;
	vector<int> candy;
	for( int i = 0; i < m; ++i ){
		int a, b; cin >> a >> b; --a; --b;
		if( a == 0 ) candy.push_back(b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for( auto k : candy ){
		for( auto node : g[k] ){
			if( node == n-1 ){
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = INT_MAX;
    for(int i = 0;i < n;i++){
      cin >> a[i];
      if(ans > a[i]){
        ans = a[i];
      }
    }
    bool flag = true;
    while(flag){
      int min = INT_MAX;
      for(int j=0;j < n;j++){
        if(ans == a[j] || a[j] == 0)continue;
        a[j] = a[j] % ans;
        // cout << a[j] << endl;
        if(a[j] != 0 && min > a[j]){
          min = a[j];
        }
      }
      // cout << "ans:" << ans << " min:" << min << endl;
      if(min == INT_MAX || min == ans || min == 0)flag = false;
      else ans = min;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <list>
#include <string>
using namespace std;
int main()
{
    int n;
    string s;
    cin >> n;
    list<string> lst;
    for(int i = 0; i<n; i++){
        cin >> s;
        lst.push_back(s);
    }
    lst.sort();
    lst.unique();
    cout << lst.size() << endl;
    return 0;
}

Measured memory_bytes: 16092
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(a == b ? a * 2 : Math.max(a, b) * 2 - 1);
	}
}

Measured memory_bytes: 24404
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    long long M;
    cin >> N >> M;
    vector<pair<long long, long long>> v(N);
    for (int i = 0; i < N; ++i) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());

    long long res = 0;
    for (int i = 0; i < N && M > 0; ++i) {
        res += v[i].first * min(M, v[i].second);
        M -= min(M, v[i].second);
    }
    cout << res << endl;
}



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

int main() {
  int A;
  cin >> A;
  int B;
  cin >> B;
  int C;
  cin >> C;
  int D;
  cin >> D;
  int E;
  cin >> E;
  //input data
  int s = 0;
  if( B <= 0) {
    if(A < 0) s += C * ((A - B) * -1);
  }else if( B > 0) {
    if(A < 0){
       s += C * (A * -1);
       A = 0;
    }
    if(A == 0) s += D;
    if(A >= 0) s += E * (B - A);
  }
  cout << s << endl;
}

Measured memory_bytes: 3056
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int a,b;
  char op;
  cin >> a >> op >> b;
  while(op!='?'){
    int c;
    if(op=='+') c=a+b;
    if(op=='-') c=a-b;
    if(op=='*') c=a*b;
    if(op=='/') c=a/b;
    cout << c << endl;
    cin >> a >> op >> b;
  }
  return 0;
}



Measured memory_bytes: 3088
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
K, = [int(s) for s in inputs]

# 1000

if K<=9:
    print(K)
else:
    pre = list(range(1, 10))
    sp = [0]
    digit = 0
    num = 9
    while True:
        lunluns = []

        for pp in sp:
            num += 1
            lunlun = (10**(digit+1))+pp
            if K==num:
                print(lunlun)
                quit()
            lunluns.append(lunlun)

        for i in range(1, 10):

            for p in pre:
                s = p // (10**digit)
                if i==1 and s==1:
                    sp.append(p)
                if abs(i-s)<=1:
                    num += 1
                    lunlun = i*(10**(digit+1))+p
                    if K==num:
                        print(lunlun)
                        quit()
                    lunluns.append(lunlun)
        pre = lunluns
        digit += 1





Measured memory_bytes: 6592
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define se second
#define fi first
#define pb push_back
#define mod 1000000007
int main()
{
  ll n,k;
  cin >> n >> k ;
  ll sum=0,count=0,count1=0 ;
  ll i=0 ;
  while(i<=n)
  {
    count1 += (i) ;
    count += (n -i) ;
    //cout << count << " " << count1 << endl;
    if(i>=k-1)sum = (sum + count-count1+1)%mod ;
    i++ ;
  }
  cout << sum << endl;


}


Measured memory_bytes: 3644
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    char[] c = s.toCharArray();

    int count = 1;

    for(int i=0; i<n-1; i++){
      if(!(c[i] == c[i+1])){
        count++;
      }
    }
    System.out.println(count);
  }
}



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

struct UnionFind{
    // 頂点数(1-indexed)
    const int V;
    // par[x]:=xのroot
    vector<int> par;
    // sz[x]:=xを含む集合のサイズ
    vector<int> sz;
    UnionFind(const int V):V(V){
        par.resize(V+1);
        for(int i=0;i<=V;i++) par[i]=i;
        sz.resize(V+1,1);
    }
    void init(){
        for(int i=0;i<=V;i++) par[i]=i;
        for(int i=0;i<=V;i++) sz[i]=1;
    }
    bool unite(int x,int y){
        x=root(x),y=root(y);
        if(same(x,y)) return false;
        if(y<x) swap(x,y);
        par[y]=x;
        sz[x]+=sz[y];
        return true;
    }
    int root(int x){
    	if(par[x]==x) return x; // xはroot
    	return (par[x]=root(par[x])); // xの親のroot
    }
    bool same(int x,int y){
    	return (root(x)==root(y));
    }
    int size(int x){
        return sz[root(x)];
    }
};

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

bool able(int y, int x) {
    if(y < 0 or h <= y) return false;
    if(x < 0 or w <= x) return false;
    return true;
}

void merge(UnionFind &uf, vector<vector<int>> &board) {
    for(int y = 0; y < h; ++y) {
        for(int x = 0; x < w; ++x) {
            for(int i = 0; i < 4; ++i) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if(able(ny, nx)) {
                    if(board[y][x] == board[ny][nx]) {
                        uf.unite(y * w + x, ny * w + nx);
                    }
                }
            }
        }   
    }
}

int solve(vector<int> &color, vector<vector<int>> &board, UnionFind &uf) {
    // first merge
    merge(uf, board);
    // color change
    for(int q = 0; q < 5; ++q) {
        for(int y = 0; y < h; ++y) {
            for(int x = 0; x < w; ++x) {
                if(uf.same(0, y * w + x)) {
                    board[y][x] = color[q];
                }
            }   
        }
        merge(uf, board);
    }
    return uf.size(0);
}

int main() {
    while(cin >> h >> w >> c and h > 0) {
        c--;
        vector<vector<int>> p(h, vector<int>(w));
        for(int y = 0; y < h; ++y) {
            for(int x = 0; x < w; ++x) {
                cin >> p[y][x];
                p[y][x]--;
            }
        }
        int ans = 0;
        for(int mask = 0; mask < (int)pow(6, 4); ++mask) {
            vector<vector<int>> board = p;
            vector<int> color(5);
            int tmp = mask;
            for(int i = 0; i < 4; ++i) {
                color[i] = tmp % 6;
                tmp /= 6;
            }
            color[4] = c;
            UnionFind uf(h * w);
            ans = max(ans, solve(color, board, uf));
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);    
    for (int i = 0; i < n; i++)
        cin >> p[i];
    
    ll total = 0;
    for (int i = 0; i < k; i++)
        total += p[i];
    
    int id = 0;
    ll sub = total;
    for (int i = 1; i < n - k + 1; i++) {
        sub = sub - p[i - 1] + p[i + k - 1];
        if (sub > total) {
            id = i;
            total = sub;
        }
    }
    
    double e = 0.0;
    for (int i = id; i < id + k; i++) {
        e += double(p[i] + 1) / 2;
    }
    
    cout << setprecision(12) << e << endl;
    
    return 0;
}


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

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	ll s = c - a - b;
	if (s > 0 && 4 * a * b < s * s) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;

const int N = 105;
const int INF = 1e9 + 5;

char s[N];
int n, m, g[N][N], dp[N][N][2];

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; ++j) {
      g[i][j] = (s[j] == '#');
    }
  }
  for (int i = n; i >= 1; --i) {
    for (int j = m; j >= 1; --j) {
      for (int inside = 0; inside < 2; ++inside) {
        if (i == n and j == m) continue;
        dp[i][j][inside] = INF;
        if (i + 1 <= n) {
          int at = g[i + 1][j] ^ inside;
          dp[i][j][inside] = min(dp[i][j][inside], (at == 0) ? dp[i + 1][j][inside] : (inside ^ 1) + dp[i + 1][j][inside ^ 1]);
        } if (j + 1 <= m) {
          int at = g[i][j + 1] ^ inside;
          dp[i][j][inside] = min(dp[i][j][inside], (at == 0) ? dp[i][j + 1][inside] : (inside ^ 1) + dp[i][j + 1][inside ^ 1]);  
        }
      }
    }
  }
  int ans = g[1][1] ? 1 + dp[1][1][1] : dp[1][1][0];
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 384
fun main(args:Array<String>){
    val n=readInt()
    val a=readInts()
    var ok=1
    for(i in 0 until n){
        if(a[i]%2==0){
            if(a[i]%3==0||a[i]%5==0){

            }else{
                ok=0
            }
        }
    }
    if(ok>0){
        println("APPROVED")
    }else{
        println("DENIED")
    }
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

Measured memory_bytes: 37616
i,o,t,j,l,s,z=map(int,input().split())
ans=o
ans+=i-(i%2)
ans+=l-(l%2)
ans+=j-(j%2)
if i%2+j%2+l%2==3:
  ans+=3
elif i%2+j%2+l%2==2:
  if i*j*l>0:
    ans+=1
print(ans)

Measured memory_bytes: 3064
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))
D.sort()
T.sort()
from collections import Counter
D=Counter(D)
dic_D={}
for i in D.most_common():
  dic_D[i[0]]=i[1]
T=Counter(T)
ret = 'YES'
for i in T.most_common():
  if i[0] in dic_D:
    if dic_D[i[0]]<i[1]:
      ret = 'NO'
      break
  else:
    ret = 'NO'
    break
print(ret)

Measured memory_bytes: 79876
n, m = map(int, input().split())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))

ab.sort(key=lambda x:x[0])
nn = 0
ans = 0
for a, b in ab:
    if nn+b<m:
        nn += b
        ans += a*b
    else:
        ans += a*(m-nn)
        print(ans)
        break


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

int main(){
  int N; cin >> N;
  vector<double> v(N);
  for(int i=0;i<N;i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  double now=v[0];
  for(int i=1;i<N;i++){
    now=(now+v[i])/2;
  }
  cout << fixed << setprecision(10);
  cout << now << endl;
}
    

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
  int a[3],b[3],c[3][3],flag=1;
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      scanf("%d",&c[i][j]);
  a[0]=0;
  b[0]=c[0][0];
  b[1]=c[0][1];
  b[2]=c[0][2];
  a[1]=c[1][0]-b[0];
  a[2]=c[2][0]-b[0];
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++){
      if(c[i][j]!=a[i]+b[j])
        flag=0;
    }
  if(flag)
    printf("Yes\n");
  else
    printf("No\n");
}

Measured memory_bytes: 128
import java.util.*

fun main(args: Array<String>) {
	val sc = Scanner(System.`in`)
	val k = sc.nextInt()
	val s = sc.nextInt()

	var cnt = 0
	for (x in 0..k) {
		for (y in 0..k) {
			val z = s - x - y
			if (z in 0..k) {
				cnt++
			}
		}
	}
	println(cnt)
}


Measured memory_bytes: 29608
#!/usr/bin/env python3
class UnionFind():
    def __init__(self, n, m = None, read = 0):
        self.n = n
        self.parents = [-1] * n
        if read:
            if m is None:
                raise ValueError("What is M")
            for i in range(m):
                a, b = map(int, input().split())
                self.union(a - 1, b - 1)

    def find(self, 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 = 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):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, 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()}

C = []
n, k, l = map(int, input().split())
UF_R = UnionFind(n, k, 1)
UF_T = UnionFind(n, l, 1)
for i in range(n):
    R = UF_R.find(i)
    T = UF_T.find(i)
    C += (R, T),
from collections import*
c = Counter(C)
print(*[c[g] for g in C])

Measured memory_bytes: 44448
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B;
  cin >> A >> B;
  if(A<6){
   cout << 0 << endl;
  }
  if(A<13&&5<A){
   cout << B/2 << endl;
  }
  if(12<A){
   cout << B << endl;
  }  
}

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

using namespace std;

int INF = 10000000;

int n , p;

int k[50];


int main()
{

	while(cin >> n >> p && n && p)
	{
		
		memset(k,0,50*sizeof(int));
		int turn = 0;
		int pmax = p;

		while(1)
		{
			if(p > 0)
			{
				k[turn]++;p--;
				if(k[turn] == pmax)break;

			}else
			{
				p = k[turn];
				k[turn] = 0;
			}

			turn++;
			turn = turn % n;
		}

		cout << turn << endl;
	}

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <iostream>
#include <time.h>
using namespace std;
int g_bm = 1000000007;

#define _LL long long

int modl(_LL a)
{
    a %= g_bm;
    if( a < 0 ) a += g_bm * ( 1 - (a + 1) / g_bm );
    return a;
}

int modadd(_LL a, _LL b)
{
    return modl(a + b);
}

int modminus(_LL a, _LL b)
{
    return modl(a - b);
}

int modmul(_LL a, _LL b)
{
    return modl(a * b);    
}

int modpow(_LL a, _LL b)
{
    int prebit = modl(a);
    int ans = 1;
    for( int bit = 0; (long unsigned int) b >= (1UL << bit); bit++ )
    {
        if( bit > 0 ) prebit = modmul(prebit, prebit);
        if( b & (1UL << bit) ) ans = modmul(ans, prebit);
    }
    return ans;
}

int modcalcsub(_LL a, _LL b, char c)
{
    switch(c)
    {
        case '+':
            return modadd(a, b);
        case '-':
            return modminus(a, b);
        case '*':
            return modmul(a, b);
    }
    return 0;
}

int modsublevel(char c)
{
    switch(c)
    {
        case '+':
        case '-':
            return 0;
        case '*':
            return 1;
    }
    return 0;
}

int modinv(_LL a) 
{
    _LL b = g_bm, u = 1, v = 0;
    while (b) 
    {
        _LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    return modl(u);
}

int modcalc(_LL a1, char c1, _LL a2, char c2 = 0, _LL a3 = 0, char c3 = 0, _LL a4 = 0, char c4 = 0, _LL a5 = 0, char c5 = 0, _LL a6 = 0, char c6 = 0, _LL a7 = 0, char c7 = 0)
{
    char c[8] = {c1, c2, c3, c4, c5, c6, c7, '0'};
    _LL a[8] = {a1, a2, a3, a4, a5, a6, a7, 0};
    int ans[4];
    char prec[4];
    int level = 0;
    int index = 0;
    ans[0] = 0;
    prec[0] = '+';
    // 3 + 4 * 8 + 3
    while( prec[level] != '\0' )
    {
        int nlevel = modsublevel(c[index]);
        while( level < nlevel )
        {
            ans[level + 1] = 0;
            prec[level + 1] = '+';
            level++;
        }        
        ans[level] = modcalcsub( ans[level], a[index], prec[level]);
        while( nlevel < level )
        {
            ans[level - 1] = modcalcsub( ans[level - 1], ans[level], prec[level - 1]);
            level--;
        }
        prec[level] = c[index++];
    }
    return ans[0];
}

void addbitsum(_LL a, _LL *s0, _LL *s1, int d)
{
    for( _LL k = 0 ; k < 60; k++ )
    {
        if( a & (1LL << k) )
        {
            s1[k] += d;
        }
        else
        {
            s0[k] += d;
        }
    }

}

int main()
{
    _LL n;
    cin >> n;
    _LL *a = new _LL[n];
    for( _LL i = 0; i < n; i++ ) cin >> a[i];
    _LL sumj0[64];
    _LL sumj1[64];
    for( _LL k = 0 ; k < 64; k++ ) sumj0[k] = 0, sumj1[k] = 0;
    for( _LL j = 0; j < n; j++ ) addbitsum( a[j], sumj0, sumj1, 1);
    _LL ans = 0;
    for( _LL i = 0; i < n - 1; i++ )
    {
        addbitsum( a[i], sumj0, sumj1, -1);
        _LL bitpow = 1;
        for( _LL k = 0 ; k < 60; k++ )
        {
            _LL tmp = (a[i] & (1LL << k)) ? sumj0[k] : sumj1[k];
            ans = modadd( ans, modmul(tmp, bitpow % 1000000007) );
            bitpow = (bitpow << 1);
        }
    }
    cout << ans << endl;
    delete a;
}

Measured memory_bytes: 5540
use std::cmp::Ordering;
use std::cmp::Ordering::*;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, m, l) = parse!(it, 3);
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        let (a, b, c): (usize, usize, usize) = parse!(it, 3);
        g[a - 1].push((b - 1, c));
        g[b - 1].push((a - 1, c));
    }
    const LARGE: usize = std::usize::MAX / 10;
    let mut d = vec![vec![LARGE; n]; n];
    for i in 0..n {
        d[i][i] = 0;
        for &(j, c) in g[i].iter() {
            d[i][j] = c;
        }
    }
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                let alt = d[i][k] + d[k][j];
                if d[i][j] > alt {
                    d[i][j] = alt;
                }
            }
        }
    }

    let mut e = vec![vec![LARGE; n]; n];
    for i in 0..n {
        e[i][i] = 0;
        for j in 0..n {
            if d[i][j] <= l {
                e[i][j] = 1;
            }
        }
    }
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                let alt = e[i][k] + e[j][k];
                if e[i][j] > alt {
                    e[i][j] = alt;
                }
            }
        }
    }

    let qn: usize = parse!(it);
    for _ in 0..qn {
        let (s, t): (usize, usize) = parse!(it, 2);
        let s = s - 1;
        let t = t - 1;
        if e[s][t] == LARGE {
            println!("{}", -1);
        } else {
            println!("{}", e[s][t] - 1);
        }
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MAX (int)1e9 + 99
#define maxof(a,b,c) max(a,max(b,c))
#define minof(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vvi vector<vector<int>>
#define vb vector<bool>
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define bitcnt(x) __builtin_popcount(x)
#define gcd(a,b) __gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define ts(x) to_string(x)
#define rsort(a) sort(all(a)); reverse(all(a))
#define set0(x) memset(x, 0, sizeof(x))
const double pi = 3.14159265358979323846;
ll binpow(ll, ll);
ll mult(ll, ll);
ll add(ll , ll);
ll division(ll, ll);
ll nCr(ll, ll);
ll inv(ll);
void calc();
void maxi(int &a, int b) {if(a<b) a = b;}
void mini(int &a, int b) {if(a>b) a = b;}
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) {if (!v.empty()) {os << v.front();for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];} return os;}
const int N=50010;
const int MOD = 1e9+7;
//ll fact[N];






void solve()
{
    string s;
    cin>>s;
    int n = s.length();
    char e = 'e';
    char ch = 's';
    cout<<s;
    if(s[n-1] == 's') cout<<'e';
    

    cout<<'s';
}

int main()
{
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    
    rep(i,t)
    {
        solve();
        //cout<<"\n";
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}








ll add(ll a, ll b){
    a+=b;
    while(a>=MOD) a-=MOD;
    while(a<0) a+=MOD;
    return a;
}

ll mult(ll a, ll b){
    return (a * 1ll * b) % MOD;
}


ll binpow(ll a, ll b){
    ll c = 1;
    while(b > 0)
    {
        if(b % 2 == 1)
            c = mult(c, a);
        a = mult(a, a);
        b /= 2;
    }
    return c;   
}

ll inv(ll a){
    return binpow(a, MOD-2);
}

ll division(ll a, ll b){
    return mult(a, inv(b));
}
/*
ll nCr(ll n, ll r){
    if(r > n) return 0;
    return division(fact[n], mult(fact[n-r], fact[r]));
}

void calc(){
    fact[0] = 1;
    srep(i,1,N-1)
        fact[i] = (i*1ll*fac[i-1])%MOD;

}*/

Measured memory_bytes: 3796
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define INF 1e9;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
int main(){
	int x,y,z;
	cin>>x>>y>>z;
	x=x-z;
	int ans=x/(y+z);
	cout<<ans;
	return 0;
}

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

int main() {
  int a, b, k, d = 0;
  vector<int> vec;
  cin >> a >> b >> k;

  if (a > b) {
    d = b;
  }
  else {
    d = a;
  }

  for (int i = 1; i <= d; i++) {
    if (a % i == 0 && b % i == 0) {
      vec.push_back(i);
    }
  }
  sort(vec.begin(), vec.end(), greater<>());

  cout << vec.at(k-1) << endl;
}

Measured memory_bytes: 3600
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (a, b) = {
    let v: Vec<u64> = read_vec();
    (v[0], v[1])
  };
  let n = b - a - 1;
  let ans = (n * (n + 1)) / 2 - a;
  println!("{}", ans);
}


Measured memory_bytes: 4352
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, C;
int imos[35][200010];
 
signed main() {
    cin >> N >> C;
    rep(i,0,N) {
        int s, t, c; cin >> s >> t >> c; c--;
        imos[c][2*s-1]++;
        imos[c][2*t]--;
    }

    rep(i,0,C) rep(j,1,200010) imos[i][j] += imos[i][j-1];

    int ans = 0;
    rep(i,0,200010) {
        int tmp = 0;
        rep(k,0,C) {
            if(imos[k][i]) tmp++;
        }
        chmax(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 47360
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		int min = Integer.MAX_VALUE;
		for(int i = 1; i <= N - 1; i++){
			int A = i;
			int B = N - A;
			int sum = 0;
			while(true){
				sum += A % 10;
				A /= 10;
				if(A == 0) break;
			}
			while(true){
				sum += B % 10;
				B /= 10;
				if(B == 0) break;
			}
			min = Math.min(min, sum);
		}
		System.out.println(min);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21332
#!/usr/bin/ruby
P=->s{puts s;exit};R,C=gets.split.map &:to_i;N=gets.to_i;M=Hash.new{|h,k|h[k]=[]}
N.times{x,y,d=gets.split.map &:to_i;M[x]<<[y+R,d];M[y+R]<<[x,-d]}
while !M.empty?
	a=-1<<61;b=1<<61;s=M.find{|e|e}[0];t=[[s,0]];m={s=>0}
	while !t.empty?
		x,d=t.pop;m[x]=d;M[x].each{|y,c|!m[y]?t<<[y,d+c]:m[y]!=d+c&&P[:No]};x<=R ? a=[a,d].max: b=[b,d].min
	end
	a>b&&P[:No]
	m.map{|k,v|M.delete k}
end
P[:Yes]

Measured memory_bytes: 60156
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string s; cin >> s;
    ll dec = 0;
    ll x = 0;
    ll res = 0;
    ll bef = 0;
    REP(i, s.size()) {
        if (s[i] == '>') {
            dec++;
            if (x > 0) {
                bef = x;
                x = 0;
            } else {
                if (dec <= bef) {
                    res += dec - 1;
                } else {
                    res += dec;
                }
            }
        } else {
            dec = 0;
            x++;
            res += x;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main () {
    int a, b, c, tmp;

    cin >> a >> b >> c;

    if (a > b) {
       tmp = a;
       a = b;
       b = tmp;
    }
    if (b > c) {
       tmp = b;
       b = c;
       c = tmp;
    }
    if (a > b) {
       tmp = a;
       a = b;
       b = tmp;
    }
    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 3088
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] a = new long[n];
		long[] b = new long[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextLong();
			b[i] = sc.nextLong();
		}
		Map<Long, Long> map = new HashMap<>();
		for(int i = 0 ; i < n ; i++) {
			if(map.containsKey(a[i])) {
				map.put(a[i], map.get(a[i]) + b[i]);
			} else {
				map.put(a[i], b[i]);
			}
		}
		List<Entry<Long, Long>> q = new ArrayList<>(map.entrySet());
		Collections.sort(q, new Comparator<Entry<Long, Long>>() {
			public int compare(Entry<Long, Long> obj1, Entry<Long, Long> obj2) {
				return (int)(obj1.getKey() - obj2.getKey());
			}
		});
		for(int i = 0 ; i < q.size() ; i++) {
			k -= q.get(i).getValue();
			if(k <= 0) {
				System.out.println(q.get(i).getKey());
				return;
			}
		}
	}
}


Measured memory_bytes: 87028
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{cout<<#r": ";for(const auto &i:r){cout<<i<<" ";}cout<<endl;}while(0)
int main()
{
    int H, W; cin >> H >> W;
    int N; cin >> N;
    vector<int> A(N); REP(i, N) cin >> A[i];
    vector<vector<int>> map(H, vector<int>(W));
    int i = 0;
    int cnt = A[i];
    for (int y = 0; y < H; y++) {
        if (y % 2 == 0) {
            for (int x = 0; x < W; x++) { map[y][x] = i; if (--cnt == 0) cnt = A[++i]; }
        } else {
            for (int x = W-1; x >= 0; x--) { map[y][x] = i; if (--cnt == 0) cnt = A[++i]; }
        }
    }
    REP(y, H) {
        REP(x, W) cout << map[y][x] + 1 << " ";
        cout << endl;
    }
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int64 L, N;
vector<int64> X, l, r;

int64 calc(vector<int64>& ll, vector<int64>& rr){
	int32 l=0, r=0, t=0;
	int64 res = 0, sum = 0, len = 0;
	REP(i, N){
		if(i%2 == 0){
			r++;
			len += rr[r]-rr[r-1];
			sum += len;
		}else{
			l++;
			len += ll[l]-ll[l-1];
			sum += len;
		}
	}
	res = sum;
	REP(i, N){
		t++;
		if(l > 0){
			sum -= rr[t]+ll[l];
		}else{
			sum -= rr[t]-rr[-l];
		}
		if((N+i)%2 == 0){
			r++; l--;
		}
		sum += rr[r]-rr[t];
		res = max(res, sum);
	}
	return res;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> L >> N;
	X.resize(N);
	REP(i, N) cin >> X[i];
	l.push_back(0);
	REP(i, N){
		l.push_back(X[i]);
	}
	l.push_back(L);
	REP(i, N+2) r.push_back(L-l[N+1-i]);
	int64 res = max(calc(l, r), calc(r, l));
	cout << res << endl;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> x(N), y(N);
  vector<char> c(N);
  map<char, char> m;
  m['B'] = 'W';
  m['W'] = 'B';
  vector<vector<ll>> W(K, vector<ll>(K));
  vector<vector<ll>> B(K, vector<ll>(K));
  rep(i, N) {
    cin >> x[i] >> y[i] >> c[i];
    if ((x[i] / K) & 1)
      c[i] = m[c[i]];
    if ((y[i] / K) & 1)
      c[i] = m[c[i]];
    x[i] %= K;
    y[i] %= K;
    if (c[i] == 'W') {
      W[x[i]][y[i]]++;
    } else if (c[i] == 'B') {
      B[x[i]][y[i]]++;
    }
  }

  vector<vector<ll>> Wsum(K + 1, vector<ll>(K + 1));
  vector<vector<ll>> Bsum(K + 1, vector<ll>(K + 1));
  repp(i, 1, K) {
    repp(j, 1, K) {
      Wsum[i][j] = W[i - 1][j - 1] + Wsum[i - 1][j] + Wsum[i][j - 1] -
                   Wsum[i - 1][j - 1];
      Bsum[i][j] = B[i - 1][j - 1] + Bsum[i - 1][j] + Bsum[i][j - 1] -
                   Bsum[i - 1][j - 1];
    }
  }

  ll ans = 0;
  repp(i, 0, K) {
    repp(j, 0, K) {
      ll temp = 0;
      temp += Wsum[K][K] - Wsum[i][K] - Wsum[K][j] + 2 * Wsum[i][j];
      temp += Bsum[i][K] + Bsum[K][j] - 2 * Bsum[i][j];
      chmax(ans, max(N - temp, temp));
    }
  }
  cout << ans << endl;
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define        sqr(a)       ((a)*(a))


ll dp[3009][3009];
ll ar[3009];

ll sol(ll i,ll j)
{
    if(i == j)return ar[i];

    if(dp[i][j] != -1)return dp[i][j];

    ll ans = max(ar[i]-sol(i+1,j),ar[j]-sol(i,j-1));

    return dp[i][j] = ans;
}
int main()
{
    ll i,j,k,l,m,n;
    memset(dp,-1,sizeof dp);

    cin >> n;

    for(i=0;i<n;i++)cin >> ar[i];
    cout << sol(0,n-1) << endl;
}


Measured memory_bytes: 71168
#include <cstring>
#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

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

#include <set>

using namespace std;

int safe[4][4];
int n;
// [pos][prev][antei][combo][point]
double dp[101][5][11][11][101];

vector<int> s;
int a, b;

double solve(int pos, int prev, int antei, int combo, int point){
  /*
  printf("pos: %d, prev: %d, antei: %d, combo: %d, point: %d\n",
         pos, prev, antei, combo, point);
  */
  if(pos == n){
    if(point == 100) return 1.0;
    else return 0.0;
  }

  double &ret = dp[pos][prev][antei][combo][point];
  if(ret >= -1.0) return ret;
  ret = 0.0;

  const int note = s[pos] - 1;

  if(note == -1){
    ret = solve(pos + 1, 4, 10, combo, point);
  }else{
    REP(h,2){
      const int hh = note * 2 + h;
      int aa = 0;
      if(prev == 4){
        aa = 10;
      }else{
        aa = max(0, antei + safe[prev][hh] - 10);
      }
      if(aa){
        ret = max(ret,
                  (aa / 10.0) * solve(pos + 1, hh, aa, min(10, combo + 1), min(100, point + a + b * combo)) +
                  (1.0 - aa / 10.0) * solve(pos + 1, hh, aa, 0, point));
      }
    }
    ret = max(ret, solve(pos + 1, 4, 10, 0, point));
  }

  return ret;
}

int main(){
  while(true){
    REP(i,4) safe[0][i] = getInt();

    if(safe[0][0] + safe[0][1] +
       safe[0][2] + safe[0][3] == -4)
      break;

    REP(i,3) REP(j,4)
      safe[i + 1][j] = getInt();

    const int l = getInt();
    vector<int> s(l);

    REP(i,l) s[i] = getInt();
    ::a = getInt() / 100;
    ::b = getInt() / 100;
    ::s = s;
    ::n = l;

    // double dp[101][5][11][11][101];
    REP(i,101) REP(j,5) REP(k,11) REP(l,11) REP(m,101)
      dp[i][j][k][l][m] = -2.0;

    printf("%.8f\n", solve(0, 4, 10, 0, 0));
  }

  return 0;
}

Measured memory_bytes: 49320
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define db double
#define LL long long
#define inf 0x3f3f3f3f
#define N 200005
using namespace std;
int gi()
{
    int res=0,s=1; char ch;
    for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
    if(ch=='-') s=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) res=res*10+ch-48;
    return res*s;
}

const int mo=1000000007;
int n,A[N],last[N],tr[N],cnt[N],D[N],mul[N],S=1,ans,sum;

LL qp(LL x,LL y) {
    LL res=1;
    for(;y;y>>=1,x=x*x%mo)
	if(y&1) res=res*x%mo;
    return res;
}
//BIT
int lb(int x) {return x&-x;}
void add(int x,int v) {
    for(;x<=n;x+=lb(x))
	tr[x]+=v,tr[x]>=mo?tr[x]-=mo:0;
}
int ask(int x) {
    int res=0;
    for(;x;x-=lb(x))
	res+=tr[x],res>=mo?res-=mo:0;
    return res;
}
int main()
{
    n=gi();
    for(int i=1;i<=n;++i) A[i]=gi();
    //PRE
    for(int i=1;i<=n;++i) add(A[i],1);
    for(int i=1;i<=n;++i) {
	cnt[i]=(ask(n)-ask(i-1))-(n-i),S=1ll*S*(cnt[i]<=0 ? 0 : cnt[i])%mo;
	if(cnt[i]>0) D[i]=1ll*(cnt[i]-1)*qp(cnt[i],mo-2)%mo;
	if(D[i]) last[i]=last[i-1],mul[i]=1ll*(D[i-1] ? mul[i-1] : 1)*D[i]%mo;
	else last[i]=i,mul[i]=0;
    }
    if(!S) {printf("0\n"); return 0;}
    //PART1
    memset(tr,0,sizeof(tr));
    for(int i=1;i<=n;++i) {
	ans+=1ll*(ask(A[i])-ask(last[A[i]])+mo)%mo*mul[A[i]]%mo*S%mo,ans>=mo?ans-=mo:0;
	add(A[i],qp(mul[A[i]],mo-2));
    }
    ans=1ll*ans*qp(2,mo-2)%mo;
    //PART2
    memset(tr,0,sizeof(tr));
    for(int i=1;i<=n;++i) {
	ans+=1ll*(i-1-ask(A[i]))*S%mo,ans>=mo?ans-=mo:0;
	add(A[i],1);
    }
    memset(tr,0,sizeof(tr));
    for(int i=n;i;--i) {
	if(last[A[i]]==A[i]) continue;
	sum+=1ll*(ask(A[i]-1)-ask(last[A[i]])+mo)%mo*mul[A[i]]%mo*S%mo,sum>=mo?sum-=mo:0;
	add(A[i],qp(mul[A[i]],mo-2));
    }
    sum=1ll*sum*qp(2,mo-2)%mo;
    ans-=sum,ans<0?ans+=mo:0;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <iterator>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 100010;
const LL INF = 100000000000000LL;
const LL mod = 998244353;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define For(i,a,b) for(int i=a;i<=b;++i)

int n;
int a[maxn];

void solve() {
    if(n % 2 == 0) {
        cout << n << endl;
    }
    else  {
        cout << 2 * n << endl;
    }
}

int main() {
	int t = 1;
    while(~scanf("%d", &n)) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
  string line;
  char ball = 'A';
  while (getline(cin, line)) {
    stringstream s;
    s << line;
    char a, b, c;
    s >> a >> b >> c;
    if (ball == a) ball = c;
    else if (ball == c) ball = a;
  }
  cout << ball << endl;
}

Measured memory_bytes: 1204