akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)

Measured memory_bytes: 18028
/// a.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < pll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    fi>>n;
    static int D[55];
    for (int i = 1;i <= 9;++i)
        D[i] = -1e9;
    while (n --)
    {
        static int d[55];
        for (int i = 0;i <= 9;++i)
            d[i] = D[i];
        int v;
        fi>>v;
        for (int i = 0;i <= 9;++i)
            smax(d[(i + v) % 10],D[i] + v);
        for (int i = 0;i <= 9;++i)
            D[i] = d[i];
    }
    fo << max(0,(*max_element(D + 1,D+10))) << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 256
#from statistics import median
import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
B = readInts()
num = 0
minus = 0
box = []
for i in range(n):
    diff = A[i] - B[i]
    if diff < 0:
        minus -= diff
        num += 1
    else:# プラスの分を足していく
        box.append(diff)
box = sorted(box,reverse = True)
if num == 0:
    print(0)
else:
    # 大きい方から＋の和を取っていって、それが－の合計以上になったらもうやらなくていいよ
    plus = 0
    for a in box:
        plus += a
        num += 1
        if plus >= minus:
            break
    if plus >= minus:
        print(num)
    else:
        print(-1)


Measured memory_bytes: 18740
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int h, n;
    cin >> h >> n;
    int a;
    rep(i,n){
        cin >> a;
        h -= a;
    }
    if(h <= 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
struct Edge {
	int to;
	int next;
}edge[N * 2];
int head[N];
int cnt;
void AddEdge(int fr, int to) {
	edge[++cnt].to = to;
	edge[cnt].next = head[fr];
	head[fr] = cnt;
}
int d[N];
bool v[N];
int Find(int x, int fa) {
	if (d[x] > 2) return x;
	for (int i = head[x]; i; i = edge[i].next) {
		if (edge[i].to != fa) {
			return Find(edge[i].to, x);
		}
	}
	return x;
}
int main() {
	scanf("%d", &n);
	for (int a, b, i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		d[++a]++;
		d[++b]++;
		AddEdge(a, b);
		AddEdge(b, a);
	}
	bool flag = 0;
	for (int i = 1; i <= n; i++) {
		if (d[i] > 2) {
			flag = 1;
			break;
		}
	}
	if (!flag) {
		printf("1\n");
		return 0;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (d[i] == 1) {
			v[Find(i, 0)] = 1;
			ans++;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (v[i]) {
			ans--;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

bool check(string s, string t) {
    
    if (s.size() < t.size()) {
        bool flag = true;
        sort(s.begin(), s.end());
        sort(t.begin(), t.end());
        for (int i=0; i<s.size(); i++) {
            if (s[i] != t[i]) {
                flag = false;
                break;
            }
        }
        if (flag) return true;
    }
    
    for (auto i : s) {
        for (auto j : t) {
            if (i < j) return true;
        }
    }
    
    return false;
}

int main(void){
    string s, t;
    cin >> s >> t;
    cout << (check(s, t) ? "Yes" : "No") << endl;
    return 0;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N,K;
  cin>>N>>K;
  map<ll,ll> m;
  ll t = 1LL;
  while(t*(t+1LL)<N){
    m[N/t]=1LL;
    m[t]=(N/t-N/(t+1));
    t++;
  }
  if(t*(t+1LL)==N){
    m[t]=1LL;
    m[t+1LL]=1LL;
  }
  else {
    if(m[N/t]==0) m[N/t]=1LL;
  }
  ll l = m.size();
  vector<ll> v(l);
  ll i = 0LL;
  for(auto x:m){
    v[i]=(x.second)%mod;
    i++;
  }
  reverse(v.begin(),v.end());
  vector<ll> dp(l,0LL);
  dp[0]=1LL;
  for(ll j = 0LL; j < K; j++){
    vector<ll> S(l);
    for(ll k = 0LL; k < l; k++){
      if(k==0LL) S[k]=dp[k]%mod;
      else S[k]=(dp[k]+S[k-1])%mod;
    }
    for(ll k = 0LL; k < l;k++){
      dp[k]=((S[l-k-1LL]%mod)*(v[k]%mod))%mod;
    }
  }
  ll ans = 0LL;
  for(auto x:dp) ans=(ans+x)%mod;
  cout<<ans<<endl;
}

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

int main() {
  
  int n,m,p,x,sum=0;
  cin >> n;
  
  vector<int> t(n);
  for(int i = 0;i<n;i++){
    cin >> t.at(i);
    sum+=t.at(i);
  }
  
  cin >> m;
  
  for(int i=0;i<m;i++){
    cin>>p>>x;
    sum = sum - t.at(p-1) + x;
    cout << sum << endl;
    sum = sum + t.at(p-1) - x;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n, h[100000];

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 0; i < n; i++) cin >> h[i];
	for(int i = 0; i < n - 1; i++){
		if(h[i] > h[i + 1] || (h[i] == h[i + 1] && h[i] - 1 >= h[i - 1])) h[i] = max(0, h[i] - 1);
		if(h[i] > h[i + 1] || (i != 0 && h[i] < h[i - 1])){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
    int N;

    cin >> N;

    string S;
    set<string> item;

    for(int i = 0; i < N; i++) {
        cin >> S;
        item.insert(S);
    }

    int ans = item.size();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 19152
function Main(input) {
    input = input.split(' ');
  	train = input[1];
  	members = input[0];
	taxi = input[2];
	if(taxi >= members*train){
      console.log(members*train);
    }else{
      console.log(taxi);
    }
  
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
#define MOD (LL)(1e9+7)

int main(){
	int N;
	cin >> N;
	long double sum = 0;
	for(int i=0; i<N; i++){
		long double A;
		cin >> A;
		sum += 1.0/A;
	}
	cout << setprecision(36) << 1.0/sum << endl;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

long long gcd(long long a, long long b){
	ll c;
	while ( a != 0 ) {
		c = a; a = b%a; b = c;
	}
	return b;
}

long long lcm(long long a, long long b){
	if(a == 0 || b == 0) return 0;
	return a / gcd(a, b) * b;
}

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	ll n;
	cin >> n;

	set<ll> a;
	for(int i=0; i<n; i++){
		ll t;
		cin >> t;
		a.insert(t);
	}

	ll ans = 1;
	for(auto it=a.begin(); it != a.end(); it++){
		ans = lcm(ans, *it);
	}

	cout << ans << endl;


	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define lint long long
#define INF 10000000000000
lint dp[100010];
lint h[100010];
int main() {

	lint N; cin >> N;
	
	for (int i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);

	for (int i = 2; i < N; i++)
	{
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[N - 1] << endl;
	return 0;
}


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

int main()
{
  ll N;
  cin >> N;
  vector<ll> a(N);
  for (int i=0; i<N; i++){
    cin >> a[i];
  }

  ll c = 1;
  ll ans = 0;
  for (int i=0; i<N; i++) {
    if (a[i] == c) {
      c++;
    } else {
      ans++;
    }
  }
  if (ans == N) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var s = long.Parse(Console.ReadLine().Trim());
        var hs = new HashSet<long>();
        var pre = s;
        hs.Add(s);
        var w = 0L;
        for (int i = 2; i <= 1000000; i++)
        {
            if (pre % 2 == 0)
            {
                 w = pre / 2;
                if (!hs.Add(w)) { Console.WriteLine(i); break; }
            }
            else
            {
                 w = pre * 3 + 1;
                if (!hs.Add(w)) { Console.WriteLine(i); break; }
            }
            pre = w;
        }

    }
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int a, b, k;
int main() {
    cin >> a >> b >> k;
    if (b - a + 1 <= 2 * k) {
        for (int i = a; i <= b; ++i) {
            cout << i << endl;
        }
    } else {
        for (int i = 0; i < k; ++i) {
            cout << a + i << endl;
        }
        for (int i = k - 1; i >= 0; --i) {
            cout << b - i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
int d,n;scanf("%d %d",&d,&n);

if(d==0){
    if(n==100){printf("101\n");}
    else{printf("%d\n",n);}
}
if(d==1){
    if(n==100){printf("10100\n");}
    else{printf("%d\n",n*100);}
}

if(d==2){
    if(n==100){printf("1010000\n");}
    else{printf("%d\n",n*10000);}
}

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
 int a;
 cin>>a;
 cout<<2*a*M_PI;
}


Measured memory_bytes: 3784
//TINY_OUNCE911666
// You are not prepared!
 
#include <bits/stdc++.h>
using namespace std;
 
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
 
int32_t main() {
	_upgrade
	
	int H, W;
	cin >> H >> W;
	
	vector<vector<char>> grid(H, vector<char>(W));
	
	for (vector<char>& x : grid) {
		for (char& y : x) {
			cin >> y;
		}
	}
	
	vector<vector<ll>> dp(H, vector<ll>(W, 0));
	
	for (int i = 0; i < W; ++i) {
		if (grid[0][i] == '#') {
			break;
		}
		
		dp[0][i]++;
	}
	
	for (int i = 0; i < H; ++i) {
		if (grid[i][0] == '#') {
			break;
		}
		
		dp[i][0]++;
	}
	
	const int MOD = 1e9+7;
	for (int i = 1; i < H; ++i) {
		for (int j = 1; j < W; ++j) {
			if (grid[i][j] != '#') {
				dp[i][j] = dp[i-1][j] + dp[i][j-1];
				
				if (dp[i][j] > MOD) {
					dp[i][j] -= MOD;
				}
				//dbg(dp[i][j]);
			}
		}
	}
	
	cout << dp[H-1][W-1] << "\n";
}


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

int main(){
  int A, B, K;
  cin >> A >> B >> K;

  set<int> ans;
  for(int i = 0; i < K; i++){
    ans.insert(min(A + i, B));
    ans.insert(max(A, B - i));
  }

  for(auto x: ans){
    cout << x << endl;
  }
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $N);
$array = explode(" ", trim(fgets(STDIN)));
$all = array_sum($array);
$ans = 0;
$now = 1;

for($i=0;$i<=$N; $i++){
    $ans += $now;
    $now = $now-$array[$i];
    if($now < 0){
        echo -1;
        exit;
    }
    $all-= $array[$i];
    $now*=2;
    if($now > $all){
        $now = $all;
    }


}
//$ans -= $array[$N];
echo $ans;


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

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  bool takahashi = true;
  while (true)
  {
    C -= B;
    if (C <= 0) break;
    A -= D;
    if (A <= 0)
    {
      takahashi = false;
      break;
    }
  }
  if (takahashi) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3620
s = input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3]) 
operations = ["+", "-"]
for op1 in operations:
    if op1 == "+":
        ab = a+b
    else:
        ab = a-b
    for op2 in operations:
        if op2 == "+":
            abc = ab+c
        else:
            abc = ab-c
        for op3 in operations:
            if op3 == "+":
                ans = abc+d
            else:
                ans = abc-d
            if ans == 7:
                print('{}{}{}{}{}{}{}=7'.format(a,op1,b,op2,c,op3,d))
                exit()

Measured memory_bytes: 3064
import numpy as np

c = [list(map(int, input().split())) for _ in range(3)]

a0 = 0
B = np.array([c[0][0], c[0][1], c[0][2]])

if len(set(np.array(c[1]) - B)) == 1 and len(set(np.array(c[2]) - B)) == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14448
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
const int maxn=1e9;
void read(int &xxxxx){scanf("%d",&xxxxx);}

int main()
{
    char t[100];cin>>t;int l=strlen(t),minn=100000;
    rep(i,0,l-2){
        minn=min(minn,abs((t[i]-'0')*100+(t[i+1]-'0')*10+(t[i+2]-'0')-753));
    }
    cout<<minn<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  map<string,int> memo;
  rep(i,n){
      string buf;cin>>buf;
      sort(buf.begin(),buf.end());
      memo[buf]+=1;
  }
  lint res=0;
  for(auto& val:memo){
      res+=val.second*(val.second-1)/2;
  }
  cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 11308
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		char[] inArray = in.toCharArray();
		StringBuffer buf = new StringBuffer();
		for (int i = 0 ; i < inArray.length; i = i + 2) {
			buf.append(Character.toString(inArray[i]));
		}
		System.out.println(buf.toString());

	}


}

Measured memory_bytes: 27952
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

int N, T;

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

  int maxa = INT_MIN;
  int mina = INT_MAX;
  int ans = 0;
  rep(i, N) {
    int a;
    cin >> a;
    mina = min(a, mina);
    int now = a - mina;
    if (now > maxa) {
      ans = 1;
      maxa = now;
    } else if (now == maxa) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define INF 1000000000

int main()
{ 
	int t,n,i;
	long long int sum;
		string s;
		cin >> s; 

		i=0;
		sum=0;
		while(s[i] != '\0')
		{
			sum += (int)(s[i] - '0');
			i++;
		}

		if(sum%9==0){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	return 0;
}




Measured memory_bytes: 3692
import java.util.Scanner;
import java.util.*;
public class Main {
	static int[] ar;
	static int n;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		n = stdIn.nextInt();
		int m = stdIn.nextInt();
		ar = new int[2*n];
		for(int i = 0; i < 2 * n; i++) {
			ar[i] = i+1;
		}
		for(int i = 0; i < m; i++) {
			int tmp = stdIn.nextInt();
			if(tmp == 0) rs();
			else cut(tmp);
		}
		
		for(int i = 0; i < 2 * n; i++) {
			System.out.println(ar[i]);
		}
	}
	
	static void rs(){
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = ar[i];
		}

		int[] b = new int[n];
		for(int i = 0; i< n; i++) {
			b[i] = ar[i + n];
 		}
		
		for(int i = 0; i < 2*n; i++) {
			if(i % 2 == 0) {
				ar[i] = a[i / 2 ];
			}
			else {
				ar[i] = b[i / 2 ];
			}
		}
	}
	static void cut(int k) {
		int[] a = new int[k];
		for(int i = 0; i< k; i++) {
			a[i] = ar[i];
		}
		
		int[] b = new int[2 * n - k];
		for(int i = 0; i < 2 * n - k; i++) {
			b[i] = ar[i + k];
		}
		for(int i = 0; i < 2 * n - k; i++) {
			ar[i] = b[i];
		}
		
		for(int i = 0; i < k; i++) {
			ar[2 * n - k + i] = a[i];
		}
		
	}
	

}

Measured memory_bytes: 24432
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val X = rd.readInt()


    val ans = if (X==0) 1 else 0
    println(ans)
}


//val rd = debug.Reader("abc", "178", "a", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readDouble: () -> Double = { br.readLine().toDouble() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readIntArray: () -> IntArray = { readListInt().toIntArray() }
    val readLongArray: () -> LongArray = { readListLong().toLongArray() }
    val readListStringCol: (Int) -> List<String> = { N -> (0 until N).map { readString() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { readListInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { readListLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 34692
#include<bits/stdc++.h>
using namespace std;pair<int,int>p[200100];int N,i,c,n[200100],d[200100];main(){cin>>N;for(;i<N;i++)cin>>p[i].first>>p[i].second;sort(p,p+N);d[N]=1;for(;i--;){c=i+1;while(c<N&&p[c].first<p[i].first+p[i].second)c=n[c];d[i]=(d[i+1]+d[n[i]=c])%998244353;}cout<<d[0]<<"\n";}

Measured memory_bytes: 3456
# from collections import deque
import numpy as np
h,w = map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
# d=deque([0,0])
ans=np.array([[-1]*(w+2)] + [[-1]+[0]*w+[-1] for i in range(h)] + [[-1]*(w+2)])
opt = [[0,1],[1,0],[0,-1],[-1,0]]
temp=[1,1]
# print(ans)
for i in range(n):
    num=a[i]
    while num:
        ans[temp[0]][temp[1]] = i+1
        for j in opt:
            if ans[temp[0]+j[0]][temp[1]+j[1]] == 0:
                temp[0]+=j[0]
                temp[1]+=j[1]
                break
        num-=1

for i in range(1,h+1):
    print(*ans[i][1:-1])



Measured memory_bytes: 13248
#include <iostream>
using namespace std;
bool is_prime(int n){
	if(n<=1)
		return false;
	for(int i=2;i*i<=n;i++){
		if(n%i==0)
			return false;
	}
	return true;
}
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int num=0;
	for(int i=0;i<n;i++){
		if(is_prime(a[i]))
			num++;
	}
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 1196
n = gets.to_i
a = gets.split.map(&:to_i)
if a[0] != 0
  puts 0
  exit
end

mod = 1000000007
cnt = Array.new(n + 1, 0)
cnt[0] = 1
ans = 3

1.upto(n - 1) do |i|
  if a[i] != 0 && cnt[a[i] - 1] <= cnt[a[i]]
    ans *= 0
  end
  if cnt[a[i]] == 0 # 1回めの出現
    ans *= cnt[a[i] - 1]
    ans %= mod
    cnt[a[i]] += 1
  elsif cnt[a[i]] == 1
    if a[i] == 0
      ans *= 2
    else
      ans *= (cnt[a[i] - 1] - cnt[a[i]])
    end
    ans %= mod
    cnt[a[i]] += 1
  elsif cnt[a[i]] == 2
    cnt[a[i]] += 1
  else
    ans *= 0
  end
end
p ans


Measured memory_bytes: 10892
/******************************************
* NICK : nikhilsinghh59 *
******************************************/


#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
const int M = 1e9+7;

int main()
{   


    ll x , y;
    cin >> x>> y;

    bool ans = false;

    for(int i=0;i<=x ; i++){
        if(y == 2*i + (x - i)*4) {
            ans = true;
            break;
        }
    }
    if(ans) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    ans+=2 * min(x, K - x);
  }
  cout << ans << endl;
}


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

int main(){
    int n,a[100];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=a[n-1]-a[0];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 400005
using namespace std;
int head[N],ver[N],nxt[N],tot;
void add(int a,int b)
{
    tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;return ;
}
int n,k;
int f[N],ans,s[N],dep[N];
void dfs(int x)
{
    f[x]=1;
    for(int i=head[x];i;i=nxt[i])
    {
        dep[ver[i]]=dep[x]+1;
        dfs(ver[i]);
        f[x]=max(f[x],f[ver[i]]+1);
    }
    if(x!=1&&f[x]==k)
    {
        f[x]=0;
        if(dep[x]!=1)ans++;
    }
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&s[i]);
        if(i==1)if(s[i]!=1)ans++;
        if(i!=1)add(s[i],i);
    }
    dfs(1);
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int n,c;
  cin >> n >> c;
  int d[c][c];
  rep(i,c)rep(j,c)cin >> d[i][j];
  int mod0[30],mod1[30],mod2[30];
  rep(i,30){
    mod0[i] = 0;
    mod1[i] = 0;
    mod2[i] = 0;
  }
  int grid[n][n];
  rep(i,n){
    rep(j,n){
      cin >> grid[i][j];
      grid[i][j]--;
      if((i+j)%3 == 0)mod0[grid[i][j]]++;
      else if((i+j)%3 == 1)mod1[grid[i][j]]++;
      else mod2[grid[i][j]]++;
    }
  }
  int ans = INF;
  rep(i,c){
    rep(j,c){
      rep(k,c){
        if(i==j || j==k || k==i)continue;
        int tmp = 0;
        rep(l,30){
          tmp += mod0[l]*d[l][i] + mod1[l]*d[l][j] + mod2[l]*d[l][k];
        }
        if(ans > tmp)ans = tmp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4620
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

for i in range(1,4):
    cnt=0
    for j in range(n):
        cnt+=abs(A[j]-B[j])**i
    print(cnt**(1/i))
cnt=0
for j in range(n):
    cnt=max(cnt,abs(A[j]-B[j]))
print(cnt)


Measured memory_bytes: 5636
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const rows = input.split("\n")
const N = parseInt(rows[0], 10)
const values = rows[1].split(" ")
var sum = BigInt(values[0]);
function multi () {
    for (var i = 1; i < N; i ++) {
        sum *= BigInt(values[i])
        if (sum > 1000000000000000000) {
            return -1
        }
    }
    return sum
}
if (values.find(value => value === '0')) {
    console.log(0)
} else {
    console.log(multi().toString().replace('n', ''))
}


Measured memory_bytes: 41520
#include<stdio.h>
int main()
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	int flag=1;
	while(a>0 && c>0)
	{
		if(flag==1) 
		{
			c=c-b;
			flag=0;
		}
		else
		{
			a=a-d;
			flag=1;
		}
	}
	if(a<=0) printf("No\n");
	if(c<=0) printf("Yes\n");
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(2*N);
  for (int i = 0; i < 2*N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = ans + vec.at(2*i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int s[10000], t[500], n, q, i, c = 0, j;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &s[i]);
	}
	
	scanf("%d", &q);
	for (i = 0; i < q; i++)
	{
		scanf("%d", &t[i]);
	}
	
	for (i = 0; i < q; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (s[j] == t[i])
			{
				c++;
				break;
			}
		}
	}
	
	printf("%d\n", c);
	
	return 0;
}

Measured memory_bytes: 2764
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int  a = sc.nextInt();
		int[] b=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=sc.nextInt();
		}
		int sum=0;
		for(int i=0;i<a;i++) {
			if(i==a-1) {
				sum=sum+Math.abs(b[i]-0);
				break;
			}
			if(i==0) sum=sum+Math.abs(0-b[i]);
			sum=sum+Math.abs(b[i]-b[i+1]);
		}
		int Asum=sum;
		for(int i=0;i<a;i++) {
			sum=Asum;
			if(i==0) {
				sum=sum-Math.abs(0-b[i]);
				sum=sum-Math.abs(b[i]-b[i+1]);
				sum=sum+Math.abs(0-b[i+1]);
				System.out.println(sum);
				continue;
			}
			if(i==a-1) {
				sum=sum-Math.abs(b[i]-0);
				sum=sum-Math.abs(b[i-1]-b[i]);
				sum=sum+Math.abs(b[i-1]-0);
				System.out.println(sum);
				break;
			}
			sum=sum-Math.abs(b[i]-b[i+1])-Math.abs(b[i-1]-b[i]);
			sum=sum+Math.abs(b[i-1]-b[i+1]);
			System.out.println(sum);
		}
		
	}
}

Measured memory_bytes: 66220
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

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

  int H,W,K;
  cin>>H>>W>>K;
  int sx,sy,gx,gy;
  cin>>sx>>sy>>gx>>gy;
  sx--;sy--;gx--;gy--;
  vector<string> S(H);
  rep(i,H) cin>>S[i];

  vector<vector<vector<int>>> dp(H,vector<vector<int>> (W,vector<int> (2,MOD)));
  dp[sx][sy][0]=0;
  dp[sx][sy][1]=0;
  priority_queue<tuple<int,int,int,int>,vector<tuple<int,int,int,int>>,greater<tuple<int,int,int,int>>> PQ;
  PQ.push(mkt(0,sx,sy,0));
  PQ.push(mkt(0,sx,sy,1));
  while(!PQ.empty()){
      auto f=PQ.top();
      PQ.pop();

      int d=get<0>(f);
      int x=get<1>(f);
      int y=get<2>(f);
      int c=get<3>(f);
      if(dp[x][y][c]<d) continue;

      for(int k=0;k<4;k++){
          int nx=x;
          int ny=y;
          for(int i=0;i<K;i++){
              nx+=dx[k];
              ny+=dy[k];
              if(nx<0||ny<0||nx>=H||ny>=W) break;
              if(S[nx][ny]!='.') break;
              if(dp[nx][ny][k%2]<=d) break;
              if(dp[nx][ny][k%2]==d+1) continue;
              dp[nx][ny][k%2]=d+1;
              PQ.push(mkt(d+1,nx,ny,k%2));
          }
      }
  }

  if(min(dp[gx][gy][0],dp[gx][gy][1])==MOD) cout<<-1<<endl;
  else cout<<min(dp[gx][gy][0],dp[gx][gy][1])<<endl;

  return 0;
}


Measured memory_bytes: 113564
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF LLONG_MAX / 2;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;

const ll INF = LLONG_MAX;

#define ARRAY_MAX 200002
#define INF 1e9+7


int main(){

    int n,c;
    cin >> n >> c;
    vector<int> s(n),t(n),ch(n);
    REP(i,n){
        cin >> s[i] >> t[i] >> ch[i];
    }
    int imos[ARRAY_MAX];
    int ans[ARRAY_MAX];
    REP(i,ARRAY_MAX){
        ans[i] = 0;
    }

    for(int i = 1;i <= c;i++){

        REP(j,ARRAY_MAX){
            imos[j] = 0;
        }
        REP(j,n){
            if(ch[j] == i){
                imos[s[j]*2-1]++;
                imos[t[j]*2+1]--;
            }
        }
        REP(j,ARRAY_MAX){
            imos[j+1] += imos[j];
        }
        REP(j,ARRAY_MAX){
            if(imos[j] > 0){
                ans[j]++;
            }
        }
    }
    int mx = 0;
    REP(i,ARRAY_MAX){
        mx = max(mx,ans[i]);
    }
    cout << mx << endl;

    return 0;
}

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

signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	if(abs(c-a) <=d||(abs(a-b)<=d&&abs(b-c)<=d)){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool* PrimeSieve(int n) {
  bool*s = new bool[n];
  for (int i = 0; i < n; ++i) s[i] = true;
  s[0] = s[1] = false;
  for (int i = 2; i < n; ++i)
    if (s[i]) for (int j = i << 1; j < n; j += i) s[j] = false;
  return s;
}

int main() {

  const int N = 50022;
  auto isprime = PrimeSieve(N);

  loop {
    int n; cin >> n;
    if (!cin) break;
    int a,b;
    for (int m = n-1; m > 0; --m) {
      if (isprime[m]) {
        a = m;
        break;
      }
    }
    for (int m = n+1; m < N; ++m) {
      if (isprime[m]) {
        b = m;
        break;
      }
    }
    cout << a << ' ' << b << endl;
  }

  return 0;
}

Measured memory_bytes: 1236
#define _USE_MATH_DEFINES    
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define quickIO()   {cin.tie(0);    cout.sync_with_stdio(false);}
#define rep(i,n)    for(ll i=0; i<(ll)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define fcout cout << fixed << setprecision(10) 
const ll inf = 1e18;
const ll mod = 1e9 +7;
     
ld sqrtld(ld x){
    ld left = 0, right = x;
    rep(i, 100){
        ld mid = (left + right)/2;
        if (mid*mid <= x)   left =mid;
        else    right = mid;
    }
    return left;
}

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


ll cul(ll n){
    return (n-1)*n/2;
}


int main (){
    int n;    cin >> n ;
    int ans;
    ans = n * (n+1) /2;

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



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
ll p[200005];
int a[200005];

typedef pair<int, int> P;
int main() {
	int n,k;
	cin >>n>>k;
	
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	
	int count = 1;
	int ans = 1;
	int min[200005];
	for (int i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1]) {
			count++;
		}
		else {
			min[ans - 1] = count;
			ans++;
			
			count = 1;
		}
	}
	min[ans - 1] = count;
	
	ll sum = 0;
	sort(min, min + ans);
	
	
		for (int i = 0; i < ans-k; i++) {
			sum += min[i];
		}
	
		cout << sum << endl;

	return 0;
}

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

#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)
#define rep(i,x,N) for(int i=x;i<=N;i++)
#define revrep(i,x,N) for(int i=x;i>=N;i--)
#define ar array

using namespace std;
using ll=long long int;
using ld=long double;
using vi=vector<int>;
using vll=vector<ll>;
using vd=vector<double>;
using vvi=vector<vi>;
int ctoi(char c) {return c-'0';}
int slen(string s) {return s.length();}
int vsize(vi a) {return (int)a.size();}
int in() {int x;cin>>x;return x;}
void tf(bool ok) {cout<<(ok ? "YES" : "NO")<<endl;}

//https://dmoj.ca/problem/dpv

const int MAXN = 1e5 + 10;

vector<int> g[MAXN];
ll dp[MAXN],c[MAXN],ans[MAXN];
int N,M;

void dfs1(int v,int p){

	dp[v] = 1;
	vector<int> cdrn;
	for(int u : g[v]){
		if(u == p) continue;
		dfs1(u,v);
		dp[v] = (dp[v] * (1 + dp[u])) % M;
		cdrn.pb(u);
	}

	vector<ll> ps,ss;
	ll pref = 1, suf = 1;
	for(int i = 0;i<(int)cdrn.size();i++){
		ps.pb(pref);
		pref = (pref * (dp[cdrn[i]]+1)) % M;
	}
	for(int i = (int)cdrn.size() - 1;i>=0;i--){
		ss.pb(suf);
		suf = (suf * (dp[cdrn[i]]+1)) % M;
	}
	reverse(ss.begin(),ss.end());
	for(int i = 0;i<(int)cdrn.size();i++){
		c[cdrn[i]] = (ps[i]*ss[i]) % M;
	}

}

void dfs2(int v,int p){

	ans[v] = (dp[v] * c[v]) % M;

	for(int u : g[v]){
		if(u == p) continue;
		c[u] = (c[u] * (c[v]) + 1) % M;
		dfs2(u,v);
	}

}

int main(){

  cin>>N>>M;
	for(int i = 1;i<N;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}

	dfs1(1,-1);
	c[1] = 1;
	dfs2(1,-1);

	for(int i = 1;i<=N;i++)
    cout<<ans[i]<<endl;

	return 0;

}




Measured memory_bytes: 24892
# N = gets.chomp.to_i
N, R = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

if (N >= 10)
  p R
else
  # R = intermediate - 100*(10-N)
  # intermediate = R + 100 * (10-N)
  p R + 100 * (10-N)
end  

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

main(){
  int i,j,min[3],ans;
  char a[102];
  while(cin >> a){
    ans = 0;
    for(i=0;i<3;i++) min[i] = 0;

    for(i=0;i<102;i++){
      if(a[i] == '\0') break;
      else if(a[i] == 'I'){
	min[0]++;
	ans++;
      }
      else if(a[i] == 'V'){
	ans += 5;
	if(min[0] != 0){
	  ans -= min[0] * 2;
	  min[0] = 0;
	}
      }
      else if(a[i] == 'X'){
	ans += 10;
	if(min[0] != 0){
	  ans -= min[0] * 2;
	  min[0] = 0;
	}
	min[1]++;
      }
      else if(a[i] == 'L'){
	ans += 50;
	if(min[1] != 0){
	  ans -= min[1] * 20;
	  min[1] = 0;
	}
      }
      else if(a[i] == 'C'){
	ans += 100;
	if(min[1] != 0){
	  ans -= min[1] * 20;
	  min[1] = 0;
	}
	min[2]++;
      }
      else if(a[i] == 'D'){
	ans += 500;
	if(min[2] != 0){
	  ans -= min[2] * 200;
	  min[2] = 0;
	}
      }
     else if(a[i] == 'M'){
	ans += 1000;
	if(min[2] != 0){
	  ans -= min[2] * 200;
	  min[2] = 0;
	}
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 0
using System;

public class SmallOrLarge
{
    //?????????????????§?°????????????????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int num1;
        int num2;
        int num3;
        string[] num_unit;
        /*---??£?¨???¨---*/

        /*??°???????????????????????§??????*/
        num_unit = Console.ReadLine().Split(' ');
        num1 = int.Parse(num_unit[0]);
        num2 = int.Parse(num_unit[1]);
        num3 = int.Parse(num_unit[2]);

        /*???????????????????????????[a<b<c]??????Yes*/
        if (num1 < num2 && num2 < num3){
            Console.WriteLine("Yes");
        }
        else{
            Console.WriteLine("No");
        }

    }
}

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

int main() {

	int A, B, M; cin >> A >> B >> M;
	vector<int> a(A), b(B);
	for (int i = 0; i < A; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < B; i++) {
		cin >> b[i];
	}
	int ans = 1000000000;
	for (int i = 0; i < M; i++) {
		int x, y, c; cin >> x >> y >> c;
		--x;
		--y;
		int tmp = 0;
		tmp = a[x] + b[y] - c;
		ans = min(ans, tmp);
	}
	ans = min(ans, *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end()));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3980
#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rg register
#define mn 100005
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
template<class T> il T Max(T a,T b){return a>b?a:b;}
template<class T> il T Min(T a,T b){return a<b?a:b;}
int n,A,B,u,v,cnt,fa[mn],h[mn],dep[mn],g[mn];
struct E{int to,nxt;}e[mn<<1];
il vd Add(int u,int v){e[++cnt]=(E){v,h[u]},h[u]=cnt;}
vd Dfs(int u){
    g[u]=dep[u]=dep[fa[u]]+1;
    for(rg int i=h[u];i;i=e[i].nxt){int v=e[i].to;
        if(v!=fa[u]){
            fa[v]=u,Dfs(v),g[u]=Max(g[u],g[v]);
        }
    }
}
int main(){
    n=rd(),A=rd(),B=rd();
    rep(i,2,n) u=rd(),v=rd(),Add(u,v),Add(v,u);
    Dfs(B);
    int c=(dep[A]-2)>>1;
    for(rg int i=c;i;--i){
        A=fa[A];
    }
    rt(g[A]-2);
    return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
    while(!isdigit(c=gc())&&c!='-');
    int f=c=='-'?c=gc(),1:0,x=c^48;
    while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
    return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 10624
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        boolean[][] likeFoods = new boolean[N][M+1];
        for (int i = 0; i < N; i++) {
            int K = sc.nextInt();
            for(int k = 0; k < K; k++){
               likeFoods[i][sc.nextInt()] = true;
            }
        }

        solver(N, M, likeFoods);
    }

    public static void solver(int N, int M, boolean[][] likeFoods) {
        int count = 0;
        for(int m = 1; m < M+1; m++){
            boolean allLike = true;
            for(int n = 0; n < N; n++){
                if(!likeFoods[n][m]){
                    allLike = false;
                    break;
                }
            }
            if(allLike == true){
                count++;
            }
        }
        out.println(count);
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ll a, b; cin >> a >> b;

    int out = 1;
    int p_max = (int)min(sqrt(a), sqrt(b));

    bool flag_a = true, flag_b = true;
    for (int i = 2; i <= p_max; i++) {
        bool fa = false, fb = false;
        if (a % i == 0) {
            fa = true; flag_a = false;
            while (a % i == 0 && a > 0) {
                a /= i;
            }
        }
        if (b % i == 0) {
            fb = true; flag_b = false;
            while (b % i == 0 && b > 0) {
                b /= i;
            }
        }
        if (fa && fb) out++;
    }
    if (a >= b) {
        swap(a, b);
        swap(flag_a, flag_b);
    }
    if (a != 1)
        if (flag_a || b % a == 0) out++;

    cout << out << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
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<class T>T extGCD(T a, T b, T& x, T& y){
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

int main()
{
    int a, b; cin >> a >> b;
    int x, y;
    extGCD(a, b, x, y);
    cout << x << " " << y << endl;
    return 0;}


Measured memory_bytes: 3132
#include <algorithm>
#include <vector>
#include <complex>
using namespace std;
//---------------------------------------------------------------
using Point = complex<double>;
using Polygon = vector<Point>;
double dot(const Point &a, const Point &b) { return real(conj(a) * b); }
double cross(const Point &a, const Point &b) { return imag(conj(a) * b); }
//---------------------------------------------------------------

#include <iostream>
int main() {
    while (true) {
        vector<double> x(4), y(4);
        for (int i = 0; i < 4; i++) { cin >> x[i] >> y[i]; };
        if (!cin) break;
        Point a(x[0], y[0]), b(x[1], y[1]), c(x[2], y[2]), p(x[3], y[3]);
        double s1 = cross(a - p, b - p);
        double s2 = cross(b - p, c - p);
        double s3 = cross(c - p, a - p);
        bool ok = (s1 > 0 && s2 > 0 && s3 > 0) || (s1 < 0 && s2 < 0 && s3 < 0);
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> grid(h, vector<char>(w));
	for(int i=0; i<h; ++i) {
		for(int j=0; j<w; ++j) {
			cin >> grid[i][j];
		}
	}
	vector<vector<int>> dp(h, vector<int>(w));
	dp[0][0] = 1;
	for(int i=1; i<h; ++i) {
		if(grid[i][0] == '#') {
			dp[i][0] = 0;
			continue;
		}
		dp[i][0] = dp[i-1][0];
	}
	for(int j=1; j<w; ++j) {
		if(grid[0][j] == '#') {
			dp[0][j] = 0;
			continue;
		}
		dp[0][j] = dp[0][j-1];
	}
	for(int i=1; i<h; ++i) {
		for(int j=1; j<w; ++j) {
			if(grid[i][j] == '#') {
				dp[i][j] = 0;
				continue;
			}
			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
		}
	}
	printf("%d", dp[h-1][w-1]);
	return 0;
}

Measured memory_bytes: 8692