akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
	int N,sc[200][3],re[200][3],sum[200];
	for(int i=0;i<200;i++){
		for(int j=0;j<3;j++){
			sc[i][j]=0;
			re[i][j]=0;
			}
		}
	for(int i=0;i<200;i++)
		sum[i]=0;
	cin >>N;
	for(int i=0;i<N;i++){
		for(int j=0;j<3;j++)
			cin >>sc[i][j];
		}

	for(int j=0;j<3;j++){
		for(int i=0;i<N;i++){
			for(int k=0;k<N;k++){
				if(sc[i][j]==sc[k][j] && i!=k){
					re[i][j]=0;
					break;
					}
				if(sc[i][j]!=sc[k][j] && i!=k)
					re[i][j]=sc[i][j];	
				}
			}
		}
	for(int i=0;i<N;i++){
		for(int j=0;j<3;j++)
			sum[i]=sum[i]+re[i][j];
		}
	for(int i=0;i<N;i++)
		cout <<sum[i] <<"\n";
			

	return 0;

}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << 'a';
    if (a > b)
    {
        cout << " > ";
    }
    else if (a < b)
    {
        cout << " < ";
    }
    else
    {
        cout << " == ";
    }
    cout << 'b' << endl;
    return 0;
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll three_diff(ll a, ll b, ll c)
{
    ll mx,mn;
    mx = max(a,b);
    mx = max(mx,c);
    mn = min(a,b);
    mn = min(mn,c);
    return mx-mn;
}

ll answer(ll h,ll w)
{
    ll nh;
    ll mn = LINF;
    for (nh = 0; nh <= h; nh++)
    {
        ll s1 = nh*w;
        ll s2 = (h-nh)*(w/2);
        ll s3 = (h-nh)*(w-w/2);
        ll temp1 = three_diff(s1, s2, s3);

        ll h_dash = h-nh;
        s2 = w * (h_dash / 2);
        s3 = w * (h_dash-h_dash/ 2);
        ll temp2 = three_diff(s1, s2, s3);
        mn = min(mn, temp1);
        mn=  min(mn, temp2);
    }
    return mn;

}

int main()
{
    ll h,w;
    cin >> h >> w;

    ll ans;
    ans = min(answer(h,w), answer(w,h));
    cout << ans << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

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

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)3e2+11;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n>>x;
        
        ll sum=0;
        ll ans=0;
        for(i=1;i<=n;i++){
                cin>>y;
                sum+=y;
                if(sum<=x)ans++;
        }
        cout<<ans+1<<endl;
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

Measured memory_bytes: 3612
house=[[[0 for i in range(10)]for j in range(3)]for k in range(4)]
n=int(input())
for h in range(n):
 b,f,r,v=map(int,input().split())
 house[b-1][f-1][r-1]=house[b-1][f-1][r-1]+v

for a in range(4):
    for b in range(3):
        for c in range(10):
            print(' ',house[a][b][c],sep='',end='')
        print('',sep='')
    
    if a == 3:
        n=0
    else:
        for d in range(20):
            print('#',sep='',end='')
        print('',sep='')


Measured memory_bytes: 5644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] sequence = new int[n];
		for (int i = 0; i < n; i++) {
			sequence[i] = in.nextInt();
		}
		
		int m = in.nextInt();
		int[] set_integer = new int[m];
		for (int i = 0; i < m; i++) {
			set_integer[i] = in.nextInt();
		}
		
		int res = 0;
		for (int i = 0; i < set_integer.length; i++) {
			int num = set_integer[i];
			for (int j = 0; j < sequence.length; j++) {
				if (sequence[j] == num) {
					res++;
					break;
				}
			}
		}
		System.out.println(res);
		in.close();
	}
}


Measured memory_bytes: 40228
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main()
{
    long long a,b,c;
    cin>>a>>b>>c;
    if(a%2==0||b%2==0||c%2==0) cout<<"0";
    else cout<<min(a*b,min(b*c,c*a));
}

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

long long get1(long long a) {
	long long ret = 0;
	while(a) {
		ret++;
		a /= 10;
	}
	return ret;
}

long long get(long long a, long long b) {
	return max(get1(a), get1(b));
}

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

	vector <long long> v;
	
	for(long long i = 1; i * i <= n; i++) {
		if((n % i) == 0)
			v.push_back(i);
	}

	long long ans = 111;
	
	for(long long i = 0; i < v.size(); i++) {
		long long temp = get(v[i], n / v[i]);
		ans = min(ans, temp);
	}   
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll N, X, M;
    cin >> N >> X >> M;

    if (N <= 1000000) {
        ll ans = 0;
        Rep (i, N) {
            ans += X;
            X *= X;
            X %= M;
        }
        cout << ans << endl;
        return 0;
    }

    ll tmp = X;

    vec appear(M, -1);
    deque<ll> A;
    ll start;
    while (true) {
        if (appear[tmp] > -1) {
            start = tmp;
            break;
        }

        A.push_back(tmp);
        appear[tmp] = 1;
        tmp *= tmp;
        tmp %= M;
    }

    ll ans = 0;
    while (A.front() != start) {
        ans += A.front();
        A.pop_front();
        N--;
    }

    ll s = 0;
    for (ll e : A) {
        s += e;
    }

    ll n = A.size();
    ll div = N / n;
    ll rem = N % n;

    ans += s * div;
    Rep (i, rem) {
        ans += A[i];
    }

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

Measured memory_bytes: 4568
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
list_a = list(map(int, sys.stdin.readline().split()))

sum = 0

for i in range(N):
    sum += 1/list_a[i]

print(1/sum)

Measured memory_bytes: 5076
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    int a,b;
    cin>>a>>b;

    if(a>8 || b>8) cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,c,d,t;
int main(){
    scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
    t=abs(b-a);
    for(int i=0;i<n;i++)
        if(c*(n-1-i)-d*i<=t&&-1*c*(i)+(n-1-i)*d>=t)return puts("YES"),0;
    puts("NO");
}

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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, k;
    string s;
    cin >> n >> k >> s;
    
    vector<int> sum;
    int now = 1;
    int id = 0;
    int cnt = 0;
    while(id < n){
        if(s[id] - '0' == now){
            ++cnt;
        }
        else{
            sum.push_back(cnt);
            now ^= 1;
            cnt = 1;
        }
        ++id;
    }
    sum.push_back(cnt);
    
    if(sum.size() % 2 == 0)     sum.push_back(0);
    
    int left = 0, right = 0;
    int ans = 0;
    int temp = 0;
    int add = 2 * k + 1;
    for(int i = 0; i < sum.size(); i += 2){
        int n_left = i;
        int n_right = min(i + add, (int)sum.size());
        
        while(n_left > left){
            temp -= sum[left++];
        }
        while(n_right > right){
            temp += sum[right++];
        }
        
        ans = max(ans, temp);
    }
    
    
    cout << ans << endl;
}

Measured memory_bytes: 1020
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,a[200],b[200],c[1000],d[1000],z,x[201],y[201],w,p,flg,flg2,i,j,o,u,g;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d %d",&a[i],&b[i]);
		}
		scanf("%d",&m);
		for(i=0;i<m;i++){
			scanf("%d %d",&c[i],&d[i]);
		}
		for(i=0;i<201;i++){
			x[i]=0; y[i]=0;
		}
		for(i=1;i<n;i++){
			x[i]=a[0]-a[i];
			y[i]=b[0]-b[i];
//			printf("aa %d %d\n",x[i],y[i]);
		}
		o=0;
		for(i=0;i<m;i++){
			p=1; 
			for(j=0;j<m;j++){
				flg=0;
				if(c[i]-c[j]==x[p]&&d[i]-d[j]==y[p]){
					flg=1;
					z=c[j]-a[p]; w=d[j]-b[p];
				}
				if(flg==1){
					j=-1;
					p++;
				}
				if(p>=n){
					break;
				}
			}
			if(o<p){
				o=p;
				u=z;g=w;
			}
		}
		printf("%d %d\n",u,g);
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int A = 0;
  int i = 0;
  while (i < N) {
    int l, r;
    cin >> l >> r;
    A += r - l + 1;
    i++;
  }
  cout << A << endl;
}
    

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

int main(){
  string w;
  cin >> w;
  set<char> a;
  for(int i = 0; i < w.size(); i++){
    a.insert(w.at(i));
  }
  for(auto value : a){
    int count = 0;
    for(int i = 0; i < w.size(); i++){
      if(value == w.at(i)){
        count++;
      }
    }
    if(count % 2 != 0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

int main(){
    int k, t;
    cin >> k >> t;

    priority_queue<pair<int, int>> q;
    for (auto i = 0; i < t; i++) {
        int a; cin >> a; q.push({a, i});
    }

    int ans = 0;
    while(not q.empty()) {
        auto max = q.top(); q.pop(); max.first--;
//        cout << "start:" << max.first << " " << max.second << endl;
        while(max.first > 0 and not q.empty()) {
            auto p = q.top(); q.pop(); p.first--;
            if(p.first != 0) q.push(p);
            max.first--;
//            cout << p.first << " " << p.second << endl;
        }
//        cout << "ans: " << ans << " " << max.first << " " << max.second << endl;
        if(max.first != 0) ans += max.first;
    }

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

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define pb push_back
#define mod 1000000007
vector<ll>cost ,h ;

int main() {
    ll n ,i ;
    cin >> n ;
    cost.resize(n+2) ;
    h.resize(n+2) ;
    for(i=0;i<n+2;i++) cost[i]=LLONG_MAX ;

    for(i=0;i<n;i++)  cin >> h[i] ;

    cost[0] = 0 ;
    for(i=1;i<n;i++) {
        if (i==1) {
            cost[i] = min(cost[i],abs(h[i]-h[i-1])) ;
        }
        else {
            cost[i] = min(cost[i],cost[i-1]+abs(h[i]-h[i-1])) ;
            cost[i] = min(cost[i],cost[i-2]+abs(h[i]-h[i-2])) ;
        }
    }
    cout << cost[n-1] << endl ;


}


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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long r;
        cin >> r;

        printf("%lld\n", r*r);
    }
}


Measured memory_bytes: 3724
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


int main()
{
	ios::sync_with_stdio(false);

	int k, x;
	cin >> k >> x;
	for (int i = x - k + 1; i <= x + k - 1; i++)
		cout << i << " ";
	cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <array>

int main(void) {

	int n, l, m;
	int sum = 0;
	std::array<int,210> a;

	scanf("%d%d", &n, &l);

	for (m = 1; m <= n; m++) {

		a[m] = l + m - 1;
//		std::cout << a[m] << "  "; 

	}
//	puts("");

	if (l >= 0) {
		a[1] = 0;
		for (m = 1; m <= n; m++) {
			sum += a[m];
	//		std::cout << a[m] << "  ";
		}
//		puts("");
		printf("%d\n", sum);
	}

	if (l <= -n) {

		a[n] = 0;
		for (m = 1; m <= n; m++) {
			sum += a[m];
//			std::cout << a[m] << "A  ";
		}
//		puts("");
		printf("%d\n", sum);
	}



	if (-n < l && l < 0) {
		for (m = 1; m <= n; m++) {
			sum += a[m];
//			std::cout << a[m] << "  ";
		}
//		puts("");
		printf("%d\n", sum);
	}

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <math.h>
using namespace std;

int main(void){
    int n, k, l=1, tmp=0;
    
    cin >> n;
 
    int a[n];
    
    a[0] = 2;
    
	for(int i=3; i<=55556; i+=2){
		k=0;
		for(int j=3; j<=sqrt(i); j+=2){
			if(i%j==0){
				k=1;
				break;
			}
		}

		if(k==0){
		    tmp = 0;
		    a[l]=i;
		    if(a[l]%5==1) l++;
		}
		if(l==n) break;
	}
    
    for(int i=0; i<n; i++) cout << a[i] << " ";
    
    return 0;
}


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

using namespace std;

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

  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  int sum = 0;
  for (auto &e : x) {
    cin >> e;
    sum += e;
  }

  uint64_t dp[51][51][sum + 1];
  for (int i = 0; i <= n; ++i) {
    dp[i][0][0] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    int newcard = x[i-1];
    for (int j = 1; j <= i; ++j) {
      for (int k = 0; k < newcard; ++k)
        dp[i][j][k] = dp[i - 1][j][k];
      for (int k = newcard; k <= sum; ++k) {
        dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - newcard];
      }
    }
  }

  uint64_t ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (sum < i*a) break;
    ans += dp[n][i][i * a];
  }

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


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

int main()
{
    int N;
    cin >> N;
    vector<int> masu(N);
    for (int i=0; i<N; i++) cin >> masu[i];
    int answer=0;
    for (int i=0; i<N; i++)
    {
        if ((i+1)%2==1 && masu[i]%2==1) answer++;
    }
    cout << answer << endl;
}

Measured memory_bytes: 3616
# include <iostream>

using namespace std;
int main(){
    char aa;
   cin >> aa ;
   if (aa == 'A'){
       cout << 'T' << endl ;
       }else if (aa =='T'){
           cout << 'A' << endl;
       }else if (aa =='C'){
           cout << 'G' << endl;
       }else  if(aa == 'G'){
           cout <<  'C' <<endl;
            } 
            return 0;
    }

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define INF 0x3f3f3f

int max(int x,int y){return x>y?x:y;} 
int min(int x,int y){return x<y?x:y;}
int d[110][110];
void floyd(int n){
	for(int k=0;k<n;k++)
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	d[i][j]=min(d[i][j],(d[i][k]+d[k][j]));
}
void into(int n){
	memset(d,INF,sizeof(d));
	for(int i=0;i<n;i++)
		d[i][i]=0;
}
int main(){
	int n,m;
	int a,b,k;
	while(~scanf("%d",&n),n){
		into(12);
		m=0;
		for(int i=0;i<n;i++){
			scanf("%d%d%d",&a,&b,&k);
			d[a][b]=d[b][a]=k;
			m=max(max(a,b),m);
		}
		floyd(m+1);
		int minn=INF;
		int kase;
		for(int i=0;i<=m;i++){
			int ans=0;
			for(int j=0;j<=m;j++) ans+=d[i][j]; 
			if(ans<minn){
				minn=ans;
				kase=i;
			}
			
		}
		printf("%d %d\n",kase,minn);
	}
	return 0;
}


Measured memory_bytes: 2760
#include<iostream>
#include<string>
#include<cmath>
#include<vector>

int main(){
	long long a, b, c, k;
	std::cin>>a>>b>>c>>k;

	long long ans= 0;

	if(k<=a)
		ans= k;
	else if(k<= a+b) 
		ans= a;
	else
		ans= a-(k-a-b);

	std::cout<<ans<<std::endl;

	return 0;

}

Measured memory_bytes: 3608
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Set<Integer> a=new TreeSet<>();
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for(int i=0;i<n;i++)
        {
            a.add(in.nextInt());
        }
        System.out.println(a.size());
    }
}


Measured memory_bytes: 23636
#include<stdio.h>

#define Max 10000
#define NIL -1

struct Node{
  int p, l, r;
};
struct Node T[Max];
int n;

void P(int u){
  if(u == NIL)
       return;
  printf(" %d", u);
  P(T[u].l);
  P(T[u].r);
}


void in(int u){
  if(u == NIL)
     return;
  in(T[u].l);
  printf(" %d", u);
  in(T[u].r);
}


void post(int u){
  if(u == NIL)
       return;
  post(T[u].l);
  post(T[u].r);
  printf(" %d", u);
}




int main(){
  int i, v, l, r, root;

  scanf("%d", &n);
  for(i = 0 ; i < n ; i++){
    T[i].p = NIL;
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) 
            T[l].p = v;
    if(r != NIL)
            T[r].p = v;
  }

  for(i = 0 ; i < n ; i++){
       if(T[i].p == NIL)
        root = i;
  }

  printf("Preorder\n");
  P(root);
  printf("\n");
  printf("Inorder\n");
  in(root);
  printf("\n");
  printf("Postorder\n");
  post(root);
  printf("\n");
  return 0;
}


Measured memory_bytes: 2708
#include<stdio.h>
int main()
{   int n,nn,m,mm;
   scanf("%d%d",&n,&nn);
   scanf("%d%d",&m,&mm);
   if(n==2||n==4||n==6||n==9||n==11)
   {
   	   if(nn==30)
   	   {
		  printf("1\n");
   	   return 0;}
	}
		if(n==1||n==3||n==5||n==7||n==8||n==10||n==12)
   {
   	   if(nn==31)
   	   {
		  printf("1\n");
   	   return 0;}
	}
	if(n==2)
	{
		if(nn==28)
		{
		printf("1\n");
		return 0;}
	}
	printf("0\n");
} 

Measured memory_bytes: 128
#include <stdio.h>

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

void	ft_qsort(int *tab, int left, int right)
{
	int Left = left;
	int Right = right;
	int pivot = tab[(left + right) / 2];

	while (1)
	{
		while (tab[Left] < pivot)
			Left++;
		while (tab[Right] > pivot)
			Right--;
		if (Left >= Right)
			break ;
		ft_swap(&tab[Left], &tab[Right]);
		Left++;
		Right--;
	}

	if (Left - 1 > left)
		ft_qsort(tab, left, Left - 1);
	if (Right + 1 < right)
		ft_qsort(tab, Right + 1, right);
}

int	main(void)
{
	int N;
	scanf("%d", &N);
	int tab[N];
	int i = 0;
	while (i < N)
		scanf("%d", &tab[i++]);
	ft_qsort(tab, 0, N - 1);
	double max = tab[0];
	i = 1;
	while (i < N)
	{
		max += tab[i];
		max /= 2;
		i++;
	}
	printf("%f", max);
	return (0);
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
ll a,b,c,d;

ll cal(ll x){
	if(x<=0)return 0LL;
	return x-(x/c+x/d-x/(c*d/__gcd(c,d)));
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	cin >> a >> b >> c >> d;
	cout << cal(b)-cal(a-1);
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		static int overRedCount = 0;

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int[] a = in.nextIntArray(n);
			int[] color = new int[n];
			for (int i = 0; i < n; i++) {
				color[i] = getColor(a[i]);
			}

			Set<Integer> set = new HashSet<>();
			for (int i : color) {
				if (i == 0) continue;
				set.add(i);
			}

			int min = -1, max = -1;
			if (set.size() == 0) {
				min = 1;
				max = overRedCount;
			} else {
				min = set.size();
				max = set.size()+overRedCount;
			}

			out.println(min+" "+max);

		}

		static int getColor(int a) {
			int ret = 0;
			if (1 <= a && a <= 399) {
				ret = 1;
			} else if (400 <= a && a <= 799) {
				ret = 2;
			} else if (800 <= a && a <= 1199) {
				ret = 3;
			} else if (1200 <= a && a <= 1599) {
				ret = 4;
			} else if (1600 <= a && a <= 1999) {
				ret = 5;
			} else if (2000 <= a && a <= 2399) {
				ret = 6;
			} else if (2400 <= a && a <= 2799) {
				ret = 7;
			} else if (2800 <= a && a <= 3199) {
				ret = 8;
			} else if (3200 <= a) {
				overRedCount++;
			}
			return ret;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//////////////////

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

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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 (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)



void solve(){
    int N;
    cin >> N;
    map<string,int> m;
    while(N--){
        string s;
        cin >> s;
        m[s] ++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;

}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 3632
n,k = map(int,input().split())
a = list(map(int,input().split()))
ls = [a[:]]
for i in range(70):
  lsa = [0]*n
  for j in range(n):
    lsa[j] = ls[-1][ls[-1][j]-1]
  ls.append(lsa)
ans = 1
for i in range(71)[::-1]:
  if k&1<<i:
    ans = ls[i][ans-1]
print(ans)

Measured memory_bytes: 181884
using System;
using System.Linq;

namespace abc137_a
{
    static class Program
    {
        static void Main(string[] args)
        {
            var items = Console.ReadLine().ToIntArray();
            var a = items[0];
            var b = items[1];
            Console.WriteLine($"{Math.Max(a + b, Math.Max(a - b, a * b))}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static int[] ToIntArray(this string s, char separator = ' ')
        {
            return s.Split(separator).Select(m => m.ToInteger()).ToArray();
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V.at(i);
  sort(V.begin(), V.end());

  double ans = V.at(0);

  for (int i = 1; i < N; i++) {
    ans = (ans + V.at(i)) / 2.0;
  }

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

Measured memory_bytes: 256
MOD = 10**9+7

S = input()
N = len(S)
amari = [0 for _ in range(13)]


for i, s in enumerate(S):
    if i == 0:
        next_amari = [0 for _ in range(13)]
        if s != "?":
            number = int(s)
            now_amari = number * pow(10, N-1-i, 13) % 13
            next_amari[now_amari] = 1
        else:
            for number in range(10):
                now_amari = number * pow(10, N-1-i, 13) % 13
                next_amari[now_amari] += 1
        amari = next_amari
        continue

    next_amari = [0 for _ in range(13)]
    if s != "?":
        number = int(s)
        now_amari = number * pow(10, N-1-i, 13) % 13
        for j, n in enumerate(amari):
            next_amari[(j+now_amari) % 13] = n
    else:
        for number in range(10):
            now_amari = number * pow(10, N-1-i, 13) % 13
            for j, n in enumerate(amari):
                next_amari[(j+now_amari) % 13] = (n+next_amari[(j+now_amari) % 13])%MOD

    amari = next_amari
print(amari[5])


Measured memory_bytes: 45820
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

#define  kak 1000000000000;



int main(){
    ll A;
    ll B;

    cin >> A;
    cin >> B;
    if(A>=13){
        cout << B;
    }else if(A>=6 and A<=12){
        cout << ll(B/2);
    }else{
        cout << 0;
    }

    return 0;
}




Measured memory_bytes: 256
import Data.Array.IO
import Data.Array.Unboxed
import Control.Monad

type Graph = UArray (Int, Int) Int
type Memo = IOUArray (Int, Int, Int) Int

memoize :: Memo -> Graph -> Int -> Int -> Int -> IO Int
memoize m g i j k = do
    v <- readArray m (i, j, k)
    if v /= -1 then return v
    else do
        ans <- shortest_path m g i j k
        writeArray m (i, j, k) ans
        return ans

shortest_path :: Memo -> Graph -> Int -> Int -> Int -> IO Int
shortest_path m g i j (-1) = return $ g ! (i, j)
shortest_path m g i j k    = do
        d  <- memoize m g i j (k - 1)
        ik <- memoize m g i k (k - 1)
        kj <- memoize m g k j (k - 1)
        return $ min d (ik + kj)

read_int :: String -> Int
read_int = read

tokenize :: String -> [Int]
tokenize = map read_int . words

main = do
    getLine
    c <- forM [0..9] $ \i -> getLine
    let g_aslist = concat $ map tokenize c
    let g = listArray ((0, 0), (9, 9)) g_aslist :: Graph
    memo <- newArray ((0,0,-1), (9,9,9)) (-1) :: IO(Memo)
    wall <- filter (\x -> x >= 0) . map read_int . concat . map words . lines <$> getContents
    dists <- mapM (\x -> shortest_path memo g x 1 9) $ wall
    print . sum $ dists



Measured memory_bytes: 8572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main()
{
	string s, t;
	cin >> s >> t;
	int n = s.size();
	vector<int> snum(n), tnum(n);
	map<char, int> smp, tmp;
	int sc = 0, tc = 0;
	rep(i, n) {
		if (smp[s[i]] == 0) {
			smp[s[i]] = sc;
			snum[i] = sc;
			sc++;
		}
		else {
			snum[i] = smp[s[i]];
		}
		if (tmp[t[i]] == 0) {
			tmp[t[i]] = tc;
			tnum[i] = tc;
			tc++;
		}
		else {
			tnum[i] = tmp[t[i]];
		}
	}
	rep(i, n) {
		if (snum[i] != tnum[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
  	return 0;
}

Measured memory_bytes: 5432
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>
#include <queue>

#define int long long

int inf = (1LL <<  62);

using namespace std;

int re(int x, int y){
    if(x % y == 0){
        return y;
    }else{
        int z = x % y;
        return re(y, z);
    }
}

signed main(){
    int n;
    cin >> n;
    vector<int> v;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for(int i = 0; i < n - 1; i++){
        int b = max(v[i], v[i + 1]);
        int c = min(v[i], v[i + 1]);
        int a = b / re(b, c) * c;
        v[i + 1] = a;
    }
    cout << v[n - 1];
}


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

typedef vector<int> vi;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s;
	int i, r, rt = 0, l, ri, li, m, dr, dl;
	bool change = true;
	cin >> s;
	vi nums(s.size());
	for (i = 0; i < s.size(); i++) {
		if (i == 0 or s[i] != s[i - 1]) {
			change = !change;
			if (!change) {
				r = rt;
				rt = i;
			}
			if (change) {
				ri = i - 1;
				li = i;
			}
			if ((i > 0 and !change)) {
				l = i - 1;
				m = l - r + 1;
				if (m % 2 == 0) {
					nums[ri] = m / 2;
					nums[li] = m / 2;
				} else {
					dr = ri - r; dl = l - li;
					nums[ri] = ((dr + 1) % 2 ? m / 2 + 1 : m / 2);
					nums[li] = m - nums[ri];
				}
			}
		}
		if (i + 1 == s.size()) {
			r = rt;
			l = i;
			m = l - r + 1;
			if (m % 2 == 0) {
				nums[ri] = m / 2;
				nums[li] = m / 2;
			} else {
				dr = ri - r; dl = l - li;
				nums[ri] = ((dr + 1) % 2 ? m / 2 + 1 : m / 2);
				nums[li] = m - nums[ri];
			}
		}
	}
	for (i = 0; i < nums.size(); i++)
		cout << nums[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 1104
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
 
int main() {
    long long N, K;
    cin >> N >> K;
    long long a = N % K;
    long long b = abs(a - K);
    
    long long ans = 0;
    
    if(a>b){
        ans = b;
    }
    else{
        ans = a;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int count =0;
		int flag =0;
		int N = scanner.nextInt();
		int[] a = new int[N];
		
		for(int i=0; i<N;i++) {
			a[i] = scanner.nextInt();
		}
		
		for(int i=0;i<N-1;i++) {
			if(a[i] == a[i+1] && flag ==0) {
					count++;
					flag=1;
			}
			else {
				flag=0;
			}
		}
		
	    System.out.println(count);
		scanner.close();
	}

}


Measured memory_bytes: 22356
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int l = in.nextInt();
		double r = solve((double) l);
		System.out.println(r);
	}

	private static double solve(double l) {
		l /= 3;
		return l * l * l;
	}
}

Measured memory_bytes: 21460
h, w = map(int, input().split())
A = []
A.append(['.'] * (w + 2))
for i in range(h):
    A.append(['.'] + list(input()) + ['.'])
A.append(['.'] * (w + 2))

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if A[i][j] == '.':
            cnt = 0
            for k in range(-1, 2):
                for l in range(-1, 2):
                    if A[i + k][j + l] == '#':
                        cnt += 1
            A[i][j] = str(cnt)
            
for i in range(1, h + 1):
    print(''.join(A[i][1:w + 1]))

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

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

    vector<pair<int, int>> a(n);
    for (auto i = 0; i < n; i++) {
        a.emplace_back(0, 0);
        cin >> a[i].first;
    }
    
    if(a[0].first == 2){
        cout << 1 << endl;
        return 0;
    }
    
    bool flg = true;
    int next = a[0].first - 1, ans = 1;
    a[0].second++;
    while(true){
        if(a[next].first == 2) break;
        if(a[next].second != 0) {
            flg = false;
            break;
        }
        a[next].second++;
        next = a[next].first - 1;
        ans++;
    }

    if(not flg) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 1792
import scala.io.Source

object Main extends App {
  val Array(i, j) = Source.stdin.getLines.next.split(" ").map(_.toInt)

  def gcd(i: Int, j: Int): Int = {
    if (i % j == 0) j
    else gcd(j, i % j)
  }

  println(gcd(i, j))
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int prime[int(1e7) + 1];

ll calc(int x) {
  map<ll, ll> m;
  while (x > 1) {
    m[prime[x]]++;
    x /= prime[x];
  }
  ll ret = 1;
  for (auto [k, v] : m) {
    ret *= v + 1;
  }
  return ret;
}

int main() {
  in(ll, n);
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ll x = n / i;
    ans += i * x * (x + 1) / 2;
  }
  out(ans);
}


Measured memory_bytes: 3620
#include <iostream>

using namespace std;

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

int main() {
    int n;
    cin >> n;
    int A[n];
    for(int i = 0; i < n; i++) cin >> A[i];

    int x = partition(A, 0, n - 1);
    
    for(int i = 0; i < n; i++) {
        if(i) cout << " ";
        if(i == x) {
            cout << "[" << A[i] << "]";
        }
        else cout << A[i];
    }
    cout << endl;
}


Measured memory_bytes: 3384
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  ll ans = 0;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == '+')
      ans++;
    else
      ans--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

d = ni()
c = na()
s = []

for i in range(d):
    ss = na()
    s.append(ss)

last = [0]*26
score = 0

for i in range(1,d+1): # i日目
    t = ni()
    t-=1 # 0-index
    last[t] = i
    score += s[i-1][t]
    for j in range(26):
        score -= c[j]*(i-last[j])
    print(score)


score = max(10**6+score, 0)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

#define YES "YES"
#define NO "NO"

int main(int argc, char **argv) {
	string s;
	cin >> s;
	bool er = false;
	for (int i = 0; i < s.length();) {
		if (s[i] == 'e') {
			++i;
			if (i >= s.length() || s[i] != 'r') {
				cout << NO << endl;
				return 0;
			}
			++i;
			if (i < s.length() && s[i] == 'a') {
				++i;
				if (i + 1 >= s.length() || s[i] != 's' || s[i + 1] != 'e') {
					cout << NO << endl;
					return 0;
				}
				i += 2;
				if (i < s.length() && s[i] == 'r') ++i;
				er = true;
			}
			else if (er) {
				er = false;
			}
			else {
				cout << NO << endl;
				return 0;
			}
		}
		else if (s[i] == 'd') {
			++i;
			if (i + 3 >= s.length() || s[i] != 'r' || s[i + 1] != 'e' || s[i + 2] != 'a' || s[i + 3] != 'm') {
				cout << NO << endl;
				return 0;
			}
			i += 4;
			er = true;
		}
		else {
			cout << NO << endl;
			return 0;
		}
	}
	cout << YES << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	int N;
	cin >> N;
	vl A(N);
	for (auto& x : A)
		cin >> x;
	ll x = 0;
	for (int i = 0; i < N-1; ++i)
	{
		int d = max(A[i] - A[i + 1], 0LL);
		x += d;
		A[i+1] += d;
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
void func(vector<int> k){
	vector<int> k1(k.size());
	for(int i:k){
		k1[i-1]++;
	}
	for(int i:k1){
		cout<<i<<endl;
	}
	cout<<"0"<<endl;
}
int main(){
	int n;
	cin>>n;
	vector<int> k(n-1);
	for(int i=0;i<n-1;i++){
		cin>>k[i];
	}
	func(k);
}

Measured memory_bytes: 5544
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int ret = T.length();
		for(int i = 0 ; i <= S.length() - T.length() ; ++i){
			int change = 0;
			for(int j = 0 ; j < T.length() ; ++j){
				char cs = S.charAt(i + j);
				char ct = T.charAt(j);
				if(cs != ct){
					++change;
				}
			}
			ret = Math.min(ret, change);
		}
		System.out.println(ret);
	}
}


Measured memory_bytes: 35392
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
const int maxnfact = 100010;
const int md = 1e9+7;
int N, K;
int fact[maxnfact], fact_inv[maxnfact];
int A[maxnfact];

inline void add(int &a, int b) {
 a += b;
 if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int mdpow(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

void pre() {
  fact[0] = 1;
  fact_inv[0] = 1;
  for(int i = 1; i < maxnfact; i++){
    fact[i] = mul(fact[i-1], i);
  }
  fact_inv[maxnfact - 1] = mdpow(fact[maxnfact - 1], md - 2);
  for (int i = maxnfact-1-1; i >= 1; i--) {
    fact_inv[i] = mul(fact_inv[i+1], i+1);
  }
}

inline int nck(int n, int k) {
  return mul(mul(fact[n], fact_inv[n-k]), fact_inv[k]);
}

int main() {
  fastio;
  cin >> N >> K;
  pre();
  for (int i = 0; i < N; i++) { cin >> A[i]; }
  sort(A, A + N);
  int res = 0;
  for (int i = K-1; i < N; i++) {
    int val = A[i] + md; val %= md;
    int choose = nck(i, K-1);
    add(res, mul(val, choose));
  }

  for (int i = 0; i < N - K + 1; i++) {
    int val = A[i] + md; val %= md;
    int choose = nck(N - i - 1, K-1);
    sub(res, mul(val, choose));
  }
  cout << res << endl;
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int N;
    int l,r;
    int sum=0;
    cin >> N;
    for(int i=0; i<N; ++i) {
        cin  >> l >> r;
        sum+=r-l+1;
    }
    cout << sum << endl;
}


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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  vi64 v(4);
  i64 n;
  rep(i, 4) cin >> v[i];
  cin >> n;
  vi32 c = {0, 1, 2, 3};
  i64 ans = 1e18;
  do {
    i64 price = 0, rest = n * 4;
    rep(i, 4) {
      i64 cnt = rest / bit(c[i]);
      price += cnt * v[c[i]];
      rest -= cnt * bit(c[i]);
    }
    amin(ans, price);
  } while (next_permutation(all(c)));
  cout << ans << endl;
  return 0;
}


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

int main() {
	int n;
	std::cin >> n;

	std::set<int> set;
	for (int i = 0; i < n; ++i) {
		int a;
		std::cin >> a;

		set.insert(a);
	}

	std::cout << (set.size() == n ? "YES" : "NO") << std::endl;
}

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

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

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

    int now = 0;
    for(int i = 0; i < n; i++){
        if(A[i] == now + 1){
            now++;
        }
    }

    if(now > 0) cout << n - now << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 1024