akhauriyash/Code-Regression huggingface dataset:
let quick_sort a cmp =
  let partition p r =
    let x = a.(r) in
    let swap i j =
      let t = a.(i) in a.(i) <- a.(j); a.(j) <- t
    in
    let rec doit i j =
      if j >= r then i
      else begin
        if cmp a.(j) x <= 0 then (swap (i + 1) j; doit (i + 1) (j + 1))
        else doit i (j + 1)
      end
    in
    let i = doit (p - 1) p in
    swap (i + 1) r;
    i + 1
  in
  let rec doit p r =
    if p < r then begin
      let q = partition p r in
      doit p (q - 1);
      doit q r
    end
  in
  doit 0 (Array.length a - 1)

let calc_cost a n =
  let b = Array.copy a in
  quick_sort b compare;
  let min_a = b.(0) in
  let max_a = b.(n - 1) in
  let b_i = Array.make (max_a + 1) 0 in
  Array.iteri (fun i e -> b_i.(e) <- i) b;
  let v = Array.make n false in
  let rec doit i cost =
    if i = n then cost
    else if v.(i) then doit (i + 1) cost
    else begin
      let rec aux j ws =
        v.(j) <- true;
        let w = a.(j) in
        if v.(b_i.(w)) then w :: ws
        else aux b_i.(w) (w :: ws)
      in
      let ws = aux i [] in
      let n_w = List.length ws in
      let sum_w = List.fold_left (+) 0 ws in
      let min_w = List.fold_left min max_a ws in
      let c = min (sum_w + (n_w - 2) * min_w) (sum_w + min_w + (n_w + 1) * min_a) in
      doit (i + 1) (cost + c)
    end
  in
  doit 0 0

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in
  Printf.printf "%d\n" (calc_cost a n)

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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

map<int,int > f;
int a,b,c,d,n;

int solve(int x) {
    if(!x) return 0;
    if(f[x]) return f[x];
    int &ans=f[x];ans=9e18;
    if(x<=2e9) ans=min(ans,x*d);
    ans=min(ans,solve(x/2)+a+(x&1)*d);
    if(x&1) ans=min(ans,solve(x/2+1)+a+d);
    int t=x/3*3;
    if(x-t<t+3-x) ans=min(ans,solve(x/3)+b+(x-t)*d);
    else ans=min(ans,solve(x/3+1)+b+(t+3-x)*d);
    t=x/5*5;
    if(x-t<t+5-x) ans=min(ans,solve(x/5)+c+(x-t)*d);
    else ans=min(ans,solve(x/5+1)+c+(t+5-x)*d);
    return ans;
}

signed main() {
    int t;read(t);
    while(t--) {
        f.clear();
        read(n),read(a),read(b),read(c),read(d);
        write(solve(n));
    }
    return 0;
}


Measured memory_bytes: 4344
def q754(S: str) -> int:
    ans = float('inf')
    for i in range(len(S)):
        d = int(S[i:i+3])
        if abs(753 - d) < ans:
            ans = abs(753-d)
    return ans


if __name__ == "__main__":
    S = input()
    ans = q754(S)
    print(ans)


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2**20)

class Node:
    def __init__(self):
        self.id = None
        self.p = None
        self.left = None
        self.right = None

def Preorder(u):
    if u == -1:
        return
    print(' {}'.format(u), end='')
    Preorder(T[u].left)
    Preorder(T[u].right)
            
def Inorder(u):
    if u == -1:
        return
    Inorder(T[u].left)
    print(' {}'.format(u), end='')
    Inorder(T[u].right)

def Postorder(u):
    if u == -1:
        return
    Postorder(T[u].left)
    Postorder(T[u].right)
    print(' {}'.format(u), end='')

n = int(input())
T = [None] * n
for i in range(n):
    temp = Node()
    T[i] = temp

for i in range(n):
    d = 0
    L = [int(x) for x in input().split()]
    v, l, r = L[0], L[1], L[2]
    T[v].id = v
    T[v].left = l
    T[v].right = r
    if l != -1:
        T[l].p = v
    if r != -1:
        T[r].p = v

for i, t in enumerate(T):
    if t.p == None:
        t.p = -1
        root = i

print('Preorder')
Preorder(T[root].id)
print('\nInorder')
Inorder(T[root].id)
print('\nPostorder')
Postorder(T[root].id)
print('')


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; 

#define     int                 ll
#define     pb                  push_back
#define     mp                  make_pair
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     init(x, a)          memset(x, a, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     cpy(a,b)            memcpy(a,b,sizeof(b))
#define     is(a)               to_string(a)
#define     ci(a,c)             a-c
#define     db(i)               cout<<"point :"<<i<<'\n';
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
    int n; cin>>n;
    int ans = 0;
    double val = 100;
    while(n>floor(val)){
    	val*=1.01;
    	ans++;
    	val = floor(val);
    }
    cout<<ans<<'\n';
}

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

Measured memory_bytes: 3656
a = int(input())
ans = [100000]*100010
ans[0] = 0
for n in range(1,100001):
    power = 1
    while power <= n:
        ans[n] = min(ans[n],ans[n-power] + 1)
        power *= 6
    power = 1
    while power <= n:
        ans[n] = min(ans[n],ans[n-power] + 1)
        power *= 9
print(ans[a])

Measured memory_bytes: 3828
#include "bits/stdc++.h"
using namespace std;

int a,b,c,x,cnt=0,sum=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			sum = i * 500 + j * 100;
			if(x >= sum && (x - sum) % 50 == 0 && (x - sum) / 50 <= c)
				cnt++;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

type point struct {
	x int
	y int
}

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	var H, W int
	fmt.Scan(&H, &W)

	M := make([]string, H)
	for i := 0; i < H; i++ {
		M[i] = nextLine()
	}

	var nq []point
	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			if string(M[y][x]) == "#" {
				nq = append(nq, point{x: x, y: y})
			}
		}
	}

	dists := []point{point{-1, 0}, point{1, 0}, point{0, -1}, point{0, 1}}
	reached := make([][]bool, H)
	for y := 0; y < H; y++ {
		reached[y] = make([]bool, W)
	}

	res := 0
	for len(nq) > 0 {
		q := make([]point, len(nq))
		copy(q, nq)
		nq = nil
		for _, u := range q {
			for _, d := range dists {
				nx, ny := u.x+d.x, u.y+d.y
				if nx < 0 || nx >= W || ny < 0 || ny >= H {
					continue
				}
				if string(M[ny][nx]) == "#" || reached[ny][nx] {
					continue
				}
				reached[ny][nx] = true
				nq = append(nq, point{x: nx, y: ny})
			}
		}
		if len(nq) > 0 {
			res++
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 51200
#include<iostream>
using namespace std;
int main () {
    long n, b, min, max;
    long total = 0;
    min = 1000000;
    max = -1000000;
    cin >> n;
    for(int i=0; i < n; i++) {
        cin >> b;
        if (b < min) {
            min = b;
        }
        if (b > max) {
            max = b;
        }
        total = total + b;
    }
    cout << min << " " << max << " " << total << endl;
    return 0;
}



Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	
	string s;
	cin>>s;
	
	s[k-1]+=32;
	
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
using graph = vector<vector<int>>;

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int h, w, k; cin >> h >> w >> k;
	vector<vector<char>> mp(h, vector<char>(w));
	rep(i,h){
		rep(j,w){
			cin >> mp[i][j];
		}
	}
	int ans = 0;
	for(int i = 0; i < (1<<h); i++){
		for(int j = 0; j < (1<<w); j++){
			vector<vector<char>> mp1 = mp;
			int cnt = 0;
			for(int a = 0; a < h; a++){
				if(i & 1<<a){
					rep(l, w) mp1[a][l] = '.';
				}
			}
			for(int a = 0; a < w; a++){
				if(j & 1<<a){
					rep(l, h) mp1[l][a] = '.';
				}
			}
			rep(a,h){
				rep(l,w){
					if(mp1[a][l] == '#') cnt++;
				}
			}
			if(cnt == k) ans++;
		}
	}
	cout << ans << endl;
} 

Measured memory_bytes: 3656
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    x = II()
    dp = [0] * (x + 1)
    dp[0] = 1
    for i in range(6):
        a = 100 + i
        for i in range(a, x + 1):
            dp[i] |= dp[i - a]
    print(dp[-1])
    return


#main
if __name__ == '__main__':
    solve()


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

int N;

const int INF = 1e9+5;

int main() {
  
  cin >>N;

  vector <int> heights (N);

  for (int& height: heights) {
    cin >> height;
  }


  vector <int> dp (N, INF);

  dp[0] = 0;

  for (int i =0; i<N; i++) {

    if (i+1 <N )
      dp [i+1] = min (dp [i+1], dp [i] + abs(heights[i+1]-heights[i]));
    

    if (i+2 <N )
      dp [i+2] = min (dp [i+2], dp [i] + abs(heights[i+2]-heights[i]));
    
  }

  cout << dp [N-1];
}

Measured memory_bytes: 4016
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
using namespace std;

//#define FILE_INPUT
//#define DEBUG_MODE

int memo[100000];
int h[100000];

int Search(int n, int position)
{
	if (position == n - 1) {
		return 0;
	}
	if (memo[position] >= 0) {
		//cout << "get : " << position << endl;
		return memo[position];
	}
	int cost = abs(h[position] - h[position + 1]) + Search(n, position + 1);
	if (position < n - 2) {
		int cost2 = abs(h[position] - h[position + 2]) + Search(n, position + 2);
		if (cost2 < cost) {
			cost = cost2;
		}
	}
	memo[position] = cost;
	//cout << "save : " << position << endl;
	return cost;
}

int main()
{
#ifdef FILE_INPUT
	ifstream in("test3.txt");
	cin.rdbuf(in.rdbuf());
#endif	/* FILE_INPUT */  
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
		memo[i] = -1;
	}

	int min = Search(n, 0);
	cout << min << endl;

	return 0;
}

Measured memory_bytes: 5760
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

if P == Q:
    print(0)
else:
    l = []
    for i in range(1, N+1):
        l.append(i)

    t = tuple(l)
    p = 0
    q = 0
    for i, v in enumerate(itertools.permutations(t)):
        if P == v:
            p = i+1
        elif Q == v:
            q = i+1
    print(abs(p - q))

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

int main() {
  int K,A,B;
  cin >> K;
  cin >> A >> B;

  string res = "NG";

  for(int i=A; i<=B; i++){
    if(i%K==0){
      res = "OK";
      break;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 3560
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String s = sc.next();
      String t = sc.next();
      int count = 0;
      for(int i = 0;i <= s.length();i++){
      	if(s.equals(t))count++;
        s = s.substring(s.length()-1,s.length())+s.substring(0,s.length()-1);
      }
      if(count > 0)System.out.println("Yes");
      else System.out.println("No");
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n;

int main()
{
    scanf("%d",&n);
    int maxx=0,ind=-1;
    for(int i=1;i<=n;i++)
    {
        int num;scanf("%d",&num);
        if(abs(num)>abs(maxx))
            ind=i,maxx=num;
    }
    if(ind==-1)
    {
        cout<<0<<endl;
        return 0;
    }
    cout<<2*n-1<<endl;
    for(int i=1;i<=n;i++)
        cout<<ind<<" "<<i<<endl;
    if(maxx>0)
        for(int i=1;i<n;i++)
            cout<<i<<" "<<i+1<<endl;
    else
        for(int i=n;i>1;i--)
            cout<<i<<" "<<i-1<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
  INIT = 100
  
  query = []
  ans = []
  while True:
    q = int(input())
    if q == 0:
      break
    query.append(q)
  MAX = max(query)
  
  table = [INIT] * (MAX + 1)
  table[0] = 0
  all_item = [i * (i + 1) * (i + 2) // 6 for i in range(1, 181)]
  odd_item = [i for i in all_item if i % 2]
  eve_item = [i for i in all_item if not i % 2]
  
  for v in odd_item:
    for j in range(v, MAX + 1):
      tjv = table[j - v]
      if table[j] > tjv + 1:
        table[j] = tjv + 1
  
  for q in query:
    ans.append(table[q])
  
  for v in eve_item:
    for j in range(v, MAX + 1):
      tjv = table[j - v]
      if tjv < 5 and table[j] > tjv + 1:
        table[j] = tjv + 1
  
  for i, q in enumerate(query):
    print(table[q], ans[i])

main()


Measured memory_bytes: 13160
N = int(input())
no = [i for i in range(N)]
A = list(map(int, input().split()))

no_minus_height = {}
#no_plus_height = {}
total = 0
for i in range(N-1,-1,-1):
    no_plus_height = no[i]+A[i]
    try:
        total += no_minus_height[no_plus_height]
    except:
        pass
    
    try:
        no_minus_height[no[i]-A[i]] += 1
    except:
        no_minus_height[no[i]-A[i]] = 1
print(total)

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

int main() {
  string n;
  cin >> n;
  int sum = n[0] - '0';
  for (int i = 1; i < n.size(); ++i) {
    if (n[i] != '9') {
      sum--;
      sum += 9 * (n.size() - i);
      break;
    }
    sum += 9;
  }
  cout << sum << endl;
  return 0;
}

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

using namespace std;

int main() {
	string S;
	cin >> S;
	int ans = 1e9;

	for (int i = 0; i < 2; i++) {
		int cnt = 0;
		for (int j = 0; j < S.size(); j++) {
			if (j % 2 == 0 && S[j] != (char)(i + '0')) {
				cnt++;
			}
			if (j % 2 == 1 && S[j] == (char)(i + '0')) {
				cnt++;
			}
		}
		ans = min(ans, cnt);
	}

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N = 1 << 17;

int n, s, t, lim;
int a[20], b[20];
int bitcnt[N];

void output() {
	int num = 0;
	for (int i = 0; i < n; ++i) {
		num += a[i] << i;
 	}
	printf("%d ", num);
}

void search(int lim) {
	if (lim == 0) return;
	for (int i = 0; i < n; ++i) {
		if (lim >> i & 1) {
			search(lim ^ (1 << i));
			a[i] ^= 1;
			output();
			search(lim ^ (1 << i));
			break;
		}
	}
}

void solve(int lim) {
	int pos = -1;
	for (int i = 0; i < n; ++i) {
		if (a[i] != b[i]) {
			pos = i;
			break;
		}
	}
	if (pos == -1) {
		return;
	}
	lim ^= 1 << pos;
	// cout << pos << ' ' << lim << endl;
	// return;
	output();
	search(lim);
	a[pos] ^= 1;
	solve(lim);
}

int main() {
	cin >> n >> s >> t;
	lim = (1 << n) - 1;
	for (int i = 1; i < (1 << n); ++i) {
		bitcnt[i] = bitcnt[i >> 1] + (i & 1);
	}
	for (int i = 0; i < n; ++i) {
		a[i] = s >> i & 1;
		b[i] = t >> i & 1;
	}
	if (abs(bitcnt[s] - bitcnt[t]) % 2 != 1) return 0 * puts("NO");
	puts("YES");
	solve(lim);
	printf("%d\n", t);
}


Measured memory_bytes: 1536
import java.util.Scanner;
     
    public class Main {
     
    static Scanner sc = new Scanner(System.in);
    static String str;
     
    static boolean solve() {
    int change = 0;
    for (int i = 0; i < str.length() - 1; ++i) {
    if (str.charAt(i) != str.charAt(i + 1)) ++change;
    }
    if (str.charAt(0) == 'o' && str.charAt(str.length() - 1) == 'o') {
    ++change;
    }
    return change % 2 != 0;
    }
     
    public static void main(String[] args) {
    str = sc.next();
    System.out.println(solve() ? 'o' : 'x');
    }
    }

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

int main(){
    double pai=3.141592653589;
    int n;
    int x[1000],y[1000];
    double ans1=0,ans2=0,ans3=0,ans4=0,anstmp=0,tmp;
    scanf("%d",&n);
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            if(i==0) scanf("%d",&x[j]);
            else scanf("%d",&y[j]);
        }
    }
    for(int i=0;i<n;i++){
        ans1+=abs(x[i]-y[i]);
    }
    printf("%.8lf\n",ans1);
    for(int i=0;i<n;i++){
        ans2+=(x[i]-y[i])*(x[i]-y[i]);
    }
    printf("%.8lf\n",pow(ans2,1.0/2.0));

    for(int i=0;i<n;i++){
        tmp=abs(x[i]-y[i]);
        ans3+=tmp*tmp*tmp;
    }
    printf("%.8lf\n",pow(ans3,1.0/3.0));

    for(int i=0;i<n;i++){
        anstmp=abs(x[i]-y[i]);
        ans4=max(ans4,anstmp);
    }
    printf("%.8lf\n",ans4);

    return 0;
}


Measured memory_bytes: 3376
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("\\s");
int a = sc.nextInt();
int b = sc.nextInt();
if(a<b)
System.out.println("a < b");
else if (a>b)
System.out.println("a > b");
else
System.out.println("a == b");
    }
}


Measured memory_bytes: 26260
N,K = map(int,input().split())
counter = [0 for _ in range(N)]
for _ in range(K):
    _ = int(input())
    p = map(int,input().split())
    for i in p:
        counter[i-1] += 1
total = 0
for i in counter:
    if i == 0:
        total += 1
print(total)

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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    vector<int> b(n);
    rep(i,n-1)cin>>b[i];
    ll ans = 0;
    rep(i,n){
        if(i==0)ans+=b[0];
        else if(i==n-1)ans+=b[n-2];
        else ans+=min(b[i-1],b[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
_n, m = gets.split.map(&:to_i)

data = m.times.map.with_index do |i|
  p, y = gets.split.map(&:to_i)
  [p, i, y]
end

ken = data.clone.group_by(&:first)

ken.each do |p, value|
  value
    .sort_by(&:last)
    .each.with_index(1) {|(_p, data_index, _year), order| data[data_index][2] = order }
end

data.each {|p, _i, y| puts "%06d%06d" % [p, y] }


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

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



}

Measured memory_bytes: 256
n = int(input())
cbt = input().split()
cbt.insert(0,0)

for i in range(1,len(cbt)):
    parent_index = int(i/2)
    left_index = 2*i
    right_index = 2*i +1
    if i == 1:
        print('node {}: key = {}, left key = {}, right key = {}, '.format(
            i,cbt[i],cbt[i+1],cbt[i+2]))
    else:
        if len(cbt) <= left_index:
            print('node {}: key = {}, parent key = {}, '.format(i,cbt[i],cbt[parent_index]))
        elif len(cbt) <= right_index:
            print('node {}: key = {}, parent key = {}, left key = {}, '.format(
                i,cbt[i],cbt[parent_index],cbt[left_index]))
        else:
            print('node {}: key = {}, parent key = {}, left key = {}, right key = {}, '.format(
                i,cbt[i],cbt[parent_index],cbt[left_index],cbt[right_index]))



Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
//#define ACL
#ifdef ACL
#include <atcoder/all>
using namespace atcoder;
#endif
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
using LD = long double;
using VI = vector<int>;
using VVI = vector<vector<int> >;
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T> >;
template <typename T> using VVV = vector<vector<vector<T> > >;
void print() {cout << endl;}
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <typename T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <typename T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> void SORT (T &v) {sort(v.begin(), v.end());}
template <typename T> void SORTR (T &v) {sort(v.begin(), v.end(), greater<>());}
template <typename T> T GCD(T x,T y) {return __gcd(x,y);}
template <typename T> T LCM(T x,T y) {return x/__gcd(x,y)*y;}
template <typename T> int SZ(T v) {return v.size();}
template <typename T> T PCNT(T x) {return __builtin_popcountll(x);}
template <typename T> T BIT(T x) {return 1LL<<(x);}
int INF = 2000000000;
long double PI = acosl(-1);
int MOD = 1000000007;


int32_t main() {
    chrono::system_clock::time_point start_time, end_time;
    start_time = chrono::system_clock::now();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0, res = 0;
    
    REP(i,5) {
        cin >> ans;
        if (ans == 0) {
            cout << i+1 << endl;
            return 0;
        }
    }

    
    



    end_time = chrono::system_clock::now();
    assert(chrono::duration_cast<chrono::milliseconds>(end_time-start_time).count() < 2500);
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc170/abc170_a && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc170/abc170_a && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc170/abc170_a && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3644
#include <stdio.h>

char S[4],T[4];

int main(int argc, char const *argv[])
{
	int corrct = 0;
	scanf("%s", S);
	scanf("%s", T);

	for (int i = 0; i < 3; ++i)
	{
		if (S[i] == T[i])
		{
			corrct++;
		}
	}

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

	return 0;
}

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

const string AL="ATGC";
struct Node{ UL nx[4]; bool ex; Node(){rep(i,4)nx[i]=~0u; ex=false;} };

vector<Node> G;

int main() {
 G.push_back(Node());
 UL Q; scanf("%u",&Q);
 char buf[100];
 rep(q,Q){
  scanf("%s",buf); string c{buf};
  if(c=="insert"){
   scanf("%s",buf); string tg{buf};
   UL p=0;
   for(char c:tg){
    UL nx=G[p].nx[AL.find(c)];
    if(nx==~0u){
     nx=G[p].nx[AL.find(c)]=G.size();
     G.push_back(Node());
    }
    p=nx;
   }
   G[p].ex=true;
  }
  else if(c=="find"){
   scanf("%s",buf); string tg{buf};
   UL p=0;
   for(char c:tg){
    p=G[p].nx[AL.find(c)];
    if(p==~0u) break;
   }
   if(p==~0u) printf("no\n");
   else if(G[p].ex) printf("yes\n");
   else printf("no\n");
   fflush(stdout);
  }
 }
 return 0;
}



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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n+1];
    
    for(int k=1;k<=n;k++)
        cin>>a[k];
        
    
    int d[n+1];
    d[1]=0;
    d[0]=0;
    
    d[2]=abs(a[1]-a[2]);
    d[3]=min(d[1]+abs(a[1]-a[3]),d[2]+abs(a[2]-a[3]));
    
    for(int k=4;k<=n;k++){
        d[k]=min(d[k-1]+abs(a[k-1]-a[k]),abs(a[k-2]-a[k])+d[k-2]);
    }
        
    cout<<d[n];    

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int n,k;scanf("%d%d",&n,&k);
	int id;
	for(int i=1;i<=n;i++)
	{
		int a;scanf("%d",&a);
		if(a==1)id=i;
	}
	n--;k--;
	int ok=0;if(n%k)ok++;
	printf("%d\n",n/k+ok);return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <sstream>
#include <iostream>
#include <cstdlib>

using namespace std;

#define BUF_SIZE 1024
#define ARRAY_SIZE 100


void selectionSort(int array[],int n,int& change_count)
{
	int min;
	for(int i = 0; i < n-1; i++){
		min = i;	//?????????
		for(int j = i+1; j < n; j++){
			if(array[j] < array[min]){
				min = j;
			}
		}
		if(i != min){
			swap(array[i],array[min]);
			change_count++;
		}
	}

}

int main(){

	char buf[BUF_SIZE];
	int n = atoi(fgets(buf,BUF_SIZE,stdin));
	int array[ARRAY_SIZE];
	int change_count = 0;

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

	selectionSort(array,n,change_count);

	for(int i = 0; i < n; i++){
		if(i != n-1){
			printf("%d ",array[i]);
		}else{
			printf("%d\n",array[i]);
		}
	}
	printf("%d\n",change_count);
}


Measured memory_bytes: 3228
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        String[] p = scan.next().split("");
        for (int i = 1; i <= 3; i++) {
            if (p[i - 1].equals(p[i])) {
                System.out.println("Bad");
                break;
            }
          if(i==3)
                  System.out.println("Good");
        }

    }
}

Measured memory_bytes: 22228
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for(int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 0x3b9aca07;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

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

	int n, m; cin >> n >> m;

	vector<string> a(n), b(m);
	rep(i, 0, n) cin >> a[i];
	rep(i, 0, m) cin >> b[i];

	rep(i, 0, n) {
		rep(j, 0, n) {
			bool ok = true;
			rep(k, 0, m) {
				rep(l, 0, m) {
					if (i + k >= n || j + l >= n || a[i + k][j + l] != b[k][l]) ok = false;
				}
			}
			if (ok)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}


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

#define task "C"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
int n, a[200004];
map<int, int> mp;
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	bool ok = 1;
	rep(i, 1, n)
	{
	    cin >> a[i];
	    if (mp[a[i]]) ok = 0;
	    mp[a[i]] = 1;
	}
	cout << (ok ? "YES" : "NO");
}


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

int main(){
  long long n;
  cin>>n;
  long long arr[n],cnt = 0;
  map<long long,long long> m;
  for(int i=0;i<n;i++){
    cin>>arr[i];
    m[arr[i]]++;
  }
  map<long long,long long> m1;
  for(auto it : m){
    if(it.second >= 2){
      m1[it.first] = ((it.second)*(it.second - 1))/2;
      cnt+=m1[it.first];
    }
  }
//   cout<<cnt<<"\n";
//   for(auto it:m){
//       cout<<it.first<<" "<<it.second<<"\n";
//   }
  for(int i=0;i<n;i++){
    if(m[arr[i]] >= 2){
      cout<<cnt-m[arr[i]]+1<<"\n";
    }
    else{
        cout<<cnt<<"\n";
    }
  }
  return 0;
}
  

Measured memory_bytes: 14336
n = int(input())

zyunnsitigoL = [3, 5, 7]

def zyunnsitigo(zyunsiL):
    index=0
    newSitiL=[]
    while index < len(zyunsiL):
        newSitiL.append(int(str(zyunsiL[index])+"3"))
        newSitiL.append(int(str(zyunsiL[index])+"5"))
        newSitiL.append(int(str(zyunsiL[index])+"7"))
        index+=1
    return newSitiL

def sitigoCounter(n, zyunsiL):
    index =0
    count =0
    while index < len(zyunsiL):
        if zyunsiL[index]<n+1:
            newSL = list(map(int, list(str(zyunsiL[index]))))
            if 3 in newSL and 5 in newSL and 7 in newSL:
                if 0 in newSL or 1 in newSL or 2 in newSL or 4 in newSL or 6 in newSL or 8 in newSL or 9 in newSL:
                    pass
                else:
                    count+=1
        index+=1
    return count

def listMaker(n, zyunsiL):
    if n < 10:
        return zyunsiL
    else:
        newL = zyunnsitigo(zyunsiL)
        zyunsiL.extend(newL)
        if n > 100:
            newL=zyunnsitigo(newL)
            zyunsiL.extend(newL)
            if n > 1000:
                newL = zyunnsitigo(newL)
                zyunsiL.extend(newL)
                if n > 10000:
                    newL = zyunnsitigo(newL)
                    zyunsiL.extend(newL)
                    if n > 100000:
                        newL = zyunnsitigo(newL)
                        zyunsiL.extend(newL)
                        if n > 1000000:
                            newL = zyunnsitigo(newL)
                            zyunsiL.extend(newL)
                            if n > 10000000:
                                newL = zyunnsitigo(newL)
                                zyunsiL.extend(newL)
                                if n > 100000000:
                                    newL = zyunnsitigo(newL)
                                    zyunsiL.extend(newL)
        return zyunsiL

zyunsiL = listMaker(n, zyunnsitigoL)
ans = sitigoCounter(n, zyunsiL)
print(ans)

Measured memory_bytes: 4468
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[114514]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    long long int cost1=0;
    long long int sum=0;
    for(int i=0;i<n;i++){
        sum+=a[i];
        if(i%2==0){
            if(sum>=0){
                cost1+=sum+1;
                sum=-1;
            }
        }else{
            if(sum<=0){
                cost1+=1-sum;
                sum=1;
            }
        }
    }
    long long int cost2=0;
    sum=0;
    for(int i=0;i<n;i++){
        sum+=a[i];
        if(i%2==0){
            if(sum<=0){
                cost2+=1-sum;
                sum=1;
            }
        }else{
            if(sum>=0){
                cost2+=sum+1;
                sum=-1;
            }
        }
    }
    cout<<min(cost1,cost2)<<endl;
}



Measured memory_bytes: 640
def digit_num(_num):
    _digit = 0
    while _num:
        _digit += 1
        _num //= 10
    return _digit


_num = int(input())
_digit = digit_num(_num)
_topdig = _num // 10 ** (_digit - 1)
_sumlist = [9 * (_digit - 1)]
if (_num - _topdig * 10 ** (_digit - 1)) == 10 ** (_digit - 1) - 1:
    _sumlist.append(_topdig + 9 * (_digit - 1))
else:
    _sumlist.append(_topdig - 1 + 9 * (_digit - 1))

print(max(_sumlist))

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sub = [a[i] - b[i] for i in range(n)]
sub.sort()

minus = 0
count = 0
for i in sub:
    if i >= 0:
        break
    count += 1
    minus += i
sub.reverse()

for i in sub:
    if minus >= 0:
        break
    minus += i
    count += 1
if minus < 0:
    print(-1)
else:
    print(count)

Measured memory_bytes: 18396
#include<bits/stdc++.h>
using namespace std;
pair<int,int> p[105];
int main()
{
    int n,t;
    cin >> n >> t;
    for(int i=0;i<n;++i)
    {
        cin >> p[i].first >> p[i].second;
    }
    sort(p,p+n);
    for(int i=0;i<n;++i)
    {
        if(p[i].second<=t)
        {
            cout << p[i].first;
            return 0;
        }
    }
    cout << "TLE" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,m,n,i;
    scanf("%d %d",&a,&b);
    if(a>b){
        for(i=0;i<a;i++)
            printf("%d",b);
    }
    else{
        for(i=0;i<b;i++)
            printf("%d",a);
    }
}

Measured memory_bytes: 1736
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int k,s;
    cin>>k>>s;
    int ans=0;
    for(int i=0;i<=min(k,s);i++){
        for(int j=0;j<=min(k,s-i);j++){
            if(s-i-j<=k && s-i-j>=0){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <math.h> 
#include <iomanip>
#include <string.h>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define PI 3.14159265358979323846264338327950L

#define INF 0x3f3f3f3f
//const int N = 2e5 + 5;
   
int sum(int l, int r) {

	return (l + r)*(r - l + 1) / 2;

}

int gcd(int a, int b) {

	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a%b);
	}

}

int32_t  main() {

	IOS;

	int N;
	cin >> N;

	string S;
	cin >> S;
	int cnt = 0;

	int r = 0;
	int g = 0;
	int b = 0;
	for (int i = 0; i < N; i++) {

		if (S[i] == 'R') {
			r++;
		}
		else if (S[i] == 'G') {
			g++;
		}
		else {
			b++;
		}

	}

	int tot = r * g*b;

	int rgb = (int)('R') + (int)('G') + (int)('B');

	for (int i = 0; i < N; i++) {

		for (int j = i + 1; j < N; j++) {

			int k = 2 * j - i;

			if (k < N) {

				if ((int)S[i] + (int)S[j] + (int)S[k] == rgb) {

					tot--;

				}

			}

		}


	}

	
	


	cout << tot << endl;

}


Measured memory_bytes: 3160
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    int c1 = 0, c2 = 0;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        if (a % 4 == 0) c1++;
        else if (a%2 == 0) c2++;
    }

    cout << (N-(c2==0) <= c1*2+c2 ? "Yes" : "No") << endl;
}

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

int main()
{
    unsigned long long int n, a[10] = {}, min = 10000000000000001;
    for(int i = 0 ; i < 6; i ++)
    {
        if(i)
            cin >> a[i-1];
        else
            cin >> n;
        if(a[i-1] < min && i)
            min = a[i-1];
    }
    if(n % min == 0)
        cout << n/min + 4;
    else
        cout << n/min + 5;
}


Measured memory_bytes: 256
n,c,k=map(int,input().split())
a=sorted([int(input()) for _ in range(n)],reverse=True)
cnt=0
cnt2=1
while len(a) > 0:
    b=a.pop()
    cnt+=1
    if len(a)==0:
        break
    cnt2=1
    while cnt2<c:
        if a[-1]<=b+k:
            a.pop()
            cnt2+=1
            if len(a)==0:
                cnt2=1
                break
        else:
            cnt2=1
            break
print(cnt)
    

Measured memory_bytes: 52056
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define e cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,k,l,ii,jj;
ll n,m;
ll x,y;
ll a[100005],b[100005];

ll ans=0;
ll sum=0;
ll memo,num;
 
int main(){
	cin>>n>>m;
	if(n>m){
		p(n-1);
	}else{
		p(n);
	}
	return 0;
}

Measured memory_bytes: 4992
from collections import defaultdict
N = int(input())
dict = defaultdict(int)
for i in range(N):
    s = input()
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        dict[s[0]] += 1
a = []
for v in dict.values():
    if v > 0:
        a.append(v)
ans = 0
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        for k in range(j + 1, len(a)):
            ans += a[i] * a[j] * a[k]
print(ans)


Measured memory_bytes: 3316
#include<stdio.h>
int main(){

   char c;

   scanf("%c",&c);

   if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
      printf("vowel\n");
   }else{
      printf("consonant\n");
   }

   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll n, m, a[310][310], ans=INF;
bool b[310];

void dfs(int c) {
	ll ma = 0, game = 0;
	map<ll, ll>mp;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < m;j++) {
			if (!b[a[i][j]]) {
				mp[a[i][j]]++;
				break;
			}
		}
	}
	for (auto u : mp) {
		if (ma < u.sc) {
			ma = u.sc;
			game = u.fr;
		}
	}
	ans = min(ans, ma);
	b[game] = true;
	if (c + 1 == m)return;
	dfs(c + 1);
}

int main() {
	cin >> n >> m;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < m;j++) {
			cin >> a[i][j];
		}
	}
	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    rep(i,30){
        rep(j,20){
            if(i*4 + j*7 == N) {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct node
{
	int a,b;
}g[200005];
int n,t,i,j,k,l1,l2,w[200005],f[40],ans;
long long sum[200005];
bool cmp(node a,node b)
{
	return 1ll*b.a*(a.b+1)<1ll*a.a*(b.b+1);
}
int main()
{
	scanf("%d%d",&n,&t);
	for(i=1;i<=n;++i)
	{
		scanf("%d%d",&j,&k);
		if(j)
			g[++l1]=(node){j,k};
		else
			w[++l2]=k;
	}
	for(i=1;i<=35;++i)
		f[i]=1<<30;
	if(l1)
	{
		sort(g+1,g+1+l1,cmp);
		for(i=1;i<=l1;++i)
			for(j=35;j>=1;--j)
				f[j]=min(1ll*f[j],1ll*(f[j-1]+1)*(g[i].a+1)+g[i].b);
	}
	sort(w+1,w+1+l2);
	for(i=1;i<=l2;++i)
		sum[i]=sum[i-1]+1+w[i];
	for(i=0;i<=35;++i)
		if(f[i]<=t)
		{
			for(j=0;j<=l2&&sum[j]<=t-f[i];++j);
			ans=max(ans,i+j-1);
		}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>

std::string f(int t, std::vector<std::pair<int, int> > arr) {
    int min_cost = -1;
    for (int i = 0; i < arr.size(); i++) {
        if (arr[i].second > t) {
            continue;
        }
        if (min_cost == -1 || min_cost > arr[i].first) {
            min_cost = arr[i].first;
        }
    }

    if (min_cost == -1) {
        return "TLE";
    }

    return std::to_string(min_cost);
}

int main() {

    int n, t;
    std::cin >> n >> t;

    std::vector<std::pair<int, int> > arr;
    for (int i = 0; i < n; i++) {
        std::pair<int, int> p;
        std::cin >> p.first >> p.second;
        arr.push_back(p);
    }

    std::string result = f(t, arr);
    std::cout << result << std::endl;

    return 0;
}


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

using namespace std;

int main() {
    long double a, b, h, m;

    long double kakudo;

    long double result;

    cin >> a >> b >> h >> m;

    m /= 5;
    h += m / 12;
    long double wariai = (h - m);

    kakudo = 3.141592653589793238462643 * abs(wariai) / 6;
    //cout<<cos(kakudo)<<endl;

    result = sqrt(a * a + b * b - (2 * a * b * cosl(kakudo)));

    cout << setprecision(20) << result << endl;
}


Measured memory_bytes: 4156
#include <cstdio>
#include <cmath>
using namespace std;

typedef long long int LLI;

int cnt;
LLI sum;
LLI total;

int main() {
  while (1) {
    LLI a, b;
    if (scanf("%lld,%lld", &a, &b) != 2) break;
    cnt++;
    sum += a*b;
    total += b;
  }

  printf("%lld\n", sum);
  printf("%d\n", (int)round(total/double(cnt)));
}

Measured memory_bytes: 2704
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>

int main() {
	int n, x; std::cin >> n >> x;
	int current = 0;
	int count = 0;
	for (auto i = 0; i < n; ++i) {
		int l; std::cin >> l;
		if (current <= x) {
			++count;
		}
		current += l;
	}
	if (current <= x) {
		++count;
	}
	std::cout << count << std::endl;
}



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

using ll = long long;

signed main(){
    ll n,od=0,ev=0,ans=0;cin>>n;
    for(int i=0;i<n;i++){
        ll x;cin>>x;
        if(x%2==0){
            ev++;
        }else{
            od++;
        }
    }

    if(!od || !ev){
        cout<<0<<endl;
        return 0;
    }

    ans+=(od-1)/2;
    ev+=(od-1)/2;

    ans+=ev;

    cout<<ans<<endl;

}


Measured memory_bytes: 3092
N, M = [int(i) for i in input().split()]
counter = [0 for i in range(M)]
count = 0
A = []
for i in range(N):
  A.append([int(i) for i in input().split()])
  A[i] = A[i][1:]
  for a in A[i]:
    counter[a - 1] += 1

for i in range(M):
  if counter[i] == N:
    count += 1

print(count)
  

Measured memory_bytes: 3060
n,m=map(int,input().split())
A=[]
b=[]
for i in range(n):
    A.append([int(x) for x in input().split()])
for i in range(m):
    b.append([int(input())])
for i in range(n):
    sum=0
    for j in range(m):
        sum+=A[i][j]*b[j][0]
    print(sum)


Measured memory_bytes: 6020
/*
created on 21/4/2020
*/
#include<bits/stdc++.h>
using namespace std;
#define Endl '\n'
typedef long long int lli;
void solve();
int main(int argc, char const *argv[]){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
int H, W;
int const maxlen = (1e3) + 100;
int const MOD=(1e9) + 7;
char arena[maxlen][maxlen];
lli memo[maxlen][maxlen];
lli dfs(int i, int j){
  if(i == H && j == W)
    return 1;
  if(arena[i][j]!='.')
    return 0;
  lli& ret  = memo[i][j];
  if(ret!=-1)
    return ret%MOD;
  return ret  = (dfs(i+1, j)%MOD + dfs(i, j+1)%MOD)%MOD;
}
void solve(){
  cin>>H>>W;
  memset(memo, -1, sizeof memo);
  memset(arena, '#', sizeof arena);
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin>>arena[i][j];
    }
  }
  lli ans = dfs(1, 1)%MOD;
  cout<<ans<<Endl;
}


Measured memory_bytes: 11008
//12252024832524
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; 

typedef long long LL;
const int MAXN = 10005;
LL n,ans,now = 100;

LL Read()
{
	LL x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(LL x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(LL x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
	if(c >= 0) putchar(c);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n = Read();
	while(now < n)
	{
		now += now / 100;
		ans++;
	}
	Put(ans);
	return 0;
}

Measured memory_bytes: 2976
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+15
#define MOD 1000000007
using namespace std;


int main(){
    int n,h,w;
    cin >> n >> h >> w;
    cout << (n-h+1)*(n-w+1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;


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

    int out = 0;
    for (int i = 1; i <= N; i += 2)
    {
        int n = 0;
        for (int j = 1; j <= i; j += 2)
            if (i % j == 0)
                ++n;
        if (n == 8)
            ++out;
    }
    cout << out << endl;
}


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

int main(){
	int N;
	string S;
	cin>>S;
	int ans1=0,ans2=0;
	for(int i=0;i<S.length();++i){
		if(i%2==0){
			if(S[i]=='1')ans1++;
			else ans2++;
		}
		else{
			if(S[i]=='0')ans1++;
			else ans2++;
		}
	}
	cout<<min(ans1,ans2)<<endl;
}


Measured memory_bytes: 512