akhauriyash/Code-Regression huggingface dataset:
import os, sys, re, math, queue

def run_it():
	N,M = list(map(int,input().split(' ')))
	divider = 1000000007
	n_max = 100000
	memo = [0] * (n_max + 1)
	memo[0] = 1
	memo[1] = 1
	for i in range(2,n_max+1):
		memo[i] = (memo[i-2] + memo[i-1]) % divider
	
	cur = 0
	ret = 1
	for m in range(M+1):
		if m < M:
			a = int(input())
		else:
			a = N + 1
		
		if a == cur:
			ret = 0
			break
		ret *= memo[a-cur-1]
		ret %= divider
		cur = a + 1

	print(ret)

if sys.platform == 'ios':
	for i in range(3):
		sys.stdin = open('Ctest' + str(i) + '.txt')
		run_it()
else:
	run_it()

Measured memory_bytes: 8040
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int a1,b1,a2,b2,k,s1,s2;
int main(){
	cin>>a1>>b1>>a2>>b2>>k;
	s1=a1*60+b1,s2=a2*60+b2;
	cout<<s2-s1-k;
	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
int N,i,b,d;main(){for(std::cin>>N;i<N;i++){char c;std::cin>>c;c-='1';if(c==1)b=-1e9;if(((N-1)&i)==i)d+=c,b+=c/2;}std::cout<<(b>=0?2*(b%2):d%2);}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()

using namespace std;

bool check(string& s, string& t, int n)
{
  REP(i, n) {
    if (s[s.size() - n + i] != t[i]) return false;
  }
  return true;
}

int main()
{
  int N;
  cin >> N;
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    if (check(s, t, i)) cnt = i;
  }
  cout << s.size() + t.size() - cnt << endl;

  return 0;
}

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

#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

const int maxn = 2e3+5;
const int intinf = 1<<29;
const ll inf = 1ll<<60;


void GG(){cout<<"No\n"; exit(0);}


vector<int> tree[maxn];
int nx = 0;
int k;
bool seen[maxn];

int dfs(int at, int left){
	if (left<0) return 0;
	seen[at]=1;
	int re = 1;
	for (int &v: tree[at]){
		if (!seen[v]) re+=dfs(v,left-1);
	}
	seen[at]=0;
	return re;
}

int solve(int x){
	int ex = 0, aa = 1;
	seen[x]=1;
	for (int &v: tree[x]){
		int a = dfs(v, k/2-1), b = dfs(v,k/2);
		aa += a; MXTO(ex, b-a);
		//debug(v); debug(a); debug(b);
	}
	seen[x]=0;
	return aa + ex;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   	int n; ll L; cin>>n>>L;
   	vector<ll> a(n);
   	REP(i,n) cin>>a[i];
   	bool fnd = 0;
   	REP(i,n-1){
   		if (a[i]+a[i+1]>=L) {
   			cout<<"Possible\n";
   			//int j = 1;
   			vector<int> ord; ord.pb(i);
   			RREP(it, i){
   				ord.pb(it);
   			}
   			FOR(it, i+1,n-1) ord.pb(it);
   			RREP(it, ord.size()){
   				cout<<ord[it]+1<<'\n';
   			}
   			//cout<<i+1<<'\n';
   			return 0;
   		}
   	}
   	cout<<"Impossible"<<endl;
}

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

void output(vector<int> B, int s) {
    rep(i, s - 1) cout << B.at(i) << " ";
    cout << B.at(s - 1) << endl;
}


int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A.at(i);
  int counter = 0;

  rep(i,N){
    int minj = i;
    for(int j = i; j < N;j++){
      if(A.at(j) < A.at(minj)) minj = j;
    }
    if(i != minj) counter++;
    swap(A.at(i),A.at(minj));
  }
  output(A,N);
  cout << counter << endl;
}



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

string S;

int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '1') S[i] = '9';
		else if (S[i] == '9') S[i] = '1';
	}
	cout << S << endl;
	return 0;
}

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

int main() {

    int A,B;
    cin >> A >> B;

    int coins = 0;
    for(int i = 0; i < 2; i++) {
        if(A >= B) {
            coins += A--;
        } else {
            coins += B--;
        }
    }

    cout << coins << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define RFOR(i, begin, end) for(int i=(end)-1, i##_begin_=(begin);i>=i##_begin_;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()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long int;
using V = vector<ll>;
using P = pair<ll, ll>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
constexpr int mod = 1e9+7;
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;}

ll n;

int main() {
    cin >> n;
    cout << n*n*n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    for(;;){
        string word;
        int hand = 0, sum = 0;
        getline(cin,word);
        if(word == "#"){break;}
        for(int i=0; i<word.size(); i++){
            int flag = 2;
            if(word[i] == 'q'){flag = 1;}
            if(word[i] == 'w'){flag = 1;}
            if(word[i] == 'e'){flag = 1;}
            if(word[i] == 'r'){flag = 1;}
            if(word[i] == 't'){flag = 1;}
            if(word[i] == 'a'){flag = 1;}
            if(word[i] == 's'){flag = 1;}
            if(word[i] == 'd'){flag = 1;}
            if(word[i] == 'f'){flag = 1;}
            if(word[i] == 'g'){flag = 1;}
            if(word[i] == 'z'){flag = 1;}
            if(word[i] == 'x'){flag = 1;}
            if(word[i] == 'c'){flag = 1;}
            if(word[i] == 'v'){flag = 1;}
            if(word[i] == 'b'){flag = 1;}
            if(!hand){hand = flag;}
            else if(hand != flag){hand = flag; sum++;}
        }
        cout <<sum<<endl;
    }
    return 0;
}

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

#define forsn(i,s,n) for(tint i=(s);i<(tint)(n); i++)
#define forn(i,n) forsn(i,0,n)
#define dforn(i,n) for(tint i = tint(n)-1; i >= 0; i--)
#define debug(x) cout << #x << " = "  << x << endl

using namespace std;

typedef long long tint;

random_device rd;
mt19937 gen(rd());

uniform_int_distribution<tint> dis(1, 10000);

void imprimirVector (vector<tint> v)
{
	if (!v.empty())
	{ 
		tint p = tint(v.size());
		cout << "[";
		forn(i,p-1)
			cout << v[i] << ",";
		cout << v[p-1] << "]" << endl;
	}
	else
		cout << "[]" << endl;
}

int main()
{
	#ifdef ACMTUYO
		assert(freopen("entrada.in", "r", stdin));
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	string s;
	while (cin >> s)
	{
		if ((s[2] == s[3]) && (s[4] == s[5])) 
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	
	
	return 0;
}






Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                count += 1
print(count)

Measured memory_bytes: 3060
#include<stdio.h>
main()
{
    int i=1,x[10000],a=0;
     for(a=0;a<10000;a++)
     {
         scanf("%d",&x[a]);

         if(x[a]==0){
            break;
         }
     }
    for(a=0;a<10000;a++)
    {
        if(x[a]==0)
        {
            break;
        }

        printf("Case %d: %d\n",i,x[a]);
        i++;

    }
    return 0;
}



Measured memory_bytes: 1936
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    string s;
    cin>>s;
    int n =s.size();
    vector<int> ary(n);
    for(int i=0;i<n;i++) ary[i] = s[i]-'0';

    vector<int> ten(n+1);
    ten[0]=1;
    for(int i=1;i<=n;i++) ten[i] = ten[i-1]*10%2019;

    ll res = 0;
    map<int,int> mp;
    mp[0]++;
    int sum = 0;
    for(int i=0;i<n;i++){
        sum = (sum+ary[i]*ten[n-i])%2019;
        res+=mp[sum];
        mp[sum]++;
    }
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 5144
#include <iostream>

using namespace std;

void bubbleSort(int a[], int n) 
{
    int count = 0;
    
    bool flag = 1;
    while (flag) {
        flag = 0;
        for (int j = n - 1; j > 0; j--) {
            if (a[j] < a[j-1]) {
                int s = a[j];
                a[j] = a[j-1];
                a[j-1] = s;
                flag = 1;
                count++;
                
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (i > 0) cout << " ";
        cout << a[i];
    }
    cout << endl;

    cout << count << endl;
    
}

int main()
{
    int a[100], n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    bubbleSort(a, n);
    return 0;
}

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

#define vint vector<int>
#define vvint vector<vint>
#define sint stack<int>
#define qint queue<int>
#define rep(i, n) for(int i=0;i<(int)(n);i++) // 繰り返し処理
#define all(x) (x).begin(),(x).end() // 全体 こんな感じで使う→sort(all(a));
#define ct(a) cout << a << endl
#define iceil(a,b) (a+(b-1))/b //int ceil : 繰り上げの割り算 通常のceilではceil((7.0/2.0))のようにしなければならなかった。
vint CinLine(int N){vint v(N);for(int i=0;i<N;i++){cin >> v.at(i);}return v;}//cin line 連続でvectorに格納
void CoutLine(vint v){for(int i=0;i<v.size()-1;i++){cout<<v.at(i)<<" ";}cout << v.at(v.size()-1)<<endl;}
// str.substr(開始位置, 取り出す長さ);

int main() {
    vint x(5);
    x = CinLine(5);
    int i;
    for(i = 0 ;i < 5; i++){
        if(x[i] == 0) {
            break;
        }
    }
    ct(i+1);

}

Measured memory_bytes: 3548
#include <stdio.h>
#include <string.h>

int main(void){
    int a, i;
    char S[100005];
    scanf("%s", S);
    i=strlen(S)-1;
    while (i!=-1) {
        a=1;
        if (S[i-4]=='d' && S[i-3]=='r' && S[i-2]=='e' && S[i-1]=='a' && S[i]=='m') {
            i-=5;
            a=0;
            // printf("%d\n", i);
        }
        if (a==0) continue;
        if (S[i-4]=='e' && S[i-3]=='r' && S[i-2]=='a' && S[i-1]=='s' && S[i]=='e') {
            i-=5;
            a=0;
            // printf("%d\n", i);
        }
        if (a==0) continue;
        if (S[i-5]=='e' && S[i-4]=='r' && S[i-3]=='a' && S[i-2]=='s' && S[i-1]=='e' && S[i]=='r') {
            i-=6;
            a=0;
            // printf("%d\n", i);
        }
        if (a==0) continue;
        if (S[i-6]=='d' && S[i-5]=='r' && S[i-4]=='e' && S[i-3]=='a' && S[i-2]=='m' && S[i-1]=='e' && S[i]=='r') {
            i-=7;
            a=0;
            // printf("%d\n", i);
        }
        if (a==1) break;
    }
    if (i==-1) printf("YES");
    else printf("NO");
    // printf("%c", S[10]);
    return 0;
}

Measured memory_bytes: 256
import sys

def move(cmd, gems):
    n = 0
    x = y = 10
    for c in cmd:
        d = c[0]
        l = c[1]
        for s in range(0, l):
            if d == "N":
                y += 1
            elif d == "E":
                x += 1
            elif d == "S":
                y -= 1
            elif d == "W":
                x -= 1
            if gems[y][x] == 1:
                n += 1
                gems[y][x] = 0
    return n

gems = []
cmd = []
att = "gemsN"
for line in sys.stdin:
    if att =="gemsN":
        n = w_n = int(line)
        if n == 0:
            break
        att = "gemsXY"
        gems = [[0 for i in range(0,21)] for j in range(0,21)]
    elif att == "gemsXY" and w_n > 0:
        xy = list(map(int, line.strip().split(" ")))
        gems[xy[1]][xy[0]] = 1
        w_n -= 1
    elif att == "gemsXY" and w_n == 0:
        att = "cmd"
        cmd = []
        m = int(line)
    elif att == "cmd" and m > 0:
        dl = line.strip().split(" ")
        cmd.append([dl[0], int(dl[1])])
        m -= 1
        if m == 0:
            a = move(cmd, gems)
            ans = "Yes" if a == n else "No"
            print(ans)
            att = "gemsN"


Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    if (s == "Sunny")
        cout << "Cloudy" << endl;
    else if (s == "Rainy")
        cout << "Sunny" << endl;
    else
        cout << "Rainy" << endl;
    return 0;
}


Measured memory_bytes: 256
S = input()

count = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "L":
            count = count + 1
    if i % 2 == 1:
        if S[i] == "R":
            count = count + 1
if count == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int a, b;
	while(scanf("%d%d", &a, &b)==2)
	{
		int ans=max(a+b, max(a+a-1, b+b-1));

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


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll l0 = 2;
    ll l1 = 1;

    ll n;
    cin >> n;

    if (n == 1)
    {
        cout << 1 << endl;
        exit(0);
    }

    ll li = l1 + l0;
    ll li_1 = l1;

    for (ll i = 3; i <= n; i++)
    {
        ll temp = li_1;
        li_1 = li;
        li = li + temp;
    }

    cout << li << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static boolean[][] edge;
    private static int N;
    private static int M;

    public static void main(String[] args) {
	N = Integer.parseInt(scan.next());
	M = Integer.parseInt(scan.next());

	edge = new boolean[N][N];
	for (int i = 0; i < M; i++) {
	    int a = Integer.parseInt(scan.next()) - 1;
	    int b = Integer.parseInt(scan.next()) - 1;
	    edge[a][b] = edge[b][a] = true;
	}

	boolean[] data = new boolean[N];
	data[0] = true;
	int count = func(data, 0, 1);

	System.out.println(count);
	scan.close();
    }

    private static int func(boolean[] data, int node, int num) {
	if(num == N-1) {
	    int count = 0;
	    for (int i = 0; i < N; i++) {
		if(data[i] == false && edge[node][i] == true) count++;
	    }
	    return count;
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
	    if(data[i] == false && edge[node][i] == true) {
		data[i] = true;
		count += func(data, i, num+1);
		data[i] = false;
	    }
	}
	return count;
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=3030;
int n,P,w,x,r,ans,c[N][N],s[N][N],pp[N],pw[N];
void ini(int n){
	FOR(i,0,n) c[i][0]=1;
	s[0][0]=pw[0]=1;pp[0]=2;
	FOR(i,1,n)FOR(j,1,i){
		c[i][j]=(c[i-1][j-1]+c[i-1][j])%P;
		s[i][j]=(s[i-1][j-1]+1ll*s[i-1][j]*j)%P;
	}
	FOR(i,1,n) pw[i]=(pw[i-1]<<1)%P;
	FOR(i,1,n) pp[i]=1ll*pp[i-1]*pp[i-1]%P;
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d",&n,&P);ini(n+1);
	FOR(i,0,n){
		w=1ll*(i&1?P-1:1)*c[n][i]%P;x=0;r=1;
		FOR(j,0,i) (x+=1ll*s[i+1][j+1]*pp[n-i]%P*r%P)%=P,r=1ll*r*pw[n-i]%P;
		(ans+=1ll*w*x%P)%=P;
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 70656
#include <stdio.h>

int main()
{
   long long int n, sum = 0;
   scanf("%lld", &n);
   
   for(long long int i=1; i<=n; i++) {
       if(i%5!=0 && i%3 !=0)
       sum += i;
   }
   
   printf("%lld", sum);

    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

bool allZero(vector<int> s, int cur) {
	for (int i = 0; i < s.size(); i++) {
		if (s[i] > 0 && i != cur) return false;
	}
	
	return true;
}
int main()
{
	// cinはscanfより基本的に遅い
	// sync_with_studio()を事前に書いておくとcinでも速度向上が期待出来る！

	bool flg = false;
	int n, p, cur;
	int curP;
	vector<int> s; 
	
	while (cin >> n >> p) {
		if (n == 0 && p == 0) {
			break;
		}

		
		cur = 0;
		curP = p;
		s.clear();
		s.resize(n);

		// 現在の候補者が碗から石を取り出す
		// 番号が降ってあるわけではない！
		while (true) {
			// 現在ターンである候補者が1つ取り出す
			if (curP > 0) {
				s[cur]++;
				curP--;
			} else if (curP == 0 && s[cur] > 0) {// 手元に小石があれば全て碗の中に入れる
				curP += s[cur];
				s[cur] = 0;
			}
			
			// 条件を満たして入れば終了
			if (curP == 0) {
				// && allZero(s, cur)) {
				flg = true;
				for (int i = 0; i < s.size(); i++) {
					if (s[i] > 0 && i != cur) flg = false;// 条件満たさず
				}
				if (flg) {
					cout << cur << endl;
					break;
				}
				
			}

			// 次の候補者へ
			cur++;
			if (cur == n) cur = 0;
		}
	
		
	}

	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef array<ll,2> pll;
const ll NMAX=100005;
ll h[NMAX],dp[NMAX][3],cost[3];
int main()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>cost[0]>>cost[1]>>cost[2];
        for(ll j=0;j<3;j++){
            for(ll k=0;k<3;k++){
                if(j==k)
                    continue;
                dp[i][j]=max(dp[i][j],dp[i-1][k]+cost[j]);
            }
        }
    }
    ll ans=0;
    for(ll i=0;i<3;i++)
        ans=max(ans,dp[n][i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5936
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
    ll n, x;
    vector<ll> a;
    cin >> n >> x;
    int tmp;
    REP(i, n) {
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(ALL(a));

    int res = 0;
    REP(i, n) {
        if (x >= a[i]) {
            if (i == n - 1) {
                if (x != a[i]) {
                    break;
                } else {
                    res++;
                    x -= a[i];
                }
            } else {
                res++;
                x -= a[i];
            }
        } else {
            break;
        }
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    ll prev_max = 0, cnt = 0;
    rep(i, N){
        ll h; cin >> h;
        if (h >= prev_max){cnt++; prev_max = h;}
    }
    cout << cnt << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main() {  
  vector<int> n(4);
  cin >> n[0] >> n[1] >> n[2] >> n[3];
  sort(n.begin(), n.end());  
  cout << ( n[0]==1 and n[1]==4 and n[2]==7 and n[3]==9 ?"YES" :"NO") << "\n";
}

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

int main() {
	int a,b;
	int d=0;
	while(1)
	{
		cin>>a>>b;
		if(a==0&&b==0)break;
		else if(d)cout<<endl;
		d=1;
		int c=0;
		for(int i=a;i<=b;i++)
		{
			if(i%4==0)
			{
				if(i%100==0)
				{
					if(i%400==0)
					{
						cout<<i<<endl;
						c++;
					}
				}
				else
				{
					cout<<i<<endl;
					c++;
				}
			}
		}
		if(c==0)cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3024
#![allow(dead_code)]

fn main() {
    let num:Vec<i32> = read_vec();
    let h1 = num[0];
    let m1 = num[1];
    let h2 = num[2];
    let m2 = num[3];
    let t  = num[4];
    let hd:i32;
    let md:i32;
    if m1 > m2 {
        hd = (h2 - h1-1).abs();
        md = (60 + m2 - m1).abs();
    } else {
        hd = (h2 - h1).abs();
        md = (m2 - m1).abs();
    }
    let total = hd*60+md;

    println!("{}", total-t);
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


fn read_n<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

Measured memory_bytes: 2100
def sinkIsland(x, y, islandmap)
  sunk = false
  if ((x < islandmap[0].size && y < islandmap.size) && islandmap[x][y] == 1) then
    islandmap[x][y] = 0
    sunk = true  
    #右チェック
    sinkIsland(x + 1, y, islandmap) if x + 1 < islandmap[0].size
    #左チェック
    sinkIsland(x - 1, y, islandmap) if 0 <= x - 1 
    #下チェック
    sinkIsland(x, y + 1, islandmap) if y + 1 < islandmap.size
    #上チェック
    sinkIsland(x, y - 1, islandmap) if 0 <= y - 1
  end
  return sunk
end

loop do
  islandmap = Array.new
  12.times{
    islandmap << $stdin.gets.chomp.split("").map{|m| m.to_i}
  }
  numIsland = 0
  islandmap.size.times{|y|
    islandmap[0].size.times{|x|
      numIsland += 1 if sinkIsland(x, y, islandmap)
      }
  }
  
  p numIsland
  
  break if $stdin.gets == nil
end

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

int mp[5001][5001];

int main(){
    int n,m,a,b,x;
    cin>>n>>m;
    for(int i=0;i<m;++i){
        cin>>a>>b>>x;
        mp[a-1][b-1]=max(mp[a-1][b-1],x+1);
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<=i;++j){
            if(mp[i][j]!=0){
                mp[i+1][j]=max(mp[i+1][j],mp[i][j]-1);
                mp[i+1][j+1]=max(mp[i+1][j+1],mp[i][j]-1);
            }
        }
    }
    int ans=0;
    for(int i=0;i<n;++i){
        for(int j=0;j<=i;++j){
            if(mp[i][j]!=0) ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 69896
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

H, W, N = reads()

field = Counter()
for _ in range(N):
  a, b = reads()
  a, b = a-1, b-1
  for i, j in product(range(-1, 2), range(-1, 2)):
    field[a+i, b+j] += 1

ans = [0] * 10
for (x, y), v in field.items():
  if 1 <= x < H-1 and 1 <= y < W-1:
    ans[v] += 1
ans[0] = (H-2) * (W-2) - sum(ans[1:10])

for a in ans:
  print(a)


Measured memory_bytes: 153848
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val t: MutableList<Int> = (0 until n).map { sc.nextInt() } as MutableList<Int>
    val m = sc.nextInt()
    val p = Array<MutableList<Int>>(m) { mutableListOf() }
    for (index in 0 until m) {
        p[index].add(sc.nextInt())
        p[index].add(sc.nextInt())
    }
    answer050bAlt(t, m, p)
}

fun answer050bAlt(t: MutableList<Int>, m: Int, p: Array<MutableList<Int>>) {
    for (i in 0 until m) {
        var tempList = t.toMutableList()
        var sum: Int
        tempList[(p[i][0].toInt()) - 1] = p[i][1]
        sum = tempList.sum()
        println(sum)
    }
}


Measured memory_bytes: 31268
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int p[100010];
    cin >> N;
    rep(i,0,N){
        cin >> p[i];
    }
    int seq = 0;
    int ans = 0;
    rep(i,0,N){
        if(p[i] == i+1){
            seq++;
        }else{
            if(seq <= 1){
                ans += seq;
            }else{
                ans += (seq+1)/2;
            }
            seq = 0;
        }

    }
    if(seq <= 1){
        ans += seq;
    }else{
        ans += (seq+1)/2;
    }
    print(ans);


}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int n;
	cin >> n;
	cout << (n*800)-(n/15)*200 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            List<ClsShp> lstShp = new List<ClsShp>();
            for (int i = 0; i < iN; i++)
            {
                sS = System.Console.ReadLine().Trim().Split(' ');
                ClsShp oneUsr = new ClsShp();
                oneUsr.iX = i + 1;
                oneUsr.sS = sS[0];
                oneUsr.iP = int.Parse(sS[1]);
                lstShp.Add(oneUsr);
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstShp.Sort(delegate (ClsShp mca1, ClsShp mca2) { return mca1.sS.CompareTo(mca2.sS) == 0 ? mca2.iP - mca1.iP: mca1.sS.CompareTo(mca2.sS); });      // sS昇順のiPの降順

            // 出力
            for (int i = 0; i < lstShp.Count; i++)
            {
                System.Console.WriteLine("{0}", lstShp[i].iX.ToString().Trim());
            }

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // 店情報
        private class ClsShp
        {
            public int    iX { get; set; } = 0;
            public string sS { get; set; } = "";
            public int    iP { get; set; } = 0;
        }

}


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  int n;
  cin>>n;
  vector<string> v;
  REP(i,n){
    string s;
    cin>>s;
    v.push_back(s);
  }
  sort(ALL(v));
  v.erase(unique(ALL(v)),v.end());
  cout<<v.size()<<endl;
}


Measured memory_bytes: 11668
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll bit = 1, ans = 0;
  rep(i, 60){
    ll cnt = 0;
    rep(j, n) if((a[j] >> i) & 1) cnt++;
    ans += ((cnt * (n - cnt)) % mod) * bit % mod;
    ans %= mod;
    (bit <<= 1) %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5448
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    
    int a[3],t = 0;
    for(int i = 0; i < 3; i++){
        cin >> a[i];
        t += a[i];
    }
    
    cout << min({t-a[0],t-a[1],t-a[2]}) << endl;
    
}


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

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

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

    while(1){
        c -= b;
        if(c <= 0) {
            puts("Yes");
            return 0;
        }
        a -= d;
        if(a <= 0){
            puts("No");
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

lli n_C(int n) {
	lli ans = 0, tmp = 0;
	rep(r, 0, n + 1) {
		if (r == 0)tmp = 1;
		else tmp = ((lli)n - r + 1) * tmp / r;
		ans += tmp;
	}

	return ans;
}

int main(void)
{
	lli N, P; cin >> N >> P;
	lli odd = 0;
	rep(i, 0, N) {
		int tmp; cin >> tmp;
		odd += (tmp % 2);
	}
	lli C_even = n_C(N - odd);

	lli ans = 0;
	if (P == 1) {
		lli tmp = 0;
		for (lli r = 1; r <= odd; r += 2) {
			if (r == 1)tmp = odd;
			else tmp = ((lli)odd - r + 1) * ((lli)odd - r + 2) * tmp / r / (r - 1);
			ans += tmp;
		}
	}
	else {
		lli tmp = 0;
		for (lli r = 0; r <= odd; r += 2) {
			if (r == 0)tmp = 1;
			else tmp = ((lli)odd - r + 1) * ((lli)odd - r + 2) * tmp / r / (r - 1);
			ans += tmp;
		}
	}

	ans *= C_even;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int h, w;
char a[101][101];
bool a_b[101][101];
bool is_not_print[101][101];
signed main() {
    cin >> h >> w;
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            cin >> a[i][j];
            if (a[i][j] == '.') a_b[i][j] = true;
        }
    }
    // 列
    bool t;
    for (int i=0;i<w;i++) {
        t = true;
        for (int j=0;j<h;j++) {
            t &= a_b[j][i];
        }
        if (t) {
            for (int j=0;j<h;j++) {
                is_not_print[j][i] = true;
            }
        }
    }
    // 行
    for (int i=0;i<h;i++) {
        t = true;
        for (int j=0;j<w;j++) {
            t &= a_b[i][j];
        }
        if (t) {
            for (int j=0;j<w;j++) {
                is_not_print[i][j] = true;
            }
        }
    }
    
    bool flg = false;
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            if (!is_not_print[i][j]) {
                cout << a[i][j];
                flg = true;
            }
        }
        if (flg) {
            cout << endl;
            flg = false;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
//#include <string.h>
#include <bits/stdc++.h>
#define INF 999999999
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
struct shi
{
    int x=0;
    int T;
}s[1000000];
int cmd(shi a,shi b)
{
    return a.x<b.x;
}
/*long long cmd(long long a, long long  b)
{
    return a > b;
}*/

int main()
{
    boost;
    int N;
    cin >>N;
    int   hh[100000];
    for(int i=0;i<N;i++){
        cin >>hh[i];
    }
    sort(hh,hh+N);
    int kk[105000];
    int ma=0;
    for(int i=0;i<N;i++){
        if(i!=0&&i!=N-1){
            kk[i]+=abs(hh[i]-hh[N-1])*2;
            kk[i]+=abs(hh[i]-hh[0]);
        }
        else
            kk[i]+=abs(hh[0]-hh[N-1]);

    }

    sort(kk,kk+N);
    cout<<kk[0]<<endl;
    return 0;

}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF (2e9)
#define EPS (1e-7)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin>>n;
    vector<int> v;
    vector<int> c;
    REP(i,n) {
        int tmp;
        cin>>tmp;
        v.push_back(tmp);
    }
    REP(i,n) {
        int tmp;
        cin>>tmp;
        c.push_back(tmp);
    }
    int ans = 0;
    REP(i,n) {
        int nv = v[i] - c[i];
        if (nv > 0) {
            ans += nv;
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;

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

// chmax, chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    
    int X;
    cin >> X;
    
    if ( X >= 30 ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  unordered_map<int, int> numbers;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++numbers[a];
  }
  int cnt = 0;
  for (auto element : numbers) {
    if (element.second % 2 == 1) ++cnt;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 4388
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=500050;
//↑templete
//↓区間和を求めるSegmentTree
struct SegmentTreeSum {
private:
    int n;
    vector<int> node;

public:
    // 元配列 v をセグメント木で表現する
    SegmentTreeSum(vector<int> v) {
        // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
        // セグメント木全体で必要なノード数は 2n-1 個である
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);

        // 最下段に値を入れたあとに、下の段から順番に値を入れる
        // 値を入れるには、自分の子の 2 値を参照すれば良い
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = (node[2*i+1] + node[2*i+2]);
    }
	void update(int x, int val) {
		// 最下段のノードにアクセスする
		x += (n - 1);

		// 最下段のノードを更新したら、あとは親に上って更新していく
		node[x] = val;
		while(x > 0) {
			x = (x - 1) / 2;
			node[x] = (node[2*x+1] + node[2*x+2]);
		}
	}
	int getsum(int a, int b, int k=0, int l=0, int r=-1) {
		// 最初に呼び出されたときの対象区間は [0, n)
		if(r < 0) r = n;

		// 要求区間と対象区間が交わらない -> 適当に返す
		if(r <= a || b <= l) return 0;

		// 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
		if(a <= l && r <= b) return node[k];

		// 要求区間が対象区間の一部を被覆 -> 子について探索を行う
		// 左側の子を vl ・ 右側の子を vr としている
		// 新しい対象区間は、現在の対象区間を半分に割ったもの
		int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
		int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
		return (vl + vr);
	}
};
//↑区間和を求めるSegmentTree
signed main(){

	int N;
	cin>>N;
	string S;
	cin>>S;

	vint v(N+50);
	vector<SegmentTreeSum> T;
	SegmentTreeSum seg(v);
	for(int i=0;i<26;i++)
		T.pb(seg);

	for(int i=0;i<N;i++){
		T[S[i]-'a'].update(i, 1);
	}

	int Q;
	cin>>Q;
	while(Q--){
		int t;
		cin>>t;
		if(t==1){
			int a;
			char b;
			cin>>a>>b;
			a--;
			if(S[a]==b)
				continue;
			
			T[b-'a'].update(a, 1);
			T[S[a]-'a'].update(a, 0);
			S[a]=b;
		}
		else{
			int l, r;
			cin>>l>>r;
			l--, r--;
			int ans=0;
			for(int i=0;i<26;i++){
				if(T[i].getsum(l, r+1))
					ans++;
			}
			cout<<ans<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 115552
#include "bits/stdc++.h"
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	int ans=0;
	for(int i=0;i<n;i++){
		int b;
		cin>>b;
		ans+=min(b,k-b);
	}
	cout<<ans*2<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=2e6+10;
const int M=1e6;
const int mod7=1e9+7;
const int mod=998244353;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int vis[N];
int main()
{
    int n;read(n);
    for(re int i=1,x;i<n;i++) read(x),vis[x]++;
    for(re int i=1;i<=n;i++) printf("%d\n",vis[i]);
    return 0;
}

Measured memory_bytes: 4436
#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 FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int a,b; cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
  int main() {
int N ; //直線の本数=ボールの個数
int K ; //ロボットBのx座標=直線の長さ
cin >>N >>K; //N,Kの入力
int xi ; //ボールのx座標
int sum=0 ; //ロボットの移動した距離の和

//各ロボットがボールへ進んでいく距離と、ボールに近いほうのロボットが回収しスタート地点に戻る距離の和を足す
//つまりボールに近いほうのロボットのスタート地点とボールのx座標の差*2が直線一本につきsumに加算される
//ボールに近いほうのロボットのスタート地点とボールのx座標の差はxiと、K-xiのどちらか小さいほう。これを*2したものが直線一本当たりの総移動距離


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

//xiを入力受付
cin >>xi;
if(xi<K-xi){sum+=xi*2;}  // cout<<i+1 <<"つめはA ";} //座標(0,N)に位置するロボットAがより近い場合
else{sum+=(K-xi)*2;} //cout<<i+1 <<"つめはB ";} //座標(K,N)に位置するロボットBがより近い場合
//cout <<sum <<endl; //テスト用
}

cout <<sum <<endl;
}

Measured memory_bytes: 256
// Problem : E - Colorful Blocks
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 998244353
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n,m,k,fact[200005],inv[200005];

int binpow(int x, int y){
    x = x%mod;
    int res = 1;
    while(y){
        if(y&1) res = (res*x)%mod;
        x = (x*x)%mod;
        y /= 2;       
    }
    return res;
}

int inverse(int x){
    return binpow(x,mod-2);
}

void compute(){
    fact[0] = inv[0] = 1;
    for(int i=1;i<=n;i++){
        fact[i] = (fact[i-1]*i)%mod;
        inv[i] = inverse(fact[i]);
    }
}

int C(int a,int b){
    return (((fact[a]*inv[b])%mod)*inv[a-b])%mod;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n>>m>>k;
    compute();
    int ans = 0;
    for(int i=0;i<=k;i++){
        ans = (ans + (((m*binpow(m-1,n-i-1))%mod)*C(n-1,i))%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    map<int, int> mp;
    vector<int> values;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        values.push_back(a);
        mp[a]++;
    }

    sort(values.rbegin(), values.rend());
    values.erase(std::unique(values.begin(), values.end()), values.end());

    int ans = 0;
    for(auto a : values){
        for(int i=30; i>=0; i--){
            if(mp[a] == 0) break;
            int b = (1<<i) - a;
            if(!mp.count(b)) continue;
            int add;
            if(a == b){
                add = mp[a]/2;
            }else{
                add = min(mp[a], mp[b]);
            }
            ans += add;
            mp[a] -= add;
            mp[b] -= add;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10356
def resolve():
    s = input()
    def dfs(i, pri):
        if i == n-1:
            return sum(list(map(int, pri.split(","))))
        return dfs(i+1, pri+s[i+1]) + dfs(i+1, pri + "," + s[i+1])
    n = len(s)
    print(dfs(0, s[0]))
resolve()

Measured memory_bytes: 38896
let N = Int(readLine()!)!

var V = 0
var E = 0

for i in 1...N {
  V += i * (N - i + 1)
}

for _ in 0..<N-1 {
  let inp = readLine()!.split(separator: " ").map { Int($0)! }
  var left = inp[0]
  var right = inp[1]
  if left > right {
    (right, left) = (left, right)
  }
  E += left * (N - right + 1)
}
print(V - E)

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

int sum(int x){
  int a;
  int y=0;
  while(x!=0){
    a=x%10;
    x=x/10;
    y=y+a;
  }
  return y;
}

int main() {
  int x;
  cin >>x;
  if (x%sum(x)==0){
    cout <<"Yes"<<endl;
  }
  if (x%sum(x)!=0){
    cout <<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll dp[maxn];
ll n,W;
ll v[maxn];
ll w[maxn];
int main()
{
    memset(dp,0x3f,sizeof(dp));
    gbtb;
    cin>>n>>W;
    repd(i,1,n)
    {
        cin>>w[i]>>v[i];
    }
    ll ans=0ll;
    dp[0]=0;
    repd(i,1,n)
    {
        for(int j=1e5;j>=v[i];--j)
        {
            {
                dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
                if(dp[j]<=W)
                    ans=max(ans,(ll)(j));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 11392
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    bool ans = false;
    for(int i = a; i <= b; i++) {
        if(i % k == 0) {
            ans = true;
            break;
        }
        else ans = false;
    }
    if(ans) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
    int n,arr[100],m,a,b;
    int sum=0;
    cin>>n;
    for(int i=0; i<n; ++i)
    {
        cin>>arr[i];
    }
    cin>>m;
    while(m--)
    {
        sum=0;
        cin>>a>>b;
        for(int i=0; i<n; ++i)
        {
            if(i==a-1)
                sum+=b;
            else 
            sum+=arr[i];
        }
        cout<<sum<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int a, b;
    cin >> a >> b;
    int ans = -1;
    for (int i = 0; i <= 10000; i++) {
        int c = i * (0.08);
        int d = i * (0.10);
        if (c == a && d == b) {
            ans = i; break;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *b = map(int, read().split())

a = [b[0]]
for i in range(1, n-1):
    a.append(min(b[i - 1], b[i]))
a.append(b[-1])
print(sum(a))


Measured memory_bytes: 2940