akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

const std::string dir("DLUR");


bool visit[2222][2222];


std::string bfs(int sx, int sy, int tx, int ty)
{
  std::string s;

  int parent[2222][2222];

  memset(parent, -1, sizeof(parent));

  std::queue<std::pair<int, int>> queue;

  queue.emplace(sx, sy);

  visit[sy][sx] = true;
  visit[ty][tx] = false;

  while (! queue.empty()) {
    int x, y;

    std::tie(x, y) = queue.front(); queue.pop();

    for (int i = 0; i < 4; i ++) {
      int xx = x + dx[i], yy = y + dy[i];

      if (xx - std::min(sx, tx) <= -2 ||
          yy - std::min(sy, ty) <= -2 ||
          xx - std::max(sx, tx) >=  2 ||
          yy - std::max(sy, ty) >=  2)

        continue;

      if (visit[yy][xx])
        continue;

      if (parent[yy][xx] == -1) {
        queue.emplace(xx, yy);

        parent[yy][xx] = i;

        if (xx == tx && yy == ty) {
          while (1) {
            visit[yy][xx] = true;

            if (xx == sx && yy == sy)
              break;
          
            int i = parent[yy][xx];

            s += dir[i];

            xx -= dx[i];
            yy -= dy[i];
          }

          goto endloop;
        }
      }
    }
  }

 endloop:

  std::reverse(ALL(s));

  return s;
}

int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int sx, sy, tx, ty;

  std::cin >> sx >> sy >> tx >> ty;

  sx += 1111;
  sy += 1111;
  tx += 1111;
  ty += 1111;

  std::string s;

  s += bfs(sx, sy, tx, ty);
  s += bfs(tx, ty, sx, sy);
  s += bfs(sx, sy, tx, ty);
  s += bfs(tx, ty, sx, sy);

  std::cout << s << std::endl;

  return 0;
}


Measured memory_bytes: 23936
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int n;
	cin >> n;
	vi a(n);
	rep(i,n) cin >> a[i];

	double ans = 0;
	rep(i,n){
		ans += 1.0/a[i];
	}
	cout << fixed << 1.0/ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def calc(s1, s2, s3):
    f12 = [True]*2001
    f23 = [True]*2001
    f13 = [True]*4001
    
    for i in range(2001):
        for j in range(len(s2)):
            if i+j>=len(s1):
                break
            
            if s1[i+j]!='?' and s2[j]!='?' and s1[i+j]!=s2[j]:
                f12[i] = False
                break
    
    for i in range(2001):
        for j in range(len(s3)):
            if i+j>=len(s2):
                break
            
            if s2[i+j]!='?' and s3[j]!='?' and s2[i+j]!=s3[j]:
                f23[i] = False
                break
    
    for i in range(4001):
        for j in range(len(s3)):
            if i+j>=len(s1):
                break
            
            if s1[i+j]!='?' and s3[j]!='?' and s1[i+j]!=s3[j]:
                f13[i] = False
                break
    
    res = 1000000
    
    for i in range(2001):
        for j in range(2001):
            if f12[i] and f23[j] and f13[i+j]:
                res = min(res, max(len(s1), i+len(s2), i+j+len(s3)))
    
    return res

a = input()[:-1]
b = input()[:-1]
c = input()[:-1]
ans = 1000000
ans = min(ans, calc(a, b, c))
ans = min(ans, calc(a, c, b))
ans = min(ans, calc(b, a, c))
ans = min(ans, calc(b, c, a))
ans = min(ans, calc(c, a, b))
ans = min(ans, calc(c, b, a))
print(ans)

Measured memory_bytes: 75460
b=int(input())-1
ary=[1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772,10813692]
print(ary[b])

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

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var tHP = vals[0];
        var tAttack = vals[1];
        var aHP = vals[2];
        var aAttack = vals[3];

        while (true)
        {
            aHP -= tAttack;
            if (aHP <= 0)
            {
                Console.WriteLine("Yes");
                return;
            }

            tHP -= aAttack;
            if (tHP <= 0)
            {
                Console.WriteLine("No");
                return;
            }
        }
    }
}

Measured memory_bytes: 28236
IDENTIFICATION DIVISION.
       PROGRAM-ID. ATCODER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  indata PIC X(100).
       01  a1 PIC 9(12).
       01  a2 PIC 9(12).
       01  a3 PIC 9(12).
       01  r pic 9(12).
       01  g pic 9(12).
       01 disp pic Z(10)9.
       PROCEDURE DIVISION.
        ACCEPT indata.
        
        UNSTRING indata DELIMITED BY SPACE INTO a1 a2.

         IF a1 < a2 THEN
           display "0"
         ELSE
           display "10"
         END-IF


       STOP RUN.


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };



int main() {
	fastIO;
	int n;
	cin >> n;
	vector<int> A(n), B(n), C(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> C[i];
	}

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	vector<ll> ansB(n);
	ll sum = 0;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		sum += C.end() - upper_bound(C.begin(), C.end(), B[i]);
		ansB[i] = sum;
	}

	for (int i = 0; i < n; i++) {
		auto ub = upper_bound(B.begin(), B.end(), A[i]);
		if (ub == B.end())
			continue;

		ll idx = ub - B.begin();
		ans += sum;
		if (idx)
			ans -= ansB[idx-1];
	}

	cout << ans;


}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nmax=2000100;
const ll mod=1e9+7;
ll fac[nmax],finv[nmax],inv[nmax];
 
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;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;
  }
}
ll com(int n,int k){
  if(n<k||n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    COMinit();
    int r1,c1,r,c;
    cin >> r1 >> c1 >> r >> c;
    cout << (com(r+1+c+1,r+1)-com(r+1+c1,c1)-com(r1+c+1,r1)+com(r1+c1,r1)+2*mod)%mod << endl;
}

Measured memory_bytes: 47104
#include "bits/stdc++.h"
#define lpa(i,a,b) for(int i=a; i<b; ++i)
#define lp(i,n) lpa(i,0,n)
using namespace std;
int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	int a,b=0;
	lp(i,n)
	{
		cin>>a;
		b+=2*min(k-a,a);
	}
	cout<<b;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(int argc, char const *argv[]) {

  int a, b;
  scanf("%d", &a);
  scanf("%d", &b);

  if (9 < a || 9 < b){
      printf("%d\n", -1);
  }
  else {
      printf("%d\n", a*b);
  }

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
#define MAXN 10000007
ll int spf[MAXN]; 
 // map<ll int,ll int> mp;
void sieve() 
{ 
    spf[1] = 1; 
    for (ll int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (ll int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (ll int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (ll int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
//ll int val=1;
ll int getf(ll int x) 
{ 
   // vector<int> ret; 
	//map<ll int,ll int> mp;
	ll int prev=-1,c=0;ll int val=1;
    while (x != 1) 
    { 
    	ll int z=spf[x];

    	if(prev==-1)
    	{
    		prev=z;
    		c++;
    	}
    	else if(z==prev)
    		c++;
    	else if(z!=prev)
    	{
    		val=(c+1)*val;
    		prev=z;
    		c=1;
    	}


        //mp[spf[x]]++; 
        x = x / spf[x]; 
        if(x==1)
        {
        	val=(c+1)*val;
        }
    } 
    
    /*for(auto j=mp.begin();j!=mp.end();j++)
    	{
    		val=(j->S+1)*val;
    	}*/
    return val; 
} 
int main()
{
    fast;
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    ll int n;
    cin>>n;
    sieve();
    ll int i,val,ans=1;
    for(i=2;i<=n;i++)
    {
    	//mp.clear();
    	//val=1;
    	ll int val=getf(i);
    	
    	
    	ans+=i*val;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 81776
#include <iostream>

using namespace std;

void reorder(int Preorder[], int Inorder[], int Postorder[], int l, int a, int b, int c) {
  if (l == 0) return;

  int num = Preorder[a];
  Postorder[c + l - 1] = num;
  // if (l == 1) return;
  // if (l == 0) {
  //   cout << "l==0" << endl;
  //   return;  // should not happen
  // }

  for (int i = 0; i < l; i++) {
    if (Inorder[b + i] == num) {
      reorder(Preorder, Inorder, Postorder, i, a + 1, b, c);
      reorder(Preorder, Inorder, Postorder, l - i - 1, a + i + 1, b + i + 1, c + i);
      break;
    }
  }
}

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

  int Preorder[N];
  int Inorder[N];
  int Postorder[N];

  for (int i = 0; i < N; i++) {
    cin >> Preorder[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> Inorder[i];
  }

  reorder(Preorder, Inorder, Postorder, N, 0, 0, 0);

  for (int i = 0; i < N; i++) {
    if (i != 0) cout << " ";
    cout << Postorder[i];
  }
  cout << endl;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string a;
    cin >> a;
    if (a == "A"){
        cout << "T" << endl;
    }
    else if (a == "T"){
        cout << "A" << endl;
    }
    else if (a == "G"){
        cout << "C" << endl;
    }
    else if (a == "C"){
        cout << "G" << endl;
    }
    else {
        cout << "caution" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main(){

  int N, D;
  cin >> N >> D;

  int count = 0;
  
  for(int i = 0; i < N; i++){
	double x, y;
    cin >> x >> y;
    if(sqrt( x * x + y * y ) <= (double)D){
      count++;
    }
  }
  cout << count << endl;
  
  return 0;
  
}

Measured memory_bytes: 3780
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    int n,m,k;
    cin >> n >> m >> k;
    int v[555][555];
    rep(i,m){
        int l,r;
        cin >> l >> r;
        v[l][r]++;
    }
    REP(i,1,n+1){
        REP(j,1,n+1){
            v[i][j] += v[i][j-1];
        }
    }
    REP(i,1,n+1){
        REP(j,1,n+1){
            v[i][j] += v[i-1][j];
        }
    }
    rep(i,k){
        int l,r;
        cin >> l >> r;
        P(v[r][r] + v[l-1][l-1] - v[l-1][r] - v[r][l-1]);
    }
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
//配列の添字ズレに注意
//=に注意

int main(){
  int a,k; cin>>a;
  if(a<600){cout<<8<<endl;return 0;}
  if(a<800){cout<<7<<endl;return 0;}
  if(a<1000){cout<<6<<endl;return 0;}
  if(a<1200){cout<<5<<endl;return 0;}
  if(a<1400){cout<<4<<endl;return 0;}
  if(a<1600){cout<<3<<endl;return 0;}
  if(a<1800){cout<<2<<endl;return 0;}
  if(a<2000){cout<<1<<endl;return 0;}
  
  //string s; cin>>s;
  //cout<< <<endl;
}


Measured memory_bytes: 3628
import java.io.*;
import java.util.Arrays;
class Main{
	public static void main(String[] args) throws IOException {
		int i;
		int[] n = new int[5];
		String[] str = new String[5];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		for(i=0;i<2;i++){
			n[i]=Integer.parseInt(str[i]);
		}
		String f = String.format("%.5f",((double)n[0]/(double)n[1]));
		System.out.println(n[0]/n[1]+" "+n[0]%n[1]+" "+f);
	}
}

Measured memory_bytes: 24732
answer = 0
judge = True
price = []
n,m,x = map(int,input().split())
ca = []
for i in range(n):
    ca.append(list(map(int, input().split())))
for i in range(2**n):
    judge = True
    choice_str = bin(i)
    now_x = []
    new_ca = 0
    for j in range(m):
        now_x.append(0)
    for j in range(len(choice_str)-2):
        choice_int = int(choice_str[-j-1])
        if choice_int == 1:
            for k in range(m):
                now_x[k] += ca[j][k+1]
    for j in range(m):
        if now_x[j] < x:
            judge = False
    if judge == True:
        for j in range(len(choice_str)-2):
            choice_int  = int(choice_str[-j-1])
            if choice_int == 1:
                new_ca += ca[j][0]
        price.append(new_ca)
if len(price) != 0: 
    answer = min(price)
else:
    answer = "-1"
print(answer)

Measured memory_bytes: 9312
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <assert.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for (ll i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int main ()
{
	int cnt[5] = {};
	REP(i,3) {
		int a,b; cin >> a >> b;
		cnt[a]++;
		cnt[b]++;
	}

	for (int i = 1; i <= 4; i++) {
		if (cnt[i] > 2) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[100];
  cin >> n;
  int tmp1=1000000000;
  int tmp2=0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    tmp1 = min(a[i],tmp1);
    tmp2 = max(a[i],tmp2);
  }
  cout << tmp2-tmp1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

const ll MOD = 1000000007;

int main() {
    int N; ll K; cin >> N >> K;
    veci A(N);
    REP(i,N) cin >> A[i];
    ll ans = 0;
    REP(i,N) {
        int r = 0;
        int l = 0;
        for(int j = i+1; j < N; j++) if(A[i] > A[j]) r++;
        for(int j = i-1; j >= 0; j--) if(A[j] < A[i]) l++;
        ll total = K*(K+1)/2;
        total %= MOD;
        ans += r * total;
        ans %= MOD;
        total = K*(K-1)/2;
        total %= MOD;
        ans += l * total;
        ans %= MOD;
    }
    for(int i = N-1; i >= 0; --i) {

    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll n, m;
    scanf("%lld%lld", &n, &m);
    ll ans = 0;
    // 偶数回裏返すと表、奇数回裏返すと裏
    // 制約n <= m
    // N = 1 かつ M = 1 のとき
    if(n == 1 && m == 1) {
       ans = 1;
    }
    // 行、列、一方に長い行列。長い方の両端以外が裏になる。
    else if(n == 1 || m == 1) {
        ans = max(n, m) - 2;
    }
    // N >= 2 かつ N <= M かつ M >= 2
    // 四隅は4回、四隅以外の端は6回、それ以外は9回
    else {
        // ans = n * m - (2 * (n + m) - 4);
        ans = (n - 2) * (m - 2); 
    }
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

long long n, d, k;

int sum(long long x) {
  int s = 0;
  while (x) {
    s += x % 10;
    x /= 10;
  }
  return s;
}
int main() {
	cin >> k;
	cout << 1 << "\n";
	n = 1; d = 1;
	k--;
	while(k) {
		if(sum(n + 10 * d) * (n + d) > sum(n + d) * (n + 10 * d))
      d *= 10;
		n += d;
    cout << n << "\n";
    k--;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string S; cin >> S ; int goalx, goaly; cin >> goalx >> goaly;
  
  int cnt = 0;;
  int head= 0; int tail = 0; int N = (int) S.size();
  
  vector<int> vecx; vector<int> vecy; int initx = 0;
  
  
  while( head < N){
    int res = 0;
    if( S[head] == 'T'){ cnt++; cnt %= 2; head++; tail++;}
    else{
     while( tail < N && S[tail] == 'F'){ tail++;}
      res = tail-head;
      if(cnt%2){ //cntが奇数→yへ 
        vecy.push_back(res);}
      else{
        if( head == 0 ){ initx = tail - head;}//これだけは特別扱い
        else{ 
          vecx.push_back(res);}
                            }
      head = tail;
   }
  }
  
  
    
    bool dpx[8010][16020];
    //dpx[i][j]は、iターン目にx座標jに到達できるかどうかを示す
    bool dpy[8010][16020];
    
    for(int i = 0; i < 8010; i++){
      for(int j  = 0; j < 16020; j++){
        dpx[i][j] = false; dpy[i][j] = false;}}
    // x座標0を、dpx[][8010]で表現する
    dpx[0][initx+8010] = true;  dpy[0][8010] = true;
    
    for(int i = 0; i < (int) vecx.size(); i++){
      for(int j = 0; j < 16020; j++){
        if( dpx[i][j] ){ 
          if( j+vecx[i] < 16020){dpx[i+1][j+vecx[i]] = true; }
          if( j-vecx[i] >= 0   ){dpx[i+1][j-vecx[i]] = true;} }}}
    
    for(int i = 0; i < (int) vecy.size(); i++){
      for(int j = 0; j < 16020; j++){
        if( dpy[i][j] ){ 
          if( j+vecy[i] < 16020){dpy[i+1][j+vecy[i]] = true; }
          if( j-vecy[i] >= 0   ){dpy[i+1][j-vecy[i]] = true;} }}}
    
    if( dpx[(int)vecx.size()][goalx + 8010] && dpy[(int)vecy.size()][goaly + 8010]){ 
      cout << "Yes" << endl;}
    else{ cout << "No" << endl;}
    
    return 0;}
  
                                  
      
      
    
  
    

Measured memory_bytes: 250880
using static System.Math;using static System.Console;using System.Collections.Generic;using System.Linq;using System;using System.Collections;

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine());
    static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine());
    static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    #endregion
    #region Method
    static int mod = (int)Pow(10, 9) + 7;
    public static int Mod(int a,int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    #endregion

    public static Dictionary<int, int> PrimeFactors(int n)
    {
        int i = 2;
        int tmp = n;
        Dictionary<int, int> d = new Dictionary<int, int>();

        while (i * i <= n) //※1
        {
            if (tmp % i == 0)
            {
                tmp /= i;
                if (d.ContainsKey(i)) d[i]++;
                else d.Add(i, 1);
            }
            else
            {
                i++;
            }
        }
        if (tmp != 1)
        {
            if (d.ContainsKey(tmp)) d[tmp]++;
            else d.Add(tmp, 1);
        }
        return d;
    }


    static void Main()
    {
        int N = ReadInt;

        var d = PrimeFactors(N);

        List<int> ans = new List<int>();
        Write(N + ": ");

        foreach (var item in d)
        {
            for (int i = 0; i < item.Value; i++)
            {
                ans.Add(item.Key);
            }
        }
        WriteLine(string.Join(" ", ans));
    }



}



Measured memory_bytes: 18072
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

int main(void) {
	int n = 0;
	vector<int> w(100);
	cin >> n;
	rep( 0, n) {
		cin >> w[i];
		if (i > 0) w[i] += w[i - 1];
	}
	int ans = abs(w[0] - (w[n-1] - w[0]));
	rep(1, n-1) {
		ans = min(ans, abs(w[i] - (w[n-1] - w[i])));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007/4;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

int n;
char mp[127][127];

map<pair<P, P>, bool> used;
map<pair<P, P>, int> ans;
int dfs(int lx, int ly, int rx, int ry) {
	pair<P, P> p = { {lx,ly},{rx,ry} };
	if (used[p])return ans[p];
	used[p] = true;
	bool f = true;
	Rep1(i, lx, rx) {
		Rep1(j, ly, ry) {
			if (mp[i][j] == 'x')f = false;
		}
	}
	if (f)return ans[p] = 0;
	vector<bool> h(rx - lx + 1, false);
	vector<bool> w(ry - ly + 1, false);
	int ret = mod;
	Rep1(i, lx, rx) {
		h[i-lx] = true;
		Rep1(j, ly, ry) {
			h[i-lx] = h[i-lx]&(mp[i][j] == 'x');
		}
	}
	Rep1(j, ly, ry) {
		w[j - ly] = true;
		Rep1(i, lx, rx) {
			w[j - ly] = w[j - ly] & (mp[i][j] == 'x');
		}
	}
	rep(i, rx - lx + 1) {
		if (!h[i])continue;
		rep(j, ry - ly + 1) {
			if (!w[j])continue;
			int x = i + lx;
			int y = j + ly;
			int sum = 1 + dfs(lx, ly, x - 1, y - 1) + dfs(x + 1, ly, rx, y - 1) + dfs(lx, y + 1, x - 1, ry) + dfs(x + 1, y + 1, rx, ry);
			ret = min(ret, sum);
		}
	}
	return ans[p] = ret;
}
void solve() {
	cin >> n;
	rep(i, n) {
		rep(j, n) {
			cin >> mp[i][j];
		}
	}
	cout << dfs(0, 0, n - 1, n - 1) << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n>>h>>m>>s,n)solve();
	solve();
	//stop
	return 0;
}



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

const int NMAX = 2e5 + 5;
int n, val, x;

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> x;
        if(x == val + 1) {
            val++;
        }
    }
    if(val == 0) {
        cout << -1;
    } else {
        cout << n - val;
    }
    return 0;
}

Measured memory_bytes: 3628
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n), b(n-1);
    rep(i, n-1) cin >> b[i];
    a[0] = b[0];
    for (int i = 1; i < n-1; i++) {
        a[i] = min(b[i-1], b[i]);
    }
    a[n-1] = b[n-2];
    cout << accumulate(all(a), 0) << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>

int main(int argc, char const* argv[])
{
  while (true) {
    int N;
    std::cin >> N;
    if (N == 0)
      break;
    int W, H;
    std::cin >> W >> H;
    std::vector<std::vector<char> > field(H, std::vector<char>(W, 0));
    for (int i = 0; i < N; ++i) {
      int x, y;
      std::cin >> x >> y;
      field[y - 1][x - 1] = 1;
    }
    int S, T;
    std::cin >> S >> T;

    int max_trees = 0;
    for (int y = 0; y <= H - T; ++y) {
      for (int x = 0; x <= W - S; ++x) {
        int cnt = 0;
        for (int h = 0; h < T; ++h)
          for (int w = 0; w < S; ++w)
            if (field[y + h][x + w])
              ++cnt;
        if (cnt > max_trees)
          max_trees = cnt;
      }
    }
    std::cout << max_trees << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#include <iostream>
using namespace  std;
vector<long long int> vc;
vector<pair<long long ,long long>>vc2;
int main() {
long long sum=0;
    long long n,p;
    cin>>n>>p;
    long long maxix=0;
    for(int i=0;i<n;i++)
    {
       long long int x,y;
        cin>>x>>y;
        maxix= max(maxix,x);
        vc.push_back(y);

    }
    int counter=0;
sort(vc.begin(),vc.end());
    for(int i=vc.size()-1;i>=0;i--){

        if(vc[i]>maxix) {
            p -= vc[i];
            counter++;
        }
        if(p<=0)break;}


while(p>0){
    p-=maxix;
    counter++;
}


cout<<counter;


}





Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<stack>
#include<iterator>
#include<functional>
#include<string.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//namespace mp = boost::multiprecision;

int main() {
	unsigned long long int n, p; cin >> n >> p;
	unsigned long long int tmp = 0;
	float t = 1.0000000000000000 / n;
	unsigned long long int s = pow(p, t);
	//if (s < 0) {
	//	s = 1;
	//}
	for (unsigned long long int i = s; i>0; i--) {
		unsigned long long k = pow(i, n);
		if (p%k == 0) {
			tmp = i;
			break;
		}
	}
	cout << tmp << endl;
}
	


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

s=1
for i in range(n):
    s=s*a[i]

# sが奇数なら
if s%2==1:
    print("APPROVED")
    exit()

p=[]
for i in range(n):
    p.append(1)

z=0
for i in range(n):
    if a[i]%2==1:
        p[i]=0
    else:
        if a[i]%6==0:
            p[i]=0
        elif a[i]%10==0:
            p[i]=0
    z=z+p[i]

if z==0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38384
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch, cw, dh, dw = ch-1, cw-1, dh-1, dw-1
s = [input() for _ in range(h)]

import heapq
inf = 10 ** 7
d = [[inf]*w for _ in range(h)]
 
def bfs():
    que = [(0, ch, cw)]
    d[ch][cw] = 0
    heapq.heapify(que)
    
    while len(que) > 0:
        dist, qx, qy = heapq.heappop(que)
        if dist > d[qx][qy]:
            continue
        if qx == dh and qy == dw:
            return d[dh][dw]
        for dx, dy in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
            px, py = qx+dx, qy+dy
            if 0 <= px < h and 0 <= py < w and s[px][py]=='.' and d[px][py] > d[qx][qy]:
                d[px][py] = d[qx][qy]
                heapq.heappush(que, (d[px][py], px, py))
        
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                px, py = qx+dx, qy+dy
                if 0 <= px < h and 0 <= py < w and s[px][py]=='.' and d[px][py] > d[qx][qy] + 1:
                    d[px][py] = d[qx][qy] + 1
                    heapq.heappush(que, (d[px][py], px, py))
    
    return -1

ans = bfs()
print(ans)

Measured memory_bytes: 122096
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int left = (a + b);
  int right = (c + d);
  if (left > right) cout << "Left" << endl;
  else if(left == right) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}

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

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

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


void solve(ll N, ll M, vector<ll> a, vector<ll> b) {
    map<ll, ll> c;
    for (int i = 0; i < M; i++) c[a[i]]++, c[b[i]]++;
    for (auto i : c) {
        if (i.second % 2 == 1) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}


void main_(istream &cin) {
    ll N;
    ll M;
    cin >> N;
    cin >> M;
    vector<ll> b(M - 1 + 1);
    vector<ll> a(M - 1 + 1);
    for (int i = 0; i <= M - 1; i++) {
        cin >> a[i];
        cin >> b[i];
    }
    solve(N, M, a, b);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
long long i,j,c[20];
int main(){
    scanf("%lld%lld",&i,&j);
    if(i==1&&j==1)cout<<1;
    else if(i==1)cout<<j-2;
    else if(j==1)cout<<i-2<<endl;
    else cout<<(i-2)*(j-2);
    return 0;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int N, W;
    cin >> N >> W;

    vs32 v(N), w(N);
    rep (i, N)
    {
        cin >> v[i] >> w[i];
    }

    int dp[W + 1];
    rep (i, W + 1) dp[i] = 0;

    rep (i, N)
    {
        for (int j = w[i]; j<= W; ++j)
        {
            dp[j] = MAX(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    cout << dp[W] << "\n";
    return 0;
}



Measured memory_bytes: 3272
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;


int main(){
  string s;cin>>s;
  int ans=0,cur=0;
  for(int i=0;i<s.size();i++){
      if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G')cur ++;
      else cur=0;
      ans=max(ans,cur);
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <queue>
//#include <boost/foreach.hpp>
using namespace std;
int main(){
    long long n;
    cin >> n;
    string s = to_string(n);
    int c=0;
    for(int i=0;i<s.size();i++){
        c+=s[i]-'0';
    }
    //cout<<m<<endl;
  //  cout<<m<<endl;
   int m=s[0]-'0'-1;
 //  cout<<m<<endl;
    for(int i=1;i<s.size();i++){
        m += 9;
    }
    cout<<max(m,c)<<endl;
   // cout<<to_string(s)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> ans(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> A.at(i);
	}
	for (size_t i = 0; i < N; i++)
	{
		ans.at(0) += A.at(i) * pow(-1, i);
	}
	for (size_t i = 1; i < N; i++)
	{
		ans.at(i) = 2*A.at(i - 1) - ans.at(i - 1);
	}
	for (size_t i = 0; i < N; i++)
	{
		cout << ans.at(i)<<endl;
	}
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <numeric>
#include <map>
using namespace std;

int main(){
    int h1,m1,h2,m2,k;
    string s ;
    cin >> h1 >> m1 >> h2 >> m2 >> k ;
    int ans = h2*60 + m2 - h1*60 -m1 - k ;
    cout << ans << endl ;

}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for(int i = 0; i < n; i++){
        int checker = distance(a.begin(), lower_bound(a.begin(), a.end(), b[i]));
        //cout << b[i] << " " << checker << endl;
        if(abs(i - checker) % 2 == 1){
            ans++;
        }
    }
    cout << ans / 2 << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<string>
#include<bitset>
#include<queue>
using namespace std;


int main() {
	string S;
	int Q;
	cin >> S >> Q;
	bool re = true; //trueなら偶数回
	string head;
	for (int i = 0; i < Q; i++) {	
		int T;
		cin >> T;
		switch (T) {
		case 1:
			//操作1
			re = !re;
			break;
		case 2:
			//操作2
			bool atama = true;
			int F;
			string C;
			cin >> F >> C;
			if (F == 2) atama = false;
			if (!re) atama = !atama;
			if (atama) {
				head += C;
			}
			else {
				S += C;
			}
			break;
		}
		
	}

	if (!re) {
		//反転操作
		reverse(S.begin(), S.end());
		cout << S+head << endl;
	}
	else {
		reverse(head.begin(), head.end());
		cout << head +S << endl;
	}
	
	return 0;
}

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

bool operator<(const P &p1, const P &p2) {
  int tmp1 = p1.fi * p1.fi + p1.se * p1.se;
  int tmp2 = p2.fi * p2.fi + p2.se * p2.se;
  if(tmp1 == tmp2) {
    return p1.se < p2.se;
  } else {
    return tmp1 < tmp2;
  }
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int w, h; cin >> h >> w;
    if(w == 0 && h == 0) break;
    P p = P(10000, 10000);
    FOR(i, 1, 150) {
      FOR(j, 1, min(150, i)) {
        if(P(w, h) < P(i, j) && P(i, j) < p) {
          p = P(i, j);
        }
      }
    }
    cout << p.se << " " << p.fi << endl;
  }
}



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

struct NODE{
	int x,t,c;
};
bool operator < (const NODE &a,const NODE &b){
	return a.c > b.c;
}
int main(){
	int c,n,m,s,d;
	while(cin >> c >> n >> m >> s >> d && c ){
		s--,d--;
		vector<NODE> g[110];
		for(int i = 0 ; i < m ; i++){
			int a,b,c;
			cin >> a >> b >> c;
			--a,--b;
			g[a].push_back({b,0,c});
			g[a].push_back({b,1,c/2});
			g[b].push_back({a,0,c});
			g[b].push_back({a,1,c/2});
		}
		priority_queue<NODE> Q;
		Q.push({s,c,0});
		int done[110][11] = {};
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if( q.t < 0 ) continue;
			if( done[q.x][q.t]++ ) continue;
			if( q.x == d ){
				cout << q.c << endl;
				break;
			}
			for( auto e : g[q.x] ) Q.push({e.x,q.t-e.t,q.c+e.c});
		}
		
		
	}	
}

Measured memory_bytes: 1348
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
count=0
D=[]
BC.sort(key=lambda x:x[1],reverse=True)
A.sort()
for B,C in BC:
  D+=[C]*B
  count+=B
  if count>=N:
    break

D=D[:N]
for i in range(len(D)):
  d=D[i]
  if A[i]<d:
    A[i]=d
  else:
    break
  
print(sum(A))

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

using namespace std;

long long a, ans;
string s;

int main(){

    cin >> s;
    if(s.size() == 1) {cout << s; return 0;}
    for(int i = s.size() - 1; i > 0; --i){
        if (s[i] < '9') {
            s[i] = '9';
            for(int j = i - 1; j >= 0; --j){
                s[j]-=1;
                if(s[j]>= '0') break;
                else if(j != 0) s[j] = '9';
            }
        }
        ans += 9;
    }
    cout << ans + s[0] - '0';

    return 0;

}


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

int main(){
	std::string a, b;
	std::cin >> a >> b;
	if(a.length() < b.length()){
		std::cout << "LESS" << std::endl;
	}
	else if(a.length() > b.length()){
		std::cout << "GREATER" << std::endl;
	}
	else if(a > b){
		std::cout << "GREATER" << std::endl;
	}
	else if(a < b){
		std::cout << "LESS" << std::endl;
	}
	else{
		std::cout << "EQUAL" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
vector<ll> calc(ll n){
	vector<ll> ret;
	for(ll i=1LL;i * i<=n;i++){
		if(n%i == 0LL){
			if(i*i!=n)ret.pb(n/i);
			ret.pb(i);
		}
	}
	return ret;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
    	cin >> a[i];
    }
    sort(be(a));
    ll ans = 0;
    set<ll> s;
    map<ll, ll> mp;
    for(int i=0;i<n;i++){
    	mp[a[i]]++;
    }
    for(int i=0;i<n;i++){
    	if(mp[a[i]] >= 2LL){
    		s.insert(a[i]);
    		continue;
    	}
    	bool maki = true;
    	for(auto& j: calc(a[i])){
    		if(s.count(j)){
    			maki =false;
    		}
    	}
    	if(maki) ans++;
    	s.insert(a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 26676
N=int(input())
oldn,oldx,oldy=0,0,0
#print(x,y)
no=0
for i in range(N):
  nxy=input().split()
  n,x,y=int(nxy[0]),int(nxy[1]),int(nxy[2])
#  print(n,x,y)
  ndiff = n - oldn
  distance = abs(x - oldx) + abs(y - oldy)
#  print(ndiff,distance)
  oldn,oldx,oldy=n,x,y
  if distance > ndiff:
    print("No")
    no=1
    break
#  print((ndiff-distance)%2)
  if (ndiff-distance)%2==0:
    continue
  else:
    no=1
    print("No")
    break
if no==0:
  print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  // cout << sqrt(pow(a, 2.0) + pow(b, 2.0) - 2.0 * a * b *
  // cos(M_PI*((5.0*h-m)/30.0))) << endl;
  cout << fixed << setprecision(15)
       << sqrt(pow(a, 2.0) + pow(b, 2.0) -
               2.0 * a * b * cos(abs(M_PI*((h/6.0 + m/360.0) - (m/30.0)))))
       << endl;
}


Measured memory_bytes: 4200
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};
int n,p[500010],a[555][555],ans;
pa q[500010];
bool zai[555][555];
void ri(int h){
	int hang=(h-1)/n+1;
	int lie=h-(hang-1)*n;
	zai[hang][lie]=0;
	int he=0,ta=1;
	q[1]=mp(hang,lie);
	a[hang][lie]--;
	ans+=a[hang][lie];
	while (he<ta){
		pa x=q[++he];
		FOR(d,0,3){
			pa y=mp(x.fi+dx[d],x.se+dy[d]);
			if (y.fi<1 || y.fi>n || y.se<1 || y.se>n) continue;
			if (zai[y.fi][y.se]+a[x.fi][x.se]<a[y.fi][y.se]){
				a[y.fi][y.se]=zai[y.fi][y.se]+a[x.fi][x.se];
				q[++ta]=y;
			}
		}
	}
}
int main(){
	cin>>n;
	FOR(i,1,n*n) scanf("%d",&p[i]);
	FOR(i,1,n) FOR(j,1,n){
		zai[i][j]=1;
		a[i][j]=min(min(i-1,n-i),min(j-1,n-j))+1;
	}
	FOR(i,1,n*n) ri(p[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// void fileio()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }
 
 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}
void selfadd(int& a, int b){
    a = a+b;
    if(a>mod)
        a = a-mod;
}
void selfsub(int& a, int b){
    a = a-b+mod;
    if(a>mod)
        a = a-mod;
}  
const int N = 200005; 
 
int dp[10003][103][2];
int D;
string s;
int rec( int index,int d, int state){
    
    if(index==s.size()){
        if(d==0)
            return 1;
        else
            return 0;
    }
    if(dp[index][d][state] !=-1){
        return dp[index][d][state];
    }
 
    int a = s[index]-'0';
 
    int ans = 0;
    if(state){
        for(int i=0;i<a;i++){
            selfadd(ans ,rec(index+1,(d+i)%D, 0)); 
        }
        selfadd(ans ,rec(index+1,(d+a)%D,1));
    }
    else{
        for(int i=0;i<=9;i++){
            selfadd(ans ,rec(index+1,(d+i)%D, 0)); 
        }
    }
    // cout<<index<<" "<<d<<" "<<state<<" "<<ans<<endl;
    return dp[index][d][state] = ans;
 
}
 
void solve(){
    
    // string s;
    // int D;
    cin>>s;
    cin>>D;
     for(int i=0;i<10003;i++){
        for(int j = 0;j<103;j++){
            for(int k = 0;k<2;k++){
                dp[i][j][k] = -1;
            }
        }
    }
    cout<<(rec(0,0,1)-1)%mod;
}
 
int32_t main()
{
    // fileio();
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

Measured memory_bytes: 17152
#include<cstdio>
#include<cstdlib>
#include<vector>
using namespace std;
typedef pair<int, int> P;

int n;
int a[50];
vector<pair<int, int>> v;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    
    int ind = 0;
    for (int i = 0; i < n; i++) {
        ind = (abs(a[i]) > abs(a[ind])) ? i : ind;
    }
    for (int i = 0; i < n; i++) {
        a[i] += a[ind];
        v.push_back(P(ind + 1, i + 1));
    }
    
    if (a[ind] < 0) {
        for (int i = n - 2; i >= 0; i--) {
            if (a[i] > a[i + 1]) {
                a[i] += a[i + 1];
                v.push_back(P(i + 2, i + 1));
            }
        }
    }
    else {
        for (int i = 1; i < n; i++) {
            if (a[i] < a[i - 1]) {
                a[i] += a[i - 1];
                v.push_back(P(i, i + 1));
            }
        }
    }
    
    printf("%d\n", static_cast<int>(v.size()));
    for (auto &i : v) {
        printf("%d %d\n", i.first, i.second);
    }
    return 0;
}

Measured memory_bytes: 256