akhauriyash/Code-Regression huggingface dataset:
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

C1 = input()
C2 = input()

flag = True
for i in range(3):
    if (C1[i] != C2[2 - i]):
        flag = False
if flag:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 27084
#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>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc060/tasks/abc060_b

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

    for (int i = 1; i <= a*b; i++) if (a*i % b == c){
            cout << "YES" << endl;
            return 0;
    }

    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
// C - Modulo Summation
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll in(){ll x;cin>>x;return x;}

int main(){
	int N; cin>>N;
	ll ans = 0; while(N--) ans += in() - 1;
	cout<< ans <<endl;
}

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

// v ÍpYÌóÔ, pos Í 0(ó) ÌÊu, cnt Íè
struct state{
	vector<int> v;
	int pos, cnt;
};

// m[v] ÍpYÌóÔ v ©çÌÅZèðÔ·
map<vector<int>,int> m;
 
int solve(){
	queue<state> q;
	state ini;
	vector<int> v(8);
	for(int i=0 ; i < 8 ; i++ ){
		v[i] = i;
	}
	ini.v = v;
	ini.cnt = 0;
	ini.pos = 0;
	q.push( ini );
	m[v] = 0;
	
	while( !q.empty() ){
		state s = q.front(); q.pop();
		
		if( s.pos < 4 ){ // ãÉ®©·
			state next = s;
			swap( next.v[ next.pos ] , next.v[ next.pos+4 ] );
			next.pos += 4;
			next.cnt = s.cnt + 1;
			if( m.count(next.v) == 0 ){
				m[next.v] = next.cnt;
				q.push( next );
			}
		}else{ // ºÉ®©·
			state next = s;
			swap( next.v[ next.pos ] , next.v[ next.pos-4 ] );
			next.pos -= 4;
			next.cnt = s.cnt + 1;
			if( m.count(next.v) == 0 ){
				m[next.v] = next.cnt;
				q.push( next );
			}
		}
		// ¶É®©·
		if( s.pos % 4 != 0 ){
			state next = s;
			swap( next.v[ next.pos ] , next.v[ next.pos-1 ] );
			next.pos -= 1;
			next.cnt = s.cnt + 1;
			if( m.count(next.v) == 0 ){
				m[next.v] = next.cnt;
				q.push( next );
			}
		}
		// EÉ®©·
		if( s.pos % 4 != 3 ){
			state next = s;
			swap( next.v[ next.pos ] , next.v[ next.pos+1 ] );
			next.pos += 1;
			next.cnt = s.cnt + 1;
			if( m.count(next.v) == 0 ){
				m[next.v] = next.cnt;
				q.push( next );
			}
		}
	}
}

int main(){
	int e;
	solve();
	
	while( cin >> e ){
		vector<int> v(8);
		v[0] = e;
		for(int i = 1 ; i < 8 ; i++ ){
			cin >> v[i];
		}
		cout << m[v] << endl;
	}
}

Measured memory_bytes: 2400
import itertools as ite
import math

INF = 10 ** 18
N, M = map(int, raw_input().split())
m = map(int, raw_input().split()) + [N + 1]
Q = input()
l = map(int, raw_input().split())
cost = [0] * (N + 1)
for i in range(M):
    cost[m[i + 1] - m[i] - 1] += 1
cost[N] += m[0] - 1
grad = 0
for i in range(N)[::-1]:
    grad += cost[i]
    cost[i] = cost[i + 1] + grad
dic = {}
S = 10 ** 5 + 1
for i in range(1, N + 1):
    if S != cost[i]:
        for j in range(cost[i], S):
            dic[j] = i
        S = cost[i]
for num in l:
    if not num in dic:
        print -1
    else:
        print dic[num]



Measured memory_bytes: 28640
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  int rnum = 0;
  for(int i=0;i<N;++i) {
    if(S[i]=='R') rnum++;
  }
  int ans = 0;
  for(int i=0;i<rnum;++i) {
    if(S[i]=='W') ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;


int N,M;
vector<vector<int>> to;
int ans = 0;
int f = 0;

vector<bool> com;

void dfs(int u, int v, int a, int b){
    
    for (int i : to[u]) {
        
        if(i == v) continue;
        if(u == a && i == b) continue;
        
        if(u != a && i == b){
            f++;
            return;
        }
        if(!com[i]){
            com[i] = true;
            dfs(i,u,a,b);
        }
    }
    
}



int main()
{

    cin >> N >> M;
    to.resize(N);
    vector<int> A(M),B(M);
    
    rep(i,M){
        int a,b;
        cin >> a >> b;
        a--,b--;
        to[a].push_back(b);
        to[b].push_back(a);
        A[i] = a,B[i] = b;
    }
    rep(i,M){
        com.assign(N,false);
        com[A[i]] = true;
        com[B[i]] = true;
        f = 0;
        dfs(A[i],-1,A[i],B[i]);
        if(f == 0) ans++;
    }
    int k = 0;
    rep(i,N) if(to[i].size() == 0) k++;
    cout << ans+k << endl;
    
    
    return 0;
}



Measured memory_bytes: 256
if __name__ == '__main__':
    N, W = map(int,input().split(" "))
    w,v = [0]*(N+1),[0]*(N+1)
    for i in range(N):
        w[i+1],v[i+1] = map(int,input().split(" "))

    V = sum(v)
    dp = [ [float('inf')]*(V+1) for _ in range(N+1) ]
    for i in range(N+1):
        dp[i][0] = 0

    for i in range(1,N+1):
        for j in range(1,V+1):
            if j >= v[i]:
                dp[i][j] = min([dp[i][j],dp[i-1][j],dp[i-1][j-v[i]] + w[i]])
            else:
                dp[i][j] = min([dp[i][j],dp[i-1][j]])

    for j in range(V,-1,-1):
        if dp[N][j] <= W:
            print(j)
            break



Measured memory_bytes: 405048
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n, k = map(int, readline().split())
r, s, p = map(int, readline().split())
t = read().rstrip().decode("utf-8")

hands = ['r', 's', 'p']

points = {}

player = {}
player['r'] = 'p'
player['s'] = 'r'
player['p'] = 's'
points['p'] = p
points['r'] = r
points['s'] = s

ans = 0

for i in range(k):
    t_ = t[i::k] + '.'
    myhand = ['.'] * len(t_)
    for i in range(len(t_) - 1):
        c = t_[i]
        if i < 1:
            ans += points[player[c]]
            myhand[i] = player[c]
        elif player[c] != myhand[i-1]:
            ans += points[player[c]]
            myhand[i] = player[c]
        else:
            myhand[i] = set(hands) and not player[c] and player[t_[i+1]]

print(ans)

Measured memory_bytes: 4084
def main():
    n, k = map(int, input().split())
    if n - k > k:
        n_k = (n-k) // k
        minv = n - k * n_k
    else:
        minv = n

    def min_x(x):
        minv = x
        for _ in range(2):
            if abs(minv - k) < abs(minv):
                minv = abs(minv - k)
            else:
                print(minv)
                exit()
        print(minv)

    min_x(minv)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    vector<tuple<int, int, char, i64, string>> as;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b;
        char c;
        i64 d;
        string e;
        cin >> a >> b >> c >> d >> e;
        as.emplace_back(a, b, c, d, e);
    }
    sort(as.begin(), as.end());

    for (int i = 0; i < n; i++) {
        cout << get<0>(as[i]) << " " << get<1>(as[i]) << " " << get<2>(as[i]) << " " << get<3>(as[i]) << " " << get<4>(as[i]) << endl;
    }
}


Measured memory_bytes: 12316
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int result[15][9];
int able[9][4];
char t;

int solve(int battery, char room, int dst)
{
	if(able[room-'A'][dst]){
		if(dst == 0)      room -= 3;
		else if(dst == 1) ++room;
		else if(dst == 2) room += 3;
		else              --room;
	}
	
	--battery;
	if(battery == 0){
		return room == t;
	}else{
		if(result[battery][room-'A'] != -1)
			return result[battery][room-'A'];
		
		result[battery][room-'A'] = 0;
		for(int i=0 ; i<4 ; ++i)
			result[battery][room-'A'] += solve(battery, room, i);
		
		return result[battery][room-'A'];
	}
}

int main()
{
	int n;
	char s;
	
	while(scanf("%d", &n), n){
		char b;
		scanf(" %c %c %c", &s, &t, &b);
		
		for(int i=0 ; i<9 ; ++i){
			for(int j=0 ; j<4 ; ++j)
				able[i][j] = 1;
			
			if(i<3)    able[i][0] = 0;
			if(i>5)    able[i][2] = 0;
			if(i%3==0) able[i][3] = 0;
			if(i%3==2) able[i][1] = 0;
		}
		
		b -= 'A';
		if(b>=3)   able[b-3][2] = 0;
		if(b<=5)   able[b+3][0] = 0;
		if(b%3!=0) able[b-1][1] = 0;
		if(b%3!=2) able[b+1][3] = 0;
		
		for(int i=0 ; i<15 ; ++i){
			for(int j=0 ; j<9 ; ++j)
				result[i][j] = -1;
		}
		
		int acc = 0;;
		for(int i=0 ; i<4 ; ++i)
			acc += solve(n, s, i);
		
		printf("%lf\n", acc/pow(4.0, n));
	}
	return 0;
}

Measured memory_bytes: 0
package main

import (
	"fmt"
)

func main() {
	var a, b, v, w, t int
	fmt.Scanf("%d %d", &a, &v)
	fmt.Scanf("%d %d", &b, &w)
	fmt.Scanf("%d", &t)

	// 逃げが鬼より小さい座標にいるとき、初期座標を交換する(今回は追いつくかどうかだけの判定なので)
	if b < a {
		tmp := a
		a = b
		b = tmp
	}

	if a+v*t >= b+w*t {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1820
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define tam 300000
#define offset 
const ll MOD= 1e9+7;



#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);

struct debug {
    ~debug() { cerr << endl; }
    
    //     Part 1
    
    template < class c > typename \
    enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
        cerr << boolalpha << i;
        return * this;
    }
    
    //     Part 2
    
    template < class c > typename \
    enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
        return * this << range(begin(i), end(i)); 
    }
    
    //   Part 3
    
    template < class c, class b > debug & operator << (pair < b, c > d) {
        return * this << "(" << d.first << ", " << d.second << ")";
    }
    
    //   Part 4
    
    template < class c > debug & operator <<(rge<c> d) {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
            *this << ", " + 2 * (it == d.b) << *it;
        return * this << "]";
    }
    
};
#define qwer(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int s,w;
    cin>>s>>w;
    if (w>=s)
        cout<<"unsafe\n";
    else
        cout<<"safe\n";
    

}
// PLUS ULTRA!
    

Measured memory_bytes: 3632
a = input().split(' ')
h1 = int(a[0])
h2 = int(a[1])
h3 = int(a[2])
 
if h1 < h3 and h3 < h2:
  print('Yes')
else:
  if h2 < h3 and h3 < h1:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 2940
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

string s;
vector< string > ans;
int cnt;

bool f;
void encode(string now, char c) {
    if(c == 'z' + 1) {
        if(now == s.substr(0, now.size())) f = true;
        return;
    }
    bool rep = true;
    for(int i = 0; i < now.size(); i++) {
        if(now[i] == c) {
            now[i] = c - 1;
            if(now[i] == s[i]) encode(now, c + 1);
            now[i] = c;
            rep = false;
            break;
        }
    }
    if(rep) encode(now, c + 1);
}

void rec(string now) {

    f = false;
    encode(now, 'b');
    if(!f) return;

    if(now.size() == s.size()) {
        cnt++;
        ans.push_back(now);
        if(ans.size() > 10) ans.erase(ans.begin() + 5);
        return;
    }

    char r = s[now.size()];
    rec(now + r);
    if(s[now.size()] != 'z') rec(now + (char)(r + 1));
}

int main() {

    while(cin >> s, s != "#") {
        cnt = 0;
        rec("");
        cout << cnt << endl;
        for(int i = 0; i < ans.size(); i++) {
            cout << ans[i] << endl;
        }
        ans.clear();
    }
}

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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int t = 1;
		while (t-->0) {
		    String s = sc.nextLine();
		    boolean ok = (s.charAt(2)==s.charAt(3) && s.charAt(4)==s.charAt(5));
		    System.out.println((ok?"Yes":"No"));
		}
	}
	static ArrayList<Integer> key;
	static int n1;
	static void insert(int key1){
		key.add(key1);
		n1++;
		swim(n1);
	}
	static void swim(int k){
		while (k>1 && less(k/2, k)) {
			swap(k/2, k);
			k/=2;
		}
	}
	static int deleteMax(){
		int max = key.get(1);
		key.set(1,key.get(n1--));
		sink(1);
		key.remove(n1+1);
		return max;
	}
	static void sink(int k){
		while (2*k<=n1) {
			int j = 2*k;
			if (j<n1 && less(j,j+1)) {
				j++;
			}
			if (!less(k, j)) {
				break;
			}
			swap(k,j);
			k=j;
		}
	}
	static boolean less(int a, int b){
		return key.get(a)<key.get(b);
	}
	static void swap(int a, int b){
		int c=key.get(a);
		key.set(a,key.get(b));
		key.set(b,c);
	}
	static String getit(String s, String b){
	    StringBuilder temp=new StringBuilder(" ");
        temp.append(s);
        temp.append("#");
        temp.append(b);
	    int n = temp.length()-1;
	    String p = temp.toString();
	    int[] pi = new int[n+1];
	    pi[0] = -1;
	    int k = -1;
	    for (int i=1;i<=n ;i++ ){
	        while(k>=0 && p.charAt(k+1)!=p.charAt(i)) k = pi[k];
	        pi[i] = ++k;
	    } 
	    return s.substring(1,pi[n]);
	}
	static class Query {
		int x1, x2, y, id;
		public Query(int c, int d, int e, int a){
			x1 = c;
			x2 = d;
			y = e;
			id = a;
		}
	}
	static class Compare1 implements Comparator<Query>{
		@Override
		public int compare(Query q1, Query q2){
			if(q1.x2==q2.x2) return q1.x1-q2.x1;
			return q1.x2-q2.x2;
		}
	}
	static class Pair implements Comparable<Pair>{
		int a, b;
		public Pair(int c, int d){
			a = c;
			b = d;
		}
		public int compareTo(Pair p){
		    return a-p.a;
		}
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
		FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}
		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

Measured memory_bytes: 22612
import math
s = input()
a=s[::-1]
flag=0
n=len(s)
if s==a:
    a=s[0:math.ceil((n-1)/2)]
    b = a[::-1]
    if a == b:
        a = s[math.ceil((n+3)/2-1):n]
        b = a[::-1]
        if a == b:
            flag=1
if flag==0:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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")
    };
}

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        _n: usize,
        m: usize,
        city: [(usize, usize); m],
    }

    // 県 -> [(市, 年)]
    let mut cs = std::collections::HashMap::<usize, Vec<(usize, usize)>>::new();

    for (i, (p, y)) in city.into_iter().enumerate() {
        cs.entry(p).or_insert(Vec::<(usize, usize)>::new());

        if let Some(pairs) = cs.get_mut(&p) {
            pairs.push((i, y));
        };
    }

    let mut sorted = std::collections::HashMap::new();
    for (pref, cities) in &cs {
        let mut years: Vec<usize> = cities.iter().map(|&(_i, y)| y).collect();
        years.sort();
        sorted.insert(pref, years);
    }
    let mut ans = vec![String::new(); m];

    for (pref, cities) in &cs {
        let sorted_years = &sorted[pref];

        for &(i, y) in cities {
            let y_idx = sorted_years.binary_search(&y).unwrap();
            let s = format!("{:06}", &pref) + &format!("{:06}", y_idx + 1);
            ans[i] = s;
        }
    }

    for s in ans {
        echo!(s);
    }
}


Measured memory_bytes: 31348
N = int(input())
A = [int(input()) for _ in range(N)]
dic = {num: 0 for num in set(A)}
for i in range(N):
    dic[A[i]] = 1 if dic[A[i]]==0 else 0
ans = 0
for num in set(A):
    ans += dic[num]
print(ans)

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

using namespace std;

const int N = 2e5 + 10;

int f1[N], f2[N];
map<pair<int, int>, int> ans;

int getf(int *f, int u) {
	if(u == f[u])return u;
	return f[u] = getf(f, f[u]);
}

void merge(int *f, int x, int y) {
	int u = getf(f, x), v = getf(f, y);
	if(u != v)f[u] = v;
}

int main() {
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	for(int i = 1; i <= n; i++) {
		f1[i] = f2[i] = i;
	}
	for(int i = 1; i <= m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		merge(f1, x, y);
	}
	for(int i = 1; i <= k; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		merge(f2, x, y);
	}
	for(int i = 1; i <= n; i++) {
		ans[make_pair(getf(f1, i), getf(f2, i))]++;
	}
	for(int i = 1; i <= n; i++) {
		printf("%d", ans[make_pair(getf(f1, i), getf(f2, i))]);
		if(i == n)puts("");
		else putchar(' ');
	}
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf

#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)

#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()

#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))

#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >

#define nl puts("");
#define line puts("-------");
#define dbb(x) cout<<#x<<" : "<<x<<"\n";

void __print(int x) {cerr << x;} void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;} void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V> void __print(const pair<T, V> &x)
{cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const queue<T> &x)
{queue<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.front() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const stack<T> &x)
{stack<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.top() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const T &x)
{int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v)
{__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
    #define db(x...) cerr << "[" << #x << "] = [", _print(x)
#endif
using ll = long long;
const int N = 100005;
const int MOD = 1000000007;

int main()
{
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt","w",stdout);
    #endif
    ll i,n,sum=0,ans=0,k,now=0;
    sl(n);
    vector<ll>vec;
    rep0(i,n)
    {
        sl(k);
        vec.pb(k);
        sum+=k;
    }
    rep0(i,n)
    {
        sum-=vec[i];
        ans+=((vec[i]%MOD)*(sum%MOD))%MOD;
        ans%=MOD;
    }
    pf("%lld",ans%MOD);
}


Measured memory_bytes: 5372
import math
def main4():
    N, M = map(int, input().split())
    S = input()
    T = input()

    L = (N * M) // math.gcd(N, M)

    pair = dict()

    for i in range(1, N + 1):
        idx = (i - 1) * (L // N) + 1
        pair[idx] = S[i - 1]

    for i in range(1, M + 1):
        idx = (i - 1) * (L // M) + 1

        if idx in pair.keys():
            if pair[idx] != T[i - 1]:
                print(-1)
                exit()

    print(L)

if __name__ == "__main__":
    main4()

Measured memory_bytes: 19572
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int a,b,x;
  scanf("%d %d %d",&x,&a,&b);
  printf("%d",(x-a)%b);
  return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    string s;
    getline(cin, s);
    if(s <= "2019/04/30"){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
    return 0;
}


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

int mod_pow(int n, int e, int mod){
    int ans = 1;
    n = n % mod;
    while(e != 0){
        if(e % 2 == 1){
            ans = (ans * n) % mod;
        }
        e /= 2;
        n = (n * n) % mod;
    }
    return ans;
}

int mod_inv(int n, int mod){
    return mod_pow(n, mod-2, mod);
}

int sieve(int p, int q){
    // ax + bz = a, ay + bw = b からスタートして
    // 右辺について互除法して係数を変えていく
    // (x, y) -> (y, x-y*(a/b)), (z, w) -> (w, z-w*(a/b))
    // 最終的に ax + bz = gcd(a, b) となるので a, b が互いに素なら x が逆元
    // z と w を覚えておく必要はない
    int a = p, b = q, x = 1, y = 0;
    while(b){
        x -= y * (a/b); swap(x, y);
        a -= b * (a/b); swap(a, b);
    }
    while(x < 0) x += q;
    return x;
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    int nn = n;
    vector<int> fac;

    int t = 2;
    while(n % 2 == 0){
        n /= 2;
        t *= 2;
    }
    fac.push_back(t);

    for(int i=3; i*i<=n; i+=2){
        if(n % i == 0){
            int f = i;
            n /= i;
            while(n % i == 0){
                f *= i;
                n /= i;
            }
            fac.push_back(f);
        }
    }
    if(n != 1) fac.push_back(n);

    int ans = 2*nn;
    for(int i=0; i<(1<<fac.size()); i++){
        int p = 1;
        for(int j=0; j<fac.size(); j++){
            if(i & (1<<j)) p *= fac[j];
        }
        int q = 2*nn / p;

        int k;
        if(p == 841705){
            cout << "";
        }
        if(q == 1) k = p-1;
        else if(p == 1) k = q;
        else{
            int a = sieve(p, q);
            k = a*p - 1;
        }
        
        ans = min(ans, k);
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=100005;
int n;
int par[maxn],sz[maxn],ord[maxn],dep[maxn];
ll d[maxn];
map<ll,int>rev;
bool cmp(int a,int b){
	return d[a]<d[b];
} 

int main(){
	scanf("%d",&n);
	REP(i,n){
		scanf("%lld",&d[i]);
		ord[i]=i;
		rev[d[i]]=i;
	}
	sort(ord+1,ord+1+n,cmp);
	for(int i=n;i>1;i--){
		int x=ord[i];
		if(sz[x]+1>=n||!rev.count(2*(sz[x]+1)+d[x]-n)){
			puts("-1");
			return 0;
		}
		int y=rev[2*(sz[x]+1)+d[x]-n];
		par[x]=y;
		sz[y]+=sz[x]+1;
	}
	if(sz[ord[1]]+1!=n){
		puts("-1");
		return 0;
	}
	dep[ord[1]]=0;
	for(int i=2;i<=n;i++)dep[ord[i]]=dep[par[ord[i]]]+1;
	ll tot=0;
	REP(i,n)tot+=dep[i];
	if(tot!=d[ord[1]]){
		puts("-1");
		return 0;
	}
	REP(i,n)if(par[i])printf("%d %d\n",par[i],i);
	return 0;
}

Measured memory_bytes: 9984
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};
const main=()=>{
  let s=ts(),ans=[]
  for(let i=0;i<s.length;i++){
    if(s[i]=='0')ans.push('0')
    else if(s[i]=='1')ans.push('1')
    else if(s[i]=='B')ans.pop()
  }
  to(ans.join(''))
}
main()


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int main(){
  int N;
  int K;
  int Q;
  cin >> N >> K >> Q;
  vector<i64> A(N);
  rep(i,0,N - 1) cin >> A[i];

  using P = pair<i64,i64>;
  vector<P> vec;
  rep(i,0,N - 1) vec.emplace_back(A[i],i);
  vector<bool> used(N,false);
  i64 ans = 1e18;
  sort(vec.begin(),vec.end());
  rep(i,0,N - 1){
    vector<i64> able;
    vector<i64> temp;
    rep(j,0,N - 1){
      if(used[j]){
        sort(temp.begin(),temp.end());
        int len = temp.size();
        rep(k,0,len - K){
          able.push_back(temp[k]);
        }
        temp.assign(0,0);
      }
      else{
        temp.push_back(A[j]);
      }
    }
    sort(temp.begin(),temp.end());
    int len = temp.size();
    rep(k,0,len - K){
      able.push_back(temp[k]);
    }
    temp.assign(0,0);

    sort(able.begin(),able.end());
    if(able.size() >= Q){
      ans = min(ans , able[Q - 1] - able[0]);
    }

    used[vec[i].second] = true;
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char const *argv[]) {
  int n,index,arr[100000];

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", &index);
    arr[index-1] = i+1;
  }

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

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

int main() {
	int n; cin>>n;
	vector<int> divs(n+1,1);
	divs[0] = divs[1] = 0;
	for (int i=2; i<=n; i++) {
		int x = i;
		for (int j=2; j<=x; j++) {
			while (x%j==0) {
				x/=j;
				divs[j]++;
			}
		}
	}
	int d75=0,d25=0,d15=0,d5=0,d3=0;
	for (int i : divs) {
		if (i >= 75) d75++;
		if (i >= 25) d25++;
		if (i >= 15) d15++;
		if (i >= 5) d5++;
		if (i >= 3) d3++;
	}

	cout << d75 + d25*(d3-1) + d15*(d5-1) + d5*(d5-1)*(d3-2)/2 << endl;
	return 0;
}


Measured memory_bytes: 256
char buf[5000],k;
sz;
S,N,A,K,i,T;
main()
{
	read(0,buf,5000);
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(i=0;i<N;i++)
	{
		A=K=0;
		for(;;)
		{
			k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		for(;;)
		{
			k=buf[sz++];
			if(k<'0')break;
			K=K*10+k-'0';
		}
		while(T=A/K+1,A%K%T)A=A/K*K-T+A%K%T;
		S^=T-1;
	}
	write(1,S?"Takahashi":"Aoki",S?9:4);
}

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

int main() {
  int a, b;
  string op;
  cin >> a >> op >> b;
  
  int ans;
  if (op == "+") ans = a + b;
  else if (op == "-") ans = a - b;
  
  cout << ans << endl;
}


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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int V, E, r;
    cin >> V >> E >> r;
    vector<vector<pair<int, int>>> dist(V+1, vector<pair<int, int>>());
    for(int i=0; i<E; i++){
        int s, t, d;
        cin >> s >> t >> d;
        dist[s].push_back(make_pair(d, t));
    }

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push(make_pair(0, r));

    int INF = (1<<30);
    vector<int> d_from_r(V, INF);
    while(!pq.empty()){
        int now_d = pq.top().first;
        int now_v = pq.top().second;
        pq.pop();
        if(d_from_r[now_v] != INF){
            // もう訪れた後だった
            continue;
        }
        // 来てなかったので最短経路、ここで更新
        d_from_r[now_v] = now_d;
        for(int i=0; i<dist[now_v].size(); i++){
            int next_d = dist[now_v][i].first + now_d;
            int next_v = dist[now_v][i].second;
            // next_v には未訪問だった
            if(d_from_r[next_v] == INF){
                // d_from_r[next_v] = next_d; // ここで更新すんのは気が早い
                pq.push(make_pair(next_d, next_v));
            }
        }
    }

    for(int i=0; i<V; i++){
        int d = d_from_r[i];
        if(d == INF) cout << "INF" << endl;
        else cout << d << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

ll N,M;
ll x[100000];
ll y[100000];
mint X;

int main(){
    cin >> N >> M;
    for(int i=0;i<N;i++) cin >> x[i];
    for(int i=0;i<M;i++) cin >> y[i];
    X = mint(0);
    ll n = N-1;
    ll m = M-1;
    for(ll i=0;i<n;i++){
        X += (mint(x[i+1] - x[i]) * (mint(i+1) * mint(n-i)));
    }
    mint S(0);
    for(ll i=0;i<m;i++){
        S += (mint(y[i+1] - y[i]) * (mint(i+1) * mint(m-i))) * X;
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 5164
#include <iostream>
using namespace std;
int main(){
    int A,B,k,i,x,y,C;
    cin >> A >> B;
    x=0;
    y=0;
    if(A>B){
        C=B;
        B=A;
        A=C;
    }
    /*
    for(i=0;i<B;i++){
        if(A-i==B-i){
            x=i;
            break;
        }
    }
    */
    for(i=0;i<B;i++){
        if(A-i==i-B){
            y=i;
            break;
        }
    }
    /*
    if(x!=0)
        cout << x;
    */
    if(y!=0)
        cout << y;
    else
        cout << "IMPOSSIBLE";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

int main(){
    ll H,N;
    cin >> H >> N;
    vector<ll> A(N,0);
    vector<ll> B(N,0);
    for(int i = 0; i < N; i++) cin >> A[i] >> B[i];
    ll max_A = 0;
    for(int i = 0; i < N; i++) max_A = max(max_A,A[i]);
    vector<ll> dp(H + max_A + 1 ,0);
    for(int j = 0; j < H + max_A + 1; j++) dp[j] = 10000000007;

    dp[0] = 0;
	for(int i = 1; i < H + max_A + 1; i++){
		for(int j = 0; j < N; j++){
			if(i - A[j] <= 0)
				dp[i] = min(dp[i], B[j]);
			else{
				dp[i] = min(dp[i], dp[i - A[j]] + B[j]);
			}            
        }
    }
    ll ans = 10000000007;
    for(int i = H; i < H + max_A + 1; i++){
        ans = min(ans, dp[i]);
    }
    cout << ans << endl;

}

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

int32_t main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0; i<n; i++)cin>>a[i];
  int dp[n][n];
  memset(dp,0,sizeof(dp));
  for(int i=n-1; i>=0; i--){
    for(int j=0; j<n; j++){
      if(i==j){
        dp[i][j] = a[i];
      }
      if(i>j){
      	dp[i][j] = 0;
      }
      if(i<j){
      	dp[i][j] = max(a[i]-dp[i+1][j], a[j] - dp[i][j-1]);
      }
    }
  }
  cout<<dp[0][n-1]<<"\n";
  return 0;
}

Measured memory_bytes: 73960
#include<stdio.h>
#include<math.h>
int main(){
	int t,d,c=0;
	scanf("%d %d",&t,&d);
	while(t--){
		long int x,y;
		scanf("%ld %ld",&x,&y);
		double result=sqrt(x*x + y*y);
		if(result<=d)
		 c=c+1;
	}
	printf("%d",c);
}

Measured memory_bytes: 2152
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
int a[300005],mx[300005],b[300005];
void change(ll x){
    while(x<=300001){
        mx[x]=b[x];
        for(ll i=1;i<(x&(-x));i<<=(ll)1){
            mx[x]=max(mx[x],mx[x-i]);
        }
        x+=x&(-x);
    }
}
int getmx(ll l,ll r){
    int res=b[r];
    while(l<=r){
        res=max(res,b[r]);
        for(--r;r-l>=(r&(-r));r-=(r&(-r))){
            res=max(res,mx[r]);
        }
    }
    return res;
}
int main(){
    int n,k;cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];a[i]++;
    }
    for(int i=1;i<=n;i++){
        int l=max(1,a[i]-k),r=min(300001,a[i]+k);
        int v=getmx(l,r);b[a[i]]=v+1;change(a[i]);
    }
    cout<<getmx(1,300001)<<endl;
} 

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
bool cmp(pair<string,int> a,pair<string,int> b){
    if(a.first==b.first)return a.second>b.second;
    else return a.first<b.first;
}
int main(){
    int n;cin>>n;
    vector<pair<string,int>> v;
    ll ten[101];
    
    rep(i,0,n){
        string s;cin>>s;
        int p;cin>>p;
        v.push_back(make_pair(s,p));
        ten[p]=i+1;
    }
    sort(v.begin(),v.end(),cmp);
    rep(i,0,n)cout<<ten[v[i].second]<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */

	NodePointer x;
	x = nil->next;
	while(x != nil && x->key != key){
		x = x->next;
	}
	return x;
}

/* リストの初期化 */
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
	nil->key = -1;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
	if( t==nil ) return; //tが番兵の場合は処理しない
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	/* your code */
	deleteNode(nil->next);
}

void deleteLast(){
  /* your code */
	deleteNode(nil->prev);
}

void delete(int key){
  /* your code */
	deleteNode(listSearch(key));
}


void insert(int key){
	NodePointer x,y;
	x = malloc(sizeof(struct node));
	x->key = key;
  /* your code */
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main(){
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	
	scanf("%d", &n);
	init();
	
	for ( i = 0; i < n; i++ ){
		scanf("%s%d", com, &key);
		if ( com[0] == 'i' ) {insert(key); np++; size++;}	//insert
		else if ( com[0] == 'd' ) {		//delete
			if (strlen(com) > 6){
				if ( com[6] == 'F' ) deleteFirst();	//deleteFirst
				else if ( com[6] == 'L' ) deleteLast();	//deleteLast
			} else {
				delete(key); nd++; 
			}
 			size--;
		}
	}

	printList();
	return 0;
}


Measured memory_bytes: 33052
import java.awt.geom.*;
import java.io.*;
import java.util.*;


public class Main {
	//1610 start
	int INF = 1 << 24;
	
	class Edge{
		int from, to, dis, cost;

		public Edge(int from, int to, int dis, int cost) {
			this.from = from;
			this.to = to;
			this.dis = dis;
			this.cost = cost;
		}
		
	}
	
	class State implements Comparable<State>{
		int now, dis, cost;

		public State(int now, int dis, int cost) {
			this.now = now;
			this.dis = dis;
			this.cost = cost;
		}


		public int compareTo(State o) {
			if(this.dis < o.dis) return -1;
			if(this.dis > o.dis) return 1;
			if(this.cost < o.cost) return -1;
			if(this.cost > o.cost)return 1;
			return 0;
		}


		@Override
		public String toString() {
			return "State [now=" + now + ", dis=" + dis + ", cost=" + cost
					+ "]";
		}
		
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m) == 0)break;
			ArrayList<ArrayList<Edge>> data = new ArrayList<ArrayList<Edge>>();
			for(int i = 0; i < n; i++){
				data.add(new ArrayList<Main.Edge>());
			}
			
			for(int i = 0; i < m; i++){
				int from = sc.nextInt()-1;
				int to = sc.nextInt()-1;
				int dis = sc.nextInt();
				int cost = sc.nextInt();
				data.get(from).add(new Edge(from, to, dis, cost));
				data.get(to).add(new Edge(to, from, dis, cost));
			}
			PriorityQueue<State> open = new PriorityQueue<Main.State>();
			open.add(new State(0, 0, 0));
			int [] close = new int[n];
			Arrays.fill(close, INF);
			close[0] = 0;
			int ans = 0;
			boolean [] vi = new boolean[n];
			int count = 1;
			while(! open.isEmpty()){
				State now = open.poll();
				if(vi[now.now]) continue;
				vi[now.now] = true;
				ans += now.cost;
				if(count == n) break;
				count++;
				
				for(int i = 0; i < data.get(now.now).size(); i++){
					Edge next =data.get(now.now).get(i);
					if(next.dis == INF ) continue;
					int nextdis = now.dis + next.dis;
					if(vi[next.to])continue;
					if(close[next.to] >= nextdis){
						open.add(new State(next.to, nextdis,next.cost));
						close[next.to] = nextdis;
					}
				}
			}
			System.out.println(ans);
		}
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

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

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

#define MAX_N 100100

bool probability[MAX_N];
int ball_num[MAX_N];
int N,M;
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> M;
    probability[0] = true;
    fill(ball_num,ball_num+N,1);
    REP(i,M) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        if (probability[x]) {
            probability[y]=true;
            if (ball_num[x]==1) {
                probability[x]=false;
            }
        }
        ball_num[x]--;
        ball_num[y]++;
    }
    int ans = 0;
    REP(i,N) {
        if(probability[i]>0) ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 768
n = int(input())
li = list(map(int,input().split()))

# dp = [[-1 for i in range(1100)] for j in range(1100)]
ans = [0]*n
ans[0] = 0
# def solve(a,b,dp,li):
#     if dp[a][b] !=-1 :
#         return dp[a][b]
#     else:
#         dp[a][b] = abs(li[a]-li[b])
#         return dp[a][b]

for i in range(2,n+1):
    if i == 2:
        ans[i-1]= abs(li[1]-li[0])
    else:
        ans[i-1] = min(abs(li[i-1]-li[i-2])+ans[i-2],abs(li[i-1]-li[i-3])+ans[i-3])

print(ans[-1])

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

/// Constant:
#define         eps         10e-9
#define         pi          2*acos(0)
#define         P1          1e9+7
#define         P2          1e9+9

#define         lli         long long int
#define         PB          push_back
#define         pb          pop_back
#define         mk          make_pair
#define         I           insert
/// Loop:
#define         f1(a,b)     for (int i=a; i<=b; i++)
#define         f2(a,b)     for (int j=a; j<=b; j++)
#define         f-1(a,b)     for (int i=b; i>=a; i--)
#define         f-2(a,b)     for (int j=b; j>=a; j--)
///Print:
#define         pY          cout<<"YES"<<endl;
#define         pN          cout<<"NO"<<endl;
#define         py          cout<<"Yes"<<endl;
#define         pn          cout<<"No"<<endl;

using namespace std;
///ISNNJB

/// Functions:
//lli bigmod(lli b, lli p, lli m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ lli res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//lli mod_inverse(lli a, lli mod) { return bigmod(a,mod-2,mod); }
//lli LCM(lli a, lli b){ return a*b/ __gcd(a,b);}

///Global Variable:
int ara[400005],brr[400004];

/**int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};*/

int main() {

    /**freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    lli a,b,c,d,k,t,n,m,x,y,q,ctn=0,l1,l2,total=0;
    //string s,p,q;

    cin>>n;
    if(n%1000==0)
        cout<<"0"<<endl;
    else {
        m=n%1000;
        cout<<1000-m<<endl;
    }

    return 0;
}


Measured memory_bytes: 3636