akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
using namespace std;

int N;
vector<vector<int>> G;

vector<int> calc_distance(vector<vector<int>> &G, int s){
    int N = G.size();
    vector<int> ret(N, 1<<30);
    ret[s] = 0;
    queue<int> que;
    que.push(s);
    vector<int> vis(N, false);
    vis[s] = true;
    while(!que.empty()){
        int fr = que.front();
        que.pop();
        for(int t : G[fr]){
            if(vis[t]) continue;
            ret[t] = ret[fr] + 1;
            vis[t] = true;
            que.push(t);
        }
    }
    return ret;
}

int main(){
    cin >> N;
    G.resize(N);
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> d = calc_distance(G, 0);
    int idx = max_element(d.begin(), d.end()) - d.begin();
    vector<int> d2 = calc_distance(G, idx);
    int depth = *max_element(d2.begin(), d2.end());
    if(depth % 3 == 1)
        cout << "Second" << endl;
    else
        cout << "First" << endl;
    return 0;
}


Measured memory_bytes: 15076
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

"""
[トポロジカルソート]
⇒入次数0の頂点からスタートし、その番号を1とする.
　1から出ている有向辺をすべて削除
  入次数0になった頂点の番号を2とし、2から出ている有向辺をすべて削除
  入次数0になった頂点の番号を3とし、...を繰り返す

常に入次数が0になった頂点を選択してその1つ前を親とするため、
出来上がったグラフの各頂点の親は、そのグラフで最も近い親(距離1)
つまり、後から足されたM本の辺ではない
よって、トポロジカルソートによって得られるグラフが元の木である.
"""
n,m = LI()

edges = [[] for _ in range(n)]
cnt = [0]*n
for _ in range(n-1+m):
    a,b = LI()
    edges[a-1].append(b-1)
    cnt[b-1] += 1


ans = [None]*n
que = deque()
for i in range(n):
    if cnt[i] == 0:
        que.append(i)
        ans[i] = 0
        while que:
            v = que.popleft()
            for i in edges[v]:
                cnt[i] -= 1
                if cnt[i] == 0:
                    que.append(i)
                    ans[i] = v+1
        break
for i in ans:
    print(i)


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

int main() {
  int N;
  cin >> N;
  char s;
  int i,x;
  x = 0;
  for(i = 0; i < N; i++){
    cin >> s;
    if( s == 'Y') x = 1;
  }
  if(x == 0) cout << "Three" << endl;
  else cout << "Four" << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from itertools import product

def solve():
    hq = [(0, y, x) for y, x in product(xrange(m), xrange(n)) 
          if not(0 < y < m - 1 and 0 < x < n - 1)]
    heapify(hq)
    while len(hq) != 0:
        cost, cy, cx = heappop(hq)
        if field[cy][cx] == "&":
            return cost
        if memo[cy][cx] <= cost:
            continue
        memo[cy][cx] = cost
        for dx, dy in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            ny, nx = cy + dy, cx + dx
            if 0 <= ny < m and 0 <= nx < n:
                if field[ny][nx] != "#" and field[cy][cx] == "#": 
                    heappush(hq, (cost + 1, ny, nx))
                else:
                    heappush(hq, (cost, ny, nx))

while True:
    n, m = map(int, raw_input().split())
    if n | m == 0:
        break
    memo = [[1 << 20] * n for _ in xrange(m)]
    field = [raw_input() for _ in xrange(m)]    
    print solve()

Measured memory_bytes: 5788
# coding: utf-8
# Your code here!

import sys

S = [x for x in input()]
T = [x for x in input()]

chars = dict([(c, i) for i, c in enumerate('abcdefghijklmnopqrstuvwxyz')])

match_chars = [[] for _ in range(26)]
for s, t in zip(S, T):
    match_chars[chars[s]].append(t)

for match_char in match_chars:
    if len(set(match_char)) > 1:
        print('No')
        sys.exit()
        
match_chars = [[] for _ in range(26)]
for s, t in zip(S, T):
    match_chars[chars[t]].append(s)

for match_char in match_chars:
    if len(set(match_char)) > 1:
        print('No')
        sys.exit()

print('Yes')

Measured memory_bytes: 9348
# coding: utf-8
# Your code here!
while True:
    a,op,b=input().split()
    if op=="?":
        break
    a=int(a)
    b=int(b)
    if op=="+":
        x=a+b
    elif op=="-":
        x=a-b
    elif op=="*":
        x=a*b
    else:
        x=a//b
    print(x)
    


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

using namespace std;

const int N = 3005;

string s, t;
int dp[N][N], parent[N][N];

int main() {
	cin >> s >> t;

	for (int i = 0; i < N; i++) {
		dp[i][0] = dp[0][i] = 0;
		parent[i][0] = parent[0][i] = -1;
	}

	for (int i = 1; i <= s.length(); i++)
		for (int j = 1; j <= t.length(); j++) {
			int changed = 0;
			if (s[i-1] == t[j-1]) {
				dp[i-1][j-1]++;
				changed = 1;
			}

			if (dp[i-1][j] >= dp[i-1][j-1] && dp[i-1][j] >= dp[i][j-1]) {
				parent[i][j] = 1;
				dp[i][j] = dp[i-1][j];
			} else if (dp[i][j-1] >= dp[i-1][j-1] && dp[i][j-1] >= dp[i-1][j]) {
				parent[i][j] = 2;
				dp[i][j] = dp[i][j-1];
			} else {
				if (!changed)
					parent[i][j] = 3;
				else
					parent[i][j] = 4;
				dp[i][j] = dp[i-1][j-1];
			}
		}

	string answer = "";

	int i = s.length(), j = t.length();

	while (parent[i][j] != -1) {
		if (parent[i][j] == 1)
			i--;
		else if (parent[i][j] == 2)
			j--;
		else if (parent[i][j] == 3)
			i--, j--;
		else {
			i--, j--;
			answer += s[i];
		}
	}

	for (int i = answer.length()-1; i >= 0; i--)
		cout << answer[i];
	cout << endl;

	return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	ll N, M;
	cin >> N >> M;
	if (N == 1 || M == 1) {
		if (N == 1 && M == 1) {
			cout << 1;
		}
		else if (N == 1) {
			cout << M - 2;
		}
		else if (M == 1) {
			cout << N - 2;
		}
		return 0;
	}
	cout << N * M - (N + M - 2) * 2;
	return 0;
}

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

using namespace std;
typedef unsigned long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    string S;
    cin >> S;

    S[3] = '8';

    cout << S << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
    ll n,m,stamina=999999,min_stamina=999999;
    cin>>n;
    ll a[n];
    REP(i,0,n-1)
        cin>>a[i]; 
    m=*max_element(a,a+n);
    REP(i,1,m)
    {
        stamina=0;
        REP(j,0,n-1)
        {
            stamina+=(a[j]-i)*(a[j]-i);
        }
        //cout<<"i "<<i<<" stamina "<<stamina<<endl;
        min_stamina=min(min_stamina,stamina);
    }   
    //REP(i,0,n-1)
        //cout<<a[i]<<" ";    
    cout<<min_stamina;       
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a == b)
		{printf("%d\n",c);}
	if(a == c)
		{printf("%d\n",b);}
	if(b == c)
		{printf("%d\n",a);}
	return 0;
}


Measured memory_bytes: 128
import java.util.*; 
public class Main{
    static public void main(String[] args){
        Scanner sc=new Scanner(System.in);
       int a=sc.nextInt();

       int a2=a*a;
       int a3=a*a*a;
       System.out.print(a+a2+a3);
        sc.close();
    }
}

Measured memory_bytes: 35728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//ll mod = 1000000007;
ll mod = 998244353;

signed main()
{
    int n;
    cin >> n;
    vi a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    sort(all(a));
    int ai = a[n - 1];
    ll ans = INT_MAX;
    rep(i, n - 1)
    {
        if (abs(a[i] * 2 - ai) < abs(ai - ans * 2))
        {
            ans = a[i];
        }
    }
    cout << ai << " " << ans << endl;
    return 0;
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  vector<pair<int, int>> d(m);
  for (int i = 0; i < m; i++) {
    int b, c;
    cin >> b >> c;
    d.at(i) = make_pair(c, b);
  }
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  int index = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < d.at(i).second; j++) {
      if (index >= n || a.at(index) >= d.at(i).first) goto end;
      a.at(index) = d.at(i).first;
      index++;
    }
  }
end:
  long s = 0;
  for (int i = 0; i < n; i++) s += a.at(i);
  cout << s << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int X,Y,Z;
	cin>>X>>Y>>Z;
	int ans = X/(Y+Z);
	if(ans*(Y+Z)+Z > X){
		ote(ans-1);
	}
	else{
		ote(ans);
	}
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    s=[sorted(list(input())) for i in range(n)]
    s.sort()
    ans=0
    cnt=1
    for i in range(n-1):
        if s[i]==s[i+1]:
                cnt+=1
                if i ==n-2:
                    ans+=cnt*(cnt-1)//2
        else:
            if cnt>=2:
                ans += cnt * (cnt - 1) // 2
                cnt=1
    print(ans)
resolve()

Measured memory_bytes: 24652
fun main(args: Array<String>) {
    val num = readLine()?.toInt() ?: return
    call(num)
}

private fun call(n: Int) {
    1.until(n + 1).forEach {
        if (it % 3 == 0) {
            print(" $it")
        } else if (it.toString().contains("3")) {
            print(" $it")
        }
    }
    println()
}


Measured memory_bytes: 30224
using System;
using System.Collections.Generic;
using System.Linq;

class Restaulant
{
    public string city { get; set; }
    public int point { get; set; }
    public int number { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        var listR = new List<Restaulant>();

        for (int i = 0; i < n; i++)
        {
            var ret = new Restaulant();

            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            ret.city = input[0];
            ret.point = int.Parse(input[1]);
            ret.number = (i + 1);

            listR.Add(ret);
        }

        foreach(var r in listR.OrderBy(w => w.city).ThenByDescending(w => w.point))
        {
            //出力
            Console.WriteLine(r.number);
        }
    }
}

Measured memory_bytes: 13536
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

n, a, b, c, d = na()
a -= 1
b -= 1
c -= 1
d -= 1
s = ns()

if "##" in s[a:c + 1] or "##" in s[b:d + 1]:
    print("No")
else:
    if c > d and "..." not in s[b - 1:d + 2]:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 3572
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
swi = 0
s = [0, 0]
i = 0
while i < len(a) - 1:
    if a[i] == a[i + 1]:
        s[swi] = a[i]
        i += 1
        swi += 1
        if swi == 2:
            break
    i += 1

print(s[0] * s[1])


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N;
	cin >> N;
	vector<int64> cnt(N+1, 1);
	for (int64 i = 2; i <= N; i++) {
	  for (int64 j = 1; i * j <= N; j++) {
	    cnt[i * j] ++;
	  }
	}
	int64 res = 0;
	FOR(i, 1, N+1) {
	  res += i * cnt[i];
	}
	cout << res << endl;
}


Measured memory_bytes: 81336
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
		int[] mem = new int[N];
		for(int i = 0; i < Q; i++) {
			mem[sc.nextInt() - 1] += 1;
		}
		for(int i = 0; i < N;i++) {
			if(mem[i] > Q - K) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
		//Q-Kの値よりAiに出てくる回数が小さいものを敗退でも良いかも
	}

}

Measured memory_bytes: 57296
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

bool canBeMM(int num) {
    if (num > 0 and num <= 12) {
        return true;
    } else {
        return false;
    }
}

int main()
{
    std::string S;
    std::cin >> S;
    int former = std::stoi(S.substr(0, 2));
    int latter = std::stoi(S.substr(2, 2));
    if (canBeMM(former) and canBeMM(latter)) {
        std::cout << "AMBIGUOUS" << std::endl;
    } else if (canBeMM(former)) {
        std::cout << "MMYY" << std::endl;
    } else if (canBeMM(latter)) {
        std::cout << "YYMM" << std::endl;
    } else {
        std::cout << "NA" << std::endl;
    }
    return 0;
}


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

int main() {
    int N;
    cin >> N ;
    vector<int> S(N);
    for (int i = 0; i < N; i++){
        cin >> S.at(i) ;
    }
    sort(S.begin(),S.end());
    int L = 1;
    for (int k = 0; k < N-1; k++){
       if (S.at(k) != S.at(k+1))
       L++; 
    }
    cout << L << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#EDPC O

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = [LI() for _ in range(n)]
dp = [[0]*(2**n) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(2**n):
        if dp[i][j]:
            for k in range(n):
                if (j>>k)&1 == 0 and a[i][k] == 1:
                    dp[i+1][j|(1<<k)] += dp[i][j]
                    dp[i+1][j|(1<<k)] %= mod
print(dp[-1][-1])

Measured memory_bytes: 394904
#include <stack>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
const int Max_N(200050);

void Get_Val(int &Ret)
{
	Ret = 0;
	char ch;
	while (ch = getchar(), ch > '9' || ch < '0')
		;
	do
	{
		(Ret *= 10) += ch - '0';
	}
	while (ch = getchar(), ch >= '0' && ch <= '9');
}

int N, Head[Max_N], To[Max_N], Next[Max_N], root;
int dfsclock, Pre[Max_N], Lowlink[Max_N], scctot, sccno[Max_N];
vector<int> SCC[Max_N];
stack<int> S;

inline bool comp(const int &u, const int &v)
{
	return Pre[u] < Pre[v];
}

void Tarjan(int u)
{
	int v;
	S.push(u), Pre[u] = Lowlink[u] = ++dfsclock;
	for (int i = Head[u];i;i = Next[i])
		if (!Pre[v = To[i]])
			Tarjan(v), Lowlink[u] = min(Lowlink[u], Lowlink[v]);
		else
			if (!sccno[v])
				Lowlink[u] = min(Lowlink[u], Pre[v]);
	if (Pre[u] == Lowlink[u])
	{
		++scctot;
		while (true)
		{
			v = S.top(), S.pop(), SCC[sccno[v] = scctot].push_back(v);
			if (u == v)
				break;
		}
		if (SCC[scctot].size() > 1)
			root = scctot, sort(SCC[root].begin(), SCC[root].end(), comp);
	}
}

int SG[Max_N];
bool done[Max_N];

int getSG(const vector<int> &V)
{
	for (int i = 0;i < V.size();++i)
		done[V[i]] = true;
	int Ret;
	for (int i = 0;;++i)
		if (done[i] == false)
		{
			Ret = i;
			break;
		}
	for (int i = 0;i < V.size();++i)
		done[V[i]] = false;
	return Ret;
}

void dfsTree(int u)
{
	vector<int> Son;
	for (int i = Head[u], v;i;i = Next[i])
		dfsTree(v = To[i]), Son.push_back(SG[v]);
	SG[u] = getSG(Son);
}

int main()
{
	Get_Val(N);
	for (int t = 1, s;t <= N;++t)
	{
		Get_Val(s);
		To[t] = t, Next[t] = Head[s], Head[s] = t;
	}
	for (int i = 1;i <= N;++i)
		if (!Pre[i])
			Tarjan(i);
	for (int j = 0, u;j < SCC[root].size();++j)
	{
		u = SCC[root][j];
		for (int i = Head[u], v;i;i = Next[i])
			if (sccno[v = To[i]] != root)
				dfsTree(v);
	}
	vector<int> Son;
	for (int i = Head[SCC[root][0]], v;i;i = Next[i])
		if (sccno[v = To[i]] != root)
			Son.push_back(SG[v]);
	SG[SCC[root][0]] = getSG(Son);
	for (int j = SCC[root].size() - 1, u;j;--j)
	{
		u = SCC[root][j], Son.clear();
		for (int i = Head[u];i;i = Next[i])
			Son.push_back(SG[To[i]]);
		SG[u] = getSG(Son);
	}
	Son.clear();
	for (int i = Head[SCC[root][0]];i;i = Next[i])
		Son.push_back(SG[To[i]]);
	if (getSG(Son) == SG[SCC[root][0]])
	{
		puts("POSSIBLE");
		return 0;
	}
	Son.clear();
	for (int i = Head[SCC[root][0]], v;i;i = Next[i])
		if (sccno[v = To[i]] != root)
			Son.push_back(SG[v]);
	Son.push_back(getSG(Son)), SG[SCC[root][0]] = getSG(Son);
	for (int j = SCC[root].size() - 1, u;j;--j)
	{
		u = SCC[root][j], Son.clear();
		for (int i = Head[u];i;i = Next[i])
			Son.push_back(SG[To[i]]);
		SG[u] = getSG(Son);
	}
	Son.clear();
	for (int i = Head[SCC[root][0]];i;i = Next[i])
		Son.push_back(SG[To[i]]);
	if (getSG(Son) == SG[SCC[root][0]])
	{
		puts("POSSIBLE");
		return 0;
	}
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 25720
import java.util.*;

class Shop implements Comparable<Shop>{
  String s;
  int p, n;
  public Shop( String str, int i , int j){
    s = str;
    p = i;
    n = j;
  }

  @Override
  public int compareTo( Shop t ){
    if(this.s.compareTo(t.s) > 0) return - 1;
    else if(this.s.compareTo(t.s) < 0) return 1;
    else return (int)(this.p - t.p);
  }
}

public class Main{

    public static void main(String args[]){

        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int n = sc.nextInt();
        List<Shop> list = new ArrayList<>();

        String a;
        int b, c;
        for(int i = 0; i < n; i++){
            a = sc.next();
            b = sc.nextInt();
            c = i;
            list.add(new Shop(a, b, c));
        }

        Collections.sort(list, Comparator.reverseOrder());

        // 出力
        for(int i = 0; i < n; i++){
            System.out.println(list.get(i).n + 1);
        }

    }

}


Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<map>
#include<utility>

using namespace std;

static const int MAX = 26;

map<char, int> letters;

int main() {
  for (int i = 0; i < 26; i++) {
    char c = (char)((int)'a' + i);
    letters[c] = 0;
  }

  string S;

  cin >> S;

  if (S.size() < 1 || S.size() > MAX) {
    cout << "-1" << endl;
    return 0;
  }


  for (int i = 0; i < S.size(); i++) {
    if (letters[S[i]] > 0) {
      cout << "-1" << endl;
      return 0;
    }
    letters[S[i]] += 1;
  }

  if (S.size() != MAX) {
    for (int i = 0; i < 26; i++) {
      char c = (char)('a' + i);
      if (letters[c] == 0) {
        S += c;
        cout << S << endl;
        return 0;
      }
    }
  }
  else {
    for (int i = S.size() - 1; i > 0; i--) {
      char c = S[i];
      letters[c] -= 1;
      S.pop_back();
      if ((int) S[i - 1] < (int) c) {
        for (int j = 0; j < 26; j++) {
          char l = (char)('a' + j);
          if ((int) l > (int) S[i - 1] && letters[l] == 0) {
            S[i - 1] = l;
            cout << S << endl;
            return 0;
          }
        }
      }
    }
  }

  cout << "-1" << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
  #n = int(input())
  s = input()
  #s = input().split()
  #a,b = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  if s == "ABC":
    print("ARC")
  else:
    print("ABC")

if __name__ == '__main__':
  main()

Measured memory_bytes: 9028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, M, L;
	cin >> N >> M >> L;
	int C[301][301];
	rep1(j, N) rep1(i, j - 1) C[i][j] = 1e9 + 1;
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		C[a][b] = c;
		C[b][a] = c;
	}

	rep1(k, N) {
		rep1(j, k - 1) {
			rep1(i, j - 1) {
				chmin(C[i][j], C[i][k] + C[j][k]);
			}
		}
		for (int j = k + 1; j <= N; j++) {
			rep1(i, k - 1) {
				chmin(C[i][j], C[i][k] + C[k][j]);
			}
			for (int i = k + 1; i < j; i++) {
				chmin(C[i][j], C[k][i] + C[k][j]);
			}
		}
	}

	rep1(i, N) rep1(j, N) {
		cesp(C[i][j]);
		if (j == N) ce("");
	}

	rep1(j, N) rep1(i, j - 1) {
		C[i][j] = (C[i][j] <= L) ? 1 : 1e9;
	}

	rep1(k, N) {
		rep1(j, k - 1) {
			rep1(i, j - 1) {
				chmin(C[i][j], C[i][k] + C[j][k]);
			}
		}
		for (int j = k + 1; j <= N; j++) {
			rep1(i, k - 1) {
				chmin(C[i][j], C[i][k] + C[k][j]);
			}
			for (int i = k + 1; i < j; i++) {
				chmin(C[i][j], C[k][i] + C[k][j]);
			}
		}
	}
	rep1(i, N) rep1(j, N) {
		cesp(C[i][j]);
		if (j == N) ce("");
	}

	int Q;
	cin >> Q;
	rep(i, Q) {
		int s, t;
		cin >> s >> t;
		if (s > t) swap(s, t);
		if (C[s][t] < 1e9) co(C[s][t] - 1);
		else co(-1);
	}

	Would you please return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}


int facctorialMethod(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

using namespace std;
int main() {

	/*int n,m,q;
	cin >> n, m, q;

	vector<int> vec(n);

	vector<vector<int>> data(q, vector<int>(n));

	for (int i = 0; i < q; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> data.at(i).at(j);
		}
	}
*/

	ll a, b, n;
	cin >> a >> b >> n;


	ll x = 0;
	x = b - 1;

	if (n < x) {
		x = n;
	}

	ll A = a * x / b;



	cout << A << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    string s, t; cin >> s >> t;
    vector<vector<int>> order(26);
    REP(i, 0, s.size()) order[s[i] - 'a'].push_back(i);

    int cnt = 0, idx = -1;
    REP(i, 0, t.size()) {
        int cur = t[i] - 'a';
        if (order[cur].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        auto itr = upper_bound(ALL(order[cur]), idx);
        if (itr != order[cur].end()) {
            idx = *itr;
        } else {
            idx = order[cur].front();
            cnt++;
        }
    }

    cout << (ll)cnt * s.size() + idx + 1 << endl;
    return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*int find(int a){
     if(a==par[a])return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);
     if(a==b)return ;
     par[b]=a;
}
ll modexpo(ll a,ll b)
{
     ll ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
*/
vector<int> adj[100005];

int main(){
     int n,k;
     cin>>n>>k;
     ll tmp=(n-1)*(n-2)/2;
     if(k>tmp){cout<<-1;return 0;}
     for(int i=2;i<=n;i++){
          adj[1].pb(i);
     }
     int left=tmp-k;
     int ct=0;
     for(int i=2;i<=n&&left>0;i++){
          for(int j=i+1;j<=n&&left>0;j++){
               adj[i].pb(j);
               left--;
               ct++;
          }
     }
     cout<<(n-1+ct)<<endl;
     for(int i=1;i<=n;i++){
          if(adj[i].size()>0){
               for(auto it:adj[i]){
                    cout<<i<<" "<<it<<"\n";
               }
          }
     }
     
     
}
 
 
 
 

























Measured memory_bytes: 5952
#include<iostream>

using namespace std;

typedef pair<int,int> P;
const int MAX = 21;
P pos;
char m[MAX][MAX];
int r,c;

void input(){
  for(int i = 0; i < r; i++)
    for(int j = 0; j < c; j++){
      cin >> m[i][j];
      if(m[i][j] == '<' || m[i][j] == '>' || 
	 m[i][j] == '^' || m[i][j] == 'v') pos = P(i,j);
    }
}

bool inside(P p){
  return (0 <= p.first && p.first < r && 0 <= p.second && p.second < c);
}

void shoot(char c){

  int x = 0, y = 0;
  P p = pos;
  if(c == '^') y = -1;
  if(c == 'v') y = 1;
  if(c == '>') x = 1;
  if(c == '<') x = -1;

  while(1){
    p.first += y;
    p.second += x;
    if(!inside(p)) break;
    if(m[p.first][p.second] == '#') break;
    if(m[p.first][p.second] == '*'){
      m[p.first][p.second] = '.';
      break;
    }
  }
}

void move(char c, int x, int y){
  if(inside(P(pos.first+y,pos.second+x)) && m[pos.first+y][pos.second+x] == '.'){
    m[pos.first][pos.second] = '.';
    m[pos.first+y][pos.second+x] = c;
    pos.first += y;
    pos.second += x;
  }else{
    m[pos.first][pos.second] = c;
  }
}

int main(){
  bool flag = false;
  int X;
  cin >> X;
  while(X--){
    if(flag) cout << endl;
    flag = true;

    cin >> r >> c;
    input();
    int num;
    cin >> num;
    for(int i = 0; i < num; i++){
      char c;
      cin >> c;
      if(c == 'S') shoot(m[pos.first][pos.second]);
      if(c == 'U') move('^',0,-1);
      if(c == 'D') move('v',0,1);
      if(c == 'L') move('<',-1,0);
      if(c == 'R') move('>',1,0);
    }

    for(int i = 0; i < r; i++){
      for(int j = 0; j < c; j++)
	cout << m[i][j];
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    string s;
    cin >> s;
    ll cnt = 0;
    int slen = s.length();
    rep(i,slen){
        cnt += (int)(s[i]-'0');
    }
    if(cnt % 9 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 3720
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll a,b;
  cin>>a>>b;
  ll ans = 0;
  if(a%b!=0)ans++;
  cout << ans+a/b << endl; 
  return 0;
}

Measured memory_bytes: 256
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {  // O( log(a) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }  // O( log(a) )
bool isPrime(ll n) {                                  // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) flag = false;
  }
  return flag;
}
vector<pair<ll, ll>> primeFac(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

int main() {
  ll h, w;
  cin >> h >> w;
  ll ans;
  if (h == 1 || w == 1)
    ans = 1;
  else if (h % 2 == 0)
    ans = w * h / 2;
  else
    ans = w * (h - 1) / 2 + (w + 1) / 2;

  cout << ans << endl;
}

Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int inputData = Integer.parseInt(in.readLine());
		StringBuilder sb = new StringBuilder();
		String str;

		for (int i = 1; i <= inputData; i++) {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				if (str.contains("3")) {
					sb.append(" " + i);
				}
				// char[] ch = str.toCharArray();
				// for (int j = 0; j < ch.length; j++) {
				// if (ch[j] == '3') {
				// sb.append(" " + i);
				// break;
				// }
				// }
			}
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 27040
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int main(){

    int L,R,d; cin >> L >> R >> d;
    int ans = 0;
    for(int i = L; i <= R; i++){
        if (i % d == 0) ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3592
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<numeric>
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
bool isDigit(char c){return '0' <= c && c <= '9';}
template<typename T> void remove(std::vector<T>& vector, unsigned int index){vector.erase(vector.begin() + index);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed power(int num){
    if(num == 1)return 1;
    return (num * power(num - 1)) % mod;
}

signed main(){
    SPEED;
    int n;
    cin >> n;
    cout << power(n) << endl;
}


Measured memory_bytes: 1152
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	vector<int> mountains;

	for (int i = 0; i < 10; i++){
		int mountain;
		scanf("%d", &mountain);
		mountains.push_back(mountain);
	}
	sort(mountains.begin(), mountains.end());
	for (int i = 0; i < 3; i++)
		printf("%d\n", mountains[9 - i]);

	return (0);
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
int main() {
	int n;
	cin >> n;
	if (n >= 30)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi; 
typedef pair<int,int> pi;
typedef long long ll;
#define F first 
#define S second 
#define PB push_back 
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)

vector<ll> dp, h;

int main(){
	
	ll n, k; 
	
	k = 2;
	
	cin  >> n;

	dp.assign(n, 10000000000);
	h.assign(n, 0);
	
	for(ll i = 0; i < n; i++){
		cin >> h[i];
	}
	
	dp[0] = 0;
	
	for(ll i = 0; i < n; i++){
		
		for(ll i2 = i+1; i2 <= i+k; i2++) {
						
			if(i2 == n) break;
			dp[i2] = min( dp[i2] , dp[i] + ( abs( h[i2] - h[i] ) ) );
		}
		
	}
	
	cout << dp[n-1] << endl;

	return 0;
}

Measured memory_bytes: 1792
N, K = map(int, input().split())
A = list(map(int, input().split()))
journey = [1]
dup = {}
for i in range(N+100000):
    journey.append(A[journey[-1] - 1])

end_idx, start_idx = 0, 0
dup = {}
for i, j in enumerate(journey):
    if j in dup:
        end_idx = i
        break
    else:
        dup[j] = 0
for i, j in enumerate(journey):
    if j == journey[end_idx]:
        start_idx = i
        break

if K <= start_idx:
    print(journey[K])
    exit()
b = end_idx - start_idx
m = (K - start_idx) % b
print(journey[start_idx + m])

Measured memory_bytes: 38216
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200200,M=2002000,P=1000000007;
int i,j,k,n,m,En,X,Y,ch,ff,mi1,mi2,An,ans;
int c[N],w[N],h[N],mi[N],A[N],z[N],Jc[N],Jc_[N];
struct edge { int s,n;} E[M];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void E_add(int x,int y) {
	E[++En].s=y;E[En].n=h[x];h[x]=En;
	E[++En].s=x;E[En].n=h[y];h[y]=En;
}
void dfs(int x) {
	A[++An]=c[x];z[x]=1;
	for (int k=h[x];k;k=E[k].n) if (!z[E[k].s]) dfs(E[k].s);
}
int ksm(int x,int y) {
	int z=1;
	for (;y;y>>=1,x=(ll) x*x%P) if (y&1) z=(ll) z*x%P;
	return z;
}
void pre(int n) {
	int i;
	Jc[0]=Jc_[0]=1;
	for (i=1;i<=n;i++) Jc[i]=(ll) Jc[i-1]*i%P;
	Jc_[n]=ksm(Jc[n],P-2);
	for (i=n-1;i;i--) Jc_[i]=(ll) Jc_[i+1]*(i+1)%P;
}
int main() {
	R(n);R(X);R(Y);
	w[0]=P;
	pre(n);
	for (i=1;i<=n;i++) {
		R(c[i]);R(w[i]);
		if (w[i]<w[mi[c[i]]]) mi[c[i]]=i;
	}
	for (i=1;i<=n;i++) if (mi[i]) {
		if (w[mi[i]]<w[mi1]) mi2=mi1,mi1=mi[i];
		else {
			if (w[mi[i]]<w[mi2]) mi2=mi[i];
		}
	}
	for (i=1;i<=n;i++) {
		if (w[i]+w[mi[c[i]]]<=X) E_add(i,mi[c[i]]);
		if (c[i]!=c[mi1] && w[i]+w[mi1]<=Y) E_add(i,mi1);
		if (c[i]!=c[mi2] && w[i]+w[mi2]<=Y) E_add(i,mi2);
	}
	ans=1;
	for (i=1;i<=n;i++) if (!z[i]) {
		An=0;
		dfs(i);
		sort(A+1,A+An+1);
		ans=(ll) ans*Jc[An]%P;
		for (j=1;j<=An;j++) {
			k=j;
			while (k<An && A[k+1]==A[j]) k++;
			ans=(ll) ans*Jc_[k-j+1]%P;
			j=k;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 15872
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

#define fst first
#define snd second

typedef long long llint;
typedef pair<int, int> pii;

const int B = 27397, MOD = 1e9 + 7;
const int B1 = 33941, MOD1 = 1e9 + 9;

const int MAXN = 310;

bool excluded[MAXN];

int n, m;
int a[MAXN][MAXN], cnt[MAXN];

int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
      --a[i][j];
    }
  }

  int sol = MOD;
  for (int t = 0; t < m; ++t) {
    memset(cnt, 0, sizeof cnt);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (excluded[a[i][j]]) continue;
        ++cnt[a[i][j]];
        break;
      }
    }

    int mx = 0, pivot = 0;
    for (int i = 0; i < m; ++i) {
      if (cnt[i] > mx) {
        mx = cnt[i];
        pivot = i;
      }
    }

//    TRACE(pivot);

    sol = min(sol, mx);
    excluded[pivot] = true;
  }

  printf("%d\n", sol);
  return 0;
}



Measured memory_bytes: 640
let bin_search x (a : int array) n =
  let rec doit l r =
    if l >= r then false
    else
      let m = (l + r) / 2 in
      if x = a.(m) then true
      else if x < a.(m) then doit l m
      else doit (m + 1) r in
  doit 0 n

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let read_seq () = read_line () |> split_on_char ' ' |> List.map int_of_string in
  let n = read_int () in
  let s = read_seq () |> Array.of_list in
  let _ = read_int () in
  let t = read_seq () in
  List.fold_left (fun acc e -> if bin_search e s n then acc+1 else acc) 0 t
  |> Printf.printf "%d\n"

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	pair <int, int> a[5];
	for (int i = 0; i < 5; i++){
		cin >> a[i].second;
		a[i].first = a[i].second % 10;
		if (a[i].first == 0)
			a[i].first = 10;
	}
	sort(a, a + 5);
	reverse(a, a + 5);
	int ans = 0;
	for (int i = 0; i < 4; i++){
		ans += 10 * (a[i].second / 10 + (bool)(a[i].first != 10));
	}
	ans += a[4].second;
	cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
  int A, B, C;
  scanf("%d%d%d", &A, &B, &C);
  
  int i = 0;
  if (A == B && B != C) i = 1;
  if (B == C && A != C) i = 1;
  if (A == C && A != B) i = 1;
  
  if (i) {
    puts("Yes");
  } else {
    puts("No");
  }
  
  return 0;
}

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

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

    int ans = 0;
    for(int i = 1; i < n; i++) {
        string x = s.substr(0, i);
        string y = s.substr(i, n-i);
        int count = 0;
        set<char> st;

        for(char c : x) {
            st.insert(c);
        }

        for(auto c : st) {
            if(y.find(c) != string::npos) count++;
        }
        ans = max(ans, count);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	vector<bool>x( 2000000, 1 );
	vector<long long int>prime;
	x[0] = x[1] = 0;
	for( size_t i = 0; i < 2000000; i++ ) {
		if( x[i] ) {
			prime.emplace_back( i );
			long long int j = 2;
			while( i*j < 2000000 ) {
				x[i*j] = 0;
				j++;
			}
		}
	}
	long long int N, M;
	while( cin >> N, N ) {
		if( find( prime.begin(), prime.end(), N ) != prime.end() ) {
			cout << 0 << endl;
		} else {
			auto now = upper_bound( prime.begin(), prime.end(), N ) - prime.begin();
			cout << prime[now] - prime[now - 1] << endl;
		}
	}
}

Measured memory_bytes: 4904
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

int N;
vector<vector<int> > G;
vector<int> dist;

void dfs(int v,int d=0,int p=-1){
  dist[v]=d;
  for(int nv:G[v]){
    if(nv==p) continue;
    dfs(nv,d+1,v);
  }
}

vector<int> calcdist(int v){
  dist=vector<int>(N);//初期化
  dfs(v);
  return dist;
}

int main(){
  cin >> N;
  int u,v;
  cin >> u >> v;
  u--; v--;
  G.resize(N,vector<int>(0));
  rep(i,N-1){
    int a,b;
    cin >> a >> b;    
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> distu=calcdist(u);
  vector<int> distv=calcdist(v);

  int mv=0;
  rep(i,N){
    if(distu[i]<distv[i]){
      mv=max(mv,distv[i]);
    }
  }
  int ans=mv-1;
  cout << ans << endl;
}

Measured memory_bytes: 10744
#include<iostream>
#include<cstdio>
using namespace std;
const int gram[6] = {200,300,500,1000,1200,1500};
const int  val[6] = {380,550,850,1520,1870,2244};
int dp[7000];
void Init(){
  for(int i=0;i<5500;i++)dp[i] = 1<<30;
  // dp[200] = 380;dp[300] = 550;
  for(int i=0;i<6;i++)dp[gram[i]] = val[i];
  for(int i=0;i<6;i++){
    for(int j=400;(j-gram[i])<=5000;j+=100){
      if(j-gram[i] < 0)continue;
      dp[j] = min(dp[j],dp[j-gram[i]]+val[i]);
    }
  }
}

int main(){
  int n;
  Init();
  while(cin >> n && n){
    cout << dp[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
N,M = map(int, input().split())
E = [[] for _ in range(N)]
E2 = [[] for _ in range(N)]
d = [0]*N
for _ in range(M):
    x,y = map(int, input().split())
    E[x-1].append(y-1)
    E2[y-1].append(x-1)
    d[y-1] += 1

from collections import deque

tpsort = [v for v in range(N) if len(E2[v]) == 0]
q = deque(tpsort)
while q:
    t = q.popleft()
    for v in E[t]:
        d[v] -= 1
        if d[v] == 0:
            q.append(v)
            tpsort.append(v)

dp = [0]*N
for v in tpsort:
    for par in E2[v]:
        dp[v] = max(dp[v], dp[par]+1)

print(max(dp))


Measured memory_bytes: 74800
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[]){
    int n=readI();
    for(int i=1;i<=n;i++){
      int c=0;
      for(int x=1;;x++){
        if(x*x>i){
          break;
        }
        for(int y=1;y<=x;y++){
          if(x*x+y*y+x*y>i){
            break;
          }
          for(int z=1;z<=y;z++){
            if(x*x+y*y+z*z+x*y+y*z+z*x>i){
              break;
            }
            if(x*x+y*y+z*z+x*y+y*z+z*x==i){
              if(x==y&&y==z){
                c++;
              }else if(x==y||y==z||x==z){
                c+=3;
              }else{
                c+=6;
              }
              break;
            }
          }
        }
      }
      pl(c+"");
    }
  }

  static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
  public static String read(){
    try{
      return ctos((char)br.read());
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static char readC(){
    try{
      return (char)br.read();
    }catch(IOException e){
      e.printStackTrace();
      return (char)-1;
    }
  }
  public static String readL(){
    try{
      return br.readLine();
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static String readS(){
    StringBuilder sb = new StringBuilder();
    while(true){
      try{
        int k = br.read();
        if(k==-1||(char)k==' '||(char)k=='\n'){break;}
        sb.append((char)k);
      }catch(IOException e){
        e.printStackTrace();
      }
    }
    return sb.toString();
  }
  public static int readI(){
    return stoi(readS());
  }
  public static long readLong(){
    return stol(readS());
  }
  public static long stol(String s){
    return Long.parseLong(s);
  }
  public static String[] readSs(){
    return readL().split(" ");
  }
  public static int[] readIs(){
    return stoi(readSs());
  }
  public static int stoi(String s){
    return Integer.parseInt(s);
  }
  public static int[] stoi(String s[]){
    int a[]=new int[s.length];
    for(int i=0;i<s.length;i++){
      a[i]=stoi(s[i]);
    }
    return a;
  }
  public static String itos(int i){
    return String.valueOf(i);
  }
  public static String[] itos(int[] a){
    String s[]=new String[a.length];
    for(int i=0;i<a.length;i++){
      s[i]=itos(a[i]);
    }
    return s;
  }
  public static String ctos(char c){
    return String.valueOf(c);
  }
  public static String cstos(char[] c){
    return new String(c);
  }
  public static char stoc(String s){
    return s.charAt(0);
  }
  public static char[] stocs(String s){
    return s.toCharArray();
  }
}


Measured memory_bytes: 39748
#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
char s[36];
int len,f1;
bool f;
int main()
{
	scanf("%s",s);
	len=strlen(s);
	if(s[0]!='A')
		f=1;
	if('A'<=s[1]&&s[1]<='Z')
		f=1;
	for(int i=2;i<len;i++)
	{
		if(s[i]=='C')
			f1++;
		else if('A'<=s[i]&&s[i]<='Z')
			f=1;
	}
	if('A'<=s[len-1]&&s[len-1]<='Z')
		f=1;
	if(f1!=1)
		f=1;
	printf("%s",f?"WA":"AC");
}

Measured memory_bytes: 128