akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int p,q,r;
int ans;
int a[7];
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>p>>q>>r;
    ans = INT_MAX;
    a[1] = p+q;
    a[2] = p+r;
    a[3] = q+r;
    for(int i=1;i<=3;i++){
        ans = min(ans,a[i]);
    }
    cout<<ans<<newl;
}



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

import sys
from functools import reduce
from operator import xor

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=[INT() for i in range(N)]

mnbit=set()
for i, a in enumerate(A):
    bina=format(a, 'b')
    # 2進で最初に1になる桁を、各値について見る
    mnbit.add(len(bina)-bina.rfind('1'))

# 現状のA全部XOR
res=format(reduce(xor, A, 0), 'b')
cnt=0
ln=len(res)
for i in range(ln):
    idx=ln-i
    # 大きい桁から見て、1になっているところについて処理する
    if res[i]=='1':
        # その桁用の値があるか
        if idx in mnbit:
            # あればそれを1減らせば、その桁より下が全部反転する
            res=format(int(res, 2)^int('1'*idx, 2), '0'+str(ln)+'b')
            cnt+=1
        else:
            # 必要な桁用の値がなければNG
            print(-1)
            exit()
print(cnt)


Measured memory_bytes: 7656
//Minimization

#include<stdio.h>
#include<math.h>

int main(void){
    double n,k;
    scanf("%lf%lf", &n,&k);
    double a;
    for(int i=0; i<n; i++){
        scanf("%lf", &a);
    }

    printf("%d\n", (int)ceil((n-1)/(k-1)));

    return 0;
}

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

int main() {

    int n;

    std::cin >> n;

    if(n%10 == 3){
        std::cout << "bon";

    } else if (n%10 ==0 | n%10 ==1 | n%10 ==6 | n%10 ==8){
        std::cout << "pon";

    } else {
        std::cout << "hon";
        
    }

    return 0;
}


Measured memory_bytes: 3624
line=input().split()
h=int(line[0])
w=int(line[1])
m = []
m.append("."*(w+2))
for i in range (h):
    m.append("." + input() + ".")
m.append("."*(w+2))
works=True
for i in range (1,h+1):
    for j in range (1,w+1):
        if m[i][j]=="#":
            if m[i+1][j]=="#" and m[i][j+1]=="#":
                works=False
            if m[i-1][j]=="#" and m[i][j-1]=="#":
                works=False
if works:
    print ("Possible")
else:
    print("Impossible")
        


Measured memory_bytes: 3188
n = io.read('*n')

e = {}
for i = 1, n do e[i] = {} end

for i = 1, n - 1 do
    local a, b, c = io.read('*n'), io.read('*n'), io.read('*n')
    e[a][#e[a] + 1] = { b, c }
    e[b][#e[b] + 1] = { a, c }
end

far = {}

dfs = function (u, p, d)
    far[u] = d
    for i = 1, #e[u] do if e[u][i][1] ~= p then
        dfs(e[u][i][1], u, d + e[u][i][2])
    end end
end

q, k = io.read('*n'), io.read('*n')

dfs(k, -1, 0)

for i = 1, q do print(far[io.read('*n')] + far[io.read('*n')]) end


Measured memory_bytes: 67832
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n m
k1 a11 ... a1k1
...
kn an1 ... ankn

n m 30
 */
int n,m,a[30][30];
int num[30];

int main(){
  cin>>n>>m;
  REP(i,n){
    int k;
    cin>>k;
    REP(j,k){
      cin>>a[i][j];
      a[i][j]--;
      num[a[i][j]]++;
    }
  }

  int ans=0;
  REP(j,m){
    if(num[j]==n)
      ans++;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001
typedef long long ll;

int n;
int a;

ll dp[51][51][2510];
int x[50];
// char X[100][100];
// int dp[1000000001];

int main(void){
    cin >> n >> a;
    REP(i,0,n) {
        cin >> x[i];
    }
    
    dp[0][0][0] = 1;
    REP(i,0,n) REP(j,0,n) REP(k,0,2500) {
        if (dp[i][j][k]) {
            dp[i+1][j][k] += dp[i][j][k];
            dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
        }
    }
    

    ll ans = 0;
    REP(i,1,n+1) {
        ans += dp[n][i][i*a];
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 48256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, K;
string S;

int section_count(string S) {
    string aSa = "a" + S;
    int res = 0;
    for(int i = 1; i < N + 1; ++i) {
        if(aSa[i] != aSa[i - 1]) {
            res++;
        }
    }
    return res;
}


int main(int argc, char **argv) {
    cin >> N >> K >> S;

    int sections = section_count(S);
    int res = N - sections;

    int X = sections % 2 == 1 ? 
            (sections - 1) / 2 : (sections - 2) / 2;
    
    X = min(K, X);
    K -= X;
    res += X * 2;

    if(K > 0 && sections % 2 == 0) {
        res++;
    }

    cout << res << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
//#define DEBUG

/*??°????????°?????????????????°??§????´?*/
int map[14][14] = {{}};



void search(int,int);

int main (void){


	while (1){
		char str[12] = {};
		int counter = 0 ;
		int i = 0 ;
		int j = 0 ;
		/*??°??????????????????*/

		for( i = 0 ; i < 12 ; i++){
				if(scanf("%s",str) == EOF){			//EOF???????????£??????????????´??§??????
					return 0;
				}
				for ( j = 0 ; j < 12 ; j++){
					map[i+1][j+1] = str[j] - '0';
				}
		}



		for(i = 0 ; i < 14 ; i++){
			for( j = 0 ; j < 14 ; j++){
				if(map[i][j]){			//?????°?????£??????

					search(i,j);
					counter++;
				}
			}
		}


#ifdef DEBUG
		//??°????????¶????????¨????????????
		for(i = 0 ; i < 14 ; i++){
			for( j = 0 ; j < 14 ; j++){
				printf("%2d",map[i][j]);
			}
			printf("\n");
		}
#endif

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




	}
	return 0;
}

void search(int x,int y){
	map[x][y] = 0 ;
	if(map[x][y-1]){
		search(x,y-1);
	}
	if(map[x][y+1]){
		search(x,y+1);
	}
	if(map[x-1][y]){
		search(x-1,y);
	}
	if(map[x+1][y]){
		search(x+1,y);
	}
}

Measured memory_bytes: 548
n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    line = list(map(int, input().split()))
    s.append(line[0])
    c.append(line[1])
l = 10**(n-1)
if n == 1:
    l = 0
for i in range(l, 10**n):
    flag = 0
    flag2 = 0
    for j in range(m):
        if str(i)[s[j]-1] != str(c[j]):
            flag = 1
    if flag == 0:
        print(i)
        flag2 = 1
        break
if flag2 == 0:
    print(-1)

Measured memory_bytes: 40688
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
const int INF = 1e18, MOD = 1e9 + 7;

signed main() {
    int h, n, a, b;
    cin>>h>>n;
    int dp[111111] = {};
    dp[0] = 0;
    for (int i = 1; i < 111111; i++) {
        dp[i] = INF;
    }
    pair<int, int> w[1111];
    int mx = -INF;
    for (int i = 0; i < n; i++) {
        cin>>a>>b;
        mx = max(mx, a);
        w[i] = make_pair(a, b);
    }
    for (int i = 0; i < h + mx; i++) {
        for (int j = 0; j < n; j++) {
            dp[i + w[j].first] = min(dp[i + w[j].first], dp[i] + w[j].second);
        }
    }
    int mn = INF;
    for (int i = h; i < 111111; i++) {
        mn = min(mn, dp[i]);
    }
    cout<<mn<<endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=3123;

int d,a,b,i2,kmax,pos;
ll dp[102],res,tmp[102],tmp2;
char k[10002];

int main()
{
    scanf("%s",&k);
    for(; k[kmax]!=0; ++kmax)
    {
        a+=k[kmax]-'0';
    }
    scanf("%d",&d);
    pos=kmax-1;
    dp[0]=1;
    a%=d;
    if(a==0)
        ++res;
    while(pos>=0)
    {
        if(k[pos]!='0')
        {
            b=k[pos]-'0';
            a-=b;
            while(a<0)
                a+=d;
            tmp2=0;
            i2=(d-a)%d;
            for(int i=0; i<b; ++i)
            {
                tmp2+=dp[i2];
                --i2;
                if(i2<0)
                    i2+=d;
            }
            res=(res+tmp2)%MOD;
        }
        tmp[0]=0;
        i2=d-1;
        for(int i=0; i<9; ++i)
        {
            tmp[0]+=dp[i2];
            --i2;
            if(i2<0)
                i2+=d;
        }
        for(int i=1; i<d; ++i)
        {
            ++i2;
            i2%=d;
            tmp[i]=tmp[i-1]+dp[i-1]-dp[i2];
        }
        for(int i=0; i<d; ++i)
        {
            dp[i]=(dp[i]+tmp[i])%MOD;
        }
        --pos;
    }
    --res;
    if(res<0)
        res+=MOD;
    printf("%lld",res);
    return 0;
}


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

const int maxn = 2005;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int n, k, cnt, eu[maxn], ev[maxn];

struct edge
{
	int to, next;
} e[maxn * 2];
int h[maxn], tot;

void add(int u, int v)
{
	e[++tot] = (edge) {v, h[u]}; h[u] = tot;
	e[++tot] = (edge) {u, h[v]}; h[v] = tot;
}

void dfs(int u, int fa, int d)
{
	if (d > k) ++cnt;
	for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
		if (v != fa) dfs(v, u, d + 1);
}

int main()
{
	n = gi(); k = gi();
	for (int i = 1; i < n; ++i) add(eu[i] = gi(), ev[i] = gi());

	int ans = 1e9;
	if (~k & 1) {
		k >>= 1;
		for (int i = 1; i <= n; ++i) {
			cnt = 0; dfs(i, 0, 0);
			ans = min(ans, cnt);
		}
	} else {
		k >>= 1;
		for (int i = 1; i < n; ++i) {
			cnt = 0;
			dfs(eu[i], ev[i], 0);
			dfs(ev[i], eu[i], 0);
			ans = min(ans, cnt);
		}
	}

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



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

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (i % 2 == 0 && a % 2 == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define INF (int)1e9+5
#define nax (int)1e5+2
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hello\n"
using namespace std;



int main(){
	fast;
	//1 dimension dp[k] -> bool
	int n,k;
	cin>>n>>k;
	vector<bool> dp(k+2,false);
	dp[0] = false;
	vector<int> values(n);
	for(int i=0;i<n;i++){
		cin>>values[i];
	}
	for(int i=0;i<k;i++){
		if(dp[i] == false){
			for(int j=0;j<n;j++){
				if(i+values[j]<=k){
					dp[i+values[j]] = true;
				}
			}
		}
	}
	if(dp[k] == true){
		cout<<"First\n";
	}
	else{
		cout<<"Second\n";
	}
	
	return 0;
}


Measured memory_bytes: 256
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    x = root(x)
    y = root(y)
    par[x] = y

v,e = map(int, input().split())
adj = [list(map(int, input().split())) for i in range(e)]
adj.sort(key = lambda x:x[2])
par = [i for i in range(v)]
sum = 0

for i,j,k in adj:
    if not same(i, j):
        sum += k
        unite(i, j)
print(sum)


Measured memory_bytes: 28188
class BinarySearchTree:
    def __init__(self):
        self.root = None
        self.order_list = []
    def insert(self, z):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z
    def find(self, key):
        x = self.root
        while x != None:
            if key == x.key:
                return x
            elif key < x.key:
                x = x.left
            else:
                x = x.right
        return None
    def delete(self, z):
        if z.left == None and z.right == None:
            if z.key < z.parent.key:
                z.parent.left = None
            else:
                z.parent.right = None
        elif z.left != None and z.right == None:
            z.left.parent = z.parent
            if z.key < z.parent.key:
                z.parent.left = z.left
            else:
                z.parent.right = z.left
        elif z.left == None and z.right != None:
            z.right.parent = z.parent
            if z.key < z.parent.key:
                z.parent.left = z.right
            else:
                z.parent.right = z.right
        else:
            next_node = z.right
            while next_node.left:
                next_node = next_node.left
            z.key = next_node.key
            self.delete(next_node)
            
    def walk_preorder(self, node):
        if node == None:
            return None
        self.order_list.append(node.key)
        self.walk_preorder(node.left)
        self.walk_preorder(node.right)
    def walk_inorder(self, node):
        if node == None:
            return None
        self.walk_inorder(node.left)
        self.order_list.append(node.key)
        self.walk_inorder(node.right)
    def print_nodes(self):
        self.order_list = []
        self.walk_inorder(self.root)
        inorder_str = ' '.join(map(str, self.order_list))
        print(' {}'.format(inorder_str))
        self.order_list = []
        self.walk_preorder(self.root)
        preorder_str = ' '.join(map(str, self.order_list))
        print(' {}'.format(preorder_str))
        
class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

n = int(input())
tree = BinarySearchTree()
for _ in range(n):
    command = input().split(' ')
    if len(command) == 1:
        tree.print_nodes()
    else:
        opecode, operand = command[0], int(command[1])
        if opecode == 'insert':
            node = Node(operand)
            tree.insert(node)
        elif opecode == 'find':
            node = tree.find(operand)
            if node != None:
                print('yes')
            else:
                print('no')
        elif opecode == 'delete':
            node = tree.find(operand)
            if node != None:
                tree.delete(node)


Measured memory_bytes: 121440
#include <iostream>

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

using namespace std;

int main(){
	while(1){
		int n, m, p, x, total, tickets;
		double ans;
		cin >> n >> m >> p;
		if (n==0 && m==0 && p==0) return 0;
		total = 0;
		for(int i=1; i<=n; i++){
			cin >> x;
			total += x;
			if (i==m) tickets = x;
		}
		if (tickets==0) ans = 0;
		else	 ans = (total*(100-p))/tickets;
		cout << (int)ans << endl;
	}
	return 0;
}




Measured memory_bytes: 3084
/*
[abc106] D - AtCoder Express 2
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 500;
const int MAX_M = 200000;

int N, M, Q;
int L[MAX_M], R[MAX_M];
int imos[MAX_N + 1][MAX_N + 1];

void do_imos() {
    for (int i = 0; i < M; i++) {
        imos[L[i]][R[i]]++;
    }
    for (int j = 0; j <= N; j++) {
        for (int i = 0; i < N; i++) {
            imos[i + 1][j] += imos[i][j];
        }
    }
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j < N; j++) {
            imos[i][j + 1] += imos[i][j];
        }
    }
}

ll solve(int p, int q) { return imos[N][q] - imos[p - 1][q]; }

int main() {
    cin >> N >> M >> Q;
    for (int i = 0; i < M; i++) {
        cin >> L[i] >> R[i];
    }

    do_imos();

    for (int i = 0; i < Q; i++) {
        int p, q;
        cin >> p >> q;
        cout << solve(p, q) << endl;
    }

    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

const int MOVE = 0;
const int BARRIIER = 1;
const int JUMP = 2;

int course[15][15];
int prog[15][15];
int sizeX, sizeY;
int answer = 0;

void init() {
  for (int i = 0; i < 15; i++) {
    for (int j = 0; j < 15; j++) {
      prog[i][j] = 0;
      course[i][j] = -1;
    }
  }
}

void inputCourse() {
  for (int i = 0; i < sizeY; i++) {
    for (int j = 0; j < sizeX; j++) {
      cin >> course[i][j];
    }
  }
}

int main(int argc, char* argv[]) {
  while (cin >> sizeX >> sizeY, sizeX) {
    init();
    inputCourse();
    answer = 0;
    for (int x = 0; x < sizeX; x++) {
      if (course[0][x] == MOVE) {
        prog[0][x] = 1;
      }
    }
    for (int y = 0; y < sizeY; y++) {
      for (int x = 0; x < sizeX; x++) {
        if (course[y][x] == MOVE) {
          if (y + 1 >= sizeY) {
            answer += prog[y][x];
          } else {
            if (course[y + 1][x] == MOVE || course[y + 1][x] == JUMP) {
              prog[y + 1][x] += prog[y][x];
            }
            if (x - 1 >= 0 && course[y + 1][x - 1] == MOVE) {
              prog[y + 1][x - 1] += prog[y][x];
            }
            if (x + 1 < sizeX && course[y + 1][x + 1] == MOVE) {
              prog[y + 1][x + 1] += prog[y][x];
            }
          }
        }
        if (course[y][x] == JUMP) {
          if (y + 2 >= sizeY) {
            answer += prog[y][x];
          } else {
            prog[y + 2][x] += prog[y][x];
          }
        }
      }
    }
    cout << answer << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

//#include "set/union_find_g.h"
template<class T>
struct ufs_g {
	map<T,T> f;
	map<T,int> c;
	T find(T v) {
		T r, u;
		for(r=v; f.find(r) != f.end(); r=f[r]);
		for(u=v; u!=r; ) {
			T t = f[u];
			f[u] = r;
			u = t;
		}
		return r;
	}
	T merge(T a, T b) {
		a = find(a);
		b = find(b);
		if (a!=b) {
			f[a] = b;
			c[b] = count(b) + count(a);
		}
		return b;
	}
	void clear() {
		f.clear();
		c.clear();
	}
	int count(int v){
		v = find(v);
		return c.find(v)==c.end()? 1: c[v];
	}
	void get_sets(map<T,vector<T>> &s) {
		for (auto &x: f) {
			s[find(x.first)].push_back(x.first);
		}
		for (auto &x: s) {
			s[x.first].push_back(x.first);
		}
	}
};

#define MAXN 100000

int n, m;
vector<pair<int,int>> g[MAXN];

map<int, ufs_g<int>> uf;
map<int, map<int, vector<int>>> us;

int q[MAXN];
int h, t;
int dist[MAXN];

void adde(int a, int b, int c) {
	g[a].push_back({b,c});
	g[b].push_back({a,c});
	uf[c].merge(a, b);
}

int input() {
	if (scanf("%d %d", &n, &m) < 0) return 0;
	for (int i=0; i<m; i++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		a--, b--, c--;
		adde(a,b,c);
	}
	return 1;
}

void init() {
	for (int i=0; i<n; i++) dist[i] = INT_MAX;
	for (auto &x: uf)
		x.second.get_sets(us[x.first]);
}

int solve() {
	h=0, t=0;
	dist[0] = 0;
	q[t++] = 0;
	set<pair<int,int>> done;
	while (h<t) {
		int v = q[h++], d = dist[v]+1;
		//printf("-->v=%d d=%d\n", v, d);
		for(auto &x: g[v]) {
			int u = x.first, c = x.second;

			//need to process when dist[u]==d
			if (dist[u] < d) continue;

			int r = uf[c].find(v);

			//!! speed up
			if (done.count({c,r})) continue;
			done.insert({c,r});

			for (auto &x: us[c][r]) {
				if (d < dist[x]) {
					dist[x] = d;
					q[t++] = x;
				}
			}
		}
	}
	//cout << us << endl; printa(dist,n);
	return dist[n-1];
}

void output(int ans) {
	printf("%d\n", ans==INT_MAX? -1: ans);
}

void cleanup() {
	for (int i=0; i<n; i++) g[i].clear();
	uf.clear();
	us.clear();
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





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

int main()
{
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
  {
    cout << "vowel" << endl;
  }
  else
  {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
def bfs(field,H,W,start_x,start_y,tmp_N):
    direction = [[-1,0],[1,0],[0,-1],[0,1]]
    que = []
    que.append([start_x,start_y])
    INF = 1000000
    min_path = [[INF] * W for i in range(H)]
    min_path[start_y][start_x] = 0
    while len(que) != 0:
        current = que.pop(0)
        for d in direction:
            nx = current[0] + d[0]
            ny = current[1] + d[1]
            if 0 <= nx < W and 0 <= ny < H and field[ny][nx] != "X" and min_path[ny][nx] == INF:
                min_path[ny][nx] = min_path[current[1]][current[0]] + 1
                if field[ny][nx] == tmp_N: # at the same cheese-power number
                    return nx,ny,min_path[ny][nx]
                else:
                    que.append([nx,ny])

def getField():
    matrix = []
    first = input().strip()
    H,W,N = map(int,first.split())
    for i in range(H):
        row = list(input().strip())
        for j in range(W):
            if row[j].isdigit():
                row[j] = int(row[j])
        matrix.append(row)
    return matrix,H,W,N

def getStart(field):
    for y in range(len(field)):
        for x in range(len(field[0])):
            if field[y][x] == "S":
                return x,y

def main():
    matrix,H,W,N = getField()
    sx,sy = getStart(matrix)
    distance = 0
    for k in range(N):
        if k != 0:
            tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,tmps[0],tmps[1],k+1)
            distance += tmp_dist
            tmps = [tmp_x,tmp_y]
        else:
            tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,sx,sy,k+1)
            distance += tmp_dist
            tmps = [tmp_x,tmp_y]
    print(distance)


if __name__=='__main__':
    main()

Measured memory_bytes: 36908
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  string s[2];
  rep(i, 2) cin >> s[i];

  char t[2][3];
  for (int i = 1; i >= 0; --i) for (int j = 2; j >= 0; --j) t[1 - i][2 - j] = s[i][j];
  
  rep(i, 2) rep(j, 3) {
    if (s[i][j] != t[i][j]) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 256
def test():

	count = 0
	output = [[0 for i in range(3000)] for j in range(2)]

	while True:
		i = list(map(int,input().split()))
		if i[0] == 0 and i[1] == 0:
			break

		if i[0] > i[1]:
			output[0][count] = i[1]
			output[1][count] = i[0]
		else:
			output[0][count] = i[0]
			output[1][count] = i[1]

		count += 1
	
	loop = 0
	for loop in range(count):
		print(f"{output[0][loop]} {output[1][loop]}")

if __name__ == "__main__":
	test()



Measured memory_bytes: 5940
a, b, k=map(int, input().split())
out=set()
for i in range(k):
  out.add(a+i)
  out.add(b-i)
out=list(out)
out.sort()
for i in range(len(out)):
  if out[i]>=a and out[i]<=b:
    print(out[i])

Measured memory_bytes: 3060
from operator import itemgetter
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key = itemgetter(1))
now = 0
ans = "Yes"
for i in ab:
    a,b = i[0],i[1]
    now += a
    if now > b:
        ans = "No"
        break
print(ans)

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

int main(){
  int k,a,b;
  cin >> k;
  cin >> a >> b;
  bool flag = false;
  for(int i=a;i<b+1;i++){
    if(i%k==0){flag=true;break;}
  }
  flag==true?cout << "OK" << endl:cout << "NG" << endl;
}


Measured memory_bytes: 3632
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		double ans=M_PI*2*N;
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   while (true) {
      int m, r, f;
      cin >> m >> r >> f;
      if (m == r && r == f && f == -1) break;
      int sum = m + r;
      if (m == -1 || r == -1)
         cout << "F" << endl;
      else if (sum >= 80)
         cout << "A" << endl;
      else if (sum >= 65)
         cout << "B" << endl;
      else if (sum >= 50)
         cout << "C" << endl;
      else if (sum >= 30) {
         if (f >= 50)
            cout << "C" << endl;
         else
            cout << "D" << endl;
      } else
         cout << "F" << endl;
   }
   return 0;
}


Measured memory_bytes: 3108
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
sum = 0
for i in b:
    sum += bisect.bisect_left(a, i)*(n-bisect.bisect_right(c, i))

print(sum)

Measured memory_bytes: 23360
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  vector<ll> H(N);
  rep(i,N) cin>>H[i];
  ll ok=1e9;
  ll ng=0;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    ll sum=0;
    ll X=mid*B;
    ll AB=A-B;
    rep(i,N) sum+=max(0ll,(H[i]-X+AB-1)/AB);
    if(sum<=mid) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long 
#define inf 0x7fffffff
#define clr(c) memset(c,0,sizeof(c))
using namespace std;
int mod=998244353;
const int M=1e6+10;
const int N=2e5+10;
inline ll read(){
    ll b=1,sum=0; char c=getchar();
    while(!isdigit(c)){if(c=='-') b=-1; c=getchar();}
    while(isdigit(c)){sum=sum*10+c-'0'; c=getchar();}
    return b*sum;
}
int n,m,k,T;
int a[N];

int main() 
{
    int i,j;
	n=read();
	for(i=1;i<=n-1;i++) {
		int x=read();
		a[x]++;
	}
	for(i=1;i<=n;i++) {
		printf("%d\n",a[i]);
	}
    return 0;
}


Measured memory_bytes: 4432
#include <iostream>

using namespace std;

int main(){
    int n;
    while(cin >> n && n){
            int score = 0;
        for(int i = 1; i * i <= n && i < n; i++){
            if(n % i) continue;
            score += i;
            if(i * i < n && i != 1){
                score += n / i;
            }
        }
        if(n == score){
            cout << "perfect number\n";
        }else if(n > score){
            cout << "deficient number\n";
        }else{
            cout << "abundant number\n";
        }
    }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

int main() {
  int N;
  cin >> N;
  int ans = 0;
  int cnt = 0;

  FOR(i, 1, N+2){
    int p;
    if(i == N+1) p = 0;
    else cin >> p;
    
    if (p == i) cnt++;
    else{
      ans += (cnt+1)/2;
      cnt = 0;
    }
  }

  cout << ans << endl;
}


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

int main(){
  int N,K;
  int num = 1;
  cin >> N >> K;
  for(int i = 0;i < N;i++){
    if(2*num < num + K){
      num *= 2;
    }else{
      num += K;
    }
  }
  cout << num << endl;
}

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

using namespace std;


int main(){
    int n;
    cin >> n;
    
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    
    sort(x.begin(), x.end());
    
    double value = (double)x[0];
    for(int i = 1; i < x.size(); i++) {
        value = (value + (double)(x[i])) / 2.0;
    }
    
    cout << fixed << setprecision(5) ;
    cout << value << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>

using flt = double;
const flt eps = 1e-12, inf = 1e18, PI = acos(-1.0);
template<typename T>
inline T sqr(T x) {return x * x;}
inline flt cmp(flt a, flt b, flt e = eps) {
  return fabs(a - b) >= e + fabs(a) * e ? a - b : 0;
}
inline int sgn(flt x, flt e = eps) {return x < -e ? -1 : (x > e);}
inline flt fix(flt x, flt e = eps) {return cmp(x, 0, e);}

struct point {
  flt x, y;
  point(flt x = 0, flt y = 0): x(x), y(y) {}
  bool operator < (const point &rhs) const {
    return cmp(x, rhs.x) < 0 || (cmp(x, rhs.x) == 0 && cmp(y, rhs.y) < 0);
  }
  bool operator == (const point &rhs) const {
    return cmp(x, rhs.x) == 0 && cmp(y, rhs.y) == 0;
  }
  point operator + (const point &rhs) const {
    return point(x + rhs.x, y + rhs.y);
  }
  point operator - (const point &rhs) const {
    return point(x - rhs.x, y - rhs.y);
  }
  point operator * (const flt k) const {
    return point(x * k, y * k);
  }
  point operator / (const flt k) const {
    return point(x / k, y / k);
  }
  point operator ~ () const {// counter clockwise rotate 90 degree
    return point(-y, x);
  }
  flt dot(const point &rhs) const {
    return x * rhs.x + y * rhs.y;
  }
  flt det(const point &rhs) const {
    return x * rhs.y - y * rhs.x;
  }
  flt norm2() const {
    return x * x + y * y;
  }
  flt norm() const {
    return hypot(x, y);
  }
  point rot(flt a) const {// counter clockwise rotate A rad
    return point(x * cos(a) - y * sin(a), x * sin(a) + y * cos(a));
  }
  point rot(flt cosa, flt sina) const {// counter clockwise rotate using cos/sin
    return point(x * cosa - y * sina, x * sina + y * cosa);
  }
  point trunc(flt a = 1.0) const {
    return (*this) * (a / this->norm());
  }
};

using poly_t = std::vector<point>;

flt area(const poly_t &P, point &res) {
  flt sum = 0;
  res = point(0, 0);
  int n = P.size();
  for (int i = 0; i < n; ++i) {
    const point &A = P[i], &B = P[(i + 1) % n];
    sum += B.det(A);
    res = res + (A + B) * B.det(A);
  }
  sum = abs(sum);
  res = res / (3.0 * sum);
  return sum * 0.5;
}

int main() {
  int n;
  scanf("%d", &n);
  std::vector<point> p(n);
  for (int i = 0; i < n; ++i) {
    scanf("%lf%lf", &p[i].x, &p[i].y);
  }
  point mass;
  printf("%.1f\n", area(p, mass));
  return 0;
}

Measured memory_bytes: 2732
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
const double eps = 1e-8;
ll arr1[100010];
ll arr2[100010];
ll arr3[100010];
ll dp[100010][4];
ll n;
ll solve(ll i,ll k)
{
    if(i>n)
        return 0;
    if(dp[i][k]!=-1)
        return dp[i][k];
    ll t1=INT_MIN;
    ll t2=INT_MIN;
    ll t3=INT_MIN;
    if(k!=1)
        t1=arr1[i]+solve(i+1,1);
    if(k!=2)
        t2=arr2[i]+solve(i+1,2);
    if(k!=3)
        t3=arr3[i]+solve(i+1,3);
    return dp[i][k]=max(max(t1,t2),t3);

}

int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(ll i=1; i<=n; i++)
        cin>>arr1[i]>>arr2[i]>>arr3[i];
    cout<<solve(1,0);

}








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

int main()
{
	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include<iostream>
using namespace std;
long long GCD(long long a,long long b){
  if(b==0) return a;
  else return GCD(b,a%b);
}
int main(){
  long long a,b;
  cin>>a>>b;
  cout<<a/GCD(a,b)*b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e+18
#define ll long long
using namespace std;

signed main(){
	int a,b;
	cin >> a >> b;
	if(a <= 5) cout << 0 << endl;
	else if(a <= 12) cout << b / 2 << endl;
	else cout << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    vector<pair<i64, i64>> p;
    vector<i64> X, Y;
    for(int i = 0; i < N; i++) {
        i64 x, y;
        cin >> x >> y;
        X.push_back(x);
        Y.push_back(y);
        p.emplace_back(x, y);
    }

    sort(WHOLE(X));
    sort(WHOLE(Y));

    vector<vector<i64>> V(N, vector<i64>(N, 0));

    i64 ans = 5 * 1e18;

    for(int u = 0; u < N; u++) {
        for(int d = u + 1; d < N; d++) {
            for(int l = 0; l < N; l++) {
                for(int r = l + 1; r < N; r++) {
                    int k = 0;
                    for(int i = 0; i < N; i++) {
                        i64 x, y;
                        tie(x, y) = p[i];
                        if(Y[u] <= y && y <= Y[d] && X[l] <= x && x <= X[r]) {
                            k++;
                        }
                    }
                    if(k == K) {
                        ans = min(ans, (X[r] - X[l]) * (Y[d] - Y[u]));
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;

const ll MOD = 1e9 + 7;

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int h, w;
    cin >> h >> w;

    bool grid[h][w];
    char t;

    for(int i=0; i < h; i++){
        for(int j=0; j < w; j++){
            cin >> t;
            if(t == '.') grid[i][j] = true;
            else grid[i][j] = false;   
        }
    }

    ll dp[h][w];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for(int i=0; i < h; i++){
        for(int j=0; j < w; j++){

            if(!grid[i][j]){
                dp[i][j] = 0;
                continue;
            }

            if(i == 0 && j == 0) continue;
            if(i == 0){
                dp[i][j] = dp[i][j-1];
            }else if(j == 0){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            }

        }
    }

    cout << dp[h-1][w-1] << endl;

    return 0;
}

Measured memory_bytes: 9088
# # https://atcoder.jp/contests/abc128/abc128_b

N = int(input())
pairs = [input().split() for _ in range(N)]
pairs = [(a, int(b)) for a, b in pairs]
indices = list(range(N))
indices.sort(key=lambda idx: (pairs[idx][0], -pairs[idx][1]))
for idx in indices:
    print(idx + 1)



Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int l = sc.nextInt();
		String val = String.valueOf(l);
		BigDecimal bd = new BigDecimal(val);
		BigDecimal three = new BigDecimal("3");
		BigDecimal bd1 = bd.divide(three, 3, BigDecimal.ROUND_DOWN);
		BigDecimal bd2 = bd.divide(three, 3 ,BigDecimal.ROUND_UP);
		
		BigDecimal ans = new BigDecimal("0");
		
		if(l%3 == 0) {
			ans = (bd1.multiply(bd1)).multiply(bd1);
		}else if(l%3 == 1) {
			ans = (bd1.multiply(bd1)).multiply(bd2);
		}else {
			ans = (bd1.multiply(bd2)).multiply(bd2);
		}
		
		System.out.println(ans);
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}

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

using namespace std;

char move(char c,unsigned move){

	char A= 'A';
	char Z= 'Z';
	//int start=(int)A;
	//int end= (int)Z;
	
	char newpos;

	if(c + move > Z){
		newpos= static_cast<char>(A + c + move -Z -1);
	}
	else{
		newpos= static_cast<char>(c + move);
	}	
	return newpos;
}

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

	
	int len = S.length();

	for(int i=0;i<len;i++){
		//char c = S[i];
		S[i] = move(S[i], N);
	}
	cout << S;
	//printf("%s",S);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    LL a,b,ans;
    cin >> a >> b;
    ans = max(a*b, max(a+b,a-b));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp2
{
    using static System.Console;
    using static System.Math;

    class Program
    {
        static void Main(string[] args)
        {
            var nx = ReadLine().Split().Select(int.Parse).ToArray();
            N = nx[0];
            X = nx[1];
            L = ReadLine().Split().Select(int.Parse).ToArray();
            WriteLine(Solve());
        }

        static int N, X;
        static int[] L;

        static string Solve()
        {
            var sum = 0;
            for (int i = 0; i < L.Length; i++)
            {
                sum += L[i];
                if (sum > X)
                    return (i + 1).ToString();
            }
            return (N + 1).ToString();
        }
    }
}


Measured memory_bytes: 13396
s = list(input())
flag = 1
if s[0] == "A" :
    if s[2:-1].count("C") == 1 :
        for i in range(1,len(s)) :
            if i != s[2:-1].index("C") + 2 :
                if s[i] != s[i].lower() :
                    flag = 0
                    break
    else :
        flag = 0
else :
    flag = 0

print("AC" if flag ==1 else "WA")


Measured memory_bytes: 9112
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APC001B solver = new APC001B();
        solver.solve(1, in, out);
        out.close();
    }

    static class APC001B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long aSum = 0;
            long bSum = 0;
            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                aSum += a[i];
            }
            for (int i = 0; i < n; i++) {
                b[i] = in.nextInt();
                bSum += b[i];
            }

            long aReq = 0;
            long bReq = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] > b[i]) bReq += a[i] - b[i];
                if (a[i] < b[i]) {
                    aReq += (b[i] - a[i]) / 2;
                    if (b[i] % 2 != a[i] % 2) {
                        aReq++;
                        bReq++;
                    }
                }
            }

            long count = bSum - aSum;
            if (count >= aReq && count >= bReq) out.println("Yes");
            else out.println("No");
        }

    }
}



Measured memory_bytes: 42400