akhauriyash/Code-Regression huggingface dataset:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    A = LI()

    k = max(A)
    B = [0]*(n+1)

    def CountingSort(A, B, k):
        C = [0]*(k+1)

        for j in range(n):
            C[A[j]] += 1

        for i in range(1, k+1):
            C[i] = C[i] + C[i-1]

        for j in range(n-1, -1, -1):
            B[C[A[j]]] = A[j]
            C[A[j]] -= 1

        print(*B[1:])

    CountingSort(A, B, k)

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 224200
import sys
input = sys.stdin.readline
from collections import Counter, deque

import numpy as np


INF = float('inf')


def ctoi(char):
    return ord(char) - ord('A')


def itoc(number):
    return chr(number + ord('A'))


def main():
    N = int(input())
    S = list(input().rstrip())
    S_list = np.array([ctoi(c) for c in S])
    S_list += N
    ans = [itoc(num % 26) for num in S_list]
    print(''.join(ans))


if __name__ == '__main__':
    main()

Measured memory_bytes: 21912
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
const int N=5010;
const ll p=1000000007;
int n;
ll f[N][N][2];
ll f2[N][2];
ll h[N];
vector<int> g[N];
int s[N];
void add(ll &a,ll b)
{
	a=(a+b)%p;
}
void dfs(int x,int fa)
{
	s[x]=1;
	f[x][1][0]=1;
	for(auto v:g[x])
		if(v!=fa)
		{
			dfs(v,x);
			memcpy(f2,f[x],sizeof f2);
			memset(f[x],0,sizeof f[x]);
			for(int i=1;i<=s[x];i++)
				for(int j=1;j<=s[v];j++)
					for(int k=0;k<=1;k++)
						for(int l=0;l<=1;l++)
						{
							//割
							add(f[x][i][k^l^1],f2[i][k]*f[v][j][l]%p*h[j]);
							//不割 
							add(f[x][i+j][k^l],f2[i][k]*f[v][j][l]);
						}
			s[x]+=s[v];
		}
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	h[2]=1;
	for(int i=4;i<=n;i+=2)
		h[i]=h[i-2]*(i-1)%p;
	dfs(1,0);
	ll ans=0;
	for(int i=1;i<=n;i++)
		ans=(ans+(f[1][i][0]-f[1][i][1])*h[i])%p;
	ans=(ans+p)%p;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 392704
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 100000000;
const int MOD = 1000000007;
int cou=0;
void dfs(int x,int y,int a,int b,vector<vector<char> > &v){
  v[x][y]='#';
  cou++;
  
  int dx[4]={0,0,-1,1},dy[4]={-1,1,0,0};
  for (int i = 0; i < 4; i++) {
    /* code */
    int nx=x+dx[i],ny=y+dy[i];
    if(0<=nx&&nx<a&&0<=ny&&ny<b&&v[nx][ny]=='.')dfs(nx,ny,a,b,v);
  }
}
int main(){
  for (;;) {
    int a,b;
    cou=0;
    std::cin >> a>>b;
    if(a==0&&b==0)exit(0);
    vector<vector<char> > v(a,vector<char>(b));
    int s1,s2;
     rep(j,b){
      rep(i,a){
        std::cin >> v[i][j];
        if(v[i][j]=='@'){s1=i;s2=j;}
      }
    }
    dfs(s1,s2,a,b,v);
    /* code */
    std::cout << cou << std::endl;
  }
}


Measured memory_bytes: 3088
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
	"math"
)

var INF int32 = math.MaxInt32
var INF64 int64 = math.MaxInt64

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func readLineNums(bf *bufio.Reader) []int {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int{}
	for _, field := range fields {
		num, _ := strconv.Atoi(field)
		nums = append(nums, num)
	}
	return nums
}

func readLineNum64s(bf *bufio.Reader) []int64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int64{}
	for _, field := range fields {
		num, _ := strconv.ParseInt(field, 10, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineFloats(bf *bufio.Reader) []float64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []float64{}
	for _, field := range fields {
		num, _ := strconv.ParseFloat(field, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineStrs(bf *bufio.Reader) []string {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	return strings.Split(line, " ")
}

func main() {
	bf := bufio.NewReader(os.Stdin)
	N := readLineNums(bf)[0]
	A := readLineNum64s(bf)

	sums := make([]int64, N)
	sums[0] = A[0]
	for i:=1; i<N; i++ {
		sums[i] = sums[i-1]+A[i]
	}

	dp := make([][]int64, N)
	for i := range dp {
		dp[i] = make([]int64, N)
	}

	for l:=2; l<=N; l++ {
		for i:=0; i<=N-l; i++ {
			j := i+l-1
			dp[i][j] = INF64
			for k:=i; k<j; k++ {
				dp[i][j] = min64(dp[i][j], dp[i][k]+dp[k+1][j])
			}
			dp[i][j] += sums[j]-sums[i]+A[i]
		}
	}

	fmt.Println(dp[0][N-1])
}


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

int main () {
	
	int m=0, k=0, i=0;

	cin >> m >> k;

	if (m==0) {
		if (k==0) cout << "0 0" << endl;
		else cout << "-1" << endl;
	}

	else if (m==1) {
		if (k==0) cout << "0 0 1 1" << endl;
		else cout << "-1" << endl;
	}

	else if (m>1) {

		double aux = pow(2.00, (double)(m));
		aux--;

		if (k<=aux) {

			vector <int> v;

			for (i=0; i<=aux; i++)
				if (i!=k)
					v.push_back(i);
			v.push_back(k);

			for (i=aux; i>=0; i--)
				if (i!=k)
					v.push_back(i);
			v.push_back(k);

			cout << v[0];
			for(i=1; i<v.size(); i++) cout << " "  << v[i];
			cout << endl;

		}
		else cout << "-1" << endl;

	}


	return 0;
}

Measured memory_bytes: 2932
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main(void){
	int ab,bc,ca;
	cin>>ab>>bc>>ca;
	cout<<ab*bc/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import numpy as np
import math

def solve(A: int, B: int, N: int):
    x = min(B-1, N)
    print(math.floor(A*x/B)-A*math.floor(x/B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(A, B, N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 26928
#include <bits/stdc++.h>
#define eb emplace_back
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<60;
const ll MOD=998244353LL;
template<class T> void chmin(T &a,T b){a=min(a,b);}
template<class T> void chmax(T &a,T b){a=max(a,b);}
vector<int> dep,c;
vector<vector<int>> G;
void dfs(int i,int p){
	if(dep[i]%2==0){
		c[i]=1;
	}else{
		c[i]=2;
	}
	for(auto &e:G[i]){
		if(e==p)continue;
		dep[e]=dep[i]+1;
		dfs(e,i);
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;cin>>n;
	G.resize(n);
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;--a;--b;
		G[a].eb(b);
		G[b].eb(a);
	}
	dep.resize(n);
	c.resize(n);
	dfs(0,-1);
	int c0=0,c1=0,c2=0;
	int cc0=n/3,cc1=(n+2)/3,cc2=(n+1)/3;
	for(int i=0;i<n;i++){
		if(c[i]==1){
			c1++;
		}else{
			c2++;
		}
	}
	if(c1>c2){
		for(int i=0;i<n;i++){
			if(c[i]==1){
				c[i]=2;
			}else{
				c[i]=1;
			}
		}
		swap(c1,c2);
	}
	if(c1<cc1){
		for(int i=0;i<n;i++){
			if(c[i]==1){
				c[i]=0;
			}
		}
		c0=c1;
		c1=0;
		for(int i=0;i<n;i++){
			if(c1<cc1&&c[i]==2){
				c1++;
				c[i]=1;
				c2--;
			}
		}
	}
	for(int i=0;i<n;i++){
		if(c0<cc0){
			if(c2>cc2&&c[i]==2){
				c2--;
				c0++;
				c[i]=0;
			}
			if(c1>cc1&&c[i]==1){
				c1--;
				c0++;
				c[i]=0;
			}
		}
	}
	int t0=3,t1=1,t2=2;
	for(int i=0;i<n;i++){
		if(c[i]==0){
			cout<<t0<<" ";
			t0+=3;
		}else if(c[i]==1){
			cout<<t1<<" ";
			t1+=3;
		}else{
			cout<<t2<<" ";
			t2+=3;
		}
	}
	cout<<endl;
}


Measured memory_bytes: 17920
#include<cstdio>
int h,w,n,sr,sc;
char s[200001],t[200001];
bool judge(int pos, int max_pos, int dir, char a, char b){
    for(int i=0;i<n;i++){
        if(s[i]==a){
            pos+=dir;
            if(pos<=0 || pos>max_pos)return false;
        }
        if(t[i]==b){
            pos-=dir;
            if(pos<=0)pos=1;
            if(pos>max_pos)pos=max_pos;
        }
    }
    return true;
}
int main(){
    scanf("%d%d%d%d%d",&h,&w,&n,&sr,&sc);
    scanf("%s%s",s,t);
    if(judge(sc,w,1,'R','L') && judge(sc,w,-1,'L','R') && judge(sr,h,-1,'U','D') && judge(sr,h,1,'D','U')){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 512
String = list(input().split())
Number = list(map(int,input().split()))
U = input()

if U == String[0]:
    num = Number[0]-1
    print(num,Number[1])
elif U == String[1]:
    num = Number[1] - 1
    print(Number[0], num)
else:
    print("Error")

Measured memory_bytes: 3060
#include <iostream>
#include <memory>
#include <string>
#include <cmath>
using namespace std;

int main()
{
  int age;
  cin >> age;
  if(age == 1) {
    cout << "Hello World" << endl;
  }
  else {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())

s1 = set()
s2 = set()
for i in range(m):
    a,b = map(int,input().split())
    if a == 1:
        s1.add(b)
    elif b == 1:
        s1.add(a)
    elif a == n:
        s2.add(b)
    elif b == n:
        s2.add(a)

if s1.isdisjoint(s2):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


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

//はじめからいけるか試す

string S;
string T;

bool ok( int n){ // S.at(n)以降でTに一致させられるか
    if(S.size()-n < T.size()) return false;
    for(int i=0; i<T.size(); i++){
        if(S.at(i+n) =='?') continue;
        if(S.at(i+n) != T.at(i) ) return false;
    }
    return true;
}

int main(){
    cin >> S >> T;
    int num=-1;
    for(int i=0; i<S.size();i++){
        if(ok(i)) num = i;
    }
    if(num==-1) {cout << "UNRESTORABLE" << endl; return 0;}
    string ans=S;
    for(int i=0; i<S.size(); i++){
        if(ans.at(i)=='?') ans.at(i)='a';
    }
    for(int i=0; i<T.size(); i++){
        ans.at(i+num) = T.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int ans=0;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='?')
		if(s[i-1]=='P' &&   s[i]=='?'){
			s[i]='D';
		}
		else if(s[i+1]=='D' || s[i+1]=='?' && s[i]=='?'){
			s[i]='P';
		}
		else{
			s[i]='D';
		}
	}
	cout<<s<<endl;
  return(0);
}

Measured memory_bytes: 3756
n= int(input())
ss=input()
rs = set()
gs = set()
bs = set()
 
for i, s in enumerate(ss):
    if s == "R":
        rs.add(i)
    elif s == "G":
        gs.add(i)
    else:
        bs.add(i)
ans = 0
if len(gs) > len(bs) and len(gs) > len(rs):
    tmp = gs
    gs = bs
    bs = tmp
elif len(rs) > len(bs) and len(rs) > len(gs):
    tmp =rs
    rs = bs
    bs = tmp
    
for r in rs:
    for g in gs:
        c = 0
        if r+r-g in bs:
            c+=1
        if g+g-r in bs:
            c+=1
        if (g+r)/2 in bs:
            c+=1
        ans += len(bs) -c
print(ans)

Measured memory_bytes: 9560
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;
use std::collections::HashSet;
use std::char;
use std::cmp::{min, max};
use itertools::Itertools;
use std::ops::{Add, AddAssign};
use num_integer::{Integer, gcd, lcm};
use std::collections::VecDeque;
use smallvec::alloc::collections::LinkedList;
use regex::internal::Char;
use std::iter::once;

fn read<T: FromStr>(stdin: &mut StdinLock) -> T {
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>(stdin: &mut StdinLock) -> (T, S) {
    let a = read(stdin);
    let b = read(stdin);
    (a, b)
}

fn read_tuple3<T: FromStr, S: FromStr, R: FromStr>(stdin: &mut StdinLock) -> (T, S, R) {
    let a = read(stdin);
    let b = read(stdin);
    let c = read(stdin);
    (a, b, c)
}

fn lower_bound<T: Copy, F>(v: &Vec<T>, f: F) -> Option<usize> where
    F: Fn(T) -> bool
{
    let mut left = 0;
    let mut right = v.len() - 1;
    if !f(v[left]) {
        return None;
    }
    if f(v[right]) {
        return Some(right);
    }
    loop {
        if right - left == 1 {
            return Some(left);
        }
        let mid = (left + right) / 2;
        if f(v[mid]) {
            left = mid;
        } else {
            right = mid;
        }
    }
}


fn main() {
    // template
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    // template ends
    let n:u32 = read(&mut stdin);
    let a_list:Vec<u32> = (0..n).map(|_|read(&mut stdin)).collect();
    let mut s = HashSet::new();
    for a in a_list {
        if s.contains(&a) {
            s.remove(&a);
        } else {
            s.insert(a);
        }
    }
    writeln!(out, "{}", s.len());

}



Measured memory_bytes: 3472
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int n;
    cin>>n;
    cout<<"ABC"<<n<<endl;
}

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

int main()
{
	int y, m, d;
	while (cin>>y>>m>>d)
	{
		if (y >= 1990 || (y == 1989 && m >= 2) || (y == 1989 && m == 1 && d >= 8))
		{
			cout << "heisei " << y - 1989 + 1 << " " << m << " " << d << endl;
		}
		else if (y >= 1927 || (y == 1926 && m == 12 && d >= 25))
		{
			cout << "showa " << y - 1926 + 1 << " " << m << " " << d << endl;
		}
		else if (y >= 1913 || (y == 1912 && m >= 8) || (y == 1912 && m == 7 && d >= 30))
		{
			cout << "taisho " << y - 1912 + 1 << " " << m << " " << d << endl;
		}
		else if (y >= 1869 || (y == 1868 && m >= 10) || (y == 1868 && m >= 9 && d >= 8))
		{
			cout << "meiji " << y - 1868 + 1 << " " << m << " " << d << endl;
		}
		else 
		{
			cout << "pre-meiji" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	retur5n a * (b / g);
}*/

int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

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

	if (a == b) {
		cout << a + b << endl;
	} else {
		int ans = max(a, b);
		ans += ans - 1;
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i, j;
	int num[100] = {0};
	int n;
	int max_n = 0;
	int max[100] = {0};
	
	while (scanf("%d", &n) != EOF){
		num[n - 1]++;
	}
	
	j = 0;
	for (i = 0; i < 100; i++){
		if (max_n < num[i]){
			while (--j >= 0){
				max_n = num[i];
				max[j] = 0;
			}
			max[0] = i + 1;
			j = 1;
		}
		else if (max_n == num[i]){
			max[j++] = i + 1;
		}
	}
	for (i = 0; max[i]; i++){
		printf("%d\n", max[i]);
	}
	
	return (0);
}

Measured memory_bytes: 596
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.List (group)

main :: IO ()
main = do
  let
    f :: Int -> Int -> Int
    f k m = (2 * k) `min` (m - 1)
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  ds <- map ('R' ==) . head . words <$> getContents :: IO [Bool]
  let
    (m, s) = ((,) <$> length <*> sum . map (pred . length)) . group $ ds :: (Int, Int)
  print $ s + f k m

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

using namespace std;

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

    int D, G, ans = 0;

    cin >> D >> G;
    vector<pair<int, int>> p(D);
    for (int i = 0; i < D; ++i) {
        cin >> p[i].first >> p[i].second;
        ans += p[i].first;
    }

    for (int s = 0; s < 1 << D; ++s) {
        int sum = 0, num = 0;
        for (int i = 0; i < D; ++i) {
            if (s >> i & 1) {
                sum += 100 * (i + 1) * p[i].first + p[i].second;
                num += p[i].first;
            }
        }

        if (G <= sum) {
            ans = min(ans, num);
            continue;
        }

        for (int i = 0; i < D; ++i) {
            if (s >> i & 1 || 100 * (i + 1) * p[i].first + p[i].second + sum < G) continue;

            int x = min((int)ceil((G - sum) / ((i + 1) * 100.0)), p[i].first), score = 0;

            if (x == p[i].first) score += p[i].second;

            score += x * (i + 1) * 100;
            if (G <= score + sum) ans = min(ans, num + x);
        }
    }

    cout << ans << endl;

    return 0;
}


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

signed main(){
	int n,sum=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n-1;i++){
		sum+=a[i];
	}
	cout<<sum+a[n-1]/2<<endl;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();

    if(n == 1){
        cout << 0 << endl;
        return 0;
    }

    int m = n;
    if(n % 2 != 0){
        m++;
    }

    vector<int> even(m/2, -1);
    vector<int> odd(m/2, -1);

    //cout << s[0] - '0' << endl;
    int even_j = 0;
    int odd_j = 0;
    for(int i = 0; i < n; i++){
        if(i % 2 == 0){
            even[even_j] = s[i] - '0';
            even_j++;
        }
        else {
            odd[odd_j] = s[i] - '0';
            odd_j++;
        }
    }

    sort(even.begin(), even.end());
    sort(odd.begin(), odd.end());

    int even_o = 0;
    int even_w = 0;
    for(int i = 0; i < even.size(); i++){
        if(even[i] == 1){
            even_w++;
        }
        else if(even[i] == 0){
            even_o++;
        }
    }
    int odd_w = 0;
    int odd_o = 0;
    for(int i = 0; i < odd.size(); i++){
        if(odd[i] == 1){
            odd_w++;
        }
        else if(odd[i] == 0){
            odd_o++;
        }
    }

    int e_min = 0;
    int o_min = 0;
    e_min = min(even_o, even_w);
    o_min = min(odd_o, odd_w);

    if(o_min == e_min){
        if(e_min == even_o){
            cout << o_min + min(even_w, odd_w) << endl;
        }
        else if(e_min == even_w){
            cout << o_min + min(even_o, odd_o) << endl;
        }
    }
    else if(o_min < e_min){
        if(o_min == odd_o){
            cout << o_min + even_w << endl;
        }
        else if(o_min == odd_w){
            cout << o_min + even_o <<endl;
        }
    }
    else {
        if(e_min == even_o){
            cout << e_min + odd_w << endl;
        }
        else if(e_min == even_w){
            cout << e_min + odd_o << endl;
        }
    }

}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  int n;
  ll k;
  scanf("%d %lld", &n, &k);
  vector<int> a(n), arrv;
  set<int> arr;
  for(int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    a[i] = --t;
  }
  int nc = 0;
  do {
    arr.insert(nc);
    arrv.push_back(nc);
    nc = a[nc];
  } while(arr.find(nc) == arr.end());
  ll st = 0;
  for(int i = 0; i < arrv.size(); i++) {
    if(arrv[i] == nc) {
      st = i;
      break;
    }
  }
  if(k <= st)
    printf("%d\n", arrv[k] + 1);
  else
    printf("%d\n", arrv[(k - st) % (arrv.size() - st) + st] + 1);
}

Measured memory_bytes: 13824
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vector<pair<ll,pair<ll,ll>>> A(n);
  for(int i=0;i<n;i++){
    ll a,b;cin>>a>>b;
    A[i] = mp(a+b,mp(a,b));
  }
  ll ans = 0;
  sort(ALL(A),greater<pair<ll,pair<ll,ll>>>());
  for(int i=0;i<n;i++)
    if(i%2){
      ans -= A[i].S.S;
    }else{
      ans += A[i].S.F;
    }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
P = get_ints
Q = get_ints

px = P.join
qx = Q.join

a = nil
b = nil

arr = 1.step(N).map { _1 }

arr.permutation.each.with_index do |test, index|
  a = index if test.join == px
  b = index if test.join == qx
end
puts (a - b).abs



Measured memory_bytes: 14420
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

N, P = map(int, raw_input().split())
A = map(int, raw_input().split())
cnt = 0

for a in A:
    if a % 2 == 1:
        cnt += 1

m = {}
def comb(n, k):
    if (n, k) in m:
        return m[(n, k)]
    if n == k or k == 0:
        m[(n, k)] = 1
        return 1
    m[(n, k)] = comb(n - 1, k) + comb(n - 1, k - 1)
    return m[(n, k)]

ans = 0
rem = N - cnt
for i in range(0, cnt + 1, 2):
    ans += comb(cnt, i)
if P == 1:
    ans = 2 ** cnt - ans
print ans * (2 ** rem)

Measured memory_bytes: 2936
use std::io::{self, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let len: usize = read();
    let mut v: Vec<i32> = Vec::new();
    for _ in 0..len {
        let x: i32 = read();
        v.push(x);
    }
    let mut ans = 0;
    for i in 1..(len - 1) {
        if (v[i] - v[i - 1]) * (v[i] - v[i + 1]) < 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll a[15][15], c[15], b[15];

int main()
{
    fast_io;
    ll n, m, x, i, j, k, s, sum = inf;
    cin >> n >> m >> x;
    for (i = 0; i < n; i++)
    {
        cin >> c[i];
        for (j = 1; j <= m; j++)
            cin >> a[i][j];
    }
    for (i = 1; i < (1 << n); i++)
    {
        bitset<15> bt = i;
        s = 0;
        for (j = 1; j <= m; j++) b[j] = 0;
        for (j = 0; j < n; j++)
        {
            if (!bt[j]) continue;
            for (k = 1; k <= m; k++) b[k] += a[j][k];
            s += c[j];
        }
        for (j = 1; j <= m; j++)
            if (b[j] < x) break;
        if (j > m) sum = min(sum, s);
    }
    cout << (sum == inf ? -1 : sum);
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>

using namespace std;

int main()
{
	int i=1;
	int x;
	while(1){
		cin>>x;
		if(x==0){
			break;}
		else{
			cout<<"Case "<<i<<": "<<x<<endl;
		i++;
		}
		
	}
	return 0;
}

Measured memory_bytes: 3000
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	r, d, x := nextInt(), nextInt(), nextInt()
	for i := 0; i < 10; i++ {
		x = r*x - d
		fmt.Println(x)
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=n-i;j++){
            string t=s.substr(i,j);
            bool ok=true;
            rep(k,t.size()){
                if(t[k]=='A' || t[k]=='C' || t[k]=='G' || t[k]=='T') continue;
                ok=false;
            }
            if(ok) ans=max(ans,(int)t.size());
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n, k = map(int,input().split())
ans  = []
x = 0

for i in range(n):
    ans.append(list(map(int,input().split())))

ans.sort()

for l in ans:
    x += l[1]
    if x < k:
        continue
    else:
        print(l[0])
        exit()

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int L,R,d; cin>>L>>R>>d;
    cout<<R/d-(L-1)/d<<endl;
    return 0;
}


Measured memory_bytes: 3608
import sys
import bisect
import copy

N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())
Q = int(sys.stdin.readline().rstrip())

cnt = [0] * 26
cumcnt = [cnt]

for i, s in enumerate(S):
    tmp = copy.copy(cumcnt[i])
    tmp[ord(s) - ord("a")] += 1
    cumcnt.append(tmp)

q_remove = {}
q_add = {}

for _ in range(Q):
    t, i, c = sys.stdin.readline().rstrip().split()
    t = int(t)
    i = int(i)
    d = S[i - 1]
    if t == 1:
        if d != c:
            if d not in q_remove.keys():
                q_remove[d] = [i]
            else:
                bisect.insort(q_remove[d], i)
            if c not in q_add.keys():
                q_add[c] = [i]
            else:
                bisect.insort(q_add[c], i)
            S[i - 1] = c 
    else:
        c = int(c)
        cnt_l = copy.copy(cumcnt[i - 1])
        cnt_r = copy.copy(cumcnt[c])
        for q, idx in q_add.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] += x
            cnt_r[ord(q) - ord("a")] += y
        for q, idx in q_remove.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] -= x
            cnt_r[ord(q) - ord("a")] -= y
        ans = 0
        for l, r in zip(cnt_l, cnt_r):
            if r - l > 0:
                ans += 1
        print(ans)

Measured memory_bytes: 217688
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


s = S()

ans = 0
temp = 0
for a in s:
    if a in 'ACGT':
        temp += 1
    else:
        temp = 0
    ans = max(ans, temp)
print(ans)


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

int main(){
	int a, b, c;
	cin >> a >> b >> c;

	int counter = 0;
	for(int i = a; i <= b; i++){
		if (c % i == 0){
			counter++;
		}
	}

	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  int m1,d1,m2,d2;
  cin>>m1>>d1>>m2>>d2;

  if(m1!=m2) cout<<1;
  else cout<<0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
 
 
int main () {
    int N;

    cin >> N;

    bool can = false;
    rep(i,100){
        rep(j,100){
            if(i*7 + j*4 == N){
                can = true;
            }
        }
    }

    if(can)cout << "Yes" << endl;
    else cout << "No" << endl;



}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] c = new int[N];
    int[] s = new int[N];
    int[] f = new int[N];

    for (int i = 0; i < N - 1; i++) {
      c[i] = scanner.nextInt();
      s[i] = scanner.nextInt();
      f[i] = scanner.nextInt();
    }

    for (int i = 0; i < N; i++) {
      int t = s[i] + c[i];
      for (int j = i + 1; j < N - 1; j++) {
        t = Math.max(t, s[j]);
        t = ((t - 1) / f[j] + 1) * f[j];
        t += c[j];
      }
      System.out.println(t);
    }
  }
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, c;
	cin >> n >> m >> c;
	vi v(c);
	REP(i, c)cin >> v[i];
	vector<pii> a(n);
	REP(i, n) {
		cin >> a[i].second >> a[i].first;
		a[i].second--;
	}
	sort(ALL(a), greater<>());
	int cnt = 0;
	int ans = 0;
	REP(i, n) {
		if (cnt == m)break;
		if (v[a[i].second] > 0) {
			ans += a[i].first;
			v[a[i].second]--;
			cnt++;
		}
	}
	cout << ans << endl;
}


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

using namespace std;

const int MAXN = 1e6+5;
int tab[MAXN];
int main()
{
  string a, b;
  cin >> a >> b;
  if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) cout << "YES\n";
  else cout << "NO\n";
}


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

public class Hello
{
    public static void Main()
    {
        var hs = new HashSet<int>();
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var a = int.Parse(Console.ReadLine().Trim());
            if (!hs.Add(a)) hs.Remove(a);
        }
        Console.WriteLine(hs.Count());
    }
}


Measured memory_bytes: 19420
from math import *

while True:
    a,b,c,d=map(float,raw_input().split())
    if a==b==c==d==-1:break
    rd=pi/180
    a,b,c,d=a*rd,b*rd,c*rd,d*rd
    print int(round(6378.1*acos((sin(a)*sin(c)+cos(a)*cos(c)*cos(d-b)))))

Measured memory_bytes: 4472
#include <iostream>

using namespace std;

int main(){
	unsigned long long n;
	cin >> n;
	unsigned long long a[205];
	for(unsigned long long i=0;i<n;i++){
		cin >> a[i];
	}

	int sig=0,ans=0;
	while(sig == 0){
		for(unsigned long long i=0;i<n;i++){
			if(a[i] % 2 != 0){
				sig = 1;
				break;
			}else{
				a[i] = a[i]/2;
			}
		}
		if(sig == 0){
			ans++;
		}
	}

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


Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%s', $s);

$array = array();
$x = 0;
$array[] = $x;
for($i=0; $i<$n; $i++){
    if($s[$i] === 'I'){
        $x++;
        $array[] = $x;
    }else{
        $x--;
        $array[] = $x;
    }
}
print max($array);

Measured memory_bytes: 4604
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
const int MX = 40005;
struct line{double a[2], c;} ln[MX];
int n;
double a, b, c, l, r, m;

struct BIT{
	vector<int> dat;
	int sz;
	BIT(int n){
		for(sz = 1; sz < n; sz *= 2);
		sz++;
		dat.resize(sz);
	}
	int ch(int n){
		int ret = 0;
		for(int i = n; i > 0; i -= i&-i) ret += dat[i];
		for(int i = n; i < sz; i += i&-i) dat[i]++;
		return ret;
	}
};

int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%lf%lf%lf", &a, &b, &c);
		ln[i] = {{a,b},c};
	}
	rep(k,2){
		sort(ln,ln+n,[&](line &a, line &b){return a.a[k] / a.a[!k] < b.a[k] / b.a[!k];});
		int ord[MX];
		rep(i,n) ord[i] = i;
		for(l = -1e10, r = 1e10; r-l > 1e-11;){
			m = (l + r) / 2;
			int cnt = 0;
			double v[MX];
			rep(i,n) v[i] = (ln[i].c - ln[i].a[k]*m) / ln[i].a[!k];
			sort(ord,ord+n,[&](int a, int b){return v[a] < v[b];});
			BIT bt(n);
			rep(i,n) cnt += bt.ch(ord[i]+1);
			(cnt > n*(n-1)/4 ? l : r) = m;
		}
		printf("%.11f%c", m, k ? '\n' : ' ');
	}
}

Measured memory_bytes: 1920
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int N;
vector<pair<pair<string,int>,int> > vec_sort(vector<pair<pair<string,int>,int> > v){
	string s0 = v[0].first.first;
	int p0 = v[0].first.second;
	vector<pair<pair<string,int>,int> > lf,ri;
	REP(i,v.size()){
		if(i==0) continue;
		if(v[i].first.first<s0){
			lf.pb(v[i]);
		}else if(v[i].first.first>s0){
			ri.pb(v[i]);
		}else{
			if(v[i].first.second>p0){
				lf.pb(v[i]);
			}else{
				ri.pb(v[i]);
			}
		}
	}
	if(lf.size()>1){
		lf = vec_sort(lf);
	}
	if(ri.size()>1){
		ri = vec_sort(ri);	
	}
	lf.pb(v[0]);
	lf.insert(lf.end(),all(ri));
	return lf;
}

int main(){
	cin >>N;
	vector<pair<pair<string,int>,int> > v;
	REP(i,N){
		string s;
		int p;
		cin >> s >> p;
		v.pb(make_pair(make_pair(s,p),i+1));
	}
	
	v=vec_sort(v);
	REP(i,N){
		
		cout << v[i].second << endl;
	}
	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

const i64 mod = 1e9 + 7;
i64 ipow(i64 a, i64 b) {
    i64 x = a, y = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) (y *= x) %= mod;
        (x *= x) %= mod;
    }
    return y;
}
i64 inv(i64 x) {
    return ipow(x, mod - 2);
}
i64 fact(i64 x) {
    static vector<i64> f;
    i64 i = f.size();
    if (x >= i) {
        f.resize(x + 1);
        for (; i <= x; ++i) {
            f[i] = i == 0 ? 1 : i * f[i - 1] % mod;
        }
    }
    return f[x];
}
i64 perm(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(n - k)) % mod : 0;
}
i64 comb(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(k) * fact(n - k) % mod) % mod : 0;
}
int main() {
    i64 n, k;
    cin >> n >> k;
    i64 ans = 0;
    for (i64 i = k, sign = 1; i >= 1; --i) {
        ans += sign * (comb(k, i) * ipow(i, n) % mod) + mod;
        ans %= mod;
        sign = -sign;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>
#define X 1
#define Y 1000000000

int main()
{
  int x,y,num,div=0;

  while(1)
    {
      scanf("%d %d",&x,&y);
      if((x >= X && x <= Y) && (y >= X && y <= Y)) break;
    }

  if(x<y)
    {
      num = x;
      x = y;
      y = num;
    }
 
  while(1)
    {
      div = x % y;
      if(div == 0) break;
      x = y;
      y = div;
     }

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



Measured memory_bytes: 2140
# -*- coding: utf-8 -*-
import math
a, b, n = map(int, input().split())
result = 0

if b <= n:
    result = math.floor(a * (b-1)/b) - a * math.floor((b-1)/b)
else:
    result = math.floor(a * n/b) - a * math.floor(n/b)

print(result)


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

const long long INF = 1e18 + 10;
const int MAX_V = 1e5 + 10;

int main() {

    int n, max_w; scanf("%d%d", &n, &max_w);

    vector <long long> v(n), w(n);
    for (int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    vector <vector <long long> > dp(n + 1, vector <long long> (MAX_V, INF));

    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < MAX_V; j++) {
            if (dp[i][j] != INF) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
                dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
            }
        }
    }

    long long result = 0;
    for (int i = dp[n].size() - 1; i >= 0; i--) {
        if (dp[n][i] <= max_w) {
            result = i;
            break;
        }
    }

    cout << result;

    return 0;
}

Measured memory_bytes: 80256
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Int
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.IArray as Array
import Data.Array.MArray
import Data.Array.ST

import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

getInts :: IO [Int]
getInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main :: IO ()
main = do
  [h, n] <- getInts :: IO [Int]
  [a, b] <- transpose <$> replicateM n getInts
  
  let ans = runST $ do
        dp <- VUM.replicate 10001 (10 ^ 9) :: ST s (VUM.MVector s Int)

        VUM.write dp 0 0

        forM_ (zip a b) $ \(a', b') -> do
          forM_ [0..10000] $ \i -> do
            when (i - a' >= 0) $ do
              s <- VUM.read dp i
              t <- VUM.read dp (i - a')

              VUM.write dp i $ minimum [s, t + b']

        VU.freeze dp

  print $ (VU.! h) $ VU.scanr min (10 ^ 9) ans

  return ()


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

void operation_test(bool &Next_plus,ll &sum,ll Next_number,ll &operation);

int main(int argc, char const *argv[]) {
  int N;
  scanf("%d",&N);
  std::vector<ll> A(N);
  for (size_t i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  ll operation_one=0;
  ll operation_two=0;
  ll sum=0;

  bool Next_plus=false;
  for (size_t i = 0; i < N; i++) {
    operation_test(Next_plus,sum,A[i],operation_one);
  }
  Next_plus=true;
  sum=0;
  for (size_t i = 0; i < N; i++) {
    operation_test(Next_plus,sum,A[i],operation_two);
  }

  if(operation_one>operation_two){
    printf("%lld\n",operation_two);
  }else{
    printf("%lld\n",operation_one);
  }

  return 0;
}

void operation_test(bool &Next_plus,ll &sum,ll Next_number,ll &operation){
  if(Next_plus){
    if(sum+Next_number>0){
      Next_plus=false;
      sum+=Next_number;
    }else{
      Next_plus=false;
      operation+=abs((1-sum)-Next_number);
      sum=1;
    }
  }else{
    if(sum+Next_number<0){
      Next_plus=true;
      sum+=Next_number;
    }else{
      Next_plus=true;
      operation+=abs((-1-sum)-Next_number);
      sum=-1;
    }
  }
}


Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
using namespace std;
long long int a[3];
int main()
{
	cin>>a[0]>>a[1]>>a[2];
	if(a[0]%2==0||a[1]%2==0||a[2]%2==0)
	{
		cout<<"0"<<endl;
	}
	else
	{
		sort(a,a+3);
		cout<<a[0]*a[1]<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include <string.h>
#include<iostream>
using namespace std;
 
int main()
{
    int N;
    std::string str;
  	cin>>N;
 
    str = std::to_string(N);
 if(str[0]=='7'||str[1]=='7'||str[2]=='7')
	cout<<"Yes"<<endl;
  else
  	cout<<"No"<<endl;
  
    return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }


int main(){
    int N;
    cin>>N;
    int s=0, n=N;
    for(;;){
        s += n%10;
        n /= 10;
        if(n==0)break;
    }
    if(N%s==0)
    {cout<<"Yes"<<endl;}
    else
    {
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1046527
vector<string> H(M);

int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

long long getKey(string str){
  long long sum = 0, p = 1,i;
  for(i=0;i<str.size();++i){
    sum += p*(getChar(str.at(i)));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M;}
int h2(int key){ return 1 + (key % (M - 1));}

int find(string str){
  long long key, i, h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i * h2(key)) % M;
    if(H.at(h) == str) return 1;
    else if(H.at(h).size() == 0) return 0;
  }
  return 0;
}

int insert(string str){
  long long key,i,h;
  key = getKey(str);
  for(i=0;;i++){
      h = (h1(key) + i * h2(key)) % M;
      if(H.at(h) == str) return 1;
      else if(H.at(h).size() == 0){
        H.at(h) = str;
        return 0;
      }
    }
    return 0;
}

int main(){
  int i,n;
  string str,com;

  cin >> n;
  for(i=0;i<n;++i){
    cin >> com >> str;

    if(com.at(0) == 'i'){
      insert(str);
    }else{
      if(find(str)){
        cout << "yes" << endl;
      }else{
        cout << "no" << endl;
      }
    }
  }
  return 0;
}



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

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

#define MOD 1000000007

ll func(ll n,ll m,ll p){
        if(p==0)return 1;
        if(p%2==0){
                ll t=func(n,m,p/2);
                return t*t%m;
        }else{
                return n*func(n,m,p-1)%m;
        }
}

int main(){
        int n,m;
        cin>>n>>m;
        cout<<func(n,MOD,m)<<endl;
        return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> kouho={4,7,8,11,12,14,15,16,18,19,20,21};
  int n;cin>>n;
  if(n>22) cout<<"Yes"<<endl;
  else{
    bool flag=false;
    for(auto i:kouho){
      if(i==n) flag=true;
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256