akhauriyash/Code-Regression huggingface dataset:
def combination(n,r):
  n1,r = n+1, min(r,n-r)
  numer = denom = 1
  for i in range(1, r+1):
    numer = (numer*(n1-i)) % mod
    denom = (denom*i) % mod
  return numer * pow(denom, mod-2, mod) % mod

n,a,b = map(int, input().split())

mod = 10**9+7

all = pow(2,n,mod)-1
exc = (combination(n,a)+combination(n,b))%mod
ret = (all - exc)%mod

print(ret)

Measured memory_bytes: 3064
S=6000
A=4000
B=3000
C=2000

for k in range(4):
    i,z=map(int,input().split())
    if i==1:
        print(f"{S*z}")
    elif i==2:
        print(f"{A*z}")
    elif i==3:
        print(f"{B*z}")
    elif i==4:
        print(f"{C*z}")


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

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char);
long long getKey(char str[]);
int h1(int);
int h2(int);
int find(char[]);
int insert(char[]);

int main(void){
    int i, n;
    char str[L], com[9];
    for(i = 0; i < M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%s %s", com, str);
        if(com[0] == 'i') insert(str);
        else{
            if(find(str)) printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
}

int getChar(char ch){
    switch(ch){
        case 'A':
            return 1;

        case 'C':
            return 2;

        case 'G':
            return 3;

        case 'T':
            return 4;

        default:
            return 0;
    }
}

long long getKey(char str[]){
    long long sum = 0, p = 1, i;
    for(i = 0; i < strlen(str); i++){
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    return key % M;
}
int h2(int key){
    return 1 + (key % (M - 1));
}

int find(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i = 0;  ;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i = 0; ;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 16032
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        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();

        // j - i == Ai + Aj
        // j - Aj == i + Ai

        Map<Integer, Long> m1 = new HashMap<>(), m2 = new HashMap<>();
        for (int i=0;i<N;i++) {
            m1.put(i+1+A[i], m1.getOrDefault(i+1+A[i], 0L) + 1);
            m2.put(i+1-A[i], m2.getOrDefault(i+1-A[i], 0L) + 1);
        }

        long ret = 0;
        for (int k : m1.keySet()) {
            if (!m2.containsKey(k)) continue;
            ret += m1.get(k) * m2.get(k);
        }

        System.out.println(ret);
    }
}


Measured memory_bytes: 78896
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int n,h,w ;
	cin >> n >> h >> w ;
	cout << (n-h+1)*(n-w+1) << endl ;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
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 stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
char ss[200010];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    scanf("%s",ss+1);int n=strlen(ss+1);
    long long ans=0;
    int f0=0,f1=0;
    for(int i=1;i<=n;i++)
	{
		if(ss[i]=='1')
		{
			ans+=(i+1)/2;
			if(i&1)f0++;
			else f1++;
		}
		else {int ul=max(f0,f1);ans+=max(f0,f1),f0=f1=ul;}
	}
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1924
n,c = gets.split(" ").map(&:to_i)

task = []
n.times do
  input = gets.split(" ").map(&:to_i)
  task << input
end

rec = [[]]

task.sort_by!{|t| t[0]}
rec[0] << task.slice!(0)

task.each do |t|
  rec.each_with_index do |r,idx|
#    puts "rec #{idx} ---"
#    puts "t:#{t}  r.last: #{r.last}"
    # スタートとエンドが同じ
    if t[0] == r.last[1]
      # チャンネルが同じ
      if t[2] == r.last[2]
        r << t
        break
      else
#        puts "idx #{idx}  rec.size:#{rec.size}"
        if idx == rec.size-1
          rec << [t]
          break
        else
          next
        end
      end
    elsif t[0] < r.last[1] # スタートがエンドより早い
      if idx == rec.size-1
        rec << [t]
        break
      else
        next
      end
    else
      # 被らない
      r << t
      break
    end

  end

#  puts "=====rec====="
#  rec.each_with_index do |r,i|
#    puts "rec #{i}"
#    p r
#  end
#  puts "=====rec=====\n\n"
end

#rec.each_with_index do |r,i|
#  puts "rec #{i}"
#  p r
#end

puts rec.size

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

typedef long long ll;

const int MAXN = 100 + 10, MAXW = 1e5 + 10;

int N, W;
ll v[MAXN], w[MAXN], f[MAXW];

int main() {
    scanf("%d %d", &N, &W);
    for (int i = 1; i <= N; ++i) {
        scanf("%lld %lld", &w[i], &v[i]);
    }
    for (int i = 1; i <= N; ++i) {
        for (int j = W; j >= w[i]; --j) {
            f[j] = max(f[j], f[j - w[i]] + v[i]);
        }
    }
    ll ans = 0;
    for (int i = 0; i <= W; ++i) ans = max(ans, f[i]);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
import heapq
import sys
input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().strip().split()]
    w_list = [[int(x) for x in input().strip().split()] for _ in range(N)]
    w_list = sorted(w_list, key=lambda x: (x[0], -x[1]))

    ans = 0
    w_idx = 0
    value_list = []
    for day in range(1, M+1):
        if w_idx < len(w_list):
            while w_list[w_idx][0] == day:
                heapq.heappush(value_list, -w_list[w_idx][1])
                w_idx += 1
                if w_idx >= len(w_list):
                    break
        if len(value_list) > 0:
            ans -= heapq.heappop(value_list)

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 79452
#include <bits/stdc++.h>
#define ll long long int
#define REP(i,n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)v.size()
#define endl "\n"
#define ff first
#define ss second
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll INF=1e29;
const ll MOD=1e9+7;
const ll nxm=2e7+5;
bool c(pair<ll,ll> a,pair<ll,ll> b){    return a.ss>b.ss;    }
bool sgn(ll a){ if(a>=0) return 1 ;return 0;}
void solve()
{

    ll a[5];
    REP(i,5) cin>>a[i];
    REP(i,5)
    {
        if(a[i]==0)
        {
            cout<<i+1;
            return;
        }
    }
}
int main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
//	cin>>t;
	while(t--){
		solve();
	}


	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;

int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int a , b;
    cin >> a >> b;

    if(a <= 5)
        cout << 0 << endl;
    else if(a <= 12)
        cout << b / 2 << endl;
    else cout << b << endl;
}


Measured memory_bytes: 256
def sub():
    N = int(input())
    Ls = [int(e) for e in input().split()]
    Ls = sorted(Ls)
    a = sum(Ls[:-1])
    b = Ls[-1]
    if b < a:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    sub()



Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,count=0;
    cin>>n;
    vector<int> data(n,0);
    for(int i=0;i<n;i++){
        cin>>data[i];
    }
    for(int i=1;i<n-1;i++){
        vector<int> p(3,0);
        p[0]=data[i-1];
        p[1]=data[i];
        p[2]=data[i+1];
        int mi,ma;
        mi=p[0];
        ma=p[0];
        for(int j=1;j<3;j++){
            mi=min(mi,p[j]);
            ma=max(ma,p[j]);
        }
        if(p[1]!=mi && p[1]!=ma){
            count++;
        }
    }
    cout<<count<<endl;
}

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

ll n, mod = 998244353;
const ll MAX = 1000001;
vector<ll> v(MAX);

ll inv[MAX];

void init() {
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
    }
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    init();
    cin>>n;
    ll d = 0,i2=inv[2];
    for(ll i=0;i<n;i++){
        ll a; cin>>a;
        v[a]++;
        d += a;
        d %= mod;
    }
    ll ans = 0;
    for(ll i=1;i<MAX;i++){
        ll sum = (v[i] * i)%mod;
        for(ll j=i+i;j<MAX;j+=i){
            // if(v[j]==0) continue;
            (inv[j] += mod - inv[i]) %= mod;
            (sum += v[j] * j) %= mod;
        }
        sum *= sum;
        sum %= mod;
        (ans += inv[i] * sum) %= mod;
        //cerr << i << " " << inv[i] << " " << sum << " " << ans << endl; 
    }
    ans += mod - d;
    ans %= mod;
    ans *= i2;
    ans %= mod;
    cout << ans << endl;



}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int a,b;
    cin>>a>>b;
    for(int i = 0 ; i <10 ; i++)
    {
        if((8*(b*10+i))/100==a)
            {
                cout<<b*10+i<<endl;
                return 0;
            }
    }
    cout<<-1<<endl;
    return 0;
}

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

int main(){
    while(1){
        int n, s[1000];
        double mean = 0, variance = 0;
        cin >> n;
        if (n == 0) return 0;

        for (int i = 0; i < n; i++){
            cin >> s[i];
            mean += s[i];
        }
        mean = mean / n;

        for (int i = 0; i < n; i++) variance += pow(s[i] - mean, 2);
        
        variance = variance / n;

        cout << fixed << setprecision(8) << sqrt(variance) << endl;
    }
    return 0;
}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
int main(){
  unordered_set<string>st;
  string ans,s="?a";
  st.insert("a");
  while(1){
    cout<<s<<endl;
    cout.flush();
    if(s[0]=='!')break;
    cin>>ans;
    if(st.count(ans)||s[s.size()-1]!=ans[0])s="!OUT";
    else st.insert(ans),s="?"+ans.substr(ans.size()-1)+ans+"a";
  }
  return 0;
}

Measured memory_bytes: 3260
def examA():
    N = SI()
    ans = "No"
    for s in N:
        if s=="7":
            ans = "Yes"
    print(ans)
    return

def examB():
    N = I()
    ans = 0
    for i in range(1,N+1):
        if i%3==0:
            continue
        if i%5==0:
            continue
        ans += i
    print(ans)
    return

def examC():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    K = I()
    ans = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            cur = gcd(i,j)
            for k in range(1,K+1):
                ans += gcd(cur,k)
    print(ans)
    return

def examD():
    N = I()
    S = SI()
    R = [0]*(N+1)
    G = [0]*(N+1)
    B = [0]*(N+1)
    for i in range(N):
        s = S[i]
        R[i+1] += R[i]
        G[i+1] += G[i]
        B[i+1] += B[i]
        if s=="R":
            R[i+1] += 1
        elif s=="G":
            G[i+1] += 1
        elif s=="B":
            B[i+1] += 1
    ans = 0
    for l in range(N):
        Ls = S[l]
        for r in range(l+3,N):
            Rs = S[r]
            if (Ls=="R" and Rs=="B") or (Ls=="B" and Rs=="R"):
                ans += G[r] - G[l]
                if (l+r)%2==0:
                    if S[(l+r)//2]=="G":
                        ans -= 1
            elif (Ls=="R" and Rs=="G") or (Ls=="G" and Rs=="R"):
                ans += B[r] - B[l]
                if (l+r)%2==0:
                    if S[(l+r)//2]=="B":
                        ans -= 1
            elif (Ls=="G" and Rs=="B") or (Ls=="B" and Rs=="G"):
                ans += R[r] - R[l]
                if (l+r)%2==0:
                    if S[(l+r)//2]=="R":
                        ans -= 1
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 78712
#include<bits/stdc++.h>
using namespace std;
  
 
int main(){
     int N;
     cin >> N;
  std::vector<int> v;
  int sum = 0;
  for(int i=0;i<N;i+=1){
       int x;
       cin >> x;
          v.push_back(x);
          sum+=x;
  }
  int b=999999;
  int right = 0;
  for(int i=(N-1);i>=0;i-=1){
          sum-=v[i];
          right+=v[i];
          int ans = abs(sum-right);
          if(ans<b){
               b = ans;
          }
  }
  cout << b;
  
  
     
}

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 998244353;
const int maxn = (int) 200000 + 20;
const int maxm = (int) 1000000 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}


void work()
{
    int n, x;
    cin >>n >>x;
    if(n * 500 >= x) puts("Yes");
    else puts("No");
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int C = scanner.nextInt();

		if (A == B && A != C) {
			System.out.println("Yes");
			return;
		}
		if (B == C && B != A) {
			System.out.println("Yes");
			return;
		}
		if (C == A && C != B) {
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
		scanner.close();
	}

}


Measured memory_bytes: 23252
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;
 
using ll = long long;
 
//vector
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
 
//constant
const double EPS = 1e-10;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()
 
//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;
 
// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }
 
// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
 
// DP
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(){
 
    ll N, K;
    cin >> N >> K;
    
    vll A(N);
    REP(i, N){
        cin >> A[i];
        A[i]--;
    }
 
    vvll visited(N);
    vll rireki = {0};
 
    ll cur = 0;
    bool flag = false;
    REP(i, K){
        cur = A[cur];
        if (!visited[cur].empty()){
            flag = true;
            break;
        }
        rireki.push_back(cur);
        visited[cur].push_back(i + 1);
    }
 
    if(!flag) {
        cout << cur + 1 << endl;
        return 0;
    }
 
    ll second = rireki.size();
    ll first = visited[cur][0];
 
    ll idx = (K - first) % (second - first);
 
    cout << rireki[first + idx] + 1 << endl;
 
 
    return 0;
}

Measured memory_bytes: 15728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    set<char> st={ 'M', 'A', 'R', 'C' ,'H'};
    map<char,ll> mp;
    for(ll i=0;i<n;i++){
        string s;cin>>s;
        if(st.count(s[0]))mp[s[0]]++;
    }
    vector<ll> a;
    for(auto &ele:mp)a.push_back(ele.second);
    ll ans = 0 ; n=a.size();
    for(ll i=0;i<n;i++)for(ll j=i+1;j<n;j++)for(ll k=j+1;k<n;k++)ans+=a[i]*a[j]*a[k];//,cout<<i<<" "<<j<<" "<<k<<endl;
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 
  typedef pair<int,PII> PIPII;

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

bool isArea(int x, int y){
  return x>=0 && x<=100 && y>=0 && y<=100;
}

vector<vector<bool> > checked(101,vector<bool>(101,false));

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

bool bfs(const vector<PIPII> & v, const int N){
  queue<PIPII> que;
  que.push(v[0]);
  checked[v[0].second.first][v[0].second.second] = true;
  while(!que.empty()){
    PIPII p = que.front();que.pop();
    int h = p.first;
    int x = p.second.first;
    int y = p.second.second;
    bool issat = true;
    rep(i,N){
      if(v[i].first != max(h
            -abs(v[i].second.first - x)
            -abs(v[i].second.second - y),0)){
        issat = false;
        break;
      }
    }
    if(issat){
      cout << x SP y SP h << endl;
      return true;
    }
    rep(i,4){
      int nx = x+dx[i], ny = y + dy[i];
      if(!isArea(nx,ny))continue;
      if(checked[nx][ny])continue;
      checked[nx][ny] = true;
      que.push(PIPII(h+1,PII(nx,ny)));
    }
  }
  return false;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<PIPII> v(N);
  rep(i,N)cin >> v[i].second.first >> v[i].second.second >> v[i].first;
  sort(all(v),greater<PIPII>());
  bfs(v,N);
  return 0;
}


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

typedef long long int llint;

int lim = 9;
int c[11][11];

int dfs(int from, int cost);

int main()
{
  int a;
  int h, w;
  int cost[10] = {};

  cin>> h >> w;

  for(int i = 0; i < 10; i++) for(int j = 0; j < 10; j++) cin>> c[i][j];
  
  cost[1] = 0;
  for(int i = 0; i < 10; i++) {
    if(i == 1) continue;
    lim = c[i][1];
    cost[i] = dfs(i, 0);
  }

  int sum = 0;

  for(int i = 1; i <= h; i++) {
    for(int j = 1; j <= w; j++) {
      cin>> a;
      if(a != -1) sum += cost[a];
    }
  }

  cout<< sum <<endl;
  
  return 0;
}

int dfs(int from, int cost)
{
  if(lim <= cost) return lim;
  if(from == 1)   return cost;

  int rec = 1 << 30;

  for(int i = 0; i < 10; i++) {
    if(from == i) continue;
    rec = min(rec, dfs(i, cost + c[from][i]));
  }

  return rec;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<string>
#include<cmath>
#include<tuple>
#include <algorithm>
#define INF 1111111111
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> tup;
typedef long long ll;
vector<int> vec(100100);
vector<int> passed(100100);
vector<int> dx = {-1,1};
int n,k;

int main() {
  cin >> n ;
  int num = 1;
  int ans = 0;
  while(n>0){
    if(n%10==1)
    ans+=9*num;
    else
    ans+=1*num;
    n /= 10;
    num *= 10;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout << setprecision(12)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cin4(x, y, z, _) cin >> x >> y >> z >> _
#define cin5(x, y, z, p, q) cin >> x >> y >> z >> p >> q
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define Test ll _t; cin1(_t); rep(w, 0, _t)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cntv(v,a) count(v.begin(),v.end(),a)
#define fans(x) \
    if ( x  ) coul("YES"); \
    else coul("NO")

struct point{    int x, y, ind;   char ch;  };
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod = 1000000007;
const ll mx =131080;
//ll rnd(ll x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
bool cmp(point A, point B){   if(A.x != B.x) ret(A.x < B.x);  ret(A.y < B.y);   }
//void segPre(ll l, ll h, ll in) {  ll segTree[3*mx];   if ( l == h ){  segTree[ in ] = arr[ l ];   return;  }   ll m = (l + h) / 2; pre(l, m, 2*in);  pre(m+1, h, 2*in+1);    segTree[ in ] = segTree[ in*2 ] | segTree[ in*2+1 ];   segTree[ in ] = segTree[ in*2 ] ^ segTree[ in*2+1 ];    }
// head collected
// Don't use variable name as --> prev, time, _t, w, y1


db n;


start;
// op = 0 when n = even
    cin1(n);

    cout << 2*pi*n << "\n";

finish


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

int main(){
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int count = 0;
  rep(i, n){
    rep(j, n){
      int bz = n - r*i - g*j;
      if (bz >= 0 && bz % b == 0) count++;
    }
  }
  
  cout << count << endl;
      
  
}

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

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

	vector<long long int> a(n);

	for(auto& an : a){
		cin >> an;
	}

	sort(a.begin(),a.end());

	long long int prev = 0;
	vector<long long int> pole;

	for(int i = n - 1; i >= 0; --i){
		if(prev == a[i]){
			pole.push_back(prev);
			prev = 0;
			if(pole.size() == 2){
				cout << pole[0] * pole[1] << endl;
				return 0;
			}
			continue;
		}
		prev = a[i];
	}

	cout << 0 << endl;
	return 0;

}

Measured memory_bytes: 1024
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

const int MOD = 1e9 + 7;

int power(int n, int p)
{
    if (p == 0)
        return 1;
    long long res = 1;
    long long add = n;
    while (p > 0)
    {
        if (p & 1)
            res = (res * add) % MOD;
        p >>= 1;
        add = add*add%MOD;
    }
    return res;
}

      

int getinv(int n) {
    static int invtable[1000001];
    if (invtable[n])
        return invtable[n];
    return invtable[n] = power(n, MOD - 2);
}

int comb(int n, int r) {
    long long res = 1;
    for (int i = n - r + 1; i <= n; i++)
        res = (res * i) % MOD;
    for (int i = 1; i <= r; i++)
        res = (res * getinv(i)) % MOD;

    return res;
}
      



int main() {
    int x, y;
    cin >> x >> y;
    if((x + y) % 3){
        cout << 0 << endl;
        return 0;
    }
    if(x > y)
        swap(x, y);
    
    int n = (x + y) / 3;
    if(x < n || y > 2 * n){
        cout << 0 << endl;
        return 0;
    }

    int diff = y - x;
    int tmp = n - diff;
    if(tmp % 2){
        cout << 0 << endl;
        return 0;
    }
    int xkai = tmp / 2;
    int ykai = n - xkai;

    cout << comb(n, xkai) << endl;

    return 0;
}

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;

  string ans = "";
  if (a >= b) {
    ans = "delicious";
  } else {
    if (b - a <= x) {
      ans = "safe";
    } else {
      ans = "dangerous";
    }
  }

  // 解答
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
#define dwn(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	string s;
	cin >> s;
	rep(i, 4) {
		cout << s[i];
	}
	cout << " ";
	REP(i, 4, (int)s.size()) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
long long c, s;
string a;
int main() {
	cin>>a;
	for(int i=a.size()-1; i>=0; i--) {
		if(a[i]=='W') c++;
		else s += c;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const ll mod = (int) 10e8+7;

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

    vi a(N);
    REP(i,N) cin >> a[i];

    int cnt = 0;
    REP(i,N) REP(j,N) {
        if (i > j) continue;
        if (a[i] > a[j]) {
            cnt++;
            // cout << a[i] << ">" << a[j] << endl;
        }
    }
       
    if (K == 1) {   
        cout << cnt << endl;  
        return 0;
    }
 
    int cnt2 = 0;
    REP(i,N) REP(j,N) {
        
        if (a[i] > a[j]) {
            cnt2++;
            // cout << a[i] << ">" << a[j] << endl;
        }
    }
    
    
    
    long long C1 = K;
	long long C2 = K * (K - 1) / 2LL; C2 %= mod;
    ll ans = (cnt*C1 + cnt2 * C2) % mod;
    //cout << cnt << "*" << K << "+" << dif << "*" << (K*(K-1))/2 << endl;

    cout << ans%mod << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

int main()
{
	int N;
	std::map<int, int> A;

	std::cin >> N;
	for (int i = 0; i < N; ++i) {
		int a;
		std::cin >> a;
		++A[a];
	}

	if (A.size() == 1) {
		if (A.begin()->first == 0) {
			std::cout << "Yes\n";
		} else {
			std::cout << "No\n";
		}
	} else if (N % 3 == 0) {
		if (A.size() == 3) {
			auto it = A.begin();
			auto jt = it; ++jt;
			auto kt = jt; ++kt;
			if ((it->first ^ jt->first) == kt->first && it->second == jt->second && jt->second == kt->second) {
				std::cout << "Yes\n";
			} else {
				std::cout << "No\n";
			}
		} else if (A.size() == 2) {
			auto it = A.begin();
			auto jt = it; ++jt;
			if (it->first != 0) {
				std::swap(it, jt);
			}
			if (it->first != 0) {
				std::cout << "No\n";
			} else if (it->second * 2 == jt->second) {
				std::cout << "Yes\n";
			} else {
				std::cout << "No\n";
			}
		} else {
			std::cout << "No\n";
		}
	} else {
		std::cout << "No\n";
	}
}


Measured memory_bytes: 3840
h, w = [int(i) for i in input().split()]
s = [list(input()) for _ in range(h)]
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]

for i in range(h):
    for j in range(w):
        count = 0
        if s[i][j] == '#':
            continue
        else:
            for d in range(8):
                if (0 <= i+dy[d] < h) and (0 <= j+dx[d] < w):
                    if s[i+dy[d]][j+dx[d]] == '#':
                        count += 1
            s[i][j] = str(count)

for i in range(h):
    print(''.join(s[i]))

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

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

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1000000000;

int main(){
   int n;
   cin >> n;
   for(int i=0;i<=n/7;i++){
      for(int j=0;j<=n/4;j++){
         if(n == 7*i+4*j){
            cout << "Yes";
            return 0;
         }
      }
   }
   cout << "No";
   return 0;
}

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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;


int main() {
	int k, t;
	cin >> k >> t;
	int mx = 0;
	for (int i = 0; i < t; ++i) {
		int a;
		cin >> a;
		mx = max(mx, a);
	}
	if (mx <= (k + 1) / 2) {
		cout << 0 << "\n";
	}
	else {
		cout << mx - ((k - mx) + 1) << "\n";
	}
	return 0;
}




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

static const long long INF = (1LL<<60);

int main() {
    int N, M, R; std::cin >> N >> M >> R;
    std::vector<int> r(R);
    for (int i = 0; i < R; i++) {
        std::cin >> r[i];
        r[i]--;  // 0 begin;
    }
    std::vector<std::vector<long long >> G(N, std::vector<long long>(N, INF));
    for (int i = 0; i < N; i++) {
        G[i][i] = 0;
    }

    for (int i = 0; i < M; i++) {
        int a, b, c;
        std::cin >> a >> b >> c;
        a--; b--;
        G[a][b] = G[b][a] = c;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                G[i][j] = std::min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }

    std::sort(r.begin(), r.end());
    long long min = INF;
    do {
        long long s = 0;
        for (int i = 1; i < R; i++) {
            s += G[r[i-1]][r[i]];
        }
        min = std::min(min, s);
    } while (std::next_permutation(r.begin(), r.end()));

    std::cout << min << std::endl;
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3 2 6");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3 1 3");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5 10 1");
            //4
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();

        int W = wkArr[0];
        int a = wkArr[1];
        int b = wkArr[2];

        int Left = Math.Min(a, b);
        int Right = Math.Max(a, b);

        //間にある場合
        if (Left <= Right && Right <= Left + W) {
            Console.WriteLine(0);
        }
        else {
            Console.WriteLine(Right - (Left + W));
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#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 FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    char N;
    cin >> N;

    char ans = 0;

    if ('a'<= N && N<= 'z') {
        ans = 'a';
    }
    else {
        ans = 'A';
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll N,A[200007];

int main(){
  cin >> N;
  rep(i,N){
    cin >> A[i];
  }
  ll L=0,R=0,Xsum=0,sum=0,ANS=0;
  while(1){
    Xsum^=A[R];sum+=A[R];
    R++;
    while(Xsum!=sum){
      Xsum^=A[L];sum-=A[L];
      L++;
    }
    ANS+=R-L;
    if(R==N){
      break;
    }
  }
  cout << ANS << endl;
}


Measured memory_bytes: 5168
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vec vector
#define psb push_back
#define ppb pop_back
#define mkp make_pair
#define fst first
#define scd second
#define ins insert
#define psf push_front
#define ppf pop_front
using namespace std;
ll fact(ll n) {
	ll ans = 1, i, modv = 1e9+7;
	for(i = 1; i <= n; i++) {
		ans = ans * i % modv;
	}
	return ans;
}
ll modExp(ll a, ll b, ll c) {
	a %= c;
	ll ans = 1;
	for(; b; b >>= 1) {
		if(b & 1){
			ans *= a;
			ans %= c;
		}
		a *= a;
		a %= c;
	}
	return ans;
}
int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll a, b, modv = 1e9+7;
	cin >> a >> b;
	if(((a << 1) - b) < 0 || ((b << 1) - a) < 0) {
		cout << 0;
		return 0;
	}
	if(((a << 1) - b)%3 == 0 && ((b << 1) - a)%3 == 0) {
		ll x = ((a << 1) - b) / 3;
		ll y = ((b << 1) - a) / 3;
		ll ans = fact(x + y);
		ans = ans * modExp(fact(x) * fact(y) % modv, modv - 2, modv) % modv;
		cout << ans;
	}
	else {
		cout << 0;
	}
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
S = input()
y = int(S[:4])
m = int(S[5:7])
d = int(S[8:10])
ans = False


def solve():
    if y != 2019:
        return y < 2019
    if m != 4:
        return m < 4
    if d != 30:
        return d < 30
    return True


print(['TBD', 'Heisei'][solve()])

Measured memory_bytes: 3064
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    def bfs(n, e, fordfs, C):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        i = 0
        W[e] = C[i]
        i += 1
        que = deque()
        que.append(e)
        while que and i<n:
            now = que.popleft()
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = C[i]
                    i += 1
                    que.append(ne)
        return W
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        A, B = LI()
        V[A-1].append(B-1)
        V[B-1].append(A-1)
    C = LI(); C.sort(reverse=True)
    e = 0
    ans = bfs(N,e,V,C)
    print(sum(ans)-C[0])
    print(" ".join(map(str,ans)))
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

Measured memory_bytes: 46032
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int k,x;cin>>k>>x;
  int start = x-(k-1);
  int end = x+(k-1);
  for(int j=start;j<=end;++j) {
    if(-1000000<=j||j<=1000000)
    cout<<j<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n,k;
    cin >> n >> k;
    vector<int> d(k);
    for(int i=0;i<k;i++){
        cin >> d[i];
    }

    int keta,n2=0;
    
    for(int i=n;i<=99999;i++){
        bool flag=true;
        n2=i;
        while(n2>0){ 
            keta=n2%10;
            rep(j,k){
                if(keta==d[j]){
                    flag=false;
                    break;
                }
            }
            n2=n2/10;
        }
        if(flag==true){
            cout << i;
            return 0;
        }
    }
}

Measured memory_bytes: 256
n = int(input())
points = [complex(*map(int, input().split())) for _ in range(n)]
edges = [p1 - p0 for p0, p1 in zip(points, points[1:] + [points[0]])]
prev = edges[0]
while edges:
    edge = edges.pop()
    if edge.real * prev.imag - prev.real * edge.imag < -1e-6:
        print(0)
        break
    prev = edge
else:
    print(1)

Measured memory_bytes: 7728
#include<iostream>
using namespace std;
long long n,a,b;
int main()
{
    cin>>n>>a>>b;
    if((n==1 && a==b) || (n>1 && b>=a))
    {
        cout<<(n-2)*(b-a)+1<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N=3005;
const int MOD=1000000007;

int n,m,c[N][N],a[N],f[N][N];
struct data{int l,r;}op[N];
char str[N];

bool cmp(data a,data b)
{
    return a.l<b.l||a.l==b.l&&a.r<b.r;
}

void mod(int &x)
{
    x-=x>=MOD?MOD:0;
}

void prepare()
{
    c[0][0]=1;
    for (int i=1;i<=n;i++)
    {
        c[i][0]=1;
        for (int j=1;j<=i;j++) mod(c[i][j]=c[i-1][j]+c[i-1][j-1]);
    }
}

int main()
{
    scanf("%d%d",&n,&m);
    prepare();
    scanf("%s",str+1);
    for (int i=1;i<=n;i++) a[i]=a[i-1]+str[i]-'0';
    for (int i=1;i<=m;i++) scanf("%d%d",&op[i].l,&op[i].r);
    sort(op+1,op+m+1,cmp);
    int tmp=m,mx=0;
    for (int i=1;i<=m;i++)
        if (op[i].l==op[i+1].l||op[i].r<=mx) tmp--,op[i].l=n+1;
        else mx=max(mx,op[i].r);
    sort(op+1,op+m+1,cmp);
    m=tmp;
    f[op[1].l-1][a[op[1].l-1]]=1;
    op[m+1].l=n+1;
    for (int i=1;i<=m;i++)
    {
        int l=op[i].l,r=op[i].r,nx=op[i+1].l;
        for (int j=0;j<l;j++)
        {
            if (!f[l-1][j]) continue;
            int s=a[r]-j,p=max(0,s-(r-nx+1)),q=min(s,nx-l);
            if (nx>r) {mod(f[nx-1][a[nx-1]]+=(LL)f[l-1][j]*c[r-l+1][s]%MOD);continue;}
            if (p>q) continue;
            for (int k=p;k<=q;k++) mod(f[nx-1][j+k]+=(LL)f[l-1][j]*c[nx-l][k]%MOD);
        }
    }
    printf("%d",f[n][a[n]]);
    return 0;
}

Measured memory_bytes: 69120
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

/*N個の箱が横一列に並んでいます。 最初、左からi番目の箱には 
ai 個のキャンディが入っています。
すぬけ君は次の操作を好きな回数だけ行うことができます。
キャンディが1個以上入っている箱をひとつ選び、その箱のキャンディを 
1個食べる.すぬけ君の目標は次の通りです。
どの隣り合う2つの箱を見ても、それらの箱に入っているキャンディの個数の総和が 
x以下である。
目標を達成するために必要な操作回数の最小値を求めてください。*/
using namespace std;
int main() {
	int N, x;
	cin >> N >> x;
	int tmp;
	vector<int> v;
	long ans = 0;
	while (cin >> tmp) v.push_back(tmp);
	for (int i = 1; i < v.size(); i++) {
		int gap;
		if ((gap = v[i - 1] + v[i] - x) > 0) {
			ans += gap;
			v[i] = max(v[i] - gap, 0);
		}
	}
	cout << ans << endl;
}


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

int main(){
int R,G,B,N;
cin>>R>>G>>B>>N;
int ans = 0;
for(int r=0;r<N/R+1;r++){
for(int g=0;g<(N-R*r)/G+1;g++){
if( (N-R*r-G*g) < 0) continue;
if( (N-R*r-G*g)%B != 0) continue;

ans ++;
//cout<<r<< "  " <<g<<endl;
}
}
cout << ans << endl;
}

Measured memory_bytes: 256