akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int const nax = 2e5 + 10;
using ll = long long ;
struct pa{
    int x, h;
    bool operator < (const pa & a) const{
        return x < a.x;
    }
    void read(){
        scanf("%d %d", &x, &h);
    }
}a[nax];
int n, A;
ll d;

ll sum[nax];

int cdiv(ll x, ll y){
    return (x - 1) / y + 1;
}

int main(){
    scanf("%d %lld %d", &n, &d, &A);
    for(int i = 1 ;i <= n; i ++){
        a[i].read();
    }
    sort(a + 1 , a + 1 + n);
    ll ans = 0;
    for(int i = 1 ; i <= n ;i ++){
        sum[i] += sum[i - 1];
        ll now = sum[i] + a[i].h;
        if(now <= 0) continue;
        ans += cdiv(now, A);
        ll tosub = cdiv(now, A);
        ll to = d * 2 + a[i].x;
        to = min(to, (ll)a[n].x);
        int l = i , r = n ,mid, ans1 = -1;
        while(l <= r){
            mid = l + r >> 1;
            if(a[mid].x <= to){
                ans1 = mid;
                l = mid + 1;
            }
            else r = mid  - 1;
        }
        sum[i] -= tosub * A;
        sum[ans1 + 1] += tosub * A;
    }
    printf("%lld\n", ans);
}

/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3328
import sys
sys.setrecursionlimit(1000000)

n, m = map(int, input().split(' '))
steps = [int(input()) for _ in range(m)]

def stepcmb(st):
    memo = [0]*(st+1)
    memo[0] = 1
    def _fib(st):
        if st <= 1:
            return 1
        if memo[st] != 0:
            return memo[st]
        memo[st] = _fib(st-1) + _fib(st-2)
        return memo[st]
    return _fib(st)

if m >= 2:
    for i in range(1, m):
        if steps[i] - steps[i-1] == 1:
            print(0)
            exit()

res = 1
nowstep = 0
for i in range(m):
    res *= stepcmb(steps[i]-nowstep-1) % (10**9+7)
    nowstep = steps[i] + 1
res = (res * stepcmb(n-nowstep)) % (10**9+7)

print(res)
            

Measured memory_bytes: 513140
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int m;
/*
int calc_j(int n,int x,int k)
{
	x=(x%n+n)%n;
//	cerr<<"calc_j:"<<n<<" "<<x<<" "<<k<<endl;
	if(n==1||x==0)return 0;
	if(k>=n)return 1+calc_j(n-1,x-1-k%n,k);
	if(x%k==0)return x/k;
	else
	{
		int id=x/k+1,kill=n/k;
		return kill+calc_j(n-kill,(x-id-(1ll*k*kill%n)),k);
	}
}
int calc(int n,int k)
{
	int sz=n/k+1;
	return sz-calc_j(sz,((sz-n%k)%sz+sz)%sz,k)-1;
}*/
int calc(int n,int k)
{
	if(n%k==0)return n/k;
	else 
	{
		int sz=n/k+1;
		return calc(n-max(1,(n-n/k*k)/sz)*sz,k);
	}
}
int main()
{
	cin>>m;
	int sum=0;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		int tmp=calc(x,y);
		sum^=tmp;
	}
	if(sum==0)puts("Aoki");
	else puts("Takahashi");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,a[100005],b[100005],c[100005];
  long long maxv,dp[100005][5];
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  
  for(int i=1; i<n; i++){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
  }
  
  maxv=max(dp[n-1][0],dp[n-1][1]);
  maxv=max(maxv,dp[n-1][2]);
  cout<<maxv<<'\n';
  return 0;
}


Measured memory_bytes: 5376
from itertools import permutations
 
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
 
p = 0
q = 0
i = 0
for n in permutations(range(1,N+1)):
    if n == P:
        p = i
    if n == Q:
        q = i
    i += 1
 
print(abs(p-q))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(){
    int i,cnt=0,n;
    cin >> n;
    int a[n];
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    for(i=0;i<n;i++){
        if(a[i]!=i+1){
            cnt++;
        }
    }
    if(cnt==2||cnt == 0){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
}

Measured memory_bytes: 256
x = int(input())

check = 0

while True:
  for i in range(x, x*2):
    for j in range(2, x*2):
#      print(i, j)
      if i % j == 0 and i != j:
        break
      elif i == j:
        check += 1
#        print("koko")
        break
    if check > 0:
      break
  break

print(i)

Measured memory_bytes: 62712
void main()
{
    writeln(readln.chomp.count('x') < 8 ? "YES" : "NO");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
r, c = map(int, input().split())
last = [0]*(c+1)
for i in range(r):
    columns = list(map(int, input().split()))
    for j in range(c):
        last[j] += columns[j]
    total = sum(columns)
    last[c] += total
    columns.append(total)
    print(' '.join(map(str, columns)))
print(' '.join(map(str,last)))


Measured memory_bytes: 5620
#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=(n);i++)
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
//#include <string.h>
using namespace std;
//using Graph = vector<vector<int>>;
//queue<long>que;

int gcd(int x, int y){
    if(x%y == 0)
        return y;
    else
        return (gcd(y,x%y));
}

int main(){
    int k;
    cin >>k;
    long ans=0;
    
    rep(p,k){
        rep(q,k){
            rep(r,k){
                int a = max(r,q);
                int b = min(r,q);
                int c = gcd(a,b);
                int d = max(c,p);
                int e = min(c,p);
                ans += gcd(d,e);
            }
        }
    }
    
    cout << ans <<endl;
}


Measured memory_bytes: 3580
N = int(input())
a = [ int(input()) for i in range(N)]

ans = 0
for i in range(N):
        ans += a[i]//2
        a[i] %= 2
        if i != N - 1 and  a[i] > 0 and a[i+1] > 0:
            ans += 1
            a[i+1] -= 1
print(ans)


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

#define N 1000
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define fastio ios::sync_with_stdio(false); cin.tie(0)

int main(){
    fastio;
    ll n, i = 1, sum = 0, a, b;
    cin >> n;
    while(i*i <= n){
    	a = i;
    	b = n/i;
    	a--;
    	b--;
    	if(a == b){
    		if(a != 0)
				if(n/a == n%a)
		 			sum += a;
 			
    	}
    	else{
			if(a != 0)
				if(n/a == n%a)
		 			sum += a;
 			
 			if(b != 0)
				if(n/b == n%b)
	 				sum += b;
 			
    	}
    	i++;
    }
    cout << sum << endl;
    return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

int n;
const int max_n = 1e5;
vector<int> v1;
vector<int> v2;
int v1_num, v2_num;

tuple<int, int, int> solver(vector<int>& x){
  
  sort(x.begin(), x.end());

  int cnt = 1;
  int max_cnt = 0;
  int second_cnt = 0;
  int num = 0;
  int second_num = 0;
  int s = 0;
  // cout << "vector size = " << x.size() << endl;
  for(int i = 1; i < x.size(); i++){
    if(x[i] != x[i-1]){
      cnt = i-1 - s + 1;
      if(max_cnt <= cnt){
        second_cnt = max_cnt;
        max_cnt = cnt;
        second_num = num;
        num = x[i-1];
      }else if(max_cnt > cnt && second_cnt <= cnt){
        second_cnt = cnt;
        second_num = num;
      }
      s = i;
    }
    if(i == x.size() - 1){
      cnt = i - s + 1;
      if(max_cnt <= cnt){
        second_cnt = max_cnt;
        max_cnt = cnt;
        second_num = num;
        num = x[i];
      }else if(max_cnt > cnt && second_cnt <= cnt){
        second_cnt = cnt;
        second_num = num;
      }
    }
  }

  int ans = x.size() - max_cnt;
  int second_ans = x.size() - second_cnt;
  

  return make_tuple(num, ans, second_ans);
}

int main(){

  cin >> n;

  for(int i = 0; i < n; i++){
    int v;
    cin >> v;
    if(i%2 == 0) v1.push_back(v);
    else v2.push_back(v);
  }

  tuple<int, int, int> ans1 = solver(v1);
  tuple<int, int, int> ans2 = solver(v2);
  // cout << get<0>(ans1) << ", " << get<1>(ans1) << ", " << get<2>(ans1) << endl;
  // cout << get<0>(ans2) << ", " << get<1>(ans2) << ", " << get<2>(ans2) << endl;

  if(get<0>(solver(v1)) != get<0>(solver(v2))){
    cout << get<1>(solver(v1)) + get<1>(solver(v2)) << endl;
  }else{
    // cout << "dif" << endl;
    cout << min(get<1>(solver(v1)) + get<2>(solver(v2)), get<2>(solver(v1)) + get<1>(solver(v2))) << endl;
  }


  return 0;
}

Measured memory_bytes: 3780
#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 pair<char, char> P;

int main() {
  int N; cin >>N;
  REP(n, N){
    string str; cin >>str;
    if(str.length() == 1){
      cout <<str <<endl;
      continue;
    }
    map<char, P> m;
    set<char> s;
    for(int i = 0; i + 3 < (int)(str.length()); i += 3){
      char c = str[i], next = str[i + 3];
      if(s.find(c) == s.end()) m[c] = P('A', 'A');
      if(s.find(next) == s.end()) m[next] = P('A', 'A');
      s.insert(c);
      s.insert(next);
      if(str[i + 2] == '>'){
        m[c].second = next;
        m[next].first = c;
      } else{
        m[c].first = next;
        m[next].second = c;
      }
    }
    char now = 'A';
    for(map<char, P>::iterator it = m.begin(); it != m.end(); ++it) if(it->second.first == 'A') now = it->first;
    while(now != 'A'){
      cout <<now;
      now = m[now].second;
    }
    cout <<endl;
  }
  return 0;
}

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

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int sum = 0;
	if (n > k) {
		for (int i = 0; i < k; i++) {
			sum += x;
		}
		rep(i, n - k)sum += y;
		cout << sum << endl;
	}
	else {
		rep(i, n)sum += x;
		cout << sum << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long long a[500], n;
int main() {
	cin >> n; for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n); long long cnt = 1;
	for (int i = n - 1; i >= 0; i--) {
		int L = (n - 1 - i) / 4 + 1;
		if (a[i] >= L) { cnt += a[i] - L + 1; }
	}
	cout << cnt << endl;
	return 0;
}

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

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vi;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl cout<<'\n'
#define pb push_back
#define all(s) s.begin(),s.end()
#define bs binary_search

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a)*(b)/(__gcd((a),(b)))

const int Mod=1e9+7;
#define sum(a,b) (((a)%Mod)+((b)%Mod))%Mod
#define sub(a,b) (((a)%Mod)-((b)%Mod))%Mod
#define mul(a,b) (((a)%Mod)*((b)%Mod))%Mod
#define digit(x) floor((log10(x))+1)


#define count1(x) __builtin_popcount(x)

#define dbg(x) cout << #x <<":"<<x<<endl;

bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
} 

ll pow(ll x, ll y, ll mod)
{
	int ans=1;
	while(y)
	{
		if(y&1)
			ans=(ans*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}
	return ans;
}

int main()
{
	fast;
	ll k,ans,i,j,m,temp,temp2;
	cin >> k;
	ans=0;
	for(i=1;i<=k;i++)
	{
		for(j=1;j<=k;j++)
		{
			for(m=1;m<=k;m++)
			{
				temp=gcd(i,j);
				temp2=gcd(temp,m);
				ans+=temp2;
				//dbg(ans);
				//dbg(temp);
				//dbg(temp2);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3652
N = int(input())
A = list(map(int,input().split()))
ans = 0
for a in A:
    ans ^= a
M = 2**60-1
b = M^ans
for i in range(N):
    A[i] &= b
A.sort(reverse=True)
for i in range(min(60,N)):
    a = A[i]
    if a == 0:
        break
    l = len(bin(a))-3
    for j in range(N):
        if j==i:
            continue
        if A[j]//2**l%2==1:
            A[j] ^= a
        else:
            if i < j:
                break
    A.sort(reverse=True)
s = 0
for a in A:
    s ^= a
ans += 2*s
print(ans)

Measured memory_bytes: 82080
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

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

int main(){
    int n, k;
    cin >> n >> k;
    int ans = k;
    rep(i, n-1){
        ans *= ( k - 1 );
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#include<regex>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl; }
const LL MOD = 1e9 + 7;
const LL LLINF = 1LL << 60;
const int INF = 1 << 30;

int main(void) {
	string S;
	cin >> S;

	regex re("(dream|dreamer|erase|eraser)+");

	if (regex_match(S,re)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;
string s;
int main() {
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == 'p') count++;

  cout << s.length()/2-count << endl;
  return 0;
}


Measured memory_bytes: 512
// https://beta.atcoder.jp/contests/abc092/tasks/arc093_a
// giveup

#include <iostream>
#include <cstdlib>
using namespace std;

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

    int N;
    long long sum = 0;
    int A[100002] = {};

    cin >> N;
    for(int i=1; i<=N; ++i){
        cin >> A[i];
        sum += abs(A[i] - A[i-1]);
    }
    sum += abs(A[N+1] - A[N]);

    for(int j=1; j<=N; ++j){
        cout << sum - abs(A[j] - A[j-1]) - abs(A[j+1] - A[j]) + abs(A[j+1] - A[j-1]) << endl;
    }

    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine(); // 改行
        String[] strz = new String[N];
        for (int n = 0; n < N; n++){
            strz[n] = sc.nextLine();
        }

        for (int n = 0; n < N; n++){
            char[] charn = strz[n].toCharArray();
            Arrays.sort(charn);
            strz[n] = new String(charn);
        }

        Map<String, Integer> map = new HashMap<>();
        for (String s : strz) {
            Integer i = map.get(s);
            map.put(s, i == null ? 1 : i + 1);
        }
        long cnt = 0;
        for (String key : map.keySet()){
            long num = map.get(key);
            if (num > 1) {
                // cnt+=conbi(num,2);
                cnt+= (num*(num-1)/2);
            }
        }
        System.out.println(cnt);
    }

    public static long f (long n){
        if (n<=1){return 1;}
        return f(n-1)*n;
    }
    public static long conbi(long n,long r){
        if ((f(n-r) == 0) || (f(r) == 0)){return 1;}
        return (f(n)/(f(n-r)*f(r)));
    }
}


Measured memory_bytes: 99668
import java.util.Scanner;

public class Main
{
    // https://atcoder.jp/contests/abc081/tasks/abc081_b
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        int[] numbers = new int[size];
        for (int i = 0; i < size; i++) {
            numbers[i] = sc.nextInt();
        }
        System.out.println(calculate(numbers));
    }

    public static int calculate(int[] numbers)
    {
        int answer = 0;
        while(divide(numbers)) {
            answer++;
        }
        return answer;
    }

    private static boolean divide(int[] numbers)
    {
        for (int i = 0; i < numbers.length; i++) {
            if (numbers[i] % 2 != 0) {
                return false;
            }
            numbers[i] /= 2;
        }
        return true;
    }
}


Measured memory_bytes: 21716
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, X: "List[int]"):
    
    res = 0
    for x in X:
        res += min(x, K-x)

    print(res*2)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, x)

if __name__ == '__main__':
    main()


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

using namespace std;
#define int long long
#define N 666666
struct str{
	int val;
	int id;
	 bool operator < (const str &b)const
	 {
	 	return val<b.val;
	 } 
};
int a[N],b[N],arr[N];
priority_queue<str> q;
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		arr[i]=a[i];
	} 
	int f=1;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		if(b[i]<a[i]) f=0;
		q.push((str){b[i],i});
	} 
	if(!f){
	//	cout<<"==";
		cout<<"-1";
		return 0; 
	}
	f=1;
	int ans=0;
	while(!q.empty()){
		struct str t=q.top();
		q.pop();
		int id=t.id;
		if(id==1){
			if(t.val==a[id]){
				continue;
			}
			int temp=b[t.id+1]+b[n];
			if(t.val-temp<a[id]){
				f=0;
			}
			int add=(t.val-a[id])/temp;
			ans+=add;
			int cnt=(t.val-a[id])%temp;
			b[id]-=add*temp;
			int st=a[id]+cnt;
			if(cnt)
				q.push((str){st,t.id});
		}else if(id==n){
			if(t.val==a[id]){
				continue;
			}
			int temp=b[t.id-1]+b[1];
			if(t.val-temp<a[id]){
				f=0;
			}
			int add=(t.val-a[id])/temp;
			ans+=add;
			int cnt=(t.val-a[id])%temp;
			b[id]-=add*temp;
			int st=a[id]+cnt;
			if(cnt)
				q.push((str){st,t.id});
		}else{
			if(t.val==a[id]){
				continue;
			}
			int temp=b[t.id-1]+b[1+t.id];
			if(t.val-temp<a[id]){
				f=0;
			}
			int add=(t.val-a[id])/temp;
			ans+=add;
			int cnt=(t.val-a[id])%temp;
			int st=a[id]+cnt;
			b[id]-=add*temp;
			if(cnt)
				q.push((str){st,t.id});
		}
		if(!f){
		//	cout<<ans<<" "<<t.id<<'\n';
			break;
		}
	}
	if(!f) cout<<"-1";else cout<<ans;
	return 0;
}

/*
3
1 2 3
1 2 6
1 9 6
16 9 6
31 9 6
*/

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

//------------------------------------------------------

const int MAX_N = 202;
int N, M, R;
int r[9];
ll dist[MAX_N][MAX_N];
ll dist_min = LINF;

int main() {

    cin >> N >> M >> R;


    rep(i, R) cin >> r[i];
    sort(r, r+R);

    rep(i, MAX_N) {

        rep(j, MAX_N) {
            if (i == j) dist[i][j] = 0;
            else dist[i][j] = LINF;
        }
    }

    rep(i, M) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        dist[a - 1][b - 1] = c;
        dist[b - 1][a - 1] = c;
    }

    rep(k, N) {

        rep(i, N) {

            rep(j, N) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    vector<int> v;
    rep(i, R) v.push_back(r[i] - 1);

    do {
        ll sum = 0;

        rep(i, v.size() - 1) {
            sum += dist[v[i]][v[i + 1]];
        }

        dist_min = min(dist_min, sum);

    } while (next_permutation(v.begin(), v.end()));

    cout << dist_min << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		int n = s.length();
		String ans[] = { "YES", "NO" };
		int a = 0;
		String tmp = "";
		String t[] = { "dream", "dreamer", "erase", "eraser" };
		for (int i = n - 1; i >= 0; --i) {
			if (s.charAt(i) == 'r') {
				if (i < 5) {
					a = 1;
					break;
				} else {
					tmp = s.substring(i - 5, i + 1);
					if (!tmp.equals(t[3])) {
						if (i >= 6) {
							tmp = s.substring(i - 6, i + 1);
							if (!tmp.equals(t[1])) {
								a = 1;
								break;
							} else {
								i = i - 6;
								continue;
							}
						}
						a = 1;
						break;
					} else {
						i = i - 5;
						continue;
					}
				}
			}
			if (s.charAt(i) == 'e') {
				if (i < 4) {
					a = 1;
					break;
				}
				tmp = s.substring(i - 4, i + 1);
				if (tmp.equals(t[2])) {
					i = i - 4;
					continue;
				}
				else {
					a = 1;
					break;
				}
			}
			if (s.charAt(i) == 'm') {
				if (i < 4) {
					a = 1;
					break;
				}
				tmp = s.substring(i - 4, i + 1);
				if (tmp.equals(t[0])) {
					i = i - 4;
					continue;
				}
				else {
					a = 1;
					break;
				}
			}
		}
		System.out.println(ans[a]);

	}

}


Measured memory_bytes: 27248
package main

import (
	"fmt"
)

func main() {
	for {
		var a, b int
		var op string
		fmt.Scan(&a)
		fmt.Scan(&op)
		fmt.Scan(&b)

		if op == "?" { break }

		if op == "+" {
			fmt.Printf("%d\n", a + b)
		} else if op == "-" {
			fmt.Printf("%d\n", a - b)
		} else if op == "*" {
			fmt.Printf("%d\n", a * b)
		} else if op == "/" {
			fmt.Printf("%d\n", a / b)
		}
	}
}

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

int main() {
  int c1, c5, c10, c50, c100, c500; cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
  if (c1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500 >= 1000) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define ll long long
#define maxn (1000+10)
#define mod 10000003
#define lnode node*2,start,mid
#define rnode node*2+1,mid+1,end
using namespace std;
int main()
{   ios::sync_with_stdio(false);
	#define int ll
	int n,k,q,x,s[100001];
	cin>>n>>k>>q;
	memset(s,0,sizeof(s));
	for(int i=1;i<=q;i++)
	{  cin>>x;
	   s[x]+=1;
	}
	if(q<k)
	  for(int i=1;i<=n;i++)
	    cout<<"Yes"<<endl;
	else
	  for(int i=1;i<=n;i++)
	    if(q-s[i]<k)
	      cout<<"Yes"<<endl;
	    else
	      cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		char[] NcharList = N.toCharArray();
		int total = 0;
		for (char Nchar : NcharList) {
			total += Character.getNumericValue(Nchar);
		}
		System.out.println(Integer.parseInt(N)%total == 0 ? "Yes": "No");


	}
}


Measured memory_bytes: 21972
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long X, x = 100;

  std::cin >> X;

  for (int i = 0; ; i ++, x *= 1.01) {
    if (x >= X) {
      std::cout << i << std::endl;

      break;
    }
  }

  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int H,W,h,w;

void solve(){
  cin >> H >> W >> h >> w;
  int s=H/h,t=W/w;
  if(H%h==0 && W%w==0){
    cout << "No" << endl;
    return;
  }
  int m=s*t/((W%w)*H+(H%h)*W);m+=5;
  cout << "Yes" << endl;
  rep(i,H){
    rep(j,W){
      if(j%w==w-1 && i%h==h-1) cout << -m*(h*w-1)-1 << " ";
      else cout << m << " ";
    }
    cout << "" << endl;
  }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,i,x,y;
  string s;
  s="";
  cin>>n;
  while(n>0)
  {
     x=(n-1)/26;
     y=n-(26*x+1);
     s+=('a'+y);
     n=x;
  }  
  reverse(s.begin(),s.end());
  cout<<s<<endl;

}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int a[110];

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

  cin >> n;

  int ama = -100;
  int ami = 100;

  REP(i, n) {
    cin >> a[i];
    ama = max(ama, a[i]);
    ami = min(ami, a[i]);
  }

  int ans = INF;
  FOR(i, ami, ama + 1) {
    int sum = 0;
    REP(j, n) {
      sum += ((a[j] - i) * (a[j] - i));
    }
    ans = min(sum, ans);
    sum = 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

var reader = bufio.NewScanner(os.Stdin)

func main() {
	reader.Split(bufio.ScanWords)
	reader.Scan()
	n, _ := strconv.Atoi(reader.Text())
	houses := make([]int, n)
	for i := 0; i < n; i++ {
		reader.Scan()
		a, _ := strconv.Atoi(reader.Text())
		houses[i] = a
	}
	sort.Ints(houses)
	ans := 0
	for i := 1; i < n; i++ {
		ans += houses[i] - houses[i-1]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){return "";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var s = nextCharArray();
  var K = nextInt();
  if(K > s.length){
    K = s.length;
  }
  var output = "1";
  for(var i = 0; i < K; i++){
    if(s[i] != "1"){
      output = s[i];
      break;
    }
  }
  myout(output);
}

Measured memory_bytes: 7372
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A)
    A = A[::-1]

    ans = 0
    for i in range(N-1):
        ans += A[(i+1)//2]
#        print(i//2)                                                                                   
    print(ans)


if __name__ == "__main__":
    main()






Measured memory_bytes: 105308
#!/usr/bin/env pypy3


def get_line():
    return input()


def get_tokens():
    return get_line().split()


def get_ints():
    return [int(_) for _ in get_tokens()]


def main():
    n, = get_ints()
    w = []
    for i in range(n):
        v = get_line()
        w.append(v)

    s = set()
    ok = True
    s.add(w[0])
    last_v = w[0]
    for i in range(1, n):
        v = w[i]
        if v[0] != last_v[-1]:
            ok = False
        if v in s:
            ok = False
        s.add(v)
        last_v = v

    print('Yes' if ok else 'No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll i,o,t,j,l,s,z;
	cin >> i >> o >> t >> j >> l >> s >> z;

	ll ans = 0;
	if(i>0 && j>0 && l>0){
		ans = max(((i-1)/2 + (j-1)/2 + (l-1)/2) * 2 + 3
			      ,(i/2 + j/2 + l/2)*2) + o;
	}else{
		ans = (i/2 + j/2 + l/2) * 2 + o;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <iostream>
using namespace std;
typedef long long LL;
const int Maxn = 1e5 + 6;
const int inf = 1000000000;
const LL Inf = 1LL<<60;
int main ()
{
	int n;
	char s[109][109];
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%s",s[i]);
	int len = strlen(s[1]);
	char c = s[1][len-1];
	for (int i = 2; i <= n; i++){
		int len1 = strlen(s[i]);
		if (s[i][0] != c) {
			printf("No\n");
			return 0;
		}
		c = s[i][len1-1];
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			if (i == j) continue;
			if (strcmp(s[i],s[j])==0){
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int k;
    cin>>k;
    cout<<binary_search(a.begin(),a.end(),k)<<endl;
  }
  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod=1000000007;


int main() {
    vector<queue<char>> v(3);
    rep(i,3) {
        string s;
        cin >> s;
        rep(j,s.size()) {
            v[i].push(s[j]);
        }
    }
    int c = 0;
    while(true) {
        if(v[c].empty()) break;
        char ch = v[c].front();
        v[c].pop();
        if(ch == 'a') c = 0;
        else if(ch == 'b') c = 1;
        else c = 2;
    }
    if(c == 0) cout << "A" << endl;
    else if(c == 1) cout << "B" << endl;
    else cout << "C" << endl;
}

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

//#define double long double

const int MAXN = 2E5 + 10;
const double PI = atan((double)1.0) * 4;

int n, lis[MAXN];

vector<pair<int, int> > fount;

int main() {
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(0);
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2 >> n;
	if (x1 > x2) swap(x1, x2), swap(y1, y2);
	bool flip = false;
	if (y1 > y2) {
		flip = true;
		y1 = 1E9 - y1, y2 = 1E9 - y2;
	}
	for (int i = 1; i <= n; i++) {
		int x, y; cin >> x >> y;
		if (flip) y = 1E9 - y;
		if (x1 <= x && x <= x2 && y1 <= y && y <= y2) fount.push_back({ x, y });
	}
	sort(fount.begin(), fount.end());
	int ans = 0;
	for (int i = 0; i < (int)fount.size(); i++) {
		int p = lower_bound(lis, lis + ans, fount[i].second) - lis;
		if (p == ans) lis[ans++] = fount[i].second;
		else lis[p] = fount[i].second;
	}
	double gridAns = 100.0 * (x2 - x1 + y2 - y1);
	if (ans == min(x2 - x1, y2 - y1) + 1) {
		gridAns -= 20 - 10 * PI;
		ans--;
	}
	cout << fixed << setprecision(15) << gridAns - ans * (20 - 5 * PI) << '\n';
}


Measured memory_bytes: 2800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
vector<int> vec(200020);
  int A, B;
  cin >> A;
  for(int i=0;i<A-1;i++){
      cin >> B;
      vec.at(B)+=1;
  }
  for(int j=1;j<A+1;j++){
   cout << vec.at(j) << endl;   
  }
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int gcd(int x, int y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}
vector<int> div(int n)
{
    vector<int> res;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            res.push_back(i);
            if (i != n / i)
                res.push_back(n / i);
        }
    }
    sort(all(res));
    return res;
}

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

    int a, b;
    cin >> a >> b;
    int c = gcd(a, b);
    vector<int> d = div(c);
    vector<bool> f(d.size(), true);
    int ans = 1;
    Rep(i, 1, d.size())
    {
        if (!f[i])
            continue;
        ans++;
        Rep(j, i + 1, d.size())
        {
            if (d[j] % d[i] == 0)
                f[j] = false;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
using System;
class Program
{
    static void Main()
    {
        var N=long.Parse(Console.ReadLine());
        long S=0;
        for(long i=0;i<=N;i++)
            S+=i;
        for(int i=1;i<=N/3;i++)
            S-=i*3;
        for(int i=1;i<=N/5;i++)
            S-=i*5;
        for(int i=0;i<=N/15;i++)
            S+=i*15;
        Console.WriteLine(S);
    }
}

Measured memory_bytes: 27516
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
 
#define REP(i,b,n) for(int i=b;i<n;++i)
#define REPR(i,b,n) for(int i=n-1;i>=b;--i)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PI acos(-1.0)

#define INF 1<<14

using namespace std;

static const double EPS = 1e-9;
typedef pair<int, int> pii;
typedef long long ll;

int N, a, b, t;
int amat[22][22]={{0}};
int dist[22][22]={{0}};
int brg_count[22]={0, INF, 0};
int far_land = 0;

void warshall_floyd(){
	
	for(int i=1; i<=N; ++i)
		for(int j=1; j<=N; ++j)
			dist[i][j] = (amat[i][j]>0?amat[i][j]:INF);
	
	for(int k=1; k<=N; ++k)
		for(int i=1; i<=N; ++i)
			for(int j=1; j<=N; ++j)
				dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
	
	return;
}

int solve(){
	
	warshall_floyd();
	
	int sum = 0;
	
	for(int i=1; i<=N; ++i){
		for(int j=i; j<=N; ++j){
			
			if( amat[i][j] && brg_count[i]>1 && brg_count[j]>1 )
				sum += 2*amat[i][j];
		}
	}
	
	int res = sum;
	
	for(int k=2; k<=N; ++k){
		
		if( brg_count[k] > 1 )
			res = min(res, sum - dist[1][k]);
	}
	
	if(res == sum)
		res = 0;
	
	return res;
}	

int main(){
		
	while(cin >> N, N){
		
		CLR(amat);
		CLR(dist);
		CLR(brg_count);
		brg_count[1] = INF;
		far_land = 0;
		
		for(int i=0; i < N-1; ++i){
			cin >> a >> b >> t;
			amat[a][b] = amat[b][a] = t;
			brg_count[a]++; brg_count[b]++;
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}

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

int main() {
  int n, p;
  while (cin >> n >> p && n) {
    int have[50], cup = p, turn = 0;

    fill(have, have + n, 0);
    while (true) {
      
      if (cup == 1 && have[turn] == p - 1) {
	cout << turn << endl;
	break;
      }

      if (cup == 0)
	swap(cup, have[turn]);

      else
	have[turn]++, cup--;

      turn = (turn + 1) % n;
    }
  }
}

Measured memory_bytes: 3016
#import math
N,K = (int(i) for i in input().split())

count = 0
minus = []
for i in range(1,N+1):
    
    a = i
    b = i
    c = i
    if (a + b) % K == 0:
        count += 1
        count += len(minus) * (3*2)
        if len(minus) >= 2:
            #kumiawase = math.factorial(len(minus))/(math.factorial(len(minus)-2)*math.factorial(2))
            kazu = len(minus)
            kumiawase = kazu * (kazu - 1) / 2
            count += kumiawase * (3*2)
    if i % K == 0:
        minus.append(i)

print(int(count))

Measured memory_bytes: 10968
#include<iostream>
#include<vector>
#include<cmath>
#define ll long long

using namespace std;

int main()
{
	int n,d;
	cin>>n>>d;
	int ans = 0;
	while(n--)
	{
		ll a,b;
		cin>>a>>b;
		if(sqrt(a*a + b*b) <= d) ans++;
	}
	cout<<ans;
	return 0;
}

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

int main() {

	string a,b;
	cin>>a>>b;
	string h = b.substr(0,b.length() - 1);
	//cout<<h;
	//cout<<a.compare(h);
	if(a.compare(h) == 0) {
		cout<<"Yes";
	}
	else { 
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3628
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while 1:
  c=m[y][x]
  if'>'==c:x+=1;
  if'v'==c:y+=1;
  if'<'==c:x-=1;
  if'^'==c:y-=1;
  if'.'==c:print(x,y);break
  if(x,y)in s:print('LOOP');break
  else:s|={(x,y)}


Measured memory_bytes: 5624
#include <stdio.h>
int main(void){
  int n,c[500],s[500],f[500],i,j,t;
  scanf("%d",&n);
  for (i=0;i<n-1;i++) scanf("%d%d%d",&c[i],&s[i],&f[i]);
  for (i=0;i<n-1;i++){
    t=0;
    for (j=i;j<n-1;j++){
      if (t<=s[j]) t=s[j]+c[j];
      else t+=((t%f[j])? f[j]:0)-t%f[j]+c[j];
    }
    printf("%d\n",t);
  }
  printf("0\n");
  return 0;
}

Measured memory_bytes: 128
N = int(input())
x = ""
S = []
for i in range(N):
    x = input()
    S.append(x)
ans = [0]*4
for i in range(N):
    if S[i] == "AC":
        ans[0] += 1
    elif S[i] == "WA":
        ans[1] += 1
    elif S[i] == "TLE":
        ans[2] += 1
    elif S[i] == "RE":
        ans[3] += 1
print('AC x ',end='')
print(ans[0])
print('WA x ',end='')
print(ans[1])
print('TLE x ',end='')
print(ans[2])
print('RE x ',end='')
print(ans[3])


Measured memory_bytes: 16240
from collections import deque
S = deque(input())
n = int(input())
Q = [list(map(str, input().split())) for _ in range(n)]

flg = True
for q in Q:
    if q[0] == "1":
        flg = not flg
    else:
        F = int(q[1])
        if not flg:
            F = 3 - F
        if F == 1:
            S.appendleft(q[2])
        if F == 2:
            S.append(q[2])

if not flg:
    S.reverse()
print("".join(S))

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

const ll mod = 1e9+7;
int n;

const int N = 2e4+10;
ll dp[N];

ll rec(int i) {
    if(i == 0)
        return 1;
    ll&  cur = dp[i];
    if(cur != -1)
        return cur;
    ll ans = 0;
    for(int j=3;j<=2000;++j)
        if(j <= i)
            ans += (rec(i - j))%mod , ans%=mod;
    return cur = ans;
}


void solve(){
    cin >> n;
    memset(dp,-1,sizeof(dp));
    cout << rec(n) << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t =1;
    while(t--)
        solve();
    return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	string S;
	cin >> S;
	
	int t = 0 , s = 0;
	rep(i,S.size()){
		if(S[i] == 'S'){
			s ++;
		}
		else {
			if(s > 0)s --;
			else t ++;
		}
		//cout << s << " " << t << endl;
	}
	cout << s+t << endl;
}



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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> a(n+1, vector<int>(3));
    for(int i = 1; i <= n; i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }

    vector<vector<int>> memo(n+1, vector<int>(3, 0));
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                if(memo[i][j] < memo[i-1][k] + a[i][k]){
                    memo[i][j] = memo[i-1][k] + a[i][k];
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < 3; i++){
        if(ans < memo[n][i]) ans = memo[n][i];
    }

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

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    vector<vector<int>> a(3, vector<int>(3));
    rep(i, 0, 3) rep(k, 0, 3) cin >> a[i][k];
    int n; cin >> n;
    vector<int> b(n);
    rep(i, 0, n) cin >> b[i];

    for (auto &&sub : b)
    {
        rep(i, 0, 3) rep(k, 0, 3) a[i][k] = (a[i][k] == sub) ? -1 : a[i][k];
    }
    
    string ans = "No";
    rep(i, 0, 3) ans = (a[i][0] == a[i][1] && a[i][1] == a[i][2]) ? "Yes" : ans;
    rep(i, 0, 3) ans = (a[0][i] == a[1][i] && a[1][i] == a[2][i]) ? "Yes" : ans;
    ans = (a[0][0] == a[1][1] && a[1][1] == a[2][2]) ? "Yes" : ans;
    ans = (a[0][2] == a[1][1] && a[1][1] == a[2][0]) ? "Yes" : ans;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mx 100000
#define pb push_back
#define siz(v) v.size();
typedef unsigned long  ull;
typedef long long  ll;
using namespace std;

int main()
{
 	ios_base::sync_with_stdio(0);
 	cin.tie(0); cin.tie(0);
	
	int n,q;
	map<int,int>mp;
	cin>>n>>q;
	while(q--)
	{
		int d,a;
		cin>>d;
		
		while(d--){
			cin>>a;
			mp[a]=1;
		}
	}
	cout<<(n-mp.size())<<"\n";
	
 return 0;
 }


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template
<
    typename TYPE,
    size_t SIZE
>
size_t array_length(const TYPE (&)[SIZE])
{
    return SIZE;
}
const ll mod = 1e9+7;

vector<vector<int>> tree(100002);
int dv[100002];
int du[100002];
int n,V,U;
void depthv(int v){
    if (v == V) dv[v] = 0;
    for(int i:tree[v]){
        if (dv[i] == -1){
            dv[i] = dv[v]+1;
            depthv(i);
        }
    }
}
void depthu(int v){
    if (v == U) du[v] = 0;
    for(int i:tree[v]){
        if (du[i] == -1){
            du[i] = du[v]+1;
            depthu(i);
        }
    }
}
int main(){
    //u:nigeru v:ou
    int a,b;
    cin >> n >> U >> V;
    U--;
    V--;
    rep(i,n-1){
        cin >> a >> b;
        tree[a-1].push_back(b-1);
        tree[b-1].push_back(a-1);
    }
    rep(i,n){
        dv[i] = -1;
        du[i] = -1;
    }
    depthv(V);
    depthu(U);
    int escape = dv[U];
    rep(i,n){
        if (dv[i] > du[i]) chmax(escape,dv[i]);
    }
    PRINT(escape-1);
}


Measured memory_bytes: 9088
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s,t;
  int i,cnt=0;
  cin >> s;
  cin >> t;
  for(i=0; i<s.size(); i++){
    if(s.at(i)==t.at(i)){
      cnt++;
    }
  }
  if(cnt==s.size()){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3624