akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll ans = 0;
    if (S[0] == S[1] && S[1] == S[2] && S[0] == 'R')
        ans = 3;
    else if (S[1] == 'R' && (S[0] == S[1] || S[1] == S[2])) {
        ans = 2;
    }
    else {
        REP(i, 3) {
            if (S[i] == 'R')
                ans = 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
n, k = map(int, input().split())
a = list(map(int, input().split()))
t, s = 0, 0

for i in range(n-1):
  for j in range(i+1, n):
    if a[i] > a[j]:
      t += 1
      
a.sort()
l = [ i for i in range(n) ]
for i in range(1, n):
  if a[i] == a[i-1]:
    l[i] = l[i-1]
s = sum(l)
    
print((k*t%1000000007 + s*k*(k-1)//2%1000000007)%1000000007)


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

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

  vector<ll> X(200001, 0);
  vector<ll> Y(200001, 0);
  rep(i, n) X[a[i]]++;
  ll res=0;
  rep(i, 200001) {
    if (X[i]>1) Y[i]=(X[i]-1)*X[i]/2;
    res+=Y[i];
  }
  rep(i, n) {
    ll tmp=res-Y[a[i]];
    if (X[a[i]]>2) tmp+=(X[a[i]]-1)*(X[a[i]]-2)/2;
    cout<<tmp<<endl;
  }
}


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

int main(void) {
  int R;
  string ans;
  cin >> R;
  if (R < 1200)
    ans = "ABC";
  else if (R < 2800)
    ans = "ARC";
  else
    ans = "AGC";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  bool isgood=false;
  if(s[0]==s[1]&&s[0]==s[2]) isgood=true;
  if(s[1]==s[2]&&s[1]==s[3]) isgood=true;
  if(isgood) print("Yes");else print("No");
  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()



int main() {
    int N,M;
    cin >> N >> M;
    int left,right;
    left=1;
    right = N;

    for(int i=0;i<M;i++){
        int tmpleft,tmpright;
        cin >> tmpleft >> tmpright;
        left = max(tmpleft,left);
        right = min(tmpright,right);
    }

    cout <<  max(0,right-left+1) << endl;

}



Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-08-03
**/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a), greater<int>());
    
    long long area = 0;
    int side = -1;
    for (int i = 0; i < n-1; i++) {
        if (a[i] == a[i+1] && side == -1) {
            side = a[i];
            i++;
        }
        else if (a[i] == a[i+1]) {
            area = (long long) side * a[i];
            break;
        }
    }
    cout << area << '\n';
    return 0;
}

Measured memory_bytes: 3664
N, M = map(int, input().split())
pref_dict = {}

for i in range(M):
    P, Y = map(int, input().split())
    pref_dict[i] = [P, Y]

sorted_dict = sorted(pref_dict.items(), key= lambda x: (x[1][0], x[1],[1]))
ans_dict = {}
buf = ""
count = 1

for tup in sorted_dict:

    row = tup[0]
    pref_name = "00000{}".format(tup[1][0])
    pref_name = pref_name[-6:]

    if pref_name == buf:
        count += 1
    else:
        count = 1

    pref_id = "00000{}".format(count)
    pref_id = pref_id[-6:]
    ans_dict[row] = [pref_name, pref_id]
    buf = pref_name

for key, value in sorted(ans_dict.items(), key=lambda x: x[0]):
    print(*value, sep="")

Measured memory_bytes: 74096
import Foundation

var input_num = [String]()
var count:Int = 0

for i in 0..<2 {
  input_num.append(readLine()!)
}

let nk = input_num[0].componentsSeparatedByString(" ")
let n = Int(nk[0])!
let k = Int(nk[1])!

let h = input_num[1].componentsSeparatedByString(" ")
for i in 0..<h.count {
  if Int(h[i]) >= k {
    count += 1
  }
}

print(count)

Measured memory_bytes: 7908
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;pair<long,int>P[1<<17];long c[1<<17],n,a,i,w=1e9;main(){for(cin>>n;i<n;P[i].s=i++)cin>>P[i].f;sort(P,P+n,[](pair<long,int>p,pair<long,int>q){return p.f-q.f?p.f>q.f:p.s<q.s;});for(i=0;i<n;i++)c[w=w>P[i].s?P[i].s:w]+=-~i*(P[i].first-P[i+1].first);for(i=0;i<n;i++)cout<<c[i]<<endl;}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef unsigned long long ULL;
#define int LL
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

const int MAX = 400*1000+5;
const int INF = 1000*1000*1000 + 7;
const LL LINF = 1LL*INF*INF;
const int MOD = INF;
const double PI = acos(-1.);
const int MAXN = 3*100007;

mt19937 rnd(time(0));

int res[301][301];
int g[301][301];
int p[301];

int getP(int v)
{
    if (p[v] == v)
        return v;
    else
        return p[v] = getP(p[v]);
}

int unite(int u, int v)
{
    u = getP(u);
    v = getP(v);
    if (rand()%2)
        p[u] = v;
    else
        p[v] = u;
}

main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    set<pair<int, PII>> a;
    for (int i=0;i<n;i++)
    {
        p[i] = i;
        for (int j=0;j<n;j++)
        {
            g[i][j] = INF;
            cin>>res[i][j];
            if (i<j)
                a.insert({res[i][j], {i, j}});
        }
    }
    LL sum = 0;
    for (auto p:a)
    {

        int len = p.F;
        int x = p.S.F;
        int y = p.S.S;
        if (getP(x) != getP(y) || g[x][y] > len)
        {
            sum += len;
            g[x][y] = len;
            g[y][x] = len;
            unite(x,y);
            for (int i=0;i<n;i++)
            {
                for (int j=0;j<n;j++)
                {
                    g[i][j] = min(g[i][j], g[i][x]+g[x][j]);
                }
            }
            for (int i=0;i<n;i++)
            {
                for (int j=0;j<n;j++)
                {
                    g[i][j] = min(g[i][j], g[i][y]+g[y][j]);
                }
            }
        }
    }

    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
        {
            if (i!=j && res[i][j] != g[i][j])
            {
                cout<<-1;
                return 0;
            }
        }
    }
    cout<<sum ;


    return 0;
}


Measured memory_bytes: 4480
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        int a[] = new int[N];
        int b[] = new int[N];
        Tree trees[] = new Tree[N];
        int maxSides = 0;
        for (int i = 0; i < N; i++) {
            trees[i] = new Tree();
        }

        for (int i = 0; i < N-1; i++) {
            a[i] = scan.nextInt() - 1;
            b[i] = scan.nextInt() - 1;
            trees[a[i]].addChild(b[i], i);
            trees[b[i]].addChild(a[i], i);

            if (maxSides < trees[a[i]].getChildrenNum())
                maxSides = trees[a[i]].getChildrenNum();
            if (maxSides < trees[b[i]].getChildrenNum())
                maxSides = trees[b[i]].getChildrenNum();
        }

        //K
        os.println(maxSides);

        int ans[] = new int[N-1];
        dfs(0, -1, -1, trees, ans);

        for(int i = 0; i < N-1; i++) {
            os.println(ans[i]);
        }
    }


    static void dfs(int to, int root, int rootColor, Tree[] trees, int[] ans) {
        int color = 1;
        for (Entry<Integer, Integer> entry: trees[to].getChildren().entrySet()) {
            Integer child = entry.getKey();
            if (child == root)
                continue;
            if(color == rootColor)
                color++;
            ans[entry.getValue()] = color;
            dfs(child, to, color++, trees, ans);
        }

    }


    static class Tree {
        HashMap<Integer, Integer> children = new HashMap<>();//tree番号、color番号

        Tree() {
        }

        void addChild(int num, int i) {
            children.put(num, i);
        }

        public int getChildrenNum() {
            return children.keySet().size();
        }

        HashMap<Integer, Integer> getChildren() {
            return children;
        }
    }
}

Measured memory_bytes: 119060
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int> > vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define all(a) a.begin(), a.end()
#define pb push_back
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forab(i, a, b) for(int i=(int)a; i<(int)b; ++i)

const int inf = (int)1e6+5;
const int nax = (int)3e5+5;

void compute(){
    int n; cin >> n;
    vi v(n);
    int mx = 0, res = 0;
    forn(i, n){
        int x;
        cin >> x;
        if(x >= mx){
            ++res;
        }
        mx = max(x, mx);
    }
    cout << res << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    //    int t;
    //    cin>>t;
    //    while(t--)
    compute();
    return 0;
}


Measured memory_bytes: 256
n = int(input())
d,x = map(int,input().split())
A =[]
ans = x

for i in range(n):
  a = int(input())
  A.append(a)
  
for i in range(n):
  if d%A[i] != 0:
    ans += d//A[i] + 1
  elif d%A[i] == 0:
    ans += d//A[i]
  
print(ans)

Measured memory_bytes: 3064
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>


using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int>a(n), seq;
	for (int i = 0; i < n; i++)cin >> a[i];
	
	int t = 1;
	for (int i = 0; i < n-1; i++)
	{
		if (a[i] == a[i + 1]) {
			t++;
			if (i == n - 2) {
				seq.push_back(t);
			}
		}
		else {
			seq.push_back(t);
			t = 1;
		}

	}

	int res = 0;
	for (int i : seq) {
		res += i/2;
	}

	cout << res << endl;


    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
#define eb emplace_back
using namespace std;

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

int main(int argc, char const *argv[]) {
    /* code */
    ll n;
    cin >> n;
    ll t[n], x, y, curX = 0, curY = 0, curT = 0;
    //vector<P> destL;
    REP(i, n){
        cin >> t[i] >> x >> y;
        //destL.pb(x, y);
        ll d = abs(x - curX) + abs(y - curY);
        if((t[i] - curT) < d) {
            cout << "No" << endl;
            return 0;
        }else if((t[i] - curT - d) % 2 == 0){
            curX = x;
            curY = y;
            curT = t[i];
            continue;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    int[] B = Arrays.stream(A).sorted().toArray();
    int max = B[N-1];
    int nextMax = B[N-2];
    for (int i = 0; i < N; i++) {
      if (A[i] == max) {
        System.out.println(nextMax);
      } else {
        System.out.println(max);
      }
    }
  }
}

Measured memory_bytes: 92196
#include <stdio.h>
#include <algorithm>
#define MN 200000
int n,a[MN+5],ans;
bool vis[MN+5];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	std::sort(a+1,a+1+n);
	for(int k=(1<<30);k>=2;k>>=1){
		int l=1;
		for(;a[n]>=(k>>1);n--){
			if(vis[n]) continue;
			while(l<n&&(vis[l]||a[l]+a[n]<k)) l++;
			if(l>=n) continue;
			if(a[l]+a[n]==k){
				vis[l]=vis[n]=true;
				ans++;
			}
		}
	}
	printf("%d\n",ans);
}

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

int main(){
    int x;
    cin >> x;
    if(x==3||x==5||x==7) puts("YES");
    else puts("NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int res[100005] = {0};
int N,d = 0;
long long sum = 0;
int main()
{

     while(~scanf("%d",&N))
    {
     sum = 0;
     memset(res,0,sizeof(res));
     for(int i = 0; i < N; i++)
     {
        scanf("%d",&d);
        res[d] ++;
        sum+= d;
     }
     int Q;
     scanf("%d",&Q);
     int y=0,x=0;
     for(int i = 0; i < Q; i++){
        scanf("%d %d",&y,&x);
        sum += (x-y)*res[y];
        res[x] += res[y];
        res[y] = 0;
        cout<<sum<<endl;
     }
     }
    return 0;
}


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

int main()
{
    int N;
    string S;
    
    cin >> N;
    cin >> S;
    
    if((N%2 != 0) || (N == 1)){
        cout << "No" << endl;
        return 0;
    }
    else{
        for(int i=0; i<N/2; i++){
//            cout << S[i] << endl;
            if(S[i] != S[i+N/2]){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
    int w, i;
    int m[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}, u[10];
    
    while(scanf("%d", &w) != EOF){
        for(i = 0; i < 9; i++) u[i] = 0;
    
        for(i = 9; i >= 0; i--)
            if(w >= m[i]){
                w -= m[i];
                u[i] = 1;
            }
        
        for(i = 0, w = 0; i < 10; i++)
            if(u[i])
                if(!w) printf("%d", (w++, m[i]));
                else  printf(" %d", m[i]);
            
        printf("\n");
    }
 
    return 0;
}

Measured memory_bytes: 596
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int count = 0;
        for (int i = 0; i < n; i++) {
            char ai = a.charAt(i);
            char bi = b.charAt(i);
            char ci = c.charAt(i);
            if (ai == bi && bi == ci) {
                // do nothing
            } else if (ai != bi && bi != ci && ci != ai) {
                count += 2;
            } else {
                count += 1;
            }
        }
        so.println(count);
    }
}


Measured memory_bytes: 23764
N = int(input())

stgsn = []

def make753(nowstr,three,five,seven,isEnd):
    #print(nowstr,three,five,seven,isEnd,len(nowstr))
    if len(nowstr) > len(str(N)):
        #print("isEnd")
        isEnd = True
        return 0
    if three and five and seven and (int(nowstr) <= N):
        stgsn.append(nowstr)

    #末尾に追加
    if not isEnd:
        make753(nowstr+"3",True,five,seven,isEnd)
        make753(nowstr+"5",three,True,seven,isEnd)
        make753(nowstr+"7",three,five,True,isEnd)

make753("",False,False,False,False)

print(len(stgsn))


Measured memory_bytes: 4852
def main():
    N = int(input())
    input_list = [list(map(int, input().split())) for _ in range(N)]
    dish_list = [(sum(row), row[0], row[1], n) for n, row in enumerate(input_list)]
    dish_list.sort(reverse=True)
    ans = sum([((- 1)**(n % 2)) * dish[1 + n % 2] for n, dish in enumerate(dish_list)])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 46516
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int n, m, k;

int main(){
	cin >> n >> m >> k;
	
	int cnt = 0;
	for(int i = 0 ; i < n; i++){
		cnt = i * m;
		if(cnt == k){cout << "Yes" << endl; return 0;}
		for(int j = 0; j < m; j++){
			cnt += (n-i) - i;
			if(cnt == k){cout << "Yes" << endl; return 0;}
		}
	}
	cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
long long int fact(long long int num);
long long int fact(long long int num){
  if(num == 0 || num == 1){
    return 1;
  }else{
    return (num*fact(num-1));
  }
}
int main(){
  long long int x;
  scanf("%lld", &x);
  printf("%lld\n", fact(x));
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n);
    vector<ll> a(n),b(n);
    in(a,b);
    ll asum=0,bsum=0,dif1=0;
    for(int i=0;i<n;i++){
        asum+=a[i];
        bsum+=b[i];
        if(b[i]>a[i]){
            dif1+=updivide(b[i]-a[i],2);
        }
    }
    yn(dif1<=bsum-asum);
}

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
/******************************TYPE name************************************/
typedef long long ll;
typedef vector<int> vi;
typedef pair<int ,int > pii;
typedef map<int,int>mii;

/***********************************MACRO*************************/
#define test int ct;cin>>ct;while(ct--)
#define fo(i,n) for( i=1;i<=n;i++)
#define el <<"\n"
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define sq(a) (a)*(a)
#define file() freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define zro 1e-9
#define F first
#define S second
#define pb(a) push_back(a)
#define sqsum(n) (((n)*(n+1)*(2*(n)+1))/6) //sum of square number 1 to n
#define mltpls(first,last,ratio) ((last)*(ratio)-(first))/(ratio-1) //multiple series
#define linear_sum(n) (n)*(n+1)/2; //sum of 1 to n
#define arithmetic_progression(first,last,ratio) ((ratio)*(first+last))/2
#define rb rbegin()
#define re rend()
#define bg begin()
#define en end()
#define itr iterator
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
int i;
#define gcd(a,b) __gcd(a,b)
#define gl(s) getline(cin,s)

//code: amr and music :: map of vector

/********************************code***************************/
int main()
{
    int a,b,c;
    int j,k;
    ll sum=0;
    cin>>a;
    fo(i,a)
    {
        fo(j,a)
        {
            fo(k,a)
            {
                sum+=gcd(gcd(i,j),k);
            }
        }
    }
    cout<<sum el;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main() {
    int N,M; cin >> N >>M;
    vector<int> v(M);
    vector<int> p(M);
    for(int i=0;i<M;i++){
        int k; cin >> k;
        for(int j=0;j<k;j++) {
            int n; cin >> n; n--;
            v[i] = v[i]|(1<<n);
        }
    }
    for(int i=0;i<M;i++) cin >> p[i];

    ll ans=0;
    for(int bit=0; bit<(1<<N);bit++){
        bool good=true;
        for(int i=0;i<M;i++){
            int n = __builtin_popcount(bit&v[i]);
            if(n%2!=p[i]){good=false; break;}
        }
        if(good) ans++;
    }
    cout << ans << endl;
}



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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp(a, b) make_pair(a, b)
#define pb push_back

const long long MOD = 1000000007;


int main(){
    cout << fixed;
    cout << setprecision(12);
    ll n;
    cin >> n;

    if(n%2 == 0){
        cout << 1.0/2 << endl;
    }else{
        cout << (((double)n+1)/2)/n << endl;
    }

    return 0;
}


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

using namespace std;

int main(){

	int cant;
  	cin >>cant;
  	int impares=0;
  	for(int i=0;i<cant;i++){
		if(i%2==0){
     		++impares;
		}
   }
   float as=(float(impares)/cant);
  	printf("%.6f",as);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
	int x,y;cin>>x>>y;
	//x animals
	//i cranes, j turtles
	for(int i=0;i<=x;i++){
		int j = x-i;
		int legs = j*4+(i*2);
		if(legs==y) {cout<<"Yes";return;}
	}
	cout<<"No";
}	
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3608
use std::io::*;
use std::str::FromStr;

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")
}

use std::cmp::{max, min};

fn main() {
    let n: usize = read();
    let mut w: Vec<i64> = vec![];
    for _ in 0..n {
        w.push(read());
    }

    let mut ans = std::i64::MAX;
    for T in 1..100 {
        let mut wc = w.clone();
        if T >= wc.len() {
            break;
        }
        let (left, right) = wc.split_at(T);
        ans = min(
            ans,
            (left.iter().sum::<i64>() - right.iter().sum::<i64>()).abs(),
        );
    }
    println!("{}", ans);
}


Measured memory_bytes: 2156
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define EE emplace
#define RB rbegin()
#define MD 1000000007
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define PPF pop_front()
#define EB emplace_back
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>ww,cc,u;
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
LL ar[100];
LL dxx[]= {-1,0,1,0};
LL dyy[]= {0,1,0,-1};
LL dx[]= {2,1,-1,-2,-2,-1,1,2};
LL dy[]= {1,2,2,1,-1,-2,-2,-1};
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    while(tt--)
    {
        UOSMOY;
        cin>>n;
        k=0;;
        s=-1;
        for(i=1; i<=1000000; i++)
        {
            k*=10;
            k+=7;
            if(k%n==0)
            {
                s=i;
                break;
            }
            k=k%n;
        }
        cout<<s<<endl;

    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

struct TWO{
    long long int a,b;
};

bool cmp(TWO x,TWO y){
    if(x.a!=y.a){
        return x.a<y.a;
    }else{
        return x.b<y.b;
    }
}

int main() {
    const long long int mod = 1000000007,INF=50000000000000;
    typedef pair<long long int,long long int>P;
	map<long long int, long long int>mp;
    priority_queue<P,vector<P>,greater<P> >mazuisushi;
    
    priority_queue<P>umaisushi;
	cout << fixed << setprecision(10);
    string str;
    long long int n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    for(long long int i=0;i<=n-1;i++){
        
        if(a-(n-1-2*i)*c-(n-1-i)*(d-c)<=b&&b<=a-(n-1-2*i)*c+(i)*(d-c)){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
} 


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

int main(void){
	int p, q, r;
	int sum = 0;
	scanf("%d %d %d", &p, &q, &r);
	if(p < q){
		if(q < r){
			sum = p + q;
		}else{
			sum = p + r;
		}
	}else{
		// q < p
		if(p < r){
			sum = p + q;
		}else{
			sum = r + q;
		}
	}
	printf("%d\n", sum);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a;
	cin>>n;
	ll ans=0;
	REP(i, n){
		cin>>a;
		while(a>0){
			if(a&1){
				break;
			}
			a>>=1;
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 3e3 + 5;
const ll mod = 998244353;
namespace IO{
    const int SIZE = (1 << 20) + 1;
    char ibuf[SIZE], *iS, *iT, obuf[SIZE],*oS = obuf, *oT = obuf + SIZE - 1;
    char _st[55];
    int _qr = 0;
    inline char gc(){
        return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++);
    }
    inline void qread(){}
    template<class T1, class ...T2>
    inline void qread(T1 &IEE, T2&... ls){
        register T1 __ = 0, ___ = 1;
        register char ch;
        while(!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
        do{
            __ = (__ << 1) + (__ << 3) + (ch ^ 48);
        }while(isdigit(ch = gc()));
        __ *= ___;
        IEE = __;
        qread(ls...);
        return ;
    }
    inline void flush(){
        fwrite(obuf, 1, oS - obuf, stdout);
        oS = obuf;
        return ;
    }
    inline void putc_(char _x){
        *oS++ = _x;
        if(oS == oT) flush();
    }
    inline void qwrite(){}
    template<class T1, class ...T2>
    inline void qwrite(T1 IEE, T2... ls){
        if(!IEE) putc_('0');
        if(IEE < 0) putc_('-'), IEE = -IEE;
        while(IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
        while(_qr) putc_(_st[_qr--]);
        qwrite(ls...);
        return ;
    }
    struct Flusher_{~Flusher_(){flush();}}io_flusher;
}
using namespace IO;
ll dp[maxm][maxm];
int main(){
    ll a, b, c, d;
    qread(a, b, c, d);
    dp[a][b] = 1;
    ll now = 1;
    for(int i = b + 1;i <= d;i++){
        now *= a;
        now %= mod;
        dp[a][i] = now;
    }
    now = 1;
    for(int i = a + 1;i <= c;i++){
        now *= b;
        now %= mod;
        dp[i][b] = now;
    }
    for(ll i = a + 1;i <= c;i++){
        for(ll j = b + 1;j <= d;j++){
            ll k1 = dp[i][j - 1] * i + dp[i - 1][j] * j - dp[i - 1][j - 1] * (i - 1) * (j - 1);
            k1 = (k1 % mod + mod) % mod;
            dp[i][j] = k1;
        }
    }
    cout << dp[c][d] << endl;
    return 0;
}

Measured memory_bytes: 73944
#include <cstdio>


int n, k, x, y;

int main(){
    scanf("%d %d %d %d", &n, &k, &x, &y);

    if(n > k)
        printf("%d\n", k * x + (n - k) * y);
    else
        printf("%d\n", n * x);

    return 0;
}


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

int main() {
  int N;
  
  //入力処理
  cin >> N;
  
  //リュカ数の生成
  vector<int64_t> num(N+1);
  num.at(0) = 2;
  num.at(1) = 1;
  for (int i = 2; i < N+1; i++) {
    num.at(i) += num.at(i-1) + num.at(i-2);
  }

  //出力処理
    cout << num.at(N) << endl;
}

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

int main(){
  int X;cin >> X;
  if(((int)X/100)*105>=X && ((int)X/100)*100<=X){
    cout << 1 << endl;
    return 0;
  }
  else{
    cout << 0 << endl;
    return 0;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::setprecision(11);
    float n;
    cin>>n;
    if(n==1)
    {
        cout<<1.0000000<<"\n";
        return 0;
    }
    if(remainder(n,2)==0)
        cout<<1/2.0<<"\n";
    else
        cout<<((int)(n/2)+1.0)/n<<"\n";

    
}

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

int main() {
  //
  string S;
  string T = "CODEFESTIVAL2016";
  cin >> S;
  int ans = 0;
  rep(i, S.size()) {
    if (S.at(i) != T.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

vector<bool> f() {
	vector<bool> ok(55555, true);
	ok[0] = false; ok[1] = false;
	for (int i = 2; i * i < 55555; i++)
	{
		if(!ok[i]) continue;
		for (int j = i * i; j < 55555; j+=i)
		{
			ok[j] = false;
		}
	}
	return ok;
}

int main() {
    int n; cin >> n;
	vector<bool> prime = f();
	int res = 0;
	int i = 11;
	while (res < n)
	{
		if(prime[i] && i % 5 == 1) {
			cout << i << " ";
			res++;
		}
		i++;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
N,M,X = list(map(int,input().split()))

books = []

for _ in range(N):
    books.append(list(map(int,input().split())))
    
patterns = []

ans = 1145141919

for i in range(2 ** N):
    abilities = [0] * M
    cost = 0
    for j in range(N):
        if ((i >> j) & 1):
            cost += books[j][0]
            for k in range(M):
                abilities[k] += books[j][k + 1]
        
        check = 0
        for x in range(M):
            if abilities[x] >= X:
               check += 1
        if check == M:        
            ans = min(ans, cost)

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


            


Measured memory_bytes: 9228
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
	int n;
  	cin >> n;
	int st = 0;
	vector<ll> ans(n+1);
	vector<ll> ns(n);
	rep(i, n){
    	cin >> ns.at(i);
    	ns.at(i)*=2;
    }
	ans.at(0) = 0;
	for(int i=1; i<=n; i++){
    	ans.at(i) = ns.at(i-1) - ans.at(i-1);
    }
	ans.at(0) = ans.at(n)/2;
	cout << ans.at(0) << ' ';
	for(int i=1; i<n; i++){
    	ans.at(i) = ns.at(i-1) - ans.at(i-1);
		cout << ans.at(i);
    	if(i != n-1) cout << ' ';
    }
	cout << endl;
}

Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;

#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i,m,n) for(int i=m; i<=(int)(n); ++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};


int n,m;
set<vector<string> > app,dir;

vector<string> parse(string in){

  FOR(it,in) if(*it=='/') *it = ' ';  
  stringstream ss(in);
  vector<string> path;
  vector<string> raise;
  raise.pb("$");
  
  while(ss >> in){
    if(in==".") {
      if(app.count(path))
        return raise;
      continue;
    }
    
    if(in==".."){
      if(app.count(path))
        return raise;
      
      if(!path.empty()){
        path.pop_back();
        continue;
      }
      
      return raise;
    }
    
    if(!dir.count(path))
      return raise;
    path.pb(in);
    if(!dir.count(path) &&
       !app.count(path))
      return raise;
  }
  
  return path;
}

void solve(){
  app.clear();
  dir.clear();
  
  rep(i,n){
    string in;
    cin >> in;
    FOR(it,in) if(*it=='/') *it = ' ';
    
    stringstream ss(in);
    vector<string> path;
    while(ss >> in){
      dir.insert(path);
      path.pb(in);
    }
    app.insert(path);
  }

  rep(i,m){
    string a,b;
    cin >> a >> b;
    bool indea=false,indeb=false;
    if(a[SZ(a)-1]=='/'){
      indea=true;
      a=a.substr(0,SZ(a)-1);
    }
    if(b[SZ(b)-1]=='/'){
      indeb=true;
      b=b.substr(0,SZ(b)-1);
    }    
    vector<string> pa,pb;
    pa=parse(a);
    pb=parse(b);
    if(0){
    FOR(it,pa) cout << *it << ' ';
    cout << endl;
    FOR(it,pb) cout << *it << ' ';
    cout << endl;
    cout << endl;
    }
    
    if(dir.count(pa) || indea) pa.pb("index.html");
    if(dir.count(pb) || indeb) pb.pb("index.html");
    
    if(pa==pb && app.count(pa)) cout << "yes" << endl;
    else if(app.count(pa)+app.count(pb)<2) cout << "not found" << endl;
    else cout << "no" << endl;
  }
}

main(){
  while(cin >> n >> m,n)
    solve();
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
long long x[1000010],y[1000010];
#define int long long
signed main(){
  
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a,b,h;
  cin>>a>>b>>h;

  cout<<(a+b)*h/2<<'\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 8;
bool isPrime(ll n){
  if(n<2||n%2==0) return n==2;
  __uint128_t t=n-1, d=t/(t&-t);
  for(__uint128_t a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){
    t=d;
    a=modPow(a,t,n);
    while(t!=n-1 && a!=1 && a!=n-1) a=a*a%n, t=t*2%n;
    if(a!=n-1 && t%2==0) return false;
  }
  return true;
}
ll x;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> x;
  while(!isPrime(x)) x++;
  cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  vector<P> v[n];
  rep(i,n-1) {
    ll x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    v[x].pb(P(y,z));
    v[y].pb(P(x,z));
  }
  ll d[n];
  fill(d,d+n,MAXL);
  priority_queue<P,vector<P>,greater<P> > que;
  rep(i,n) {
    if(v[i].size()==1) { 
      d[i]=0;
      que.push(P(0,i));
      break;
    }
  }
  while(!que.empty()) {
    P p=que.top();que.pop();
    ll x=p.S,c=p.F;
    if(d[x]<c) continue;
    rep(i,v[x].size()) {
      P q=v[x][i];
      ll y=q.F,cc=q.S;
      if(d[y]>c+cc) {
        d[y]=c+cc;
        que.push(P(d[y],y));
      }
    }
  }
  rep(i,n) pr(d[i]%2);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 8704
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  map<i64, i64> m;
  m[0] = 1;
  i32 n;
  cin >> n;
  vi32 a(n + 1);
  rep(i, n) cin >> a[i + 1];
  rep(i, n) a[i + 1] += a[i];
  sort(all(a));
  i64 ans = 0;
  i64 now = a[0], cnt = 1;
  rep(i, n) {
    if (now == a[i + 1]) {
      cnt++;
      ans += cnt - 1;
    } else {
      now = a[i + 1];
      cnt = 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cmath>

int main(void){
	int n;
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int keta;
		int nums[10] = {0,};
		int iMax = 0, iMin = 0;
		char buf[16];

		scanf("%s", buf);

		for(int i = 0; i < 8; i++){
			nums[ buf[i] - '0' ]++;
		}

		keta = 7;
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < nums[i]; j++){
				iMin += i * (int)pow(10.0, keta);
				keta--;
			}
		}
		keta = 7;
		for(int i = 9; i >= 0; i--){
			for(int j = 0; j < nums[i]; j++){
				iMax += i * (int)pow(10.0, keta);
				keta--;
			}
		}
		printf("%d\n", iMax - iMin);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long[] array = new long[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextLong();
        }
        
        long ans = 0;
        for (int i = 1; i < n; i++) {
            long dis = array[i] - array[i-1];
            if (dis * a < b) {
                ans += dis * a;
            } else {
                ans += b;
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 61004
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

const int limit = 50;
int n,m;
int a[limit], b[limit];
bool graph[limit][limit];
bool visited[limit];

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

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

  cin >> n >> m;
  REP(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  int ans = 0;

  REP(i, m) {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

    REP(j, n) {
      visited[j] = false;
    }

    dfs(0);

    bool bridge = false;
    REP(j, n) {
      if(visited[j] == false) bridge = true;
    }
    if(bridge) ans += 1;

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

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

	LL n, m, v, p;
	cin >> n >> m >> v >> p;
	vector<LL> a(n);
	REP(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	debug(a);

	if(v < p) {
		LL t = a[n - p] - m;
		LL ans = 0;
		REP(i, n) {
			if(t <= a[i])
				ans++;
		}
		cout << ans << "\n";
		return 0;
	}

	auto check = [&](LL mx) {
		LL q = m * v - (p - 1) * m;
		REP(i, n - p + 1) {
			if(a[i] > mx) return false;
			q -= min<LL>(mx - a[i], m);
		}
		return q <= 0;
	};

	LL l = 0, r = 2e9;
	while(l < r) {
		LL md = (l + r) / 2;
		if(check(md)) 
			r = md;
		else
			l = md + 1;
	}

	LL q = m * v;
	auto b = a;
	for(int i = n - 1; i >= n - p + 1; i--)
		b[i] += m, q -= m;
	REP(i, n - p + 1) {
		LL d = min<LL>(l - a[i], m);
		LL x = max(min(q, d), 0LL);
		b[i] += x;
		q -= x;
	}

	sort(b.rbegin(), b.rend());
	LL k = b[p - 1] - m;

	int ans = 0;
	REP(i, n) if(k <= a[i])
		ans++;

	cout << ans << "\n";
}


Measured memory_bytes: 1792