akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define ll long long
#define N 200010
using namespace std;

ll c,n,l,r,q[N],h[N],dp[N];

double calc(ll a,ll b)
{
    ll dy=dp[a]+h[a]*h[a]-dp[b]-h[b]*h[b];
    ll dx=h[a]-h[b];
    return (double)dy/dx;
}

int main()
{
    cin>>n>>c;
    FOR(i,0,n) cin>>h[i];
    FOR(i,1,n)
    {
        while(l<r && calc(q[l],q[l+1])<2*h[i]) l++;
        dp[i]=dp[q[l]]+(h[q[l]]-h[i])*(h[q[l]]-h[i])+c;
        while(l<r && calc(q[r-1],q[r])>calc(q[r-1],i)) r--;
        q[++r]=i;
    }
    cout<<dp[n-1]<<'\n';

    return 0;
}

Measured memory_bytes: 4992
from collections import Counter
def find(M):
    fact=[]
    while M>1:
        in1=len(fact)
        for i in range(2,int(M**0.5)+1):
            if M%i==0:
                fact+=[i]
                M=M//i
                break
        in2=len(fact)
        if in1==in2:
            break
    fact+=[M]
    return fact
N,M=list(map(int,input().strip().split(' ')))
dic=Counter(find(M))
fact=[1]
temp=1
MOD=10**9+7
for i in range(1,10**6):
    temp*=i
    temp%=MOD
    fact+=[temp]

if N==1 or M==1:
    print(1)
else:
    ans=1
    for x in dic:
        y=dic[x]
        #bino(N+y-1,y)
        up=fact[N+y-1]
        down=(fact[y]*fact[N-1])%MOD
        ans*=(up*pow(down,MOD-2,MOD))%MOD
        ans%=MOD
    print(ans)

Measured memory_bytes: 73736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dbg(x) cerr << #x << " : " << x << endl;
ll cnt=0;
vector<ll> tree;
const ll maxn=2e5+4;
vector<ll> adj[maxn];
vector<ll> from(maxn),to(maxn);
void dfs(ll u,ll p){
    tree.push_back(0);
    from[u]=cnt++;
    for(ll v:adj[u]){
        if(v!=p) dfs(v,u);
    }
    to[u]=cnt-1;
}
int main(){
    ll n,q;
    cin >> n >> q;
    for(ll i=0;i<n-1;i++) {
        ll u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    cnt=0;
    dfs(1,-1);
    tree.push_back(0);
    while(q--){
        ll p,x;
        cin >> p >> x;
        tree[to[p]+1]-=x;
        tree[from[p]]+=x;
    }
    // for(ll i=1;i<=n;i++){
    //     cout << "from[i]: " << from[i] << endl;
    //     cout << "to[i]:  " << to[i] << endl;
    // }
    // // for(ll i=0;i<tree.size();i++) {
    //     cout << "i : " << tree[i] << endl;
    // }
    for(ll i=0;i<tree.size();i++){
        if(i) tree[i]+=tree[i-1];
    }
    for(ll i=1;i<=n;i++){
        cout << tree[from[i]] << " ";
    }
    cout << endl;
    return 0;
}

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

int main()
{
	auto& in = cin;

	int N;
	in >> N;
	map<string, int> nums;
	for (int i = 0; i < N; ++i) {
		string str;
		in >> str;
		++nums[str];
	}
	cout << "AC x " << nums["AC"] << "\n";
	cout << "WA x " << nums["WA"] << "\n";
	cout << "TLE x " << nums["TLE"] << "\n";
	cout << "RE x " << nums["RE"] << "\n";

	return 0;
}


Measured memory_bytes: 3632
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
N = int(input())
x = make_divisors(N-1)[1:]
ans = len(x)
d = make_divisors(N)[1:]
for c in d:
  m = N
  while m%c==0:
    m //= c
  if m%c==1:
    ans += 1
print(ans)


Measured memory_bytes: 3188
def aaaa(h):
    if h == int(h):
        return int(h)
    else:
        return int(h) + 1

a, b = map(int, input().split())
s = [a / 0.08, (a + 1) / 0.08]
r = [b / 0.1, (b + 1) / 0.1]

for i in range(aaaa(s[0]), aaaa(s[1])):
    for j in range(aaaa(r[0]), aaaa(r[1])):
        if i == j:
            print(i)
            exit()

print(-1)


Measured memory_bytes: 3064
def WarshallFloyd(M):
    N = len(M)
    for k in range(N):
        for j in range(N):
            for i in range(N):
                M[i][j] = min(M[i][j], M[i][k] + M[k][j])
    return M

INF = float("inf")

N, M, L, *I = map(int, open(0).read().split())
ABC, ST = I[:3 * M], I[3 * M + 1:]

E = [[INF] * N for _ in range(N)]
for a, b, c in zip(*[iter(ABC)] * 3):
    E[a - 1][b - 1] = E[b - 1][a - 1] = c


E = WarshallFloyd(E)

for i in range(N):
    for j in range(N):
        if E[i][j] <= L:
            E[i][j] = 1
        else:
            E[i][j] = INF

E = WarshallFloyd(E)

for s, t in zip(*[iter(ST)] * 2):
    a = E[s - 1][t - 1] - 1
    print(-1 if a == INF else a)


Measured memory_bytes: 133600
module Main where

import Control.Applicative
import Control.Monad

solve :: Integer -> Integer -> Integer -> Integer -> Integer
solve curr 0 _ _ = curr
solve curr 1 _ _ = curr + 1
solve curr k a b | b <= a + 2 = curr + k
                 | curr < a = solve (curr + incs) (k - incs) a b
                 | otherwise = solve (curr + (b - a) * dbls) (k - 2 * dbls) a b
    where incs = min (a - curr) k
          dbls = k `div` 2

main :: IO ()
main = do
  [k, a, b] <- (map read . words) <$> getLine
  print $ solve 1 k a b


Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
ll N;
vector<vector<ll>> G;
vector<ll> C;
signed main(){
    cin >> N;
    G.resize(N);
    REP(i,N-1){
        ll a, b; cin >> a>> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    C.resize(N);
    REP(i, N) cin>>C[i];
    sort(RALL(C));
    vector<int> used(N,0);
    priority_queue<P, vector<P>, greater<P>> pq;
    ll v = 0;
    REP(i, N) {
        if(G[v].size() < G[i].size()) v = i;
    }
    ll score = 0;
    vector<ll> D(N);
    pq.push(P(G[v].size(), v));
    ll n = 0;
    while(pq.size()){
        P p = pq.top(); pq.pop();
        ll v = p.second;
        if(used[v]) continue;
        D[v] = C[n];
        n++;
        used[v] = 1;
        for(ll i=0; i<G[v].size(); i++){
            ll nv = G[v][i];
            if(used[nv]){
                score += min(D[v], D[nv]);
                continue;
            } 
            pq.push(P(G[nv].size(), nv)); 
        }
    }
    cout << score << endl;
    REP(i, N) cout << D[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int lim = 100;
int n, m;
int a[lim], b[lim];
bool graph[lim][lim];
bool visit[lim];

void dfs(int v) {
  visit[v] = true;
  for (int i = 0; i < n; i++) {
    if (graph[v][i] == false)
      continue;
    if (visit[i] == true)
      continue;
    dfs(i);
  }
}

int main() {

  cin >> n >> m;
  int ans = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  for (int i = 0; i < m; i++) {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    for (int j = 0; j < n; j++) {
      visit[j] = false;
    }

    dfs(0);
    bool bridge = false;
    for (int j = 0; j < n; j++) {
      if (visit[j] == false) {
        bridge = true;
      }
    }
    if (bridge == true)
      ans++;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  cout << ans << endl;
  return 0;
}


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

VI divisor(int n){
    VI ret;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
        }
    }
    sort(ret.begin(),ret.end());
    return ret;
}

int main(void){
    int N,ans=0;
    cin>>N;
    VI t(N),maxt_d;
    rep(i,N)cin>>t[i];
    sort(t.begin(),t.end());
    maxt_d=divisor(t[N-1]);

    rep(i,N){
        auto ITE=lower_bound(maxt_d.begin(),maxt_d.end(),t[i]); 
        ans+=maxt_d[ITE-maxt_d.begin()]-t[i];
    }
    cout<<ans<<endl;
}





Measured memory_bytes: 3188
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll A,P;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>A>>P;
	cout<<(P+A*3)/2<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Solver().solve(new Scanner(System.in));
//        new Solver().solve(new Scanner(ex));
    }

    private static final String ex = "3 3\n" +
            "dxx\n" +
            "axx\n" +
            "cxx";
}

class Solver {
    Solver() {}

    void solve(Scanner scanner) {
        int[] split = splitInt(scanner.nextLine());
        int N = split[0];
        int L = split[1];

        List<String> strs = new ArrayList<>();
        for (int i = 0; i < N; i ++) {
            strs.add(scanner.nextLine());
        }

        Collections.sort(strs);

        System.out.println(String.join("", strs));
    }

    private int[] splitInt(String s) {
        String[] split = s.split(" ");
        int[] splitInt = new int[split.length];
        for (int i = 0; i < split.length; i ++) {
            splitInt[i] = Integer.parseInt(split[i]);
        }
        return splitInt;
    }
}


Measured memory_bytes: 23892
# -*- coding: utf-8 -*-
N=int(input())
A=list(map(int,input().split()))
ans=[0]
for i in range(N):
    if i%2==0:
        ans[0]=ans[0]+A[i]
    else:
        ans[0]=ans[0]-A[i]
for n in range(1,N):
    ans.append(int(2*(A[n-1]-ans[n-1]/2)))
ans=[str(m) for m in ans]
print(" ".join(ans))

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

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    int count = 0;
    for(int i = 0; ; i++){
        count += K;
        if(count >= A && count <= B){
            cout << "OK" << endl;
            break;
        }
        else if(count > B){
            cout << "NG" << endl;
            break;
        }
    }
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vec a(N);
    int tmp = 0, cnt = 0;
    rep(i, N){
        cin >> a[i];
        if(abs(tmp) < abs(a[i])){
            tmp = a[i];
            cnt = i;
        }
    }
    cout << 2*N-1 << endl;
    rep(i, N){
        cout << cnt+1 << " " << i+1 << endl;
        // a[i] += tmp;
    }
    if(tmp >= 0){
        rep(i, N-1){
            cout << i+1 << " " << i+2 << endl;
        }
    }else{
        rep(i, N-1){
            cout << N-i << " " << N-i-1 << endl;
        }
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#pragma GCC optimize 03
#pragma GCC optimize ("unroll-loops")
#define int long long
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
const int N = 2e6 + 2e5;
const int inf = 2e9;
const int MOD = 998244353;
const int LogN = 30;

unordered_set<int> m;

int nod(int a, int b) {
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return nod(b, a % b);
}

void solve() {
    int i, j, k, n;
    cin >> n;
    int nd = 0, x;
    bool prime = 1;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        nd = nod(nd, x);
        if (prime) {
            for (int i = 2; i * i <= x; ++i)
            if (x % i == 0) {
                if (m.count(i) > 0)
                    prime = 0;
                m.insert(i);
                if (i * i != x && m.count(x / i) > 0)
                    prime = 0;
                m.insert(x / i);
            }
            if (x != 1) {
                if (m.count(x) > 0)
                    prime = 0;
                m.insert(x);
            }
        }
    }
    if (prime) {
        cout << "pairwise coprime\n";
    } else {
        if (nd == 1)
            cout << "setwise coprime\n";
        else
            cout << "not coprime";
    }
}

signed main() {
    #ifdef local
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(0);
    solve();
}


Measured memory_bytes: 6660
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
using namespace std;
const int MOD = (int)1e9+7;
void solve()
{
  ll n;
  cin>>n;
  string Str;
  cin>>Str;
  int Sz=Str.size();
  if(Sz>n)
  {
    string temp="";
    for(int i=0;i<n;i++)temp+=Str[i];
    temp+="...";
    cout<<temp<<endl;
  }
  else{
    cout<<Str<<endl;
  }
}
int  main()
{
    IOS
        solve();
    return 0;
}



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

#define N 1200

#define max(a, b) (a < b ? b : a)

int dp[N][N];
char X[N], Y[N];

int LCS();

int main(){
 
  int n, i;

  scanf("%d\n", &n);

  for ( i = 0; i < n; i++ ){
    fgets(X, N, stdin);
    fgets(Y, N, stdin);
    printf("%d\n", LCS());
  }
  return 0;
}



int LCS(void)
{
  const int m = strlen(X) - 1; 
  const int n = strlen(Y) - 1;
  
  int i, j;

  memset(dp, 0, sizeof(dp));

  for (i = 1; i < m + 1; ++i) {
    for (j = 1; j < n + 1; ++j) {
     
      int mx = max(dp[i][j - 1], dp[i - 1][j]);
      if (X[i - 1] == Y[j - 1]) {
        mx = max(mx, dp[i - 1][j - 1] + 1);
      }
      dp[i][j] = mx;
    }
  }

  return dp[m][n];
}

Measured memory_bytes: 6236
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;
 
int main()
{
	int w, h;
	int a[100][100][2][3];
	//3つ目が現在、彼が向いている方角を示す。0なら北、1なら東
	//4つ目が前回の交差点で行なった動作を示す。0なら直進、1なら右折、2なら左折
	while (cin >> w >> h)
	{
		if (w == 0 && h == 0)
		{
			break;
		}
		memset(a, 0, sizeof(a));
		for (int i = 0; i < w; i++)
		{
			for (int j = 0; j < h; j++)
			{
				if (i == 0)
				{
					a[i][j][0][0] = 1;
				}
				else if (j == 0)
				{
					a[i][j][1][0] = 1;
				}
				else
				{
					a[i][j][0][0] = (a[i][j - 1][0][0] + a[i][j - 1][0][2]) % 100000;
					a[i][j][0][2] = a[i][j - 1][1][0] % 100000;
					a[i][j][1][0] = (a[i - 1][j][1][0] + a[i - 1][j][1][1]) % 100000;
					a[i][j][1][1] = a[i - 1][j][0][0] % 100000;
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < 2; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				ans += a[w - 1][h - 1][i][j];
			}
		}
		cout << ans % 100000 << endl;
	}
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
using namespace std;

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

    cout << min(a*x + b*y, min(c*2*min(x, y) + ((x < y) ? b*(y-x) : a*(x-y)), c*2*max(x, y))) << endl;
}


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

using namespace std;

int main()
{
	int n,max_num = -1000001,min_num = 1000001,storage;
	long long int sum = 0;
	cin>>n;
	for(int i = 0; i < n; i++)
	{
	cin>>storage;
		sum += storage;
		max_num = max(max_num,storage);
		min_num = min(min_num,storage);
	}
    cout<<min_num<<" "<<max_num<<" "<<sum<<endl;
}


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

#define INF 2147483647
#define RMQ_SIZE 262144  // 2^18

int tree[RMQ_SIZE];

int dfs(int a, int b, int k, int l, int r);
int find(int first, int second);
void update(int pos, int value);
int min(int a, int b);


int main(void)
{
    int n, q, com, x, y, i;

    scanf("%d %d", &n ,&q);

    for (i = 0; i < n; i++) {
        update(i, INF);
    }

    for (i = 0; i < q; i++) {
        scanf("%d %d %d", &com, &x, &y);
        if (com) {
            printf("%d\n", find(x, y+1));
        } else {
            update(x, y);
        }
    }
    
    return 0;
}

/*
 * a??????b???????????????????????¢?´¢????????????????±????.
 * ?????¨???tree[k]???????????????.
 * tree[k]???l??????r?????§???????°?????????????.
 */
int dfs(int a,int b,int k,int l,int r)
{
    int m;
    //* a~b??¨l~r??????????????????????????¨????????¨?????????.
    if (r <= a || b <= l) {
        return INF;
    }
    //* tree[k]?????¬?????????????±?????????\???a~b?????????????????¨???.
    if (a <= l && r <= b) {
        return tree[k];
    }
    m = (l+r)/2;
    return min(dfs(a, b, k*2, l, m), dfs(a, b, k*2+1, m, r));
}

/*
 * ??????????????????[right,left)??§???????????¨?????¨???
 */
int find(int right, int left)
{
    return dfs(right, left, 1, 0, RMQ_SIZE/2);
}

/*
 * pos?????????????????????value????????´??????.
 * ??????????????¨??¨?????????????????????.
 */
void update(int pos, int value)
{
    pos += RMQ_SIZE/2;
    tree[pos] = value;
    /*
     * ?????????????????§????°?????????´??°????????????.
     * ???????????????????????????.
     * ????????´????????´??°???????????????????????£???????????§return??????.
     */
    while (pos) {
        pos = pos/2;
        tree[pos] = min(tree[pos*2], tree[pos*2+1]);
    }
}

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

Measured memory_bytes: 1412
def gcd(a,b):
    m = max(a,b)
    n = min(a,b)
    if n==0:
        return m
    return gcd(n, m%n)

def lcm(a,b):
    return (a*b)//gcd(a,b)

N = input()
Ti = []

for i in range(int(N)):
    tmp = input()
    Ti.append(int(tmp))

ans_lcm = 1
for i in range(len(Ti)):
    ans_lcm = lcm(ans_lcm,Ti[i])
print(ans_lcm)

Measured memory_bytes: 3064
def solve():
    S = input()
    for i in range(len(S)):
        if (i+1)%2 == 0 and S[i] == "R":
            print("No")
            return 0
        if (i+1)%2 == 1 and S[i] == "L":
            print("No")
            return 0
    
    print("Yes")

solve()

Measured memory_bytes: 38384
'use strict';
function main(input) {
  const
    arr = input.trim().split('\n'),
    [n, k] = arr[0].split(' ').map(x => Number(x));
  let
    ans = [];
  
  for (let i = 2; i <= k * 2; i += 2) {
    ans = ans.concat(arr[i].split(' ').map(x => Number(x)));
  }

  // console.log(ans);
  
  ans = ans.filter(function (x, i, self) {
    return self.indexOf(x) === i;
  });
  
  // console.log(ans);

  console.log(n - ans.length);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 31888
#include <iostream>

using namespace std;

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

  if (d == 25) {
    cout << "Christmas" << endl;
  } else if (d == 24) {
    cout << "Christmas Eve" << endl;
  } else if (d == 23) {
    cout << "Christmas Eve Eve" << endl;
  } else if (d == 22) {
    cout << "Christmas Eve Eve Eve" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<stack>
#include<ctime>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<queue>
using namespace std;
typedef int _int;
#define int long long 
inline int read(){
	int num=0,f=1;char x=getchar();
	while(x<'0'||x>'9'){if(x=='-')f=-1;x=getchar();}
	while(x>='0'&&x<='9'){num=num*10+x-'0';x=getchar();}
	return num*f;
}
int n,d;
_int main(){
	n=read();d=read();
	int cnt=0;
	for(int i=1,x,y;i<=n;++i){
		x=read();y=read();
		cnt+=(x*x+y*y<=d*d);
	}
	printf("%lld\n",cnt);
	return 0;
}


Measured memory_bytes: 3760
#!/usr/bin/perl

my $s = <STDIN>;
$s =~ s/[\x00-\x20]+$//io;
my ($k) = map {$_ - 0} split(/\s+/o,<STDIN>);

my $sl = length($s);

my %ss = ();
for(my $l=1;$l<=5;$l++){
  for(my $i = 0; $i<$sl;$i++){
    my $ll = $l;
    $ll = $sl - $i if $i + $l > $sl;
    $ss{substr($s,$i,$ll)} = 1;
  }
}
my @s = sort keys %ss;
print "$s[$k-1]\n";

exit(0);



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

int main()
{
    int ball[3] = {};
    ball[0] = 1;

    char x, y, p;

    while( cin >> x >> p >> y )
    {
        int s, t;
        if( x == 'A' )
            s = 0;
        else if( x == 'B' )
            s = 1;
        else
            s = 2;

        if( y == 'A' )
            t = 0;
        else if( y == 'B' )
            t = 1;
        else
            t = 2;

        int temp = ball[s];
        ball[s] = ball[t];
        ball[t] = temp;
    }

    if( ball[0] == 1 )
        cout << "A" << endl;
    if( ball[1] == 1 )
        cout << "B" << endl;
    if( ball[2] == 1 )
        cout << "C" << endl;

    return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    int matrix[100][100];
    int b[100];
    int ans[100];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> matrix[i][j];
        }
    }

    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++){
        ans[i] = 0;
        for(int j = 0; j < m; j++){
            ans[i] += matrix[i][j] * b[j];
        }
    }
    for(int k =0; k < n; k++){
        cout << ans[k] << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
int main()
{	long long int n,k,x,y,sum;
	scanf("%lld",&n);
	scanf("%lld",&k);
	scanf("%lld",&x);
	scanf("%lld",&y);
	if(n<k)
	{
		sum=n*x;
	}
	
	else sum=k*x+(n-k)*y;
	printf("%lld",sum);
	return 0;
	
 } 

Measured memory_bytes: 128
def main():
    import sys
    input = lambda : sys.stdin.readline().rstrip()
    sys.setrecursionlimit(max(1000, 10**9))
    write = lambda x: sys.stdout.write(x+"\n")


    n,m = map(int, input().split())

    lx = [None] * n
    ly = [None] * m
    sx = set([-10**10, 0, 10**10])
    sy = set([-10**10, 0, 10**10])
    ix = 0
    iy = 0
    for i in range(n):
        t = tuple(map(int, input().split()))
        lx[i] = t
        sx.add(t[0])
        sx.add(t[1])
        sy.add(t[2])

    for i in range(m):
        t = tuple(map(int, input().split()))
        ly[i] = t
        sx.add(t[0])
        sy.add(t[1])
        sy.add(t[2])

    xs = list(sx)
    ys = list(sy)
    xs.sort(); ys.sort()

    wx = len(xs)*2
    wy = len(ys)*2
    bs = [[1]*wy for _ in range(wx)]
    import bisect
    for i, (x0, x1, y) in enumerate(lx):
        ix0 = bisect.bisect_left(xs, x0)*2
        ix1 = bisect.bisect_left(xs, x1)*2
        iy = bisect.bisect_left(ys, y)*2
        for ii in range(ix0+1, ix1, 2):
            bs[ii][iy] = -1
    for i, (x, y0, y1) in enumerate(ly):
        ix = bisect.bisect_left(xs, x)*2
        iy0 = bisect.bisect_left(ys, y0)*2
        iy1 = bisect.bisect_left(ys, y1)*2
        for ii in range(iy0+1, iy1, 2):
            bs[ix][ii] = -1

    xx = bisect.bisect_left(xs, 0)*2+1
    yy = bisect.bisect_left(ys, 0)*2+1
    s = [(xx,yy)]
    dx = [-1,0,1,0]
    dy = [0,-1,0,1]
    ans = 0
    end = False
    while s:
        ix,iy = s.pop()
        for x, y in zip(dx,dy):
            ixx = ix + x
            iyy = iy + y
            if bs[ixx][iyy]!=1:
                continue
            ixx += x
            iyy += y
            if bs[ixx][iyy]!=1:
                continue
            if ixx<0 or ixx>=wx-1 or iyy<0 or iyy>=wy-1:
                print("INF")
                s = []
                end = True
                break
            bs[ixx][iyy] = 2
            ans += (xs[ixx//2+1] - xs[ixx//2]) * (ys[iyy//2+1] - ys[iyy//2])
            s.append((ixx, iyy))

    if not end:
        print(ans)
main()

Measured memory_bytes: 640324
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum[1000000], ans, dp[110000];
Pll a[200000], b[2000000];
string str, ss, dd;
bool f,ff;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m >> h;
	if (n + m >=h)
		f = 1;
	yn(f);
	return 0;
}

Measured memory_bytes: 512
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	for (auto &i : s) {
		i -= 3;
		if (i < 'A')i += 26;
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}


int main(){
  ll n ; cin>> n ;
 vector<ll> A(n) ;rep(i,n) cin>>A[i] ;

 vector<ll> sum(100) ;
vector<vector<ll>> p(n,vector<ll>(100,0)) ;
rep(j,n){
  ll lo=A[j] ;
  rep(i,100){
   p[j][i]=lo%2ll ;
   sum[i]+=p[j][i] ;
   lo= lo/2ll ;
  }
 }
 
rep(i,100) sum[i]= sum[i]%2ll ;

rep(j,n){
  ll ans=0 ;
  rep(i,100){
   if(sum[i]==0) ans+=p[j][i]*pow(2,i) ;
   else ans+= (1-p[j][i])*pow(2,i) ;
  }
 cout<<ans<<endl ;

}
  return 0 ;
}


Measured memory_bytes: 169272
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF=1e15+10;
const int MAX=100005;
typedef pair<ll,ll> p;
struct Edge
{
    ll to;
    ll cost;
    Edge(ll to,ll cost):to(to),cost(cost) {}
};
vector<Edge> edge[MAX*100];
ll dis[MAX];
ll u,v,w;
ll n,q,x;
void Dijkstra(int s)
{
    priority_queue<p,vector<p>,greater<p> > que;
    fill(dis+1,dis+n+1,INF);
    dis[s]=0;
    que.push(p(0,s));
    while(!que.empty())
    {
        p P=que.top();
        que.pop();
        v=P.second;
        if(dis[v]<P.first)
            continue;
        for(ll i=0; i<edge[v].size(); i++)
        {
            Edge e=edge[v][i];
            if(dis[e.to]>dis[v]+e.cost)
            {
                dis[e.to]=dis[v]+e.cost;
                que.push(p(dis[e.to],e.to));
            }
        }
    }
    return ;
}
int main()
{
    while(~scanf("%lld",&n))
    {
        for(ll i=1; i<=n-1; i++)
        {
            scanf("%lld%lld%lld",&u,&v,&w);
            edge[u].push_back(Edge(v,w));
            edge[v].push_back(Edge(u,w));
        }
        scanf("%lld%lld",&q,&x);
        Dijkstra(x);
        for(ll i=0; i<q; i++)
        {
            scanf("%lld%lld",&u,&v);
            printf("%lld\n",dis[u]+dis[v]);
        }
    }



}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;


void solve()
{
    string S; cin >> S;
    int l = 0;
    int r = S.length()-1;
    int ans = 0;

    while(l < r)
    {
        if(S[l++] != S[r--]) ans++;
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int D;
vector<int> c(26); 
vector<vector<int>> s(365, vector<int>(26));

vector<int> cal_score(vector<int> t){
    vector<int> res(D);
    int satis = 0;
    vector<int> last(26, 0);
    rep(d, D){
        satis += s[d][t[d] - 1];
        last[t[d] - 1] = d + 1;
        rep(i, 26){
            satis -= c[i] * (d - last[i] + 1);
        }
        res[d] = satis;
    }
    return res;
}

int ch_sch(vector<int> t, int d, int q, int score){
    // change t[d - 1] -> q
    // calculate the score
    int old = t[d - 1];
    score -= s[d - 1][old - 1];
    score += s[d - 1][q - 1];

    int last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old ) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score += c[old - 1] * (i - last_old + 1);
        score += c[q - 1] * (i - last_new + 1);
    }

    t[d - 1] = q;

    last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score -= c[old - 1] * (i - last_old + 1);
        score -= c[q - 1] * (i - last_new + 1);
    }
    return score;
}


int main(){
    // input 
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }
    vector<int> t(D);
    rep(i, D) cin >> t[i];
    vector<int> res = cal_score(t);
    int score = res[D - 1];

    int m; cin >> m;
    rep(i, m){
        ll d_i, q_i; cin >> d_i >> q_i;
        score = ch_sch(t, d_i, q_i, score);
        cout << score << endl;
        t[d_i - 1] = q_i;
    }
    return 0;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}


signed main(){start();
    int n,ans=INF;
    cin>>n;
    REP(i,0,n){
        int t1,t2;
        cin>>t1>>t2;
        chmin(ans,t1+t2);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

int main(){

    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    //cout << a << b << c << x << y << endl;

    ll ans1 = a*x+b*y;
    ll ans2 = 1000000000000000;
    ll ans3 = 1000000000000000;
    ll ans4 = 1000000000000000;
    if(x>y){
        ans2 = min(2*c*y + (x-y)*a,2*c*x);
    }else if(x<y){
        ans3 = min(2*c*x+(y-x)*b,2*c*y);
    }else{
        ans4 = min(2*c*y,2*c*x);
    }
    //cout << ans1 << " " << ans2 << " " << ans3 << " " << ans4 << endl;
    ll ans = min(min(ans1,ans2),min(ans3,ans4));
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int grundy[101][201];

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

	rep(i,101) { //黒
		rep(j,201) { // 白
			set<int> dic;
			if (j) dic.emplace(grundy[i][j-1]);
			if (i) dic.emplace(grundy[i-1][j+1]);
			for (int k = i-1; k >= max(0,i-j); --k) dic.emplace(grundy[k][j]);
			rep(k,200) {
				if (!dic.count(k)) {
					grundy[i][j] = k;
					break;
				}
			}
		}
	}

	int N; cin >> N;
	int ans = 0;
	while (N--) {
		int w,b; cin >> w >> b;
		ans ^= grundy[b][w];
	}

	cout << (ans ? 0 : 1) << ln;
}



Measured memory_bytes: 3308
N, M, K = map(int, input().split())

mod = 998244353

ans = 0

class Combination:
    def __init__(self, n):
        self.facts = [1 for i in range(N+1)]
        self.invs = [1 for i in range(N+1)]
        
        for i in range(1, N+1):
            self.facts[i] = self.facts[i-1] * i % mod
            self.invs[i] = pow(self.facts[i], mod-2, mod)

    def ncr(self, n, r):
        return self.facts[n] * self.invs[r] * self.invs[n-r] % mod

comb = Combination(N)

for i in range(K+1):
    d = M * pow(M-1, N-i-1, mod) * comb.ncr(N-1, i)
    ans = (ans + d % mod) % mod

print(ans)


Measured memory_bytes: 24640
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600
typedef pair<int, int> P;

class UnionFind {
public:
  vector<int> par, rank; // parent(negative := its root and abs-value is its size), depth
  UnionFind(int sz) : par(sz, -1), rank(sz, 0){}
  int find(int x){
    if(par[x]<0) return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x, int y){
    x=find(x); y=find(y);
    if(x==y) return;  // already belong to same tree
    if(rank[x] < rank[y]){  // y becomes parent node
      par[y] += par[x];
      par[x] = y;
    } else {  // x becomes parent node
      par[x] += par[y];
      par[y] = x;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int size(int x){ return -par[find(x)]; }
}; // END class UnionFind

#define SUBWAYS 1000000

int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<P> > subway(SUBWAYS, vector<P>());
  vector<vector<int> > v(n+m, vector<int>());

  rep(i,m){
    int p,q,c;
    scanf("%d %d %d", &p, &q, &c);
    p--;q--;c--;
    subway[c].pb(mp(p,q));
  }

  UnionFind uf(n);

  int group=0;
  vector<int> i2group(n);
  rep(i,SUBWAYS){
    if(subway[i].empty()) continue;

    for(auto p : subway[i]){
      uf.rank[p.fi] = uf.rank[p.se] = 0;
      uf.par[p.fi]  = uf.par[p.se] = -1;
      i2group[p.fi] = i2group[p.se] = -1;
    }

    for(auto p : subway[i]){
      uf.unite(p.fi, p.se);
    }

    for(auto p : subway[i]){
      int r = uf.find(p.fi);
      if(i2group[r]==-1) i2group[r] = group++;
      int tgt = i2group[r]+n;
      v[p.fi].pb(tgt);
      v[p.se].pb(tgt);
      v[tgt].pb(p.fi);
      v[tgt].pb(p.se);
    }
  }

  // dijkstra 0->n-1
  priority_queue<P, vector<P>, greater<P> > q;
  q.push(mp(0,0));
  vector<int> cost(n+m, INF);
  cost[0]=0;
  while(!q.empty()){
    P p = q.top(); q.pop();
    int now = p.se;
    if(cost[now]<p.fi) continue;
    for(auto nxt : v[now]){
      if(cost[nxt] > cost[now] + 1){
        cost[nxt] = cost[now]+1;
        q.push(mp(cost[nxt], nxt));
      }
    }
  }

  if(cost[n-1]==INF) cout<<-1<<endl;
  else cout<<cost[n-1]/2<<endl;

  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d.at(i);
    }
    sort(d.begin(), d.end());
    int ans = 1;
    for (int i = 1; i < n; ++i) {
        if (d.at(i - 1) < d.at(i)) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <algorithm>

#define NMAX 100
#define WMAX 10000

using namespace std;

struct Node {
	int v;
	int w;
};

Node C[NMAX+1];
int T[NMAX+1][WMAX+1];
int N,W;

int main() {
	int i,j;
	
	scanf("%d %d",&N,&W);
	
	for(i=1;i<=N;i++) {
		scanf("%d %d",&C[i].v,&C[i].w);
	}
	
	for(i=0;i<=W;i++) {
		T[0][i]=0;
	}
	
	for(i=1;i<=N;i++) {
		T[i][0]=0;
	}
	
	for(i=1;i<=N;i++) {
		for(j=1;j<=W;j++) {
			T[i][j]=T[i-1][j];
			if(C[i].w>j) continue;
			if(C[i].v+T[i-1][j-C[i].w]>T[i-1][j]) {
				T[i][j]=C[i].v+T[i-1][j-C[i].w];
			}
		}
	}
	
	printf("%d\n",T[N][W]);
	
	return 0;
}


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

int main(){
    int N, M, W;
    cin >> N >> M >> W;
    vector<vector<pair<int, int>>> edges(N);
    vector<int> indeg(N);
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        edges[a].emplace_back(b, c);
        indeg[b]++;
    }

    queue<int> que;
    for(int i=0; i<N; i++) if(indeg[i] == 0) que.push(i);
    vector<bitset<101>> dp(N);

    while(que.size()){
        int i = que.front();
        que.pop();
        for(auto& p : edges[i]){
            int j = p.first, c = p.second;
            dp[j] |= dp[i]<<c;
            dp[j][c] = 1;
            indeg[j]--;
            if(indeg[j] == 0) que.push(j);
        }
    }

    int ans = -1000;
    for(int i=0; i<N; i++) for(int j=0; j<abs(W); j++) if(dp[i][j]) ans = max(ans, j+W);
    if(ans == -1000){
        cout << "NA" << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 14980
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  set<char> s1;
  s1.insert('M');
  s1.insert('A');
  s1.insert('R');
  s1.insert('C');
  s1.insert('H');
  map<char,int> m1;
  int n;
  cin>>n;
  rep(i,0,n){
    string s;
    cin>>s;
    if(s1.find(s[0])!=s1.end())m1[s[0]]++;
  }
  vector<ll> v1;
  for(auto i:m1) v1.pb(i.s);
  ll cnt=0;
  rep(i,0,v1.size()){
    rep(j,i+1,v1.size()){
      rep(k,j+1,v1.size()){
        cnt+= v1[i]*v1[j]*v1[k];
      }
    }
  }
  cout<<cnt<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    {solve();}
}


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

long count(long n, long x, vector<long>& NL, vector<long>& M) {
  if (x <= 0) return 0;
  if (n == 0) return 1;
  if (M[n] != 0 && x == NL[n]) {
    return M[n];
  }

  long ans = 0, Lm1 = NL[n-1];
  if (x == 1) return 0; x--;
  if (Lm1 < x) {
    ans += count(n-1, Lm1, NL, M);
    x -= Lm1;
    M[n-1] = ans;
    ans++; x--;
    if (x == 0) return ans;
    x = min(x, Lm1);
    ans += count(n-1, x, NL, M);
  } else {
    ans += count(n-1, x, NL, M);
  }
  return ans;
}

int main() {
  long N, X;
  cin >> N >> X;
  vector<long> NL(51);
  NL[0] = 1;
  for (int i = 1; i <= 50; i++) {
    NL[i] = 3 + 2 * NL[i-1];
  }
  vector<long> M(51, 0);
  cout << count(N, X, NL, M) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int Q;
    cin >> Q;
    vector<int> M(Q);
    vector<bool> ok(Q);
    rep(i, Q) cin >> M[i];
    for(int bit = 0; bit < (1 << N); bit++) {
        int sum = 0;
        rep(i, N) {
            if(bit & (1 << i))
                sum += A[i];
        }
        rep(i, Q) {
            if(sum == M[i])
                ok[i] = true;
        }
    }
    rep(i, Q) { cout << (ok[i] ? "yes" : "no") << '\n'; }
    return 0;
}


Measured memory_bytes: 3092
#include<stdio.h>

int main(){
    int i,N;
    int count=0;
    int a[1000]={};
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<N;i++){
        if(a[i]==a[i+1]){
            if(a[i]+a[i+1]<10000){
                a[i+1]=a[i]+a[i+2];
                count++;
            }
            else{
                a[i+1]=1;
                count++;
            }
        }
    }
    
    printf("%d",count);
    
    return 0;
}

Measured memory_bytes: 128
while (n = gets.to_i) != 0 do
	a_s = b_s = 0

	n.times do
		a, b = gets.split.map(&:to_i)

		if a > b then
			a_s += (a + b)
		elsif a == b then
			a_s += a
			b_s += b
		else
			b_s += (a + b)
		end
	end

	puts "#{a_s} #{b_s}"
end

Measured memory_bytes: 6100
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
        int[] number = new int[n];
        int a;

        for(int i = 0; i < n; i++){
            a = sc.nextInt();
            number[a - 1] = i + 1;
        }

        for(int i = 0; i < n; i++){
            System.out.print(number[i] + " ");
        }

        System.out.println();

    }

}


Measured memory_bytes: 60260
n,m,c=map(int, input().split())
b=list(map(int, input().split()))
cnt = 0
for i in range(n):
  a=list(map(int, input().split()))
  sum = c
  for j in range(m):
  	sum += b[j]*a[j]
  if sum > 0:
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
a, b, c = map(int, input().split())

cnt = 0
for i in range(50000000):
    if a%2 + b%2 + c%2 >= 1:
        print(cnt)
        break
    new_a = (b + c) // 2
    new_b = (c + a) // 2
    new_c = (a + b) // 2
    a, b, c = new_a, new_b, new_c
    cnt += 1
else:
    print(-1)

Measured memory_bytes: 40300