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

int main()
{
	long long W, H, x, y;
	cin >> W >> H >> x >> y;

	double ans = (double)W * H / 2;
	int ans1 = 0;
	if( W == x * 2 && H == y * 2 ) ans1 = 1;

	cout << fixed << setprecision(12) << ans << " " << ans1 << endl;
}


Measured memory_bytes: 3780
#include <iostream>
#include <sstream>  // istringstream
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{   
    int N;
    cin >> N;
    long long A[N];
    for(int i=0; i<N; ++i) cin >> A[i];

    long long ret = 1;
    for(int i=0; i<N; ++i) {
        if(log10(ret) + log10(A[i]) > 18){
            ret = -1;
            break;
        }
        ret*=A[i];
    } 
    if(ret > 1000000000000000000) {
        ret = -1;
    }

    for(int i=0; i<N; ++i) {
        if(A[i] == 0){
            ret = 0;
        }
    } 


    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4680
x, k, d = map(int, input().split())
x = abs(x)
m = x//d
ans = 0
if m > k:
    ans = x - k * d
else :
    x -= d*m
    k -= m
    if k%2==1:
        x -= d
        ans = abs(x)
    else :
        ans = abs(x)
print(ans)

Measured memory_bytes: 9124
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int bfs(vector< vector <char>> map, int h,int w,int i,int j){
    vector< vector <int>> d{{0,-1},{1,0},{0,1},{-1,0}};
    queue< vector<int>> q;
    vector<int> node(3);
    int v=0, bv=1,buf=0, max=0;
    map[i][j] = 'f';
    node[0] = i;
    node[1] = j;
    node[2] = 0;
    q.push(node);

    
    while(!q.empty()){
        node = q.front();
        q.pop();
        buf=0;
        
        //cout<<"qsize "<<q.size()<<endl;
        //cout<<"node "<<node[0]<<" "<<node[1]<<" "<<node[2]<<endl;
        
        for(int k=0; k<4; k++){
            vector<int> new_node(3);
            int dx=d[k][0], dy=d[k][1];
            if(map[node[0]+dy][node[1]+dx] == '.'){
                map[node[0]+dy][node[1]+dx] = 'f';
                new_node[0] = node[0]+dy;
                new_node[1] = node[1]+dx;
                new_node[2] = node[2]+1;
                q.push(new_node);
                if(max < new_node[2])
                    max = new_node[2];
            }
        }
    }
    return max;
}


int main(void){
    int h,w,buf;
    int max = 0;
    cin>>h>>w;
    h+=2;
    w+=2;
    vector< vector <char>> map(h, vector<char>(w, 0));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(i==0 || j==0 || i==h-1 || j==w-1 )
                map[i][j]='#';
            else
                cin>>map[i][j];
            //cout<<map[i][j];
        }
        //cout<<endl;
    }
    
    for(int i=1; i<h-1; i++){
        for(int j=1; j<w-1; j++){
            if(map[i][j] == '.'){
                buf = bfs(map, h, w, i, j);
                if(max < buf)
                    max = buf;
            }
        }
    }
    cout<<max<<endl;
}


Measured memory_bytes: 256
step = [int(i) for i in input().split()]
breaked_step = [int(input()) for i in range(step[1])]
dp = [1] * (step[0] + 1)
ans = 0
ans_ptn = 0
par = 1000000007

"""for i in range(len(breaked_step) - 1):
    if breaked_step[i + 1] - breaked_step[i] == 1:
        ans = 0
    else:
        ptn = breaked_step[i + 1] - breaked_step[i]
        ans_ptn += ptn * 2
        print("breaked_step[i + 1] - breaked_step[i]:{} - {}".format(breaked_step[i+1], breaked_step[i]))
        print("ans_ptn:{}".format(ans_ptn))

ans = ans_ptn % par"""
for i in breaked_step:
    dp[i] = 0

for j in range(1, step[0]):
    #print("dp[{}]:{}".format(j+1, dp[j+1]))
    if dp[j + 1] != 0:
        dp[j + 1] = (dp[j] + dp[j - 1]) % par
        #print("dp[{}] - dp[{}] = {}".format(j, j - 1, dp[j] - dp[j-1]))

print(dp[step[0]])


Measured memory_bytes: 7844
#!/bin/sh

while true;
do
        read line1
        read line2

        if [ -z "$line1" ]; then
                break
        fi

        monthA=`echo $line1 | awk '{print $1}'`
		monthB=`echo $line2 | awk '{print $1}'`
		if [ $monthA = $monthB ]; then
                echo "0"
        else
                echo "1"
        fi

done

Measured memory_bytes: 760
#include <stdio.h>

int sum[7];
int main(void)
{
	int i, j, n, g;
	
	while (scanf("%d", &n), n != 0){
		for (j = 0; j < n; j++){
			scanf("%d", &g);
			if (g / 10 > 6){
				sum[6]++;
			}
			else {
				sum[g / 10]++;
			}
		}
		for (i = 0; i < 7; i++){
			printf("%d\n", sum[i]);
			sum[i] = 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
def main():
    n=int(input())
    s=[]
    for i in range(n):
        si=list(input())
        si.sort()
        s.append(si)
    s.sort()
    s.append("X")
    cnt=1
    ans=0
    for i in range(n):
        if s[i]==s[i+1]:
            cnt+=1
        else:
            ans+=cnt*(cnt-1)//2
            cnt=1
    print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 24652
program main
	implicit none
    integer(8) n,m,t
    integer(8),parameter::x=1000000007_8
    integer(8)::ans=1
    read *,n,m
    t=mod(n+m,2)
    if(abs(n-m)>1) then
    	print '(i0)',0
        stop
    end if
    do while(n>0)
       	ans=ans*n
        ans=mod(ans,x)
        n=n-1
    end do
    do while(m>0)
        ans=ans*m
        ans=mod(ans,x)
        m=m-1
   	end do
    if(t==0) then
    	ans=ans*2
        ans=mod(ans,x)
    end if
    print '(i0)',ans
end program main

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int N,ans=0;
    cin >> N;
    string S;
    cin >> S;
    bool e = false;
    for(int i=0;i<N;i++){
        if(S[i]==S[i+1])ans += 1;
    }
    cout << N - ans << endl;
}


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

typedef long long ll;
typedef pair <ll, ll> ii;

int k;
int X, Y;
vector <ii> seq;

bool Solve(ll k, ll X, ll Y)
{
    if (k % 2 == 0 && (X + Y) % 2 != 0) return false;
    ll curX = 0, curY = 0;
    while (X - curX >= k && X - curX + Y - curY > 2 * k) {
        curX += k;
        seq.push_back(ii(curX, curY));
    }
    while (Y - curY >= k && X - curX + Y - curY > 2 * k) {
        curY += k;
        seq.push_back(ii(curX, curY));
    }
    if (curX == X && curY == Y) return true;
    if (X - curX + Y - curY == k) {
        seq.push_back(ii(X, Y));
        return true;
    }
    ll sum = X - curX + Y - curY;
    if (sum % 2) {
        if (X - curX >= Y - curY) {
            ll tk = min(k, X - curX);
            curX += tk; curY -= (k - tk);
        } else {
            ll tk = min(k, Y - curY);
            curX -= (k - tk); curY += tk;
        }
        seq.push_back(ii(curX, curY));
    }
    sum = X - curX + Y - curY;
    if (sum > 0) {
        ll tk = sum / 2;
        if (X - curX >= tk) {
            curX += tk; curY -= (k - tk);
        } else {
            curY += tk; curX -= (k - tk);
        }
        seq.push_back(ii(curX, curY));
        seq.push_back(ii(X, Y));
    }
    return true;
}

int main()
{
    scanf("%d", &k);
    scanf("%d %d", &X, &Y);
    if (Solve(k, abs(X), abs(Y))) {
        printf("%d\n", int(seq.size()));
        for (int i = 0; i < seq.size(); i++) {
            if (X < 0) seq[i].first = -seq[i].first;
            if (Y < 0) seq[i].second = -seq[i].second;
            printf("%lld %lld\n", seq[i].first, seq[i].second);
        }
    } else printf("-1\n");
    return 0;
}


Measured memory_bytes: 5484
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

int gcd(vector<int> x) {
    if (x.size() == 1)
        return x[0];
    int ans = x[0];
    FOR(i, 1, x.size()) { ans = gcd(ans, x[i]); }
    return ans;
}

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

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    int ans = gcd(A);

    cout << ans << endl;

    return 0;
}

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

int main() {
	std::array <int, 9> a;
	std::array <int, 100> b;
	int count = 0;
	for (int i = 0; i < 9; i++) {
		cin >> a[i];

	}
	for (int i = 0; i < 10; i++) {
		cin >> b[i];

	}
	for (int i = 0; i < 9; i++) {
		for (int q = 0; q < 10; q++) {
			if (a[i] == b[q]) {
				a[i] = 0;
			}

		}
	}
	if (a[0] == 0 && a[1] == 0 && a[2] == 0&&count==0) {
		cout << "Yes" << endl;
		count++;
	}
	if (a[3] == 0 && a[4] == 0 && a[5] == 0 && count == 0) {
		cout << "Yes" << endl;
		count++;
	}
	if (a[6] == 0 && a[7] == 0 && a[8] == 0 && count == 0) {
		count++;
		cout << "Yes" << endl;
	}
	if (a[0] == 0 && a[3] == 0 && a[6] == 0 && count == 0) {
		count++;
		cout << "Yes" << endl;
	}
	if (a[1] == 0 && a[4] == 0 && a[7] == 0 && count == 0) {
		cout << "Yes" << endl;
		count++;
	}
	if (a[2] == 0 && a[5] == 0 && a[8] == 0 && count == 0) {
		count++;
		cout << "Yes" << endl;
	}

	if (a[0] == 0 && a[4] == 0 && a[8] == 0 && count == 0) {
		count++;
		cout << "Yes" << endl;
	}
	if (a[2] == 0 && a[4] == 0 && a[6] == 0 && count == 0) {
		count++;
		cout << "Yes" << endl;
	}
	
	else if(count==0) {
	cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, a, pr = 1;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    pr *= (a%2==0?2:1);
  }
  cout << (int)pow(3,n) - pr << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int A, B;

	cin >> A >> B;
	if (B == 1)
	{
		cout << 0 << endl;
		return (0);
	}
	int ans = 1;
	B -= A;
	A--;
	ans += (B + A - 1) / A;
	cout << ans << endl;
}



Measured memory_bytes: 256
n = int(input())
li = []
for i in range(n):
  li.append(int(input()))
li_2 = sorted(li)
m_1 = li_2[-1]
m_2 = li_2[-2]
for i in range(n):
  if m_1 == li[i]:
    print(m_2)
  else:
    print(m_1)
    

Measured memory_bytes: 14112
import sys
readline = sys.stdin.readline

def solve():
    N = int(readline())
    A = list(map(int, readline().split()))

    t = 0
    for a in A:
        t = t ^ a
    
    ans = []
    for a in A:
        ans.append(a ^ t)
    
    print(*ans)

solve()

Measured memory_bytes: 108396
#include<bits/stdc++.h>
using namespace std;
int main() {
	int w,h,n;
	cin >> w >> h >> n;
	int x[1001],y[1001];
	for(int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	int sum = 0;
	for(int i = 1; i <= n - 1; i++) {
		int dx = x[i] - x[i-1], dy = y[i] - y[i-1];
		if(dx * dy > 0) sum += max(abs(dx), abs(dy));
		else sum += abs(dx) + abs(dy);
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1168
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  int n, k;
  cin >> n >> k;

  lint ans = 0;

  for (int b = k + 1; b <= n; b++) {
    int p = n / b, r = n % b;
    ans += max(0, b - k) * p + max(0, r - k + 1);
    if (k == 0) ans--;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define     ll long long
#define     nl '\n'
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define     mod             100000000
#define     space           10000005

vector<ll> pwx(61);
void cal(ll x){ pwx[0] = 1; for(ll i = 1; i < 61 ; i++)pwx[i] = x*pwx[i-1]; }

ll f(ll y, ll x){
    return (y*(y+1)*x)/2;
}

int main(){
    boost;
    
    ll n, ans = 0; 
    cin >> n;

    for(ll i = 1 ; i <= n ; i++){
        ans += f(n/i, i);
    }

    cout << ans << nl;
    
    return 0;
}

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

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

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  string n; cin >> n;
  lint size=(lint)n.size();

  lint sum=0;
  for(lint i=0;i<size;i++) {
    sum += n[i] - '0';
  }

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


Measured memory_bytes: 3716
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;


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

    int N; cin >> N;
    vl A(N); REP(i, N) cin >> A[i];

    ll ans = 0;
    ll sum = 0;
    int r = 0;
    REP(l, N) {
        while(r < N && (sum & A[r]) == 0) {
            sum += A[r];
            r++;
        }
        ans += (r - 1) - l + 1;

        sum -= A[l];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>

using namespace std;

int main(){
  int a;
  cin>>a;
  string s;
  if (a<1200){
    s="ABC";
  }else if (a<2800){
    s="ARC";
  }else {
    s="AGC";
  }

  cout<<s;
  return 0;
}


Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
long long c,s;
cin>>s>>c;
if (c/2>s) s+=(c/2-s)/2;
if (c/2==s-1 && c>s) cout<<s-1<<endl;
else if (c<s) cout<<c/2<<endl;
     else if (c==s) cout<<c/2<<endl;
      else if(c/2<s) cout<<c/2<<endl;
           else cout<<s<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int a,b,x;
    scanf("%d%d%d",&a,&b,&x);
    if (x<=a+b&&x>=a) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[114514];
signed main(){
	ic(n)
	int ans=0;
	rep(1,i,sqrt(n)+1){
		if(n%i==0){
			ans=i;
		}
	}
	c(ans+n/ans-2)
}		

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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
	if (l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve() {
	pos = 0;
	rec(0, pre.size());
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << post[i];
	}
	cout << endl;
}

int main() {
	int k;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> k;
		pre.push_back(k);
	}
	for (int i = 0; i < n; i++) {
		cin >> k;
		in.push_back(k);
	}

	solve();
	return 0;
}



Measured memory_bytes: 3140
#include <stdio.h>

int main(void){

  long a,b,k;
  scanf("%ld %ld %ld", &a, &b, &k);
  int takahashi = a;
  int aoki = b;
  for (long i = 0; i < k; i++) {
    if (i%2 == 0) {
      takahashi /= 2;
      aoki += takahashi;
    } else {
      aoki /= 2;
      takahashi += aoki;
    }
  }
  printf("%d %d\n", takahashi, aoki);

  return 0;
}

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

#define MAX_SIZE 200

int Stack[MAX_SIZE];
int Stack_size;

void push(int x){
  Stack_size++;
  Stack[Stack_size]=x;
}

int pop(){
  Stack_size--;
  
  return Stack[Stack_size+1];
}

int main(void){
  int  num, a, b;
  char com[100];
  
  while(scanf("%s", com) != EOF){
    if(com[0] == '+'){
      push(pop()+pop());
    }
    else if(com[0] == '-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(com[0] == '*'){
      push(pop()*pop());
    }
    else{
      num=atoi(com);
      push(num);
    }
  }

  printf("%d\n", Stack[Stack_size]);
  
  return 0;
}



Measured memory_bytes: 2724
import collections
N, K = map(int, input().split())
A = list(map(int, input().split()))

A = collections.Counter(A)
A = sorted(A.items(), key=lambda x:x[1])
cnt = A[:len(A)-K]

ans = []
for c in cnt:
    ans.append(c[1])
    
print(sum(ans))

Measured memory_bytes: 41648
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    long long n, m, min_value = LLONG_MAX;
    
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        min_value = min(min_value, temp);
        m -= temp;
    }
    
    cout << n + m / min_value << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int n;
  cin >> n;
  int inf = 51;
  vector<int> countsAll(26, inf);
  for (int i = 0; i < n; ++i) {
    string S;
    cin >> S;
    vector<int> count(26, 0);
    for (int j = 0; j < (int)S.size(); ++j) {
      count[S[j] - 'a']++;
    }
    for (int i = 0; i < 26; ++i) {
      countsAll[i] = min(countsAll[i], count[i]);
    }
  }

  string ans = "";
  for (int i = 0; i < 26; ++i) {
    if (countsAll[i] == inf) continue;
    for (int j = 0; j < countsAll[i]; ++j) {
      ans += (char)(i + 'a');
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))

#define INF 1000000000

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &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);
}

int main()
{
	int H;
	int N;
	int M;
	int L;
	int A[100000];
	int ans = 0;
	int flag = 0;


	scanf("%d%d",&H,&N);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
		ans += A[i];
	}

	if (ans >= H)
		printf("Yes");
	else
		printf("No");
}
		

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

using namespace std;

using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
 
template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}
 
template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

int n, maxim = -1e9;
string s;
map<string, int> M;

int main()
{
	ios_base::sync_with_stdio(false);

	cin>>n;
	for (int i=1; i<=n; i++)
	{
		cin>>s;
		M[s]++;
	}

	for (auto i : M)
	{
		maxim = max(maxim, i.second);
	}

	for (auto i : M)
	{
		if (i.second == maxim)
		{
			cout<<i.first<<'\n';
		}
	}

	return 0;
}

Measured memory_bytes: 23808
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

bool check(int N, int M, vector<vector<int>> a, int x) {
    vector<deque<int>> list(M);
    vector<bool> playable(M, true);
    vector<deque<int>> A(N);
    rep(i,N) rep(j,M) A[i].push_back(a[i][j]);
    rep(i,N) {
        int k = A[i].front(); A[i].pop_front();
        list[k].push_back(i);
    }
    while (true) {
        int flag = -1;
        int max_count = x;
        rep(i,M) {
            if (list[i].size() > max_count) {
                flag = i;
                max_count = list[i].size();
            }
        }
        if (flag < 0) {
            return true;
        }
        playable[flag] = false;

        while (!list[flag].empty()) {
            int i = list[flag].front(); list[flag].pop_front();
            while (true) {
                if (A[i].empty()) return false;
                int k = A[i].front(); A[i].pop_front();
                if (playable[k]) {
                    list[k].push_back(i);
                    break;
                }
            }
        }
    }
}

int main() {

    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N, vector<int>(M));
    rep(i,N) rep(j,M) {
        cin >> A[i][j];
        A[i][j]--;
    }

    for (int i = 1; i <= N; i++) {
        if (check(N, M, A, i)) {
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}

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

#define gap " "
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}

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

const int N=1000009;
const int sq=1100; //sieve size
int vis[sq+5],prime[sq],flag,ar[N];
map<int,int> mpp;
void sieve()
{
   int k=0; 
   for(int i=4; i<=sq; i+=2) vis[i]=1;
   prime[k++]=2;

   for(int i=3; i<=sq; i+=2){
        if(vis[i]==0){
            prime[k++]=i;
            for(int j=i+i; j<=sq; j+=i){
                vis[j]=1;
            }
        }
   }
}

void factor(int n)
{
    int idx=0,pf=prime[idx++];

    while(pf*pf<=n){
        if(n%pf==0)
        {
            while(n%pf==0) n/=pf;
            if(mpp.find(pf)!=mpp.end()){
            flag=1;
            return;
           }
            mpp[pf]=1;
        }
        pf=prime[idx++];
    }
    if(n!=1) {
        if(mpp.find(n)!=mpp.end()) {
            flag=1;
            return;
        }
        mpp[n]=1;
    }
}
int main()
{
    sieve();
    int n,i;
    flag=0;
    scanf("%d",&n);
    for(i=1; i<=n; i++){
        scanf("%d",&ar[i]);

        if(!flag) factor(ar[i]);
       
    }
    if(!flag){
        printf("pairwise coprime\n");
        return 0;
    }
   
    int gc=ar[1];
    for(i=2; i<=n; i++){
        gc=__gcd(gc,ar[i]);
    }
    gc==1? printf("setwise coprime\n"):printf("not coprime\n");
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  for (int i = 0; i < (int)s.size(); i++) {
    if (i % 2 == 0)
      cout << s.at(i);
  }
  
  return 0;
}

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

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main(){
    int N; cin >> N;
    if( N % 2 == 0 ) cout << N / 2 - 1 << endl;
    else cout << N / 2 << endl;
    
}

/*


*/


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    try {
      String s = scanner.next();
      String[] patterns = new String[] {
        "k.*eyence",
        "ke.*yence",
        "key.*ence",
        "keye.*nce",
        "keyen.*ce",
        "keyenc.*e",
      };

      for (String pattern: patterns) {
        if (s.matches(pattern)) {
          System.out.println("YES");
          return;
        }
      }
      System.out.println("NO");
    } finally {
      scanner.close();
    }
  }
}


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

using ll= long long;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

int main(){
    string S; cin >> S;
    int res=0;
    for(int i=0; i<S.size(); i++){
        for(int j=i; j<S.size(); j++){
            bool ok=true;
            for(int k=i; k<=j; k++){
                switch(S[k]){
                    case 'A':
                    case 'C':
                    case 'G':
                    case 'T':
                        break;
                    default:
                        ok=false;
                }
            }
            if(ok) res=max(res, j-i+1);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();

        if (a + b >= 2 && a + b <= 9) {
            System.out.println(a + b);
        } else if (a + b >= 10) {
            System.out.println("error");
        }
    }
}

Measured memory_bytes: 21972
// CPP program to find if x is a 
// perfect square. 
#include <iostream>
#include <math.h>       /* sqrt */
 
using namespace std; 

bool isPerfectSquare(long double x) 
{ 
// Find floating point value of 
// square root of x. 
long double sr = sqrt(x); 

// cout << " sr : " << sr << " floor(sr) : " << floor(sr) << endl;

// If square root is an integer 
return ((sr - floor(sr)) == 0); 
} 

int main() { 

    long double n;
    cin >> n;

    for (int i = n; i > 0; i--)
        if (isPerfectSquare(i)) {
            cout << i;
            break; 
        }

    return 0; 
} 


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

int main() {
  int A, B;
  cin >> A >> B;
  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=int(input())
    x,y= map(str, sys.stdin.readline().split(' '))
    ans=""
    for i in range(n):
        ans+=x[i]
        ans+=y[i]
    print(ans)
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
using namespace std;
int n,a=1,b=1000000000,x;
int p[20005],d[20005];
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",p+i);
        if(p[i]==1)x=i;
    }
    for(int i=0;i<n;i++){
        d[p[i]-1]=i-x;
    }
    for(int i=0;i<n;i++){
        a=1000000001+d[i]-b;
        printf("%d",a);
        if(i!=n-1)printf(" ");
        b-=20000;
    }
    printf("\n");
    b=1000000000;
    for(int i=0;i<n;i++){
        printf("%d",b);
        if(i!=n-1)printf(" ");
        b-=20000;
    }
    printf("\n");
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main(){

    string s;
    cin >> s;

    int n;
    n = s.size();
    bool flg = true;
    for(int i = 0; i < n; i++){
        if(s[i] != s[n-1-i]) flg = false;
    }
    for(int i = 0; i < (n-1)/2; i++){
        if(s[i] != s[((n-1)/2)-1-i]) flg = false;
    }
    for(int i = 0; i < n - ((n+3)/2); i++){
        if(s[((n+3)/2)-1+i] != s[n-1-i]) flg = false;
    }
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

const int MAX = 555;
const string COLORS = "RYGB";

int H, W, D;

void solve2() {
    REP (h, H) {
        REP (w, W) {
            cout << COLORS[(w+(h&2))%4];
        }
        cout << "\n";
    }
}

void solveOdd() {
    REP (h, H) {
        REP (w, W) {
            cout << COLORS[(w+h)%2];
        }
        cout << "\n";
    }
}

inline int diff(int h, int w, int ch, int cw) {
    return abs(h-ch) + abs(w-cw);
}

void solveEven() {
    int ch = D/2-1;
    int cw = D/2-1;
    REP (h, H) {
        REP (w, W) {
            int k = (w/D+h/D)%2;
            int hh = h-h/D*D;
            int ww = w-w/D*D;
            if (diff(hh,ww,ch,cw)<D/2 || diff(hh,ww,ch,cw+1)<D/2) {
                cout << COLORS[k];
            } else if ((hh-ch)*(ww-cw) > 0) {
                cout << COLORS[2+k];
            } else {
                cout << COLORS[3-k];
            }
        }
        cout << "\n";
    }
}

void solve() {
    if (D == 2) {
        solve2();
    } else if (D%2 == 1) {
        solveOdd();
    } else {
        solveEven();
    }
}

int main() {
    cin >> H >> W >> D;
    solve();
}

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

int main()
{
  double N,M;
  int l_A = 0; int l_B = 0; int l_C = 0; int l_D = 0;
  int r_A = 0; int r_B = 0; int r_C = 0; int r_D = 0;

  while(cin>>N>>M){

    if(N >= 1.1){
      ++l_A;
    }
    else if(N < 1.1 && N >= 0.6){
      ++l_B;
    }
    else if(N < 0.6 && N >= 0.2){
      ++l_C;
    }
    else{
      ++l_D;
    }

    if(M >= 1.1){
      ++r_A;
    }
    else if(M < 1.1 && M >= 0.6){
      ++r_B;
    }
    else if(M < 0.6 && M >= 0.2){
      ++r_C;
    }
    else{
      ++r_D;
    }
  }

  cout<<l_A<<" "<<r_A<<endl;
  cout<<l_B<<" "<<r_B<<endl;
  cout<<l_C<<" "<<r_C<<endl;
  cout<<l_D<<" "<<r_D<<endl;

  return 0;
}


Measured memory_bytes: 3040
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int N;
    cin >> N;
    int max;
    int y = 100000;
    for(int i=5; i>=0; i--){
        if(int(N / y) > 0){
            max = i;
            break;
        }
        y = y / 10;
    }
                        
    int num = 0;
    if(max % 2 == 0){
        int value = pow(10, max);
        num += N - value + 1;
        max -= 1;
        for(int i=max; i>0; i-=2){
        int value = pow(10, i) - 1;
        int value_lower = pow(10, i-1);
        num += value - value_lower + 1;
        }
    } else{
        for(int i=max; i>0; i-=2){
        int value = pow(10, i) - 1;
        int value_lower = pow(10, i-1);
        num += value - value_lower + 1;
        }
    }

    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
n,k=map(int, input().split())
mod = 10**9 + 7
ans = [0]*k
import math
ans[0]=(math.factorial(2+n-k-1) // (math.factorial(2+n-k-1-n+k) * math.factorial(n-k))) %mod

for i in range(1,k):#iは仕切りの数
    spl = math.factorial(k-1) // (math.factorial(k-1- i) * math.factorial(i))#仕切りのパターン
    rest = n-k-i
    if rest < 0:
        break
    if rest == 0:
        ans[i] = spl%mod
    else:
        ans[i] = (spl*(math.factorial(2+i+rest-1) // (math.factorial(2+i-1) * math.factorial(rest))))%mod
for i in ans:
    print(i)

Measured memory_bytes: 3444
# -*- coding: utf-8 -*-
from itertools import permutations
def  inpl(): return list(map(int, input().split()))

N, M = inpl()
OK = [0]*(M+1)

for i in range(N):
    for a in inpl()[1:]:
        OK[a] += 1
print(sum([ok == N for ok in OK]))

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

int main() {
  int N;
  cin >> N;
  
  long long ans=1;
  
  vector<long long> vec(N);
  for (int i = 0; i < N; i++) {
   cin >> vec.at(i);
   }
  
  
  for (int i = 0; i < N; i++) {
   if(vec.at(i)==0){
     cout<<0;
     return 0;
     }
   }
    
  for(int j = 0; j < N; j++){
   if(vec.at(j)>1000000000000000000/ans){
    cout<<-1;
    return 0;
      }
   ans=ans*vec.at(j);
   }
  
  cout << ans <<endl;
}

Measured memory_bytes: 4016
import scala.io.StdIn

object Main extends App {

  val Array(x1, y1, x2, y2) = StdIn.readLine().split(" ").map(_.toInt)

  val (x3, y3) = (x2 - (y2 - y1), y2 + (x2 - x1))
  val (x4, y4) = (x3 - (x2 - x1), y3 - (y2 - y1))

  println(s"$x3 $y3 $x4 $y4")
}


Measured memory_bytes: 27084
import copy
N, M = map(int, input().split())
key = [0] * M
bin_max = (2 ** N) 
dp = [[float('inf')] * (bin_max) ]
for i in range(M):
  a, _ =  map(int, input().split())
  c = list(map(int, input().split()))
  temp = 0
  for j in c:
    temp += (1 << (j-1))
  key[i] = ([a,temp])
  
for i in range(0,M):
  b = key[i][1]
  value = key[i][0]
  dp_low = copy.copy(dp[i])
  for j in range(1,bin_max):
    if j & b == j and dp_low[j] > value:
      dp_low[j] = value
    if dp_low[j] != float('inf'):
      next_b = j | b
      next= dp_low[j] + value
      if dp_low[next_b] > next:
        dp_low[next_b] = next
  dp.append(dp_low)
ans = -1 if dp[M-1][bin_max - 1] == float('inf') else dp[M-1][bin_max - 1]
print(ans)
      

      

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

int main(){
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum = 0;

    for(int i = 0; cin >> ch; i++){
        if(ch == '\\') S1.push(i);
        else if(ch == '/' && S1.size() > 0){
            int j = S1.top();
            S1.pop();
            sum += i - j;
            int a = i - j;
            while(S2.size() > 0 && S2.top().first > j){
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while(S2.size() > 0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();

    for(int i = 0; i < ans.size();i++){
        cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


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

int main(){
  string S;
  cin >> S;
  if(S.at(0)!=S.at(1) && S.at(1)!=S.at(2) && S.at(2)!=S.at(0)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
a, b = map(int, input().split())
n = b - a + 1
if ( (a<=0 and b>=0) or (a==0) or (b==0) ):
    print('Zero')
    sys.exit(0)
if a>0 or n%2 == 0:
    print('Positive')
    sys.exit(0)
print('Negative')
    

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cstring>
using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
//////////////////////

#ifdef _DEBUG
int const N = 41;
#else
int const N = 2e5 + 41;
#endif
int const MOD = 1e9 + 7;

int n, p[N], ans, two[N];
vector<int> vh[N];
vector<int> e[N];

void add(int &a, int b){
	a += b;
	if(a >= MOD) a -= MOD;
}

int mul(int a, int b){
	return a * 1LL * b % MOD;
}

namespace lca{
	int const L = 17;
	int lca[N][L], q, tin[N], tout[N], h[N];

	void dfs(int x, int p = -1){
		vh[h[x]].pb(x);
		++q;
		tin[x] = q;
		fi(0, L) lca[x][i] = -1;
		lca[x][0] = p;
		fi(1, L){
			int pp = lca[x][i-1];
			if(pp != -1) lca[x][i] = lca[pp][i-1];
		}
		fi(0, sz(e[x])){
			int y = e[x][i];
			h[y] = h[x] + 1;
			dfs(y, x);
		}
		++q;
		tout[x] = q;
	}

	bool isa(int x, int y){
		return tin[x] <= tin[y] && tout[x] >= tout[y];
	}

	int getlca(int x, int y){
		if(isa(x, y)) return x;
		if(isa(y, x)) return y;
		fdi(L, 0){
			if(lca[x][i] == -1 || isa(lca[x][i], y)) continue;
			x = lca[x][i];
		}
		return lca[x][0];
	}

	void build(){
		dfs(0);
	}
};

set<int> v;
vector<int> e0[N];
int p0[N];

int buildtree(){
	vector<pii> a;
	for(int x : v){
		a.pb(mp(lca::tin[x], x));
	}
	sort(a.begin(), a.end());
	set<pii> b;
	fi(0, sz(a)){
		int x = a[i].second;
		set<pii> :: iterator it = b.upper_bound(mp(lca::tout[x], -1));
		if(it == b.end()) p0[x] = -1;
		else{
			p0[x] = (*it).second;
			e0[p0[x]].pb(x);
		}
		b.insert(mp(lca::tout[x], x));
	}
	return a[0].second;
}

void clear(){
	for(int x : v){
		e0[x].clear();
	}
	v.clear();
}

int d0[N][2];
int d1[N][3];

void dfs(int x){
	memset(d0[x], 0, sizeof(d0[x]));
	int m = sz(e0[x]);
	fi(0, m){
		int y = e0[x][i];
		dfs(y);
	}
	fi(0, m+1) fo(0, 3) d1[i][o] = 0;
	d1[0][0] = 1;
	fi(0, m){
		int y = e0[x][i];
		fo(0, 3){
			for(int o1=0;o1<2;++o1){
				int no = o + o1;
				no = min(no, 2);
				int v0 = d0[y][o1];
				int v1 = d1[i][o];
				int v = mul(v0, v1);
				add(d1[i+1][no], v);
			}
		}
	}
	if(sz(e0[x]) == 0){
		d0[x][0] = 1;
		d0[x][1] = 1;
	}else{
		fo(0, 3){
			add(d0[x][(o%2)], d1[m][o]);
		}
	}
}

void solve(){
	two[0] = 1;
	fi(1, N) two[i] = mul(2, two[i-1]);
	fi(1, n+1){
		e[p[i]].pb(i);
	}
	lca::build();
	fi(0, N){
		if(sz(vh[i]) > 0){
			fj(0, sz(vh[i])){
				v.insert(vh[i][j]);
				if(j){
					v.insert(lca::getlca(vh[i][j], vh[i][j-1]));
				}
			}
			//
			/*fj(0, sz(vh[i])){
				fo(0, sz(vh[i])){
					v.insert(lca::getlca(vh[i][j], vh[i][o]));
				}
			}*/
			//
			int r = buildtree();
			dfs(r);
			int v0 = two[n+1-sz(vh[i])];
			int v1 = d0[r][1];
			//cerr << i << " " << mul(v0, v1) << endl;
			add(ans, mul(v0, v1));
			clear();
		}
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fi(1, n+1){
		scanf("%d",&p[i]);
	}

	solve();

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

	return 0;
}

Measured memory_bytes: 57300
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;

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

    int H, W, h, w;

    cin >> H >> W >> h >> w;

    if (!(H % h) && !(W % w))
    {
        cout << "No" << endl;
        return 0;
    }

    int res[510][510];

    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            res[i][j] = 1;

    ll sum = H * W;

    for (int i = h - 1; i < H; i += h)
        for (int j = w - 1; j < W; j += w)
            res[i][j] = -h * w, sum -= h * w + 1;

    ll a = H * W - (H - H % h) * (W - W % w);

    ll add = max(0LL, (1LL - sum + a - 1) / a);

    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            if (res[i][j] > 0)
                res[i][j] += add;
            else
                res[i][j] -= (h * w - 1) * add;

    cout << "Yes" << endl;

    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            cout << res[i][j] << (j == W - 1 ? "\n" : " ");

    return 0;
}

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

#define read(num) scanf("%d", &num)
#define readll(num) scanf("%lld", &num)
#define read2(num1, num2) scanf("%d%d", &num1, &num2)
#define read3(num1, num2, num3) scanf("%d%d%d", &num1, &num2, &num3)
#define reads(str) scanf("%s", str)
#define readc(ch) scanf("%c", &ch)

#define pb push_back
#define mp make_pair

#define pii pair<int, int>
#define vi vector<int>
#define ll long long

int need[2001][10];
vector<vector<int>>dp;

int main()
{
       int h1,s1,h2,s2;
       cin>>h1>>s1>>h2>>s2;
       int h=0;
       while(1){
           if(h){
               h1-=s2;
           }else {
               h2-=s1;
           }
           if(h1<=0){
               cout<<"No";
               break;
           }else if(h2<=0){
               cout<<"Yes";
               break;
           }
           h=!h;
       }
}


Measured memory_bytes: 3624
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int w[] = new int[N];
        int v[] = new int[N];
        int dp[][] = new int[N+1][W+1];
        for(int i = 0 ; i <= W ; i++)
            dp[0][i] = 0;
        for(int i = 0 ; i < N ; i++){
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }
        for(int i = 0 ; i < N ; i++){
            for(int j = 0 ; j <= W ; j++){
                if(w[i] <= j)
                    dp[i+1][j] = Math.max(dp[i][j-w[i]]+v[i] , dp[i][j]);
                else
                    dp[i+1][j] = dp[i][j];
            }
        }
        System.out.println(dp[N][W]);
    }
}


Measured memory_bytes: 30972
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int h, w;
int a[88][88], b[88][88];
bool dp[88][88][160*160+1];

int main()
{
    cin>>h>>w;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++) cin>>a[i][j];
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++) cin>>b[i][j];
    }
    const int m=160*80;
    dp[0][0][m+a[0][0]-b[0][0]]=1;
    dp[0][0][m+b[0][0]-a[0][0]]=1;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            for(int k=0; k<=2*m; k++){
                if(!dp[i][j][k]) continue;
                if(i+1<h){
                    if(k+a[i+1][j]<=2*m){
                        dp[i+1][j][k+a[i+1][j]-b[i+1][j]]=1;
                    }
                    if(k-b[i+1][j]>=0){
                        dp[i+1][j][k+b[i+1][j]-a[i+1][j]]=1;
                    }
                }
                if(j+1<w){
                    if(k+a[i][j+1]<=2*m){
                        dp[i][j+1][k+a[i][j+1]-b[i][j+1]]=1;
                    }
                    if(k-b[i][j+1]>=0){
                        dp[i][j+1][k+b[i][j+1]-a[i][j+1]]=1;
                    }
                }
            }
        }
    }
    int ans=m;
    for(int i=0; i<=2*m; i++){
        if(dp[h-1][w-1][i]){
            ans=min(ans, abs(i-m));
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += 2 * min(x[i], k - x[i]);
    }
    cout << ans << endl;
}


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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main() {
	int k;
	cin >> k;
	ll ans = 0;
	for(int a = 1; a <= k; a++){
		for(int b = 1; b <= k; b++){
			for(int c = 1; c <= k; c++){
				ans += gcd(gcd(a, b), c);
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  if ((A+B)%2==0) {
    cout << (A+B)/2 << endl;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 3500