akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <deque>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <map>
#include <stack>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

string s;
int K;

int main(void)
{
    cin >> s;
    cin >> K;
    vector<int> a(s.size());
    for(int i = 0; i < s.size(); i++){
        a[i] = 'z' - s[i] + 1;
    }

    int k = K;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'a'){
            continue;
        }

        if(k - a[i] >= 0){
            k -= a[i];
            a[i] = 26;
            s[i] = 'a';
        }
    }

    int l = s.size() - 1;
    k = k % 26;
    for(int i = k; i > 0; i--){
        if(s[l] == 'z'){
            s[l] = 'a';
        }
        else{
            s[l]++;
        }
    }

    printf("%s\n", s.c_str());
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> ball(n);
  vector<int> count(n);
  for(int i = 0;i <= n - 1;i++)ball[i] = 1;
  for(int i = 0;i <= n - 1;i++)count[i] = 0;
  count[0] = 1;
  //int now = 0;
  //now = 0;
  for(int i = 0;i <= m - 1;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    if(count[a] == 1){
      if(ball[a] == 1)count[a] = 0,count[b] = 1;
      else count[a] = 1,count[b] = 1;
      //now = b;
    }
    ball[a]--;
    ball[b]++;
    /*cout << "ball " << ball[0] << " " << ball[1] << " " << ball[2] << endl;
    cout << "count " << count[0] << " " << count[1] << " " << count[2] << endl;
    cout << "now" <<  now << endl;*/
  }
  int res = 0;
  for(int i = 0;i <= n - 1;i++)if(count[i] == 1)res++;
  cout << res << endl;
  return 0;
}

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

int zyoutai[50][50], dp[51][51], a, b;
int main() {
	memset(dp, 1, sizeof(dp));
	dp[1][0] =dp[0][1]= 0;
	cin >> a >> b;
	for (int c = 0; c < a; c++) {
		for (int d = 0; d < b; d++) {
			scanf("%1d", &zyoutai[c][d]);
		}
	}
	for (int e = 0; e < a; e++) {
		for(int f=0;f<b;f++){
			dp[e + 1][f + 1] = min(dp[e][f + 1], dp[e + 1][f]) + zyoutai[e][f];
		}
	}
	cout << dp[a][b] << endl;
}

Measured memory_bytes: 3236
t=[]
alphabet={}
alphabet=dict.fromkeys(list("abcdefghijklmnopqrstuvwxyz"),0)
while True:
    try:
        word=str(input())
        a=str.lower(word)
        t.append(a)
    except EOFError:
        break
t.sort()

for w in t:
    for c in w:
        try:
            alphabet[c] +=1
        except KeyError:
            pass
for k, v in alphabet.items():
    print(f'{k} : {v}')



Measured memory_bytes: 5576
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int nn = n;
        int s = 0;
        while (nn > 0) {
            s += nn % 10;
            nn /= 10;
        }

        if (n % s == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String ws[] = {"Sunny", "Cloudy", "Rainy"};
		String s = sc.next();
		for(int i = 0 ; i < ws.length ; ++i){
			if(ws[i].equals(s)){
				int j = (i + 1) % ws.length;
				System.out.println(ws[j]);
				break;
			}
		}
	}
}


Measured memory_bytes: 21204
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

int main()
{
	int n;

	cin >> n;

	vector<int> a(n);

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

	int x = 0;
	int cnt = 0;
	int i = 1;
	while (1) {
		x = a[i - 1];
		a[i - 1] = -1;
		i = x;
		cnt++;
		if (x == -1) {
			cout << -1 << endl;
			break;
		}
		if (x == 2) {
			cout << cnt << endl;
			break;
		}
	}

	return (0);
}

Measured memory_bytes: 640
#coding:utf-8

N = int(input())

A = [int(y) for y in input().split()]

lif = [0] * (10 ** 5 + 1)
sasa = 0

for y in A:
    lif[y] += 1
    sasa += y

Q = int(input())

k = 0

for i in range(Q):
    
    b,c = map(int,input().split())

    k = lif[b]

    lif[c] += k
    lif[b] = 0
    sasa += (k * (c - b))

    print("{}".format(sasa))

Measured memory_bytes: 20928
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll k;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>k;
    ll n = 50;
    Vi a(50,49);
    ll tmp = k%50;
    rep(i,tmp){
        a[i]+=n-tmp+1;
    }
    repi(i,tmp,n){
        a[i] -= tmp;
    }
    print(n);
    rep(i,n-1){
        princ(a[i]+k/50);
    }
    print(a[n-1]+k/50);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var NQ = ReadLine().Split().Select(int.Parse).ToArray();
        var N = NQ[0];
        var Q = NQ[1];
        var S = ReadLine();
        var l = new int[Q];
        var r = new int[Q];
        for (int i = 0; i < Q; i++)
        {
            var line = ReadLine().Split();
            l[i] = int.Parse(line[0]);
            r[i] = int.Parse(line[1]);
        }

        var T = S.Replace("AC", "BD");

        var sum = new int[N + 1];
        for (int i = 0; i < N; i++)
        {
            sum[i + 1] = sum[i] + (T[i] == 'D' ? 1 : 0);
        }
        for (int i = 0; i < Q; i++)
        {
            WriteLine(sum[r[i]] - sum[l[i]]);
        }
    }
    
}


Measured memory_bytes: 17736
import math


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


N, M = map(int, input().split())
divisors = make_divisors(M)
ans = 1
for d in divisors:
    if d*N <= M:
        ans = max(ans, d)
print(ans)


Measured memory_bytes: 3060
#!/usr/bin/env python
# -*- coding: utf-8 -*-
x,y=[int(x) for x in input().split()]
mod=10**9+7

def inv(a,n,mod):
    result=1
    while n>0:
        if n & 1==1:
            result*=a
            result%=mod
        a=a*a%mod
        n >>=1
    return result%mod

if (2*x-y)<0 or (2*y-x)<0 or (2*x-y)%3 !=0 or (2*y-x)%3!=0:
    print(0)
else:
    # p+2q=x
    # 2p+q=y
    p=(2*y-x)//3
    q=(2*x-y)//3
    ans=1
    for i in range(q):
        ans*=(p+q-i)%mod
        ans%=mod
        ans*=inv(i+1,mod-2,mod)
        ans%=mod
    print(ans)

Measured memory_bytes: 41708
import sys
from collections import deque
readline = sys.stdin.readline
n, q = map(int, input().split())
f = lambda a, b: (a, int(b))
dq = deque(f(*readline().split()) for _ in range(n))
cnt = 0
ans = []
while dq:
    s, t = dq.popleft()
    if t <= q:
        cnt += t
        ans.append(f"{s} {cnt}")
    else:
        cnt += q
        dq.append((s, t - q))
print(*ans, sep="\n")



Measured memory_bytes: 13392
#include<bits/stdc++.h>
using namespace std;
/*void mayank()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}*/
#define ll long long
#define inf 1e9
const int mxN = 1e5;
//ll a[mxN + 1], b[mxN + 1];

struct item
{
	int wt;
	int val;
};

ll solve(vector<item>ar, int n, int W) {
	ll dp[n + 1][W + 1];

	for (int w = 0; w <= W; w++)
		dp[1][w] = 0;

	dp[1][ar[1].wt] = ar[1].val;

	for (int i = 2; i <= n; i++) {
		for (int w = 0; w <= W; w++) {
			dp[i][w] = dp[i - 1][w];

			if (ar[i].wt > w)
				continue;

			dp[i][w] = max(dp[i][w], ar[i].val + dp[i - 1][w - ar[i].wt]);
		}
	}

	return *max_element(dp[n], dp[n] + W + 1);
}
int main()
{
	//mayank();
	int n, w;
	cin >> n >> w;
	vector<item>ar(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> ar[i].wt >> ar[i].val;
	}
	cout << solve(ar, n, w);

	return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=200005;
const int MOD=1000000007;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())

int N,M;
int U[MAXN],V[MAXN];
bool ans[MAXN];

vector<int>adj[MAXN];
bool C[MAXN];
int o[MAXN];
int f(int x){return o[x]==x?x:o[x]=f(o[x]);}
void merge(int x, int y){o[f(x)]=f(y);}
bool D[MAXN];
const int LOGN=20;
int h[MAXN];
int p[MAXN][LOGN+1];

void dfs(int v, int par, int d){
	h[v]=d;
	p[v][0]=par;
	FOR(k,1,LOGN){
		if(p[v][k-1]!=-1){
			p[v][k]=p[p[v][k-1]][k-1];
		}
	}
	for(auto i:adj[v])if(i!=par){
		dfs(i,v,d+1);
	}
}
void dfs2(int v, int par){
	for(auto i:adj[v])if(i!=par){
		dfs2(i,v);
		D[v]^=D[i];
	}
}
//~ int lca(int a, int b){
	//~ if(h[a]>h[b])swap(a,b);
	//~ int d=h[b]-h[a];
	//~ FOR(k,0,LOGN)if(d&(1<<k))b=p[b][k];
	//~ assert(h[a]==h[b]);
	//~ if(a==b)return a;
	//~ DEC(k,LOGN,0)if(p[a][k]!=p[b][k])a=p[a][k],b=p[b][k];
	//~ assert(p[a][0]==p[b][0]);
	//~ return p[a][0];
//~ }
bool intree[MAXN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	memset(p,-1,sizeof p);
	cin>>N>>M;
	if(M&1){
		cout<<"-1\n";
		return 0;
	}
	FOR(i,1,N)o[i]=i;
	FOR(i,1,M){
		int a,b;cin>>a>>b;
		U[i]=a;V[i]=b;
		C[V[i]]^=1;
		if(f(a)==f(b))continue;
		merge(a,b);
		//~ cout<<a<<' '<<b<<" tree\n";
		adj[a].pb(b);
		adj[b].pb(a);
		intree[i]=true;
	}
	//~ FOR(i,1,N)cout<<C[i]<<" \n"[i==N];
	dfs(1,-1,0);
	//~ FOR(i,1,N)cout<<h[i]<<" \n"[i==N];
	//~ FOR(i,1,N)FOR(k,0,5)cout<<p[i][k]<<" \n"[k==5];
	//~ db(lca(1,2));
	//~ return 0;
	int prv=-1;
	FOR(i,1,N){
		if(!C[i])continue;
		if(prv==-1)prv=i;
		else{
			//~ cout<<prv<<' '<<i<<' '<<lca(prv,i)<<" prvi\n";
			D[prv]^=1;
			D[i]^=1;
			prv=-1;
		}
	}
	//~ FOR(i,1,N)cout<<D[i]<<" \n"[i==N];
	dfs2(1,-1);
	//~ FOR(i,1,N)cout<<D[i]<<" \n"[i==N];
	FOR(i,1,M){
		if(!intree[i])cout<<V[i]<<' '<<U[i]<<"\n";
		else if(h[U[i]]<h[V[i]]){
			if(D[V[i]])cout<<U[i]<<' '<<V[i]<<"\n";
			else cout<<V[i]<<' '<<U[i]<<"\n";
		}
		else{
			if(D[U[i]])cout<<U[i]<<' '<<V[i]<<"\n";
			else cout<<V[i]<<' '<<U[i]<<"\n";
		}
	}
	
}
/*
*/


Measured memory_bytes: 34304
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

const int mod = 1000000007;

int main(){
  int x;
  cin >> x;
  x *= 2;
  bool prime[x+1];
  for(int i=0;i<=x;i++) prime[i] = true;
  prime[0] = prime[1] = false;
  for(int i=2;i<=x;i++){
    if(prime[i]){
      for(int j=i+i;j<=x;j+=i){
        if(j%i == 0) prime[j] = false;        
      }
    }
  }

  for(int i=x/2;i<x;i++){
    if(prime[i]){
      cout << i << endl;
      break;
    }
  }

}


Measured memory_bytes: 384
s = input()

s_cnt, t_cnt = 0, 0
t = 0
for i in s:
    if i == "S":
        s_cnt += 1
    if s_cnt == 0 and i == "T":
        t += 1
    if s_cnt != 0 and i == "T":
        s_cnt -= 1
    s_cnt = max(s_cnt, 0)

print(2*t)

Measured memory_bytes: 3500
from math import sqrt
#from math import floor
def is_prime(n):
	if n<4:
		return True
	else:
		s = int(sqrt(n))
		for i in range(2, s+1):
			if not n%i:
				return False
		return True
n = int(input())
count = 0
for i in range(n):
    if is_prime(int(input())):
        count += 1
print(count)



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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
char a;
	cin >> a;
	if (a>='A'&&a<='Z') {
		ce("A")
	}
	else {
		ce("a")
	}
    return 0;
}



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

using namespace std;

typedef long long ll;

#define pb push_back
#define fo(i, n) for(int i = 1; i <= n; ++i)

const int mod = 1e9 + 7;
const int N = 400012;
const int inf = 2e9;
vector<pair<int, pair<int, int> > > ans;

inline void add_edge(int u, int v, int len) {
    ans.pb({u, {v, len}});
}
int f[N];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n = 20;
    int l;
    cin >> l;
    l--;
    int cur = 0;
    for(int i = 1; i < n; ++i) {
        add_edge(i, i + 1, 0);
    }
    int pw = 1;
    f[1] = 1;
    for(int i = 1; i < n; ++i) {
        if(cur * 2 + 1 <= l)
            cur = cur * 2 + 1, f[i+1] = cur+1, add_edge(i, i + 1, pw), pw *= 2;
    }
    int ned = l - cur;
    for(int i = n - 1; i >=  1; --i) {
        if(f[i] && f[i] <= ned) {
            add_edge(i, n, cur+1);
            ned -= f[i];
            cur += f[i];
        }
    }
    cout << n << ' ' << ans.size() << '\n';
    for(auto &x :ans) {
        cout << x.first << ' ' << x.second.first << ' ' << x.second.second << '\n';
    }
    return 0;
}

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

namespace cswork
{

    class Program
    {
        public Program() { }

        Scanner cin;

        void Omame()
        {
            cin = new Scanner();
            long n = cin.nextLong();
            List<int> list = new List<int>();
            for (int i = 0; i < n; i++)
            {
                list.Add(cin.nextInt());
            }

            list.Sort();

            int ans = 1;
            for (int i = 1; i < n; i++)
            {
                if (list[i -1] < list[i])
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <queue>
#include <numeric>
#include <algorithm>
#include <set>
using namespace std;

string reverse(string str){
	string rev = "";
	for(int i=str.size()-1; i>=0; i--){
		rev += str[i];
	}
	return rev;
}

int main(){

	int m; cin >> m;
	for(int i=0; i<m; i++){
		set<string> train;
		string s; cin >> s;
		int l = s.size();
		for(int j=1; j<l; j++){
			string first = s.substr(0, j);
			string second = s.substr(j);
			train.insert(first + second);
			train.insert(first + reverse(second));
			train.insert(reverse(first) + second);
			train.insert(reverse(first) + reverse(second));
			train.insert(second + first);
			train.insert(second + reverse(first));
			train.insert(reverse(second) + first);
			train.insert(reverse(second) + reverse(first));
		}
		cout << train.size() << endl;
	}


	return 0;
}

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

int main(){
  int A,B;
  int out;
  cin >> A;
  cin >> B;
  
  if(A<1 || A>9 || B<1 || B>9){
    out = -1;
  }
  else{
    out = A*B; 
  }
  cout << out;
  
  return 0;
}



Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
one = 0
four = 0
two = 0

for j in range(N):

  if a[j]%2 == 1:
    one += 1
  elif a[j]%4 == 0:
    four += 1
  else :
    two +=1

print("Yes" if four >= one or (four == one - 1 and two == 0) else "No")

Measured memory_bytes: 14252
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct Node{
  int key;
  struct Node *right,*left,*parent;
};

struct Node *root,*NIL;

void insert(int k){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  z=malloc(sizeof(struct Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
    while(x!=NIL){
    y=x;
    if(z->key < x->key){x=x->left;}
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else {
    if(z->key < y->key) y->left=z;
    else y->right=z;
  }
}

void inorder(struct Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(struct Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  char *str1="insert";
  char *str2="print";
  char tmp[1000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",tmp);
    if(strcmp(tmp,str1)==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(tmp,str2)==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25144
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1e18;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  vi a(3);
  cin>>a;
  sort(rng(a));
  int ans = a[2]-a[0];
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr uint64_t INF = 1e18;

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

  string N;
  cin >> N;
  int64_t sum = 0;
  for (int i = 0; i < (int) N.size(); i++) {
    int v = (int)(N[i] - '0');
    sum += v;
  }
  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }



  return 0;
}


Measured memory_bytes: 3708
import sys

num =int(input())
alf =input()
if num%2==1:
  print("No")
  sys.exit()
l=num/2
for i in range(int(l)):
	if not alf[i]==alf[int(l)+i]:
		#print(alf[i])
		#print(alf[int(l)+i])
		print("No")
		sys.exit()
print("Yes")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,h,n;
  cin>>w>>h>>n;
  int minx=101;
  int maxx=0;
  int miny=101;
  int maxy=0;
  for(int i=0;i<n;i++){
    int a,b,c;
    cin>>a>>b>>c;
    if(c==1){maxx=max(maxx,a);}
    else if(c==2){minx=min(minx,a);}
    else if(c==3){maxy=max(maxy,b);}
    else{miny=min(miny,b);}
  }
  cout<<max(0,min(minx,w)-maxx)*max(0,min(h,miny)-maxy);
}

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

int main(){
	int a;
	int b;
	cin>>a;
	cin>>b;
	string s;
	if (a==b){
		s=" == ";
	}else if(a<b){
		s=" < ";
	}else{
		s=" > ";
	}
	std::cout<<'a'<<s<<'b'<<std::endl;
}


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

int main()
{
    vector<long long int> ans;
       long long int x,y,a,b,c;
       cin>>x>>y>>a>>b>>c;
       vector<long long int> p;
       vector<long long int> q;
       for(long long int i=0;i<a;i++)
       {
           long long int o;cin>>o;p.push_back(o);}
          
    for(long long int i=0;i<b;i++)
    {
        long long int o;cin>>o;
        q.push_back(o);
    }
    for(long long int i=0;i<c;i++)
    {
        long long int o;cin>>o;
        ans.push_back(o);
    }
    
    sort(p.begin(),p.end(),greater<long long int>());
    sort(q.begin(),q.end(),greater<long long int>());
    
    for(long long int i=0;i<x;i++)
    ans.push_back(p[i]);
    
    for(long long int i=0;i<y;i++)
        ans.push_back(q[i]);
    
    
     sort(ans.rbegin(),ans.rend());
     long long int xxx  = 0;
     for(int i= 0;i<x+y;i++)
     {
         xxx += ans[i];
     }
       
      cout<<xxx<<endl; 
       
}


Measured memory_bytes: 7920
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast_io cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define MOD 1000000007
using namespace std;

int main(){
	fast_io;
	map<ll,ll> m;
    ll n;
    cin>>n;
    ll a[n];
    cin>>a[0];
    ll k = a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        k = k^a[i];
    }
    if(k==0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}



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

typedef long long ll;

void printArray(vector<int> arr) {
	for (int a: arr) cout << a << " ";
	cout << '\n';
}

int main() {
	std::ios_base::sync_with_stdio(false);
	int x,y;
	cin >> x >> y;
	bool verdict = (y%2==0 && y >= 2*x && 4*x >= y);
	cout << (verdict ? "Yes" : "No") << '\n';
	
}



Measured memory_bytes: 3576
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  st s,t;
  	ci(s>>t);
  ll ans=0;
  FOR(i,0,3){
    if(s[i]==t[i]){
      ans++;
    }
  }
  co(ans)
}


Measured memory_bytes: 1024
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

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

int ab(int a, int b){return a>b?a-b:b-a;}

int main(void){
	int n, i;
	int a[100002];
	scanf("%d", &n);
	a[0]=a[n+1]=0;
	for(i=1; i<=n; i++){
		scanf("%d", a+i);
	}
	int sum=0;
	for(i=0; i<=n; i++){
		sum+=ab(a[i], a[i+1]);
	}
	for(i=1; i<=n; i++){
		if(((a[i-1]-a[i])&INT_MIN) == ((a[i]-a[i+1])&INT_MIN)){
			printf("%d\n", sum);
		}else{
			printf("%d\n", sum+ab(a[i-1], a[i+1])-ab(a[i-1], a[i])-ab(a[i], a[i+1]));
		}
	}
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    vector<long long int> ans(N);

    long long int k = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
        k += B[A.at(i)]++;
    }
    
    for (int i = 0; i < N; i++)
        cout <<  k - B[A.at(i)] + 1 << endl;
    
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cmath>

using namespace std;

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

    if (n <= 99) {
        cout << int(n * pow(100, d)) << endl;
    } else {
    	cout << int(101 * pow(100, d)) << endl;
    }
}

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

int main(){
    int n;
    cin>>n;
    vector<pair<long long, long long>> p(n);
    for(int i=0;i<n;++i){
        long long a,b;
        cin>>a>>b;
        p[i]=make_pair(b,a);
    }
    
    sort(p.begin(),p.end());
    long long sum=0;
    for(int i=0;i<n;++i){
        sum+=p[i].second;
        if(sum>p[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 6400
#include <iostream>
#define mx 1000000000
using namespace std;
long long mat[510][510];
int main(){
	int a,b,c,d,i,j;
	long long sum=0;
	cin >> a >> b >> c >> d;
	if(a%c==0 && b%d==0){
		cout << "No" << endl;
		return 0;
	}
	for(i=0;i<a;i++){
		for(j=0;j<b;j++){
			if(i%c==0 && j%d==0){
				mat[i][j] = mx-1;
			}else if(i%c==c-1 && j%d==d-1){
				mat[i][j] = -mx;
			}else{
				mat[i][j] = 0;
			}
			sum += mat[i][j];
		}
	}
	if(sum>0){
		cout << "Yes" << endl;
		for(i=0;i<a;i++){
			for(j=0;j<b;j++){
				cout << mat[i][j] << " " ;
			}
			cout << endl;
		}
	}else{
		cout  << "No" << endl;
	}
}

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

using namespace std;

vector< int > z_algorithm(const string &s) {
    vector< int > prefix(s.size());
    for(int i = 1, j = 0; i < s.size(); i++) {
        if(i + prefix[i - j] < j + prefix[j]) {
        prefix[i] = prefix[i - j];
        } else {
        int k = max(0, j + prefix[j] - i);
        while(i + k < s.size() && s[k] == s[i + k]) ++k;
        prefix[i] = k;
        j = i;
        }
    }
    prefix[0] = (int) s.size();
    return prefix;
}

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

    int ans = 0;
    for(int i=0; i<N-1; i++) {
        auto z = z_algorithm(S.substr(i));
        for(int j=0; j<z.size(); j++) {
            int l = min(z[j], j);
            ans = max(ans, l);
        }
    }

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	ll dx;
	dx =tx-sx;
	ll dy;
	dy=ty-sy;
	for(int i=0;i<dx;i++){
		cout <<'R';
	}
	for(int i=0;i<dy;i++){
		cout << 'U';
	}
	for(int i=0;i<dx;i++){
		cout << 'L';
	}
	for(int i=0;i<dy;i++){
		cout << 'D';
	}
	cout << "DR";
	for(int i=0;i<dx;i++){
		cout <<'R';
	}
	for(int i=0;i<dy;i++){
		cout << 'U';
	}
	cout <<"ULUL";
	for(int i=0;i<dx;i++){
		cout << 'L';
	}
	for(int i=0;i<dy;i++){
		cout << 'D';
	}
	cout << "DR";
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
using namespace std;
typedef pair<double, double> Point;

Point splitMN(Point p1, Point p2, double m, double n){
  Point result;
  result.first = (n*p1.first+m*p2.first)/(m+n);
  result.second = (n*p1.second+m*p2.second)/(m+n);
  return result;
}

Point rot60ClockWise(Point p1, Point p2){
  constexpr double sqrt3=1.7320508075688772935274463;
  constexpr double sin60=sqrt3/2;
  constexpr double cos60=1/2.0;
  Point result;
  result.first = (p2.first - p1.first)*cos60 - (p2.second - p1.second)*sin60 + p1.first;
  result.second = (p2.first - p1.first)*sin60 + (p2.second - p1.second)*cos60 + p1.second;
  return result;
}

void kochCurve(Point l, Point r, int n){
  if (n==0) return;
  Point s= splitMN(l, r, 1, 2);
  Point t= splitMN(l, r, 2, 1);
  Point u= rot60ClockWise(s, t);

  kochCurve(l, s, n-1);
  cout << s.first << " " << s.second << endl;

  kochCurve(s, u, n-1);
  cout << u.first << " " << u.second << endl;

  kochCurve(u, t, n-1);
  cout << t.first << " " << t.second << endl;

  kochCurve(t, r, n-1);
}

int main(){
  int n;
  cin >> n;
  cout << "0 0" << endl;
  kochCurve(Point(0,0), Point(100,0), n);
  cout << "100 0" << endl;
  return 0;
}



Measured memory_bytes: 3296
#include<iostream>
#include<set>
using namespace std;
int solve(int x, set<int>& p)
{
	bool first = true;
	int best = -1;
	int LIM = 10000;
	for(int k = -LIM; k <= LIM; k++)
		if(p.count(k)==0 && (first || abs(k-x) < abs(best-x)))
		{
			best = k;
			first = false;
		}
	return best;
}
int main()
{
	int x, n; cin >> x >> n;
	set<int> p;
	for(int i = 0; i < n; i++)
	{
		int a; cin >> a;
		p.insert(a);
	}
	cout<<solve(x,p)<<endl;
	return 0;
}

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

template <class T>
inline void read(T &x) {
	static char ch; 
	static bool opt; 
	while (!isdigit(ch = getchar()) && ch != '-'); 
	x = (opt = ch == '-') ? 0 : ch - '0'; 
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0'; 
	if (opt)
		x = ~x + 1; 
}

template <class T>
inline void putint(T x) {
	static char buf[45], *tail = buf; 
	if (!x)
		putchar('0'); 
	else {
		if (x < 0)
			putchar('-'), x = ~x + 1; 
		for (; x; x /= 10) *++tail = x % 10 + '0'; 
		for (; tail != buf; --tail) putchar(*tail); 
	}
}

template <class T>
inline bool tense(T &x, const T &y) {
	return y < x ? x = y, true : false; 
}

template <class T>
inline bool relax(T &x, const T &y) {
	return x < y ? x = y, true : false; 
}

template <class T>
inline T getAbs(const T &x) {
	return x < 0 ? -x : x; 
}

typedef long long s64; 
typedef long double ld; 
typedef std::vector<int> vi; 
typedef std::pair<int, int> pii; 
#define mp(x, y) std::make_pair(x, y)

const int MaxN = 1e6 + 5; 
const int base = 26; 

int n, len[MaxN]; 
char *s[MaxN]; 

int nT = 1, ans; 
int trans[MaxN][base], apr[MaxN]; 

int cnt[26]; 

void insert(char *s, const int &len) {
	int x = 1; 
	for (int i = len; i >= 1; --i) {
		int ch = s[i] - 'a'; 
		if (!trans[x][ch])
			trans[x][ch] = ++nT; 
		x = trans[x][ch]; 
	}
	++apr[x]; 
}

int main() {
#ifdef orzczk
	freopen("a.in", "r", stdin); 
#endif

	read(n); 
	for (int i = 1; i <= n; ++i) {
		static char t[MaxN]; 
		scanf("%s", t + 1); 

		len[i] = strlen(t + 1); 
		s[i] = new char[len[i] + 3]; 

		memcpy(s[i], t, sizeof(char) * (len[i] + 1));  
		insert(t, len[i]); 
	}

	for (int i = 1; i <= n; ++i) {
		memset(cnt, 0, sizeof(cnt)); 
		for (int j = 1; j <= len[i]; ++j)
			++cnt[s[i][j] - 'a'];
		
		int x = 1; 
		for (int j = len[i]; j > 1; --j) {
			for (int ch = 0; ch < base; ++ch)
				ans += apr[trans[x][ch]] && cnt[ch]; 
			x = trans[x][s[i][j] - 'a']; 
			--cnt[s[i][j] - 'a']; 
		}
	}

	std::cout << ans << '\n'; 

	return 0; 
}

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

int main() {
  int h, w;
  cin >> h >> w;
  
  vector<vector<char>> data(h, vector<char>(w));
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> data.at(i).at(j);
    }
  }
  
  bool flag = false;
  for (int i = h-1; i > -1; i--) {
    for (int j = 0; j < w; j++) {
      if(data.at(i).at(j) == '#') break;
      if(j==w-1) {
        for (int k = i; k < data.size()-1; k++) {
          data.at(k) = data.at(k+1);
        }
        data.pop_back();
      }
    }
  }
  for (int j = w-1; j > -1; j--) {
    for (int i = 0; i < data.size(); i++) {
      if(data.at(i).at(j) == '#') break;
      if(i==data.size()-1) {
        for (int k = 0; k < data.size(); k++) {
          for (int l = j; l < data.at(k).size()-1; l++) {
            data.at(k).at(l) = data.at(k).at(l+1);
          }
          data.at(k).pop_back();
        }
      }
    }
  }
  
  for (int i = 0; i < data.size(); i++) {
    for (int j = 0; j < data.at(i).size(); j++) {
      cout << data.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
N,K=map(int,input().split())
MOD=int(1e9)+7

dp=[0]*(K+1)
for i in range(K):
  j=K-i
  dp[j]+=pow(K//j, N, MOD)

  k=2*j
  while k<=K:
    dp[j]=(dp[j]-dp[k]+MOD) % MOD
    k+=j

ans=0
for i in range(1,K+1):
  ans+=dp[i]*i
  ans%=MOD
print(ans)

Measured memory_bytes: 71180
import java.util.*;class Main{public static void main(String[] $){Scanner s=new Scanner(System.in);int INF=(int)1e9;int N=s.nextInt();int M=s.nextInt();int[] a=new int[M];int[] b=new int[M];int[][] c=new int[M][];for(int i=0;i<M;i++){a[i]=s.nextInt();b[i]=s.nextInt();c[i]=new int[b[i]];for(int j=0;j<b[i];j++){c[i][j]=s.nextInt()-1;}}int[] dp=new int[1<<N];Arrays.fill(dp,INF);dp[0]=0;for(int i=0;i<M;i++){int t=0;for(int j=0;j<b[i];j++){t|=1<<c[i][j];}for(int k=0;k<1<<N;k++){dp[k|t]=Math.min(dp[k|t],dp[k]+a[i]);}}System.out.println(dp[(1<<N)-1]==INF ? -1 : dp[(1<<N)-1]);}}

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

using namespace std;

int in()
{
    int a;
    scanf("%d",&a);
    return a;
}

int hobe[30000],hobe1[30000];

int main()
{
    int a=in(),b=in(),c=in(),d=in(),e=in(),f=in();
    hobe[0]=1;
    for(int i=1;i<=4000;i++)
    {
        if(i>=c)
        {
            if(hobe[i-c]==1)
                hobe[i]=1;
        }
        if(i>=d)
        {
            if(hobe[i-d]==1)
                hobe[i]=1;
        }
    }
    hobe1[0]=1;
    for(int i=1;i<=4000;i++)
    {
        if(i>=100*a)
        {
            if(hobe1[i-100*a]==1)
                hobe1[i]=1;
        }
        if(i>=100*b)
        {
            if(hobe1[i-100*b]==1)
                hobe[i]=1;
        }
    }
    int water,sugar,hoise=0;
    int mxl=-1,mxh=-1;
    for(int i=((f+1)/100)*100;i>=1;i-=100)
    {
        if(hobe1[i])
        {
            for(int j=min(f-i,((i+1)/100)*e);j>=1;j--)
            {
                if(hobe[j])
                {
                    if(mxl==-1)
                    {
                        hoise=1;
                        mxl=(100*j);
                        mxh=i+j;
                        water=i;
                        sugar=j;
                    }
                    else if((100*j)*mxh>(mxl*(i+j)))
                    {
                        mxl=(100*j);
                        mxh=i+j;
                        water=i;
                        sugar=j;
                    }
                }
            }
        }
    }
    if(!hoise)
    {
       printf("%d 0\n",a*100);
    }
    else
    printf("%d %d\n",water+sugar,sugar);
}


Measured memory_bytes: 256
//file_name:ABC80_C.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


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

    ll f[n+1][10];
    srep(i,1,n+1){
        rep(j,10){
            cin >> f[i][j];
        }
    }
    ll p[n+1][11];
    srep(i,1,n+1){
        rep(j,11){
            cin >> p[i][j];
        }
    }

    ll ans = -99999999999;

    srep(i,1,1024){
        int a[10];
        int ii = i;
        rep(j,10){
            a[j] = ii%2;
            ii /= 2;
        }
        ll ans2 = 0;
        srep(j,1,n+1){
            int count = 0;
            rep(k,10){
                if(a[k]+f[j][k]==2){
                    count++;
                }
            }
            ans2 += p[j][count];
        }
        maxs(ans,ans2);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forv(i, n)	for(int i = n - 1; i >= 0; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
 
const int inf = 1e9 + 1;
const ll modw = 1e9 + 7;
 
using namespace std;

vector<int> a[N];
bool used[N];
int dp[N];
vector<int> top;

void dfs(int x)
{
	used[x] = 1;
	forn(i, a[x].si)
	{
		int p = a[x][i];
		if(!used[p])	dfs(p);
	}
	top.pb(x);
}

int main() {
	barnarnar
	int n, m;
	cin >> n >> m;
	forn(i, m)
	{
		int t1, t2;
		cin >> t1 >> t2;
		t1--;
		t2--;
		a[t1].pb(t2);
	}
	forn(i, n)
	{
		if(!used[i])
		{
			dfs(i);
		}
	}
	reverse(all(top));
	forn(j, top.si)
	{
		forn(k, a[top[j]].si)
		{
			int p = a[top[j]][k];
			dp[p] = max(dp[p], dp[top[j]] + 1);
		}
	}
	int ans = 0;
	forn(i, n)
	{
		//cout << dp[i] << ' ';
		ans = max(ans, dp[i]);
	}
	//cout << endl;
	cout << ans;
	return 0;
}

Measured memory_bytes: 8056
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    vector<int> v(5);
    rep(i, 5) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int ans = 1e8;
    do {
        int cur_time = 0;
        rep(i, 5) {
            cur_time += v[i];
            if (i == 4) break;

            if (cur_time % 10 == 0) continue;
            else {
                cur_time += 10 - (cur_time % 10);
            }
        }
        ans = min(ans, cur_time);
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}


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

using P = pair<int, int>;

int N;
vector<vector<P> > G;
vector<int> M, L;
vector<vector<int> > dp;

int dfs(int n, int bit) {
  if ( n == N ) return 0;
  if ( dp[n][bit] >= 0 ) return dp[n][bit];

  int ret = dfs(n+1, bit);
  bool flag = true;
  int nxt = bit;  
  for ( int i = 0; i < M[n]; i++ ) {
    int s = G[n][i].first, e = G[n][i].second;
    for ( int j = s; j < e; j++ ) {
      if ( nxt & (1<<j) ) {
	flag = false;
	break;
      }
      nxt |= (1<<j);      
    }
  }

  if ( flag ) ret = max(ret, dfs(n+1, nxt)+L[n]);
  return dp[n][bit] = ret;  
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while ( cin >> N, N ) {
    G = vector<vector<P> >(N);
    M = L = vector<int>(N);    
    for ( int i = 0; i < N; i++ ) {
      cin >> M[i] >> L[i];
      for ( int j = 0; j < M[i]; j++ ) {
	int s, e;
	cin >> s >> e;
	s -= 6;
	e -= 6;
	G[i].emplace_back(P(s, e));	
      }
    }

    dp = vector<vector<int> >(N, vector<int>(1<<17, -1));
    cout << dfs(0, 0) << endl;
  }
  
  return 0;
}



Measured memory_bytes: 107472
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
b = [0, 1]
c = []
ans = 1

for _ in range(n):
    b.append(b[-1] + b[-2])

if m == 0:
    ans = b[n + 1]
else:
    c.append(a[0])
    for i in range(m - 1):
        c.append(a[i + 1] - a[i] - 1)
    c.append(n - a[m - 1])

    for i in c:
        ans *= b[i]

print(ans % 1000000007)


Measured memory_bytes: 464868
# -*- coding: utf-8 -*-

def main():

    n = int(raw_input())
    a = map(int,raw_input().split())

    if n <= 0 or n > 10 ** 5:
        return
    for i in a:
        if i <= 0 or i > 10 ** 9:
            return

    a.sort(reverse=True)
    trio_sum = 0

    for i in range(n):
        index = (i * 2) + 1
        trio_sum += a[index]

    return trio_sum

print main()


Measured memory_bytes: 28752
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int N;
    cin >> N;
    vector<ll> A(N), pl(N + 1), xo(N + 1);
    rep(i, 0, N) cin >> A[i];

    rep(i, 0, N) {
        pl[i + 1] = pl[i] + A[i];
        xo[i + 1] = xo[i] ^ A[i];
    }

    int l = 0, r = 1;
    ll ans = 0ll;
    while (r < N + 1) {
        while (pl[r] - pl[l] != (xo[r] ^ xo[l])) {
            l++;
        }
        ans += r - l;
        r++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7040
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
const int MAX=1000001;

int main(){
    string s;cin>>s;
    int ia,iz;
    for(int i=0;i<s.size();i++)if(s[i]=='A'){
        ia=i;
        break;
    }

    for(int i=s.size()-1;i>=0;i--)if(s[i]=='Z'){
        iz=i;
        break;
    }

    cout<<(iz-ia+1)<<endl;
}    

Measured memory_bytes: 832