akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    
    ll tmp=0;
    rep(i,N){
        tmp^=A[i];
    }
    rep(i,N) cout<<(tmp^A[i])<<" ";
}



Measured memory_bytes: 4792
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 1010
inline ll read()
{
    ll x=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    return x*f;
}
inline void write(ll x)
{
    static int buf[20],len; len=0;
    if(x<0)x=-x,putchar('-');
    for(;x;x/=10)buf[len++]=x%10;
    if(!len)putchar('0');
    else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
char mp[maxn][maxn];
int f[maxn][maxn];
int n,m;
int main()
{
    n=read(); m=read();
    for(int i=1;i<=n;i++)
        scanf("%s",mp[i]+1);
    memset(f,0x3f,sizeof(f));
    f[1][1]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            f[i+1][j]=std::min(f[i+1][j],f[i][j]+(mp[i][j]!=mp[i+1][j]));
            f[i][j+1]=std::min(f[i][j+1],f[i][j]+(mp[i][j]!=mp[i][j+1]));
        }
    if(mp[n][m]=='.')writeln(f[n][m]/2);
    else writeln((f[n][m]+1)/2);
	return 0;
}

Measured memory_bytes: 4224
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>

using namespace std;
 
#define memset_clear(_) memset(_,0,sizeof(_))
#define memset_clear_tre(_) memset(_,1,sizeof(_))
#define memset_clear_reg(_) memset(_,-1,sizeof(_))
#define memset_clear_max(_) memset(_,0x3f,sizeof(_))
#define memset_clear_min(_) memset(_,0x80,sizeof(_))
#define sqr(_) ((_)*(_))
 
#define int long long
 
const int maxn=100005;
int n,m;
int a[maxn];
 
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
 
signed main(){
	n=read();m=read();
	for (int i=1;i<=n;i++) a[i]=read();
	if (a[n]<0){
		for (int i=1;i<=n/2;i++) a[i]=-a[i],a[n-i+1]=-a[n-i+1],swap(a[i],a[n-i+1]);
	}
	int ans=(long long)1<<60;
	int x=0;
	if (x<a[1]) x=1; else
	if (x>a[n]) x=n; else
	for (int i=1;i<n;i++)
		if (a[i]<x && x<=a[i+1]) {x=i+1;break;}
	for (int i=x;i<=min(n,x+m-1);i++) if (i-m+1>0){
		if (a[i-m+1]<0){
			ans=min(ans,a[i]*2-a[i-m+1]);
			ans=min(ans,a[i]-a[i-m+1]*2);
		} else if (i>=m) ans=min(ans,a[i]);
	}
	if (ans==((int)1<<60)) printf("0\n"); else printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    int a, b, c, d;
    cin >> a;
    cin >> b;
    cin >> c;
    if (a-b>0)
    {
        d = a;
        a = b;
        b = d;
    }    
    if (b-c>0)
    {
        d = b;
        b = c;
        c = d;
    }
    if (a-b>0)
    {
        d = a;
        a = b;
        b = d;
    }
    if (b-c>0)
    {
        d = b;
        b = c;
        c = d;
    }
    cout << a << " " << b << " " << c << endl;
	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll x,a[105];
int main(){
	cin>>n>>x;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	ll sum = 0;
	for(int i=1;i<=n;i++){
		sum += a[i];
		if(sum > x){
			cout<<i-1<<endl;
			return 0;
		}
	}
	if(sum != x){
	    cout<<n-1<<endl;
	}
	else cout<<n<<endl;
}

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

int main() {
  string S,T;
  cin >> S >> T;
  int Transmin = T.size(),Ssize = S.size(),Tsize = T.size();
  for (int i = 0;i <  Ssize - Tsize + 1;i++) {
    int Trans = Tsize;
    for (int j = 0;j < Tsize;j++) {
      if (T.at(j) == S.at(i+j))
        Trans--;
    }
    Transmin = min (Trans,Transmin);
  }
  cout << Transmin << endl;
  
}

Measured memory_bytes: 3624
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))

for b1 in range(101):
    for b2 in range(101):
        for b3 in range(101):
            if c1[0] - b1 == c1[1] - b2 == c1[2] - b3:
                if c2[0] - b1 == c2[1] - b2 == c2[2] - b3:
                    if c3[0] - b1 == c3[1] - b2 == c3[2] - b3:
                        print("Yes")
                        exit()
else:
    print("No")

Measured memory_bytes: 40812
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
typedef unsigned long long ll;
int main(){
  ll inf=1;
  inf = inf << 32;
  ll n;
  cin >> n;
  ll i,j,k;
  for(i=0;i<n;i++){
    string strs[9];
    ll is[9];
    for(j=0;j<9;j++){
      cin >> hex >> is[j];
    }
    ll o=0;
    for(j=0;j<32;j++){
      ll c=0;
      for(k=0;k<8;k++) {
	c+=is[k]^o;
	c%=inf;
      }
      if(((is[8]>>j)&1)^((c>>j)&1)) {
	o+=1<<j;
	o%=inf;
      }
    }
    o%=inf;
    cout <<hex << o << endl;
  }
  return 0;
}

Measured memory_bytes: 1148
{-
 - `chebyshev n' returns the number of primes between n+1 and 2n.
 - e.g.:
 -   chebyshev 10 == 4    -- 11, 13, 17, 19
 -   chebyshev 13 == 3    -- 17, 19, 23
 -}

import Control.Monad  -- when

chebyshev :: Int -> Int
chebyshev n = length [x | x<-[n + 1 .. 2 * n], prime x]
 
prime :: Int -> Bool
prime n | n >= 2 = [x | x<-fs, n`mod`x == 0] == []
  where fs = takeWhile (\x->x*x <= n) ([2] ++ [3,5..])
                         -- x*x is faster than x^2

main :: IO ()
main = do n <- readLn
          when (n /= 0) $ do
            print (chebyshev n)
            main

Measured memory_bytes: 4168
n=int(input())
for i in range(n):
    x1,y1,r1,x2,y2,r2=map(float,input().split())
    d=((x1-x2)**2+(y1-y2)**2)**0.5
    r_min=min(r1,r2)
    r_max=max(r1,r2)
    if r_max>r_min+d:
        if r1>r2:
            print(2)
        else:
            print(-2)
    elif d<=r1+r2:
        print(1)
    else:
        print(0)


Measured memory_bytes: 5644
#include <iostream>

int main(void){
    int a, b, quo, rem, ans;
    std::cin >> a >> b;
    quo = (b-1) / (a-1);
    rem = (b-1) % (a-1);

    ans = quo;
    if (rem != 0) ++ans;

    std::cout << ans << std::endl; 

    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <string.h>

using namespace std;
int a,b,c,d,k,i,m=1234567,o[300010],l[600010],e[600010];
long long x,y,z;
//char c[110][110];
string r;
stack<int> s;
queue<int> qx,qy;
vector<int> v[110];

long long f(int t)
{
    int n=0,m=0;
    if(o[t]==a)
        n=a+1;
    else
    for(int w=o[t]+1;w<=a;)
    {
        if(w%i==1&&e[(w-1)/i]==0)
        {
            w+=i;
        }
        else
        {
            if(l[w])
            {
                //printf("#%d",o[t]);
                n=w;
                break;
            }
            else
            w++;
        }
        if(w>a)
            n=a+1;
    }
    for(int w=o[t]-1;w>=0;)
    {
        if(w%i==0&&e[(w-1)/i]==0)
        {
            w-=i;
        }
        else
        {
            if(l[w])
            {
                m=w;
                break;
            }
            else
            w--;
        }
        if(w<=0)
            m=0;
    }
   // printf("%d %d",m,n);
    return (long long)(n-o[t])*(o[t]-m)*t;
}

int main()
{
     scanf("%d",&a);
     for(;i*i<a;i++);
     for(int t=1;t<=a;t++)
     {
        scanf("%d",&b);
        o[b]=t;
     }
     for(int t=1;t<=a;t++)
     {
         x+=f(t);
     //    printf(" %lld\n",x);
         l[o[t]]++;
         e[(o[t]-1)/i]++;
     }
     printf("%lld",x);
     return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//二次元配列の生成
		String[][] C = new String[2][3];
		for(int i = 0; i <= 1; i++) {
			String s = sc.next();
			for(int j = 0; j <= 2; j++) {
				C[i][j] = s.substring(j, j + 1);
			}
		}
		sc.close();
		if(C[0][0].equals(C[1][2]) && C[0][1].equals(C[1][1]) && C[0][2].equals(C[1][0])) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  int k, t;
  cin >> k >> t;
  V a(t);
  for (int i = 0; i < t; i++) cin >> a[i];
  sort(a.begin(), a.end());
  dump(max(a[t-1]-1-(k-a[t-1]), 0));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  ll a,b,x;
  cin >> a >> b >> x;
  ll l =(a-1)/x+1;
  if(a==0){
    l=0;
  }
  ll r = b/x+1;
  cout << r-l << endl;
}


Measured memory_bytes: 256
int main(void){
 
 
    int n, i;
    scanf("%d", &n);
     
    for(i = 1; i <= n; i++){
        if(i % 3 == 0){
            printf(" %d", i);
        }
        else if((i / 10) % 10 == 3 || (i / 100) % 10 == 3 || (i / 1000) % 10 == 3)
            printf(" %d", i);
        else if(i % 10 == 3){
            printf(" %d", i);
        }
    }
    printf("\n");
 
    return 0;
 
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;


void solve(){
    int n, m, f = 1;
    cin>>n>>m;
    int a[n];
    f(i,n)a[i] = -1;
    while(m--){
        int s, c;
        cin>>s>>c;
        s--;
        if(a[s] == -1)a[s] = c;
        else if(a[s] != c){cout<<"-1";return ;}
    }
    if(n == 1)cout<<max(0ll,a[0]);
    else{
        if(a[0] == 0){cout<<"-1";return ;}
        cout<<max(a[0],1ll);
        for(int i = 1; i < n; i++)cout<<max(a[i],0ll);
    }
    
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
x = 0
break_loop = False
while True:
    for i in range(n):
        if a[i]%2 != 0:
            print(x)
            break_loop = True
            break    
        else:
            a[i] = a[i]/2
    x += 1
    if break_loop:
        break

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 50;
int n;
ll f[MAXN];

void fib(int n){
    if(n == 0||n == 1){
        return;
    }
    int i;
    for(i = 2; i <= n; i++){
        f[i] = f[i-1] + f[i-2];
    }
}
int main(){
    scanf("%d", &n);
    f[0] = 1; f[1] = 1;
    fib(n);
    printf("%lld\n", f[n]);
    return 0;
}



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

int main() {
  int A,B,C,D,E;
  cin >> A;
  B=A/1000;
  C=A%1000/100;
  D=A%100/10;
  E=A%10;
  
  if (B==C&&B==D) {
    cout <<"Yes"<< endl;
  }else if(D==C&&D==E){
    cout <<"Yes"<< endl;
  }else{
    cout <<"No"<< endl;
  }
}

Measured memory_bytes: 256
def main():
    from string import ascii_lowercase

    N = int(input())

    ans = ''
    while N > 0:
        N -= 1
        N, r = divmod(N, 26)
        ans = ascii_lowercase[r] + ans

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9968
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  ll a,b;cin>>a>>b;
  string ans;
  if(a<=0 && b>=0){
    ans="Zero";
  }else if(a>0){
    ans="Positive";
  }else if((b-a)%2==0){
    ans="Negative";
  }else{
    ans="Positive";
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var Q = nextInt()
    repeat(Q) {
        val (A, B) = listOfLong()
        val ans = when {
            (A == B) -> 2 * A - 2
            (A + 1 == B || B + 1 == A) -> 2 * Math.min(A, B) - 2
            else -> {
                val ab = A * B
                var d = Math.sqrt(ab.toDouble()).toLong()
                if (d * d == ab) d--
                if (d * (d + 1) >= ab) 2 * d - 2 else 2 * d - 1
            }
        }
        println(ans)
    }
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfLong(d: Long = 0) = listOfString().map { it.toLong() + d }


Measured memory_bytes: 38048
#include<stdio.h>
main(){
  int a,b,c,d,n,i;
  while(scanf("%d",&n)!=EOF){
    i=0;
    for(a=0;a<=9;a++){
      for(b=0;b<=9;b++){
	for(c=0;c<=9;c++){
	  for(d=0;d<=9;d++){
	    if(n==a+b+c+d){
	      i++;
	    }
	  }
	}
      }
    }
    printf("%d\n",i);
  }
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    int ans=1;
    while(ans<=n){
    	ans*=2;
    }
    cout << ans/2 << endl;
}


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

typedef long long ll;

int main() {
	ll N;
	scanf("%lld", &N);
	if (N == 0 || N == 1) {
		printf("1\n");
	}
	else {
		ll ans = 1;
		for (ll j = 1; j <= N; j++) {
			ans=(ans*j)%1000000007;
		}
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 256
H,W = map(int,input().split())
c = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int,input().split())) for  i in range(H)]
ans = 0

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j],c[i][k]+c[k][j])

for i in range(H):
    for j in range(W):
        if A[i][j] == -1 or A[i][j] == 1:
            continue
        else:
            ans += c[A[i][j]][1]
print(ans)


Measured memory_bytes: 3444
using System;
using System.Linq;

namespace _174.B
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToList();
            var n = input[0];
            var d = input[1];

            var count = 0;
            for (var i = 0; i < n; i++)
            {
                input = Console.ReadLine().Split().Select(int.Parse).ToList();
                if (Math.Sqrt(Math.Pow(input[0], 2) + Math.Pow(input[1], 2)) <= d) count++;
            }
            Console.WriteLine(count.ToString());
        }
    }
}

Measured memory_bytes: 23204
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

int main() {
    ll K, T;
    cin >> K >> T;

    vector<ll> a(T);
    rep(i, T) { cin >> a[i]; }

    while (a.size() > 1) {
        sort(a.begin(), a.end(), greater<int>());

        // repv(a) { cout << *it << " "; }
        // cout << endl;

        if (a.size() == 1) break;

        // cout << a[0] << "," << a[a.size() - 1] << endl;
        a[0] -= a[a.size() - 1];

        a.pop_back();
    }

    cout << max(0LL, a[0] - 1) << endl;

    return 0;
}

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

ll mod = 998244353;

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<ll> R, G, B;
    for (int i = 0; i < 3*N; i++) {
        if (S[i] == 'R') R.push_back(i);
        if (S[i] == 'G') G.push_back(i);
        if (S[i] == 'B') B.push_back(i);
    }
    vector<ll> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) {
        a[i] = min(min(R[i], G[i]), B[i]);
        c[i] = max(max(R[i], G[i]), B[i]);
        b[i] = R[i] + G[i] + B[i] - a[i] - c[i];
    }
    ll ans = 1;
    int pos = 0;
    for (int i = 0; i < N; i++) {
        while (pos < N-1 && a[pos+1] < b[i]) pos++;
        ans = ans * (pos - i + 1) % mod;
    }
    
    pos = 0;
    for (int i = 0; i < N; i++) {
        while (pos < N-1 && b[pos+1] < c[i]) pos++;
        ans = ans * (pos - i + 1) % mod;
    }
    
    for (int i = 1; i <= N; i++) ans = ans * i % mod;
    
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int N,M;
    cin >> N >> M;

    vector<bool> one(N+1, false), enu(N+1, false);
    for (int i = 0; i < M; i++) {
         int a,b;
         cin >> a >> b;
         if (a == 1) {
             one[b] = true;
         }else if (b == N) {
             enu[a] = true;
         }
    }

    for (int i = 0; i < N; i++) {
        if (one[i] && enu[i]) {
            cout << "POSSIBLE" << endl;
            return;
        }
    }

    cout << "IMPOSSIBLE" << endl;
    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
キュー　queue<int> q;
   q.push(7);　//７が入る
   cout << q.front() << endl;  // 先頭の値を出力
   q.pop();  // 先頭の値を削除
   q.empty();
*/
//座標　corrdinateト深さヲ保持スルタメノ構造体
struct Coor{
  ll y;
  ll x;
  ll depth;
};
 ll N,M;  
 ll sy,sx,gy,gx;
 ll y,x,depth;//キューから取り出した座標
vector<string> vec;
queue<Coor> q;
vector<ll> y_vec={0,0,-1,+1};//technique
vector<ll> x_vec={-1,+1,0,0};

int BFS(){
  while(!q.empty()){
    Coor now=q.front();q.pop();//キューの先頭を取り出す
    y=now.y,x=now.x,depth=now.depth;
    
    //停止条件
    if(y==gy&&x==gx){return depth;}
    
    //上下左右４方向を探索、進むことができればキューに格納
    for(int i=0;i<4;i++){
      Coor next={y+y_vec[i],x+x_vec[i],depth+1};
      if(0<=next.y&&next.y<=N-1&&0<=next.x&&next.x<=M-1&&vec[next.y][next.x]=='.'){
        vec[next.y][next.x]='x';//同じ場所を探索しないようにする
        q.push(next);
      }
    }
  }
  return 0;
}
                   
  


int main(void){
cout<<fixed<<setprecision(14);
//cin.tie(0); ios::sync_with_stdio(false);

 ll A,B,C;
  cin>>A>>B>>C;
  
  if(A==B)cout<<C<<endl;
  if(B==C)cout<<A<<endl;
  if(C==A)cout<<B<<endl;
  
  
  
  
}



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

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>b)
		swap(a,b);
	if(b<=9) cout<<a*b<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> a(n+1,0);
	rep(i,n) std::cin >> a[i];
	rep(j,k) {
		std::vector<int> ac(n+1,0);
		rep(i,n) {
			ac[std::max(0,i-a[i])]++;
			ac[std::min(n,i+a[i]+1)]--;
		}
		rep(i,n) ac[i+1]+=ac[i];
		if(a==ac) {
			debug(j);
			break;
		}
		std::swap(a,ac);
	}
	rep(i,n) std::cout << a[i] << ' ';
	std::cout << EL;
}


Measured memory_bytes: 4756
# -*- coding: utf-8 -*-
s = input()

flag = True

if s[0]!="A":
    print("WA")
    exit()

if "C" not in s[2:-1]:
    print("WA")
    exit()

idx = s[2:-1].find("C")+2

s = s[1:idx]+s[idx+1:]

if s == s.lower():
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3060
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val N = sc.nextInt
    val A, B = Array.fill(N)(sc.nextLong)
    var ans = B.sum - A.sum
    for (i <- Range(0, N)) {
      if (A(i) < B(i)) {
        ans -= ((B(i) - A(i) + 1) / 2: Long)
      }
    }
    println(if (ans >= 0) ("Yes") else ("No"))
  }

  def gcd(i: Int, j: Int): Int = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}



Measured memory_bytes: 42084
package main

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

var checked []bool
var edge [][]int
var points []int
var ans []int

func dfs(p int, score int) int {
	s := score
	ans[p] = score

	for _, v := range edge[p] {
		if checked[v] {
			continue
		}
		checked[v] = true
		s += dfs(v, score+points[v])
	}
	return s
}

func main() {
	sc := NewScanner()
	N, Q := sc.NextInt(), sc.NextInt()
	edge = make([][]int, N)
	points = make([]int, N)
	ans = make([]int, N)

	for i := 0; i < N; i++ {
		edge[i] = make([]int, 0)
	}
	for i := 0; i < N-1; i++ {
		a, b := sc.NextInt(), sc.NextInt()
		a--
		b--
		edge[a] = append(edge[a], b)
		edge[b] = append(edge[b], a)
	}
	for i := 0; i < Q; i++ {
		p, x := sc.NextInt(), sc.NextInt()
		p--
		points[p] += x
	}

	checked = make([]bool, N)

	checked[0] = true
	dfs(0, points[0])
	PrintI(ans...)
}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 71808
#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
    int s1,e1,s2,e2;
    cin >> s1 >> e1 >> s2 >> e2;
    if(e1<=s2||e2<=s1)
        cout << 0;
    else if(s1<=s2&&e2<=e1)
            cout << e2-s2;
    else if(s2<=s1&&e1<=e2)
            cout << e1-s1;
    else {
        int a[4];
        a[0]=s1;
        a[1]=e1;
        a[2]=s2;
        a[3]=e2;
        sort(a,a+4);
        cout << a[2]-a[1];
    }

	return 0;
}


Measured memory_bytes: 256
/*input
issii
2
*/
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 3e5 + 100;
const int mod = 1e9 + 7;
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	string s;
	ll k;
	cin >> s;
	cin >> k;
	ll bad = 0, st = 0, en = 0;
	for(int i = 0; i < sz(s); i++)
	{
		int j = i;
		while(j + 1 < sz(s) && s[i] == s[j + 1])
			++j;
		if(i == 0)
		{
			if(j == sz(s) - 1)
				return cout << 1ll * sz(s) * k / 2 << "\n", 0;
			st = j - i + 1;
		}
		if(j == sz(s) - 1)
			en = j - i + 1;
		bad += (j - i + 1) / 2;
		i = j;
	}
	if(s[0] != s.back())
		cout << bad * k << "\n";
	else
	{
		bad -= st / 2;
		bad -= en / 2;
		ll ans = bad * k;
		ans += st / 2;
		ans += en / 2;
		ans += (k - 1) * ((st + en) / 2);
		cout << ans << "\n";
	}
	return 0;
}

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

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < W; i++) printf("#");
		printf("\n");

		for(int i = 1; i < H-1; i++){
			printf("#");
			for(int j = 1; j < W-1; j++) printf(".");
			printf("#\n");
		}

		if(H > 1){
			for(int i = 0; i < W; i++) printf("#");
			printf("\n");
		}
		printf("\n");
	}
}



Measured memory_bytes: 2504
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  char a[h][w];
  rep(i,h)rep(j,w) cin>>a[i][j];
  int ans=0;
  
  rep(i,(1<<h)){
    rep(j,(1<<w)){
      int now=0;
      rep(p,h){
        rep(o,w){
          if(a[p][o]=='#' &&!(i&(1<<p))&&!(j&(1<<o)) ) now++;
        }
      }
      if(now==k) ans++;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
template<class T>
using PAIR = pair<T,T>;
template<class T>
using vec = vector<T>;
template<class T>
using maps = map<string, T>;
template<class T>
using mapi = map<int, T>;
using ll = long long;
int main(){
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 0;i < N;i++){
        int x;
        cin >> x;
        if(x != i+1){
            ans++;
        }
    }
    if(ans <= 2){
        cout << "YES" << "\n";
    }
    else{
        cout << "NO" << "\n";
    }
    return 0;
}

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

//#define int long long
//#define ll int long long
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(vec) (vec).begin(),(vec).end()
#define vint vector<int>
#define pint pair<int,int>
#define vpint vector<pint>

signed main(){
    string s;
    int k;
    cin>>s>>k;
    set<string> st;
    for(int i=0;i<s.length();i++){
        for(int j=1;j<s.length()-i+1;j++){
            st.insert(s.substr(i,j));
            if(j==5)break;
        }
    }
    for(set<string>::iterator itr = st.begin(); itr != st.end(); ++itr) {
        if(--k==0){
            cout<<(*itr)<<endl;
            break;
        }
    }
    return 0;
}

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

int main(void) {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if ((A + B) > (C + D)) {
		cout << "Left" << endl;
	}
	else if ((A + B) < (C + D)) {
		cout << "Right" << endl;
	} 
	else {
		cout << "Balanced" << endl;
	}
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] p = new int[m];
        String[] s = new String[m];
        for (int i = 0; i < m; i++) {
            p[i] = Integer.parseInt(sc.next());
            s[i] = sc.next();
        }

        // 主処理
        int[] status = new int[n];
        int[] count = new int[n];
        for (int i = 0; i < m; i++) {
            // 正答していない場合
            if (status[p[i] - 1] < 1) {
                if ("AC".equals(s[i])) {
                    status[p[i] - 1] = 1;
                } else {
                    count[p[i] - 1]++;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            if (status[i] < 1) {
                count[i] = 0;
            }
        }
        String result = Arrays.stream(status).sum() + " " + Arrays.stream(count).sum();

        // 出力
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 66432
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 5e5+7;
int a[N];
int n;
void nhap()
{
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
}
void solve()
{
    if (a[1] != 0) {
        cout << -1;
        return;
    }
    long long res = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] - a[i - 1] > 1) {
            cout << -1;
            return;
        }
        if (a[i] > a[i - 1]) {
            res++;
        }
        else {
            res += a[i];
        }
    }
    cout << res;
}
int main()
{
    nhap();
    solve();
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func gcd(m, n int) int {
	if n == 0 {
		return m
	}
	return gcd(n, m%n)
}

func main() {
	var N, X int
	fmt.Scanf("%d%d", &N, &X)
	var ans int
	for i := 0; i < N; i++ {
		var x int
		fmt.Scanf("%d", &x)
		m, n := x-X, ans
		if m < 0 {
			m *= -1
		}
		if m < n {
			m, n = n, m
		}
		ans = gcd(m, n)
	}
	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 5504
from sys import stdin
N = int(stdin.readline().rstrip())
S = (stdin.readline().rstrip())
stack = []
l = 0
r = 0
for i in range(N):
    if S[i] == "(":
        stack.append(1)
    elif S[i] == ")":
        if not stack:
            l += 1
        else:
            stack.pop()

r = len(stack)
print(l*"(" + S + r*")")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)


int main(){

	ll N,S,sum=0,l=0,r=1,ans=1000000;
	cin >> N >> S;
	vector<ll> a(N);
	FOR(i,0,N)cin >> a[i];
	sum = a[0];

	FOR(i,0,N){
		while(sum<S && r<N){
			sum += a[r++];
		}
		if(sum>=S)ans = min(ans,r-l);
		sum -= a[l++];
	}
	if(ans==1000000)ans=0;
	cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  map<lint,int> m;
  REP(i,N){
    lint a;
    cin>>a;
    m[a]++;
  }
  auto itr=m.begin();
  lint b[3];
  if(m.size()==1){
    if(m[0]==N){
      cout<<"Yes"<<endl;
      return 0;           
    }
  }else if(m.size()==2 and N%3==0){
    if(m[0]==N/3){
      cout<<"Yes"<<endl;
      return 0;     
    }
  }else if(m.size()==3 and N%3==0){
    REP(i,3){
      if(itr->second!=N/3){
        cout<<"No"<<endl;
        return 0;
      }
      b[i]=itr->first;
      itr++;
    }
    if((b[0]^b[1]^b[2])==0){
      cout<<"Yes"<<endl;
      return 0;      
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<string>
#include<cstring>

// ref : https://qiita.com/nomikura/items/98e53c1eb0be7af15847

using ll = long long;

int n, a;
std::vector<int> card;

// dp[id][maisu]][sum] = id以上のindexからmaisu枚以上を選んで合計がsum以上で条件を満たす総数
ll dp[51][51][2501];

ll rec(int id, int maisu, ll sum){
    if(id >= n){
        if(maisu * a == sum && maisu > 0) return 1;
        else return 0;
    }

    if(dp[id][maisu][sum] != -1){
        return dp[id][maisu][sum];
    }

    ll ret = 0;
    // idのカードを選ぶか選ばないか
    ll yes = rec(id + 1, maisu + 1, sum + card[id]);
    ll no = rec(id + 1, maisu, sum);
    ret += yes + no;
    
    dp[id][maisu][sum] = ret;
    return ret;
}

int main(){
    std::cin >> n >> a;
    card.resize(n);
    for(int i = 0; i < n; i++){
        std::cin >> card[i];
    }

    std::memset(dp, -1, sizeof(dp));
    std::cout << rec(0, 0, 0) << std::endl;

    return 0;
}


Measured memory_bytes: 51072
package main

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

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  a, _ := strconv.Atoi(sc.Text())

  sc.Scan()
  b, _ := strconv.Atoi(sc.Text())

  if a < 6 {
    fmt.Println(0)
  } else if a < 13 {
    fmt.Println(b / 2)
  } else {
    fmt.Println(b)
  }
}



Measured memory_bytes: 640
sa = list(input())
sb = list(input())
sc = list(input())

from collections import deque
a_hand = deque(sa)
b_hand = deque(sb)
c_hand = deque(sc)
x = a_hand.popleft()
flag = 0
while True:
    if x == "a":
        if not a_hand:
            flag = 1
            break
        x = a_hand.popleft()
    elif x == "b":
        if not b_hand:
            flag = 2
            break
        x = b_hand.popleft()
    else:
        if not c_hand:
            flag = 3
            break
        x = c_hand.popleft()

if flag == 1:
    print("A")
elif flag == 2:
    print("B")
elif flag == 3:
    print("C")

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

const int MAX = 2e5 + 5;
int n, M, ans[MAX], dp[MAX];
vector <int> g[MAX];

int get(vector <int> &v, int p) {
	if(p < 0 || p >= (int) v.size())
		return 1;

	return v[p];
}

void dfs1(int u, int p = -1) {
	dp[u] = 1;

	for(int v : g[u]) {
		if(v != p) {
			dfs1(v, u);
			dp[u] = 1LL * dp[u] * (dp[v] + 1) % M;
		}
	}
}

void dfs2(int u, int p = -1, int up = 0) {
	ans[u] = 1LL * dp[u] * (up + 1) % M;

	vector <int> pre, suf;

	for(int v : g[u]) {
		if(v != p) {
			if(pre.empty())
				pre.push_back(dp[v] + 1);

			else pre.push_back(1LL * pre.back() * (dp[v] + 1) % M);
		}
	}

	for(int i = (int) g[u].size() - 1; i >= 0; i--) {
		int v = g[u][i];

		if(v != p) {
			if(suf.empty())
				suf.push_back(dp[v] + 1);

			else suf.push_back(1LL * suf.back() * (dp[v] + 1) % M);
		}
	}

	reverse(suf.begin(), suf.end());

	int it = 0;
	for(int v : g[u]) {
		if(v != p) {
			int nup = 1LL * get(pre, it - 1) * get(suf, it + 1) % M;
			nup = 1LL * nup * (up + 1) % M;
			dfs2(v, u, nup);
			it++;
		}
	}
}

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

	for(int i = 1; i < n; i++) {
		int a, b; scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}

	dfs1(1);
	dfs2(1);

	for(int i = 1; i <= n; i++)
		printf("%d\n", ans[i]);

	return 0;
}

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

class myList
{
public:
	myList() : mSize( 0 ){}

	void insert( string str, int page ){
		for( int i = 0; i < mSize; ++i ){
			if( str == mList[ i ].first ){
				mList[ i ].second.push_back( page );
				return;
			}
		}
		vector< int > vec;
		vec.push_back( page );
		mList.push_back( pair< string, vector< int > >( str, vec ) );
		++mSize;
	}

	void sort(){
		std::sort( mList.begin(), mList.end() );
		for( int i = 0; i < mSize; ++i ){
			std::sort( mList[ i ].second.begin(), mList[ i ].second.end() );
		}
	}

	void output(){
		for( int i = 0; i < mSize; ++i ){
			cout << mList[ i ].first << endl;
			for( int j = 0; j < (int)mList[ i ].second.size(); ++j ){
				if( j != 0 ){
					cout << " ";
				}
				cout << mList[ i ].second[ j ];
			}
			cout << endl;
		}
	}

	vector< pair< string, vector< int > > > mList;
	int mSize;
};

int main()
{
	string str;
	int page;
	myList db;

	while( cin >> str >> page ){
		db.insert( str, page );
	}
	db.sort();
	db.output();

	return 0;
}

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

int main() {
	int n, c, k;
	cin >> n >> c >> k;
	int t[11000000];
	for (int i = 0;i < n;i++)cin >> t[i];
	sort(t, t + n);
	int time = t[0], ans = 1, drive = 0;
	for (int i = 1;i < n;i++) {
		drive++;
		if (drive == c || time + k < t[i]) {
			time = t[i];
			drive = 0;
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2432
N = int( input() )
T = [ int( input() ) for _ in range(N) ]


# 最小公倍数を求めたい
# aとbの最小公倍数 = a*b / aとbの最大公約数
# 最大公約数 (Greatest Common Divisor)
def GCD( a, b ):
    if b == 0: return a
    return GCD(b, a%b)

# 最小公倍数 (Least Common Multiple)
def LCM( a, b ):
    return a*b // GCD(a,b)


ans = 1
for i in range(N): ans = LCM( ans, T[i] )
print( ans )

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
    long long x;
    mint(long long x=0):x(x % MOD + (0 <= x ? 0 : MOD)) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint& a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
    mint& operator-=(const mint& a) { if ((x -= a.x) < 0) x += MOD; return *this; }
    mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; }
    mint operator+(const mint& a) const { return mint(x) += a; }
    mint operator-(const mint& a) const { return mint(x) -= a; }
    mint operator*(const mint& a) const { return mint(x) *= a; }

    // for prime mod
    mint inv() const {
        long long a = x, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return mint(u);
    }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { return mint(x) /= a; }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

int main(){
    string L;
    cin >> L;

    int N = L.size();

    vector<vector<mint>> dp(N + 1, vector<mint>(2));
    dp[0][0] = 1;
    rep(i, N) {
        rep(j, 2) {
            mint pre = dp[i][j];
            if (j == 0) {
                if (L[i] == '0') {
                    dp[i+1][0] += pre;
                } else {
                    dp[i+1][0] += pre * 2;
                    dp[i+1][1] += pre;
                }
            } else {
                dp[i+1][1] += pre * 3;
            }
        }
    }

    cout << dp[N][0] + dp[N][1] << endl;
}

Measured memory_bytes: 5760
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = sum(B)
for n in range(N-1):
    if A[n+1] - A[n] == 1:
        ans += C[A[n]-1]
print(ans)


Measured memory_bytes: 3060
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var data = (input.trim()).split('\n');

/**
 * Prints digit number of sum of two integers
 * @param {Array} data
 */
function main(data) {
  for (var i = 0; i < data.length; i++) {
    console.log(digitNumber(data[i]));
  }
}

/**
 * Returns the output to be printed
 * @param {String} numbers
 * @returns {Number}
 */
function digitNumber(numbers) {
  var ary = numbers.split(' ');
  var numberString = String(Number(ary[0]) + Number(ary[1]));
  return numberString.length;
}

main(data);

Measured memory_bytes: 16060
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
	b = b * 100 + c;
	e = e * 100 + f;
	if (d > a) {
		int ans = d - a;
		if (e > b)ans++;
		cout << ans << endl;
	}
	else if (d < a) {
		int ans = a - d;
		if (e < b)ans++;
		cout << ans << endl;
	}
	else if (d == a) {
		if (b == e)cout << 0 << endl;
		else cout << 1 << endl;
	}
}


Measured memory_bytes: 3112
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const double PI=3.14159265358979323846;
int gcd(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(y>0){
    int r=x%y;
    x=y;
    y=r;
  }
  return(x);
}
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint a(n);
  rep(i,n){
    cin>>a[i];
  }
  int ans=a[0];
  REP(i,1,n){
    ans=gcd(ans,a[i]);
  }
  cout<<ans<<'\n';
  return(0);
}


Measured memory_bytes: 3740
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr ll MOD = 1000000007;

#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
#else
#define print(...)
#endif


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

    ll a,b,h,m;
    cin >> a >> b >> h >> m;

    h = h%12;
    m = m%60;
    double s = (h%12 + m/60.0)/12.0;
    double l = (m%60)/60.0;

    double r = abs(l-s);
    

    double x = abs(a-b);

    if(r!=0)
        x = sqrt(a*a+b*b-2*a*b*cos(r*2.0*M_PI));


    print(s,l,r,x);

    printf("%.12lf\n", x);

    return 0;
}


Measured memory_bytes: 4180