akhauriyash/Code-Regression huggingface dataset:
#coding:utf-8
#1_7_C 2015.4.6
r,c = map(int,input().split())
sheet = [list(map(int,input().split())) for i in range(r)]

for row in sheet:
    row.append(sum(row))

s = [sum(list(row[i] for row in sheet)) for i in range(c + 1)]
sheet.append(s)

for row in sheet:
    print(*row)

Measured memory_bytes: 6856
n,m = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]

all_a = sum(a)
flag = True

a.sort(reverse=True)

for i in range(m):
    if a[i] < (all_a / (4 * m)):
        flag = False
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;


struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;b--;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, n){
        ans = max(ans, abs(uf.size(i)));
    } 
    cout << ans << endl;

}

Measured memory_bytes: 3972
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#define ll long long 
#define pb push_back
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   
#define F first 
#define S second
const ll INF = std::numeric_limits<long long>::max(); 
const int IINF = std::numeric_limits<int>::max(); 
const int MOD = 1e9 + 7; 
/*rrrohan*/ 
using namespace std; 
 
/*less than or equal to -> l + r + 1*/
/*upper_bound -> greater than x 
lower_bound -> greater than or equal to x*/
ll gcd(ll a, ll b) //O(log(a+b))
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}  
/*class dsu{
private: 
	vector <int> r,p; 
public: 
	dsu(int n){
		p.resize(n+1);
		r.resize(n+1);  
		for(int i = 0; i < n+1; i++){
			p[i] = i; 
			r[i] = 0; 
		}
	}
	int findset(int i){
		return (p[i] == i) ? i : (p[i] = findset(p[i])); 
	}
	bool issameset(int a, int b){
		return findset(a) == findset(b); 
	}
	void unionset(int i, int j){
		if(!issameset(i,j)){
			int x = findset(i), y = findset(j); 
			if(r[x] > r[y]){
				p[y]  = x; 
			}else{
				p[x] = y; 
				if(r[x] == r[y]){
					r[y]++; 
				}
			}
		}
	}
};
*/ 

int main(){
	double n,k; 
	cin >> n >> k; 
	double ans = 0; 
	ans += max((double)0, n - k + 1)/n; 
	for(int i = 1; i <=  min(n, k - 1); i++){
		ans += pow(0.5, ceil(log2(k/i)))*(1/n); 
		//cout << ceil(log2(k/i)) << endl; 
	}
	cout << std::setprecision(10) << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<pair<pair<string,int>,int>> v(n);
    rep(i,0,n){
        string s;int p;
        cin>>s>>p;
        v[i]=make_pair(make_pair(s,-p),i);
    }
    sort(all(v));
    
    rep(i,0,n) cout<<v[i].second+1<<endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;

ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n;
	cin>>n;
	cout<<up(n,2);
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n;
	cin>>n;
	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];

	lli ans = INF;

	for(lli num=-100;num<=100;num++){
		lli sum = 0;
		REP(i,0,n){
			sum += (a[i]-num)*(a[i]-num);
		}
		ans = min(ans,sum);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count = 0;
		int n = N;
		for(int i = 0; i < N;i++) {
			if(n >= 3) {
				n = n-3;
				count++;
			}else {
				break;
			}
		}
		System.out.println(count);
	}
}

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

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    rep(i, n) {
        if (i == k - 1) {
            s[i] = tolower(s[i]);
        }
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3656
N,K=map(int,input().split())
if K<=((N-1)*(N-2))//2:
    G = {i:[] for i in range(1,N+1)}
    for i in range(1,N+1):
        for j in range(1,N+1):
            if j!=i:
                G[i].append(j)
    cnt = 0
    for i in range(2,N+1):
        for j in range(2,N+1):
            if j in G[i]:
                if cnt==K:break
                G[i].remove(j)
                G[j].remove(i)
                cnt += 1
        if cnt==K:break
    print((N*(N-1))//2-K)
    for i in range(1,N):
        for j in G[i]:
            if j>i:
                print(i,j)
else:
    print(-1)

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

int gcd(int m,int n){
	if(n==0)return m;
	
	return gcd(n,m%n);
}

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

	int g = gcd(W,H);

	cout << W*H*C/(g*g) << endl;	

	return 0;
}


Measured memory_bytes: 3100
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s.size() == 3) reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static Scanner s = new Scanner(System.in);

	public static void main(String[] args) {

		while(true){
			char[] cards = s.next().toCharArray();

			if(cards[0] == '-'){
				return;
			}

			char[] temp = new char[cards.length];
			int m = s.nextInt();

			for(int i=1; i<=m; i++){
				int h = s.nextInt();

				for(int j=0; j<cards.length; j++){
					temp[j] = cards[(j+h)%cards.length];
				}

				for(int j=0; j<cards.length; j++){
					cards[j] = temp[j];
				}

			}

			System.out.println(cards);
		}
	}

}

Measured memory_bytes: 26240
chomp (my ($n, $m) = split / /, <STDIN>);
my @a;
for my $i (1..$m) {
  chomp (my $in = <STDIN>);
  $a[$i] = $in;
}
$a[0] = -1;
push @a, $n + 1;
my @b;
for my $i (1..$m+1) {
  if ($a[$i] - $a[$i - 1] == 1) {
    print "0\n";
    exit;
  }
  push @b, $a[$i] - $a[$i - 1] - 1;
}
my @memo;
$memo[1] = 1;
$memo[2] = 1;
for my $i (3..$n+1) {
  $memo[$i] = $memo[$i - 1] + $memo[$i - 2];
  $memo[$i] %= 1e9 + 7;
}
my $ans = 1;
for my $i (@b) {
  $ans *= $memo[$i];
  $ans %= 1e9 + 7;
}
print "$ans\n";

Measured memory_bytes: 10368
import copy

def main():
    h, w, k = map(int, input().split())
    c = [list(input()) for _ in range(h)]
    ans = solve(h, w, k, c)
    print(ans)

def solve(h, w, k, c):
    ans = 0
    for i in range(2 ** h):
        for j in range(2 ** w):
            cc = copy.deepcopy(c)
            for ii in range(h):
                if i >> ii & 1:
                    cc[ii] = ["!"] * w
            for jj in range(w):
                if j >> jj & 1:
                    for kk in range(h):
                        cc[kk][jj] = "!"
            tmp = [inner for outer in cc for inner in outer]
            if tmp.count('#') == k:
                ans += 1
    return ans

if __name__ == '__main__':
    main()

Measured memory_bytes: 9348
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
int main(){
  int n,maxh=0,ans=0;
  cin>>n;
  int h[105];
  for(int i=0;i<n;i++) {
    cin>>h[i];
    maxh=max(maxh,h[i]);
  }
  for(int i=1;i<=maxh;i++){
    int cnt=0;
    bool f=false;
    for(int j=0;j<n;j++){
      if(h[j]>=i){
        if(!f) cnt++;
        f=true;
      }
      else{
        f=false;
      }
    }
    ans+=cnt;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  as <- getIntList

  let countAs (a:as') m = let m' = case Map.lookup a m of
                                     Nothing -> Map.insert a (1::Int) m
                                     Just c  -> Map.insert a (c+1) m
                          in countAs as' m'
      countAs [] m = m

      h = Map.toList $ countAs as Map.empty

      ans = sum $ map (\(x, c) -> if c >= x then c - x else c) h

  print ans

Measured memory_bytes: 18812
/* kadai3_2
   reo012 */

#include<stdio.h>

int main(void){
  int num, base;
  // 整数numと進法baseを取得
  scanf("%d %d", &num, &base);

  // while文を用いて桁数digits計算。
  int digits = 0;
  while(1){
    num /= base;
    digits++;  // numをdigitsで割れたらdigitsを1足す
    if(num==0){ // 商が0になったらbreak
      break;
    }
  }
  printf("%d\n", digits);
  return 0;
}


Measured memory_bytes: 128
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val xx = readLine()!!.split(" ").map { it.toInt() }.sorted()

    var min = Int.MAX_VALUE
    for (i in xx.first()..xx.last()) {
        var sum = 0
        xx.forEach {
            sum += (it - i) * (it - i)
        }

        min = Math.min(sum, min)
    }

    println(min)
}

Measured memory_bytes: 36088
n = gets.chomp.to_i

f = []
n.times do
    f << gets.chomp.split(" ").join.to_i(2)
end

p = []
n.times do
    p << gets.chomp.split(" ").map(&:to_i)
end

ans = nil
for i in 1..1023
    sum = 0
    n.times do |j|
        k = (f[j] & i).to_s(2).split("").count{|i| i == "1"}
        sum += p[j][k]
    end
    ans = sum if ans == nil || ans < sum
end
puts ans



Measured memory_bytes: 2172
import sys
ptn = [18,48,6,30,20,34,16]

def f(D):
    i = 0
    s = 0
    D = D[D.index("1"):]
    for c in D:
        if c=="1": s += i
        i += 1
    p = "ABCDEFG"[ptn.index(s)]
    return p

i=0
D=""
for s in sys.stdin:
    if i<8:
        i+=1
        D+=s[:-1]
    else:
        print f(D)
        i=0
        D=""
print f(D)

Measured memory_bytes: 4224
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val xl = (0 until n).map { sc.next().toLong() to sc.next().toLong() }
    println(problem2020b(n, xl))
}

fun problem2020b(n: Int, xl: List<Pair<Long, Long>>): Int {
    val xl = xl.map { it.first - it.second to it.first + it.second } .sortedBy { it.second }
    var res = 0
    var cur = -Long.MAX_VALUE
    for (i in 0 until n) {
        if (cur > xl[i].first) continue
        res++
        cur = xl[i].second
    }
    return res
}

Measured memory_bytes: 98924
use std::io;
use std::io::BufRead;
use std::collections::VecDeque;

struct Graph {
    n: usize,
    adj: Vec<Vec<usize>>,
}

fn read_graph() -> Graph {
    let stdin = io::stdin();
    let lock = stdin.lock();
    let mut lines = lock.lines();
    let n = lines.next().unwrap().unwrap().parse().unwrap();
    let mut adj = Vec::new();

    for line in lines {
        let parsed: Vec<usize> = line
            .unwrap()
            .split_whitespace()
            .map(|s| s.parse().unwrap())
            .collect();

        adj.push(parsed[2..].iter().map(|x| x - 1).collect());
    }

    Graph { n, adj }
}

fn main() {
    let graph = read_graph();

    let mut d = vec![-1; graph.n];
    let mut q = VecDeque::new();

    d[0] = 0;
    q.push_back(0);

    while let Some(i) = q.pop_front() {
        for &j in graph.adj[i].iter() {
            if d[j] < 0 {
                d[j] = d[i] + 1;
                q.push_back(j);
            }
        }
    }

    for i in 0..(graph.n) {
        println!("{} {}", i + 1, d[i]);
    }
}



Measured memory_bytes: 5032
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;



int main()
{
	int A, B;
	double T;
	cin >> A >> B >> T;
	
	double time = 0;
	int biscuit = 0;
	while(time <= T + 0.5){
		time += A;
		biscuit += B;
		
	}
	
	cout << biscuit - B << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define M 1000000007
#define N 200016

unsigned long ulget();
inline unsigned long ulget()
{
    register unsigned long t = 0;
    register char c;
    while((c = getchar() - '0') >= 0)
    {
        t = t * 10 + c;
    }
    return t;
}

unsigned int colorlastdp[N];
int main()
{
    unsigned int dp[N];
    unsigned int n = ulget();
    dp[0] = 0; dp[1] = 1;
    unsigned int color, lastcolor = 0;
    for (register unsigned int i = 1; i <= n; i++)
    {
        color = ulget();
        if (color != lastcolor)
            dp[i] = (dp[i] + colorlastdp[color]) % M;
        colorlastdp[color] = dp[i];
        dp[i+1] = dp[i];
        lastcolor = color;
        //printf("%d %d %d\n", i, color, dp[i]);
    }
    printf("%u", dp[n]);
}


Measured memory_bytes: 3164
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        a: i64,
        b: String,
    }
    let mut b = b;
    b.retain(|c| c != '.');
    println!("{}", a * b.parse::<i64>().unwrap() / 100);
}

Measured memory_bytes: 2132
import sys
from collections import Counter


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n = _i()
    ai = Counter(_ia())
    s = sum(k * v for k, v in ai.items())
    q = _i()
    for _ in range(q):
        b, c = _ia()
        m = ai.get(b, 0)
        s += (c-b) * m
        ai[b] = 0
        ai[c] += m
        print(s)


if __name__ == "__main__":
    main()


Measured memory_bytes: 88248
#include <stdio.h>
#include <math.h>
typedef long long Int;
int main() {
	Int S;
	scanf("%lld",&S);
	Int s = (Int)(ceill(sqrtl((long double)S)));
	Int a = s;
	Int d = s;
	Int c = 1;
	Int b = a*d-S;
	printf("0 0 %lld %lld %lld %lld",a,b,c,d);
}

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

int main(){
  string cards[3];
  int cnt[3] = {0, 0, 0};
  
  for(int i = 0; i < 3; i++){
    cin >> cards[i];
  }
  
  int turn = 0;
  
  while(1){
    if(cnt[turn] == cards[turn].size()) break;
    cnt[turn]++;
    turn = cards[turn][cnt[turn]-1] - 'a';
  }

  cout << (char)('A' + turn) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int p=0,i=0,j,k,b=1;
  
  while(s[i]!='.') p=p*10+s[i]-'0',i++;
  i++;
  while(i<s.size()&&s[i]!='(') {
    b*=10;
    p=p*10+s[i]-'0';
    i++;
  }
  if(s[i]=='('){
    i++;j=0;k=0;
    while(s[i]!=')') {
      k=k*10+9;
      j=j*10+s[i]-'0';
      i++;
    }
    b*=k;
    p=p*k+j;
  }
  cout << p/__gcd(p,b) << "/" <<  b/__gcd(p,b) << endl;
  return 0;
}

Measured memory_bytes: 3184
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


signed main()
{
	fio
	inp(n)
	inpa(a,n)
	inpa(b,n)
	int ans=0;
	priority_queue<pair<int,int>> pq;
	fo(i,n)
	{
		if(a[i]!=b[i])
			pq.push({b[i],i});
	}
	while(pq.size())
	{
		int val=pq.top().F;
		int ind=pq.top().S;
		pq.pop();
		if(val<a[ind])
		{
			cout<<-1<<'\n';
			return 0;
		}
		int x=(val-a[ind])/(b[(ind-1+n)%n]+b[(ind+1)%n]);
		if(x==0)
		{
			cout<<-1<<'\n';
			return 0;
		}
		ans+=x;
		b[ind]-=x*((b[(ind-1+n)%n]+b[(ind+1)%n]));
		if(b[ind]!=a[ind])
			pq.push({b[ind],ind});
	}
	cout<<ans<<'\n';
	printclock;
}

Measured memory_bytes: 9456
import math
import itertools
import statistics
#import numpy as np
import collections

#n = int(input())
#n, l = list(map(int, input().split()))
#a = list(map(int, input().split()))
s = input()
ans = ""
for i in range(len(s)):
    if s[i]=="0":
        ans += "0"
    elif s[i]=="1":
        ans += "1"
    else:
        if ans!="":
            ans = ans[0:-1]

print(ans)
            


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;

int main(){
    
    int N,ans=0;cin>>N;
    vector<ll> S(N),T;
    map<ll,int> M;
    for(int i=0;i<N;i++){
        ll a;cin>>a;
        M[a]++;
        S[i]=a;
    }
    
    ll a=1;
    while(a<=2000000000){
        a*=2;
        T.push_back(a);
    }
    
    sort(all(S));
    
    for(int i=N-1;i>=0;i--){
        ll diff;
        for(int j=0;j<T.size();j++){
            if(T[j]>S[i]){
                diff=T[j]-S[i];
                break;
            }
        }
        if(diff==S[i]){
            if(M[S[i]]>=2){
                ans++;
                M[S[i]]-=2;
            }
        }else{
            if(M[S[i]]>=1&&M[diff]>=1){
                ans++;
                M[S[i]]--;
                M[diff]--;
            }
        }
    }
    
    cout<<ans<<endl;
    
}


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

int N;

long long twoPointers (vector<int> a, long long x) {
  int r = 0;
  long long sum = 0;
  long long ans = 0;

  for (int l = 0; l < N; l++) {
    while (sum <= x) {
      if (r == N) {
        break;
      } else {
        if (sum + a[r] > x) {
          break;
        }
        sum += a[r];
        r++;
      }
    }
    sum -= a[l];
    ans += r - l;
  }
  return ans;
};

int main() {
  int Q;
  cin >> N >> Q;
  vector<int> a(N);
  vector<long long> x(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < Q; i++) {
    cin >> x[i];
  }

  for (int i = 0; i < Q; i++) {
    long long ans = twoPointers(a, x[i]);
    cout << ans << endl;
  }
};



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

using namespace std;

int n, a;
float total = 0;

int main () {

    cin >> n;
    for  (int i = 1; i <= n; i++){
        cin >> a;
        total += 1.0 / a;
    }

    cout << 1 / total << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cfenv>
#include <cmath>
#include <string>

using namespace std;

int main(){
  string s, t, u;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  cin >> u;
  if(s == u) a = a-1;
  else b = b-1;
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 384
fn main(){
	loop{
		let v = read_vec::<String>();
		if &(v[1]) == "?" { break; }
		
		let op = get_fn(&(v[1]));
		let (a, b) = (v[0].parse::<i32>().unwrap(), v[2].parse::<i32>().unwrap());
		println!("{}", op(a, b))
	}
}

fn get_fn(op : &str) -> Box<Fn(i32, i32) -> i32> {
	match op {
		"+" => Box::new(move |x, y| x + y),
		"-" => Box::new(move |x, y| x - y),
		"*" => Box::new(move |x, y| x * y),
		"/" => Box::new(move |x, y| x / y),
		_   => panic!("Invalid Operator"),
	}
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


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

int main() {
    int N; cin >> N;
    int M = (N * (N - 2) + 1) / 2;

    cout << M << endl;
    for (int i = 1; i <= N - 1; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (i + j != ((N & 1) ? N : N + 1))
                cout << i << " " << j << endl;
        }
    }
}

Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
ll mod=1e9+7;
ll facctorialMethod(ll k,ll m){
   ll sum = 1;
   if(k==0) return 1;
   for (int i = m+1; i <= k; ++i)
   {
       sum *= i;
       sum%=mod;
   }
   return sum;
}

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

    ll n,m;
    cin>>n>>m;
    if(abs(n-m)>=2){cout<<0<<endl;return 0;}
    if(n==m){cout<<2*facctorialMethod(n,1)*facctorialMethod(m,1)%mod<<endl;return 0;}
    else{
        cout<<facctorialMethod(n,1)*facctorialMethod(m,1)%mod<<endl;
        return 0;
    }
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define LL long long
using namespace std;
LL a,b;
int k;
int main()
{
    scanf("%lld%lld%d",&a,&b,&k);
    if(b-a+1<=k*2){
        for(LL i=a;i<=b;i++){
            printf("%lld\n",i);
        }
    }
    else{
        for(LL i=a;i<a+k;i++){
            printf("%lld\n",i);
        }
        for(LL i=b-k+1;i<=b;i++){
            printf("%lld\n",i);
        }
    }
    return 0;
}


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

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  cout << z << ' ' << x << ' ' << y << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, a, m = 1e9+7;
long long ans;
bool odd;

int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a);
        odd ^= a <= 0;
        ans += abs(a);
        m = min(m, abs(a));
    }
    if(odd) ans -= m*2;
    printf("%lld\n", ans);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
    	cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}


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

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

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

    bool can = true;
    for (auto &&x : a)
    {
        if (x % 2 == 0)
        {
            if (x % 3 && x % 5)
                can = false;
        }
    }

    cout << (can ? "APPROVED" : "DENIED") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9+5
int dp[100001][3];
vector<vector<int > >v;
int solve(int n,int current)
{
    if(n<0)
        return 0;
    int answer=-(INF);

    if(dp[n][current]!=-1)
        return dp[n][current];

    for(int i=0;i<3;i++)
    if(current!=i)
        answer=max(answer,solve(n-1,i)+v[n][i]);
    return dp[n][current]=answer;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;

        vector<int >temp;
        temp.push_back(x);
        temp.push_back(y);
        temp.push_back(z);
        v.push_back(temp);
    }
    memset(dp,-1,sizeof(dp));
    int answer=max(solve(n-1,0),max(solve(n-1,1),solve(n-1,2)));
    cout<<answer<<endl;
    return 0;
}


Measured memory_bytes: 15408
def solve():
    a, b, c = map(int, input().split())
    k = int(input())
    while a >= b and k > 0:
        b *= 2
        k -= 1

    if a >= b:
        print("No")
        exit()

    d = c * 2 ** k
    #print(a,b,c,d,k)
    if d > b:
        print("Yes")
    else:
        print("No")


solve()


Measured memory_bytes: 9100
s = input()
k = int(input())

if len(s) == 1:
    print(s[0])
    exit()

if k == 1:
    print(s[0])
else:
    i = 1
    while i <= k:
        if s[i-1] != '1':
            print(s[i-1])
            break
        elif i == k:
            print(s[i-1])
            break
        i += 1


Measured memory_bytes: 3060
N, K=map(int, input().split())
A=list(map(int, input().split()))
for i in range(K):
  p=[0]*N
  n=[0]*N
  for i in range(N):
    if i-A[i]>0:
      p[i-A[i]]+=1
    else:
      p[0]+=1
    if i+A[i]<N-1:
      n[i+A[i]+1]+=1
  light=0
  Ncount=0
  for i in range(N):
    light=light+p[i]-n[i]
    A[i]=light
    if light==N:
      Ncount+=1
  if Ncount==N:
    out=[N]*N
    print(*out, sep=' ')
    exit()
print(*A, sep=' ')

Measured memory_bytes: 169784
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


#n,a = [int(i) for i in read().split()]
s =input()

if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 2940
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
long long dp[2][200000] = {};
int visited[2][200000] = {};
vector<tuple<long long, long long, long long>> vertexs[200000];
int main() {
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	for (int i = 0; i < m; ++i) {
		long long a, b, c, d;
		cin >> a >> b >> c >> d;
		vertexs[a].push_back(make_tuple(b, c, d));
		vertexs[b].push_back(make_tuple(a, c, d));
	}
	for (int i = 0; i < 200000; ++i) {
		dp[0][i] = LONG_INF;
		dp[1][i] = LONG_INF;
	}
	priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> next;
	next.push(make_pair(0, s));
	dp[0][s] = 0;
	while (next.empty() == false) {
		int now = next.top().second;
		next.pop();
		if (visited[0][now] == 0) {
			visited[0][now] = 1;
			for (int i = 0; i < vertexs[now].size(); ++i) {
				if (dp[0][get<0>(vertexs[now][i])] > dp[0][now] + get<1>(vertexs[now][i])) {
					dp[0][get<0>(vertexs[now][i])] = dp[0][now] + get<1>(vertexs[now][i]);
					next.push(make_pair(dp[0][get<0>(vertexs[now][i])], get<0>(vertexs[now][i])));
				}
			}
		}
	}
	next.push(make_pair(0, t));
	dp[1][t] = 0;
	while (next.empty() == false) {
		int now = next.top().second;
		next.pop();
		if (visited[1][now] == 0) {
			visited[1][now] = 1;
			for (int i = 0; i < vertexs[now].size(); ++i) {
				if (dp[1][get<0>(vertexs[now][i])] > dp[1][now] + get<2>(vertexs[now][i])) {
					dp[1][get<0>(vertexs[now][i])] = dp[1][now] + get<2>(vertexs[now][i]);
					next.push(make_pair(dp[1][get<0>(vertexs[now][i])], get<0>(vertexs[now][i])));
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		next.push(make_pair(dp[0][i] + dp[1][i], i));
	}
	for (int i = 0; i < n; ++i) {
		while (next.top().second <= i) {
			next.pop();
		}
		cout << 1000000000000000LL - next.top().first << endl;
	}
	return 0;
}

Measured memory_bytes: 19440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int x, a, b; cin >> x >> a >> b;
    if (abs(x - a) < abs(x - b)) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }
    return 0;
}

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  vector<char> s(n);
  for(int i=0;i<n;i++)
    cin >> s.at(i);
  
  int c=0;//A+B
  int d=0;//B
  
  for(int i=0;i<n;i++){
    
    if(s.at(i)=='a'){
      if(c<a+b){
        cout << "Yes" << endl;
        c++;
      }
      else
        cout << "No" << endl;
    }
      
    else if(s.at(i)=='b'){
      if(c<a+b&&d<b){
        cout << "Yes" << endl;
        c++;
        d++;
      }
      else
        cout << "No" << endl;
    }
      
    else{
      cout << "No" << endl;
    }
      
  }
  
}

Measured memory_bytes: 768
import itertools
H,W,K=map(int,input().split())
 
C=[]
 
for i in range(H):
  C.append(input())
 
ans=0
for i in range(H+1):
  for j in range(W+1):
    for n in itertools.combinations(list(range(H)),i):
      for m in itertools.combinations(list(range(W)),j):
        count = 0
        for a in n:
          for b in m:
            if(C[a][b]=="#"):
                count+=1
        if(count == K):
          ans += 1
print(ans)

Measured memory_bytes: 74192
#include<bits/stdc++.h>
using namespace std;
long long nc2(long long n){
    return n*(n-1)/2;
}

int main(){
    int n;cin>>n;
    map<int,int>m;
    vector<int> v;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        v.push_back(a);
        m[a]++;
    }
    long long y=0;
    for(map<int,int>::iterator itr=m.begin();itr != m.end();itr++){
        y+=nc2((*itr).second);
    }
    for(int i=0;i<n;i++){
        cout<<y-(m[v[i]]-1)<<endl;
    }

}

Measured memory_bytes: 9204
mod = 10**9+7
n = int(input())
s = input()
d = {}
for i in s:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
result = 1
for i, j in d.items():
    result = (result*(j+1))%mod

print((result-1)%mod)

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void) {
	char s[200001];
	int ind1,ind2,i,j,max=0,length;
	scanf("%s",s);
	length = strlen(s);
	for (i = 0; length > i; i++) {
		if (s[i] == 'A') {
			ind1 = i;
			for (j = length-1;  j >=0; j--) {
				if (s[j] == 'Z') {
					ind2 = j + 1;
					max = ind2 - ind1;
					break;
				}		
			}
			break;
		}	
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

string s;

signed main() {
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

int N;
string S1,S2;

LL ans = 1;

void solve(){
	const int STARTING = -1;
	const int HORIZONTAL = 0;
	const int VERTICAL = 1;
	int prev_state = STARTING;
	int state = STARTING;
	int index = 0;
	while(index<N){
		if(S1[index]==S2[index]){
			state = VERTICAL;
			index++;
		}else{
			state = HORIZONTAL;
			index += 2;
		}

		if(prev_state==STARTING){
			if(state==HORIZONTAL){
				ans *= 6LL;
				ans %= mod;
			}else{
				ans *= 3LL;
				ans %= mod;
			}
		}else{
			if(prev_state==VERTICAL && state==HORIZONTAL){
				ans *= 2LL;
				ans %= mod;
			}else if(prev_state==VERTICAL && state==VERTICAL){
				ans *= 2LL;
				ans %= mod;
			}else if(prev_state==HORIZONTAL && state==HORIZONTAL){
				ans *= 3LL;
				ans %= mod;
			}
		}
		prev_state = state;
	}
}
 
int main(){
    cin >> N;
    cin >> S1;
    cin >> S2;
 
    solve();

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
#include<string>
#include<vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;

ll calc_pow(ll x, ll y) {
    ll z = 1;
    while (y > 0) {
        if (y & 1) {
            z = (z * x) % MOD;
        }
        x = (x * x) % MOD;
        y /= 2;
    }
    return z;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];
    ll ans = 0;
    rep(i, 0, N) {
        ll prev = 0, tail = 0;
        rep(j, 0, i) {
            if (A[i] < A[j]) prev++;
        }
        rep(j, i, N) {
            if (A[i] < A[j]) tail++;
        }
        ll sum = (K * ((2 * prev) % MOD + ((K - 1) * (prev + tail)) % MOD)) % MOD;
        sum = (sum * calc_pow(2, MOD - 2)) % MOD;
        ans = (ans + sum) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){

 int h, w, i, j;

 while(1) {
  cin >> h >> w;

  if ((h == 0) && (w == 0)) break;

  for (i = h; i > 0; i--) {
   for (j = w; j > 0; j--) {
    if (i == h || i == 1) cout << "#";
    else if (j == w || j == 1) cout << "#";
    else cout << ".";
   }
   cout << endl;
  }
  cout << endl;
 }

 return 0;
}

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

int main() {
  ll n;
  cin >> n;
  vector<tuple<string, ll, ll>> s;
  for (ll i = 0; i < n; i++) {
    string a;
    ll p;
    cin >> a >> p;
    s.push_back(make_tuple(a, p * -1, i + 1));
  }

  sort(s.begin(), s.end());

  for (int i = 0; i < n; i++) {
    cout << get<2>(s[i]) << endl;
  }
}

Measured memory_bytes: 256
parseInt(x) = parse(Int,x)

parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
#readline() |> split |> parseMap
function main()
    N = parseInt(readline()) 
    K = parseInt(readline())
    X = parseInt(readline())
    Y = parseInt(readline())
	A = min(K,N)
	B = max(N-K,0)
    println(X*A+Y*B)
end

main()


Measured memory_bytes: 112288
#include<bits/stdc++.h>
using namespace std;
 
signed main(){
int a;
int c[100];
while(cin>>a){
    for(int b=0;b<a;b++)cin>>c[b];
    sort(c,c+a);
    int s=0;
    for(int d=0;d<a;d++){
	s+=(a-d)*c[d];
	}
	printf("%d\n",s);
    }
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1<<29;
using Graph = vector<vector<int>>;
int main() {
    int N,K; cin >> N >> K;
    int res = 0;
    vector<int> B(N,0);
    for (int i=0;i<K;++i){
        int d; cin >> d;
        for (int j=0;j<d;++j){
            int A; cin >> A; --A;
            B[A]++;
        }
    }
    for (int i=0;i<N;++i) if (B[i]==0) res++;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
# define ll long long
# define ld long double
# define pb push_back
#define F first
#define S second
#define vi vector <int>
#define vl vector <ll>
 
// #define loop(i,n) for(int i=0;i<n;i++)
// #define loops(i,s,n) for(int i=s;i<=n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
 
  
    // for(int i=0;i<n;i++){  
        
    //     int x,y;
    //     cin>>x>>y;
        
    //     v.pb({x,y});         //make pair in vector
    // }
 
using namespace std;
 
#define P 1000000007
priority_queue<int, vector<int>, greater<int> > Q;
 
const int INF= 1e9+9;
int main()
{ string s,t;
 cin>>s>>t;
 bool flag=true;
 for(int i=0;i<s.length();i++)
 { if(s[i]!=t[i])
 { flag=false;
   break;} }
  
  if(flag)
  {cout<<"Yes"<<"\n";}
  else
  {cout<<"No"<<"\n";}
 
 
 
	
} 

Measured memory_bytes: 3624
N = int(input())
ans = [0 for i in range(N)]

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            tmp = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if tmp > N:
                break
            ans[tmp - 1] += 1

[print(i) for i in ans]


Measured memory_bytes: 9236
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private int N;
    private int Ma;
    private int Mb;
    private int[] a;
    private int[] b;
    private int[] c;

    private Map<String, Integer> memo = new HashMap<>();

    private void solve(Scanner sc) {
        N = sc.nextInt();
        Ma = sc.nextInt();
        Mb = sc.nextInt();
        a = new int[N];
        b = new int[N];
        c = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        int r = calc(0, 0, 0);
        if (r == Integer.MAX_VALUE) {
            _out.println(-1);
        } else {
            _out.println(r);
        }
    }
    private int calc(int d, int ma, int mb) {
        String key = d + "/" + ma + "/" + mb;
        if (memo.containsKey(key)) {
            return memo.get(key);
        }
        if (d >= N) {
            if (d == N && ma > 0 && mb > 0 && ma % Ma == 0 && mb % Mb == 0 && ma / Ma == mb / Mb) {
                return 0;
            }
            return Integer.MAX_VALUE;
        }

        int r1 = calc(d + 1, ma, mb);
        int r2 = calc(d + 1, ma + a[d], mb + b[d]);
        if (r2 != Integer.MAX_VALUE) {
            r2 = r2 + c[d];
        }
        int r = Math.min(r1, r2);
        memo.put(key, r);
        return r;
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 85196
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> n_comment(n,0);
    vector<vector<pair<int,int>>> comment(n,vector<pair<int,int>>());
    rep(i,n) {
        cin>>n_comment[i];
        rep(j,n_comment[i]) {
            int x,y;cin>>x>>y;
            x--;
            comment[i].emplace_back(x,y);
        }
    }
    int lim = (1<<n);
    int res = 0;
    rep(i,lim) {
        int n_honest = __builtin_popcount(i);
        bool flg = true;
        rep(j,n) {
            if (!(i>>j&1)) {
                continue;
            }
            for (auto x: comment[j]) {
                flg &= ((i>>x.first&1) == x.second);
            }
        }
        if (flg) {
            chmax(res, n_honest);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

ll lcm(ll a,ll b){
	ll g = __gcd(a,b);
	return (a / g) * b;
}

int main(){
	ll n,m;
	cin >> n>>m;
	vector<ll> a(n);

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

	ll x = a[0]/2LL;
	ll c = 0LL;
	while(x % 2LL == 0LL){
		x /= 2LL;
		c++;
	}
	bool flag = false;
	for(int i = 1; i < a.size(); i++) {
		ll x = a[i]/2LL;
		ll counter = 0LL;
		while(x % 2LL == 0LL){
			x /= 2LL;
			counter++;
		}
		if (c != counter){
			flag = true;
			break;
		}
	}
	ll l = a[0]/2LL;
	if (!(flag)){
		
		for(int i = 1; i < a.size(); i++) {
			l = lcm(l,a[i] / 2LL);
		}
	}

	if (!(flag)){
		ll i = 0LL;
		while(l * (2LL * i + 1LL) <= m && l * (2LL * i + 1LL) >= 1LL){
			i++;
		}
		cout << i << endl;
	}
	else{
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 1024