akhauriyash/Code-Regression huggingface dataset:
n = int(input())
S = [input() for i in range(n)]

check = [[0] * 26 for i in range(n)]
for i in range(n):
    for j in S[i]:
        check[i][ord(j)-ord('a')] += 1

ans = ''
for i in range(26):
    num = 500
    for j in range(n):
        num = min(num, check[j][i])
    ans += chr(i + ord('a')) * num

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

ll fac[3000000], ifac[3000000];

//comb(fac, ifac, n, k)でnCk
ll comb(int n, int k){
    ll c = fac[n];
    c *= ifac[n-k], c %= MOD;
    c *= ifac[k], c %= MOD;
    return c;
}

//perm(fac, ifac, n, k)でnPk
ll perm(ll fac[], ll ifac[], int n, int k){
    return(fac[n]*ifac[n-k])%MOD;
}
//mpow(x,n)で(x^n)%MODをO(log(n))で計算
ll mpow(ll x, ll n){
    ll res = 1, now = x;
    while(n > 0){
        if(n%2 == 1) res *= now, res %= MOD;
        now *= now, now %= MOD;
        n /= 2;
    }
    return res;
}

int main(){
    ll r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    //1〜nまでのmod(m)における逆元
    ll n = 3e6-1, inv[n+1];
    rep2(i, 1, n){
        inv[i] = mpow(i, MOD-2);
    }
    //i!とi!の逆元
    fac[0] = 1, ifac[0] = 1;
    rep2(i, 1, n){
        fac[i] = (fac[i-1]*i) % MOD;
        ifac[i] = (ifac[i-1]*inv[i]) % MOD;
    }
    //i!とi!の逆元
    fac[0] = 1, ifac[0] = 1;
    rep2(i, 1, n){
        fac[i] = (fac[i-1]*i) % MOD;
        ifac[i] = (ifac[i-1]*inv[i]) % MOD;
    }
    ll ans = 0;
    ans += comb(r2+c2+2, c2+1);
    ans += MOD-comb(c2+r1+1, r1);
    ans += MOD-comb(r2+c1+1, c1);
    ans += comb(r1+c1, r1);
    cout << ans%MOD << endl;
}

Measured memory_bytes: 70528
(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
            vars
            (mapcar (constantly '(read))
                vars)))
       ,@body)))

(defsolver solution-aaa ()
  (let ((l))
    (dotimes (i 4)
      (let* ((c (read-char))
	     (old (rassoc c l :test #'char=)))
	(push (cons (if old (1+ (car old)) 1)
		    c)
	      l)))
    (format t "~:[No~;Yes~]"
	    (= 2 (count 2 l :key #'car)))))

(solution-aaa)

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

namespace ConsoleApp38 {
    class Program {
        static void Main(string[] args) {
            string C1 = Console.ReadLine();
            string C2 = Console.ReadLine();

            if (C1[0] == C2[2] && C1[1] == C2[1] && C1[2] == C2[0]) {
                Console.WriteLine("YES");
            } else {
                Console.WriteLine("NO");
            }

        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    double s = 0;
    repi(i, n, 0)
    {
        int a;
        cin >> a;
        s += 1./a;
    }
    cout << fixed << setprecision(15) << 1./s << endl;
    return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = (x << 3) + (x << 1) + (c ^ 48), c = nc;
  return x;
  #undef nc
}

const int maxn = 2e5 + 10, P = 998244353;
char str[maxn];
int n, dp[2][2][3][3];

set <int> mp;

void dfs() {
  int val = 0;
  rep(i, 1, n) {
    val = (2333ll * val + str[i]) % P;
  }
  if (mp.find(val) != mp.end()) return;
  mp.insert(val);
  rep(i, 1, n - 1) {
    if (str[i] != str[i + 1]) {
      char ch, t1 = str[i], t2 = str[i + 1];
      rep(c, 0, 2) if (t1 - 'a' != c && t2 - 'a' != c) {
        ch = c + 'a';
      }
      str[i] = str[i + 1] = ch;
      dfs();
      str[i] = t1, str[i + 1] = t2;
    }
  }
}

inline void Add(int &x, int y) {
  x += y;
  if (x >= P) x -= P;
}

int main() {
  scanf("%s", str + 1);
  n = strlen(str + 1);
  if (n <= 3) {
    dfs(), printf("%d\n", (int) mp.size());
    return 0;
  }
  int sum = 0;
  bool flg_eq = 1, flg_neq = 1;
  rep(i, 1, n) flg_eq &= str[i] == str[1], flg_neq &= i == n || str[i] != str[i + 1], sum = (sum + str[i] - 'a') % 3;
  if (flg_eq) return puts("1"), 0;
  int sel = 0;
  dp[0][0][0][0] = dp[0][0][1][1] = dp[0][0][2][2] = 1;
  rep(T, 1, n - 1) {
    memset(dp[sel ^ 1], 0, sizeof dp[sel ^ 1]);
    rep(i, 0, 2) {
      rep(j, 0, 2) {
        rep(k, 0, 2) {
          Add(dp[sel ^ 1][1][(i + k) % 3][k], dp[sel][1][i][j]);
          if (j != k) Add(dp[sel ^ 1][0][(i + k) % 3][k], dp[sel][0][i][j]);
          if (j == k) Add(dp[sel ^ 1][1][(i + k) % 3][k], dp[sel][0][i][j]);
        }
      }
    }
    sel ^= 1;
  }
  int res = flg_neq;
  rep(i, 0, 2) Add(res, dp[sel][1][sum][i]);
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 384
d = {}
def solve(h):
    if h in d:
        return d[h]
    if h == 1:
        return 1
    else:
        res = solve(h / 2) * 2 + 1
        d[h] = res
        return res

assert solve(2) == 3
assert solve(4) == 7
assert solve(1000000000000) == 1099511627775

h = int(raw_input())

print solve(h)


Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int time = c;
    rep(i, 101000) {
        if (a * i + b * i <= time && time <= a * (i + 1) + b * i) {
            cout << time << endl;
            return 0;
        } else if (time < a * i + b * i) {
            time += 60;
            i--;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3096
from string import ascii_lowercase


def main():
    n = int(input())
    answer = []
    while n > 0:
        answer.append(ascii_lowercase[n % 26 - 1])
        if n % 26:
            n //= 26
        else:
            n = (n - 1) // 26
    print("".join(answer[::-1]))


if __name__ == '__main__':
    main()



Measured memory_bytes: 9980
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int x,y;
  cin >> x >> y;
  if(x == 1)
    x = 14;
  if(y == 1)
    y = 14;
  if(x > y)
    cout << "Alice" << endl;
  else if(y == x)
    cout << "Draw" << endl;
  else
    cout << "Bob" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll h, n;
    cin >> h >> n;
    vector<pair<ll, ll>> ab(n);
    rep(i, n) cin >> ab[i].first >> ab[i].second;
    const ll inf = LONG_LONG_MAX / 2;
    vector<ll> dp(h + 1, inf);
    dp[0] = 0;
    rep(i, n) {
        rep(ii, h) {
            if (dp[ii] == inf) continue;
            ll next = min(h, ii + ab[i].first);
            dp[next] = min(dp[next], dp[ii] + ab[i].second);
        }
    }
    // rep(i, h + 1) printf("%lld%s", dp[i], (i == h) ? "\n" : " ");
    cout << dp[h] << endl;
    return 0;
}


Measured memory_bytes: 384
n,a,b = map(int,input().split())
mod = 10 ** 9 + 7

# 乗法のmod逆元 (mod-2乗)
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

# nCr mod m
# modinvが必要
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

ans = pow(2, n, mod)
ans -= combination(n,a) + combination(n,b) + 1

print(ans % mod)


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

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll x, k, d;
	cin >> x >> k >> d;
	ll exp = abs(x / d), ans;
	//cout << ans << endl;
	if (k < exp) {
		ans = min(abs(x + (k * d)), abs(x - (k * d)));
	}
	else {
		ll rem = k - exp;
		ans = min(abs(x + exp * d), abs(x - exp * d));
		if (rem % 2) {
			ans = min(abs(ans + d), abs(ans - d));
		}
	}
	cout << ans << endl;
	// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
*/





























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

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

  vector<int64_t> A(N+1);
  
  A.at(0) = 2;
  A.at(1) = 1;
  
  for (int i = 2; i < N+1; i++) {
    A.at(i) = A.at(i-1) + A.at(i-2);
  }
  cout << A.at(N) << endl;
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
int nx[4]={-1,0,1,0};
int ny[4]={0,-1,0,1};


int main()
{
    int h,w;
    int ans=0;
    cin >> h >> w;
    vector <vector<char>> maze(h,vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> maze[i][j];
        }
    }
    for(int si=0;si<h;si++){
        for(int sj=0;sj<w;sj++){
            if(maze[si][sj]=='#') continue;
            vector <vector<int>> dis(h,vector<int>(w,inf));
            queue<pair<int,int>> q;
            dis[si][sj]=0;
            q.push(pair<int,int>(si,sj));
            while(!q.empty()){
                int i=q.front().first;
                int j=q.front().second;
                int oi=i; int oj=j;
                q.pop();
                for(int k=0;k<4;k++){
                    i=oi+nx[k]; j=oj+ny[k];
                    if(i<0||i>=h||j<0||j>=w) continue;
                    if(maze[i][j]=='#'||dis[i][j]!=inf) continue;
                    dis[i][j]=dis[oi][oj]+1;
                    q.push(pair<int,int>(i,j));
                }
            }
            rep(i,h)rep(j,w){
                if(dis[i][j]==inf) continue;
                ans=max(ans,dis[i][j]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)

ll sq(ll x){
	return x*x;
}

int main(void){
	int a,b,h;
	cin >> a;
	cin >> b;
	cin >> h;
	cout << (((a+b)*h)/2) << endl;
	return 0;
}

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

// 関数ポインタ定義
typedef void(*FUNC_POINTER) (int*, int*);

// スタックを実装、操作は以下の３つでそれぞれ0,1,2で操作の種類を指定
// ・push(t, x) : St に整数xを挿入する。
// ・top(t) : Stから次に取り出される要素を報告する。ただし、Stが空の場合は何もしない。
// ・pop(t) : Stから要素を取り出し削除する。ただし、Stが空の場合は何もしない。

void push(int* piData, int* iElementNum);
void top(int* piData, int* iElementNum);
void pop(int* piData, int* iElementNum);

int main()
{
	int iInputN;
	int iInputQ;
	int iInputT;
	int iInputOrder;
	int** ppiData;
	int* iElementNum;
	int iCnt;

	// 関数ポインタ
	FUNC_POINTER pFunc[] = {
		push,
		top,
		pop
	};

	scanf("%d %d", &iInputN, &iInputQ);

	// 初期化
	ppiData = (int**)malloc(sizeof(int*) * iInputN);
	for (iCnt = 0; iCnt < iInputN; iCnt++)
	{
		ppiData[iCnt] = (int*)malloc(sizeof(int) * iInputQ);
	}
	iElementNum = (int*)calloc(iInputN, sizeof(int));

	for (iCnt = 0; iCnt < iInputQ; iCnt++)
	{
		scanf("%d %d", &iInputOrder, &iInputT);
		
		if (iInputOrder == 0 || iInputOrder == 1 || iInputOrder == 2)
		{
			pFunc[iInputOrder](ppiData[iInputT], &iElementNum[iInputT]);
		}
	}

	return 0;
}

// スタックに整数挿入
void push(int* piData, int* iElementNum)
{
	scanf("%d", &piData[*iElementNum]);
	(*iElementNum)++;

	return;
}

// 次に取り出される要素を出力
void top(int* piData, int* iElementNum)
{
	if (*iElementNum <= 0)
	{
		return;
	}
	printf("%d\n", piData[(*iElementNum) - 1]);
	return;
}

// 要素を取り出して削除
void pop(int* piData, int* iElementNum)
{
	if (*iElementNum <= 0)
	{
		return;
	}
	(*iElementNum)--;

	return;
}


Measured memory_bytes: 6508
S = input()
while len(S) > 0:
    if ''.join(S[-5:]) == 'dream' or ''.join(S[-5:]) == 'erase':
        S = S[:-5]
    elif ''.join(S[-6:]) == 'eraser':
        S = S[:-6]
    elif ''.join(S[-7:]) == 'dreamer':
        S = S[:-7]
    else:
        print('NO')
        quit()
print('YES')

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

void solve()
{
	vector<int> a(3);
	int count[2] = { 0 };
	for (int i = 0; i < 3; ++i)
	{
		cin >> a[i];
		if (a[i] == 5)
		{
			++count[0];
		}
		else if (a[i] == 7)
		{
			++count[1];
		}
	}
	if (count[0] == 2 && count[1] == 1)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

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

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

int main(){
  long cash = 100;
  long X;
  cin >> X;
  int count = 0;
  do{
    cash *= 1.01;
    count++;
    //cout << cash << endl;
  }while(cash < X);
  cout << count << endl;
}

Measured memory_bytes: 3644
inputstr = input()
inputlist = inputstr.split()
a = int(inputlist[0])
b = int(inputlist[1])
c = int(inputlist[2])
d = int(inputlist[3])

ac = a*c
ad = a*d
bc = b*c
bd = b*d

max = -9999999999999999999999999
if max < ac:
    max = ac
if max < ad:
    max = ad
if max < bc:
    max = bc
if max < bd:
    max = bd

print(max)

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


def main():
    N = int(input())
    A = [[set(), set()] for _ in range(N)]
    for i in range(N):
        m = int(input())
        for j in range(m):
            x, y = map(int, input().split())
            A[i][y].add(x)

    ans = 0
    for i in range(1 << N):
        h = set()
        u = set()
        for j in range(N):
            if (i >> j) & 1:
                h.add(j+1)
            else:
                u.add(j+1)
        b = True
        for j in range(N):
            if (i >> j) & 1:
                h |= A[j][1]
                u |= A[j][0]
                if u & A[j][1] or h & A[j][0]:
                    b = False
        if b:
            ans = max(ans, bin(i).count("1"))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int cnt=0;
for(int i=0;i<n-2;i++){
for(int j=i+1;j<n-1;j++){
for(int k=j+1;k<n;k++){
if((a[i]<a[k]+a[j])&&(a[k]<a[j]+a[i])&&(a[j]<a[k]+a[i])){
cnt++;
}
}
}
}
cout<<cnt<<endl;
return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll N, A, B; std::cin >> N >> A >> B;
  std::vector<ll> X(N); rep(i,N) std::cin >> X[i];

  ll ans = 0;
  rep(i,N) {
    if ( i == 0 ) continue;
    ll d = X[i] - X[i-1];
    ll walk = d*A;
    ll tele = B;
    ans += std::min(walk, tele);
  }
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pair<int, int> a, pair<int, int> b) {
	return a < b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	llint a,b;
	cin >> a >> b;
	if ((a + b) % 2 != 0) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	cout << (llint)(a + b) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    int n,k;
    cin >> n >> k;
    int mini;
    vector<int>a(n);
    rep(i,n){
        cin >>a[i];
        if(a[i]==1)mini = i;
    }
    if(n-k<=0){
        cout <<1 << endl;
        return 0;
    }else{
        int g = 1;
        while(n>k+(k-1)*(g-1)){
            ++g;
        }
        cout << g << endl;
        return 0;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-11;
const int maxn=2e5+10;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int tmp=min(a,k);
	int ans=tmp;
	k-=tmp;
	k=max(0,k-b);
	if(k){
		ans-=min(c,k);
	}
	cout<<ans<<endl;
 	return 0;
}







Measured memory_bytes: 3504
#include<stdio.h>

int main(){
	
	int c[3][3],i,j,k,b[3][3];
	
	
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
	scanf("%d",&c[i][j]);
	}
	}
	for(i=0;i<101;i++){
		for(j=0;j<101;j++){
			for(k=0;k<101;k++){
				b[0][0]=c[0][0]-i;
				b[0][1]=c[0][1]-i;
				b[0][2]=c[0][2]-i;
				
				b[1][0]=c[1][0]-j;
				b[1][1]=c[1][1]-j;
				b[1][2]=c[1][2]-j;
				
				b[2][0]=c[2][0]-k;
				b[2][1]=c[2][1]-k;
				b[2][2]=c[2][2]-k;
				
				if(b[0][0]==b[1][0]&&b[1][0]==b[2][0]&&b[0][1]==b[1][1]&&b[1][1]==b[2][1]&&b[0][2]==b[1][2]&&b[1][2]==b[2][2]){
					printf("Yes\n");
					return 0;
					
				}
				
				
				
			}
		}
	
	}
	
	
	printf("No\n");
	
	
	
	
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
int main()
{
	int L1,L2,i,m;
	char a[105],b[105];
	scanf("%s %s",&a ,&b);
	L1 = strlen(a);
	L2 = strlen(b);
	if(L1 > L2) printf("GREATER\n");
	else if(L1 < L2) printf("LESS\n");
	else
	{
		i = 0;
		while(a[i] == b[i] && i < L1)
		{
			i++;
		}
		m = i;
		if(m == L1) m = m - 1;
		if(a[m] > b[m]) printf("GREATER\n");
		else if(a[m] < b[m]) printf("LESS\n");
		else printf("EQUAL\n");
	}
	return 0;
}

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

ll gcd(ll a, ll b){
  if (a%b == 0)
  {
    return(b);
  }
  else{
    return(gcd(b, a%b));
  }
}

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

ll cal(ll a, ll b, ll c){
  if(a%c==0) return ((b-b%c)-a)/c+1;
  else return ((b-b%c)-(a+(c-a%c)))/c+1;
}

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll chohuku= lcm(c,d);
  cout << (b-a+1) - (cal(a,b,c) + cal(a,b,d) - cal(a,b,chohuku)) << endl;
  //cout << cal(a,b,c) << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
s = []
res = []
#print(a)
for i in range(H):
  if i % 2:
    for j in range(W):
      s.append((i, j))
  else:
    for j in range(W - 1, -1, -1):
      s.append((i, j))
for i in range(H * W - 1):
  y, x = s[i]
  if a[y][x] % 2:
    res.append((y + 1, x + 1, s[i + 1][0] + 1, s[i + 1][1] + 1))
    a[s[i + 1][0]][s[i + 1][1]] += 1
print(len(res))
for r in res: print(*r)

Measured memory_bytes: 84264
#include <bits/stdc++.h>
#include <cmath>
#include <map> 
using namespace std;
long long komb;
#define mod 1000000007 // nmax 2*10^5 llmax 8*10^18
long long bul(long long n,long long m)
{
	long long son=((((((((n * (n+1) * (2*n+1)) /6) + (n*(n+1)/2)) / 2)%mod)  *  m)%mod)  *  m)%mod;
	return son;
}

long long fcomb(long long n, long long r)
{
	long long i,mi=min(n,n-r),nmu=1,rmu=1,fmo,rmuinv=1;
	for(i=1;i<=mi;i++)
	{
		nmu*=n--;	nmu%=mod;
		rmu*=i; rmu%=mod;
	}
	for(fmo=mod-2;fmo;fmo>>=1)
	{
		rmuinv=(rmuinv*((fmo%2)?rmu:1))%mod;
		rmu*=rmu; rmu%=mod;
	}
	return (nmu*rmuinv)%mod;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	long long n,m,k,i;
	long long yaz=0;
	cin>>n>>m>>k;

	komb=((((m*n-2)%mod)*((m*n-3)%mod)/2)%mod);
	if(k==2 || k==3) komb=1;
	yaz=(bul(n-1,m)+bul(m-1,n))*fcomb((m*n-2),k-2);
	yaz%=mod;

	cout<<yaz<<endl;
	return 0;
}

Measured memory_bytes: 256
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n,k = readInt()
    a = readInt()
    ans = ["Yes\n" for i in range(n-k)]
    for i in range(n):
        if i<k:
            continue
        if a[i]>a[i-k]:
            print("Yes")
        else:
            print("No")
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 31456
#include <bits/stdc++.h>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

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

  int a;
  std::cin >> a;
  int maxA = a;
  int gcd = a;
  bool anyEquals = a == k;
  while (std::cin >> a) {
    anyEquals = anyEquals || (a == k);
    gcd = boost::math::gcd(a, gcd);
    maxA = std::max(a, maxA);
  }
  bool const found = anyEquals || (maxA > k && k % gcd == 0);
  std::cout << (found ? "POSSIBLE" : "IMPOSSIBLE") << std::endl;
  return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string s;
    cin>>s;
    V<ll> a(26,0);
    rep(i,n) a[s[i]-'a']++;
    ll ans=0;
    V<ll> tmp1;
    ll tmp2=0;
    rep(i,(1<<13)){
        //if(i==0) continue;
        ll cnt=1;
        rep(j,13){
            if(i>>j&1){
                cnt=(cnt*a[j])%mod;
            }
        }
        tmp1.push_back(cnt);
    }
    rep(i,(1<<13)){
        ll cnt=1;
        rep(j,13){
            if(i>>j&1){
                cnt=(cnt*a[j+13])%mod;
            }
        }
        tmp2=(tmp2+cnt)%mod;
    }
    for(ll cur:tmp1) ans=(ans+cur*tmp2%mod)%mod;
    ans--;
    if(ans<0) ans+=mod;
    out(ans);
}

Measured memory_bytes: 3692
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from fractions import gcd

A, B, C, D = map(int, input().split())

A -= 1

lcm = C * D // gcd(C, D)

def calc(x):
    count = 0
    count += x // C
    count += x // D
    count -= x // lcm
    return x - count

ans = calc(B) - calc(A)
print (ans)

Measured memory_bytes: 5048
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long

int main(int argc, char const *argv[]){
	int n,m,*a,*b;
	int cnt[57] = { 0 };
	scanf("%d%d",&n,&m);
	a = (int *)malloc(sizeof(int) * m);
	b = (int *)malloc(sizeof(int) * m);	
	for (int i = 0; i < m; ++i)	scanf(" %d%d",&a[i],&b[i]);
	for (int i = 0; i < m; ++i)	++cnt[a[i]];
	for (int i = 0; i < m; ++i)	++cnt[b[i]];
	for (int i = 1; i <= n; ++i)	printf("%d\n",cnt[i]);	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,a) for(int i=0;i<(a);i++)
#define MOD 1000000007

int main(){
  while(1){
    int n; cin>>n;
    if(n==0) break;
    int width[n]={}, height[n]={};
    int maw=0,miw=0,mah=0,mih=0;
    rep(i,n-1){
      int x,y;
      cin>>x>>y;
      if(y==0||y==2){
        width[i+1]=width[x]+(y==2?1:-1);
        miw=min(miw,width[i+1]);
        maw=max(maw,width[i+1]);
        height[i+1]=height[x];
      }else{
        height[i+1]=height[x]+(y==3?1:-1);
        mih=min(mih,height[i+1]);
        mah=max(mah,height[i+1]);
        width[i+1]=width[x];
      }
    }
    cout<<abs(maw-miw)+1<<" "<<abs(mah-mih)+1<<endl;
  }
  return 0;
}



Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main()
{
  int n, k, q;
  cin >> n >> k >> q;
  int p[n] = {};
  REP(i, q) {
    int a;
    cin >> a;
    p[a - 1]++;
  }
  REP(i, n) {
    if (q - p[i] < k) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  map<int, int> a;
  for(int i = 0; i < n; i++){
    int now;
    cin >> now;
    a[now]++;
  }
  
  bool ok = true;
  if(a.size() > 3) ok = false;
  if(a.size() == 1){
    if(!a.count(0)) ok = false;
  }
  if(a.size() == 2){
    if(!a.count(0)) ok = false;
    else{
      if(a.at(0) == n / 3 && n % 3 == 0) ok = true;
      else ok = false;
    }
  }
  if(a.size() == 3){
    queue<int> k;
    for(auto now : a){
      if(now.second != n/3) ok = false;
      if(n%3 != 0) ok = false;
      k.push(now.first);
    }
    int x, y, z;
    x = k.front();
    k.pop();
    y = k.front();
    k.pop();
    z = k.front();
    k.pop();
    int ans = x ^ y ^ z;
    if(ans != 0) ok = false;
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3840
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
int main()
{
  int flag=1;
  ll sum=0;
  int flag1=0;
  ll tot=0;
  int ans=0;
  map<int,int>m;
  vi v;
  set<int>st;
  string s;
  sciii(a,b,c);
  sci(d);
  if((c+b-1)/b<=(a+d-1)/d) cout<<"Yes";
  else cout<<"No";


    return 0;
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> vec(n,0);
  int tmp=0;
  rep(i,n){
    if(s.at(i)=='I') tmp++;
    else tmp--;
    vec.at(i) = tmp;
  }
  sort(vec.begin(), vec.end());
  cout << max(0,vec.at(vec.size()-1)) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int n, a, b;
	int i;
	scanf("%d", &n);
	scanf("%d", &a);
	scanf("%d", &b);

	n = n - a;
	for (i = 0; i < 10000; i++) {
		if (n < b) {
			printf("%d", n);
			break;
		}
		n = n - b;
	}
}

Measured memory_bytes: 128
import math
x = int(input())

def Is_prime(a):
	flag = 0
	for k in range(2,int(math.sqrt(a))+1):
		if a%k == 0:
			flag = 1
	if flag == 0:
		return True
	else:
		return False

while not Is_prime(x):
	x += 1
print(x)

# below is good site about prime number
#https://www.takapy.work/entry/2018/06/26/220608


Measured memory_bytes: 2940
function main(input) {
  const inputs = input.split('\n')
  // console.log(inputs)
  const [N, K] = inputs[0].split(' ').map(BigInt)
  const Ai = inputs[1].split(' ').map(Number)

  // 雑


  // let current = 0
  // const max = 10
  // const path = [1]
  // for(let i = 0; i < K; i++) {
  //   if (max === i) break
  //   current = Ai[current] - 1
  //   path.push(current + 1)
  //   console.log(current)
  // }
  // console.log(path)
  //

  // ループを見つける
  // let loop = [0]
  // let current = 0
  // let count = 0
  // for(let i = 0; i < K; i++) {
  //   console.log(count ++)
  //   current = Ai[current] - 1
  //   if (current === 0) {
  //     console.log('loop found')
  //     break
  //   }
  //   loop.push(current)
  // }
  // console.log(loop)
  // console.log(loop[K % loop.length] + 1)

  // 途中からのループを見つけられない


  let loop = [0]
  let current = 0
  let a = 0
  let visited = []
  for(let i = 0; i < K; i++) {
    current = Ai[current] - 1
    if (visited[current]) {
      // console.log('loop found', current)
      a = loop.indexOf(current)
      loop = loop.slice(loop.indexOf(current))
      break
    }
    visited[current] = true
    loop.push(current)
    // console.log(loop)
  }
  // console.log(a, loop)
  console.log(loop[(K - BigInt(a)) % BigInt(loop.length)] + 1)

}

// main(
//   `6 10
// 6 5 2 5 3 2`
// )
// main(
//   `4 5
// 3 2 4 1`
// )

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


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

using namespace std;

typedef long long ll;

const int maxn = 110;
ll v[maxn], w[maxn];
ll dp[maxn][100010];

int main()
{
    int n, W;
    cin >> n >> W;
    for(int i = 1; i <= n; i++){
        cin >> w[i] >> v[i];
    }
    for(int i = 0; i <= W; i++)
        dp[0][i] = 0;
    for(int i = 0; i <= n; i++)
        dp[i][0] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= W; j++){
            if (j >= w[i]){
                dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    cout << dp[n][W];
    return 0;
}


Measured memory_bytes: 80128
import sys
sys.setrecursionlimit(10 ** 6)
N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append((b, c))
    G[b].append((a, c))
d = [0] * N


def dfs(u, p, k):
    d[u] = k
    for w, c in G[u]:
        if w == p:
            continue
        dfs(w, u, k + c)


Q, K = map(int, input().split())
dfs(K - 1, -1, 0)
for i in range(Q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    print(d[x] + d[y])



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

int n;
char s[233];
int a, w, t, r;

int main(){
	cin >> n;
	while(n--){
		cin >> s;
		if(s[0] == 'A') a++;
		else if(s[0] == 'W') w++;
		else if(s[0] == 'T') t++;
		else r++;
	}
	printf("AC x %d\n", a);
	printf("WA x %d\n", w);
	printf("TLE x %d\n", t);
	printf("RE x %d", r);
	return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)

namespace FastIO {
struct Strs {
  char strs[10000 * 4];
  constexpr Strs() : strs() {
    for (int i = 0; i < 10000; ++i) {
      int j = i;
      for (int t = 3; t >= 0; --t) {
        strs[i * 4 + t] = j % 10 + '0';
        j /= 10;
      }
    }
  }
} constexpr strs;
static constexpr size_t buf_size = 1 << 20;
char buf_in[buf_size], buf_out[buf_size];
size_t pt_in = 0, pt_out = 0, tail_in = 0;
inline size_t num_digits(long long x) {
  if (x >= (long long)1e5) return 6;
  if (x >= (long long)1e4) return 5;
  if (x >= (long long)1e3) return 4;
  if (x >= (long long)1e2) return 3;
  if (x >= (long long)1e1) return 2;
  return 1;
}
inline void load() {
  memcpy(buf_in, buf_in + pt_in, tail_in - pt_in);
  size_t width = tail_in - pt_in;
  tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin);
  pt_in = 0;
}
inline void flush() {
  fwrite(buf_out, 1, pt_out, stdout);
  pt_out = 0;
}
inline void scan(char& c) { c = buf_in[pt_in++]; }
template <class T>
inline void scan(T& x) {
  if (pt_in + 32 > tail_in) load();
  char c;
  bool minus = 0;
  x = 0;
  scan(c);
  while (c >= '0') {
    x = x * 10 + (c & 15);
    scan(c);
  }
  if (minus) x = -x;
}
inline void print(char c) { buf_out[pt_out++] = c; }
template <class T>
inline void print(T x) {
  if (pt_out > buf_size - 32) flush();
  if (x < 0) {
    print('-');
    x = -x;
  }
  size_t digits = num_digits(x);
  int i;
  for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) {
    memcpy(buf_out + i, strs.strs + (x % 10000) * 4, 4);
    x /= 10000;
  }
  memcpy(buf_out + pt_out, strs.strs + x * 4 + (pt_out - i), 4 + i - pt_out);
  pt_out += digits;
}
inline void print(const char* s) {
  if (pt_out > buf_size - 32) flush();
  for (int i = 0; s[i] != 0; ++i) print(s[i]);
}
template <class T>
inline void println(T x) {
  print(x);
  print('\n');
}
struct SetUp {
  SetUp() { load(); }
  ~SetUp() { flush(); }
} setup;
}  // namespace FastIO

using FastIO::print;
using FastIO::println;
using FastIO::scan;

int main() {
  int N;
  scan(N);
  int A[200000], B[200000];
  REP(i, N) scan(A[i]);
  REP(i, N) scan(B[N - 1 - i]);
  int ngs[200000];
  int ngp = 0;
  int ngx = -1;
  REP(i, N) {
    if (A[i] == B[i]) {
      ngs[ngp++] = i;
      ngx = A[i];
    }
  }
  int l = 0, r = N - 1;
  REP(j, ngp) {
    int i = ngs[j];
    int target;
    if (A[l] != ngx && B[l] != ngx) {
      target = l++;
    } else if (A[r] != ngx && B[r] != ngx) {
      target = r--;
    } else {
      println("No");
      return 0;
    }
    swap(B[i], B[target]);
  }
  println("Yes");
  REP(i, N) println(B[i]);
  return 0;
}

Measured memory_bytes: 7308
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  std::string S;
  std::cin >> S;
  std::map< std::string, ll> mm;

  mm["SUN"] = 7;
  mm["MON"] = 6;
  mm["TUE"] = 5;
  mm["WED"] = 4;
  mm["THU"] = 3;
  mm["FRI"] = 2;
  mm["SAT"] = 1;

  print(mm[S]);
  return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int ci = -1, fi = -1;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == 'C') {
      ci = i;
      break;
    }
  for (int i = s.size() - 1; i >= 0; i--)
    if (s[i] == 'F') {
      fi = i;
      break;
    }

  if (ci >= 0 && fi >= 0 && ci < fi) puts("Yes");
  else puts("No");

  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h1, m1, h2, m2, k, ans = 0;
    cin>>h1>>m1>>h2>>m2>>k;
    ll hour = k / 60;
    ll min = k % 60;
    if(m2 - min < 0) {
    	m2 = m2 + 60 - min;
    	h2--;
    } else {
    	m2 = m2 - min;
    }
    h2 -= hour;
    if(m1 > m2) {
    	ans = 60 - m1 + m2;
    	h1++;
    } else {
    	ans = m2 - m1;
    }
    ans = ans + (h2 - h1)*60;
    cout<<ans<<"\n";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

string S;

bool solve() {
    if (S.find("AA") != string::npos) return false;
    if (S.find("KIH") == string::npos) return false;

    size_t c;
    while((c = S.find('A')) != string::npos) {
        S.erase(c, 1);
    }

    return S == "KIHBR";
}

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

    cin >> S;

    cout << (solve() ? "YES" : "NO") << "\n"; 
}

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

#define REP( i, n) for( int i = 0; i < (n); ++i)
#define FOR( i, a, b) for( int i = (a); i < (b); ++i)

#define pb push_back

const int INF = 100100100;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

int main(){

  int n;
  vector<int> v;

  cin >> n;
  v.resize(n);
  REP( i, n){
    cin >> v[i];
  }

  int key;
  int j;
  for( int i = 1; i < v.size()+1; ++i){
    REP( k, n-1){
      std::cout << v[k] << " ";
    }
    cout << v[n-1] << '\n';
    key = v[i];
    j = i-1;
    while( j >= 0 && v[j] > key){
      v[j+1] = v[j];
      --j;
    }
    v[j+1] = key;
  }

}

Measured memory_bytes: 3060
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int[] ans = new int[3];
		ans[0] = a + b;
		ans[1] = a - b;
		ans[2] = a * b;
		Arrays.sort(ans);
		System.out.println(ans[2]);
	}	
}

Measured memory_bytes: 21844
AC = WA = TLE = RE = 0
N = int(input()) #1行目のNを取得する

s = [input() for i in range(N)] #複数行の数値の入力を取得

for v in s:
    if(v == "AC"):
        AC+=1
    elif(v == "WA"):
        WA+=1
    elif(v == "TLE"):
        TLE+=1
    else:
        RE+=1
        
print('AC x %d' % (AC))
print('WA x %d' % (WA))
print('TLE x %d' % (TLE))
print('RE x %d' % (RE))

Measured memory_bytes: 16168
H, W = map(int, input().split())
s_list = [input() for _ in range(H)]

yoko = [[0] * W for _ in range(H)]
tate = [[0] * H for _ in range(W)]


for i in range(H):
    S = s_list[i]
    for j in range(W):
        s = S[j]
        if s == "#":
            continue
        else:
            yoko[i][j] += 1
    for j in range(W):
        if yoko[i][j] == 1 and j > 0:
            yoko[i][j] += yoko[i][j - 1]
    for j in range(W - 1, -1, -1):
        if yoko[i][j] != 0 and j - 1 >= 0 and yoko[i][j - 1] != 0:
            yoko[i][j - 1] = yoko[i][j]
for j in range(W):
    for i in range(H):
        s = s_list[i][j]
        if s == "#":
            continue
        else:
            tate[j][i] += 1
    for i in range(H):
        if tate[j][i] == 1 and i > 0:
            tate[j][i] += tate[j][i - 1]
    for i in range(H - 1, -1, -1):
        if tate[j][i] != 0 and i - 1 >= 0 and tate[j][i - 1] != 0:
            tate[j][i - 1] = tate[j][i]

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, tate[j][i] + yoko[i][j] - 1)
print(ans)


Measured memory_bytes: 123096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, i; cin >> N >> i;
	
	int res = N - i + 1;

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256