akhauriyash/Code-Regression huggingface dataset:
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val x = in.readLine().toInt

    def divisors(x: Int): List[Int] = {
      val limit = Math.sqrt(x).toInt + 1

      @tailrec
      def inner(ds: List[Int], i: Int): List[Int] = {
        if (i < limit) {
          if (x % i == 0) {
            if (x / i == i) {
              inner(i :: ds, i + 1)
            } else {
              inner(i :: x / i :: ds, i + 1)
            }
          } else {
            inner(ds, i + 1)
          }
        } else {
          ds
        }
      }

      inner(Nil, 1)
    }

    val ambs = divisors(x).sorted

    def findAB(amb: Int): Option[(Int, Int)] = {
      val target = x / amb

      for (a <- -118 to 119) {
        val b = a - amb
        val f = a * a * a * a + a * b * b * b + a * a * a * b + a * a * b * b + b * b * b * b
        if (f == target) {
          return Some(a, b)
        }
      }
      None
    }

    @tailrec
    def findFirstAB(ambs: List[Int]): (Int, Int) = {
      ambs match {
        case amb :: rest =>
          findAB(amb) match {
            case Some((a, b)) => (a, b)
            case None => findFirstAB(rest)
          }
        case Nil =>
          throw new Error()
      }
    }

    out.println(findFirstAB(ambs) match {
      case (a, b) => s"${a} ${b}"
    })

    out.flush()
  }
}


Measured memory_bytes: 54604
while True:
    price = int(input())
    change = 1000 - price
    n = 0
    if price == 0:
        break
    if change >= 500:
        change -= 500
        n += 1
    while change >= 100:
        change -= 100
        n += 1
    if change >= 50:
        change -= 50
        n += 1
    while change >= 10:
        change -= 10
        n += 1
    if change >= 5:
        change -= 5
        n += 1
    while change >= 1:
        change -= 1
        n += 1
        
    print(n)


Measured memory_bytes: 5584
#include<iostream>
using namespace std;
int GCD(int a,int b)
{int c,d;
if(a<b)
{d=a;
 a=b;
 b=d;
}
 while(b!=0)
 {c=a%b;a=b;b=c;
 }
 return a;
}
int LCM(int a,int b)
{
 return a/GCD(a,b)*b;
}
int main()
{int a,b;
 while(cin>>a>>b)
 {cout<<GCD(a,b)<<" "<<LCM(a,b)<<endl;
 }
 return 0;
}

Measured memory_bytes: 2980
from sys import stdin
S = (stdin.readline().rstrip())
dp = [[0]*13 for i in range(len(S)+1)]
MOD = 10**9+7
 
S = list(reversed(S))
dp[0][0] = 1
 
t = 1
for i, c in enumerate(S, 1):
    for j in range(13):
        if c == "?":
            for k in range(10):
                nj = (k*t+j) % 13
                dp[i][nj] = dp[i][nj] + dp[i-1][j]
                dp[i][nj] %= MOD
        else:
            nj = (int(c)*t+j) % 13
            dp[i][nj] = dp[i][nj] + dp[i-1][j]
            dp[i][nj] %= MOD
    t = (t*10)%13
print(dp[-1][5])

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;

int friends[maxn], enemy[maxn];

struct dsu
{
    int rep[maxn];
    long long sz[maxn];

    void init(int n)
    {
        for(int i = 1 ; i <= n; i++)
        {
            rep[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x)
    {
        return rep[x] = (rep[x] == x ? x : find(rep[x]));
    }

    void unio(int x, int y)
    {
        x = find(x);
        y = find(y);

        if(x != y)
        {
            if(sz[x] < sz[y])
                swap(x,y);
            rep[y] = x;
            sz[x] += sz[y];
        }
    }

    bool isSame(int u, int v)
    {
      return find(u) == find(v);
    }
}d;

int main()
{
  ios::sync_with_stdio(0);
  int n,m,k;
  cin >> n >> m >> k;
  d.init(n);
  for(int i = 0; i < m ; i++)
  {
    int u, v;
    cin >> u >> v;
    friends[u]++;
    friends[v]++;
    d.unio(u, v);
  } 


  for(int i = 0; i < k ; i++)
  {
    int u, v;
    cin >> u >> v;
    if(d.isSame(u, v))
    {
      enemy[u]++;
      enemy[v]++;
    }
  } 

  for(int i = 1 ; i <= n ; i++)
  {
    int val = d.sz[d.find(i)] - friends[i] - enemy[i] - 1;
    cout << val << ' ';
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 2816
#include<iostream>
using namespace std;
int main(){
  string s;
  int n,x,i;
  cin>>n>>s;
  n%=26;
  int l=s.length();
  for(i=0;i<l;++i){
  	x=s[i]-'A';
    x+=n;
    x%=26;
    s[i]='A'+x;
  }
  cout<<s;
  return 0;
}

Measured memory_bytes: 256
import math
A, B = map(int, input().split())
candidate_a = []
candidate_b = []

def candidate(tax, tax_rate, candidate):
  candidate.append(math.ceil(tax / tax_rate))
  i = candidate[0] + 1
  while tax == math.floor(i * tax_rate):
    candidate.append(i)
    i += 1

candidate(A, 0.08, candidate_a)
candidate(B, 0.1, candidate_b)

if candidate_a[0] <= candidate_b[0]:
  if candidate_a[-1] >= candidate_b[0]:
    print(candidate_b[0])
  else: 
    print(-1)
else:
  if candidate_b[-1] >= candidate_a[0]:
    print(candidate_a[0])
  else:
    print(-1) 

Measured memory_bytes: 9076
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b, c;
    scanf("%d %d %d",&a,&b,&c);
    if (c>=a && c<=b)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    ll n = s.size();
    vvl nxt(n+1, vl(26, n));
    rrep(i,n){
        rep(j, 26){
            nxt[i][j] = nxt[i+1][j];
        }
        nxt[i][s[i] - 'a'] = i;
    }

    debug(nxt[0]);
    vector<ll> dp(n+2);
    dp[n] = 1;
    rrep(i,n){
        ll t = INF;
        rep(j,26){
            chmin(t, dp[nxt[i][j] + 1]);
        }
        dp[i] = t + 1;
    }


    debug(dp);

    string ans;
    ll id = 0;
    while(id < n){
        ll t = dp[id];
        rep(j,26){
            if(dp[nxt[id][j] + 1] == t - 1){
                ans += 'a' + j;
                id = nxt[id][j] + 1;
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 50452
use std::io;

fn main() {
    let mut a = String::new();
    let mut b = String::new();
    let mut c = String::new();
    let mut x = String::new();

    io::stdin().read_line(&mut a).expect("panic read line");
    io::stdin().read_line(&mut b).expect("panic read line");
    io::stdin().read_line(&mut c).expect("panic read line");
    io::stdin().read_line(&mut x).expect("panic read line");

    let a: i32 = a.trim().parse().unwrap();
    let b: i32 = b.trim().parse().unwrap();
    let c: i32 = c.trim().parse().unwrap();
    let x: i32 = x.trim().parse().unwrap();

    let mut count = 0;
    for i in 0..a+1 {
        for j in 0..b+1 {
            for k in 0..c+1 {
                let amount = 500 * i + 100 * j + 50 * k;
                if amount == x {
                    count += 1;
                }
            }
        }
    }

    println!("{}", count)
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    vector<long double> p(N);
    rep(i, N) cin >> p[i];

    // 状態 (i,j) : i 枚コインを投げて，j 枚 表面がでた状態
    // per(i,j) : 状態(i,j) となる確率
    vector<vector<long double>> per(N + 1, vector<long double>(N + 1, 0));
    // ddump(per);
    per[0][0] = 1;

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            if (0 <= j - 1) per[i][j] += per[i - 1][j - 1] * p[i - 1];
            per[i][j] += per[i - 1][j] * (1 - p[i - 1]);
        }
    }

    // ddump(per);

    long double ans = 0;
    for (int i = 0; i <= N; i++) {
        if (i > N / 2) ans += per[N][i];
    }
    cout << setprecision(10) << ans << endl;

    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];

ll gcd(ll a, ll b) {
    if (a < b)
        swap(a, b);
    ll c = a % b;
    if (c == 0)
        return b;
    return gcd(b, c);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, X;
    cin >> N >> X;
    REP(i, N) {
        cin >> A[i];
    }
    sort(A, A + N);
    ll ans = abs(A[0] - X);
    REP(i, N - 1) {
        ans = gcd(ans, abs(A[i] - A[i + 1]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
signed main() {
	int n, p = 1, ans = 0, a; cin >> n;
	for0(i, n) {
		cin >> a;
		if (p == a) p++;
		else ans++;
	}
	if (ans == n)cout << "-1\n";else
	cout << ans << endl;
}

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

 typedef struct{
   int parent;
   int left;
   int right;
 }Node;

int main(){
  int n, id, k, depth, a, i, j, b, c;
  Node *T;

  scanf("%d", &n);

  T = malloc(sizeof(Node)*n);

  for(i = 0; i < n; i++){
    T[i].parent = -1;
    T[i].left = -1;
    T[i].right = -1;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d", &id, &k);

    for(j = 0; j < k; j++){
      scanf("%d", &a);
      T[a].parent = id;

      if(j == 0)
	T[id].left = a;
      else if(j > 0)
	T[b].right = a;

      b = a;
    }
  }

  for(i = 0; i < n; i++){
    depth = 0;
    c = T[i].parent;

    while(c != -1){
      c = T[c].parent;
      depth++;
    }
    if(depth == 0)
      printf("node %d: parent = -1, depth = 0, root, [", i);
    else if(T[i].left == -1)
      printf("node %d: parent = %d, depth = %d, leaf, [", i, T[i].parent, depth);
    else
      printf("node %d: parent = %d, depth = %d, internal node, [", i, T[i].parent, depth);

    c = T[i].left;
    if(c != -1)
      printf("%d", c);

    while(c != -1){
      c = T[c].right;
      if(c != -1)
	printf(", %d", c);
    }
    printf("]\n");
  }
  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    sum += min(2 * x, 2 * abs(K - x));
  }
  cout << sum << endl;
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

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

    string t = s;
    sort(ALL(t));
    set<char> cs;
    for (const char c : t) {
        cs.insert(c);
    }
    
    set<string> ss;
    for (const char c : cs) {
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == c) {
                for (int j = 1; j <= min(5, (int)s.size() - i); j++) {
                    ss.insert(s.substr(i, j));
                }
            }
        }
        if (ss.size() >= 5) {
            break;
        }
    }

    for(auto i = ss.begin(); i != ss.end(); i++){
        k--;
        if (k == 0) {
            cout << *i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define FFOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

int gcd(int a, int b) {return b?gcd(b,a%b):a;}

signed main(){
	
	int n;cin>>n;
	
	int le=1;
	int ri = 1e7;
	
	while(ri-le>1)
	{
		int mid = (ri+le)/2;
		int wa = mid*(mid+1)/2;
		if(wa>=n) ri = mid;
		else le =mid;
	}
	
	int wa = ri*(ri+1)/2;
	FOR(i,1,ri) if(i != wa-n) cout << i << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c=0;
  cin>>a>>b;
  if(a!=b){
    c=max(a,b);
    cout<<c+c-1<<'\n';
  }
  else{
    cout<<a*2<<'\n';
  }
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main()
{
    while(true){
        int n;
        int ans = 0;
        cin >> n; 
        if(n == 0){
            break;
        }
        int c = 1000 - n;
        if(c >= 500){
            c -= 500;
            ans++;
        }
        if(c >= 100){
            ans += c/100;
            c %= 100;
        }
        if(c >= 50){
            ans += c/50;
            c %= 50;
        }
        if(c >= 10){
            ans += c/10;
            c %= 10;
        }
        if(c >= 5){
            ans += c/5;
            c %= 5;
        }
        ans += c;
        cout << ans << endl;
    }
}


Measured memory_bytes: 2972
package main

import "fmt"

func main() {
	var A, s, C string
	fmt.Scan(&A, &s, &C)

	A = string([]rune(A)[0:1])
	s = string([]rune(s)[0:1])
	C = string([]rune(C)[0:1])

	ans := A + s + C

	fmt.Println(ans)

}


Measured memory_bytes: 1776
#define X (x-P>0?x-P:P-x)
#define Y (y-Q>0?y-Q:Q-y)
#define N (P<x?1:-1)
#define M (Q<y?1:-1)
#define p(x,y) (A[++S]=x,B[S]=y) 
long t,k,x,y,P,Q;int S,i=1,A[1<<20],B[1<<20];main(){scanf("%ld%ld%ld",&k,&x,&y);!(k&1)&&(x+y&1)&&(exit(puts("-1")&0),0);while(X+Y>k*2)X>k?(P+=k*N):(Q+=k*M),p(P,Q);if(X+Y!=k){(k%2&&(X+Y)%2)&&(Y<=k?(P+=(k-Y)*N,Q=y):(Q+=(k-X)*M,P=x),p(P,Q));t=k*2-X-Y>>1,X<Y?p(x+t*N,Q+(k-X-t)*M):p(P+(k-Y-t)*N,y+t*M);}p(x,y),printf("%d\n",S);for(;i<=S;)printf("%d %d\n",A[i++],B[i]);}

Measured memory_bytes: 4864
#include<stdio.h>
int main(){
  
  int sum=0;
  int a=0,b=0;
  scanf("%d %d", &a,&b);
  sum = a+b;
  if (sum > 23){
       printf("%d",sum-24);
  }else{
    printf("%d",sum);
  }
  
 return 0; 
}

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

using namespace std;
using ll = long long;


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

    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        hen[a]++;
        hen[b]++;
    }
    for(auto i : hen)cout << i << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
#include <iomanip>

using pa2 = std::pair<long long, long long>;

constexpr double PI = 3.141592653589793238;

int main() {
    int N;
    std::cin >> N;
    std::vector<int> x,y;
    for (int i = 0; i < N; ++i) {
        int tmp;
        std::cin >> tmp;
        x.push_back(tmp);
        std::cin >> tmp;
        y.push_back(tmp);
    }
    std::vector<long long> p(N,0);
    long long m = 5000000;
    for (int j = 0; j < m; ++j) {
        double ml = -1e200;
        int pos = 0;
        double theta = 2.*PI * j /m;
        for (int i = 0; i < N; ++i) {
            double s = std::sin(theta)*x[i] + std::cos(theta)*y[i];
            if(ml < s){
                pos = i;
                ml = s;
            }
        }
        p[pos]++;
    }
    for (auto &&item : p) {
        double an = item;
        an /= m;
        std::cout << std::setprecision(16) << an << '\n';
    }
}

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

int main(){
	int n,m;
	int h[1501] = {},w[1501] = {};
	vector<int> sum;
	while(1){
		cin >> n >> m;
		if(!n && !m) break;
		for(int i = 0;i < n;i++) {
			cin >> h[i + 1];
			h[i + 1] += h[i];
		}
		for(int i = 0;i < m;i++) {
			cin >> w[i + 1];
			w[i + 1] += w[i];
		}
		for(int i = 0;i <= n;i++){
			for(int j = i + 1;j <= n;j++){
				sum.push_back(h[j] - h[i]);
			}
		}
		sort(sum.begin(),sum.end());
		int cnt = 0;
		for(int i = 0;i <= m;i++){
			for(int j = i + 1;j <= m;j++){
				cnt += upper_bound(sum.begin(),sum.end(),w[j] - w[i]) - lower_bound(sum.begin(),sum.end(),w[j] - w[i]);
			}
		}
		cout << cnt << endl;
		sum.clear();
	}
	return 0;
}

Measured memory_bytes: 11196
import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;

const int INF = 100000000;
int[21][21] map;
int n;
int ans;

bool check(int x,int u){
    int count;
    for(int i=1;i<=n;i++)
	if(map[x][i] > 0 && (u&(1<<i))==0) count++;
    if(count == 1) return true;
    else return false;
}

int saiki(int pos,int u,int v,int us){

    us |= 1<<pos;

    if(v > ans) return INF;
    int res = INF;
    int count;
    bool flg = true;
    for(int i=1;i<=n;i++){
	if(map[pos][i] > 0 && (u&(1<<i)) == 0 ){
	    if(check(i,u)){
	       	u |= 1<<i;
		flg = false;
	    }
	}
    }
    for(int i=1;i<=n;i++){
	if( (u&(1<<i)) != 0 ) count++;
    }
    if(count == n-1) {
	ans = min(ans,v);
	return v;
    }
    for(int i=1;i<=n;i++){
	if( (u&(1<<i)) == 0 && map[pos][i] > 0){
	    if(flg && (us&(1<<i))!=0 ) continue;
	    res = min(res,saiki(i,u,v+map[pos][i],us) );
	}
    }
    return res;
}

void main(){

    while(true){
	n = readln().chomp().to!int;
	ans = INF;
	map = new int[21][21];
	if(n==0) break;
	for(int i=0;i<n-1;i++){
	    auto s = readln().split().to!(int[]);
	    map[s[0]][s[1]] = s[2];
	    map[s[1]][s[0]] = s[2];
	}
	writeln(saiki(1,0,0,0));
    }
}

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

int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    ll tot=0;
    for(ll i=1;i<n;i++)
    {
        if(arr[i-1]>arr[i])
        {
            tot += arr[i-1]-arr[i];
            arr[i]=arr[i-1];
        }
    }
    cout<<tot<<endl;
}


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

#define rep(name, times) for (int name = 0, until##name = (times); name < until##name; name++)
#define repr(name, times) for (int name = (times)-1; name >= 0; name--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;

struct segtree {
  int n, h; vector<int> data, d;
  segtree(int n): n(n), h(32 - __builtin_clz(n)), data(n<<1), d(n) { }
  void apply(int p, int x) {
    data[p] += x;
    if (p < n) d[p] += x;
  }
  void build(int p) {
    for (; p > 1; p >>= 1) data[p>>1] = min(data[p], data[p^1]) + d[p>>1];
  }
  void push(int p) {
    repr(i, h) {
      int q = p >> (i+1);
      if (not d[q]) continue;
      apply(q<<1, d[q]);
      apply(q<<1|1, d[q]);
      d[q] = 0;
    }
  }
  void update(int l, int r, int x) {
    int l0 = l, r0 = r;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l&1) apply(l++, x);
      if (r&1) apply(--r, x);
    }
    build(l0+n); build(r0+n-1);
  }
  int query(int l, int r) {
    l += n; r += n;
    push(l); push(r-1);
    int res = numeric_limits<int>::max();
    for (; l < r; l >>= 1, r >>= 1) {
      if (l&1) res = min(res, data[l++]);
      if (r&1) res = min(res, data[--r]);
    }
    return res;
  }
};

int main() {
  int n,q; scanf("%d%d", &n,&q);
  int c,s,t,x;
  segtree st(n);
  rep(i, q) {
//    cerr << i << endl;
//    rep(i, n+n-1) cerr << st.data[i+1] << " ";
//    cerr << endl;
    scanf("%d", &c);
//    rep(i, n-1) cerr << st.d[i+1] << " ";
//    cerr << endl;
    if (c) {
//      cerr << "#0" << endl;
      scanf("%d%d",&s,&t);
      printf("%d\n", st.query(s,t+1));
    } else {
//      cerr << "#1" << endl;
      scanf("%d%d%d",&s,&t,&x);
//      cerr << s << " " << t << " " << x << endl;
      st.update(s, t+1, x);
    }
  }
}



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

int main()
{
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if( (x+r) <= W && (x-r) >= 0 &&  (y+r) <= H && (y-r) >= 0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3104
//abc163B
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  int m, n, k, i, a, cou=0, tmp;
  scanf("%d %d", &n, &m);
  for(i=0; i < m; i++){
    scanf("%d", &a);
    n-=a;
  }
  if(n < 0) printf("-1");
  else printf("%d", n);
  return 0;
}


Measured memory_bytes: 1732
#include<stdio.h>
long long t,tt;
long long a[100001],s[100001];
int b[100001],flg[100001];
int main(void)
{
	int n,q,i,j,c[1000],x;
	scanf("%d %lld %d",&n,&t,&q);
	for(i=1;i<=n;i++){
		scanf("%lld %d",&a[i],&b[i]);
		flg[i]=0;
	}	
	for(i=1;i<=q;i++)	scanf("%d",&c[i]);
	for(i=1;i<n;i++){
		if(b[i]==1&&b[i+1]==2&&a[i+1]-a[i]<t*2){
			flg[i]=1; flg[i+1]=1;
			s[i]=s[i+1]=(a[i]+a[i+1])/2;
		}
	}
	x=0;
	for(i=n;i>=1;i--){
		if(flg[i]==1){
			tt=s[i];	x=1;
		}
		else{
			if(b[i]==1&&x==1&&a[i]+t>tt){
				s[i]=tt;	flg[i]=2;
			}
		}
	}
	x=0;
	for(i=1;i<=n;i++){
		if(flg[i]==1){
			tt=s[i];	x=1;
		}
		else{
			if(b[i]==2&&x==1&&a[i]-t<tt){
				s[i]=tt;	flg[i]=2;
			}
		}
	}
	for(i=1;i<=q;i++){
		if(flg[c[i]]==0){
			if(b[c[i]]==1) s[c[i]]=a[c[i]]+t;
			else s[c[i]]=a[c[i]]-t;
		}
	}	
	for(i=1;i<=q;i++) printf("%lld\n",s[c[i]]);
}

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

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int table[h][w];
    int line = 0, row = 0, ind = 0, even = true;
    while (true) {
        if (line == h) break;
        if (a[ind] == 0) {ind++; continue;}
        if (row == w) {row--; line++; even = !even; continue;}
        if (row == -1) {row++; line++; even = !even; continue;}
        table[line][row] = ind + 1;
        a[ind]--;
        if (even) row++;
        else row--;
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << table[i][j];
            if (j < w - 1) cout << ' ';
        }
        cout << endl;
    }
    return 0;
}

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


int main() {
  int A, B, coin(0);
  cin >> A >> B;
  for (auto idx(0); idx < 2; ++idx) {
    if (A > B) {
      coin += A;
      --A;
    } else {
      coin += B;
      --B;
    }
  }
  cout << coin << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      int N=int.Parse(Console.ReadLine());
    string[] str1=Console.ReadLine().Split(' ');
      string[] dis=str1.Distinct().ToArray();
      if(str1.Length==dis.Length){
        Console.WriteLine("YES");
      }else{
        Console.WriteLine("NO");
      }
     
    }
    
  }

}


Measured memory_bytes: 54392
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define mii map<int,int>
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b)  (x/gcd(x,y))*y
#define inf (long long) 1e18
#define neg_inf (long long) (-1*1e18)
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define rep(i,n)  for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define deb(x) cout << #x << "=" << x <<"\n";
const int N = 1e9 + 7;

int pow(int x, int y) { int res = 1; while (y > 0) { if (y & 1) res = ((res) * (x)); res %= N; y = y >> 1; x = ((x) * (x)); } return res; }
int pow(int x, int y, int p)  {  int res = 1; x = x % p; while (y > 0) {if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;}   return res; }


int dp[3001][3001];
void solve()
{
    string s,t;
    cin>>s>>t;
    int n=sz(s);
    int m=sz(t);
    rep(i,n+1)
    {
        rep(j,m+1)
        {
            dp[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            dp[i][j]=0;
            int tmp=0;
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string ans="\0";
    int i=n,j=m;
    while(i>=1&&j>=1)
    {
        if(s[i-1]==t[j-1])
        {
            ans+=s[i-1];
            i--;
            j--;
        }
        else 
        {
            if(dp[i-1][j]==dp[i][j-1])
            {
                if(i>j)
                    i--;
                else
                    j--;
            }
            else if(dp[i-1][j]>dp[i][j-1])
            {
                i--;
            }
            else
            {
                j--;
            }
        }
    }
    reverse(all(ans));
    cout<<ans;
} 



int32_t main()
{
  // #ifndef ONLINE_JUDGE
 //    freopen("gymnastics.in", "r", stdin);
 //    freopen("gymnastics.out", "w", stdout);
  // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t=1;
    // cin>>t;

   while(t--)
   {
      solve();
   }
}






//code by-Roshan











//unnecessary
// bool cmp(pair<int,int> &a,pair<int,int> &b)
// {
//  if(a.F==b.F)
//    return (a.S<b.S);
//  else 
//    return (a.F<b.F);
//  //< =chota wala pehle
//  //> =chota wala baad me
// }


//better use this structure
// struct s{
//  int a;
//  bool operator <(const s &x) const
//  {
//    return (a>x.a);
//  }
// };



//  priority_queue<int,vector<int>,greater<>> p;(priority queue as min heap)



Measured memory_bytes: 73980
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
const ll INF = 1e18;
signed main(){
    int N; cin >> N;
    vector<string>grid(N);
    for(auto& s : grid) cin >> s;
    vector<vector<ll>>edge(N);
    vector<vector<ll>>dis(N,vector<ll>(N,INF));
    for(int i = 0; i < grid.size(); ++i){
        for(int j = 0; j < grid[i].size(); ++j){
            char c = grid[i][j];
            if(c == '1'){
                edge[i].push_back(j);
                dis[i][j] = 1;
            }
        }
    }
    rep(i,N)dis[i][i] = 0;
    rep(k,N)rep(i,N)rep(j,N) cmin(dis[i][j],dis[i][k]+dis[k][j]);
    vector<ll>d(N,-1);
    bool valid = true;
    function<void(ll,ll)>visitor = [&](ll v,ll crt){
        d[v] = crt;
        for(auto nv : edge[v]){
            if(d[nv] == -1)
                visitor(nv,(not crt));
            else if(d[nv] == d[v])
                valid = false;
        }
    };
    ll root  = 0;
    visitor(root,0);
    if(not valid) return puts("-1") * 0;
    ll ans = 0;
    for(int i = 0; i < dis.size(); ++i)
        cmax(ans, *max_element(dis[i].begin(), dis[i].end()));
    cout << ans + 1 << endl;
    
}




Measured memory_bytes: 1024
// ????????????????????? cl /EHsc bubbleSort.cpp

#include <iostream>
using namespace std;

int bubbleSort(int A[],int N) {
	int sw = 0; // ???????????° 0??§?????????
	bool flag = 1;
	for(int i=0; flag; i++) {
		flag = 0;
		for(int j=N-1;j>=i+1;j--) {
			if(A[j]<A[j-1]) {
				swap(A[j],A[j-1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(void) {
	int A[100], N, sw;
	cin >> N;
	for(int i=0;i<N; i++) cin >> A[i];
	
	sw = bubbleSort(A,N);
	
	for(int i=0;i<N;i++) {
		if(i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;
}

Measured memory_bytes: 3032
#include<cstdio>
#define MAX 10001
#define NIL -1
using namespace std;

struct Node {int parent,left,right;};
Node T[MAX];

void preParse(int u){
    if(u == NIL)return;
    printf(" %d",u);
    preParse(T[u].left);
    preParse(T[u].right);
}
void inParse(int u){
    if(u == NIL)return;
    inParse(T[u].left);
    printf(" %d",u);
    inParse(T[u].right);
}
void postParse(int u){
    if(u == NIL)return;
    postParse(T[u].left);
    postParse(T[u].right);
    printf(" %d",u);
}
int main(){
    int n,p,l,r;
    int root =0;
    scanf("%d",&n);

    for(int i=0;i<n;i++)T[i].parent = NIL;

    for(int i=0;i<n;i++){
        scanf("%d %d %d",&p,&l,&r);
        T[p].left = l;
        T[p].right = r;
        if(l != NIL)T[l].parent = p;
        if(r != NIL)T[r].parent = p;
    }

    for(int i=0;i<n;i++) if(T[i].parent == NIL) root = i;

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");
    return 0;
    }



Measured memory_bytes: 2752
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[51],ans;
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(register int i=1;i<=n;i++)for(register int j=i+1;j<=n;j++)ans+=a[i]*a[j];
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
 
int main() {
    ll N, i;
    ll x = 1;
    ll mod = 1000000007;

  cin >> N;

    for (i = 1; i <= N; ++i)
      (x *= i) %= mod;
    cout << x << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            char[] nums = Console.ReadLine().ToArray();

            int unionCount = 0;

            for (int i = 0; i < nums.Length - 1; i++ )
            {
                if(nums[i] == nums[i + 1])
                {
                    unionCount++;
                }
            }

            Console.WriteLine(nums.Length - unionCount);
            //Console.ReadKey();
        }

    }
}


Measured memory_bytes: 12128
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N = 0, M =0;
    cin(N);cin(M);

    vll S(M), C(M); 
    REP(i,M) cin >> S[i] >> C[i];


    //本文
    REP(i,1000){
        string str = to_string(i);
        if(N!=str.size()) continue;
        bool ok = true;
        REP(j,M){
            ll k = S[j]-1;
            string l = to_string(C[j]);
            char m = l[0];
            if(str[k]!= m){ok = false;break;}
        }
        if(ok){cout << str;return 0;}
    }

    //出力
    cout << -1 << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>string join(const v(T)&v){stringstream s;rep(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<class T>inline ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
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 gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N, A, B;
  cin >> N >> A >> B;

  int ans = min(A*N, B);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
int main ( int argc , char** argv ) {
 	std::string s, t, u;
  	std::cin>>s>>t;
  	int ns , nt;
  	std::cin>>ns>>nt;
  	std::cin>>u;
  	if ( u.compare(s) == 0 ) ns--;
  	else if ( u.compare(t) == 0 ) nt--;
  	else{
    }
  	std::cout<<ns<<" "<<nt<<std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}


const int MAX = 510000;


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main()
{
	ll n,m,k;
	cin >> n >> m >> k;
	ll ans = 0;
	COMinit();
	for(int i = 0;i<=k;i++)
	{
		//n-i個に分けたい
		ll now = m;
		(now *= mod_pow(m-1,n-i-1,MOD))%=MOD;
		(now*=COM(n-1,n-i-1))%=MOD;
		(ans+=now)%=MOD;
		//cout<<now<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 15592
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char s[] = sc.next().toCharArray();
        sc.close();
        Deque<Integer> q = new ArrayDeque<>();
        for (char x : s) {
            if (q.isEmpty()) {
                if (x != 'B') {
                    q.add(x - 48);
                }
            } else if (x == 'B') {
                q.pollLast();
            } else {
                q.add(x - 48);
            }
        }
        for (int i : q) {
            System.out.print(i);
        }
        System.out.println();
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

lli n, m;

int main(void){
	cin >> n >> m;
	vector<pair<lli, lli>> a(m);
	map<pair<lli, lli>, lli> id;
	rep(i, m){
		lli p, y;
		cin >> p >> y;
		a[i] = {p, y};
		id[a[i]] = i;
	}
	sort(a.begin(), a.end());
	vector<string> ans(m);
	lli i = 0;
	while(i < m){
		lli num = a[i].first;
		lli od = 1;
		while(i < m && a[i].first == num){
			ostringstream pre, suf;
			pre << setfill('0') << setw(6) << a[i].first;
			suf << setfill('0') << setw(6) << od;
			lli x = id[a[i]];
			ans[x] = pre.str()+suf.str();
			i++;
			od++;
		}
	}
	rep(i, m){
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 14264
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;


int main(){
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i, 0, N) cin >> p.at(i);
    sort(all(p));
    int sum = 0;
    rep(i, 0 ,K){
        sum += p.at(i);
    }
    cout << sum << endl;
}

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

int main() {
  int n;
  cin >> n;
  string str;
  str = std::to_string(n);
  if(str.at(str.size()-1) == '3')
    cout << "bon" << endl;
  else if(str.at(str.size()-1) == '0' ||
          str.at(str.size()-1) == '1' ||
          str.at(str.size()-1) == '6' ||
          str.at(str.size()-1) == '8')
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
}



Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define init_random mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define start_routine cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int begtime = clock();
#define end_routine int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define PB push_back
#define MP make_pair
#define int long long
#define sd(n) scanf("%lld", &n)
#define pd(n) printf("%lld\n", n)
#define MOD ((long long) (1000*1000*1000 + 7))
#define exit(a, b) return cout << a, b;
#define eps (double)1e-9
#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define vi vector<int>
#define vb vector<bool>
#define all(v) v.begin(), v.end()
#define ll long long 
#define pii pair<int, int>
#define mii map<int, int> 
#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

int H;
bool check (int cx, int cy, vector<pii> &coordinates, vector<int> &heights) {
	for (int i = 0; i < len(heights); i += 1) {
		if (heights[i] == 0) continue;
		H = heights[i] + abs(coordinates[i].first - cx) + abs(coordinates[i].second - cy);
		break;
	}

	for (int i = 0; i < len(coordinates); i += 1) {
		if (heights[i] != max(0LL, H - abs(coordinates[i].first - cx) - abs(coordinates[i].second - cy))) {
			return false;
		}	
	}
	return true;
}
signed main()
{
  start_routine;
  #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  #endif	
  
  int n; cin >> n;
  vector<pii> coordinates;
  vector<int> heights;
  bool found = false;
  int in[101][101];
  for (int i = 0; i <= 100; i++) for (int j = 0; j <= 100; j++) in[i][j] = false;
  for (int i = 1; i <= n; i++) {
  	int a, b, c; cin >> a >> b >> c;
  	coordinates.push_back(MP(a, b));
  	heights.push_back(c);
  	in[a][b] = true;
  	if (c != 0) found = true;
  }

  if (found == false) {
  	for (int i = 0; i <= 100; i++) for (int j = 0; j <= 100; j++) {
  		if (in[i][j] == false) {
  			cout << i << " " << j << " " << 1 << endl;
  			return 0;
  		}
  	}
  }

  for (int cx = 0; cx <= 100; cx++) {
  	for (int cy = 0; cy <= 100; cy++) {
  		if (check(cx, cy, coordinates, heights)) {
  			cout << cx << ' ' << cy << ' ' << H << endl;
  			return 0;
  		}
  	}
  }
  end_routine;
}

Measured memory_bytes: 384
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var T = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        var m = int.Parse(Console.ReadLine());
        var P = new int[m];
        var X = new int[m];
        for (int i = 0; i < m; i++)
        {
            var px = Console.ReadLine().Split();
            P[i] = int.Parse(px[0]);
            X[i] = int.Parse(px[1]);
        }

        var sum = 0;
        for (int i = 0; i < n; i++) sum += T[i];

        for (int i = 0; i < m; i++)
        {
            Console.WriteLine(sum - T[P[i] - 1] + X[i]);
        }
    }
}


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

int main()
{
    int a , b;
    int n;
    cin>>n>>a>>b;
    if((b-a-1)&1) cout<<"Alice"<<endl;
    else if((b-a-1)%2==0)cout<<"Borys"<<endl;
    else cout<<"Draw"<<endl;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  int h,w;
  char c[105][105];
  cin>>h>>w;
  
  rep(i,h){
    rep(j,w){
      cin>>c[i][j];
    }
  }
  //cout<<h<<" "<<w<<endl;
  rep(i,h*2){
    rep(j,w){
      cout<<c[i/2][j];
    }
    cout<<endl;
  }
  return 0;
 
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>


using namespace std;
using Int = long long;
Int INF = 1LL << 60;


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;

	Int all = 1;//確率全体の分母
	while (all <= K - 1) {
		all *= 2;
	}

	Int temp = 0;
	for (Int i = 1; i <= min(N,K-1); i++) {
		Int temp1 = i;
		Int temp2 = all;
		while (temp1 <= K - 1) {
			temp1 *= 2;
			temp2 /= 2;
		}
		temp += temp2;
	}

	temp += all * (max(0LL, N - K + 1));

    double ans = 0;
	ans = (double) temp / all / N;

	printf("%.20lf\n", ans);

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  
  int n;
  scanf("%d",&n);
  int f = n % 10;
  if(f == 2 || f == 4 || f == 5 || f == 7 || f == 9){
    printf("hon");
  }else if(f == 0 || f == 1 || f == 6 || f == 8){
    printf("pon");
  }else printf("bon");
  
  return 0;
}

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

const int Maxn = 100005;

int n;
int dp[Maxn];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + 1;
		for (int j = 6; j <= i; j *= 6)
			dp[i] = min(dp[i], dp[i - j] + 1);
		for (int j = 9; j <= i; j *= 9)
			dp[i] = min(dp[i], dp[i - j] + 1);
	}
	printf("%d\n", dp[n]);
	return 0;
}


Measured memory_bytes: 4116