akhauriyash/Code-Regression huggingface dataset:
use std::io::*;

const SP: u8 = b' ';
const LF: u8 = b'\n';

struct CharacterInput<'a> {
    locked_stdin: StdinLock<'a>,
    bytes_buffer: Vec<u8>,
}

impl<'a> CharacterInput<'a> {
    fn read(&mut self, delimiter: u8) -> &[u8] {
        self.bytes_buffer.clear();

        let len = self
            .locked_stdin
            .read_until(delimiter, &mut self.bytes_buffer)
            .unwrap();

        let end_index = match self.bytes_buffer.last() {
            Some(byte) => {
                if *byte == delimiter {
                    len - 1
                } else {
                    len
                }
            }
            None => len,
        };

        &self.bytes_buffer[0..end_index]
    }

    fn scan_u(&mut self, delimiter: u8) -> u64 {
        self.read(delimiter)
            .into_iter()
            .fold(0, |accumulator, byte| {
                (byte - b'0') as u64 + accumulator * 10
            })
    }

    fn scan_u_vec(&mut self, n: usize, separator: u8, delimiter: u8) -> Vec<u64> {
        let mut vector = Vec::with_capacity(n);
        if n > 1 {
            for _i in 0..n - 1 {
                vector.push(self.scan_u(separator));
            }
        }
        vector.push(self.scan_u(delimiter));
        vector
    }
}

fn create_cin<'a>(input: StdinLock<'a>, buffer_capacity: usize) -> CharacterInput {
    CharacterInput {
        locked_stdin: input,
        bytes_buffer: Vec::with_capacity(buffer_capacity),
    }
}


// ------------------------------------------------------------------------

fn main() {
    let cin = stdin();
    let cin = &mut create_cin(cin.lock(), 16);

    let n = cin.scan_u(LF) as usize;
    let mut a = cin.scan_u_vec(n + 1, SP, LF);
    let b = cin.scan_u_vec(n, SP, LF);

    let total_count = (0..n).map(|i| {
        let monster_count = a[i] + a[i + 1];
        let max_defeatable_count = b[i];

        if max_defeatable_count >= monster_count {
            a[i + 1] = 0;
            return monster_count;
        }

        if max_defeatable_count > a[i] {
            a[i + 1] = monster_count - max_defeatable_count;
        }

        return max_defeatable_count;
    }).sum::<u64>();

    println!("{}", total_count);
}


Measured memory_bytes: 6396
n,a,b,c,d = map(int,input().split())
b = abs(b-a)
t = False
for m in range(n):
    if c*(n-1-m)-d*m <= b and b <= -c*m + (n-1-m)*d:
        t = True
        break

if t:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 38768
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>h(n);
	rep(i, n) {
		cin >> h[i];
	}
	vector<int>a(m), b(m);
	vector<bool>ok(n);
	rep(i, n) {
		ok[i] = true;
	}
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		if (h[a[i]] > h[b[i]])ok[b[i]] = false;
		else if (h[a[i]] < h[b[i]])ok[a[i]] = false;
		else {
			ok[a[i]] = false;
			ok[b[i]] = false;
		}
	}
	int ans = 0;
	rep(i, n) {
		if (ok[i])ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4504
#include <stdio.h>

void fib(int A[],int first,int last)
{
  while(first <= last){
    if(first ==0 || first == 1){
      A[first] = 1;
      first++;
    }else{
      A[first] = A[first -1] + A[first -2];
      first++;
	}
  }
  return ;
}
    
  
  


int main(void)
{
int n;
 int A[45] = {0};
 
scanf("%d",&n);
 fib(A,0,n);

 printf("%d\n",A[n]);

 return 0;
}


Measured memory_bytes: 2128
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

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

int main()
{
	int N;
	cin >> N;
	vector<int> L(N);
	rep(i, N) {
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	int x = 0;
	rep(i, N-1) {
		x += L[i];
	}
	bool ans = x > L[N - 1];
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


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


int main(){
  int n;
  scanf("%d", &n);
  
  int par = 0, max =0, tres = 0;
  
  for(int j = 0; j<n; ++j){
    int a, b;
    scanf("%d %d", &a, &b);
    
    if (a == b){
      par += 1;
      tres += 1;
      if (tres > max)
        max = tres;
    }
    else{
      par = 0;
      tres =0;
    }
  }
  if (max > 2)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

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

using namespace std;

int Judge(const string s, string &ans, string c) {
	for (int i = 1; i < s.size(); i++) {
		if (ans[i] == 'S') {
			if (s[i] == 'o')
				ans += ans[i - 1];
			else {
				if (ans[i - 1] == 'S')
					ans += "W";
				else
					ans += "S";
			}
		}
		else {
			if (s[i] == 'x')
				ans += ans[i - 1];
			else {
				if (ans[i - 1] == 'S')
					ans += "W";
				else
					ans += "S";
			}
		}
	}
	if (ans[0] == ans[s.size()] && ans[s.size() - 1] == c[0]) {
		ans[s.size()] = '\n';
		return true;
	}
	return false;
}

int main(void) {
	string s, ans;
	int num, i;
	cin >> num >> s;
	if (s[0] == 'o') {
		if (Judge(s, ans = "WS", "W") || Judge(s, ans = "SW", "W") || Judge(s, ans = "WW", "S") || Judge(s, ans = "SS", "S"))
			cout << ans;
		else
			printf("-1\n");
	}
	else {
		if (Judge(s, ans = "WS", "S") || Judge(s, ans = "SW", "S") || Judge(s, ans = "WW", "W") || Judge(s, ans = "SS", "W"))
			cout << ans;
		else
			printf("-1\n");
	}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
int A[11];
int a[50],b[50],c[50],d[50];
long long ans = 0;
void dfs(int n) {
    if (n == N) {
        long long sum = 0;
        for (int i = 0; i < Q; i++) {
            if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
        }
        ans = max(ans, sum);
        return;
    }
    for (int i = min(A[n], M); i <= M; i++) {
        A[n + 1] = i;
        dfs(n + 1);
    }
}
int main() {
    cin >> N >> M >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    A[0] = 1;
    dfs(0);
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#include<climits>
using namespace std;

int main(void){

    int X;
    cin>>X;

    int ans=0;
    int max=1;

    for(int i=2;i<34;i++){
        int j=2;
        while(1){
            
            if(pow(i,j)>X)break;
            ans = pow(i,j);
            j++;
        }
        if(max < ans) max = ans;
    }

    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
N = int(input())

allSum = (1 + N) * (N/2)
ko3 = N//3
ko5 = N //5
ko15 = N//15

s3 = 3 * ((1 + ko3) * (ko3/2))
s5 = 5 * ((1 + ko5) * (ko5/2))
s15 = 15 * ((1 + ko15) * (ko15/2))
print(math.floor(allSum - s3 - s5 + s15))

Measured memory_bytes: 9192
import heapq
n,m=map(int,input().split())
A=[-int(i) for i in input().split()]
heapq.heapify(A)
for i in range(m):
  a=heapq.heappop(A)
  a/=2
  heapq.heappush(A,a)
ans=0
for i in range(n):
  ans+=int(A[i])
print(-ans)


Measured memory_bytes: 14180
#include<iostream>
#include<cctype>
#include<string>

using namespace std;

int main() {
    string W, T;
    cin >> W;
    int sum = 0;
    while (true) {
        cin >> T;
        if (T == "END_OF_TEXT") break;
        for (int i = 0; i < T.size(); i++) {
            if (isupper(T[i])) T[i] = tolower(T[i]);
        }
        if (T == W) sum += 1;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int mod=1e9+7;
const int INF =LONG_LONG_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int n;
   cin>>n;
   int h[n];
   for(int i=0;i<n;i++)
    cin>>h[i];
   int dp[n];
   dp[0]=0;
   dp[1]=abs(h[1]-h[0]);
   for(int i=2;i<n;i++)
   {
       dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
   }
   cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n;
    cin>>n;
    string s,s1="ACL";
    for(int i=0;i<n;i++)
    {
        s=s+s1;
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n; cin >>n;
  vector<ll> vec(n);
  rep(i,n) cin >>vec[i];
  ll ans=__gcd(vec[0],vec[1]);
  rep(i,n-1){
    ans=min(ans,__gcd(vec[i],vec[i+1]));
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 1024
s = list(input())
size = len(s)
ans = []
for i in range(size) :
    if len(ans) >= 1 :
        if s[i] ==  "B" :
            ans.pop(-1)
        else : ans.append(s[i])

    elif s[i] != "B" : ans.append(s[i])

b = "".join(ans)
print(b)

Measured memory_bytes: 2940
A, B = map(int, input().split())
S = input()
flag = False
for i in range(A):
  if S[i] == "-":
    flag=True
if S[A] != "-":
  flag=True
for i in range(A+1, A+B+1):
  if S[i] == "-":
    flag=True
if flag:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int count=0,count1=0;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]=='R')
      count++;
    else
    {
      count1=max(count,count1);
      count=0;
    }
       
  } 
  count1=max(count,count1);
  cout<<count1;
}


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

public class Main {
    private static IO io = new IO();
    
    public static void main(String[] args) {
        int k = io.nextInt();
        long d[] = new long[k];
        Arrays.fill(d, Long.MAX_VALUE);
        d[1] = 1;
        Deque<long[]> que = new ArrayDeque<>();
        que.offer(new long[] {1, 1});    // 総コスト、現在位置

        while (!que.isEmpty()) {
            long poll[] = que.poll();
            long dis = poll[0];
            long now = poll[1];
            if (dis > d[(int)now]) continue;

            if (d[(int)((now*10)%k)]>dis) {
                d[(int)((now*10)%k)] = dis;
                que.offerFirst(new long[] {dis, (now*10)%k});
            }

            if (d[(int)((now+1)%k)]>dis+1) {
                d[(int)((now+1)%k)] = dis+1;
                que.offerLast(new long[] {dis+1, (now+1)%k});
            }
        }

        System.out.println(d[0]);
    }

    static class IO extends PrintWriter {
        private final InputStream in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        IO() {
            this(System.in);
        }

        IO(InputStream source) {
            super(System.out);
            this.in = source;
        }

        boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }
        int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }
        boolean isPrintableChar(int c) {return 33<=c &&c <=126;}
        void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;}
        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }

        int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

        public void close() {
            super.close();
            try {
                in.close();
            } catch (IOException ignored) {
            }
        }
    }
}


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

int n, mod, s[3030][3030], C[3030][3030], f[3030];

ll K(ll x,ll y=mod-2){
    ll t=1;
    for (;y;y>>=1,x=x*x%mod)
        if (y&1) t=t*x%mod;
    return t;
}

int main(){
    cin>>n>>mod;
    s[0][0]=1;
    for (int i=1;i<=n;++i)
        for (int j=0;j<=i;++j){
            s[i][j]=((j? s[i-1][j-1]: 0)+(ll)s[i-1][j]*(j+1))%mod;
        }
    for (int i=0;i<=n;++i){
        C[i][0]=1;
        for (int j=1;j<=i;++j)
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
    }
    for (int i=0;i<=n;++i){
        --mod; ll t=K(2,i); ++mod;
        f[i]=K(2,t);
    }
    ll ans=0;
    for (int i=0;i<=n;++i)
        for (int j=0;j<=i;++j){
            ans=(ans+ (ll)s[i][j]*C[n][i]%mod*K(mod-1,i)%mod*K(K(2,n-i),j)%mod*f[n-i])%mod;
        }
    cout<<ans<<endl;
}

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

xy = []
for i in range(n):
    x,y = map(int, input().split())
    xy.append((x,y))

from itertools import permutations

paths = [i for i in range(n)]
path_perms = list(permutations(paths))

d_list = []
for path in path_perms:
    d = 0
    for i in range(len(path)-1):
        p1 = path[i]
        p2 = path[i+1]
        tmp = ((xy[p1][0]-xy[p2][0])**2+(xy[p1][1]-xy[p2][1])**2)**(1/2)
        d += tmp
    d_list.append(d)

print(sum(d_list)/len(d_list))

Measured memory_bytes: 9460
T = input()
ans = ""
# i = 0
# while i < len(T)-1:
#     if T[i] == "D":
#         ans += "D"
#     elif T[i] == "P":
#         ans += "P"
#     else:
#         if ans == "":
#             ans += "D"
#         elif ans[-1] == "P":
#             ans += "D"
#         else:

#     i += 1
# if len(ans) != len(T):
#     if T[-1] == "P":
#         ans += "P"
#     else:
#         ans += "D"
for i in range(len(T)):
    if T[i] == "?":
        ans += "D"
    else:
        ans += T[i]
print(ans)

Measured memory_bytes: 9460
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

int n;
int a[100009], b[100009], c[100009], dp[100009][3];

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

    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];
    for (int i = 2; i <= n; i++)
    {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }

    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << "\n";
}

Measured memory_bytes: 2560
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    // 11:07-
    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            int N = sc.nextInt();
            int[] vs = new int[N];
            for (int i = 0; i < N; i++) vs[i] = sc.nextInt();

            int[] as = new int[N];
            int[] bs = new int[N];

            as[0] = vs[0];
            for (int i = 1; i < vs.length; i++) as[i] = gcd(as[i - 1], vs[i]);

            bs[N - 1] = vs[N - 1];
            for (int i = bs.length - 2; i >= 0; i--) bs[i] = gcd(bs[i + 1], vs[i]);

            int max = Math.max(bs[1], as[N - 2]);
            for (int i = 1; i < vs.length - 1; i++) max = Math.max(max, gcd(as[i - 1], bs[i + 1]));
            
            out.println(max);
        }
    }

    private static int gcd(int a, int b) {
        while (b > 0) {
            int t = a % b;
            a = b;
            b = t;
        }
        return a;
    }

}


Measured memory_bytes: 52072
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

ll GCD(ll x, ll y){
  if(x < y)swap(x, y);
    if(y == 0)return x;
    return GCD(x % y, y);
}

ll LCM(ll x, ll y){
  return x/GCD(x, y)*y;
}

int main()
{
  int a, b;
  cin >> a >> b;
  ll ans = LCM(a, b);
  cout << ans << endl;
  system("pause");
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#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 make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
const LL mod = 1000000007;
const long double pi = acosl(-1);
int main(){
    LD h, m, a, b;
    scanf("%Lf %Lf %Lf %Lf",&a,&b,&h,&m);
    LD t = 2*(pi*h/12+pi*m/720);
    LD t2 = 2*pi*m/60;
    t -= t2;
    printf("%.10Lf",sqrtl(a*a+b*b-2*a*b*cosl(t)));
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

Measured memory_bytes: 4036
N,P = map(int,input().split())
s = list(input())
S = [0]*N

for i in range(N):
    S[i] = int(s[i])

count = 0

if P != 2 and P != 5:
    now = 0
    remainder = []
    for i in range(1,N+1):
        now += S[N-i] * (pow(10,(i-1),P) )
        remainder.append(now % P)

    result={}
    for i in range (0,len(remainder)):
        item = remainder[i]
        if item in result:
            result[item] = result[item]+1
        else:
            result[item] = 1

    for k in result.keys():
        if k == 0:
            if result[0] >= 2:
                count += result[0] + result[0]*(result[0]-1)//2
            else:
                count += result[0]
        else:
            count += result[k]*(result[k]-1)//2

else:
    if P == 2:
        for i in range(N):
            if S[i] %2 == 0:
                count += i+1
    if P == 5:
        for i in range(N):
            if S[i] %5 == 0:
                count += i+1

print(count)

Measured memory_bytes: 63560
function main(input){
  let list = input.split(" ");
  let n = parseInt(list[0]);//作る数
  let x = parseInt(list[1]);//一度に作れる数
  let t = parseInt(list[2]);//time
  let answer = Math.ceil(n/x)*t;
  console.log(answer);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29572
X, Y = map(int, input().split())
MOD = 10**9+7

N = 10**6+1
def pow_mod(x, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return pow_mod(x * x % MOD, n // 2) % MOD
    else:
        return x * pow_mod(x * x % MOD, n // 2) % MOD

fact = [1]
for i in range(1,N+1):
    fact.append( (fact[i-1] * i) % MOD )

inv = [1] * (N+1)
inv[N] = pow_mod(fact[N], MOD-2)
for i in range(N, 1, -1):
    inv[i-1] = inv[i] * (i) % MOD

def cmb_mod(n,r):
    return fact[n] * inv[r] * inv[n-r] % MOD


if (X+Y) % 3 != 0:
    print(0)
else:
    n = (2*X - Y) // 3
    m = (2*Y - X) // 3
    if n < 0 or m < 0:
        print(0)
    else:
        print(cmb_mod(n+m, n))


Measured memory_bytes: 93932
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5+5;
const ll mod =   1e9+7;
int n,m,l;ll dis1[305][305],dis2[305][305];
int main()
{  fast
cin>>n>>m>>l;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(i!=j)
dis1[i][j]=dis2[i][j]=inf;
for(int i=0;i<m;i++){
	int x,y,z;
	cin>>x>>y>>z;x--;y--;
	dis1[x][y]=dis1[y][x]=z;
}
for(int k=0;k<n;k++)
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
dis1[i][j]=min(dis1[i][j],dis1[i][k]+dis1[k][j]);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
	if(dis1[i][j]<=l)
	dis2[i][j]=1;
}
for(int k=0;k<n;k++)
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
dis2[i][j]=min(dis2[i][j],dis2[i][k]+dis2[k][j]);
int q;
cin>>q;
while(q--){
	int x,y;
	cin>>x>>y;x--;y--;
	if(dis2[x][y]==inf)
	cout<<"-1\n";
	else
	cout<<dis2[x][y]-1<<endl;
}
}

Measured memory_bytes: 5104
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second
#define MP make_pair
#define PB push_back

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;


int main()
{
  int n ;
  cin >> n ;
  vector<int> num(n-1) ;
  vector<int> ans(n) ;
  int cnt = 0 ;
  REP(i,n-1){
    cin >> num.at(i) ;
  }
  ans.at(0) = num.at(0) ;
  ans.at(n-1) = num.at(n-2) ;
  FOR(i,1,n-1){
    ans.at(i) = min(num.at(i-1),num.at(i)) ;
  }
  REP(i,n){
    cnt += ans.at(i) ;
  }
  
  cout << cnt <<endl ;
    
  

  return 0 ;
}

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

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long) (1e9+7);
	static long cf = 998244353;
    static final int MAX = 100000;
   // public static List<Integer>[] edges;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		for(int i=0;i<n;++i) 
			a[i] = sc.nextInt();
		Arrays.sort(a);
		TreeMap<Integer,Integer> map = new TreeMap<>();
		for(int i=0;i<n;++i) {
			map.put(a[i],i);
		}
		
		long ans = 0;
		for(int i=n-2;i>0;--i) {
			for(int j=i-1;j>=0;--j) {
				
				int key = a[i]+a[j];
				if(map.lowerKey(key) != null) {
					int idx = map.get(map.lowerKey(key));
					ans+=Math.max(0L,idx-i);
				}
			}
		}
		
		out.print(ans);
	    out.close();
	}
	
}

Measured memory_bytes: 46184
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int h, n, a[100010];
int main() {
	scanf("%d %d", &h, &n);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0; i < n; i++)
		h -= a[i];
	printf(h <= 0 ? "Yes\n" : "No\n");
}

Measured memory_bytes: 512
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

typedef	vector<int>	vi;

const int INF=1<<29;

struct Edge{
	int u,v,cost;
	Edge(){}
	Edge(int U,int V,int C):u(U),v(V),cost(C){}
	bool operator<(const Edge &e)const{ return cost<e.cost; }
};

class UnionFind{
	vi a;
	int root(int x){ return ~a[x]?a[x]=root(a[x]):x; }
public:
	UnionFind(int n):a(n,-1){}
	bool find(int x,int y){ return root(x)==root(y); }
	bool unite(int x,int y){ return find(x,y)?0:(a[root(y)]=root(x),1); }
};

int main(){
	for(int m,n;scanf("%d%d",&n,&m),n;){
		Edge e[5000];
		rep(i,m){
			scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].cost);
			e[i].u--,e[i].v--;
		}
		sort(e,e+m);

		int ans=INF;
		vector<UnionFind> uf(m,UnionFind(n));
		int cnt[5000],dmin[5000],dmax[5000];
		rep(i,m){
			dmin[i]=dmax[i]=e[i].cost;
			cnt[i]=1;
		}
		for(int i=0,l=0;i<m;i++){
			for(int j=l;j<=i;j++){
				if(uf[j].unite(e[i].u,e[i].v)){
					if(dmax[j]<e[i].cost)	dmax[j]=e[i].cost;
					cnt[j]++;
					int delta=dmax[j]-dmin[j];
					if(ans<=delta)	l++;	// pruning
					else if(cnt[j]==n){		// spanning tree made up
						if(delta<ans)	ans=delta;
						l++;
					}
				}
			}
		}

		printf("%d\n",ans<INF?ans:-1);
	}

	return 0;
}

Measured memory_bytes: 2964
from collections import defaultdict

N, M = map(int, input().split())
steps = [1 for _ in range(N + 1)]
for _ in range(M):
    i = int(input())
    steps[i] = 0
scores = defaultdict(int)
scores[0] = 1
scores[1] = steps[1]

if N > 1:
    for i in range(2, N + 1):
        if steps[i]:
            scores[i] = scores[i - 1] + scores[i - 2]
        else:
            scores[i] = 0
print(scores[N] % 1000000007)

Measured memory_bytes: 469636
#include<bits/stdc++.h>
#define maxn 1000050
#define modu 998244353
using namespace std;
typedef long long LL;

bool noprime[maxn];
int p[maxn],pnum;

LL mu[maxn],g[maxn],f[maxn];

int n,a;

const int N=1000000;
LL I[maxn]={1,1};
LL c[maxn],sum[maxn];

LL sq(LL a) {
    return a*a%modu;
}

int main()  {
    for (int i=2;i<maxn;++i)    I[i]=modu-modu/i*I[modu%i]%modu;

    scanf("%d",&n);
    for (int i=1;i<=n;++i)
        scanf("%d",&a),++c[a];
    for (int i=1;i<=N;++i)
        sum[i]=(sum[i-1]+i*c[i])%modu;

    mu[1]=1;
    for (int i=2;i<maxn;++i)    {
        if (!noprime[i])
            mu[p[pnum++]=i]=modu-1;
        for (int j=0;j<pnum&&i*p[j]<maxn;++j)   {
            noprime[i*p[j]]=1;
            if (i%p[j])
                mu[i*p[j]]=modu-mu[i];
            else
                break;
        }
    }

    // LL res=0;
    // for (int d=1;d<=N;++d)
    //     for (int T=1;T<=N;++T)
    //         if (T%d==0)
    //             res=(res+I[d]*mu[T/d]%modu*sq(sum[N/T]))%modu;
    // cout<<res<<endl;

    for (int i=1;i<=N;++i)
        for (int j=i;j<=N;j+=i)
            f[i]=(f[i]+j*c[j])%modu,
            g[j]=(g[j]+mu[i]*I[j/i])%modu;
    for (int i=1;i<=N;++i)
        f[i]=sq(f[i]);
    
    LL ans=0;
    for (int i=1;i<=N;++i)
        ans=(ans+f[i]*g[i]-i*c[i]%modu+modu)%modu;
    printf("%lld\n",ans*I[2]%modu);
    return 0;
}

Measured memory_bytes: 51968
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<Long, Integer> map = new HashMap<>();

        for (int i = 0; i < N; i++) {
            long value = sc.nextLong();
            if (map.containsKey(value)) {
                map.put(value, map.get(value) + 1);
            } else {
                map.put(value, 1);
            }
        }

        List<Long> candidates = new ArrayList<>();
        for (Map.Entry<Long, Integer> entry : map.entrySet()) {
            if (entry.getValue() >= 4) {
                candidates.add(entry.getKey());
                candidates.add(entry.getKey());
            } else if (entry.getValue() >= 2) {
                candidates.add(entry.getKey());
            }
        }
        Collections.sort(candidates);

        if (candidates.size() >= 2) {
            long a = candidates.get(candidates.size() - 1);
            long b = candidates.get(candidates.size() - 2);
            System.out.println(a * b);
        } else {
            System.out.println(0);
        }
    }
}

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        int[] arr = new int[4];
        while (t-- > 0) {
            String s = sc.next();
            if (s.equals("AC")) {
                arr[0]++;
            } else if (s.equals("WA")) {
                arr[1]++;
            } else if (s.equals("TLE")) {
                arr[2]++;
            } else {
                arr[3]++;
            }
        }
        
        System.out.println("AC x " + arr[0]);
        System.out.println("WA x " + arr[1]);
        System.out.println("TLE x " + arr[2]);
        System.out.println("RE x " + arr[3]);
 
    }
}

Measured memory_bytes: 58452
# coding:utf-8


def inpl(): return list(map(int, input().split()))


A, B, K = inpl()

c = A
while c < A + K and c <= B:
  print(c)
  c += 1

if c <= B - K:
  c = B - K + 1
  
while c > B - K and c <= B:
  print(c)
  c += 1


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

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	
	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	} else {
		cout << ":(" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
/*Shivam Bhalla */
  /* f2016941@pilani.bits-pilani.ac.in */


  #include <iostream>
  #include <cstdio>
  #include <cstring>
  #include <cstdlib>
  #include <cctype>
  #include <algorithm>
  #include <map>
  #include <vector>
  #include <list>
  #include <set>
  #include <queue>
  #include <deque>
  #include <stack>
  #include <iostream>
  #include <string>
  #include <cmath>
  #include <cassert>
  #include <bits/stdc++.h>
  #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
  using namespace std;
  long long maxv = 1e9+7;


  int main()
  {
      int n;
      cin>>n;
      string s,t;
      cin>>s>>t;
      string u="";
      for(int i=0;i<n;i++){
        u=u+s[i]+t[i];
      }
      cout<<u;
      return 0;
  }


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

using namespace std;

struct edge{
    int to;
    long cost;
};

vector<int> G[100000];
vector<edge> G1[100000];

long s[100000];
long ans[100000];
int a[100000], b[100000];
long cnt[100000];
bool used[100000];
int N;

void clear(){
    for(int i = 0; i < N; i++) used[i] = false;
}

long dfs1(int v){
    //cout << v << ' ' << cnt[v] << endl;
    used[v] = true;
    long ret = 0;
    for(int i = 0; i < G1[v].size(); i++){
        if(!used[G1[v][i].to]){
            ret += (dfs1(G1[v][i].to) + G1[v][i].cost*cnt[G1[v][i].to]);
        }
    }
    return ret;
}

void dfs(int v){
    used[v] = true;
    cnt[v] = 1;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]){
            dfs(G[v][i]);
            cnt[v] += cnt[G[v][i]];
        }
    }
}

int main(){
    int eql = -1;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }
    dfs(0);
    for(int i = 0; i < N-1; i++){
        int l = min(cnt[a[i]], cnt[b[i]]);
        int r = N-l;
        if(r < l) swap(r, l);
        if(l == r){
            eql = i;
        }else{
            ans[i] = abs(s[a[i]]-s[b[i]])/(r-l);
        }
    }
    if(eql != -1){
        for(int i = 0; i < N-1; i++){
            G1[a[i]].push_back(edge{b[i], ans[i]});
            G1[b[i]].push_back(edge{a[i], ans[i]});
        }
        clear();
        long sum = dfs1(0);
        //cout << sum << ' ' << s[0] << endl;
        ans[eql] = (s[0]-sum)/(N/2);
    }
    for(int i = 0; i < N-1; i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 21248
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int max=0,n,v[25],c[25];
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>v[i];
  }
  for(int i=0; i<n; i++){
    cin>>c[i];
  }
  for(int i=0; i<n; i++){
    if(v[i]>c[i]){
      max+=v[i]-c[i];
    }
  }
  cout<<max<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s; cin >> s;
	for (int i = 0; i < 4; i++)cout << s[i]; cout << ' ';
	for (int i = 4; i < 12; i++)cout << s[i]; cout << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main()
{
    string s,t;
    cin>>s>>t;
    ll a[s.length()+1][t.length()+1],i,j;
    memset(a,0,sizeof(a));
    for(i=0;i<=s.length();i++)
    {
        for(j=0;j<=t.length();j++)
        {
            if(i==0 || j==0)
            {
                a[i][j]=0;
            }
            else
            {
                if(s[i-1]==t[j-1])
                {
                    a[i][j]=a[i-1][j-1]+1;
                }
                else
                {
                    a[i][j]=max(a[i-1][j],a[i][j-1]);
                }
            }
        }
    }
 
    string s1="";
    for(i=s.length(),j=t.length();i>0 && j>0;)
    {
            if(s[i-1]==t[j-1])
            {
                s1+=s[i-1];
                i--,j--;
            }
            else
            {
                if(a[i-1][j]==a[i][j])
                {
                    i--;
                }
                else
                {
                    j--;
                }
            }
    }
    reverse(s1.begin(),s1.end());
    cout<<s1<<endl;
    //cout<<a[s.length()-1][t.length()-1]<<endl;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
  ll a,b;
  cin>>a>>b;
  ll c=max(a,b);
  ll d=min(a,b);
  loop(i,c)cout<<d;
}


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

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

  sort(S.begin(), S.end());
  if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main()
{
  string c,d;
  cin >> c;
  cin >> d;
  bool flag = 1;
  for(int i = 0;i < 3;i++){
    if(c[i] != d[2 - i]) flag = 0;
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

bool check(int x){
    int last = x % 10;
    x = x / 10;
    while(x > 0){
        int temp = x % 10;
        if (last != temp+1) return false;
        last = temp;
        x = x / 10;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    vector<int> in;
    int mx = -1;
    for (int i = 0; i < n; i++){
        int bil;
        cin >> bil;
        int temp;
        for (int j = 0; j < i; j++){
            temp = bil * in[j];
            if (check(temp) && temp > mx){
                mx = temp;
            }
        }
        in.push_back(bil);
    }
    cout << mx << endl;
    return 0;
}


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

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

    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i] >> B[i];
    }

    vector<ll> diff(N);
    for (int i = 0; i < N; i++)
    {
        if(A[i] == 0){
            diff[i] = 0;
        } else {
            diff[i] = B[i] - A[i];
        }
    }

    for (int i = 0; i < N; i++)
    {
        if(diff[N-i-1] < 0){
            diff[N-i-1] += ((ll)ceil(- (double) diff[N-i-1] / (double) B[N-i-1])) * B[N-i-1];
        }

        if (i > 0)
        {
            if(diff[N-i-1] < diff[N-i]){
                diff[N - i - 1] += ((ll)ceil((double) (diff[N-i] - diff[N-i-1]) / (double) B[N-i-1])) * B[N-i-1];
            }

        }
    }

    cout << diff[0] << endl;

    return 0;
}


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

int main(){
	string a,b;
	cin >>a>>b;
	if(a.size()>b.size())cout << "GREATER" << endl;
	else if(a.size()<b.size())cout << "LESS" << endl;
	else{
		if(a==b)cout << "EQUAL" << endl;
		else if(a<b)cout << "LESS" << endl;
		else cout << "GREATER" << endl;
	}
	return 0;
}

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

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

    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
let rec factorize acc i n =
  if n <= 1 then acc
  else if n < i * i then n :: acc
  else if n mod i = 0 then factorize (i :: acc) i (n / i)
  else factorize acc (i + 1) n
let factorize n =
  match factorize [] 2 n with
  | [] -> []
  | p :: ps ->
      let (acc, p, n) = List.fold_left (fun (acc, p, n) q ->
        if p = q
        then (acc, p, n + 1)
        else ((p, n) :: acc, q, 1)) ([], p, 1) ps in
      (p, n) :: acc

let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m
let ( -^ ) x y = x +^ (m - y)

let perm n k =
  Array.fold_left ( *^ ) 1 @@
  Array.init k @@ ( +^ ) (n - k + 1)
let comb n k = power ( *^ ) (perm n k) (perm k k) (m - 2)
let repcomb n k = comb (n + k - 1) k

let () = Scanf.scanf "%d %d" @@ fun n m ->
  Printf.printf "%d\n" @@
  List.fold_left (fun acc (_, i) -> ( *^ ) acc @@ repcomb n i) 1 @@
  factorize m


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
char s[maxn];


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

    cin>>(s+1);
    int n=strlen(s+1);
    for(int i=1;i<=n;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<i<<" "<<i+1<<'\n';
            return 0;
        }
        if(s[i]==s[i+2])
        {
            cout<<i<<" "<<i+2<<'\n';
            return 0;
        }
    }
    cout<<-1<<" "<<-1<<'\n';






}


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

int a[10010];

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

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

    int s = 0;
    for(int i=0; i<m; i++) s+=a[i];

    if(s>n) cout << "-1";
    else cout << n-s;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vector<Pl> comp;
	for (int i = 0; i < N; i++) {
		int A, B; cin >> A >> B;
		comp.emplace_back(A, 1);
		comp.emplace_back(B+1, -1);
	}
	sort(begin(comp), end(comp));	
	int l = 1, r = 0;
	ll cnt = 0;

	ll ll1=-1, rr1=-1, ll2=-1, rr2=-1;

	for (int i = 0; i < (int)comp.size()-1; i++) {
		if (comp[i].second == 1) r++;
		else l++;
		//cout << "[" << comp[i].first << ", " << comp[i+1].first << "), " << l << " " << r << endl;
		if (N & 1) {
			if (r >= (N+1)/2 && l <= (N+1)/2) {
				cnt += comp[i+1].first - comp[i].first;
			}
		} else {
			if (r >= N/2 && l <= N/2) {
				if (ll1==-1) ll1 = comp[i].first;
				rr1 = comp[i+1].first-1;
			}
			if (r >= N/2+1 && l <= N/2+1) {
				if (ll2==-1) ll2 = comp[i].first;
				rr2 = comp[i+1].first-1;
			}
		}
	}
	
	if (N & 1) {
		cout << cnt << endl;
	} else {
		//cout << ll1 << " " << ll2 << " " << rr1 << " " << rr2 << endl;
		cout << (rr1+rr2) - (ll1+ll2) + 1 << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 11592
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N,Q;
  ll K;
  cin >> N >> K >> Q;
  vector<int> AC(N);
  int temp_AC;
  for(int i=0;i<Q;i++){
    cin >> temp_AC;
    --temp_AC;
    AC.at(temp_AC)++;
  }

  for(int i=0;i<N;i++){
    if(0<K-Q+AC.at(i)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x=0,old=0;
string s;
cin>>n;
cin>>s;
    for (int z = 0; z <n ; ++z) {
                if (s[z]=='I'){
            x++;
        }else if (s[z]=='D'){
            x--;
        }
        if(x>old){
            old=x;
        }
    }

    printf("%d",old);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long X, K, D;
  cin >> X >> K >> D;
  long long min = abs(X) / D;
  int dir = (X >= 0 ? -1 : 1);
  if (K <= min) {
  	cout << abs(X + dir * K * D) << endl;
  } else if ((K - min) % 2 == 0) {
    cout << abs(X + dir * min * D) << endl;
  } else {
    cout << abs(X + dir * (min + 1) * D) << endl;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define MN 41
typedef long long ll;
int n;
ll dp[MN][MN][MN],ans;
char mp[MN][MN];
int main()
{
	scanf("%d",&n);n<<=1;
	for(int i=1;i<=n;i++) scanf("%s",mp[i]+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++) dp[i][i][j]=(mp[i][j]=='1');
		dp[i][i][i]=1;
	}
	for(int len=3;len<=n;len+=2)
	{
		for(int L=1;L+len-1<=n;L++)
		{
			int R=L+len-1;
//			printf("%d %d\n",L,R);
			for(int r=L+1;r<R;r+=2) {
				for(int l=r+1;l<=R;l+=2)
				{
//					printf("%d %d %d %d %d %d\n",L,r,l,R,l+2,l+2<=R);
					ll now=0;
					for(int i=l;i<=R;i++) now+=dp[L][r-1][i]*dp[l][R][i];
					for(int i=r;i<l;i++) {
//						printf("%lld\n",dp[1][3][1]);
//						printf("%d %d %lld %lld\n",L,R,dp[r][l-1][i],now);
					dp[L][R][i]+=dp[r][l-1][i]*now;
					}
				}
			}
			for(int i=L;i<=R;i++)
				for(int j=R+1;j<=n;j++) if(mp[i][j]=='1') dp[L][R][j]+=dp[L][R][i];
			for(int i=L;i<=R;i++) {
//				printf("%d ll %d %d %lld\n",L,R,i,dp[L][R][i]);
			}
		}
	}
	for(int i=2;i<=n;i++)
		if(mp[1][i]=='1') ans+=dp[2][n][i];
	printf("%lld\n",ans);
}

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

using namespace std;

int main()
{
    long long x,k,d,g;
    cin>>x>>k>>d;
    if(x<0) x=(-1)*x;
    if(x/d>=k) x -=d*k;
    else
    {
        g=x/d;
        k -=g;
        x=x%d;
        if(k%2==1)
        {
            if(d>x) x=d-x;
            else x -=d;
        }
    }
    cout<<x;
    return 0;
}


Measured memory_bytes: 3584
#include<cstdio>
#include<cstring>

using namespace std;

char s[30];
int len,sum;
bool flag[30];

bool solve(char*s){
	for(int i = 0;i <= len - 1;i ++){
		if(flag[s[i]] == 0) sum++;
		flag[s[i]] = 1;
	}
	if(sum == len) return 1;
	else return 0;
}

int main(){
	scanf("%s",s);
	len = strlen(s);
	if(solve(s)) printf("yes\n");
	else printf("no\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      char s[4];
      int n,i,a=0,b=0;
      cin>>s;
      
      for(i=0;i<3;i++)
      {
        
        if(s[i]=='A')
          a++;
        else
          b++;
      }
      	if(a!=0 && b!=0)
          cout<<"Yes";
      else
        cout<<"No";
      return 0;
    }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int[] b = new int[n];
    for (int i = 0; i < n; i++) {
      b[i] = 0;
    }

    for (int i = 1; i <= n - 1; i++) {
      b[scan.nextInt() - 1]++;
    }

    for (int i = 0; i < n; i++) {
      System.out.println(b[i]);
    }
  }

}

Measured memory_bytes: 60208