akhauriyash/Code-Regression huggingface dataset:
#include<bits//stdc++.h>
using namespace std;
 
int main()
{
   long long n,maxw,sum=0;
   cin>>n>>maxw;
   long long int wei[n],val[n];
   long long int tt=0;
   for(int i=0;i<n;i++)
   {
   	cin>>wei[i]>>val[i];
   	sum+=val[i];
   	tt+=wei[i];
   }
   vector<long long int>tmp(sum+1,tt);
   vector<vector<long long int> >dp(n,tmp);
   dp[0][0]=0;
   for(int i=1;i<=sum;i++)
   {
    if(val[0]==i)
    dp[0][i]=wei[0];
    
   }
 
   for(int i=1;i<n;i++)
   {
    for(int j=0;j<=sum;j++)
    {
      if(j==0)
      {dp[i][0]=0;continue;}
      if(j-val[i]>=0&&dp[i-1][j-val[i]]!=tt)
      dp[i][j]=wei[i]+dp[i-1][j-val[i]];
      dp[i][j]=min(dp[i][j],dp[i-1][j]);

    }

    
   }
 
   for(int i=sum;i>=0;i--)
   {
   	if(dp[n-1][i]<=maxw)
    {cout<<i<<endl;break;}
   }
}

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


def solve(N: int):
    count = 0
    for i in range(1, N + 1):
        if i % 2 != 0:
            count += 1
        else:
            pass

    result = count / N

    print(result)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == "__main__":
    main()


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

#define llint long long int

using namespace std;

int main(){
    int L, R, d;

    cin >> L >> R >> d;

    int ans = 0;

    for(int i = L; i <= R; i ++){
        if(i % d == 0){
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define VEC(n)  int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

int main()
{
    FAST();
    ll int n,m,res;
    char ara[28];
    for(int i=1;i<=25;i++)ara[i]=i+'a'-1;
    ara[0]='z';
    string s;
     cin>>n;
       while(n)
       {
           m=n%26;
           s+=ara[m];
           if(m==0)n--;
           n=n/26;
       }


    reverse(s.begin(),s.end());
    cout<<s<<endl;



}




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

int N, M;
int A[200010], dp[1000010];
deque<int> dq;

int main() {
    scanf("%d", &N);

    int sum = 0;
    for(int i = 0; i < N - 1; i++) {
        scanf("%d", &A[i]);
        if(i >= 2) sum += A[i];
    }

    for(int i = 0; i < sum + 1; i++) {
        dq.push_back(i);
    }
    for(int i = 3; i < N; i++) {
        for(int j = 0; j < A[i - 1]; j++) {
            dq.push_front(dq[2*j + 1]);
        }
    }

    scanf("%d", &M);

    for(int i = 0; i < M; i++) {
        int x; scanf("%d", &x);

        if(x >= dq.size()) {
            printf("%d\n", A[0] - A[1] + x - sum);
        }
        else printf("%d\n", A[0] - A[1] + dq[x]);
    }
}


Measured memory_bytes: 13068
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        long sum = 0;
        long[] data = Stream.of(br.readLine().split(" "))
            .mapToLong(Long::parseLong).toArray();
        long min = data[0];
        long max = data[0];
        for (int i = 0; i < n; i++) {
            if (max < data[i]) {
                max = data[i];
            } else if (data[i] < min) {
                min = data[i];
            }
            sum += data[i];
        }
        System.out.println(min + " " + max + " " + sum);
    }
}

Measured memory_bytes: 32576
#date: 2020-03-15 21:28
import sys
stdin = sys.stdin
from heapq import heappop, heappush, heapify

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m = na()
    a = na()
    aminus = [-ai for ai in a]
    heapify(aminus)
    for i in range(m):
        amax = heappop(aminus)
        heappush(aminus, -((-amax)//2))
    print(-sum(aminus))


if __name__ == "__main__":
    main()

Measured memory_bytes: 14204
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using PL = pair<ll,ll>;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
constexpr int INF = (1 << 29);
constexpr ll INF_ = (1LL << 58);
constexpr ld EPS = (1e-10);
constexpr ld PI_ = 3.141592653589793238;//46264338327950288
constexpr ld E_ = 2.71828182845904523;//5360287471352
constexpr ll MOD = 1000000007;
//// functions (integer)_________________________________
ll modpow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a % m;
		a = a * a%m; n >>= 1;
	}
	return res;
}
long long modinv(long long a, long long p, long long mod){
  return modpow(a,p-2,mod);
}
////-----------------------------------------------------



int main(){
  int N;vector<int> A; set<int>P; map<int,int> B;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  RPT(i,0,N){
    ll a; cin >> a;
    A.push_back(a);
  }
  sort(A.begin(),A.end());

  FOR(i,2,1000003){
    bool ynprime = true;
    for(auto x : P){
      if(i % x == 0){ ynprime = false; break; }
      if( x*x > i ) break;
    }
    if(ynprime) P.insert(i);
  }

  RPT(i,0,N){
    int ttl = A[i];
    set<int>::iterator it = P.find(A[i]);
    if(it!=P.end()){
      ttl = 1;
      if(B[A[i]]<1) B[A[i]] = 1;
    }
    for(auto &xx : P){
      auto x = xx;
      int cnt = 0;
      if(x > A[i] || ttl == 1) break;
      while(ttl % x == 0){
        ttl /= x;
        cnt++;
      }
      if(cnt){
        if(B[x]<cnt) B[x] = cnt;
      }
    }
    if(ttl != 1) {
      P.insert(A[i]);
      B[A[i]] = 1;
    }
  }

  ll L=1, Ainv = 0;
  for(auto x : P){
    if(B[x] != 0)L = ((L * (modpow(x,B[x],MOD))%MOD)) % MOD;
  }
  RPT(i,0,N){
    Ainv = (Ainv + ((modpow(A[i],MOD-2,MOD)%MOD)%MOD) ) % MOD;
  }
  ll ans = (Ainv * L) % MOD;
  //ll ans = (Ainv % MOD);
  cout << ans << endl; 
  //cout << L << endl << Ainv << endl;for(auto x: P) if(B[x]) cout << x << "^" << B[x] << " ";
  return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
struct UnionFind {
    VI d;
    UnionFind(int n = 0): d(n,-1) {}
    int find(int x) {
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x,int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x,int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};
int deg[100005];
VI to[100005];

int main() {
    int n,r;
    cin >> n >> r;
    if(n >= 10) {
        cout << r << endl;
    } else {
        int ans = 0;
        ans = r + 100 * (10 - n);
        cout << ans << endl;
    }

    
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mm 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>

#define show(x) cout<<#x<<" "<<x<<'\n'
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define oset tree<int , null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

int main()
{
    iosbase;
    
    int n;
    cin>>n;
    
    unordered_map<ll,ll > m;
    
    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        m[x]++;
    }
    
    if(m.size()>3)
    {
        //cout<<"here1"<<endl;
        cout<<"No";
        return 0;
    }
    if(m.size() == 1)
    {
        if(m[0]==n) {cout<<"Yes"; return 0;}
        cout<<"No";
        return 0;
    }
    if(m.size() == 3)
    {
        if(n%3)
        {
           // cout<<"here2"<<endl;
            cout<<"No";
            return 0;
        }
        ll a[3],i=0;
        for(auto itr=m.begin();itr != m.end();itr++)
        {
            a[i]= itr->ff;
            int cnt= itr->ss;
            if(cnt != n/3)
            {
                //cout<<"here3"<<endl;
                cout<<"No";
                return 0;
            }
            i++;
        }
        //show(a[0]);show(a[1]);show(a[2]);
        if((a[0]^a[1]) != a[2])
        {
            //cout<<"here4"<<endl;
            cout<<"No";
            return 0;
        }
        
        cout<<"Yes";
        return 0;
    }
    
    if(m.size() == 2)
    {
        if(n%3==0)
        {
            if(m[0]==(n/3))
            {
                cout<<"Yes";
                return 0;
            }
        }
        cout<<"No";
        return 0;
    }
    return 0;
}

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

int main() {
  int N,K,S;
  cin>>N>>K>>S;
  vector<int>ans(N);
  if(K==0){
    if(S!=1000000000){
      for(int i=0;i<N;i++) ans[i]=S+1;
    }
    else{
      for(int i=0;i<N;i++) ans[i]=S-1;
    }
  }
  else{
    if(S!=1000000000){
      for(int i=0;i<K;i++) ans[i]=S;
      for(int i=K;i<N;i++) ans[i]=S+1;
    }
    else{
      for(int i=0;i<K;i++) ans[i]=S;
      for(int i=K;i<N;i++) ans[i]=S-1;
    }
  }
  for(int i=0;i<N;i++) cout<<ans[i]<<endl;


      
}



Measured memory_bytes: 1664
#coding:utf-8

A, B = map(int,raw_input().split())
S = raw_input()

if S[A] != '-':
    print "No"

else:
    Flag = 0
    for i in range(A):
        if (S[i] < '0' or S[i] > '9'):
            Flag = 1
            #print "hello1"
    for i in range(A+1,len(S)):
        if (S[i] < '0' or S[i] > '9'):
            Flag = 1

    if Flag == 1:
        print "No"
    else:
        print "Yes"


Measured memory_bytes: 2568
n = int(input())

exponents = [0] * (n + 1)
for i in range(2, n + 1):
    x = i
    for j in range(2, i + 1):
        while x % j == 0:
            exponents[j] += 1
            x //= j

def f(x):
    return sum(exponent >= x - 1 for exponent in exponents)

ans = 0
ans += f(75)
ans += f(25) * (f(3) - 1)
ans += f(15) * (f(5) - 1)
ans += f(5) * (f(5) - 1) // 2 * (f(3) - 2)

print(ans)

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	string s, t;
	cin >> s >> t;

	rep(i,s.length()){
		if(s[i] != t[i]){
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3640
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
vi64 v(3);
forn(i,3)
cin>>v[i];
sort(all(v));
if(v[0]==v[1]&&v[1]==v[2])
cout<<"Yes";
else
cout<<"No";

    return 0;
  }


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

int x[200010],check[200010];
std::vector<int> V;
int main()
{
	int a;
	long long int b;
	scanf("%d%lld",&a,&b);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	if(b<=3*a)
	{
		int k = 1;
		for(int i=1;i<=b;i++) k = x[k];
		printf("%d",k);
		return 0;
		
	}
	
	V.push_back(1);
	int k = 1, p = 1;
	check[1] = 1;
	
	for(int i=2;;i++)
	{
		k = x[k];
		if(check[k])
		{
			p = i-check[k];
			break;
		}
		check[k] = i;
		V.push_back(k);
	}
	b %= p;
	while(b<2*a) b += p;
	
	k = 1;
	for(int i=1;i<=b;i++) k = x[k];
	printf("%d",k);
}

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

int main(){
  string S;
  cin >> S;
  
  int money = 700;
  
  for(int i = 0; i < 3; i++){
    if(S.at(i) == 'o'){
      money = money + 100;
    }
  }
  
  cout << money << endl;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

typedef pair<int, int> pii;

ll H, W, N;
map<pii, int> cnt;
int a[100001], b[100001];

struct pair_hash {
    inline std::size_t operator()(const std::pair<int,int> & v) const {
        return v.first*31+v.second;
    }
};
namespace std {
template <> struct hash<std::pair<int, int>> {
    inline size_t operator()(const std::pair<int, int> &v) const {
        std::hash<int> int_hasher;
        return int_hasher(v.first) ^ int_hasher(v.second);
    }
};

}
set<pii> pts;

int main() {

  ll ans[10] = {};

  cin >> H >> W >> N;
  rep(i, N) {
    scanf("%d%d", &a[i], &b[i]); a[i]--, b[i]--;
    pts.insert({a[i], b[i]});
  }

  rep(k, N) {
    REP(basei, a[k]-2, a[k]+1) {
      REP(basej, b[k]-2, b[k]+1) {
        if(basei < 0 || basej < 0 || basei + 2 >= H || basej + 2 >= W)  continue;
        int num = 0;
        rep(i, 3) rep(j, 3) {
          num += pts.count({basei + i, basej + j});
        }
        cnt[{basei, basej}] = num;
      }
    }
  }

  for(auto e: cnt) {
    ans[e.second]++;
  }

  ans[0] = ll(H - 2) * (W - 2);
  REP(i, 1, 10) {
    ans[0] -= ans[i];
  }

  rep(i, 10) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 61952
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cstdlib>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	string s;
	while(cin >> s)
	{
		if(s == "0000") break;
		
		bool flag = true;
		rep(i,s.size()) if(s[0] != s[i]) flag = false;

		if(flag)
		{
			cout << "NA" << endl;
		}
		else
		{
			int cnt = 0;
			while(true)
			{
				if(s == "6174")
				{
					cout << cnt << endl;
					break;
				}
			
				string temp = s,temp2 = s;
				sort(temp.begin(),temp.end());
				sort(temp2.begin(),temp2.end(),greater<char>());

				int t = atoi(temp.c_str());
				int t2 = atoi(temp2.c_str());

				stringstream ss;
				ss << t2 - t;

				s = "";
				REP(i,ss.str().size(),4) s += "0";

				s += ss.str();
				cnt++;
			}
		}

	}
}

Measured memory_bytes: 1240
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;

    string ans;
    rep(i, N) {
        ans += S.at(i);
        ans += T.at(i);
    }

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


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x,sum=0,a[105];
int main(){
    int i; cin>>n>>x;
    for(i=1;i<=n;i++) cin>>a[i],sum+=a[i];
    if(sum==x) printf("%d\n",n);
    else if(sum<x) printf("%d\n",n-1);
    else {
        sort(a+1,a+1+n); sum=0;
        for(i=1;i<=n;i++)
        if(sum+a[i]>x){
            printf("%d\n",i-1);
            break ;
        } else sum+=a[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;


int main(){
   IOS;
 //    #ifndef ONLINE_JUDGE
 //        freopen("in.txt",  "r",  stdin);
 //        freopen("out.txt", "w", stdout);
 //    #endif
   

   long int n;
   cin>>n;

   string a,b,c;
   cin>>a>>b;

   for(long int i =0 ;i < n; i++){
    c.push_back(a[i]);
    c.push_back(b[i]);
   }

   cout<<c;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>

using namespace std;
const long long P = 1000000007;
const double PI=3.14159265358979323846;

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

  for(int i = 1; i < n; i++) {
    cin >> a[i];
    upper[a[i]] += 1;
  }
  for(int i = 1; i <= n; i++) {
    cout << upper[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 5200
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 50;

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

    cin >> A >> B;

    K = A + B;
    if(K % 2)cout << "IMPOSSIBLE" << endl;
    else cout << K / 2 << endl;

    return 0;
}


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

using namespace std;

int A(int N, int R) {
	if (N >= 10)
		return R;
	else
		return R + 100 * (10 - N);
}

int main() {
	int N, R;
	cin >> N >> R;
	cout << A(N, R);	
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k; cin >> n >>k;
    vi h(n);rep(i,n) cin >>  h[i];
    sort(all(h));
    int ans = INF;
    rep(i,n-k+1) {
        chmin(ans, h[i+k-1]-h[i]);
    }
    ct(ans);
}


Measured memory_bytes: 640
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
	S := getStdin()
	var ch byte
	for i := 0; i < len(S); i++ {
		if ch == S[i] {
			fmt.Printf("Bad\n")
			return
		}
		ch = S[i]
	}
	fmt.Printf("Good\n")
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 896
import itertools
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
l=list(itertools.permutations(range(1,n+1)))
x=0
y=0
for i in range(len(l)):
    if p==l[i]:
        x=i
    if q==l[i]:
        y=i
print(abs(x-y))

Measured memory_bytes: 8052
#include <iostream>
using namespace std;
#define max(a, b) (a>b?a:b)
typedef long long LL;
LL n, m;
int main() {
    cin >> n >> m;
    if (n < m) swap(n, m);
    if (n == 1 && m == 1) {
        return !printf("1\n");
    }
    if (m >= 3) {
        return !printf("%lld\n", (n-2)*(m-2));
    }
    if (m == 2) {
        return !printf("%d\n", 0);
    }
    if (m == 1) {
        return !printf("%lld\n", max(n-2,0));
    }
}

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

int jos(int n, int k){
	int i;
	for( i = k-1 ; i<(k-1)*n ; i = (k*i)/(k-1)+1 );
	return (k*n-i);
}

int main(){
	int n,k;
	while( cin >> n >> k , n || k ){
		cout << jos(n,k) << endl;
	}
}

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

class team{
public:
	int w,l;
	char name;
	team(){
		w = l = 0;
	}
	void clear(){
		w = l = 0;
	}
}T[10];

void sort(int *a, int n){
	for(int i=1; i<n; i++){
		if(T[a[i-1]].w < T[a[i]].w || (T[a[i-1]].w == T[a[i]].w && T[a[i-1]].l > T[a[i]].l)){
			int tmp = a[i];
			a[i] = a[i-1];
			a[i-1] = tmp;
			i=0;
		}
	}
}

int main(){
	int n,tmp;
	char ntmp;
	int ans[10];
	while(true){
		cin >> n;
		if(n==0)
			break;
		for(int i=0; i<n; i++){
			ans[i] = i;
			cin >> ntmp;
			T[i].name = ntmp;
			for(int j=0; j<n-1; j++){
				cin >> tmp;
				if(tmp == 0)
					T[i].w++;
				else if(tmp == 1)
					T[i].l++;
			}
		}
		sort(ans, n);
		for(int i=0; i<n; i++){
			cout << T[ans[i]].name << endl;
			T[i].clear();
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int X, Y;
	cin >> X >> Y;
	
	for(int i = 0; i < 100; i++){
		for(int j = 0; j < 100; j++){
			if(i+j == X && i*2+j*4 == Y){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int n, m;

struct edge{
	int to;
	int cost;
};

vector<vector<edge>> graph(100100);
int val[100100];
bool visited[100100];

bool dfs( int prev, int target, int k ){
	// cout << "prev: " << prev << ", target: " << target << ", k: " << k << endl;
	if( prev == -1 && visited[target] ) return true;
	if( prev != -1 && visited[prev] && visited[target] ){
		// cout << "valprev: " << val[prev] << ", valtarget: " << val[target] << ", k: " << k << endl;
		if( val[target]-val[prev] == k ){
			return true;
		} else {
			return false;
		}
	}
	val[target] = val[prev]+k;
	visited[target] = true;
	for( auto t : graph[target] ){
		if( !dfs( target, t.to, t.cost ) ){
			return false;
		}
	}
	return true;
}


int main(){
	cin >> n >> m;
	for( int i = 0; i < m; ++i ){
		int x, y, d; cin >> x >> y >> d;
		--x; --y;
		edge temp;
		temp.to = y;
		temp.cost = d;
		graph[x].push_back(temp);
		temp.to = x;
		temp.cost = -d;
		graph[y].push_back(temp);
	}
	for( int i = 0; i < n; ++i ){
		// cout << "when i = " << i << endl;
		if( !dfs( -1, i, 0 ) ){	
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 11136
let () =
    let xy = Array.map int_of_string (Array.of_list (Str.split (Str.regexp " ") (read_line ()))) in
    let x = Array.get xy 0 in
    let y = Array.get xy 1 in
    Printf.printf "%d %d\n" (x * y) ((x + y) * 2)
    

Measured memory_bytes: 2272
#include<iostream>
#include<vector>
#include<algorithm>
#define MAX_V 100
#define INF 1e9
using namespace std;
int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;
void dijkstra(int s) {
	for (int i = 0; i < MAX_V; i++) {
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;
	while (true) {
		int v = -1;
		for (int u = 0; u < V; u++) {
			if (!used[u] && ((v == -1) || d[u] < d[v])) {
				v = u;
			}
		}
		//全ての頂点が到達済み
		if (v == -1) {
			break;
		}
		//集合に新たに頂点を追加
		used[v] = true;
		for (int u = 0; u < V; u++) {
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}
}

int main() {
	for (int i = 0; i < MAX_V; i++) {
		for (int j = 0; j < MAX_V; j++) {
			cost[i][j] = INF;
		}
	}
	cin >> V;
	for (int i = 0; i < V; i++) {
		int u;
		cin >> u;
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int v;
			cin >> v;
			int c;
			cin >> c;
			cost[u][v] = c;
		}
	}
	dijkstra(0);

	for (int i = 0; i < V; i++) {
		cout << i << " " << d[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3132
N = int(input())
Q = []

for i in range(N):
    Q.append(tuple(map(int, input().split())))

Q = sorted(Q, key=lambda x: x[1])
now = 0
for i in range(N):
    if now + Q[i][0] <= Q[i][1]:
        now += Q[i][0]
    else:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 33484
n=int(input())
a=list(map(int,input().split()))


b=[0]*(n-1)

for i in range(n-1):
    if a[i]>=a[i+1]:
        b[i]=1
    
from itertools import groupby

gr = groupby(b)

ans=0
for k,v in gr:
    if k==1:
        ans =max(ans,len(list(v)))

print(ans)

Measured memory_bytes: 20432
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };
int main(){
    int H,W;
    cin>>H>>W;
    string s[H];
    rep(i,H) cin>>s[i];
    queue<pair<int,int>> q;
    vector<vector<int>> dist(H,vector<int>(W,-1));
    dist.at(0).at(0)=0;
    q.push(mp(0,0));
    int cnt=0;
    rep(i,H){
        rep(j,W){
            if(i==0&&j==0) continue;
            if(s[i][j]=='.') cnt++;
        }
    }
    while(!q.empty()){
        pair<int,int> now=q.front();
        q.pop();
        rep(i,4){
            int ny=now.F+dy[i],nx=now.S+dx[i];
            if(ny<0 || nx<0 || ny>=H || nx>=W) continue;
            if(dist.at(ny).at(nx)>=0) continue;
            if(s[ny][nx]=='#') continue;

            dist.at(ny).at(nx)=dist.at(now.F).at(now.S)+1;
            q.push(mp(ny,nx));
        }
    }
    if(dist.at(H-1).at(W-1)==-1) cout<<dist.at(H-1).at(W-1)<<endl;
    else cout<<cnt-dist.at(H-1).at(W-1)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long
#define N 10000007
#define dd double

int main()
{
	ll n,m,l[100005],r[100005];
	cin>>n>>m;
	
	for(ll i=0;i<m;i++)
		cin>>l[i]>>r[i];
	ll max=l[0];
	ll min=r[0];
	for(ll i=0;i<m;i++){
		if(l[i]>max)
			max=l[i];
		if(r[i]<min)
			min=r[i];
	}
	
	ll ans=min-max+1;
	if(ans>=0){
		if(ans<n)
			cout<<ans<<endl;
		else
			cout<<n<<endl;
	}
	else
		cout<<0<<endl;

	return 0;
}

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


int main(){
    int N;
    cin >> N;
    vector<long long> a(N);
    double cnt=0;
    for (int i=0; i<N; ++i) {
        cin >> a[i];
        if (a[i]%4==0) cnt++;
        else if (a[i]%2==0) cnt+=0.5;
    }
    if (N/2<=cnt) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a, b, c, k;
	int ans = 0;
	cin >> a >> b >> c >> k;
	if (a >= k)
		ans = k;
	else {
		ans = a;
		k-=a;
		if (k != 0) {
			if (b < k) {
				k -= b;
				ans -= k;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}


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

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int32_t main()
{
    set<int> se({1, 2, 3});
    for(int i=1; i<=2; i++){
        int k=in();
        se.erase(k);
    }
    cout<<(*se.begin())<<nl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

int main() {
	long long int a, b;
	int k;
	cin >> a >> b >> k;
	rep2(i, a, b) {
		if (i < a + k) {
			cout << i << endl;
		}
		else if (i > b - k) {
			cout << i << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
// #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int INF = 2147483647;
bool is_integer( double x ){
  return std::floor(x)==x;
}
int main(){
  string s;
  cin >> s;
  if (s == "AAA"){
    cout << "No";
    return 0;
  }
  else if(s == "BBB"){
    cout << "No";
    return 0;
  }
  else{
    cout << "Yes";
    return 0;
  }
}
 




Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int i,min_i=0,sum=0,a[6]={0};

    for(i=0;i<6;i++){
        scanf("%d",&a[i]);
    }
    for(i=1;i<4;i++){
        if(a[i] < a[min_i]){
            min_i = i;
        }
    }
    for(i=0;i<4;i++){
        if(i != min_i){
            sum += a[i];
        }
    }
    if(a[i] > a[i+1]){
        sum += a[i];
    }else{
        sum += a[i+1];
    }

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

    return 0;
}

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

typedef long long ll;

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

    int n;
    string s;
    cin >> n >> s;

    ll r = 0, g = 0, b = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') r++;
        else if (s[i] == 'G') g++;
        else if (s[i] == 'B') b++;
    }

    ll sum = r * g * b;
    ll ex = 0;
    for (int i = 0; i < n; i++) {
        for (int m = 1; i + 2 * m < n; m++) {
            if (s[i] != s[i+m] && s[i] != s[i+2*m] && s[i+m] != s[i+2*m]) ex++;
        }
    }

    cout << sum - ex << endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
const int MAX = 100000;
int dp[200];

int dfs(int index, vector<pair<int, int> > &mato){
	if(dp[index]) return dp[index];
	if(!index) return 1;
	int maxc = 0;
	for(int i = index-1; i >= 0; i--){
		if((mato[index].first<=mato[i].first)||(mato[index].second<=mato[i].second)) continue;
		maxc = max(maxc, dfs(i, mato));
	}
	dp[index] = maxc+1;
	return dp[index];
}

void substitute(int time, vector<pair<int, int> > &mato){
	for(int i = 0; i < time; i++){
		pair<int, int> tmp;
		cin >> tmp.first >> tmp.second;
		mato.push_back(tmp);
	}
}

int main(){
	int n, m;
	while(cin >> n && n != 0){
		fill(dp, dp+200, 0);
		vector<pair<int, int> > mato;
		substitute(n, mato);
		cin >> m;
		substitute(m, mato);
		sort(mato.begin(), mato.end());
		int maxc = 0;
		for(int i = n+m-1; i >= 0; i--) maxc = max(maxc, dfs(i, mato));
		cout << maxc << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
N = int(input())
A = [[] for i in range(N)]
for i in range(N):
	for j in range(int(input())):
		A[i].append(list(map(int,input().split())))

flag = True
ans = []
for i in range(2 ** N):
	l = list(format(i, 'b').zfill(N))
	k = [int(s) for s in l]
	for j in range(N):
		if k[j] == 1:
			for l in range(len(A[j])):
				if A[j][l][1] != k[A[j][l][0] - 1]:
					flag = False
					break
	if flag == True:
		ans.append(k.count(1))
	else:
		flag = True

print(max(ans))

Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

#define ll long long

using namespace std;

const int N = 200010;
const int mod = 1e9 + 7;

inline int read() {
	int jg = 0, jk = getchar() - '0', f = 1;
	while(jk < 0 || jk > 9) {
	    if(jk == '-' - '0')  f = -1;
		jk = getchar() - '0';
	}
	while(jk >= 0 && jk <= 9)
		jg *= 10, jg += jk, jk = getchar() - '0';
	return jg * f;
}

int n, c, la[N], f[N], sum[N];
 
int main() {
	//freopen("a.txt", "r", stdin);
    n = read();
	f[0] = sum[0] = 1;
	for(int i = 1, j; i <= n; ++i) {
		j = read();
		if(!la[j]) {
			f[i] = 0;
			sum[i] = sum[i - 1] + f[i];
			la[j] = i;
			continue;
		}
		if(la[j] == i - 1) {
			la[j] = i;
			sum[i] = sum[i - 1];
			continue;
		}
		f[i] = sum[la[j]];
		if(f[i] >= mod)  f[i] -= mod;
		sum[i] = sum[i - 1] + f[i];
		if(sum[i] >= mod) sum[i] -= mod;
		la[j] = i;
		//cout<<i<<" "<<f[i]<<" "<<sum[i]<<endl;
	}
	printf("%d\n", sum[n]);
    return 0;
}

Measured memory_bytes: 6004
def line_sym(p, x1, x2):
    p -= x1
    d = x2 -x1
    return d * p.conjugate() / d.conjugate() + x1
 
import sys
 
p = []
for line in sys.stdin:
    x1, y1, x2, y2, xq, yq = map(float, line.split(','))
    p1 = complex(x1, y1)
    p2 = complex(x2, y2)
    q = complex(xq, yq)
     
    r = line_sym(q, p1, p2)
     
    print(r.real, r.imag)

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

string max(const string& a, const string& b) {
	if (a.size() > b.size()) return a;
	if (a.size() < b.size()) return b;
	if (a > b) return a;
	return b;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	for (int& i : A) cin >> i;
	vector<string> dp(N + 1);
	vector<int> tmp{ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
	for (int i = 1; i <= N; ++i) {
		for (int& j : A) {
			if (tmp[j] <= i) {
				if (!dp[i - tmp[j]].empty() || tmp[j] == i) dp[i] = max(dp[i - tmp[j]] + to_string(j), dp[i]);
			}
		}
	}
	cout << dp[N];
}

Measured memory_bytes: 31872
# coding: utf-8
N,D,A=map(int,input().split())
XH=[]
for i in range(N):
    XH.append(list(map(int,input().split())))

XH.sort()

bombs=[]
damage=0
ans=0

for i in range(N):
    if bombs:
        while bombs[0][1]<XH[i][0]:
            b=bombs.pop(0)
            damage-=b[0]
            if not(bombs):
                break
    
    hp=XH[i][1]-damage
    num_b=-(-hp//A)
    num_b=max(num_b,0)
    bom_d=A*num_b
    bom_l=XH[i][0]+2*D
    if num_b>0:
        bombs.append([bom_d,bom_l])
        damage+=bom_d
    ans+=num_b

print(ans)




Measured memory_bytes: 66188
#include <bits/stdc++.h>
using namespace std;
int main() {
    map<char, string> mp;
    mp['2'] = mp['4'] = mp['5'] = mp['7'] = mp['9'] = "hon";
    mp['0'] = mp['1'] = mp['6'] = mp['8'] = "pon";
    mp['3'] = "bon";
    string s; cin >> s;
    cout << mp[s.back()];
}

Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <string.h>
#include <queue>

using namespace std;

using ll = long long;
const int NNODES = 1e5 + 6;
vector<int> v[NNODES];
int fatherOf[NNODES];

ll down[NNODES];
ll up[NNODES];
ll prefix[NNODES], suffix[NNODES];

ll dfsDown(int root, int m) {
    vector<int> l;
    ll temp = 1;
    for(int node: v[root]) {
        if (fatherOf[root] == node) {
            continue;
        }
        fatherOf[node] = root;
        temp = ((temp % m) * (1 + (dfsDown(node, m)%m)) % m ) % m;

        // calculate prefix, suffix
        l.push_back(node);
    }

    ll t = 1;
    for (int i = 0; i < l.size(); i++) {
        // pair<int, int> a(root, l[i]);
        prefix[l[i]] = t;
        t = ((t%m) * ((1 + (down[l[i]]%m))%m)) % m;
        // printf("sss %d, %d, %lld\n", root, l[i], prefix[{root, l[i]}]);
    }
    t = 1;
    for (int i = l.size()-1; i >= 0; i--) {
        // pair<int, int> a(root, l[i]);
        suffix[l[i]] = t;
        t = ((t%m) * ((1 + (down[l[i]]%m))%m)) % m;
    }
    down[root] = temp%m;
    return down[root];
}

ll dfsUp(int root, int m) {
    if (up[root] > 1) {
        return up[root];
    } 
    if (fatherOf[root] == -1) {
        up[root] = 1;
        return up[root];
    }
    ll upV = dfsUp(fatherOf[root], m);
    ll kk = ((prefix[root]%m) * (suffix[root]%m)) % m;
    up[root] = (((kk * (upV%m)) % m) + 1) %m;
    return up[root];
}

void solve(int n, int m) {
    int root = 1;
    fatherOf[root] = -1;
    dfsDown(root, m);
    for (int i = 1; i <= n; i++) {
        dfsUp(i, m);
    }
    queue<int> q;
    q.push(root);
    while (q.size() > 0) {
        int it = q.front();
        q.pop();
        dfsUp(it, m);
        for (int node: v[it]) {
            if (node == fatherOf[it]) {
                continue;
            }
            q.push(node);
        }
    }
}

int main() {
    memset(down, -1, sizeof(down));
    memset(up, -1, sizeof(up));
    memset(prefix, 1, sizeof(prefix));
    memset(suffix, 1, sizeof(suffix));
    int n,m;
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    solve(n, m);
    for (int i = 1; i <= n; i++) {
        // printf("father of %d %d\n", i, fatherOf[i]);
        // printf("down %d %d\n", i, down[i]);
        // printf("up %d %d\n", i, up[i]);
        printf("%lld\n", (down[i] * up[i])%m);
    }
	return 0;
}

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

int gcd(int a, int b) {
  return !b ? a : gcd(b, a % b);
}

int gcd(int a, int b, int c) {
  return gcd(gcd(a, b), c);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> k;
  int ans = 0;
  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= k; ++j) {
      for (int q = 1; q <= k; ++q) {
        ans += gcd(i, j, q);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}



Measured memory_bytes: 3576
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int MAX = 30;
	double EPS = 1e-5;
	int n, m;
	int s, g;
	int map[][];
	int lim[][];
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			n = sc.nextInt();
			m = sc.nextInt();
			if( (n|m) == 0 ) break;
			s = sc.nextInt()-1;
			g = sc.nextInt()-1;
			map = new int[n][n];
			lim = new int[n][n];
			for(int i=0;i<m;i++) {
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				int d = sc.nextInt();
				int l = sc.nextInt();
				map[a][b] = map[b][a] = d;
				lim[a][b] = lim[b][a] = l;
			}
			System.out.println(dijkstra());
		}
	}
	int dv[] = {-1,0,1};
	String dijkstra() {
		double t[][][] = new double[n][n+1][MAX+1];
		for(double[][] a:t ) for(double[] b:  a) fill(b, INF);
		t[s][n][0] = 0;
		PriorityQueue<Pair> que = new PriorityQueue<Pair>(1, new MyComp());
		Pair now = new Pair(s, -1, 1, 0, 0);
		que.add(now);
		for(;!que.isEmpty();) {
			now = que.remove();
//			debug(que);
//			debug(now.p, now.past_p, now.v, now.t);
			if( now.p == g && now.past_v == 1 ) return String.valueOf(now.t);
			if( 0 == now.v ) continue;
			for(int i=0;i<n;i++) {
				if( map[now.p][i] == 0 || now.p == i || now.past_p == i) continue;
				if( now.v > lim[now.p][i] ) continue;
				double time = now.t + (double)map[now.p][i] / now.v;
//				debug(now.p, i, map[now.p][i]*1.0/now.v);
				if(time < t[i][now.p][now.v]) {
					for(int j=0;j<3;j++) {
						if( now.v + dv[j] >= 0 ) {					
							que.add(new Pair(i, now.p, now.v+dv[j], now.v, time));
//							debug(i, now.p, now.v+dv[j], time);
						}
					}
					t[i][now.p][now.v] = time;
				}
			}
		}
		return "unreachable";
	}
	
	class Pair {
		int p, v, past_p, past_v;
		double t;
		Pair(int p, int past_p, int v, int past_v, double t) {
			this.p = p;
			this.v = v;
			this.t = t;
			this.past_p = past_p;
			this.past_v = past_v;
		}
	}
	
	class MyComp implements Comparator<Pair> {

		@Override
		public int compare(Pair o1, Pair o2) {
			// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
			if(o1.t > o2.t ) return 1;
			else if(o1.t < o2.t) return -1;
			return o1.v - o2.v;
		}
		
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 16000
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    //final List<Integer> list = new ArrayList<>();
    //final List<Integer> list2 = new ArrayList<>();
    //final List<Long> list3 = new ArrayList<>();

    String s = sc.next();
    int count = 0;
    
    for(int i = 0; i < s.length() ; i++){
        if(s.charAt(i) == 'o'){
            count++;
        }
    }

    System.out.println(700 + count*100);
    

    




    







}
}

Measured memory_bytes: 35576
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("Yes\n")
#define no printf("No\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using ull=unsigned long long;
using vi=vector<int>;
using pint=pair<int,int>;

const int INF=1LL<<55;

int a,b;
int mx = -100000000;

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

    cin>>a>>b;
    mx = max(a+b, mx);
    mx = max(a-b, mx);
    mx = max(a*b,mx);
    cout<<mx<<endl;



    return 0;
}


Measured memory_bytes: 888
/*
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

bool as[MAX_N];
int cnts[MAX_N + 1];

/* subroutines */

/* main */

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

  for (int i = 0; i < m; i++) {
    int ai, li;
    cin >> ai >> li;
    for (int j = 0; j < li; j++) as[(ai + j) % n] = true;
  }
  //for (int i = 0; i < n; i++) printf(" %d", as[i]); putchar('\n');

  int cnt = 0, k = n;
  while (k > 0 && as[k - 1]) cnt++, k--;

  for (int i = 0; i < k; i++) {
    if (as[i]) cnt++;
    else {
      if (cnt > 0) cnts[cnt]++;
      cnt = 0;
    }
  }
  if (cnt > 0) cnts[cnt]++;

  for (int i = n; i > 0; i--)
    if (cnts[i] > 0) printf("%d %d\n", i, cnts[i]);
  return 0;
}


Measured memory_bytes: 1148
n = int(input())
a = list(map(int, input().split()))
x = sum(a)
b = list(map(int, input().split()))
for i in range(n):
    if (a[i] >= b[i]):
        a[i] -= b[i]
    else:        
        a[i+1]= max(a[i+1]+a[i]-b[i],0)
        a[i]=0
y = sum(a)
print(x-y)

Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  bool t=true;
  if(n!=0){
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if((double)n/i==j){
        t=false;
        cout << "Yes" << endl;
        break;
      }
    }
    if(t==false)break;
  }
  if(t)cout << "No" << endl;
  }else cout << "No" << endl;
}


Measured memory_bytes: 3620
n=int(input())
a=list(map(int,input().split()))

if n%2==0:
    S=a[-1::-2]+a[::2]
    for x in S:
        print(x,end=' ')
else:
    S=a[-1::-2]+a[1::2]
    for x in S:
        print(x,end=' ')
print()


Measured memory_bytes: 30856
integer(8) TA,AO
integer N
integer(8) T,A,nn
read*,N
TA=1;AO=1
do i=1,N
  read*,T,A
  nn=max((TA-1)/T+1,(AO-1)/A+1)
  TA=nn*T
  AO=nn*A
end do
print"(I0)",TA+AO
end

Measured memory_bytes: 256
import collections

n = int(input())
d = list(map(int,input().split()))
mod = 998244353

ans = 0
c = collections.Counter(d)
if c[0] == 1 and d[0] == 0:
    ans = 1
for i in range(1,max(d)+1):
    if c[i] == 0:
        ans = 0
        break
    ans *= pow(c[i-1],c[i],mod)
    ans %= mod
print(ans%mod)

Measured memory_bytes: 24460