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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

random_device rd;
mt19937 eng(rd());
const string material="abcdefghijklmnopqrstuvwxyz";

string RandomString(int len){
	string res;
	rep(i,0,len) res+=material[eng()%26];
	return move(res);
}

void Solve(){
	set<string> used;
	bool fir=true;
	int cnt[26]={};
	string out,in;
	while(true){
		int maxi=-1,idx;
		rep(i,0,26) if(maxi<cnt[i]){
			maxi=cnt[i];
			idx=i;
		}
		
		if(fir){
			out=RandomString(1);
			fir=false;
		}else out=in[in.size()-1];
		out+=RandomString(8);
		out+=idx+'a';
		cout << '?' << out << endl;
		
		cin >> in;
		if(used.count(in)||in[0]!=out[9]){
			cout << "!OUT" << endl;
			return;
		}
		used.insert(in);
		++cnt[in[0]-'a'];
	}
}

int main(){
	//std::ios::sync_with_stdio(false);
	//std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 1256
n = gets.to_i

p (1..n)
    .select{|i|i.odd?}
    .map{|i|
        sum = 0
        (1..i).each{|j|
            sum += 1 if i % j == 0
        }
        sum
    }
    .select{|i|i == 8}
    .count


Measured memory_bytes: 1788
#include <iostream>
#include <vector>

int main() {
    int N;
    std::cin >> N;

    std::vector<long> H(N);
    for (int i = 0; i < N; i += 1) {
        std::cin >> H[i];
    }

    long left = 0;
    for (int i = 0; i < N; i += 1) {
        long current = H[i];
        if (left < current) {
            current -= 1;
        } else if (left > current) {
            std::cout << "No" << std::endl;
            return 0;
        }
        left = current;
    }

    std::cout << "Yes" << std::endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str1[21], str2[21];
	int i, n, len;
	
	scanf("%s", str1);
	
	len = strlen(str1);
	
	n = len - 1;
	
	for (i = 0; i < len; i++){
		str2[n] = str1[i];
		
		n--;
	}
	str2[len] = '\0';
	
	printf("%s\n", str2);
	
	return (0);

}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    ll K; cin >> K;
    int A[N]; rep(i, N) cin >> A[i];
    bool dp[K+1] = {};
    for(int i = A[0]; i <= K; i++){
        bool res = false;
        rep(j, N){
            int val = i - A[j];
            if(val < 0) break;
            if(!dp[val]) res = true; //遷移によって負け局面に遷移できる
        }
        dp[i] = res;
    }
    if(dp[K]) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  map<string, int> m;
  for (int i=0; i<n; i++) {
    string s;
    cin>>s;
    ++m[s];
  }
  int max_v = 0;
  set<string> s;
  for (auto i: m) {
    string k = i.first;
    int v = i.second;
    if (v > max_v) {
      s.clear();
      s.insert(k);
      max_v = v;
    } else if (v == max_v) {
      s.insert(k);
    }
  }
  for (string i: s) {
    cout<<i<<endl;
  }
}

Measured memory_bytes: 36480
#include<bits/stdc++.h>
using namespace std;
const int N = 1006;
typedef long long ll;
ll a[N];
vector<ll> v,u;
int main()
{
    int n,k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ll s = 0;
        for (int j = i; j >= 0; --j)
            v.push_back(s += a[j]);
    }
    sort(begin(v),end(v));
    ll ans = 0;
    for (ll b = 1LL<<42; b; b>>=1) {
        u.clear();
        for (int i = 0; i < v.size(); ++i)
            if (v[i] & b)
                u.push_back(v[i]);
        if (u.size() >= k) {
            ans |= b;
            swap(v,u);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int cnt = 0;
    for(int i=0;i<3;i++)
    {
        if(s[i]==t[i])
            cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n = II()
    ss = Counter([IS() for _ in range(n)])
    m = II()
    tt = Counter([IS() for _ in range(m)])
    tt_key = set(tt.keys())
    maxv = 0
    for s, c in ss.items():
        cnt = c
        if s in tt_key:
            cnt -= tt[s]
        maxv = max(maxv, cnt)
    print(maxv)


if __name__ == '__main__':
    main()

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


int main(){
  int N,Y;
  cin >> N >> Y;
  int A = 0,B= 0,C = 0;
  int ans = -1;
  int k;
  for(int i = 0;i <= N;i++){
    if(ans == 1){break;}
    for(int j = 0;j <= N-i;j++){
      k = N - i -j;
      if(k >=0){
      if(10000*i + 5000*j + 1000*k == Y){
        A = i;
        B = j;
        C = k;
        ans = 1;
        break;
      }
      }
    }
    
  }
  if(ans == -1){
	A = -1;
    B = -1; 
    C = -1;
  }
  cout << A << " " << B << " " << C << endl;
}
  

Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));
 
ll gcd(ll x, ll y){
	if(x<y) swap(x,y);
	if(y==0) return x;
	return gcd(y,x%y);
}
 
ll lcm(ll x, ll y){
	return (x*y/gcd(x,y));
}

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int a,b,c,d,e,f,g,h,x,y;
    cin >> a >> b >> c >> d;
    x=c-a;
    y=d-b;
    e=c-y;
    f=d+x;
    g=a-y;
    h=b+x;
    cout << e << " " << f << " " << g << " " << h << endl;

/////////////////////////////////////////////
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,l,a[200005];
long long solve()
{
	long long sum=0;
	for (int i=0;i<n/2;i++)
	sum+=2*a[i];
	for (int i=(n+2)/2;i<n;i++)
	sum+=2*(l-a[i]);
	if (n%2)
	sum+=a[n/2];
	else
	sum+=l-a[n/2];
	long long ret=sum;
	for (int i=1;i<n;i++)
	{
		sum-=2*a[i-1];
		sum-=l-a[i+(n-i)/2];
		sum+=a[i+(n-i-1)/2];
		ret=max(ret,sum);
	}
	return ret;
}
int main()
{
	scanf("%d%d",&l,&n);
	for (int i=0;i<n;i++)
	scanf("%d",&a[i]);
	long long ans=solve();
	reverse(a,a+n);
	for (int i=0;i<n;i++)
	a[i]=l-a[i];
	printf("%lld",max(ans,solve()));
}

Measured memory_bytes: 4560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{



    public class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ').Select(int.Parse).Sum();

            Console.WriteLine(s >= 22 ? "bust" : "win");
        }
    }
}


Measured memory_bytes: 11220
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
using namespace std;
#define ll long long int

int main(void)
{
	int a, b, d, g, count = 0;
	cin >> g;
	vector<int> vec(g);
	map<char, int> mp;
	for (int i = 0;i < g;i++)
	{
		std::cin >> vec[i];
	}
	sort(vec.begin(), vec.end());
	
		if (vec[g / 2 - 1] == vec[g / 2])
		{
			cout << 0 << endl;
			return 0;
		}
		else
		{
			cout << vec[g / 2]- vec[g / 2 - 1] << endl;
			return 0;
		}
	
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int x=0;
    x=min(a,b);
    int y=0;
    if(n-a-b>=0)
        y=0;
    else
        y=a+b-n;
    cout<<x<<" "<<y;
    return 0;
}


Measured memory_bytes: 256
// Ambition without ammunition is dangerous
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M   1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}
ll Sum(ll n)
{
    ll d=n*(n+1);
    d/=2;
    return d;
}
int main()
{
    ll n,i;
    cin>>n;
    ll b[n+1]={0},x;
    for(i=0;i<n-1;i++)
    {
        cin>>x;
        b[x]++;
    }
    for(i=1;i<=n;i++)
        cout<<b[i]<<"\n";
}


Measured memory_bytes: 5160
#include <cstdio>
#include <iostream>

using namespace std;

const int MAX_N = 1000000;

int N;

int len;
int prime[MAX_N];				//save all prime number less than MAX_N
bool isPrime[MAX_N];

void sieve(){
	//init
	fill(isPrime, isPrime + MAX_N, true);
	isPrime[0] = isPrime[1] = false;
	
	for(int i = 2; i < MAX_N; i ++){
		if(isPrime[i]){
			prime[len ++] = i;
			for(int j = 2 * i; j < MAX_N; j += i)
				isPrime[j] = false;
		}
	}
}

void solve(){
	int ans = 0;
	for(int i = 0; i < len; i ++){
		if(N >= prime[i])
			ans ++;
	}
	printf("%d\n", ans);
}

int main(int argc, char const *argv[]){

	sieve();
	while(scanf("%d", &N) != EOF){
		solve();
	}

	return 0;
}

Measured memory_bytes: 2472
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

r = INT()

print(r*r)

Measured memory_bytes: 5712
N,X=map(int,input().split())
x=list(map(int,input().split()))

def devidable(numbers,i):
    for number in numbers:
        if number%i: return False
    return True

def gcd(numbers):
    i=min(numbers)
    while True:
        if devidable(numbers,i): return i
        else: i-=1

x.append(X)
x.sort()
y=[]

for i in range(len(x)-1):
    y.append(x[i+1]-x[i])
    
print(gcd(y))

Measured memory_bytes: 14228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

int n,m,x,c[20],t[20],a[20][20],ans=1e9;

void dfs(int q)
{
	if(q==n+1)
	{
		int sum;
		for(int i=1;i<=m;i++)
		{
			sum=0;
			for(int j=1;j<=n;j++)
			if(t[j]) sum+=a[j][i];
			if(sum<x) return ;
		}
		sum=0;
		for(int i=1;i<=n;i++)
		if(t[i]) sum+=c[i];
		ans=min(ans,sum);
		return ;
	}
	t[q]=0;
	dfs(q+1);
	t[q]=1;
	dfs(q+1);
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		for(int j=1;j<=m;j++)
		cin>>a[i][j];
	}
	dfs(1);
	if(ans!=1e9)
	cout<<ans;
	else cout<<"-1";
	return 0;
}




Measured memory_bytes: 3644
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
    int n;
    int d[100001];
    int s[100001] = {0}; // 各難易度ごとの値を格納
    int ss[100001] = {0}; // 各難易度以上の数を格納
    cin >> n;
    REP(i, n) {
        cin >> d[i];
        s[d[i]]++;
    }

    int tot = 0;
    FORD(i, 100000, 1) {
        tot += s[i];
        ss[i] = tot;
    }

    int res = 0;
    FOR(i, 1, 100000) {
        if (ss[i] == n / 2) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x)  (x).begin(),(x).end()

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

const int MOD = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    ll N, M;
    string s, t;
    cin >> N >> M >> s >> t;

    ll tmp = __gcd(N, M);
    ll n = N / tmp;
    ll m = M / tmp;

    rep(i, tmp){
        if(s[i*n] != t[i*m]) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans = N * M / tmp;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5;
int a[maxn+5],b[maxn+5],c[maxn+5];
inline int Read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
	int n;
	n=Read();
	for(int i=1;i<=n;i++){
		a[i]=Read();
	}
	for(int i=1;i<=n;i++){
		b[i]=Read();
	}
	for(int i=1;i<=n;i++){
		c[i]=Read();
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	long long ans=0;
	for(int i=1;i<=n;i++){
		int x = lower_bound(a+1,a+n+1,b[i])-(a+1);
		int y = upper_bound(c+1,c+n+1,b[i])-(c+1);
		ans+=(long long)x*(n-y);
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

#define endl "\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1n(i, n) for (int i = 1; i < (int)(n); ++i)
#define forln(i, n) for (long long i = 0; i < (long long)(n); ++i)
#define forl1n(i, n) for (long long i = 1; i < (long long)(n); ++i)

const ld EPS = 1e-9;
#define mod 1000000007

ll GetMod(ll n, ll z) { // func to get mod for positive num and negitive nums
    return (n % z + z) % z;
}

//          U   R  D  L
int dx[] = {-1, 0, 1, 0, -1, +1, +1, -1}; // dx for the 8 adjacent places in matrix
int dy[] = {0, 1, 0, -1, +1, +1, -1, -1};// dy for the 8 adjacent places in matrix

map<ll, ll> m;

ll fp(ll base, ll exp) {
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void GetPrime(ll a) {
    map<ll, ll> m1;

    for (ll i = 2; i * i <= a; i++) {
        while (a % i == 0) {
            m1[i]++;
            a /= i;
        }
    }
    if (a > 1)m1[a]++;


    for (auto s = m1.begin(); s != m1.end(); s++) {
        ll dig = s->first;
        ll poww = s->second;
        if (m[dig] != 0) {
            m[dig] = max(poww, m[dig]);

        } else {
            m[dig] = poww;

        }

    }


}

ll GetLCM() {
    ll ans = 1;
    for (auto s = m.begin(); s != m.end(); s++) {
        ans = (ans * fp(s->first, s->second)) % mod;
    }
    return ans;
}

vector<ll> v;

int main() {

    ios_base::sync_with_stdio(false), cin.tie(NULL);
    ll n;
    cin >> n;
    v.resize(n);
    forn(i, n)cin >> v[i];
    forn(i, n) {
        GetPrime(v[i]);
    }
    ll res = GetLCM();


    ll sum = 0;
    forn(i, n) {
        ll z = (res * fp(v[i], mod - 2)) % mod;

        sum = (sum + z) % mod;
    }
    cout << sum;

}

Measured memory_bytes: 1024
/*
[yahoo-procon2019-qual] A - Anti-Adjacency
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int N, K;

bool solve() { return (N + 1) / 2 >= K; }

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

    cout << (solve() ? "YES" : "NO") << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	string s, c, r;
	s = "Sunny";
	c = "Cloudy";
	r = "Rainy";
	string i, o;
	cin >> i;
	if (i==s) o = c;
	else if (i==c) o = r;
	else o = s;
	cout << o << endl;
	return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  string s; cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) cout << "Yes";
  else cout << "No";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

int ans[2000];
int v[2001];
int len[2001];

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

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

    for (int i = 1; i <= n; ++i)
    {
        queue<int> splash;
        splash.push(i);
        len[i] = 0;
        int cur;

        v[i] = i;

        while (splash.empty() == false)
        {
            cur = splash.front();
            splash.pop();

            if (cur - 1 > 0 && v[cur-1] != i)
            {
                v[cur-1] = i;
                splash.push(cur-1);
                ans[len[cur]+1]++;
                len[cur-1] = len[cur]+1;
            }

            if (cur + 1 <= n && v[cur+1] != i)
            {
                v[cur+1] = i;
                splash.push(cur+1);
                ans[len[cur]+1]++;
                len[cur+1] = len[cur]+1;
            }

            if (cur == x && v[y] != i)
            {
                v[y] = i;
                splash.push(y);
                ans[len[cur]+1]++;
                len[y] = len[cur]+1;
            }

            if (cur == y && v[x] != i)
            {
                v[x] = i;
                splash.push(x);
                ans[len[cur]+1]++;
                len[x] = len[cur] +1;
            }
        }
    }

    for (int i = 1; i < n; ++i)
    {
        cout << ans[i]/2 << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N, ans=0;
  cin >> N;
  int A[N], B[N], C[N-1];
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) cin >> B[i];
  for(int i=0; i<N-1; i++) cin >> C[i];

  for(int i=0; i<N-1; i++){
    ans += B[i];
    if(A[i]+1 == A[i+1]) ans += C[A[i]-1];
  }
  ans += B[N-1];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// IlyM

#include <bits/stdc++.h>
#define pb push_back
#define sp " "
#define sl "\n"
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define tra(a,b) for (auto a:b) 
#define fo(a,b,c) for (int a=b;a<=c;a++) 
#define ms(a,b) memset(a,b,sizeof(a)) 
#define all(a) a.begin(),a.end()
#define rev(a) reverse(a.begin(),a.end())
#define bit(i,j) (i&(1<<j))

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef pair<int,ii> iii;

const int N=2e5+5,mod=998244353;
bool sen;
string a;
int q,t,f;
char x;
deque<char> hi;
int main()
{
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	cin>>a>>q;
	for (int i=0;i<sz(a);i++) hi.pb(a[i]);
	while (q--) {
		cin>>t;
		if (t==1) sen^=1;
		else {
			cin>>f>>x;
			if (f==2) {
				if (sen==0) hi.pb(x);
				else hi.push_front(x);
			} else {
				if (sen==0) hi.push_front(x);
				else hi.pb(x);
			}
		}
	}
	if (!sen) {
		while (!hi.empty()) {
			char y=hi.front();
			hi.pop_front();
			cout<<y;
		}
	} else {
		while (!hi.empty()) {
			char y=hi.back();
			hi.pop_back();
			cout<<y;
		}
	}
	return 0;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

ll i,j,k,l,m,n;
/////////////////////////////////////////////////////
#define MOD 998244353
#define Nmax 2020 
#define Kmax 2020
#define tpl tuple<int,int,int>
#define mktp make_tuple

ll N,K;
//int bit[20],ex=0;
//vector<tpl> a;
ll C[Kmax+Nmax][Kmax+Nmax];
ll pow2[Kmax];
ll sum[Nmax][Nmax];
ll sum2[Nmax];

int main(){
    scanf("%lld%lld",&K,&N);
    pow2[0] = 1;
    fornum(i,0,2002){
        pow2[i+1] = (pow2[i] * 2) % MOD;
    }
    C[0][0] = 1;
    fornum(i,0,4004){
        C[i + 1][0] = 1;
        fornum(j,0,i+2){
            C[i + 1][j + 1] = (C[i][j] + C[i][j + 1]) % MOD;
        }
    }
    fornum(i,1,2*K){
        ll ii = 2 * K - i;
        ii = min(ii, i);
        ll ka = ii / 2;
        ll kb = K - ii - 1;
        ll ans = 0;
        if(kb>=0){
            if(i%2){
                ans = (ans + C[N + kb-1][kb]) % MOD;
            }
            ans = (ans + C[N + kb][kb]) % MOD;
        }
        //printf("%lld ", N+kb+1);
        fornum(j,1,ka+1){
            if(i%2&&N-1>=j){
                ans = (ans + C[N + kb-1][kb + j] * C[ka][j] % MOD * pow2[j] % MOD) % MOD;
            }
            if(N>=j){
                ans = (ans + C[N + kb][kb + j] * C[ka][j] % MOD * pow2[j] % MOD) % MOD;
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 127872
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const rep=(n,c:(i?:number)=>void)=>{for(let i=0;i<n;i++)c(i)};
const main=()=>{
  let [n,k]=tnn(2),ans=0
  rep(n,(i)=>{
    let a=i+1
    let num=0
    while(a*(2**num)<k){
      num++
    }
    ans+=(1/n)*(1/(2**num))
  })
  to(ans)
}
main()


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

int main() {
    int h,w;
    cin>>h>>w;
    vector<vector<bool> > s = vector<vector<bool> >(h, vector<bool>(w,0));
    char* tmp = new char[w+1];
    for(int i=0; i<h; i++) {
        cin>>tmp;
        for(int j=0; j<w; j++) {
            if(tmp[j] == '#') {
                s[i][j] = true;
            } else{
                s[i][j] = false;
            }
        }
    }

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

    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            if(!s[i][j]) continue;
            for(int k=0; k<4; k++) {
                if(i+dx[k]<0 || i+dx[k]>=h || j+dy[k]<0 || j+dy[k]>=w) continue;
                if(s[i+dx[k]][j+dy[k]]) break;
                if(k==3) {
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
import math
def factorization(n):
    if n == 1:
      return []
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def ston(s):
  return (-1+math.sqrt(1+8*s))/2

n = int(input())

s = 0
soinsu = factorization(n)
#print(soinsu)
for i in soinsu:
  num = int(ston(i[1]))
  s += num
  
print(s)

Measured memory_bytes: 9488
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ans = float("inf")
for i in range(2**n):
    l = [0] * m
    c = 0
    for j ,d in enumerate(format(i, "b").zfill(n)):
        f = 0
        if d == "1":
            c += ca[j][0]
            for k in range(1, m+1):
                l[k-1] += ca[j][k]
            
    for li in l:
        if li < x:
            f = 1
            break
    if f:
        continue
    ans = min(ans, c)

if ans == float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68680
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  cout << (((A1 + A2 + A3) >= 22) ? "bust" : "win") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int n;
int x=2, a;
int main () {
	cin >> n;
	while (a != n) {
		int l=0;
		for (int i = 2; i < x; i++) {
			if (x%i==0) {
				l=1;
				break;
			}
		}
		
		if (l!=1) {
			if ((x-1)%5==0) {
			cout << x << " ";	
			a++;
			}
		}
		x++;
	}







return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int128, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
  N = parseInt(readline())
  seki = Int128(0)
  sum = 0
  for i in 1:N-1
     sum += trunc((N-1)/i)
  end
  println(Int(sum))

end
main()


Measured memory_bytes: 184376
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        QuickScanner in = new QuickScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
}

class Task {
    public void solve(QuickScanner in, PrintWriter out) {
        int D = in.nextInt();
        int T = in.nextInt();
        int S = in.nextInt();
        double time = (double)D/(double)T;
        if(T*S >= D) {
        	out.print("Yes");        	
        }else {
        	out.print("No");
        }
    }
}

class QuickScanner {
    BufferedReader in;
    StringTokenizer token;
    String delim;
    public QuickScanner(InputStream inputStream)
    {
        this.in=new BufferedReader(new InputStreamReader(inputStream));
        this.delim=" \n\t";
        this.token=new StringTokenizer("",delim);
    }

    public boolean hasNext()
    {
        while(!token.hasMoreTokens())
        {
            try {
                String s=in.readLine();
                if(s==null) return false;
                token=new StringTokenizer(s,delim);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return true;
    }

    public String next()
    {
        hasNext();
        return token.nextToken();
    }

    public int nextInt()
    {
        return Integer.parseInt(next());
    }

}


Measured memory_bytes: 32680
N, M, X, Y = tuple(int(i) for i in input().split())
x = tuple(int(i) for i in input().split())
y = tuple(int(i) for i in input().split())

x_max = max(x)
y_min = min(y)

for z in range(X+1, Y+1):
    if x_max < z and y_min >= z:
        print("No War")
        break
else:
    print("War")


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;

int main() {
  INCANT;
  cin >> N;
  int ans = (N/500)*1000+((N%500)/5)*5;
  cout << ans << "\n";
  return 0;
}

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

int main(){
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;

    int ans = 0;
    for(int i=0; i<n; i++){
        if(a[i] == b[i] && b[i] == c[i]) continue;
        else if(a[i] == b[i] 
             || b[i] == c[i]
             || a[i] == c[i]) ans += 1;
        else ans += 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;
typedef long long ll;

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

  ll res = 0;
  for(int i = 0; i < N-1; i++){
    if(a[i] + a[i+1] > x){
      ll r = a[i] + a[i+1] - x;
      res += r;
      a[i+1] = max(0LL, a[i+1]-r);
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
	long long n,i;
	int x;
	n=1;
	scanf("%d",&x);
	for(i=1;i<=x;i++){
		n*=((long long)i);
	}
	
	printf("%lld\n",(long long)n);
	return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				        3.14159265358979
#define 	mod 			        1000000007
#define 	ll  			        long long
#define 	rep(i, a, b) 	        for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)           for(ll i = a ; i > b ; i--)
#define 	mod1 			        1000003
#define     mod2                    998244353
#define 	hi   			        "hello"
#define 	nl 				        "\n"
#define 	ws 				        " "
#define 	ff 				        first
#define 	ss 				        second
#define 	pb 				        push_back
#define 	B 				        begin()
#define     RB                      rbegin()
#define 	E 				        end()
#define     UB                      upper_bound
#define     LB                      lower_bound
#define 	all(v) 			        v.begin(), v.end()
#define 	reset(a, val) 	        memset(a, val, sizeof(a))
#define     pll                     pair<ll, ll>
#define     vll                     vector<ll>
#define     vpll                    vector<pll>
#define 	vs 				        vector<string>
#define     vc                      vector<char>
#define     sqr(a)                  ((a)*(a))
#define 	print1(a) 		        for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		        for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		        for(auto i : a)cout<<i<<nl;
#define 	boost 			        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
vll pwx(10);
void cal(ll x){ pwx[0] = 1; rep(i, 1, 10)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

bool comp1(const pair<ll, ll>&a, const pair<ll, ll> &b) {
    return a.ff + a.ss > b.ff + b.ss;
}

bool comp2(const pair<ll, ll>&a, const pair<ll, ll> &b) {
    return a.ff - a.ss > b.ff - b.ss;
}

void solve() {
   ll n;
   cin >> n;
   vpll a(n);

   rep(i, 0, n){
       cin >> a[i].ff >> a[i].ss;
   }

   ll ans1, ans2;

   sort(all(a), comp1);
   ans1 = abs(a[0].ff - a[n-1].ff) + abs(a[0].ss - a[n-1].ss);

   sort(all(a), comp2);
   ans2 = abs(a[0].ff - a[n-1].ff) + abs(a[0].ss - a[n-1].ss);

   cout << max(ans1, ans2) << nl;
   
}

int main(){
    boost;
    // cal(3);

    // // For getting input from input.txt file 
    // freopen("alchemy_input.txt", "r", stdin); 
  
    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout);

    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}


Measured memory_bytes: 6336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> a(n+1),b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll sum = 0;
    rep(i,n+1) sum += a[i];
    for(int i=n; i>0; --i){
        if(a[i]-b[i-1] >= 0){
            a[i] -= b[i-1];
            b[i-1] = 0;
        }else{
            b[i-1] -= a[i];
            a[i] = 0;
        }
        if(a[i-1]-b[i-1] >= 0){
            a[i-1] -= b[i-1];
            b[i-1] = 0;
        }else{
            b[i-1] -= a[i-1];
            a[i-1] = 0;
        }
    }
    ll now = 0;
    rep(i,n+1) now += a[i];
    cout << sum - now << endl;

    return 0;
}

Measured memory_bytes: 4048
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    A = []
    for _ in range(3):
        A.append(list(map(int, input().split())))
    
    N = int(input())
    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    A[i][j] = 0
    
    ans = "No"
    for i in range(3):
        if A[i][0] == A[i][1] and A[i][1] == A[i][2]:
            ans = "Yes"
            break
    for j in range(3):
        if A[0][j] == A[1][j] and A[1][j] == A[2][j]:
            ans = "Yes"
            break
    
    if A[0][0] == A[1][1] and A[1][1] == A[2][2]:
        ans = "Yes"
    if A[0][2] == A[1][1] and A[1][1] == A[2][0]:
        ans = "Yes"

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 63980
N, M = map(int, input().split())

ans = [-1 for i in range(N)]
flag = False
for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] == -1:
        ans[s-1] = c
    elif ans[s-1] == c:
        continue
    else:
        flag = True
        break

if len(ans) > 1 and ans[0] == -1:
    ans[0] = 1

for i in range(len(ans)):
    if ans[i] == -1:
        ans[i] = 0

if len(ans) > 1 and ans[0] == 0:
    flag = True

if flag:
    print(-1)
else:
    print("".join([str(c) for c in ans]))


Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define mod 1000000007ll

long long inv(long long n) {
    long long ans = 1;
    while (n > 1) {
        ans *= (mod - mod / n) % mod;
        ans %= mod;
        n = mod % n;
    }
    return ans;
}

long long comb_mod(long long n, long long r) {
    long long deno = 1;
    long long mole = 1;
    long long r_change = (r <= n / 2) ? r : n - r;
    for (long long i=1; i<=r_change; i++) {
        mole *= i;
        mole %= mod;
    }
    for (long long i=n-r_change+1; i<=n; i++) {
        deno *= i;
        deno %= mod;
    }
    mole = inv(mole);
    return (mole * deno) % mod;
}

int main() {
    int n = 0, k = 0;
    cin >> n >> k;
    for (int i=1; i<=k; i++) {
        if (n-k+1 < i) {
            cout << 0 << endl;
        }
        else {
            cout << comb_mod(n-k+1, i) * comb_mod(k-1, i-1) % mod << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
# input関係の定義
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

# BEGIN CUT HERE
class RollingHash():
    BASE1 = 1007
    BASE2 = 2009
    MOD1 = 1000000007
    MOD2 = 1000000009

    def __init__(self, s):
        self.n = len(s)
        self.hash1 = [0] * (self.n + 1)
        self.hash2 = [0] * (self.n + 1)
        self.power1 = [1] * (self.n + 1)
        self.power2 = [1] * (self.n + 1)
        for i, e in enumerate(s):
            self.hash1[i + 1] = (self.hash1[i] * self.__class__.BASE1 + ord(e)) % self.__class__.MOD1
            self.hash2[i + 1] = (self.hash2[i] * self.__class__.BASE2 + ord(e)) % self.__class__.MOD2
            self.power1[i + 1] = (self.power1[i] * self.__class__.BASE1) % self.__class__.MOD1
            self.power2[i + 1] = (self.power2[i] * self.__class__.BASE2) % self.__class__.MOD2

    def get(self, l: int, r: int):
        res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.__class__.MOD1
        if(res1 < 0):
            res1 += self.__class__.MOD1
        res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.__class__.MOD2
        if(res2 < 0):
            res2 += self.__class__.MOD2
        return (res1, res2)
# END CUT HERE

def ABC131E():
    N = ii()
    S = li()
    rh = RollingHash(S)
    def check(n: int):
        d = dict()
        for i in range(N - n + 1):
            p = rh.get(i, i + n)
            if p in d.keys():
                if(i - d[p] >= n):
                    return True
            else:
                d[p] = i
        return False
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)



if __name__ == '__main__':
    ABC131E()


Measured memory_bytes: 5372
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<class T>
inline bool ch1100000(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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


ll X, Y;

ll fac[1100000], finv[1100000], inv[1100000];
 
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 1100000; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main () {
  COMinit();

  cin >> X >> Y;

  ll p = X+Y;
  if (p % 3 != 0) {
    cout << 0 << "\n";
    return 0;
  }

  p /= 3;

  ll q = Y-X;

  if ((p+q) % 2 != 0) {
    cout << 0 << "\n";
    return 0;
  }

  ll a = (p+q) / 2;
  ll b = (p-q) / 2;

  if ((a < 0) || (b < 0)) {
    cout << 0 << "\n";
    return 0;
  }

  cout << COM(a+b, a) << "\n";
}

Measured memory_bytes: 25984
sx, sy, tx, ty = map(int, input().split())

x_shift = tx - sx
y_shift = ty - sy
ans = ""
#1回目sy→ty
if y_shift > 0:
  for i in range(y_shift):
    ans += "U"
else:
  y = abs(y_shift)
  for i in range(y):
    ans += "D"
#sx→tx
if x_shift > 0:
  for i in range(x_shift):
    ans += "R"
else:
  x = abs(x_shift)
  for i in range(x):
    ans += "L"
#ty→sy
if y_shift > 0:
  for i in range(y_shift):
    ans += "D"
else:
  y = abs(y_shift)
  for i in range(y):
    ans += "U"
#tx→sx
if x_shift > 0:
  for i in range(x_shift + 1):
    ans += "L"
else:
  x = abs(x_shift)
  for i in range(x + 1):
    ans += "R"
#2回目sy→ty
if y_shift > 0:
  for i in range(y_shift + 1):
    ans += "U"
else:
  y = abs(y_shift)
  for i in range(y + 1):
    ans += "D"
#sx→tx
if x_shift > 0:
  for i in range(x_shift + 1):
    ans += "R"
else:
  x = abs(x_shift)
  for i in range(x + 1):
    ans += "L"
if y_shift > 0:
  ans += "D"
else:
  ans += "U"
if x_shift > 0:
  ans += "R"
else:
  ans += "L"
#ty→sy
if y_shift > 0:
  for i in range(y_shift + 1):
    ans += "D"
else:
  y = abs(y_shift)
  for i in range(y + 1):
    ans += "U"
#tx→sx
if x_shift > 0:
  for i in range(x_shift + 1):
    ans += "L"
else:
  x = abs(x_shift)
  for i in range(x + 1):
    ans += "R"
if y_shift > 0:
  ans += "U"
else:
  ans += "D"
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const int maxn = 100000 + 100;

int n;
int a[maxn];
ll t[maxn];

int main() {

    // freopen("test.txt", "r", stdin);

    scanf("%d",&n);

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

    sort(a, a+n);

    t[0] = a[0];
    for(int i=1; i<n; i++) {
        t[i] = a[i] + t[i-1];
    }

    int u = -1;
    for(int i=1; i<n; i++) {
        if (2*t[i-1] < a[i]) {
            u = i;
        }
    }

    if (u == -1) {
        printf("%d", n);
    } else {
        printf("%d", n - u);
    }

    return 0;
}



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

// D - Dice in Line
int main() {
    int N, K;
    cin >> N >> K;

    long double p[N];
    int tmpP;
    for (int i = 0; i < N; i++) {
        cin >> tmpP;
        p[i] = ((tmpP + 1.0) / 2.0);
    }

    /*
    // debug
    for (int i = 0; i < N; i++) {
        cout << p[i] << endl;
    }
    */

    long double nowSum = 0, maxSum = 0;
    for (int i = 0; i < K; i++) {
        nowSum = nowSum + p[i];
    }   
    // cout << "nowSum:" << nowSum << endl; // debug
    maxSum = nowSum;
    for (int i = K; i < N; i++) {
        nowSum = nowSum - p[i - K] + p[i];
        maxSum = max(nowSum, maxSum);
    }
    // cout << maxSum;
    printf("%Lf", maxSum);
}


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

int main() {
    int n, l, r, ans = 0;
    cin >> n;
    rep(i, n) {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
typedef long long ll;
using namespace std;
typedef pair<ll, ll> ii;
#define MAXN 100100

ll n;
ll u[MAXN], v[MAXN]; ll w[MAXN];
vector<ii> g[MAXN];
ll s[MAXN], reza;

ll dfs(ll cv, ll rod)
{
  ll ret = 1;

  for (ii i: g[cv]) {
    if (i.X != rod)
      ret += dfs(i.X, cv);
  }

  return s[cv] = ret;
}

ll dfs2(ll cv, ll rod, ll xx = -1)
{
  for (ii i: g[cv]) {
    if (rod == i.X) continue;
    if (s[i.X] >= (n + 1) / 2) return dfs2(i.X, cv, i.Y);
  }

  return xx;
}

ll dfs3(ll cv, ll rod)
{
  for (ii i: g[cv]) {
    if (rod == i.X) continue;
    if (s[i.X] >= (n + 1) / 2) return dfs3(i.X, cv);
  }

  return cv;
}

int main()
{
  scanf("%lld", &n);
  for (ll i = 0; i < n - 1; i++) {
    scanf("%lld%lld%lld", &u[i], &v[i], &w[i]);
    u[i]--; v[i]--;
    g[u[i]].pb({v[i], i});
    g[v[i]].pb({u[i], i});
  }
  dfs(0, -1);
  //for (ll i = 0; i < n; i++) cout << s[i]<< ' ';cout<<endl;
  for (ll i = 0; i < n - 1; i++) {
    reza += min(min(s[u[i]], s[v[i]]), ll(n) - min(s[u[i]], s[v[i]])) * 2LL * w[i];//cout<<reza<<endl;
  }
  //cout << reza;
  ll e = dfs2(0, -1); /// nadji edge
  if (e != -1 && n % 2 == 0 && min(s[u[e]], s[v[e]]) == n / 2) {
    printf("%lld\n", reza - w[e]);
    return 0;
  }
  ll h = dfs3(0, -1);
  ll mn = -1;
  for (ii i: g[h]) {
    if (mn == -1 || mn > w[i.Y])
      mn = w[i.Y];
  }
  printf("%lld\n", reza - mn);
  return 0;
}


Measured memory_bytes: 14976
n,m,c = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

ans = 0
n.times do |i|
  a = gets.split.map(&:to_i)
  sum = c
  m.times do |j|
    sum += a[j]*b[j]
  end
  ans += 1 if sum > 0
end

puts ans

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	vector<bool> box(n);

	for(int i=n-1; i>=0; i--) {
		int index = i;
		int num = i+1;
		int count = n / num;
		int acc = 0;
		for(int j = count; j>1; j--) {
			if(box[num*j-1]) acc++;
		}
		if(acc % 2 == a[i]) box[index] = false;
		else box[index] = true;
	}
	int acc2 = 0;
	rep(i,n) if(box[i]) acc2++;
	cout << acc2 << endl;
	int acc3=0;
	rep(i,n) {
		if(box[i]) {
			++acc3;
			cout << i+1;
			if(acc2 != acc3) cout << " ";
			else cout << endl;
		}
	}

  return 0;
}


Measured memory_bytes: 1792
N=int(input())
T=[int(i) for i in input().split()]
M=int(input())
D=[int(i) for i in input().split()]
if M>N:
  print('NO')
else:
  cnt={}
  for t in T:
    cnt[t]=[0,0]
  for d in D:
    cnt[d]=[0,0]
  for t in T:
    cnt[t][0]+=1
  for d in D:
    cnt[d][1]+=1
  ans='YES'
  for key in cnt:
    n,m=cnt[key]
    if n<m:
      ans='NO'
  print(ans)
    
    

Measured memory_bytes: 53860