akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

#define YES "Yes"
#define NO "No"

#define A (999999999)
#define B (-1000000000)
#define C (B / 2)

int arr[500];

bool solve(int X, int x) {
	if (x == 1 || X % x == 0) return false;
	if (X % 2 == 0 && x % 2 == 0) {
		if (!solve(X / 2, x / 2)) return false;
		for (int i = X - 1; i >= 0; --i) arr[i] = arr[i / 2];
		return true;
	}
	REP(i, X) {
		if (i % x == 0) arr[i] = A;
		else if ((i + 1) % x == 0) arr[i] = B + x - 2;
		else arr[i] = -1;
	}
	return true;
}

int main(int argc, char **argv) {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	if (solve(W, w)) {
		cout << YES << endl;
		REP(y, H) {
			REP(x, W) {
				if (x != 0) cout << ' ';
				cout << arr[x];
			}
			cout << endl;
		}
	}
	else if (solve(H, h)) {
		cout << YES << endl;
		REP(y, H) {
			REP(x, W) {
				if (x != 0) cout << ' ';
				cout << arr[y];
			}
			cout << endl;
		}
	}
	else {
		cout << NO << endl;
	}
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

int main()
{
    LL bSum = 0;
    priority_queue<int, vector<int>> smalls;
    priority_queue<int, vector<int>, greater<int>> bigs;
    LL smallSum = 0;
    LL bigSum = 0;
    bool hasMiddle = false;
    int middle = 0;

    int Q;
    cin >> Q;

    rep(i, Q) {
        int q;
        cin >> q;
        if (q == 1) {
            int a, b;
            cin >> a >> b;
            if (hasMiddle) {
                int s = min(a, middle);
                int l = max(a, middle);
                smallSum += s;
                bigSum += l;
                smalls.push(s);
                bigs.push(l);
                hasMiddle = false;
            } else {
                if (!smalls.empty() && a < smalls.top()) {
                    middle = smalls.top();
                    smalls.pop();
                    smalls.push(a);
                    smallSum += (a-middle);
                } else if (!bigs.empty() && bigs.top() < a) {
                    middle = bigs.top();
                    bigs.pop();
                    bigs.push(a);
                    bigSum += (a-middle);
                } else {
                    middle = a;
                }
                hasMiddle = true;
            }
            bSum += b;
        } else {
            int x = hasMiddle ? middle : smalls.top();
            LL ans = bSum - smallSum + bigSum;
            cout << x << ' ' << ans << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3452
import sys

lines = sys.stdin.read().split('\n')
age = int(lines[0])
if age == 1:
    print('Hello World')
elif age == 2:
    if len(lines) < 3:
        raise "age 2 but did not receive A and B"
    A = int(lines[1])
    B = int(lines[2])
    print(A+B)
else:
    raise "received invalid age " + str(age)

Measured memory_bytes: 3064
#include<stdio.h>

int main (void)
{
    int N,i;
    int a[20];
    int b[20];
    int c[20];
    int val;
    char bin;
    int satisfy = 0;

//はいんねえ

    scanf("%d",&N);
    scanf("%c",&bin);

    for(i=0;i<N;i++){
        scanf("%d ",&a[i]);
        //printf("got %d\n",a[i]);
        //scanf("%c",&bin);
    }


    for(i=0;i<N;i++){
        scanf("%d ",&b[i]);
        //printf("b got %d\n",b[i]);
        //scanf("%c",&bin);
    }


    for(i=0;i<N-1;i++){
        scanf("%d",&c[i]);
        //printf("got %d\n",c[i]);
        scanf("%c",&bin);
    }

    //printf("sty:%d\n",satisfy);

    for(i=0;i<N;i++){
        satisfy+=b[a[i]-1];
        //printf("wii add %d\n",b[a[i]-1]);
        if(i==0){

        }else if(a[i-1]+1 == a[i]){
            //printf("add c:%d",c[a[i-1]-1]);
            satisfy+=c[a[i-1]-1];
        }

        //printf("now sty %d\n",satisfy);
    }

    printf("%d",satisfy);





    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cnt = 1000 - (n % 1000);
		if (cnt == 1000) {
			cnt = 0;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 35588
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
gl=[0]
gr=[0]
for i in range(n):
  gl.append(gcd(a[i], gl[-1]))
  gr.append(gcd(a[n-i-1], gr[-1]))
gr=gr[::-1]
ans = 0
for i in range(n):
  ans = max(ans, gcd(gl[i],gr[i+1]))
  
print(ans)

Measured memory_bytes: 16148
#include<stdio.h>

int main(){
  int N;
  
  scanf("%d",&N);
  if(N%10==3){
    printf("bon\n");
  }else if(N%10==0||N%10==1||N%10==6||N%10==8){
    printf("pon\n");
  }else{
    printf("hon\n");
  }
  return 0;
}

Measured memory_bytes: 1648
#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define IN freopen("in.txt", "r", stdin);
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;

const int MOD = 998244353;
const int N = 4010;
int dp[N][N][2];

int a,b,c,d;

void up(int &x,int y){
    x=x+y>=MOD?x+y-MOD:x+y;
}

int main(){
    IOS;
    cin>>a>>b>>c>>d;
    dp[a][b][0]=1;
    for(int i=a;i<=c;i++)for(int j=b;j<=d;j++){
        up(dp[i+1][j][0],1LL*dp[i][j][0]*j%MOD);
        up(dp[i][j+1][1],1LL*dp[i][j][0]*i%MOD);
        up(dp[i+1][j][0],dp[i][j][1]);
        up(dp[i][j+1][1],1LL*dp[i][j][1]*i%MOD);
    }
    cout<<(dp[c][d][0]+dp[c][d][1])%MOD;
    return 0;
}

Measured memory_bytes: 85876
#include <stdio.h>

#define NUM_SUIT 4
#define NUM_RANK 13

enum {
    SPADE,
    HEART,
    CLUB,
    DIAMOND,
};

int main (void) {
    int n, r;
    char s;
    char e; // enter
    int cards[NUM_SUIT][NUM_RANK];

    for (int i=0; i<NUM_SUIT; i++) {
        for (int j=0; j<NUM_RANK; j++) {
            cards[i][j]=0;
        }
    }

    scanf ("%d%c", &n, &e);
    
    for (int i=0; i<n; i++) {
        scanf ("%c %d%c", &s, &r, &e);
        if (s=='S') cards[SPADE][r-1]=1;
        else if (s=='H') cards[HEART][r-1]=1;
        else if (s=='C') cards[CLUB][r-1]=1;
        else if (s=='D') cards[DIAMOND][r-1]=1;
    }

    for (int i=0; i<NUM_SUIT; i++) {
        for (int j=0; j<NUM_RANK; j++) {
            if (cards[i][j]==0) {
                if (i==SPADE) printf ("%c %d\n", 'S', j+1);
                else if (i==HEART) printf ("%c %d\n", 'H', j+1);
                else if (i==CLUB) printf ("%c %d\n", 'C', j+1);
                else if (i==DIAMOND) printf ("%c %d\n", 'D', j+1);
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 2108
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()

lis = list(map(int, input().split()))


a = list(range(-1,102))

for i in lis:
    a.remove(i)

ans = 10000    
tans = 0
for j in a:
    tmp = abs(j-x)
    if tmp < ans:
        tans = j
        ans = tmp
        
print(tans)

Measured memory_bytes: 9224
#include<stdio.h>
int main(){
int a[4][11];
int c[4][11];
int d[4][11];
int e[4][11];
int b,f,r,v,g,h;
for(g=1;g<4;g++){
for(h=1;h<11;h++){
a[g][h]=0;
c[g][h]=0;
d[g][h]=0;
e[g][h]=0;
}
}
scanf("%d\n",&g);
for(h=0;h<g;h++){
scanf("%d %d %d %d\n",&b,&f,&r,&v);
if(b==1){
a[f][r]=v+a[f][r];
}
else if(b==2){
c[f][r]=v+c[f][r];
}
else if(b==3){
d[f][r]=v+d[f][r];
}
else if(b==4){
e[f][r]=v+e[f][r];
}
}
for(g=1;g<4;g++){
for(h=1;h<11;h++){
printf(" %d",a[g][h]);
}
printf("\n");
}
printf("####################\n");
for(g=1;g<4;g++){
for(h=1;h<11;h++){
printf(" %d",c[g][h]);
}
printf("\n");
}
printf("####################\n");
for(g=1;g<4;g++){
for(h=1;h<11;h++){
printf(" %d",d[g][h]);
}
printf("\n");
}
printf("####################\n");
for(g=1;g<4;g++){
for(h=1;h<11;h++){
printf(" %d",e[g][h]);
}
printf("\n");
}
return 0;
}






Measured memory_bytes: 2140
#include<stdio.h>

#define tail -1

int main(){

  int i,j,k,n,m,det[101][101];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&det[i][0],&m);
    for(j=2;j<m+2;j++){
      scanf("%d",&det[i][j]);
    }
    det[i][++j]=tail;
  }

  //print
  for(i=0;i<n;i++){
    j=2;
    for(k=0;k<n;k++){
      if(det[i][j]==tail){
	printf("0");
      }else if(det[i][j]==k+1){
	printf("1");
	j++;
      }else printf("0");
      if(k!=n-1)printf(" ");
    }
    printf("\n");
  }

  return 0;

}

Measured memory_bytes: 604
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    S = ST()
    T = ST()
    contin = False
    equal = False
    if S[0] == T[0]:
        ans = 3
        equal = True
    else:
        ans = 6
        contin = False
    start = 1 + (S[0] != T[0])
    for s, t in zip(S[start:], T[start:]):
        if s == t:
            if equal:
                ans *= 2
            else:
                pass
            equal = True
        else:
            if contin:
                if equal:
                    ans *= 2
                else:
                    ans *= 3
                contin = False
                equal = False
            else:
                contin = True
        ans %= mod
        
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ch;
    cin>>ch;
    switch(ch)
    {


    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
        cout<<"vowel"<<endl;
        break;

    default:
        cout<<"consonant"<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(a,b,c) for(int a=(b);a<=(c);++a)
#define wer rd()
char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p1=buf,p2=buf+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
inline ll wer{
    ll ans=0,fl=1;char t=GC;
    while(!isdigit(t)){if(t=='-')fl=-1;t=GC;}
	while(isdigit(t))ans=ans*10+t-'0',t=GC;
	return ans*fl;
}
 
//#define double long double 
const double eps=1e-8;
int sb(double x)
{
	if(-eps<x&&x<eps)return 0;
	return x>0?1:-1;
}
struct pv{
	double x,y;int id;
	friend pv operator+(const pv&a,const pv&b)
	{
		return {a.x+b.x,a.y+b.y};
	}
	friend pv operator-(const pv&a,const pv&b)
	{
		return {a.x-b.x,a.y-b.y};
	}
	friend double operator*(const pv&a,const pv&b)
	{
		return a.x*b.y-a.y*b.x;
	}
	friend bool operator<(const pv&a,const pv&b)
	{
		return a.x<b.x;
	}
	friend bool operator==(const pv&a,const pv&b)
	{
		return a.x==b.x&&a.y==b.y;
	}
	friend double operator/(const pv&a,const pv&b)
	{
		return a.x*b.x+a.y*b.y;
	}
	
	
}p[10001];
const double PI=acos(-1);
double cross(pv a,pv b,pv c)
{
	return (b-a)*(c-a);
}
double ans[10001];
int n,st,xt,zt,ids[10001],idx[10001],idz[10001];
pv sm[10001],xm[10001],zm[10001];
double agl(pv a,pv b)
{
	if(sb(a*b)==0){if(sb(a.x*b.x)>=0||sb(a.y*b.y)>=0)return 0;return PI;}
	return acos((a/b)/sqrt((a.x*a.x+a.y*a.y)*(b.x*b.x+b.y*b.y)));
}
int main()
{
	cin>>n;
	f(i,1,n)cin>>p[i].x>>p[i].y,p[i].id=i;
	f(i,1,n)
	{
		complex<double>a(p[i].x,p[i].y);
		a*=complex<double>(cos(0.2),sin(0.2));
		p[i]={a.real(),a.imag(),p[i].id};
	 } 
//	f(i,1,n)cout<<p[i].x<<" "<<p[i].y<<"\n";
	sort(p+1,p+n+1);
	f(i,1,n)
	{
//		cout<<p[i].x<<" "<<p[i].y<<"\n";
		while(st>=2&&sb(cross(sm[st-1],sm[st],p[i]))>0)st--;
		sm[++st]=p[i];ids[st]=p[i].id;
	}
//	f(i,1,st)cout<<ids[i]<<" \n"[i==st];
	for(int i=n;i;i--)
	{
		while(xt>=2&&sb(cross(xm[xt-1],xm[xt],p[i]))>0)xt--;
		xm[++xt]=p[i];idx[xt]=p[i].id;
	}
	f(i,1,st)
	{
		if(zt==0||!(zm[zt]==sm[i]))
		zm[++zt]=sm[i],idz[zt]=ids[i];
	}
	f(i,1,xt)
	{
		if(zt==0||!(zm[zt]==xm[i]))
		zm[++zt]=xm[i],idz[zt]=idx[i];
	}
	while(zt>1&&zm[zt]==zm[1])--zt;
	f(i,1,zt)
	{
//		cout<<idz[i]<<"\n";
		int ne=i%zt+1,pre=(i==1?zt:i-1);
//		cout<<idz[ne]<<" "<<idz[pre]<<"\n";
		ans[idz[i]]=(PI-agl(zm[ne]-zm[i],zm[pre]-zm[i]))/(PI*2);
	}
	f(i,1,n)
	{
		if(ans[i]<0)ans[i]=0;
		printf("%.20lf\n",ans[i]);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long a,b,c,d,ans;
  cin >> a >> b >> c >> d;
  ans=a*c;
  ans=max(ans,a*d);
  ans=max(ans,b*c);
  ans=max(ans,b*d);
  cout << ans << endl;
}

Measured memory_bytes: 3636
import Text.Printf
import Debug.Trace

ip::[Double]->[Double]->Double
ip a b = sum $ zipWith (*) a b

norm::[Double]->Double
norm a = (sum $ map (**2.0) a)**0.5

pos::(Double,[Double], [Double])->(Double,[Double], [Double])
pos (theta2, p2, p1) = 
--    trace ("pos  "++show (theta3', p3', p2')) $
--    trace ("cos  "++show ((ip p2 p1)/((norm p2)*(norm p1)))) $
--    trace ("ip   "++show (ip p2 p1)) $
--    trace ("norm "++show (norm p2, norm p1)) $
    (theta3', p3', p2')
    where 
        theta3' = theta2+acos((ip p2 p1)/((norm p2)*(norm p1)))
        p3' = [p2!!0+cos(theta3'), p2!!1+sin(theta3')]
        p2' = p2

theta1 = 0.0
theta2 = pi/2.0
p1 = [1.0, 0.0]
p2 = [1.0, 1.0]

pos'::Int -> [Double]
pos' 1 = p1
pos' 2 = p2
pos' n = p3' where (theta3', p3', p2') = last $ take (n-1) $ iterate pos (theta2,p2,p1)

solve::Int-> IO ()
solve n = do
    mapM_ (printf "%.2f\n") $ pos' n

main::IO ()
main=do
    str<-getContents::IO String
    mapM_ solve $ takeWhile (/=(-1)) $ map (\x->read x::Int) . lines $ str

Measured memory_bytes: 5148
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

#from itertools import permutations

n = int(input())
#a,b = [int(i) for i in readline().split()]
#lr = [[int(i)-1 for i in readline().split()] for _ in range(q)]
"""
L = list(range(1,n+1))
ans = 0
for i in permutations(L):
    res = 0
    for j in range(n):
        res += (j+1)%i[j]
    ans = max(ans,res)    
"""

print(n*(n-1)//2)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=2019;
int main(){
  ll L,R;
  cin>>L>>R;
  //priority_queue<ll,vector<ll>,greater<ll>>que;
  vector<int>que;
  if(R-L>=2019){
    R=L+2019;
  }
  for(ll i=L;i<=R;i++){
    que.push_back(i%MOD);
    //cout<<i%MOD<<endl;
  }
  int mini=2018;
  for(int i=0;i<que.size()-1;i++){
    for(int j=i+1;j<que.size();j++){
      int tmp=(que[i]*que[j])%MOD;
      mini=min(mini,tmp);
      //cout<<mini<<endl;
    }
  }
  cout<<mini<<endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll x,a,b;
    cin >> x >> a >> b;
    print((x-a)%b);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3576
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=100005;
int a[MAXN],n,opt[MAXN];char ch[15];
LL gi(int x)
{
	if(opt[x]!=1)return a[x];
	return a[x]+gi(x+1);
}
int main()
{
//	freopen("a.txt","r",stdin);
	n=read();LL sum=0;
	int fi=-1;
	for(int i=1;i<=n;i++)
	{
		a[i]=read();sum+=a[i];
		if(i!=n)
		{
			scanf("%s",ch+1);
			opt[i]=ch[1]=='+'?1:-1;
			if(opt[i]==-1&&fi==-1)fi=i;
		}
	}
	if(fi==-1)return pr2(sum),0;
	if(opt[fi+1]==-1)return pr2(sum-2*a[fi+1]),0;
	LL ans=-1e18;chkmax(ans,sum-2*a[fi+1]-2*gi(fi+2));sum-=2*a[fi+1];
	for(int i=fi+1;i<n;i++)
	{
		if(opt[i]==-1)
		{
			if(opt[i+1]==-1)chkmax(ans,sum-2*a[i+1]);
			else chkmax(ans,sum-2*a[i+1]-2*gi(i+2));
			sum-=2*a[i+1];
		}
	}pr2(ans);
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int vis[30];
int main()
{
    string str;
    cin>>str;
    for(int i=0;i<str.length();i++){
        vis[str[i]-'A']++;
    }
    int cnt=0;
    for(int i=0;i<26;i++){
        if(vis[i]==2) cnt++;
    }
    if(cnt!=2) puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        long[] a = sc.nextLongArray(n);
        HashMap<Long,Integer> map = new HashMap<Long,Integer>();
        long ans = 0;
        for(int i = 0; i < n; i++){
            if(i != 0){
                a[i] += a[i-1];
            }
            map.put(a[i],map.getOrDefault(a[i],0)+1);
        }
        for(Map.Entry<Long,Integer> e : map.entrySet()){
            long k = e.getKey();
            long v = e.getValue();
            ans += k == 0 ? (v+1)*v/2 : v*(v-1)/2;
            
        }
        System.out.println(ans);
    }
}

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: 53760
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
int a[MAXN],cnta[MAXN],cntb[MAXN];
int n;
int main(){
	SF("%d",&n);
	for(int i=1;i<=n;i++)
		SF("%d",&a[i]);
	for(int i=1;i<=n;i++){
		if(i%2==1)
			cnta[a[i]]++;
		else
			cntb[a[i]]++;
	}
	int maxva=0;
	int maxvb=0;
	for(int i=1;i<=100000;i++)
		if(cnta[i]>cnta[maxva])
			maxva=i;
	for(int i=1;i<=100000;i++)
		if(cntb[i]>cntb[maxvb])
			maxvb=i;
	if(maxva!=maxvb){
		PF("%d",n-cnta[maxva]-cntb[maxvb]);	
	}
	else{
		int maxva1=100001;
		for(int i=1;i<=100000;i++)
			if(i!=maxva&&cnta[i]>cnta[maxva1])
				maxva1=i;
		int ans=n-cnta[maxva1]-cntb[maxvb];
		int maxvb1=100001;
		for(int i=1;i<=100000;i++)
			if(i!=maxvb&&cntb[i]>cntb[maxvb1])
				maxvb1=i;
		ans=min(ans,n-cnta[maxva]-cntb[maxvb1]);
		PF("%d\n",ans);	
	}
}

Measured memory_bytes: 1280
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int A,B,C;
long long K;
int main(){
	scanf("%d%d%d",&A,&B,&C);
	cin>>K;
	if(K&1) printf("%d\n",B-A);
	else printf("%d\n",A-B);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		int end = 100;
		for(int i=1;i<=n;i++) {
			int ans =0;
			for(int x=1;x<=end;x++) {
				for(int y=x;y<=end;y++) {
					for(int z=y;z<=end;z++) {
						if((x+y+z)*(x+y+z)-(x*y+y*z+z*x)==i) {
							if(x==y&&y==z&&z==x) {
								ans++;
							}else if((x==y)||(y==z)||(y==z)) {
								ans = ans + 3;
							}else {
								ans = ans + 6;
							}
						}
						if((x+y+z)*(x+y+z)-(x*y+y*z+z*x)>=i) {
							break;
						}
					}
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 40792
#include<stdio.h>
int main(void)
{
	int n, m;
	int i, j;
	scanf("%d %d",&n,&m);
	int x[n][m];
	for(i=0; i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d", &x[i][j]);
		}
	}
	int y[m];
	for(i=0;i<m;i++){
		scanf("%d", &y[i]);
	}
	int z[n];
	for(i=0;i<n;i++){
		z[i]=0;
		for(j=0;j<m;j++){
			z[i] = z[i]+x[i][j]*y[j];
		}
	}
	for(i=0;i<n;i++){
		printf("%d\n", z[i]);
	}
	
	return 0;
}

Measured memory_bytes: 636
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias Path = Tuple!(int, "to", int, "w");
alias SS = Tuple!(int, "cur", int, "c");

Path[][10^^5] PS;
int[10^^5] TS;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (_; 0..N-1) {
        auto uvw = readln.split.to!(int[]);
        auto u = uvw[0]-1;
        auto v = uvw[1]-1;
        auto w = uvw[2]%2;
        PS[u] ~= Path(v, w);
        PS[v] ~= Path(u, w);
    }

    TS[0] = 1;
    SS[] Q = [SS(0, 1)];
    while (!Q.empty) {
        auto head = Q[0];
        Q = Q[1..$];
        foreach (next; PS[head.cur]) {
            if (TS[next.to]) continue;
            int c;
            if (next.w == 0) {
                c = head.c;
            } else if (head.c == 1) {
                c = 2;
            } else {
                c = 1;
            }
            TS[next.to] = c;
            Q ~= SS(next.to, c);
        }
    }

    foreach (i; 0..N) {
        writeln(TS[i] - 1);
    }
}

Measured memory_bytes: 18148
#include<cstdio>

int main() {
	int n; scanf("%d", &n);
	int s = 0;
	for(int i=0;i<n;i++) {
		int x; scanf("%d", &x);
		s+=x-1;
	}
	printf("%d\n", s);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(int argc, char const* argv[])
{
	double a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << setprecision(15) << sqrt((a-c)*(a-c) + (b-d)*(b-d)) << endl;
	return 0;
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;
/*int dfs(vector<int> &T, vector<int> &C, int i, int sum, int g, int count){
   
}*/

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> X(m);
  rep(i, m) cin >> X[i];
  if(n>=m) cout << 0 << endl;
  else {
    sort(X.begin(), X.end());
  vector<int> A(m-1);
    rep(i, m-1){
      A[i] = X[i+1] - X[i];
    }
    sort(A.begin(), A.end());
    int sum = 0;
    rep(i, m-n){
       sum += A[i];
    }
    cout << sum << endl;
  }
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w));
    vector<vector<ll>> b(h, vector<ll>(w));
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];
    ll rc = (h + w) * 80;
    vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(2 * rc + 1, false)));
    dp[0][0][a[0][0] - b[0][0] + rc] = true;
    dp[0][0][b[0][0] - a[0][0] + rc] = true;
    rep(i, h) {
        rep(j, w) {
            if ((i == 0) && (j == 0)) continue;
            rep(k, 2 * rc + 1) {
                bool f = false;
                ll d = abs(a[i][j] - b[i][j]);
                if (i > 0) {
                    if ((k >= d) && (dp[i - 1][j][k - d])) f = true;
                    if (((k + d) < (2 * rc + 1)) && (dp[i - 1][j][k + d])) f = true;
                }
                if (j > 0) {
                    if ((k >= d) && (dp[i][j - 1][k - d])) f = true;
                    if (((k + d) < (2 * rc + 1)) && (dp[i][j - 1][k + d])) f = true;
                }
                dp[i][j][k] = f;
            }
        }
    }
    ll ans = LONG_LONG_MAX;
    rep(i, 2 * rc + 1) {
        if (dp[h - 1][w - 1][i]) {
            ans = min(ans, abs(i - rc));
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){

    int  n,l;
    cin >> n;
    cin >> l;

    int sum;

    sum=n*(l+l+n-1)/2;

    if(l<=0 && l+n-1>=0){
    cout << sum <<endl;
  }
  else if(l>0){
    cout << sum-l <<endl;
  }
  else{
    cout << sum-(l+n-1) <<endl;
  }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

int main(){
  int n;
  cin >> n;
  int S[100010];
  rep(i,n) cin >> S[i];
  int q;
  cin >> q;
  int T[50010];
  rep(i,q) cin >> T[i];
  int ans=0;
  rep(i,q){
    int k=T[i];
    int num=upper_bound(S,S+n,k)-lower_bound(S,S+n,k);
    if(num) ans++;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3664
package main

import "fmt"

func main() {
	var A, B string
	fmt.Scan(&A, &B)

	if len(A) > len(B) {
		fmt.Println("GREATER")
		return
	}
	if len(A) < len(B) {
		fmt.Println("LESS")
		return
	}
	if A == B {
		fmt.Println("EQUAL")
		return
	}
	for i := 0; i < len(A); i++ {
		if A[i:i+1] > B[i:i+1] {
			fmt.Println("GREATER")
			return
		}
		if A[i:i+1] < B[i:i+1] {
			fmt.Println("LESS")
			return
		}
	}
	fmt.Println("EQUAL")
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = 1 << 30;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int h, w, K;
    cin >> h >> w >> K;
    int chocolate[h][w];
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            char c;
            cin >> c;
            chocolate[i][j] = c - '0';

        }
    }

    int res = INF;
    int add_pos[10], total[10];
    int sum, pos;
    for(int i = 0; i < (1 << (h - 1)); ++i) {
        sum = 0;
        pos = 0;
        for(int j = 0; j < 10; ++j) {
            total[j] = 0;
            add_pos[j] = pos;
            pos += ((i >> j) & 1);
        }
        sum += pos;

        for(int j = 0; j < w; ++j) {
            bool f = true;
            for(int k = 0; k < h; ++k) {
                total[add_pos[k]] += chocolate[k][j];
                if(total[add_pos[k]] > K) f = false;
            }
            if(!f) {
                ++sum;
                for(int k = 0; k < 10; ++k) total[k] = 0;
                for(int k = 0; k < h; ++k) {
                    total[add_pos[k]] += chocolate[k][j];
                    if(total[add_pos[k]] > K) sum = INF;

                }
            }
            if(sum >= res) break;
        }
        res = min(res, sum);
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    private static int res = int.MaxValue;
    static void Main(string[] args)
    {
        var nc = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var ds = new int[nc[1]][];
        for (var i = 0; i < nc[1]; i++)
            ds[i] = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        
        var dic = new Dictionary<int, Dictionary<int, int>>();
        for(var i = 1; i <= nc[0]; i++)
        {
            var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
            for (var j = 0; j < nc[0]; j++)
            {
                var mod = (i + j + 1) % 3;
                if (!dic.ContainsKey(mod))
                    dic[mod] = new Dictionary<int, int>();
                if (dic[mod].ContainsKey(ar[j]-1))
                    dic[mod][ar[j]-1]++;
                else
                    dic[mod][ar[j]-1] = 1;
            }
        }
        for (var i = 0; i < nc[1]; i++)
            dfs(Enumerable.Repeat(-1,3).ToArray(), 0,  i, ds, dic, nc[1]);
        WriteLine(res);
    }
    private static void dfs(int[] sel,int index,int num,int[][] ds,Dictionary<int,Dictionary<int,int>> dic,int c)
    {
        sel[index] = num;
        if (index == 2)
        {
            var sum = 0;
            for(var i = 0; i < 3; i++)
            {
                for (var j = 0; j < c; j++)
                    if (dic.ContainsKey(i)&&dic[i].ContainsKey(j))
                        sum += ds[j][sel[i]] * dic[i][j];
            }
            res = Min(res, sum);
            sel[index] = -1;
            return;
        }
        for (var i = 0; i < c; i++)
            if (!sel.Contains(i))
                dfs(sel, index + 1, i, ds, dic, c);
        sel[index] = -1;
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 17608
X[1001];
main(){
	int N,M,i,d,p,g;
	for(;scanf("%d%d",&N,&M),N;){
		for(i=1;i<=N;i++)
			scanf("%d",X+i);
		p=1;
		g=0;
		for(i=1;i<=M;i++){
			scanf("%d",&d);
			p+=d;
			if(p<N)
				p+=X[p];
			if(!g&&p>=N)
				g=i;
		}
		printf("%d\n",g);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int l[n];
    for (int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l,l+n);
    int ans =0;
    for (int i = 0;i<n-2;i++){
        for (int j =i+1;j<n-1;j++){
            for (int k =j+1;k<n;k++){
                if (l[k]<l[i]+l[j] && l[i]<l[j] && l[j]<l[k]){
                    ans++;
                }
            }
        }
    }
    cout<<ans;
    
}


Measured memory_bytes: 3640
from bisect import bisect_right


N, K = map(int, input().split())
S = input()

psum = [0] * 2
ncnt = [0] * 2

i = 1
state = int(S[0])
if state == 0:
    ncnt[i] += 1
for s in S:
    if int(s) != state:
        psum.append(psum[i])
        ncnt.append(ncnt[i])
        i += 1
        state ^= 1
        if s == '0':
            ncnt[i] += 1

    psum[i] += 1

ans = 0
for i in range(len(psum)):
    j = bisect_right(ncnt, K + ncnt[i])
    ans = max(ans, psum[j - 1] - psum[i])

print(ans)


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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x))
#define umin(m, x) (m = min(m, x))

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define bit(x, n) ((x) >> (n) & 1)
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


int main() {
    int n;
    cin >> n;
    vi p(n), q(n);
    rep(i, n) cin >> p[i], p[i]--;
    rep(i, n) cin >> q[i], q[i]--;

    vi fact(n + 1);
    fact[0] = 1;
    rep(i, 1, n + 1)
        fact[i] = fact[i - 1] * i;

    int a = 0, b = 0;
    vi x, y;

    rep(i, n) {
        x.push_back(i);
        y.push_back(i);
    }

    rep(i, n) {
        auto r = find(rng(x), p[i]);
        auto s = find(rng(y), q[i]);
        a += fact[n - i - 1] * (r - x.begin());
        b += fact[n - i - 1] * (s - y.begin());
        x.erase(r);
        y.erase(s);
    }

    cout << abs(a - b) << endl;

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int main () {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (c-(a-b) <= 0 ? 0 : c-(a-b));
}


Measured memory_bytes: 256
#include <stdio.h>

#define HEIGHT 12
#define WIDTH 6

enum { YET, ALREADY };

int calcChain( void );
int deleteBlock( void );
int findGroup( int, int );
int findGroup_body( int, int, char, int );
void deleteGroup( void );
void fallBlock( void );

typedef struct {
	char color;
	int state;
} FIELD;

FIELD field[ HEIGHT ][ WIDTH ];
const int dx[ 4 ] = { -1, 0, 1, 0 };
const int dy[ 4 ] = { 0, -1, 0, 1 };

typedef struct {
	int i;
	int j;
} INDEX;

INDEX stack[ HEIGHT * WIDTH ];
int sp;

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

	scanf( "%d%*c", &n );
	while ( n-- ) {
		for ( i = 0; i < HEIGHT; i++ ) {
			for ( j = 0; j < WIDTH; j++ ) {
				scanf( "%c", &field[ i ][ j ].color );
				field[ i ][ j ].state = YET;
			}

			scanf( "%*c" );
		}

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

	return 0;
}

int calcChain( void ) {
	int chain;

	for ( chain = 0; ; chain++ ) {
		if ( !deleteBlock() )
			break;

		fallBlock();
	}

	return chain;
}

int deleteBlock( void ) {
	int i, j, deleted;

	deleted = 0;
	for ( i = 0; i < HEIGHT; i++ )
		for ( j = 0; j < WIDTH; j++ )
			if ( field[ i ][ j ].color != '.' && field[ i ][ j ].color != 'O' && field[ i ][ j ].state == YET ) {
				sp = 0;
				if ( findGroup( i, j ) >= 4 ) {
					deleted = 1;
					deleteGroup();
				}
			}

	return deleted;
}

int findGroup( int i, int j ) {
	INDEX tmp = { i, j };

	stack[ sp++ ] = tmp;
	field[ i ][ j ].state = ALREADY;

	findGroup_body( i, j - 1, field[ i ][ j ].color, 2 );
	findGroup_body( i - 1, j, field[ i ][ j ].color, 3 );

	return findGroup_body( i, j + 1, field[ i ][ j ].color, 0 ) + findGroup_body( i + 1, j, field[ i ][ j ].color, 1 ) + 1;
}

int findGroup_body( int i, int j, char color, int comeDir ) {
	int sum, d;
	INDEX tmp = { i, j };

	if ( i < 0 || i >= HEIGHT || j < 0 || j >= WIDTH || field[ i ][ j ].state == ALREADY || field[ i ][ j ].color != color && field[ i ][ j ].color != 'O' )
		return 0;

	stack[ sp++ ] = tmp;

	if ( field[ i ][ j ].color == 'O' )
		return 0;

	field[ i ][ j ].state = ALREADY;

	sum = 0;
	for ( d = 0; d < 4; d++ )
		if ( d != comeDir )
			sum += findGroup_body( i + dy[ d ], j + dx[ d ], color, d + 2 & 3 );
	
	return sum + 1;
}

void deleteGroup( void ) {
	while ( sp-- )
		field[ stack[ sp ].i ][ stack[ sp ].j ].color = '.';
}

void fallBlock( void ) {
	int i, j, cnt;

	for ( j = 0; j < WIDTH; j++ ) {
		cnt = 0;
		for ( i = HEIGHT - 1; i >= 0; i-- )
			if ( field[ i ][ j ].color == '.' )
				cnt++;
			else {
				field[ i + cnt ][ j ].color = field[ i ][ j ].color;
				field[ i + cnt ][ j ].state = YET;
			}

		for ( i = cnt - 1; i >= 0; i-- )
			field[ i ][ j ].color = '.';
	}
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n, m;
typedef pair<ll, ll> P;
priority_queue<ll, vector<ll>, greater<ll> > que;
ll ans;

int main()
{
    cin >> n >> m;
    vector<P> p(m);
    for (int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        que.push(a);
    }
    for (int i = 0; i < m; i++)
    {
        ll x, y;
        cin >> x >> y;
        p[i] = P(y, x);
    }
    sort(p.begin(), p.end(), greater<P>());
    for (int i = 0; i < m; i++)
    {
        ll x, y;
        x = p[i].first;
        y = p[i].second;
        while (!que.empty() && y > 0)
        {
            ll t = que.top();
            if (t < x)
            {
                ans += x;
                que.pop();
                y--;
            }
            else
            {
                ans += t;
                que.pop();
            }
        }
    }
    while (!que.empty())
    {
        ll t = que.top();
        que.pop();
        ans += t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m,d;cin>>n>>m>>d;
  double ans;
  if(d==0) ans=1.0*(m-1)/n;
  else ans=2.0*(m-1)*(n-d)/(n*n);
  printf("%.7f\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#ifdef _MSC_VER
#define GC getchar
#else
#define GC getchar_unlocked
#endif
int input()
{
	int x=0;
	char c;
	bool minus=false;
	for(;;)
	{
		c=GC();
		if (c=='-')
		{
			minus=true;
			continue;
		}
		if (c==' '||c=='\n')
			if (minus)
				return -x;
			else
				return x;
		x=10*x+c-'0';
	}
}
void fix()
{
	char c;
	for(;;)
	{
		c=GC();
		if (c==-1||c!=' '&&c!='\n')
			break;
	}
	if (c!=-1)
		ungetc(c,stdin);
}
int main()
{
	int N,i,j,k,d;
	int a[6];
	int m[32];
	int M[32];
	for (i=0; i<32; i++)
	{
		m[i]=1000000000;
		M[i]=-1000000000;
	}
	scanf("%d",&N);
	d=2;
	fix();
	for (i=0; i<N; i++)
	{
		for (j=0; j<d; j++)
			a[j]=input();//,fix();
		for (j=0; j<1<<(d-1); j++)
		{
			int x=a[0];
			for (k=0; k<d-1; k++)
				if (j&(1<<k))
					x+=a[k+1];
				else
					x-=a[k+1];
			if (m[j]>x)
				m[j]=x;
			if (M[j]<x)
				M[j]=x;
		}
	}
	int ans=0;
	for (i=0; i<1<<(d-1); i++)
		if (ans<M[i]-m[i])
			ans=M[i]-m[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N,K;
    cin >> N >>K;
    vector<ll> A(N),sum(N+1);
    rep(i,N){
        cin >> A[i];
        A[i]--;
        sum[i+1] = A[i] + sum[i];
        sum[i+1] %= K;
    }
    ll ans = 0;
    map<ll,ll> mp;
    ll l = 0,r = 0;
    while(r <= N){
        if(r-l < K){
            ans += mp[sum[r]];
            mp[sum[r]]++;
            r++;
        }else{
            mp[sum[l]]--;
            l++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

struct State{
    array<int, 9> board;
    int cost;
    bool operator < (const State& s) const {
        if(cost != s.cost) return cost > s.cost;
        return board < s.board;
    }
};

int main(){
    int ch, cv;
    while(cin >> ch >> cv){
        if(ch == 0 && cv == 0) break;
        array<int, 9> start;
        array<int, 9> goal;
        REP(i, 9) cin >> start[i];
        REP(i, 9) cin >> goal[i];

        State init;
        init.board = start;
        init.cost = 0;

        priority_queue<State> que;
        map<array<int, 9>, int> dist;
        dist[init.board] = init.cost;
        que.push(init);

        array<int, 4> adj = {1, 8, 6, 3};

        while(!que.empty()){
            State s = que.top();
            que.pop();
            if(s.board == goal) break;
            for(int from = 0; from < 9; from++) if(s.board[from] == 0) {
                for(int t = 0; t < 4; t++){
                    int to = (from + adj[t]) % 9;
                    State next = s;
                    swap(next.board[from], next.board[to]);
                    next.cost += (t < 2 ? ch : cv);
                    if(!dist.count(next.board) || dist[next.board] > next.cost){
                        dist[next.board] = next.cost;
                        que.push(next);
                    }
                }
            }
        }
        cout << dist[goal] << endl;
    }
    return 0;
}

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

struct point {
    double x;
    double y;
};

void koch(int d, point p1, point p2){
    if(d == 0){
        return;
    }

    point s, u, t;
    s.x = (2*p1.x + p2.x) / 3;
    s.y = (2*p1.y + p2.y) / 3;
    t.x = (p1.x + 2*p2.x) / 3;
    t.y = (p1.y + 2*p2.y) / 3;
    u.x = (t.x-s.x)*cos(M_PI/3) - (t.y-s.y)*sin(M_PI/3) + s.x;
    u.y = (t.x-s.x)*sin(M_PI/3) + (t.y-s.y)*cos(M_PI/3) + s.y;

    koch(d-1, p1, s);
    printf("%f %f\n", s.x, s.y);
    koch(d-1, s, u);
    printf("%f %f\n", u.x, u.y);
    koch(d-1, u, t);
    printf("%f %f\n", t.x, t.y);
    koch(d-1, t, p2);

    
}

int main() {
    int n; cin >> n;
    point p1 = {0, 0};
    point p2 = {100, 0};
    printf("%f %f\n", p1.x, p1.y);
    koch(n, p1, p2);
    printf("%f %f\n", p2.x, p2.y);
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;

int f(int M, string S){
    int N = SZ(S);
    vec v(N + 1, 0);
    int now = 0, m = 0;
    IREP(i, N){
        if(S[i] == '1') now++;
        else now--;
        Min(m, now);
        v[i] = now - m;
    }

    m = 0, now = 0;
    REP(i, N){
        if(S[i] == '1') now++;
        else if(S[i] == '0') now--;
        else{
            if(now + 1 + v[i + 1] <= M) now++;
            else now--;
        }
        Min(m, now);
    }

    return m;
}

signed main(){

    string S; cin >> S;
    int N = SZ(S);

    int Z = 0, now = 0;
    REP(i, N){
        if(S[i] == '1') now++;
        else now--;
        Max(Z, now);
    }

    int ans = min(Z - f(Z, S), Z + 1 - f(Z + 1, S));
    Out(ans);

    return 0;
}


Measured memory_bytes: 13900