akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//std out
template<typename T>
void print_container(const vector<T> vals) {
    REPinit(i, 0, vals.size() - 1) cout << vals.at(i) << " ";
    cout << vals.back();
}


bool judge(int a, int b, int c) {
    if ((a > b && b > c) || (a < b && b < c)) return true;
    return false;
}

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

    double numerator, denominator;
    numerator = 1.;
    denominator = 0.;

    int N;
    cin >> N;

    double a;
    REPinit(i, 0, N) {
        cin >> a;
        denominator += (1 / a);
    }

    cout << (numerator / denominator) << endl;

    return 0;
}


Measured memory_bytes: 3740
#include <stdio.h>
 
int main(){
  int days, num;
  scanf("%d %d ", &days, &num);
  int left = days;
  int memo;
  for(int i=0; i<num; i++){
    scanf("%d ", &memo);
    left -= memo;
    
  }
  if(left < 0){
    printf("-1\n");
  }else{
    printf("%d\n", left);
  }
  return 0;
}

Measured memory_bytes: 1732
using System;

class Program {
    private static int Main() {
        var input = Console.ReadLine();
        int n = int.Parse( input );

        Call( n );

        return 0;
    }

    private static void Call( int n ) {
        for( int i = 1; i <= n; ++i ) {
            int x = i;
            if( x % 3 == 0 ) {
                Console.Write( " " + i.ToString() );
                continue;
            }

            do {
                if( x % 10 == 3 ) {
                    Console.Write( " " + i.ToString() );
                    break;
                }
            } while( ( x /= 10 ) > 0 );
        }
        Console.WriteLine();
    }
}

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

const int mx = 1e6+3;
bool tab[mx+100];
int  amt[mx+100];

int main() {
	for(int i = 0; i < mx+100; i++)
		tab[i] = true;
	tab[0] = tab[1] = false;
	for(int i = 2; i*i < mx+100; i++) {
		if(tab[i]) {
			for(int j = i*2; j < mx+100; j += i) {
				tab[j] = false;
			}
		}
	}

	for(int i = mx; i < mx+100; i++)
		tab[i] = false;

	for(int i = 1; i < mx+100; i++) {
		amt[i] = amt[i-1];
		if(tab[i]) amt[i]++;
	}

	int n;
	while(cin >> n, n) {
		int res = 0;
		for(int i = 0; i < n; i++) {
			int p, m;
			cin >> p >> m;
			res += (amt[min(mx-1,p+m)] - amt[max(0,p-m-1)]) - 1;
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 6044
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    string S;cin>>S;
    vector<vector<int>> dp(S.size()+1,vector<int>(4,0));
    REP(i,S.size()){
        dp[i+1][1]=max({dp[i][0],dp[i][2],dp[i][3]})+1;
        if(i>0&&S[i]!=S[i-1]) dp[i+1][1]=max(dp[i+1][1],dp[i][1]+1);
        if(i>=1){
            dp[i+1][2]=max({dp[i-1][0],dp[i-1][1],dp[i-1][3]})+1;
            if(i>=3&&S.substr(i-3,2)!=S.substr(i-1,2)) dp[i+1][2]=max(dp[i+1][2],dp[i-1][2]+1);
        }
        if(i>=2){
            dp[i+1][3]=max({dp[i-2][0],dp[i-2][1],dp[i-2][2]})+1;
            if(i>=5&&S.substr(i-5,3)!=S.substr(i-2,3)) dp[i+1][3]=max(dp[i+1][3],dp[i-2][3]+1);
        }
    }
    int ans=0;
    REP(i,4) ans=max(ans,dp[S.size()][i]);
    cout<<ans<<endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n;cin>>n;
    vl a(n);
    ll sum1=0,sum2=0,sum3=0;
    rep(i,n){
        cin>>a[i];
        sum1+=a[i];
        if(i%2==1)sum2+=a[i];
        if(i%2==0)sum3+=a[i];
    }
    sum3-=a[0];
    rep(i,n){
        if(i%2==0&&i!=n-1){
            cout<<sum1-sum2*2<<" ";
            int k=i+1;
            if(i+1>n-1){
                k=n-(i+1);
            }
            sum2=sum2-a[k]+a[i];
        }
        if(i%2==1){
            cout<<sum1-sum3*2<<" ";
            int k=i+1;
            if(i+1>n-1){
                k=n-(i+1);
            }
            sum3=sum3-a[k]+a[i];
        }
        if(i==n-1)cout<<sum1-sum2*2<<endl;
    }
}

Measured memory_bytes: 2048
n = int(input())
l = list(map(int,input().split()))
dp = [[float("inf")] for i in range(n)]

dp[0] = 0
dp[1] = abs(l[0]-l[1])
for i in range(2,n):
    dp[i] = min(dp[i-2]+abs(l[i]-l[i-2]),dp[i-1]+abs(l[i]-l[i-1]))
print(dp[n-1])


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

using namespace std;

typedef long long ll;


int main()
{

int n,m;
cin>>n>>m;

int arr[n+1]={0};
int ac=0,penalities=0;

for(int index=0;index<m;index++)
{
    int pbn;
    string veridct;
    cin>>pbn>>veridct;

    if(veridct=="AC"&&arr[pbn]>=0)
    {
        ac++;
        penalities+=arr[pbn];
        arr[pbn]=-1;
    }
    else
    {
        if(arr[pbn]>=0)
            arr[pbn]++;
    }
}

cout<<ac<<" "<<penalities<<endl;

return 0;
 }



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int n[500001],a;

void move(int now){
  int l,h;
  if(now*2<=a&&n[now*2]>n[now])l=now*2;
  else l=now;
  if(now*2+1<=a&&n[now*2+1]>n[l])l=now*2+1;

  if(l!=now){
    h=n[now];
    n[now]=n[l];
    n[l]=h;
    move(l);
  }
}

int main(){

  cin>>a;
  for(int i=1;i<=a;i++)cin>>n[i];
  
  for(int i=a/2;i>=1;i--)move(i);
  
  for(int i=1;i<=a;i++)cout<<" "<<n[i];
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
  FIO
  int a[3][3];
  for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
    cin>>a[i][j];
    }
  }
   int n;
   cin>>n;
   map<int,int> m;
   int h;
    for(int i=0;i<n;i++)
   {
    cin>>h;
    m[h]=i;
    }
    for(int i=0;i<3;i++)
    {
      int fl=1;
      for(int j=0;j<3;j++)
      {
        if(m.find(a[i][j])!=m.end())fl*=1;
        else fl*=0;
      }
      if(fl){cout<<"Yes";return 0;}
    }int i,j;
    for(i=0;i<3;i++)
    {
      int fl=1;
      for(j=0;j<3;j++)
      {
        if(m.find(a[j][i])!=m.end())fl*=1;
        else fl*=0;
      }
      if(fl){cout<<"Yes";return 0;}
    }
    int fl=1;
    if(m.find(a[0][0])!=m.end())fl*=1;
    else fl*=0;
    if(m.find(a[1][1])!=m.end())fl*=1;
    else fl*=0;
    if(m.find(a[2][2])!=m.end())fl*=1;
    else fl*=0;
        if(fl){cout<<"Yes";return 0;}
     fl=1;
    if(m.find(a[0][2])!=m.end())fl*=1;
    else fl*=0;
    if(m.find(a[1][1])!=m.end())fl*=1;
    else fl*=0;
    if(m.find(a[2][0])!=m.end())fl*=1;
    else fl*=0;
    if(fl){cout<<"Yes";return 0;}
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
from sys import exit
N, Y = map(int, input().split())
counter = 0
for man in range(N + 1):
    for gosen in range(N + 1):
        sen = N - (man + gosen)
        if (10000 * man) + (5000 * gosen) + (1000 * sen) == Y and sen >= 0:
            print(man, gosen, sen)
            exit()
        if (10000 * man) + (5000 * gosen) > Y:
            break
print(-1, -1, -1)


Measured memory_bytes: 2940
s = str(input())
for bits in range(1 << 3):
    op1 = '+'
    op2 = '+'
    op3 = '+'
    for i in range(3):
        if (bits >> i & 1) == 1:
            if i == 0:
                op1 = '-'
            if i == 1:
                op2 = '-'
            if i == 2:
                op3 = '-'
    if eval(s[0]+op1+s[1]+op2+s[2]+op3+s[3]) == 7:
        print(s[0]+op1+s[1]+op2+s[2]+op3+s[3]+'=7')
        break

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

int main()
{
    int A, B, tmp=0, flag=0;
    cin >> A>>B;
    tmp = A + B + 1;
    vector<char> S(tmp);

    for (int i = 0; i < tmp; i++)
    {
        cin >> S.at(i);
    }

    for (int i = 0; i < A; i++)
    {
        if (S.at(i) == '0' || S.at(i) == '1' || S.at(i) == '2' || S.at(i) == '3' || S.at(i) == '4' || S.at(i) == '5' || S.at(i) == '6' || S.at(i) == '7' || S.at(i) == '8' || S.at(i) == '9' ){

        }
        else{
            flag = 1;
        }
    }
    for (int i = A+1; i < tmp;i++){
        if (S.at(i) == '0' || S.at(i) == '1' || S.at(i) == '2' || S.at(i) == '3' || S.at(i) == '4' || S.at(i) == '5' || S.at(i) == '6' || S.at(i) == '7' || S.at(i) == '8' || S.at(i) == '9')
        {
        }
        else
        {
            flag = 1;
        }
    }
    if(S.at(A)=='-'){
    }
    else{
        flag = 1;
    }
    
    if(flag==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    //cout << flag << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define MOD 1000000007
#define ull unsigned long long
#define foi(j, n) for(int i = j;i<n;i++)
#define foj(z, n) for(int j = z;j<n;j++)
#define FO(j, n) for(int i = j;i<=n;i++)

int main()
{
	fastio;
	int t;
	cin>>t;
	int flag = 0;
	while(t>0) {
		if(t%10 == 7) flag = 1;
		t/=10;
	}
	
	if(flag == 0) cout<<"No\n";
	else cout<<"Yes\n";
	
return 0; 
}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC083A
{
    class Program
    {
        static void Main(string[] args)
        {
            var abcd = ReadInts;

            int left = abcd[0] + abcd[1];
            int right = abcd[2] + abcd[3];
            if (left == right) Console.WriteLine("Balanced");
            else if (left > right) Console.WriteLine("Left");
            else Console.WriteLine("Right");

        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] ReadLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

const int MOD = (int)1e9 + 7;
string K;
int D;
int dig;
vector<vvi> dp;

void input_init(void) {
	cin >> K >> D;
	dig = K.length();
	dp.resize(dig + 1, vvi(D + 1, vi(2, 0)));
}

int solve(void) {
	dp[0][0][0] = 1;
	for (int i = 1; i <= dig; ++i) {
		for (int j = 0; j < D; ++j) {
			for (int k = 0; k < 10; ++k) {
				int now = (int)(K[i - 1] - '0');
				if (now > k) {
					dp[i][(j + k) % D][1] += (dp[i - 1][j][0] + dp[i - 1][j][1]) % MOD;
					dp[i][(j + k) % D][1] %= MOD;
				}
				else if (now == k) {
					dp[i][(j + k) % D][1] += dp[i - 1][j][1];
					dp[i][(j + k) % D][0] += dp[i - 1][j][0];
					dp[i][(j + k) % D][1] %= MOD;
					dp[i][(j + k) % D][0] %= MOD;
				}
				else {
					dp[i][(j + k) % D][1] += dp[i - 1][j][1];
					dp[i][(j + k) % D][1] %= MOD;
				}
			}
		}
	}
	int ret = dp[dig][0][0] + dp[dig][0][1] - 1;
	if (ret < 0)
		ret += MOD;
	ret %= MOD;
	return ret;
}

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

	input_init();
	int ans = solve();

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 55808
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n = int(input())
C = list(map(int,input().split()))

path = [set() for _ in range(n)]

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    path[a].add(b)
    path[b].add(a)
    
ans = [n*(n+1)//2]*n
size = [0]*n
cparent = [[] for _ in range(n)]
reached = [False]*n
root_size = [n]*n

def dfs (p):
    c = C[p] - 1
    cparent[c].append(p)
    s = 1
    for nxt in path[p]:
        #print (nxt)
        
        if reached[nxt]:
            continue
        size[p] = 0
        reached[nxt] = True
        ret = dfs(nxt)
        s += ret
        size[p] +=ret
        ans[c] -= size[p] * (size[p] + 1)//2
    cparent[c].pop()
    if cparent[c]:
        size[cparent[c][-1]] -=s
    else:
        root_size[c] -=s    
    return s

reached[0] = True
dfs (0)

for i in range(n):
    print (ans[i]-root_size[i]*(root_size[i]+1)//2)

Measured memory_bytes: 291736
#include <bits/stdc++.h>
using namespace std;
int main()
{
  double n, t, a, h, ans;
  double tmp = 10000.;
  cin >> n >> t >> a;
  for(int i=0;i<n;i++){
    cin >> h;
    if(tmp > fabs(a - (t - h*0.006))){
      tmp = fabs(a - (t - h*0.006));
      ans = i+1;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(void){

    char A[16], B[16], C[16];

    scanf("%s%s%s", A, B, C);

    if(A[strlen(A)-1] == B[0] && B[strlen(B)-1] == C[0]){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 1644
N = int(input())
W = list(map(int, input().split()))
W1, W2 = 0, sum(W)
ans = sum(W)
for i in range(N):
    W1 += W[i]
    W2 -= W[i]
    ans = min(ans, abs(W2 - W1))
print(ans)


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

typedef long long ll;

int c_digit(ll div){
    int cnt = 0;
    while(div != 0){
        div /= 10;
        cnt++;
    }
    return cnt;
}


int main(void){
    ll N;
    cin >> N;
    int tmp;
    int cnt = 20;
    for(ll i = 1 ; i * i <= N ; i++){
        
        if(N % i == 0){
            tmp = max(c_digit(i),c_digit(N/i));
        }
        if(tmp < cnt){
            cnt = tmp;
        }
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 3580
// Problem Code: abc162_b

#include <iostream>

using namespace std;

long long fizz_buzz(int N) {
	long long sum = 0;
	for (int i = 1; i <= N; i++) 
		if (i % 3 != 0 && i % 5 != 0)
			sum += i;
	return sum;
}

int main() {
	int N;
	cin >> N;
	cout << fizz_buzz(N);
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;

int cnt = 0;

bool solve(){
	int in;
	cin>> in;
	if(!in) return false;
	if(cnt){
		cout<< endl;
	}
	cnt++;
	
	int n = 4;
	int aa[] = {10, 50, 100, 500};
	vector<pair<int, int> > a(n);
	for(int i=0;i<n;i++){
		a[i].first = aa[i];
		cin>> a[i].second;
	}
	
	vector<pair<int, int> > b = a;
	for(int i=n-1;i>=0;i--){
		while(b[i].second && in>0){
			in -= b[i].first;
			b[i].second--;
		}
	}
	
	in *= -1;
	b[0].second += in/10;
	in = 0;
	
/*	cout<< " "<< in;
	for(int i=0;i<n;i++) cout<< " "<< b[i].first<< " "<< b[i].second;
	cout<< endl;
*/	
	for(int i=0;i<n-1;i++){
		while(b[i].second * b[i].first >= b[i+1].first){
			b[i].second -= b[i+1].first/b[i].first;
			b[i+1].second++;
		}
	}
	for(int i=0;i<n;i++){
		int num = a[i].second - b[i].second;
		if(num > 0){
			cout<< b[i].first<<" "<< num<< endl;
		}
	}
	
/*	cout<< " "<< in;
	for(int i=0;i<n;i++) cout<< " "<< b[i].first<< " "<< b[i].second;
	cout<< endl;
*/	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	while(solve());

	return 0;
}

 

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w,m;
    cin>>h>>w>>m;
    vector <pair<int,int>> row(h);
    vector <pair<int,int>> column(w);
    unordered_map <int, unordered_map<int,int>> graph;
    for(int i=0;i<h;i++)
    {
        row[i].first = 0;
        row[i].second = i;
    }
    for(int i=0;i<w;i++)
    {
        column[i].first = 0;
        column[i].second = i;
    }
    for(int i=0;i<m;i++)
    {
        int hi,wi;
        cin>>hi>>wi;
        graph[hi-1][wi-1] = 1;
        row[hi-1].first++;
        column[wi-1].first++;
    }
    sort(row.begin(), row.end());
    // reverse(row.begin(),row.end());
    sort(column.begin(), column.end());
    // reverse(column.begin(), column.end());
    // cout<<row[0].second+1<<" "<<column[0].second+1<<endl;
    int countx = row[h-1].first;
    int county = column[w-1].first;
    long long int max = row[h-1].first+column[w-1].first;
    if(graph[row[h-1].second][column[w-1].second])
        max--;
    int flag = 1;
    int count= 0;
    for(int i=h-1;i>=0 and row[i].first==countx;i--)
    {
        for(int j=w-1;j>=0 and column[j].first==county;j--)
        {
            count++;
            long long int destruction = row[i].first+column[j].first;
            if(graph[row[i].second][column[j].second])
                destruction--;
            if(destruction>max)
            {
                max = destruction;
                flag = 0;
                break;
            }
            if(count>m)
            {
                max = row[h-1].first+column[w-1].first;
                flag = 0;
                break;
            }
        }
        if(!flag)
            break;
    }
    
    
    cout<<max<<'\n';
}

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

int main(void) {
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	printf((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 3832
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

typedef long long ll;
const int MAXN = 1e5 + 10;
int N;
int A[MAXN];
vector<int> adj[MAXN];
int ok = -1;

inline ll Dfs(int x, int fa = 0) {
	ll res = A[x];
	if(adj[x].size() > 1) res += A[x];
	for(auto v: adj[x])
		if(v != fa) {
			ll tmp = Dfs(v, x);
			if(tmp > A[x]) ok = 0;
			res -= tmp;
		}
	if(res < 0 || res > A[x]) ok = 0;
	return res;
}

int main() {
	register int i; int x, y;
	scanf("%d", &N);
	for(i = 1; i <= N; ++i)
		scanf("%d", A + i);
	for(i = 1; i < N; ++i)
		scanf("%d%d", &x, &y),
		adj[x].push_back(y),
		adj[y].push_back(x);
	int rt = 1;
	for(i = 2; i <= N; ++i) if(adj[i].size() > 1) rt = i;
	ok = !Dfs(rt) && (ok == -1);
	puts(ok ? "YES" : "NO");
	return 0;
}

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

bool comp(int s){
  return (s > 0 && s <= 12);
}

int main() {
  int n; cin >> n;
  int fore = n/100;
  int back = n - fore * 100;
  
  if(comp(fore)){
    if(comp(back)) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }
  else {if(comp(back)) cout << "YYMM" << endl;
        else cout << "NA" << endl;
       }
}

Measured memory_bytes: 256
n,k=map(int, input().split())
def com(a,b):
    r=1
    for i in range(b):
        r*=(a-i)
        r//=i+1
    return r
if k%2==0:
    x=0
    y=0
    for i in range(1,n+1):
        if i%k==k//2:
            x+=1
        if i%k==0:
            y+=1
    ans=0
    if x>=1:
        ans+=com(x,1)
    if x>=2:
        ans+=6*com(x,2)
    if x>=3:
        ans+=6*com(x,3)
    if y>=1:
        ans+=com(y,1)
    if y>=2:
        ans+=6*com(y,2)
    if y>=3:
        ans+=6*com(y,3)
    print(ans)
else:
    x=0
    for i in range(1,n+1):
        if i%k==0:
            x+=1
    ans=0
    if x>=1:
        ans+=com(x,1)
    if x>=2:
        ans+=6*com(x,2)
    if x>=3:
        ans+=6*com(x,3)
    print(ans)

Measured memory_bytes: 3188
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      k: usize,
      s: usize,
    }

    let mut ans = 0;
    for x in 0..k+1 {
        for y in 0..k+1 {
            if x+y <= s && s - (x+y) <= k {
                ans += 1;
            }
        }
    }
    puts!("{}\n", ans);
}


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

dp = [float('inf')] * n

dp[0] = 0

for i in range(1, n):

  dp[i] = min(dp[i], dp[i-1] + abs(li[i] - li[i-1]))
  if i > 1:
    dp[i] = min(dp[i], dp[i-2] + abs(li[i] - li[i-2]))

print(dp[n - 1])

Measured memory_bytes: 52728
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

    bool fg = false;
    rep(i, s.length()){
        if(s == t) {fg = true; break;} 
        char c = s.back();
        s.pop_back();
        s.insert(s.begin(), c);
    }
    if(fg) cout << "Yes" << ln;
    else cout << "No" << ln; 
}


Measured memory_bytes: 256
#include <iostream>

#define ll long long int

const ll MOD = 998244353;

ll facs[300005];
ll invs[300005];

using namespace std;

ll mod_pow(ll k, ll pow) {
  ll ans = 1;
  while (pow > 0) {
    if (pow & 1) ans = ans * k % MOD;
    k = k * k % MOD;
    pow >>= 1;
  }
  return ans;
}

int main() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  invs[0] = 1;
  facs[0] = 1;
  for (int i = 1; i <= n; i++) {
    facs[i] = facs[i - 1] * i % MOD;
    invs[i] = (invs[i - 1] * mod_pow(i, MOD - 2)) % MOD;
  }
  ll ans = 0;
  for (ll na = 0; na <= n; na++) {
    if (k < na * a) break;
    if ((k - na * a) % b == 0) {
      ll nb = (k - (na * a)) / b;
      if (nb <= n) {
	ll nca = (facs[n] * ((invs[n - na] * invs[na]) % MOD)) % MOD;
	ll ncb = (facs[n] * ((invs[n - nb] * invs[nb]) % MOD)) % MOD;
	ll ways = (nca * ncb) % MOD;
	ans = (ans + ways) % MOD;
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 4992
#include <iostream>

using namespace std;

const int maxn = 1e4 + 100, maxl = 110, dig = 10, mod = 1e9 + 7;
long long dp[maxn][maxl], ps[maxn][maxl];

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

    for (int i = 0; i < maxn - dig; i++)
        for (int j = 0; j < d; j++)
            for (int x = 0; x < dig; x++)
                if (!i)
                    dp[i + 1][j] += (((x % d) == j) && x);
                else
                    dp[i + 1][(j + x) % d] = (dp[i + 1][(j + x) % d] + dp[i][j]) % mod;

    for (int j = 0; j < d; j++)
        for (int i = 1; i < maxn - dig; i++)
            ps[i][j] = (ps[i - 1][j] + dp[i][j]) % mod;

    long long ans = 0;
    for (int i = 0, s = 0, x; i < k.size(); s += x, ans %= mod, i++)
    {
        x = k[i] - '0';

        if (i == k.size() - 1)
            for (int j = 0; j <= x; j++)
                if (j || i)
                    ans += !((s + j) % d);
                else
                    continue;
        else
            for (int j = 0; j < x; ans += ((!((s + j) % d)) && (j || i)) ,j++)
                for (int u = 0; u < d; u++)
                    if (!((u + s + j) % d))
                        ans = (ans + ps[k.size() - i - 1][u]) % mod;
    }

    cout << ans;

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int k = 0;
    rep(i, n) {
        if (p[i] != i+1) k++;
    }
    cout << (k <= 2 ? "YES" : "NO") << endl;
    return 0;
}


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

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

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

	for (int i = 0; i < s.length(); i += 2) {
		cout << s[i];
	}

	return 0;
}

Measured memory_bytes: 512
import sys
input_num = input()
input_list = input()
 
total_pow = 1
for num in input_list.split(" "):
    total_pow *= int(num)
    if total_pow > 10**18:
        if "0" in input_list.split(" "):
            print("0")
        else:
            print("-1")
        sys.exit()

print(total_pow)


Measured memory_bytes: 28708
#include <stdio.h>

int main(){
	int n,minute,second,tortal,i;
	tortal = 0;
	const int basetime = 60;
	for(i=0;i<4;i++){
		scanf("%d",&n);
		tortal += n;
	}
	minute = tortal/basetime;
	second = tortal - basetime*minute;
	printf("%d\n%d\n",minute,second);
	return 0;
}

Measured memory_bytes: 0
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
 
public class Main {
	static boolean debug = true;
	static Scanner sc = new Scanner(System.in);
 
	static long max = Long.MIN_VALUE;
 
	public static void main(String[] args) throws Exception {
 
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int sum=0;
		Set<Integer> s=new HashSet();
		while(true){
			int res=sum%B;
			if(res==C){
				System.out.println("YES");
				break;
			}
			else if(s.contains(res)){
				System.out.println("NO");
				break;
			}
			s.add(res);
			sum+=A;
		}
	
		 

	}
 
	private static void print(String string) {
		// TODO Auto-generated method stub
		if (debug)
			System.out.println(string);
	}
 
	private static void print(int[] data) {
		if (debug) {
			for (int i = 0; i < data.length; i++)
				System.out.println(i + ":" + data[i]);
		}
	}
 
	private static void print(String[] data) {
		if (debug) {
			for (int i = 0; i < data.length; i++)
				System.out.println(i + ":" + data[i]);
		}
	}
 
	private static void print(char[] data) {
		if (debug) {
			for (int i = 0; i < data.length; i++)
				System.out.println(i + ":" + data[i]);
		}
	}
 
	private static void print(double[] data) {
		if (debug) {
			for (int i = 0; i < data.length; i++)
				System.out.println(i + ":" + data[i]);
		}
	}
 
	private static void print(int[][] data) {
 
		if (debug) {
			for (int i = 0; i < data.length; i++) {
				for (int j = 0; j < data[0].length; j++) {
					System.out.print(data[i][j] + " ");
				}
				System.out.println();
			}
		}
	}
 
	private static void print(char[][] data) {
 
		if (debug) {
			for (int i = 0; i < data.length; i++) {
				for (int j = 0; j < data[0].length; j++) {
					System.out.print(i + " " + j + ":" + data[i][j] + " ");
				}
				System.out.println();
			}
		}
	}
 
	private static void print(String[][] data) {
 
		if (debug) {
			for (int i = 0; i < data.length; i++) {
				for (int j = 0; j < data[0].length; j++) {
					System.out.print(i + " " + j + ":" + data[i][j] + " ");
				}
				System.out.println();
			}
		}
	}
 
	private static void print(double[][] data) {
 
		if (debug) {
			for (int i = 0; i < data[0].length; i++) {
				for (int j = 0; j < data.length; j++) {
					System.out.print(i + " " + j + ":" + data[i][j] + " ");
				}
				System.out.println();
			}
		}
	}
 
	public static void inPutData(char[][] c) {
		for (int i = 0; i < c.length; i++) {
			c[i] = sc.nextLine().toCharArray();
		}
	}
 
}

Measured memory_bytes: 23764
n=int(input())
cnt=0
flg=0

for i in range(n):
    d1,d2=map(int,input().split())
    if d1==d2:
        cnt+=1
    else:
        cnt=0
    if cnt==3:
        flg=1

if flg:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define mod 1000000007
#define rep(i,n)    for(ll i=0;i<n;++i)
#define forup(i,a,b)    for(ll i=a;i<=b;++i)
#define all(v)    v.begin(),v.end()
#define inf 1000000010
#define pii pair<ll,ll>
#define vl vector<ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define MAXN 110
#define bsize 555
#define sz(v) v.size()
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll power(ll x,ll y, ll md){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

int main(){
    ll n;
    cin>>n;
    ll grid[100010][3];
    rep(i,n){
        rep(j,3){
            cin>>grid[i][j];
        }
    }

    ll dp[100010][3];
    dp[0][0]=grid[0][0];
    dp[0][1]=grid[0][1];
    dp[0][2]=grid[0][2];
    forup(i,1,n-1){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+grid[i][0];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+grid[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+grid[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 4992
import java.util.*

fun main(args: Array<String>) {
    val MOD = 1000000007

    val sc = Scanner(System.`in`)
    val N = sc.nextLong()

    var power = 1L
    for (i in 2..N) {
        power = power % MOD * i % MOD
    }

    println(power)
}


Measured memory_bytes: 21552
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   long long n,k,ans=0;
   cin>>n>>k;
   vector<long long> h(n);
   if(n<=k)cout<<0<<endl;
   else{
   rep(i,n)cin>>h.at(i);
    sort(h.begin(),h.end());
    reverse(h.begin(),h.end());
   rep(i,n-k){
    ans+=h.at(k+i);
   }
   cout<<ans<<endl;
   }

}


Measured memory_bytes: 1792
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        long jpy = 0;
        BigDecimal btc = BigDecimal.ZERO;
        for (int i = 0; i < count; i++) {
            BigDecimal amount = sc.nextBigDecimal();
            String unit = sc.next();
            if (unit.equals("JPY")) {
                jpy += amount.longValue();
            } else {
                btc = btc.add(amount);
            }
        }
        BigDecimal total = BigDecimal.valueOf(jpy).add(btc.multiply(BigDecimal.valueOf(380_000))).stripTrailingZeros();
        System.out.println(total.toPlainString());
    }
}

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

int main(){
    long long N,x=1;
    long long K;
    cin>>N>>K;
    long long A[N],B[N];
    for (long int i=0;i<N;i++){
        cin>>A[i];
        B[i]=-1;
    }
    B[0]=0;
    long long c,dd,y;
    bool f=true;
    for (long int i=0;i<=N;i++){
        if (i==K){
            f=false;
            y=x;
            break;
        } 
        x=A[x-1];
        if (B[x-1]!=-1){
             c=i+1-B[x-1];
             dd=i+1;
            break;
        }
        B[x-1]=i+1;
    }
    long long ans;
    ans=(K-dd)%c;
    for (long int i=0;i<ans;i++){
        x=A[x-1];
    }
    if (f==true)    cout<<x<<endl;
    else cout<<y<<endl;
    return 0;
}

Measured memory_bytes: 6724
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, M = get_ints
X = []
M.times do |i|
  X[i] = [i] + get_ints
end

X.sort! { |a, b| a[2] <=> b[2] }

hash = Hash.new { |h, k| h[k] = 1 }

test = X.map do |i, p, y|
  number = p.to_s.rjust(6, '0') + hash[p].to_s.rjust(6, '0')
  hash[p] += 1
  [i, p, y, number]
end

test.sort { |a, b| a[0] <=> b[0] }.each do |i, p, y, num|
  puts num
end


Measured memory_bytes: 42240
n,m = gets.split.map(&:to_i)
a = gets.split.map{|i|i.to_i-1}
sums = Array.new(2*m+2,0)
for i in 1..n-1
    r = a[i]
    r += m if a[i-1] > a[i]
    sums[a[i-1]+2] += 1
    sums[r+1] -= r-a[i-1]
    sums[r+2] += r-a[i-1]-1
end
for i in 0..2*m
    sums[i+1] += sums[i]
end
for i in 0..2*m
    sums[i+1] += sums[i]
end
b = Array.new(m){|i|sums[i]+sums[i+m]}
mx = 0
m.times do |i|
    mx = i if b[mx] < b[i]
end
ans = 0
for i in 1..n-1
    ans += a[i]-a[i-1]
    ans += m if a[i] < a[i-1]
end
puts ans-b[mx]

Measured memory_bytes: 10516
#include <iostream>
#include <forward_list>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <climits>

using namespace std;

#define INFINITE INT_MAX
#define _for(j,N) for(int i = (j);i < (N);++i)

vector<long> wt;
vector<bool> pre;

class HeapNode{
public:
    int v;
    long wt;
    HeapNode(int vi,long wti):v(vi),wt(wti){;}
    bool operator < (const HeapNode& rhs) const{
        return wt > rhs.wt;
    }
};

priority_queue<HeapNode> pq;

class Graph{
public:
    int V;
    int E;
    vector<forward_list<HeapNode>> adj;
    Graph(int v,int e):V(v),E(e){
        adj.resize(V);
        wt.resize(V);
        pre.resize(V);
        _for(0,V) {pre[i] = false;wt[i] = INFINITE;}
    }

    void addEdge(int v,int w,long wt){adj[v].push_front(HeapNode(w,wt));}
    void distra(int v);
};


void Graph::distra(int v){
    wt[v] = 0;
    pq.push(HeapNode(v,0));

    while(!pq.empty()){
        int w = pq.top().v;
        pq.pop();
        if(pre[w]) continue;

        pre[w] = true;
        for(auto a = adj[w].begin();a != adj[w].end();++a){
            int t = (*a).v;
            long wt_now = (*a).wt;

            if(wt[t] > wt_now + wt[w]){
                wt[t] = wt_now + wt[w];
                pq.push(HeapNode(t,wt[t]));
            }
        }
    }
}

int main()
{
    int V,E,r;
    int s,t,w;
    scanf("%d %d %d",&V,&E,&r);
    Graph G(V,E);
    _for(0,E){
        scanf("%d %d %d",&s,&t,&w);
        G.addEdge(s,t,w);
    }

    G.distra(r);

    _for(0,V){
        if(wt[i] == INFINITE) printf("INF\n");
        else printf("%ld\n",wt[i]);
    }
    return 0;
}



Measured memory_bytes: 21620
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    char a; cin >> a;
    if('A'<=a && a<='Z') cout << "A" << endl;
    else cout << "a" << endl;
    return 0;
}


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

int main() {
    int N;
    int cake = 4, donuts = 7;

    cin >> N;

    int ans = 0;

    for (int i = 0; i < N/cake +1; ++i){
        if ((N - i * cake) % donuts == 0) ans ++;
    }

    if (N < cake) ans = 0;

    if(ans == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 256
h,w = map(int,input().split())

res = 10**18

if(h%3)==0:
    res = min(res,0)
else:
    res = min(res,w)
if(w%3)==0:
    res = min(res,0)
else:
    res = min(res,h)

#-------
#   |
for i in range(1,min(h//2+2,h)):
    row = i*w
    left =(h-i)* ((w//2)+(w%2))
    right = (h-i)*(w//2)
    res = min(res,max(left,row)-min(row,right)) 
#|
#|
#|-----------
#|
#|
for i in range(1,min(w//2+2,w)):
    col = h * i
    up = (w-i) * ((h//2)+(h%2))
    down = (w-i) *(h//2)
    res = min(res, max(up,col)-min(down,col))

print(res)


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

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

    long long n, p;
    cin >> n >> p;

    if(n == 1){
        cout << p << endl;
        return 0;
    }

    long long tmp = p;

    map<long long, long long> mp;
    for(long long i = 2; i * i <= p; i++){
        if(tmp % i == 0){
            long long cnt = 0;
            while(tmp % i == 0){
                tmp /= i;
                cnt++;
            }
            mp[i] = cnt;
        }
    }

    long long ans = 1;
    for(auto x : mp){
        for(int i = 0; i < x.second / n; i++){
            ans *= x.first;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()!!.toInt()
    val s = (readLine()!!.split(" ").map(String::toInt))
    var n = readLine()!!.toInt()
    for (i in 0 until n){
        var ts = s.toMutableList()
        var (tn,tt) = readLine()!!.split(" ").map(String::toInt)
        ts[tn - 1] = tt
        println(ts.sum())
    }
}

Measured memory_bytes: 37876
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int n, m;
	int[] D, P;

	void run(){
		for(;;){
			n=sc.nextInt();
			m=sc.nextInt();
			if((n|m)==0){
				break;
			}
			D=new int[n];
			P=new int[n];
			for(int i=0; i<n; i++){
				D[i]=sc.nextInt();
				P[i]=sc.nextInt();
			}
			solve();
		}
	}

	void solve(){
		class P{
			int d, p;

			P(int d, int p){
				this.d=d;
				this.p=p;
			}
		}
		P[] ps=new P[n];
		for(int i=0; i<n; i++){
			ps[i]=new P(D[i], P[i]);
		}
		sort(ps, new Comparator<P>(){
			public int compare(P p1, P p2){
				return -p1.p+p2.p;
			};
		});
		int sum=0;
		for(P p : ps){
			if(p.d>m){
				p.d-=m;
				m=0;
			}else{
				m-=p.d;
				p.d=0;
			}
			sum+=p.d*p.p;
		}
		println(sum+"");
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 81572