akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	double x,y,z,dist;
};

int N;
Info info[500];
bool check[500];

double calc_dist(Info info){
	return sqrt(info.x*info.x+info.y*info.y+info.z*info.z);
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf",&info[i].x,&info[i].y,&info[i].z);
		info[i].dist = calc_dist(info[i]);
	}

	for(int i = 0; i < N; i++)check[i] = false;

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

	Info scope;
	double degree,degree2;

	for(int loop = 0; loop < M; loop++){
		scanf("%lf %lf %lf %lf",&scope.x,&scope.y,&scope.z,&degree);
		scope.dist = calc_dist(scope);

		for(int i = 0; i < N; i++){
			degree2 = acos((info[i].x*scope.x+info[i].y*scope.y+info[i].z*scope.z)/(info[i].dist*scope.dist));
			if(degree2 <= degree){
				check[i] = true;
			}
		}
	}

	int ans = 0;
	for(int i = 0; i < N; i++){
		if(check[i])ans++;
	}

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


int main(){

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

		func();
	}

	return 0;
}

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

void solve(long long N, std::vector<long long> L) {
  sort(L.begin(), L.end(), greater<int>());
  long long t = 0;
  for (long long a = 0; a < N - 2; a++) {
    for (long long b = a + 1; b < N - 1; b++) {
      for (long long c = b + 1; c < N; c++) {
        if ((L[a] < L[b] + L[c]) && (L[b] < L[c] + L[a]) &&
            (L[c] < L[a] + L[b])) {
          t += 1;
        }
      }
    }
  }
  cout << t << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> L(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &L[i]);
  }
  solve(N, std::move(L));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        while (i + 1 < n && a[i] == a[i + 1])
        {
            i++;
        }
        if (i + 1 < n && a[i] < a[i + 1])
        {
            while (i + 1 < n && a[i] <= a[i + 1])
            {
                i++;
            }
        }
        else if (i + 1 < n && a[i] > a[i + 1])
        {
            while (i + 1 < n && a[i] >= a[i + 1])
            {
                i++;
            }
        }
        ans++;
    }
    cout << ans << endl;
}

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

int main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  rep(i,N){
    cin >> a.at(i);
  }
  long long takasa = a.at(0);
  long long ans  = 0;
  rep(i,N-1){
    int miru = i + 1;
    if(a.at(miru)<takasa){
      ans += takasa - a.at(miru);  
    }
    else{
      takasa = a.at(miru);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4836
#include<bits/stdc++.h>
#define ffr(i,a,b) for(i=a;i<b;i++)
#define ffrr(i,a,b) for(i=a;i<=b;i++)
#define ll long long int
#define pf printf
#define mp make_pair
#define mm(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define MMAX 200005

using namespace std;

int minn(int a, int b)
{
    if(a<b) return a; return b;
}

int main(){
    ll n, i, j, sum=0, ans=0, a, b, c, MOD=200003, sz, num, cur;
    string s;
    map< pair<ll,ll>, ll > mpp; mpp.clear();
    cin >> n;
    ffr(j,0,n){
        cin >> s;
        i=0; sz=s.size(); num=0;

        while(i<sz && s[i]!='.'){
            cur = s[i]-'0';
            num*=10; num+=cur;
            i++;
        }
        i++;
        a=b=c=0;
        while(i<sz){
            cur = s[i]-'0';
            num*=10; num+=cur;
            i++;
            c++;
        }
        while(1){
            if(num&1) break;
            else{
                num>>=1;
                a++;
            }
        }
        while(1){
            if(num%5>0) break;
            else{
                num/=5;
                b++;
            }
        }
        mpp[mp(a-c,b-c)]++;
    }
    for(auto i:mpp){
        //if(i.first.first<0) continue;
        for(auto j:mpp){
            //if(j.first.first>0) continue;
            if(i==j) continue;
            if(i.first.first+j.first.first>=0 && i.first.second+j.first.second>=0) ans+=(i.second*j.second);
        }
        if(i.first.first>=0 && i.first.second>=0)
        {
            cur = i.second;
            ans+= (cur*cur-cur);
        }
    }

    cout << ans/2 << endl;
}


Measured memory_bytes: 3392
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
int p[105];
int main() {
  int x, n;
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int ans, mn = 1e9;
  for (int i = -105; i <= 105; i++) {
    bool ok = 1;
    for (int j = 0; j < n; j++) {
      if (p[j] == i)
        ok = 0;
    }
    if (ok)
      if (abs(i - x) < mn)
        mn = abs(i - x), ans = i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
AB=[0]*N
BC=[0]*N

i=0
j=0
while j<N:
  while i<N and A[i]<B[j]:
    i+=1
  AB[j]=i
  j+=1
  
ABs=[0]*(N+1)
for i in range(1, N+1):
  ABs[i]=ABs[i-1]+AB[i-1]
  
i=0
j=0
out=0
while j<N:
  while i<N and B[i]<C[j]:
    i+=1
  BC[j]=ABs[i]
  j+=1
  
print(sum(BC))

Measured memory_bytes: 25076
package main

import (
	"fmt"
	"sort"
)

func main() {
	a := make([]int, 3)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	fmt.Println(abs(a[0]-a[1]) + abs(a[1]-a[2]))
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

Measured memory_bytes: 512
def helper(h, n):
    res = [0]*n
    res[0] = 0
    res[1] = abs(h[1]-h[0])
    for i in range(2, n):
        res[i] = min(res[i-1]+abs(h[i]-h[i-1]), res[i-2]+abs(h[i]-h[i-2]))
    return res[-1]

def main():
    n = int(input())
    h = list(map(int, input().split(" ")))
    print(helper(h, n))

if __name__ == "__main__":
    main()

Measured memory_bytes: 13928
A, B = map(int,input().split())

ord = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]
if ord.index(A) > ord.index(B):
    print('Alice')
elif ord.index(A) < ord.index(B):
    print('Bob')
else:
    print('Draw')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<long>a(n);
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  int ans = 1;
  int tmp = 0;
  int tmpi = 0;
  int chk = -1;//0 増加 1 減少

  for(i=1;i<n;i++){
    if(a[tmpi]!=a[i]){
      if(a[tmpi]>a[i])tmp = 0;
      else tmp = 1;
      if(chk != tmp && chk!=-1){
        ans++;
        chk = -1;
      }else if(chk == -1){
        chk = tmp;
      }
      tmpi = i;
    }
  }

  cout << max(1,ans) << endl;
}


Measured memory_bytes: 1024
//package codeforces;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeMap;
import java.util.TreeSet;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Stack;
import java.util.Set;

public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;
	static long count = 0;

	public static void main(String[] args) {
		long h=scn.nextLong();
		if(h==1)
		{
			System.out.println("1");
		}
		else
		{
			System.out.println(hel(h));
		}
		
	}
	public static long hel(long d)
	{	if(d<1)
		return 0;
		if(d==1)
			return 1;
		else
		{
			return 1+2*hel(Math.floorDiv(d, 2));
		}
	}
}


Measured memory_bytes: 22996
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort()

counter = 0
array1 = []

for i in range(N):
  counter += ab[i][1]
  if K <= counter:
    ans = ab[i][0]
    break

print(ans)

Measured memory_bytes: 27872
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;

int main() {
    srand(time(0));
    
    ios_base :: sync_with_stdio(false);
    int n, m; cin >> n >> m;
    
    vector<int> a(m, 0), b(m, 0), c(m, 0);
    vector<int> v(n, inf);
    vector<pair<int, int>> edges;

    for(int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        v[a[i]] = min(v[a[i]], c[i] + 1);
        v[b[i]] = min(v[b[i]], c[i] + 2);
    }
    
    int best = inf;

    for(int i = 0; i < 3 * n; ++i) {
        best = min(best + 2, v[i % n]);
        v[i % n] = min(best, v[i % n]);
    }

    for(int i = 0; i < n; ++i) {
        a.push_back(i);
        b.push_back((i + 1) % n);
        c.push_back(v[i]);
    }

    for(int i = 0; i < n + m; ++i) {
        edges.push_back({c[i], i});
    }

    sort(edges.begin(), edges.end());
    long long ans = 0;

    vector<int> dad(n, 0), sz(n, 0);
    for(int i = 0; i < n; ++i)
        dad[i] = i;

    auto f = [&] (int x) {
        int root = x;
        int steps = 0;
        while(root != dad[root]) {
            root = dad[root];
            ++steps;
        }
        return root;
    };

    auto unite = [&] (int a, int b) {
        if(sz[a] < sz[b])
            dad[a] = b;
        else 
            dad[b] = a;
        if(sz[a] == sz[b])
            sz[a]++;
    };

    for(auto edge : edges) {
        int x = a[edge.second];
        int y = b[edge.second];
        if(f(x) != f(y)) {
            unite(f(x), f(y));
            ans += edge.first;
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 11900
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
#define int long long
#define itn int
using namespace std;
#define INF (1<<29)
#define f(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
ll GCD(ll a, ll b) {
	if (b == 0)return a;
	return GCD(b, a%b);
}
ll LCM(ll a, ll b) {
	return a / GCD(a, b)*b;
}
ll mypow(ll a, ll b, ll c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	else return mypow(a, b / 2, c)*mypow(a, b / 2, c) % c;
}
signed main() {
	int a, b, x[100001], y[100000];
	cin >> a >> b;
	int i = a+1;
	f (i, a) {
		cin >> x[i];
	}
	x[a] = b;
	sort(x, x + a+1);
	for (int i = 1; i <= a; i++) {
		y[i - 1] = x[i] - x[i - 1];
	}
	while (1) {
		int ii = i;
		i = 0;
		for (int j = 0; j*2 < ii; j++) {
			if (j * 2 + 1 == ii) {
				x[j] = GCD(y[j * 2 - 1], y[j * 2]);
			}
			else x[j] = GCD(y[j * 2], y[j * 2 + 1]);
			y[j] = x[j];
			i++;
		}
		if (i == 1) break;
	}
	cout << y[0] << endl;
	return 0;
}


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

string a="apple";
string p="peach";

int num[4];
int main(){
	string in,out;
	getline(cin,in);
	out=in;
	int start=-1;
	while((start=in.find(a,start+1))!=string::npos)
		rep(i,5) out[start+i]=p[i];
	start=-1;
	while((start=in.find(p,start+1))!=string::npos)
		rep(i,5) out[start+i]=a[i];
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 1188
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	static String Sa, Sb, Sc;
	static StringBuilder a, b, c;
	static Map<Character, StringBuilder> map;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Sa = br.readLine();
		Sb = br.readLine();
		Sc = br.readLine();
		a = new StringBuilder(Sa);
		b = new StringBuilder(Sb);
		c = new StringBuilder(Sc);
		map = new HashMap<Character, StringBuilder>();
		map.put('a', a);
		map.put('b', b);
		map.put('c', c);
		char turn, next = 'a';
		while (true) {
			turn = next;
			if (map.get(turn).length() == 0) {
				System.out.println(Character.toUpperCase(turn));
				return;
			}
			next = map.get(turn).charAt(0);
			map.put(turn, map.get(turn).deleteCharAt(0));
		}
	}
}


Measured memory_bytes: 8400
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

const int MAX = 100;
long long D[MAX][MAX];
long long INF = (1LL << 32);

int main() {

	int v, e;
	scanf("%d %d", &v, &e);
	for (int i = 0; i < v; ++i) {
		for (int j = 0; j < v; ++j) {
			if (i == j) {
				D[i][j] = 0;
			} else {
				D[i][j] = INF;
			}
		}
	}
	for (int i = 0; i < e; ++i) {
		int s, t, d;
		scanf("%d %d %d", &s, &t, &d);
		D[s][t] = d;
	}

	for (int k = 0; k < v; ++k) {
		for (int i = 0; i < v; ++i) {
			if (D[i][k] == INF)
				continue;
			for (int j = 0; j < v; ++j) {
				if (D[k][j] == INF)
					continue;
				D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
			}
		}
	}

	bool negative = false;
	for (int i = 0; i < v; ++i) {
		if (D[i][i] < 0) {
			negative = true;
		}
	}

	if (negative) {
		cout << "NEGATIVE CYCLE" << endl;
	} else {
		for (int i = 0; i < v; ++i) {
			for (int j = 0; j < v; ++j) {
				if (j != 0) {
					cout << " ";
				}
				if (D[i][j] != INF) {
					cout << D[i][j];
				} else {
					cout << "INF";
				}
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3292
import math
N=int(input())

MOD = (10 ** 9) + 7

def factorization(n):
    x = 2
    pw = 0
    factlist = []
    while(n != 1):
        if(n%x == 0):
            n = n // x
            pw += 1
        elif(pw > 0):
            factlist.append([x,pw])
            pw = 0
            x += 1
        else:
            x += 1
    factlist.append([x,pw])
    return factlist


list = factorization(math.factorial(N))
ans = 1
for i in range(len(list)):
    ans = ((ans % MOD) * ( (list[i][1] + 1) % MOD)) % MOD
print(ans)

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

int main(){
  using state= pair<int64_t, int>;
  int N1,N2,N3,K;
  cin >> N1 >> N2 >> N3 >> K;

  vector<int64_t> cake1(N1);
  vector<int64_t> cake2(N2);
  vector<int64_t> cake3(N3);

  for(int i=0; i<N1; i++){
    cin >> cake1.at(i);
  }
  for(int i=0; i<N2; i++){
    cin >> cake2.at(i);
  }
  for(int i=0; i<N3; i++){
    cin >> cake3.at(i);
  }
  
  vector<int64_t> cake12;
  for(auto c1:cake1){
    for(auto c2:cake2){
      cake12.emplace_back(c1+ c2);
    }
  }

  sort(cake12.begin(), cake12.end(), greater<int64_t>());
  sort(cake3.begin(), cake3.end(), greater<int64_t>());

  priority_queue<state> outputs;
  vector<int> id12_push(N3, -1);
  vector<int> id12_output(N3, -1);
  outputs.push(make_pair(cake12.at(0)+ cake3.at(0), 0));
  id12_push.at(0)= 0;

  int cnt= 0;
  int64_t val; int id3_this;
  while(cnt < K){
    state output= outputs.top();
    outputs.pop();

    tie(val, id3_this)= output;
    cout << val << endl;

    id12_output.at(id3_this)++;
    int id12_output_this= id12_output.at(id3_this);

    if(id3_this+ 1 < N3){
      int id3_ngh= id3_this+ 1;
      int id12_output_ngh = id12_output.at(id3_ngh);

      if(id12_output_ngh==id12_output_this- 1){
        id12_push.at(id3_ngh)++;
        int id12_push_ngh = id12_push.at(id3_ngh);

        outputs.push(make_pair(cake12.at(id12_push_ngh)+ cake3.at(id3_ngh), id3_ngh));
      }
    }
    if(id12_output_this+ 1 < N1*N2){
      int id3_ngh= id3_this- 1;
      int id12_output_ngh= (id3_this > 0) ? id12_output.at(id3_ngh)
                                          : -1;

      if(id3_this==0 || id12_output_ngh > id12_output_this){
        id12_push.at(id3_this)++;
        int id12_push_this= id12_push.at(id3_this);

        outputs.push(make_pair(cake12.at(id12_push_this)+ cake3.at(id3_this), id3_this));
      }
    }

    cnt++;
  }
}

Measured memory_bytes: 10540
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;


int n, z, w;
int as[2010];

int memo[2][2010];
int go(int turn, int pos) {
  int& res = memo[turn][pos];
  if(res < 0) {
    if(turn == 0) {
      int prev = pos == 0 ? w : as[pos-1];
      res = abs(prev - as[n-1]);
      for(int i = pos+1; i < n; ++i) {
        res = max(res, go(turn^1, i));
      }
    } else {
      int prev = pos == 0 ? z : as[pos-1];
      res = abs(prev - as[n-1]);
      for(int i = pos+1; i < n; ++i) {
        res = min(res, go(turn^1, i));
      }
    }
    // cerr << "go(" << turn << ", " << pos << ")" << endl;
  }
  return res;
}

int main(void) {
  scanf("%d%d%d", &n, &z, &w);
  REP(i, n) {
    scanf("%d", &as[i]);
  }
  memset(memo, -1, sizeof memo);
  int res = go(0, 0);
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong();
        long b = in.nextLong();
        long n = in.nextLong();

        long x = Math.min(b - 1, n);
        long l = (a * x) / b;
        long r = a * (x / b);
        System.out.println(l - r);
    }
}

Measured memory_bytes: 35724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x[] = {0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51},n;
    cin>>n;
    cout<<x[n]<<endl;
    return 0;
}


Measured memory_bytes: 256
/*根付き２分木 T の各節点uについての情報を出力するプログラム*/
#include<stdio.h>

/*マクロ*/
#define NIL -1
#define V 10000

/*グローバル変数*/
int n = 0;

/*構造体（Tree）*/
typedef struct Node{
  int parent;
  int left;
  int right;
  int sibling;
  int height;
  int depth;
  
}node;

 node T[V];

/*プロトタイプ宣言*/
void setHeight(int );
void treePrint(int );



/*main*/
int main(){
  int i, j;//counter
  int id=0, l_child=0, r_child=0, flag=0, u =0;

  //節点を決める
  scanf("%d",&n);

  /*Treeの初期設定*/
  for(i = 0; i < n; i++) {
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
    T[i].sibling = NIL;
  }

  //節点の数だけキーボード入力
 for(i = 0; i < n; i++) {

   scanf("%d %d %d",&id,&l_child,&r_child);

   //数が変更されたところに子供を作り、それを親とする。
   if( l_child!= NIL && r_child ==NIL){
     T[id].left = l_child;
     T[l_child].parent = id;
   }

   if(r_child != NIL && l_child == NIL){
    T[id].right = r_child; 
    T[r_child].parent = id;
   }

   if(l_child != NIL && r_child != NIL){
     T[id].left = l_child;//左子供作成
     T[l_child].parent = id;//左子供→親とする
     T[id].right = r_child; //右子供作成
     T[r_child].parent = id;//右子供→親とする
     T[l_child].sibling = r_child;//右と左は兄弟
     T[r_child].sibling = l_child;//左と右は兄弟(互いに認識させる)
   }
 }
 //ここまで


 //depthを作る
 for(i = 0 ;i < n ;i++) {
    u = i;

  while(1)
    {
    if(T[u].parent == NIL)  {
      break;
    }
    
    flag++;
    u = T[u].parent;
    }

    T[i].depth = flag;
    flag = 0;
  }
 //ここまで

  for(i = 0 ;i < n ;i++) {

    treePrint(i);
  }

  return 0;

}
 
/*節点の高さを求める関数*/
void setHeight(int n) {
  int i,j;//counter
  int flag2;//根の高さを格納する変数

  for(i = 0; i < n; i++) {
   
    if(T[i].right == NIL && T[i].left == NIL){
      T[i].height == 0;

      for(j = i, flag2 = 1; j != NIL; flag2++) {

	j = T[j].parent;

	if(T[j].height < flag2) {
	  T[j].height = flag2;
	}
	
      }
    }
  }
 
}



/*結果を出力する関数*/
void treePrint(int i){
  
   printf("node %d: parent = %d, sibling = %d, ",i,T[i].parent,T[i].sibling);

   printf("degree = ");

   if(T[i].right == NIL && T[i].left == NIL) {
     printf("0, ");
   }

   else if(T[i].right == NIL || T[i].left == NIL) {
     printf("1, ");
   }

   else {
     printf("2, ");
   }

   setHeight(n);

   printf("depth = %d, height = %d,",T[i].depth,T[i].height);

   if(T[i].parent == NIL) {
     printf(" root\n");
   }

   else if(T[i].left == NIL && T[i].right == NIL) {
     printf(" leaf\n");
   }

   else {
     printf(" internal node\n");
   }
   
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

int gcd(int m, int n) {
    return n == 0 ? m : gcd(n, m % n);
}
int lcm(int m, int n) {
    return (m / gcd(m, n)) * n;
}

signed main() {
    cin >> K;
    REPS(a, K)
    REPS(b, K)
    REPS(c, K) {
        ans += gcd(a, gcd(b, c));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <vector>

void swap(int* a, int* b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

int do_partition(std::vector<int>& data, int begin_index, int end_index)
{
    int pivot = data[end_index-1];
    int left_last_index = begin_index;
    for(int i = begin_index; i < end_index - 1; i++) {
        if(data[i] <= pivot) {
            swap(&data[i], &data[left_last_index]);
            left_last_index++;
        }
    }
    swap(&data[end_index-1], &data[left_last_index]);
    return left_last_index;
}

int main()
{
    int input_size;
    std::cin >> input_size;
    std::vector<int> data(input_size);
    for(int i = 0; i < data.size(); i++) {
        std::cin >> data[i];
    }

    int pivot_index = do_partition(data, 0, data.size());

    if(pivot_index == 0) {
        printf("[%d]", data[0]);
    } else {
        printf("%d", data[0]);
    }
    for(int i = 1; i < data.size(); i++) {
        if(pivot_index == i) {
            printf(" [%d]", data[i]);
        } else {
            printf(" %d", data[i]);
        }
    }
    putchar('\n');
}

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

using namespace std;

vector<pair<char, int> > A(100009);
vector<pair<char, int> > B(100009);
int n;

void merge(int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    vector<pair<char, int> > L(n1+1);
    vector<pair<char, int> > R(n2+1);
    for(int i = 0; i < n1; i++){
        L[i] = B[left+i];
    }
    for(int i = 0; i < n2; i++){
        R[i] = B[mid+i];
    }
    pair<char, int> inf; inf.first = 'U'; inf.second = 1000000009;
    L[n1] = inf;
    R[n2] = inf;
    int i = 0;
    int j = 0;
    for(int k = left; k < right; k++){
        if(L[i].second <= R[j].second){
            B[k] = L[i];
            i++;
        }else{
            B[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int left, int right){
    if(left+1 < right){
        int mid = (left + right) / 2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
}

int partition(int p, int r){
    pair<char, int> x = A[r];
    int i = p - 1;
    pair<char, int> temp;
    for(int j = p; j < r; j++){
        if(A[j].second <= x.second){
            i++;
            temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
    }
    A[r] = A[i+1];
    A[i+1] = x;
    return i+1;
}

void quickSort(int p, int r){
    if(p < r){
        int q = partition(p, r);
        quickSort(p, q - 1);
        quickSort(q + 1, r);
    }
}

bool isStable(){
    for(int i = 0; i < n; i++){
        if(A[i].first != B[i].first || A[i].second != B[i].second) return false;
    }
    return true;
}

int main(void){
    cin >> n;
    pair<char, int> temp;
    for(int i = 0; i < n; i++){
        cin >> temp.first >> temp.second;
        B[i] = temp;
        A[i] = temp;
    }
    quickSort(0, n-1);
    mergeSort(0, n);
    if(isStable()){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    for(int i = 0; i < n; i++){
        cout << A[i].first << " " << A[i].second << endl;
    }
    return 0;
}


Measured memory_bytes: 5120
#include<iostream>
#include<algorithm>
#include<cstdio>
#include <vector>
#include <map>

using namespace std;

const int maxn = 1E5 + 5;
long long A[maxn], sum, tmp[maxn], ans[maxn];
int n;

int main( )
{
	cin >> n;
	long long t;
	for( int i = 1; i <= n; ++ i )
	{
		cin >> A[i];
	}
	A[0] = A[n];
	for( int i = 1; i <= n; ++ i )
	{
		if( i == 1 )
			tmp[i] = ( A[i] - A[i - 1] );
		else
			tmp[i] = A[i] - tmp[i - 1];
	}
	ans[n] = tmp[n - 1];
	for( int i = n - 1; i >= 1; -- i )
	{
		ans[i] = 2ll * A[i] - ans[i + 1];
	}
	for( int i = 1; i <= n; ++ i )
		cout << ans[i] << " ";
	cout << endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin>>N;
	if(N<=104){
		cout<<0<<endl;
	}
	else if(N<=134){
		cout<<1<<endl;
	}
	else if(N<=164){
		cout<<2<<endl;
	}
	else if(N<=188){
		cout<<3<<endl;
	}
	else if(N<=194){
		cout<<4<<endl;
	}
	else {
		cout<<5<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <string.h>

using namespace std;

int n,k,r,s,p;
string t;
long long ttl;

int main(){
    cin >> n >> k >> r >> s >> p;
    cin >> t;
    for(int i = 0; i < k; i++){
        if(t[i] == 'r') ttl += p;
        if(t[i] == 's') ttl += r;
        if(t[i] == 'p') ttl += s;
    }
    for(int i = 0; i < k; i++){
        for(int j = 1; (i+k*j) < n; j++){
            if(t[i+j*k] != t[i+(j-1)*k]){
                if(t[i+j*k] == 'r') ttl += p;
                if(t[i+j*k] == 's') ttl += r;
                if(t[i+j*k] == 'p') ttl += s;
            }else{
                t[i+j*k] = 'n';
            }
        }
    }

    cout << ttl << endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define all(c) begin(c),end(c)
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
using ll = long long;
using vi = vector<int>; using vs = vector<string>;
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

int W, H;
string ans;
int m;
vector<string> C;
vector<vector<bool>> B;
vector<vs> dp;

//void dfs(int y, int x, int depth, string s)
//{
//	if (('A' <= C[y][x] && C[y][x] <= 'Z'))
//	{
//		if (m < depth)
//		{
//			m = depth;
//			ans = s;
//		}
//		else if (m == depth)
//		{
//			chmax(ans, s);
//		}
//		return;
//	}
//	B[y][x] = true;
//	if(y < H - 1)dfs(y + 1, x, depth + 1, s + C[y][x]);
//	if(x < W - 1)dfs(y, x + 1, depth + 1, s + C[y][x]);
//}
void solve()
{
	while (true)
	{
		cin >> W >> H;
		if (W == 0 && H == 0)break;
		ans = "";
		m = 0;
		C = vs(H);
		dp = vector<vs>(H, vs(W, ""));
		for (int i = 0; i < H; i++)
		{
			cin >> C[i];
		}
		string ans = "";
		for (int y = 0; y < H; y++)
		{
			for (int x = 0; x < W; x++)
			{
				if ('A' <= C[y][x] && C[y][x] <= 'Z')continue;

				dp[y][x] = C[y][x];
				if (0 <= y - 1 && dp[y - 1][x] != "0")
				{
					dp[y][x] = dp[y - 1][x] + C[y][x];
				}
				if (0 <= x - 1 && dp[y][x - 1] != "0")
				{
					if (dp[y][x].size() < dp[y][x - 1].size() + 1)
					{
						dp[y][x] = dp[y][x - 1] + C[y][x];
					}
					else if (dp[y][x].size() == dp[y][x - 1].size() + 1)
					{
						chmax(dp[y][x], dp[y][x - 1] + C[y][x]);
					}
				}

				if (ans.size() < dp[y][x].size())
				{
					ans = dp[y][x];
				}
				else if (ans.size() == dp[y][x].size())
				{
					chmax(ans, dp[y][x]);
				}
			}
		}
		cout << ans << endl;


	}
}

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


Measured memory_bytes: 3312
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
#include<array>
#include<string>
#include<numeric>
#include<set>
#include<cstdio>
#include<cmath>
#include<unordered_map>
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
    ld pi = acos(-1);
    ld a, b, h, m;
    cin>>a>>b>>h>>m;
    ld angle;
    angle = pi*2*(ld(h/12.0)+(ld)((m/60.0)/12.0)-(ld)(m/60.0));
    ld result = (ld)(a*a) + (ld)(b*b) - (ld)(2.0*a*b*cosl(angle));
    result = sqrt(result);
    cout<<fixed;
    cout<<setprecision(20)<<result<<"\n";
    return 0;
}


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

#define f(i,a,b) for (int i = a; i < b; i++)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n; cin >> n;
	char board[3*n][3*n];
	f(i,0,n) f(j,0,n) cin>>board[i][j];
	f(i,0,3*n) f(j,0,3*n)
		board[i][j] = board[i%n][j%n];
	int dp[3*n][3*n];
	f(i,0,3*n) f(j,0,3*n) {
		int k = 0;
		while (i+k<3*n && j+k<3*n && board[i+k][j] == board[i][j+k])
			k++;
		dp[i][j] = k;
	}
	int cnt = 0;
	f(i,0,n) f(j,0,n) {
		int ni = i+n, nj = j+n;	
		bool found = 1;
		f(k,0,n) if (dp[ni+k][nj+k]<n-k) {
			found = 0;
			break;
		}
		cnt += found; 
	}
	cout << cnt << endl;

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 4224
#include <iostream>
#include <vector>
using namespace std;
int main(){
    string s;
    cin>>s;
    char lastword=s[0];
    int num=0;
    for(int i=0;i<s.length();i++){
        if(lastword!=s[i]){
            num++;
        }
        lastword=s[i];
    }
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll int
#define rep(i,a,N) for(int (i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for(int (i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define pb(b) push_back(b) 
#define all(a) a.begin(),a.end()
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define llpvec vector<pair<ll,ll>>
#define size_(a,b) (a,vector<ll>(b))
#define S 21
////////////////////////////////////////////////////////////
ll n,x,y;
llvec g; 
llpvec pairs;
vector<ll> cnt;
map<pair<ll,ll>,ll> color;
ll mx=0;
void bfs(ll a,ll b,ll c){
 ll ed=g[a].size(),d=0;
 color[{b,a}]=c;
 rep(i,0,ed){
  if(i+1==c)++d;
  bfs(g[a][i],a,i+d+1);
 }
}

int main(){
 cin>>n;
 g.resize(n+1);
 cnt.assign(n+1,0);
 rep(i,0,n-1){
  cin>>x>>y;
  g[x].pb(y);
  pairs.pb(pair(x,y));
  ++cnt[x];++cnt[y];
  mx=max(cnt[x],mx);
 }
 cout<<mx<<endl;
 bfs(1,0,0);
 rep(i,0,n-1){
  pair<ll,ll>p=pairs[i];
  cout<<color[p]<<endl;
 }
return 0;}

Measured memory_bytes: 15148
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
int arr[100005];
int find(int index){
	while(1){
		if(arr[index]==-1)
			break;
		else
			index=arr[index];
	}
	return index;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0); 
	int n,m,a,b;
	cin >> n >> m;
	for(int i=0;i<=n;i++){
		arr[i]=-1;
	}
	while(m--){
		cin >> a >> b;
		int tmp1=find(a);
		int tmp2=find(b);
		if(tmp1!=tmp2){
			arr[tmp2]=tmp1;
		}
	}
	
	int q;
	cin >> q;
	while(q--){
		cin >> a >> b;
		if(find(a)==find(b)){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
 	}
	return 0;
}




Measured memory_bytes: 3516
// C++11
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iostream>
#include <numeric>
#include <random>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>

using namespace std;

#define LOCAL 1

#if LOCAL
#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl
#else
#define pv(val)
#define pvn(name, val)
#define pl
#endif

template <class T>
ostream& operator<<(ostream& os, vector<T> const& vec) {
  if (vec.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
    os << vec.back() << '}';
  }
  return os;
}

template <class T, size_t S>
ostream& operator<<(ostream& os, array<T, S> const& arr) {
  if (arr.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
    os << arr.back() << '}';
  }
  return os;
}

int main(void)
{
  string s;
  cin >> s;
  cout << 700 + 100 * count(s.begin(), s.end(), 'o') << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n;   cin >> n;
    vector<ll> dp(n+1, 0);
    dp[0] = 1;
    rep(i, n){
        for(int k=3; i+k<=n; k++){
            dp[i+k] += dp[i];
            dp[i+k] %= MOD;
        }
        //cout << dp[i] << ' ';
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3500
input()
nlist=map(int, raw_input().split())
input()
qlist=map(int, raw_input().split())

n = len(nlist)

dic = {}

def func(idx, m):
    
    try:
        return dic[m][idx]
    except:
        pass

    if m==0:
        tmp=dic.get(m,{})
        tmp.update({idx: True})
        dic.update({m:tmp})
    elif idx > n-1:
        tmp=dic.get(m,{})
        tmp.update({idx: False})
        dic.update({m:tmp})
        
    elif func(idx+1, m):
        tmp=dic.get(m,{})
        tmp.update({idx: True})
        dic.update({m:tmp})
    elif func(idx+1, m-nlist[idx]):
        tmp=dic.get(m,{})
        tmp.update({idx: True})
        dic.update({m:tmp})
    else:
        tmp=dic.get(m,{})
        tmp.update({idx: False})
        dic.update({m:tmp})
        
    return dic[m][idx]


for q in qlist:
    # print dic
    print "yes" if func(0, q) else "no"

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int checkRecursive(vector<int> &counter, int size, int start, int end, int k) {
    assert(counter.size() >= 2);

    if (start + 1 == end) return min(k, max(counter[start], counter[end]));

    if (counter[start] < counter[end]) {
        int now_k = size - counter[start];
        counter[start + 1] += counter[start];
        counter[start] = 0;
        return checkRecursive(counter, size, start + 1, end, min(k, now_k));
    } else {
        int now_k = size - counter[end];
        counter[end - 1] += counter[end];
        counter[end] = 0;
        return checkRecursive(counter, size, start, end - 1, min(k, now_k));
    }

}

int main() {

//    ifstream myfile("C:\\Users\\riku\\Downloads\\16.txt");
//    ofstream outfile("log.txt");


    string s;

    cin >> s;
//    myfile >> s;

    vector<int> counter;
    {
        char before = s[0];
        int count = 0;
        for (int i = 0; i < s.size(); i++) {
            if (before == s[i]) {
                count++;
            } else {
                before = s[i];
                counter.push_back(count);
                count = 1;
            }
        }
        counter.push_back(count);
    }
    if (counter.size() == 1) {
        cout << counter[0] << endl;
        return 0;
    }

//    for (int i : counter) {
//        outfile << i << endl;
//    }
//    outfile.flush();
//    outfile.close();
    int ans = checkRecursive(counter, s.size(), 0, counter.size() - 1, INF);

    cout << ans << endl;

}

Measured memory_bytes: 3068
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define black_tree tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pair_black_tree tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update>
#define gp __gnu_pbds
#define INF 1000000000
#define MOD 1000000007
#define MAX 1000001
#define endl '\n'
#define ll long long
#define ld long double
#define lli long long int
#define ull unsigned long long
#define ulli unsigned long long int
#define pb push_back
#define pf push_front
#define ook order_of_key
#define fbo find_by_order
#define np next_permutation
#define mp make_pair
#define eb emplace_back
#define mae max_element
#define mie min_element
#define lb lower_bound 
#define ub upper_bound
#define bs binary_search
#define ff first
#define ss second
using namespace std;
using namespace gp;
ll n,dp[2001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    dp[0]=1;
    for(int i=3;i<=n;i++){
    	for(int j=3;j<=i;j++){
    		dp[i]=(dp[i]+dp[i-j])%MOD;
		}
	}
	cout<<dp[n];
}

Measured memory_bytes: 3604
#include<stdio.h>
int main(void)
{
	int i,n,a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	n=0;
	for(i=a;i<=b;i++){
		if(c%i==0){
			n=n+1;
		}
	}
	printf("%d\n",n);
	
	return 0;
}



Measured memory_bytes: 2736
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int n;
    cin >> n;
    cout << (n + 1 >> 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

ll n;
ll a[420];
ll dp[420][420];
ll s[420];

ll f(ll x, ll y){
	ll &r=dp[x][y];
	if(r>=0)return r;
	if(y==x+1){
		r=0; return r;
	}
	r=1e18;
	fore(i,x+1,y){
		r=min(r,s[y]-s[x]+f(x,i)+f(i,y));
	}
	return r;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n)cin>>a[i];
	mset(dp,-1);
	fore(i,0,n)s[i+1]=a[i]+s[i];
	cout<<f(0,n);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int d,n;
  cin >> d >> n;
  if(n!=100)r(i,d)n*=100;
  else {
    n++;
    r(i,d)n*=100;
  }
  cout << n<< endl;
  
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        K: i64,
    }

    // 数学的性質として、この数列を素因数分解しても2と5は現れない
    if K % 2 == 0 || K % 5 == 0 {
        println!("-1");
        return;
    }

    // 出現の順番がバラバラなので、「実際にやってみた」としたい
    // しかし、数が10^999999くらいなので実際にやってみることができない (これが気のせい)

    // 表現方法はさておき、O(K)ではあるのでは?
    // 初めからmodで表現すればいけるのでは?

    let mut d = 1;
    let mut val = 7;
    while true {
        if val % K == 0 {
            println!("{}", d);
            return;
        }
        val = (val * 10) % K;
        val = (val + 7) % K;
        d += 1;
    }
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a, b; cin >> a >> b;
    if ((a + b) % 2 == 0) cout << (a + b) / 2 << '\n';
    else cout << "IMPOSSIBLE\n";
}


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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


auto solve() {
    int N, M;
    cin >> N >> M;

    map<int,int> c;
    REP(_i, N) {
        int K;
        cin>>K;
        while(K--) {
            int a;
            cin>>a;
            c[a]++;
        }
    }

    int res = 0;
    for(auto&&e: c) {
        if(e.second == N)
            res++;
    }
    return res;
}


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

//    cout << (solve() ? "First" : "Second") << endl;
//    cout << (solve() ? "YES" : "NO") << endl;
    cout << solve() << endl;
//    solve();

    return 0;
}


Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

void solv() {

	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	ll g = gcd(c, d);
	ll lcd = (c * d) / g;
	ll cc = (b / c) - ((a - 1) / c);
	ll dc = (b / d) - ((a - 1) / d);
	ll lcc = (b / lcd) - ((a - 1) / lcd);
	ll res = (b - (a - 1)) - (cc + dc) + lcc;
	cout << res << endl;
}

int main() {
	//	COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>

#if __cplusplus >= 201103 //C++11~
#include <tuple>

#endif



using namespace std;

typedef pair<int,int> Paint;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
#define MOD 1000000007

#define pb push_back
#define fir first
#define scn second

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout<< (char)数値 //数値にあった文字に置き換えられる
cout<< (double)int型/(2など)//小数になる
YesNo大文字小文字間違えてないか
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
sqrt(数値型)でrootが取れる
vector.unique()は隣接した同じ要素を削除するので先にソートをする
tupleはC++11以降

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  int a,b;cin>>a>>b;
  cout << max(0,a-b*2) << endl;
}




Measured memory_bytes: 768
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = [I() for _ in range(n)]
    b = [a[0]] + [a[i] for i in range(1,n) if a[i] != a[i-1]]
    l = len(b)
    r = [0] * l
    r[0] = 1
    c = collections.defaultdict(int)
    c[b[0]] = 1
    for i in range(1,l):
        t = c[b[i]]
        t += r[i-1]
        t %= mod
        c[b[i]] = t
        r[i] = t

    return r[-1]


print(main())





Measured memory_bytes: 37976
import sys
import numpy as np

N = int(sys.stdin.readline())
a = np.fromstring(sys.stdin.read(), dtype=np.uint32, sep=' ')
maxi = np.argmax(a)
max_value = a[maxi]
a[maxi] = 0
mnext = a.max()

for i in range(N):
    if i == maxi:
        print(mnext)
    else:
        print(max_value)



Measured memory_bytes: 15160