akhauriyash/Code-Regression huggingface dataset:
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

ll f(ll N) {
    if(N%2 == 0) return N/2;
    else return 3*N+1;
}

int main() {
    ll s; cin >> s;
    map<ll,int> res;
    res[s] = 1;
    ll ans = 1;
    while(1) {
        if(res.count(f(s))) 
            res[f(s)]++;
        else res[f(s)] = 1;
        ans++;
        if(res[f(s)] == 2) {
            cout << ans << endl;
            return 0;
        }         
        s = f(s);
    }
}


Measured memory_bytes: 764
/* ex3_4
   tamayama　*/

#include<stdio.h>
 int main (void){
     int N;
     int i;
     int Input_N;
     int check=0;
     scanf("%d",&N);
     Input_N = N;

     for(i=1; i<10; i++){
         if(Input_N / i < 10 && Input_N % i == 0){
             check++;
         }
     }

     if(check > 0){
         printf("Yes");
     }else{
         printf("No");
     }
     return 0;
 }


Measured memory_bytes: 128
S=input()
datas=["dream","dreamer","erase","eraser"]
stack=[]
stack.append(0)
while stack:
  index=stack.pop()
  if index==len(S):
    print("YES")
    break
  for data in datas:
    if index+len(data)>len(S):
      continue
    if S[index:index+len(data)]==data:
      stack.append(index+len(data))
else:
  print("NO")

Measured memory_bytes: 3492
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define int long long
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    int prev ;
    int cur;
    int count = 0;
    int Max = -1;
    cin >> n;
    REP(i,n){
        cin >> cur;
        if(i == 0) prev = cur;
        else{
            if(cur <= prev) {
                count ++;
                prev = cur;
                if(i == n-1){
                    Max = max(Max,count);
                }
            }else{
                prev = cur;
                Max = max(Max,count);
                count = 0;
            }
        }
    }

    if(n == 1) cout << 0;
    else cout << Max;

    return 0;
}









Measured memory_bytes: 3648
n = int(input())
W = [input() for i in range(n)]
WW = set(W)
flag = 1
if len(WW) != n:
    print("No")
    exit()
else:
    for i in range(n-1):
        if W[i][-1] != W[i+1][0]:
            flag = 0
    if flag == 1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
import numpy as np
from collections import Counter
R,G,B,N = list(map(int, input().split()))
a = [R, G, B]
a.sort()
a = a[::-1]
R, G, B = a

s = 0
r_cand = np.arange(0, N + 1, R)[:, None]
g_cand = np.arange(0, N + 1, G)[None, :]
rest = N - r_cand - g_cand
rest = rest[rest >= 0]
c = Counter(rest)

s = 0
for k in c.keys():
    s += (k%B == 0) * c[k]

print(s)

Measured memory_bytes: 126944
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll a,b,n; cin>>a>>b>>n;
	cout<<(a*(min(n,b-1))-((a*(min(n,b-1)))%b))/b<<'\n';
}


Measured memory_bytes: 3612
import java.util.Scanner;
 
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int i=1,n=sc.nextInt();
        while(i<=n){
            int x=i;
            if(x%3==0){
                System.out.printf(" %d",i);
            }else{
                while(x>=1){
                    if(x%10==3){
                        System.out.printf(" %d",i);
                        break;
                    }
                    x/=10;
                }
            }
            i++;
        }
        System.out.printf("\n");
    }
};


Measured memory_bytes: 36592
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}

const LL MOD = 2019;
inline LL mod_add(LL a, LL b) { return (a + b) % MOD; }
inline LL mod_sub(LL a, LL b) { return (a + MOD - b) % MOD; }
inline LL mod_mul(LL a, LL b) { return ((a % MOD) * (b % MOD)) % MOD; }
LL mod_bipow(LL x, LL y) {   // x^y by bisection method
    if (y == 0) return 1;
    else if (y == 1) return x % MOD;
    else if (y % 2 == 0) {
        LL val = mod_bipow(x, (LL)(y / 2));
        return mod_mul(val, val);
    } else {
        LL val = mod_bipow(x, (LL)(y / 2));
        return mod_mul(mod_mul(val, val), x);
    }
}
LL mod_inv(LL x) { return mod_bipow(x, MOD - 2); }   // x^{-1} = x^{MOD-2} (MOD: prime number)
LL mod_div(LL a, LL b) { return mod_mul(a, mod_inv(b)); }   // a/b = a*b^{-1}

void solve(long long L, long long R){
    LL lmod = L % MOD, rmod = R % MOD;
    VB e(2019);
    REP(i, 2019) {
        if (L + i > R) break;
        e[mod_add(L, i)] = true;
    }

    LL ans = LLONG_MAX - INT_MAX;
    REP(i, 2019) {
        REP(j, 2019) {
            if (i >= j) continue;
            if (!e[i] || !e[j]) continue;
            LL tmp = mod_mul(i, j);
            if (ans > tmp) {
                ans = tmp;
            }
        }
    }
    cout << ans << endl;
}

int main(){
    long long L;
    scanf("%lld",&L);
    long long R;
    scanf("%lld",&R);
    solve(L, R);
    return 0;
}


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

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

    string S;
    cin >> S;

    S.erase(unique(S.begin(), S.end()), S.end());

    cout << S.size() << endl;

    return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	//-正解数, 整理番号
	vector<PII> data;
	while (true) {
		int p, s; char c; cin >> p >> c >> s;
		if (p == 0 && s == 0)break;
		data.pb(mp(-s, p));
	}
	sort(all(data));

	//整理番号, 順位
	map<int, int> m;
	m.insert(mp(data[0].second, 1));
	int x = 1;
	FOR(i, 1, sz(data)) {
		if (data[i].first != data[i - 1].first)x++;
		m.insert(mp(data[i].second, x));
	}

	int q;
	while (cin >> q) {
		Cout(m[q]);
	}
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}



int main(void)
{
  ll n, a, b;
  string s;
  cin >> n >> a >> b >> s;

  ll ac = 0, bc = 0;
  REP(i, n) {
    bool ok = false;
    switch(s[i]) {
    case 'a':
      if(ac + bc < a + b) {
	ac ++;
	ok = true;
      }
      break;
    case 'b':
      if(ac + bc < a + b && bc < b) {
	bc++;
	ok = true;
      }
      break;
    }
    cout << (ok?"Yes":"No") << endl;
  }
      
}


Measured memory_bytes: 896
n = int(input())
lis = list(map(int,input().split()))
lis = sorted(lis, reverse=True)
ans = lis[0]
res = []
for i in range(1,n):
    res.append(lis[i])
    res.append(lis[i])
for i in range(n - 2):
    ans += res[i]
print(ans)

Measured memory_bytes: 124272
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1 << 30;

int main(){
	int n;scanf("%d",&n);
	printf("%d\n",3*n*n);

	return 0;
}


Measured memory_bytes: 256
k,n = gets.chomp.split(" ").map(&:to_i)
a = gets.split(" ").map(&:to_i)
diff = []
(0..n-2).each do |i|
  diff.push(a[i+1]-a[i])
end
diff.push(k-a.last+a[0])
puts k - diff.max

Measured memory_bytes: 17028
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,ans=0;
  cin>>n;
  vector<ll>a(n+1,0);
  vector<ll>b(n,0);
  for(ll i=0;i<n+1;i++){
    cin>>a[i];
  }
  for(ll i=0;i<n;i++){
    cin>>b[i];
  }

  for(ll i=0;i<n;i++){
    ans+=min(a[i],b[i]);
    b[i]-=min(a[i],b[i]);
    ans+=min(a[i+1],b[i]);
    a[i+1]-=min(a[i+1],b[i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define PI 3.14159265358979323846264338327950L

long long int res;

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

    string S;
    cin >> S;
    int N = S.size();
    int ans = 999;
    for (int i = 0; i <= N - 3; ++i)
    {
        int num = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + S[i + 2] - '0';
        ans = min(ans, abs(num - 753));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n, cnt=0;
    string s;
    cin>>n>>s;
    map<char, set<int>>p;
    for(int i = 0; i < n; i++)p[s[i]].in(i);
    for(char i = '0'; i <= '9'; i++){
        int cur = -1;
        if(!sz(p[i]))continue;
        cur=*p[i].upper_bound(cur);
        for(char j = '0'; j <= '9'; j++){
            if(!sz(p[j]))continue;
            if(p[j].upper_bound(cur)==p[j].end())continue;
            int d = *p[j].upper_bound(cur);
            for(char l = '0'; l <= '9'; l++){
                if(!sz(p[l]))continue;
                if(p[l].upper_bound(d)==p[l].end())continue;
                cnt++;
            }
        }
    }
    cout<<cnt;
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 5004
DEBUG = False

N, M = map(int, input().split())
iPY = []
for i in range(M):
    P, Y = map(int, input().split())
    iPY.append([i, P, Y])

if DEBUG:
    print(iPY)

sorted_iPY = sorted(iPY, key=lambda x: x[2])

if DEBUG:
    print(sorted_iPY)

counts = {}

for n, ipy in enumerate(sorted_iPY):
    i, p, y = ipy
    if p not in counts:
        counts[p] = 1
    else:
        counts[p] += 1
    if DEBUG:
        print(counts)
    sorted_iPY[n].append("{:0=6}".format(p) +  "{:0=6}".format(counts[p]))

if DEBUG:
    print(sorted_iPY)

restored_iPY = sorted(iPY, key=lambda x: x[0])

if DEBUG:
    print(restored_iPY)

for i in range(M):
    print(restored_iPY[i][3])


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

int main() {
	int N;
	cin >> N;
	int A[N];
	for (int i = 0; i < N; i++) cin >> A[i];

	int ans = 0;
	while (1) {
		int flag = 0;
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 == 1) flag = 1;
			A[i] /= 2;
		}
		if (flag == 0) ans++;
		else break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			int[] a = new int[n];
			for(int i=0;i<n;i++){
				a[i] = stdIn.nextInt();
			}
			int cnt = 0;
			for(int i=0;i<n;i++){
				for(int j=n-1;j>i;j--){
					if(a[j]<a[j-1]){
						cnt++;
						int tmp = a[j];
						a[j] = a[j-1];
						a[j-1] = tmp;
					}
				}
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

// 13:11-
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=101;
int N;
int A[MAX_N],B[MAX_N],C[MAX_N],D[MAX_N];
const int MAX_V=1e4;
class MaxBipartiteMatching {
public:
  MaxBipartiteMatching(int V) : V(V) {}
  
  void addEdge(int u, int v) {
    assert(u<V&&v<V);
    E[u].push_back(v);
    E[v].push_back(u);
  }
  
  int solve() {
    int res=0;
    memset(match, -1, sizeof(match));
    for(int u=0; u<V; ++u) if(match[u]<0) {
      memset(viz,0,sizeof viz);
      res+=dfs(u);
    }
    
    return res;
  }
private:
  int V;
  vector<int> E[MAX_V];
  int match[MAX_V];
  bool viz[MAX_V];
  
  // find augmenting path in residual network
  bool dfs(int u) {
    viz[u]=true;
    for(auto v : E[u]) {
      int w=match[v];
      if(w<0||(!viz[w]&&dfs(w))) {
        match[v]=u;
        match[u]=v;
        return true;
      }
    }
    return false;
  }
};

void solve() {
  MaxBipartiteMatching M(2*N);
  REP(i,N)REP(j,N) if(A[i]<C[j]&&B[i]<D[j]) {
    M.addEdge(i,N+j);
  }
  cout<<M.solve()<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N;
  REP(i,N) cin>>A[i]>>B[i];
  REP(i,N) cin>>C[i]>>D[i];
  solve();
  return 0;
}


Measured memory_bytes: 1144
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll A1, A2, A3;
    cin >> A1 >> A2 >> A3;

    cout << ((A1 + A2 + A3 >= 22) ? "bust" : "win") << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
H,W=map(int,input().split())

A=[list('X'+input()+'X') for i in range(H)]
A.append('X'*(W+2))
A.insert(0,'X'*(W+2))
d=[[0,1],[0,-1],[1,0],[-1,0]]
wnum=0
blis=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if A[i][j]=='.':
            wnum+=1
        if A[i][j]=='#':
            blis.append([i,j])

if wnum==0:
    print(0)
    exit()

ans=0
wtob=0
while len(blis):
    ans+=1
    nblis=[]
    for p in blis:
        for v in d:
            ny=p[0]+v[0]
            nx=p[1]+v[1]
            if A[ny][nx]=='.':
                A[ny][nx]='#'
                nblis.append([ny,nx])
                wtob+=1
    if wtob==wnum:
        print(ans)
        exit()
    blis=[]
    for i in nblis:
        blis.append(i)


Measured memory_bytes: 178704
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, ans = 0; cin >> n; int test[101] = { 0 };
	for (int h = 1; h < n; h++) {
		cin >> a;
		test[h] = a;
	}
	for (int h = 1; h < n; h++) {
		if (h == 1) {
			ans += test[h];
		}
		if (h == n - 1) {
			ans += test[h];
		}
		if (h >= 2) {
			ans += min(test[h - 1], test[h]);
		}
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int n,k;
vector<int> to[100005];
mint ans=1;

mint perm(int n, int k) {
  mint x = 1;
  rep(i, k) x *= n-i;
  return x;
}

void dfs(int v, int p=-1) {
  int colors = (p==-1)?k:k-2;
  int unset = p==-1?to[v].size()+1:to[v].size()-1;
  ans *= perm(colors, unset); 
  for (int u: to[v]) {
    if (u==p) continue;
    dfs(u, v);
  }
}

int main() {
  cin >> n>> k;
  rep(i,n-1) {
    int a, b; cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  } 
  dfs(0);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)

int main(){
    int n, m, q, cnt, ans = 0;
    sc(n), sc(m), sc(q);
    vector<int> a(q), b(q), c(q), d(q), tmp;
    rep(i, 0, q) sc(a[i]), sc(b[i]), sc(c[i]), sc(d[i]);

    int now;
    rep(i, 1, 1<<(n+m)){
        if (i & 1) continue; 
        tmp.clear();
        cnt = 0, now = 1;
        rep(j, 1, n+m){
            if (i & (1<<j)) tmp.push_back(now);
            else now += 1;
        }
        if (tmp.size() != n) continue;
        rep(j, 0, q){
            if (tmp[b[j]-1] - tmp[a[j]-1] == c[j]) cnt += d[j];
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3696
#include<stdio.h>

int main(void) {
	int a[5];
	int i;
	scanf("%d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4]);
		for (i = 0; i < 5; i++) {
			if (0 == a[i])
				break;
		}
		printf("%d", i + 1);

	return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int A,B;
	scanf("%d %d",&A,&B);

	if(A == 1){
		A += 13;
	}
	if(B == 1){
		B += 13;
	}

	if(A > B){

		printf("Alice\n");

	}else if(A < B){

		printf("Bob\n");

	}else{

		printf("Draw\n");
	}

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

string tostr(int n)
{
	string ret="";
	for(int i=0;i<3;i++)
	{
		char cur=(n%10)+'0';
		ret=cur+ret;
		n/=10;
	}
	return ret;
}

int main()
{
	int N;
	string S;

	cin >> N;
	cin >> S;

	int ans=0;
	for(int i=0;i<1000;i++)
	{
		string s=tostr(i)+" ";
		int c=0;
		for(int j=0;j<N;j++)
		{
			if(S[j]==s[c])
				c++;
		}
		if(c==3)
			ans++;
	}

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



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
 
int main() {
    int n,i,p,ten,out;
    char d[3]={'I','U','O'},ch[8];
    cin >> n;
    for (n;n>0;n--) {
        p=0; out=0; ten=0;
        while(out<3) {
            cin >> ch;
            for (i=0;i<3;i++) if (ch[1]==d[i]) break;
            if (i==0) { ten+=p & 1; p=(p/2) | 4;}
            if (i==1) out++;
            if (i==2) { ten+=(p & 4)/4+(p & 2)/2+(p & 1)+1; p=0;}
            }
        cout << ten << endl;
    }
    return 0;
    }

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

int n;
pair<long long, pair<long long, long long> > p[100010];

int main(){
  cin >> n;

  for(int i = 0;i < n;i++){
    cin >> p[i].second.first >> p[i].second.second;
    p[i].first = p[i].second.second + p[i].second.first;
  }

  sort(p,p+n,greater<pair<long long, pair<long long, long long> > >() );

  long long t, a;

  t = a = 0;
  for(int i = 0;i < n;i++){
    if(i % 2 == 0){
      t += p[i].second.first;
    }else{
      a += p[i].second.second;
    }
  }

  cout << t-a << endl;

  return 0;
}

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

using namespace std;

#define pb push_back
#define fo(i, n) for(int i = 1; i <= n;++i)

typedef long long ll;

const int N = 302066;
const ll inf = 1e9;

int n, a[N], b[N];
int dp[4004][4004];
char x;
int d[4004][4004];
int cnt[N], pos[2][N];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n + n; ++i) {
        cin >> x >> a[i];
        b[i] = (x == 'B');
        pos[b[i]][a[i]] = i;
    }
    for(int i = 0; i <= n + n; ++i)
        for(int j = 0; j <= n + n; ++j)
            dp[i][j] = 1e9;
    dp[0][0] = 0;
    for(int i = n + n; i >= 1; --i) {
        int add = 0;
        for (int j = i + 1; j <= n + n; ++j)
            if (b[j] == b[i] && a[j] < a[i]) ++add;
        d[i][0] = add;
        for (int other = 1; other <= n; ++other) {
            if (pos[b[i] ^ 1][other] > i) {
                ++add;
            }
            d[i][other] = add;
        }
    }
    for(int i = 1; i <= n + n; ++i) {
        for(int white = 0; white <= i - 1; ++white) {
            if(dp[i-1][white] == 1e9) continue;
            int need_white = white + 1;
            int need_black = (i - 1 - white) + 1;
            if(need_white <= n) {
                int p = pos[0][need_white];
                p += d[p][need_black - 1];
                dp[i][need_white] = min(dp[i][need_white], dp[i-1][white] + (p - i));
            }
            if(need_black <= n) {
                int p = pos[1][need_black];
                p += d[p][need_white - 1];
                dp[i][white] = min(dp[i][white], dp[i-1][white] + (p - i));
            }
        }
    }

    cout << dp[n+n][n];
    return 0;
}

Measured memory_bytes: 129280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl

//ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int main() {
    int N;
    cin >> N;
    map<ll, ll>mp;

    mp[0] = 1;
    ll sum = 0, cou = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        sum += a;
        cou += mp[sum];
        mp[sum]++;
    }
    cout << cou << endl;
}

Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int xy[4][2];
bool used[4][4];

int dfs(int x, int y){
    if(y == 4) return 1;
    if(x == 4) return dfs(0, y+1);
    if(used[x][y]){
        return dfs(x+1, y);
    }
    int res = 0;
    for(int i=0; i<4; i++){
        int nx = x +xy[i][0];
        int ny = y +xy[i][1];
        if(nx<0 or 4<=nx or ny<0 or 4<=ny) continue;
        if(used[nx][ny]) continue;
        used[nx][ny] = true;
        res += dfs(x+1, y);
        used[nx][ny] = false;
    }
    return res;
}

int main(){
    while(1){
        int tmp;
        cin >> tmp;
        if(tmp > 4) break;

        for(int i=0; i<4; i++){
            for(int j=0; j<2; j++){
                if(i==0 and j==0){
                    xy[i][j] = tmp;
                }else{
                    cin >> xy[i][j];
                }
            }
        }
        cout << dfs(0, 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 3064
function Main(input) {
    var [A,B,C,D] = input[0].split(" ").map(v=>v-0);
    while(A>0 && C>0){
        C-=B;
        if(C>0){
            A-=D;
        }
    }
    console.log(A>0?"Yes":"No")
}



Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));

Measured memory_bytes: 29624
// B - Multiplication 2
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using INT = __int128_t;

ll in(){ll x;cin>>x;return x;}

int main(){
	int n; cin>>n;
	INT inf = INT(1e18) + 1;
	INT ans = 1;
	while(n--) ans = min(ans*in(), inf);
	if(ans == inf) puts("-1");
	else cout<< (ll)ans <<endl;
}


Measured memory_bytes: 3564
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int32 i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int32 i = (b) - 1; i >= (a); --i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define C(x) cout << #x << ":" << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;

template<typename Monoid, typename Operand>
class SegTree {
public:
	Monoid* tree;
	size_t size;
	int32 i;
	//?????????????????????
	SegTree(size_t length) {
		--length;
		size = length;
		if (size & 0xffff0000) { size = size & 0xffff0000; }
		if (size & 0xff00ff00) { size = size & 0xff00ff00; }
		if (size & 0xf0f0f0f0) { size = size & 0xf0f0f0f0; }
		if (size & 0xcccccccc) { size = size & 0xcccccccc; }
		if (size & 0xaaaaaaaa) { size = size & 0xaaaaaaaa; }
		if (length) { size <<= 1; }
		else { size = 1; }
		tree = (Monoid *)calloc(size << 1, sizeof(Monoid));
	}
	//?????????
	void set(bool merge) {
		i = size << 1;
		while (--i) { tree[i].set(); }
		if (merge) {
			i = size;
			while (--i) { tree[i] = tree[i << 1] + tree[i << 1 | 1]; }
		}
	}
	//tree[index]???data???§???´???°
	void update(size_t index, Operand &data) {
		index += size;
		tree[index] = tree[index] * data;
		while (index >>= 1) tree[index] = tree[index << 1] + tree[index << 1 | 1];
	}
	//[begin,end)??????????????????
	Monoid range(size_t begin, size_t end) {
		Monoid retL, retR;
		for (begin += size, end += size; begin < end; begin >>= 1, end >>= 1) {
			if (begin & 1) retL = retL + tree[begin++];
			if (end & 1)  retR = tree[end - 1] + retR;
		}
		return retL + retR;
	}
};
struct SUB {
	int32 e;
	SUB() { set(); }
	SUB(int32 x) { e = x; }
	void set() { e = 1000000000; }
	SUB operator*(const SUB &other) {
		return other;
	}
};
struct MIN {
	int32 e;
	MIN() { set(); }
	MIN(int32 x) { e = x; }
	void set() { e = 2147483647; }
	MIN operator+(const MIN &other) {
		if (e < other.e) return *this;
		return MIN(other.e);
	};
	MIN operator*(const SUB &other) {
		return MIN(other.e);
	}
};

int main() {
	int32 n, l;
	cin >> n >> l;
	SUB a;
	SegTree<MIN, SUB> t(n);
	rep(i, 0, n){
		cin >> a.e;
		t.update(i, a);
	}
	printf("%d", t.range(0, l).e);
	rep(i, 1, n - l + 1)
		printf(" %d", t.range(i, i + l).e);
	printf("\n");
	return 0;
}

Measured memory_bytes: 18856
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double l,mx=0;
double fun(double a)
{
	double low = 0,high = 1001;
	double b,c;
	double temp=0;
	while(low<high)
	{
		b = low+(high-low)/2;
		c = l-a-b;
		if((a*b*c)>temp) temp=(a*b*c),low=b;
		else high=b;
	}

	return temp;

}

int solve()
{
	cin>>l;
	cout<<setprecision(15)<<(l*l*l/27);
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define len(s) s.length()
#define forp(i,a,b) for( i=a;i<=b;i++)
#define rep(i,n)    for( i=0;i<n;i++)
#define ren(i,n)    for( i=n-1;i>=0;i--)
#define forn(i,a,b) for( i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define b(v) v.begin()
#define e(v) v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define pll pair<long long,long long>
#define vii vector<int>
#define vll vector<long long>
#define gl(cin,s)  getline(cin,s);
#define bitc(n) __builtin_popcountll(n)
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define SIZE 100010

typedef long long  ll;
typedef unsigned long long ull;
typedef long double  ldo;
typedef double  db ;
using namespace std;
int dp1[SIZE];
int dp2[SIZE];
int which[SIZE];
vector<int> pref[SIZE];
vector<int> suff[SIZE];
int N,M;
vector<int> edges[SIZE];
int sz[SIZE];
void dfs1(int curr,int par,int val)
{
  which[curr] = val;
  dp1[curr] = 1;
  sz[curr] = edges[curr].size();
  if(curr != 1)
  sz[curr]--;
  int Val = 0;
  for(int i=0;i<edges[curr].size();i++){
    if(edges[curr][i] != par){
      dfs1(edges[curr][i],curr,Val++);
      dp1[curr] = (1LL*dp1[curr]*((1 + dp1[edges[curr][i]])%M))%M;
      pref[curr].push_back(dp1[curr]);
    }
  }
  int currVal = 1;
  for(int i=edges[curr].size()-1;i>=0;i--){
    if(edges[curr][i] != par){
      currVal = (1LL*currVal*((1 + dp1[edges[curr][i]])%M))%M;
      suff[curr].push_back(currVal);
    }
  }
}
void dfs2(int curr,int par)
{
  if(curr != 1){
    int currVal;
    if(sz[par] == 1){
      currVal = 1;
    }
    else{
      if(which[curr] == 0){
        currVal = suff[par][sz[par]-2-which[curr]];
      }
      else if(which[curr] == sz[par] - 1){
        currVal = pref[par][which[curr]-1];
      }
      else{
        currVal = (1LL*pref[par][which[curr]-1]*suff[par][sz[par]-2-which[curr]])%M;
      }
    }
    dp2[curr] = (1LL*dp2[par]*currVal)%M;
    dp2[curr] = (dp2[curr] + 1)%M;
  }
  else{
    dp2[curr] = 1;
  }
  for(int i=0;i<edges[curr].size();i++){
    if(edges[curr][i] != par){
      dfs2(edges[curr][i],curr);
    }
  }
}
int main()
{
    boost;
    cin>>N>>M;
    for(int i=1;i<N;i++){
      int x,y;
      cin>>x>>y;
      edges[x].push_back(y);
      edges[y].push_back(x);
    }
    dfs1(1,1,0);
    dfs2(1,1);
    for(int i=1;i<=N;i++){
      int currAns = (1LL*dp1[i]*dp2[i])%M;
      cout<<currAns<<endl;
    }
    return 0;
}


Measured memory_bytes: 26240
n,m = map(int, input().split())

lights = []
for i in range(m):
    lights.append([int(_) for _ in input().split(' ')[1:]])

rules = [int(_) for _ in input().split(' ')]

patterns = []
for i in range(2**n):
    tmp = ['off'] * n
    for j in range(n):
        if (i >> j & 1):
            tmp[j] = 'on'
    patterns.append(tmp)

count = 0
for p in patterns:
    bright = 0
    for i in range(m):
        on_count = 0
        for switch in lights[i]:
            if(p[switch-1] == 'on'):
                on_count += 1
        if(on_count%2 == rules[i]):
            bright += 1
    if(bright == m):
        count += 1
        
print(count)

Measured memory_bytes: 42096
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)
#define int long long

vector<int> B(1,1),P(1,1);
int f(int N,int X){
    int res = 0;
    if(N == 0) res += 1;
    else if(X == 1) res += 0;
    else if(X <= B[N-1]+1) res += f(N-1,X-1);
    else if(X == B[N-1]+2) res += P[N-1] + 1;
    else if(X <= 2*B[N-1]+2) res = P[N-1] + 1 + f(N-1,X-B[N-1]-2);
    else res += 2*P[N-1]+1;

    return res;
}

signed main(){
    ll N,X;
    cin >> N >> X;
    for(int i=0;i<=50;++i){
        B.emplace_back(B[i]*2 + 3);
        P.emplace_back(P[i]*2 + 1);
    }

    cout << f(N,X) << endl;
}

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

using namespace std;

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

    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using Int = int64_t;
const Int inf = 1LL << 53;

std::pair<Int,Int> eval2(std::string ss, Int i) {
   if( ss[i] == '0' ) {
      return std::make_pair(0, i+1);
   }
   else if( ss[i] == '1' ) {
      return std::make_pair(1, i+1);
   }
   else if( ss[i] == '-' ) {
      Int i2 = i;
      i2 += 1;
      Int t;
      std::tie(t, i2) = eval2(ss, i2);
      return std::make_pair(t ^ 1, i2);
   }
   else if( ss[i] == '(' ) {
      Int i2 = i;
      i2 += 1;
      Int left;
      std::tie(left, i2) = eval2(ss, i2);
      char op = ss[i2];
      i2 += 1;
      Int right;
      std::tie(right, i2) = eval2(ss, i2);
      assert(ss[i2] == ')');
      i2 += 1;
      if( op == '*' ) {
         return std::make_pair(left & right, i2);
      }
      else if( op == '^' ) {
         return std::make_pair(left ^ right, i2);
      }
      else {
         assert(0);
      }
   }
   else {
      std::cerr << ss[i] << std::endl;
      assert(0);
   }
   assert(0);
   return std::make_pair(-1,-1);
}

Int eval(std::string ss) {
   Int res = 0;
   for(Int i = 0; i < 1<<4; ++i) {
      std::string ts = ss;
      for(Int k = 0; k < 4; ++k) {
         for(Int j = 0; j < (Int)ts.size(); ++j) {
            if( ts[j] == 'a' + k ) {
               if( (i & (1 << k)) == 0 ) {
                  ts[j] = '0';
               }
               else {
                  ts[j] = '1';
               }
            }
         }
      }
      res |= eval2(ts, 0).first << i;
   }
   return res;
}


int main() {
   std::map<Int,Int> dp;
   dp[0x0000] = 1;
   dp[0xffff] = 1;
   dp[0xaaaa] = 1;
   dp[0xcccc] = 1;
   dp[0xf0f0] = 1;
   dp[0xff00] = 1;
   for(Int i = 0; i < 16; ++i) {
      // -
      for(auto xs1 : dp) {
         Int x1, s1;
         std::tie(x1, s1) = xs1;
         if( dp.count(x1^0xffff) == 0 ) {
            dp[x1^0xffff] = s1+1;
         }
         else {
            dp[x1^0xffff] = std::min(dp[x1^0xffff], s1+1);
         }
      }
      // *, ^
      for(auto xs1 : dp) {
         Int x1, s1;
         std::tie(x1, s1) = xs1;
         for(auto xs2 : dp) {
            Int x2, s2;
            std::tie(x2, s2) = xs2;
            if( s1 + s2 + 3 > 16 ) {
               continue;
            }
            // ^
            if( dp.count(x1^x2) == 0 ) {
               dp[x1^x2] = s1 + s2 + 3;
            }
            else {
               dp[x1^x2] = std::min(dp[x1^x2], s1 + s2 + 3);
            }
            // *
            if( dp.count(x1&x2) == 0 ) {
               dp[x1&x2] = s1 + s2 + 3;
            }
            else {
               dp[x1&x2] = std::min(dp[x1&x2], s1 + s2 + 3);
            }
         }
      }
   }
   for(;;) {
      std::string ss;
      std::cin >> ss;
      if( ss == "." ) {
         break;
      }
      // printf("%lx\n", eval(ss));
      std::cout << dp[eval(ss)] << std::endl;
   }
}



Measured memory_bytes: 3292
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

lcm = A[0]
for i in range(1, len(A)):
	#リストA（N個）の最小公倍数
	lcm = lcm * A[i] // gcd(lcm, A[i])

# print(lcm)
print(sum([(lcm-1) % a for a in A]))

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

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var cin = new MyInputStream();
            var c = Console.Read();
            var vowels = new char[] { 'a', 'i', 'u', 'e', 'o' };
            Console.WriteLine(vowels.Where(i => i == c).Count()  != 0 ? "vowel" : "consonant");
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine()   { return Console.ReadLine(); }
        public int    ReadInt()    { return int.Parse(Read()); }
        public long   ReadLong()   { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
    }

    public class MyUtility
    {
        /// <summary>2値を入れ替える</summary>
        public static void Swap<T>(ref T m, ref T n)
        {
            T tmp = m;
            m = n;
            n = tmp;
        }

        public static void PutYN(bool f)
        {
        	Console.WriteLine(f ? "YES" : "NO");
        }
    }
}

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

pair<char, int> card_b[37];
pair<char, int> card_s[37];

bool stable(int n){

	for (int i = 0; i < n; i++){
		if (card_b[i] != card_s[i])
			return false;
	}
	return true;
}

void bubble(int n){

	for (int i = 0; i < n; i++){
		for (int j = n - 1; j >= i; j--){
			if (card_b[j].second < card_b[j - 1].second)
				swap(card_b[j], card_b[j - 1]);
		}
	}

	for (int i = 0; i < n - 1; i++)
		cout << card_b[i].first << card_b[i].second << ' ';
	cout << card_b[n - 1].first << card_b[n - 1].second << endl << "Stable" << endl;

	return;
}

void selction(int n){

	for (int i = 0; i < n - 1; i++){

		int mini = i;
		for (int j = i; j < n; j++){
			if (card_s[j].second < card_s[mini].second)
				mini = j;
		}

		if (i != mini)
			swap(card_s[i], card_s[mini]);
	}

	for (int i = 0; i < n - 1; i++)
		cout << card_s[i].first << card_s[i].second << ' ';
	cout << card_s[n - 1].first << card_s[n - 1].second << endl;
	if (stable(n)) cout << "Stable" << endl;
	else cout << "Not stable" << endl;

	return;
}

int main(void){

	int n;

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> card_b[i].first >> card_b[i].second;
		card_s[i] = card_b[i];
	}

	bubble(n);
	selction(n);
}

Measured memory_bytes: 1164
#include <iostream>
#define int long long
using namespace std;

int a[500010], n;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    int last = 0;
    for(int i = 1; i <= n; i += 2) {
        last += a[i];
    }
    for(int i = 2; i <= n; i += 2) {
        last -= a[i];
    }
    cout << last;
    for(int i = 2; i <= n; ++i) {
        cout << ' ' << (last = a[i - 1] * 2 - last);
    }
    return 0;
}

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

int main(){
  int num;
  cin >> num;
  int a = num/1000;
  int b = (num - (1000*a))/100;
  int c = (num - (1000*a + 100*b))/10;
  int d = (num - (1000*a + 100*b + 10*c));
  if(a != b && b != c && c != d){
    cout << "Good" << endl;
  }
  else{
    cout << "Bad" << endl;
  }
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d%d", $x, $y);

$arrayA = [1,3,5,7,8,10,12];
$arrayB = [4,6,9,11];
$arrayC = [2];

$rslA = [];
$rslB = [];

if (in_array($x,$arrayA)){
    $rslA[] = 1;
}elseif (in_array($x,$arrayB)){
    $rslA[] = 2;
}else{
    $rslA[] = 3;
}

if (in_array($y,$arrayA)){
    $rslB[] = 1;
}elseif (in_array($y,$arrayB)){
    $rslB[] = 2;
}else{
    $rslB[] = 3;
}

if ($rslA == $rslB){
    echo 'Yes';
}else{
    echo 'No';
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll K;
  cin>>K;
  if(K%2==0) {
cout<<(K/2)*(K/2)<<endl;
  }
  else {
cout<<(K/2+1)*(K/2)<<endl;
  }
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (int)(s); i < (int)(e); ++i)
#define per(i,s,e) for(int i = (int)(s)-1; i >= (int)(e); --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

int main(){
  int n,m; cin >> n >> m;
  heaP<int> hp;
  ll sum = 0;
  rep(i,0,n){int x; cin >> x; hp.push(x);sum+=x;}
  vector<P<int,int>> vec(m);
  rep(i,0,m)cin >> vec[i].second >> vec[i].first;
  sort(vec.begin(),vec.end(),greater<P<int,int>>());
  rep(i,0,m){
    int c, v;tie(v,c) = vec[i]; 
    rep(j,0,c){
      int x = hp.top();
      if(x >= v)break;
      hp.pop();
      hp.push(v);
      sum += v-x;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1528
def gcd(m,n):
  x=max(m,n)
  y=min(m,n)
  while y!=0:
    x,y=y,x%y
  return x

n = int(input())
a = list(map(int, input().split()))
b = []
l = [0]
r = [0]

for i in range(n):
  l.append(gcd(a[i],l[i]))
  r.append(gcd(a[n-1-i],r[i]))

for i in range(n):
  b.append(gcd(l[i],r[n-1-i]))
  
print(max(b))

Measured memory_bytes: 14076
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <map>

using namespace std;
using lli = long long int;
using ll = long long;

int main() {

    lli A1, A2, A3;
    cin >> A1 >> A2 >> A3;

    if (A1 + A2 + A3 > 21) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }

}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long int ll;
vector<ll> fact(200001);
void init_fact(int n){
	fact[0]=1;
	for (int i = 1; i < n+1; i++){
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
}
ll mod_pow(ll x, ll p){
	ll res=1;
	ll n=x;
	while(p>0){
		if(p&1==1)res=(res*n)%MOD;
		n=(n*n)%MOD;
		p=(p>>1);
	}
	return res;
}
ll nCr(int n, int r){
	ll res=1;
	//if n is large
	// for (int i = n; i > n-r; i--){
	// 	res*=i;
	// 	res%=MOD;
	// }
	res*=fact[n];
	res*=mod_pow(fact[r],MOD-2);
	res%=MOD;
	res*=mod_pow(fact[n-r],MOD-2);
	res%=MOD;
	return res;
}
int main() {
	ofstream ofs("a.txt");
	int n,k;
	cin>>n>>k;
	init_fact(n);
	int i_max=min(k,n-1);
	ll ans=0;
	for (int i = 0; i <=i_max; i++){
		ofs<<i<<endl;
		ll tmp=nCr(n,min(i,n-i))*nCr(n-1,min(i,n-i-1));
		tmp%=MOD;
		ans+=tmp;ans%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3072