akhauriyash/Code-Regression huggingface dataset:
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/24 12:04:08 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	ll	n, k, s;
	cin >> n >> k >> s;

	if (k == 0)
	{
		if (s == 1e9)
		{
			rep(i, n)
				cout << 1000000000 - 1 << " ";
		}
		else
		{
			rep(i, n)
				cout << 1000000000 << " ";
		}
		cout << endl;
		return ;
	}
	rep(i, k)
	{
		if (i)
			cout << " ";
		cout << s;
	}
	if (s == 1e9)
	{
		rep(i, n - k)
		{
			cout << " " << 1000000000 - 1;
		}
	}
	else
	{
		rep(i, n - k)
			cout << " " << 1000000000;
	}
	cout << endl;
}
// END

int		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout << fixed << setprecision(15);
	Main();
}


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

namespace ABC168
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_B();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var n = Ex.Read;

            int i = n.LastOrDefault() - '0';
            if (i == 2 || i == 4 || i == 5 || i == 7 || i == 9) "hon".Cw();
            else if (i == 3) "bon".Cw();
            else "pon".Cw();
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            var k = Ex.ReadInt;
            var s = Ex.Read;

            if (s.Length <= k) s.Cw();
            else
            {
                (string.Join("", s.Take(k)) + "...").Cw();
            }
        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
        }
    }
    public class ABC_D
    {
        public ABC_D()
        {
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }

        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
        public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
        public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 18812
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
// http://drken1215.hatenablog.com/entry/2019/01/14/033200
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    vector<int> B(M);
    REP(i, N) { cin >> A[i]; }
    REP(i, M) { cin >> B[i]; }
    A.push_back(0);
    B.push_back(0);
    // N行M列
    //重複がない
    sort(A.begin(), A.end(), greater<int>());
    sort(B.begin(), B.end(), greater<int>());
    ll res = 1;
    // A, B でXより大きいのが何個有るのか
    int biggerX_a = 0;
    int biggerX_b = 0;
    // 各マスに何が入りうるのかを考える
    // 各数字がどこのマスに入りうるのかを考える

    for(int x = N * M; x >= 1; x--) {
        if(A[biggerX_a] > x) {
            cout << 0 << endl;
            return 0;
        }
        if(B[biggerX_b] > x) {
            cout << 0 << endl;
            return 0;
        }
        ll tmp = 1;
        if(A[biggerX_a] == x and B[biggerX_b] == x) {
            //一意にきまる
            tmp = 1;
            biggerX_a++;
            biggerX_b++;
        } else if(A[biggerX_a] == x) {
            tmp = biggerX_b;
            biggerX_a++;
        } else if(B[biggerX_b] == x) {
            tmp = biggerX_a;
            biggerX_b++;
        } else {
            tmp = biggerX_a * biggerX_b - (N * M - x);
            if(tmp < 0) {
                cout << 0 << endl;
                return 0;
            }
        }
        res = (res * tmp) % MOD;
    }
    cout << res << endl;
    return 0;
}

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

vector<int> heap;
int hp = 1;

// void propagate(int i)
// {
//   if (i == 1) return;
//   int parent = i/2;
//   if (heap[parent] < heap[i]) {
//     swap(heap[i], heap[parent]);
//     propagate(parent);
//   }
// }
// 
// void insert(int v)
// {
//   heap[hp] = v;
//   propagate(hp);
//   hp++;
// }

void max_heapify(int n, int i)
{
  int li = 2*i;
  int ri = 2*i+1;

  int largest;
  if (li <= n && heap[li] > heap[i])
    largest = li;
  else
    largest = i;
  if (ri <= n && heap[ri] > heap[largest])
    largest = ri;

  if (largest != i) {
    swap(heap[i], heap[largest]);
    max_heapify(n, largest);
  }
}

int main()
{
  int n; cin >> n;
  heap = vector<int>(n+1);
  for (int i = 0; i < n; i++) {
    int v; cin >> v;
    // insert(v);
    heap[hp++] = v;
  }
  for (int i = n; i >= 1; i--)
    max_heapify(n, i);
  for (int i = 1; i <= n; i++)
    cout << " " << heap[i];
  cout << endl;
  return EXIT_SUCCESS;
}




Measured memory_bytes: 6672
import sys
input = sys.stdin.readline
 
N = int(input())
A = [int(x) for x in input().split()]

cnt = 0

from collections import Counter

c = Counter(A)

for i in c.values():
    if i > 1:
        cnt += i - 1

print(N - (cnt + int(cnt % 2 != 0)))

Measured memory_bytes: 62108
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
  int a[5], k;
  for (int i = 0; i < 5; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &k);
  for (int i = 0; i < 5; i++) {
    for (int j = i; j < 5; j++) {
      if (abs(a[i] - a[j]) > k) {
        printf(":(\n");
        return 0;
      }
    }
  }
  printf("Yay!\n");
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	int H,W,i,j;
	while(1){
	scanf("%d %d",&H,&W);
		if(H==0 && W==0){
			break;
		}
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			if(i==0 || j==0 || j==W-1 || i==H-1){
				printf("#");
			}
			else{
				printf(".");
			}
		}
		printf("\n");
	}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2032
/**
 * @author torith
 * @date 2018-10-10
 */

#include <bits/stdc++.h>

using namespace std;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;

    char S[300000];
    for (int i = 0; i < N; ++i) {
        cin >> S[i];
    }

    // 先頭がリーダとした時
    int ans = 0;
    for (int i = 1; i < N; ++i) {
        if(S[i] == 'E') ans++;
    }

    int tmp = ans;
    for (int i = 1; i < N; ++i) {
        if(S[i-1] == 'W') tmp++;
        if(S[i] == 'E') tmp--;
        ans = min(ans,tmp);
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 512
D = int(input())
C = [int(_) for _ in input().split()]
S = [[int(_) for _ in input().split()] for _ in range(D)]
T = [int(input()) - 1 for _ in range(D)]

ans = 0
last = [-1] * 26

for day, t in enumerate(T):
    ans += S[day][t]
    last[t] = day
    for t2, day2 in enumerate(last):
        ans -= C[t2] * (day - day2)
    print(ans)


Measured memory_bytes: 9508
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int N = intArray[0];
            int Y = intArray[1];
            if(10000 * N < Y)
            {
                Console.WriteLine("-1 -1 -1");
                return;
            }
            else if(10000 * N == Y)
            {
                Console.WriteLine(Y / 10000 + " 0 0");
                return;
            }
            for(int i = 0; i <= N; i++)
            {
                if(10000 * i > Y)
                {
                    break;
                }
                for(int j = 0; j <= N -i; j++)
                {
                    if (10000 * i + 5000 * j > Y)
                    {
                        break;
                    }
                    int l = N - (i + j);
                    if (i + j + l == N && (10000 * i) + (5000 * j) + (1000 * l) == Y)
                    {
                        Console.WriteLine(i + " " + j + " " + l);
                        return;
                    }
                }
            }
            Console.WriteLine("-1 -1 -1");
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 28132
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int N=100005;
int n,m;
struct ex{int num,next,w;}map[N*2];
int head[N],col[N],len;
inline void link(int x,int y)
{
  len++;map[len]=(ex){y,head[x],1};head[x]=len;
  len++;map[len]=(ex){x,head[y],2};head[y]=len;
}
bool vis[N],NO;int num[3],tot,bot;
inline void dfs(int k)
{
  vis[k]=1;num[col[k]]++;tot++;
  int i,x,u=col[k],y;
  for(i=head[k];i;i=map[i].next)
    {
      x=map[i].num;bot++;
      y=(u+map[i].w)%3;
      if(vis[x]) NO|=(col[x]!=y);
      else col[x]=y,dfs(x);
    }
}
int main( )
{
  int i,x,y;LL ans=0;
  n=read( );m=read( );
  for(i=1;i<=m;i++) x=read( ),y=read( ),link(x,y);
  for(i=1;i<=n;i++)
    {
      if(vis[i]) continue;
      num[0]=num[1]=num[2]=0;
      NO=0;tot=0;bot=0;dfs(i);
      if(NO) ans+=1LL*tot*tot;
      else if(num[0]&&num[1]&&num[2]) ans+=1LL*num[0]*num[1]+1LL*num[1]*num[2]+1LL*num[2]*num[0];
      else ans+=bot>>1;
    }
  printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 4992
import bisect
N = int(input())
arr = sorted([int(i) for i in input().split()])
c = (N * (N-1) * (N-2)) // 6
for i in range(N-1):
    for j in range(1, N-i):
        tmp = arr[i] + arr[i+j]
        idx = bisect.bisect_left(arr, tmp)
        #print(idx, arr[i], arr[i+j])
        c -= (N - idx)
print(c)


Measured memory_bytes: 3188
#include <stdio.h>

int main(void){
  int n; 
  scanf("%d",&n);
  int p[n];
  int i;
  int count=0;
  int max=300000;
  
  for(i=0;i<n;i++){
    scanf("%d ",&p[i]);
  }
  for(i=0;i<n;i++){
    if(p[i]<=max){
      count++;
      max=p[i];
    }
  }
  
  printf("%d\n",count);
  return 0;
}

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

typedef long long ll;

int n, t, Cnt;
ll sum;
bool z;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    int m = INT_MAX;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        if (t < 0) {
            ++Cnt;
            m = min(m, -t);
            sum += -t;
        } else if (t > 0) {
            m = min(m, t);
            sum += t;
        } else {
            z = true;
        }
    }
    if (!z && (Cnt & 1)) {
        sum -= m * 2;
    }
    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3572
#include <iostream>
#include <cmath>
#include <iomanip> 
using namespace std;

double round(double x, int k) {
  double res = x * pow(10, k) + 0.5;
  res = (double)(int)res;
  res = res * pow(0.1, k);
  return res;
}

int main() {
  double a, b, c, d, e, f;
  while (cin >> a >> b >> c >> d >> e >> f) {
    double det = a*e - b*d;
    double x = (e * c - b * f)/det;
    double y = (-1*d * c + a * f)/det;
    cout << fixed << setprecision(3) << round(x, 4) 
	 << " " << round(y, 4) << endl;
  }
}

Measured memory_bytes: 1328
#include<iostream>
#include<cstring>
#include<math.h>
#include<algorithm>
#define ll long long
using namespace std;
int main(){
	ll n,k;
	cin>>n>>k;
	if(n==k){
		cout<<0<<endl;
	}else if(n>k){
		ll num=n-k;
		ll t=num%k;
		n=t;
		if(n<=floor(k*1.0/2)){
			cout<<n<<endl;
		}else{
			cout<<k-n<<endl;
		}
	}else if(n<k){
		if(n<=floor(k*1.0/2)){
			cout<<n<<endl;
		}else{
			cout<<k-n<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    string s; cin >> s;
    int ans = 100100;
    
    for(int i = 0; i < s.size()-2; i++) {
        ans = min(ans, abs(atoi(s.substr(i,3).c_str()) - 753));
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;



template<typename T, int DEFAULT_SIZE=0, int DEFAULT_MOD=0>
struct BIT {
  int n;
  int mod;
  std::vector<T> d;

  BIT(int n=DEFAULT_SIZE, int mod=DEFAULT_MOD) : n(n), mod(mod), d(n+1) {}

  void init(int size) {
      n = size;
      d = std::vector<T>(size);
  }

  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
      if (mod) {
          d[i] %= mod;
      }
    }
  }

  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
      if (mod) {
          x %= mod;
      }
    }
    return x;
  }

  T range(int from, int to) {
      T x = sum(to) - sum(from-1);
      if (mod) {
          x = (x + mod) % mod;
      }
      return x;
  }

  T val(int i) {
      return range(i, i);
  }
};

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

    vector<int> a(N);
    rep(i, N) cin >> a[i];

    vector< BIT<int, 100001, MOD> > dp(N);

    int maxCandies = 0;
    for (int i = N-1; 0 <= i; --i) {
        maxCandies += a[i];
        for (int c = 0; c <= K; ++c) {
            if (maxCandies < c) break;
            if (i == N-1) {
                dp[i].add(c);
            } else {
                dp[i].add(c, dp[i+1].range(c - min(a[i], c), c));
            }
        }

        // rep(k,K+1) {
        //     cout << i << ' ' << k << " => " << dp[i].val(k) << endl;
        // }
    }

    cout << dp[0].val(K) << endl;

    return 0;
}


Measured memory_bytes: 41088
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
using ll = int_fast64_t; using namespace std;

#ifndef __GNUC__
string text =
R"X(8 12 2)X";
stringstream iss{text};
#endif

ll cnt;
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	ll A, B, K; iss >> A >> B >> K;
	for (ll i = min(A, B); i > 0; --i) {
		if ((A % i == 0) && (B % i == 0)) ++cnt;
		if (cnt == K) {
			cout << i << "\n";
			return 0;
		}
	}
}

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

int main()
{
    vector<int> A = {5, 7, 5, 7, 7};
    while (true)
    {
        int N;
        cin >> N;
        if(N == 0)return 0;

        vector<int> S(N);
        rep(i, N)
        {
            string tmp;
            cin >> tmp;
            S[i] = tmp.size();
        }

        rep(i, N)
        {
            int now = i;
            bool flag = true;
            rep(j, 5)
            {
                int sum = 0;
                while(true)
                {
                    sum += S[now];
                    now++;
                    if(A[j] < sum)
                    {
                        flag = false;
                        break;
                    }
                    else if (sum == A[j]) {
                        break;
                    }
                    
                }
                if (!flag) {
                    break;
                }
                
            }

            if (flag) {
                cout << (i + 1) << "\n";
                break;
            }
            
        }
    }
}



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

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

	cout << (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0] ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256
def solve(x, y)
	t=0
	if x<y
		if y==0
			t=-x
		elsif x>=0 && y>=0
			t=y-x
		elsif x<0 && y>=0
			y=-y
			t= x<y ? y-x+1 : x-y+1
		elsif x<0 && y<0
			t=y-x
		end
	elsif x>y
		if y==0
			t=x+1
		elsif x>=0 && y>=0
			t=x-y+2
		elsif x>=0 && y<0
			y=-y
			t= x<y ? y-x+1 : x-y+1
		elsif x<0 && y<0
			x=-x
			y=-y
			t= x<y ? y-x+2 : x-y+2
		end
	elsif x==y
		t=0
	end
	p t
end

if __FILE__==$0
	data=gets.strip.split(" ").map(&:to_i)
	solve(data[0],data[1])
end

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 int n, f=0;
 cin >> n;
 for(int i=1;i<10;i++){
   if(n%i==0&&(n/i)<10){
     cout << "Yes";
     f=1;
     break;
   }
 }
  if(f==0) cout << "No";
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n:usize,
        mut bottuns: [(usize, usize); n],
    }
    let mut ans = 0;
    for i in 0..n {
        let amari = (bottuns[n - 1 - i].0 + ans) % bottuns[n - 1 - i].1;
        if amari != 0 {
            ans = ans + bottuns[n - 1 - i].1 - amari;
        }
    }
    println!("{}", ans);
}


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

int main() {
	int seg[]{
		0b0111111,
		0b0000110,
		0b1011011,
		0b1001111,
		0b1100110,
		0b1101101,
		0b1111101,
		0b0100111,
		0b1111111,
		0b1101111
	};
	int n;
	while (cin >> n, ~n) {
		int now = 0;
		rep(i, n) {
			int j; cin >> j;
			cout << bitset<7>(seg[j] ^ now) << endl;
			now = seg[j];
		}
	}
}

Measured memory_bytes: 3000
#include<bits/stdc++.h>
using namespace std;
int dp[2][395][395];
int main(){
  int n;
  cin>>n;
  vector<int> s(n),l(n),p(n);
  for(int i=0;i<n;i++){
    cin>>s[i]>>l[i]>>p[i];
  }
  fill_n(**dp,2*395*395,-1);
  dp[0][0][0]=0;
  for(int i=0;i<n;i++){
    int ii=i%2;
    int ni=(i+1)%2;
    for(int j=0;j<395;j++)
      for(int k=j;k<395;k++)
	dp[ni][j][k]=-1;

    for(int j=0;j<395;j++){
      for(int k=j;k<395;k++){
	if(dp[ii][j][k]==-1)continue;
	dp[ni][j][k]=max(dp[ni][j][k],dp[ii][j][k]);
	int nj=min(394,j+s[i]);
	int nk=min(394,k+l[i]);
	dp[ni][nj][nk]=max(dp[ni][nj][nk],dp[ii][j][k]+p[i]);
	dp[ii][nj][nk]=max(dp[ii][nj][nk],dp[ii][j][k]+p[i]);
      }
    }
  }
  int m;
  cin>>m;
  vector<int> ans;
  int f=0;
  for(int i=0;i<m;i++){
    int w;
    cin>>w;
    int ma=-1;
    for(int j=0;j<395;j++)
      for(int k=j;k<395;k++){
	if(j<=w&&w<=k)ma=max(dp[n%2][j][k],ma);
      }
    if(ma==-1)f=1;
    ans.push_back(ma);
  }
  if(f)cout<<-1<<endl;
  else for(int i=0;i<m;i++)cout<<ans[i]<<endl;
  return 0;
}



Measured memory_bytes: 4368
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(M);
    vector<pair<pii, int>> segs(M);
    rep(i, 0, M) {
        int l, r, c;
        cin >> l >> r >> c;
        l--, r--;
        segs[i] = {{l, r}, c};
    }
    sort(all(segs));

    dump(segs);

    heap<pair<int, int>> overwrap;
    int idx = 0;
    vector<int> C(M, INF);
    vector<int> dist(N, INF);
    dist[0] = 0;
    multiset<int> cost;

    rep(i, 0, N) {
        while (sz(overwrap) && overwrap.top().first < i) {
            auto itr = cost.find(C[overwrap.top().second]);
            assert(itr != cost.end());
            cost.erase(itr);
            overwrap.pop();
        }
        
        if (i > 0) {
            if (cost.empty()) dist[i] = INF;
            else dist[i] = *cost.begin();
        }

        while (idx < sz(segs) && segs[idx].first.first == i) {
            overwrap.emplace(segs[idx].first.second, idx);
            C[idx] = min(INF, dist[i] + segs[idx].second);
            cost.insert(C[idx]);
            idx++;
        }
    }
    if (dist[N - 1] == INF) cout << -1 << endl;
    else cout << dist[N - 1] << endl;
    return (0^_^0);
}



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

using namespace std;

int main(){
    string S;
    cin >> S;
    int k,total = 0;
    k = S.length();
    for(int i = 0;i < k;++i){
        if(S[i] == 'o')++total;
    }
    if(7 - k + total >= 0){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
#define diup(v,a,k) distance((v).begin(),(k)+upper_bound((v).begin(),(v).end(),(a)))
#define dilo(v,a,k) distance((v).begin(),(k)+lower_bound((v).begin(),(v).end(),(a)))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};

struct D21{
  int is,js;
  D21(int isize,int jsize){
    is = isize;
    js = jsize;
  }
  int operator()(int i,int j){
    return i*js+j;
  }
};


void Main(){
  ll h;
  cin>>h;
  ll ans=0;
  ll m = 1;
  while(h){
    ans+=m;
    m*=2;
    h/=2;
  }
  cout<<ans<<endl;
} int main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<string, int> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}


int main()
{
	ios_base::sync_with_stdio(false);
	ll a,b,c,n, ret = 0;
	string s;
	cin >> a;
	ll l = 0, r = 0;
	REP(i,1, a+1) {
		if (i % 2 == 1) l++;
		else r++;
	}
	cout << l*r << endl;
	return 0;
}

Measured memory_bytes: 256
// list(map(int, input().rstrip().split()))
//' '.join(map(str, res)) 

#include<bits/stdc++.h>
#include<stdio.h> //per fare input output con scanf and printf
#include<stdlib.h> //per fare qsort e bsearch
#include<string.h> // per fare strcpy(sarrivo, spartenza) strcat(str, aggiungo) strcmp(a,b) che da 0 se sono uguali
#include<math.h>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
 
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector <ll> 
#define pi pair <int, int>
#define binary(v, el) binary_search((v).begin(), (v).end(), (el))
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(n, t) get<(n)>((t)) // get element of a tuple
#define F first
#define S second
#define input(type, n) type n; cin >> n
#define FORN(n) for (ll i=0;i<(n); i++)
#define print(x) cout << x << endl
#include <iomanip>      // std::setprecision



struct missione {
        int s;
        int g;
    };
missione v[1000000];
 
bool Ordina (missione a, missione b) {
    return a.s < b.s;    
}

int main () {
    priority_queue<int>  q;
    int N,M;
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        int a,b;
        cin >> a >> b;
        v[i].s = a;
        v[i].g = b;
    }
    int res = 0;
    sort(v,v+N,Ordina);
    int i = 0;
    for (int j = 1; j <= M; ++j) {
        while (v[i].s == j && i < N) {
            q.push(v[i].g);
            ++i;
        }
        if (!q.empty()) {
            res += q.top();
            q.pop();
        }
    }    
    cout << res;
}

Measured memory_bytes: 1660
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    int n; cin >> n;
    vector<lint> v; rep(i, n){ lint x; cin >> x; v.push_back(x); }
    rep(i, n){
        if(i == 0) continue;
        v[i] += v[i-1];
    }

    int l = 0, r = 2; lint res = LLONG_MAX - 1;
    for(int i = 1; i < n - 2; i++){
        while(l < i - 1){
            lint d1 = abs(v[i]-v[l]*2);
            lint d2 = abs(v[i]-v[l+1]*2);
            if(d1 > d2) l++;
            else break;
        }
        while(r < n - 1){
            lint d1 = abs(v[n-1]-v[r]*2+v[i]);
            lint d2 = abs(v[n-1]-v[r+1]*2+v[i]);
            if(d1 > d2) r++;
            else break;
        }
        lint g1 = v[l], g2 = v[i]-v[l], g3 = v[r]-v[i], g4 = v[n-1]-v[r];
        lint m = min(g1, min(g2, min(g3, g4))), M = max(g1, max(g2, max(g3, g4)));
        res = min(res, M - m);
    }
    cout << res << endl;
}

Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int main(void){
    int h,w;
    cin >> h >> w;
    char s[55][55];
    for(int i = 1;i < h+1;i++){
        for(int j = 1;j < w+1;j++)cin >> s[i][j];
    }
    bool flg = false;
    for(int i = 1;i < h+1;i++){
        for(int j = 1;j < w+1;j++){
            if(s[i][j] == '#' && s[i-1][j] != '#' && s[i+1][j] != '#' &&s[i][j-1] != '#' &&s[i][j+1] != '#')
            flg = true;
        }
    }
    if(flg)cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
N,M,X=map(int,input().split())
g=[[]for i in range(N)]
for i in range(N):
  A=list(map(int,input().split()))
  g[i]=A

c=[]
for i in range(2**N):
  cost=0
  point=[0 for i in range(M)]
  i=format(i,'b')
  i=i.rjust(N,'0')
  for j in range(N):
    if i[j]=='1':
      cost+=g[j][0]
      for k in range(M):
        point[k]+=g[j][k+1]
        
    if all(i>=X for i in point):
      c.append(cost)
if c==[]:
  print(-1)
else:
  print(min(c))

Measured memory_bytes: 9952
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main()
{
    int n, maxw;
    cin >> n >> maxw;
    vector<long long> dp(maxw + 1, 0), ddp(maxw + 1, 0);
    for (int i = 0; i < n; i++) {
        int w, v;
        cin >> w >> v;
        for (int i = 0; i + w <= maxw; i++) {
            dp[i + w] = max(ddp[i + w], ddp[i] + v);
        }
        ddp = dp;
    }
    cout << dp[maxw] << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;typedef vector<int> ivec;typedef vector<string> svec;

int main(){
	int A,B,C;
	cin >> A >> B >> C;
	int ans = A+B+C+max(A,max(B,C))*9;
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iostream>
#include<map>
#include<string>
#include<bitset>

#define maxn 5005
#define MOD 1000000007

using namespace std;

inline long long getint()
{
	long long num=0,flag=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
	return num*flag;
}

int n;
int fir[maxn],nxt[maxn<<1],to[maxn<<1],cnt;
int f[maxn][maxn],g[maxn],tmp[maxn];
int sz[maxn];

inline void newnode(int u,int v)
{to[++cnt]=v,nxt[cnt]=fir[u],fir[u]=cnt;}

inline void dfs(int u,int fa)
{
	sz[u]=1;f[u][1]=1;
	for(int i=fir[u];i;i=nxt[i])if(to[i]!=fa)
	{
		int v=to[i];dfs(v,u);
		for(int j=0;j<=sz[u]+sz[v];j++)tmp[j]=0;
		for(int j=1;j<=sz[u];j++)for(int k=0;k<=sz[v];k++)
			tmp[j+k]=(tmp[j+k]+1ll*f[u][j]*f[v][k])%MOD;
		sz[u]+=sz[v];
		for(int j=1;j<=sz[u];j++)f[u][j]=tmp[j];
	}
	for(int i=2;i<=sz[u];i+=2)f[u][0]=(f[u][0]+MOD-1ll*f[u][i]*g[i]%MOD)%MOD;
}

int main()
{
	n=getint();
	for(int i=1;i<n;i++)
	{
		int u=getint(),v=getint();
		newnode(u,v),newnode(v,u);
	}
	g[0]=1;
	for(int i=2;i<=n;i+=2)g[i]=1ll*g[i-2]*(i-1)%MOD;
	dfs(1,0);
	printf("%d\n",MOD-f[1][0]);
}

Measured memory_bytes: 58464
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long h1,m1,h2,m2,ans=0,k;
    cin>>h1>>m1>>h2>>m2>>k;
    ans+=abs(h1-h2)*60;
    ans-=m1;
    ans+=m2;
    ans-=k;
    if(ans<0)
    {
        ans=0;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

struct Edge{
    ll t,w;
    Edge(){}
    Edge(ll t,ll w) : t(t),w(w){};
};

vector<Edge> G[MAX];
ll n,d[MAX];

void bfs(ll s){
    rep(i,n) d[i]=LLINF;
    queue<ll> que;
    que.push(s);
    d[s]=0;
    ll u;
    while(!que.empty()){
        u=que.front();
        que.pop();
        rep(i,G[u].size()){
            Edge e=G[u][i];
            if(d[e.t]==LLINF){
                d[e.t]=d[u]+e.w;
                que.push(e.t);
            }
        }
    }
}

void Diameter(){
    bfs(0);
    ll maxv=0,target=0;
    rep(i,n){
        if(d[i]==LLINF) continue;
        if(maxv<d[i]){
            maxv=d[i];
            target=i;
        }
    }
    bfs(target);
    maxv=0;
    rep(i,n){
        if(d[i]==LLINF) continue;
        maxv=max(maxv,d[i]);
    }
    cout<<maxv<<endl;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll s,t,w;
    cin>>n;
    rep(i,n-1){
        cin>>s>>t>>w;
        G[s].push_back(Edge(t,w));
        G[t].push_back(Edge(s,w));
    }
    Diameter();
    return 0;
}



Measured memory_bytes: 21528
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int n;
  cin >> n;
  vector<ld> t(n + 3), v(n + 2);
  t[0] = t[1] = 0, v[0] = 0;
  rep(i, n)
  {
    int ti;
    cin >> ti;
    t[i + 2] = t[i + 1] + ti;
  }
  rep(i, n) cin >> v[i + 1];
  t[n + 2] = t[n + 1], v[n + 1] = 0;

  ld Min[40010];
  fill(Min, Min + 40010, INF);
  rep(i, n + 2)
  {
    int l = t[i] * 2, r = t[i + 1] * 2;
    for (int ii = l; ii <= r; ii++)
    {
      Min[ii] = min(Min[ii], v[i]);
    }
    for (int ii = l, j = 0; ii >= 0; ii--, j++)
    {
      Min[ii] = min(Min[ii], v[i] + 0.5 * (ld)j);
    }
    for (int ii = r, j = 0; ii <= 40005; ii++, j++)
    {
      Min[ii] = min(Min[ii], v[i] + 0.5 * (ld)j);
    }
  }
  ld sum = 0;
  rep(i, t[n + 2] * 2)
  {
    sum += (Min[i] + Min[i + 1]) / 4.0;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N, M);
  vector<vector<pll>> v(N);
  rep(i, 0, M) {
    VAR(ll, P, Y);
    v[P - 1].push_back(pll(Y, i));
  }
  vector<pll> anss(M);
  rep(i, 0, N) {
    sort(all(v[i]));
    rep(j, 0, (int)v[i].size()) {
      anss[v[i][j].second] = pll(i + 1, j + 1);
    }
  }
  each(x, anss) {
    printf("%06lld%06lld\n", x.first, x.second);
  }
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pii pair<int, int>
#define vii vector<pii>
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vd vector<double>
#define vvi vector< vector<int> >
#define vvii vector< vector< pii > >
#define ld long double
#define mapii map<int, int>
#define mapsi map<string, int>
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pie  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-8)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'
#define output freopen("output.txt", "w", stdout)
#define mp(x, y, z) {x, {y, z}}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    int temp = 0;
    temp = temp*10 + a;
    temp = temp*10 + b;
    temp = temp*10 + c;
    if (temp%4 == 0) cout << "YES";
    else cout << "NO";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

string s;
int main() {
  cin >> s;

  int ans[26];
  rep(i, 26) {
    ans[i] = 0;
  }
  auto n = s.size();
  rep(i, n) {
    ans[s.at(i) - 'a']++;
  }

  rep(i, 26) {
    if (ans[i]%2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, N;
    cin >> H >> W >> N;
    int x = max(W, H);
    cout << (N + x - 1) / x << endl;
    return 0;
}

Measured memory_bytes: 892
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		String s=scanner.next();
		int[] a=new int[s.length()];
		for(int i=0;i<s.length();i++) {
			char c=s.charAt(i);
			if(c=='g')a[i]=0;
			else a[i]=1;
		}
		int sc=0;
		for(int i=0;i<s.length();i++) {
			if(i%2==a[i])sc+=0;
			else if(i%2>a[i])sc+=1;
			else sc-=1;
		}
		System.out.println(sc);
	}
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 22356
n = gets.chomp.to_i
cards = gets.chomp.split(' ').map do |str|
  suit, value = str.split('')
  card = { suit: suit, value: value.to_i }
end

def print_cards(cards)
  cards_str = cards.map do |card|
    card[:suit] + card[:value].to_s
  end
  puts cards_str.join(' ')
end

def bubble_sort(cards)
  (0..(cards.length - 1)).each do |i|
    ((cards.length - 1)).downto(i + 1) do |j|
      if cards[j - 1][:value] > cards[j][:value]
        cards[j - 1], cards[j] = cards[j], cards[j - 1]
      end
    end
  end

  cards
end


def selection_sort(cards)
  (0..(cards.length - 1)).each do |i|
    minj = i
    (i..(cards.length - 1)).each do |j|
      if cards[j][:value] < cards[minj][:value]
        minj = j
      end
    end
    cards[i] , cards[minj] = cards[minj], cards[i]
  end

  cards
end



bubble_sort = bubble_sort(cards.dup)
print_cards(bubble_sort)
puts 'Stable'

selection_sort = selection_sort(cards.dup)
print_cards(selection_sort)
puts bubble_sort == selection_sort ? 'Stable' : 'Not stable'



Measured memory_bytes: 6908