akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;


public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.simpleCalculator();
		return;
	}
	
	private void simpleCalculator() {
		
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); //標準入力
		LinkedList<Long> operandList = new LinkedList<Long>(); //被演算子のリスト
		LinkedList<Character> operatorList = new LinkedList<Character>(); //演算子のリスト
		
		try {
			
			//式の入力
			while (true) {
				
				String inputStr = bufferedReader.readLine();
				
				if (this.numberCheck(inputStr)) {
					
					operandList.add(Long.parseLong(inputStr));
					
				} else {
					
					if (inputStr.charAt(0) != '=') {
						operatorList.add(inputStr.charAt(0));
					} else if (inputStr.charAt(0) == '=') {
						break;
					}
					
				}
			}
			
			//式の計算
			long resultNum = 0;
			for (int i = 1; i < operandList.size(); i++) {
				
				long leftNum = operandList.get(i - 1);
				long rightNum = operandList.get(i);
				
				if (operatorList.get(i - 1) == '+') {
					
					if (resultNum == 0 && i == 1) {
						long tmp = leftNum + rightNum;
						resultNum += tmp;
					} else {
						long tmp = resultNum + rightNum;
						resultNum = tmp;
					}
					
				} else if (operatorList.get(i - 1) == '-') {
					
					if (resultNum == 0 && i == 1) {
						long tmp = leftNum - rightNum;
						resultNum += tmp;
					} else {
						long tmp = resultNum - rightNum;
						resultNum = tmp;
					}
					
				} else if (operatorList.get(i - 1) == '*') {
					
					if (resultNum == 0 && i == 1) {
						long tmp = leftNum * rightNum;
						resultNum += tmp;
					} else {
						long tmp = resultNum * rightNum;
						resultNum = tmp;
					}
					
				} else if (operatorList.get(i - 1) == '/') {
					
					if (resultNum == 0 && i == 1) {
						long tmp = leftNum / rightNum;
						resultNum += tmp;
					} else {
						long tmp = resultNum / rightNum;
						resultNum = tmp;
					}
					
				}
				
			}
			
			System.out.println(resultNum);
			
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		
	}
	
	//入力された文字列が数字かどうかを判定する
	private boolean numberCheck(String str) {
		
		try {
			Long.parseLong(str);
			return true;
		} catch (NumberFormatException e) {
			return false;
		}
		
	}
}

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

int Gcd(int m, int n)
{
	int temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main(){
  int N;
  int a[3000];
  cin >> N;
  int sum = 0;
  for(int i=0;i<N;i++){
    cin >> a[i];
    sum += a[i];
  }  
  cout << sum-N << "\n";
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a<0 && b<0 && ((abs(a-b)+1)%2 == 1)){
   cout << "Negative" << endl;
    return 0;
  }
  else if(a<0 && b<0){
   cout << "Positive" << endl;
    return 0;
  }
  else if(a>0 && b>0){
    cout << "Positive" << endl;
    return 0;
  }
 else {
   cout << "Zero" << endl;
 }
}


Measured memory_bytes: 3600
def add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]
 
def split(ar, k, w):
    a = 0
    if max(max(ar)) > k:
      return -1
    tm = ar[0]
    for i in range(1, w):
        tm = add(tm, ar[i])
        if max(tm) > k:
            a += 1
            tm = ar[i]
    return a        
 
h, w, k = map(int, input().split())
s = [[int(i) for i in input()] for j in range(h)]
ans = h*w
 
for i in range(2**(h-1)):
    data = []
    temp = s[0]
    sp = bin(i+2**h)[4:]
    if ans < sp.count("1"):
        continue
    for j in range(1, h):
        if sp[j-1] == "0":
            temp = add(temp, s[j])
        else:
            data.append(temp)
            temp = s[j]
    data.append(temp)
    ans_ = split([list(x) for x in zip(*data)], k, w)
    if ans_ == -1:
        continue
    ans_ += sp.count("1")
    if ans > ans_:
        ans = ans_
print(ans)


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

int main() {
  int k, s;
  cin >> k >> s;
  int res = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j<= k; j++) {
      if (s - i - j >= 0 && s - i - j <= k) {
        res++;
      }
    }
  }
  cout << res << endl;

}


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

#define pb push_back
#define fr first
#define sc second
typedef pair<int,int> pii;
typedef vector<int> vi;
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int p[31]={0};
int q[31]={0,1,1,1,1,1,1,1,1,1,2,2,2,4,4,4,6,6,6,5,5,5,3,3,3,3,3,3,3,3,3};
int ret=8;

void a(){
  swap(p[1],p[28]);
  swap(p[2],p[29]);
  swap(p[3],p[30]);
  swap(p[15],p[16]);
  swap(p[19],p[21]);
}

void b(){
  swap(p[3],p[22]);
  swap(p[6],p[25]);
  swap(p[9],p[28]);
  swap(p[12],p[19]);
  swap(p[13],p[15]);
}

void c(){
  swap(p[7],p[22]);
  swap(p[8],p[23]);
  swap(p[9],p[24]);
  swap(p[13],p[18]);
  swap(p[10],p[12]);
}

void d(){
  swap(p[1],p[24]);
  swap(p[4],p[27]);
  swap(p[7],p[30]);
  swap(p[10],p[21]);
  swap(p[16],p[18]);
}

void solve(int num){
  int cnt=0;
  for(int i=1;i<31;i++){
    if(p[i]==q[i]) cnt++;
  }

  if(cnt==30) ret=num;
  if(ret<=num) return;
  a();solve(num+1);a();

  b();solve(num+1);b();

  c();solve(num+1);c();

  d();solve(num+1);d();

}
int main(){
  int n;
  cin>> n;
  while(n--){
    for(int i=1;i<31;i++){
      cin>> p[i];
    }

    ret=8;
    solve(0);
    cout<< ret<< endl;
  }
}

Measured memory_bytes: 1160
from collections import*
class UnionFind():
    def __init__(self,size):
        self.table=[-1]*size
    def root(self,x):
        while self.table[x]>=0:
            x=self.table[x]
        return x
    def unite(self,x,y):
        s1=self.root(x)
        s2=self.root(y)
        if s1!=s2:
            if self.table[s1]>self.table[s2]:
                s1,s2=s2,s1
            self.table[s1]+=self.table[s2]
            self.table[s2]=s1
        return
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def size(self,x):
        return -self.table[self.root(x)]
n,m,*t=map(int,open(0).read().split())
u=UnionFind(n+1)
f=defaultdict(list)
e=defaultdict(list)
for l,r,d in zip(t[::3],t[1::3],t[2::3]):
    u.unite(l,r)
    e[l].append((r,d))
for i in range(n+1):
    f[u.root(i)].append(i)
for t in f.values():
    if len(t)<3:continue
    outs=defaultdict(list)
    ins=defaultdict(int)
    for i in t:
        outs[i]=[j for j,v in e[i]]
        for j in outs[i]:
            ins[j]+=1
    q=deque(v1 for v1 in t if ins[v1]==0)
    res=[]
    while q:
        v1=q.popleft()
        res.append(v1)
        for v2 in outs[v1]:
            ins[v2]-=1
            if ins[v2]==0:
                q.append(v2)
    if not res:
        print('No')
        exit()
    c=defaultdict(int)
    for i in res:
        for j,v in e[i]:
            if c[j]and c[j]!=c[i]+v:
                print('No')
                exit()
            c[j]=c[i]+v
print('Yes')

Measured memory_bytes: 131736
#include <bits/stdc++.h>
#define read(arr,n)	for(int i=0;i<n;i++) cin>>arr[i];
#define print(arr,n) for(int i=0;i<n;i++) cout << arr[i]<<' ';cout << endl;
typedef int int32;
#define int ll

using namespace std;

typedef long long ll;

void solve() {
	string s;
	cin >> s;
	for (auto x: s) {
		if (x == '7') {
			cout << "Yes\n";	return;
		}
	}
	cout << "No\n";	return ;
}

int32 main() {
	int t = 1;
	//cin >> t;
	int c = 0;
	while (c < t) {
		solve();
		c++;	
	}
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
inline int max(int x, int y){return (x<y)?y:x;}
int main(void){
    int k,n,i,a00,a0,a1,d=0;
    cin >> k >> n;
    cin >> a0;
    a00=a0;
    for(i=1;i<n;i++){
        cin >> a1;
        d=max(d,a1-a0);
        a0=a1;
    }
    d=max(d,a00+(k-a0));
    cout << k-d << endl;
    return 0;
}

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

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

const int MOD = 1e9 + 7;

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(i, vec) for(auto (i) = (vec).begin(); (i) != (vec).end(); (i)++)
#define vrREP(i, vec) for(auto (i) = (vec).end()-1;(i) != (vec).begin()-1;(i)--)

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class Calcu{
  private:
    lli n, n_head, n_size;
    int size;
  public:
    Calcu(lli nn){
      n = nn;
      size = 1; n_size = 1;
      while(nn >= 10){
        size++; n_size *= 10;
        nn /= 10;
      }
      n_head = nn;
    }
    ~Calcu(void){};
    lli computing(int s){
      lli res = 0;
      lli n_copy = n, working_size = n_size, working_numb = n_head;
      REP(i, size-1){
        n_copy %= working_size; working_size /= 10;
        int tmp = n_copy / working_size;
        //n_copy %= working_size; working_size /= 10;
        if((1 << i) & s){
          res += working_numb;
          working_numb = tmp;
        }
        else working_numb = 10 * working_numb + tmp;
      }
      res += working_numb;
      //cout << bitset<16>(s) << " : " << res << "\n";
      return res;
    }
    void solve(void){
      lli res = 0;
      REP(i, 1 << (size - 1)) res += computing(i);
      cout /* << "res = " */<< res << "\n";
    }
};


int main(void){
  lli n; cin >> n;
  Calcu A(n);
  A.solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

int main() {

int N,W; cin>>N>>W;

vector<int> v(N),w(N);

rep(i,N) cin>>v[i]>>w[i];

vector<vector<int>> dp(N+1,vector<int>(W+1));
rep(i,W+1) dp[0][i]=0;

for(int i=0;i<N;i++){
  for(int j=0;j<=W;j++){
    if(w[i]<=j) dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][j]);
    else dp[i+1][j]=dp[i][j];
  }
}

cout << dp[N][W] << endl;

return 0;
}


Measured memory_bytes: 6772
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        while(true){
            int n=sc.nextInt();
            if(n==0){
                break;
            }
            int s[]=new int[n];
            int p[]=new int[n];
            int q[]=new int[n];
            int r[]=new int[n];
            int k[]=new int[n];
            for(int i=0;i<n;i++){
                s[i]=sc.nextInt();
                p[i]=sc.nextInt();
                q[i]=sc.nextInt();
                r[i]=sc.nextInt();
                k[i]=4*(p[i]+r[i])+9*q[i];
            }
            int P,Q,R,C;
            P=sc.nextInt();
            Q=sc.nextInt();
            R=sc.nextInt();
            C=sc.nextInt();
            int cnt=0;
            for(int i=0;i<n;i++){
                if(p[i]<=P&&q[i]<=Q&&r[i]<=R&&k[i]<=C){
                    cnt++;
                    System.out.println(s[i]);
                }
            }
            if(cnt==0){
                System.out.println("NA");
            }
        }
    }
}


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

int x, y;
string ans = "No";

int main() {
  cin >> x >> y;
  rep (i, x+1) {
    if ((x-i)*2 + i*4 == y) ans = "Yes";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <stack>
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <cstdio>
using namespace std;

int main()
{
	int n;
	typedef pair <int, int> p;//????????????????????????
	while (cin >> n, n != 0) {
		vector <p> map[12];
		int a, b, c;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			map[a].push_back(p(b, c));
			map[b].push_back(p(a, c));
		}
		p ans = p(0, 9999999);
		for (int z = 0; z < 10; z++) {
			if (map[z].size() == 0)break;
			int d[12] ;
			for (int i = 0; i < 12; i++)d[i] = 9999999;
			priority_queue<p, vector<p>, greater<p> > que;//??????????????????
			que.push(p(0, z));
			d[z] = 0;
			while (!que.empty()) {
				p now = que.top();
				que.pop();
				if (now.first > d[now.second])continue;
				for (int i = 0; i < map[now.second].size(); i++) {
					p dst = map[now.second][i];
					if (d[dst.first] > now.first + dst.second) {
						que.push(p(now.first + dst.second, dst.first));
						d[dst.first] = now.first + dst.second;
					}
				}
			}int cnt = 0;
			for (int i = 0; i < 10; i++) { if (d[i] != 9999999)cnt += d[i]; }
			if (ans.second > cnt)ans = p(z, cnt);
		}
		cout << ans.first << " " << ans.second << endl;
	}
}

Measured memory_bytes: 1196
#include <stdio.h>
#define num 100
int main(){
  int i,j,N,A[num],flag=1,st,co=0;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  while(flag){
    flag = 0;
    for(j=N-1;j>=1;j--){
      if(A[j] < A[j-1]){
	st = A[j-1];
	A[j-1] = A[j];
	A[j] = st;
	flag = 1;
	co += 1;
      }
    }
  }

  for(i=0;i<N;i++){
    if(i != N-1)printf("%d ",A[i]);
    else printf("%d\n",A[i]);
  }
  printf("%d\n",co);

  return 0;
}



Measured memory_bytes: 2104
N = int(input())

t, x, y = [0]*N, [0]*N, [0]*N
t[0], x[0], y[0] = map(int, input().split())
if t[0] == x[0]+y[0] or ((-x[0]-y[0] + t[0]) > 0 and  (-x[0]-y[0] + t[0]) % 2 == 0):
    check = True
else:
    check = False
for i in range(1, N):
    tt, xx, yy = map(int, input().split())
    t[i], x[i], y[i] = tt-t[i-1] ,abs(xx-x[i-1]) , abs(yy-y[i-1])
    judge = -x[i]-y[i]+t[i]
    if judge < 0 or ( judge % 2 !=0 and judge > 0) or (x[i]==y[i]==0 and t[i]%2 !=0) :
        if t[i] != x[i]+y[i]:
            check = False
            break

if check==True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11636
#include <cstdio>
using namespace std;

class Dice{
    public:
    int face[6];
    Dice(){}
    int roll(int a, int b, int c, int d){
        int temp = face[a]; face[a] = face[b]; face[b] = face[c]; face[c] = face[d]; face[d] = temp;
        return 0;
    }
    int move(char c){
        if (c == 'W') roll(0, 2, 5, 3);
        if (c == 'E') roll(0, 3, 5, 2);
        if (c == 'S') roll(0, 4, 5, 1);
        if (c == 'N') roll(0, 1, 5, 4);
        return 0;
    }
};

int right(Dice dice, int top, int front){
    for (int i = 0; i <= 6; i++){
        if (dice.face[1] == front){
            for (int j = 0; j < 4; j++){
                if (dice.face[0] == top){
                    printf("%d\n", dice.face[2]);
                    return 0;
                }
                else dice.move('W');
            }
        }
        else{
            if (i == 3) dice.move('W');
            dice.move('N');
        }
    }
    return 0;
}

int samedice(Dice dice1, Dice dice2){
    for (int i = 0; i <= 6; i++){
        if (dice1.face[1] == dice2.face[1]){
            for (int j = 0; j < 4; j++){
                if (dice1.face[0] == dice2.face[0]){
                    if (dice1.face[2] == dice2.face[2] && dice1.face[3] == dice2.face[3] && dice1.face[4] == dice2.face[4] && dice1.face[5] == dice2.face[5]){
                        return 1;
                    } 
                }
                else dice1.move('W');
            }
        }
        else{
            if (i == 3) dice1.move('W');
            dice1.move('N');
        }
    }
    return 0;
}

int multi_samedice(Dice dices[], int num_of_dice){
    for (int i = 0; i < num_of_dice; i++){
        for (int j = i+1; j < num_of_dice; j++){
            if (samedice(dices[i], dices[j])){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}

int main(void){
    int num_of_dice;
    Dice dices[100];
    scanf("%d", &num_of_dice);
    for (int i = 0; i < num_of_dice; i++){
        scanf("%d%d%d%d%d%d", &dices[i].face[0], &dices[i].face[1], &dices[i].face[2], &dices[i].face[3], &dices[i].face[4], &dices[i].face[5]);
    }
    multi_samedice(dices, num_of_dice);
    return 0;
}

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

int main(){
  int H,W,min_row,min_col;
  cin >> H >> W >> min_row >> min_col;

  string pattern0,pattern1;
  for(int w=0; w<W; w++){
    if(w < min_row){
      pattern0+= '0';
      pattern1+= '1';
    }
    else{
      pattern0+= '1';
      pattern1+= '0';
    }
  }

  for(int h=0; h<H; h++){
    if(h < min_col){
      cout << pattern0 << endl;
    }
    else{
      cout << pattern1 << endl;
    }
  }
}

Measured memory_bytes: 3624
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int n;
	cin>>n;
	int c=0;
	loop(i,1,n)loop(j,1,n){
		if(i*j>=n)break;
		c++;
	}
	cout<<c<<endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

bool isSolvable(int x, int y){
    if(y%2!=0)return false;
    if(x==0 && y==0)return true;
    if(y<0)return false;
    if(x<0 && y>=0)return false;
    if(x>=y)return false;
    return isSolvable(x-1,y-2)||isSolvable(x-1,y-4);
}

void solve(){
    int x, y;
    cin>>x>>y;
    bool flag=isSolvable(x,y);
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3656
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))

a, b = map(int, input().split())

if (b == 1):
    print(0)
    exit()
ans = 0
for i in range(1,1000000000):
    if (i == 1):
        b -= a
    else:
        b -= (a-1)
    ans += 1
    if (b <= 0):
        break
print(ans)




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

using namespace std;

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

typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> q;
    vector<vector<int> > jobs(M);
    rep(i,N){
        int a, b;
        cin >> a >> b;
        if(a > M) continue;
        jobs[M-a].push_back(b);
    }
    ll ans = 0;
    for(int i = M-1; i >= 0; i--){
        for(int b : jobs[i]){
            q.push(b);
        }
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5504
n = int(input())
t,a = map(int, input().split())
ls = list(map(int, input().split()))
res = float('inf')

for i in range(n):
    tmp = t - ls[i] * 0.006
    if res > abs(a-tmp):
        res = abs(a-tmp)
        ans = i + 1
print(ans)

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

int a[101] = {0};

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    int ans = INT_MAX;
    for(int i=-100;i<=100;++i){
        int sum = 0;
        for(int j=0;j<n;++j){
            sum += (a[j] - i) * (a[j] - i);
        }
        if(sum < ans)ans = sum;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

class UnionFind{
public:
	vector<int> par;
	//0-indexed
	void init(int n = 1) {
		par.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i;
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		else{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		else par[x] = y;
	}
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,M;
	cin >> N >> M;
	UnionFind uf;
	uf.init(N+1);
	FOR(i,0,M){
		ll a,b,c;
		cin >> a >> b >> c;
		uf.unite(a,b);
	}
	ll ans = 0;
	set<ll> se;
	FOR(i,1,N+1){
		ll x = uf.root(i);
		if(se.count(x)==0){
			ans++;
			se.insert(x);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  ll m;
  cin >> m;
  rep(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    ll tmp = 0;
    for (ll j = a; j < b; j++) {
      if (v.at(j) == c) tmp++;
    }
    cout << tmp << endl;
  }
}


Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		try (Scanner sc = new Scanner(System.in)) {
			int A = Integer.parseInt(sc.next());
			int B = Integer.parseInt(sc.next());
			int T = Integer.parseInt(sc.next());
			
			System.out.println((T / A) * B); 
		} // Scanner Close
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N, M; cin >> N >> M;
    long long ac = 0;
    long long pena = 0;
        
    vector<long long> wa(N, 0), isac(N, 0);
    for (int i = 0; i < M; ++i) {
        int p; string s;
        cin >> p >> s;
        --p;
        if (s == "AC") {
            if (!isac[p]) {
                ++ac;
                pena += wa[p];
                isac[p] = true;
            }
        }
        else wa[p]++;
    }
    cout << ac << " " << pena << endl;
}

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

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a,ll b){
    return a * b / gcd(a, b);
}


int main(){
    int n;
    ll ans=0;
    string s;
    cin>>n;
    map<string,int> mp;
    rep(i,n){
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    for(auto& p : mp){
        ans+=(ll)p.second*(p.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
S=input()

endflag=0
count=0
for num,i in enumerate(S):
    if num==0:
        if S[0]!="A":
            print("WA")
            endflag=1
    elif i=="C":
        if num<2 or num>=(len(S)-1) or count>0:
            print("WA")
            endflag=1
        else:
            count+=1
    elif i.islower() == False:
        print("WA")
        endflag=1

    if endflag==1:
        break
if endflag==0:
    if count==1:
        print("AC")
    else:
        print("WA")


Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
long long int fie[5000];
int main(){
    fie[0]=1;
    long long int S;
    cin>>S;
    for(int i=0;i<2003;i++){
        for(int j=3;j<2003;j++){
            fie[i+j]+=fie[i];
            fie[i+j]%=1000000007;
        }
    }
    cout<<fie[S]<<endl;
    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,ll> P;

int n;
int k[200005],l[200005],r[200005];

void solve(){
	scanf("%d",&n);
	ll ans=0;
	vector<P> vf,vb;
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&k[i],&l[i],&r[i]);
		k[i]--;
		ans+=min(l[i],r[i]);
		if(l[i]>=r[i]){
			vf.push_back(P(k[i],l[i]-r[i]));
		}else{
			vb.push_back(P(k[i],r[i]-l[i]));
		}
	}
	sort(vf.begin(),vf.end());
	priority_queue<ll,vector<ll>,greater<ll> > que;
	int cur=0;
	int cnt=0;
	for(int i=0;i<n;i++){
		while(cur<vf.size() && vf[cur].first==i){
			que.push(vf[cur].second);
			cnt++;
			if(cnt>i+1){
				que.pop();
				cnt--;
			}
			cur++;
		}
	}
	while(que.size()){
		ans+=que.top();
		que.pop();
	}
	sort(vb.begin(),vb.end());
	reverse(vb.begin(),vb.end());
	cur=0;
	cnt=0;
	for(int i=n;i>=0;i--){
		while(cur<vb.size() && vb[cur].first==(i-1)){
			que.push(vb[cur].second);
			cnt++;
			if(cnt>(n-i)){
				que.pop();
				cnt--;
			}
			cur++;
		}
	}
	while(que.size()){
		ans+=que.top();
		que.pop();
	}
	printf("%lld\n",ans);
}

int main(void){
	int t;
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		solve();
	}
	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

double d1,d2;
int X1,Y1,X2,Y2;
int N;
int XX[202020],YY[202020];

vector<int> LIS(vector<int>& v) {
	int i,N=v.size();
	vector<int> dp(N,1<<30),id(N);
	FOR(i,v.size()) {
		id[i] = lower_bound(dp.begin(),dp.end(),v[i]) - dp.begin();
		dp[id[i]] = v[i];
	}
	int nl = *max_element(id.begin(),id.end());
	vector<int> ret(nl+1);
	FOR(i,N) if(id[N-1-i] == nl) ret[nl--] = v[N-1-i];
	return ret;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	double PI=atan(1)*4;
	d1=20-20*PI/4;
	d2=20*PI/2-20;
	
	cin>>X1>>Y1>>X2>>Y2;
	cin>>N;
	FOR(i,N) {
		cin>>XX[i]>>YY[i];
		if(XX[i]<min(X1,X2) || XX[i]>max(X1,X2) || YY[i]<min(Y1,Y2) || YY[i]>max(Y1,Y2)) i--,N--;
	}
	
	X2-=X1;
	Y2-=Y1;
	FOR(i,N) {
		XX[i]-=X1;
		if(X2<0) XX[i]=-XX[i];
		YY[i]-=Y1;
		if(Y2<0) YY[i]=-YY[i];
	}
	if(X2<0) X2=-X2;
	if(Y2<0) Y2=-Y2;
	
	double ret;
	
	if(X2==0) {
		ret=100.0*Y2+N*d2;
	}
	else if(Y2==0) {
		ret=100.0*X2+N*d2;
	}
	else if(N) {
		vector<pair<int,int>> V;
		vector<int> V2;
		FOR(i,N) V.push_back({XX[i],YY[i]});
		sort(ALL(V));
		FORR(v,V) V2.push_back(v.second);
		auto V3=LIS(V2);
		
		if(V3.size()==min(X2,Y2)+1) {
			ret=100.0*(X2+Y2)-d1*(V3.size()-1)+d2;
		}
		else {
			ret=100.0*(X2+Y2)-d1*V3.size();
		}
		
	}
	else {
		ret=100.0*(X2+Y2);
	}
	_P("%.12lf\n",ret);
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 6768
#include <bits/stdc++.h>
#define bear ryan
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define ends ' '
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll inf = 1e9;

int k;
int d[15][10];
vector<int> ans;

void solve(int a, int b) {
    if(!a)  return;
    b = max(b, 0);
    for(int i = b; i <= b + 2; ++i) {
        if(k <= d[a][i]) {
            ans.eb(i);
            solve(a - 1, i - 1);
            break;
        }
        k -= d[a][i];
    }
}

int main(void) {
    fastio;
    cin >> k;
    for(int i = 0; i < 10; ++i) d[1][i] = 1;
    for(int i = 2; i <= 10; ++i) {
        for(int j = 0; j < 10; ++j) {
            for(int k = -1; k <= 1; ++k) if(0 <= j + k && j + k <= 9) {
                d[i][j] += d[i - 1][j + k];
            }
        }
    }

    for(int i = 1; i <= 10; ++i) for(int j = 1; j < 10; ++j) {
        if(k <= d[i][j]) {
            ans.eb(j);
            solve(i - 1, j - 1);
            goto BREAK;
        }
        k -= d[i][j];
    }
BREAK:
    for(auto i : ans)   cout << i;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(_) for _ in input().split()]
Q = int(input())
BC = [[int(_) for _ in input().split()] for _ in range(Q)]


class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        res = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                res = f(res, dat[l])
                l += 1
            if r & 1:
                r -= 1
                res = f(dat[r], res)
            l >>= 1
            r >>= 1
        return res


array = [0] * (10**5 + 1)
for a in A:
    array[a] += a
st = SegmentTree(array, f=lambda x, y: x + y, ti=0)
for b, c in BC:
    st.update(c, st.query(c, c + 1) + st.query(b, b + 1) * c // b)
    st.update(b, 0)
    print(st.query(0, 10**5 + 1))


Measured memory_bytes: 105352
n, x = map(int, input().split())

table_l = [-1 for _ in range(51)]
table_p = [-1 for _ in range(51)]
table_l[0] = 1
table_p[0] = 1

for i in range(1, 51):
    table_l[i] = table_l[i-1] * 2 + 3
    table_p[i] = table_p[i-1] * 2 + 1


def f(level, x):
    if level == 1:
        if x == 0 or x == 1:
            return 0
        if x == 2:
            return 1
        if x == 3:
            return 2
        else:
            return 3

    if table_l[level] == x:
        return table_p[level]

    if x - 1 <= table_l[level - 1]:
        return f(level - 1, x - 1)

    if x - 2 == table_l[level - 1]:
        return table_p[level - 1] + 1
    if x - 2 > table_l[level - 1]:
        xx = x - 2 - table_l[level - 1]
        return table_p[level - 1] + 1 + f(level - 1, xx)


print(f(n, x))


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int a, b;
  cin >> a >> b;
  for (int i = 0; i <= 20000; i++) {
    if (i * 8 / 100 == a && i / 10 == b) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

using namespace std;
#define int int64_t
#define rep(i,a,n) for(int i=(a); i<(n); ++i)
#define reps(i,a,n) for(int i=(a); i<(n); --i)
#define all(x) (x).begin(),(x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed(n) fixed << setprecision(n)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
	cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n,cnt=0,rcnt=0,bcnt=0,gcnt=0;
    cin>>n;
    string s;
    cin>>s;

    rep(i,0,n){
        if(s[i] == 'R') ++rcnt;
        else if(s[i] == 'B') ++bcnt;
        else ++gcnt;
    }

    //cout<<rcnt<<' '<<bcnt<<' '<<gcnt<<'\n';

    int wa;
    rep(i,0,n){
        rep(j,i,n){
            wa = abs(j-i) * 2;
            wa += i;
            if(wa < n && s[i] != s[j] && s[i] != s[wa] && s[j] != s[wa]){
                ++cnt;
                //cout<<s[i]<<' '<<s[j]<<' '<<s[wa]<<'\n';
            }

        }
    }

    cout<<(rcnt*bcnt*gcnt)-cnt<<'\n';
    return 0;
}

Measured memory_bytes: 3652
//By Bibi
///                 .-~~~~~~~~~-._       _.-~~~~~~~~~-.
///             __.'              ~.   .~              `.__
///           .'//                  \./                  \\`.
///        .'//                     |                     \\`.
///       .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
///     .'//.-"                 `-.  |  .-'                 "-.\\`.
///   .'//______.============-..   \ | /   ..-============.______\\`.
/// .'______________________________\|/______________________________`.
#include<bits/stdc++.h> 
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define dep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
int read()
{
	int sum=0,flag=1;
	char c;
	for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=-1;
	for(;c>='0'&&c<='9';c=getchar())sum=(sum<<1)+(sum<<3)+c-'0';
	return sum*flag;
}
char c[5][5];
void init()
{
	rep(i,1,3)
	rep(j,1,3) cin>>c[i][j];
}
int main()
{
	init();
	cout<<c[1][1]<<c[2][2]<<c[3][3];
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int x[500005];
double y[500005];
int main(){
	int n,L;
	scanf("%d%d\n",&n,&L);
	int head=1,tail=0,sum=0;
	double ans=0;
	for (int i=1;i<=n;i++){
		int t,v;
		scanf("%d%d\n",&t,&v);
		for (;head<=tail && sum-x[head]>=L-v;) ans-=y[head],sum-=x[head++];
		if (sum>L-v){
			ans-=y[head];
			y[head]-=(sum-L+v)*y[head]/x[head];
			ans+=y[head];
			x[head]-=sum-L+v;
		}
		sum=L;
		double s=1.0*v*t;ans+=s;
		for (;head<=tail && y[tail]*v>=s*x[tail];tail--)
			v+=x[tail],s+=y[tail];
		x[++tail]=v;y[tail]=s;
		printf("%.7f\n",ans/L);
	}
}

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
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; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  SPEED;
  int a; cin >> a;
  cout << 3*a*a << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef pair<int, TIII> QIIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b,c))
#define MQ(a,b,c,d) MP(a, MT(b,c,d))
#define Q1 first
#define Q2 second.first
#define Q3 second.second.first
#define Q4 second.second.second

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8
#define MOD 1000000007

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

int board[33][33];
int memo[33][33][4];
int w,h;
int c[4];

int main(){
	while(cin>>w>>h, w){
		memset(memo, -1, sizeof(memo));
		memset(board, -1, sizeof(board));
		REP(i,h)REP(j,w)scanf("%d", &board[i+1][j+1]);
		REP(i,4)scanf("%d", c+i);
		priority_queue<QIIII, vector<QIIII>, greater<QIIII> > q;
		q.push(MQ(0, 1, 1, 0));
		while(!q.empty()){
			QIIII tmp = q.top();
			q.pop();
			int y=tmp.Q2;
			int x=tmp.Q3;
			int d=tmp.Q4;
			if(memo[y][x][d]>=0)continue;
			memo[y][x][d] = tmp.Q1;
			REP(i,4){
				int nd = (i+d)%4;
				int nx = x+dx[nd];
				int ny = y+dy[nd];
				if(board[ny][nx]!=-1){
					if(board[y][x]==i)q.push(MQ( tmp.Q1, ny, nx, nd));
					else q.push(MQ( tmp.Q1+c[i], ny, nx, nd));
				}
			}
		}
		int ret = 1000000000;
		REP(i,2)ret = min(ret, memo[h][w][i]);
		cout << ret << endl;
	}
	return 0;
}

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

int main() {
    int number;
    double weight, height;
    while (scanf("%d,%lf,%lf", &number, &weight, &height) != EOF) {
        double BMI = weight / (height * height);
        if (BMI >= 25) {
            cout << number << endl;
        }
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	int n, w[110],s = 0,g = 0;
	cin >> n;
	int i = 1, j = n - 2;
	for (int i = 0; i < n; i++) { cin >> w[i]; }
	s = w[0], g = w[n - 1];
	while(i <= j)
	{
		if (s <= g) { s += w[i]; i++; }
		else { g += w[j]; j--; }
	}
	cout << abs(s - g) << endl;
	return 0;
}

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

int main()
{
	int H, W;
	std::cin >> H >> W;

	char A[100][100] = { 0 };
	for ( int i = 0; i < H; i++ )
	{
		char tmpbuf[100];
		std::cin >> tmpbuf;
		for ( int j = 0; j < W; j++ )
		{
			A[i][j] = tmpbuf[j];
		}
	}

	bool bErase;
	do {
		bErase = false;

		for ( int i = 0; i < H; i++ )
		{
			int j;
			for ( j = 0; j < W; j++ )
			{
				if ( A[i][j] == '#' )
				{
					break;
				}
			}

			if ( j == W )
			{
				for ( int k = i; k < H - 1; k++ )
				{
					for ( int l = 0; l < W; l++ )
					{
						// 一行詰める
						A[k][l] = A[k + 1][l];
					}
				}
				for ( int l = 0; l < W; l++ )
				{
					A[H - 1][l] = 0;	//	最後の行を消す
				}
				--H;	//	一行減らす

				bErase = true;
			}
		}
	} while ( bErase );

	do {
		bErase = false;

		for ( int i = 0; i < W; i++ )
		{
			int j;
			for ( j = 0; j < H; j++ )
			{
				if ( A[j][i] == '#' )
				{
					break;
				}
			}

			if ( j == H )
			{
				for ( int k = 0; k < H; k++ )
				{
					for ( int l = i; l < W - 1; l++ )
					{
						// 一列詰める
						A[k][l] = A[k][l + 1];
					}
				}
				for ( int k = 0; k < H; k++ )
				{
					A[k][W - 1] = 0;	//	最後の列を消す
				}
				--W;	//	一列減らす

				bErase = true;
			}
		}
	} while ( bErase );

	for ( int i = 0; i < 100; i++ )
	{
		for ( int j = 0; j < 100; j++ )
		{
			if ( A[i][j] != 0 )
			{
				std::cout << A[i][j];
			}
		}
		if ( A[i][0] != 0 )
		{
			std::cout << std::endl;
		}
	}

	return ( 0 );
}


Measured memory_bytes: 888
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int n = 10;
int d[n][n];

int h, w;

int main() {
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
     */
    cin >> h >> w;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> d[i][j];
        }
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int x;
            cin >> x;
            if (x == -1) continue;
            ans += d[x][1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int e;


signed main(){
    while(cin >> e, e){
        int m = INF;
        for(int z = 0;z*z*z <= e;z++) for(int y = 0;y*y <= e;y++){
            int x = e-z*z*z-y*y;
            if(x >= 0) chmin(m, x+y+z);
        }
        cout << m << endl;
    }

    return 0;
}


Measured memory_bytes: 3000
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int n,y,m,d;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d%d%d",&y,&m,&d);
        int t = 0;
        if(y%3 == 0 )
        {
            t += 200 - ((m -1)* 20 + d);
        }
        else
        {
             t += 195 - ((m -1)* 20 + d) +(m-1)/2;
        }
        int y3=0,y1=0;
        for(int i = y+1; i < 1000; i++)
        {
            if(i%3==0)
                y3++;
            else
                y1++;
        }
        t += y3 * 200 + y1 * 195;
        printf("%d\n",t+1);
    }
    return 0;
}

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

using namespace std;

int main() {
	int A, B, C;

	cin >> A >> B >> C;

	int ans = 0;
	int num = A % 2 + B % 2 + C % 2;
	//偶数２
	if (num == 1) {
		if (A % 2 == 0) A++;
		if (B % 2 == 0) B++;
		if (C % 2 == 0) C++;
		ans++;
	}
	//奇２
	else if (num == 2) {
		if (A % 2 == 1) A++;
		if (B % 2 == 1) B++;
		if (C % 2 == 1) C++;
		ans++;
	}

	//一番大きい数に合わせる
	int maximum = max({ A, B, C });
	ans += (3 * maximum - A - B - C) / 2;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
map<ll, ll> prime_factor(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] = 1;
    }
    return res;
}

int main()
{
    ll N, P;
    cin >> N >> P;
    auto M = prime_factor(P);
    ll max = 0;

    ll ans = 1;
    for (auto i : M)
    {
        if (i.second >= N)
        {
            ans *= pow(i.first,i.second/N);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256