akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;
const ll mod = (ll)1e9 + 7;

ll powmod(ll a, ll k, ll m) {
  if (k == 0) return 1;
  ll t = powmod(a, k / 2, m);
  t = (t * t) % mod;
  if (k % 2 == 1) t = (t * a) % mod;
  return t;
}

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  bool has = false;
  rep(i, n) {
    int c, d;
    cin >> c >> d;
    if (c == d)
      cnt++;
    else
      cnt = 0;
    if (cnt >= 3) has = true;
  }
  if (has)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>

using namespace std;

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

int main(void)
{
	int n;
	cin >> n;
	long long t[105];
	for(int i=1;i<=n;i++)
		cin >> t[i-1];
	
	long long ans=t[0];

	for(int i=2;i<=n;i++)
	{
		ans=ans/gcd(ans,t[i-1])*t[i-1];
	}

	cout << ans << endl;
}

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

n, K = [int(w) for w in input().split()]
dd = collections.defaultdict(int)

for i in range(n):
    a, b = [int(w) for w in input().split()]
    dd[a] += b

s_dd = sorted(dd.items(), key=lambda x: x[0])

i = 0
ans = 0
for k, v in s_dd:
    i += v
    if i >= K:
        ans = k
        break
print(ans)


Measured memory_bytes: 21288
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

class C{
  public:
    int id, u, a, p;
    C(){}
    bool operator < (const C &c) const {
      if(a != c.a) return a > c.a;
      if(p != c.p) return p < c.p;
      return id < c.id;
    }
};

int main() {
  int N;
  while(cin >>N && N){
    vector<C> T(N);
    REP(i, N) cin >>T[i].id >>T[i].u >>T[i].a >>T[i].p;
    SORT(T);
    map<int, int> m;
    int cnt = 0;
    REP(i, N){
      if(cnt < 10){
        if(m[T[i].u] < 3){
          cout <<T[i].id <<endl;
          m[T[i].u] += 1;
          ++cnt;
        }
      } else if(cnt < 20){
        if(m[T[i].u] < 2){
          cout <<T[i].id <<endl;
          m[T[i].u] += 1;
          ++cnt;
        }
      } else if(cnt < 26){
        if(m[T[i].u] < 1){
          cout <<T[i].id <<endl;
          m[T[i].u] += 1;
          ++cnt;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define Would
#define you
#define please

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

	int N, M, X;
	cin >> N >> M >> X;
	int A;
	int mae = 0;
	int ato = 0;
	rep(i, M) {
		cin >> A;
		if (A < X) mae++;
		else ato++;
	}
	co(min(mae, ato));

	Would you please return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
pst = [[] for _ in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  pst[a].append(b)
s,t = map(int,input().split())
s -= 1
t -= 1
cnt = [[0,0,0] for _ in range(n)]
cnt[s][0] = 1
now = [s]
time = 0
while now:
  time += 1
  last = now
  now = []
  for x in last:
    for y in pst[x]:
      if cnt[y][time%3] == 0:
        cnt[y][time%3] = 1
        now.append(y)
  #print(time,cnt,now)
  if cnt[t][0] == 1:
    print(time//3)
    break
else:
  print(-1)

Measured memory_bytes: 28160
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
int inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
int n, m;
Graph a;

//inputします
void input() {
    cin >> n >> m;
    a.resize(m+1);
    ff(i, 0, n) {
        int day, get;
        cin >> day >> get;
        if (day <= m) {
            a[day].push_back(get);
        }
    }
}

//ライブラリ置き場



//main
int main() {
    input();
    priority_queue<int> pre;
    i64 ans = 0;
    ff(i, 1, m+1) {
        ff(j, 0, a[i].size()) {
            pre.push(a[i][j]);
        }
        if (!pre.empty()) {
            ans += pre.top();
            pre.pop();
        }
    }
    cout << ans << endl;
	return 0; 
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,H,W;
  int answer = 0;
  cin >> N >> H >> W;
  vector<long int> h(N);
  vector<long int> w(N);
  for(int i = 0;i < N;i++){
    cin >> h.at(i) >> w.at(i);
    if(h.at(i) >= H && w.at(i) >= W) answer++;
  }
  cout << answer << endl;
}
    

Measured memory_bytes: 256
// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e6 + 69 , MOD = 1e9 + 7 ; 

int n , arr[MAXN][5] , dp[MAXN][5] ;

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n ;
	for ( int i = 1 ; i <= n ; i ++ )
		for ( int j = 1 ; j <= 3 ; j ++ )
			cin >> arr[i][j] ;
	for ( int i = 1 ; i <= n ; i ++ ) {
		dp[i][1] = max(dp[i - 1][2] , dp[i - 1][3]) + arr[i][1] ;
		dp[i][2] = max(dp[i - 1][1] , dp[i - 1][3]) + arr[i][2] ;
		dp[i][3] = max(dp[i - 1][1] , dp[i - 1][2]) + arr[i][3] ;
	}
	int ans = 0 ;
	for ( int i = 1 ; i <= 3 ; i ++ )
		ans = max(ans , dp[n][i]) ;
	cout << ans << "\n" ;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=2e5+5;

int n;
string s;
set<string>sety;

int main(){
//	fri("in.txt");
//	fro("out.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	while(n--){
		cin>>s;
		sety.insert(s);
	}
	cout<<sety.size()<<endl;
return 0;
}

Measured memory_bytes: 19128
// -*- coding:utf-8-unix -*-

// use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
// use std::convert::TryInto;
use libm::*;
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
use superslice::*;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//abc115-D
#[fastout]
fn main() {
    input![n: u64, x: u64];

    println!("{}", go(n, x));
}

fn go(level: u64, x: u64) -> u64 {
    // println!("{}", size_burger(50));
    // println!("{}, {}", level, x);

    let max_size = size_burger(level);

    if level == 0 && x == 1 {
        return 1;
    } else if x <= 1 {
        return 0;
    }

    if max_size - 1 <= x {
        return size_meet(level);
    }

    let bound = max_size / 2;
    if x <= bound {
        return go(level - 1, x - 1);
    } else {
        return size_meet(level - 1) + 1 + go(level - 1, x - size_burger(level - 1) - 2);
    }
}

fn size_burger(level: u64) -> u64 {
    (pow(2.0, level as f64 + 2.0) - 2.99999999999999999) as u64
}

fn size_meet(level: u64) -> u64 {
    (pow(2.0, level as f64 + 1.0) - 0.99999999999999999) as u64
}


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

const int MOD = 1000000007;
const int INF = 1000000007;
const int N = 200002;
const int logN = 20;

int a[256];
int t, p;

inline void No() {
    cout << "No\n";
    exit(0);
}

inline void Yes() {
    cout << "Yes\n";
    exit(0);
}

int main() {
  int n, m;
  cin >> n >> m;
  char c;
  for (int i = 1; i <= m*n; ++i) {
    cin >> c;
    a[c]++;
    if (a[c]&1) {
      t++;
    }
    else {
      t--;
    }
    if (a[c]%4 == 3) {
      p--;
    }
    if(a[c]%4 == 2) {
      p++;
    }
  }
  cerr << t << " " << p<< endl;
  if (t > 1) {
    No();
  }
  if (n%2 == 1 && m%2 == 1 && t != 1) {
    No();
  }
  if ((n*m)%2 == 0 && t) {
    No();
  }
  if (n%2 == 0 && m%2 == 0 && p) {
    No();
  }
  if (n%2 == 0 && m%2 == 0 && !p) {
    Yes();
  }

  if (n%2 == 1 && m%2 == 1) {
    if (p > n/2 + m/2) {
      No();
    }
    Yes();
  }

  if (n%2 == 0) {
    swap(n, m);
  }

  if (p > m/2) {
    No();
  }
  Yes();
  return 0;
}

//1 3 3 4 4 6 100 200


Measured memory_bytes: 256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

s=input()
t=input()

for i in range(len(s)):
  s=s[-1]+s[:-1]
  if s==t:
    print('Yes')
    exit()

print('No')

Measured memory_bytes: 9080
# 桁DPは、
# 「０以上N以下の整数で、ある条件を満たすものの個数を求めよ」
# 「０以上N以下の整数で、ある条件を満たすものの最大値を求めよ」
# といった問題を解く場合に用いられる方法です。
# https://qiita.com/pinokions009/items/1e98252718eeeeb5c9ab

n = input()
k_in = int(input())

# dp[i][smaller][k] := 上位からi桁目まで見て、smaller（nと一致しているいない）で非0の桁がk個だけあるものの数
# i <= 101, k <= 3 より、マス目の数は高々606。

# k = 4まで取っておくと（番兵）漸化式の場合分けをしなくて良いから楽。ただしループは
dp = [[[0 for _ in range(4 + 1)] for _ in range(2)] for _ in range(len(n))] 

digit = int(n[0])

dp[0][False][0] = 1
dp[0][False][1] = digit - 1
dp[0][True][1] = 1

for i in range(len(n) - 1):
    for smaller in [True, False]:
        for k in range(4):
            # 配るDPのほうが楽そうな予感
            if not smaller:
                # 0をつけたら
                dp[i+1][False][k] += dp[i][smaller][k]
                # 1~9をつけたら
                dp[i+1][False][k+1] += 9 * dp[i][smaller][k]
            else:
                next_digit = int(n[i+1])
                if next_digit == 0:
                    # 0をつけるしかない
                    dp[i+1][True][k] += dp[i][smaller][k]
                else:
                    # 0をつけたら
                    dp[i+1][False][k] += dp[i][smaller][k]
                    # 1〜(next_digit - 1)をつけたら
                    dp[i+1][False][k+1] += (next_digit - 1) * dp[i][smaller][k]
                    # next_digit をつけたら
                    dp[i+1][True][k+1] += dp[i][smaller][k]

print(dp[len(n)-1][True][k_in] + dp[len(n)-1][False][k_in])


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
void haichi(void);
void Block(int,int);
int c,d,x,y,xg,yg,M,Flag;
int MAP[102][102],MF[102][102];
int main(void)
{
	int w,h,xs,ys,n;
	while(1){
		Flag=0;
		memset(MAP,0,sizeof(MAP));
		memset(MF,0,sizeof(MF));
		scanf("%d %d",&w,&h);
		if(w == 0 && h == 0) break;
		scanf("%d %d %d %d",&xs,&ys,&xg,&yg);
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d %d %d %d",&c,&d,&x,&y);
			haichi();
		}
		/*for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				printf("%d",MAP[i][j]);
			}
			printf("\n");
		}*/
		M = MAP[ys][xs];//
		if(MAP[ys][xs] == MAP[yg][xg])
			Block(xs,ys);
		if(Flag==1)
			printf("OK\n");
		else
			printf("NG\n");
	}
	return 0;
}

void haichi(void)
{
	if(d==0){
		MAP[y][x]=c;MAP[y][x+1]=c;MAP[y][x+2]=c;MAP[y][x+3]=c;
		MAP[y+1][x]=c;MAP[y+1][x+1]=c;MAP[y+1][x+2]=c;MAP[y+1][x+3]=c;
	}
	else if(d==1){
		MAP[y][x]=c;MAP[y][x+1]=c;
		MAP[y+1][x]=c;MAP[y+1][x+1]=c;
		MAP[y+2][x]=c;MAP[y+2][x+1]=c;
		MAP[y+3][x]=c;MAP[y+3][x+1]=c;
	}
}

void Block(int X,int Y)
{
	MF[Y][X] = 1;
	//printf("%d",M);
	if(X == xg && Y == yg)
		Flag = 1;
	if(Y>0 && X>0){
		if(MAP[Y-1][X] == M && MF[Y-1][X] == 0){
			Block(X,Y-1); //???
			MF[Y][X-1]=0;
		}
		if(MAP[Y+1][X] == M && MF[Y+1][X] == 0){
			Block(X,Y+1); //???
			MF[Y+1][X]=0;
		}
		if(MAP[Y][X-1] == M && MF[Y][X-1] == 0){
			Block(X-1,Y); //???
			MF[Y][X-1]=0;
		}
		if(MAP[Y][X+1] == M && MF[Y][X+1] == 0){
			Block(X+1,Y); //???
			MF[Y][X-1]=0;
		}
	}
}

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

int main() {
	long n=0,max=0,min=0,a=0,all=0;//n=数、a=整数 all=合計
	cin >>n;
	for (int i=1;i<=n ;i++ )
	{
		cin>>a;
		all+=a;
		if(i==1)
		{
			max=a,min=a;
		}
		if(a>max)
		{
			max=a;
		}
		if(a<min)
		{
			min=a;
		}
	}
	cout<<min<<" "<<max<<" "<<all<<endl;
	return 0;
}



Measured memory_bytes: 3084
from collections import deque
K=int(input())
Graph1=[0 for i in range(K)]
Graph0=[0 for i in range(K)]
Graph1[K-1]=0
for i in range(K-2):
  Graph1[i+1]=i+2
for i in range(1,K):
  Graph0[i]=(10*i)%K
l=1
q=deque([(1,1)])
Visited=[0]*K

while q:
  x,d=q.popleft()
  if x==0:
    ans=d
    break
  if Visited[x]==1:
    continue
  Visited[x]=1
  if Visited[Graph0[x]]==0:
    q.appendleft((Graph0[x],d))
  if Visited[Graph1[x]]==0:
    q.append((Graph1[x],d+1))
print(ans)      

      
      
  


Measured memory_bytes: 46004
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    T = read_ints()
    M = read_int()
    S = sum(T)
    for _ in range(M):
        p, x = read_ints()
        print(S-T[p-1]+x)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 62852
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];
    for (int i = 0; i < n; i++)
        cin >> q[i];

    vector<int> prm(n);
    for (int i = 0; i < n; i++)
        prm[i] = i + 1;

    int prm_counter = 0, counter_p, counter_q, position_p = 0, position_q = 0;

    do
    {
        prm_counter++;
        for (int i = 0; i < n; i++)
        {
            if (prm[i] == p[i])
                counter_p++;
            if (prm[i] == q[i])
                counter_q++;
        }
        //全て等しかったら場所記録
        if (counter_p == n)
            position_p = prm_counter;
        if (counter_q == n)
            position_q = prm_counter;

        counter_p = 0;counter_q = 0;
    } while (next_permutation(prm.begin(), prm.end()));

    cout << abs(position_p - position_q) << endl;

    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
 	int n; cin >> n;
 	for(int i=1;i<=n+5;i++){
 		int k=i*1.08;
 		if(k==n){
 			cout << i << endl;
 			return 0;
 		}
 	}
 	cout << ":(" << endl;
}

Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

S = input()

def isKaibun(S):
    flag = True

    for i in range(len(S)):
        if S[i] != S[len(S) - i - 1]:
            flag = False
    
    return flag

N = len(S)
print("Yes" if (isKaibun(S) and isKaibun(S[0 : int((N-1)/2)]) and isKaibun(S[int((N+3)/2)-1 : N])) else "No")


Measured memory_bytes: 38384
from heapq import heappush, heappop
N = int(input())
children = [0]*N
parents = [-1]
for i in range(N-1):
    a = int(input())-1
    parents.append(a)
    children[a] += 1

depth = [0]*N
leaf = [(0, i) for i, c in enumerate(children) if c==0]
while leaf:
    d, l = heappop(leaf)
    p = parents[l]
    if p==-1:
        continue
    depth[p] = max(depth[p], d)+1
    children[p] -= 1
    if children[p]==0:
        heappush(leaf, (depth[p], p))

print(depth[0])

Measured memory_bytes: 89636
x = int(input())
# 例 x =14
# 14/2 == 0(break)　x+= 1 ,15/3 == 0(break) x+= 1 ,16/2 = 0(break) x+= 1 ,17は割り切れない（素数）のでelse
while True:
    for i in range(2,x):
        if x%i == 0:
            break
    else:
        print(x)
        break
    x += 1

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<int> A(n+1);
  rep(i, m) {
    int l, r; cin >> l >> r;
    l--;
    A[l]++;
    A[r]--;
  }
  rep(i, n) A[i+1] += A[i];
  int ans = 0;
  rep(i, n) if(A[i] == m) ans++;
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3700
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

int power(int x, int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
int modInverse(int n, int p) 
{ 
    return power(n, p-2, p); 
} 
int ncr(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    int fac[n+1]; 
    fac[0] = 1; 
    for (int i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 

signed main() {
   tezz
   
   int x,y;
   cin >> x >> y;
   int t=(x+y);
   if(t%3!=0){
       cout << 0;
       return 0;
   }
   t/=3;
   int tt=x-t;
//   cout << tt << " " << t << endl;
  if(tt<0 || t<0 || tt>t){
      cout << 0;
      return 0;
  }
   if(tt==0 || tt==t){
       cout << 1;
       return 0;
   }
   if(tt==1 || tt==t-1){
       cout << t;
       return 0;
   }
   
   cout << ncr(t,tt,MOD);
  
   return 0;
}



Measured memory_bytes: 5504
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <tuple>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
int t;
int a[200001];
ll ans = 0;
int main() {
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < n; i++) {
		if (a[i] - a[i - 1] < t) {
			ans += a[i] - a[i - 1];
		}
		else {
			ans += t;
		}
	}
	ans += t;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

vector<int> A, B, C;

LL cnt[1000000];

int main() {
	int N;
	cin >> N;
	int x;
	FOR (i, N) {
		cin >> x;
		A.pb(x);
	}
	sort(all(A));

	FOR (i, N) {
		cin >> x;
		B.pb(x);
	}
	sort(all(B));

	FOR (i, N) {
		cin >> x;
		C.pb(x);
	}
	sort(all(C));
	
	SET(cnt, 0);
	int idx = 0;
	FOR (i, N) {
		while (idx < N && B[i] > A[idx])
			idx++;
		cnt[i] = idx;
	}

	LL ret = 0LL;
	LL sum = 0;
	idx = 0;
	FOR (i, N) {
		while (idx < N && C[i] > B[idx]) {
			sum += cnt[idx];
			idx++;
		}
		ret += sum;
	}
	cout << ret << endl;
	return 0;
}

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

int main(void){
 
  int A,B;
  cin >> A >> B;
  
  if(A%3 == 0 || B%3 == 0 || (A+B)%3==0){
      cout << "Possible" <<endl;
  }
  else{
      cout << "Impossible" <<endl;
  }
}

Measured memory_bytes: 3560
# coding: utf-8
while True:
    n = int(input())
    if n == 0:
        break
    t = 0
    ma = 0
    mi = 1000
    for i in range(n):
        s = int(input())
        t += s
        if(s > ma):
            ma = s
        if(s < mi):
            mi = s
    print((t - ma - mi) // (n - 2))

Measured memory_bytes: 7560
# coding: utf-8
n, k = [int(x) for x in input().split()]
ans = 0
if k > n:
    if k - n < n:
        ans = k - n
    else:
        ans = n
else:
    t = n - k * (n // k)
    # print(t)
    # print(-(t-k))
    if t > -(t-k):
        ans = -(t-k)
    else:
        ans = t
print(ans)

Measured memory_bytes: 3060
N, M = map(int, input().split())
S = [[0 for j in range(2)] for i in range(M)]
for i in range(M):
  X = input().split()
  S[i][0] = int(X[0])
  S[i][1] = str(X[1])
A = [0] * N
p = 0
s = 0
for i in range(M):
  if S[i][1] == "WA":
    if A[S[i][0]-1] != "x": 
      A[S[i][0]-1] += 1
  if S[i][1] == "AC":
    if A[S[i][0]-1] != "x":
      p +=  A[S[i][0]-1]
      A[S[i][0]-1] = "x"
      s += 1
arr = [s, p]
print(*arr)

Measured memory_bytes: 96932
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using ULL = int64_t;
using P = pair<LL, LL>;
#define rep(i, n) for (LL i = 0; i < (n); ++i)
#define all(v) (v).begin(), (v).end()
//#define DEBUG

LL huge = 200 * 1000;
LL n, m;

void bfs(const vector<vector<LL>> e, vector<LL> &c) {
  vector<bool> completed(n, false);
  queue<P> q; // id, current cost
  
  q.push(make_pair((LL)0, (LL)0));

  while (!q.empty()) {
    const LL id = q.front().first;
    const LL cost = q.front().second;
    q.pop();
    #ifdef DEBUG
    cout << id << ":" << cost << endl;
    #endif

    if (completed.at(id)) {
      continue;
    }
    #ifdef DEBUG
    cout << "not completed" << endl;
    #endif

    completed.at(id) = true;
    c.at(id) = cost;

    for (const auto next: e.at(id)) {
      if (!completed.at(next)) {
        q.push(make_pair(next, cost + 1LL));
      }
    }
  }
}

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

  vector<vector<LL>> e(n, vector<LL>()); // edge
  vector<LL> c(n, huge);
  c.at(0) = 0;

  #ifdef DEBUG
  cout << n << endl;
  cout << m << endl;
  #endif
  rep(i, m) {
    LL a, b;
    cin >> a >> b;
    e.at(a - 1).push_back(b - 1);
    e.at(b - 1).push_back(a - 1);
  }
  
  bfs(e, c);
  #ifdef DEBUG
  rep(i, n) {
    cout << i << ":" << c[i] << endl;
  }
  #endif
  LL max_cost = *(max_element(all(c)));
  if (max_cost == huge) {
    cout << "No" << endl;
    return 0;
  }
  
  cout << "Yes" << endl;
  for (LL i = 1; i < n; ++i) {
    for (const auto next: e.at(i)) {
      if (c.at(i) == c.at(next) + 1) {
        cout << next + 1 << endl;
        break;
      }
    }
  }
  

  return 0;
  #ifdef DEBUG
  // cout << 123 << endl;
  #endif
}



Measured memory_bytes: 20648
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;++i) cin>>a[i];
  for(int i=n-1;i>=0;--i) cout<<a[i]<<(i?" ":"\n");
}

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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<ll,int> P;

const ll MAX_N=131072;
int bit[MAX_N*2-1];
ll n;
int main(){
  string A,B,C;cin>>A>>B>>C;
  cout <<A[0]<<B[0]<<C[0]<<endl;
}


Measured memory_bytes: 256
ID     = 'id'
PARENT = 'parent'
DEPTH  = 'depth'
TYPE   = 'type'
POINT  = 'POINT'

n = int(input())
nodes = [{} for _ in range(n)]
for i in range(n):
  detail = list(map(int, input().split()))
  nodes[detail[0]][ID] = detail[0]
  nodes[detail[0]][PARENT] = -1
  nodes[detail[0]][DEPTH] = 0
  nodes[detail[0]][TYPE] = 'root'
  if detail[1] > 0:
    nodes[detail[0]][POINT] = detail[2:]
  else:
    nodes[detail[0]][POINT] = []
    nodes[detail[0]][TYPE] = 'leaf'

for node in nodes:
  if node[POINT]:
    for i in node[POINT]:
      nodes[i][PARENT] = node[ID]

for node in nodes:
  depth = 0
  parent = node[PARENT]
  while True:
    if parent == -1:
      break
    else:
      parent = nodes[parent][PARENT]
    depth += 1
  node[DEPTH] = depth

for node in nodes:
  if node[PARENT] == -1:
    node[TYPE] = 'root'
  elif len(node[POINT])>0:
    node[TYPE] = 'internal node'

for node in nodes:
  print ('node {id}: parent = {parent}, depth = {depth}, {type}, {point}'
    .format(id=node[ID], parent=node[PARENT], depth=node[DEPTH], type=node[TYPE], point=node[POINT]))


Measured memory_bytes: 46216
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= 9; j++)
                {
                    if (i * j == N)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
            }

            Console.WriteLine("No");
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13140
N = int(input())
flag = 0
if N%4==0 or N%7==0:
    flag=1
    print("Yes")
else:
    for i in range(7,N,7):
        if (N-i)%4==0:
            flag=1
            print("Yes")
            break
if flag==0:
    print("No")

Measured memory_bytes: 3060
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                while(true){
                        int n = sc.nextInt();
                        if (n == 0) {
                                break;
                        }
                        HashMap<String, Integer> map = new HashMap<String, Integer>();
                        for (int i = 0; i < n; i++) {
                                map.put(sc.next(), sc.nextInt());
                        }
                        int m = sc.nextInt();
                        String[][] memo = new String[m][];
                        for (int i = 0; i < m; i++) {
                                String S = sc.next();
                                int l = sc.nextInt();
                                memo[i] = new String[l + 1];
                                for (int j = 1; j <= l; j++) {
                                        memo[i][j] = sc.next();
                                }
                                memo[i][0] = S;
                        }
                        boolean f = true;
                        while (f) {
                                f = false;
                                for (int i = 0; i < m; i++) {
                                        int num = 0;
                                        for (int j = 1; j < memo[i].length; j++ ) {
                                                num += map.get(memo[i][j]);
                                        }
                                        if (num < map.get(memo[i][0])) {
                                                f = true;
                                                map.put(memo[i][0], num);
                                        }
                                }
                        }
                        System.out.println(map.get(sc.next()));
                }
        }
}

Measured memory_bytes: 32540
dish = [0]*5
for i in range(5):
  dish[i] = int(input())
dish = [i for i in dish if i%10==0] + sorted([i for i in dish if i%10!=0], key=lambda x: -x%10)
sum_ = 0
for d in dish[:-1]:
  sum_ += d
  if sum_%10!=0:
    sum_ -= (sum_%10)
    sum_ += 10
print(sum_+dish[-1])

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 998244353;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  string s;
  cin>>n>>s;
  if(n&1){
    cout<<"No"<<endl;
    return 0;
  }
  int st = n/2;
  for(int i=0;i<st;i++)
    if(s[i]!=s[st+i]){
      cout<<"No"<<endl;
      return 0;
    }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())

ca = (2*math.pi/12 * (h + m/60)) % (2*math.pi)
cb = 2*math.pi * m/60

c = abs(ca - cb)
if c > math.pi:
    c = 2*math.pi - c

print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(c)))

Measured memory_bytes: 9508
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


const int MOD = 1e9+7;

const int N = 400005;
ll fac[N];
ll ifac[N];

ll mpow(ll a, ll n){
  ll p = 1;
  while(n){
    if (n & 1) p = (p * a) % MOD;
    n >>= 1;
    a = (a * a) % MOD;
  }
  return p;
}

ll choose(ll n, ll m){
  if (m < 0 || m > n) return 0;
  return fac[n] * ifac[m] % MOD * ifac[n-m] % MOD;
}

void init(){
  ll f = 1;
  fac[0] = ifac[0] = 1;

  for(int i=1;i<N;i++){
    fac[i] = (i * fac[i-1]) % MOD;
    ifac[i] = mpow(fac[i], MOD - 2);
  }
}

int main() {
  init();
  int n, k;
  cin >> n >> k;
  int n_max = min(n, k+1);

  ll ans = 1;
  for(int i=1;i<n_max;i++){
    ans += choose(n-1, i) * choose(n, i);
    ans %= MOD;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>
#define N 3.141592653589

int main(void)
{
	int a, b;
	char op;
	int ans;

	while (1) {
		scanf("%d %c %d", &a, &op, &b);

		if (op == '?') {
			break;
		}
		else if(op == '+'){
			ans = a + b;
		}
		else if (op == '-') {
			ans = a - b;
		}
		else if (op == '*') {
			ans = a * b;
		}
		else if (op == '/') {
			ans = a / b;
		}

		printf("%d\n", ans);
	}

	
	return 0;
}


Measured memory_bytes: 2056
#include <stdio.h>

int main(void) {
    int n = 0, a = 0;
    int result = 0;
    int oddcnt = 0, e2cnt = 0, e4cnt = 0;
    
    scanf("%d", &n);
    while (n--) {
        scanf("%d", &a);
        if (a % 4 == 0) {
            e4cnt++;
        } else if (a % 2 == 0) {
            e2cnt++;
        } else {
            oddcnt++;
        }
    }
    
    if (e2cnt == 0) {
        if (oddcnt <= e4cnt + 1) {
            result = 1;
        }
    } else {
        if (oddcnt <= e4cnt) {
            result = 1;
        }
    }
    
    printf("%s\n", (result) ? "Yes" : "No");
    
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <string>
#include <iostream>
 
using namespace std;
 
long long gcd(long long a, long long b){
    if(a == 0) return b;
    return gcd(b%a, a);
}
 
int main(void){
  long long x,y;
  std::cin >> x >> y;
 if(x < y){
 cout << x << endl;
return 0;
}
  if(x % y == 0) std::cout << -1 << endl;
  else{
      //long long g = gcd(x,y);
     std::cout << x << endl;
  }
 
  return 0;
}


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    scanf("%lld", &N);
    vector<ll> L(N);
    REP(int, i, 0, N) scanf("%lld", &L.at(i));
    sort(L.begin(),L.end());
    ans = 0;
    REP(int, i, 0, N-2){
        REP(int, j, i+1, N-1){
            REP(int, k, j+1, N){
                //cout << i << j << k << endl;
                if ( L.at(i) + L.at(j) > L.at(k) ){
                    ans++;
                }
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
// clang-format

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;

void solve(std::string t) {
  lli a = 0;

  string s = ">" + t + "<";
  lli n = s.size();
  lli inf = 1e18;
  vector<lli> b(n - 1, inf);
  rep(i, n - 1) {
    if (s[i] == '>' && s[i + 1] == '<') {
      b[i] = 0;
    }
  }
  // cout << s << endl;
  rep(i, n - 1) {

    if (b[i] == 0) {
      for (lli j = i + 1; j < n - 1; j++) {
        if (b[j] != inf) {
          b[j] = max(j - i, b[j]);
          break;
        }
        b[j] = min(j - i, b[j]);
        if(s[j+1] != '<'){
          break;
        }
      }
      for (lli j = i-1; j >= 0; j--) {
        //cout << "J: " << j << " ";
        if (b[j] != inf) {
          b[j] = max(i - j, b[j]);
          break;
        }
        b[j] = min(i - j, b[j]);
        if(s[j] != '>'){
          break;
        }
      }
      //cout << endl;
    }
      // rep(j, n-1) {
      //   cout << b[j] << " " ;
      // }
      // cout << endl;
  }
  lli ans = 0;
  rep(i, n - 1) ans += b[i];
//  rep(i, n - 1) cerr << b[i] << endl;

  cout << ans << endl;
}

int main() {
  int a;
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 5252
n, m = map(int, input().split())
a=list(map(int, input().split()))
s=[0]*(n+1)
for i in range(1, n+1):
    s[i]=s[i-1]+a[i-1]
dic={}
for i in range(n+1):
    tmp=s[i]%m
    if tmp in dic.keys():
        dic[tmp]+=1
    else:
        dic[tmp]=1
ans=0
for i in dic.values():
    ans+=i*(i-1)//2
print(ans)


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

int main()
{
  ll n; cin >> n;
  ll a; cin >> a;
  ll b; cin >> b;
  ll x = n/(a+b);
  ll y = min(n%(a+b), a);
  cout << x*a+y << endl;

  return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : Partition.cpp
// Author      : Ken
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <map>
#include <sstream>
using namespace std;

bool isStable = true;

struct Card{
	char mark;
	int number;
};

void QuickSort(vector<Card>&, int, int);

void Print(vector<Card>& A, int n){
	for(int i=0; i<n; i++){
		cout << A.at(i).mark << A.at(i).number << " ";
	}

	cout << "[" << A.at(n).mark << A.at(n).number << "] ";

	for(int i=n+1; i<A.size()-1; i++){
		cout << A.at(i).mark << A.at(i).number << " ";
	}

	cout << A.at(A.size()-1).mark << A.at(A.size()-1).number << "\n";
}

void Print(vector<Card>& A){
	for(int i=0; i<A.size(); i++){
		cout << A.at(i).mark << " " << A.at(i).number << "\n";
	}
}

int Partition(vector<Card>& A, int p, int r){
	int x = A.at(r).number;
	int i = p-1;
	for(int j=p; j<r; j++){
		//cout << "j: " << j << "\n";
		if(A.at(j).number <= x){
			i ++;
			Card tmp;
			tmp = A.at(i);
			A.at(i) = A.at(j);
			A.at(j) = tmp;
			//cout << "i: " << i << "\n";
			//Print(A);
			//cout << "\n";
		}
	}
	Card tmp = A.at(i+1);
	A.at(i+1) = A.at(r);
	A.at(r) = tmp;

	return i+1;
}



void QuickSort(vector<Card>& A, int p, int r){
	if(p<r){
		int q = Partition(A, p, r);
		//Print(A);
		//cout << "\n";
	    QuickSort(A, p, q-1);
	    QuickSort(A, q+1, r);
	}
}

map<int, string> ReadOrder(vector<Card>& A){
	map<int, string> order;

	for(int i=0; i<A.size(); i++){
		stringstream ss;
		string str;
		ss << A.at(i).mark;
		ss >> str;

		if(order.count(A.at(i).number) == 0){
		    order[A.at(i).number] = str;
		}else{
			order[A.at(i).number] += str;
		}
	}

	return order;
}

void PrintOrder(map<int, string>& A){
	map<int, string>::iterator p;
	for(p = A.begin(); p != A.end(); p++){
		cout << p->first << " " << p->second << " ";
	}
}

bool CheckOrder(map<int, string>& A, map<int, string>& B){
	bool isSame = true;

	map<int, string>::iterator p;
	for(p=A.begin(); p!=A.end(); p++){
		int position = p->first;
		if(A.at(position) != B.at(position)){
			isSame = false;
		}
	}

	return isSame;
}

int main() {
	map<int, string> before_order;
	map<int, string> after_order;

	int n;
	cin >> n;
	vector<Card> A;

	for(int i=0; i<n; i++){
		char mark;
		int number;
		cin >> mark >> number;
		Card card = {mark, number};
		A.push_back(card);
	}
	//Print(A);
	//cout << "\n";
	//cout << "here\n";
	//int ret = Partition(A, 0, n-1);
	before_order = ReadOrder(A);
	QuickSort(A, 0, n-1);
	after_order = ReadOrder(A);

	isStable = CheckOrder(before_order, after_order);

	if(isStable){
		cout << "Stable\n";
	}else{
		cout << "Not stable\n";
	}

	Print(A);
	//cout << "before_order:\n";
	//PrintOrder(before_order);
	//cout << "after_order:\n";
	//PrintOrder(after_order);


	return 0;
}



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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */

signed main() 
{
  string a,b,c;
  cin >> a >> b >> c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) print("YES");
  else print("NO");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 100005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(int N, int pos){return (bool)(N & (1<<pos));}

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

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    string s;
    cin>>s;
    int n = s.size();
    string r(s.begin(), s.begin()+(n-1)/2);
    ///error(r);
    bool flag = true;
    reverse(r.begin(), r.end());
    for(int i = 0; i < r.size(); i++)
        if(s[i]!=r[i])
            flag = false;
    int pos = (n+3)/2;
    string tot = s.substr(pos-1);
    r = tot;
    reverse(r.begin(), r.end());
    for(int i = 0; i < r.size(); i++)
        if(s[i]!=r[i])
            flag = false;
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    //End();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

string alph = "0123456789";
int main() {
    init();

    int n, h, m;
    vector<pair<int, int>> time;
    FOR(i, 0, 2) {
        cin >> n;
        FOR(j, 0, n) {
            cin >> h >> m;
            time.push_back({ h,m });
        }
    }

    SORT(time);
    time.erase(unique(all(time)), time.end());
    vector<string> ans;
    for (auto i : time) {
        tie(h, m) = i;
        string s = to_string(h) + ':';
        if (m < 10)s += '0';
        ans.push_back(s + to_string(m));
    }
    FOR(i, 0, ans.size())cout << ans[i] << (i == ans.size() - 1 ? "\n" : " ");
}


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

int main()
{long long int k,n;
cin>>k>>n;
long long int a[n],b[n],y;
long long int i;
cin>>a[0]; b[0]=a[0];
for(i=1;i<n;i++)
    {cin>>a[i];
    b[i]=a[i]-a[i-1];}
    sort(b,b+n);
 y=max(b[n-1],k-a[n-1]+a[0]);
    cout<<k-y;

}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>A(N);
  int sum=0;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    sum=sum+A.at(i)-1;
  }
  cout<<sum<<endl;
}
  

Measured memory_bytes: 256
fun main(args: Array<String>) {
    agc035a()
}

fun agc035a() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map { it.toLong() }.toLongArray()

    val othersOfZero = aList.filterNot { it == 0L }
    val zeroCount =n-othersOfZero.size

    if (zeroCount == n) return println("Yes")

    if (n % 3 != 0) return println("No")

    if (n / 3 == zeroCount
        && othersOfZero.all { it == othersOfZero.first() }
    ) return println("Yes")
    
    if (othersOfZero.size!=n) return println("No")
    
    val grouped = othersOfZero.groupBy { it }
    
    if (grouped.size != 3 || grouped.map { it.value.size }.any { it!= n/3 }) return println("No")

    val xor = grouped.map { it.key }.reduce { acc, l -> acc xor l }
    
    return println( if (xor==0L) "Yes" else "No") 
}


Measured memory_bytes: 57336
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

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

used = [False] * N
stack = [0]
used[0] = True
while len(stack) != 0:
    tmp = stack.pop()
    for i in graph[tmp]:
        if not used[i]:
            stack.append(i)
            count[i] += count[tmp]
            used[i] = True

print (*count)

Measured memory_bytes: 55856