akhauriyash/Code-Regression huggingface dataset:
import queue

N, M = map(int, input().split())

graph = [[] for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    graph[A].append(B)
    graph[B].append(A)

# 各部屋に設定する番号を記録する
v = [-1 for i in range(N)]  # 全頂点を「未訪問」に初期化
v[0] = 0  # スタート地点を0にする
# queueを作成し部屋1（インデックスは0）を入れる
q = queue.Queue()
q.put(0)

while not q.empty():
    # queueの先頭（今いる部屋の番号）を取り出す
    x = q.get()
    # 今いる部屋と繋がっている部屋を順に探索する
    for y in graph[x]:
        # -1 でない場合は探索済みなのでスキップする
        if v[y] != -1:
            continue
        # あとで探索するためにqueueに入れておく
        q.put(y)
        v[y] = x

print("Yes")
for i in range(1, N):
    print(v[i] + 1)


Measured memory_bytes: 34264
#include <iostream>

#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

int N;
vector<vector<int>> win;
struct game {
	int pw, pl;
	int w, l;
	int d;
};
vector<game> games;

//深さ、ノード
pair<int,int> add(int p) {
	if (win[p].size() == 0)return pair<int,int>(0, -1);
	struct TEMP {
		int l, d;
		int g;
	};
	vector<TEMP> V;
	for (int i : win[p]) {
		pair<int, int> t = add(i);
		V.push_back({ i, t.first, t.second });
	}
	sort(V.begin(), V.end(), [](TEMP a, TEMP b) {
		return a.d < b.d;
	});
	int back = -1;
	int ans = 0,counter = V.size();
	for (auto itr = V.begin(); itr != V.end();itr++) {
		games.push_back({ back,itr->g,p,itr->l,0 });
		back = games.size()-1;
		ans = max(ans, itr->d + (counter--));
	}
	return pair<int, int>(ans, back);
}

int main() {
	cin >> N;
	win.resize(N);
	for (int n = 1; n < N; n++) {
		int a;
		cin >> a;
		win[--a].push_back(n);
	}
	int game0 = add(0).second;
	vector<int> deep(N, 0);
	//ノード、深さ
	queue < pair<int, int>> q;
	q.push(pair<int,int>(game0,1));
	while (!q.empty()) {
		int node = q.front().first;
		int d = q.front().second;
		q.pop();
		games[node].d = d;
		if (games[node].pl == -1)deep[games[node].l] = d;
		else q.push(pair<int, int>(games[node].pl, d + 1));
		if (games[node].pw == -1)deep[games[node].w] = d;
		else q.push(pair<int, int>(games[node].pw, d + 1));
	}
	int ans = 0;
	for (int n = 0; n < N; n++)ans = max(ans, deep[n]);
	cout << ans << endl;
	return 0;
}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c)
  {
    cout << "No" << endl;
  }
  else if (a != b && b != c && c != a)
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#define num 8

int a[num][num]={0};



void printboard(){
	int i,j;
	
	for(i=0;i<num;i++){
		for(j=0;j<num;j++){
			if(a[i][j]==1){
			    printf("Q");
			}
			else printf(".");
		}
		printf("\n");
	}

}


int check(int y,int x){
	int i,j;
	
	for(i=0;i<num;i++){
		if(i!=x && a[y][i]==1){
		    return 0;
		}
	}
	for(i=0;i<num;i++){
		if(i!=y && a[i][x]==1){
		    return 0;
		}
	}
	i=y-1; j=x+1;
	while(i>=0 && j<num){
		if(a[i--][j++]==1){
		    return 0;
		}
	}
    i=y-1; j=x-1;
	while(i>=0 && j>=0){
		if(a[i--][j--]==1){
		    return 0;
		}
	}
	i=y+1; j=x-1;
	while(i<num && j>=0){
		if(a[i++][j--]==1){
		    return 0;
		}
	}
	i=y+1; j=x+1;
	while(i<num && j<num){
		if(a[i++][j++]==1){
		    return 0;
		}
	}
	
	return 1;
	
}


int Get_Solution(int d){
	int i;
	
	for(i=0;i<num;i++){
		if(a[d][i]==1){
			if(!Get_Solution(d+1)){
			    return 0;
			}
		}
	}
	

	if(d==num){
		printboard();
		return 1;
	}
else {
		for(i=0;i<num;i++){
			if(a[d][i]==0 && check(d,i)){
				a[d][i]=1;
				if(!Get_Solution(d+1)){
					a[d][i]=0;
				}
			}
		}
	}
	
	
	return 0;

}

int main(){
	int n,i,j,x,y,d=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d %d",&y,&x);
		a[y][x]=1;
	}
	
	i=Get_Solution(d);

	return 0;
}



Measured memory_bytes: 2084
#include<stdio.h>
int main()
{
	int N;
	scanf("%d",&N);
	
	int v[N];
	for(int i=0;i<N;i++) scanf("%d",&v[i]);
	
	//小さい順に並び替え
	int i_min=0, min=0;
	float b[N];
	for(int j=0;j<N;j++){
		min = 1000;//最大値で初期化
		for(int i=0;i<N;i++){
			if(min >= v[i]){
				min=v[i];
				i_min = i;
			}
		}
		v[i_min] = 1000;
		b[j] = min;
	}
	
	float tmp;
	for(int j=0;j<N;j++){
		tmp = (b[j]+b[j+1])/2.0;
		b[j+1] = tmp;
	}
	
	printf("%f\n", b[N-1]);
	
	return 0;
}

Measured memory_bytes: 128
a=int(input(""))
b=int(input(""))
c=int(input(""))
d=int(input(""))
e=int(input(""))
k=int(input(""))
M=max(a,b,c,d,e)
m=min(a,b,c,d,e)
sa=M-m
if sa<=k:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc()) 
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

typedef pair<ll,ll> pll;
const ll LLINF = 1ll << 60;
const int N = 20;
map<pll,ll> dp[N][N];
int n, arr[N];
ll solve(int l,int r,ll xl,ll xr) {
  if (dp[l][r].count(pll(xl, xr)))
    return dp[l][r][pll(xl,xr)];
  if (l + 1 == r)
    return arr[l] * xl + arr[r] * xr;
  ll &ret = dp[l][r][pll(xl, xr)];
  ret = LLINF;
  rep (i, l+1, r-1)
    ret = min(ret, solve(l, i, xl, xl + xr) + solve(i, r, xl + xr, xr) - arr[i] * (xl + xr));
  return ret;
}
int main() {
  read(n);
  rep (i, 1, n) read(arr[i]);
  cout << solve(1, n, 1, 1) << endl;
  return 0;
}


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

int main()
{
    int nums[] = {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};
    int n;
    cin >> n;
    cout << nums[n - 1] << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			long k = scanner.nextLong();
			int[] a = new int[n + 1];
			IntStream.rangeClosed(1, n).forEach(i -> a[i] = scanner.nextInt());
			List<Integer> list = new ArrayList<>();
			// containsを計算用（実行時間オーバー対応）
			Set<Integer> set = new HashSet<>();
			list.add(1);
			set.add(1);
			int index = 1, count = 0;
			while (!set.contains(a[index])) {
				list.add(a[index]);
				set.add(a[index]);
				count++;
				if (k == count) {
					System.out.println(a[index]);
					return;
				}
				index = a[index];
			}
			int start = list.indexOf(a[index]);
			System.out.println(list.get(start + (int) ((k - list.size()) % (list.size() - start))));
		}
	}
}


Measured memory_bytes: 69256
#include<stdio.h>
#define MIN(x,y) ((x<y)?(x):(y))

int main(void){
  unsigned int math,algo,code;
  unsigned int input[6],sum;
  unsigned int i,j,k,min;
  unsigned int contest,mcon,acon,ccon;

  while(1){
    for(i=0;i<6;i++) scanf("%u",&input[i]);
    sum=input[0];
    for(i=1;i<6;i++) sum+=input[i];
    if(sum==0) break;
    
    math=input[0]+input[3];
    algo=input[1]+input[4];
    code=input[2]+input[5];
    
    mcon=math/3;
    acon=algo/3;
    ccon=code/3;
    contest=mcon+acon+ccon;
    math%=3;
    algo%=3;
    code%=3;
    
    min=MIN(MIN(math,algo),code);
    math-=min;
    algo-=min;
    code-=min;
    contest+=min;
    
    if(ccon>=1 && math==2 && algo==2) contest++;
    else if(mcon>=1 && algo==2 && code==2) contest++;
    else if(acon>=1 && code==2 && math==2) contest++;
    
    printf("%u\n",contest);
  }
  return 0;
}

Measured memory_bytes: 412
#include <stdio.h>
#include <memory.h>

#define MIN(x, y) ((x) <= (y) ? (x) : (y))
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
void *partition(int *first, int *last) {
    int pivot = *(last - 1);
    int *p = first - 1;
    for(int *it = first; it != last - 1; ++it) {
        if(*it <= pivot) {
            p++;
            int tmp = *p;
            *p = *it;
            *it = tmp;
        }
    }
    int tmp = *++p;
    *p = pivot;
    *(last - 1) = tmp;
    return p;
}
void quick_sort(void *first, void *last, size_t N) {
    if(last - first <= N) return;
    void *mid = partition(first, last);
    quick_sort(first, mid, N);
    quick_sort(mid, last, N);
}
int mincost_sort(const int *a, const int N, const int minw) {
    int cnt = 0;
    int b[N];
    memcpy(b, a, N * sizeof(int));
    quick_sort(b, b + N, sizeof(int));
    int pos[10001];
    for(int i = 0; i < N; ++i) pos[b[i]] = i;
    int flag[1001] = {};
    for(int i = 0; i < N; ++i) {
        if(flag[i]) continue;
        int cur = i;
        int sum = 0;
        int num = 0;
        int mina = 1 << 29;
        while(!flag[cur]) {
            flag[cur] = 1;
            num++;
            sum += a[cur];
            mina = MIN(mina, a[cur]);
            cur = pos[a[cur]];
        }
        // [ sum + (num-2)*mina + 2(mina+minw) - (num-1)*(mina-minw) ] -> [ sum + mina + (n+1)*minw ]
        cnt += MIN(sum + (num - 2) * mina, sum + mina + (num + 1) * minw);
    }
    return cnt;
}
int main(int argc, char **argv) {
    int n = get_uint();
    int w[n];
    int minw = 1 << 29;
    for(int i = 0; i < n; ++i) {
        w[i] = get_uint();
        minw = MIN(minw, w[i]);
    }
    put_uint(mincost_sort(w, n, minw));
    putchar_unlocked('\n');
    return 0;
}



Measured memory_bytes: 2144
#!/usr/bin/env python
# -*- coding: utf-8 -*-

(A, B, C, X) = [int(input()) for i in range(4)]

r = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if 500 * a + 100 * b + 50 * c == X:
                r += 1

print(r)


Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
int main(){
char s[103];
scanf("%s",s);
int l=strlen(s);
int count=0;
for(int i=0;i<l/2;i++){
    if(s[i]!=s[l-1-i])
    count++;
}
printf("%d",count);
 
}


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

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

const int N = 40;
char s[N];

int main()
{
    int n;
    scanf("%d %s", &n, s);
    map<pll, ll> hsh;
    for (int conf = 0; conf < (1<<n); ++conf) {
        ll r = 0, b = 0;
        for (int i = n-1; i >= 0; --i) if (!(conf&(1<<i))) {
            r *= P;
            r += s[i];
        }
        for (int i = 0; i < n; ++i) if (conf&(1<<i)) {
            b *= P;
            b += s[i];
        }
        ++hsh[pll(r, b)];
    }
    ll ans = 0;
    for (int conf = 0; conf < (1<<n); ++conf) {
        ll r = 0, b = 0;
        for (int i = 2*n-1; i >= n; --i) if (!(conf&(1<<(i-n)))) {
            r *= P;
            r += s[i];
        }
        for (int i = n; i < 2*n; ++i) if (conf&(1<<(i-n))) {
            b *= P;
            b += s[i];
        }
        ans += hsh[pll(b, r)];
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 33024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int n, y;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> y;
    y /= 1000;
    rep(a, 0, 10000) {
      rep(b, 0, 10000) {
        int c = y - 10 * a - 5 * b;
        if (c < 0) continue;
        if (n == a + b + c && y == 10 * a + 5 * b + c) {
          cout << a << " " << b << " " << c << endl;
          return 0;
        }
      }
    } 
    cout << -1 << " " << -1 << " " << -1 << " " << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int tmp, cnt = 0;
ll a,b,c,d,n,m;
string s;

int main()
{
    
    cin >> s;

    if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
    {
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
using namespace std;


const int INF = 1e8;

int n, k, dis[2010][2010];
vector < int > g[2010];

bool used[2010][2010], check;

vector < pair <int, int> > pos_ans;

map < pair <int, int>, bool> mp;

void dfs(int orig, int v, int ct = 0) {

    used[orig][v] = 1;

    if(ct > k) {check = 1; return;}

    if(orig != v) {

        dis[orig][v] = ct;

        if(ct == k && !mp[mper(min(orig, v), max(orig, v))]) {pos_ans.pb(mper(orig, v)); mp[mper(min(orig, v), max(orig, v))] = 1;}


    }




    for(auto to : g[v]) {

        if(!used[orig][to]) {

            dfs(orig, to, ct + 1);

        }

    }

}

int main(){



cin >> n >> k;



for(int i = 1, l, r; i < n; ++i) {

    cin >> l >> r;

    g[l].pb(r);
    g[r].pb(l);

}

for(int i = 1; i <= n; ++i) {
    dfs(i, i);
}


if(!check) {cout << 0;return 0;}


int ans = (int)1e8;

for(auto to : pos_ans) {

    int a = to.fe;
    int b = to.se;
    int ct = 0;



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

        if(i == a || b == i) {continue;}

        if(dis[a][i] == 0) {ct++;}
        else if(dis[b][i] == 0) {ct++;}

    }

    ans = min(ans, ct);

}

cout << ans;

return 0;
}

/*

2000 2


*/


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<pair<int,int>>v(max(n,m));
	vector<bool>a(200001),b(200001);
	for(int i=0;i<m;i++) {
		cin>>v.at(i).first>>v.at(i).second;
		if(v.at(i).second==n){
			b.at(v.at(i).first)=true;
		}
		if(v.at(i).first==1){
			a.at(v.at(i).second)=true;
		}
	}
	for(int i=0;i<200000;i++) {
		if(a.at(i)==b.at(i) && a.at(i)==true){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
void solve()
{
	ll n;
	cin>>n;
	cout<<"ABC"<<n;
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

#define EPS (1e-10)
#define equals( A, B ) (fabs((A) - (B)) < EPS)

class Point {
public:
    double x, y;
    Point( double x = 0, double y = 0 ): x(x), y(y) {}
    
    Point operator + ( Point p ) { return Point( x + p.x, y + p.y ); }
    Point operator - ( Point p ) { return Point( x - p.x, y - p.y ); }
    Point operator * ( double a ) { return Point( a * x, a * y ); }
    Point operator / ( double a ) { return Point( x / a, y / a ); }

    double abs() { return sqrt( norm() ); }
    double norm() { return x * x + y * y; }

    bool operator < ( const Point &p ) const {
	return ( x != p.x ) ? x < p.x : y < p.y;
    }

    bool operator == ( const Point &p ) const {
	return equals( x, p.x ) && equals( y, p.y ); 
    }

    double dot( Point a ) { return x * a.x + y * a.y; }
    double cross( Point a ) { return x * a.y - y * a.x; }
    double distance( Point a ) {
	return (*this - a).abs();
    }
    double arg() {
	return atan2( y, x );
    }
};

typedef Point Vector;

typedef vector<Point> Polygon;

int contains( Polygon poly, Point p ) {
    int n = poly.size();
    int count = 0;
    for ( int i = 0; i < n; i++ ) {
	Vector a = poly[i] - p;
	Vector b = poly[ ( i + 1 ) % n ] - p;

	// ???????????????
	if ( abs( a.cross( b ) ) < EPS && a.dot( b ) < EPS ) {
	    return 1;
	}
	// a.y???b.y??\?????????????????????
	if ( a.y > b.y ) {
	    Vector tmp = a; a = b; b = tmp;
	}
	// ??£?????????????????´????????????????????´???
	if ( a.y < EPS && b.y > EPS && a.cross( b ) > EPS ) {
	    count++;
	}
    }

    return ( count % 2 ) ? 2 : 0;
}

int main()
{
    int n;
    Polygon poly;
    scanf("%d", &n);

    for ( int i = 0; i < n; i++ ) {
	Point p;

	scanf("%lf %lf", &p.x, &p.y);
	poly.push_back( p );
    }
    
    scanf("%d", &n);

    for ( int i = 0; i < n; i++ ) {
	Point p;
	scanf("%lf %lf", &p.x, &p.y);
	printf("%d\n", contains( poly, p ));
    }

    return 0;
}

Measured memory_bytes: 1076
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 1e5 + 5;
typedef long long ll; 
#define int ll
using namespace std;

int n, m, a[N];
ll ans; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

signed main()
{
	n = read <int> (), m = read <int> ();
	for(int i = 1; i <= n; i++) a[i] = read <int> ();
	if(a[1] > m) ans = a[1] - m, a[1] = m; 
	for(int tmp, i = 2; i <= n; i++)
	{
		tmp = a[i] + a[i - 1]; 
		if(tmp > m) ans += tmp - m, a[i] -= (tmp - m); 
	}
	printf("%lld\n", ans); 
	return 0; 
}


Measured memory_bytes: 3844
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Random;

public class Main {

	private static final int COMMAND_TRAINING = 1;
	private static final int COMMAND_QUEST = 2;
	private static final int COMMAND_JOB = 3;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();

		if (X == 7 || X == 5 || X == 3) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static void shuffle(int[] array) {
		if (array.length <= 1) {
			return;
		}

		// Fisher-Yates shuffle
		Random rnd = new Random();
		for (int i = array.length - 1; i > 0; i--) {
			int index = rnd.nextInt(i + 1);
			int tmp = array[index];
			array[index] = array[i];
			array[i] = tmp;
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 22484
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int N, M; cin >> N >> M;
	int L = 1, R = N;

	for (int i = 0; i < M && L <= R; i++) {
		int l, r; cin >> l >> r;
		L = max(L, l);
		R = min(R, r);
	}

	if (L > R) cout << 0 << endl;
	else cout << R - L + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>

using namespace std;


int main(){
	int n; cin >> n;
	int a, b; cin >> a >> b;
	int p[n];
	int i;
	int mx = n / 3;

	for (i = 0; i < n; i++) {
		cin >> p[i];
	}

	sort(p, p + n);

	int sumx = 0;

	for (i = 0; i < n; i++) {
		if (p[i] <= a) { sumx++; }
		else { break; }
	}
	
	int sumy = 0;

	for (i; i < n ; i++) {
		if (p[i] <= b) { sumy++; }
		else { break; }
	}

	int sumz = 0;

	for (i; i < n; i++) {
		sumz++;
	}

	cout << min({ mx,sumx,sumy,sumz }) << endl;

	return 0;
}

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

class Point{
	private :
	int x; //X point of grid
	int y; //Y point of grid
	int path; //number of path
	bool roadWork; //roadWork flag

	public : 
	Point() : x(), y(), path(), roadWork() {}
	// ~Point() = default;
	void setX(int i) { x = i; }
	void setY(int i) { y = i; }
	void setPath(int i) { path = i; }
	void setRoadWork(bool b) { roadWork = b; }
	int getX() { return x; }
	int getY() { return y; }
	int getPath() { return path; }
	int getRoadWork() { return roadWork; }
};

int main(void){
	int a; //number of road from south to north
	int b; //number of road from east to west 

	while(std::cin >> a >> b){ //input number of road
		if(a == 0 && b == 0){ //end input
			break;
		}

		size_t num; //number of dataset
		std::cin >> num; //input number of dataset

		std::vector<Point> pointList; //array of point
		std::vector<Point> rwpList; //array of road work point

		for(size_t i = 0; i < num; ++i){ //input grid of road work point
			int tmp1, tmp2;
			std::cin >> tmp1 >> tmp2;
			Point p;
			p.setX(tmp1);
			p.setY(tmp2);
			rwpList.push_back(p);
		}

		for(size_t i = 0; i < a; ++i){
			for(size_t j = 0; j < b; ++j){
				Point p;
				p.setX(i + 1);
				p.setY(j + 1);

				for(size_t k = 0; k < rwpList.size(); ++k){
					if(p.getX() == rwpList.at(k).getX() && p.getY() == rwpList.at(k).getY()){
						p.setRoadWork(true);
					}
				}

				if(p.getRoadWork() == true){
					p.setPath(0);
				}else{
					if(i == 0 && j == 0){
						p.setPath(1);
					}else if(i == 0 && j != 0){
						p.setPath(pointList.back().getPath()); //add number of path at west point 
					}else if(j == 0 && i != 0){
						p.setPath(pointList.at(pointList.size() - b).getPath()); //add number of path at south point 
					}else{
						p.setPath(pointList.back().getPath() + pointList.at(pointList.size() - b).getPath()); //add number of path at west and south point 
					}
				}
				pointList.push_back(p);
			}
		}

		std::cout << pointList.back().getPath() << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3080
n=int(input())
v=list(map(int,input().split()))
e=[0 for _ in range(1,10**5+2)]
o=[0 for _ in range(1,10**5+2)]
for i in range(0,n,2):
    e[v[i]]+=1
    o[v[i+1]]+=1
ans=0
if len(set(v))==1:
    ans=n//2
else:
    me=max(e)
    mo=max(o)
    mei=e.index(me)
    moi=o.index(mo)
    if mei==moi:
        e[mei]=0
        o[moi]=0
        ans += n-max(me,mo)-max(max(e),max(o))
    else:
        ans=n-max(e)-max(o)
print(ans)

Measured memory_bytes: 17508
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
#define rep3(i,n,m) for(long long i=n;i>=m;i--)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
 ll n;
 cin >> n ;
 vector<ll> A(n) ;
 rep(i,n) cin>> A[i] ;
 sort(A.begin(),A.end()) ;
 ll sum=0 ;
 rep(i,n){
   sum+=A[i] ;
 }
 ll ans=1 ;
  rep(i,n-1){
    
    sum-=A[n-1-i];
    if(A[n-1-i]>2*sum){
      break ;
    }
   ans++ ;
  } 
   
   cout <<ans<<endl;
    return 0;
}

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

int parseInt(char ch){
	switch(ch){
		case 'I':
			return 1;
		case 'V':
			return 5;
		case 'X':
			return 10;
		case 'L':
			return 50;
		case 'C':
			return 100;
		case 'D':
			return 500;
		case 'M':
			return 1000;
	}
}

int main(){
	string str;
	int last, n;
	int ans;
	while(cin >> str){
		ans = last = parseInt(str[0]);
		for (int i = 1; i < str.size(); i++) {
			n = parseInt(str[i]);
			if(n > last){
				ans += (n-last) - last;
			}else{
				ans += n;
			}
			last = n;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
// abc142_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

struct Graph {

    vector<int> visited, candidates, ans;
    vector<vector<int>> edges;
    vector<vector<int>> rev_edges;
    Graph(int n): edges(n), rev_edges(n), visited(n, 0) {}

    void add_edge(int u, int v){
        edges[u].emplace_back(v);
        rev_edges[v].emplace_back(u);
    }

    void dfs(int v, int s){
        if (visited[v]) return;

        visited[v] = 1;

        for (auto t: edges[v]) {
            if (t == s){
                if (ans.empty() || candidates.size() < ans.size()){
                    ans = candidates;
                }
                return;
            }
            candidates.emplace_back(t);
            dfs(t, s);
            candidates.pop_back();
        }
    }

    void dfs_wrap(int s){
        visited.assign(visited.size(), 0);
        candidates = {s};
        dfs(s, s);
    }
};


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;

    Graph g(N);

    REP(i, M){
        int a, b;
        cin >> a >> b; a--; b--;
        g.add_edge(a, b);
    }

    vector<int> cand;
    REP(i, N){
        g.dfs_wrap(i);
    }

    if (g.ans.size() > 1){
        print(g.ans.size());
        for (auto v: g.ans) print(v+1);
    } else {
        print(-1);
    }


    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;

  if(S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3) ){
    cout << "Bad";
  }else{
    cout <<"Good";
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            String strSum = String.valueOf(a+b);
            System.out.println(strSum.length());
        }
    }
}

Measured memory_bytes: 20452
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;

int main(){
    string s, t;
    cin >> s;
    cin >> t;

    vector<set<int>> char_trees(26);
    vector<int> min_indices(26, 0);

    for(int i = 0; i < s.size(); ++i){
        int index = s[i] - 'a';
        char_trees[index].insert(i+1);
        if(min_indices[index] == 0){
            min_indices[index] = i + 1;
        }
    }

    long long num_loop = 0;
    int cur_pos = 0;
    for(int i = 0; i < t.size(); ++i){
        int index = t[i] - 'a';

        if(min_indices[index] == 0){
            cout << -1;
            return 0;
        }

        auto it = char_trees[index].upper_bound(cur_pos);
        if(it != char_trees[index].end()){
            cur_pos = *it;
        }
        else{
            cur_pos = min_indices[index];
            ++num_loop;
        }
    }

    cout << num_loop * s.size() + cur_pos;

}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    ll a[100001];
    int n; cin >> n;
    int mcnt = 0;
    ll absmin = LLONG_MAX;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] < 0) mcnt++;
        absmin = min(absmin, abs(a[i]));
        sum += abs(a[i]);
    }
    
    if (mcnt % 2 == 0) {
        cout << sum << '\n';
    } else {
        cout << sum - absmin * 2 << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  map <int, bool> used;
  map <int, int> seenbad;
  int bad = 0, good = 0;
  for (int i = 0; i < m; i++) {
    int x;
    string a;
    cin >> x >> a;
    if (a == "AC") {
      if (!used[x]) {
        good++;
        bad += seenbad[x];
      }
      used[x] = 1;
    } else {
      seenbad[x]++;
    }
  }
  swap(bad, good);
  cout << bad << " " << good << endl;
  return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <locale>
#include<set>



using namespace std;

#define MAX 200000
int main() {

long long n,m,i,j,k,fow,pt=0,ans=0;
long long syurui=0;
cin>>n;
vector<string> s(n);
vector<long long> march(5,0);

for(i=0;i<n;i++){
    cin>>s[i];
}

    for(i=0;i<n;i++){
        switch(s[i][0])
        {
            case 'M':
            march[0]++;
            break;
            case 'A':
                march[1]++;
                break;
            case 'R':
                march[2]++;
                break;
            case 'C':
                march[3]++;
                break;
            case 'H':
                march[4]++;
                break;
            default:
                break;

        }
    }
for(i=0;i<5;i++){
    if(march[i]>0){
        syurui++;
        ans*=march[i];
    }
}
if(syurui<3){
    cout << 0 << endl;
    return 0;
}

for(i=0;i<3;i++){
    for(j=i+1;j<4;j++){
        for(k=j+1;k<5;k++){
            ans+=march[i]*march[k]*march[j];
        }
    }
}



    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int d[] = { 1,2,3 };
	for (int i = 0; i < 3; i++) {
		if (d[i] != a && d[i] != b) {
			cout << d[i];
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
template<typename T> T gcd(T a,T b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
set<string> q;
string s;
int k;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s >> k;
  FOR(i, 0, sz(s))FOR(j, 1, min(sz(s)-i, k)+1){
    q.insert(s.substr(i, j));
    if(sz(q) > k) q.erase(prev(q.end()));
  }
  cout << *prev(q.end()) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  std::set<string> st;
  rep(i,0,N) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
}


Measured memory_bytes: 19080
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 12 23:38:36 2020

@author: liang
"""

N = int(input())
cost = [int(input()) for _ in range(5)]
cost.sort()
if N%cost[0] == 0:
    ans = 4 + N//cost[0] 
else:
    ans = 4 + N//cost[0] + 1
print(ans)

Measured memory_bytes: 9108
#include <cstdio>

int main() {
    int group[15] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int x, y;
    scanf("%d %d", &x, &y);

    if (group[x] == group[y])
        printf("Yes");
    else
        printf("No");

    return 0;
}


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

int main() {
  double n, m, d;
  cin >> n >> m >> d;

  double answer;
  if (d == 0) {
    answer = (m - 1) / n;
  } else if (2 * d <= n) {
    answer = (m - 1) * (2 * (n - 2 * d) + 2 * d) / pow(n, 2);
  } else {
    // 2 * d > n
    answer = (m - 1) * (2 * (n - d)) / pow(n, 2);
  }
  printf("%.8f\n", answer);
}


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

int main(){
    char a[3];
    int n=0;
    for(int i=0;i<3;i++)scanf("%c",&a[i]);

    for(int i=0;i<3;i++)if(a[i]=='1')n++;

    printf("%d",n);

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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


vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}



int main(){
  ll x; cin >> x;
  
  if(x == 1) cout << 0 << endl;
  else cout << 1 << endl;
  
  
}

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

using namespace std;

template<typename Edge> class Graph {
protected:
  vector<vector<Edge>> edges;

public:
  Graph(int n = 0) : edges(n) {}
  
  void addEdge(const Edge& edge) {
    if (int(edges.size()) <= max(edge.from, edge.to)) edges.resize(max(edge.from, edge.to) + 1);
    edges[edge.from].emplace_back(edge);
  }
};

template<typename Edge> class ShortestPath : public Graph<Edge> {
private:
  typedef __typeof(Edge::cost) Cost;

  struct State {
    int pos, prv;
    Cost cost;
    bool operator<(const State& state) const {return cost > state.cost;}
  };

public:
  const Cost INF;

  vector<vector<int>> prev;
  vector<Cost> dist;

  ShortestPath(const Graph<Edge>& graph) : Graph<Edge>(graph), INF(numeric_limits<Cost>::max()) {}
  
  void run (int from) {
    priority_queue<State> que;
    que.push((State){from, -1, 0});
    prev.resize(this->edges.size());
    dist.resize(this->edges.size(), INF);
    
    while (!que.empty()) {
      State now = que.top();
      que.pop();
      if (dist[now.pos] < now.cost) continue;
      prev[now.pos].emplace_back(now.prv);
      if (dist[now.pos] == now.cost) continue;
      dist[now.pos] = now.cost;
      for (const Edge& edge : this->edges[now.pos]) {
        if (dist[edge.to] < now.cost + edge.cost) continue;
        que.push((State){edge.to, now.pos, now.cost + edge.cost});
      }
    }
  }
};

struct Edge {
  int from, to, cost;
};

int main() {
  int v, e, r;
  cin >> v >> e >> r;
  Graph<Edge> graph(v);
  for (int i = 0; i < e; ++i) {
    int s, t, d;
    cin >> s >> t >> d;
    graph.addEdge((Edge){s, t, d});
  }
  ShortestPath<Edge> shortestPath = graph;
  shortestPath.run(r);
  for (int c : shortestPath.dist) {
    if (c != shortestPath.INF) cout << c << endl;
    else cout << "INF" << endl;
  }
}

Measured memory_bytes: 29592
#include "stdio.h"
#include <math.h>

#define INF 10000000000000000

int main(){
    long long int N;
    scanf("%ld",&N);
    long long int ans=INF;
    long long int a,b;


    for(long long int i=1;i<=1000000;i++){
        if(N%i==0){
            a=i;
            b=N/a;
            if(ans>a+b-2){
                ans=a+b-2;
            }
        }
    }
    printf("%lld",ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    scanf("%d",&N);
    vii xy(N,vi(2));
    rep(i,N) {
        rep(j,2) {
            cin>>xy.at(i).at(j);
        }
    }
    int sum=1;;
    for(int i=1; i<=N; i++) {
        sum*=i;
    }
    int d;
    if(N!=2) d=sum/N*2;
    if(N==2) d=2;
    double counter=0;
    rep(i,N) {
        for(int j=i+1; j<N; j++) {
            int square=0;
            rep(k,2) {
                int distance=abs(xy.at(i).at(k)-xy.at(j).at(k));
                square+=distance*distance;
            }
            long double di=sqrt(square);
            counter+=di;
        }
    }
    counter*=d;
    //cout<<sum<<" "<<d<<endl;
    cout<<fixed<<setprecision(10);
    cout<<counter/sum<<endl;
}

Measured memory_bytes: 256
import fractions

n, m = list(map(int, input().split()))
s = input()
t = input()

l = n * m // fractions.gcd(n,m)

a = l // n
b = l // m

for i in range(0, l, a*b):
    if s[i // a] != t[i // b]:
        print(-1)
        break
else:
    print(l)

Measured memory_bytes: 5436
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
#define derr if(0) cerr
// END NO SAD

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;

vector<ll> basis;
vector<int> bit;
set<int> bits;

void reset() {
  derr << "resetting" << endl;
  basis.clear();
  bit.clear();
  bits.clear();
}
bool tryadd(ll x) {
  derr << "trying to add " << x << endl;
  for(int i = 0; i < sz(basis); i++) {
    ll mask = 1LL << bit[i];
    if(x&mask) {
      x ^= basis[i];
    }
  }
  if(x == 0) return false;
  derr << "turns into " << x << endl;
  int id = 0;
  while(bits.count(id) || (x&(1LL<<id)) == 0) id++;
  basis.push_back(x);
  bit.push_back(id);
  bits.insert(id);
  return true;
}

ll l[205];
string s;
int n;
void rsolve() {
  cin >> n;
  for(int i = 0; i < n; i++) cin >> l[i];
  cin >> s;
  reset();
  for(int i = n-1; i >= 0; i--) {
    if(s[i] == '1') {
      if(tryadd(l[i])) {
        cout << "1\n";
        return;
      }
    }
    tryadd(l[i]);
  }
  cout << 0 << "\n";
}

void solve() {
  int t;
  cin >> t;
  while(t--) rsolve();
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


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

int main(){
	int n,ans=0;
	cin >> n;
	vector<int> an(n);
	
	for(int i=0;i<n;i++) cin >> an[i];
	
	for(int i=1;i<n-1;i++){
		if((an[i+1]>an[i] && an[i]>an[i-1]) || (an[i+1]<an[i] && an[i]<an[i-1]) )
		ans++;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[110];
int main(){
	int n;
	cin>>n;
	n*=2;
	for(register int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	int ans=0;
	for(register int i=1;i<=n;i+=2)
	ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,x,i,j,k,A[100][100],temp,half1[100],half2[100],sum[100];
    scanf("%d",&N);
    for(x=0;x<N;x++)
        scanf("%d",&A[x][0]);
    for(x=0;x<N;x++)
        scanf("%d",&A[x][1]);
    for(i=0;i<N;i++)
    {
        for(k=0;k<i+1;k++)
        {
         half1[i]=half1[i]+A[k][0];
        }
        for(j=i;j<N;j++)
        {
         half2[i]=half2[i]+A[j][1];
        }
        sum[i]=half1[i]+half2[i];
    }
    for(i=0; i<N; i++)
    {
        for(k=i+1; k<N; k++)
        {
            if(sum[i] < sum[k])
            {
                temp = sum[i];
                sum[i] = sum[k];
                sum[k] = temp;
            }
        }
    }
    printf("%d",sum[0]);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題162

            int n = int.Parse(Console.ReadLine());

            while (n != 0)
            {
                if (n % 10 == 7)
                {
                    Console.WriteLine("Yes");
                    return;
                }

                n /= 10;
            }

            Console.WriteLine("No");

        }


    }
}


Measured memory_bytes: 27448