akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main()
{
   int N;
   string S;
   cin >> N >> S;
   if (N<3200)
      cout<< "red" << endl;
   else
      cout << S <<endl;
   return;
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}


Measured memory_bytes: 256
import collections

n = int(input())
v_list = [int(x) for x in input().split()]
v_oddlist = v_list[::2]
v_evenlist = v_list[1::2]
c_odd = collections.Counter(v_oddlist)
c_even = collections.Counter(v_evenlist)
if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
    print(n - c_odd.most_common()[0][1] - c_even.most_common()[0][1])
elif len(c_odd.most_common()) == 1 and len(c_even.most_common()) == 1:
    print(n - c_odd.most_common()[0][1])
else:
    a = c_odd.most_common()[0][1] + c_even.most_common()[1][1]
    b = c_odd.most_common()[1][1] + c_even.most_common()[0][1]
    if a > b:
        print(n - a)
    else:
        print(n - b)


Measured memory_bytes: 19040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,l;
  cin >> n >> l;
  vector<string>str(n);
  for(int i=0;i<n;i++){
    cin >> str.at(i);
  }
  sort(str.begin(),str.end());
  string ans ="";
  for(int i =0;i<n;i++){
    ans += str.at(i);
  }
  cout << ans << endl;
}

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

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

    for(int i = 0; i <= 3; ++i) {
        cout << s[i];
    }
    cout << " ";

    for(int i = 4; i <= 11; ++i) {
        cout << s[i];
    }
    cout << endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
using namespace std;

int main() {
  int N,M;
  cin >> N >> M;
  vector<vector<int> > connect(N,vector<int>());
  vector<int> a(M),b(M);
  rep(i,M){
    cin >> a[i] >> b[i];
    a[i]--,b[i]--;
    connect[a[i]].push_back(b[i]);
    connect[b[i]].push_back(a[i]);
  }
  int ans=0;
  while(true){
    vector<int> graph;
    rep(i,N){
      if(connect[i].size()==1){
        graph.push_back(i);
      }
    }
    if(graph.size()==0) break;
    for(int g : graph){
      if(connect[g].size()==0) break;
      auto itr=find(connect[connect[g][0]].begin(),connect[connect[g][0]].end(),g);
      connect[connect[g][0]].erase(itr);
      connect[g].clear();
      ans++;
    }
    graph.clear();
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
# ALDS1_3_A.py
from collections import deque as stack
S = input().split()
q = stack([])
# print(S)
for i in S:
    # print("i:", i)
    if i == "+":
        b = int(q.pop())
        a = int(q.pop())
        q.append(a+b)
        # print("+:", a, b)
    elif i == "-":
        b = int(q.pop())
        a = int(q.pop())
        q.append(a-b)
        # print("-:", a, b)
    elif i == "*":
        b = int(q.pop())
        a = int(q.pop())
        # print("*:", a, b)
        q.append(a*b)
    else:
        q.append(int(i))
print(q.pop())



Measured memory_bytes: 5996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,t,ans;
priority_queue<ll> pq;
int main()
{
    scanf("%lld%lld",&n,&m);
    for(ll i=1;i<=n;i++)
    {
        scanf("%lld",&t);
        pq.push(t);
    }
    while(m)
    {
        ll t=pq.top();
        pq.pop();
        t/=2;
        m--;
        pq.push(t);
        //printf("%lld\n",t);
    }
    while(!pq.empty())
    {
        ans+=pq.top();
        pq.pop();
        //printf("%lld\n",ans);
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main() {

	char s[12];
	cin >> s;
	if(s[6]<'4'){
		switch(s[5]){
		case '0':
			cout << "Heisei" << endl;
			break;
		case '1':
			cout << "TBD" << endl;
			break;}
	}else if(s[6]>'4'){
		cout << "TBD" << endl;
	}else if(s[8]<'3'){
		cout << "Heisei" << endl;
	}else if(s[9] == '0'){
		cout << "Heisei" << endl;
	}else{
		cout << "TBD" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    E = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v = map(int,input().split())
        u -= 1; v -= 1
        E[u].append(v)
        E[v].append(u)

    dp = [[1] * 2 for _ in range(n)]
    stack = [(~0, -1), (0, -1)]
    while stack:
        v, p = stack.pop()
        if v >= 0:
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            v = ~v
            white = black = 1
            for nv in E[v]:
                if nv == p:
                    continue
                white = white * (dp[nv][0] + dp[nv][1]) % MOD
                black = black * dp[nv][0] % MOD
            dp[v][0], dp[v][1] = white, black

    print((dp[0][0] + dp[0][1]) % MOD)
resolve()

Measured memory_bytes: 84400
from math import factorial

n=int(input())
fcr=[]
for i in range(1,n+1):
    p=2
    while p*p<=i:
        while i%p==0:
            fcr.append(p)
            i//=p
        p+=1
    if i>1:
        fcr.append(i)
ans=1
s_fcr=set(fcr)
for i in s_fcr:
    ans*=fcr.count(i)+1
print(ans%(10**9+7))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

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

  string s;
  cin >> s;

  if (s == "SUN") cout << 7 << endl;
  if (s == "MON") cout << 6 << endl;
  if (s == "TUE") cout << 5 << endl;
  if (s == "WED") cout << 4 << endl;
  if (s == "THU") cout << 3 << endl;
  if (s == "FRI") cout << 2 << endl;
  if (s == "SAT") cout << 1 << endl;

  return 0;
}


Measured memory_bytes: 256
local function meld(a,b)
    if not a then
        return b
    elseif not b then
        return a
    elseif a[1]<b[1] then
        b[4]=a[3]
        a[3]=b
        return a
    else
        a[4]=b[3]
        b[3]=a
        return b
    end
end

local function pair(a)
    local b,c,d,e
    while a do
        c=false
        b=a
        a=a[4]
        b[4]=false
        if a then
            c=a
            a=a[4]   
            c[4]=false
        end
        b=meld(b,c)
        b[4]=d
        d=b
    end
    while d do
        e=d
        d=d[4]
        a=meld(a,e)
    end
    return a
end


local PairingHeap={}

PairingHeap.empty=function(self)
    return not self[1]
end

PairingHeap.push=function(self,key,value)
    self[1]=meld(self[1],{key,value,false,false})
end

PairingHeap.top=function(self)
    return self[1][2]
end

PairingHeap.pop=function(self)
    self[1]=pair(self[1][3])
end

PairingHeap.join=function(self,other)
    if self[1][1]<other[1][1]then
		other[1][4]=self[1][3]
        self[1][3]=other[1]
	else
		self[1][4]=other[1][3]
        other[1][3]=self[1]
        self[1]=other[1]
    end
    return self
end

PairingHeap.new=function(self)
    local obj={}
    setmetatable(obj,{__index=PairingHeap})
    return obj
end

----------
 
local n,m=io.read("n","n")
local a=PairingHeap:new()
for i=1,n do
    local input=io.read("n")
    a:push(-input,input)
end
 
for i=1,m do
    local x=a:top()
    x=(x//2)
    a:pop()
    a:push(-x,x)
end
 
local total=0
for i=1,n do
    total=total+a:top()
    a:pop()
end
print(total)

Measured memory_bytes: 29200
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {	

	private static void solve(){
		//Implement solution here.
		String S = next();
		for(int i = 0; i < 3; i++) {
			System.out.print(S.charAt(i));
		}
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 25376
N = int(input())
cur_t = 0
cur_x = 0
cur_y = 0
flag = True
for i in range(N):
    t, x, y = map(int, input().split())
    cur_t += abs(x - cur_x)
    cur_t += abs(y - cur_y)
    if(cur_t > t):
        print('No')
        flag = False
        break
    cur_x = x
    cur_y = y
    if((t - cur_t) % 2 != 0):
        print('No')
        flag = False
        break

if(flag):
    print('Yes')

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

static inline int int_size(int n){ return (int)log10(n) + 1; }
static inline int split(int n, int s){ 
  int deli = (int)pow(10, s);
  return (n % deli) * (n / deli);
}

int main()
{
  rep(i, in()){
    int n = in();

    int count = 0;
    bool ok = true;
    set<int> vis;
    while (n > 9){
      int maxi = 0;
      count++;
      rep(j, int_size(n) - 1){
        maxi = max(maxi, split(n, j + 1));
      }
      if (vis.find(maxi) != vis.end()){
        ok = false;
        break;
      }
      else {
        vis.insert(maxi);
      }
      n = maxi;
    }
    if (ok){
      printf("%d\n", count);
    }
    else {
      printf("-1\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1252
use strict;
use warnings;
use utf8;
use feature qw/say/;

my $S = <STDIN>;
my $length = length($S);

chop($S);
chop($S);

for (0..$length) {
  if (length($S)%2 == 0){
    if (substr($S, 0, length($S)/2) eq substr($S, length($S)/2, length($S))){
      print length($S);
      last;
    }
  }
  chop($S);
}

Measured memory_bytes: 768
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int w,a,b;
  cin>>w>>a>>b;
  if(a<b){
    cout<<(b-(a+w)<=0 ? 0 : b-(a+w))<<'\n';
  }
  else{
    cout<<(a-(b+w)<=0 ? 0 : a-(b+w))<<'\n';
  }
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
///////////////////////////////////////////////
int main(){
	int N;
	SCD(N);
	static int h[100002] = {};
	h[0] = 0;
	FORq(i,1,N){
		SCD(h[i]);
	}

	static int dp[100002] = {};
	dp[0] = 0;
	FORq(i,1,N){
		if (i == 1) dp[1] = 0;
		else if (i == 2) dp[2] = abs(h[2] - h[1]);
		else dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]) , dp[i-2] + abs(h[i-2] - h[i]));
	}

	PRINTD(dp[N]);


}


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

int main() {
	long long N, K;
	cin >> N >> K;
	vector<long long>A(N);
	long long sum = 0;
	for (int n = 0;n<N;++n) {
		cin >> A[n];
		sum += (long long)A[n];
	}
	set<long long>B;
	for (int i = 1;i*i<sum; ++i) {
		if (0 == sum%i) {
			B.insert(i);
			B.insert(sum/i);
		}
	}
	long long ans = 0;
	
	for (auto itr = B.begin();itr != B.end();itr++) {
		long long nowans = 1e18;
		long long now = *itr;
		vector<long long>C(N);
		for (int n = 0; n < N; ++n) {
			C[n] = A[n] % now;
		}	
		sort(C.begin(), C.end());
		long long l = 0;
		long long r = 0;
		vector<long long>L(N);
		vector<long long>R(N);
		for (int n = 0; n < C.size(); ++n) {
			L[n] = C[n];
			R[n] = now - C[n];
			l += L[n]; 
		}
		nowans = min(nowans, max(l, r));
		for (int n = 0; n < C.size(); ++n) {
			l -= L[C.size()-1-n];
			r += R[C.size() - 1-n];
			nowans = min(nowans, max(l, r));
		}
		if (K >= nowans) {
			ans = max(ans, now);
		}
	}
	cout << ans << endl;
	return 0;
}

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


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

    cout<< ( (abs(a-x)<abs(b-x) ? 'A' : 'B')) <<endl;


    return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())

target_total = 0

for n in range(1, N + 1):
    total_each_digit = 0
    n_length = len(str(n))
    
    for i in range(n_length):
        total_each_digit += int(str(n)[i])
    if A <= total_each_digit <= B:
        target_total += n

print(target_total)

Measured memory_bytes: 3060
import sys
from math import floor,ceil
K=int(input())
A=[int(i) for i in input().split()]
def f(x):
    t=x
    for a in A:
        t=t-(t%a)
    return t

mi=0
ma=10**16
while ma-mi>1:
    mid=(ma+mi)//2
    if f(mid)>=2:
        ma=mid
    else:
        mi=mid
left=ma
mi=0
ma=10**16
while ma-mi>1:
    mid=(ma+mi)//2
    if f(mid)<=2:
        mi=mid
    else:
        ma=mid
if left>mi:
    print(-1)
else:
    print(left,mi)

Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
int n;
int A,B;
long long ans=0;
long long x[10010006];
long long y[10010006];
int main()
{
	scanf("%d %d %d",&n,&A,&B);
	x[0]=0;
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	for(int i=1;i<=n-1;i++)
	    y[i]=x[i+1]-x[i];
	for(int i=1;i<=n-1;i++)
	{
		if(y[i]*A<=B) ans+=y[i]*A;
		else ans+=B;
	}
	printf("%lld",ans);
	return 0;
} 

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

map<int, int> r;

int main() {
	int n; cin >> n;
	int res = 0;
	for (int i = 0; i < n; i++)
	{
		int a; cin >> a;
		if(r[a] == 0) {
			res++;
			r[a] = 1;
		}
		else {
			res--;
			r[a] = 0;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 8120
#include <stdio.h>

int main()
{
    int k,s,i,j,ans = 0;

    scanf("%d %d",&k,&s);

    for (i = 0; i <= k; i++)
    {
        for (j = 0; j <= k; j++)
        {
          	//printf("%d %d %d\n",i,j,s - i - j);
            if ((0 <= s - i - j) && (s - i - j <= k))
            {
              	//printf("%d %d %d\n",i,j,s - i - j);
                ans ++;
            }
        }
    }

    printf("%d",ans);
}

Measured memory_bytes: 128
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int W = in.nextInt();
		int H = in.nextInt();
		int cnt = 0;
		int [] status = new int [2];
		int [] moveto = new int [2];
		int N = in.nextInt();
		for(int i = 0; i < N; i++){
			for(int k = 0; k < 2; k++){
				moveto[k] = in.nextInt();
			}
			if(i == 0){
				for(int k = 0; k < 2; k++){
					status[k] = moveto[k];
				}
				//System.out.println("スタート地点"+status[0]+","+status[1]);
			}
			else{
				int flg = 0;
				while(flg == 0){
					int compare = comp(moveto,status);
					switch (compare){
					case 0:
						status[0]--;
						cnt++;
						//System.out.println("1移動");
						//System.out.println("左に移動"+status[0]+","+status[1]);
						//System.out.println("移動目標"+moveto[0]+","+moveto[1]);
						break;
					case 1:
						status[0]--;
						status[1]--;
						cnt++;
						//System.out.println("1移動");
						//System.out.println("左下に移動"+status[0]+","+status[1]);
						//System.out.println("移動目標"+moveto[0]+","+moveto[1]);
						break;
					case 2:
						status[0]--;
						status[1]++;
						cnt += 2;
						//System.out.println("2移動");
						//System.out.println("左上に移動"+status[0]+","+status[1]);
						//System.out.println("移動目標"+moveto[0]+","+moveto[1]);
						break;
					case 3:
						flg++;
						break;
					case 4:
						status[1]--;
						cnt++;
						//System.out.println("1移動");
						//System.out.println("下に移動"+status[0]+","+status[1]);
						//System.out.println("移動目標"+moveto[0]+","+moveto[1]);
						break;
					case 5:
						status[1]++;
						cnt++;
						//System.out.println("1移動");
						//System.out.println("上に移動"+status[0]+","+status[1]);
						//System.out.println("移動目標"+moveto[0]+","+moveto[1]);
						break;
					case 6:
						status[0]++;
						//System.out.println("1移動");
						//System.out.println("右に移動"+status[0]+","+status[1]);
						//System.out.println("移動目標"+moveto[0]+","+moveto[1]);
						cnt++;
						break;
					case 7:
						status[0]++;
						status[1]--;
						//System.out.println("2移動");
						//System.out.println("右下に移動"+status[0]+","+status[1]);
						//System.out.println("移動目標"+moveto[0]+","+moveto[1]);
						cnt += 2;
						break;
					case 8:
						status[0]++;
						status[1]++;
						cnt++;
						//System.out.println("1移動");
						//System.out.println("右上に移動"+status[0]+","+status[1]);
						//System.out.println("移動目標"+moveto[0]+","+moveto[1]);
						break;
					}
				}
			}
		}
		System.out.println(cnt);
	}
	public static int comp(int after[], int before[]){
		int distx = after[0] - before[0];
		int disty = after[1] - before[1];
		if(distx < 0){
			if(disty == 0) return 0;
			else if(disty < 0) return 1;
			else return 2;
		}
		else if(distx == 0){
			if(disty == 0) return 3;
			else if(disty < 0) return 4;
			else return 5;
		}
		else{
			if(disty == 0) return 6;
			else if(disty < 0) return 7;
			else return 8;
		}
	}
}

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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

ld l;

int main()
{
	cin >> l;
	cout << setprecision(10) << fixed << l * l * l / 27;
	return 0;
}


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

struct kank{
  ll num;
  ll dx;
};

int main(){
  
  ll n,m;
  cin>>n>>m;
  ll l[m],r[m],d[m];
  list<kank> kanks[n+1];
  REP(i,m){
    cin>>l[i]>>r[i]>>d[i];
    kank k;
    k.num = r[i];
    k.dx = d[i];
    kanks[l[i]].push_back(k);
    k.num = l[i];
    k.dx = -d[i];
    kanks[r[i]].push_back(k);
  }
  
  string ans = "Yes";
  ll x[n+1];
  REP(i,n+1){
    x[i] = 0;
  }
  bool tukatta[n+1];
  REP(i,n+1){
    tukatta[i] = false;
  }
  
  for(int i=1;i<=n;i++){
    if(tukatta[i]==false){
      tukatta[i] = true;
      queue<ll> q;
      q.push(i);
      while(!q.empty()){
        ll l = q.front();
        q.pop();
        tukatta[l] = true;
        while(!kanks[l].empty()){
          kank k = kanks[l].front();
          kanks[l].pop_front();
          if(tukatta[k.num]){
            if((x[k.num]-x[l])!=k.dx){
//              cout<<k.dx<<" "<<x[k.num]-x[l]<<endl;
              ans="No";
              cout<<ans<<endl;
              return 0;
            }
          }else{

            x[k.num] = x[l] + k.dx;
           //             cout<<k.num<<" "<<x[k.num]<<endl;
            q.push(k.num);
            tukatta[k.num]=true;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  
  return 0;
}



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

int main() {
	int N; cin >> N;
	int sum = 0;
	int neg = INT_MAX;
	for (int i = 0; i < N; ++i) {
		int t = 0; cin >> t;
		sum += t;
		if (t % 10 != 0) {
			neg = min(neg, t);
		}
	}
	if (sum % 10 == 0) {
		if (neg == INT_MAX) {
			cout << 0 << endl;
		}
		else {
			cout << sum - neg << endl; 
		}
	}
	else {
		cout << sum << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

signed main() {
    int N;
    cin >> N;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    int Min = 1;
    int Max = N;
    for(int i = 0;i < N - 1;i++) {
        if(vec.at(i) >= vec.at(i + 1)) {
            Min++;
        }
    }
    cout << Min << endl;
    cout << Max << endl;
}


Measured memory_bytes: 3616
N = input()
if len(N) == 1:
	if N == '3':
		print('bon')
	elif N == '0' or N == '1' or N == '6' or N == '8':
		print('pon')
	else:
		print('hon')
elif len(N) == 2:
	if N[1] == '3':
		print('bon')
	elif N[1] == '0' or N[1] == '1' or N[1] == '6' or N[1] == '8':
		print('pon')
	else:
		print('hon')
elif len(N) == 3:
	if N[2] == '3':
		print('bon')
	elif N[2] == '0' or N[2] == '1' or N[2] == '6' or N[2] == '8':
		print('pon')
	else:
		print('hon')

Measured memory_bytes: 9096
import itertools

n = int(input())

name = {"M":[],"A":[],"R":[],"C":[],"H":[]}
for i in range(n):
    s = input()
    if s[0] not in name:
        continue
    else:
        name[s[0]].append(s)

ans = 0
for p,q,r in itertools.combinations(name.keys(), 3):
    ans += len(name[p])*len(name[q])*len(name[r])
    
print(ans)

Measured memory_bytes: 83772
#pragma warning(disable: 4996)
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	int n = s.size() / 2;
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] != s[s.size() - 1 - i]) {
			++cnt;
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N, C = getNM()
query = [getList() for i in range(N)]

query_alta = copy.deepcopy(query)
query_alta.sort(reverse = True)

imos_fore = [0]
imos_back = [0]
for i in range(N):
    # 右回り
    imos_fore.append(imos_fore[i] + query[i][1])
    # 左周り
    imos_back.append(imos_back[i] + query_alta[i][1])

imos_fore_back = copy.deepcopy(imos_back)
imos_back_back = copy.deepcopy(imos_fore)

for i in range(1, N + 1):
    imos_fore[i] -= query[i - 1][0]
    imos_back_back[i] -= 2 * query[i - 1][0]
    imos_back[i] -= (C - query_alta[i - 1][0])
    imos_fore_back[i] -= 2 * (C - query_alta[i - 1][0])

for i in range(1, N + 1):
    imos_fore_back[i] = max(imos_fore_back[i], imos_fore_back[i - 1])
    imos_back_back[i] = max(imos_back_back[i], imos_back_back[i - 1])

fore_ans = 0
for i in range(N + 1):
    opt = imos_fore[i] + imos_fore_back[N - i]
    fore_ans = max(fore_ans, opt)

back_ans = 0
for i in range(N + 1):
    opt = imos_back[i] + imos_back_back[N - i]
    back_ans = max(back_ans, opt)

print(max(fore_ans, back_ans))

Measured memory_bytes: 151928
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

struct UnionFind {
  vector<int> c, s;
  UnionFind(size_t n) : c(n), s(n, 1) { iota(begin(c), end(c), 0); }
  int root(int i) { return c[i] == i ? i : (c[i] = root(c[i])); }
  bool same(int i, int j) { return root(i) == root(j); }
  void unite(int i, int j) {
    i = root(i); j = root(j);
    if (i != j) {
      if (s[i] > s[j]) { c[j] = i; s[i] += s[j]; }
      else { c[i] = j; s[j] += s[i]; }
    }
  }
  int size(int i) { return s[root(i)]; }
};

lli n, k, l;
int main() {
  cin >> n >> k >> l;
  UnionFind ufp(n+1), ufr(n+1), ufm(n+1);
  for (lli i=0; i<k; ++i) {
    lli u, v; cin >> u >> v;
    ufp.unite(u, v);
  }
  for (lli i=0; i<l; ++i) {
    lli u, v; cin >> u >> v;
    ufr.unite(u, v);
  }
  map<pair<lli, lli>, lli> m;
  for (lli i=1; i<=n; ++i) {
    m[make_pair(ufp.root(i), ufr.root(i))]++;
  }
  for (lli i=1; i<=n; ++i) {
    cout << m[make_pair(ufp.root(i), ufr.root(i))] << '\n';
  }
  return 0;
}



Measured memory_bytes: 16640
fun main(args:Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val states = readLine()!!.trim().split(' ').map(String::toInt)
    val ranges = states.indices.mapNotNull { i ->
        when {
            i == 0 ->
                i until ((i + 1 until n).find { j -> states[j] != states[i] } ?: n)
            states[i] != states[i - 1] ->
                i until ((i + 1 until n).find { j -> states[i] != states[j] } ?: n)
            else ->
                null
        }
    }
    val memo = Array(ranges.size){Array(ranges.size){null as Boolean?}}
    fun sub(from: Int, to: Int): Boolean {
        return when{
            to < from -> true
            memo[from][to] != null -> memo[from][to]!!
            else -> {
                memo[from][to] = (ranges[from].count() > 1 && sub(from + 1, to)) ||
                        (from + 1 until to).any{mid -> sub(from, mid) && sub(mid + 1, to)} ||
                        (states[ranges[from].first] == states[ranges[to].first] && ((from until to).filter{mid -> states[ranges[mid].first] == states[ranges[from].first]}.any{mid -> sub(from + 1, mid - 1) && sub(mid + 1, to - 1)}))
                memo[from][to]!!
            }
        }
    }
    println(
            if (sub(0, ranges.lastIndex)) "yes" else "no"
    )
}


Measured memory_bytes: 34664
N, M = map(int, input().split())
H = list(map(int, input().split()))

DP =[1]*N
for i in range(M):
  A, B = map(int, input().split())
  if H[A-1] > H[B-1]:
    if DP[A-1]!=-1:
	    DP[A-1] = 1
    DP[B-1] = -1
  elif H[B-1] > H[A-1]:
    if DP[B-1]!=-1:
	    DP[B-1] = 1
    DP[A-1] = -1
  else:
    DP[A-1] = -1
    DP[B-1] = -1
ans = DP.count(1)
print(ans)

Measured memory_bytes: 20132
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define debug1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"
#define INF (int)10000000000000000
#define PI (double)3.14159265358979
// #define M 421412341324321
#define MOD 1000000007

map <pair <int, int>, int> m;

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int n;
	cin>>n;
	for (int i=1;i<=n;++i)
	{
		string s = to_string(i);
		int x1 = s[0]-48;
		int x2 = s[sz(s)-1]-48;
		m[{x1, x2}]++;
	}
	int c=0;
	for (int i=0;i<=9;++i)
	{
		for (int j=0;j<=9;++j)
		{
			c+=m[{i,j}]*m[{j,i}];
		}
	}
	cout<<c;

	



	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll                    long long int
#define loop(i,a,b)           for(int i=(int)a;i<(int)b;++i)
#define rloop(i,a,b)          for(int i=(int)a;i<=(int)b;++i)
#define loopl(i,a,b)          for(ll i=(ll)a;i<(ll)b;++i)
#define loopr(i,a,b)          for(int i=(int)a;i>=(int)b;--i)
#define count_1(n)            __builtin_popcountll(n)
#define pb                    push_back
#define eb                    emplace_back
#define ab(a)                 (a<0)?(-1*a):a
#define pc                    putchar_unlocked
#define gc                    getchar_unlocked
#define mset(a,b,c)           loop(i,0,b) a[i]=c
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define itoc(c)               ((char)(((int)'0')+c))
#define vi                    vector<int>
#define vvi                   vector<vi>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define mini                  INT_MIN
#define vloop(i,v)            for(auto i:v)
const int MX=10010896;
const int lmt=3164;
const int N=10000001;
int flag[MX>>6];
#define ifc(i)                (flag[i>>6]&(1<<((i>>1)&31)))
#define isc(i)                (flag[i>>6]|=(1<<((i>>1)&31)))
#define chk(n)                (n==2||(n>2&&(n&1)&&!ifc(n)))
#define sv()                  int t; scanf("%d",&t); while(t--)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
void sieve(){ int i,j,k; for(i=3;i<lmt;i+=2) if(!ifc(i)) for(j=i*i,k=i<<1;j<MX;j+=k) isc(j);}
void solve()
{
    int h,w;
    cin>>h>>w;
    ll dp[h][w];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    loop(i,0,h)    
    {
        loop(j,0,w)
        {
            char t;
            cin>>t;
            if(t!='#')
            {
                if(i>0)
                dp[i][j]=dp[i][j]+dp[i-1][j]%1000000007;
                if(j>0)
                dp[i][j]=dp[i][j]+dp[i][j-1]%1000000007;
            }
            dp[i][j]=dp[i][j]%1000000007;
        }
    }
    cout<<dp[h-1][w-1];
}

int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();
    }
}

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

int main() {
  int N;
  cin>>N;
  int64_t a=1;
  int64_t b=1;
  int64_t c=1;
  for(int i=0; i<N; i++){
    a*=10;
    a%=1000000007;
    b*=8;
    b%=1000000007;
    c*=9;
    c%=1000000007;
  }
  int64_t d;
  d=2*c;
  d%=1000000007;
  
  
  int64_t ans;
  ans =(a+b-d+1000000007)%1000000007;
  cout<<ans<<endl;

}




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

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

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

  vector<int> a(n+2);
  a.at(0) = 0;
  a.at(n+1)=0;
  rep(i,n) cin >> a.at(i+1);
  
  vector<int> d(n+2);
  rep(i,n+1) d.at(i) = abs(a.at(i)-a.at(i+1));

  ll sum=0;
  rep(i,n+2) sum+=d.at(i);

  rep(i,n){
    ll ans = sum-d.at(i) - d.at(i+1) + abs(a.at(i+2)-a.at(i));
    cout << ans << endl;
  }
}

Measured memory_bytes: 4020
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    cnt = 0
    for idx, a in enumerate(A):
        if idx % 2 == 0 and a % 2 != 0:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long ll;

int main(){
    int N,M;
    int input;
    cin >> N >> M;
    int cnt = 0;
    vector<int> a;
    for (int i = 0; i<N; i++){
        cin >> input;
        a.push_back(input);
    }

    for(int i = 0; i < a.size(); i++){
        if(a[i] >= M){
            cnt++;
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 892
#include<cstdio>
const int MAXN = 100;
int D;
inline int add(int a, int b) {return (a + b)%D;}
inline int mul(int a, int b) {return 1LL*a*b%D;}
inline int sub(int a, int b) {return add(a,D-b);}
int pow_mod(int b, int p) {
	int ret = 1;
	while( p ) {
		if( p & 1 ) ret = mul(ret, b);
		b = mul(b, b);
		p >>= 1;
	}
	return ret;
}
int comb[MAXN + 5][MAXN + 5];
int trans1[MAXN + 5][MAXN + 5][MAXN + 5];
int trans2[MAXN + 5][MAXN + 5][MAXN + 5];
int f[MAXN + 5][MAXN + 5][MAXN + 5];
int g[MAXN + 5][MAXN + 5][MAXN + 5];
int N, M, K;
void init() {
	for(int i=0;i<=MAXN;i++) {
		comb[i][0] = 1;
		for(int j=1;j<=i;j++)
			comb[i][j] = add(comb[i-1][j], comb[i-1][j-1]);
	}
	for(int i=1;i<=K;i++) {
		for(int k=0;k<=M;k++) {
			trans1[i][k][0] = 1;
			if( k == M ) trans1[i][k][1] = 0;
			else trans1[i][k][1] = mul(pow_mod(K-i+1, k), sub(pow_mod(i, M-k), pow_mod(i-1, M-k)));
			for(int p=2;p<=N;p++)
				trans1[i][k][p] = mul(trans1[i][k][p-1], trans1[i][k][1]);
		}
	}
	for(int i=1;i<=K;i++) {
		for(int j=0;j<=N;j++) {
			trans2[i][j][0] = 1;
			if( j == 0 ) trans2[i][j][1] = 0;
			else trans2[i][j][1] = mul(pow_mod(i, N-j), sub(pow_mod(K-i+1, j), pow_mod(K-i, j)));
			for(int q=2;q<=M;q++)
				trans2[i][j][q] = mul(trans2[i][j][q-1], trans2[i][j][1]);
		}
	}
}
int main() {
	scanf("%d%d%d%d", &N, &M, &K, &D), init();
	f[0][0][0] = 1;
	for(int i=1;i<=K;i++) {
		for(int j=0;j<=N;j++) {
			for(int k=0;k<=M;k++) {
				for(int p=0;j+p<=N;p++) {
					g[j+p][k][i] = add(g[j+p][k][i], mul(comb[N-j][p], mul(trans1[i][k][p], f[j][k][i-1])));
// g[j+p][k][i] = g[j+p][k][i] + ((K-i+1)^k * (i^(M-k) - (i-1)^(M-k))^p * f[j][k][i-1]
				}
			}
		}
		for(int j=0;j<=N;j++) {
			for(int k=0;k<=M;k++) {
				for(int q=0;k+q<=M;q++) {
					f[j][k+q][i] = add(f[j][k+q][i], mul(comb[M-k][q], mul(trans2[i][j][q], g[j][k][i])));
// f[j][k+q][i] = f[j][k+q][i] + (i^(N-j) * ((K-i+1)^j - (K-i)^j)^q * g[j][k][i]
				}
			}
		}
	}
	printf("%d\n", f[N][M][K]);
}

Measured memory_bytes: 18176
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

long long my_pow( long long n ){
	long long a = 1;
	rep(i,0,n){
		a *= 2;
		a %= 1000000007;
	}
	ret a;
} 

int main(){
	int n;
	cin >> n;
	
	int a[100001] = {};

	rep(i,0,n){
		int tmp;
		cin >> tmp;
		a[tmp]++;
	}
	
	if( n % 2 == 0 ){
		bool f = 1;
		for( int i = 0 ; i < n ; i++ ){
			if(i%2){
				if(a[i] != 2 ){
					f = 0;
					break;
				}
			}
			else{
				if(a[i] > 0 ){
					f = 0;
					break;
				}
			}
		}

		if(f)
			cout << my_pow(n/2) << endl;
		else
			cout << 0 << endl;
	}
	else{
		if( a[0] > 1 )
			cout << 0 << endl;
		else{
			bool f = true;
			for(int i = 1 ; i < n ; i += 1 ){
				if( i % 2 ){
					if(a[i] > 0 ){
						f = false;
						break;
					}
				}
				else{
					if( a[i] != 2 ){
						f = false;
						break;
					}
				}
			}
			if(f)
				cout << my_pow(n/2) << endl;
			else
				cout << 0 << endl;

		}
	}


	ret 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define p 998244353
#define ll long long
#define maxn 300010
using namespace std;
ll fac[maxn],in[maxn],k,n,a,b,ans;
ll ksm(ll a,ll b){
	ll res=1;
	while(b){
		if (b&1) res=res*a%p;
		a=a*a%p;b>>=1;
	}
	return res;
}
void Init(){
	fac[0]=1;
	for (int i=1;i<maxn;i++)
	fac[i]=fac[i-1]*i%p;
	in[maxn-1]=ksm(fac[maxn-1],p-2);
	for (int i=maxn-2;i>=0;i--)
	in[i]=in[i+1]*(i+1)%p;
}
ll C(ll n,ll m){
	return n<m?0:fac[n]*in[m]%p*in[n-m]%p;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>a>>b>>k;Init();
	if (k==0){cout<<1<<endl;return 0;}
	for (ll i=0;i<=n;i++){
		if (k>=a*i&&(k-a*i)%b==0&&(k-a*i)/b<=n){
			ll j=(k-a*i)/b;
//			cout<<i<<" "<<j<<endl;
			(ans+=(C(n,i)*C(n,j))%p)%=p;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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


int main() {

    string n;
    cin >> n;
    rep(i,3) {
        if (n[i] == '1') cout << 9;
        else cout << 1;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, M, R;
    cin >> N >> M >> R;
    int r[R];
    rep(i, R) {cin >> r[i]; r[i]--;}
    int dp[N][N];
    fill(dp[0], dp[N], inf);
    rep(i, M){
        int u, v, c;
        cin >> u >> v >> c;
        u--, v--;
        chmin(dp[u][v], c), chmin(dp[v][u], c);
    }
    rep(i, N) dp[i][i] = 0;

    rep(k, N){
        rep(i, N){
            rep(j, N) chmin(dp[i][j], dp[i][k]+dp[k][j]);
        }
    }

    vector<int> v(R);
    iota(all(v), 0);
    int ans = inf;
    do{
        int tmp = 0;
        rep(i, R-1) tmp += dp[r[v[i]]][r[v[i+1]]];
        chmin(ans, tmp);
    } while(next_permutation(all(v)));
    
    cout << ans << endl;
}

Measured memory_bytes: 3756
class Heap
  attr_reader :size
  def initialize(up: false)
    @up = up
    @heap = []
    @size = 0
  end
  def sum
    x = 0
    @size.times do |i|
      x += @heap[i]
    end
    x
  end
  def push(n)
    n = -n if @up
    i = @size
    while i > 0
      pid = (i - 1) / 2
      break if n >= @heap[pid]
      @heap[i] = @heap[pid]
      i = pid
    end
    @heap[i] = n
    @size += 1
  end
  def pop
    return nil if @size == 0
    top = @heap[0]
    @size -= 1
    n = @heap[@size]
    i = 0
    while i * 2 + 1 < @size
      cid1 = i * 2 + 1
      cid2 = cid1 + 1
      if cid2 < @size && @heap[cid2] < @heap[cid1]
        cid1 = cid2
      end
      break if @heap[cid1] >= n
      @heap[i] = @heap[cid1]
      i = cid1
    end
    @heap[i] = n
    if @up
      -top
    else
      top
    end
  end
end

_, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = Array.new(m){gets.split.map(&:to_i)}
h = Heap.new(up: false)
a.each do |x|
  h.push(x)
end
catch(:done) do
  b.sort_by{|x, y| -y}.each do |x, y|
    x.times do
      u = h.pop
      if y > u
        h.push(y)
      else
        h.push(u)
        throw :done
      end
    end
  end  
end
puts h.sum

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(long long N, std::string S){

    lli r=0,g=0,b=0;
    REP(i,0,N){
        if(S[i]=='R')r++;
        else if(S[i]=='G')g++;
        else b++;
    }

    lli ans = r*g*b;

    for(lli k=N-1;k>=0;k--){
        for(lli j=N-1;j>=0;j--){
            if(S[k] ==S[j])continue;
            lli i = 2*j-k;
            if(i<0)continue;
            if(i>N)continue;
            if(i>=k || i>=j)continue;
            if(S[i] != S[j] && S[i] != S[k]){
                ans--;
            }
        }
    }

    cout<<ans<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    func(N, S);
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  ll A, B;
  cin >> A >> B;
  ll C, K;
  cin >> C >> K;

  ll ans = A - B;
  if (K % 2)
    ans *= -1;
  cout << ans << "\n";
}

Measured memory_bytes: 256
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

def findProductSum(A, n): 
    T = list(accumulate(A[::-1]))[::-1]
    #print(T)
    Ans = 0
    for i in range(n-1):
        x = A[i]*T[i+1]
        x %= MOD
        Ans += x
        Ans%= MOD
    return Ans
    

N= int(input())
A  = alele()
print(int(findProductSum(A,N) % MOD))
        

Measured memory_bytes: 105216
import java.io.*;
import java.util.*;


public class Main {

  void solve() throws IOException {
    int h = nextInt();
    int n = nextInt();
    for (int i = 0; i < n; i++) {
      h -= nextInt();
    }
    if (h > 0) {
      out.println("No");
    } else {
      out.println("Yes");
    }
  }

  public static void main(String[] args) throws IOException {
    new Main().run();
  }

  void run() throws IOException {
    reader = new BufferedReader(new InputStreamReader(System.in));
//		reader = new BufferedReader(new FileReader("input.txt"));
    tokenizer = null;
    out = new PrintWriter(new OutputStreamWriter(System.out));
//		out = new PrintWriter(new FileWriter("output.txt"));
    solve();
    reader.close();
    out.flush();

  }

  BufferedReader reader;
  StringTokenizer tokenizer;
  PrintWriter out;

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  String nextToken() throws IOException {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine());
    }
    return tokenizer.nextToken();
  }
}


Measured memory_bytes: 31864