akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

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

int main(void)
{
    int n;
    int p;
    int j[66000];
    unsigned int total;
    int t;
    unsigned int max;
    int i, k;
    int flag;
    
    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }
        
        total = 0;
        for (i = 0; i < n; i++){
            scanf("%d", &p);
            total += p;
        }
        
        for (i = 0; i < n - 1; i++){
            scanf("%d", &j[i]);
            total += j[i];
        }

        qsort(j, n - 1, sizeof(int), comp);
#if 0
        for (i = 0; i < n - 1; i++){
            flag = 0;
            for (k = 0; k < n - 2; k++){
                if (j[k] > j[k + 1]){
                    t = j[k];
                    j[k] = j[k + 1];
                    j[k + 1] = t;
                    flag = 1;
                }
            }
            if (flag != 0){
                break;
            }
        }
#endif        
        max = total;
        
        for (i = 0; i < n - 1; i++){
            total -= j[i];
            if (max < total * (i + 2)){
                max = total * (i + 2);
            }
        }
        
        printf("%u\n", max);
    }
    
    return (0);
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll sum=0;int n;cin>>n;
	for(int a=1;a<=n;a++)
	for(int b=1;b<=n;b++)
	for(int c=1;c<=n;c++)
	{
		ll g=__gcd(a, b);
		g=__gcd(g,(ll)c);
		sum+=g;
	}
	cout<<sum;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(int argc, char const *argv[])
{
    ll arr[5],i;
    for(i=0;i<5;i++) cin>>arr[i];
    for(i=0;i<5;i++)
    {
        if(arr[i]==0)
        {
            cout<<i+1;
            return 0;
        }
    }
    return 0;
}

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

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

int main()
{
  long long N, SUM = 0;
  cin >> N;
  for(int i=0;i<=N;i++)
  {
    if (i % 3 != 0 && i % 5 != 0)
      SUM += i;
  }
  cout << SUM << endl;
  return 0;
}


Measured memory_bytes: 3192
n,m,c=gets.chomp.split().map(&:to_i)
b = gets.chomp.split().map(&:to_i)
num = 0
n.times do |i|
  code = gets.chomp.split().map(&:to_i)
  cnt=c
  code.each_with_index do |n, i|
    cnt += b[i]*n
  end
  num +=1 if cnt>0
end
puts num



Measured memory_bytes: 1788
#include <iostream>
#include <string>
using namespace std;
int sw[1000006], se[1000006];
string s;
int main(){
	int n;
	cin >> n;
	cin >> s;
	for (int i = 1; i <= n; ++ i)
		sw[i] = sw[i - 1] + (s[i - 1] == 'W');
	for (int i = n; i; -- i)
		se[i] = se[i + 1] + (s[i - 1] == 'E');
	int ans = n;
	for (int i = 1; i <= n; ++ i)
		ans = min(ans, sw[i - 1] + se[i + 1]);
	cout << ans << endl;
}


Measured memory_bytes: 5892
#include <stdio.h>

int main()
{
	int data[4][3][10]={0};
	int b,f,r,v;
	int n,i;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		data[b-1][f-1][r-1]+=v;
	}
	for(b=0; b<4; b++){
		for(f=0; f<3; f++){
			for(r=0; r<10; r++){
				printf(" %d", data[b][f][r]);
			}
			printf("\n");
		}
		if(b<4-1){
			printf("####################\n");
		}
	}
	return 0;
}

Measured memory_bytes: 612
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long a, b, k;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> b;
    if (abs(a - b)%2) {
        cout << "IMPOSSIBLE" << E;
    }
    else {
        cout << (a + b)/2 << E;
    }
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, n) for (ll i = a; i < n; i++)

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string>S(n);
    ll ans= 0;
    ll cnt= 1;
    REP(i,n){
        cin >> S[i];
        sort(S[i].begin(), S[i].end());
    }
    sort(S.begin(),S.end());
    REP(i,n){
        if(i!=0){
            if(S[i-1]==S[i]){
                cnt++;
            }else{
                ans+= (cnt*(cnt-1))/2;
                cnt= 1;
            }
        }
    }
    ans+= (cnt*(cnt-1))/2;

    if(ans>=1000000000){
        cout << ans << endl;
    } else{
        cout << ans << endl;
    }

}

Measured memory_bytes: 5760
#include<iostream>
#include<cstring>
using namespace std;
int n, i;
long long sol;
int ff[200];
char s[200005];
int main(){
    cin>> s + 1;
    n = strlen(s + 1);
    sol = 1;
    for(i = 1; i <= n; i++){
        ff[ s[i] ]++;
        sol += i - ff[ s[i] ];
    }
    cout<< sol;
}


Measured memory_bytes: 384
"""
Hが少ないので、縦で割るパターンは全探索して見る。
dpとか使わずに、貪欲的に割っていけばよい。

"""
H,W,K = map(int,input().split())
choco = [list(input()) for _ in range(H)]
accum = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        accum[i][j] = accum[i][j-1] + int(choco[i][j])

ans = float("INF")
for i in range(2**H):
    """
    i を2進数表記したときに1になっているインデックスに該当する行数で分割する。
    例えば00100なら3行目と4行目の間で分割する。
    """
    binI = format(i,"0"+str(H)+"b")
    group = {}
    groupNum = 0
    for j in range(H):
        group[j] = groupNum
        if binI[j] == "1":
            groupNum += 1
    breakCnt = groupNum
    tmp = [0]*(groupNum+1)
    for j in range(W):
        tmp2 = [0]*(groupNum+1)
        for k in range(H):
            groupNum = group[k]
            if choco[k][j] == "1":
                tmp2[groupNum] += 1
        if max(tmp2) > K:
            break
        else:
            for l in range(groupNum+1):
                tmp[l] += tmp2[l]
            if max(tmp) > K:
                breakCnt += 1
                tmp = tmp2
    else:
        ans = min(ans,breakCnt)
print(ans)

Measured memory_bytes: 75272
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_146
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            string s = Read();
            for(int i = 0; i < s.Length; i++)
            {
                char c = (char)(s[i] + n);
                if (c > 'Z') c = (char)(c - 26);
                Write(c);
            }
            WriteLine();
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main()
{

        long long N;
        cin >> N;
        long long A[N];
        long long cnt[N];
        long long cal[N];
        for (int i = 0; i < N; ++i) {
                cnt[i] = 0;
                if (i == 0) {
                        cal[i] = 0;
                }
                else {
                        cal[i] = cal[i-1] + i;
                }
        }
        for (int i = 0; i < N; ++i) {
                cin >> A[i];
                cnt[A[i] - 1]++;
        }
        long long total = 0;
        for (int i = 0; i < N; ++i) {
                if (cnt[i] == 0) {
                        continue;
                }
                else {
                        total += cal[cnt[i] - 1];
                }
        }

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

                cout << total - (cnt[A[i] - 1] - 1) << endl;

        }




}


Measured memory_bytes: 7296
#include<stdio.h>
int main(){
	int ka;
	int na; 
    int num[1000005];
    scanf("%d %d", &na, &ka);

    for (int i=0; i<na; i++){
        scanf ("%d", num + i);
    }

    for (int i=ka; i<na; i++){
        if (num[i] > num[i - ka]){  
            printf ("Yes\n");   
        }
        else {
            printf ("No\n");
        }
    }
	return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define maxn 500005
#define int long long
using namespace std;
inline int read()
{
	char x = getchar();
	int lin = 0, f = 1;
	while(x < '0' || x > '9')
	{
		if(x == '-') f = -1;
		x = getchar();
	}
    while(x >= '0' && x <= '9')
	{
		lin = (lin << 1) + (lin << 3) + x - '0';
		x = getchar();
	}
	return lin * f;
}
#define PII pair<int,int>
#define fir first
#define sec second
#define ma(a,b) make_pair(a,b)
#define db double
multiset <int> sett;
deque <int> q;
int n,val[maxn],ans,jie,s[maxn],tot;
void insert_big()
{
	int val = *(--sett.end());
	sett.erase(--sett.end()); 
	if(q.size())
	{
		if(abs(q.front() - val) <= abs(q.back() - val)) ans += abs(q.back() - val),q.push_back(val);
		else ans += abs(q.front() - val),q.push_front(val);
	}
	else q.push_front(val);
}
void insert_small()
{
	int val = *sett.begin();
	sett.erase(sett.begin());
	if(q.size())
	{
		if(abs(q.front() - val) <= abs(q.back() - val)) ans += abs(q.back() - val),q.push_back(val);
		else ans += abs(q.front() - val),q.push_front(val);
	}
	else q.push_front(val);
}
signed main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	n = read();
	for(int i = 1; i <= n; i++)
	{
		val[i] = read();
	}
	if(n == 2)
	{
		cout << abs(val[1] - val[2]);
		return 0;
	}
	if(n & 1)
	{
		for(int i = 1; i <= n; i++)
			sett.insert(val[i]);	
		for(int i = 1; i <= n; i++)
			if(!(i & 1)) insert_big();
			else insert_small();
		jie = ans;
		ans = 0;
		while(q.size()) q.pop_front();
		
		for(int i = 1; i <= n; i++)
			sett.insert(val[i]);	
		for(int i = 1; i <= n; i++)
			if(i & 1) insert_big();
			else insert_small();
		jie = max(ans,jie);
		ans = jie;
		cout << ans;
		return 0;
	}
	sort(val + 1,val + 1 + n);
	int v1 = val[n / 2],v2 = val[n / 2 + 1];
	for(int i = 1; i <= n; i++)
		if(i != n / 2 && i != n / 2 + 1)
			s[++tot] = val[i];
	n -= 2;
	for(int i = 1; i <= n; i++)
		val[i] = s[i];
		

	for(int i = 1; i <= n; i++)
		sett.insert(val[i]);	
	for(int i = 1; i <= n; i++)
		if(i & 1) insert_big();
		else insert_small();
	ans += max(abs(q.front() - v1) + abs(q.back() - v2),abs(q.front() - v2) + abs(q.back() - v1));

	jie = ans;
	ans = 0;

	while(q.size()) q.pop_back();
	for(int i = 1; i <= n; i++)
		sett.insert(val[i]);

	for(int i = 1; i <= n; i++)
		if(!(i & 1)) insert_big();
		else insert_small();
	ans += max(abs(q.front() - v1) + abs(q.back() - v2),abs(q.front() - v2) + abs(q.back() - v1));	

	ans = max(ans,jie);
	cout << ans;	
}


Measured memory_bytes: 9984
#include <cstdio>
#include <cstring>
#include <algorithm>
const int MAXN = 1e5 + 10;

int n;
int a[MAXN];
namespace solver1 {
  void main() {
    long long minn = 2, maxx = 2;
    long long range = 2;
    if (a[n] != 2) { puts("-1"); return; }
    maxx += a[n] - 1;
    range += a[n] - 1;
    for (int i = n - 1 ; i >= 1; i--) {
      
      minn = (((minn - 1) / a[i]) + 1) * a[i];
      maxx = maxx / a[i] * a[i];
      maxx += a[i] - 1;
      if (minn > maxx) {
        puts("-1");
        return;
      }
      range += a[i] - 1;
    }
    printf("%lld %lld\n", minn, maxx);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  solver1::main();
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

inline int read () {
    int ret = 0, t = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') t = -1, c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret * t;
}


int main () {
    string x;
    cin >> x;
    int i = x.size();
    while (i--) putchar('x'); putchar('\n');
    return 0;
}

Measured memory_bytes: 760
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_set>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
int main() {
    int n; scanf("%d", &n);
    vector<int> a(n); repeat (i,n) scanf("%d", &a[i]);
    unordered_set<int> x;
    for (int i = 0; i < n; i += 2) x.insert(a[i]);
    whole(sort, a);
    int ans = 0;
    for (int i = 1; i < n; i += 2) ans += x.count(a[i]);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2988
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,m,n,i,f=0,j,ans=0,k,x,r;
    cin >> x ;
    n=100;
    while(n<x)
    {
        n+=n/100;
        ans++;
    }
    cout << ans ;
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(void){
    int M1,D1,M2,D2;

    scanf("%d",&M1);
    scanf("%d",&D1);
    scanf("%d",&M2);
    scanf("%d",&D2);

    if (M1 == M2){
        printf("0");
    }

    else{
        printf("1");
    }

    return 0;
}

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

const int N = 1e5 + 5, M = 1e5 + 5;
std::vector<int> adj[N];
std::deque<int> ans;
bool inpath[N];
int u[M], v[M], n;

bool traverse(int& u) {
	for (auto v: adj[u])
		if (!inpath[v]) {
			u = v; return true;
		}
	return false;
}

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

	int m;
	std::cin >> n >> m;
	for (int i = 0; i < m; ++ i) {
		std::cin >> u[i] >> v[i];
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}

	ans.push_front(u[0]); ans.push_back(v[0]);
	inpath[u[0]] = inpath[v[0]] = true;
	int l = u[0], r = v[0];
	while (traverse(l)) {
		inpath[l] = true; ans.push_front(l);
	}
	while (traverse(r)) {
		inpath[r] = true; ans.push_back(r);
	}

	std::cout << ans.size() << std::endl;
	for (auto x: ans) {
		std::cout << x << " ";
	}
	std::cout << std::endl;
}

Measured memory_bytes: 7552
h,w = map(int,input().split())
s = [[(l == '.')*1 for l in list(input())] for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if i == 0:
      U[i][j] = s[i][j]
      D[h-i-1][j] = s[h-i-1][j]
    else:
      U[i][j] = (U[i-1][j]+1)*s[i][j]
      D[h-i-1][j] = (D[h-i][j]+1)*s[h-i-1][j]
    if j == 0:
      L[i][j] = s[i][j]
      R[i][w-j-1] = s[i][w-j-1]
    else:
      L[i][j] = (L[i][j-1]+1)*s[i][j]
      R[i][w-j-1] = (R[i][w-j]+1)*s[i][w-j-1]
for i in range(h):
  for j in range(w):
    m = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
    if ans < m:
      ans = m
print(ans)

Measured memory_bytes: 199816
package main

import "fmt"

func main() {
	var r, g, b int
	fmt.Scanf("%d %d %d", &r, &g, &b)

	m := (r*10+g)*10 + b
	if m%4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if(n > m) n = m;
		ArrayList<Integer> x = new ArrayList<>();
		for(int i = 0; i < m; i++) {
			x.add(sc.nextInt());
		}
		Collections.sort(x);
		ArrayList<Integer> dif = new ArrayList<>();
		for(int i = 1;i < m; i++) {
			dif.add(x.get(i) - x.get(i - 1));
		}
		Collections.sort(dif);
		int num = 0;
		for(int i = 0; i < m - n; i++) {
			num += dif.get(i);
		}
		System.out.println(num);
	}
}

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

int main() {
    
    int X,N;
    cin >> X >> N;
    int p;
    map<int,int> mp;
    for(int i = 0; i < N;i++){
        cin >> p;
        mp[p]++;
    }
    
    int target = X;
    
    if(mp[target]==0){
        cout << X << endl;
        return 0;
    }
    int i = 1;
    while(true){
        
        if(mp[target-i]==0){
            cout << target - i << endl;
            return 0;
        }
        if(mp[target+i]==0){
            cout << target + i << endl;
            return 0;
        }        
        
        i++;
        
    }
    

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
    ll n,d;
    cin>>n>>d;
    cout<<(n+(2*d))/(2*d+1)<<endl;
}
   



Measured memory_bytes: 256
#include <cstdio>

int main()
{
	char s[10];
	int ans = 0;
	
	scanf("%s", s);
	
	for (int i = -1; i == -1 || s[i]; i++){
		int a = 0, b = 0;
		for (int j = 0; j <= i; j++) a = a * 10 + s[j] - '0';
		if (s[i + 1] && s[i + 1] == '0') continue;
		for (int j = i + 1; s[j]; j++) b = b * 10 +  s[j] - '0';
		if (a - b <= 0 && a % 2 == b % 2) ans++;
	}
	
	printf("%d\n", ans);
	
	return (0);
}

Measured memory_bytes: 968
import numpy

n,k = map(int,input().split())
s = input()

ans = 0
cnt = 1
l = []


for i in range(n):
    if i == n-1:
        l.append(cnt)
        break
    if s[i] == s[i+1]:
        cnt += 1
    else:
        l.append(cnt)
        cnt = 1


if s[0] == '0':
    l.insert(0,0)

#print(s[-1] == '0')

if s[-1] == '0':
    l.append(0)
    
l_rui = numpy.cumsum(l)
l_rui = numpy.insert(l_rui,0,0)

k = 2*k

for i in range(n):
    if 2*i >= len(l_rui):
        break
    elif k+1+2*i >= len(l_rui):
        ans = max(ans, l_rui[-1] - l_rui[2*i])
    else:
        ans = max(ans, l_rui[k+1+2*i] - l_rui[2*i])

print(ans)

Measured memory_bytes: 15304
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

int N;
int X[1000];

signed main()
{
	cin >> N;
	REP(i, N) cin >> X[i];

	int mi = INT_MAX;
	for (int i = 0; i <= 100; i++)
	{
		int sum = 0;
		for (int j = 0; j < N; j++)
		{
			int a = i - X[j];
			a *= a;
			sum += a;
		}
		if (mi > sum)
		{
			mi = sum;
		}
	}

	cout << mi << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,x,y,a[2345];

int main(){
    cin>>n>>x>>y;
    for(int i=1;i<=n-1;i++){
        for(int j=i+1;j<=n;j++){
            int s,t=100000;
            int u=x-i,v=j-y;
            if(i<=x&&y<=j){
                s=x-i+j-y+1;
            }
            else{
                s=j-i;
                
                if(u<0)u-=2*u;
                if(v<0)v-=2*v;
                t=u+v+1;
                
            }if(t<s)s=t;
            a[s]++;
            
        }
    }
    
    for(int i=1;i<n;i++)cout<<a[i]<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
  int parent;
  int left;//left child
  int right;//right child
}BTree;

int Searcheight(int);

BTree t[25];

int main(){
  int n,i,id;
  int sib,deg,dep,tn,prov,height;
  char type[3][15]={"root","internal node","leaf"};
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    t[i].parent=-1;
    t[i].left=-1;
    t[i].right=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d",&t[id].left);
    scanf("%d",&t[id].right);
    t[t[id].left].parent=id;
    t[t[id].right].parent=id;
  }
  
  for(i=0;i<n;i++){
    //sibling
    if(t[i].parent==-1)
      sib=-1;
    else if(t[t[i].parent].left!=i)
      sib=t[t[i].parent].left;
    else if(t[t[i].parent].right!=i)
      sib=t[t[i].parent].right;
    else
      sib=-1;
    //end of sibling
    //degree
    deg=0;
    if(t[i].right!=-1)
      deg++;
    if(t[i].left!=-1)
      deg++;
    //end of degree
    //depth
    dep=0;
    prov=t[i].parent;
    while(prov!=-1){
      prov=t[prov].parent;
      dep++;
    }
    //end of depth
    //height
    height=0;
    height=Searcheight(i);
    //end of height
    //type
    if(dep==0)
      tn=0;
    else if(t[i].right!=-1||t[i].left!=-1)
      tn=1;
    else
      tn=2;
    //end of type
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",i,t[i].parent,sib,deg,dep,height,type[tn]);
  }
  return 0;
}

int Searcheight(int i){//saiki
  int r,l,height;
  if(t[i].right!=-1)
    r=Searcheight(t[i].right)+1;
  else
    r=0;
  if(t[i].left!=-1)
    l=Searcheight(t[i].left)+1;
  else
    l=0;
  if(r>l)
    height=r;
  else
    height=l;
  return height;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
 
#define int long long
 
int N,M;
 
 
bool sou[101010];
 
int cnt[202020];
 
int fff = 0;
 
int ss[202020];
int sum[202020];
 
int func(int x) {
  int res = ss[101010 - 1] - ss[x - 1] - (sum[101010 -1] - sum[x - 1]) * (x - 1) + fff;
  return res;
}
 
 
 
signed main() {
  cin >> N >> M;
  for(int i = 0;i < M;i++) {
    int m;
    cin >> m;
    m--;
    sou[m] = true;
  }
 
  sou[N] = true;
 
  int fi = 0;
  while(!sou[fi]) fi++;
 
  fff = fi;
  {
    int c = 0;
    for(int i = fi;i <= N;i++) {
      if(sou[i]) {
        cnt[c]++;
        c = 0;
      }
      else {
        c++;
      }
    }
  }
 
  cnt[0] = 0;
 
  for(int i = 1;i < 101010;i++) {
    sum[i] += sum[i - 1] + cnt[i];
  }
 
  for(int i = 1;i < 101010;i++) {
    ss[i] += ss[i - 1] + cnt[i] * i;
  }
 
  int Q;
  cin >> Q;
  vector<int> ans;
  for(int qq = 0;qq < Q;qq++) {
    int l;
    cin >> l;
    int ok = 101010;
    int ng = 0;
    while(ok - ng > 1) {
      int mid = (ok + ng) / 2;
      if(func(mid) <= l) ok = mid;
      else ng = mid;
    }
    ans.push_back(ok);
  }
 
  for(auto x : ans) {
    if(x == 101010) { cout << -1 << endl; }
    else { cout << x << endl;}
  }
 
}


Measured memory_bytes: 5592
#include <algorithm>
#include <complex>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

using std::accumulate;

typedef long long int ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 7;

class section {
   public:
    ll begin;
    ll end;
    ll velocity;

    section() {}
    section(ll begin, ll end) : begin(begin), end(end) {}
};

int main() {
    ll n;
    cin >> n;

    vector<section> ss(n);
    ll sum_t = 0;
    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        x *= 2;

        ss[i].begin = sum_t;
        ss[i].end = sum_t + x;

        sum_t += x;
    }

    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        ss[i].velocity = 2 * x;
    }

    vector<ll> a(sum_t + 1, INF);
    a[0] = 0;
    a[sum_t] = 0;

    for (const section& s : ss) {
        for (ll i = s.begin; i <= s.end; i++) {
            a[i] = min(a[i], s.velocity);
        }
    }

    for (ll i = sum_t - 1; i >= 0; i--) {
        a[i] = min(a[i + 1] + 1, a[i]);
    }

    ll speed = 0;
    ll distance = 0;
    for (ll i = 0; i < sum_t; i++) {
        distance += speed;
        if (speed < a[i + 1]) {
            speed += 1;
            distance += 1;
        } else if (speed > a[i + 1]) {
            speed -= 1;
            distance -= 1;
        }
    }

    cout << std::fixed << std::setprecision(9) << (1.0 * distance / 4) << endl;

    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s,t) sort((s).begin(),(s).end(),greater<t>())

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

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int N; string S;
void input()
{
    cin>>N;
    cin>>S;
    return;
}

void solve()
{
    int ans=0;
    for(int i=0;i<N;++i){
        if(S[i]!='A') continue;
        if(S[i+1]!='B') continue;
        if(S[i+2]!='C') continue;
        ans++;
    }
    cout<<ans<<endl;
    return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)(n);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int N,M;
    cin>>N>>M;
    set<int> a;
    REP(i,M) {
        int t;
        cin>>t;
        a.insert(t);
    }
    a.insert(-1);

    vector<vi> b(10);
    int ans=0;
    REP(i,N) {
        b[0].push_back(i);
    }
    REP(i,10) {
        if(b[i].size()==1) break;
        REP(j,b[i].size()) {
            int s=b[i][j];
            int t=b[i][j+1]; j++;
            if(EXIST(a,s) && EXIST(a,t)) b[i+1].push_back(-1);
            else if(EXIST(a,s)) b[i+1].push_back(t);
            else if(EXIST(a,t)) b[i+1].push_back(s);
            else {
                ans++;
                b[i+1].push_back(s);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3124
N = int(input())
A = list(map(int,input().split()))

MOD = 10**9 + 7
def inv(a):
	b = MOD
	u = 1
	v = 0
	while b > 0:
		t = a // b
		a -= t*b
		a,b = b,a
		u -= t*v
		u,v = v,u
	u %= MOD
	return u

def gcd(a,b):
	if a > b:
		a,b = b,a
	while b % a > 0:
		tmp = b % a
		b = a
		a = tmp
	return a

lcm = 1
for a in A:
	lcm = lcm * a // gcd(lcm, a)

L = lcm % MOD
ans = 0
for a in A:
	ans = (ans + L * inv(a)) % MOD
print(ans)

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

bool ok(int* A, int left, int right) {
    ll sum = 0;
    int x = 0;
    FOR(i, left, right) {
        sum += A[i];
        x ^= A[i];
    }
    return sum == x;
}

int main() {
    int N;
    cin >> N;
    int A[N];
    FOR(i, 0, N) cin >> A[i];
    ll right = 1;
    ll sum = A[0];
    FOR(i, 0, N) {
        while (right < N && (sum + A[right]) == (sum ^ A[right])) {
            sum += A[right];
            right++;
        }
        ans += right - i;
        sum -= A[i];
    }
    cout << ans << endl;
    return 0;
}

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

def factorize(n):#factorize(24) => [[2,3],[3,1]]
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:#2*97みたいなとき
        arr.append([temp, 1])
    if arr==[]:#n自体が素数の時
        arr.append([n, 1])
    return arr

ans = 0
for f in factorize(N):
    if f[0]==1:
        continue
    num = f[1]
    i = 1
    while num-i>=0:
        num = num - i
        ans += 1
        i += 1
print(ans)

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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


  ll n,x,y;
  cin>>n>>x>>y;
  x--;
  y--;
  ll dist[n][n];
  REP(i,n)dist[i][i]=0;

  REP(i,n){
    for(ll j=i+1; j<n; j++){
      dist[i][j] = dist[i][j-1]+1;
      dist[j][i]=dist[i][j];
    }
  }
  dist[x][y] = 1;

  vll ans(n+1);
  REP(i,n){
    for(ll j=i+1; j<n; j++){
      dist[i][j] = min(dist[i][j], dist[i][x]+dist[y][j]+1);
      ll d = dist[i][j];
      ans[d]++;
    }
  }

  REP1(i,n)cout<<ans[i]<<endl;



}



Measured memory_bytes: 31488
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    H, W, A, B = MI()
    ret = [[0] * A + [1] * (W - A)] * B \
    	+ [[1] * A + [0] * (W - A)] * (H - B)
    for row in ret:
        row = [str(i) for i in row]
        row = ''.join(row)
        print(row)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 5104
using System;
using System.Collections;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        int A, B,s=0;
        var t = Console.ReadLine().Split(' ');
        A = int.Parse(t[0]);
        B = int.Parse(t[1]);
        if (A > B)
        {
            s += A;
            A--;
        }
        else
        {
            s += B;
            B--;
        }
        if (A > B)
        {
            s += A;
            A--;
        }
        else
        {
            s += B;
            B--;
        }
        Console.WriteLine(s);
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
int main(void){
    // Your code here!
    int n, i, ans[100001] = {}, x, y, z;
    scanf("%d", &n);
    for (x = 1; x * x + 2 * x < n; x++)
    {
        for (y = 1; y * y + 2 * y < n; y++)
        {
            for (z = 1; z*z+2*z<n;z++)
            {
                ans[x * x + y * y + z * z+x*y+z*y+z*x]++;
            }
        }
    }
    for (i = 1; i <= n; i++)
        printf("%d\n", ans[i]);
}


Measured memory_bytes: 2044
from sys import exit
import bisect

N = int(input())
A = sorted([int(n) for n in input().split()])
B = sorted([int(n) for n in input().split()])
C = sorted([int(n) for n in input().split()])
Cl = len(C)
# print(A)
# print(B)
# print(C)
ans=0
for b in B:
    a = bisect.bisect_left(A,b)#未満を探す
    c = Cl - bisect.bisect_right(C,b)#以下を探して全体から引く
    # print(b,a,c)
    ans+=a*c
print(ans)

Measured memory_bytes: 23200
#include <stdio.h>
int main(){
    int h,m,s,i,x,y;
    for (i=0; i<3; i++) {
        scanf("%d %d %d",&h,&m,&s);
        x=3600*h+60*m+s;
        scanf("%d %d %d",&h,&m,&s);
        y=3600*h+60*m+s;
        y-=x;
        h=y/3600;
        s=y%60;
        m=(y-3600*h-s)/60;
        printf("%d %d %d\n",h,m,s);
    }
    return 0;
}

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

int main(){
    int Q, A, F;
    string S;
    cin >> S;

    for(int lp=0; lp<(int)S.length(); lp+=2){
        string s = S.substr(lp,2);
        if(s == "hi")continue;
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main(void){
    int n,i;
    string s;
    cin >> n >> s;

    for(i=0; i<s.size(); i++){

//        s[i] = s[i] + n;
//        cout << (int)s[i] + n;


        if((int)s[i] + n <= 90){
            s[i] = s[i] + n;
            cout << s[i];
        }else{
            s[i] = s[i] - (26 - n);
            cout << s[i];
       }
    }

    cout << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
 
int main(){
    ll n,m;
    cin>>n>>m;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll sum[n+1];
    sum[n]=0;
    for(int i=n-1;i>=0;i--){
        sum[i]=sum[i+1]+a[i];
    }
    int ok=1,ng=200001;
    ll hold[200001];
    while(ng-ok>1){
        int mid=(ok+ng)/2;
        ll t=0;
        for(int i=0;i<n;i++){
            t+=n-(lower_bound(a,a+n,mid-a[i])-a);
        }
        hold[mid]=t;
        if(t>=m)ok=mid;
        else ng=mid;
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        int tmp=lower_bound(a,a+n,ok-a[i])-a;
        ans+=sum[tmp]+a[i]*(n-tmp);
    }
    ans-=(hold[ok]-m)*ok;
    cout<<ans<<endl;
}

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

int w,h;
int grid[30][30];

int rec(int y,int x,int n){
  if(10<n)return 11;

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

  for(int i=0;i<4;i++){
    int sx = x+dx[i], sy = y+dy[i];
    if(sx<0 || sy<0 || w<=sx || h<=sy || grid[sy][sx]==1)continue;
    while(0<=sx && 0<=sy && sx<w && sy<h){
      if(grid[sy][sx] == 3){
	res = min(res,n);
	break;
      }
      if(grid[sy][sx] == 1){
	grid[sy][sx] = 0;
	res = min(res, rec(sy-dy[i],sx-dx[i],n+1) );
	grid[sy][sx] = 1;
	break;
      }
      sx += dx[i]; sy += dy[i];
    }
  }

  return res;
}

int main(){
  while(cin >> w >> h , w||h){
    int sy,sx;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin >> grid[i][j];
	if(grid[i][j]==2){
	  sy = i;
	  sx = j;
	}
      }

    int ans = rec(sy,sx,1);
    if(ans>10)cout << -1 << endl;
    else cout << ans << endl;
  }
}

Measured memory_bytes: 872
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 200005;
const ll mm = 1e+18;
void solve()
{
    string s[3];
    rep0(i,3){
        cin>>s[i];
        reverse(s[i].beg,s[i].en);
    }
    int cu=0;
    while(1){
        if(!(int)(s[cu].si)){
            cout<<(char)('A'+cu);
            return;
        }
        char c=s[cu].back();
        s[cu].pop_back();
        cu=(int)(c-'a');
    }
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 3580
def info(c):
    b = range(max([max(i) for i in c])+1)
    for i in b:
        for p in b:
            for o in b:
                cnt = 0
                for s in c:
                    if ((s[0]-i) == (s[1]-p)) and ((s[1]-p) == (s[2]-o)):
                        cnt += 1
                if cnt == 3:
                    return 'Yes'
    return 'No'
C = [list(map(int, input().split())) for i in range(3)]
print(info(C))

Measured memory_bytes: 3064
n = int(input())
b = list(map(int,input().split()))
ans = [0 for i in range(n)]

b.reverse()

ans[0] = b[0]
for i in range(n-2):
    ans[i+1] = min(b[i],b[i+1])

ans[-1] = b[-1]

# print(ans)
print(sum(ans))


Measured memory_bytes: 3060
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
  // cin>>t;
    for(int ok=1;ok<=t;ok++)
    {
         
         ll n;
         cin>>n;
         ll a[n+2];
         map<ll,ll>lol;
         for(int i=1;i<=n;i++)
         {
         	cin>>a[i];
         	lol[i-a[i]]++;
         }
         ll ans=0;
         for(int i=1;i<=n;i++)
         {
         	lol[i-a[i]]--;
         	ans+=lol[i+a[i]];
         }
         cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 27868
// AGC32-A
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    int n;
    cin>>n;
    vector<int> num(n+1);
    rep(i,n) cin>>num[i+1];
    stack<int> sosa;
    vector<bool> seen(n+1,false); //trueだともう取り除いてる
    int see=0;
    bool flag=true;
    while(see<n){
        int ind=0; //残っているやつで何番目か
        int del=0; //消せるやつ
        for(int i=1;i<=n;i++){
            if(seen[i]==false) ind+=1;
            else continue;
            if(ind==num[i]) del=i;
        }
        if(del!=0){
            seen[del]=true;
            sosa.push(num[del]);
            see+=1;
        }else{
            flag=false;
            break;
        }
    }
    if(flag){
        rep(i,n){
            int a=sosa.top();
            cout<<a<<endl;
            sosa.pop();
        }
    }else cout<<-1<<endl;
    return 0;
}

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

int main(){
int N;
  string S;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>S;
    if(S=="Y"){
    cout<<"Four"<<endl;
    break;}
    else if(i==N-1)
      cout<<"Three"<<endl;
  }
}

Measured memory_bytes: 3132
#include <string>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <queue>
using namespace std;
int main(void)
{
	queue<pair<string,int>> Q;
	int n, q, x, a, cou = 0, time = 0;
	string name;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> name >> x;
		Q.push(make_pair(name, x));
	}
	while(!(Q.empty())) {
		pair<string, int> p = Q.front(); Q.pop();
		if (p.second > q) {
			Q.push(make_pair(p.first, p.second - q));
			time += q;
		}
		else {
			time += p.second;
			cout << p.first << " " << time << endl;
		}
	}
}

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

int main(){

 int h, w, i, j;

 while(1) {
  cin >> h >> w;

  if ((h == 0) && (w == 0)) break;

  for (i = 0; i < h; i++) {
   for (j = 0; j < w; j++) {
    if ((i + j) % 2 == 0) cout << "#";
    else cout << ".";
   }
   cout << endl;
  }
  cout << endl;
 }

 return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int sum =0;
	for (int i = 1; i<=n; i++) sum = sum + i;
	cout << sum <<endl;
	
	
	
	
	
	
	return 0;
}



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

ll solve() {
    ll N, x, a = 1, b = 1;
    cin >> N;
    const ll MOD = 1e9 + 7;
    for ( ll i = 0; i < N; i++ ) {
        cin >> x;
        a = a * b % MOD;
        if ( x >= 2 * b - 1 ) b++;
    }
    return a;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll A, B, N; cin >> A >> B >> N;
    ll x = B-1;
    if(x > N) x = N;
    ll ans = (A*x)/B + A * (x/B);
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
//using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dh[8] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dw[8] = {1, -1, 0, 1, -1, 0, 1, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
using Graph = vector<vector<int>>;
Graph G;
  
/*------------------------------------------------------------------*/

int main(){
    ll a, b, c; cin >> a >> b >> c;
    if(a % 2 == 0 or b % 2 == 0 or c % 2 == 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = min({b * c * (a - a / 2 * 2), c * a * (b - b / 2 * 2), 
    a * b * (c - c / 2 * 2)});
    cout << ans << endl;
}

Measured memory_bytes: 256