akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
mod = 10**9+7
ans = 0
li = [None]*(k+1)
for i in range(k, 0, -1):
    tmp = pow(k//i, n, mod)
    for j in range(2*i, k+1, i):
        tmp -= li[j]
    li[i] = tmp
    ans += tmp*i
print(ans%mod)

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

#define rep(i, n) for(int i = 0; i < n;i++)

int main()
{
    char a, b;
    cin >> a >> b;
    if(a == 'H'){
        if(b == 'H'){
            cout << 'H' << endl;
        }else{
            cout << 'D' << endl;
        }
    }else{
        if(b == 'H'){
            cout << 'D' << endl;
        }else{
            cout << 'H' << endl;
        }
    }
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int powi(int x, int y){
    int res = 1;
    for (int i = 0; i < y; i++){
        res *= x;
    }
    return res;
}

int search_max_r(int L){
    int res = 0;
    for (int i = 1; i < 20; i++){
        if (powi(2, i) <= L)
            res = i;
    }
    return res;
}

int main(){
    int L;
    cin >> L;
    int r = search_max_r(L);
    int N = r + 1;
    int M;
    int u[60], v[60], w[60];
    int count = 0;
    for (int i = 0; i < 60; i++){
        u[i] = -1;
        v[i] = -1;
        w[i] = -1;
    }
    for (int i = 0; i < r; i++){
        u[count] = i + 1;
        v[count] = i + 2;
        w[count] = 0;
        u[count + 1] = i + 1;
        v[count + 1] = i + 2;
        w[count + 1] = powi(2, i);
        count += 2;
    }
    for (int i = r; i >= 0; i--){
        int c = L - powi(2, i - 1);
        if (c >= powi(2, r)){
            u[count] = i;
            v[count] = N;
            w[count] = c;
            L -= L - c;
            count++;
        }
    }
    M = count;
    cout << N << " " << M << endl;
    for (int i = 0; i < count; i++){
        cout << u[i] << " " << v[i] << " " << w[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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

fn is_match(s: &String) -> bool {
  s == &s.chars().rev().collect::<String>()
}

fn main() {
  let s: String = read();
  let n: usize = s.len();
  
  println!("{}",
    if is_match(&s) &&
       is_match(&s[0 .. (n - 1) /2].to_string()) &&
       is_match(&s[(n + 3) / 2 - 1 .. n].to_string()) { "Yes" }
    else { "No" }
  );
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++) 
#define rrep(i,n) for(int i = 1; i <= (int)(n); i++) 
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod = 1000000007;
//const ll INF = mod * mod;
//const double pi = 3.14159265358979;



int main() {
    int x;
    cin >> x;
    int y = x;
    if(x == 1) {
        cout << "0 -1" << endl;
        return 0;
    }
    vi v;
    for(int i = 0; i <= 1000; i++) {
        v.pb(i*i*i*i*i);
        v.pb(i*i*i*i*i*-1);
    }
    ll c,d;
    //vi a = {1,32 ,243 ,1024 ,3125 ,7776 ,16807, 32768 ,59049 ,100000 ,161051 ,248832 ,371293, 537824 ,759375 ,1048576 ,1419857 ,1889568 ,2476099 ,3200000 ,4084101, 5153632 ,6436343 ,7962624, 9765625, 11881376, 14348907 ,17210368 ,20511149 ,24300000, 28629151, 33554432 ,39135393 ,45435424 ,52521875, 60466176, 69343957, 79235168 ,90224199, 102400000, 115856201 ,130691232 ,147008443 ,164916224 ,184528125 ,205962976 , 229345007 ,254803968 ,282475249 ,312500000 ,345025251, 380204032, 418195493, 459165024, 503284375, 550731776, 601692057, 656356768 ,714924299 ,777600000 ,844596301 ,916132832 ,992436543 ,1073741824};
    //int n = a.size();
    //rep(i,v.size()) cout << v[i] << " ";
    rep(i,v.size()) {
        y -= v[i];
        rep(j,v.size()) {
            if(v[j] == y * -1) {
                c = i;
                d = j;
                break;
            }
        }
        y = x;
    }
    //cout << c << " " << d << endl;
    if(c % 2 == 0) c /= 2;
    else {
        c = (c-1)/2;
        c *= -1;
    }
    if(d % 2 == 0) d /= 2;
    else {
        d = (d-1)/2;
        d *= -1;
    }
    cout << c << " " << d << endl;
}

Measured memory_bytes: 3596
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

LL a[50];
int main() {
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	sort(a,a+N,greater<LL>());
	LL ret=0;
	while(1){
		int k=1;
		for(;k<N;k++){
			if(a[0]-a[k]>=N){
				break;
			}
		}
		if(k==N){
			break;
		}
		LL p=(a[0]-a[k]-N)/(1+N);
		ret+=p*k;
		for(int i=0;i<k;i++){
			a[i]-=p*(N-(k-1));
		}
		for(int i=k;i<N;i++){
			a[i]+=p*k;
		}
		while(a[0]-a[k]>=N){
			ret++;
			a[0]-=N;
			for(int i=1;i<N;i++){
				a[i]++;
				if(a[i-1]<a[i]){
					swap(a[i-1],a[i]);
				}
			}
		}
	}
	if(a[0]>=2*N){
		LL d=a[0]-2*N;
		ret+=N*d;
		for(int i=0;i<N;i++){
			a[i]-=d;
		}
	}
	while(a[0]>=N){
		ret++;
		a[0]-=N;
		for(int i=1;i<N;i++){
			a[i]++;
			if(a[i-1]<a[i]){
				swap(a[i-1],a[i]);
			}
		}
	}
	cout << ret << endl;


	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define intt long long int 
void solve(){
 string s;
 cin>>s;
 if(s[s.length()-1]!='s')
    cout<<s<<"s";
else 
    cout<<s<<"es";
cout<<endl;
    }
int main(){
    // int t;
    // cin>>t;
    // while(t--)
        solve();
}

Measured memory_bytes: 3624
#include<stdio.h>
    int main(){
    	int n,a,b,min;
    	scanf("%d %d %d", &n,&a,&b);
        min = n*a;
    	if(b < min){
        	min = b;
        }
      // 出力
    	printf("%d",min);
    	return 0;
    }

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

  vector<int> sieve(55556, 0);
  sieve[0] = sieve[1] = 1;
  for(int i = 2; i <= sqrt(55555); ++i) {
    for(int j = 2; i * j <= 55555; ++j) {
      if(!sieve[i * j]) sieve[i * j] = i;
    }
  }
  vector<int> cdd;
  REP(i,55556) if(!sieve[i] && (i % 5 == 1)) cdd.push_back(i);

  REP(i,N) {
    if(i) cout << " ";
    cout << cdd[i];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#include <time.h>


/// Bismillahir Rahmanir Rahim


bool strong_palindrome(char *str);


int main(void)
{
    char str[100];

    scanf("%s", str);

    if (strong_palindrome(str)) puts("Yes");
    else puts("No");



    return 0;
}

bool strong_palindrome(char *str)
{
    short int len = strlen(str);
    short int i, pal_len = len >> 1;

    for(i = 0; i < pal_len; ++i) if (str[i] ^ str[len-i-1]) return false;

    short int bound = (len-1) >> 1;

    for(i = 0; i < (bound >> 1); ++i) if (str[i] ^ str[bound-1-i]) return false;

    bound = (len+3) >> 1;

    for(i = bound - 1; i < ((len - bound) >> 1); ++i) if (str[i] ^ str[len-i-1]) return false;

    return true;

}

Measured memory_bytes: 128
package main

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

func solve() {
	t, x := getFloat(), getFloat()
	ans := t / x
	fmt.Fprintln(wr, ans)
}

// calc
const (
	inf = 1 << 60
	mod = 1000000007
)

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

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

func getFloat() float64 {
	f, err := strconv.ParseFloat(getString(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 640
#include"stdio.h"

int main (){
	char a, b;
	scanf("%c %c", &a, &b);getchar();
	if((a=='H' && b=='H')||(a=='D' && b=='D'))
	{
		puts("H");
	}
	else
	{
		puts("D");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
const int INF = 1001001001;
const int MOD = 1000000007;

ll modpow(ll a, ll n, ll mod = MOD) {
    
    ll rtn = 1;//a^0
    
    a %= MOD;
    //MODが素数のとき n%=MODも可能
    
    while (n > 0) {//指数が0になるまでやる
        
        if (n & 1) rtn = rtn * a % mod;//nの1桁目が1ならば rtn に a^iを1回かける
        
        a = a * a % mod;//次のために (a^i)^2をつくる-->whileされるほどにa^2, a^4, a^8, a^16, ...ができていく
        n >>= 1;//nを右にビットシフト ... n/2の高速な演算
    }
    return rtn;
}


int main(){
    ll n;
    cin >> n;
    
    ll ans = modpow(10,n,MOD) + modpow(8,n,MOD) + 2*MOD - 2*modpow(9,n,MOD);
    ans %= MOD;
    
    cout << ans << endl;
    
    return 0;
}

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


int main()
{
	int n, k;
	cin >> n >> k;
	vector<char> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	if (s[k - 1] == 'A') {
		s[k - 1] = 'a';
	}
	else if (s[k - 1] == 'B') {
		s[k - 1] = 'b';
	}
	else {
		s[k - 1] = 'c';
	}
	for (int i = 0; i < n; i++) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N), b(N);
  vector<int> c(M), d(M);
  for (int i = 0; i < N; ++i) {
    cin >> a.at(i) >> b.at(i);
  }
  for (int i = 0; i < M; ++i) {
    cin >> c.at(i) >> d.at(i);
  }
  for (int i = 0; i < N; ++i) {
    int ans;
    int min = 1e9;
    for (int j = 0; j < M; ++j) {
      int dist = abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j));
      if (dist < min) {
        min = dist;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define int ll
    #define M 1000000007
    #define hell 998244353
    #define big 1e18
    #define pb push_back
    #define pi 3.1415926536
    #define mp make_pair
    #define ub upper_bound
    #define lb lower_bound
    #define mem0(a) memset(a,0,sizeof(a))
    #define memf(a) memset(a,false,sizeof(a))
    #define mem1(a) memset(a,1,sizeof(a))
    #define all(a) a.begin(),a.end()
    #define ll long long
    #define vec vector <int>
    #define pii pair<int,int>
    #define endl "\n"
    using namespace std;
    int power(int x, unsigned int y, unsigned int m) 
	{ 
    	if (y == 0) 
        	return 1; 
    	int p = power(x, y/2, m) % m; 
    	p = (p * p) % m; 
  
 	   return (y%2 == 0)? p : (x * p) % m; 
	} 
	int modInverse(int a, int m) 
	{   
    	return power(a, m-2, m);
	}
    signed main()
    {
    	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    	ll t=1;
    	// cin >> t;
    	/*SAARE INPUTS LENA*/
    	/*VARIABLES KI RANGE DEKHLENA*/
    	while(t-->0)
    	{
    		ll n=0,x=0,s=0,a=0;
    		cin>>n>>x;
    		for (int i = 0; i < x; ++i)
    		{
    			cin>>a;
    			s+=a;
    		}
    		if(s<=n)
    			cout<<n-s;
    		else
    			cout<<"-1";
    	}
    	return 0;
    }

Measured memory_bytes: 3692
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main()
{
	string d = "Y";
	int i,x=0;
	string color[1000];
	cin >> i;
	for (; i > 0; i--) {
		cin >> color[i];
		if (color[i] == d) {
			x = 1;
		}
	}
	if (x == 1) { cout << "Four"; }else {
		cout << "Three";
	}
	return 0;
}

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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int x, a, b;
void in(){
    cin >> x >> a >> b;
}

void solve(){
    
    if(-a + b <= 0){
        print("delicious");
    }else if(-a + b <= x){
        print("safe");
    }else{
        print("dangerous");
    }


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

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

int main(){
    int N, ans = 0; cin >> N;
    vector<int> a(N), b(N), c(N-1);
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 0; i < N; i++) cin >> b[i];
    for(int i = 0; i < N-1; i++) cin >> c[i];
    for(int i = 0; i < N; i++){
        ans += b[a[i] - 1];
        if(i){
            if(a[i]-a[i-1]==1) ans += c[a[i-1]-1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	ll n, m, k;
	cin >> n >> m >> k;

	ll tmp_ans = 0;
	ll cost = 0;
	vecll a(n), b(m);
	vector<ll> anss;

	ll a_itr = 0;
	rep(i, n)
	{
		cin >> a[i];
	}
	rep(i, n)
	{
		if (cost + a[i] <= k)
		{
			tmp_ans++;
			cost += a[i];
			a_itr = i + 1;
		}
		else
		{
			break;
		}
	}
	ll b_itr = 0;
	rep(i, m)
	{
		cin >> b[i];
	}

	anss.push_back(tmp_ans);
	while (b_itr < m)
	{
		if (cost + b[b_itr] <= k)
		{
			tmp_ans++;
			anss.push_back(tmp_ans);
			cost += b[b_itr++];
		}
		else
		{
			if (a_itr == 0)
				break;
			anss.push_back(tmp_ans);
			cost -= a[--a_itr];
			tmp_ans--;
		}
	}
	cout << *max_element(all(anss)) << endl;
	return 0;
}

Measured memory_bytes: 10516
#include <iostream>

int main() {
    long long n, a, b, c, d;
    std::cin >> n >> a >> b >> c >> d;

    b -= a;
    n--;

    bool ret = false;
    for (int k = 0; k <= n; k++) {
        if (k * c - (n - k) * d <= b && b <= k * d - (n - k) * c) ret = true;
    }

    std::cout << (ret ? "YES" : "NO") << std::endl;

    return 0;
}

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

int main() {
  int N,ben;
  cin >> N;
  ben = 0;
  vector <int> V(N);
  vector <int> C(N);
  for(int i=0;i<N;i++)
    cin >> V.at(i);
  for(int i=0;i<N;i++)
    cin >> C.at(i);
  for(int i=0;i<N;i++){
    if(V.at(i)-C.at(i) >= 0){
      ben += V.at(i);
      ben -= C.at(i);
    }
  }
  cout << ben << endl;
}


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

int main() {
    int n, a, b, c, d, sa, sc;
    std::scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
    sa = (n % a == 0) ? n / a : n /a + 1;
    sc = (n % c == 0) ? n / c : n /c + 1;
    (sa * b <= sc * d) ? printf("%d\n", sa * b) : printf("%d\n", sc * d);
    return 0;
}


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

using namespace std;
typedef long long ll;


int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
    ll ans=0,cnt=0;
    for(int i=a;i>=1;i--)
    {
    	ans+=1;
        cnt++;
    	if(cnt==d)
    	{
    		cout<<ans<<'\n';
    		exit(0);
		}
	}
    for(int i=b;i>=1;i--)
    {
    	cnt++;
    	if(cnt==d)
    	{
    		cout<<ans<<'\n';
    		exit(0);
		}
	}
	for(int i=c;i>=1;i--)
	{
    	ans-=1;
    	cnt++;
    	if(cnt==d)
    	{
    		cout<<ans<<'\n';
    		exit(0);
		}
	}
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	int a[n];
	int j,i;
	for(i=0;i<n;i++)
	cin>>a[i];
	int dp[n];
	dp[0]=0;
	for(i=1;i<n;i++)
	{
		dp[i]=INT_MAX;
		for(j=1;j<=k && i-j>=0;j++)
		dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));	
	}
	cout<<dp[n-1]<<endl;
	return 0;
}



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

int main(){

  int R,G,B,N,ans=0;
  cin >> R >> G >> B >> N;

  if(R==1||G==1||B==1){
    if(R==1){
      for(int j=0; j<=N/G; j++){
        for(int k=0; k<=(N-j*G)/B; k++){
          ans++;
        }
      }
    }else if(G==1){
      for(int j=0; j<=N/R; j++){
        for(int k=0; k<=(N-j*R)/B; k++){
          ans++;
        }
      }
    }else if(B==1){
      for(int j=0; j<=N/G; j++){
        for(int k=0; k<=(N-j*G)/R; k++){
          ans++;
        }
      }
    }

  }else{
  for(int i=0; i<=N/R; i++){
    for(int j=0; j<=(N-i*R)/G; j++){
      for(int k=0; k<=(N-i*R-j*G)/B; k++){
        if((i*R+j*G+k*B) == N) ans++;
      }
    }
  }
}
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "3 7", "1 6 3" ].parse.expand.solve == 14 );
	assert( [ "4 9", "7 4 0 3" ].parse.expand.solve == 46 );
	assert( [ "1 0", "1000000000000" ].parse.expand.solve == 1000000000000 );
	
	assert( [ "3 6", "1 2 4" ].parse.expand.solve == 13 );		// 追加ケース
	assert( [ "3 5", "1 2 4" ].parse.expand.solve == 12 );		// 追加ケース
}
 
 
 
import core.bitop;
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;
 
void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}
 
auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], as );
}
 
auto solve( long k, long[] as )
{
	// Aをbitごとに合計
	auto kbn = ( k == 0 ) ? 1 : k.bsr + 1;
	auto bns = new long[ kbn ];
	foreach( a; as )
	{
		auto abn = ( a == 0 ) ? 1 : a.bsr + 1;
		for( auto i = 0L, b = 1L; i < kbn && i < abn; i++, b <<= 1 )
		{
			bns[ i ] += ( ( a & b ) != 0 );
		}
	}
	
	// bitごとの合計がNの半分より少ない桁はXのbitを立てる（XがKを超える場合を除く）
	auto x = 0L;
	auto unk = false;
	for( auto i = kbn - 1, b = 1L << ( kbn - 1 ); 0 <= i; i--, b >>= 1 )
	{
		auto xb = ( bns[ i ] * 2 < as.length );
		if( !unk )
		{
			auto kb = ( ( k & b ) != 0 );
			xb = ( xb && xb <= kb );
			unk = ( xb < kb );
		}
		if( xb ) x |= b;
	}
	
	// XORの足し算を計算
	return reduce!( ( t, a ) => t + ( x ^ a ) )( 0L, as );
}


Measured memory_bytes: 8580
N,M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

path_cnt = [0] * (N+1)

for i in range(M):
    path_cnt[ab[i][0]] += 1
    path_cnt[ab[i][1]] += 1

for i in range(1,N+1):
    print(path_cnt[i])


Measured memory_bytes: 3060
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f
inline int read() {
    int x = 0, neg = 1; char op = getchar();
    while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
    while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
    return neg * x;
}
inline void print(int x) {
    if (x < 0) { putchar('-'); x = -x; }
    if (x >= 10) print(x / 10);
    putchar(x % 10 + '0');
}
int n;
signed main() {
    IO;
    cin >> n;
    int ans = 0;
    ans += (n / 500)*1000;
    n %= 500;
    ans += ( n / 5 ) * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
using namespace std;
int  gcd(int a, int b) {
	if (a < b) gcd(b, a);
	int r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	int a=0, b=0;
	cin >> n >> a >> b;
	int num1 = 0, num2 = 0, num3 = 0;
	int tmp;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp <= a) { num1 += 1; }
		else {
			if (tmp > b)num3 += 1;
			else num2 += 1;
		}
	}
	cout << min(num1, min(num2, num3));
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, A[30], B[30], C[30];

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

  std::cin >> N;

  for(int i=1;i<=N;++i){
      std::cin >> A[i];
  }

  for(int i=1;i<=N;++i){
      std::cin >> B[i];
  }

  for(int i=1;i<N;++i){
      std::cin >> C[i];
  }

  int res = 0;

  for(int i=1;i<=N;++i){
      res += B[A[i]];
      if(i + 1 <= N && A[i + 1] == A[i] + 1){
          res += C[A[i]];
      }
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int h,w,c;
  int sx[8]={-1,0,1,-1,1,-1,0,1};
  int sy[8]={-1,-1,-1,0,0,1,1,1};
  char s[50][51];
  scanf("%d%d",&h,&w);
  for(int i=0;i<h;i++)scanf("%s",s[i]);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='.'){
        c=0;
        for(int k=0;k<8;k++)if(s[i+sy[k]][j+sx[k]]=='#')c++;
      s[i][j]='0'+c;
      }
    }
  }
  for(int i=0;i<h;i++)printf("%s\n",s[i]);
  return 0;
}

Measured memory_bytes: 128
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        BigDecimal bd = BigDecimal.valueOf(a);
        bd = bd.multiply(BigDecimal.valueOf(b));
        bd = bd.setScale(0, RoundingMode.FLOOR);
        System.out.println(bd.longValue());
    }
}

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

const int mod = 1000000007;
struct mint {
  long long x;
  mint(long long x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint modpow(int n) {
  if (n == 0) return 1;
  mint x = modpow(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}

mint comb(int n, int a) {
  mint x = 1, y = 1;
  for (int i = 0; i < a; i++)
  {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  mint ans = modpow(n) - 1 - comb(n,a) - comb(n,b);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b, c, d;
	
	scanf("%d %d %d %d", &a, &b, &c, &d);
	
	if(a + b > c + d)
		printf("Left");
	else if(a + b < c + d)
		printf("Right");
	else
		printf("Balanced");
		
	return 0;
} 

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;


int main() {
    string s;int k;cin>>s>> k;
    ll ans = 0;
    if (s.length()==1) ans = k/2;
    else {
        vector<string> temp;
        int l=0,r=0;
        for (int i=1;i<s.length();i++) {
            if (s[i-1]==s[i]) r++;
            else  {
                string temps = s.substr(l,r-l+1);
                temp.push_back(temps);
                l=i;r=i;
            }
            if (i==s.length()-1) {
                string temps = s.substr(l,r-l+1);
                temp.push_back(temps);
            }
        }
        ll temp_size = temp.size();

        if (temp_size==1) ans = (s.length()) * k / 2;
        else {
            if (temp[0][0]==temp[temp_size-1][0]) {
                ll first_last=0,head_tail_syn=0,body = 0;
                first_last += temp[0].length()/2 + temp[temp_size-1].length()/2;
                head_tail_syn = (temp[0].length() + temp[temp_size-1].length())/2;
                for (int i=1;i<temp_size-1;i++) body += temp[i].length()/2;
                ans = first_last + body*k + head_tail_syn*(k-1);
            }
            else {
                ll body = 0;
                for(auto tt:temp) body+= tt.length()/2;
                ans = k*body;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    int a,b;
    cin>>a>>b;
    int licz=0;
    for(int x=22;x<=b;x++)
    {
        if(x%10>=2&&(x-x%10)/10>=2)
        {
            if((x%10)*((x-x%10)/10)<=a)
                licz++;
        }
    }
    cout<<licz;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl
template<typename T>
T ncr(T left, T right) {
	right = min(left - right, right);
	T ans = 1;
	for (T i = 1; i <= right; i++) {
		ans = ans * (left - right + i) / i;
	}
	return ans;
}

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	vector<int> v(6);
	for (int i = 0; i < 6; i++) {
		cin >> v[i];
	}
	if (v[4] - v[0] > v[5]) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}
	return 0;
}



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

int main() {
	int n;
	cin >> n;
	int sm=0,ml=0;
	for(int i=0;i<n;i++)
	{
		int l;
		cin >> l;
		sm += l;
		ml = max(ml,l);
	}
	string k = "Yes";
	if(sm <= 2 * ml)
	{
		k = "No";
	}
	cout << k << endl;
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mm 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define siz(x) (int)x.size()

#define show(x) cout<<#x<<" "<<x<<'\n'
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define oset tree<int , null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

int main()
{
    int n,m,i,j;
    cin>>n>>m;
    char a[n+1][m+1];
    
    ll ans[n+1][m+1];
    memset(ans,0,sizeof(ans));
    
    for(i=1;i<=n;i++) for(j=1;j<=m;j++) cin>>a[i][j];
    
    ans[1][1]=1;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(i==1 && j==1) continue;
            
            if(a[i][j]=='#') ans[i][j]=0;
            else ans[i][j]=(ans[i-1][j]+ans[i][j-1])%mm;
        }
    }
    
    cout<<ans[n][m]<<'\n';
    return 0;
}

Measured memory_bytes: 9088
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define vec vector
#define vll vec<ll>
#define dou(s) atof(s.c_str())
#define lon(s) atoll(s.c_str())
#define str(n) to_string(n)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define line "\n"
#define mav(a) (*max_element(ALL(a)))
#define miv(a) (*min_element(ALL(a)))
#define vfind(a,n) (find(ALL(a),n)-a.begin())
#define prque priority_queue
#define MOD 1000000007ll
using namespace std;
void solve();
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

//nCk(mod p)
/*ll fac[510000], finv[510000], inv[510000];
void cmodf(ll p = MOD) {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rep(i, 2, 510000) {
		fac[i] = fac[i - 1] * i%p;
		inv[i] = p - inv[p%i] * (p / i) % p;
		finv[i] = finv[i - 1] * inv[i] % p;
	}
}
ll cmod(ll n, ll k, ll p = MOD) {
	return fac[n] * (finv[k] * finv[n - k] % p) % p;
}*/

//最大公約数
ll gcd(ll n, ll m) {
	ll k = n % m;
	while (k != 0) { n = m; m = k; k = n % m; }
	return m;
}
ll gcd(vector<ll> a) {
	rep(i, 1, a.size()) {
		ll k = a[i - 1] % a[i];
		while (k != 0) {
			a[i - 1] = a[i];
			a[i] = k;
			k = a[i - 1] % a[i];
		}
	}
	return a.back();
}

//最小公倍数
ll lcm(ll n, ll m) {
	ll t = n * m, k = n % m;
	while (k != 0) { n = m; m = k; k = n % m; }
	return t / m;
}
ll lcm(vector<ll> a) {
	ll n;
	rep(i, 1, a.size()) {
		n = a[i - 1] * a[i];
		ll k = a[i - 1] % a[i];
		while (k != 0) {
			a[i - 1] = a[i];
			a[i] = k;
			k = a[i - 1] % a[i];
		}
		n /= a[i];
		a[i] = n;
	}
	return n;
}

//keyの小さい方から探していった時に初めてvalueがjoken以上になる時のkey（keyが増えたらvalueも増えるか同じになるとき）
ll value(ll key) {
	/*変更*/
	return 0;
}
ll mini(ll lkey, ll rkey/*ここも調べる*/, ll joken) {
	ll mkey;
	while (lkey != rkey) {
		mkey = (lkey + rkey) / 2;
		if (value(mkey) >= joken)rkey = mkey;
		else lkey = mkey + 1;
	}
	return rkey;
}

//ペア配列の整理
struct cpl {
	ll f, s;
	bool operator<(const cpl &c) const {
		return f != c.f ? f < c.f : s < c.s;
	};
};

//変数定義
ll n; vec<vll> a, c; vll le;
//再帰関数
void f(ll i, ll l) {
	rep(j, 0, n) {
		if (a[i][j] == 1) {
			c[l].push_back(j);
			le[j] = l + 1;
		}
	}
}
bool g(ll i) {
	if (c[i].size() == 0)return false;
	rep(j, 0, c[i].size()) {
		rep(k, 0, n) {
			a[k][c[i][j]] = 0;
		}
	}
	return true;
}
//アルゴリズム
void solve() {
	cin >> n;
	a.resize(n, vll(n, 0));
	rep(i, 0, n) {
		ll k, m; cin >> k >> m;
		rep(j, 0, m) {
			ll l; cin >> l;
			a[k - 1][l - 1] = 1;
		}
	}
	c.resize(n);
	le.resize(n, -1);
	le[0] = 0;
	rep(i, 0, n)a[i][0] = 0;
	ll l = 0;
	f(0, l);
	while (g(l)) {
		rep(i, 0, c[l].size())f(c[l][i], l + 1);
		l++;
	}
	rep(i, 0, n)cout << i + 1 << " " << le[i] << line;
}


Measured memory_bytes: 4744
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;

int main() {
    int N;
    set<char> S;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        char s;
        cin >> s;
        S.insert(s);
    }
    if (S.size() == 3) {
        cout << "Three" << endl;
    } else {
        cout << "Four" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <limits>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <iomanip>
using namespace std;

#define FOR( i, m, n )	for( int (i) = (m); (i) < (n); i++ )
#define REP( i, n )		FOR( i, 0, n )
#define ALL( x )		(x).begin(), (x).end()

struct Koma {
	int pos;
	int id;
};

void proceed( vector<int>& pos, int id );

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


	vector<int> pos(n);
	REP( i, n ) cin >> pos[i];

	int n2; cin >> n2;
	REP( i, n2 ) {
		int id; cin >> id;
		proceed( pos, id);
	}

	REP( i, n ) cout << pos[i] << endl;

}

void proceed( vector<int>& pos, int id ) {
	if( pos[id - 1] != 2019 ) {
		if( ( id - 1 ) == ( pos.size() - 1 ) ) {
			pos[id - 1]++;
		} else {
			if( pos[id - 1] + 1 != pos[id] ) {
				pos[id - 1]++;
			}
		}
	}
}


Measured memory_bytes: 3100
#include<stdio.h>

int main(){
  int a[3];
  int i,j;
  int tmp;
  scanf("%d%d%d",&a[0],&a[1],&a[2]);
  for (i=0; i<3; ++i) {
  for (j=i+1; j<3; ++j) {
    if (a[i] > a[j]) {
      tmp =  a[i];
      a[i] = a[j];
      a[j] = tmp;
    }
  }
}

  printf("%d",a[0]+a[1]);


  return 0;
}

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

int main() {
  std::string str;
  std::cin >> str;
  for (int i=0; i<str.size(); i++) {
    if (i%2 == 0) {
      std::cout << str.at(i);
    }
  }
  std::cout << std::endl;
}


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

using namespace std;
typedef long long ll;

const ll mod=1000000007;
int n,k;
int pos=0,neg=0,zero=0;
vector<ll> one,two;

ll fpow(ll b,ll e)
{
    ll res=1;
    while(e)
    {
        if(e&1) res=(res*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return res;
}

ll inv(ll a)
{
    return fpow(a,mod-2);
}

bool chpos()
{
    for(int i=0;i<=k;i++)
    {
        if(i<=pos&&(k-i)<=neg&&((k-i)%2)==0) return 1;
    }
    return 0;
}

ll solvepos()
{
    ll now=1;
    sort(one.begin(),one.end(),greater<ll>());
    sort(two.begin(),two.end(),greater<ll>());
    int pi=0;
    int ni=0;
    while(pos<k-ni)
    {
        now=(now*two[ni++])%mod;
        now=(now*two[ni++])%mod;
    }
    for(int i=0;i<k-ni;i++)
    {
        now=(now*one[pi++])%mod;
    }
    while(pi>=2&&ni+1<neg&&(one[pi-2]*one[pi-1]<=two[ni]*two[ni+1]))
    {
        now=(now*inv(one[pi-1]))%mod;
        now=(now*inv(one[pi-2]))%mod;
        pi-=2;
        now=(now*two[ni])%mod;
        now=(now*two[ni+1])%mod;
        ni+=2;
    }
    return (now+mod)%mod;
}

ll solveneg()
{
    vector<ll> v;
    for(ll x:one) v.push_back(x);
    for(ll x:two) v.push_back(x);
    sort(v.begin(),v.end());
    ll now=1;
    for(int i=0;i<k;i++) now=(now*v[i])%mod;
    now=(-now+mod)%mod;
    return now;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for(int i=0;i<n;i++)
    {
        ll a;
        cin >> a;
        if(a>0)
        {
            pos++;
            one.push_back(a);
        }
        else if(a<0)
        {
            neg++;
            two.push_back(-a);
        }
        else zero++;
    }
    if(chpos()==1) cout << solvepos() << "\n";
    else if(zero>0) cout << "0\n";
    else cout << solveneg() << "\n";
    return 0;
}


Measured memory_bytes: 6816
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  for (int i = 0; i < m; i++) {
    cin >> x[i];
  }

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

  vector<int> d;
  for (int i = 0; i < m - 1; i++) {
    d.push_back(abs(x[i] - x[i+1]));
  }
  sort(d.begin(), d.end());
  long long ans = 0;
  for (int i = 0; i < m - n; i++) {
    ans += d[i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1276
#include <stdio.h>
#include <algorithm>
#include <vector>

using namespace std;

int pindex[100010];

bool pairc(pair<int, int> a, pair<int, int> b) {
    return a.first < b.first;
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);

  vector<pair<int, int>> py(m);
  int p[m], y[m], index[m];
  for (int i = 0; i < m; i++) {
    scanf("%d %d", p+i, y+i);
    py[i] = make_pair(y[i], i);
  }

  sort(py.begin(), py.end(), pairc);
  for (int i = 0; i < py.size(); ++i) {
    // printf("%d %d\n", py[i].first, py[i].second);
    index[py[i].second] = pindex[p[py[i].second]];
    pindex[p[py[i].second]]++;
  }

  for (int i = 0; i < m; i++) {
    printf("%06d%06d\n", p[i], index[i]+1);
  }

  return 0;
}


Measured memory_bytes: 3840
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

ll kai[200001], inv[200001];
int n, k;
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2;
  }
  return res;
}
void init() {
  kai[0] = 1LL;
  for (ll i = 1LL; i <= 200000; i++) {
    kai[i] = kai[i - 1] * i;
    kai[i] %= MOD;
  }
  inv[200000] = mod_pow(kai[200000], MOD - 2LL, MOD);
  for (ll i = 199999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1);
    inv[i] %= MOD;
  }
}

ll comb(ll r, ll c) {
  ll res;
  res = kai[r];
  res *= inv[c];
  res %= MOD;
  res *= inv[r - c];
  res %= MOD;
  return res;
}

int main() {
  ll n, ans = 0;
  cin >> n;
  init();
  for (ll i = 1; i <= n / 3LL; i++) {
    ans += comb(i + n - i * 3LL - 1, i - 1);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6768
n, k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]
assert len(a) == n
current = 0
visited = [-1] * n
visited[0] = 0
for i in range(1, k):
  current = a[current]
  if visited[current] == -1:
    visited[current] = i
  else:
    pre = visited[current]
    count = (k - pre) % (i - pre) + pre
    print(visited.index(count)+1)
    break
else:
  print(a[current]+1)


Measured memory_bytes: 32288
S = input()
S = S[::-1]
_ = ["dream", "dreamer", "erase", "eraser"]
_ = [_[i][::-1] for i in range(4)]
i = 0
while i < len(S):
    can = False
    for k in _:
        if S[i:i + len(k)] == k:
            can = True
            i += len(k)
    if not can:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;


int n;

string calc(string x){
	int Max=0;
	for(int i=1;i<x.size();i++){
		Max = max(Max, atoi(x.substr(0, i).c_str()) * atoi(x.substr(i).c_str()));
	}
	stringstream ss;
  	ss << Max;
  	return ss.str();
}
main(){
	int i,j;
	string x;
	cin >> n;
	while(n--){
		int ans=0;
		cin >> x;
		for(;x.size()>1;ans++) x=calc(x);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
n, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(1, n):
    s = a[i-1] + a[i]
    
    if s > x:
        minus = s - x
        if a[i] >= minus:
            a[i] -= minus
            cnt += minus
        else:
            a[i] = 0
            a[i-1] -= minus - a[i]
            cnt += minus
print(cnt)

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

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

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

	int odd = (float)n / 2 + 0.5;
  //cout<<odd<<endl;

	cout << (float)odd / n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int h,w;
char bch[1003][1003];

int bfs ()
{
    int ans=0, cas[1003][1003],c;
    vector<pair<int, int>> que, vec;
    for (int i=1; i<h-1; i++)
    {
        for (int j=1; j<w-1; j++)
        {
            if (bch[i][j]!='.')
            {
                c=0;
                if (bch[i-1][j-1]=='.') c++;
                if (bch[i-1][j]=='.') c++;
                if (bch[i-1][j+1]=='.') c++;
                if (bch[i][j-1]=='.') c++;
                if (bch[i][j+1]=='.') c++;
                if (bch[i+1][j-1]=='.') c++;
                if (bch[i+1][j]=='.') c++;
                if (bch[i+1][j+1]=='.') c++;
                cas[i][j]=bch[i][j]-'0'-c;
                if (cas[i][j]<=0) que.push_back({i, j});
            }
        }
    }
    while (1)
    {
        if (que.empty())
        {
            ans++;
            for (auto u : vec)
            {
                int i=u.first, j=u.second;
                if (bch[i-1][j-1]!='.') { cas[i-1][j-1]--; if (cas[i-1][j-1]==0) que.push_back({i-1, j-1}); }
                if (bch[i-1][j]!='.') { cas[i-1][j]--; if (cas[i-1][j]==0) que.push_back({i-1, j}); }
                if (bch[i-1][j+1]!='.') { cas[i-1][j+1]--; if (cas[i-1][j+1]==0) que.push_back({i-1, j+1}); }
                if (bch[i][j-1]!='.') { cas[i][j-1]--; if (cas[i][j-1]==0) que.push_back({i, j-1}); }
                if (bch[i][j+1]!='.') { cas[i][j+1]--; if (cas[i][j+1]==0) que.push_back({i, j+1}); }
                if (bch[i+1][j-1]!='.') { cas[i+1][j-1]--; if (cas[i+1][j-1]==0) que.push_back({i+1, j-1}); }
                if (bch[i+1][j]!='.') { cas[i+1][j]--; if (cas[i+1][j]==0) que.push_back({i+1, j}); }
                if (bch[i+1][j+1]!='.') { cas[i+1][j+1]--; if (cas[i+1][j+1]==0) que.push_back({i+1, j+1}); }
            }
            vec.clear();
        }
        if (que.empty()) break;
        vec.swap(que);
    }
    return ans;
}

int main()
{
    cin>>h>>w;
    for (int i=0; i<h; i++) for (int j=0; j<w; j++) cin>>bch[i][j];
    cout<<bfs()<<'\n';
    return 0;
}



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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;
const int MIN = 444;

struct DSU
{
	int P[MIN];
	int H[MIN];

	void init(int n)
	{
		FOR (i, 0, n)
		{
			P[i] = i;
			H[i] = 1;
		}
	}

	int find(int x)
	{
		if (x == P[x]) return x;
		return P[x] = find(P[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (H[x] > H[x]) swap(x, y);
		P[x] = y;
		H[y] += H[x];
	}
} D;

int NB[MIN][MIN];

PII E[MAX];

int U[MIN];
int C[MAX];
int ST[MIN];

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;
	scanf("%d%d", &n, &m);
	FOR (i, 0, m)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;
		E[i] = MP(x, y);

		if (NB[x][x] || NB[y][y])
		{
			NB[x][x] = true;
			NB[y][y] = true;
			continue;
		}

		FOR (j, 0, n)
		{
			if (NB[x][j] && NB[y][j])
			{
				NB[x][x] = true;
				NB[y][y] = true;
				continue;
			}

			if (NB[x][j] || NB[y][j])
			{
				NB[x][j] = true;
				NB[y][j] = true;
			}
		}

		NB[x][y] = true;
		NB[y][x] = true;
	}

	int res = 0;

	FOR (i, 0, n)
	{
		FOR (j, i+1, n)
		{
			if (NB[i][i] || NB[j][j]) continue;
			if (NB[i][j] || NB[j][i]) continue;

			bool ok = true;

			FOR (k, 0, n)
			{
				if (NB[i][k] && NB[j][k])
				{
					ok = false;
					break;
				}
			}

			res += ok;
		}
	}

	cout<<res<<endl;
}


Measured memory_bytes: 1664
n = int(input())
memo = [-1] * (n+1)
import sys
sys.setrecursionlimit(1000000)
def f(n):
    if n == 0:
        return 0
    if memo[n] != -1:
        return memo[n]
    res = n
    pow6 = 1
    pow9 = 1
    res = min(res, f(n - 1) + 1)
    while pow6*6 <= n:
        pow6 *= 6
        res = min(res, f(n - pow6) + 1)
        
    while pow9*9 <= n:
        pow9 *= 9
        res = min(res, f(n - pow9) + 1)
        
    memo[n] = res
    return res
print(f(n))


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

int main(){
  string s;
  cin >> s;
  int ch[26]={};
  for(int i=0; i<s.size(); i++){
    ch[s[i]-'a']++;
  }
  for(int i=0; i<26; i++){
    if(ch[i]>=2){
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define all(v) v.begin(),v.end()
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  cout << fixed << setprecision(5) << 6.2831 * n << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n = 0;
  scanf("%lld", &n);
  ll ans = 0;
  for (int i = 2; i <= 1000000; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    int x = 0;
    while ((x + 1) * (x + 2) / 2 <= cnt) x++;
    ans += x;
  }

  if (n > 1) ans++;
  printf("%lld", ans);
  return 0;
}


Measured memory_bytes: 3828
N = int(input())
S = input()

b = [0] * N
for i, s in enumerate(S):
    if s == '#':
        b[i] = b[i-1] + 1
    else:
        b[i] = b[i-1]
b = [0] + b + [0]
ans = N
for i in range(N+1):
    ans = min(ans, b[i] + N - i - b[N] + b[i-1])

print(ans)


Measured memory_bytes: 14312
#include<bits/stdc++.h>
using namespace std;
 
#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)
 
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  lli N;
  set<string> item;
  string tmp;

  cin >> N;

  rep(i,N){
    cin >> tmp;
    item.insert(tmp);
  }


  cout << item.size() << endl;
  
  return 0;
}


Measured memory_bytes: 19200