akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int dsu[100010]; 
int fnd(int x){
	return (x == dsu[x]) ? x : dsu[x] = fnd(dsu[x]);
} 
void merge(int u, int v){
    dsu[fnd(u)] = fnd(v);
} 
int main(){
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		dsu[i] = i;	
	}
	int x, y, cnt = 0;
	for(int i = 1; i <= m; i++){
		cin >> x >> y;
		merge(x, y);
	}
	for(int i = 1; i < n; i++){
		if(fnd(i) != fnd(i+1)){
			merge(i, i+1);
			cnt ++;
		}
	}
	cout << cnt;
    return 0;
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
//#include <iostream>
//#include <algorithm>
//#include <vector>
//#include <prqueue>

using namespace std;

const int maxn=1e5+10;
const int inf=0x3f3f3f3f;

typedef long long ll;

vector<int> ve[maxn];

int main()
{
//	freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n,k;
	cin>>n>>k;
	int a,b;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a>k) continue;
		ve[k-a+1].push_back(b);
	}
	priority_queue<int> q;
	int earn=0;
	for(int i=k;i>=1;i--)
	{
		for(int v:ve[i]) q.push(v);
		if(!q.empty())
		{
			earn+=q.top();
			q.pop();
		}
	}
	cout<<earn;
	
	
	return 0;
 } 
 	 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
using namespace std;
bool good(int i)
{
	return (i%2==0 || i%3==0 || i%5==0);
}
int main()
{
	int n;
	scanf("%d",&n);
	if (n<=1003)
	{
		printf("2 3 25");
		for (int i=1;i<=n-3;i++)
		printf(" %d",30*i);
		return 0;
	}
	int sum=0,cnt=0;
	for (int i=1;cnt!=n;i++)
	{
		if (good(i))
		{
			if ((cnt==n-2 && !good(sum+i)) || (cnt==n-1 && (sum+i)%30))
			continue;
			sum=(sum+i)%30;
			printf("%d ",i);
			cnt++;
		}
	}
}

Measured memory_bytes: 384
n=int(input())
l=[input().split() for i in range(n)]
x=input()

ans=0
sum=0
for i,j in l:
 if i!=x:
  ans+=int(j)
 else:
  ans+=int(j)
  break
for i,j in l:
 sum+=int(j)
print(sum-ans)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define DRACO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define GO ll t; cin>>t; while(t--)
#define mod  1000000007
#define vect vector<long long int>
#define fore(p) for(auto& x:p)
#define bins binary_search
#define vecti vector<int>::iterator
#define bitout __builtin_popcount
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(), x.rend()
#define PY 3.141592653589793238
#define F first
#define S second
ll power(ll a,ll b){
    ll res = 1;
    while(b > 0)
    {
        if(b%2 == 1) res *= a;
        a *= a;
        b /= 2;
    }
    return res;
}
double dis(double a,double b ,double c , double d)
{
    return (sqrt((a-c)*(a-c)+(b-d)*(b-d)));
}

int main() 
{   DRACO
    ll i,j,k,l,n,m;
    cout.precision(10);
    //GO
    {   
        string s;
        cin >> s;
        
        ll sum = 0;
        fore(s)
        {
            sum += int(x-'0');
        }
        
        if(sum%9==0)
            cout<<"Yes";
        else
            cout<<"No";
        
    }
return 0;
}
//check the corner cases(n==1)
//try checking in reverse order
//check your logic again

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

int main() {

	string b; cin >> b;
	string  ans;
	if (b == "A") ans = "T";
	if (b == "T") ans = "A";
	if (b == "C") ans = "G";
	if (b == "G") ans = "C";	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3544
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String b = sc.nextLine();
        String str = "";
        switch(b){
            case "A":
                str = "T";
            break;
            case "T":
                str = "A";
            break;
            case "C":
                str = "G";
            break;
            case "G":
                str = "C";
            break;
            default:
            break;
        }
        System.out.println(str);
    }
}


Measured memory_bytes: 21076
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := n
	b := 0
	for a > 0 {
		b += a % 10
		a /= 10
	}

	if n%b == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int N;
vector<int> L;

int main(void) {
	cin >> N;
	L.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> L[i];

	int ans = 0;
	for (int i = 0; i < N - 2; ++i) {
		for (int j = i + 1; j < N - 1; ++j) {
			if (L[j] == L[i])
				continue;
			for (int k = j + 1; k < N; ++k) {
				if (L[k] == L[i] || L[k] == L[j])
					continue;
				int D[3] = { L[i], L[j], L[k] };
				sort(D, D + 3);
				if (D[0] + D[1] > D[2])
					++ans;
			}
		}
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define li long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pli pair<li,li>
#define pll pair<ll,ll>
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
#define tc int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define inf INT_MAX
#define ninf INT_MIN
#define W(x) cout<<x<<endl
#define WW(x,y) cout<<x<<' '<<y<<endl;
#define in(x) cin>>x
#define int long long
const ll mod = 998244353;
const ll mod2 = 1e9+7;
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
} 
template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}
struct Node{
    int first;int second;
    Node(int x,int y){
        this->first = x;
        this->second = y;
    }
};
struct comparator{
    bool operator()(const Node &a,const Node &b){
        int lena = a.second-a.first+1;
        int lenb = b.second-b.first+1;
        if(lena == lenb)return a.first<b.first;
        else return lena>lenb;
    }
};
ll power(ll x,ll y,ll mod){
    ll res = 1;
    x%=mod;
    while(y>0){
        if(y&1)res = (res*x)%mod;
        y>>=1;
        x = (x*x)%mod;
    }
    return res;
}

signed main() {
	int n;
	cin>>n;
	vector<int> a(n),b(n);
    for(int i = 0; i<n; i++){
        cin>>a[i]>>b[i];
    }
    sort(all(a)),sort(all(b));
    int l,r;
    if(n&1){
        l = a[n/2],r = b[n/2];
    }
    else{
        l = a[n/2]+a[n/2-1],r = b[n/2]+b[n/2-1];
    }
    cout<<(r-l+1)<<"\n";
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int m;
    cin >> m;
    int a[2 * m];
    for (int i = 0; i < 2 * m; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
        int res = 0;
        for (int j = 0; j < 2 * m; j++) {
            if (a[j] == i + 1) res++;
        }
        cout << res << "\n";
    }
    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;
    int b=0;
    cin>>n;
    for(int i=0; i<3; i++)
    {
        int a = n%10;
        n = n/10;
        if(a==7)
        {
            cout<<"Yes";
            b=1;
            break;
        }
    }
    if(b==0)
    {
        cout<<"No";
    }
    
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;

ll i,j,k;


int main(){
   ll A,B,C,D;
   cin>>A>>B>>C>>D;
   cout<<max(A*B,C*D)<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007

using namespace std;

int dp[3003][3003];

string extract_string(int dp[3003][3003],int n,int m,string s) {
	
	int i=n,j=m,k = dp[n][m];
	string ans="";
	
	while(i>=0 && j>=0 && k>0) {
		for(;i>=0;i--) {
			if(dp[i][j] != k) {
				break;
			}
		}
		
		i += 1;
		
		for(;j>=0;j--) {
			if(dp[i][j] != k) {
				break;
			}
		}
		
		j += 1;
		
		ans += s[j-1];
		i -= 1;
		j -= 1;
		k = dp[i][j];
	}
	
	reverse(ans.begin(),ans.end());
	
	return ans;
}

string lcs(string s,string t) {
	
	memset(dp,0,sizeof(dp)); // initalize 2d dp array with 0
	
	for(int i=1;i<=s.size();i++) {
		for(int j=1;j<=t.size();j++) {
			if(s[i-1] == t[j-1]) {
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else {
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	
	string ans = extract_string(dp,s.size(),t.size(),t); // extract common subsequence string from dp table
	
	return ans;
}

void input() {
	string s,t;
	cin>>s>>t;
	
	string k = lcs(s,t);
	cout<<k;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	input();
	
	return 0;
}


Measured memory_bytes: 38860
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,x = li()
a = li()

mins = [ai for ai in a]
a2 = a+a

ans = sum(mins)
for k in range(n):
    for i in range(n):
        mins[i] = min(mins[i],a2[i+k])
    
    temp = sum(mins)    
    ans = min(ans, temp + k*x)
    
print(ans)

Measured memory_bytes: 42860
n = int(input())
nums = list(map(int, input().split()))

# maekara は 前から当該までの最大公約数
# ushirokara は 後ろから当該までの最大公約数
import fractions

maekara = [-1] * n
ushirokara = [-1] * n

maekara[0] = nums[0]
for i in range(1, n):
    maekara[i] = fractions.gcd(maekara[i-1], nums[i])

ushirokara[-1] = nums[-1]
for i in reversed(range(n-1)):
    ushirokara[i] = fractions.gcd(ushirokara[i+1], nums[i])

ans = 0
for i in range(n):
    if i == 0:
        ans = max(ans, ushirokara[1])
    elif i == n-1:
        ans = max(ans, maekara[n-2])
    else:
        ans = max(ans, fractions.gcd(maekara[i-1], ushirokara[i+1]))
print(ans)


Measured memory_bytes: 14436
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll a[222222];
ll cnt[222222];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	int q; cin>>q;
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		sum+=a[i];
		cnt[a[i]]++;
	}
	while(q--)
	{
		ll x,y; cin>>x>>y;
		ll cur = cnt[x];
		sum-=cur*x;
		cnt[x]=0;
		sum+=cur*y;
		cnt[y]+=cur;
		cout<<sum<<'\n';
	}
}


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

int main(void){
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int x, y;
  if(A % D == 0){
    x = A / D;
  }else{
    x = A / D + 1;
  }
  if(C % B == 0){
    y = C / B;
  }else{
    y = C / B + 1;
  }

  if(y <= x){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main(){
	map<int,bool> memo;
	int N;
	cin>>N;
	int cnt=0;
	for(int i=0;i<N;i++){
		int p[3];
		cin>>p[0]>>p[1]>>p[2];
		sort(p,p+3);
		int k=((p[0]-1)*1000+(p[1]-1))*1000+(p[2]-1);
		if(memo.find(k)!=memo.end()){
			cnt++;
		}else{
			memo[k]=true;
		}
	}
	cout<<cnt<<endl;
	
	return 0;
}

Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  const int m=110;

  for(int x=1;x<m;x++){
    for(int y=1;y<m;y++){
      for(int z=1;z<m;z++){
        int tmp;
        tmp=x*x+y*y+z*z+x*y+y*z+z*x;
        if(tmp<=n) v[tmp-1]++;
      }  
    }
  }

  for(int i=0;i<n;i++){
    cout << v[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,s=0;
	cin>>n>>m;
	int a[n+1][m+1];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	} 
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int sum=0;
			for(int k=1;k<=m;k++){
				sum+=fabs(a[i][k]-a[j][k])*fabs(a[i][k]-a[j][k]);
			}
			if(int(sqrt(sum))==sqrt(sum)){
				s++;
			}
		}
	}
	cout<<s;
}


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

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

    int digit1=N%10;
    int digit2=(N/10)%10;
    int digit3=N/100;
    
    if (digit1==7 or digit2==7 or digit3==7) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3584
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e3+5 ,mod = 1e9+7 ;

int w ,h ,x ,y ;
int main(){
    cin >> w >> h >> x >> y ;
    cout << fixed << setprecision(6) << (long double)w*h/2 << " ";
    if(w%2==0 && h%2==0 && x==w/2 && y==h/2) cout << 1;
    else cout << 0;
    return 0;
}


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

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++) cin >> A[i];
  sort(A.rbegin(), A.rend());
  
  long long s = 1;
  int t = 1;
  int a = 0;
  int b = 0;
  for(int i = 1; i < N; i++){
    if(A[i - 1] == A[i]){
      if(t == 1) a = A[i];
      if(t == 2){
        b = A[i];
        break;
      }
      i++;
      t++;
    }
  }
  
  s = (long long)a * (long long)b;
  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 640
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=6023,M=12023};

ll f[4][M*2];

int main(){
	int n=ci(), mod=ci();
	f[0][N+0] = 1;
	f[1][N+1] = 1;
	f[2][N-1] = 1;
	f[2][N+2] = 1;
	rep(i,3,n*3){
		int I = i&3;
		rep(j,-i/2,i){
			f[I][N+j] = (f[(i-1)&3][N+j-1] 
					+ (i-1)*f[(i-2)&3][N+j+1]
					+ 1ll*(i-1)*(i-2)*f[(i-3)&3][N+j] ) %mod ;
		}
	}
	ll ans = 0;
	rep(i,0,n) ans=(ans+f[(n*3)&3][N+i*3])%mod;
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}


Measured memory_bytes: 512
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    map <int,int> m;
    int a[4][4];
    for (int i=1;i<=3;i++)
        for (int j=1;j<=3;j++) cin >> a[i][j];
    int n;cin>>n;
    while (n--){
        int a; cin>>a;
        m[a]++;
    } 
    for (int i=1;i<=3;i++){
        int c=0;
        for (int j=1;j<=3;j++){
            if (m[a[i][j]]) c++;
        }
        if (c==3) { 
            cout << "Yes" << endl; 
            return; 
        } 
    }
    for (int i=1;i<=3;i++){
        int c=0;
        for (int j=1;j<=3;j++){
            if (m[a[j][i]]) c++;
        }
        if (c==3) { 
            cout << "Yes" << endl; 
            return; 
        } 
    }
    int c=0;
    for (int i=1;i<=3;i++){
        if (m[a[i][i]]) c++;
    }
    if (c==3) { 
        cout << "Yes" << endl; 
        return; 
    } 
    if (m[a[3][1]] and m[a[2][2]] and m[a[1][3]]){ 
        cout << "Yes" << endl; 
        return; 
    } 
    cout << "No" << endl ; 
    return ; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3640
from collections import deque
N,M = map(int,input().split())
G = {i:[] for i in range(1,N+1)}
F = {i:[] for i in range(1,N+1)}
for _ in range(M):
    y,x = map(int,input().split())
    G[x].append(y)
    F[y].append(x)
A = []
hist = [0 for _ in range(N+1)]
for i in range(1,N+1):
    s = i
    if hist[s]==1:continue
    if G[s]:
        while G[s]:
            s = G[s][0]
    que = deque([s])
    A.append(s)
    hist[s] = 1
    while que:
        x = que.popleft()
        for y in F[x]:
            if hist[y]==0:
                G[y].remove(x)
                if len(G[y])==0:
                    que.append(y)
                    A.append(y)
#                     print("A={}".format(A))
                    hist[y]=1
#                     print("hist={}".format(hist))
dp = [0 for _ in range(N+1)]
for i in range(N-1):
    for x in F[A[i]]:
        dp[x] = max(dp[x],dp[A[i]]+1)
print(max(dp))

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

int main () {
  int h,n;
  cin >>h>>n;
  int a[n];
  int cnt=0;
  for (int i=0;i<n;i++){
    cin>>a[i];
  }
  for (int i=0;i<n;i++){
    cnt +=a[i];
  }
  if(h>cnt){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 640
#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)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> au(n), ab(n);
    rep(i, n) {
        int a; cin >> a;
        if (i==0) au[i] = a;
        else au[i] = au[i-1] + a;
    }
    rep(i, n) {
        int a; cin >> a;
        if (i==0) ab[i] = a;
        else ab[i] = ab[i-1] + a;
    }
    ll ans = 0;
    // n番目でしたに降りる
    rep(i, n) {
        ll tmp = au[i] + ab[n-1] - ab[i-1];
        chmax(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
nums = list(map(int, input().split()))
rn = nums[::-1]
ans = 0
tmp = 0

for i in range(N-1):
    if rn[i] <= rn[i+1]:
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 0
ans = max(ans, tmp)
print(ans)


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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

int main(void){
  int a,b,x;
  cin>>a>>b>>x;

  if(a>x){cout<<"NO"<<endl;}
  else if(a+b>=x)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;


return 0;}


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

int main()
{
  int n;
  int a[10000], b[10000];
  while (1)
  {
    cin >> n;
    if (n == 0) return 0;
    for (int i = 0; i < n; i++)
    {
      cin >> a[i] >> b[i];
    }
    int Ascore = 0, Bscore = 0;
    for (int i = 0; i < n; i++)
    {
      if (a[i] > b[i]) Ascore += a[i]+b[i];
      if (a[i] < b[i]) Bscore += a[i]+b[i];
      if (a[i] == b[i])
      {
        Ascore += a[i];
        Bscore += b[i];
      }
    }
    cout << Ascore << ' ' << Bscore << endl;
  }
}

Measured memory_bytes: 1236
#pragma once
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>

#define rep(name,begin,end,up) for(long long name = begin; name < end; name += up)
#define rev(name,begin,end,down) for(long long name = begin - 1; name >= end; name -= down)

using ll = long long;
using namespace std;


void abc154a(void) {

	string s, t, u;
	int a, b;

	cin >> s >> t;
	cin >> a >> b;
	cin >> u;

	if (s == u) {
		a--;
	}
	else {
		b--;
	}

	cout << a << " " << b << endl;

}


///*
int main(void) {

	abc154a();

	return 0;
}
//*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  int r=0, b=0;
  for ( int i=0; i<n; i++ ) {
    if ( s[i] == 'R' ) r++;
    else b++;
  }
  if ( r-b > 0 ) cout << "Yes" << '\n';
  else cout << "No" << '\n';
  return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
#include <boost/math/common_factor_rt.hpp>

long solve(int k)
{
  long sum = 0;
  for (int i = 1; i <= k; ++i) {
    for (int ii = 1; ii <= k; ++ii) {
      for (int iii = 1; iii <= k; ++iii) {
        const auto x = boost::math::gcd(i, ii);
        sum += boost::math::gcd(x, iii);
      }
    }
  }
  return sum;
}

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

  std::cout << std::setprecision(20);
  std::cout << solve(k) << std::endl;
}


Measured memory_bytes: 3640
from fractions import gcd

def fctr1(n): 
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    return f

a, b = map(int, input().split(" "))
g = gcd(a, b)

fct = fctr1(g)
#print(g, fct)

out = len(fct) + 1
print(out)

Measured memory_bytes: 5048
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N =scan.nextInt();
		Double a;
		double c=0;
		List<Double> b=new ArrayList<Double>();
		for(int count=0;count<N;count++){
			a=(double) scan.nextInt();
			b.add(1/a);
		}
		scan.close();
		for(int count=0;count<b.size();count++){
			c=b.get(count)+c;
		}
		System.out.println(1/c);
	}
}


Measured memory_bytes: 21716
#include <iostream>
using namespace std;
#define MAX 251

void print(){
}

int main(void){
  int n, H[MAX];
  cin >> n;
  for(int i=1; i<=n; i++){
    cin >> H[i];
  }

  for(int i=1; i<=n; i++){
    cout << "node " << i << ": ";
    cout << "key = " << H[i] << ", ";
    if(i != 1) cout << "parent key = " << H[i/2] << ", ";
    if(i * 2 < n + 1) cout << "left key = " << H[i * 2] << ", ";
    if(i * 2 + 1 < n + 1) cout << "right key = " << H[i * 2 + 1] << ", ";
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include<iomanip>
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;
vector<int> to[200005];
vector<int> ans; //グローバル変数にしておく
void dfs(int v,int p=-1){
  for(int u:to[v]){
    if(u==p) continue;
    ans[u]+=ans[v];
    dfs(u,v);
  }
}
int main() {
  int n,q; cin >> n >> q;
  ans.resize(n);
  for(int i=0;i<n-1;i++){
    int a,b; cin >> a >> b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
    ans.at(i)=0;
  }
  for(int i=0;i<q;i++){
    int p,x; cin >> p >> x; p--;
    ans[p]+=x;
  }
  dfs(0);
  for(int i=0;i<n;i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 23424
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    ll T=1, A=1;
    ll t,a;
    ll k;
    rep(i,n){
        cin >> t >> a;
        k = max((T+t-1)/t, (A+a-1)/a);
        T = k * t;
        A = k * a;
    }
    cout << T+A << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        q: usize,
        s: chars,
        lr: [(usize1, usize1); q]
    }

    let mut a = vec![0u64;n];
    for i in 0..n-1 {
        a[i] = (s[i] == 'A' && s[i+1] == 'C') as u64;
    }

    let mut sum = vec![0u64;n+1];
    for i in 0..n {
        sum[i+1] = sum[i] + a[i];
    }

    for i in 0..q {
        let (left,right) = lr[i];
        let delta = sum[right+1] - sum[left] - a[right];
        println!("{}", delta);
    }
}


Measured memory_bytes: 8956
n, m = map(int, input().split())
count = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    count[a] += 1
    count[b] += 1

for i in count:
    if i % 2 == 1:
        print("NO")
        exit()

print("YES")

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;

typedef struct st{
    ll val,pos,siz;
    st(ll _val,ll _pos,ll _siz):val(_val),pos(_pos),siz(_siz){}
    bool operator<(const st &s)const{
        return pos < s.pos;
    };
}ST;

int main(){
    while(cin >> n && n){
        vector<ST> v;
        v.push_back(st(-1,0,1e9));
        rep(i,n){
            string s;
            ll c,siz;
            cin >> s;
            if(s == "W"){
                cin >> c >> siz;
                rep(j,v.size()){
                    if(v[j].val == -1){
                        if(v[j].siz < siz){
                            siz -= v[j].siz;
                            v[j].val = c;
                        }
                        else{
                            v.push_back(st(-1,v[j].pos+siz,v[j].siz - siz));
                            v[j].siz = siz;
                            v[j].val = c;
                            break;
                        }
                    }
                }
            }
            else if(s == "D"){
                cin >> c;
                rep(j,v.size()){
                    if(v[j].val == c)v[j].val = -1;
                }
            }
            else{
                cin >> c;
                c++;
                rep(j,v.size()){
                    c -= v[j].siz;
                    if(c <= 0){
                        cout << v[j].val << endl;
                        break;
                    }
                }
                if(c > 0)cout << -1 << endl;
            }
            sort(ALL(v));
        }
        cout << endl;
    }
}


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

int main(){
  int year, month, day;
  char c1, c2;
  cin >> year >> c1 >> month >> c2 >> day;
  
  if (month <= 4)
  cout << "Heisei" << endl;
  else
  cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<sstream>
#include<algorithm>
using namespace std;

int main(){
   vector<int> Num;
   int Max,Min;
   int n,i,l,num,z;
   
   cin>>n;
   for(i=0;i<n;i++){
      cin>>num;
      
      while(num>0){
         z=num-(num/10*10);
         Num.push_back(z);
         num/=10;
      }
      sort(Num.rbegin(),Num.rend());
      z=1;
      for(l=0;l<(int)Num.size()-1;l++){
         z*=10;
      }
      Max=0;Min=0;
      for(l=0;l<(int)Num.size();l++){
         Max+=Num[l]*z;
         z/=10;
      }
      sort(Num.begin(),Num.end());
      z=1;
      for(l=0;l<(int)Num.size()-1;l++){
         z*=10;
      }
      for(l=0;l<(int)Num.size();l++){
         Min+=Num[l]*z;
         z/=10;
      }
      cout<<Max-Min<<endl;
      Num.clear();
   }
   return 0;
}

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

int main(void)
{
int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
int n;
cin>>n;
cout<<a[n-1];

return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) { // 素数ではない
			return false;
		}
	}
	// 素数である
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
/*ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}*/
//printf("%.10f\n", n);

signed main() {
	string s, t;
	ll n, m, k, a = 0, b = 0, c = 0, cnt = 0;
	cin >> n;
	if (n / 200 == 2) { cout << 8 << endl; }
	if (n / 200 == 3) { cout << 7 << endl; }
	if (n / 200 == 4) { cout << 6 << endl; }
	if (n / 200 == 5) { cout << 5 << endl; }
	if (n / 200 == 6) { cout << 4 << endl; }
	if (n / 200 == 7) { cout << 3 << endl; }
	if (n / 200 == 8) { cout << 2 << endl; }
	if (n / 200 == 9) { cout << 1 << endl; }

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int ans = 1;
    for (int i = 1; i <= m; i++) ans *= 2;
    printf("%d\n", ans * (1900 * m + n * 100 - m * 100));
    return 0;
}


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

int main(){
  int N,M; cin >> N >> M;
  int A[M]; for(int i=0; i<M; i++){A[i]=0;}
  
  int p,k;
  for(int i=0; i<N; i++){
    cin >> k;
    for(int j=0; j<k; j++){
      cin >> p;
      A[p-1] = A[p-1]+1;
    }
  }
  
  int s=0;
  for(int i=0; i<M; i++){
  	if(A[i]==N){s++;}
  }
  
  cout << s;
  
  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp_sol(int day[][3], int n, int act, int dp[][4])
{
	if(dp[n][act]!=-1)
		return dp[n][act];
	if(n==0)
		return day[0][act];
	else if(n<0)
		return 0;
	else
	{
		if(act==3)
			dp[n][act] = max(day[n][0] + max(dp_sol(day,n-1,1,dp),dp_sol(day,n-1,2,dp)), max(day[n][1] + max(dp_sol(day,n-1,0,dp), dp_sol(day,n-1,2,dp)), day[n][2] + max(dp_sol(day,n-1,0,dp), dp_sol(day,n-1,1,dp))));
		else if(act==0)
			dp[n][act] = day[n][0] + max(dp_sol(day,n-1,1,dp),dp_sol(day,n-1,2,dp));
		else if(act==1)
			dp[n][act] = day[n][1] + max(dp_sol(day,n-1,0,dp), dp_sol(day,n-1,2,dp));
		else if(act==2)
			dp[n][act] = day[n][2] + max(dp_sol(day,n-1,0,dp), dp_sol(day,n-1,1,dp));
		return dp[n][act];
	}
		
}
int main()
{
	int n,i,j;
	cin >> n;
	int day[n][3],dp[n][4];
	for(i=0;i<n;i++)
	{
		cin >> day[i][0] >> day[i][1] >> day[i][2];
	}
	if(n==1)
    	cout<<max(day[0][0],max(day[0][1], day[0][2]));
    else
    {
    	for(i=0;i<n;i++)
    	{
    		for(j=0;j<4;j++)
    		{
    			dp[i][j]=-1;
			}
		}
    	cout << dp_sol(day,n-1,3,dp);
	}
    	
}

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

using namespace std;

int main() {

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

    int A[M + 1];

    for (int i = 1; i <= M; i++) {
        cin >> A[i];
    }

    //cout << A[2] << endl;

    int homework = 0;

    for (int i = 1; i <= M; i++) {
        homework += A[i];
    }

    //cout << homework << endl;


    if (N >= homework) {
        cout << N - homework << endl;
    } else {
        cout << "-1" << endl;
    }

    return 0;
}

Measured memory_bytes: 3644
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var c string

func main() {
	sc.Split(bufio.ScanWords)
	c = nextStr()

	alphabet := "abcdefghijklmnopqrstuvwxyz"

	i := strings.Index(alphabet, c)
	fmt.Println(string(alphabet[i+1]))

}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <fstream>
#include <string>

using namespace std;

struct mondai {
	int suisen;
	int nanido;
	int number;
};
bool hyouka(mondai a, mondai b) {
	if (a.nanido == b.nanido) {
		return a.suisen >= b.suisen;
	}
	else {
		return a.nanido >= b.nanido;
	}
}


int main() {
	while (true) {
		string str;
		int y, m, d;
		cin >> str;
		if (str == "#") break;
		cin >> y >> m >> d;
		if (y > 31) {
			cout  << "? "<< y - 30 << " " << m << " " << d;
		}
		else if (y == 31 && m > 4){
			cout << "? " << y - 30 << " " << m << " " << d;
		}
		else {
			cout << "HEISEI " << y << " " << m << " " << d;
		}
		cout << endl;
	}
}



Measured memory_bytes: 3212
/*
*
*   Bismillah Hir Rahman Nir Raheem
*   Name: Jaied Al Sabid
*
*/

#include <iostream>
#include <string>
#include <bits/stdc++.h>

using namespace std;

#define pf printf
#define sf scanf
#define elf else if
#define Size 100


int main()
{
    int64_t a,b,k;
    int64_t r1,r2;
    cin>>a>>b>>k;

    if(k > a)
    {
        r1 = 0;
        k -= a;

        if(k>b)
        {
            r2 = 0;
            k -= b;
        }

        else
        {
            r2 = b-k;
        }
    }

    else{
        if(k<a)
        {
            r1 = a - k;
            k = 0;
            r2 = b - k;
        }

        else{
            k = 0;
            r1 = 0;
            r2 = b - k;
        }
    }

    cout<<r1<<" "<<r2<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}


// TODO: write
int main() {
  int n;cin>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  vector<int> ans;
  while(!a.empty()){
  
    for(int i = a.size()-1;i >= 0;--i){
      if(i+1 == a[i]){
        ans.pb(a[i]);
        a.erase(a.begin() + i);
        break;
      }
      if(i == 0){
        print(-1);
        return 0;
      }
    }
  }
  reverse(all(ans));
  rep(i,n)print(ans[i]);
  return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <math.h>
int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<=c && b<=c){
            printf("%d\n",c*10+b+a);
            return 0;
    }
    if(a<=b && c<=b){
        printf("%d\n",b*10+a+c);
        return 0;
    }
    if(b<=a && c<=a){
    printf("%d\n",a*10+b+c);
    return 0;
    }
}


Measured memory_bytes: 128
#include <stdio.h>

int main (void)
{
    int a, b, c, d;
    int n, ways;

    while (scanf ("%d", &n) != EOF){
        ways = 0;
        for (a = 0; a <= 9; a++){
            for (b = 0; b <= 9; b++){
                for (c = 0; c <= 9; c++){
                    for (d = 0; d <= 9; d++){
                        if (a + b + c + d == n)  ways++;
                    }
                } 
            }
        }
        printf("%d\n", ways);
    }
    return (0);
}


Measured memory_bytes: 2024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pi;
const int N=1e5+10;
int n,u,v,cnt,g[N];queue<pi> q;
map<pi,int> a;set<int> f[N];
int gfa(int x){return (g[x]^x)?gfa(g[x]):x;}
int main(){
    scanf("%d",&n);
    rep(i,1,n) g[i]=i;
    rep(i,1,2*n-2){
        scanf("%d%d",&u,&v),f[u].insert(v),f[v].insert(u),++a[mp(u,v)],++a[mp(v,u)];
        if(a[mp(u,v)]==2) q.push(mp(u,v));
    }
    while(!q.empty()){
        int u=q.front().fi,v=q.front().se;q.pop();
        u=gfa(u),v=gfa(v);
        if(f[u].size()<f[v].size()) swap(u,v);
        f[u].erase(v);f[v].erase(u);
        for(int x:f[v]){
            f[x].erase(v);f[u].insert(x);f[x].insert(u);
            ++a[mp(u,x)];++a[mp(x,u)];a[mp(v,x)]=a[mp(x,v)]=0;
            if(a[mp(u,x)]==2) q.push(mp(u,x));
        }++cnt;g[v]=u;
    }
    puts(cnt==n-1?"YES":"NO");
    return 0;
}

Measured memory_bytes: 61824
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

ll abs(ll x){
	if(x<0) return (-1)*x;
	return x;
}

int main()
{	
	int n,i,x,zer=0,pos=0,neg=0; cin>>n;
	vector<ll> a(n);
	for(i=0;i<n;i++){
		cin>>x; 
		if(x>0) pos++;
		if(x<0) neg++;
		if(x == 0) zer++;
		a[i] = abs(x);
	}

	sort(a.begin(), a.end());
	bool rempos = false;
	if(neg%2 == 0) rempos=true;
	else{
		if(zer>0) rempos=true;
		else rempos=false;
	}

	ll ans=0;
	for(i=1;i<n;i++) ans += a[i];

	if(rempos) ans += a[0];
	else ans -= a[0];

	cout<<ans;	
}

Measured memory_bytes: 1024
#include <stdio.h>

int min(int a, int b){
    if(a<b)return a;
    else return b;
}
int main(void){
    int n, k;
    scanf("%d", &n);
    scanf("%d", &k);
    
    int ans=0;
    for(int i=0; i<n; i++){
        int x;
        scanf("%d", &x);
        
        int a=x*2;
        int b=(k-x)*2;
        ans+=min(a, b);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1700
#include<bits/stdc++.h>
using ll = long long;
using  INT = long long;
#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 INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*........................................DEFINE FUNCTIONS.........................................*/


/*....................................DEFINE GLOBAL VARIABLES .....................................*/

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;
}



/*.........................................kemkemG0................................................*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N,K;
	cin>>N>>K;
	VI h(N);
	REP(i,N)cin>>h[i];
	sort(ALL(h));

	int ans=INF;
	for (int i = 0; i+K -1 < N; ++i)
	{
		chmin(ans,h[i+K-1] - h[i]);
	}

	cout<<ans<<endl;




	return 0;
}







Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa

using namespace std;

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  char ch; cin >> ch;
  cout << (char)(ch+1);
  return 0;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()

A = [0] * N
for i in range(1, N):
    if S[i - 1:i + 1] == 'AC':
        A[i] += 1

accA = [0] * (N + 1)
for i in range(1, N + 1):
    accA[i] = accA[i - 1] + A[i - 1]

for _ in range(Q):
    l, r = map(int, input().split())
    print(accA[r] - accA[l])


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

int main() {
int h,w;
cin>>h>>w;
char g[h][w];
int eh[h],ew[w];
for(int i=0;i<h;i++){
  for(int j=0;j<w;j++) cin>>g[i][j];
}

for(int j=0;j<h;j++) eh[j]=0;
for(int j=0;j<w;j++) ew[j]=0;

for(int i=0;i<h;i++){
  int c=0;
  for(int j=0;j<w;j++) if(g[i][j]=='.') c++;
  if(c==w) eh[i]=1;
}

for(int i=0;i<w;i++){
  int c=0;
  for(int j=0;j<h;j++) if(g[j][i]=='.') c++;
  if(c==h) ew[i]=1;
}

for(int i=0;i<h;i++){
  for(int j=0;j<w;j++) {
    if(eh[i]==0&&ew[j]==0) cout<<g[i][j];
  }
  if(eh[i]==0) cout<<endl;
}

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n;
    cin>>n;
    int can=false;
    for(int i=0;i<=n/4;i++){
        for(int j=0;j<=n/7;j++){
            if(4*i+7*j==n){
                can=true;
                break;
            }
        }
    }
    if(can==true){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<deque>
using namespace std;
int main(){
  int n; cin >> n;
  deque<int> v;
  if(n%2==0){
    for(int i=0;i<n;i++){
      int a; cin >> a;
      if(i%2==0) v.push_back(a);
      else v.push_front(a);
    }
  }else{
    for(int i=0;i<n;i++){
      int a; cin >> a;
      if(i%2==0) v.push_front(a);
      else v.push_back(a);
    }
  }
  for(int i=0;i<n-1;i++) cout << v[i] << " ";
  cout << v[n-1] << endl;
  return 0;
}

Measured memory_bytes: 2944
coin = [500, 100, 50, 10, 5, 1];
while(1):
    ipt = int(raw_input())
    if ipt==0: break
    ans = 0; rest = 1000-ipt;
    for i in range(6):
        while(rest>=coin[i]):
            rest-=coin[i]; ans+=1;
    print(str(ans))

Measured memory_bytes: 4216