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

int main(){
    int n;
    int high,low;
    int hi,lo;
    int total;
    int cnt;
    int point[100]={0};
    while(1){
        total = 0;
        cnt = 0;
        cin >> n;
        if(n == 0) break;
        for(int i=0;i<n;i++){
            cin >> point[i];
            if(i == 0){
                high = point[i];
                low = point[i];
                hi = 0;
                lo = 0;
            }
            else if(point[i] > high){
                high = point[i];
                hi = i;
            }
            else if(point[i] < low){
                low = point[i];
                lo = i;
            }
        }
        for(int i=0;i<n;i++){
            if(i != hi && i != lo){
                total += point[i];
                cnt++;
            }
        }
        cout << total / cnt << endl;
    }
}

Measured memory_bytes: 1160
while True:
    v = int(input())
    if v == -1:
        break
    if v < 4:
        print(v)
    else:
        b = str(bin(v))[2:]
        bb = [b[i:i+2] for i in range(len(b)-2, -1, -2)]
        if len(b) % 2 != 0:
            bb.append(b[0])
        ans = []
        for t in bb:
            tmp = 0
            for i, v in enumerate(t[::-1]):
                tmp += pow(2, i) * int(v)
            ans.append(tmp)
        print(''.join(map(str, ans[::-1])))

Measured memory_bytes: 7768
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int N, M, X, Y; cin >> N >> M >> X >> Y;

	int x_max = -1;
	REP(i,N){
		int x; cin >> x;
		x_max = max(x_max, x);
	}

	int y_min = 1 << 30;
	REP(i,M){
		int y; cin >> y;
		y_min = min(y_min, y);
	}
	if(x_max < y_min and X < x_max+1 and Y >= x_max+1) cout << "No War" << endl;
	else cout << "War" << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s, t;
    cin >> s >> t;

    for (auto i : irange(0L, n)) {
        cout << s[i] << t[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000009
#define inf 1e9
#define endl '\n'
#define zeros(x) ((x)&(-x))

using namespace std;

typedef long long ll;
typedef long double ld;

ll n;
string a, s;

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll r;
    cin>>n;
    cin>>s;
    if (s.size()%2==1)
    {
        cout<<"No";
    }
    else
    {
        a = s.substr(0, s.size()/2);
        a = a + a;
        if (a == s)
            cout<<"Yes";
        else
            cout<<"No";
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []

for _ in range(n):
  s.append(input())

print('AC x ' + str(s.count('AC')))
print('WA x ' + str(s.count('WA')))
print('TLE x ' + str(s.count('TLE')))
print('RE x ' + str(s.count('RE')))

Measured memory_bytes: 16284
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

int main(){
    string l;
    cin >> l;
    int n = l.length();

    vector<long long int> pow3(n,1);// pow3[i] = pow(3,i)
    for(int i=1; i<n; i++){
        pow3[i] = 3 * pow3[i-1];
        pow3[i] %= MOD;
    }

    reverse(l.begin(),l.end());
    long long int ans = 1;
    for(int i=0; i<n; i++){
        if(l[i] == '1'){
            ans = pow3[i] + 2 * ans;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int g = sc.nextInt();
        int[] pi = new int[d];
        int[] ci = new int[d];
        for(int i = 0; i < d; i++){
            pi[i] = sc.nextInt();
            ci[i] = sc.nextInt();
        }
        int min = 1000;
        for(int i = 0; i < (1 << d); i++){
            int csum = 0;
            int cpnsum = 0;
            int n = -1;
            for(int j = 0; j < d; j++){
                if((i >> j & 1) == 1){
                    csum += 100 * (j + 1) * pi[j] + ci[j];
                    cpnsum += pi[j];
                }else{
                    n = j;
                }
            }
            if(csum >= g){
                min = Math.min(min, cpnsum);
            }else{
                for(int j = 1; j <= pi[n] - 1; j++){
                    csum += 100 * (n + 1);
                    cpnsum++;
                    if(csum >= g){
                        min = Math.min(min, cpnsum);
                        break;
                    }
                }
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 25172
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <utility>
#include <string>

using namespace std;

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }

    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }
};

bool check(RollingHash &rh, int n, int length) {
    map<pair<long long, long long>, int> cnt;
    for (int i = 0; i + length <= n; ++i) {
        auto h = rh.get(i, i + length);
        if (cnt.count(h)) {
            if (i - cnt[h] >= length) return true;
        }
        else cnt[h] = i;
    }
    return false;
};

int main() {
    int n;
    string s;
    cin >> n >> s;
    RollingHash rh(s);

    for (int length = (n >> 1); length > 0; --length) {
        if (check(rh, n, length)) {
            cout << length << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}


Measured memory_bytes: 4064
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`

				`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	k := nextInt()
	s := next()

	ans := s

	if len(s) > k {
		ans = s[:k] + "..."
	}

	//	fmt.Fprintln(out, "[DEBUG]]", a)
	fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}


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

int main(){
    string s;
    cin >> s;
    for(int i = 0; i < 3; i++){
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,Counter

h,w,m = map(int,input().split())

w_list = []
h_list = []

se = set()

for _ in range(m):
    nh,nw = map(int,input().split())

    se.add((nh,nw))
    w_list.append(nw)
    h_list.append(nh)

w_count = Counter(w_list)
h_count = Counter(h_list)

max_w = 0
max_h = 0

ch = []
cw = []

for i in w_count.values():
    max_w = max(max_w,i)
    cw.append(i)

for i in h_count.values():
    max_h = max(max_h,i)
    ch.append(i)

ma = ch.count(max_h)*cw.count(max_w)

result = max_h+max_w
point = 0

for i,j in se:
    if w_count[j] == max_w and h_count[i] == max_h:
        point += 1

if point == ma:
    print(result-1)
else:
    print(result)

Measured memory_bytes: 92460
#include<bits/stdc++.h>
#define maxn 1000201

using namespace std;

int n,cnt[maxn],k,ans,d;

int main()
{
    scanf("%d%d",&n,&k);memset(cnt,0,sizeof(cnt));
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&d); cnt[d]++;
    }
    sort(cnt+1,cnt+n+1);
    ans=n;
    for (int i=n;i>n-k;i--) ans=ans-cnt[i];
    printf("%d\n",ans);
    return 0;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    string a, b;
    cin >> a >> b;
    int a_len, b_len;
    a_len = a.size();
    b_len = b.size();

    if(a_len > b_len) cout << "GREATER" << endl;
    else if(a_len < b_len) cout << "LESS" << endl;
    else{
        if(a > b) cout << "GREATER" << endl;
        else if(a < b) cout << "LESS" << endl;
        else cout << "EQUAL" << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main(){
int a, b, c;
cin >> a >> b >> c;
int x[3];
if(a >= b && a >= c){
x[0] = a;
if(b >= c){
x[1] = b;
x[2] = c;
} else {
x[1] = c;
x[2] = b;
}
} else if(b >= a && b >= c){
x[0] = b;
if(a >= c){
x[1] = a;
x[2] = c;
} else {
x[1] = c;
x[2] = a;
}
} else if(c >= a && c >= b){
x[0] = c;
if(a >= b){
x[1] = a;
x[2] = b;
} else {
x[1] = b;
x[2] = a;
}
}
int sum = x[0] * 10 + x[1] + x[2];
cout << sum << endl;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();



        int[] a = new int[n];
        long min = Integer.MAX_VALUE;
        int c = 0;
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            min = Math.min(min, Math.abs(a[i]));
            if (a[i] < 0) {
                c++;
            }
        }

        long sum = 0;

        for (int i = 0 ; i < n ; i++) {
            sum += Math.abs(a[i]);
        }

        if (c % 2 == 0) {
            System.out.println(sum);
        } else {
            System.out.println(sum - 2 * min);
        }




    }

}


Measured memory_bytes: 50456
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<cassert>
#include<vector>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const long long inf = 1145141919810000;
typedef pair<int, int> P;
int p[15];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> p[i];
	sort(p, p + n);
	int sum = 0; p[n - 1] /= 2;
	rep(i, n) {
		sum += p[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define mod 1000000007
#define rep(i,n)    for(ll i=0;i<n;++i)
#define forup(i,a,b)    for(ll i=a;i<=b;++i)
#define all(v)    v.begin(),v.end()
#define inf 1000000010
#define pii pair<ll,ll>
#define vl vector<ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define MAXN 110
#define bsize 555
#define sz(v) v.size()
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll power(ll x,ll y, ll md){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

int main(){
    ll n;
    cin>>n;
    vector<ll> h(n);
    rep(i,n)    cin>>h[i];
    vector<ll> dp(n,0);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    forup(i,2,n-1){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1];
}

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

using namespace std;
using lint = long long;

int main(void)
{
    int N, K;
    cin >> N >> K;
    double win = 0;

    int maxcnt = 0;
    for(int i = 1; i <= K; i*=2)maxcnt++;
    vector<double> bp(maxcnt+1);
    double bn = 0.5;
    bp[0] = 1;
    for(int i = 1; i <= maxcnt; i++){
        bp[i] = bp[i-1] * bn;
        //cout << bp[i] << endl;
    }
    for(int i = 1; i <= N; i++){
        int cnt = 0;
        for(int j = i; j < K; j*=2) cnt++;
        win += bp[cnt];
        //cout << 1.0 / N << " " << bp[cnt] << endl;
    }
    cout << fixed;
    cout << setprecision(10) << win / N << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

template<class T> T factorial(T n){ return n ? n * factorial(n-1) : 1; }

int main()
{
	ll n;
	cin >> n;
	cout << factorial(n) << endl;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
char a[305][305],b[305][305];
int n,res=0;
string s[305];
bool check()
{
    for (int i=0;i<n;++i)
        for (int j=i+1;j<n;++j)
            if (b[i][j]!=b[j][i]) return false;
    return true;
}
int main()
{
    cin>>n;

    for (int i=0;i<n;++i)
        for (int j=0;j<n;++j)
            cin>>a[i][j];
    for (int p=0;p<n;++p)
    {
        for (int i=0;i<n;++i)
            for (int j=0;j<n;++j)
                b[i][(j+p)%n]=a[i][j];
        if (check()) res+=n;
    }
    cout<<res;
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> _p(N);
  auto * const p = &_p[0];
  for (int i = 0; i < N; ++i)
    cin >> p[i];
  auto __p(_p);
  sort(__p.begin(), __p.end());
  int count = 0;
  for (int i = 0; i < N; ++i)
    if (p[i] != __p[i])
      ++count;
  cout << (count <= 2 ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	ll sum = 0;
	rep(i, n) sum += a[i];
	sum -= a.front();
	ll su = a.front();
	ll ans = abs(sum - su);
	for (int i = 1; i < n - 1; ++i) {
		su += a[i];
		sum -= a[i];
		ans = min(ans, abs(sum - su));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
from collections import Counter

ans = ''
n = int(input())
count = Counter(input())
for i in range(n-1):
    count &= Counter(input())

for c in [chr(i) for i in range(ord('a'), ord('z')+1)]:
    ans = ans + c*count[c]

print(ans)

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

int main(){
	int n,k;
	cin >> n >> k;
	vector<int>h(n);
	for(int i=0; i<n; i++){
		cin >> h[i];
	}
	sort(h.begin(),h.end());
	ll sum = 0;
	if(k > n){
		cout  << 0 << endl;
	}
	else{
		for(int i = 0; i < n-k; i++){
			sum += h[i];
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
using namespace std;
#include<stack>
int main(){
while(1){
int a,b,n,v,x,y,i,j,m[18][18]={0},c=0,o=0;
pair<int,int> p,t,g;
stack<pair<int,int> > q;
scanf("%d%d",&a,&b);
if(a==0&&b==0){
break;
}
g.first=a;
g.second=b;
for(i=0;i<=a+1;i++){
	for(j=0;j<=b+1;j++){
		if(i==0||i==a+1||j==0||j==b+1){
		m[i][j]=1;
		}
	}
}
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d%d",&a,&b);
m[a][b]=1;
}
p.first=1;
p.second=1;
q.push(p);
while(!q.empty()){
	t=q.top();
	q.pop();

	if(t==g){
		c++;
	}

	if(m[t.first+1][t.second]!=1){
		t.first++;
		q.push(t);
		t.first--;
	}
	if(m[t.first][t.second+1]!=1){
		t.second++;
		q.push(t);
		t.second--;
	}
}
printf("%d\n",c);

}
return 0;
}

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

map<long long, long long> map_prime_factor(long long n) {
    map<long long, long long> res;
    for (long long i = 2LL; i * i <= n; ++i) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

void Main()
{
	int N; cin >> N;
	vector<ll> A(N);
	rep(i,N) cin >> A[i];
	ll res = 0;
	rep(i,N) {
		res += map_prime_factor(A[i])[2];
	}
	cout << res << endl;
}

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


Measured memory_bytes: 384
S = str(input())

if len(set(S)) == 1:
  print(0)
else:
  ans = pow(10,5)
  for s in set(S):
    l = S
    num = 0 
    while len(set(l)) > 1:
      tmp = ""
      for i in range(len(l)-1):
        if l[i] == s:
          tmp += l[i]
        else:
          tmp += l[i+1]
      l = tmp
      num += 1
    ans = min(num, ans)
  print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define Inf 1000000000
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	int H, W, N;
	cin >> H >> W >> N;
	int L = max(H, W);
	int ans = N / L;
	if (N % L != 0)
		ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  rep(i,n) cin>>a[i];
  sort(a,a+n,greater<int>());
  int ans=0;
  rep(i,k){
    ans+=a[i];
  }
  cout<<ans<<endl;
  return 0;
}







Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  int cnt[30]={};
  cin >> n;
  for(int i=0; i<30; i++) {
    cnt[i]=inf;
  }
  for(int i=0; i<n; i++) {
    cin >> s;
    int x[30]={};
    for(auto p:s) {
      x[p-'a']++;
    }
    for(int i=0; i<30; i++) {
      cnt[i]=min(cnt[i],x[i]);
    }
  }
  for(int i=0; i<26; i++) {
    for(int j=0; j<cnt[i]; j++) {
      cout << char('a'+i);
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

bool f[100][100]; //field

int main(){
  while(true){
    int n,w,h,s,t;
    cin>>n;
    if(n==0)break;
    cin>>w>>h;
    rep(i,w)
      rep(j,h) f[i][j]=false;
    
    rep(i,n){
      int x,y;
      scanf("%d %d", &x, &y);
      f[x-1][y-1]=true;
    }

    cin>>s>>t;

    //??¨?????????????°?????????¢?´¢??§???TLE??????????????????
    int ans=0;
    rep(i,w-s+1){
      rep(j,h-t+1){
	int tmp=0;
	rep(k,s){
	  rep(l,t){
	    if(f[i+k][j+l]) tmp++;
	  }
	}
	ans = max(ans, tmp);
      }
    }

    cout << ans << endl;
  }
}

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

int main(){
    int i, n;
    int A[100];
    cin >> n;
    for(i = 0; i < n; i++) cin >> A[i];
    cout << A[n - 1];
    for(i = 1; i < n; i++) cout << " " << A[n - 1 - i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
   
 using namespace std;
   
 #define MP make_pair
 #define PB push_back
 typedef long long LL;
 typedef pair<int,int> PII;
 const double eps=1e-8;
 const double pi=acos(-1.0);
 const int K=1e6+7;
 const int mod=1e9+7;
  
 int r,c,n,x,y,ans[200][200];
  
 int main(void)
 {
     scanf("%d%d%d",&r,&c,&n);
     x=1,y=1;
     for(int i=1,cnt;i<=n;i++)
     {
         scanf("%d",&cnt);
         while(cnt--)
         {
             ans[x][y]=i;
             if(y==c&&x%2==1)
                 y=c,x++;
             else if(y==1&&x%2==0)
                 y=1,x++;
             else if(x&1)
                 y++;
             else
                 y--;
         }
     }
     for(int i=1;i<=r;i++)
     for(int j=1;j<=c;j++)
         printf("%d%c",ans[i][j],j==c?'\n':' ');
     return 0;
 }


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
 // 1-indexedなので注意。
 struct BIT {
  private:
   vector<int> bit;
   int N;
 
  public:
   BIT(int size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(int a, int w) {
     for (int x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(int a) {
     int ret = 0;
     for (int x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 
 // ====================================================================
 
 int main() {
   int i,n,bf=9999999;
   cin >> n;
   vector<int> v(n);
   for (int i = 0; i < n; i++) { cin >> v[i]; }
 
   ll ans = 0;
   rep(i,n){
     if(bf>v[i]){
       ans++;
       bf=v[i];
     }
   }
   cout << ans << endl;
 }

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


void solve(long long L){
    cout<<setprecision(20);
    cout<<(long double)L * L * L / 27<<endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005;
int n,l;
ll ans,sum,a[N];
int main()
{
	scanf("%d",&n);l=1;
	for (int i=1;i<=n;i++) 
	{
		scanf("%lld",&a[i]);
		while ((sum^a[i])!=sum+a[i]) sum^=a[l++];
	   ans+=i-l+1;sum^=a[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <cmath>

bool is_prime(int x)
{
  for (int i = 2; i <= std::sqrt(x); i++) {
    if (!(x % i)) return false;
  }
  return true;
}

int main()
{
  int ans = 0;
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    int temp;
    scanf("%d", &temp);

    if (is_prime(temp)) ans++;
  }

  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 2704
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    long long N;
    cin >> N;
    vector<long long> num(10e5 + 1, 0);
    REP (i, N) {
        long long a;
        cin >> a;
        if (a > 0)
            num[a - 1]++;
        num[a]++;
        if (a < 10e5)
            num[a + 1]++;
    }
    long long ans = 0;
    REP(i, 10e5) {
        ans = max(ans, num[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8064
N = int(input()) #N: ボールの個数

A = list(map(int, input().split()))

from collections import defaultdict

d = defaultdict(int)
for i in A:
    d[i] += 1
max = sum([d[i]*(d[i]-1)//2 for i in range(1,N+1)])
ans = [max - d[i] + 1 for i in A]

for x in ans:
    print(x)

Measured memory_bytes: 43392
#include<iostream>
#include<math.h>
#include<queue>
#include<string>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int k=1;
	int ans=0;
	while(k<b){
		ans++;
		k=k-1+a;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

/*sortの仕方
 * ■ string s の場合
 * 昇順: sort(s.begin(), s.end())
 * 降順:  sort(s.rbegin(), s.rend())
 *
 * ■ int a[N] の場合
 * 昇順: sort(a, a+N)
 * 降順: 不明
 */

/*int alph2int(char character) {
    int x = character - 'a';
    return x;
}
*/

int main(){
	int N, M;
	cin >> N >> M;
	int ans = 0;
	if(N==1) {
		cout << M << endl;
		return 0;
	}
	
	for(int i = 1; i <= M/2; i++){
		if(M%i == 0){
			if(N <= M/i){
				ans = i;
			}
		}
	}

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


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

ans = sum(B)
for i in range(N-1):
    if A[i] + 1 == A[i + 1]:
        ans += C[A[i] - 1]

print(ans)

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

using namespace std;

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

    int half = S.length() / 2;
    int ans = 0;
    for (int i = half - 1; i >= 0; i--){
        for (int j = 0; j < i; j++){
            if (S[j] != S[i + j]){
                break;
            }
            if (j == i - 1){
                ans = 2 * i;
            }
        }
        if (ans != 0){
            break;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b,p=0,s;
    cin>>k>>a>>b;
    if(a%k==0){
            p=1;


    }
    else {
        s=(a/k)+1;
        if(s*k>a && s*k<=b)
            p=1;
        else
            p=0;
    }
    if(p)
        cout<<"OK"<<endl;
    else
        cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include<cstring>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
string S;
string ans="yes";
int counter;
int solve() 
{
    rep(i,S.size())
    {
        counter=0;
        rep(j,S.size())
        {
            if(S[i]==S[j])
            {
                counter++;
            }
        }
        if(counter!=1)
        {
            ans = "no";
        }
    }
}
int main()
{
    cin >> S;
    solve();
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;
  int cnt = 0, bcnt = 0;
  for (int i = 0; i < s.size(); ++i) {
	if (s[i] == 'a') {
	  if (cnt < a + b) {
		cout << "Yes" << endl;
		cnt++;
	  }
	  else cout << "No" << endl;
	}
	if (s[i] == 'b') {
	  if(cnt < a + b && bcnt + 1 <= b) {
		cout << "Yes" << endl;
		cnt++;
		bcnt++;
	  }
	  else cout << "No" << endl;
	}
	if (s[i] == 'c') cout << "No" << endl;
  }
  return 0;
}


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

int main(){
  int64_t N;
  cin >> N;
  int64_t x=0;
  for(int i=0;i<N;i++){
    if((i+1)%3!=0&&(i+1)%5!=0){
      x+=i+1;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define HASH 18014398241046527
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}



void SOLVE(){
    inp(k);
    inps(A, B);
    ll z = (A+k-1)/k;
    z*=k;
    if(z<=B&&z>=A){
        out("OK");
    }
    else{
        out("NG");
    }
}

int main() {
	fastIO();
	// #ifndef ONLINE_JUDGE
    //     freopen("i.txt", "r", stdin);
    //     freopen("o.txt", "w", stdout);
	// #endif
 
    ll TC;
    // cin >> TC;
    TC = 1;
    for(ll tc1=1; tc1<=TC; tc1++){
        SOLVE();
    }
    printclock;
}

Measured memory_bytes: 3844
#include<iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    int G[N][N]={};
    for(int i=0;i<N;++i){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;++j){
            int v;
            cin>>v;
            G[u-1][v-1]=1;
        }
    }
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            if(j) cout<<' ';
            cout<<G[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
map<int,int>cnt;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    for (ll i=1; i<=100; i++)
    {
        for (ll j=1; j<=100; j++)
        {
            for (ll k=1; k<=100; k++)
            {
                ll val=(i*i)+(j*j)+(k*k)+(i*j)+(i*k)+(k*j);
                cnt[val]++;
            }
        }
    }
    for (int i=1;i<=x;i++)
        cout<<cnt[i]<<endl;
    return 0;
}


Measured memory_bytes: 5456
#include <stdio.h>
#include <stdlib.h>

#define N 8
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE -1

int Search(int);
void Print();

int X[N], Y[N], sir[N][N], L[2*N-1], R[2*N-1];

int main(){
  int i, j, k, r, c;

  for(i = 0; i < N; i++){
    X[i] = OFF;
    Y[i] = OFF;
  }

  for(i = 0; i < 2*N-1; i++){
    L[i] = OFF;
    R[i] = OFF;
  }

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      sir[i][j] = FALSE;
    }
  }

  scanf("%d", &k);
  for(i = 0; i < k; i++){
    scanf("%d %d", &r, &c);
    sir[r][c] = TRUE;
  }
  Search(0);
  return 0;
}

int Search(int p){
  int q;

  if(p == N){
    Print();
    return 0;
  }

  for(q = 0; q < N; q++){ 
    if(Y[q]==ON || L[p+q]==ON || R[p-q+N-1]==ON){
      continue;
    }

    X[p] = q;
    Y[q] = ON;
    L[p+q] = ON;
    R[p-q+N-1] = ON;

    Search(p+1);

    X[p] = OFF;
    Y[q] = OFF;
    L[p+q] = OFF;
    R[p-q+N-1] = OFF;
  }
   return 0;
}

void Print(){
  int i, j;
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(sir[i][j] == TRUE){
        if(X[i] != j){
          return;
        }
      }
    }
  }

  for(i = 0; i < N; i++) {
    for(j = 0; j < N; j++) {
      if(X[i] == j) {
        printf("Q");
      }else{
        printf(".");
      }
    }
    printf("\n");
  }
}

Measured memory_bytes: 572
def gcd(a, b):
   if(a < b):
     a, b = b, a
   if(b == 0):
      return a
   return gcd(b, a%b)

N = int(input())
A = list(map(int, input().split()))
g = A[0]
for a in A:
   g = gcd(g, a)
print(g)

Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> c(m);
    rep(i,m) cin >> c[i];
    vector<int> dp(n+10,INF);
    dp[0] = 0;
    rep(i,m) rep(j,n+10){
        if(j+c[i]<n+10){
            chmin(dp[j+c[i]],dp[j]+1);
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3264
using System;

public class test
{
  static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());
    int val = n % 10;

    switch(val)
    {
      case 2:
      case 4:
      case 5:
      case 7:
      case 9:
        Console.WriteLine("hon");
        break;

      case 0:
      case 1:
      case 6:
      case 8:
        Console.WriteLine("pon");
        break;

      case 3:
        Console.WriteLine("bon");
        break;
    }
  }
}

Measured memory_bytes: 27520
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int a[]=new int[N];
		int b[]=new int[N];
		int k[]=new int[N];
		boolean visited[]=new boolean[N];
		int ori=0,max=0;
		ArrayList<ArrayList<Integer>> tree=new ArrayList<ArrayList<Integer>>();
		Deque<Integer> G=new ArrayDeque<Integer>();
		Deque<Integer> C=new ArrayDeque<Integer>();
		HashMap<String,Integer> ans=new HashMap<String,Integer>();
		for(int i=0;i<N;i++){
			tree.add(new ArrayList<Integer>());
		}
		for(int i=0;i<N-1;i++){
			a[i]=stdIn.nextInt()-1;
			b[i]=stdIn.nextInt()-1;
			ArrayList<Integer> c=new ArrayList<Integer>();
			c=tree.get(a[i]);c.add(b[i]);tree.set(a[i],c);
			c=tree.get(b[i]);c.add(a[i]);tree.set(b[i],c);
			k[a[i]]++;k[b[i]]++;
		}
		for(int i=0;i<N;i++){
			if(k[i]==1){
				ori=i;break;
			}
		}
		G.add(ori);C.add(N);visited[ori]=true;
		while(G.size()>0){
			int A=G.poll();
			int c=C.poll();
			int color=0;
			for(int i=0;i<tree.get(A).size();i++){
				if(visited[tree.get(A).get(i)]==false){
					if(color==c)
						color++;
					if(max<color)
						max=color;
					G.add(tree.get(A).get(i));C.add(color);
					ans.put(String.valueOf(A)+","+String.valueOf(tree.get(A).get(i)),color+1);
					visited[tree.get(A).get(i)]=true;
					color++;
				}
			}
		}
		System.out.println(max+1);
		for(int i=0;i<N-1;i++){
			if(ans.containsKey(String.valueOf(a[i])+","+String.valueOf(b[i])))
				System.out.println(ans.get(String.valueOf(a[i])+","+String.valueOf(b[i])));
			else
				System.out.println(ans.get(String.valueOf(b[i])+","+String.valueOf(a[i])));
		}
	}
}


Measured memory_bytes: 122592
from collections import deque

s = input()

r = False
d = deque()
d.extend(list(s))

q = int(input())
for i in range(q):
    t = input()
    if t == "1":
        r = not r
    else:
        t, f, c = list(t.split())
        f = False if f=="1" else True

        if r == f:
            d.appendleft(c)
        else:
            d.append(c)

if r:
    d.reverse()

print("".join(d))

Measured memory_bytes: 14356
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var q = int.Parse(Console.ReadLine());
        var t = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(s.Intersect(t).Count());
    }
}


Measured memory_bytes: 20328
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define sz(x) (int)(x.size())
#define pb push_back
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define endl "\n"
#define int long long

const int N = (int)(1e6) + 322;
const long long inf = (long long)(1e18) + 123;
const int mod = (int)(1e9) + 7;
const double EPS = 1e-9;

const int sz = 160 * 160 / 2 + 10;

bool dp[82][82][sz * 2 + 1];
int a[82][82], n, m;

inline bool check(int cur) {
    return (0 < cur && cur < sz * 2);
}

signed main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            cin >> a[i][j];
        }
    }
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            int x; cin >> x;
            a[i][j] -= x;
        }
    }
    dp[1][0][sz] = true;
    dp[0][1][sz] = true;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            for(int k = 1; k < sz * 2; ++k) {
                if (dp[i][j - 1][k] || dp[i - 1][j][k]) {
                    if (check(k + a[i][j])) {
                        dp[i][j][k + a[i][j]] = true;
                    }
                    if (check(k - a[i][j])) {
                        dp[i][j][k - a[i][j]] = true;
                    }
                }
            }
        }
    }

    for(int k = 0; k < sz; ++k) {
        if (dp[n][m][sz - k] || dp[n][m][sz + k]) {
            cout << k;
            return 0;
        }
    }


    return 0;
}

Measured memory_bytes: 166272
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a[12]={0,1,0,2,0,2,0,0,2,0,2,0};
int b,c;

int main(){
  cin >> b >> c;
  if(a[b-1]==a[c-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}
//xとyのビットごとの排他的論理和
template<class T> T XOR(T x, T y)
{
	T n = 0;
	while (max(x, y) > pow(2, n)) n++;
	T ans=0;
	for (int i = 0; i <= n; i++)
	{
		T x1 = (x % (T)pow(2, i + 1)) / (T)pow(2, i);
		T y1 = (y % (T)pow(2, i + 1)) / (T)pow(2, i);
		if (x1 != y1) ans += (T)pow(2, i);
	}
	return ans;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	long long N, K;
	cin >> N >> K;
	long long i = 0;
	while (pow(K, i) <= N) i++;
	cout << i << endl;
		 
	return 0;
}

Measured memory_bytes: 256
N = int(input())
T = list(map(int,input().split()))
M = int(input())
P = []
X = []
for i in range (0,M):
  P1,X1 = [int(i) for i in input().split()]
  P.append(P1)
  X.append(X1)

for i in range (0,M):
  s = sum(T) - T[P[i]-1] + X[i]
  print(s)
 



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

int main() {
    string s;
    cin >> s;
    stack<char> st;
    int cnt = 0;
    for (char c : s) {
        if (st.empty()) {
            st.push(c);
        } else {
            char t = st.top();
            if (c != t) {
                cnt += 2;
                st.pop();
            } else {
                st.push(c);
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
n = int(input())
tmp = 0
digit = 2
exponent = 1
baseMinor2 = ''

while(tmp!=n):
  #2^nで割った余りを合わせる
  if(n % digit) == (tmp % digit):
    baseMinor2 = '0' + baseMinor2
  else:
    baseMinor2 = '1' + baseMinor2 
    tmp += exponent
    
  exponent *= -2
  digit *= 2
if baseMinor2 == '':
  print(0)
else:
  print(baseMinor2)

Measured memory_bytes: 3064