akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)

vector<ll> get_acum(vector<ll> v){
    int V = v.size();
    vector<ll> acum = {0LL};
    rep(i,V){
        ll x = v[i] + acum.back();
        acum.push_back(x);
    }
    return acum;
}

int main(void){
    int x,y,A,B,C;
    cin >> x >> y >> A >> B >> C;
    vector<ll> a(A), b(B), c(C);
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    rep(i,C) cin >> c[i];
    sort(all(a), greater<ll>());
    sort(all(b), greater<ll>());
    sort(all(c), greater<ll>());
    vector<ll> ab;
    rep(i,x) ab.push_back(a[i]);
    rep(i,y) ab.push_back(b[i]);
    sort(all(ab), greater<ll>());
    auto ab_acum = get_acum(ab);
    auto c_acum = get_acum(c);
    ll res = 0;
    rep(z,C+1){
        int n = x+y-z;
        if (n < 0) continue;
        res = max(res, c_acum[z] + ab_acum[n]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 8432
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n,k;
    scanf("%ld%ld", &n, &k);

    if(k<=(n+1)/2) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int64_t first = 0;
  int64_t second = 2;
  int64_t answer = 1;
  for (int i=0;i < N - 1; i++){
  first = second;
  second = answer;
  answer = first + second;
 }
  printf("%ld",answer);

}

Measured memory_bytes: 3756
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = []
b = []
for i in range(m):
    x = list(map(int, input().split()))
    a.append(x[0])
    b.append(x[1])

ans = [True for i in range(n)]

for x, y in zip(a, b):
    if h[x-1] < h[y-1]:
        ans[x-1] = False
    elif h[x-1] > h[y-1]:
        ans[y-1] = False
    elif h[x-1] == h[y-1]:
        ans[x-1] = False
        ans[y-1] = False

print(ans.count(True))


Measured memory_bytes: 22384
N = int(input())
S = input()

left = 0
for i in range(N):
    if S[i]=="(":
        left+=1
    else:
        left=max(0,left-1)
right = 0
for i in range(N):
    if S[N-i-1]==")":
        right+=1
    else:
        right=max(0,right-1)

print("("*right + S + ")"*left)

Measured memory_bytes: 3060
def lcs c1, c2
	dp = Array.new(c2.length + 1){0}
	c1.each_char do |ch1|
		tmp = dp.dup
		c2.each_char.each_with_index do |ch2, ji|
			j = ji + 1
			if ch1 == ch2
				dp[j] = tmp[j - 1] + 1
			elsif  dp[j] < dp[j - 1] 
				dp[j] = dp[j - 1]
			end
		end
	end
	return dp[-1]
end

n = gets.to_i
dp = Array.new(1001){0}

n.times do
	c1 = gets.chomp
	c2 = gets.chomp


	puts lcs(c1, c2)
end

Measured memory_bytes: 9196
a,b,c = map(int,input().split())
ls = []
p = a%b
for i in range(1,b+2):
    q = p * i
    if q >= b:
        q %= b
    if q not in ls:
        ls.append(q)
    else:
        break
if c in ls:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
  string s;
  cin >> s;
  
  sort(s.begin(), s.end());
  
  set<char> a;
  for (int i=0; i<s.size(); ++i) {
    a.insert(s.at(i));
  }
  
  string alpha = "abcdefghijklmnopqrstuvwxyz";
  auto itr = a.begin();
  for (int i=0; i<26; ++itr, ++i) {
    if (alpha.at(i) != *itr) {
      cout << alpha.at(i) << endl;
      break;
    }
    if (i == 25) cout << "None" << endl;
  }
  
}

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

int main() {
    long n;
    cin >> n;
    long long t = 0;
    long long tmp = 0;
    for (long i=0; i<n; i++) {
        long long a, b;
        cin >> a >> b;
        if (a > t) {
            t = a;
            tmp = b;
        }
    }
    cout << t + tmp << endl;
    return 0;
}


Measured memory_bytes: 384
N = int(input())
T = [int(input()) for i in range(N)]

def gcd(x, y):
    while x % y != 0:
        t = x % y
        x = y
        y = t
    return y

def lcm(T):
    def lcm(x, y):
        g = gcd(x, y)
        return (x // g) * (y // g) * g
    m = T[0]
    for i in range(1, len(T)):
        m = lcm(m, T[i])
    return m

print(lcm(T))


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

	vector<int> solved(n + 1), wa(n + 1);
	int ac = 0;;
	int p;
	string verdict;
	for (int i = 0; i < m; ++i) {
		cin >> p >> verdict;
		if (!solved[p]) {
			if (verdict == "AC") {
				++ac;
				solved[p] = 1;
			} else {
				++wa[p];
			}
		}
	}

	int penalties = 0;
	for (int i = 1; i <= n; ++i) {
		if (solved[i]) {
			penalties += wa[i];
		}
	}

	cout << ac << " " << penalties << "\n"; 

	return 0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
ll N, Ans = 1000, K = 0;cin >> N;
bool C = 0;
vector<ll> V(N);
  
  rep(i, 0, N)cin >> V[i];
  
  rep(i, 1, N){
  
  if(V[i] == V[i - 1])continue;
    
  if(V[i] > V[i - 1] && !C){
    C = 1;K+=floorl(Ans/V[i - 1]);
    Ans-=V[i - 1]*floorl(Ans/V[i - 1]);
    continue;
  }
    
  if(V[i] < V[i - 1] && C){
    Ans+=V[i - 1]*K;
    K = 0;
    C = 0;
    continue;
  }
 
  }
  
if(C && V[N - 1] >= V[N - 2])Ans+=V[N - 1]*K;
  
cout << Ans;
  
}

Measured memory_bytes: 3624
inpl = lambda: list(map(int,input().split()))
N = int(input())
W = inpl()
Sbest = sum(W)/2
S = 0
for i in range(N):
    prevS = S
    S += W[i]
    if S >= Sbest:
        ans = int(min(S-Sbest, Sbest-prevS)*2)
        break
print(ans)

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

int main(void)
{
	string s;
	int w, cnt;

	cin >> s >> w;
	cnt = w;
	rep(i, s.size())
	{
		if (cnt == w)
		{
			cout << s[i];
			cnt = 0;
		}
		cnt++;
	}
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline

N, M = [int(item) for item in input().split()]
A = [int(item) for item in input().split()]
A.sort()

new_dict = defaultdict(lambda: 0)
for i in range(M):
    b, c = [int(item) for item in input().split()]
    new_dict[c] += b
new_dict = sorted(new_dict.items(), key=lambda x: -x[0])

new_list = []
for k, v in new_dict:
    if v > N:
        v = N
    new_list += [k] * v
    if len(new_list) >= N:
        break

new_list = new_list[:N]

#####

n = min(N, len(new_list))
for i in range(n):
    if A[i] >= new_list[i]:
        break
    A[i] = new_list[i]

print(sum(A))


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


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

  int s[n];

  for(int i=0; i<n; i++) cin >> s[i];

  int sum = 0;
  for(int i=0; i<n; i++) sum += s[i];

  sort(s,s+n);

  if(sum % 10 != 0){
    cout << sum << endl;
    return 0;
  }

  for(int i=0; i<n; i++){
    if(s[i] % 10 != 0){
      sum -=s[i];
      cout << sum << endl;
      return 0;
    }
  }

  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
def istri(a, b, c):
	f = False
	if a == b or b == c or c == a:
		return f
	elif a < b+c and b < c+a and c < a+b:
		f = True
	return f

n = int(input())
l = list(map(int, input().split()))
ans = 0
# print(l)
# print(istri(l[0], l[1], l[2]))


for i in range(n-2):
	for j in range(i+1, n-1):
		for k in range(j+1, n):
			if istri(l[i], l[j], l[k]):
				ans += 1
print(ans)		


Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define SWAP(x, y) do { int z = y; y = x; x = z; } while (0)
int main(void)
{
    char str[20001];
    int len,index,num,shu;
    int i,j,k,l;

    while(1) {
        scanf("%s",str);
        if('-'==str[0]) break;
        len=0;
        for(l=0;str[l]!='\0';l++) len++;
        index=0;
        cin>>num;
        REP(i,num) {

            cin>>shu;
            REP(j,shu) {
                str[index+len]=str[index];
                index++;
            }
        }
        REP(k,len) cout<<str[k+index];
        cout<<endl;
}
}



Measured memory_bytes: 3232
#include <stdio.h>

int n;
int S[100000];

int BinarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;

  while (left < right) {
    mid = (left+right) / 2;
    if (S[mid] == key) {
      return 1;
    }
    else if (S[mid] < key) {
      left = mid + 1;
    }
    else {
      right = mid;
    }
  }
  return 0;
}

int main() {
  int m, T[50000];
  int i;
  int count = 0;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }

  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%d", &T[i]);
  }

  for (i = 0; i < m; i++) {
    if (BinarySearch(T[i])) {
      count++;
    }
  }

  printf("%d\n", count);
  

  return 0;
}



Measured memory_bytes: 2308
a = [[0]*12 for _ in range(12)]

INF = 1 << 29

def main():
    # input
    n, m, x = map(int, input().split())
    c = [0]*n
    for i in range(n):
        tmp = list(map(int, input().split()))
        c[i] = tmp[0]
        for j in range(m) :
            a[i][j] = tmp[j+1]

    # どの本を買うか、買わないかを２進数で表す（その状態と１０進数を1対１に対応させてる）
    # 例えば１の時001、２の時010みたいに各bitがその本iを買うなら１、買わないなら０
    ans = INF
    for bit in range(2**n) :
        cost = 0
        d = [0]*m # 各アルゴリズムの理解度をいれる配列
        for i in range(n): #　このループで２進数表現に直して、各桁の１を買った本と対応させてる
            # bitのi番目のbitが立ってる時に入る
            # & 1でシフトしたときにフラグが立っていたら入る。
            # bit(10進数)を2進数で表現したときにi桁目に１が入っていたらTrueを返す
            if (bit>>i&1):
                cost += c[i]
                for j in range(m) :
                    d[j] +=  a[i][j]

        ok = True
        for j in range(m) :
            if d[j] < x: # 各アルゴリズムで理解度がx以下のがあればFalseな組み合わせ
                ok = False

        if ok:
            ans = min(ans, cost)

    if ans == INF : print(-1)
    else : print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9212
import bisect

def main():
    n = int(input())
    a = list(map(int,input().split()))
    m = int(input())
    for _ in range(m):
        b = int(input())
        index = bisect.bisect_left(a,b)
        if index<n and a[index]==b  :print (1)
        else                        :print (0)



if __name__ == '__main__':
    main()




Measured memory_bytes: 17220
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  string w;
  cin >> w;
  sort(w.begin(), w.end());
  vector<int> dif; // 文字が切り替わるタイミング
  dif.push_back(-1);
  for (int i=0; i<w.size()-1; i++) {
    if (w[i]!=w[i+1]) dif.push_back(i);
  }
  dif.push_back(w.size()-1);
  bool beauty = true;
  for (int i=1; i<dif.size(); i++) {
    if ((dif[i]-dif[i-1])%2!=0) {
      beauty = false;
      break;
    }
  }
  if (beauty) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N + 1)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

for _ in range(Q):
    p, x = map(int, input().split())
    counter[p - 1] += x

stack = [(0, -1)]
while stack:
    s, parent = stack.pop()
    counter[s] += counter[parent]
    for n in edge[s]:
        if n == parent:
            continue
        stack.append((n, s))

[print(c, end=" ") for c in counter[:N]]

Measured memory_bytes: 56724
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)
n = I()
a = LI()
g = a[0]
for i in a[1:]:
    g = gcd(g,i)
print(g)

Measured memory_bytes: 58864
/*---------------Go Code GO---------------*/

#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;

template <typename T>
using Order_Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//(order) Set.order_of_key(); (pointer) Set.find_by_order();

#define PI acos(-1.0)
#define O_O                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define precision(a) fixed << setprecision(a)
#define endl '\n'
#define Flush cout << flush
#define LLMX 0x3fffffffffffffff

long long N;

int main()
{
    O_O;

    string S;
    cin >> S;
    long long makeW = 0, ans = 0;

    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == 'W')
        {
            ans += i - makeW;
            makeW++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3732
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  string a;
  cin >> a;
   if(a[0]==a[2]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n,t=map(int,input().split())
ts=list(map(int,input().split()))
time=0
t_=10**10
for i in range(n):
     t__=ts.pop()
     if t_-t__>t:
          time+=t
     else:
          time+=(t_-t__)
     t_=t__
print(time)

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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(A) A.begin(), A.end()
#define SZ(A) (ll)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const ll N = 2e6 + 5;
ll f[N + 1], f_inv[N + 1], b[N + 1];

ll power (ll n, ll k) {
    if (k == 0) return 1;
    ll t = power (n, k / 2);
    if (k % 2 == 0) return (t * t) % mod;
    return (((t * t) % mod) * n) % mod;
}

ll C (ll n, ll k) {
    ll res = (((f[n] * f_inv[n - k]) % mod) * f_inv[k]) % mod;
    return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	b[0] = f_inv[0] = f[0] = 1;
    for (ll i = 1; i <= N; i++) {
        f[i] = (f[i - 1] * i) % mod;
        b[i] = (b[i - 1] * f[i]) % mod;
    }
    ll x = power (b[N], mod - 2);
    for (ll i = N; i >= 1; i--) {
        f_inv[i] = (x * b[i - 1]) % mod;
        x = (x * f[i]) % mod;
    }
    ll r1, r2, c1, c2, X, Y, res = 0;
    cin >> r1 >> c1 >> r2 >> c2;
    for (ll i = c1; i <= c2; i++) {
        X = C(i + r2 + 1, r2);
        Y = C(i + r1, r1 - 1);
        res = (res + X - Y + mod) % mod; 
    }
    cout << res << "\n";
 	return 0;
}

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

// input
string N;


void input() {
    cin >> N;
}


int ctoi(char c) {
    return c - '0';
}


int f(string s) {
    int ret = 0;
    for (char c : s) {
        ret += ctoi(c);
    }
    return ret;
}


int main() {
    input();
    int x = stoi(N);
    string ans;
    if (x % f(N) == 0) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


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

int main() {
  int n;
  cin>>n;
  for(int i=0; i<=n/4;i++){
    if((n-i*4)%7==0){
      cout<<"Yes"<<endl;
      break;
    }
    if(i==n/4){
      cout<<"No"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define ll long long int
#define vr vector
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define loop(i,n) for(i=0;i<n;i++)
#define inp !cin.eof()
#define sec itr->second
#define fir itr->first

ll power(ll x,ll y,ll p)
{
    ll res = 1;

    while (y > 0)
    {

        if (y & 1)
            res = (res*x)%p;


        y = y>>1;
        x = ((x%p)*(x%p))%p;
    }
    return res%p;
}





int main()
{
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     // iterating a loop until input is providing====!cin.eof()

    //ll t; cin>>t;
     //scanf("%lld",&t);
    // while(t--)
        {

         ll n,m,i,x,y,p=0,z,j,k,flag=1,mi=mod,ans=0,sum=0;
          ll a[200007];
         cin>>n;
         loop(i,n)
         {
             cin>>a[i];
         }
         for(i=0;i<n;i++)
         {
             for(j=i+1;j<n;j++)
             {
                 if(a[j]!=a[i])
                 {
                     for(k=j+1;k<n;k++)
                     {
                         if(a[k]!=a[j] && a[k]!=a[i])
                         {
                             if(a[k]+a[j]>a[i])
                             {
                                 if(a[k]+a[i]>a[j])
                                 {
                                     if(a[i]+a[j]>a[k])
                                        sum++;
                                 }
                             }
                         }
                     }
                 }

             }
         }
         cout<<sum;
         cout<<endl;
         }
    return 0;
}



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

int main(void) {
        double l;
        cin >> l;

        double res = (l / 3) * (l / 3) * (l / 3);
        cout << std::fixed;
        cout << std::setprecision(7);
        cout << res << endl;
}


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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,Q,K;
const int MAX_N = 100000;
vector< pair<int,ll> > G [MAX_N];
int par [20] [MAX_N];
ll depth [MAX_N],minDist [MAX_N];
const ll INF = 1e18;

void dfs(int curr,int prev,ll k,ll dist)
{
	depth [curr] = k;
	minDist [curr] = dist;
	for(const auto& it : G [curr]) if(it.first != prev){
		par [0] [it.first] = curr;
		dfs(it.first,curr,k + 1,dist + it.second);
	}
}

int get_lca(int x,int y)
{
	if(depth [x] < depth [y]) swap(x,y);
	for(int i = 19;i >= 0;i--) if(par [i] [x] != -1 && depth [par [i] [x]] >= depth [y]){
		x = par [i] [x];
	}
	if(x == y) return x;
	for(int i = 19;i >= 0;i--) if(par [i] [x] != -1 && par [i] [y] != -1 && par [i] [x] != par [i] [y]){
		x = par [i] [x];
		y = par [i] [y];
	}
	return par [0] [x];
}

ll get_dist(int x,int y)
{
	return minDist [x] + minDist [y] - minDist [get_lca(x,y)] * 2;
}

int main()
{
	scanf("%d",&N);
	FOR(i,0,N - 1){
		int a,b;
		ll c;
		scanf("%d%d%lld",&a,&b,&c);
		a--;
		b--;
		G [a].push_back(make_pair(b,c));
		G [b].push_back(make_pair(a,c));
	}

	dfs(0,-1,0,0);
	FOR(i,1,20) FOR(j,0,N) if(par [i - 1] [j] != -1){
		par [i] [j] = par [i - 1] [par [i - 1] [j]];
	}
	scanf("%d%d",&Q,&K);
	K--;
	FOR(i,0,Q){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		ll ans = get_dist(a,K) + get_dist(K,b);
		printf("%lld\n",ans);
	}

	return 0;
}


Measured memory_bytes: 24448
INFTY = 10**13
def floyd():
    for k in range(n):
        for i in range(n):
            if d[i][k] == INFTY:
                continue
            for j in range(n):
                if d[k][j] == INFTY:
                    continue
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
n = H*W
d = [[0 if i == j else INFTY for j in range(n)]for i in range(n)]

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        for dh, dw in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
            if 0 <= h + dh < H and 0 <= w + dw < W and S[h+dh][w+dw] == '.':
                d[h*W+w][(h+dh)*W+(w+dw)] = 1

floyd()

ans = max([x for row in d for x in row if x != INFTY])
print(ans)

Measured memory_bytes: 49792
#include<stdio.h>
int main()
{
    int x,y,p,d,T,e,f;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d%d%d", &x,&y,&p);

        d = ((x*x)+(y*y));
        e=((y*y)+(p*p));
        f=((p*p)+(x*x));

        if((p*p)==d || (x*x)==e || (y*y)==f)
        {
            printf("YES\n");

        }
        else
            printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	int t; t = 1;
	while(t--){
		string a; cin>>a;
		string b; cin>>b;
		if(b.size() == a.size()+1){
			bool flg = false;
			for(int i=0; i<a.size(); ++i){
				if(a[i] != b[i]){
					flg = true;
					break;
				}
			}
			if(flg){
				cout<<"No\n";
			}
			else{
				cout<<"Yes\n";
			}
		}
		else{
			cout<<"No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int a[200005],b[200005];
int main(){
	int k,n;
	cin>>k>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i>1)
		    b[i]=a[i]-a[i-1];
	}
	b[1]=k-a[n]+a[1];
	sort(b+1,b+n+1);
	cout<<k-b[n];
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

const int INF = 1000000100;
const int MAX_N = 1100;
const int MAX_H = 10100;
int A[MAX_N], B[MAX_N];
int H, N;
int dp[MAX_N][MAX_H];

int main()
{
    scanf("%d %d", &H, &N);
    for(int i = 0; i < N; ++i) scanf("%d %d", &A[i], &B[i]);
    
    for(int i = 0; i <= N; ++i) for(int j = 0; j <= H; ++j) dp[i][j] = INF;
    dp[0][0] = 0;
    for(int i = 1; i <= N; ++i) {
        for(int j = 0; j <= H; ++j) {
            if(j < A[i-1]) dp[i][j] = min(dp[i-1][j], B[i-1]);
            else dp[i][j] = min(dp[i-1][j], dp[i][j-A[i-1]] + B[i-1]);
        }
    }
    printf("%d\n", dp[N][H]);
    return 0;
}

Measured memory_bytes: 41216
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std;
int n,m;
//int *nail[5005];
vector< int > nail[5005];
int main(void)
{
  scanf("%d %d",&n,&m); 

  /*
  for(int i=0;i<=n+3;i++){
    nail[i] = (int*)calloc(i+3,sizeof(int));
  }
  */

  for(int i=0;i<=n+3;i++){
    nail[i].resize(i+3,0);
  }

  for(int i=0;i<m;i++){
    int a,b,x;
    scanf("%d %d %d",&a,&b,&x);
    nail[a][b]++;
    nail[a][b+1]--;
    nail[a+x+1][b]--;
    nail[a+x+2][b+1]++;
    nail[a+x+1][b+x+2]++;
    nail[a+x+2][b+x+2]--;
  }

  /*
  for(int i=1;i<=n+1;i++){
    for(int j=1;j<=n+1;j++){
      printf("%2d",nail[i][j]);
    }
    puts("");
  }
  puts("");
  */

  //横
  for(int i=1;i<=n+2;i++){
    for(int j=1;j <= i+2;j++){
      nail[i][j] += nail[i][j-1];
    }
  } 

  /*
   for(int i=1;i<=n+1;i++){
    for(int j=1;j<=n+1;j++){
      printf("%2d",nail[i][j]);
    }
    puts("");
  }
  puts("");
  */

  //縦
  for(int i=1;i<=n+2;i++){
    for(int j=i;j <= n+2;j++){
      nail[j][i] += nail[j-1][i];
    }
  }   

  /*
   for(int i=1;i<=n+1;i++){
    for(int j=1;j<=n+1;j++){
      printf("%2d",nail[i][j]);
    }
    puts("");
  }
  puts("");
  */
 
  int ret = 0;
  //斜め
  for(int i=1;i<=n;i++){
    if(nail[i][1] > 0) ret++;
    for(int j=1;j <= n-i+1;j++){
      nail[i+j][j+1] += nail[i+j-1][j];
      if(nail[i+j][j+1] > 0) ret++;
    }
  }

  /*
   for(int i=1;i<=n+1;i++){
    for(int j=1;j<=n+1;j++){
      printf("%2d",nail[i][j]);
    }
    puts("");
  }
  puts("");
  */

  /*
  for(int i=1;i<=n;i++){
    for(int j=1;j<=i;j++){
      if(nail[i][j]>0){
	ret++;
      }
    }
  }
  */
 
  printf("%d\n",ret);

  /*
  for(int i=0;i<=n+5;i++){
    free(nail[i]);
  }
  */
}

Measured memory_bytes: 50156
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
	char ABCD[5];
	scanf("%s", ABCD);

	for (int i = 0; i < 4; i++)
		ABCD[i] = ABCD[i] - '0';

	int res = 0;
	for (int i = 0; i < (0x1 << 3); i++) {
		int sum = ABCD[0];
		for (int j = 0; j < 3; j++) {
			if (i & (0x1 << j))
				sum += ABCD[j + 1];
			else
				sum -= ABCD[j + 1];
		}
		if (sum == 7) {
			res = i;
			break;
		}
	}
	printf("%c%c%c%c%c%c%c=7\n", ABCD[0] + '0', res & 1 ? '+' : '-', ABCD[1] + '0', res & 2 ? '+' : '-', ABCD[2] + '0', res & 4 ? '+' : '-', ABCD[3] + '0');
}

Measured memory_bytes: 128
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n, k, l = map(int, input().split())
    p = [list(map(int, input().split())) for _ in range(k)]
    r = [list(map(int, input().split())) for _ in range(l)]
    uf1 = UnionFind(n)
    for a, b in p:
        uf1.union(a-1, b-1)
    uf2 = UnionFind(n)
    for a, b in r:
        uf2.union(a-1, b-1)
    dic = {}
    for i in range(n):
        rt1, rt2 = uf1.find(i), uf2.find(i)
        if (rt1, rt2) in dic:
            dic[(rt1, rt2)] += 1
        else:
            dic[(rt1, rt2)] = 1
    for i in range(n):
        rt1, rt2 = uf1.find(i), uf2.find(i)
        print(dic[(rt1, rt2)], end=" ")

if __name__ == "__main__":
    main()

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

using namespace std;

int n, q, l[(int)1e5], r[(int)1e5], p[(int)1e5];
string s;

int main(){
	cin >> n >> q >> s;
	for(int i = 0; i < q; ++i) cin >> l[i] >> r[i];

	for(int i = 0; i < n - 1; ++i){
		p[i+1] = p[i];
		if(s[i] == 'A' && s[i+1] == 'C') p[i+1]++;
	}
	
	for(int i = 0; i < q; ++i){
		cout << p[r[i]-1] - p[l[i]-1] << endl;
	}
}

Measured memory_bytes: 2176
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  l=[0]*n
  l2=[1]*n

  l[0]=1

  for _ in range(m):
    x,y=LI()
    l2[y-1]+=1
    l2[x-1]-=1

    if l[x-1]>0:
      l[y-1]+=1

      if l2[x-1]==0:
        l[x-1]=0

  sm=0
  for x in l:
    if x>0:
      sm+=1
  return sm

# main()
print(main())


Measured memory_bytes: 6996
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=100005;
typedef pair<int,int> PR;
int n,f[N];
multiset<int> S[N];
map<PR,int> mp;
queue<PR> Q;
int find(int x) {return x==f[x]?x:f[x]=find(f[x]);}
int main()
{
	int x,y;
	n=read();
	for(RI i=1;i<=n;++i) f[i]=i;
	for(RI i=1;i<=2*n-2;++i) {
		x=read(),y=read();
		S[x].insert(y),S[y].insert(x);
		++mp[(PR){x,y}],++mp[(PR){y,x}];
		if((mp[(PR){x,y}])==2) Q.push((PR){x,y});
	}
	multiset<int>::iterator it;
	while(!Q.empty()) {
		x=Q.front().first,y=Q.front().second,Q.pop();
		x=find(x),y=find(y);
		if(x==y) continue;
		S[x].erase(y),S[y].erase(x);
		if(S[x].size()<S[y].size()) swap(x,y);
		for(it=S[y].begin();it!=S[y].end();++it) {
			int z=*it;
			S[z].erase(y),S[z].insert(x);
			++mp[(PR){z,x}],++mp[(PR){x,z}];
			if(mp[(PR){z,x}]==2) Q.push((PR){z,x});
			S[x].insert(z);
		}
		f[y]=x,S[y].clear();
	}
	for(RI i=1;i<=n;++i) if(find(i)!=find(1)) {puts("NO");return 0;}
	puts("YES");
	return 0;
}

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

const int MAX = 510000;
const int MOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];


void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  long long N, M, K;
  cin >> N >> M >> K;
  vector<long long> vec(N+1);// i個のブロックの塊をM色で隣合う色が異なるように塗る数
  vec[0] = 0;
  vec[1] = M;
  COMinit();
  for(int i = 2; i <= N; i++){
    vec[i] = vec[i-1] * (M-1) % MOD;
    vec[i] %= MOD;
  }
  long long sum = 0;
  for(int i = 0; i <= K; i++){
    sum += COM(N-1, i) * vec[N - i] % MOD;
    sum %= MOD;
  }
  cout << sum <<endl;
}


Measured memory_bytes: 16672
s = gets.chomp!
t = gets.chomp!

n = 0
position = 0

t.chars.each do |c|
    unless position = s.index(c, position) then
        n += 1

        unless position = s.index(c) then
            puts -1
            exit
        end    
    end
    position += 1
end

puts s.length * n + position

Measured memory_bytes: 6908
#include <bits/stdc++.h>
using namespace std;
static const int INF = 2000000000;
static const int NIL = -1;
typedef long long ll;
typedef pair<int,int> P;
//#define int ll 

static const int MAX_N = 100;

char s[MAX_N];

signed main(){
    scanf("%s",&s);
    if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I') printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string n, ans = "No";
	cin >> n;
	if (n.at(2) == n.at(1)) {
		if (n.at(0) == n.at(1) || n.at(3) == n.at(1)) {
			ans = "Yes";
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
s = [int(input()) for _ in range(n)]
s.sort()
if sum(s) %10 !=0:
    print(sum(s))
    exit()
else:
    for i in range(n):
        if s[i] %10 != 0:
            print(sum(s) - s[i])
            exit()
        else:
            continue
print(0)

Measured memory_bytes: 8992
#include<stdio.h>
int main(void)
{
    int score[10]={100,100,100,100,100,100,100,100,100},i,sum=0;
    for(i=0;i<6;i++){
        scanf("%d",&score[i]);
        sum+=score[i];
        if(i<4){
            if(score[7]>score[i]){
                score[7]=score[i];
            }
        }
        else {
            if(score[8]>score[i]){
                score[8]=score[i];
            }
        }
    }
    printf("%d\n",sum-score[8]-score[7]);


    return 0;
}

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

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

    vector<int> R(N);
    vector<vector<int> > A(N, vector<int>(N));
    for (int i = 0; i < N; i++)
    {
        cin >> R.at(i);
        A.at(0).at(i) = R.at(i);
    }

        // for (int k = 0; k < N; k++)
        // {
        //     cout << R.at(k);
        // }
        // cout << endl;


    for (int i = 1; i < N; i++)
    {
        int j = i - 1;
        int temp = R.at(i);

        while (R.at(j) > temp)
        {
            R.at(j+1) = R.at(j);
            j--;
            if (j < 0)
            {
                break;
            }
        }

        R.at(j+1) = temp;
        
        for (int k = 0; k < N; k++)
        {
            A.at(i).at(k) = R.at(k);
        }
        
    }
    for (int i = 0; i < N; i++)
    {
        for (int k = 0; k < N; k++)
        {
            cout << A.at(i).at(k);
            if (k != N-1)
            {
                cout << ' ';
            }
            
        }
        cout << endl;
    }
    
    
}


Measured memory_bytes: 3168
#include "bits/stdc++.h"
using namespace std;

#define sz(x) (int)(x.size())
#define FOR(i,L,R) for(int i = L; i <= R; i++)
#define int long long

const int N = 2e5 + 2, inf = 1e18;

int n, m;
std::vector<int> A, B;
int dp[2002][2002];
const int mod = 1e9 + 7;

int go(int i, int j) {
    if (i == n || j == m)
        return 1;
    int &ret = dp[i][j];
    if (~ret)
        return ret;
    int ans = go(i + 1, j)%mod + go(i, j + 1)%mod - (A[i] != B[j] ? go(i + 1, j + 1)%mod : 0);
    while (ans < 0) ans += mod;
    ans %= mod;
    return ret = ans;
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    A.resize(n);
    B.resize(m);
    for(int &x : A) cin >> x;
    for(int &x : B) cin >> x;

    memset(dp, -1, sizeof(dp));
    int ans = go(0,0);
    cout << ans;
}


Measured memory_bytes: 35304
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N, K; cin >> N >> K;
  LL x = N / K;
  if (K % 2 == 0) {
    LL y = N / (K / 2) - x;
    cout << x * x * x  + y * y * y << endl;
  } else {
    cout << x * x * x << endl;
  }
}


Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


void solve(int n){
    vector<int> x(n),y(n);
    int mx=0,my=0,Mx=0,My=0;
    rep(i,n-1){
        int k,d;
        cin>>k>>d;
        if(d==0){
            x[i+1]=x[k]-1;
            y[i+1]=y[k];
            mx=min(mx,x[i+1]);
        }
        if(d==2){
            x[i+1]=x[k]+1;
            y[i+1]=y[k];
            Mx=max(Mx,x[i+1]);
        }
        if(d==1){
            x[i+1]=x[k];
            y[i+1]=y[k]-1;
            my=min(my,y[i+1]);
        }
        if(d==3){
            x[i+1]=x[k];
            y[i+1]=y[k]+1;
            My=max(My,y[i+1]);
        }
    }
    cout<<Mx-mx+1<<" "<<My-my+1<<endl;
}
int main(){
    int n;
    while(cin>>n,n!=0)solve(n);
    return 0;
}


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

import sys
from itertools import accumulate
from bisect import bisect_left

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

cmsm=[0]+list(accumulate(A))
ans=INF
for i in range(2, N-1):
    # 左
    S1=cmsm[i]
    idx1=bisect_left(cmsm, S1/2)
    # 境界の手前と比べて、差が小さい方を取る
    if abs(cmsm[idx1-1]-S1/2)<abs(cmsm[idx1]-S1/2):
        idx1-=1

    # 右
    S2=cmsm[N]-cmsm[i]
    idx2=bisect_left(cmsm, S1+S2/2)
    if abs(cmsm[idx2-1]-(S1+S2/2))<abs(cmsm[idx2]-(S1+S2/2)):
        idx2-=1

    p=cmsm[idx1]-cmsm[0]
    q=cmsm[i]-cmsm[idx1]
    r=cmsm[idx2]-cmsm[i]
    s=cmsm[N]-cmsm[idx2]
    mx=max(p, q, r, s)
    mn=min(p, q, r, s)
    ans=min(ans, mx-mn)
print(ans)


Measured memory_bytes: 25068
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int k,s;cin >> k >> s;
	int ans = 0;
	rep(i,k+1)
		rep(j,k+1)
		{
			if(i+j+k>=s&&s>=i+j)ans++;
		}

	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
int main(){
    int n,p1=0,p2=0;
    string s1,s2;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> s1>> s2;
        if(s1 > s2){
            p1 += 3;
        } else if( s1 < s2 ){
            p2 += 3;
        } else{
            p1 ++;p2++;
        }
    }
    cout << p1  << ' ' << p2 << endl;
}



Measured memory_bytes: 3192
#n=int(input())
n,k=map(int,input().split())
#t=int(input())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

arrived={i:False for i in range(1,n+1)}
#arrived[1]=True
city=[]
before=1
while True:
    nxt=al[before-1]
    if arrived[nxt]:
        break
    arrived[nxt]=True
    city.append(nxt)
    before=nxt
ind=city.index(nxt)
loop=city[ind:]
if k<=ind:
    ans=city[k-1]
else:
    k-=ind
    ans=loop[k%len(loop)-1]
print(ans)

Measured memory_bytes: 40388
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;
#define def 0

int main() {
  //
  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  if (a == b && b == c) {
    if ((a & 1) == 0) {
      cout << -1 << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }

  while ((a & 1) == 0 && (b & 1) == 0 && (c & 1) == 0) {
    ll na = (b + c) / 2;
    ll nb = (a + c) / 2;
    ll nc = (a + b) / 2;
    a = na, b = nb, c = nc;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int n,k;
	cin >> n >> k;
	int num=0;
	for(int i=0;i<n;i++){
		int h;
		cin >> h;
		if(h>=k){
			num++;
		}
	}
	cout << num << endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main() {

    int X, A, B, n;
    string str;
    cin >> X >> A >> B;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> str;
        if (str == "nobiro") X = (X + A >= 0) ? X + A : 0;
        else if (str == "tidime") X = (X + B >= 0) ? X + B : 0;
        else if (str == "karero") X = 0;
    }
    cout << X << endl;
    return 0;
}



Measured memory_bytes: 3212
n = int(input())
a = list(map(int, input().split()))
ans = 1000
stock = 0
for i, num in enumerate(a):
  if i == n-1:
    ans += stock*num
  else:  
    if num > a[i+1]:
      ans += stock*num
      stock = 0
    elif num < a[i+1]:
      stock += ans//num
      ans %= num
    else:
      continue
print(ans)

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

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

    int k, x;
    cin >> k >> x;

    if (500 * k >= x)
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
    return 0;
}

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

int main(){
        long long n;
        vector<long long> dp(31);
        for(int i = 0; i < 31; i++){
                if(i == 0) dp[i] = 1;
                else if(i == 1) dp[i] = dp[i - 1];
                else if(i == 2) dp[i] = dp[i - 2] + dp[i - 1];
                else dp[i] = dp[i - 3] + dp[i - 2] + dp[i - 1];
        }
        while(cin >> n && n > 0){
                long long day, year;
                if(dp[n] % 10 > 0) day = dp[n] / 10 + 1;
                else day = dp[n] / 10;
                if(day % 365 > 0) year = day / 365 + 1;
                else year = day / 365;
                cout << year << endl;
        }
        return 0;
}



Measured memory_bytes: 3012
//g++でビルド

#include "bits/stdc++.h"

using namespace std;

vector<int> watering(vector<int> vec, int s){
    while(vec[s] != 0){
        vec[s]--;
        s++;
        if(vec.size() == s){
            break;
        }
    }
    return vec;
}

int main(){
    int N;
    cin >> N;
    vector<int> flowers;
    int result = 0;

    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        flowers.push_back(a);
    }

    for(int i = 0; i < N; i++){
        while(flowers[i] != 0){
            flowers = watering(flowers, i);
            result++;
        }
    }

    



    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
coins = (500, 100, 50, 10, 5, 1)
while True:
    n = int(input())
    if not n:
        break
    m, c = 0, 1000 - n
    for coin in coins:
        mt, c = divmod(c, coin)
        m += mt
        if not c:
            break
    print(m)

Measured memory_bytes: 7512
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  int x[120] = {};

  for(int i=1; i<=min(a,b); i++){
    if(a%i==0 && b%i==0){
      x[i] = i;
    }
    //cout << x[i] << endl;
  }
  int cnt =0;
  for(int i=min(a,b); i>=1; i--){
    if(x[i] != 0){
      cnt++;
      if(cnt == k){
        cout << x[i];
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359



int main() {
	ll N;
	ll sum = 0;
	ll l, r;
	cin >> N;
	REP(i, N) {
		cin >> l >> r;
		sum += (r - l + 1);
	}
	cout << sum;
	
	return 0;

	
}

Measured memory_bytes: 256
import numpy as np
from collections import Counter
n = int(input())
aa = list(map(int, input().split()))
ngs = np.zeros((10**6)+1, dtype=int)

for a in set(aa):
    ngs[2*a::a] = 1
    
dic = Counter(aa)
times = np.array(list(dic.keys()))[np.array(list(dic.values())) > 1]

for i in times:
    ngs[i] = 1
cnt = 0
for a in aa:
    cnt += 1-ngs[a]
print((cnt))

Measured memory_bytes: 63152
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

signed main() {
    string str;
    cin >> str;

    int ret = INF;

    for (char target : str) {
        string before = str;
        int cnt = 0;

        while (true) {
            bool flag = true;
            for (char c : before) {
                if (c != target) {
                    flag = false;
                    break;
                }
            }
            if (flag) break;

            string after;
            for (int i = 0; i < before.size() - 1; i++) {
                if (before[i] == target || before[i+1] == target) {
                    after += target;
                } else {
                    after += before[i];
                }
            }

            cnt++;
            before = after;
        }

        ret = min(ret, cnt);
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256