akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, C; cin >> N >> C;
    vvl ds(C+1, vl(C+1, 0)), cs(N+1, vl(N+1, 0));
    REP(i, C) REP(j, C) cin >> ds[i+1][j+1];
    REP(i, N) REP(j, N) cin >> cs[i+1][j+1];
    
    vvpl dif(3, vpl(C+1, PL(0, LINF)));
    FOR(k,1,C+1){
        REP(i, 3) {dif[i][k].ff = k; dif[i][k].ss = 0LL;};
        FOR(i,1,N+1){
            FOR(j,1,N+1){
                dif[(i+j)%3][k].ss += ds[cs[i][j]][k];
            }
        }
    }
    REP(i, 3) sort(dif[i].begin(), dif[i].end(), p_comp_ss);

    
    ll ret = LINF;
    REP(i, 4) REP(j, 4) REP(k, 4){
        auto p0 = dif[0][i]; auto p1 = dif[1][j]; auto p2 = dif[2][k];
        if(p0.ff == p1.ff || p1.ff == p2.ff || p2.ff == p0.ff) continue;
        ret = min(ret, p0.ss + p1.ss + p2.ss);
    }
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
 
int main()
{
int D ;
  int N ;
  int a ;
  cin >> D >> N ;
  a=pow(100,D) ;
  if(N<100)
  {
      cout << a*N << endl;
  }
  else{
          cout << a*101 << endl;
  }
    return 0;
}

Measured memory_bytes: 256
'use strict';
(function(stdin) {
  var inputs = stdin.toString().trim().split('\n');
  var params = inputs[0].split(' ').map(Number);
 var a= parseInt(params[0]);
 var b= parseInt(params[1]);
 var c= parseInt(params[2]);
  (function(a, b, c) {
    // ????????????????????????
if(a<b && a<c){
  console.log('Yes');
}else {
  console.log('No');
}

  }(params[0], params[1], params[2]));

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15576
r=int(input())
c=0
if r>699 and r<800:
    c+=1
r=r%100
if r>69 and r<80:
    c+=1
r=r%10
if r==7:
    c+=1


if c>0:
    print("Yes")
if c==0:
    print("No")

   

Measured memory_bytes: 9176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long K = sc.nextLong();
		long[] A = new long[N];
		long[] B = new long[M];
		long aSum = 0;
		for (int i = 0; i < N; i++) {
			long tmp = sc.nextLong();
			A[i] = tmp;
			aSum += tmp;
		}
		for (int i = 0; i < M; i++) {
			long tmp = sc.nextLong();
			B[i] = tmp;
		}
		int bPos = 0;
		if (aSum <= K) {
			while (bPos < B.length) {
				if (aSum + B[bPos] <= K) {
					aSum += B[bPos];
					bPos++;
				} else {
					break;
				}
			}
		}
		int res = aSum <= K ? N + bPos : 0;
		for (int i = N - 1; i >= 0; i--) {
			aSum -= A[i];
			if (aSum > K) {
				continue;
			}
			while (bPos < B.length) {
				if (aSum + B[bPos] <= K) {
					aSum += B[bPos];
					bPos++;
				} else {
					break;
				}
			}
			if (res < i + bPos) {
				res = i + bPos;
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 63776
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N;
  string s;
  cin>>N>>s;
  int cnt(0);
  string ans;
  for(int i(0);i<N;i++){
    ans += s[i];
    if (s[i] == ')'){
      cnt++;
    }else{
      cnt--;
    }
    if (i != N-1 && s[i] == ')' && s[i+1] == '('){
      if (cnt > 0){
        ans = string(cnt,'(') + ans;
        cnt = 0;
      }
    }
  }
  if (cnt > 0){
    ans = string(cnt,'(') + ans;
  }else{
    ans += string(abs(cnt),')');
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int table[100010][18];
int N, L, Q;
int x[100010];

signed main() {
    cin >> N;
    rep(i,0,N) cin >> x[i];
    cin >> L >> Q;

    rep(i,0,N) {
        int idx = upper_bound(x, x+N, x[i] + L) - x - 1;
        if(idx <= i) table[i][0] = -1;
        else table[i][0] = idx;
    }

    rep(k,0,17) {
        rep(i,0,N) {
            if(table[i][k] < 0) table[i][k+1] = -1;
            else table[i][k+1] = table[table[i][k]][k];
            // printf("table[%lld][%lld] = %lld\n", i, k+1, table[i][k]);
        }
    }

    rep(i,0,Q) {
        int a, b; cin >> a >> b; a--; b--;
        if(a > b) swap(a, b);

        int cur = a, ans = 0;
        rep(i,0,20) {
            repr(k,17,0) {
                int to = table[cur][k];
                if(to < 0 || to >= b) continue;
                // printf("cur = %lld, to = %lld, k = %lld\n", cur, to, k);
                cur = to;
                ans += (1 << k);
                break;
            }
        }
        cout << ans + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 15616
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = 0;
		int m = 0;
		n = sc.nextInt();
		m = sc.nextInt();

		int total = 0;

        for (int i = 0; i < m; i++) {
        	total += sc.nextInt();
        }

        if(n - total >= 0){
			System.out.println(n - total);
        }else{
        	System.out.println("-1");
        }
	}
}

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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> d(K);
    vector<vector<int>> A(K,vector<int>(N));
    vector<bool> ans(N,true);
    for (int i = 0; i < K; i++){
        cin >> d.at(i);
        for (int j = 0; j < d.at(i); j++){
            cin >> A.at(i).at(j);
            ans.at(A.at(i).at(j) - 1) = false;
        }
    }
    int count = 0;
    for (int i = 0; i < N; i++){
        if (ans.at(i)) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
#include<string>
#define REP(i,a,b) \
for(int i=a; i<b; i++)
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long int
typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define tr(c,i) for(typeof(c.begin()) i = (c).begin(); i != (c).end();i++)

int main()
{
	int a,b;
	cin >> a >> b;
	if(a+b == 15)cout << "+";
	else if(a*b == 15)cout << "*";
	else cout << "x";
}

Measured memory_bytes: 256
N,M = map(int, input().split())
Bridge = []
for i in range(M):
    Bridge.append([int(x) for x in input().split()])

def minpair(A,B):
    if A[1] <= B[0]:
        C = []
    elif B[0] < A[1] <= B[1]:
        C = [B[0],A[1]]
    else:
        C = B
    return C

Bridge.sort(key=lambda x: x[0])
c = 0
ans = 0
while c <= M-2:
    Temp = minpair(Bridge[c],Bridge[c+1])
    if Temp == []:
        ans += 1
    else:
        Bridge[c+1] = Temp
    c += 1
print(ans+1)

Measured memory_bytes: 22904
#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(){

	ll X;
	scanf("%lld",&X);

	ll ans = 2*(X/11);
	X %= 11;

	if(X == 0){

		printf("%lld\n",ans);
		return 0;
	}

	if(X <= 6){

		ans++;
	}else{

		ans += 2;
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def solve():
    N, M = MI()
    uf = UnionFind(N)
    for i in range(M):
        a, b = MI1()
        uf.union(a, b)
    print(uf.group_count()-1)

        
if __name__ == '__main__':
    solve()



Measured memory_bytes: 12960
#ABC093-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
Bar=IL()
Bar.sort()
ans=0
for i in range(2):
    while Bar[i]+2<=Bar[2]:
        Bar[i]+=2
        ans+=1
if Bar[0]==Bar[1] and Bar[1]==Bar[2]:
    print(ans)
elif Bar[0]==Bar[1]:
    print(ans+1)
else:
    print(ans+2)

Measured memory_bytes: 38256
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#include <bits/stdc++.h>

using namespace std;

#define BOOST 			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ALL(a) 			(a).begin(), (a).end()
#define SZ(a) 			(int)(a).size()
#define FOR(a, b, c) 	for (int a = (b); a <  (c); a++)
#define FORR(a, b, c) 	for (int a = (b); a >= (c); a--)
#define TRAV(a, b) 		for (auto& a : b)
#define ELO 			exit(0)
#define SORT(a)         sort(ALL(a))
#define REV(a)          reverse(ALL(a))
#define SORTR(a)        SORT(a), REV(a)
#define PB              push_back
using ll = 				long long;
using ld = 				long double; // 'long double' is 2.2 times slower than double
using pii = 			pair<int, int>;
using pll = 			pair<ll, ll>;
using vi = 				vector<int>;
using vll = 			vector<ll>;
using vpii = 			vector<pii>;
using vpll = 			vector<pll>;

template <class T> inline bool setmin(T& a, T b) {if (a > b) return a = b, 1; return 0; }
template <class T> inline bool setmax(T& a, T b) {if (a < b) return a = b, 1; return 0; }

namespace fastio {
    template <class T> istream &operator>>(istream &os, vector<T> & vec){for (auto &u : vec)os >> u;return os;}
    template <class T> ostream &operator<<(ostream &os, const vector<T> & vec){for (auto &u : vec)os << u << " ";return os;}
    template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) { return os >> p.first >> p.second; }
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << p.first << " " << p.second; }
    template <class T> ostream &operator<<(ostream &os, set<T> & con) { for (auto &u : con) os << u << " "; return os; }

    void re() {}
    template <typename T, typename... args> void re(T& x, args&... tail) { cin >> x; re(tail...); }
    void pr() {}
    template <typename T, typename... args> void pr(T x, args... tail) { cout << x << " "; pr(tail...);}
    template <typename... args> void prln(args... tail) { pr(tail...); cout << "\n";}
}
using namespace fastio;

namespace debug {
    template < typename _T > inline void _debug(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
    template < typename _T, typename... args > void _debug(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _debug(s + 1, a...); }
    
    #if 1
        #define debug(...) _debug(#__VA_ARGS__, __VA_ARGS__)
        #define cerr cout
    #else
        #define debug(...) 1999
        #define cerr if(0) cout
    #endif
}
using namespace debug;

//////////////_________CODE_________//////////////

constexpr int MOD = 1e9 + 7; // 998244353
constexpr int INF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;

int main() {
    BOOST;
    string s; re(s);
    FOR(i, 0, SZ(s) - 1) {
        if(s[i] == s[i + 1]) {
            prln("Bad");
            ELO;
        }
    }
    prln("Good");
    ELO;
}

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

template <class T>
vector<pair<T, T>> prime_factorization(T n) {
    vector<pair<T, T>> ret;
    for (T i = 2; i * i <= n; i++) {
        T cnt = 0;
        while(n % i == 0) { n /= i; cnt++; }
        if(cnt != 0) ret.emplace_back(i, cnt);
    }
    if (n != 1) ret.emplace_back(n, 1);
    return ret;
}

int main(){
    int64_t n, p, ans = 1; cin >> n >> p;
    auto a = prime_factorization(p);
    for (auto & elm : a) if(elm.second >= n) ans *= pow(elm.first, (elm.second / n));
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int num[N];
    int sum=0;
    for (int i=0; i<N; i++){
        cin >> num[i];
        sum+=num[i];
    }
    double avg = double(sum)/N;
    if(avg-int(avg)<0.5){
        avg=int(avg);
    }else{
        avg=int(avg)+1;
    }
    int var=0;
    for (int i=0; i<N; i++){
        var+=(avg-num[i])*(avg-num[i]);
    }
    cout << var << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long t1, t2, a1, a2, b1, b2;
long d1, d2;

int main(){
    scanf("%ld%ld%ld%ld%ld%ld", &t1, &t2, &a1, &a2, &b1, &b2);
    d1 = t1*(a1-b1);
    d2 = t2*(a2-b2);
    if(d1 + d2 == 0){
        printf("infinity\n");
        return 0;
    }
    if((d1 > 0 && (d1 + d2) > 0) || (d1 < 0 && (d1 + d2) < 0)){
        printf("0\n");
        return 0;
    }
    if((d1 + d2) < 0){
        d1 = -d1;
        d2 = -d2;
    }
    //printf("%ld %ld\n", d1, d2);
    long n = (-d1) / (d1 + d2);
    if((-d1) % (d1 + d2) == 0){
        printf("%ld\n", 2 * n);
    }else{
        printf("%ld\n", 2 * n + 1);
    }
}


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

const int MOD = 1000000007;

int n;
string S;

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string &S) {
	//int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

// mod 1000000007 の世界で a += b する関数
void add(long long &a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

int main() {
	// 入力
	cin >> n >> S;
	sort(S.begin(), S.end());
	
	// 前処理配列
	vector<vector<int> > next = calcNext(S);

	// DP
	vector<long long> dp(n + 1, 0);
	dp[0] = 1; // 初期化、空文字列 "" に対応
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 26; ++j) {
			if (next[i][j] >= n) continue; // 次の文字 j がもうない場合はスルー
			add(dp[next[i][j] + 1], dp[i]);
		}
	}

	// 集計
	long long res = 0;
	for (int i = 0; i <= n; ++i) add(res, dp[i]);

	cout << res - 1 << endl;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=2019;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int n,m,a;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> m;
	rep(m){
		cin >> a;
		n-=a;
	}
	print1(max(-1ll,n));
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ull = unsigned long long;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<ull> a;
    rep(i, n+1){
        ull x;
        cin >> x;
        a.push_back(x);
    }
    vector<ull> minim(n+1, 0ULL), maxim(n+1, 0ULL);

    minim[n] = a[n];
    maxim[n] = a[n];

    for(int i=n-1;i>=0;i--){
        maxim[i] = maxim[i+1] + a[i];
        minim[i] = (minim[i+1] + 1) / 2 + a[i];
    }

    // rep(i, n+1){
    //     cout << minim[i] << ":" << maxim[i] << endl;
    // }

    ull ok=1ULL, ans=0;
    if(n==0){
        if(a[0]!=1){
            cout << -1 << endl;
        }else{
            cout << 1 << endl;
        }
        return 0;
    }

    rep(i, n+1){
        if(minim[i]>ok||(i!=n&&minim[i]>maxim[i+1]+a[i])){
            cout << -1 << endl;
            return 0;
        }
        ull tmp = min(ok, maxim[i]);
        ans += tmp;
        //cout << tmp << endl;
        ok = tmp - a[i];
        ok<<=1;
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
	int N, K;
	std::string S;
	
	std::cin >> N >> K;
	std::cin >> S;

	S[K-1] = S[K-1] + ('a' - 'A');

	std::cout << S << "\n";
}


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

const int MAX = 112345;

struct point {
    int x, y, t;
    point(int X = 0, int Y = 0, int T = 0):
        x(X), y(Y), t(T) {}
    
    bool operator < (const point ot) const {
        return (t < ot.t);
    }
};

bool can(point cur, point targ) {
    int D = abs(cur.x - targ.x) + abs(cur.y - targ.y);
    int T = targ.t - cur.t;
    //printf("Time %d --- Dist %d\n", T, D);
    if (T >= D && ((T - D) % 2 == 0)) return true;
    return false;
}

int N;
int main() {
    point cur = point(0, 0, 0);
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        point targ;
        scanf("%d%d%d", &targ.t, &targ.x, &targ.y);
        if (!can(cur, targ)) {
            puts("No");
            return 0;
        }
        cur = targ;
    }

    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vi >
#define vvl vector< vl >
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector< pii >
#define vpll vector< pll >
#define rep(i, a, b) for(int i = a; i < b; i++) 
#define repll(i, a, b) for(ll i = a; i < b; i++) 
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define F first
#define S second
#define string_to_int(s) stoi(s)
#define string_to_ll(s) stoll(s)
#define int_to_string(n) to_string(n)
#define ll_to_string(n) to_string(n)
#define char_to_int(c) c-'0'
#define int_to_char(c) c+'0'
int main() {

	ll n;
	cin >> n;
	vector<string> s(n);
	map<string, ll> mp;
	repll(i, 0, n) {
		cin >> s[i];
		sort(all(s[i]));
		mp[s[i]]++;
	}	
	ll count = 0;
	for(auto x: mp) {
		count += x.second*(x.second-1)/2;
	}
	cout << count << "\n";

	return 0;
}


Measured memory_bytes: 18176
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

count = 0
n.times do |i|
  ene = a[i] + a[i+1]
  if ene <= b[i]
    count += a[i] + a[i+1]
    a[i] = 0
    a[i+1] = 0
  else
    count += b[i]
    if a[i] <= b[i]
      a[i+1] -= b[i] - a[i]
      a[i] = 0
    else
      a[i] -= b[i]
    end
  end
end

print count

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    lli n;
    cin1(n);
    cout << n * n* n << endl;
}


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

int main() {
  int A,B;
  cin >> A >> B;
  int jud=0;
  for(int i=A;i<=B;i++){
    int a,b,c,d,e;
	e=i%10;
    d=(i/10)%10;
    c=(i/100)%10;
    b=(i/1000)%10;
    a=(i/10000)%10;
	if(a==e && b==d){jud +=1;}
    else{}
  }
  cout << jud <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define DREP(i,n,N) for(int i=n;i>=N;i--)
#define print(S) cout<<S<<endl;
using namespace std;

int main() {
	int N,count=0,tmp=0;
	cin>>N;
	int A[N];
	int B[100001]={0};
	REP(i,0,N){
		cin>>A[i];
		B[A[i]]++;
	}
	REP(i,0,100001){
		while(B[i]>2){
			B[i]-=2;
		}
if(B[i]==1){
			count++;
		}else if(B[i]==2){
			if(tmp){
				count+=2;
				tmp=0;
			}else{
				tmp=1;
			}
		}
	}
	
	print(count);
	return 0;
}

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

edge = [[] for i in range(n)]

for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

cost = list(map(int, input().split()))

c = sorted(cost, reverse=True)

w = [0] * n

w[0] = c.pop(0)

chk = [i for i in edge[0]]

while chk != []:
    node = chk.pop(0)
    if w[node] == 0:
        w[node] = c.pop(0)
        chk.extend(edge[node])

print(sum(cost) - max(cost))

print(' '.join(map(str, w)))

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

struct RARS {
	struct type1 {
		ll val, size;
		type1(ll v, ll s = 1) : val(v), size(s) {}
	};
	using type2 = ll;
	static type1 id1() { return type1(0, 0); }
	static type2 id2() { return 0; }
	static type1 op1(const type1& l, const type1& r) { return type1(l.val + r.val, l.size + r.size); }
	static type1 op2(const type1& l, const type2& r) { return type1(l.val + l.size * r, l.size); }
	static type2 op3(const type2& l, const type2& r) { return l + r; }
};

template <typename M>
class LazySegmentTree {
	using T1 = typename M::type1;
	using T2 = typename M::type2;
	const int n;
	vector<T1> data;
	vector<T2> lazy;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	void push(int node) {
		if (lazy[node] == M::id2()) return;
		if (node < n) {
			lazy[node * 2] = M::op3(lazy[node * 2], lazy[node]);
			lazy[node * 2 + 1] = M::op3(lazy[node * 2 + 1], lazy[node]);
		}
		data[node] = M::op2(data[node], lazy[node]);
		lazy[node] = M::id2();
	}
	void suc(int l, int r, int node, int lb, int ub, T2 val) {
		if (ub <= l || r <= lb) return;
		if (l <= lb && ub <= r) {
			lazy[node] = M::op3(lazy[node], val);
			return;
		}
		push(node);
		int c = (lb + ub) / 2;
		suc(l, r, node * 2, lb, c, val);
		suc(l, r, node * 2 + 1, c, ub, val);
		data[node] = M::op1(M::op2(data[node * 2], lazy[node * 2]), M::op2(data[node * 2 + 1], lazy[node * 2 + 1]));
	}
	T1 sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return M::id1();
		if (l <= lb && ub <= r) return M::op2(data[node], lazy[node]);
		push(node);
		int c = (lb + ub) / 2;
		return M::op1(sub(l, r, node * 2, lb, c), sub(l, r, node * 2 + 1, c, ub));
	}
public:
	LazySegmentTree(int n_) : n(size(n_)), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {}
	LazySegmentTree(int n_, T1 v1, T2 v2) : n(size(n_)), data(n * 2, v1), lazy(n * 2, v2) {}
	void init() {
		for (int i = n - 1; i >= 0; i--) data[i] = M::op1(data[i * 2], data[i * 2 + 1]);
	}
	void update(int l, int r, T2 val) {
		suc(l, r + 1, 1, 0, n, val);
	}
	T1 find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, type, s, t, x;
	cin >> n >> q;
	LazySegmentTree<RARS> lst(n, RARS::type1(0, 1), 0);
	lst.init();
	while (q--) {
		cin >> type >> s >> t; s--; t--;
		if (type) {
			printf("%lld\n", lst.find(s, t).val);
		}
		else {
			cin >> x;
			lst.update(s, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 8848
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    
    Scanner scan;
    int sheep;
    int wolves;
    
    sheep = 0;
    wolves = 0;
    
    scan = new Scanner(System.in);
    sheep = scan.nextInt();
    wolves = scan.nextInt();
    
    if (sheep > wolves){
      System.out.println("safe");
    }else {
      System.out.println("unsafe");
    }
      
  }
}


Measured memory_bytes: 35756
MOD = int (1e9) + 7
N, K = list (map (int, input().split()))
a = sorted (list (map (int, input().split())))

f = [1 for i in range (N + 1)]

maxSum, minSum = 0, 0

def modPow (base, k) :
    res = 1
    while k : 
        if k & 1 :
            res = res * base % MOD
        base = base * base % MOD
        k >>= 1
    return res

def inv (x) :
    return modPow (x, MOD - 2)

def C (n, m) :
    return (f[n] * inv (f[m]) % MOD) * inv (f[n - m])

if K == 1 :
    print (0)
else :
    for i in range (2, N + 1) :
        f[i] = f[i - 1] * i % MOD
    for i in range (K - 1, N) :
        maxSum = (maxSum + a[i] * C (i, K - 1) % MOD) % MOD
    for i in range (N - K + 1) :
        minSum = (minSum + a[i] * C (N - i - 1, K - 1) % MOD) % MOD
    
    print ((maxSum - minSum + MOD) % MOD)

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

using ll=long long;

int main(){    
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(abs(b-a)>1e18){
        cout<<"Unfair"<<endl;
        return 0;
    }
    if(k%2){
        cout<<b-a<<endl;
    }else{
        cout<<a-b<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int MAX_N = 150;
int G[MAX_N][MAX_N], found[MAX_N], finished[MAX_N];
int Time, N;
void dfs(int u)
{
    Time++;
    found[u] = Time;
    for(int nextV = 1; nextV <= N; nextV++)
    {
        if(found[nextV] || G[u][nextV] == 0) continue;
        dfs(nextV);
    }
    Time++;
    finished[u] = Time;
}
void init()
{
    Time = 0;
    for(int i = 0; i <= N; i++)
    {
        found[i] = 0;
        finished[i] = 0;
    }
    for(int i = 0; i <= N; i++) for(int j = 0; j <= N; j++) G[i][j] = 0;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    init();
    for(int i = 0; i < N; i++)
    {
        int u, k; cin >> u >> k;
        for(int j = 0; j < k; j++)
        {
            int v; cin >> v;
            G[u][v] = 1;
        }
    }
    int u = 1;
    while(u <= N)
    {
        if(found[u] == 0) dfs(u);
        u++;
    }
    for(int v = 1; v <= N; v++)
    {
        cout << v << " " << found[v] << " " << finished[v] << endl;
    }
    return 0;
}




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

#define mp make_pair
#define pb push_back
#define f first
#define s second

using namespace std;

typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int,int> mii;
typedef unordered_map<int,int> umii;
typedef queue<int> qi;

ll tab[200005];
ll in[200005];
si S;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> in[i];
		tab[in[i]] ++;
		S.insert(in[i]);
	}
	
	ll xd = 0;
	for (auto it : S) {
		xd += ((tab[it]-1) * tab[it]) / 2;
	}
	//cout << xd << '\n';
	for (int i = 1; i <= n; i ++) {
		cout << xd - (tab[in[i]]-1) << '\n';
	}
	
	return 0;
}


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

int main()
{
	int h,w,k;
	cin>>h>>w>>k;
	char inp[h][w];
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cin>>inp[i][j];

	int ans=0;
	for(int mask1=0;mask1<(1<<h);mask1++)
		for(int mask2=0;mask2<(1<<w);mask2++)
		{
			int cnt=0;
			for(int i=0;i<h;i++)
				for(int j=0;j<w;j++)
				{
					int g=(mask1&(1<<i)),gd=(mask2&(1<<j));
					//cout<<g<<" "<<gd<<" "<<i<<" "<<j<<"\n";
					if((g|gd)==0&&inp[i][j]=='#')
						cnt++;
				}
			//cout<<mask1<<" "<<mask2<<" "<<" "<<cnt<<"\n";
			if(cnt==k)
				ans++;
		}
	cout<<ans;
}



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

int main(){
  int64_t n,h;
  cin >> n >> h;
  vector<int64_t>a(n);
  vector<int64_t>b(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i) >> b.at(i);
  sort(a.begin(),a.end(),greater());
  sort(b.begin(),b.end(),greater());
  bool ok=false;
  int64_t sum=0,ans=0,s=0;
  while(s<n&&b.at(s)>a.at(0)&&sum<h){
    sum+=b.at(s);
    s++;
  }
  ans=s;
  ok=(sum>=h);
  if(!ok){
    h-=sum;
    ans+=h/a.at(0)+(h%a.at(0)!=0);
  }
  cout << ans << endl;
  return 0;
}
  

Measured memory_bytes: 4728
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

class Cell{
public:
  Cell(int number){data = number;};
  int getData(){return data;};
  Cell* getNext(){return next;};
  Cell* getBack(){return back;};
  void setNext(Cell* cell){next = cell;};
  void setBack(Cell* cell){back = cell;};
private:
  int data;
  Cell* next;
  Cell* back;
};

class DLinkedList{
 public:
  DLinkedList();
  void insertX(int x);
  void deleteX(int x);
  void deleteFirst();
  void deleteLast();
  void printDLinkedList();
 private:
  Cell* dummy;
};

DLinkedList::DLinkedList(){
  dummy = new Cell(-1);
  dummy->setNext(dummy);
  dummy->setBack(dummy);
}

void DLinkedList::insertX(int x){
  Cell* first = new Cell(x);

  first->setNext(dummy->getNext());
  if (first->getNext() == dummy) {
      dummy->setBack(first);
  }
  first->setBack(dummy);
  first->getNext()->setBack(first);
  dummy->setNext(first);
}


void DLinkedList::deleteX(int x){
  Cell* cell = dummy;
  while(1){
    cell = cell->getNext();
    if(cell == dummy)return;
    if(cell->getData() == x)break;
  }

  cell->getBack()->setNext(cell->getNext());
  cell->getNext()->setBack(cell->getBack());
  delete cell;
}

void DLinkedList::deleteFirst(){
  Cell* first = dummy->getNext();
  if(first == dummy)return;

  dummy->setNext(first->getNext());
  first->getNext()->setBack(dummy);

  delete first;
}

void DLinkedList::deleteLast(){
  Cell* cell = dummy->getBack();
  if(cell == dummy)return;

  cell->getBack()->setNext(dummy);
  dummy->setBack(cell->getBack());

  delete cell;
}

void DLinkedList::printDLinkedList(){
  Cell* cell = dummy;
  if(dummy->getNext() == dummy)return;

  while(1){
    cell = cell->getNext();
    if(cell->getNext() == dummy) break;

    printf("%d ", cell->getData());
    // cout << cell->getData() << " ";
  }
  cout << cell->getData() << endl;
}
int main()
{
  int n;
  cin >> n;

  string command;
  int number;
  DLinkedList* dll = new DLinkedList();
  for(int i=0;i<n;i++){
    cin >> command;
    if(command == "insert"){
      cin >> number;
      dll->insertX(number);
    }else if(command == "delete"){
      cin >> number;
      dll->deleteX(number);
    }else if(command == "deleteFirst"){
      dll->deleteFirst();
    }else{
      dll->deleteLast();
    }
  }

  dll->printDLinkedList();

  return 0;
}

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

int H, W, N;

int main(){
  cin >> H >> W >> N;
  vector<vector<int> > col(H, vector<int>(W, 0));
  
  int h = 0, w = 0;
  bool r = true;
  for(int i = 1; i <= N; i++){
    int a; cin >> a;
    for(int j = 1; j <= a; j++){
      col[h][w] = i;
      if( ((w == W-1) && r) || ((w == 0) && !r) ){
        h++; r = !r;
      }
      else {
        if(r) w++;
        else w--;
      }
    }
  }
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cout << col[i][j] << ' ';
    }
    cout << endl;
  }
  
}

Measured memory_bytes: 384
s = input()
first = int(s[:2])
second = int(s[2:])
if 1 <= first <= 12:
  if 1 <= second <= 12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if 1 <= second <= 12:
    print('YYMM')
  else:
    print('NA')

Measured memory_bytes: 2940
/*
TEMPLATE
by.YXH_XianYu
   2018.7.21
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LLI long long
#define DBL double
#define CHR char
#define BOL bool
#define REG register
#define rep(i, j, k) for(int i = j, lim = k; i <= lim; i++)
#define req(i, j, k) for(int i = j, lim = k; i >= lim; i--)
#define MXN 3005

int n,
	a[MXN];

int main() {
	//freopen("TEMPLATE.in", "r", stdin);
	//freopen("TEMPLATE.out", "w", stdout);
	
	scanf("%d", &n);
	rep(i, 1, n)
		scanf("%d", &a[i]);
	int ans = 0;
	rep(i, 1, n)
		ans += a[i]-1;
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

ll m[26];

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

    ll N;
    string S;
    cin >> N >> S ;

    rep(i, S.size()){
        m[S[i]-'a'] ++;
    }
    ll ans = 1;
    rep(i, 26){
        ans *= (m[i] + 1);
        ans %= MOD;
    }
    ans --;
    cout << ans << endl;


    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int f(int x){
	int res = 0;
	while(x%2 == 0){
		x /= 2;
		res++;
	}
	return res;
}

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

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return a / g * b;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	rep(i,n){
		cin >> a[i];
		a[i] /= 2;
	}
	int t = f(a[0]);
	rep(i,n){
		if(f(a[i]) != t){
			cout << 0 << endl;
			return 0;
		}
		a[i] >>= t;
	}
	m >>= t;
	ll l = 1;
	rep(i,n){
		l = lcm(l, a[i]);
		if(l > m){
			cout << 0 << endl;
			return 0;
		}
	}
	m /= l;
	int ans = (m+1)/2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include <stdio.h>
#include<string>
using namespace std;
int a,b;
char c;
int main() {
	cin >> a;
	while (cin >> c) {
		if (c == '=')cout << a << endl;
		else if (c=='+')
		{
			cin >> b; a = a + b;
		}
		else if (c=='-')
		{
			cin >> b; a = a - b;
		}
		else if (c == '*')
		{
			cin >> b; a = a * b;
		}
		else 

		{
			cin >> b; a = a / b;
		}
	}

	return 0;
}


Measured memory_bytes: 3052
use std::io;
use std::io::Read;

fn main() {
    loop {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();

        let H: i32 = iter.next().unwrap().parse().unwrap();
        let W: i32 = iter.next().unwrap().parse().unwrap();

        if H == 0 && W == 0 {
            break;
        }

        for _ in 0..W {
            print!("#");
        }
        println!("");
        for _ in 0..H-2 {
            print!("#");
            for _ in 0..W-2 {
                print!(".");
            }
            println!("#");
        }
        for _ in 0..W {
            print!("#");
        }
        println!("\n");
    }
}


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


int main() {
	double n,k;
	cin>>n>>k;
	double ans=0;
	for(int i=1;i<=n;i++ ){
		ll cnt =i;
		double p=1/n;
		while(cnt <k){
			cnt*=2;
			p/=2;
		}
		ans+=p;
	}
	printf("%.10f",ans);
	return 0;
}

Measured memory_bytes: 256
n =int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")

an = 0
for i in range(n-2):
	for j in range(i+1,n-1):
		k = 2*j-i
		if k>=n:
			continue
		else:
			if s[i] != s[j] and s[k] != s[j] and s[k] != s[i]:
				an+=1


print(r*g*b-an)

Measured memory_bytes: 9208
n,k=map(int,input().split())
s=[]
count=0
for i in range(n+1):
  count+=i
  s.append(count)

t=[n]
tmp=n
for i in range(1,n+1):
  tmp-=1
  t.append(t[i-1]+tmp)
# print(t)

ans=0
for i in range(k-1,n+1):
  ans+=t[i]-s[i]+1
  ans%=(10**9+7)

print(ans)

Measured memory_bytes: 83280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) (int)((a).size())
typedef long long ll;
typedef pair<int,int> PI;

vector<PI> ed[11000];

vector<int> G[510];
int low[510];
int num[510];
int lownum;
bool isart[510];

void lowdfs(int v){
  num[v] = low[v] = lownum++;
  
  for(auto e : G[v]){
    if(low[e] == -1){
      lowdfs(e);
      low[v] = min(low[v], low[e]);
      isart[v] |=
        (num[v]==0 && num[e] != 1)||
        (num[v]!=0 && low[e] >= num[v]);
    }else low[v] = min(low[v], num[e]);
  }
}

void visit(int v,int u,vector<PI>&brdg,stack<int>&roots,stack<int>&S,vector<bool>&inS,
           vector<int>&num,int&time){
  num[v] = ++time;
  S.push(v);
  inS[v]=true;
  roots.push(v);
  for(auto e : G[v]){
    int w = e;
    if(num[w] == 0)
      visit(w,v,brdg,roots,S,inS,num,time);
    else if(u != w && inS[w])
      while(num[roots.top()] > num[w]) roots.pop();
  }

  if(v == roots.top()){
    brdg.push_back(mp(u,v));
    while(1){
      int w = S.top();S.pop();inS[w] = false;
      if(v==w) break;
    }
    roots.pop();
  }
}

vector<PI> bridge(){
  vector<int> num(510);
  vector<bool> inS(510);
  stack<int> roots,S;
  int time = 0;
  vector<PI> brd;
  
  rep(u,510) if(num[u]==0){
    visit(u,500,brd,roots,S,inS,num,time);
    brd.pop_back();
  }
  return brd;
}

int un[510];
int find(int x){
  if(un[x] == x) return x;
  return un[x] = find(un[x]);
}

void unit(int a,int b){
  un[find(a)] = find(b);
}


int solve(int cc){
  if(ed[cc].empty()) return 0;
  lownum = 0;
  //rep(i,500) G[i].clear();
  set<PI> ap;
  for(auto e : ed[cc]){
    G[e.F].pb(e.S);
    G[e.S].pb(e.F);
    ap.insert(e);
    ap.insert(mp(e.S,e.F));
  }
  
  // rep(i,500) low[i] = -1;
  // rep(i,500) isart[i] = 0;
  // rep(i,500){
  //   if(low[i] == -1) lowdfs(i);
  // }
  auto br = bridge();
  int ou = 0;
  for(auto e : br){
    
    ou += find(e.F) != find(e.S) &&
      ap.count(mp(e.F,e.S));
  }
  
  //cout << ou << " " << br.size() << endl;
  return ou;
  return br.size();
  // vector<PI> ed = bridge();
  


  // // rep(i,4) cout << isart[i] << " ";
  // // cout << endl;
  
  // for(auto e : ed[cc])
  //   use += isart[e.F] && isart[e.S];
  
  // return use;
}

int main(int argc, char *argv[])
{
  int n,m;
  cin >> n >> m;
  rep(i,n) un[i] = i;
  rep(i,m){
    int a,b,c;

    cin >> a >> b >> c;
    --a,--b;
    ed[c].pb(mp(a,b));
  }
  
  int ans = 0;
  ll acost = 0;
  for(int i = 1; i <= 10000;++i){
    int nu = solve(i);
    for(auto e : ed[i]) unit(e.F,e.S);
    ans += nu;
    acost += nu*i;
  }
  
  cout << ans << " " << acost << endl;
}

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

int main(void){
    int n,m;
    cin>>n;
    cin>>m;
    int in,out;
    int Smax=0;
    bool error = false;
    for(int i=0;i<n;i++){
      cin>>in>>out;
      Smax = max(Smax,m);
      m+=in;
      m-=out;
      if(m<0){
        error = true;
      }
    }
    Smax = max(Smax,m);
    if(error){
      cout<<0<<endl;
    }
    else{
      cout<<Smax<<endl;
    }
    return 0;
}



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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

ll dp[1000010][2];

int main()
{
    string s; cin >> s;
    ll n = s.size();
    dp[0][0] = 1;
    rep(i,n){
        rep(j,2){
            int nd = s[i] - '0';
            if(j == 0){
                if(nd == 0) dp[i+1][j] += dp[i][j];
                else{
                    dp[i+1][1] += dp[i][j];
                    dp[i+1][0] += 2*dp[i][j];
                }
            }else{
                dp[i+1][j] += 3*dp[i][j];
            }
            dp[i+1][j] %= mod;
        }
    }
    cout << (dp[n][0]%mod + dp[n][1]%mod)%mod << endl;
}


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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    int a;
    string s;
    cin >>a >> s;
    cout << ((a>=3200) ? s : "red") <<endl;
    return (0);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main() {
    int n, k;
    cin >> n >> k;
    int sum = 0;
    for(int i=0; i<n; i++) {
        int x;
        cin >> x;
        sum += 2 * min(x, k-x);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256