akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
vector<llint> G[2005];
llint size[2005];
llint dp[2005][2005][3];
llint dp2[2005][2005][3];

const int FACT_MAX = 200005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint dfs(int v)
{
	size[v] = 1;
	for(int i = 0; i < G[v].size(); i++){
		size[v] += dfs(G[v][i]);
	}
	
	llint m = G[v].size();
	for(int i = 0; i <= m; i++){
		for(int j = 0; j <= size[v]; j++){
			for(int k = 0; k < 3; k++){
				dp2[i][j][k] = 0;
			}
		}
	}
	dp2[0][0][0] = 1;
	
	llint sum = 0;
	for(int i = 0; i < m; i++){
		llint u = G[v][i];
		for(int j = 0; j <= sum; j++){
			for(int k = 0; k < 3; k++){
				for(int s = 0; s <= size[u]; s++){
					for(int t = 0; t < 3; t++){
						llint mul = 1;
						if(t == 1) mul = 2;
						(dp2[i+1][j+s][k] += dp2[i][j][k] * dp[u][s][t] % mod * mul % mod) %= mod;
						
						if(k < 2 && t != 2){
							(dp2[i+1][j+s+1][k+1] += dp2[i][j][k] * dp[u][s][t] % mod) %= mod;
						}
					}
				}
			}
		}
		sum += size[u];
	}
	
	for(int j = 0; j <= size[v]; j++){
		for(int k = 0; k < 3; k++){
			dp[v][j][k] = dp2[m][j][k];
			if(k == 2) dp[v][j][k] *= 2, dp[v][j][k] %= mod;
		}
	}
	
	return size[v];
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	make_fact();
	
	cin >> n;
	llint p;
	for(int i = 2; i <= n; i++){
		cin >> p;
		G[p].push_back(i);
	}
	
	dfs(1);
	
	llint ans = 0;
	for(int i = 0; i <= n; i++){
		llint sum = 0;
		for(int j = 0; j < 3; j++){
			if(j == 1) dp[1][i][j] *= 2, dp[1][i][j] %= mod;
			sum += dp[1][i][j], sum %= mod;
		}
		llint tmp = fact[n-i] * sum % mod;
		if(i % 2) ans += mod - tmp, ans %= mod;
		else ans += tmp, ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 190976
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
typedef long long ld;


int main() {
  // violinista forever xd
  ios::sync_with_stdio(0),cin.tie(0);
  
  ll a,b,rta;	
  cin >> a>>b;
  a *= 100;
  b *= 100;
  rta = -1;
  bool aun = true;
  for (int i = 0; i < 100000 && aun; i++){
    if ((i * 8 - a) < 100 && (i * 8 - a) >= 0){
      if ((i * 10 - b) < 100 && (i * 10 - b) >= 0){
        rta = i;
        aun = false;
      }
    }
  }
  cout << rta << endl;
  return 0;
}

Measured memory_bytes: 3628
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han Elmuzaffer Daima
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

int n,m,cev,b,a[li],k;
string s;
vector<int> v;

int main(void){
	scanf("%d %d",&n,&m);
	if((n==1 || n==3 || n==5 || n==7 || n==8 || n==10 || n==12) && (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)){printf("Yes\n");return 0;}
	if((n==4 || n==6 || n==9 || n==11) && (m==4 || m==6 || m==9 || m==11)){printf("Yes\n");return 0;}
	if(n==2 && m==2){printf("Yes\n");return 0;}
	printf("No\n");
	return 0;
}


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

using namespace std;

int n;
int dp[100002][3];
int polje[100002][3];

int rek(int x, int y) {
    if (dp[x][y] != -1) return dp[x][y];

    int rj = 0;
    for (int i=0; i<3; i++) {
        if (i == y) continue;
        rj = max(rj, rek(x-1, i));
    }
    rj += polje[x][y];
    dp[x][y] = rj;
    return rj;
}

int main() {
    cin >> n;
    for (int i=0; i<n; i++) 
        for (int j=0; j<3; j++) 
            cin >> polje[i][j];
    
    memset(dp, -1, sizeof(dp));
    dp[0][0] = polje[0][0];
    dp[0][1] = polje[0][1];
    dp[0][2] = polje[0][2];

    cout << max(rek(n-1, 0), max(rek(n-1, 1), rek(n-1, 2))) << endl;

    return 0;
}


Measured memory_bytes: 10624
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define sc(x) scanf("%lld",&x)
    #define pf(x) printf("%lld\n",x)
    #define int long long
    #define all(x) x.begin(),x.end() 
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int INF = 1e15;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ DEB $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    int adj[MAX];
    int x;
    void solve()
    {
        cin>>n;
        fo(i,2,n+1)
        {
            cin>>x;
            adj[x]++;
            adj[i]++;
        }
        adj[1]++;
        fo(i,1,n+1)
        {
            cout<<adj[i]-1<<endl;
        }
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);

        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 5224
N = int(input())
D = {}
for _ in range(N):
    s = input()
    r = ''.join(sorted([c for c in s]))
    if r in D:
        D[r] += 1
    else:
        D[r] = 1
ans = 0
for v in D.values():
    ans += v*(v-1)//2
print(ans)


Measured memory_bytes: 17892
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
sunuke = [a[0]]
for i in range(1, n):
    sunuke.append(sunuke[-1]+a[i])
total = sunuke[-1]
res = 10000000000
for i in range(n-1):
    res = min(res, abs(sunuke[i]*2 - total))
print(res)


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

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)if(s[i]=='?')s[i]='D';
	cout<<s<<endl;
	/*int ret=0;
	for(int i=0;i<s.size();i++)if(s[i]=='D')ret++;
	for(int i=0;i+1<s.size();i++){
		if(s[i]=='P'&&s[i+1]=='D')ret++;
	}
	cout<<ret<<endl;*/
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main()
{
  char str[3];
  cin>>str;
  if((str[0]=='A' && str[1]=='A' && str[2]=='A')||(str[0]=='B' && str[1]=='B' && str[2]=='B'))
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

from collections import deque
# 木構造を作る
N,K = map(int, input().split())
G = [[] for i in range(N)]
for i in range(N-1):
    # グラフに頂点を追加(距離があるときは,u,vの後に入れる)
    u,v = map(int,input().split())
    G[u-1].append((v-1))
    G[v-1].append((u-1))

# print(G)

used = [False] * N
used[0] = True
mod = 10**9 + 7
cnt = 0
ans = K
def dfs(G, i, v):
    global cnt
    global ans 
    #グラフ中の次のVについて
    used[v] = True
    cnt += 1
    numv = 0
    for next_v in G[v]:
        # すでに見られていたら無視
        if used[next_v]: continue
        numv += 1
        ans %= mod
        if i <= 1:
            ans *= K-i-numv
        else:
            ans *= K - 1 - numv
        # print("v",v,"n{},cnt{},ans{}".format(numv,cnt,ans))
        ans %= mod
        dfs(G,i+1, next_v)



dfs(G,0,0)
print(ans%mod)


Measured memory_bytes: 90768
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%lld",&a)
#define sf2(a,b) scanf("%lld %lld",&a,&b)
#define sf3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld",a)
#define pf2(a,b) printf("%lld %lld",a,b)
#define pf3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
main()
{
    timesave;
    long n;
    while(cin>>n)
    {
        long i,a;
        double sum=0.0;
        for(i=1;i<=n;i++)
        {
            cin>>a;
            sum=sum+(1.0/a);
        }
        sum=1.0/sum;
        printf("%lf\n",sum);
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	string s,k="TBD";
	cin >> s;
	if (s.at(5) == '0' && (s.at(6) == '4'|| s.at(6) == '3' || s.at(6) == '2' || s.at(6) == '1')) {
		k = "Heisei";
	}
	cout << k << endl;
}

Measured memory_bytes: 256
print([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(input()) - 1])

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

int main(){
	long long N;
	int AC=0, WA=0, TLE=0, RE=0;
	scanf("%lld", &N);
	char a[N][5];
	for(int i=0;i<N;i++){
		scanf("%s", &a[i]);
		switch(a[i][0]){
			case 'A':
				AC++;
				break;
			case 'W':
				WA++;
				break;
			case 'T':
				TLE++;
				break;
			case 'R':
				RE++;
				break;
		}
	}
	printf("AC x %d\n", AC);
	printf("WA x %d\n", WA);
	printf("TLE x %d\n", TLE);
	printf("RE x %d\n", RE);
	
	return 0;
}

Measured memory_bytes: 2216
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        //String str[]=br.readLine().split(" ");
        int n=Integer.parseInt(br.readLine());
        if(n%2==0||n%5==0)
        pw.println(-1);
        else
        {
            int ans=-1;
            long cur=7;
            for(int i=1;i<=(int)1e6;i++)
            {
                if(cur%n==0)
                {
                    ans=i;
                    break;
                }
                cur*=10;
                cur+=7;
                cur%=n;
            }
            pw.println(ans);
        }
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 32744
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
#define INF 2e9
const int maxn=200000+10;
int n;
int a[maxn];
int L[maxn/2+2],R[maxn/2+2];
LL merge(int left,int mid,int right)
{
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++) L[i]=a[left+i];
    for(int i=0;i<n2;i++) R[i]=a[mid+i];
    L[n1]=INF,R[n2]=INF;
    int i=0,j=0;
    LL cnt=0;
    for(int k=left;k<right;k++)
    {
        if(L[i]<=R[j])
        {
            a[k]=L[i++];

        }
        else
        {
            a[k]=R[j++];
            cnt+=n1-i;
        }
    }
    return cnt;



}
LL merge_sort(int left,int right)
{
    if(right-left>1)
    {
        int mid=(left+right)/2;
        LL n1=merge_sort(left,mid);
        LL n2=merge_sort(mid,right);
        LL n3=merge(left,mid,right);
        return n1+n2+n3;
    }
    return 0;
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    cout<<merge_sort(0,n)<<endl;


    return 0;
}

Measured memory_bytes: 4684
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll t;
ll ret = 0;
string s;

void input() {
  IN(s);
}

void solve() {
  bool easy = true;
  REP(i, s.size()) {
    char c = s[i];
    if (i%2 == 0) {
      easy &= (c == 'R') || (c == 'U') || (c == 'D');
    } else {
      easy &= (c == 'L') || (c == 'U') || (c == 'D');
    }
  }
  PRINT(easy?"Yes":"No");
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256
N,K=map(int,input().split())
#print(N,K)
if K%2==0:
    if N>=K/2:
        a=int(1+(N-K/2)//K)
        b=int(N/K)
        print((a**3)+(b**3))
    else:
        print(0)
else:
    if N>=K:
        c=int(N/K)
        print(c**3)
    else:
        print(0)

Measured memory_bytes: 3060
N=int(input())
i=0
while i<N:
    a,b,c=map(int,input().split())
    if a*a==b*b+c*c or b*b==c*c+a*a or c*c==a*a+b*b:
        print('YES')
    else:
        print('NO')
    i+=1


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

int main(){

  cin.tie(0); //cin高速化
  ios::sync_with_stdio(false); //cin高速化
  
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  int min = *min_element(a.begin(),a.end());
  int max = *max_element(a.begin(),a.end());
  cout<<max-min<<endl;
  return 0;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005
#define INF 200005

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int n, m, p, ansa=0, pen=0;
string s;

int main(){
  cin >> n >> m;
  vector<bool> ac(n+1);
  vector<int> wa(n+1);
  rep(i, m){
    cin >> p >> s;
    if(s[0]=='A' && !ac[p]){
      ac[p]=true;
      ansa++;
      pen+=wa[p];
    } else if(s[0]=='W') {
      wa[p]++;
    }
  }

  cout << ansa << " " << pen << endl;
  return 0;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a+b>c+d) cout << "Left" << endl;
    else if (a+b==c+d) cout << "Balanced" << endl;
    else if (a+b<c+d) cout << "Right" << endl;
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(combinations_with_replacement(KK,3))
    for i in I:
        ls=len(set(i))
        if ls==1:
            ans+=reduce(gcd,i)
        elif ls == 2:
            ans+=reduce(gcd,i)*3
        else:
            ans+=reduce(gcd,i)*6





    print(ans)


resolve()

Measured memory_bytes: 192376
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> a(N,0);
    vector<ll> b(N,0);
    vector<ll> c(M,0);
    vector<ll> d(M,0);

    rep(i,N) cin >> a[i] >> b[i];
    rep(i,M) cin >> c[i] >> d[i];

    rep(i,N){
        ll tmp = MOD;
        ll ans;
        rep(j,M){
            if((abs(a[i] - c[j]) + abs(b[i] - d[j])) == tmp) continue;
            tmp = min((abs(a[i] - c[j]) + abs(b[i] - d[j])), tmp);
            if((abs(a[i] - c[j]) + abs(b[i] - d[j])) == tmp){
                ans = j + 1;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int f[2][500005];
int main(){
	int n,mx=0;
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&f[0][i]);
	}
	for(int i=1;i<=n;++i){
		scanf("%d",&f[1][i]);
	}
	for(int i=1;i<=n;++i){
		f[0][i]+=f[0][i-1];
		f[1][n-i+1]+=f[1][n-i+2];
	}
	for(int i=1;i<=n;++i)mx=max(mx,f[0][i]+f[1][i]);
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;

int n, t, l, b;
set<int> L, B;
double dp[102][101];

void solve(){
	L.clear(); B.clear();
	rep(i,102) rep(j,101) dp[i][j] = 0.0;
	dp[0][0] = 1.0;
	rep(i,l){
		int tmp; cin >> tmp;
		L.insert(tmp);
	}
	rep(i,b){
		int tmp; cin >> tmp;
		B.insert(tmp);
	}
	rep(i,t){
		dp[i+1][n] = dp[i][n];
		for(int j = 0; j < n; j++){
			for(int k = 1; k <= 6; k++){
				int z = j+k;
				if(z > n){
					z -= n;
					z = n-z;
				}
				if(L.count(z)){
					dp[i+2][z] += dp[i][j]*1.0/6;
				} else if(B.count(z)){
					dp[i+1][0] += dp[i][j]*1.0/6;
				} else{
					dp[i+1][z] += dp[i][j]*1.0/6;
				}
			}
		}
	}
	printf("%.9f\n",dp[t][n]);
}

int main(){
	while(true){
		cin >> n >> t >> l >> b;
		if(n == 0 && t == 0 && l == 0 && b == 0) break;
		solve();
	}
}

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

typedef long long ll;
// typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

string S;
string ABC = "ABC";

int main() {
  cin >> S;
  int N = S.size();

  ll dp[100010][4] = {};
  for(int i = N; i >= 0; --i){
      for(int j = 3; j >= 0; --j){
          if(i == N){
              dp[i][j] = (j == 3 ? 1 : 0);
          }else{
              dp[i][j] = dp[i+1][j] * (S[i] == '?' ? 3LL : 1LL);
              if(j < 3 && (S[i] == '?' || S[i] == ABC[j])){
                  dp[i][j] += dp[i+1][j+1];
              }
              dp[i][j] %= MOD;
          }
      }
  }
  cout << dp[0][0] << endl;
}


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

int main() {
  long long n,a,b,ans;
  cin>>n>>a>>b;
  if((a-b)%2==0)ans=abs(a-b)/2;
  else{
    ans=min((a+b-1)/2,(2*n-a-b+1)/2);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
def main():
    N=int(input())
    A=list(map(int,input().split()))

    dp=[[0 for i in range(N+1)] for _ in range(N+1)]

    A_index=[i for i in range(N)]

    AA=zip(A,A_index)
    AA=sorted(AA,reverse=True)
    A,A_index=zip(*AA)

    for i in range(N):
        for j in range(N-i):
            score=dp[i][j]

            dp[i+1][j]=max(dp[i+1][j],score+A[i+j]*(A_index[i+j]-i))
            dp[i][j+1]=max(dp[i][j+1],score+A[i+j]*((N-1-j)-A_index[i+j]))

    res=0
    for i in range(N+1):
        res=max(res,dp[i][N-i])

    print(res)

if __name__=="__main__":
    main()


Measured memory_bytes: 101244
s=list(input())
k=int(input())
l=[chr(i) for i in range(97, 97+26)]
for i in range(len(s)-1):
  if (26-l.index(s[i]))%26<=k:
    k-=(26-l.index(s[i]))%26
    s[i]='a'
s[len(s)-1]=l[(l.index(s[len(s)-1])+k)%26]
print(''.join(s))

Measured memory_bytes: 4156
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll A[N];
  vector<ll> arr;
  for(ll i=0;i<N;++i) {
    cin>>A[i];
    arr.push_back(A[i]);
  }
  sort(arr.begin(), arr.end());
  map<ll, ll> amap;
  for(ll i=0;i<N;++i) {
    amap[arr[i]] = i%2;
  }
  int ans = 0;
  for(ll i=0;i<N;++i) {
    if(amap[A[i]]!=i%2) ans++;
  }
  cout<<ans/2<<endl;
}



Measured memory_bytes: 11168
#include <iostream>
//#include <algorithm>
//#include <vector>
//#include <string>
using namespace std;
//#include <stdio.h>

 
int main(void)
{
    long long n, i, ans = 0;
    cin >> n;
    for(i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            long long k = n / i;
            ans = 0;
            while(k > 0) {
                k /= 10;    ans++;
            }
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

string s;

int main() {

    cin >> s;

    if (s[2] == s[3] && s[4] == s[5]) {
        puts("Yes");
    } else {
        puts("No");
    }

    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ABC170C
#include <set>
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int X,N;
    cin>>X>>N;
    set<int>st;
    // 答えの範囲は０〜１０１になる
    for (int i=0; i<=101; i++) {
        st.insert(i);
    }
    int p;
    for (int i=0; i<N; i++) {
        cin>>p;
        st.erase(p);
    }
    int min=1001001001;
    int min_num=101;
    for(auto q:st){
        int d=abs(X-q);
        if(min>d){
            min=d;
            min_num=q;
        }
    }
    cout<<min_num<<endl;
    return 0;
}


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

int main(){
  int H, W;
  
  while(cin >> H >> W){
    if(H==0 && W==0){
      return 0;
    }
    else{
      for(int i=0; i<H; i++){
	for(int j=0; j<W; j++){
	  cout << "#";
	}
	cout << endl;
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 1156
K = int(input())
A,B = map(int,input().split())
A_amari = A % K
B_amari = B % K
if A_amari == 0 or B_amari == 0:
	print("OK")
elif B_amari < A_amari:
	print("OK")
elif B - A >= K:
	print("OK")
else:
	print("NG")

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,L;
  cin >> N >> L;
  
  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  
  string s;
  for (int i = 0; i < N; i++) {
    s += vec.at(i);
  }
  
  cout << s << endl;
}

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

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

    int n, m, x; cin >> n >> m >> x;
    int sum_a = 0, sum_b = 0;
    REPI(i, m){
        int y; cin >> y;
        if(y < x) sum_a++;
        else sum_b++;
    }cout << min(sum_a, sum_b);
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;

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

    struct point
    {
        int x;
        int y;
    };

    vector<point> vR(N);

    REP (i, N)
    {
        int x, y;
        cin >> x >> y;
        vR[i] = {x, y};
    }

    vector<point> vB(N);

    REP (i, N)
    {
        int x, y;
        cin >> x >> y;
        vB[i] = {x, y};
    }

    // 赤 x 大きい
    ALL (sort, vR, [](const point& f, const point& s){return s.x < f.x;});

    // 青 y 小さい
    ALL (sort, vB, [](const point& f, const point& s){return f.y < s.y;});

    vector<bool> B(N, false);
    vector<bool> R(N, false);

    int cnt = 0;
    REP (i, N)
    {
        REP (j, N)
        {
            if (R[i] || B[j]) continue;
            if (vB[j].x <= vR[i].x) continue;
            if (vB[j].y <= vR[i].y) continue;

            cnt++;
            R[i] = true;
            B[j] = true;
        }
    }

    cout << cnt << endl;
    return 0;
}


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

using namespace std;

const long long INF = 1e18;

struct dat {
    int x, y;
    bool operator < (const dat& T) const {
        return x + y < T.x + T.y;
    }
}a[5005];

long long dp[5005][5005];

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

    for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y);

    sort(a + 1, a + n + 1);

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) dp[i][j] = INF;
    }

    dp[0][0] = 0;

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            if (j - 1 >= 0 && dp[i - 1][j - 1] <= a[i].x) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + a[i].y);
        }
    }

    for (int i = n; i >= 0; i--) {
        if (dp[n][i] != INF) return 0 * printf("%d\n", i);
    }
}



Measured memory_bytes: 195840
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

using ll = long long;

#define FOR(i, m, n) for (ll i = m; i <= n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)

int gcd(int a, int b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
    ll N, R;
    cin >> N >> R;
    ll r = (100 * (10 - N));
    cout << R + (r < 0 ? 0 : r) << endl;
    return 0;
}


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

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

  long ans = 1;
  for (int i = 1; i <= N; i++) {
    ans = (ans * i) % 1000000007;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
S = gets.chomp

list = [*'a'..'z'] - S.chars.uniq

if list.empty?
  idx = 25

  S.chars.reverse.each_cons(2).with_index do |(a, b), i|
    if a > b
      break
    end

    idx = 25 - i - 1
  end

  if idx == 0
    puts -1
  else
    head = idx - 2 < 0 ? '' : S[0..idx-2]
    puts head + S[idx..-1].chars.sort.select { |c| c > S[idx-1] }.first
  end
else
  puts S + list.first
end


Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
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; }
//#define int long long

void solve() {
	int n, m; cin >> n >> m;
    vector<vector<char>> a(n, vector<char>(n));
    vector<vector<char>> b(m, vector<char>(m));
    rep(i, n) {
        rep(j, n) {
            cin >> a[i][j];
        }
    }
    rep(i, m) {
        rep(j, m) {
            cin >> b[i][j];
        }
    }
    rep(i, n - m + 1) {
        rep(j, n - m + 1) {
            bool flag = true;
            rep(p, m) {
                rep(q, m) {
                    if(b[p][q] != a[p + i][q + j]) flag = false;
                }
            }
            if(flag) {
                cout << "Yes" << endl;
                return;
            }
        }
    }
    cout << "No" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

#define NMAX 100005
#define MOD 1000000007

#define f cin
using namespace std;

//ifstream f("date.in");
vector<long long int> a[NMAX];
vector<long long int> b[NMAX];
long long int n;
long long int dp[NMAX][2];
long long int putere_doi[NMAX];
long long int vis[NMAX];

void solve(long long int x) {
    vis[x] = 1;
    for (int i = 0; i < a[x].size(); ++i) {
        int vecin = a[x][i];
        if (vis[vecin] == 0) {
            b[x].push_back(vecin);
            solve(vecin);
        }
    }
}

long long int adauga_suma(vector<long long int> vect, long long int &s, long long int current_index) {
    if (current_index == vect.size()) return -1;
    if (current_index == vect.size() - 1) {
        long long int vecin = vect[current_index];
        //s = (s + ((dp[vecin][0] + dp[vecin][1]) % MOD)) % MOD;
        return ((dp[vecin][0] + dp[vecin][1]) % MOD);
    }
    long long int curr_ans =  adauga_suma(vect, s, current_index + 1);
    long long int vecin = vect[current_index];
    // s = (s + ((dp[vecin][0] + dp[vecin][1]) * curr_ans) % MOD ) % MOD;
    return (((dp[vecin][0] + dp[vecin][1]) * curr_ans) % MOD);

}

void calc_sum(long long int x) {
    /// 0 -> alb
    /// 1 -> negru
    for (long long int i = 0; i < b[x].size(); ++i) {
        long long int vecin = b[x][i];
        calc_sum(vecin);
    }
    if (b[x].size() == 0) {
        dp[x][0] = 1;
        dp[x][1] = 1;
    } else {
        long long int sum = 1;
        for (long long int i = 0; i < b[x].size(); ++i) {
            int vecin = b[x][i];
            sum = (sum * dp[vecin][0]) % MOD;
        }
        dp[x][1] = sum;
        long long int sum_negru = 0;
        long long int nr = b[x].size();
        long long int curr_ans = 1;
        for (int i = b[x].size() - 1; i >= 0; --i) {
            int vecin = b[x][i];
            curr_ans = (curr_ans * (dp[vecin][0] + dp[vecin][1]) % MOD ) % MOD;
        }
        sum_negru = curr_ans;
        dp[x][0] = sum_negru;


    }

}

int main() {

    f >> n;
    for (long long int i = 0; i < n - 1; ++i) {
        long long int x, y;
        f >> x >> y;
        x --;
        y --;
        a[x].push_back(y);
        a[y].push_back(x);
    }

    solve(0);
    calc_sum(0);

    long long int ans = (dp[0][0] + dp[0][1]) % MOD;

    /*for (int i = 0; i < n; ++i) {
        cout << dp[i][0] << " " << dp[i][1] << "\n";
    }*/

    cout << ans;
    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(0);

    string s;
    cin >> s;
    int x=0;
    int n=s.length();
    for(int i=0;i<n;i++)
        x^=(1<<(s[i]-'a'));
    if(x) puts("No");
    else puts("Yes");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
 
int main()
{
  int N, mochis[100], count = 1;
  std::cin >> N;
  
  for(int i = 0; i < N; i++)
  {
    std::cin >> mochis[i];
  }
  
  for(int i = 0; i < N; i++)
  {
    for(int k = 0; k < N; k++)
    {
      if(mochis[i] > mochis[k])
      {
        int temp = mochis[i];
        mochis[i] = mochis[k];
        mochis[k] = temp;
      }
    }
  }

  for(int i = 0; i < N - 1; i++)
  {
    if(mochis[i] != mochis[i + 1])
    {
      count++;
    }
  }  
  
  std::cout << count;
  return 0;
}

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>

using namespace std;
typedef long long ll;

void solve(ll n)
{
	if(n == 0)	return;
	
	if(n % 26 == 0)							// 被26整除不需要进位，单独处理
	{
		solve((n - 1) / 26);
		printf("z");
	}
	else									// 进制转换的正常处理方法 
	{
		solve(n / 26);
		printf("%c", n % 26 + 'a' - 1);
	}
}

int main()
{
	ll n;
	scanf("%lld", &n);
	
	solve(n);
	
	return 0;
}

Measured memory_bytes: 3720
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const lines = content
    .trim()
    .split('\n')
    .slice(0, -1);

  const result = lines.map(num =>
    num
      .split('')
      .map(n => parseInt(n, 10))
      .reduce((prev, cur) => prev + cur)
  );

  console.log(result.join('\n'));
});


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()
auto &errStream = cerr;
#ifdef LOCAL
#define cerr (cerr << "-- line " << __LINE__ << " -- ")
#else
class CerrDummy {
} cerrDummy;
template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) {
  return cd;
}
using charTDummy = char;
using traitsDummy = char_traits<charTDummy>;
CerrDummy &operator<<(CerrDummy &cd,
                      basic_ostream<charTDummy, traitsDummy> &(
                          basic_ostream<charTDummy, traitsDummy> &)) {
  return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr << "reached" << endl
#define DMP(x) cerr << #x << ":" << x << endl
#define ZERO(x) memset(x, 0, sizeof(x))
#define ONE(x) memset(x, -1, sizeof(x))

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

#define CAPITAL
void Yes(bool ex = true) {
#ifdef CAPITAL
  cout << "YES" << endl;
#else
  cout << "Yes" << endl;
#endif
  if (ex)
    exit(0);
}
void No(bool ex = true) {
#ifdef CAPITAL
  cout << "NO" << endl;
#else
  cout << "No" << endl;
#endif
  if (ex)
    exit(0);
}

const ll infLL = LLONG_MAX / 3;

#ifdef int
const int inf = infLL;
#else
const int inf = INT_MAX / 2 - 100;
#endif

signed main() {
  int A = read(), B = read();

  if (A <= 8 && B <= 8)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256
def gcd(a,b)
  if a % b == 0
    return b
  else
    return gcd(b,a%b)
  end
end

while gets != nil
  a,b = $_.split.map(&:to_i).sort
  c = gcd(a,b)
  d = a*b/c
  puts c.to_s + " " + d.to_s
end



Measured memory_bytes: 6836
#include<stdio.h>
#include<stdlib.h>
struct node{
  struct node *r,*l,*p;
  int key;
};
typedef struct node * Node;
#define NIL NULL
Node root;
Node treeMinimum(Node a){
  while(a->l != NIL)a = a->l;
  return a;
}
Node treeMaximum(Node a){
  while(a->r != NIL)a = a->r;
  return a;
}
Node treeSearch(Node a,int b){
  while(a != NIL && b != a->key){
    if(b < a->key)a = a->l;
    else a = a->r;
  }
  return a;
}
Node treeSuccessor(Node a){
  if(a->r != NIL)return treeMinimum(a->r);
  Node b = a->p;
  while(b != NIL && a == b->r){
    a = b;
    b = b->p;
  }
  return b;
}
void treeDelete(Node a){
  Node b,c;
  if(a->l == NIL || a->r == NIL)b = a;
  else b = treeSuccessor(a);
  if(b->l != NIL)c = b->l;
  else c = b->r;
  if(c != NIL)c->p = b->p;
  if(b->p == NIL){
    root = c;
  }
  else {
    if(b == b->p->l)b->p->l = c;
    else b->p->r = c;
  }
  if(b != a){
    a->key = b->key;
  }
  free(b);
}
void insert(int a){
  Node b=NIL,c=root,d;
  d = malloc(sizeof(struct node));
  d->key = a;
  d->l = NIL;
  d->r = NIL;
  while(c != NIL){
    b = c;
    if(d->key < c->key){
      c = c->l;
    }
    else {
      c = c->r;
    }
  }
  d->p = b;
  if(b == NIL){
    root = d;
  }
  else {
    if(d->key < b->key){
      b->l = d;
    }
    else {
      b->r = d;
    }
  }
}
void inorder(Node a){
  if(a == NIL)return;
  inorder(a->l);
  printf(" %d",a->key);
  inorder(a->r);
}
void preorder(Node a){
  if(a == NIL)return;
  printf(" %d",a->key);
  preorder(a->l);
  preorder(a->r);
}
int main(){
  int n,i,x;
  char com[20];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(strcmp(com,"find") == 0){
      scanf("%d",&x);
      Node t =treeSearch(root,x);
      if(strcmp(com,"findMin") == 0){
	Node minn = treeMinimum(t);
	printf("%d\n",minn->key);
      }
      else if(strcmp(com,"findMax") == 0){
	Node maxn = treeMaximum(t);
	printf("%d\n",maxn->key);
      }
      else {
	if(t != NIL)printf("yes\n");
	else printf("no\n");
      }
    }
    else if(com[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(com,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(strcmp(com,"delete") == 0){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }

  return 0;
}



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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    string s;
    cin >> s;

    LL L = s.size();

    LL x = 0, ans = 0;
    for(LL i = 1; i < L; i++){
        if(s[i] != s[i - 1])
            x++;
    }

    ans = x;
    x = 0;
    for(LL i = L - 2; i >= 0; i--){
        if(s[i] != s[i + 1])
            x++;
    }

    cout << min(ans, x) << '\n';
    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define MAX 105
#define INF (1e8)
int K,N,M;
int T;
 
bool g[MAX][MAX];
int G[MAX][MAX];
int C[MAX];
int tmp[MAX][MAX];
 
bool visited[MAX];
bool used[MAX];
 
void copyA(){
  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      tmp[i][j]=G[i][j];
}
void copyB(){
  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      G[i][j]=tmp[i][j];
}
 
 
 
int dfs(int pos,int ti,int f){
  if(pos==ti)return f;
  visited[pos]=true;
  for(int tt=0;tt<=T;tt++){
    int to=tt;
    if(to==-1)to=T;
     
    if(visited[to])continue;
    if(G[pos][to]==0)continue;
     
    int k=dfs(to,ti, min(f,G[pos][to]) );
    if(k>0){
      G[pos][to]-=k;
      G[to][pos]+=k;
      return k;
    }
  }
  return 0;
}
 
int maxFlow(int si,int ti){
  if(si==ti)return INF;
  int res=0;
  while(1){
    memset(visited,false,sizeof(visited));
    int f=dfs(si,ti,INF);
    if(f==0)break;
    res+=f;
 
  }
  return res;
}
int calcC(int id){
  if(C[id]!=-1)return C[id];
  copyA();
  if(used[id]){
    C[id]=maxFlow(T,id);
  }else{
    C[id]=maxFlow(id,0);
  }
  copyB();
  return C[id];
}
 
int main(){
  memset(C,-1,sizeof(C));
   
  bool isOverfuro=false;
  cin>>K>>N>>M;
  T=N+K+1;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==0&&1<=b&&b<=K){
      isOverfuro=true;
    }
    if(b==0&&1<=a&&a<=K){
      isOverfuro=true;
    }
    G[a][b]+=c;
    G[b][a]+=c;
    g[a][b]=true;
    g[b][a]=true;
  }
   
  for(int i=1;i<=K;i++){
    G[T][i]=INF;
  }
 
  if(isOverfuro){
    cout<<"overfuro"<<endl;
    return 0;
  }
 
  int F=maxFlow(T,0);
  assert(F>0);
   
  memset(visited,false,sizeof(visited));
  dfs(T,0,INF);
   
  for(int i=0;i<=T;i++){
    used[i]=visited[i];
  }
 
  C[0]=INF;
   
  int ans=0;
  for(int i=0;i<T;i++){
    for(int j=0;j<T;j++){
      if(i==j)continue;
      if(G[i][j]==0&&g[i][j]==true && used[i]==true && used[j]==false ){
        calcC(i);
        calcC(j);
        ans=max(ans, min(C[i],C[j]) );
      }
    }
  }
  cout<<F+ans<<endl;
  return 0;
}

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

typedef long long ll;

char s1[5];
char s2[5];
char n[10];

int main()
{
    scanf("%s %s",s1,s2);
    strcpy(n,s1);
    strcat(n,s2);
    ll a;
    sscanf(n," %lld",&a);
    ll b=(ll)sqrt((double)a);
    if(b*b==a)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int dir(int a){
    int cnt = 0;
    FOR(i,1,a+1){
        if(a%i==0) cnt++;
    }
    return cnt;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int ans = 0;
    FOR(i,1,n+1){
        if(i%2==0) continue;
        else if(dir(i) == 8) ans++;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a,b,c;
	cin >> a >> b >> c;
	for(ll i=1; i<=1000; i++){
		ll x=(a*i)/b;
		if(a*i-x*b==c){
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
	return 0;
}

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

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

Measured memory_bytes: 256
#include <iostream>

int main()
{
    int input;
    int hour;
    int min;
    int sec;
    std::cin >> input;
    hour = (input - (input % 3600)) / 3600;
    input -= hour * 3600;
    min = (input - (input % 60)) / 60;
    input -= min * 60;
    sec = input;
    std::cout << hour << ":" << min << ":" << sec << std::endl;
    return 0;
}

Measured memory_bytes: 3088