akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
using namespace std;

int search(int A[], int n, int key){
    int i = 0;
    A[n] = key;
    while(A[i] != key) i++;
    return i != n;
}

int main(){
    int n, A[100001] = {}, q, key, sum = 0;
    
    cin >> n;
    rep(i, n) cin >> A[i];
    
    cin >> q;
    rep(i, q){
        cin >> key;
        if(search(A, n, key)) sum++;
    }
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3480
a = []
for i in range(5):
    a.append(int(input()))
    
a.sort(reverse=True, key=lambda x: (x-1)%10)

for i in range(4):
    if a[i] %10 != 0:
        a[i] = (a[i]//10 + 1)*10
        
print(sum(a))

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

def main():
    na = list(map(int, input().split()))
    N, M = na[0], na[1]
    x = []
    y = []
    z = []
    for i in range(N):
        na = list(map(int, input().split()))
        x.append(na[0])
        y.append(na[1])
        z.append(na[2])

    a = []
    b = []
    c = []
    d = []
    for i in range(N):
        a.append(x[i] + y[i] + z[i])
        b.append(x[i] + y[i] - z[i])
        c.append(x[i] - y[i] + z[i])
        d.append(-x[i] + y[i] + z[i])

    a.sort()
    b.sort()
    c.sort()
    d.sort()

    sa = sb = sc = sd = 0
    ra = rb = rc = rd = 0
    for i in range(M):
        sa += a[i]
        ra += a[N - 1 - i]
        sb += b[i]
        rb += b[N - 1 - i]
        sc += c[i]
        rc += c[N - 1 - i]
        sd += d[i]
        rd += d[N - 1 - i]
    s = max(abs(sa), abs(sb), abs(sc), abs(sd), abs(ra), abs(rb), abs(rc), abs(rd))


    print(s)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
rishi=0.05
debt= 100000
week = int(raw_input())
kiriage = 1000

def ceil(src, range):
    if int(src * (1 + rishi) % range) == 0:
        return src * (1+rishi)
    else:
        return((int)(src*(1+rishi) / range) + 1) * range

for i in range(0,week):
    debt = ceil(debt, kiriage)
print debt

Measured memory_bytes: 4676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define MOD (ll)1e9+7
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll a,b,c,k;cin>>a>>b>>c>>k;
    if(a>k){
        cout<<k<<"\n";return 0;
    }
    if(a+b>k){
        cout<<a<<"\n";return 0;
    }
    cout<<a-(k-a-b)<<"\n";
}


Measured memory_bytes: 3660
#include<stdio.h>

int main(){

    int a, b;
    char op;

    while(1){
    	scanf("%d %c %d", &a, &op, &b); 	
    	if ( op == '+' ) {
    		printf("%d\n", a+b);
    	} else if ( op == '-' ) {
    		printf("%d\n", a-b);
    	} else if ( op == '*' ) {
    		printf("%d\n", a*b);
    	} else if ( op == '/' ) {
    		printf("%d\n", a/b);
    	} else {
    		break;
    	}
    }

    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define INF 1e5
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
int n,ans,a[10010];
int main(){
	cin>>n;
	for (int i=1;i<n;i++)cin>>a[i];
	a[0]=a[n]=INF;
	for (int i=1;i<=n;i++)ans+=min(a[i-1],a[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
def check_575(array)
  appear_count_5, appear_count_7 = 0, 0

  array.each do |s|
    appear_count_5 += 1 if s == '5'
    appear_count_7 += 1 if s == '7'
  end

  appear_count_5 == 2 && appear_count_7 == 1
end

puts check_575(gets.split) ? 'YES' : 'NO'


Measured memory_bytes: 1788
#define _USE_MATH_DEFINES

#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<iostream>
#include<fstream>
#include<iomanip>

using namespace std;

vector<int> tf;

int N, a, d, M, K;
int data[200000][3];

int main(){
	scanf("%d%d%d%d", &N, &a, &d, &M);
	for (int i = 0; i < M; ++i) {
		scanf("%d%d%d", &data[i][0], &data[i][1], &data[i][2]);
	}
	scanf("%d", &K);
	
	int cur = K;
	for (int i = M - 1; i >= 0; --i) {
		if (data[i][1] <= cur && cur <= data[i][2]) {
			if (data[i][0] == 0) {
				cur = data[i][2] - (cur - data[i][1]);;
			}
			tf.push_back(data[i][0]);
		}
	}
	
	int value = a + (cur - 1) * d;
	for (int i = tf.size() - 1; i >= 0; --i) {
		if (tf[i] == 0) {
		}
		else if (tf[i] == 1) {
			value++;
		}
		else if (tf[i] == 2) {
			value >>= 1;
		}
	}
	printf("%d\n", value);

	return 0;
}

Measured memory_bytes: 3644
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BigInteger N = scanner.nextBigInteger();
        BigInteger K = scanner.nextBigInteger();
        scanner.close();

        BigInteger a = N.remainder(K);

        if (a.compareTo(K.subtract(a)) > 0) {
            System.out.println(K.subtract(a));
        } else {
            System.out.println(a);
        }
    }
}


Measured memory_bytes: 21972
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"

using namespace std;
const long long int MOD = 1000000007;

long long int a;
long long int ans;

int main() {
	cin >> a;
	ans = (a / 11) * 2;
	a %= 11;
	if (a > 6)ans += 2;
	else if(a) ans++;
	cout << ans << endl;
	return 0;
}



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

#define BL 1
#define WH 0
#define XX 2

int main()
{
    int H, W;
    cin >> H >> W;

    string S[H];
    REP(h, H) cin >> S[h];

    int board[H][W];
    REP(h, H) REP(w, W) board[h][w] = S[h][w] == '#';

    ll ret = 0;
    REP(h, H) REP(w, W)
    {
        if (board[h][w] != BL) continue;

        stack<pair<int,int>> nexts;
        nexts.push(make_pair(h, w));
        ll count[2] = {0};

        while (!nexts.empty())
        {
            pair<int,int> next = nexts.top();
            nexts.pop();

            int nh = next.first;
            int nw = next.second;
            if (board[nh][nw] == XX) continue;
            ++count[board[nh][nw]];

            if (nh-1 >= 0 && board[nh-1][nw] == !board[nh][nw]) nexts.push(make_pair(nh-1, nw));
            if (nh+1 <  H && board[nh+1][nw] == !board[nh][nw]) nexts.push(make_pair(nh+1, nw));
            if (nw-1 >= 0 && board[nh][nw-1] == !board[nh][nw]) nexts.push(make_pair(nh, nw-1));
            if (nw+1 <  W && board[nh][nw+1] == !board[nh][nw]) nexts.push(make_pair(nh, nw+1));

            board[nh][nw] = XX;
        }

        ret += count[WH]*count[BL];
    }

    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){

  int N;    cin >> N;
  if(N % 10 == 9 || N / 10 % 10 == 9)   cout << "Yes" << endl;
  else cout << "No" << endl;
  
return 0;
}


Measured memory_bytes: 256
//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
//g++ -std=c++14 -Wall -O2 -o main.exe main.cpp
 
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <queue>
#include <stack>
#include <tuple>

using namespace std;

#define ll long long int
#define sortasc(v, T) sort(v.begin(), v.end(), less<T>())
#define sortdesc(v, T) sort(v.begin(), v.end(), greater<T>())

//------

string S;

int main(){
    cin >> S;

    if(S.size() == 2) cout << S << endl;
    else{
        for(int i = 2; i >= 0; i--){
            cout << S[i];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
sums=[[]for _ in[0]*8]
for _ in[0]*N:
    c=list(map(int,input().split()))
    for t in range(8):
        sums[t]+=[sum(c[i]*[-1,1][t&(1<<i)>0]for i in range(3))]
if M:print(max(sum(sorted(sums[i])[-M:])for i in range(8)))
else:print(0)

Measured memory_bytes: 3316
#include <stdio.h>
#define N 1000001                                                                            

int binarySearch(int A[], int n, int key)
{
  int left=0, right=n, mid;

  while(left < right){
    mid = (left+right) / 2;
    if(A[mid] == key){
      return 1;
    } else if(key < A[mid]){
      right = mid;
    } else if (key > A[mid]){
      left = mid + 1;
    }
  }
    return 0;
}

int main(){

  int i, q, key, count=0;
  int n, A[N];

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  scanf("%d", &q);

  for(i=0; i<q; i++){
    scanf("%d", &key);
    if(binarySearch(A, n, key)){
        count++;
      }
  }

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

  return 0;
}

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

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



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,tk,i,j,sum;

    scanf("%d %d",&n,&tk);

    for(i=0; i<=n; i++)
    {
        for(j=0; j<=n-i; j++)
        {
            sum=10000*i+5000*j+(n-i-j)*1000;

            if(sum==tk)goto xx;
        }
    }
      if(i==n+1)printf("-1 -1 -1\n");

     else  xx:printf("%d %d %d\n",i,j,n-i-j);

     return 0;
}


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

#define int long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    string s;
    cin >> s;
    int n = s.length();
    if(s[0] != '1' || (s[n - 1] != '0')){
        cout << -1;
        return 0;
    }
    int k = 0;
    vi pts;
    for(int i = 0;i < n; ++i){
        if(n - i - 2 >= 0 && (s[i] != s[n - i - 2])){
            cout << -1;
            return 0;
        }
        if(s[i] == '1'){
            ++k;
            pts.push_back(i + 1);
        }
    }
    int i = 1;
    for(;i <= k; ++i){
        cout << i << ' ' << i + 1 << '\n';
    }
    ++i;
    for(int rt = 1;rt < pts.size(); ++rt){
        int tot = pts[rt] - pts[rt - 1] - 1;
        while(tot--){
            cout << rt + 1 << ' ' << i << '\n';
            ++i;
        }
    }
}

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

int main() {
  auto min_ = numeric_limits<int>::max();
  auto max_ = numeric_limits<int>::min();
  int N;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    int a;
    cin >> a;
    min_ = min(min_, a);
    max_ = max(max_, a);
  }
  cout << (max_ - min_) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

#define N 26
#define NIL -1

//array
int parent[N];
int leftc[N];
int rightc[N];
//root
int root;

//function Preorder
void Preorder(int now){
  if(now!=NIL){
    printf(" %d",now);
    Preorder(leftc[now]);
    Preorder(rightc[now]);
  }
}

//function Inorder
void Inorder(int now){
  if(now!=NIL){
    Inorder(leftc[now]);
    printf(" %d",now);
    Inorder(rightc[now]);
  }
}

//function Postorder
void Postorder(int now){
  if(now!=NIL){
    Postorder(leftc[now]);
    Postorder(rightc[now]);
    printf(" %d",now);
  }
}

int main(){
  int i,j,n;
  int id,child1,child2;

  //load data
  scanf("%d",&n);
  
  //initialize
  for(i=0;i<N;i++){
    parent[i]=NIL;
    leftc[i]=NIL;
    rightc[i]=NIL;
  }

  for(i=0;i<n;i++){
    
    //load data
    scanf(" %d %d %d",&id,&child1,&child2);

    //set parent
    parent[child1]=id;
    parent[child2]=id;
    
    //set left right
    leftc[id]=child1;
    rightc[id]=child2;
    
  }
  //set root
  for(i=0;i<n;i++){
    if(parent[i]==NIL){
      root=i;
      break;
    }
  }
  //  cout <<root<<endl;
  //print
  printf("Preorder\n");
  Preorder(root);
  printf("\n");
  printf("Inorder\n");
  Inorder(root);
  printf("\n");
  printf("Postorder\n");
  Postorder(root);
  printf("\n");
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <utility>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	int n, q, query, t, x;
	cin >> n >> q;
	vector<list<int> > L(n);
	
	rep(i, q)
	{
		cin >> query >> t;
		if (query == 0)
		{
			cin >> x;
			L[t].push_back(x);
		}
		else if (query == 1)
		{
			if (!L[t].empty())
			{
			    list<int>::iterator itr = L[t].begin();
				for (itr = L[t].begin(); itr != L[t].end(); itr++) {
				    if (itr != L[t].begin())
				    {
				        cout << " ";
				    }
					cout << *itr;
				}
			}
			std::cout << endl;
		}
		else
		{
			int s;
			cin >> s;
			if (!L[t].empty())
			{
				L[s].splice(L[s].end(), L[t]);
			}
		}
	}
}


Measured memory_bytes: 18656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n,m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

Measured memory_bytes: 256
// 2014/11/12 Tazoe

#include <iostream>
#include <string>
using namespace std;

bool findP(string P, string T)
{
	for(int i=0; i<T.size(); i++){
		if(T[i]!=P[0])
			continue;

		for(int j=i+1; j<T.size(); j++){
			if(T[j]!=P[1])
				continue;

			int d = j-i;

			for(int p=2; p<P.size(); p++){
				int k = i+d*p;
				if(k>=T.size())
					break;

				if(P[p]!=T[k])
					break;

				if(p==P.size()-1)
					return true;
			}
		}
	}

	return false;
}

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

	string P;
	cin >> P;

	int cnt = 0;

	for(int i=0; i<N; i++){
		string T;
		cin >> T;

		if(findP(P, T)){
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<cstdio>
using namespace std;
int n,k,q,a[100005];
int s,cnt;
int main()
{
	scanf("%d%d%d",&n,&k,&q);
	for(int i=1;i<=n;i++) a[i]=k;
	for(int i=1;i<=q;i++) scanf("%d",&s),a[s]++,cnt++;
	for(int i=1;i<=n;i++)
	if(a[i]-cnt>0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  cout << max({a+b,a-b,a*b}) <<endl;
  return 0;
}


Measured memory_bytes: 256
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
partial_sum = [0] * (N + 1)
partial_sum[1] = A[0]
for i in range(1, N+1):
    partial_sum[i] = partial_sum[i-1] + A[i-1]
partial_sum.sort()
counter = Counter(partial_sum)
ans = 0
for k, v in counter.items():
    if 2 <= v:
        ans += combinations_count(v, 2)
print(ans)

Measured memory_bytes: 41864
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << 0; return;}
#define mkp make_pair
#define cerr if(0) cerr

const int N = 1e6 + 7;

int a[N], d[N];

void solve() {
    int n; cin >> n;
    loop(i, n) {
        cin >> a[i];
        ++d[a[i]];
    }
    int ans = 0;
    loop(i, n) {
        bool ok = 0;
        for (int j = 2; j * j <= a[i]; ++j)
            if (a[i] % j == 0 && (d[a[i] / j] || d[j]))
                ok = 1;
        if ((a[i] != 1 && d[1]) || d[a[i]] > 1)
            ok = 1;
        ans += !ok;
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 8296
import sys
from heapq import heappush,heappop,heapify
read=sys.stdin.readline
INF=10**30

def dijkstra(G,s,n):
    que=[(0,s)]
    dist=[INF]*n
    dist[s]=0
    while que:
        mincost,u=heappop(que)
        if(mincost>dist[u]):
            continue
        for c,v in G[u]:
            if(dist[u]+c<dist[v]):
                dist[v]=dist[u]+c
                heappush(que,(dist[v],v))
    return dist

N,M=map(int,read().split())

G=[[] for _ in range(N)]
for i in range(N-1):
    G[i+1].append((0,i))
    
for i in range(M):
    L,R,C=map(int,read().split())
    L-=1;R-=1
    G[L].append((C,R))
    
dist=dijkstra(G,0,N)
ans=dist[N-1]
print(ans if ans!=INF else -1)

Measured memory_bytes: 93284
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Control.Applicative
import Data.Array

eps :: Double
eps = 1.0e-8

parsePoint :: String -> (Double, Double)
parsePoint str =
    let [x, y] = map read $ words str
    in (x, y)

inside :: (Double, Double) -> (Double, Double) -> Bool
inside (x1, y1) (x2, y2) =
    let dx = x1 - x2
        dy = y1 - y2
    in dx * dx + dy * dy <= 1.0 + eps

countUp :: [(Double, Double)] -> ((Double, Double), (Double, Double)) -> Int
countUp pts ((x1, y1), (x2, y2)) =
    let dx = x1 - x2
        dy = y1 - y2
        l2 = dx * dx + dy * dy
    in if l2 >= 4.0 - eps
            then 1
            else
                let mx = (x1 + x2) * 0.5
                    my = (y1 + y2) * 0.5
                    l  = sqrt l2
                    m  = sqrt (1.0 - 0.25 * l2)
                    nx = m * (-dy) / l
                    ny = m * dx    / l
                    m1 = length $ filter (inside (mx + nx, my + ny)) pts
                    m2 = length $ filter (inside (mx - nx, my - ny)) pts
                in (max m1 m2)

solve' :: [(Double, Double)] -> Int
solve' pts =
    let np    = length pts
        parr  = listArray (0, np-1) pts
        pairs = [ (parr ! i, parr ! j) | i <- [0..np-1], j <- [i+1..np-1] ]
    in if null pairs
           then 1
           else maximum $ map (countUp pts) pairs

solve :: [String] -> [Int]
solve []   = []
solve cont =
    let n           = read (head cont) :: Int
        (crds, rst) = splitAt n (tail cont)
        pts         = map parsePoint crds
    in if n == 0 then []
                 else (solve' pts) : solve rst

main :: IO ()
main = do
    contents <- getContents
    mapM_ print $ solve $ lines contents

Measured memory_bytes: 30024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,a;cin>>n>>a;
  int ans=n*n-a;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())

min_count = 10**10

for i in range(1,N):
    A = i
    B = N-i
    count = 0
    for a in str(A):
        count += int(a)
    for b in str(B):
        count += int(b)
    min_count = min(min_count, count)

print(min_count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(ll i = 0; i < N; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    ll a,b;cin>>a>>b;
    ll ans=1;
    for(ll k=2;k<=min(a,b);k++){
        if(a%k==0 and b%k==0){
            a/=k;
            b/=k;
            ans*=k;
            k=1;
        }
    }
    ans=ans*a*b;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());

            double ret = 1;
            for (int i = 1; i < X; i++)
            {
                for (int j = 2; j < 1000; j++)
                {
                    var cal = Math.Pow(i, j);
                    if (cal > X)
                    {
                        break;
                    }
                    if (ret < cal)
                    {
                        ret = cal;
                    }
                }
            }
            Console.WriteLine(ret);
        }
    }
}

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

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

long long MOD = 1000000000 + 7;

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


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int score = 0; // 初期スコア
  rep(i, 0, n-1) {
    if (s[i] == s[i+1]) {
      score++;
    }
  }
  int ans = min(score+2*k, n-1);

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


Measured memory_bytes: 512
using System;

namespace ITP1_6_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,,] a = new int[5, 4, 11];
            while (n-- > 0)
            {
                string[] strs = Console.ReadLine().Split(' ');
                int b = int.Parse(strs[0]);
                int f = int.Parse(strs[1]);
                int r = int.Parse(strs[2]);
                int v = int.Parse(strs[3]);
                a[b,f,r] += v;
            }
            for (int i = 1; i <= 4; i++)
            {
                for (int j = 1; j <= 3; j++)
                {
                    for (int k = 1; k <= 10; k++)
                    {
                        Console.Write(" "+a[i, j, k]);
                    }
                    Console.WriteLine();
                }
                if(i<4) Console.WriteLine("####################");
            }
        }
    }
}

Measured memory_bytes: 9068
#include<stdio.h>


#define MAX 1000
#define default -1
 
typedef struct node{
  int parent,left,right;
}Node;
 
Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int, int);
int setHeight(int );
int getSibling(int );

int main(){
  int i,v,l,r,deg,root=0;
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    T[i].parent =default;

  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != default)T[l].parent = v;
    if(r != default)T[r].parent = v;
  }
 
  for(i=0; i<n; i++){
    if(T[i].parent == default) root = i;
  }
  setDepth(root, 0);
  setHeight(root);
 
  for(i = 0; i<n; i++){
    printf("node %d: ", i);
    printf("parent = %d, ", T[i].parent);
    printf("sibling = %d, ", getSibling(i));
    deg = 0;
    if(T[i].left != default) deg++;
    if(T[i].right != default) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ", D[i]);
    printf("height = %d, ", H[i]);
 
    if(T[i].parent == default){
      printf("root\n");
    } else if(T[i].left == default && T[i].right == default){
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  return 0;
}
 
 
 
void setDepth(int u, int d){
  if(u==default) return;
  D[u]=d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right, d+1);
}
 
int setHeight(int u) {
  int h1=0, h2=0;
  if(T[u].left != default)
    h1 = setHeight(T[u].left) + 1;
  if(T[u].right != default)
    h2 = setHeight(T[u].right) + 1;

  if(h1>h2)return H[u]=h1;
  else return H[u]=h2;
}
 
int getSibling(int u){
  if(T[u].parent == default) return default;
  if(T[T[u].parent].left != u && T[T[u].parent].left != default)
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != default)
    return T[T[u].parent].right;
  return default;
}

Measured memory_bytes: 624
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int x, y;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> x >> y;
   int ans = 0;
   if (x <= 3) ans += (4 - x) * 100000;
   if (y <= 3) ans += (4 - y) * 100000;
   if (x == 1 && y == 1) ans += 4 * 100000;
   cout << ans;
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		int n = getInt(sc);

		int[] s = new int[n];
		for (int i = 0; i < n; i++) {
			s[i] = getInt(sc);
		}
		int ans = 0;
		int sum = Arrays.stream(s).sum();
		if (sum % 10 != 0) {
			ans = sum;
		} else {
			Arrays.sort(s);
			for (int score : s) {
				if (score % 10 != 0) {
					ans = sum - score;
					break;
				}
			}
		}
		System.out.println(ans);

	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}

class Status {
	long x;
	long tmpCoins;

	public Status(long x, long tmpCoins) {
		this.x = x;
		this.tmpCoins = tmpCoins;
	}
}


Measured memory_bytes: 27988
#include<bits/stdc++.h>
using namespace std;
#define int long long int

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n,m,i,j,k,sum=0;
    string s;
    cin>>s;
    n=s.size();vector<int> a(n,0);
    int l,r;
    l=0;r=0;
    vector<pair<char,int>> v;
    v.push_back({s[0],1});
    for(i=1;i<n;i++){
        if(s[i]==v[v.size()-1].first){
            v[v.size()-1].second++;
        }
        else v.push_back({s[i],1});
    }
    j=0;
    for(i=0;i<n-1;i++){
        if(s[i]=='R'&&s[i+1]=='L'){
            r=v[j].second;
            l=v[j+1].second;
            if(r%2==1){
                a[i]+=r/2+1;
                a[i+1]+=r/2;
                }
            else {
                a[i]+=r/2;
                a[i+1]+=r/2;
            }
            if(l%2==1){
                a[i]+=l/2;
                a[i+1]+=l/2+1;
            }
            else {
                a[i]+=l/2;
                a[i+1]+=l/2;
            }
            j+=2;
        }
    }
    for(i=0;i<n;i++){
        cout<<a[i]<<' ';
    }
    cout<<'\n';


    return 0;
}


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

int main() {
    string s;
    int res = 0, best = 0;
    cin >> s;
    for (char c: s) {
        if (c == 'R') {
            res++;
        } else {
            best = max(best, res);
            res = 0;
        }
    }
    cout << max(res, best);
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cassert>
#include<cstdio>

#define MAX 12

using namespace std;
long double minimumLength;
long double boxLength;

long double CalculateRoleCakesLength(const vector<int> &r){
	long double ret;
	ret = r[0] + r[r.size() - 1];
	for(unsigned int i = 0; i < r.size() - 1; ++i){
		ret += 2 * sqrt((long double)(r[i]*r[i+1]));
	}
	return ret;
}
inline void InternalInsert(vector<int> &v, unsigned int a, unsigned int dest){
	if( a > dest ){
		v.insert( v.begin() + dest, v[a] );
		v.erase( v.begin() + a + 1);
	}else if( dest > a ){
		v.insert( v.begin() + dest, v[a] );
		v.erase( v.begin() + a);
	}
}
template <typename T>
void printVector( vector<T> &v ){
	for(unsigned int i = 0; i < v.size(); ++i) cout << v[i] << ' '; cout << endl;
}
long double OptimizeArrangeOfRoleCakes(const long double target, vector<int> &vInBoxCakes){
	long double len;
	long double minlen;
	const long double nowlen = CalculateRoleCakesLength( vInBoxCakes );
	vector<pair<int,int> > vCands;

	minlen = target;
	for(unsigned int i = 0; i < vInBoxCakes.size(); ++i){
		for(unsigned int j = 0; j <= vInBoxCakes.size(); ++j){
			if( j >= i + 2 || j <= i - 1 ){
				InternalInsert( vInBoxCakes, i, j );
				len = CalculateRoleCakesLength( vInBoxCakes );
				if( len < minlen ){
					minlen = len;
					vCands.push_back( make_pair(i, j) );
				}
				if( i < j ) InternalInsert( vInBoxCakes, j - 1, i );
				else InternalInsert( vInBoxCakes, j, i + 1 );
			}
		}
	}
	if( vCands.size() > 0 ){
		long double retminlen = nowlen;
		int retminlenind = -1;

		for(unsigned int i = 0; i < vCands.size(); ++i){
			long double t;
			InternalInsert( vInBoxCakes, vCands[i].first, vCands[i].second );

			t = OptimizeArrangeOfRoleCakes(minlen, vInBoxCakes );
			if( t < retminlen ){
				retminlen = t;
				minimumLength = min(minimumLength, retminlen);
				retminlenind = i;
			}
			
			if( vCands[i].first < vCands[i].second ){
				InternalInsert( vInBoxCakes, vCands[i].second - 1, vCands[i].first);
			}else{
				InternalInsert( vInBoxCakes, vCands[i].second, vCands[i].first + 1 );
			}
		}
		return retminlen;
	}
	return nowlen;
}
int main(void){
	while(true){

		long double length = 0;
		vector<int> vInBoxCakes;
		
		cin >> boxLength;
		if( cin.eof() ) break;
		while( true ){
			int tmp;

			if( '\n' == cin.get() ) break;
			cin >> tmp;
			vInBoxCakes.push_back(tmp);
		}

		minimumLength = CalculateRoleCakesLength( vInBoxCakes );
		OptimizeArrangeOfRoleCakes( minimumLength, vInBoxCakes);

		//cout << "Minmum Length = " << minimumLength << endl;
		if( minimumLength <= boxLength ) cout << "OK\n";
		else cout << "NA\n";
	}
	return 0;
}

Measured memory_bytes: 956
// Beginner 114 B.cpp
#include <iostream>
#include <cmath>
using namespace std;
string str;
int getNum(string part)
{
    int bit = 100, ans = 0;
    for (int i = 0; i < part.length(); i++)
        ans += (part[i] - '0') * bit, bit /= 10;
    return ans;
}
int main()
{
    cin >> str;
    int ans = 2e9;
    for (int i = str.length() - 1; i >= 2; i--)
        ans = min(ans, abs(getNum(str.substr(i - 2, 3)) - 753));
    cout << ans;
    return 0;
}

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

const int mx=1e5+1;
int n,k;
int h[mx],dp[mx];
int solve(int s) //s->no of stone
{
    if(s==n) return 0;
    if(dp[s]!=-1) return dp[s];
    int ret=INT_MAX;
    for(int i=1;i<=k;i++){
        if((i+s)<=n) ret=min(ret,abs(h[s+i]-h[s])+solve(s+i));
    }
    return dp[s]=ret;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);    return 0;

    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>h[i];
    memset(dp,-1,sizeof dp);
    cout<<solve(1);

    return 0;
}


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


int main(){
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int res = A * X + B * Y;
  res = min(res,(C*2)*max(X,Y));
  res = min(res,min(X,Y) * 2 * C + A *(X - min(X,Y)) + B * (Y - min(X,Y)));
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int h, a;
    while(cin >> h >> a)
    {
        if(h % a == 0)
        {
            cout << h / a << endl;
        }
        else{
            cout << h / a + 1 << endl;
        }
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

int dfs(int cur, const Graph &G) {
    int n = (int)G.at(cur).size();
    vector<int> cnt(n);
    for (int i=0; i<n; ++i) {
        cnt.at(i) = dfs(G.at(cur).at(i), G);
    }
    sort(cnt.rbegin(), cnt.rend());
    int res = 0;
    for (int i=0; i<n; ++i) chmax(res, cnt.at(i)+i+1);
    return res;
}

void solve() {
    int n;
    cin >> n;
    Graph G(n);
    for (int i=1; i<n; ++i) {
        int a;
        cin >> a;
        G.at(a-1).push_back(i);
    }

    cout << dfs(0, G) << '\n';
}

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

    solve();

    return 0;
}


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

using namespace std;

int go(int curr, vector<vector<int>>& adj, vector<bool>& visited) {
	if (visited[curr]) {
		return 0;
	}
	visited[curr] = true;
	int ans = 0;
	for (int i = 0; i < adj[curr].size(); i++) {
		ans += go(adj[curr][i], adj, visited);
	}
	return 1 + ans;
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	vector<vector<int>> adj(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--;
		b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	vector<bool> visited(n, false);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (!visited[i]) {
			ans = max(ans, go(i, adj, visited));
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}

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

int main(){
  int N;
  int d[110];
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> d[i];

  sort(d, d + N, greater<int>());

  int res = N;

  for (int i = 0; i < N - 1; ++i){
    if (d[i] == d[i + 1]) --res;
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;cin>>n;int a[n],b[n],c[n];
  for (int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
  int ans1[n],ans2[n],ans3[n];ans1[0]=a[0],ans2[0]=b[0],ans3[0]=c[0];
  for (int i=1;i<n;i++)
  {
ans1[i]=a[i]+max(ans2[i-1],ans3[i-1]);
    ans2[i]=b[i]+max(ans1[i-1],ans3[i-1]);
    ans3[i]=c[i]+max(ans1[i-1],ans2[i-1]);}
  cout<<max(ans1[n-1],max(ans2[n-1],ans3[n-1]));
  
  return 0;}

Measured memory_bytes: 2688
object Main {
	def main(args: Array[String]): Unit = {
		val strAry = io.StdIn.readLine().split(" ")
		
		val judge = (n: Int, a: Int, b: Int) => math.min(n * a, b)
		
		println(judge(strAry(0).toInt, strAry(1).toInt, strAry(2).toInt))
	}
}

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


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

	int A;
	cin >> A;

	int B[1000001] = {};

	int kotae = 1;
	while (B[A] == 0) {
		B[A] = 1;
		if (A % 2) A = A * 3 + 1;
		else A /= 2;
		kotae++;
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<int> a;
    for(int i=0;i<n;i++){
        int v;
        cin>>v;
        a.push(v);
    }
    while(m--){
        int v=a.top()/2;
        a.pop();
        a.push(v);
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=a.top();
        a.pop();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 892
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let (S, P): (Vec<String>, Vec<i64>) = {
        let (mut S, mut P) = (vec![], vec![]);
        for _ in 0..N {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            S.push(iter.next().unwrap().to_string());
            P.push(iter.next().unwrap().parse().unwrap());
        }
        (S, P)
    };

    let ans = {
        let mut rs: Vec<_> = (1..(N + 1)).collect();
        rs.sort_by_key(|&i| (&S[i - 1], -P[i - 1]));
        rs.iter().map(|&i| i.to_string()).collect::<Vec<_>>().join("\n")
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

def cal(x,y,a):
    return (x+y*W)*4 + a

def uncal(val):
    a = val%4
    vxy = val//4
    x,y = vxy%W, vxy//W
    return x,y,a

def dijkstra(lines,N,s):
    weight = [INF]*N
    weight[s] = 0
    def search(s,w_0,q,weight):
        for t,w in lines[s]:
            w += w_0
            if weight[t] > w:
                heapq.heappush(q,[w,t])
                weight[t] = w
    q = [[0,s]]
    heapq.heapify(q)
    while q:
        w,n = heapq.heappop(q)
        search(n,w,q,weight)
    return weight



while True:
    W,H = inpl()
    if W==0 and H==0:
        break

    ss = [inpl() for _ in range(H)]
    cc = inpl() # 直進，右折，反転，左折

    dx = [0,1,0,-1]
    dy = [-1,0,1,0]
    lines = defaultdict(set)
    for x in range(W):
        for y in range(H):
            for a in range(4): # 向いてる方向
                s = cal(x,y,a)
                costs = cc[:]
                if ss[y][x] <= 3:
                    costs[ss[y][x]] = 0

                for st in range(4): # 進む向き (直進，右折，反転，左折)
                    ar = (a + st)%4
                    tx,ty = x+dx[ar],y+dy[ar]
                    if (0<=tx<W) and (0<=ty<H):
                        t = cal(tx,ty,ar)
                        lines[s].add((t,costs[st]))

    weights = dijkstra(lines,H*W*4,cal(0,0,1))
    #for y in range(H):
    #    for x in range(W):
    #        print(x,y,weights[cal(x,y,0):cal(x,y,3)+1])

    print(min(weights[cal(x,y,0):cal(x,y,3)+1]))



Measured memory_bytes: 9816
module Main where

import Control.Applicative

getInt :: IO Int
getInt = head <$> getInts

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  { [a ,b ] <- getInts
  ; if a < b then putStrLn "a < b"
    else if a == b then putStrLn "a == b"
         else putStrLn "a > b"
  }



Measured memory_bytes: 3600
import heapq
import bisect

N,M = (int(i) for i in input().split()) 
ab = [[int(i) for i in input().split()] for i in range(N)] 

ans=0
ab.sort()
_index=[i[0] for i in ab]
p=[]
heapq.heapify(p)

for i in range(1,M+1):
	for g in ab[bisect.bisect_left(_index, i) : bisect.bisect_right(_index, i)]:
		heapq.heappush(p, -g[1])
	if p!=[]:
		ans+=heapq.heappop(p)*(-1)

print(ans)

Measured memory_bytes: 26592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(a,j,n) for(ll i=a;i<j;i=i+n )
typedef pair<ll,ll> P;
const ll mod = 1000000007;
const ll INF = 1000000009;
ll i;


int main(){
    ll H,W;
    cin>>H>>W;
    ll ans=0;
    if(H==1||W==1)ans=1;
    else if(H%2){
        ans+=H*(W/2);
        if(W%2)ans+=H/2+1;
    }
    else ans+=H/2*W;
    cout<<ans<<endl;
}



Measured memory_bytes: 256
a = []
while true
  a[0], l = gets.split.map(&:to_i)
  break if l == 0
  a[0] = "%0#{l}d" % a[0]
  catch :exit do
    for i in 1..25
      a[i] = "%0#{l}d"  % (a[i-1].split(//).sort.reverse.join.to_i - a[i-1].split(//).sort.join.to_i)
      for j in 0...i
        if a[i] == a[j]
          puts "#{j} #{a[i].to_i} #{i-j}"
          throw :exit   
        end
      end
    end
  end
end

Measured memory_bytes: 6128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int n, q;
    cin >> n;
    vector<int> A(n);
    REP(i, n) cin >> A[i];
    cin >> q;
    vector<int> m(q);
    REP(i, q) cin >> m[i];

    vector<bool> feasible(40010, false);

    for(int bit = 0; bit < (1<<n); ++bit) {
        int tmp = 0;
        for(int l = 0; l < n; ++l)
            if(bit & (1<<l))
                tmp += A[l];
        feasible[tmp] = true;
    }

    REP(i, q) {
        if(feasible[m[i]]) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, -1)
#define RREP(i, n, k) for(auto i = n; i != k; i--)

#define debug(x) cerr << #x << " " << x << endl
#define print(x) cout << x;
#define println(x) cout << x << endl;
#define spc << " " <<

#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define eb emplace_back
#define np next_permutation

using ll = long long;
using Pii = pair<int, int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;
template<class T>using VV = vector<vector<T>>;
using Vi = vector<int>;
using VVi = vector<vector<int>>;

int main() {
   int n; cin >> n;
   Vi v = Vi(n);
   rep(i, n) {
      cin >> v[i];
   }

   int ans = 0;
   int q; cin >> q;
   rep(i, q) {
      int qi; cin >> qi;
      auto itr = lower_bound(v.cbegin(), v.cend(), qi);
      if (itr != v.cend() && *itr == qi) ans++;
   }

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



Measured memory_bytes: 3112
N,K = map(int, input().split())
if K%2 != 0:
    print((N//K)**3)
else:
    counter1 = 0
    counter2 = 0
    for i in range(1,N+1):
        if i % K == 0:
            counter1 += 1
        elif i%K == K//2:
            counter2 += 1
    print(counter1**3 + counter2**3)

Measured memory_bytes: 3188