akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n = II()
    h = LI()
    dp = [0 for i in range(n)]
    dp[1] = abs(h[0] - h[1])
    for i in range(2,n):
        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]))
    print(dp[n-1])
    return

#B
def B():
    n, K = LI()
    h = LI()
    dp = [float("INF") for i in range(n + K + 1)]
    dp[0] = 0
    for i in range(n):
        for k in range(1, K + 1):
            if i + k >= n:
                break
            dp[i + k] = min(dp[i + k], dp[i] + abs(h[i] - h[i + k]))
    print(dp[n-1])
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I():
    return 
#J

#K

#L

#M
#N
# O
# P
# Q
# R
# S
# T
# U
# V
# W
# X
# Y
# Z


#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 56812
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;

map<ull, ull> table;

ull lucas(ull n) {
    if (table.count(n)) {
        return table[n];
    } else {
        return table[n] = lucas(n - 1) + lucas(n - 2);
    }
}

int main() {
    table[0] = 2;
    table[1] = 1;
    ull N;
    cin >> N;
    cout << lucas(N) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int t,n,s,e;
	for(;scanf("%d%d",&t,&n),t;t<=0?puts("OK"):printf("%d\n",t))
		for(;n--;t-=e-s)
			scanf("%d%d",&s,&e);
	return 0;
}

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

long long solve(long long h) {
  if (h == 1) {
    return 1;
  }
  return  2 * solve(h / 2) + 1;
}



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long h;
  cin >> h;
  cout << solve(h) << '\n';
  return 0;
}



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


def dfs(s):
    if int(s) > n:  # 文字列 s で始まる七五三の個数
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0  # s 自体が七五三数なら +1
    for c in "753":
        ret += dfs(s + c)
    return ret


print(dfs("0"))  # 本当は dfs('') と書きたいが4行目でのエラーを防ぐために仕方なく


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

int main() {
  int a, b;
 
  cin >> a >> b;
   
  if(a%2 == 1&&b%2 == 1){
    cout << "Odd"<< endl;
  }
  else{
    cout << "Even"<<endl;
  }
}


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

const int P = 1e9 + 7;
inline int mpow(int a, int b) {
    int ans = 1;
    for (; b; b >>= 1, a = (ll) a * a % P)
        if (b & 1) ans = (ll) ans * a % P;
    return ans;
}
void upd(int &x, int y) { x = x + y - P; x += x >> 31 & P; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> dp(m + 1, 1);
    for (int i = 1; i <= n; ++i) {
        vector<int> new_dp(m + 1);
        vector<int> sum(m + 1, 0);
        sum[0] = 0;
        for (int j = 1; j <= m; ++j) {
            sum[j] = ((ll) 2 * sum[j - 1] % P + (ll) j * dp[j] % P) % P;
            new_dp[j] = (sum[j - 1] + (ll) dp[j] * (j + 1) % P) % P;
        }
        swap(dp, new_dp);
    }
    cout << dp[m] << '\n';
    return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  int a, i, k, N, K, b[200001], c[200001], sum, kind, target;
  scanf("%d%d", &N, &K);
  
  k=0;
  for(i=0;i<=N;i++){
    b[i]=0; c[i]=0;
  }
  
  for(i=0;i<N;i++){
    scanf(" %d", &a);
    if(b[a-1]==0)k++;
    b[a-1]++;
  }
  
  for(i=0;i<N;i++){
    c[b[i]]++;
  }
  
  sum=0;kind=0;
  if(k<=K)
    printf("0\n");
  else{
    target=k-K;
    for(i=1;i<=N;i++){
      if(kind+c[i]>=target){
        sum+=(target-kind)*i;
        printf("%d\n", sum);
        break;
      }else{
        kind+=c[i];
        sum+=c[i]*i;
      }
    }
  }
  
}


Measured memory_bytes: 1664
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

const int MAX = 5100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main()
{
	COMinit();
	int a,b;
	cin>>a>>b;
	int n = max(a,b);
	int m = min(a,b);
	unsigned long long int ans;
	if(n == m){
		ans = 2;
	}else{
		ans = 1;
	}
	ans = ans * fac[n] % MOD;
	ans = ans * fac[m] % MOD;
	if( n - m > 1) ans = 0;
	cout<<ans<<endl;
	return 0;
}



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

using namespace std;

int main() {
    int Wmax, Hmax, N;
    cin >> Wmax >> Hmax >> N;
    int Wmin=0, Hmin=0;
    
    for(int n=0; n<N; n++) {
        int x, y, a;
        cin >> x >> y >> a;
        if(a==1) {
            Wmin = max(Wmin, x);
        } else if(a==2) {
            Wmax = min(Wmax, x);
        } else if(a==3) {
            Hmin = max(Hmin, y);
        } else {
            Hmax = min(Hmax, y);
        }
    }
    
    if(Wmin<Wmax && Hmin<Hmax) {
        cout << (Wmax-Wmin)*(Hmax-Hmin) << endl;
    } else {
        cout << 0 << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <functional>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <cstdio>

using namespace std;

int main(){
    int n, a,counta, countb, count;
    vector<int> first;
    vector<int> second;
    vector<int> third;
    cin >> n;
    for (int i = 0; i < 2; i++){
        for (int x = 0; x < n; x++){
            if (i == 0){
                cin >> a;
                first.push_back(a);
            }
            else{
                cin >> a;
                second.push_back(a);
            }
        }
    }
    third = first;
    sort(third.begin(), third.end());
    a = 0;
    count = 0;
    do{
        if (third == first){
            counta = count;
            a++;
        }
        if (third == second){
            countb = count;
            a++;
        }
        if (a == 2)
            break;
        
        
        count++;
    }while (next_permutation(third.begin(), third.end()));
    
    cout << abs(counta - countb) << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double a,b,c,res;
    scanf("%lf%lf%lf",&a,&b,&c);
    res=a/c;
    if(res<=b){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 3788
//#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define I inline
//#define R register int
namespace io{
    const int l=1<<19;
    char buf[l],*s,*t,c;
    char gc(){
        if(s==t){
            t=(s=buf)+fread(buf,1,l,stdin);
            return s==t?EOF:*s++;
        }
        return *s++;
    }
    template<class IT>void gi(IT &x){
        x=0;c=gc();while(c<'0'||c>'9')c=gc();
        while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gc();}
    }
};
using io::gi;
template<class IT>void chkmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>void chkmax(IT &a,IT b){if(a<b)a=b;}

const int N=200005;

int n,a,b,c,d,f;
char s[N];
int chk(int a,int b){
	for(int i=a;i<b;i++)if(s[i]=='#'&&s[i+1]=='#')return 0;
	return 1;
}
int main(){
	scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,s+1);
	if(chk(a,c)&&chk(b,d)){
		if(d<c){
			for(int i=b;i<=d;i++)if(s[i]=='.'&&s[i-1]=='.'&&s[i+1]=='.')
				f=1;
			if(f==1)printf("Yes");else printf("No");
		}else printf("Yes");
	}else printf("No");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int f(int X)
{
    int res = 0;
    while (X > 0)
    {
        res += X % 10;
        X /= 10;
    }
    return res;
}

void _main()
{
    int N;
    cin >> N;
    cout << (N % f(N) == 0 ? "Yes" : "No") << endl;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	string s2 = "";
	string s3 = "";
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '(') {
			ans++;
		}
		else {
			ans--;
		}
		if (ans < 0) {
			s2 += '(';
			ans++;
		}
	}
	while (ans > 0) {
		s3 += ')';
		ans--;
	}
	cout << s2 + s + s3 << endl;
	return 0;
}

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

using namespace std;

int main() {
	int n,m; cin >> n >> m;
	vector<int> cnt(n);
	while(m--) {
		int a,b; cin >> a >> b;
		++cnt[a-1],++cnt[b-1];
	}
	bool flag=true;
	for(int i=0;i<n;++i)
		if(cnt[i]&1) flag=false;
	cout << (flag?"YES":"NO") << endl;
	
	return 0;
}


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

int main(){
  int N, A, B, C; cin >> N >> A >> B >> C;

  vector<int> L(N);
  for(int i=0; i<N; ++i) cin >> L[i];

  int ans = numeric_limits<int>::max(), a, b, c;
  for(int i=0; i<(1 << 2*N); ++i){
    a = b = c = 0;
    int work = -30;
    for(int k=0; k<N; ++k){
      work += 10;

      int now = (i >> 2*k) & 3;
      if(now == 1) a += L[k];
      else if(now == 2) b += L[k];
      else if(now == 3) c += L[k];
      else work -= 10;
    }
    if(a == 0 || b == 0 || c == 0) continue;
    work += (abs(A-a) +  abs(B-b) + abs(C-c));
    ans = min(ans, work);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int a;
  cin>>a;
  if(a<1200){
    cout<<"ABC"<<endl;
  }else if(a<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }
  return 0;
}


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

public class Main {

	void submit() {
		int x = nextInt();
		int k = nextInt();
		int[] flip = new int[k];
		for (int i = 0; i < k; i++) {
			flip[i] = nextInt();
		}
		
		int q = nextInt();
		
		Function func = new Function(x);
		
		int dir = -1;
		
		int ptr = 0;
		
		int curT = 0;
		
		while (q-- > 0) {
			int t = nextInt();
			int qx = nextInt();
			
			while (ptr < k && flip[ptr] <= t) {
				func.modify(flip[ptr] - curT, dir);
				curT = flip[ptr];
				dir *= -1;
				ptr++;
			}
			
			func.modify(t - curT, dir);
			curT = t;
			
			out.println(func.getAt(qx));
		}
	}
	
	static class Function {
		int flipX;
		int flipY;
		int len;
		
		final int X;

		public Function(int x) {
			flipX = 0;
			flipY = 0;
			len = x;
			this.X = x;
		}
		
		int getAt(int x) {
			if (x <= flipX) {
				return flipY;
			}
			if (x >= flipX + len) {
				return flipY + len;
			}
			return flipY + x - flipX;
		}
		
		void modify(int dist, int dir) {
			flipY += dist * dir;
			if (flipY + len <= 0) {
				flipX = flipY = len = 0;
				return;
			}
			if (flipY >= X) {
				flipX = len = 0;
				flipY = X;
				return;
			}
			
			if (flipY < 0) {
				int delta = -flipY;
				flipX += delta;
				len -= delta;
				flipY = 0;
				return;
			}
			if (flipY + len > X) {
				int delta = flipY + len - X;
				len -= delta;
				return;
			}
		}
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


Measured memory_bytes: 54340
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

void solve(){
  vector<vector<char> > maze(8,vector<char>(8));
  rep(i,8)rep(j,8)cin>>maze[i][j];
  int rand = 0;
  
  rep(i,3){
    vector<vector<char> >  move(8,vector<char>(8));
    cout<<(rand+=90)<<endl;
    
    rep(i,8)rep(j,8)
	move[i][j]=maze[7-j][i];
    rep(i,8){
      rep(j,8)cout<<move[i][j];
      cout<<endl;
    }
    maze=move;
  }
}

int main(void){
  solve();
  return 0;
}

Measured memory_bytes: 1200
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define inf 1<<30
#define il inline
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 200005
int n,q,en,cnt;
int front[N],dep[N],fa[N],size[N],son[N],id[N],top[N];
ll tree[N<<2],mark[N<<2],ans[N];
struct edge{
	int v,nex;
}e[N<<1];
il void addedge(int u,int v){
	en++;
	e[en].v=v;
	e[en].nex=front[u];
	front[u]=en;
}
il void dfs1(int u,int f){
	dep[u]=dep[f]+1;
	fa[u]=f;
	size[u]=1;
	int maxson=-1;
	for(int i=front[u];i;i=e[i].nex){
		int v=e[i].v;
		if(v==f) continue;
		dfs1(v,u);
		size[u]+=size[v];
		if(size[v]>maxson) son[u]=v,maxson=size[v];
	}
}
il void dfs2(int u,int topf){
	id[u]=++cnt;
	top[u]=topf;
	if(!son[u]) return;
	dfs2(son[u],topf);
	for(int i=front[u];i;i=e[i].nex){
		int v=e[i].v;
		if(v==fa[u]||v==son[u]) continue;
		dfs2(v,v);
	}
}
il void push_up(int p){
	tree[p]=(tree[p<<1]+tree[p<<1|1]);
}
il void push_down(int p,int l,int r){
    mark[p<<1]+=mark[p];
    mark[p<<1|1]+=mark[p];
    int mid=(l+r)>>1;
    tree[p<<1]=(tree[p<<1]+mark[p]*(mid-l+1));
    tree[p<<1|1]=(tree[p<<1|1]+mark[p]*(r-mid));
    mark[p]=0;
}
il void add(int p,int l,int r,int nl,int nr,int k){
	if(nl<=l&&r<=nr){
		mark[p]+=k;
		tree[p]+=1ll*k*(r-l+1);
		return;
	}
	if(mark[p]) push_down(p,l,r);
	int mid=(l+r)>>1;
	if(mid>=nl) add(p<<1,l,mid,nl,nr,k);
	if(mid<nr) add(p<<1|1,mid+1,r,nl,nr,k);
	push_up(p);
}
il ll query(int p,int l,int r,int ql,int qr){
	if(ql<=l&&r<=qr){
		return tree[p];
	}
	if(mark[p]) push_down(p,l,r);
	int mid=(l+r)>>1;
	ll res=0;
	if(mid>=ql) res+=query(p<<1,l,mid,ql,qr);
	if(mid<qr) res+=query(p<<1|1,mid+1,r,ql,qr);
	return res;
}
il void addson(int x,int k){
	add(1,1,n,id[x],id[x]+size[x]-1,k);
}
il ll qson(int x){
	return query(1,1,n,id[x],id[x]+size[x]-1);
}
int main(){
	int i,u,v,x,y;
	in2(n,q);
	for(i=1;i<=n-1;i++){
		in2(u,v);
		addedge(u,v);
		addedge(v,u);
	}
	dfs1(1,0);
	dfs2(1,0);
	for(i=1;i<=q;i++){
		in2(x,y);
		addson(x,y);
	}
	for(int i=1;i<=n;i++) printf("%lld ",query(1,1,n,id[i],id[i]));
	return 0;
}

Measured memory_bytes: 56192
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;

int main() {

    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    for (int r = 0; r <= 3000; r++) {
        if (r * R > N)
            continue;
        for (int b = 0; b <= 3000; b++) {
            if (r * R + b * B > N)
                continue;
            if ((N - (r * R + b * B) ) % G == 0) ans++;
        }
    }
    cout << ans << '\n';


}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){
	char input[2000];
	cin.getline(input, 1000);
	for (int i = 0; input[i] != '\0'; i++){
		if (!strncmp(&input[i], "apple", 5)){
			strncpy(&input[i], "peach", 5);
		}
		else if (!strncmp(&input[i], "peach", 5)){
			strncpy(&input[i], "apple", 5);
		}
	}
	printf("%s\n", input);
	return 0;
}

Measured memory_bytes: 1120
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	int a,b,c,x;cin>>a>>b>>c>>x;
	int ans=0;
	lol(i,a+1)lol(j,b+1)lol(k,c+1){
		int t=i*500+j*100+k*50;
		if(t==x)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
      ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
      unsigned long long h, w;
      cin >> h >> w;
      if (h==1||w==1) cout << 1 << endl;
      else if (h%2==0) cout << w*h/2 << endl;
      else
      {
            cout << w*(h-1)/2+(w+1)/2 << endl;
      }
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int H,W;
  cin >> H >> W;
  if(H == 1 || W == 1) cout << "1" << endl;
  else{
  long long int A = (H*W)/2+(H*W)%2;
  cout << A << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
int main(){
	long long N;
	int flag=0;
	long long Ans=1;
	std::cin>>N;
	std::vector<long long> Tmp(N);
	for(int i=0;i<N;i++){
		std::cin>>Tmp[i];
		if(Tmp[i]>1000000000000000000/Ans)flag=1;
		if(flag==0)Ans*=Tmp[i];
	}
	if(flag==1)Ans=-1;
	sort(Tmp.begin(),Tmp.end());
	if(Tmp[0]==0)Ans=0;
	std::cout<<Ans;
	return 0;
}


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

int main() {
  ll N, A, B;
  cin>>N>>A>>B;
  if((B-A)%2==0) cout<<(B-A)/2<<endl;
  else cout<<min(N-A, B-1)-(B-A-1)/2<<endl;
}



Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		String ans = "Yes";
		if(a+b+1 != s.length()) {
			ans = "No";
		}
		for(int i = 0; i < s.length();i++) {
			if(s.charAt(a)!='-') {
				ans = "No";
			}
			if((i<a||i>=a+1)&&s.charAt(i)=='-') {
				ans = "No";
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22612
// Problem Link: 
// Tutorial Link: 

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define ll  long long
#define all(v) v.begin(), v.end()
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<b;++i)
#define repb(i,a,b) for(LL i=a;i>b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL n;

int main()
{
	FIO;
	cin >> n;
	if(n <= 599) {
		cout << 8 << endl;
	}
	else if(n <= 799) {
		cout << 7 << endl;
	}
	else if(n <= 999) {
		cout << 6 << endl;
	}
	else if(n <= 1199) {
		cout << 5 << endl;
	}
	else if(n <= 1399) {
		cout << 4 << endl;
	}
	else if(n <= 1599) {
		cout << 3 << endl;
	}
	else if(n <= 1799) {
		cout << 2 << endl;
	}
	else if(n <= 1999) {
		cout << 1 << endl;
	}

}

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



int main()
{
	string S;
	cin >>S;
	
		if (S[0] == S[1] || S[0] == S[2]||S[1]==S[2])cout << "No" << endl;
		else cout << "Yes" << endl;
	
}






Measured memory_bytes: 256
n, d = map(int, input().split())
coodinates = [[int(x) for x in input().split()] for _ in range(n)]
result = 0
for left in range(n-1):
    for right in range(left+1,n):
        dist = 0
        for i in range(d):
            dist += (coodinates[left][i] - coodinates[right][i])**2
        dist = dist ** 0.5
        result += 1 if dist.is_integer() else 0
print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  string S;
  cin >> S;
  int ans = 0;
  REP(i,4){
    if(S[i]=='+'){
      ans++;
    }else{
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC158A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            if (S.Count(x => x == 'A') % 3 == 0) Console.WriteLine("No");
            else Console.WriteLine("Yes");
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
	

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,i;
    cin>>n;
    ll arr[n][3];
    for(i=0;i<n;i++)
    {
    	cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    ll dp[n][3];
    memset(dp,0,sizeof(dp));
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];
    for(i=1;i<n;i++)
    {
    	dp[i][0] = arr[i][0] + max(dp[i-1][1],dp[i-1][2]);
    	dp[i][1] = arr[i][1] + max(dp[i-1][0],dp[i-1][2]);
    	dp[i][2] = arr[i][2] + max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    return 0;
}

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

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  int n;
  scanf("%d",&n);

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

  printf("%d",ans);

  return 0;

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
    vector<vector<int> > c(3);
    for(int i = 0; i < 3; ++i){
    	for(int j = 0; j < 3; ++j){
    	    int tmp; cin >> tmp;
    	    c[i].push_back(tmp);
        }
    }
    for(int a1 = -100; a1 <= 100; ++a1){
    	int b1 = c[0][0]-a1;
        int b2 = c[0][1]-a1;
        int b3 = c[0][2]-a1;
        
        int a2 = c[1][0]-b1;
        if(a2 != c[1][1] - b2 || a2 != c[1][2] - b3){continue;}
        
        int a3 = c[2][0]-b1;
        if(a3 != c[2][1] - b2 || a3 != c[2][2] - b3){continue;}
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200010];
 int ans[200010];
int main(){
int n;
scanf("%d",&n);
for(int i=2;i<=n;i++) scanf("%d",&a[i]);
for(int i=2;i<=n;i++) ans[a[i]]++;
 for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
}

Measured memory_bytes: 5388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
    int n;
    cin >> n;
    int f[n][10];
    int p[n][11];
    rep (i, 0, n) rep (j, 0, 10) cin >> f[i][j];
    rep (i, 0, n) rep (j, 0, 11) cin >> p[i][j];
    int ans = -inf;
    rep (bit, 1, 1 << 10) {
        int sum = 0;
        rep (i, 0, n) {
            int cnt = 0;
            rep (j, 0, 10) {
                if (f[i][j] && (bit & (1 << j))) cnt++;
            }
            sum += p[i][cnt];
        }
        // cout << sum << " ";
        ans = max (ans, sum);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3560
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

bool** table;

void func(int N,int M){
	int coin[N],second_coin[1024],index = 0;

	for(int i = 0; i < N; i++){
		for(int k = 0; k < M+1; k++)table[i][k] = false;
	}

	for(int i = 0; i < N; i++){
		scanf("%d",&coin[i]);
	}

	table[0][coin[0]] = true;

	for(int i = 1; i < N; i++){

		for(int k = 1; k < coin[i];k++){
			if(table[i-1][k] == true)table[i][k] = true;
		}

		table[i][coin[i]] = true;

		for(int k = coin[i]+1; k <= M; k++){
			if(table[i-1][k] == true || table[i-1][k-coin[i]] == true)table[i][k] = true;
		}
	}

	for(int i = 1; i <= M; i++){
		if(table[N-1][i] == true){
			second_coin[index++] = i;
		}
	}

	int dp[M+1];
	for(int i = 1; i <= M; i++)dp[i] = 2000000000;

	dp[0] = 0;

	for(int i = 1; i <= M; i++){
		for(int k = 0; k < index; k++){
			if(i >= second_coin[k]){
				dp[i] = min(dp[i],dp[i-second_coin[k]] + 1);
			}
		}
	}

	printf("%d\n",dp[M]);

}


int main(){

	int N,M;

	table = new bool*[10];
	for(int i = 0; i < 10; i++){
		table[i] = new bool[100001];
	}

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func(N,M);
	}

    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String result = line.toUpperCase();
		System.out.println(result);
	}

}

Measured memory_bytes: 24140
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    map<int, int> mp;
    REP(i,N){
        int A;
        cin >> A;
        if(mp[A]) mp.erase(A);
        else mp[A]++;
    }
    cout << mp.size() << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

void decitobinbitodeci()
{
    string binary = bitset<8>(128).to_string(); //to binary
    cout<<binary<<"\n";

    unsigned long decimal = bitset<8>(binary).to_ulong();
    cout<<decimal<<"\n";
}

int getnum(string a)
{
    int i,p=0;
    rep0(i,a.size())
    {
        p*=10;
        p+=a[i]-'0';
    }
    return p;
}

/*
1.always remember for ncr(n,2), you can calculate by
n*(n-1)/2
2.Power of 2 ->  (1ll<<i)
*/

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a,b,c,d,e;
    cin>>a>>b;
    map<ll,ll>m;
    for(int i=0; i<a; i++)
    {
        cin>>c;
        m[i+1]=c;
    }
    vector<ll>v[a+1];
    for(int i=0; i<b; i++)
    {
        cin>>d>>e;
        v[d].push_back(e);
        v[e].push_back(d);
    }
    ll sum=0;
    for(int i=0; i<a; i++)
    {
        ll flag=0;
        ll x=m[i+1];
        for(int j=0; j<v[i+1].size(); j++)
        {
            if(x<=m[v[i+1][j]])
            {
                flag=1;
                break;
            }
        }
        if(!flag)
        {
            sum++;
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 15756
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int ans=0;
int n,m,q;
int a[55],b[55],c[55],d[55];
int s[15];
void dfs(int x)
{
	if(s[x-1]>m) return;
	if(x==n+1)
	{
		int sum=0;
		for(int i=1;i<=q;i++)
			if(s[b[i]]-s[a[i]]==c[i])
				sum+=d[i];
		ans=max(ans,sum);
		return;
	}
	for(int i=0;i<=m;i++)
	{
		s[x]=s[x-1]+i;
		dfs(x+1);
	}
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++)
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	s[1]=1;
	dfs(2);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3656
import java.util.*;
public class Main {
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        
        while(true){
        	int n=scan.nextInt();
        	if(n==0)break;
        	long syatiku[] =new long[4001];
        	for(int i=0;i<4001;i++)syatiku[i] = 0;
        	int []  input =new int [n];
        	for(int i=0;i<n;i++){
        		input[i] = scan.nextInt();
        		syatiku[input[i]]+=scan.nextLong()*scan.nextLong();
        	}
        	boolean flag =true;
        	for(int i=0;i<n;i++){
        		if(syatiku[input[i]]>=1000000){
        			System.out.println(input[i]);
        			syatiku[input[i]] =0;
        			flag =false;
        		}
        	}
        	if(flag)System.out.println("NA");
        }
    }
}

Measured memory_bytes: 12000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		solve(sc, out);
		
		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out){
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a <= 8 && b <= 8) out.println("Yay!"); else out.println(":(");
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 22996
s = input()

ans=0
base = set(['A','C','G','T'])
i = 1
while i <= len(s):
    j = 0
    while j+i <= len(s):
        word = set(s[j:j+i])
        if word <= base:
            ans = len(s[j:j+i])
        j += 1
    i += 1
print (ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    long long a,b,k,n;

    scanf("%lld %lld",&a,&b);

    n=a+b;
    if(n%2==0)
    {
       k=n/2;
       printf("%lld\n",k);
    }
    else
        printf("IMPOSSIBLE\n");

    return 0;
}


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

const int divisor = 1000000007;

int main(){
	vector<int> ansvec;

	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	int* word = new int[100000] {0};

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;

		for (int i = 0; i < N; i++) word[i] = i + 1; //まず0番目の単語を入れておく

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		//word[i]をkey, word[i]より小さい数がそれ以前にいくつ使われていたかをvalueとして格納するmap
		map<int, int> bubblehist;
		bubblehist[word[0]] = 0;

		long long ans = factmodary[N-1] * (word[0] - 1);

		for (int i = 1; i < N; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.lower_bound(word[i]);

			if (it != bubblehist.end()){
				bubblenum = it->second;
			}
			else {
				bubblenum = bubblehist.rbegin()->second + 1;
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			bubblehist.insert(--it, p);
			//word[i]より大きい数はすべてvalueが1増える
			for (map<int, int>::iterator it2 = bubblehist.upper_bound(word[i]); it2 != bubblehist.end(); it2++) ++(it2->second);

			facttime -= bubblenum;
			ans += factmodary[N - (i + 1)] * facttime;
		}
			ans %= divisor;

		ansvec.push_back((int)ans);
	}

	for (vector<int>::iterator it = ansvec.begin(); it != ansvec.end(); it++) cout << *it << "\n";

	delete[] word;
	delete[] factmodary;
	return 0;
}

Measured memory_bytes: 6816
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=100010;
const lint LINF=0x7f7f7f7f7f7f7f7fll;
int main(){
	int n=ni;
	lint f[3]={ni,-LINF,-LINF};
	for(int i=2;i<=n;i++){
		char c;
		while(c=getchar(),c!='+'&&c!='-');
		int val=ni;
		if(c=='+'){
			f[0]+=val;
		}else{
			f[2]=f[1],f[1]=f[0],f[0]=-LINF;
		}
		if(f[1]!=-LINF){
			f[1]-=val;
			if(f[2]!=-LINF){
				f[2]+=val;
				apmax(f[1],f[2]);
			}
			apmax(f[0],f[1]);
		}
		assert(f[0]>=f[1]&&f[1]>=f[2]);
	}
	printf("%lld\n",f[0]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,a[222222],b[222222];
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i],b[i]=a[i];
  b[0]=0;
  sort(b,b+n+1);
  int c=b[n/2],d=b[n/2+1];
  int t=c+d;
  t/=2;
  for(int i=1;i<=n;i++){
    if(a[i]<=t)cout<<d<<endl;
    else cout<<c<<endl;
  }
  //cout<<c<<d<<endl;
  return 0;
}


Measured memory_bytes: 5504
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

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

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

int nums[10000];
int nums2[10000];

int main(){
	int n;
	while(cin >> n && n){
		memset(nums, 0, sizeof(nums));
		memset(nums2, 0, sizeof(nums2));
		rep(i, n-1){
			nums[((i+1)*(i+1))%n]++;
		}
		for(int i = 1; i < n; i++){
			for(int j = 0; j < n - i; j++){
				int n1 = i;
				if(n1 > (n-1)/2) n1 = n - n1;
				if(nums[j] * nums[i+j] > 0){
					nums2[n1]+=2;
				//	cout << j << " " << i + j << endl;
				}
			}
		}
		rep(i, (n-1)/2) cout << nums2[i+1] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
template<typename T> class Dinic {
private:
	struct edge {
		int to;
		T cap;
		int rev;
	};
	int V;
	vector<vector<edge> > G;
	vector<int> level, iter;
	void bfs(int s) {
		fill(level.begin(), level.end(), -1);
		queue<int> que;
		level[s] = 0;
		que.push(s);
		while (!que.empty()) {
			int v = que.front();
			que.pop();
			for (auto& e : G[v]) {
				if (e.cap > 0 && level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					que.push(e.to);
				}
			}
		}
	}
	T dfs(int v, int t, T f) {
		if (v == t) {
			return f;
		}
		for (int& i = iter[v]; i < (int)G[v].size(); i++) {
			edge& e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				T d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

public:
	Dinic(int node_size) : V(node_size), G(V), level(V), iter(V) {}
	//辺を張る
	void add_edge(int from, int to, T cap) {
		G[from].push_back((edge) { to, cap, (int)G[to].size() });
		G[to].push_back((edge) { from, (T)0, (int)G[from].size() - 1 });
	}
	//最大流を計算
	T solve(int s, int t) {
		T flow = 0;
		for (;;) {
			bfs(s);
			if (level[t] < 0) return flow;
			fill(iter.begin(), iter.end(), 0);
			T f;
			while ((f = dfs(s, t, numeric_limits<T>::max())) > 0) {
				flow += f;
			}
		}
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, C;
	cin >> H >> W >> C;
	vector<vector<int> > A(H, vector<int>(W));
	int sum = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
			sum += A[i][j];
		}
	}

	int N = H * W + (H - 1) * (W - 1) + 2;


	int s = N - 2;
	int t = N - 1;


	Dinic<int> d(N);
	int INF = (int)1 << 50;
	vector<int> dc(H*W, 0);
	vector<int> sc(H*W, 0);

	for (int i = 0; i < H - 1; i++) {
		for (int j = 0; j < W - 1; j++) {

			if ((i + j) % 2 == 0) {
				int idx = H * W + i * (W - 1) + j;
				if (i % 2 == 0) {
					d.add_edge(s, idx, C);
					for (int x = 0; x < 2; x++) {
						for (int y = 0; y < 2; y++) {
							d.add_edge(idx, (i + x) * W + j + y, A[i + x][j + y]);
							dc[(i + x) * W + j + y]++;
						}
					}
				}
				else {
					for (int x = 0; x < 2; x++) {
						for (int y = 0; y < 2; y++) {
							d.add_edge((i + x) * W + j + y, idx, A[i + x][j + y]);
							sc[(i + x) * W + j + y]++;
						}
					}
					d.add_edge(idx, t, C);

				}
			}
		}
	}


	for (int i = 0; i < H * W; i++) {
		if (dc[i] == 0) {
			d.add_edge(s, i, INF);
		}
		if (sc[i] == 0) {
			d.add_edge(i, t, INF);
		}
	}
	int res = sum - d.solve(s, t);




	cout << res << endl;
}


Measured memory_bytes: 3736
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if(b==1)return cout<<0<<"\n",0;
    int ans=1;
    int count=a;
    while(count<b){
        ans++;
        count+=a-1;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    if(n==m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
    }


Measured memory_bytes: 256
N = gets.to_i
K = gets.to_i

ans = Float::INFINITY
[:A, :B].repeated_permutation(N).to_a.each do |combis|
  tmp = 1
  combis.each do |m|
    case m
    when :A
      tmp *= 2
    when :B
      tmp += K
    end
  end
  ans = tmp if ans > tmp
end
p ans

Measured memory_bytes: 1916