akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n; cin >> n;
    int ans = 0;
    rep(i,n) {
        int tmp;
        cin >> tmp;
        if (i % 2 == 0 && tmp % 2 == 1)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    int mas[100010] = {};
    int ka[100010] = {};
    ka[0] = 1;
    for(int i = 0;i < n;i++) mas[i] = 1;

    int x, y;
    for(int i = 0;i < m;i++){
        cin >> x >> y;
        x--;
        y--;

        mas[x]--;

        mas[y]++;

        if(ka[x] == 1){
            ka[y] = 1;
        }

        if(mas[x] == 0){
            ka[x] = 0;
        }
    }

    int ans = 0;
    for(int i = 0;i < n;i++){
        ans += ka[i];
    }

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






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

int main()
{
  int64_t a, yes = 1;
  vector<int64_t> C(4, 0);
  for (int i = 0; i < 6; i++)
  {
    cin >> a;
    a--;
    C.at(a)++;
  }
  for (auto c : C)
  {
    if (c == 0 || c == 3)
      yes = 0;
  }
  cout << (yes ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n;
  cin >> n;
  vector<int> v = input(n);
  rep(i,n){
    if(v[i]%2 == 0 && v[i]%3 != 0 && v[i]%5 != 0){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

signed main() {
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> bs(m);
    rep(i, m) cin >> bs[i];
    int ans = 0;
    rep(i, n) {
        int sum = 0;
        for(auto& b: bs) {
            int a;
            cin >> a;
            sum += a*b;
        }
        if(sum + c > 0) ++ans;
    }
    cout << ans << nl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==25)cout<<"Christmas"<<endl;
    if(n==24)cout<<"Christmas Eve"<<endl;
    if(n==23)cout<<"Christmas Eve Eve"<<endl;
    if(n==22)cout<<"Christmas Eve Eve Eve"<<endl;
}


Measured memory_bytes: 256
import java.text.DecimalFormat;
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
//        sc.useDelimiter(",");
        DecimalFormat df = new DecimalFormat("0.00000000");
        while (true) {
            int n = Integer.parseInt((sc.next()));
            if (n == 0) break;
            int[] s = new int[n];
            for (int i = 0; i < n; i++)
                s[i] = Integer.parseInt((sc.next()));
            out.println(df.format(Math.sqrt(var(s, n))));
        }
        out.flush();
    }
    public static double avg(int[] a, int n) {
        double sum = 0.0;
        for (int i=0; i<n; i++)
            sum += a[i];
        return (sum / n);
    }
    public static double var(int[] a, int n) {
        double sum = 0.0;
        for (int i=0; i<n; i++)
            sum += (a[i]-avg(a,n))*(a[i]-avg(a,n));
        return (sum / n);
    }
}


Measured memory_bytes: 32236
/* #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int mo = 1e9 + 7, sz = 1e5 + 100;
typedef long long ll;
ll a, ans, arr[sz];

void solve()
{
    for (int i = 1; i <= a; i++)
        if (arr[i] == i)
        {
            swap(arr[i + 1], arr[i]);
            ans++;
        }
}
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    ans = 0;
    scanf("%lld", &a);
    for (int i = 1; i <= a; i++)
        scanf("%lld", arr + i);
    solve();
    printf("%lld\n", ans);
    return 0;
} */
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
int n,q,k;
const int sz=1e6;
vector<P> edge[sz];
ll L[sz];
void dfs(int v,int u,ll sum)
{
    L[v]=sum;
    rep(i,edge[v].size())
    {
        if(edge[v][i].first==u)continue;
        dfs(edge[v][i].first,v,sum+1LL*edge[v][i].second);
    }
}
main()
{
    cin.tie(0);ios_base::sync_with_stdio(0);
    cin>>n;
    rep(i,n-1)
    {
        int a,b,c;
        cin>>a>>b>>c;
        edge[a].push_back(make_pair(b,c));
        edge[b].push_back(make_pair(a,c));
    }
    cin>>q>>k;
    dfs(k,-1,0LL);
    rep(i,q)
    {
        int a,b;cin>>a>>b;
        cout<<L[a]+L[b]<<endl;
    }
    return 0;
}

Measured memory_bytes: 37120
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e3+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	for (int i = 0; i < n; cin >> a[i++]);
	for (int i = 0; i < n; cin >> b[i++]);
	for (int i = 0; i < n; cin >> c[i++]);
	sort(a, a + n), sort(b, b + n), sort(c, c + n);
	ll acc[n];
	int low = 0, high, mid, val;
	for (int i = 0; i < n; i++)
	{
		low = 0, high = n - 1, val = n;
		while(low <= high)
		{
			mid = (low + high) / 2;
			if (b[i] < c[mid])
				high = mid - 1, val = mid;
			else
				low = mid + 1;
		}
		acc[i] = n - val;
	}
	for (int i = n - 2; i >= 0; i--)
		acc[i] += acc[i + 1];
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		low = 0, high = n - 1, val = -1;
		while(low <= high)
		{
			mid = (low + high) / 2;
			if (a[i] < b[mid])
				high = mid - 1, val = mid;
			else
				low = mid + 1;
		}
		if (~val)
			ans += acc[val];
	}
	cout << ans;
	return 0;
}


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

string weekday[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int monthday[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main(void){

	while (true){
		int m, d, days=0;
		cin>>m>>d;
		if (m==0) break;
		for (int i=0; i<m-1; i++){
			days += monthday[i];
		}
		int dif = days + d - 1;
		cout<<weekday[(dif+3)%7]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll x,kp,y,n,sg[3][100005],inv2=499122177,qz[100005],mr,ans=0;
const ll mx=1<<17,m=17;
ll aq[mx],a[2][mx],ok[mx];
const ll mod=998244353;
vector<int>s[3][100005];
ll M(ll x){return x>=mod?x-mod:x;}
void solve(int ty)
{
	int vis[100005]={0},v;
	scanf("%lld",&kp);
	for(int i=1;i<=kp;i++)
	{
		scanf("%lld%lld",&x,&y);
		if(x>y)swap(x,y);
		s[ty][x].push_back(y);
	}
	for(int i=n-1;i>0;i--)
	{
		for(int j=0;j<s[ty][i].size();j++)
		{
			v=s[ty][i][j];
			vis[sg[ty][v]]=i;
		}
		for(sg[ty][i]=0;vis[sg[ty][i]]==i;sg[ty][i]++);
	}
}
int main()
{
	qz[0]=1;
	mr=1000000000000000000%mod;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)qz[i]=qz[i-1]*mr%mod;
	solve(0);
	solve(1);
	solve(2);ok[0]=0;
	for(int i=1;i<mx;i++)
	{
		for(int j=0;j<m;j++)
		{
			if((1<<j)&i)
			{
				ok[i]=1-ok[i-(1<<j)];
				break;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		aq[sg[0][i]]=(aq[sg[0][i]]+qz[i])%mod;
		a[0][sg[1][i]]=(a[0][sg[1][i]]+qz[i])%mod;
		a[1][sg[2][i]]=(a[1][sg[2][i]]+qz[i])%mod;
	}
	for(int i=0;i<mx;i++)if(ok[i]==1)a[0][i]=M(mod-a[0][i]),a[1][i]=M(mod-a[1][i]);
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<mx;j++)
		{
			if(j&(1<<i))
			{
				x=a[0][j];y=a[0][j-(1<<i)];
				a[0][j]=M(a[0][j]+y);
				a[0][j-(1<<i)]=M(a[0][j-(1<<i)]+mod-x);
				x=a[1][j];y=a[1][j-(1<<i)];
				a[1][j]=M(a[1][j]+y);
				a[1][j-(1<<i)]=M(a[1][j-(1<<i)]+mod-x);
			}
		}
	}
	for(int j=0;j<mx;j++)a[0][j]=a[0][j]*a[1][j]%mod;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<mx;j++)
		{
			if(j&(1<<i))
			{
				x=a[0][j];y=a[0][j-(1<<i)];
				a[0][j]=(x-y+mod)*inv2%mod;
				a[0][j-(1<<i)]=(x+y)*inv2%mod;
			}
		}
	}
	for(int i=0;i<mx;i++)if(ok[i]==1)a[0][i]=M(mod-a[0][i]);
	for(int i=0;i<mx;i++)ans=(ans+aq[i]*a[0][i])%mod;
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 20224
#include<stdio.h>
int main()
{
    int t,n,i,max=0,sum=0;
    scanf("%d",&t);
    for(i=1;i<=t;i++)
    {
        scanf("%d",&n);
        sum +=n;
        if(n>max)
        {
            max=n;
        }
    }
    if(sum-max>max)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
n, q = map(int, input().split())
s = input()
cnt = 0
cumsum = [0,0]
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        cnt += 1
    cumsum.append(cnt)
for _ in range(q):
    l, r = map(int, input().split())
    print(cumsum[r] - cumsum[l])

Measured memory_bytes: 6096
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int main()
{
    int n,k;
    char in[505];
    while (~scanf("%d %d", &n,&k)) {
        scanf("%s", in+1);
        REP(i,1,n) {
            if (i==k) putchar(in[i]+32);
            else putchar(in[i]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    string S;
    cin >> S;
    if( S.back() == '2' || S.back() == '4' ||S.back() == '5' ||S.back() == '7' ||S.back() == '9'){
        cout << "hon" << endl;
    }else if(S.back() == '0' ||S.back() == '1' ||S.back() == '6' ||S.back() == '8'){
        cout << "pon" << endl;
    }
    else{
        cout << "bon" << endl;
    }
   return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>

#define MOD 1000000007
using namespace std;
typedef long long ll;
ll kai[200001], inv[200001];
ll n, k;
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2;
  }
  return res;
}
void init() {
  kai[0] = 1LL;
  for (ll i = 1LL; i <= 200000; i++) {
    kai[i] = kai[i - 1] * i;
    kai[i] %= MOD;
  }
  inv[200000] = mod_pow(kai[200000], MOD - 2LL, MOD);
  for (ll i = 199999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1);
    inv[i] %= MOD;
  }
}

ll comb(ll r, ll c) {
  ll res;
  res = kai[r];
  res *= inv[c];
  res %= MOD;
  res *= inv[r - c];
  res %= MOD;
  return res;
}
int main() {
  ll a[100001];
  ll ans = 0;
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  if (k == 1) {
    printf("0\n");
    return 0;
  }
  sort(a, a + n);
  a[n] = a[n - 1] + 1;
  init();
  for (ll i = 0; i < n; i++) {
    if (i >= k - 1) {
      ll y = a[i];
      if (a[i] < 0) {
        y = MOD + a[i];
        y %= MOD;
      }
      y *= comb(i, k - 1);
      y %= MOD;
      ans += y;

      ans %= MOD;
    }
    if (n - i >= k) {
      ll y = a[i];
      if (a[i] < 0) {
        y = MOD + a[i];
        y %= MOD;
      }
      y *= comb(n - i - 1, k - 1);
      y %= MOD;

      y = MOD - y;
      y %= MOD;
      ans += y;
      ans %= MOD;
    }
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 4096
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
  
#define mp make_pair
#define f first
#define s second
#define ll long long
#define pb push_back
#define popb pop_back
#define popf pop_front

using namespace std;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int inf = 2e9+7, mod=1e9+7;
const int N = 1e6+321, E=14e5;

ll xx[8]={1, 1, -1, -1, 1, -1, 0, 0};
ll yy[8]={1, -1, 1, -1, 0, 0, 1, -1};

string s[10];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	int n, m;
	cin >> n >> m;
	if(n*2<=m && n*4>=m && m%2==0)
		cout << "Yes";
	else
		cout << "No";
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  ll N, A, B;
  cin >> N >> A >> B;

  ll div = N/(A+B);
  ll rem = N%(A+B);
  ll ans = 0;

  ans += div*A;
  ans += min(A, rem);

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

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

int main()
{

        int n;
        string s,t;
        cin >> n;
        cin >> s >> t;

        string r;
        for (int i = 0; i < n; ++i) {

                cout << s[i] << t[i];

        }
        cout << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  int k;
  cin >> k;
  if(k % 2 == 0) cout << k*k/4 << endl;
  else cout << k/2 * (k/2+1) << endl;
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  9 20:53:23 2020

@author: H_Hoshigi
"""

N, K = map(int, input().split())
p_list = list(map(int, input().split()))
E_list = [(1+p)/2 for p in p_list]

moving_sum_E_K_list = [sum(E_list[0:K])]
max_msEK = moving_sum_E_K_list[0]
for i in range(N-K):
    msEK = moving_sum_E_K_list[-1] - E_list[i] + E_list[K+i]
    moving_sum_E_K_list.append(msEK)
    max_msEK = max(max_msEK, msEK)

print(max_msEK)
#print(p_list)
#print(E_list)
#print(moving_sum_E_K_list)


Measured memory_bytes: 24812
#include <stdio.h>
using namespace std;



int main()
{
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        int A;
        scanf("%d", &A);
        if (A % 2 == 0) {
            if (A % 5 == 0 || A % 3 == 0) {

            } else {
                printf("DENIED\n");
                return 0;
            }
        }
    }
    printf("APPROVED\n");
    
    return 0;
}


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

l={}
ans=[]

for i in range(n):
    ope,let=input().split()

    if ope=='insert':
        l[let]=0
    else:
        if let in l:
            ans.append("yes")
        else:
            ans.append("no")

for h in ans:
    print(h)


Measured memory_bytes: 37104
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

typedef long long ll;

const int MAXN = 100005;

struct Edge
{
	int to;
	int nxt;
}edge[MAXN << 1];

int n,id;
int a[MAXN];
int first[MAXN];
int deg[MAXN];

ll v1[MAXN];
ll v2[MAXN];

void addE(int u,int v)
{
	edge[++id] = (Edge){v,first[u]};
	first[u] = id;
	deg[v]++;
}

void dfs(int u,int fa)
{
	if (deg[u] == 1)
	{
		v1[u] = -a[u];
		v2[u] = a[u];
		return;
	}
	ll MAX = 0;
	for (int i = first[u];i;i = edge[i].nxt)
		if (edge[i].to != fa)
		{
			dfs(edge[i].to,u);
			v1[u] += v1[edge[i].to];
			v2[u] += v2[edge[i].to];
			MAX = max(MAX,v2[edge[i].to]);
		}
	ll tmp = v1[u];
	v1[u] = -v1[u] - a[u];
	if (v1[u] < 0)
	{
		puts("NO");
		exit(0);
	}
	if ((MAX << 1) > v2[u])
		MAX = v2[u] - MAX;
	else
		MAX = v2[u] >> 1;
	if (MAX < v1[u])
	{
		puts("NO");
		exit(0);
	}
	v2[u] -= v1[u] << 1;
	v1[fa] += v1[u];
	v1[u] += tmp;
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	for (int i = 1;i <= n;i++)
		cin >> a[i];
	for (int u,v,i = 1;i < n;i++)
	{
		cin >> u >> v;
		addE(u,v);
		addE(v,u);
	}
	if (n == 2)
	{
		puts(a[1] == a[2] ? "YES" : "NO");
		return 0;
	}
	for (int i = 1;i <= n;i++)
		if (deg[i] > 1)
		{
			dfs(i,0);
			puts(v2[i] ? "NO" : "YES");
			return 0;
		}
	return 0;
}

Measured memory_bytes: 8576
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main()
{
    int n;
    int k;
    cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int w;
        cin >> w;
        v.push_back(w);
    }

    auto sum_ = accumulate(begin(v), end(v), 0);
    auto max_ =
        accumulate(begin(v), end(v), 0, [](int z, int c) { return max(z, c); });

    int l{max_};
    int r{sum_};
    int m{0};
    auto check = [&v, k](int p) {
        int count{1};
        int payload{0};
        for (auto&& i : v) {
            payload += i;
            if (payload > p) {
                count += 1;
                payload = i;
                if (count > k) {
                    return false;
                }
            }
        }
        return true;
    };
    while (l < r) {
        m = l + (r - l) / 2;
        if (check(m)) {
            r = m;
        }
        else {
            l = m + 1;
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 3524
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[2][102];
    a[0][0] = 0;
    a[1][n+1] = 0;
    for(int i=1; i<=n; ++i) {
        int aa;
        cin >> aa;
        a[0][i] = a[0][i-1] + aa;
    }
    for(int i=1; i<=n; ++i) {
        int aa;
        cin >> aa;
        a[1][i] = aa;
    }
    for(int i=n; i>0; --i) {
        a[1][i] = a[1][i] + a[1][i+1];
    }
    int max = 0;
    for(int i=1; i<=n; ++i) {
        int sum = a[0][i] + a[1][i];
        max = (sum>max) ? sum : max;
    }
    cout << max << endl;
}

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

using namespace std;

int digitSum(int);

int main(void){
    int N;
    cin >> N;
    if(N%digitSum(N) == 0){
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

//aの各桁の和を求める
int digitSum(int a){
    if(a == 0){
        return 0;
    }
    return a%10 + digitSum(a/10);
}

Measured memory_bytes: 256
h,w = map(int,input().split())
s = [str(input()) for i in range(h)]

dxdy = {(-1, 0), (1, 0), (0, -1), (0, 1)}

ch = [[0] * w for i in range(h)]

ans = 0

for i in range(h):
    for j in range(w):
        if ch[i][j] == 0:
            black,white = 0,0
            q = [(i,j)]
            while q:
                y,x = q.pop()
                if ch[y][x] == 0:
                    if s[y][x] == "#":black += 1
                    else:white += 1
                    ch[y][x] = 1
                    for dx,dy in dxdy:
                        if 0 <= x + dx < w and 0 <= y + dy < h and ch[y+dy][x+dx] == 0 and s[y+dy][x+dx] != s[y][x]:
                            q.append((y+dy,x+dx))
            ans += black * white

print(ans)

Measured memory_bytes: 19520
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define all(V) V.begin(),V.end()

int main() {
	ll N, H, a, b, ma = 0, mb = 0;
	cin >> N >> H;
	vector<P> S(N);
	for (int i = 0;i < N;i++) {
		cin >> a >> b;
		S[i] = { b,a };
		if (ma < a) {
			ma = a;
			mb = b;
		}
		else if (ma == a) {
			if (mb > b)
				mb = b;
		}
	}
	sort(all(S));
	a = H;
	ll ans = 0;
	for (int i = 1;i <= N;i++) {
		if (S[N - i].first <= ma) {
			ans = (a - 1) / ma + i;
			break;
		}
		a -= S[N - i].first;
		if (a <= 0) {
			ans = i;
			break;
		}
		if (i == N) {
			ans = (a - 1) / ma + i + 1;
			break;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

vector<int> g[100010];

int solve(int cur) {
	vector<int> tmp;
	for (int nex : g[cur]) {
		tmp.push_back(solve(nex));
	}
	int res = 0;
	sort(tmp.rbegin(), tmp.rend());
	for (int i = 0; i < tmp.size(); i++) {
		res = max(res, tmp[i] + i + 1);
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a;
		cin >> a;
		a--;
		g[a].push_back(i);
	}
	cout << solve(0) << endl;
	return 0;
}

Measured memory_bytes: 15104
import itertools
N, M, Q = map(int, input().split())
m = list()
res = -100
for i in range(Q):
    n = list(map(int, input().split()))
    m.append(n)
l = [x for x in range(1, M + 1)]
p = itertools.combinations_with_replacement(l, N)
for p in p:
    total = 0
    for i in range(Q):
        a = m[i][0]
        b = m[i][1]
        A = p[a - 1]
        B = p[b - 1]
        C = B - A
        if m[i][2] == C:
            total = total + m[i][3]
    if res < total:
        res = total
print(res)

Measured memory_bytes: 9232
#include <iostream>

using namespace std;

int main() {
	int n, x;
	int cnt;

	cin >> n >> x;

	while(n != 0 || x != 0) {
		cnt = 0;

		for(int i = 1;i <= n;i++) {
			for(int j = i + 1;j <= n;j++) {
				for(int k = j + 1;k <= n;k++) {
					if((i + j + k) == x) {
						cnt++;
					}
				}
			}
		}

		cout << cnt << endl;
		cin >> n >> x;
	}

	return 0;
}

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

using ll =                   long long int;
using pll =                  pair<ll, ll>;
#define endl                 "\n"
#define space                " "
#define TLE_na_ho            ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MAX_SIZE             1024
#define MOD                  1000000007
#define pb                   push_back
#define fi                   first
#define se                   second
#define f(a,n)               for(ll i=a;i<n;i++)
#define fe(a,n)              for(ll i=a;i<=n;i++)
#define fr(a,n)              for(ll i=a;i>=n;i--)
#define ain(arr,n)           for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n)          for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<space


int main()
{
    TLE_na_ho;
    double t,s,d;
    cin>>d>>t>>s;
    if((d/s)<=t)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
}


Measured memory_bytes: 3736
def solve():
    i = 1
    ans = 'Yes'
    for x in S:
        if i % 2 == 1:
            if S[i-1] == 'L':
                ans = 'No'
                break
        else:
            if S[i-1] == 'R':
                ans = 'No'
                break
        i += 1
    print(ans)

S = str(input())
solve()

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

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  int a[n];
  for (int i=0;i<n;i++){
    cin >> a[i];
  }
  int count=0;
  for (int i=0;i<n;i++){
    count=count+(d-1)/a[i]+1;
  }
  cout << count+x << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

            if (!isValid(A, N)) {
                System.out.println(0);
                return;
            }

            final long mod = (long) (1e9 + 7);

            long count = 1;
            boolean[] used = new boolean[N];
            for (int i = 0; i < N; i++) {
                if (used[A[i]]) {
                    continue;
                }
                used[A[i]] = true;
                if (A[i] > 0) {
                    count *= 2;
                    count %= mod;
                }
            }

            System.out.println(count);
        }
    }

    private static boolean isValid(int[] A, int N) {
        int[] counts = new int[N];
        for (int i = 0; i < N; i++) {
            counts[A[i]]++;
        }

        if (N % 2 == 1) {
            if (counts[0] != 1) {
                return false;
            }
            for (int i = 1; i < counts.length; i++) {
                if (i % 2 == 0) {
                    if (counts[i] != 2) {
                        return false;
                    }
                } else {
                    if (counts[i] != 0) {
                        return false;
                    }
                }
            }
        } else {
            for (int i = 0; i < counts.length; i++) {
                if (i % 2 == 1) {
                    if (counts[i] != 2) {
                        return false;
                    }
                } else {
                    if (counts[i] != 0) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
}


Measured memory_bytes: 49360
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

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

ll mod(ll n) { return n % MOD; }

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

  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) cin >> a[i];

  ll sum = 0;
  for (int i = 0; i < 61; i++) {
    ll c1 = 0;
    for (int j = 0; j < n; j++) {
      if ((a[j] & (1ll << i)) != 0) ++c1;
    }
    ll c0 = (n - c1);
    sum = mod(sum + mod(mod(1ll << i) * mod(c0 * c1)));
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 2560
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n,m,r;
    cin>>n>>m>>r;
    vector<int> a(r);
    rep(i,r){
        cin>>a[i];
        a[i]--;
    }
    vector<int> dist[n];
    rep(i,n) dist[i].assign(n,INF);
    
    rep(i,n) dist[i][i] = 0;

    rep(i,m){
        int f,j,k;
        cin>>f>>j>>k;
        f--;j--;
        dist[j][f]=k;
        dist[f][j]=k;
    }
    
    rep(k,n){
        rep(i,n){
            rep(j,n){
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }
    sort(rall(a));
    Vi end=a;
    sort(all(a));
    ll ans=0;
    rep(i,r-1) ans+=dist[a[i]][a[i+1]];
    while(true){
        next_permutation(all(a));
        int memo=0;
        rep(i,r-1) memo+=dist[a[i]][a[i+1]];
        ans=min(ans,memo);
        if(a==end) break;
    }
    cout<<ans<<endl;
}

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

using namespace std;

int gcd(int x, int y){
    int a = max(x, y), b = min(x, y);
    if(a % b == 0){
	return b;
    }else{
	return gcd(a % b, b);
    }
}

int main(){
    int x, y;
    cin >> x >> y;

    cout << gcd(x, y) << endl;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int A,B;
  
  char op;
  
  cin >> A >> op >> B;
  
  if(op=='+'){
  	cout << A+B << endl;
  }else{
  	cout << A-B << endl;
  }
  
}


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

const int INF = (int)(2e+9);
int N, M;
vector<int> A;
vector<int> B;
vector<int> dp;

void input_init(void) {
	cin >> N >> M;
	A.resize(M);
	B.resize(M, 0);
	for (int j = 0; j < M; ++j) {
		int b;
		cin >> A[j] >> b;
		for (int i = 0; i < b; ++i) {
			int c;
			cin >> c;
			B[j] += (1 << (c - 1));
		}
	}
}

void solve(void) {
	dp.resize(1 << N, INF);
	dp[0] = 0;
	for (int i = 0; i < (1 << N); ++i) {
		for (int j = 0; j < M; ++j) {
			int m = i | B[j];
			dp[m] = min(dp[i] + A[j], dp[m]);
		}
	}
}

int main(void) {
	input_init();
	solve();
	int ans = dp[(1 << N) - 1];
	if (ans == INF)
		ans = -1;
	cout << ans << '\n';
	return 0;
}


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

int main() {
    // 入力
    int N, W;
    cin >> N >> W;
    vector<int>w(N);
    vector<int>v(N);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    // i+1番目以降で重さjの時の価値の最大値がdp[i][j]
    // jは普通に0からWまで必要、i=Nは dp[N][j]=0 を使って初項代入をループに埋め込むためのもの
    vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));
    for (int i = N-1; i >= 0; --i) {
        for (int j = 0; j <= W; ++j) {
            if(j < w[i]){
                dp[i][j] = dp[i+1][j];
            }else{
                dp[i][j] = max(dp[i+1][j], dp[i+1][j - w[i]] + v[i]);
            }
        }
    }
    cout << dp[0][W];
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

template<typename T>
T gcd(T a, T b) {
	if( a < b ) swap(a, b);
	
	T r;
	while( r = a % b ) {
		a = b;
		b = r;
	}
	
	return b;
}

int main(void) {
	int m;
	cin >> m;
	
	int ans = 0;
	for(int i = 1; i <= m; ++i) {
		for(int j = 1; j <= m; ++j) {
			for(int k = 1; k <= m; ++k) {
				ans += gcd(i, gcd(j, k));
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main()
{
    int i,n,mn,c=0;
    cin >> n;
    int a[n];
    for(i=0; i<n; i++)
    {
        cin >> a[i];
    }
    mn=a[0];
    for(i=0; i<n; i++)
    {
        if(mn>=a[i])
        {
            c++;
            mn=a[i];
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 4412
#include <stdio.h>
#include <math.h>

int main(void){
	
	int line[3];
	int wk;
	int i, j;
	int a_plus_b, b_minus_a;
	int la, lb, lc;
	int ei=0, tyo=0, don=0, san=0;
	
	while(scanf("%d%d%d", &line[0], &line[1], &line[2])){
	
	for(i=0; i<2; i++){
		for(j=0; j<(2-i); j++){
			if(line[j] > line[j+1]){
				wk = line[j];
				line[j] = line[j+1];
				line[j+1] = wk;
			}
		}
	}

	a_plus_b = line[0] + line[1];
	b_minus_a = line[1] - line[0];
	
	la = line[0]*line[0]; lb = line[1]*line[1]; lc = line[2]*line[2];

		if((line[2] >= a_plus_b) || (line[2] <= b_minus_a)){
			printf("%d %d %d %d\n", san, tyo, ei, don);
			break;
	}
	
	if(lc > (la + lb)) {
		don++; san++;
		continue;
		return 0;
	}
	
	if(lc == (la + lb)) {
		tyo++; san++;
		continue;
		return 0;
	}
	
	if(lc < (la + lb)){
		ei++; san++;
		continue;
		return 0;
	}
	}

	
	return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[3][3];
int vis[3][3];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n ,m;
		n = m = 3;
		fn{
			fm{
				cin >> ar[i][j];
			}
		}
		int k;
		cin >> k;
		for(int h =0 ;h < k;h++){
			int y;
			cin>>y;
			fn{
				fm{
					if(!vis[i][j] && ar[i][j]==y){
						vis[i][j]=1;
					}
				}
			}
		}
		int ok1=1;
		fm{
			ok1=1;
			fn{
				if(vis[j][i]==0)ok1=0;
			}
			if(ok1)break;	
		}
		int ok2=1;
		fm{
			ok2=1;
			fn{
				if(vis[i][j]==0)ok2=0;
			}
			if(ok2)break;
		}
	int ok3=1;
		fn{
			if(vis[i][i]==0)ok3=0;
		}
		int ok4=0;
		if(vis[0][2]==1 && vis[1][1]==1 && vis[2][0]==1)ok4=1;
		cout << (ok1 || ok2 || ok3 || ok4 ?"Yes":"No") ;
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
a.sort()
c = Counter(a)
keys = list(c.keys())
values = list(c.values())
count = 0

for i in range(len(keys)):
    if keys[i] == values[i]:
        count += 0
    elif keys[i] > values[i]:
        count += values[i]
    elif keys[i] < values[i]:
        count += values[i] - keys[i]

print(count)

Measured memory_bytes: 18672
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 Scanner in = new Scanner(System.in);
	     int n = in.nextInt();
	     int a = in.nextInt();
	     int b = in.nextInt();
	     in.nextLine();
	     String t = in.nextLine();
	     int tmp = b;
	     int total = a+b;
	     for(int i=0;i<n;i++)
	     {
	    	 if(t.charAt(i)=='a'&&total>0){
	    		 System.out.println("Yes");
	    		 total--;
	    	 }
	    	 else if(t.charAt(i)=='b'&&total>0&&tmp>0){
	    		 System.out.println("Yes");
	    		 total--;
	    		 tmp--;
	    	 }
	    	 else
	    		 System.out.println("No");
	    	 
	     }
	}

}


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

int main()
{
	while (true) {
		int n, k, m;
		cin >> n >> k >> m;

		if (n == 0 && k == 0 && m == 0) {
			break;
		}

		vector<int> stone(n);
		for (int i = 0; i < n; i++) {
			stone[i] = i + 1;
		}

		int cur = m - 1;

		while (stone.size() != 1) {
			stone.erase(stone.begin() + cur);
			cur = (cur + k - 1) % stone.size();
		}

		cout << stone[0] << endl;
	}

	return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;

#define f first
#define s second
#define rep(i, n) for(int i = 0 ; i < n ; i++)

typedef pair<int, int> P;

P field[110][110];
int N;

int main(){
  while(cin >> N, N){
    set<set<P> > ans;
    
    rep(i, N)
      rep(j, N) cin >> field[i][j].f >> field[i][j].s;
    
    rep(i, N){
      rep(j, N){
	set<P> tmp, t;
	int x = j, y = i;
	while(true){
	  if(tmp.find(P(x, y)) != tmp.end()){
	    while(true){
	      if(t.find(P(x, y)) != t.end()) goto F;
	      t.insert(P(x, y));
	      int xx = x, yy = y;
	      x = field[yy][xx].f, y = field[yy][xx].s;
	    }
	  }
	  
	  else{
	    tmp.insert(P(x, y));
	    int xx = x, yy = y;
	    x = field[yy][xx].f, y = field[yy][xx].s;
	  }
	}
      F:;
	ans.insert(t);
      }
    }
    
    cout << ans.size() << endl;    
  }
  return 0;
}

Measured memory_bytes: 2708
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)
 
int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
 
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
 
const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
 
// --------------------------------------
ll x, y;
ll f[1010100], rf[1010100];
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
 
ll cal_c(int n, int k) {
  f[0] = 1;
  FOR(i, 1, 1010100) f[i] = (f[i - 1] * i) % mod;
  FOR(i, 0, 1010100) rf[i] = inv(f[i]);
  ll a = f[n];
  ll b = rf[n-k];
  ll c = rf[k];
 
  ll bc = (b * c) % mod;
 
  return (a * bc) % mod;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  cin >> x >> y;
 
  ll ans = 0;
  ll a = (2 * x - y);
  ll b = (2 * y - x);
  if(a % 3 == 0 && b % 3 == 0) {
    a /= 3;
    b /= 3;
 
    if(a >= 0 && b >= 0) {
      ll ma = max(a, b);
      ans = cal_c(a + b, ma);
    }
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 16000
import sys
input = sys.stdin.readline

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

X, Y = [int(x) for x in input().strip().split()]
p = (X, 2 * X)
n1 = X
n2 = 0
f = True
while p != (X, Y):
    n1 -= 2
    n2 += 1
    p = (n1 + 2 * n2, 2 * n1 + n2)
    if p[1] <= 0:
        f = False
        break

if n1 < 0 or n2 < 0:
    print(0)
else:
    print(combination(n1 + n2, n1) % (10 ** 9 + 7))

Measured memory_bytes: 3064
from fractions import gcd

a,b,c,d=map(int,input().split())

nc=b//c-(a-1)//c
nd=b//d-(a-1)//d
cd=c*d//gcd(c,d)
ncd=b//cd-(a-1)//cd

print(b-a+1-nc-nd+ncd)

Measured memory_bytes: 77512
import java.util.*;

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

    String s=sc.next();
    boolean ans=true;
    String a[]=s.split("");
    for(int i=0;i<a.length;i++){
      if(i%2!=0){
        if(a[i].equals("L") || a[i].equals("U")|| a[i].equals("D")){
        }else{
          ans=false;
        }
      }else{
        if(a[i].equals("R") || a[i].equals("U")|| a[i].equals("D")){
        }else{
          ans=false;
        }
      }
    }
    if(ans==true){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }

	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <string>

using namespace std;



char is_judge(string f) {
    for (int i = 0; i < 3; i++) {
        if (f[i] != 's' && f[i] == f[i + 3] && f[i] == f[i + 6]) {
            return f[i];
        }
        if (f[i*3] != 's' && f[i*3] == f[i*3 + 1] && f[i*3] == f[i*3 + 2]) {
            return f[i*3];
        }
    }
    if (f[0] != 's' && f[0] == f[4] && f[0] == f[8]) {
        return f[0];
    }
    if (f[2] != 's' && f[2] == f[4] && f[2] == f[6]) {
        return f[2];
    }
    return 'd';
}

int main() {
    string f, r;
    while (cin >> f) {
        cout << is_judge(f) << endl;
    }

    return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for (int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int i = (int)(n); i > 0; i--)
#define rep_r_3(i, initial, n) for (int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
const long long INF = (long long)1e18;
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }

int main() {
	string S;
	cin >> S;
	int N = S.length();
	int N2 = (N-1)/2;
	int N3 = (N+2)/2;
	string result = "Yes";
	string rS = S;
	reverse(rS.begin(), rS.end());

	repeat(i, N) {
		string s = S.substr(i, 1);
		string rs = rS.substr(i, 1);

		if (s != rs) result = "No";
	}

	string s2 = S.substr(0, N2);
	string rs2 = s2;

	reverse(rs2.begin(), rs2.end());
	repeat(i, N2) {
		string s = s2.substr(i, 1);
		string rs = rs2.substr(i, 1);

		if (s != rs) result = "No";
	}

	string s3 = S.substr(N3, N);
	string rs3 = s3;
	reverse(rs3.begin(), rs3.end());
	repeat(i, N3) {
		string s = s3.substr(i, 1);
		string rs = rs3.substr(i, 1);

		if (s != rs) result = "No";
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n, s) for (int i = (s); i < (n); i++)
#define SIZE 1
using namespace std;
typedef long long int LL;
typedef long double LD;

int main() {
	string S;
	cin >> S;
	if (S[0] == S[1]) {
		cout << "1 2" << endl;
		return 0;
	}
	char pre1 = S[1], pre2 = S[0];
	REP(i, S.length(), 2) {
		if (S[i] == pre1) {
			cout << i << " " << i + 1 << endl;
			return 0;
		} else if (S[i] == pre2) {
			cout << i - 1 << " " << i + 1 << endl;
			return 0;
		}
		pre1 = S[i];
		pre2 = S[i-1];
	}
	cout << "-1 -1" << endl;
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
struct aa {
	int x;
	int y;
	int time;
};
class Compare {
public:
	//aa?????????????????¶
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};
int main() {
	map<char, int>chmp;
	chmp['L'] = 0;
	chmp['D'] = 1;
	chmp['R'] = 2;
	chmp['U'] = 3;
	int W, H, N; cin >> W >> H >> N;
	vector<vector<vector<int>>>cells(H+2, vector<vector<int>>(W+2,vector<int>(4)));
	int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy;
	
	for (int i = 0; i < N; ++i) {
		int nowx, nowy; cin >> nowx >> nowy;
		nowx += 1; nowy += 1;
		int t; cin >> t;
		string st; cin >> st;
		for (int k = 0; k < t; ++k) {
			
			for (int j = 0; j < st.size(); ++j) {
				const int way = chmp[st[j]];
				int newx = nowx + dx[way];
				int newy = nowy + dy[way];
				if (newx < 1 || newx >= W+1) {
					newx = nowx;
				}
				else if (newy < 1 || newy >= H+1) {
					newy = nowy;
				}
				else {
					cells[nowy][nowx][way]++;
					cells[newy][newx][(2 + way) % 4]++;
				}
				nowx = newx;
				nowy = newy;
			}
		}
	}
	int memo[501][501];
	for (int x = 0; x < 501; ++x) {
		for (int y = 0; y < 501; ++y) {
			memo[y][x] = 1e9;
		}
	}
	memo[sy][sx] = 0;
	priority_queue<aa,vector<aa>,Compare>que;
	que.push(aa{ sx,sy,0 });
	long long int ans = 0;
	while (!que.empty()) {
		aa atop(que.top());
		const int nowx = atop.x;
		const int nowy = atop.y;
		
		const int nowtime = atop.time;
		if (nowx == gx&&nowy == gy) {
			ans = nowtime;
			break;
		}
		que.pop();
		for (int way = 0; way < 4; ++way) {
			const int newx = nowx + dx[way];
			const int newy = nowy + dy[way];
			if (newx<0 || newx>W || newy<0 || newy>H)continue;
			else {
				int nexttime = nowtime;
				if (way == 0) {
					nexttime += cells[nowy][nowx ][1];
				}
				else if (way == 1) {
					nexttime += cells[nowy+1][nowx][2];
				}
				else if (way == 2) {
					nexttime += cells[nowy+1][nowx+1][3];
				}
				else {
					nexttime += cells[nowy][nowx][2];
				}
				if (memo[newy][newx]>nexttime) {
					memo[newy][newx] = nexttime;
					que.push(aa{ newx,newy,nexttime });
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 20760
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  console.log(' ' + buildMaxHeap(lines.shift().split(' ')).join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && Number(arr[left]) > Number(arr[largest])) largest = left;
    if (right < n && Number(arr[right]) > Number(arr[largest])) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2) - 1; i >= 0; i--) maxHeapify(i);
  return arr;
}



Measured memory_bytes: 88292
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int int_sort(const void*a,const void *b){
    return *(int*)b-*(int*)a;
}

int even[100001]={};
int odd[100001]={};

int main(){
    int a,b;
    int max_ev=0,max_od=0,sec_ev=0,sec_od=0;
    int flag_ev=1,flag_od=1;
    int sum1,sum2,sum3;
   
    scanf("%d",&a);
    for(int i=1;i<=a;i++){
        if(i%2==1){
            if(scanf("%d",&b)==EOF)
                return -1;
            odd[b]+=1;
            if(odd[flag_od]<odd[b])
                flag_od=b;
        }
        else{
            if(scanf("%d",&b)==EOF)
                return -1;
            even[b]+=1;
            if(even[flag_ev]<even[b])
                flag_ev=b;
        }
    }
    
    qsort(even,100001,sizeof(even[0]),int_sort);
    qsort(odd,100001,sizeof(odd[0]),int_sort);
    max_ev=even[0];max_od=odd[0];
    sec_ev=even[1];sec_od=odd[1];
    
    sum1=a-(max_ev+sec_od);
    sum2=a-(sec_ev+max_od);
    sum3=a-(max_od+max_ev);
    
    if( flag_ev!=flag_od){
        printf("%d\n",sum3);
        return 0;
    }
    
    if(sum1>=sum2){
        printf("%d\n",sum2);
        return 0;
    }
    else{
        printf("%d\n",sum1);
        return 0;
    }
    return 0;
}


Measured memory_bytes: 1968