akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	string S, T;
	cin >> S >> T;
	lint N = S.size();
	lint cnt = 0;
	rep(i, N) {
		if (S[i] != T[i]) {
			cnt++;
		}
	}
	cout << cnt << enld;
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
#define Int long long
using namespace std;

int main(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int x3,y3,x4,y4;
  x3=x2-(y2-y1);
  y3=y2+(x2-x1);
  x4=x1-(y2-y1);
  y4=y1+(x2-x1);
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
  return 0;
}


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

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}

int main() {
    string s;
    cin>>s;
    int n=s.size();
    if (is_palindrome(s)&&is_palindrome(s.substr(0,(n-1)/2))&&is_palindrome(s.substr((n+1)/2,(n-1)/2))){
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
}   


Measured memory_bytes: 256
N = gets.to_i

Names = {}

N.times do
  case w = gets.chomp![0]
  when 'M', 'A', 'R', 'C', 'H'
    Names[w] ? Names[w] += 1 : Names[w] = 1
  else
  end
end

sum = 0
['M', 'A', 'R', 'C', 'H'].combination(3).each do |comb|
  next unless Names[comb[0]] && Names[comb[1]] && Names[comb[2]]

  sum += Names[comb[0]] * Names[comb[1]] * Names[comb[2]]
end

puts sum


Measured memory_bytes: 2172
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5 1
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2

output:
INF
0
-5
-3

OR
input:
4 6 0
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2
3 1 0

output:
NEGATIVE CYCLE
"""

import sys
from math import isinf


def generate_adj_table(_v_info):
    for each in _v_info:
        source, target, cost = map(int, each)
        init_adj_table[source][target] = cost
    return init_adj_table


def bellman_ford():
    distance[root] = 0

    for j in range(vertices - 1):
        for current, current_info in enumerate(adj_table):
            for adj, cost in current_info.items():
                if distance[current] + cost < distance[adj]:
                    distance[adj] = distance[current] + cost

    for current, current_info in enumerate(adj_table):
        for adj, cost in current_info.items():
            if distance[current] + cost < distance[adj]:
                print('NEGATIVE CYCLE')
                return list()

    return distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges, root = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])

    distance = [float('inf')] * vertices
    init_adj_table = tuple(dict() for _ in range(vertices))

    adj_table = generate_adj_table(v_info)

    res = bellman_ford()
    for ele in res:
        if isinf(ele):
            print('INF')
        else:
            print(ele)

Measured memory_bytes: 8312
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/
ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

ll lcm(ll number1,ll number2){
	return number1 * number2 / gcd(number1,number2);	
}

int main() {
	
	int n, tmp;
	scanf("%d", &n);
	ll ans = 0;
	rep(i, n){
	  scanf("%d", &tmp);
	  ans += tmp - 1;
	}
	printf("%lld\n", ans);
	
	Please AC;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 50+2;

int n;
ll k;
int C[N][N];
int mat[N][N];
int R[N][N];

void multiply(int tipo){
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			C[i][j] = 0;
			for(int k=0; k<n; k++){
				if(tipo == 0){
					C[i][j] = add(C[i][j],mul(R[i][k],mat[k][j]));
				}
				else{
					C[i][j] = add(C[i][j],mul(mat[i][k],mat[k][j]));
				}
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(tipo == 0) R[i][j] = C[i][j];
			else mat[i][j] = C[i][j];
		}
	}
}

void fast_expo(ll x){
	while(x > 0){
		if(x&1) multiply(0);
		multiply(1);
		x >>= 1;
	}
	
}

int main(){
	ri(n);
	rll(k);
	k--;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			ri(mat[i][j]);
			R[i][j] = mat[i][j];
		}
	}
	fast_expo(k);
	int ans = 0;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			ans = add(ans,R[i][j]);
		}
	}
	printf("%d\n",ans);
	return 0;
}


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

int main(void){
    long long int h,w;

    cin >> h >> w;

    if(w == 1 || h == 1){
        cout << 1 << endl;
    }
    else if(h*w % 2 == 0){
        cout << h * w / 2 << endl;
    }else{
        cout << h * w / 2 + 1 << endl;
    }

    return 0;
}

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

int main(){
    int N, D; cin >> N >> D;
    vector<vector<int>> v(N, vector<int>(D, 0));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < D; j++)
        {
            cin >> v[i][j];
        }
    }
    
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i+1; j < N; j++)
        {
            double dis_sq = 0;
            for (int k = 0; k < D; k++)
            {
                dis_sq += (v[i][k]-v[j][k]) * (v[i][k]-v[j][k]);
            }
            double test = sqrt(dis_sq);
            if(test > ((int) test)-0.000000000001 && test < ((int) test)+0.000000000001)
                ans++;
        }
        
    }
    cout << ans << endl;   
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    if sum(a) < sum(b):
        print(-1)
    else:
        c = [a[i] - b[i] for i in range(n)]
        minus = [ci for ci in c if ci < 0]
        plus = sorted([ci for ci in c if ci > 0], reverse=True)
        ans = len(minus)
        total = sum(minus)

        if total != 0:
            for index, p in enumerate(plus, 1):
                total += p
                ans += 1

                if total >= 0:
                    print(ans)
                    exit()
        else:
            print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18620
#include<bits/stdc++.h>
using namespace std;
#define ll         long long int
#define co         cout
#define ci         cin
#define sf1(n)     scanf("%lld",&n)
#define sf2(n,m)   scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define pf1(n)     printf("%lld\n",n);
#define en         cout<<endl;
#define pb         push_back
#define fi         first
#define se         second
#define coy        cout<< "YES"<<endl;
#define con        cout<< "NO"<<endl;
#define f(a,b)     for(ll i=a;i<b;i++)
#define pi         pair<ll,ll>
#define br         break;
#define i64        long long

int main()
{
    ll a,b,c,k;
    ci>>a>>b>>c>>k;
    ll x=min(a,k);
    ll res=0;
    res+=x;
    a-=x;k-=x;
    x=min(b,k);
    b-=x;k-=x;
    x=min(c,k);
    res-=x;
    c-=x;
    k-=x;
    co<<res;
}


Measured memory_bytes: 3624
#include <cstdio>
#include<algorithm>
using namespace std;
int A[100100],n;

int pertition(int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j] <= x) {
			swap(A[++i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;

}

int main() {
	int q;
	scanf("%d", &n);
	for (int t = 0; t < n; t++) {
		scanf("%d", &A[t]);
	}

	q=pertition(0,n-1);

	for (int t = 0; t < n; t++) {
		if (t)printf(" ");
		if (t == q)printf("[");
		printf("%d", A[t]);
		if (t == q)printf("]");
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 2924
n = gets.strip.to_i
cnt = 0
1.upto(n) do |i|
  next if i.even?

  s_cnt = 0
  1.upto(i) do |j|
    next if j.even?

    s_cnt += 1 if i % j == 0
  end
  
  cnt += 1 if s_cnt == 8
end
puts cnt


Measured memory_bytes: 14184
unittest
{
	assert( [ "3 2" ].solve == 10 );
	assert( [ "200000 1000000000" ].solve == 607923868 );
	assert( [ "15 6" ].solve == 22583772 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	
	// k回移動後に0人部屋の数がiのときのパターン数を計算
	const M = 10L ^^ 9 + 7;
	auto ans = ModWorld!M( 1L );
	foreach( i; 1L .. min( k + 1, n ) )
	{
		auto r = n - 1 - i;
		auto pa = ( i + r ).combination!M( r );		// 移動先パターン数
		auto pb = n.combination!M( i );				// 0人部屋のパターン数
		ans += pa * pb;
	}
	return ans;
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	this( long n ){ this.n = n % M; }
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = ( this.n * a ) % M;
			a = ( a * a ) % M;
		}
	}
	auto opBinary( string OP )( ModWorld r ){ auto l = this; l.opOpAssign!OP( r ); return l; }
	auto opEquals( ModWorld r ){ return this.n == r.n; }
	
	void opAssign( long r ){ this.n = r % M; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	auto toString(){ return this.n.to!string; }
}

// 階乗
auto factorial( long M )( long n )
{
	static memo = [ ModWorld!M( 1L ) ];
	if( memo.length <= n )
	{
		auto i = memo.length.signed;
		memo.length = n + 1;
		for( ; i < memo.length; i++ ) memo[ i ] = memo[ i - 1 ] * i;
	}
	return memo[ n ];
}

// 組み合わせ数
auto combination( long M )( long n, long k )
{
	if( n < k ) return ModWorld!M( 0L );
	else        return n.factorial!M / ( k.factorial!M * ( n - k ).factorial!M );
}


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

#define mp make_pair
#define pb push_back

#define int int64_t

const int MOD = 1e9+7;
 
int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    map<vector<int>,int> m1;
    vector<int> v(n);
    for(int i=1;i<=n;i++) {
    	v[i-1]=i;
    }

    m1[v]=1;
    int i=2;
    while(next_permutation(v.begin(), v.end())) {
    	m1[v]=i;
    	i++;
    }

    vector<int> a,b;
    int x;
    for(int i=0;i<n;i++) {
    	cin>>x;
    	a.pb(x);
    }
    for(int i=0;i<n;i++) {
    	cin>>x;
    	b.pb(x);
    }

    cout<<abs(m1[a]-m1[b]);




	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  bool f = false;
  rep(i,n){
    if(a[i]%2==1){
      f = true;
      break;
    }
  }
  cout << (f?"first":"second") << "\n";
  
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    string S;
    cin >> S;

    string T = "";
    char now = S[0];
    T += now;

    for (int i = 1; i < len(S); ++i){
        if(S[i] != now){
            T += now;
            now = S[i];
        }
    }

    print(len(T) - 1);

    return 0;
}

Measured memory_bytes: 592
#include <iostream>
using namespace std;
#define Nmax 200000

int p[Nmax];
double kitaichi[Nmax];

int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		kitaichi[i] = (p[i] + 1.0) / 2.0;
	}
	//for (int i = 0; i < n; i++) {
	//	cout << kitaichi[i] << " ";
	//}
	//cout << endl;

	double maxkitaichi = 0;
	double tempkitaichi = 0;
	for (int i = 0; i < k; i++) {
		tempkitaichi += kitaichi[i];
	}
	maxkitaichi = tempkitaichi;

	for (int i = 1; i <= n - k; i++) {
		tempkitaichi += kitaichi[i - 1 + k] - kitaichi[i - 1];
		if (tempkitaichi > maxkitaichi)
			maxkitaichi = tempkitaichi;
	}
	
	printf("%.9lf\n", maxkitaichi);
	return 0;

}

Measured memory_bytes: 2560
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define pb push_back
using namespace std;
vector<int> v[100001];
int dp[100001];
bool vi[100001];
void dfs(int s){
    vi[s]=true;
    for(auto i:v[s]){
        if(!vi[i])
        dfs(i);
        dp[s]=max(dp[s],1+dp[i]);
    }
}
void solve(){
    int n,m,x,y,ma=0;
    cin>>n>>m;
    //vector<int> v[n];
    for(int i=0;i<m;i++){
        cin>>x>>y;
        x--,y--;
        v[x].push_back(y);
    }
    for(int i=0;i<n;i++)
    if(!vi[i])
    dfs(i);
    for(int i=0;i<n;i++)
    ma=max(ma,dp[i]);
    cout<<ma;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 12260
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
abc = [LIST() for _ in range(N-1)]
Q, K = MAP()
xy = [LIST() for _ in range(Q)]

connection = [[] for _ in range(N)]
for a, b, c in abc:
	connection[a-1].append((b-1, c))
	connection[b-1].append((a-1, c))

#print(connection)

step = [-1]*N
step[K-1] = 0
q = deque([K-1])

while q:
	p = q.popleft()
	for X, C in connection[p]:
		if step[X] == -1:
			step[X] = step[p] + C
			q.append(X)

#print(step)

for x, y in xy:
	print(step[x-1] + step[y-1])




Measured memory_bytes: 89628
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static int K;
  static long[] A;

  public static void main(String[] args) {
    K = sc.nextInt();
    A = new long[K];
    for (int i = 0; i < K; i++) {
      A[i] = sc.nextInt();
    }
    System.out.println(solve());
  }

  static String solve() {
    if (A[K - 1] != 2) return "-1";
    long min = 2;
    long max = 3;
    for (int i = K - 2; i >= 0; i--) {
      long l = (min + A[i] - 1) / A[i] * A[i];
      long r = max / A[i] * A[i];
      if (r < l) return "-1";
      min = l;
      max = r + A[i] - 1;
//      System.err.println(l + " " + r + " " + min + " " + max);
    }
    return min + " " + max;
  }

}


Measured memory_bytes: 52316
#include <stdio.h>
#include <string.h>

int min(int a, int b){
    return (b > a ? a : b);
}

void swap(int *a, int *b)
{
    *a ^= *b;
    *b ^= *a;
    *a ^= *b;
}

int main(void)
{
    int i, j;
    int n, m, h, k;
    int depth, from;
    int score[1001], vertex[1001];
    static int amida[1001][1001];
    static int adj[1001][1001];
    int ans, sum;
    
    while (1){
        if (scanf("%d%d%d%d", &n, &m, &h, &k) == EOF){
            break;
        }
        
        if (n + m + h + k == 0){
            break;
        }
        
        for (i = 1; i <= n; i++){
            vertex[i] = i;
            scanf("%d", &score[i]);
        }
        
        memset(amida, 0, sizeof(amida));
        memset(adj, 0, sizeof(adj));
        for (i = 0; i < m; i++){
            scanf("%d%d", &from, &depth);
            amida[from][depth] = 1;
        }
        
        for (i = 1; i < h; i++){
            for (j = 1; j < n; j++){
                if (amida[j][i] == 1){
                    swap(&vertex[j], &vertex[j + 1]);
                    adj[vertex[j]][vertex[j + 1]] = adj[vertex[j + 1]][vertex[j]] = 1;
                }
            }
        }
        
        sum = 0;
        for (i = 1; i <= n; i++){
            if (vertex[i] <= k){
                sum += score[i];
            }
        }
        
        ans = sum;
        for (i = 1; i <= n; i++){
            for (j = 1; j <= n; j++){
                if (vertex[i] <= k && vertex[j] > k && adj[vertex[i]][vertex[j]]){
                    ans = min(ans, sum - score[i] + score[j]);
                }
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 8248
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>

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

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

    vector<int> hight(n,0);

    rep(i,n){
        cin >> hight[i];
    }

    int count = 0;

    rep(i,n){
        if(hight[i] >= k){
            count += 1;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cctype>

using namespace std;

inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}

const int N=200005;
const int LGN=18;
const int E=N<<1;

struct tree
{
	int tov[E],nxt[E];
	int last[N];
	int tot;

	inline void insert(int x,int y){tov[++tot]=y,nxt[tot]=last[x],last[x]=tot;}
}t[2];

int LOG[N],depth[N];
int anc[N][LGN];
int n,srcx,srcy,ans;

void dfs(int x)
{
	for (int i=t[1].last[x],y;i;i=t[1].nxt[i])
		if ((y=t[1].tov[i])!=anc[x][0]) depth[y]=depth[anc[y][0]=x]+1,dfs(y);
}

void pre()
{
	LOG[1]=0;
	for (int i=2;i<=n;++i) LOG[i]=LOG[i-1]+(1<<LOG[i-1]+1==i);
	for (int i=1;i<=LOG[n];++i)
		for (int x=1;x<=n;++x)
			anc[x][i]=anc[anc[x][i-1]][i-1];
}

inline int adjust(int x,int h)
{
	for (int i=LOG[depth[x]];i>=0;--i) if (depth[anc[x][i]]>=h) x=anc[x][i];
	return x;
}

inline int lca(int x,int y)
{
	if (depth[x]>depth[y]) swap(x,y);
	y=adjust(y,depth[x]);
	if (x==y) return x;
	for (int i=LOG[depth[x]];i>=0;--i) if (anc[x][i]!=anc[y][i]) x=anc[x][i],y=anc[y][i];
	return anc[x][0];
}

inline int dist(int x,int y){return depth[x]+depth[y]-(depth[lca(x,y)]<<1);}

void calc(int x,int fa=0,int cur=0)
{
	if (cur>=depth[x]-1) return;
	ans=max(ans,depth[x]-1<<1);
	for (int i=t[0].last[x],y;~ans&&i;i=t[0].nxt[i])
		if ((y=t[0].tov[i])!=fa)
		{
			if (dist(x,y)>2) ans=-1;
			else calc(y,x,cur+1);
		}
}

int main()
{
	//freopen("sugigma.in","r",stdin),freopen("sugigma.out","w",stdout);
	n=read(),srcx=read(),srcy=read();
	for (int s=0;s<2;++s)
		for (int i=1,x,y;i<n;++i)
			x=read(),y=read(),t[s].insert(x,y),t[s].insert(y,x);
	depth[srcy]=1,dfs(srcy),pre(),ans=0,calc(srcx);
	printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}

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

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

    int n;
    cin >> n;

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

    vector<int> b(n);
    rep(i,n) cin >> b[i];

    vector<int> c(n-1);
    rep(i,n-1) cin >> c[i];

    int ans = 0;
    rep(i,n){
        if(!i){ ans = b[a[i]]; continue; }
        if(a[i-1] == a[i]-1) ans += c[a[i]-1];
        ans += b[a[i]];
    }

    cout << ans << endl;

    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const bool debug = 0;

int C, N;
int maps[1123][1123];
bool bef[1123][1123];

int dcnt; // ???????????°

bool check(int x, int y) {
	bool now = maps[y][x];
	pii p1(y, x), p2(y, N - 1 - x), p3(N - 1 - y, N - 1 - x), p4(N - 1 - y, x);
	
	if (maps[p1.fi][p1.se] != now) return false;
	if (maps[p2.fi][p2.se] != now) return false;
	if (maps[p3.fi][p3.se] != now) return false;
	if (maps[p4.fi][p4.se] != now) return false;
	
	return true;
}

int main() {
	cin >> C >> N;
	REP(i, N) {
		string s; cin >> s;
		REP(j, N) maps[i][j] = s[j] - '0';
	}
	
	REP(i, N / 2) REP(j, N / 2) {
		bef[i][j] = check(j, i);
		if (!bef[i][j]) dcnt++;
	}
	
	int ans = 0;
	if (dcnt == 0) ans++;
	
	while (--C) {
		int D; cin >> D;
		
		REP(i, D) {
			int y, x;
			scanf("%d %d", &y, &x);
			y--; x--;
			
			maps[y][x] ^= 1;
			
			if (y >= N / 2) y = N - 1 - y;
			if (x >= N / 2) x = N - 1 - x;
			
			bool jdg = check(x, y);
			
			if (!jdg && bef[y][x]) {
				dcnt++;
				bef[y][x] = false;
			}
			if (jdg) {
				dcnt--;
				bef[y][x] = true;
			}
		}
		
		if (dcnt == 0) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 8216
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <list>
#include <string.h>
using namespace std;
typedef long long int ll; typedef pair <double, double> P;
const int INF = 1000000000; const double EPS = 10e-9;
const double g = 9.8;
int n, v, X, Y;
struct block {
	int l, b, r, t;
	block(int L, int B, int R, int T)
	{
		l = L; b = B; r = R; t = T;
	}
	block() {};
};
block bl[50];
double calc(double vy, double t)
{
	return vy * t - g * t * t / 2;
}
int comp(double lb, double rb, double a)
{
	return lb + EPS > a ? -1 : rb - EPS < a ? 1 : 0;
}
bool check(int x, int y)
{
	double a = g * g / 4, b = g * y - v * v, c = x * x + y * y;
	double D = b * b - 4 * a * c;
	if (D > -EPS && D < 0) D = 0;
	if (D < 0) return false;
	for (int d = -1; d <= 1; d += 2)
	{
		double t2 = (-b + d * sqrt(D)) / (2 * a);
		if (t2 <= 0) continue;
		double t = sqrt(t2);
		double vx = x / t;
		double vy = (y + g * t * t / 2) / t;//sqrt(v * v - vx * vx);
		double loc = calc(vy, X / vx);
		if (loc < Y - EPS) continue;
		bool res = true;
		for (int i = 0; i < n; i++)
		{
			if (bl[i].l >= X) continue;
			if( X == bl[i].r && loc >= bl[i].b  && bl[i].t  >= Y) res = false;
			//if (!(bl[i].l <= X && X <= bl[i].r && loc >= bl[i].b - EPS && bl[i].t + EPS >= Y)) res = false;
			int lh = comp(bl[i].b, bl[i].t, calc(vy, bl[i].l / vx));
			int rh = comp(bl[i].b, bl[i].t, calc(vy, bl[i].r / vx));
			int mw = comp(bl[i].l, bl[i].r, vx* vy / g);
			int mh = comp(bl[i].b, bl[i].t, calc(vy, vy / g));
			if (lh * rh <= 0) res = false;
			if (mw == 0 && lh < 0 && mh >= 0) res = false;
		}
		if (res) return res;
	}
	return false;
}
int main() 
{
	cin >> n >> v >> X >> Y;
	for (int i = 0; i < n; i++)
	{
		int l, b, r, t; cin >> l >> b >> r >> t;
		r = min(r, X);
		bl[i] = block(l, b, r, t);
	}
	bool res = check(X, Y);
	for (int i = 0; i < n; i++)
	{
		res |= check(bl[i].l, bl[i].t);
		res |= check(bl[i].r, bl[i].t);
	}
	puts(res ? "Yes" : "No");
	return 0;
}

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

int main(){
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  int l[q][2];
  for(int i = 0; i < q; ++i){
    cin >> l[i][0] >> l[i][1];
  }
  
  vector<int> cnt(n);
  int c = 0;
  for(int i = 0; i < n; ++i){
    cnt.at(i) = c;
    if(s.at(i) != 'A') continue;
    if(i+1 >= n) break;
    if(s.at(i+1) != 'C') continue;
    c++;
  }
  
  for(int i = 0; i < q; ++i){
    int a = l[i][0] - 1, b = l[i][1] - 1;
    cout << cnt.at(b) - cnt.at(a) << endl;
  }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>    
#include <unordered_map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cerr<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define endl "\n"
#define fo(i,n) for(int i=0;i<n;i++)
#define foo(i,x,n) for(int i=x;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define w(x) int x;cin>>x;while(x--)
#define display(a,n) {fo(i,n) {cout<<a[i]<<" ";}cout<<endl;}
#define fil(a,n,val) {fo(i,n) a[i]=val; }
const ll MOD   = 1000*1000*1000+7;
const ll MOD2  = 998244353;
const ll N = 1000*1000+5;
const double PI  = 3.14159265;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
ll search(vl arr, ll l, ll r, ll x){if (r >= l) {ll mid = l + (r - l) / 2;if (arr[mid] == x)return mid;if (arr[mid] > x)return search(arr, l, mid - 1, x);return search(arr, mid + 1, r, x);} return -1;}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/ gcd(a,b);}
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; } return res; }
ll modInverse(ll n, ll p){return power(n, p-2, p);}
const int maxn=3e5+5;

int main(){
	fastio();
	int n,W;
	cin>>n>>W;
	ll dp[n+1][100005];
	int w[n+1], v[n+1];

	foo(i,1,n+1){
		cin>>w[i]>>v[i];
	} 
	ll inf=1e9+7;
	ll mx=0;

	fo(i,n+1){
		for(ll j=0;j<100005;j++){
			if(j==0){
				dp[i][j]=0;
				continue;
			}
			if(i==0){
				dp[i][j]=inf;
				continue;
			}
			if(v[i]>j){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=min(dp[i-1][j], w[i]+dp[i-1][j-v[i]]);
				if(dp[i][j]<=W)
					mx=max(mx,j);
			}
		}
	}
	cout<<mx<<endl;


}

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

void Main()
{
    int n;
    cin >> n;
    if(n % 10 == 7){
        cout << "Yes" << endl;
        return;
    }
    if(n / 10 % 10 == 7){
        cout << "Yes" << endl;
        return;
    }
    if(n / 100 % 10 == 7){
        cout << "Yes" << endl;
        return;
    }
    cout << "No" << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define RANGE(i,a,b) for(int i=(a);i<=(b);i++)
#define RANGER(i,a,b) for(int i=(b);i>=(a);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)
using ll=long long int;
using vi=vector<int>;
using vvi=vector<vi>;
using pi=pair<int,int>;
constexpr int INF=1<<30;
constexpr ll INTL=1ll<<60;
int main(){
  int n;
  cin>>n;
  int cnt=0;
  REP(i,n){
    int x;
    cin>>x;
    if(x!=i+1)cnt++;
  }
  if(cnt<=2)
  cout<<"YES"<<endl;
  else
  cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
import kotlin.math.min

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toLong() }
    val aaR = aa.reversed()

    val nodeSizes = mutableListOf<Pair<Long, Long>>() // min, max
    nodeSizes.add(Pair(aaR[0], aaR[0]))

    for (i in 1..n) {
        val minSize = nodeSizes[0].first/2 + nodeSizes[0].first % 2 + aaR[i]
        val maxSize = nodeSizes[0].second + aaR[i]
        nodeSizes.add(0, Pair(minSize, maxSize))
    }

    if (nodeSizes[0].first != 1L) {
        println(-1)
        return
    }

    var sum = 1L
    var pMax = 1L
    nodeSizes[0] = Pair(1, 1)

    for (i in 1..n) {
        val max = min(nodeSizes[i].second, pMax * 2)
        pMax = max - aa[i]
        sum += max
    }

    println(sum)
}

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

int main(){
	int S, h, m, s;
	cin >> S;
	s = S % 60;
	m = ((S - s) / 60) % 60;
	h = ((S - m * 60 - s) / 3600);
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 1168
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

int main() {

	int N, A[234];

	scanf("%d", &N);
	rep(i, N) scanf("%d", &A[i]);

	int c = 0;

	for (;; c++)
		rep(i, N) {
		if (A[i] & 1) {
			printf("%d\n", c);
			return 0;
		}
		else A[i] >>= 1;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は２つの値の組を表せる

int main(){
    //A=冷蔵庫の個数 B=電子レンジの個数
    int A,B,M; cin >> A >> B >> M;
    vector <int> a(A);
    int a_min=10001000;
    rep(i,A){
        cin >> a[i];
        a_min=min(a_min,a[i]);
    }

    vector <int> b(B);
    int b_min=10001000;
    rep(i,B){
        cin >> b[i];
        b_min=min(b_min,b[i]);
    }
    
    int ans=100001000;
    rep(i,M){
        int x,y,c; cin >> x >> y >> c;
        ans=min(ans,(a[x-1]+b[y-1]-c));
    }
    
    int ans2=a_min+b_min;
    cout << min(ans2,ans);
    
    
    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int cnt[200009];

int main(){
  int n,k;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    cnt[a]++;
  }
  sort(cnt,cnt+200000);
  reverse(cnt,cnt+200000);
  int ans=0;
  for(int i=k;i<=200000;i++){
    ans+=cnt[i];
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N, K;
  cin >> N >> K;
  
  ll ctt = 0;
  for(int a=1; a<=N; a++) {
    ll amod = a % K;
    if(K % 2 == 0 && amod == K / 2) {
      ll bt = (N + K / 2) / K;
      ll ct = (N + K / 2) / K;
      ctt += bt * ct;
    } else if(amod == 0) {
      ll bt = N / K;
      ll ct = N / K;
      ctt += bt * ct; 
    }
  }  
  fin(ctt);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <set>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef unsigned long long ull;
int main () {
    int N, A, B;
    cin >> N >> A >> B;
    ull minCost = 0;
    ull lastVal = -1;
    for (int i = 0; i < N; i++) {
        ull curVal;
        cin >> curVal;
        if (lastVal != -1) {
            ull walkCost = (curVal-lastVal)*A;
            ull teleCost = B;
            minCost += (min(walkCost,teleCost));
        }
        lastVal = curVal;
    }
    cout << minCost << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#include <stdio.h>
#define ll long long
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>QUE;//きゅー

int length(char* str) {
	int len = strlen(str);
	return len;
}
ll LCM(ll a,ll b)
{

    ll r, x, tmp;
    ll i, j;
    ll lcm;
    i = a;
    j = b;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    lcm = (i / b) * j;

    return lcm;
}

int main()
{
	int N;
	cin >> N;
	ll S[100010];
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
    for (int i = 0; i < N - 1; i++) {
        S[i + 1] = LCM(S[i], S[i + 1]);
    }
    cout << S[N - 1];

    return 0;

	
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func rs() string {
	sc.Scan()
	return sc.Text()
}

func ri() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func rf() float64 {
	sc.Scan()
	i, _ := strconv.ParseFloat(sc.Text(), 64)
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()

	var ans float64
	for i := 0; i < n; i++ {
		x, u := rf(), rs()
		if u == "BTC" {
			x *= 380000.0
		}
		ans += x
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author puneet
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastInput in = new FastInput(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastInput in, PrintWriter out) {
            int n = in.nextInt();

            int ans = 0, no = n;
            while (no != 0) {
                ans += no % 10;
                no /= 10;
            }

            if (n == 10 || n == 100 || n == 1000 || n == 10000 || n == 100000)
                ans *= 10;
            out.println(ans);
        }

    }

    static class FastInput {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastInput.SpaceCharFilter filter;

        public FastInput(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define all(a) begin(a), end(a)
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << ": " << a << ENDL
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

int main()
{   _
    lli n, k; cin >> n >> k;
    vi v(n); fore(i, 0, n) cin >> v[i];
    vector<lli> dp(n, 1e18);
    dp[0] = 0;
    fore(i, 0, n) {
        fore(j, i + 1, min(n, i + k + 1)) {
            dp[j] = min(dp[j], dp[i] + abs(v[i] - v[j]));
        }
    }
    cout << dp[n-1] << ENDL;
    return 0;
}


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

int main(){
    int n,m,X,Y;
    cin>>n>>m>>X>>Y;

    int maxx=X;
    for(int i=0;i<n;i++){
        int x;cin>>x;
        maxx=max(maxx,x);
    }

    int miny=Y;
    for(int i=0;i<m;i++){
        int y;cin>>y;
        miny=min(miny,y);
    }

    if(maxx<miny) cout<<"No War"<<endl;
    else cout<<"War"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
typedef pair<ll,ll> Pair;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }

const ll INF=99999999999999;
const ll MOD=1000000007;

vl divisor(ll n){
  vl ret;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i != n) ret.push_back(n/i);
    }
  }
  sort(ALL(ret));
  return ret;
} 
 
int main() {
  ll n,m;
  cin >> n >> m;
  vl a;
  a = divisor(m);
  ll ans;
  rep(i,a.size()){
    if(m/a[i] >= n) ans = a[i];
  }
  cout << ans;

 return 0;
}

Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))
B =  [[] for b in range(N)]
for i in range(N-1) :
  B[i] = A[i+1] - A[i]
B[N-1] = A[0] + K - A[N-1]
print(K - max(B))

Measured memory_bytes: 26444
iN = int(input())
aV = [int(_) for _ in input().split()]

aV0={}
aV1={}
for i in range(iN):
    iA = aV[i]
    if i % 2 == 0:
        if iA in aV0:
            aV0[iA] += 1
        else:
            aV0[iA] = 1
    else:
        if iA in aV1:
            aV1[iA] += 1
        else:
            aV1[iA] = 1
aV0[0]=0
aV1[0]=0

aV0dec = sorted(aV0,key=aV0.get,reverse=True)
aV1dec = sorted(aV1,key=aV1.get,reverse=True)

iMax1aV0 = aV0dec[0]
iMax1aV1 = aV1dec[0]

if iMax1aV0 != iMax1aV1:
    print(iN - aV0[iMax1aV0] - aV1[iMax1aV1])
else:
    print(iN - max(aV0[iMax1aV0],aV1[iMax1aV1]) - max(aV0[aV0dec[1]],aV1[aV1dec[1]]))


Measured memory_bytes: 17568
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int> 
#define vvi vector< vi >
#define vl vector<ll>
#define vpi vector<pi> 
#define vpl vector<pl>
#define vvl vector<vl>
#define vvpl vector<vpl>
#define pb emplace_back
#define MP make_pair
#define sz(x) (ll)x.size()
#define ss second
#define ff first
#define inf 0x7fffffff
#define linf 2000000000000000007
#define endl "\n"
#define mod 1000000007
#define MAX 100010
#define fill(a,x) memset(x,a,sizeof x)
#define all(x) x.begin(),x.end()
#define rep(i,a,n) for(ll i=a;i<n;++i)
#define repr(i,n,b) for(ll i=n;i>=b;i--)
using namespace std;
/*vl parent;
vl visited;
vl tree;
vvl adj;
vvpl adj; //for weighted;
*/ 
int main(){
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int test=1;
    //cin>>test;
    while(test--){
        /*visited.clear();
        visited.resize(n+1);
        adj.clear();
        adj.resize(n+1); 
        tree.clear();
        tree.resize(n+1);*/
        ll a, b;
        cin>>a>>b;
        cout<<a*b<<endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
        using namespace std;
        int main(){
			int n,l,sum=0,ans=1000;
			cin>>n>>l;
			for(int i=0;i<n;i++){
				sum+=i+l;
			}
			for(int i=0;i<n;i++){
				if(abs(sum-(sum-i-l))<abs(sum-ans)){
					ans=sum-i-l;
				}
			}
			cout<<ans<<endl;
    		return(0);
        }

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

struct Node{
  int key;
  struct Node *right,*left,*parent;
};

struct Node *root,*NIL;

struct Node *find(struct Node *u,int k){
  while(u!=NIL && k!=u->key){
    if(k < u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

void insert(int k){
  struct Node *x=root,*y=NIL,*z;

  z=(struct Node *)malloc(sizeof(struct Node));
  z->key=k;
  z->right=NIL;
  z->left=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL)root=z;
  else {
     if(z->key < y->key){
       y->left=z;
     }
     else y->right=z;
  }
}

void inorder(struct Node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){

  int n,i,x;
  char com[100];
  char str1[]="insert";
  char str2[]="print";
  char str3[]="find";

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(strcmp(com,str3)==0){
      scanf("%d",&x);
      struct Node *t=find(root,x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(com,str1)==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(com,str2)==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;

}


Measured memory_bytes: 20432