akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;
int n,c;
int m[10][10];
int dx[6]={0,1,1,0,-1,-1},dy[6]={1,1,0,-1,-1,0};
main()
{
	while(cin>>n>>c,n)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<=i;j++)cin>>m[i][j];
		}
		int ans=-114514;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<=i;j++)
			{
				if(m[i][j]==0)
				{
					m[i][j]=c;
					bool used[11][11]={};
					queue<pair<int,int> >P;
					for(int I=0;I<n;I++)for(int J=0;J<=I;J++)
					{
						if(m[I][J]==0)P.push(make_pair(I,J)),used[I][J]=1;
					}
					while(!P.empty())
					{
						int x=P.front().first,y=P.front().second;
						P.pop();
						for(int r=0;r<6;r++)
						{
							int tx=x+dx[r],ty=y+dy[r];
							if(tx<0||ty<0||tx>=n||ty>tx||used[tx][ty]||m[x][y]!=0&&m[x][y]!=m[tx][ty])continue;
							used[tx][ty]=1;
							P.push(make_pair(tx,ty));
						}
					}
					int now=0;
					for(int I=0;I<n;I++)for(int J=0;J<=I;J++)
					{
						if(!used[I][J]&&m[I][J])
						{
							now+=m[I][J]==c?-1:1;
						}
					}
					if(ans<now)ans=now;
					m[i][j]=0;
				}
			}
		}
		cout<<ans<<endl;
	}
}


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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    set<P> ab_set;
    while(true) {
        if(ab_set.count(P(a, b)) > 0) break;
        ab_set.insert(P(a, b));
        if(a == b - 1 and a == 1) {
            cout << "Borys" << ln;
            return 0;
        }
        if(a == b - 1) a--;
        else a++;

        if(b == a + 1 and b == n) {
            cout << "Alice" << ln;
            return 0;
        }
        if(b == a + 1) b++;
        else b--;
    }
    cout << "Draw" << ln;
    return 0;
}


Measured memory_bytes: 256
import fractions
a, b, c, d = map(int, input().split())
lcm = c * d // fractions.gcd(c, d)
e = b // c - (a - 1) // c
f = b // d - (a - 1) // d
g = b // lcm - (a - 1) // lcm
print((b - a + 1) - (e + f - g))


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

int main(){
  int n;cin>>n;
  vll a;
  for (int i=0;i<n;++i){
    ll a_;cin>>a_;a.push_back(a_);
  }
  sort(a.begin(), a.end(), greater<ll>());

  ll x=a[0];
  ll y=a[1];
  ll best=0;
  for (int i=0;i<n;++i){
    ll w=min(a[i], x-a[i]);
    if(w>best){y=a[i];best=w;}
  }
  cout << x << ' ' << y << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

int main() {
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	char c;
    scanf("%c", &c);
    if (c > 'Z') {
        printf("a");
    } else {
        printf("A");
    }
	return 0;
}


Measured memory_bytes: 3740
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  int n,p;
  cin >> n >> p;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll odd = 0,even = 0;
  rep(i,n){
    if(a[i]&1) odd++;
    else even++;
  }
  ll comb[60][60];
  {
    rep(i,odd+1){
      comb[i][0] = comb[i][i] = 1;
    }
    for(int i=2;i<=odd;++i){
      for(int j=1;j<i;++j){
	comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
      }
    }
  }

  ll res = 0;
  ll ex = 1LL<<even;
  for(int i=p;i<=odd;i+=2){
    res += comb[odd][i] * ex;
  }

  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
//#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 2005
#define BIG_NUM 1000000000000000005

ll LEN[NUM][NUM];
ll dp[NUM][NUM];
string line;

ll calc(ll &A,ll B){

	return min(A+B,2*(ll)BIG_NUM);
}

int main(){

	cin >> line;

	int length;
	for(length = 0; line[length] != '\0'; length++);

	for(int i = 0; i < length; i++){
		for(int k = 0; k < length; k++){
			LEN[i][k] = BIG_NUM;
			dp[i][k] = 0;
		}
	}

	ll K;
	scanf("%lld",&K);

	for(int i = length-1; i >= 0; i--){

		LEN[i][i] = 1;

		for(int k = i+1; k < length; k++){
			if(line[i] == line[k]){
				if(k == i+1){

					LEN[i][k] = 2;

				}else{

					LEN[i][k] = LEN[i+1][k-1]+2;
				}
			}
			LEN[i][k] = min(LEN[i][k],min(LEN[i][k-1],LEN[i+1][k])+2);
		}
	}

	for(int i = length-1; i >= 0; i--){

		dp[i][i] = 1;

		for(int k = i+1; k < length; k++){

			if(line[i] == line[k]){
				if(k == i+1){

					dp[i][k] = calc(dp[i][k],1);
				}else{

					dp[i][k] = calc(dp[i][k],dp[i+1][k-1]);
				}

			}else{

				if(LEN[i][k-1] < LEN[i+1][k]){

					dp[i][k] = calc(dp[i][k],dp[i][k-1]);

				}else if(LEN[i][k-1] > LEN[i+1][k]){

					dp[i][k] = calc(dp[i][k],dp[i+1][k]);

				}else{

					dp[i][k] = calc(dp[i][k],dp[i][k-1]+dp[i+1][k]);
				}
			}
		}
	}

	if(dp[0][length-1] < K){
		printf("NONE\n");
		return 0;
	}

	ll count = 1,tmp;
	int left = 0,right = length-1;
	string L = "";

	while(left < right){

		if(line[left] == line[right]){

			L += line[left];
			left++;
			right--;

		}else{ //line[left] != line[right]

			if(LEN[left][right-1] < LEN[left+1][right]){

				L += line[right];
				right--;

			}else if(LEN[left][right-1] > LEN[left+1][right]){

				L += line[left];
				left++;

			}else{

				tmp = count;

				if(line[left] < line[right]){

					tmp += dp[left+1][right];
				}else{
					tmp += dp[left][right-1];
				}

				if((tmp > K && line[left] < line[right]) || (tmp <= K && line[left] >= line[right])){

					L += line[left];
					left++;

				}else{

					L += line[right];
					right--;
				}
				if(tmp <= K){

					count = tmp;
				}
			}
		}
	}

	string R = L;
	reverse(R.begin(),R.end());

	if(left == right){
		L += line[left];
	}

	string ans = L+R;

	printf("%s\n",ans.c_str());

	return 0;
}



Measured memory_bytes: 65980
// 自端末のシェル上で動作確認をする際には下記を用いること
// ただの実行では入力を終了できない

// ヒアドキュメント： 区切文字列が入力されるまで，標準入力する．
// $ コマンド << 区切文字列
// 実行例)java Main << EOF
// 入力終了したいときにEOFを入力　など

import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		// アルファベットごとのカウント変数
		int count[] = new int[26];
		int i = 0;
		int s = 0;
		String str_scan = null;
		//char c = '0';

		// 複数行にまたがる文字列連結（終了条件は？）
		while(scan.hasNext()){
			str_scan = scan.nextLine();
			char[] c = str_scan.toCharArray();
			for(i=0; i<str_scan.length(); i++){
				if('a' <= c[i] && c[i] <= 'z'){
					// 文字の差に応じたカウンタをプラス
					s = c[i] - 'a';
					count[s] += 1;
				} else if('A' <= c[i] && c[i] <= 'Z'){
					// 文字の差に応じたカウンタをプラス
					s = c[i] - 'A';
					count[s] += 1;
				} else{
					// 何もしない
				}
			}
		}
		// 大文字小文字それ以外判定

		// 出力
		for(i=0; i<26; i++){
			System.out.println((char)('a' + i ) + " : " + count[i]);
		}
	}
}


Measured memory_bytes: 26240
#!/usr/bin python3
# -*- coding: utf-8 -*-

def od(n):
    ret = set([])
    for i in range(n):
        for j in range(i+1,n):
            if i+j+2 != n+1:
                ret.add((i+1, j+1))
    return ret

def main():
    N = int(input())

    ret = od(N//2*2)
    if N%2==1:
        for i in range(N-1):
            ret.add((i+1, N))

    print(len(ret))
    for x, y in ret:
        print(x,y)



if __name__ == '__main__':
    main()

Measured memory_bytes: 9520
import numpy as np

N = int(input())
A = np.array(input().split(), np.int64)
B = np.array(input().split(), np.int64)
C = np.array(input().split(), np.int64)
A.sort()
B.sort()
C.sort()

x = np.searchsorted(B, A, 'right')
y = np.searchsorted(C, B, 'right')
Z = np.add.accumulate(N - y[::-1])
ans = sum(Z[k - 1] for k in N - x if k)
print(ans)

Measured memory_bytes: 26508
#include<stdio.h>
int main()
{
	int N,K,i=1,j=1;
	scanf("%d%d",&N,&K);
	if(N==1)printf("%d",K);
	else
	{
		while(j<=N-1)
		{
			i=(K-1)*i;
			j++;
		}
		K=i*K;
		printf("%d",K);
	}
	return 0;
}

Measured memory_bytes: 128
N,W = map(int,input().split())
WV = [list(map(int,input().split())) for _ in range(N)]

Wdic = {}
for w in WV:
  if w[0] not in Wdic:
    Wdic[w[0]] = [w]
  else:
    Wdic[w[0]].append(w)

Wcount = [[0 for _ in range(2)] for _ in range(4)]
idx = 0
for k in Wdic.keys():
  Wcount[idx] = [k,len(Wdic[k])]
  idx += 1
#print(Wcount)

Wsum = {}
for k,v in Wdic.items():
  v.sort(key=lambda x:x[1], reverse = True)
  Wsum[k] = [v[0][1]]
  for i in range(1,len(v)):
    Wsum[k].append(Wsum[k][-1] + v[i][1])
#print(Wsum)

def check(i,j,k,l):
  ret = 0
  w = 0
  if i > 0 and Wcount[0][0] > 0:
    ret += Wsum[Wcount[0][0]][i-1]
    w += Wcount[0][0]*i
  if j > 0 and Wcount[1][0] > 0:
    ret += Wsum[Wcount[1][0]][j-1]
    w += Wcount[1][0]*j
  if k > 0 and Wcount[2][0] > 0:
    ret += Wsum[Wcount[2][0]][k-1]
    w += Wcount[2][0]*k
  if l > 0 and Wcount[3][0] > 0:
    ret += Wsum[Wcount[3][0]][l-1]
    w += Wcount[3][0]*l
  if w > W:
    ret = 0
  return ret

value = 0
for i in range(Wcount[0][1]+1):
  for j in range(Wcount[1][1]+1):
    for k in range(Wcount[2][1]+1):
      for l in range(Wcount[3][1]+1):
        value = max(value,check(i,j,k,l))
print(value)


Measured memory_bytes: 46576
use proconio::marker::Usize1;
use proconio::*;
use std::collections::BinaryHeap;

fn my_pop(
    heap: &mut BinaryHeap<(usize, usize, usize)>,
    charge: &mut [usize],
) -> Option<(usize, usize, usize)> {
    while let Some(x) = heap.pop() {
        if charge[x.2] > 0 {
            heap.push((x.0 - charge[x.2], x.1, x.2));
            charge[x.2] = 0;
        } else {
            return Some(x);
        }
    }

    None
}

fn solve() -> Option<Vec<usize>> {
    input! {
        n: usize,
        a: [Usize1; n],
        b: [Usize1; n],
    }

    let mut cnt_a = vec![0usize; n];
    let mut cnt_b = vec![0usize; n];

    for i in 0..n {
        cnt_a[a[i]] += 1;
        cnt_b[b[i]] += 1;
    }

    let mut heap = BinaryHeap::new();
    for i in 0..n {
        if cnt_b[i] == 0 {
            continue;
        }
        heap.push((cnt_a[i], cnt_b[i], i));
    }

    let mut charge = vec![0; n];
    let mut ans = Vec::new();
    for i in 0..n {
        let tmp = my_pop(&mut heap, &mut charge);
        if tmp.is_none() {
            return None;
        }
        let tmp = tmp.unwrap();
        if a[i] == tmp.2 {
            let tmp2 = my_pop(&mut heap, &mut charge);
            if tmp2.is_none() {
                return None;
            }
            let tmp2 = tmp2.unwrap();
            ans.push(tmp2.2);
            if tmp2.1 != 1 {
                heap.push((tmp2.0, tmp2.1 - 1, tmp2.2));
            }
            heap.push(tmp);
        } else {
            ans.push(tmp.2);
            if tmp.1 != 1 {
                heap.push((tmp.0, tmp.1 - 1, tmp.2));
            }
        }
        charge[a[i]] += 1;
    }

    Some(ans)
}

fn main() {
    if let Some(ans) = solve() {
        println!("Yes");
        for i in 0..ans.len() {
            if i > 0 {
                print!(" ");
            }
            print!("{}", ans[i] + 1);
        }
        println!("");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 18728
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;

int N;
string S;
char[] ans;

bool solve() {
    foreach (i; 1..N-1) {
        auto prev = ans[(i-1+N)%N];
        if (ans[i] == 'S' && S[i] == 'o') {
            ans[(i+1)%N] = prev;
        }
        else if (ans[i] == 'S' && S[i] == 'x') {
            ans[(i+1)%N] = (prev == 'S') ? 'W' : 'S';
        }
        else if (ans[i] == 'W' && S[i] == 'o') {
            ans[(i+1)%N] = (prev == 'S') ? 'W' : 'S';
        }
        else {
            ans[(i+1)%N] = prev;
        }
    }

    foreach (i; 0..N) {
        auto prev = ans[(i-1+N)%N];
        auto next = ans[(i+1)%N];
        if (ans[i] == 'S' && S[i] == 'o' && prev != next) return false;
        else if (ans[i] == 'S' && S[i] == 'x' && prev == next) return false;
        else if (ans[i] == 'W' && S[i] == 'o' && prev == next) return false;
        else if (ans[i] == 'W' && S[i] == 'x' && prev != next) return false;
    }

    return true;
}

void main() {
    N = readln.chomp.to!int;
    S = readln.chomp;

    ans = new char[](N);
    auto cand = ["SS", "SW", "WS", "WW"];
    foreach (i; 0..4) {
        foreach (j; 0..N) ans[j] = '*';
        ans[0] = cand[i][0];
        ans[1] = cand[i][1];
        if (solve) {
            ans.writeln;
            return;
        }
    }

    writeln(-1);
}


Measured memory_bytes: 636
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nk = readln.split.to!(long[]);
    auto N = nk[0];
    ulong K = nk[1];
    long[31] rs;
    foreach (_; 0..N) {
        auto ab = readln.split.to!(long[]);
        ulong A = ab[0];
        auto B = ab[1];
        if ((A&K) == A) rs[30] += B;
        foreach (i, ref r; rs) {
            if (
                (K&(1L<<i)) &&
                !(A&(1L<<i)) &&
                (((K>>(i+1))&(A>>(i+1))) == (A>>(i+1)))
            ) {
                r += B;
            }
        }
    }
    long r;
    foreach (ref rr; rs) r = max(r, rr);
    writeln(r);
}


Measured memory_bytes: 7716
#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define ll long long 
#define mod 998244353
using namespace std;



int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    _cin;

    int n,q,a,b;
    cin>>n;
    int arr[n];
    map<int,int> mp;
    long long sum = 0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mp[arr[i]]++;
        sum += arr[i];
    }
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>a>>b;
        sum += (b-a)*mp[a];
        mp[b]+= mp[a];
        mp[a] = 0;
        cout<<sum<<endl;
    }

}

Measured memory_bytes: 7876
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>

using namespace std;

// 要素数
#define N 3
#define N2 N * N

// 上,右,下,左の順でチェックする
static const int dx[4] = {0,1,0,-1};
static const int dy[4] = {-1,0,1,0};
static const char dir[4] = {'u','r','d','l'};

struct Puzzle{
    // 各々のタイルの状態(spaceは0だけど、9に換算する)
    int tiles[N2];
    // 空白の位置を管理indexで0 - 8まで
    int space;
    // 解法までのルートを記録
    string path;
    
    // 同じ状態遷移か判定する
    bool operator < (const Puzzle &p) const {
        for(int i = 0;i < N2;++i){
            if(tiles[i] == p.tiles[i]) continue;
            // タイル数値が大きいと一致していると判定する
            return tiles[i] < p.tiles[i];
        }
        return false;
    }
};

/**
    パズルの一致チェック
*/
bool isCorrect(Puzzle p){
    // パズルが順番通り一致しているかチェック
    for(int i = 0;i < N2;++i){
        // 1,2,3,4,5,6,7,8の順で並ぶ
        if(p.tiles[i] != (i + 1)){
          return false;
        }
    }
    return true;
}

// 幅優先探索を行う
string bfs(Puzzle p){
    // queueを使って、パズルの状態遷移を管理する
    queue<Puzzle> Q;
    // 同じ遷移状態がないか判定するためにmapを定義する
    map<Puzzle,bool> V;
    Puzzle u,v;
    p.path = "";
    Q.push(p);
    // 最初の状態遷移を保存
    V[p] = true;
    
    // 幅優先探索
    while(!Q.empty()){
        u = Q.front();
        Q.pop();
        
        // 正解チェック
        if(isCorrect(u)){
            return u.path;
        }
        // 空白の位置を算出する
        int sx = u.space % N;
        int sy = u.space / N;
        
        // スペースの周りの四方のタイルを動かす
        for(int r = 0;r < 4;++r){
            // 動かすタイルのindexを算出する(上,右,下,左の順)
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            // 範囲外チェック
            if(tx < 0 || ty < 0 || tx >= N || ty >= N){
                continue;
            }
            v = u;
            // 入れ替え
            swap(v.tiles[u.space],v.tiles[ty * N + tx]);
            // 入れ替えた場所がspaceになる
            v.space = (ty * N) + tx;
            
            // 同じ状態がでなかったら
            if(!V[v]){
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    return "unsolvable";
}

int main(){
    Puzzle in;
    
    for(int i = 0;i < N2;++i){
        cin >> in.tiles[i];
        if(in.tiles[i] == 0){
            // 空白は9として管理
            in.tiles[i] = N2;
            in.space = i;
        }
    }
    
    string answer = bfs(in);
    cout << answer.size() << endl;
    
    return 0;
}



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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    double d;
    cin >>d;

    double ans=sqrt(2)*d;
    for(int y=1; y<=(int)d; ++y)
    {
        double x=sqrt(d*d-y*y);
        if(x<1) ans=max(ans,(double)y+1);
    }

    printf("%.15lf\n", ans);
    return 0;
}

Measured memory_bytes: 3268
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N >> S;
  for (int i = 0; i < S.length(); i++) {
	  int n = ((int) (S[i] - 'A') + N) % 26 + (int) 'A';
	  S[i] = (char) n;
	}
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define MAX 5000
using namespace std ;

int a[40],b[40],c[40],n,ma,mb,opt;
int search(int sumA, int sumB, int sumC, int st){
    if(sumC>=opt) return opt;  
    if((sumA+a[st])*mb==(sumB+b[st])*ma){
        opt=min(opt,sumC+c[st]);
        if(st==n-1) return opt;
        return min(opt, search(sumA, sumB, sumC, st+1));
    }
    if(st==n-1) return opt;
    return min(min(opt, search(sumA, sumB, sumC, st+1)), search(sumA+a[st], sumB+b[st], sumC+c[st], st+1));
}
int main(void){
    opt=MAX;
    cin>>n>>ma>>mb;
    for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
    if(search(0,0,0,0)>=MAX) opt=-1;
    cout<<opt<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int N, A, B;
int vs[110];

int main(void) {
  cin >> N >> A >> B;
  REP(i, N) {
    cin >> vs[i];
  }
  sort(vs, vs + N);
  int cnt[3] = {};
  REP(i, N) {
    if(vs[i] <= A) {
      cnt[0]++;
    } else if(vs[i] <= B) {
      cnt[1]++;
    } else {
      cnt[2]++;
    }
  }
  int res = min(min(cnt[0], cnt[1]), cnt[2]);
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 1e5+10;

int N, M, root;
vi childs[MAX];
vi parents[MAX];
bool isRoot[MAX];
int parent[MAX];
int R[MAX];

int dfs(int n) { // n番目のノードの深さを探索
    if (R[n] >= 0) return R[n];
    int resRank = -1, idx = -1;
    FORE (p, parents[n]) {
        int r = dfs(p);
        if (r > resRank) {
            resRank = r;
            idx = p;
        }
    }
    parent[n] = idx;
    R[n] = resRank+1;
    return R[n];
}

int main() {
    cin >> N >> M;
    REP (i, N) {
        isRoot[i] = true;
    }
    REP (i, N+M-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        parent[i] = -2;
        R[i] = -1;
        childs[a].push_back(b);
        parents[b].push_back(a);
        isRoot[b] = false;
    }

    root = -1;
    REP (i, N) {
        if (isRoot[i]) {
            root = i;
            parent[i] = -1;
            R[i] = 0;
        } else {
            if (parents[i].size() == 1) {
                parent[i] = parents[i][0];
            }
        }
    }

    REP (i, N) dfs(i);

    REP (i, N) cout << parent[i]+1 << "\n";
    return 0;

}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,a) for(int i=0;i<(a);i++)
#define MOD 1000000007

int main(){
  int N;
  cin>>N;
  if(N<3){
    cout<<0<<endl;
    return 0;
  }
  cout<<N/3<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ABC161b
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);

            var t = Console.ReadLine().Split(' ');
            int all = 0;
            List<int> list = new List<int>();
            for (int i = 0; i < n; i++)
            {
                int a = int.Parse(t[i]);
                all += a;
                list.Add(a);
            }

            int count = 0;
            double th = (double)all / (4 * m);
            foreach (var item in list)
            {
                if(item < th)
                {
                    continue;
                }
                count++;
                if(count >= m)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define sc(x)            scanf("%d",&x)
#define scc(x)           scanf("%c",&x)
#define scl(x)           scanf("%lld",&x)
#define sz(v)	     	(v.size())
#define mem(v, d)		memset(v, d, sizeof(v))
#define oo				2000000100
#define OO				2000000000000000100
#define PI 3.14159265
#define S second
#define F first
#define Ceil(x,y) ((x+y-1)/y)
#define EPS 1e-8
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double pi=3.14159265358979323846264338327950288419716939937510582097494459;
typedef unsigned int uint;
typedef long long ll;
int dX[] = {0,0,1,-1,0};
int dY[] = {1,-1,0,0,0};
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int MOD = 1000000007;
const int N = 5050;
int n; string str;
ll mod = 1610612741;
ll base = 127;
ll pw[N],Hash[N];
ll fastpower(ll a,ll x)
{
	if(x == 1) return a;
	if (x==0) return 1;
	ll p = fastpower(a,x>>1);
	if(x%2) return (((p*p)%mod)*a)%mod;
	else return (p*p)%mod;
}
ll modInv(ll x, ll m) {
    return fastpower(x, m - 2);
}
void init()
{
    pw[0] = 1;
    for(int i = 1;i<N;++i)
        pw[i] = (pw[i-1]*base)%mod;
}
bool ok(int mid)
{
    unordered_map<ll,int>mp;
    mp[Hash[mid-1]]=mid-1;
    for(int i = mid;i<n;++i){
        ll sub =  (((Hash[i] - Hash[i-mid] + mod)%mod)* modInv(pw[i-mid+1],mod))%mod;
        if(mp[sub]!=0 && i - mp[sub] >= mid) return 1;
        if(!mp[sub]) mp[sub] = i;
    }
    return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
#else
    //freopen("journey.in","r",stdin);
    //freopen("journey.out","w",stdout);
#endif
    sc(n); cin>>str;
    init();
    for(int i = 0;i<n;++i)
        Hash[i] = (Hash[max(0,i-1)] + (str[i] - 'a' + 1) * pw[i]) % mod;
    int l = 0,r = n,mid;
    while(l<r)
    {
        mid = l+(r-l+1)/2;
        if(ok(mid)) l = mid;
        else r = mid-1;
    }
    printf("%d\n",l);


    return 0;
}


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

const int mod = 1e9 + 7;
const int maxn = 3e3 + 3;
ll dp[maxn][maxn];
string s;

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

  int n;
  cin >> n >> s;
  s = "." + s;
  dp[n][1] = 1;
  int len = 1;
  for (int i = n - 1; i >= 1; i--) {
    len++;
    if (s[i] == '>') {
      ll sum = dp[i + 1][1];
      for (int j = 2; j <= len; j++) {
        dp[i][j] = sum;
        sum = (sum + dp[i + 1][j]) % mod;
      }
    } else {
      ll sum = dp[i + 1][len - 1];
      for (int j = len - 1; j >= 0; j--) {
        dp[i][j] = sum;
        sum = (sum + dp[i + 1][j - 1]) % mod;
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + dp[1][i]) % mod;
  }
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 70016
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n=100000;
    int num;
    int N;
    double ans[n];
    for(int i=0;i<n;i++){
        cin >> num;
        if(num==0) {
            N=i;
            break;
        }
        double ave=0;
        //sum
        vector<int> score(num);
        for(int j=0;j<num;j++){
            cin >> score[j];
        }
        int sum=accumulate(score.begin(), score.end(), 0);
        //ave
        ave=sum/float(num);
        ans[i]=0;
        for(int j=0;j<num;j++){
            ans[i]+=pow(score[j]-ave, 2.0);
        }
        ans[i]=ans[i]/double(num);
        ans[i]=sqrt(ans[i]);
    }

    for(int i=0;i<N;i++){
        cout <<fixed << setprecision(5)<< ans[i] << endl;
    }
    return 0;

}


Measured memory_bytes: 3260
from math import *


def main():
        n, m, k = map(int, input().split())
        for i in range(n+1):
                for j in range(m+1):
                        if i * m + j * n - 2*i*j == k:
                                print('Yes')
                                return
        print('No')
        

if __name__ == '__main__':
        main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


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

    
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for(int i=1;i<n;i++){
        if(a[i] == a[i-1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES\n";

}

Measured memory_bytes: 1792
from scipy.sparse.csgraph import floyd_warshall
import itertools

N, M, R = map(int, input().split())
r = list(map(int, input().split()))
r = [ri-1 for ri in r]

graph = [[0]*N for i in range(N)]
for i in range(M):
  a, b, c = map(int, input().split())
  a -= 1; b -= 1
  graph[a][b] = graph[b][a] = c

dist = floyd_warshall(graph).astype(int)
orders = list(itertools.permutations(r, R))

ans = float('inf')
for order in orders:
  d = 0
  for u, v in zip(order, order[1:]):
    d += dist[u][v]
  ans = min(ans, d)

print(ans)

Measured memory_bytes: 19720
#include<iostream>
#include<math.h>
#include<iomanip>

int main()
{
	int a, b;
	std::cin >> a >> b;

	std::cout << std::fixed << std::setprecision(6);

	int d = a / b;
	int r = a % b;
	double f = (double)a / b;

	std::cout << d << " " << r << " " << f << std::endl;
}

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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main() {
    ll h,w;cin>>h>>w;
    string s[h];
    for(ll i=0;i<h;i++){
        cin>>s[i];
    }
    ll t[h][w];
    ll y[h][w];
    for(ll i=0;i<w;i++){
        for(ll j=0;j<h;j++){
            if(j==0){
                if(s[j][i]=='.')t[j][i]=1;
                else t[j][i]=0;
            }else if(j<=h-2){
                if(s[j][i]=='.'){
                    t[j][i]=t[j-1][i]+1;
                }else{
                    t[j][i]=0;
                    for(ll k=1;k<t[j-1][i];k++){
                        t[j-1-k][i]=t[j-1][i];
                    }
                }
            }else{
                if(s[j][i]=='.'){
                    t[j][i]=t[j-1][i]+1;
                    for(ll k=0;k<t[j][i]-1;k++){
                        t[j-1-k][i]=t[j][i];
                    }
                }else{
                    t[j][i]=0;
                    for(ll k=1;k<t[j-1][i];k++){
                        t[j-1-k][i]=t[j-1][i];
                    }
                }
            }
        }
    }
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            if(j==0){
                if(s[i][j]=='.')y[i][j]=1;
                else y[i][j]=0;
            }else if(j<w-1){
                if(s[i][j]=='.'){
                    y[i][j]=y[i][j-1]+1;
                }else{
                    y[i][j]=0;
                    for(ll k=1;k<y[i][j-1];k++){
                        y[i][j-1-k]=y[i][j-1];
                    }
                }
            }else{
                if(s[i][j]=='.'){
                    y[i][j]=y[i][j-1]+1;
                    for(ll k=0;k<y[i][j]-1;k++){
                        y[i][j-1-k]=y[i][j];
                    }
                }else{
                    y[i][j]=0;
                    for(ll k=1;k<y[i][j-1];k++){
                        y[i][j-1-k]=y[i][j-1];
                    }
                }
            }
        }
    }
    
    ll ans=0;
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            ans=max(ans,t[i][j]+y[i][j]-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 66816
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
// #define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

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

vector<int> prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        //we will try to shorten the match string length until we revert to the beginning of match (index 1)
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
int val(int x, int y, int z){
    return (x*x+y*y+z*z+x*y+y*z+z*x);
}
void solve(){

    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1;i<=n;i++){
        int ans = 0;

        for(int j = 1; j*j<=n;j++){
            int l = j, r = sqrt(n);
            // cout <<l << " " << r << endl;
            while(l<=r){
                // cout << "isbar" << endl;
                // cout << i << endl;
                // cout << j << " " << l << " " << r << endl;
                // cout << val(j,l,r) << endl;
                if(val(j,l,r)==i){
                    if(j==l && r==j)ans+=1;
                    else if(j!=l && j!=r && r!=l){
                        // cout << j << " " << l << " " << r << endl;
                    ans+=6;
                    }
                    else ans+=3;
                    l++;
                    r--;
                }
                else{

                    if(val(j,l,r)<i)l++;
                    else r--;
                }

            }
        }
        cout << ans << endl;
    }
    // cout << ans << endl;
    
} 

signed main() 
{   
    IOS;
    int t = 1;
    // cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 3556
from collections import Counter
import sys
from math import isinf


def warshall_floyd(v_count: int):
    """ ワーシャルフロイド　(user:htkb)
    :param v_count: 頂点数
    :param matrix:  隣接行列(到達不能はfloat("inf"))
    """
    # 到達不能をfloat("inf")にしておけば余計なチェックを入れなくても
    # inf > inf+(-1) のような到達不能＋負辺が繋がってしまうことはない
    global matrix
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3  # min(c1, c2+c3)


H, W = map(int, input().split())
V = 10
matrix = [[float('inf')]*V for _ in range(V)]
for i in range(10):
    c = map(int, input().split())
    for j, cj in enumerate(c):
        matrix[i][j] = cj

warshall_floyd(V)
costs = [matrix[i][1] for i in range(10)]

l = []
for _ in range(H):
    l.extend(list(map(int, input().split())))
c = Counter(l)
ans = 0


for k, v in c.items():
    if k == -1:
        continue
    ans += costs[k]*v
print(ans)


Measured memory_bytes: 3836
(defun get-base-value-range (tax tax-rate)
  (list (ceiling (/ tax tax-rate))
        (ceiling (- (/ (+ tax 1) tax-rate) 1))))

(let ((a-range (get-base-value-range (read) 0.08))
      (b-range (get-base-value-range (read) 0.1)))
  (if (or (< (cadr a-range) (car b-range))
          (< (cadr b-range) (car a-range)))
      (princ -1)
      (princ (max (car a-range) (car b-range)))))

Measured memory_bytes: 13672
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector> 
#define LL long long
using namespace std;
const int N=2e5+10;
struct NODE{
	int k,l,r;
	bool operator <(const NODE &other)
	const { return k<other.k; }
}node[N];
priority_queue<int,vector<int>,greater<int> >que;//小根堆,注意空格！！！！ 
int main()
{
	int T,n;
	scanf("%d",&T);
	while(T)
	{
		T--;
		LL sum=0;
		LL now=0;
		int cnt=0; 
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%d",&node[i].k,&node[i].l,&node[i].r);
			now+=max(node[i].l,node[i].r);
		}
	//	cout<<now<<endl;
		sort(node+1,node+n+1);
		//for(int i=1;i<=n;i++)
		//	printf("<%d %d %d>\n",node[i].k,node[i].l,node[i].r);
		int j=1;
		for(int i=1;i<=n;i++)
		{
			while(j<=n&&node[j].k<=i)
			{
				if(node[j].l>=node[j].r)
				{
					sum+=node[j].r;
					que.push(node[j].l-node[j].r);
				}
				j++;
			}
			while(que.size()>i)
			{
			//	printf("%d ",que.top());
				que.pop();
			}
			//printf("\n");
		}
		while(que.size())
		{
			sum+=que.top();
			cnt++;
			que.pop();
		}
		//cout<<cnt<<endl;
		//cout<<sum<<endl;
		j=n;
		for(int i=n;i>0;i--)
		{
			while(j&&node[j].k>=i)
			{
				if(node[j].r>node[j].l)
				{
					sum+=node[j].l;
					que.push(node[j].r-node[j].l);
				}
				j--;
			}
			while(que.size()>n-i)
			{
			//	printf("%d ",que.top());
				que.pop();
			}
		//	printf("\n"); 
		}
		while(que.size())
		{
			sum+=que.top();
			cnt++;
			que.pop();
		}
	//	cout<<cnt<<endl;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 6108
#include <algorithm>
#include <iostream>
#include<map>
using namespace std;
int n, m, k;
map<pair<int,int>, int> mp;
const int MAXN = 3e5 + 50;
struct node{
    int ord;
    int cnt;
}r[MAXN], c[MAXN];

bool cmp(struct node &a, struct node &b){
    return a.cnt > b.cnt;
}

inline void readInt(int &x) {
    static char c; c = getchar(); 
    static int minus; minus = 1;
    for (x = 0; !(c >= '0' && c <= '9'); c = getchar()) if(c == '-') minus = -1;
    for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar()); x *= minus;
}

int main(){
    cin >> n >> m >> k;
    for (int i = 0; i < k;i++){
        int x, y;
        readInt(x);
        readInt(y);
        mp[{x, y}] = 1;
        r[x].ord = x;
        r[x].cnt++;
        c[y].ord = y;
        c[y].cnt++;
    }
    sort(r, r + MAXN, cmp);
    sort(c, c + MAXN, cmp);
    
    int mxr = r[0].cnt;
    int mxc = c[0].cnt;
    int res = mxr + mxc;
    int i = 0;
    bool can = false;
    while(r[i].cnt==mxr && !can){
        int j = 0;
        while(c[j].cnt==mxc && !can){
            if(!mp[{r[i].ord, c[j].ord}])
                can = true;
            j++;
        }
        i++;
    }
    if(can)
        cout << res << endl;
    else
        cout << res - 1 << endl;
    return 0;
}

Measured memory_bytes: 27080
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, K;
  std::cin >> N >> K;
  vvi ans = vv(0, 2, 0, int);
  if(K>((N-1)*(N-2))/2){
    std::cout << -1 << '\n';
    return 0;
  }
  int count = 0, num=0;
  for(int i=0;i<N-2;i++){
    count += N-2-i;
    if(count == K){
      num=i+1;
      break;
    }else if(count>K){
      count -= N-2-i;
      num = i;
      break;
    }
  }
  vvi tmp = vv(0, 2, 0, int);
  for(int i=0;i<num;i++){
    ans.push_back(std::vector<int> {1, i+2});
  }
 for(int i=num+2;i<=N;i++){
   ans.push_back(std::vector<int> {i, 1});
   for(int j=i+1;j<=N;j++){
     if(i==num+2 && j-i<=K-count){
       continue;
     }
     ans.push_back(std::vector<int> {i, j});
   }
 }
 //std::cout << num << '\n';
 std::cout << ans.size() << '\n';
 for(int i=0;i<ans.size();i++) std::cout << ans[i][0] << " " << ans[i][1] << '\n';
 return 0;
}


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

int main() {
    int m;
    cin >> m;
    while (m--) {
        string train;
        cin >> train;
        set<string> trains;
        for (int i = 1; i < (int) train.length(); i++) {
            string sub[2];
            sub[0] = train.substr(0, i);
            sub[1] = train.substr(i);
            string rsub[2];
            for (int j = 0; j < 2; j++) {
                for (string::reverse_iterator rit = sub[j].rbegin(); rit != sub[j].rend(); rit++) {
                    rsub[j] += *rit;
                }
            }
            trains.insert(sub[0] + sub[1]);
            trains.insert(sub[0] + rsub[1]);
            trains.insert(rsub[0] + sub[1]);
            trains.insert(rsub[0] + rsub[1]);
            trains.insert(sub[1] + sub[0]);
            trains.insert(sub[1] + rsub[0]);
            trains.insert(rsub[1] + sub[0]);
            trains.insert(rsub[1] + rsub[0]);
        }
        cout << trains.size() << endl;
    }
}

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

int main()
{
    int n, b, f, r, v;
    int a[4][3][10] = {0};
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        a[b-1][f-1][r-1] += v;
    }
    
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                printf(" %d", a[i][j][k]);
            }
            putchar('\n');
        }
        if (i != 3) puts("####################");
    }
}



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

int A[100001];
long sum=0;
int main(int argc, const char** argv) {
    int n=0;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        A[a]++;
    }
    int q=0;
    cin>>q;
    for(int i=0;i<100001;i++){
        sum+= A[i]*i;
    }

    for(int i=0;i<q;i++){
        int b,c;
        cin>>b>>c;
        sum += A[b]*(c-b);
        A[c] += A[b];
        A[b] = 0;
        cout<<sum<<'\n';
    }

    return 0;
}

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

void solve(long long N, long long K, long long S) {
    if (S == 1e9) {
        rep(i, N) {
            if (i < K) {
                cout << S << " ";
            } else {
                cout << 1 << " ";
            }
        }
    } else {
        rep(i, N) {
            if (i < K) {
                cout << S << " ";
            } else {
                cout << S + 1 << " ";
            }
        }
    }
}

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


Measured memory_bytes: 3720
N = int(input())
lis = []
for i in range(N):
    S, P = [i for i in input().split()]
    lis.append([S,int(P),i+1])
    
lis2 = sorted(lis, key=lambda x:(x[0],-x[1]))
for i in lis2:
    print(i[2])

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

int main() {
  int A,B;
  int count = 0;
  string p;
  cin >> A >> B;

  // ここにプログラムを追記
  for(int i = A; i <= B; i++){
    string I = to_string(i);
    int b = I.length();
    int flag = 0;
      for(int a = 0; a < int(b/2); a++){
        if(I[a] !=  I[b-(a+1)]){
          flag = 1;
          break;
        }
      }
    if(flag == 0) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    char s,t,u,v;
    cin >> s >> t >> u >> v;
    int a,b,c,d;
    a=s-'0';b=t-'0';c=u-'0';d=v-'0';
    if(a+b+c+d==7){
        cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
        return 0;
    }
    if(a+b+c-d==7){
        cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
        return 0;
    }
    if(a+b-c+d==7){
        cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
        return 0;
    }
    if(a+b-c-d==7){
        cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
        return 0;
    }
    if(a-b+c+d==7){
        cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
        return 0;
    }
    if(a-b+c-d==7){
        cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
        return 0;
    }
    if(a-b-c+d==7){
        cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
        return 0;
    }
    if(a-b-c-d==7){
        cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
        return 0;
    }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define For(i, a, b)  for(int i = a, _b = b; i <= _b; ++i)
#define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i)
#define FileName      "test"
#define ll            long long
#define ld            long double
#define ull           unsigned long long
#define Print(x)      cerr << #x << "is " << x << '\n';
#define pb            push_back
#define X             first
#define Y             second
//#define Karma

using namespace std;

template<typename T> inline void Cin(T &x)
{
    char c;
    T sign = 1;
    x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        if (c == '-') sign = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= sign;
}
template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}
template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}

typedef pair<int, int> pii;
typedef pair<ll, int> plli;
const int N = 3007;

ll f[N][N], n, a[N];

ll S(int l, int r)
{
    if(l > r) return 0;
    return a[r] - a[l - 1];
}

void Enter()
{
     Cin(n);
     For(i, 1, n) Cin(a[i]), a[i] += a[i - 1];
}

void Solve()
{
     for(int l = n; l >= 1; --l)
     {
         f[l][l] = a[l];
         f[l][l + 1] = max(a[l] - a[l - 1], a[l + 1] - a[l]);
         for(int r = l + 2; r <= n; ++r)
         {
             f[l][r] = max(S(l + 1, r) - f[l + 1][r] + a[l] - a[l - 1], S(l, r - 1) - f[l][r - 1] + a[r] - a[r - 1]);
         }
     }
     cout << 2 * f[1][n] - a[n];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef Karma
    freopen(FileName".inp", "r", stdin);
    freopen(FileName".out", "w", stdout);
#endif // Karma

    Enter();
    Solve();

    return 0;
}


Measured memory_bytes: 70016
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#define ll long long
using namespace std;

int main()
{
	int n,x,a=1,f=0,c=0;
	cin>>n;
	vector <int> v;
	while(n--)
	{
		cin>>x;
		v.push_back(x);
	}
	vector<int>:: iterator it,pit;
    
	pit=v.begin();
	it =find(pit,v.end(),a);
	if (it!=v.end())
	{
	 c+=(it-pit);
	 a++;
	 f=1;
    }
    pit=it;
    it =find(pit,v.end(),a);
	while(it !=v.end())
	{
		
		c+=(it-pit-1);
		pit=it;
		a++;
		it=find(pit,v.end(),a);
		
	}
	c+=(v.end()-pit-1);
	if (f==1)
	cout<<c;
	else
	cout<<-1;
	
	
}
	


	
	
	
   



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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int sum = 0;
	sort(a.rbegin(), a.rend());
	for (int i = 0; i < k; i++)
		sum += a[i];

	cout << sum << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int k;
vector<int>v;
priority_queue<int,vector<int>,greater<int>>q;
signed main(){
    cin>>k;
    for(int i=1;i<=9;i++)q.push(i);
    rep(_,k){
        int p=q.top();
        q.pop();
        for(int i=p%10-1;i<=p%10+1;i++){
            if(0<=i&&i<=9){
                q.push({p*10+i});
            }
        }
        if(_==k-1)cout<<p<<endl;
    }
    return 0;
}


Measured memory_bytes: 2420