akhauriyash/Code-Regression huggingface dataset:
import Control.Monad (replicateM_,forM_)
import Data.Bits (xor)
import Data.Array (Array,listArray,elems,(!))
import qualified Data.Array.IO as IOArr

type Row = Int
type Column = Int
type Table = Array Int Int

main = do
    [nr,nc] <- getLine >>= (return . map read . words)
    if all (==0) [nr,nc] then return () else do
        nums <- IOArr.newArray (1,nc) 0 :: IO (IOArr.IOArray Int Int)
        replicateM_ nr (getLine >>= update nums . map read . words)
        nums <- IOArr.freeze nums
        print $ solve nr nums
        main

    where
    update nums bs = forM_ (zip [1..] bs) update'
        where
        update' :: (Int,Int) -> IO ()
        update' (i,b) = do
            num <- IOArr.readArray nums i
            IOArr.writeArray nums i (2*num+b)

solve :: Int -> Table -> Int
solve nr nums = mbcs `seq` maximum $ map (countWith mbcs) [0..2^nr-1]
    where
    mbcs = maxBitCounts nr
    countWith mbcs i = sum $ map (\num -> mbcs ! (num `xor` i)) (elems nums)

maxBitCounts :: Int -> Array Int Int
maxBitCounts nr = listArray (0,2^nr-1) (map maxBitCount [0..2^nr-1])
    where
    maxBitCount n = bc `seq` max bc (nr - bc)
        where
        bc = bitCount n

    bitCount 0 = 0
    bitCount n = (n `mod` 2) + bitCount (n `div` 2)

Measured memory_bytes: 20600
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[102];
long long dfs(int l, int r, int xl, int xr) {
    if (l + 1 >= r) return 0;
    long long rt = 1e18;
    for (int i = l + 1; i <= r - 1; ++i)
        rt = min(rt, dfs(l, i, xl, xl + xr) + dfs(i, r, xl + xr, xr) +
                         a[i] * (xl + xr));
    return rt;
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    printf("%lld\n", a[1] + a[n] + dfs(1, n, 1, 1));
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int H = sc.nextInt();
		int M = sc.nextInt();
		sc.close();
		// 1周のうちH時間でどれくらい進んだか 
		double h = (double)H / 12.0;
		h += (double)M / 60.0 / 12.0; // 分針
		// 1周のうちM分でどれくらい進んだか
		double m = (double)M / 60.0;
		// 角度
		double rad = Math.PI * 2 * (h - m);
		// System.out.println(rad);
		// 辺の長さ
		double rsq = (A * A) + (B * B) - (2 * A * B * Math.cos(rad));
		System.out.println(Math.sqrt(rsq));
	}
}


Measured memory_bytes: 27108
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(n);
    vi num(n+1), cnt(n+1, 1);
    rep(i, n+1) { num[i] = i; }

    Rep(i, n+1) {
        if (num[i] != 1) {
            int tmp = num[i];
            for (int j = 1; j * tmp <= n; j++) {
                if (!(num[tmp*j] % tmp)) {
                    cnt[tmp]++;
                    num[tmp*j] /= tmp;
                }
            }
        }
    }
    int ans = 1;
    Rep(i, n+1) {
        ans *= cnt[i];
        ans %= MOD;
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
while 1:
  h,w = map(int, raw_input().split())
  if h==w==0: break
  H = range(h)
  C = [0]*(h+1)
  M = C[:]
  a=[0]*w
  for i in H:
    x = raw_input()
    b=[0]*w
    sp=-1
    C = [-1]*(h+1)
    for j in range(w):
      if x[j]=="*":
        c=0
      elif x[j]==".":
        c=a[j]+1
      b[j]=c
      if c>sp:
        C[sp+1:c+1]=[j]*(c-sp)
      elif c<sp:
        for k in range(c+1,sp+1):
          M[k]=max(M[k],j-C[k])
          C[k]=-1
      sp=c
    for k in range(1,sp+1):
      if C[k]>=0:
        M[k]=max(M[k],w-C[k])
    a=b[:]
  s=max([a*b for a,b in zip(M,range(h+1))])
  print s

Measured memory_bytes: 4300
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b;
    cin>> a>>b;
    if(b==100){
    for(int i=1;i<1000;i*=10){
        int c=0;
        c=a/i%10*1000*i;
       b+=c;
      }
    }
    else if(9<b&&b<100){
        for(int i=1;i<1000;i*=10){
            int c=0;
            c=a/i%10*100*i;
            b+=c;
        }
    }
    else if(1<=b&&b<10){
        for(int i=1;i<1000;i*=10){
            int c=0;
            c=a/i%10*10*i;
            b+=c;
        }
    }
    for(int i=1;i<350;i++){
        if(i*i==b){
            cout << "Yes" <<endl;
            return 0;
        }
    }
    cout << "No"  <<endl;

}

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

if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    a1 = B - 1
    a2 = N - A
    a3 = (B - (A + 1)) // 2 + A
    a4 = (B - (A + 1)) // 2 + N - B + 1
    print(min(a1, a2, a3, a4))

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//printfを使うときは上を削除
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	

//宣言だけしとく
int N,M,H,W,K,A,B;
string S;
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout << setprecision(10);
	cin >> S;
	int ans = 6;
	if(S =="SUN"){
		ans =7 ;
	}else if(S == "MON") ans= 6;
	else if(S == "TUE") ans= 5;
	else if (S =="WED") ans =4;
	else if(S == "THU" ) ans = 3;
	else if(S == "FRI") ans = 2;
	else ans = 1;
	cout << ans << endl;
		
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;


int main(){
  int N; cin >> N;
  int score = 0;
  vi s(N);
  rep(i,N) {cin >> s[i]; score+= s[i];}
  if(score%10 != 0) { cout << score << endl; return 0;}
  sort(all(s));
  rep(i,N){
    int sscore = score - s[i];
    if(sscore%10 != 0) { cout << sscore << endl; return 0;}
  }
  
  cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 3620
import itertools
N = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

s = []
for i in range(N):
  s.append(i+1)
p_list = list(itertools.permutations(s))

p_n = 0
q_n = 0
for i in range(len(p_list)):
  if p == p_list[i]:
    p_n = i
  if q == p_list[i]:
    q_n = i
    
print(p_n - q_n) if p_n >= q_n else print(q_n - p_n)



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

using namespace std;

typedef long long ll;

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

	int mx = 0;
	map<string, int> mp;
	
	int n;
	cin >> n;

	rep(i, n){
		string s;
		cin >> s;

		if(mp.count(s) == 0) mp[s] = 0;
		mp[s]++;
		mx = max(mx, mp[s]);
	}

	vector<string> ans;
	for(auto p : mp){
		if(p.second == mx) ans.push_back(p.first);
	}
	
	sort(ans.begin(), ans.end());
	for(string s : ans){
		cout << s << endl;
	}
}


Measured memory_bytes: 25584
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e5 +7;

#include <math.h>
#define PI 3.14159265358979323846264338327950L



int main() {
    int s, w;
    cin >> s >> w;

    if (w >= s) {
        cout << "unsafe";
    }
    else {
        cout << "safe";
    }

    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

    public Main() {
    }

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

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int cnt = 0;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j <= B; j++) {
                if (X - 500 * i - 100 * j >= 0 && X - 500 * i - 100 * j <= 50 * C) {
                    cnt++;
                }
            }
        }
        System.out.println(cnt);

    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main() {
    int N; cin >> N;
    vei a(N);
    ll hiku  = 1;
    ll sum = 1;
    rep(i,N) {
      cin >> a[i];
      sum *= 3;
      if(a[i] % 2 == 0) hiku *= 2;
    }
    cout << sum - hiku << endl;
    return 0;

    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define txt freopen("ip.txt", "r", stdin); freopen("op.txt", "w", stdout)
#define a3 INT_MAX
#define i3 INT_MIN
#define a6 INT64_MAX
#define i6 INT64_MIN
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define div2(a) (!(a&1))
#define deb(x) cout<<(#x)<<" "<<(x)<<"\n";
#define newl cout<<"\n" 
#define all(s) s.begin(),s.end()
#define pi 3.14159265358979323846
#define mod 1000000007
#define fp(x) fixed<<setprecision(x)<<
template<class T>
int digit(T a)
{
    vector<long long> dig = {
        0,
        9,
        99,
        999,
        9999,
        99999,
        999999,
        9999999,
        99999999,
        999999999,
        9999999999,
        99999999999,
        999999999999,
        9999999999999,
        99999999999999,
        999999999999999,
        9999999999999999,
        99999999999999999,
        999999999999999999,
        INT64_MAX};
    auto it = lower_bound(dig.begin(), dig.end(), a);
    int idx = (it - dig.begin());
    return idx;
}
template<class T>
int sumAllInts(T n){
    int a = 1;
    int su = 0;
    while(n){
        su += n%10;
        n/=10;
    }
    return su;
}
template<class T>
void split(char c,T s){
    int n = s.size();
    int i = 0;
    while ((cout<<s[i],i+=1) && (i<n) && (cout<<c<<' '));
}
void solve(){
    
   ll a,b,c,d; cin>>a>>b>>c>>d;
   ll p = a*c;
   ll q = b*d;
   ll r = a*d;
   ll s = b*c;
   cout<<max(p,max(q,max(r,s)));
    
}
int main(){
    quickie;
    //txt;
    int t= 1;
    while(t--){
        solve(); 
        newl; 
    } 
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int N, A[100000]; cin >> N;
  REP(i, N) cin >> A[i];
  int ans = 0, sum = 0;
  REP(i, N){
    if(A[i]!=0) sum += A[i];
    else{
      ans += sum/2;
      sum = 0;
    }
  }
  ans += sum/2;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using ll = long long;
using namespace std;

int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	ll d = n / (a + b);
	ll ans = 0;
	ans += a * d;
	ll r = n % (a + b);
	if(r > a){
		ans += a;
	}else{
		ans += r;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3184
#include <iostream>
using namespace std;
 
bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p%i == 0) return false;
	}
	return true;
}
 
int n;
 
int main() {
	cin >> n;
	for (int i = 31; i <= 55555; i += 30) {
		if (isprime(i) == true) {
			if (i != 31) cout << " ";
			cout << i; n--;
		}
		if (n == 0) break;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
from operator import mul
from functools import reduce

def cmb(n, r):
  if n < r:
    return 0
  r = min(n - r, r)
  if r == 0:
    return 1
  numer = reduce(mul, range(n, n - r, -1))
  denom = reduce(mul, range(1, r + 1))
  return (numer // denom) % (10 ** 9 + 7)

N,K = map(int,input().split())
MOD = 10**9+7
for i in range(1, K+1):
  print(cmb(K-1,i-1)%MOD * cmb(N-K+1, i)%MOD % MOD)

Measured memory_bytes: 47068
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
using namespace std;

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; }

const long long INF = 1LL << 60;

int main()
{
	long long N;
	cin >> N;
	int res = 100000;
	for (int i = 1;i <= sqrt(N);i++) {
		if (N%i == 0) {
			long long A = i;
			long long B = N / A;
			int digita = 0;
			while (A != 0) {
				 A/= 10;
				digita++;
			}
			int digitb = 0;
			while (B != 0) {
				B /= 10;
				digitb++;
			}
			int F = max(digita, digitb);
			chmin(res, F);
		}
	}

	cout << res << endl;
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int n, b;
	ll ans = 0;
	vector<int> a;
	cin >> n;
	rep(i, n){
		int t;
		cin >> t;
		a.push_back(t - i);
	}
	sort(all(a));
	if(n % 2 == 0) b = (a[n / 2] + a[n / 2 - 1]) / 2;
	else b = a[n / 2];
	rep(i, n) ans += abs(a[i] - b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;


int main(void) {
    int n, i, j, k, l, t[1003][1003] = {};

    cin >> n;

    for (i = 1; i <= n; i++) {
        if (i * (i + 1) / 2 == n) {
            break;
        }
        if (i * (i + 1) / 2 > n) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    k = i;

    i = 1;
    l = 1;
    while (i <= n) {
        for (j = 0; j < l; j++) {
            t[l - 1][j] = i++;
        }
        l++;
    }

    l--;

    int di, dj, pi, pj;
    vector<int> ans[1003];
    for (i = 0; i < l; i++) {
        di = 0;
        dj = 1;
        pi = i;
        pj = 0;
        for (j = 0; j < l; j++) {
            ans[i].push_back(t[pi][pj]);
            if (i == j) {
                di = 1;
                dj = 0;
            }
            pi += di;
            pj += dj;
        }
    }

    cout << l + 1 << endl;

    for (i = 0; i < l; i++) {
        cout << l << ' ';
        for (j = 0; j < l; j++) {
            cout << ans[i][j] << ' ';
        }
        cout << endl;
    }

    cout << l << ' ';
    for (i = 0; i < l; i++) {
        cout << t[i][i] << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int  n;
	cin >> n;
	
	for(int i=0; i<n; i++){
		char s;
		cin >> s;
		if(s=='Y'){
			cout << "Four" << endl;
			return 0;
		}
	}
	
	cout << "Three" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e5;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string x,a,b,c,d;
int len;
bool test(int pos,string y)
{
    if(pos+y.length()-1>=len)
        return 0;
    for(int i=0; i<y.length(); i++)
        if(x[pos+i]!=y[i])
            return 0;
    return 1;
}
void recur(int pos)
{
    if(pos==len)
    {
        cout<<"YES"<<endl;
        exit(0);
    }
    if(test(pos,a))
        recur(pos+a.length());
    if(test(pos,b))
        recur(pos+b.length());
    if(test(pos,c))
        recur(pos+c.length());
    if(test(pos,d))
        recur(pos+d.length());
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    a="dream",b="erase",c="dreamer",d="eraser";
    cin>>x;
    len=x.length();
    recur(0);


    cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 5412
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

int main() {
  int a, b;
  scanf("%d %d", &a, &b);

  cout << (a * 3 + b) / 2 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NX = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        var (N, X) = (NX[0], NX[1]);

        var pCount = new long[51];
        var pbLength = new long[51];
        pCount[0] = 1;
        pbLength[0] = 1;
        for (int i = 1; i <= 50; i++)
        {
            pCount[i] = pCount[i - 1] * 2 + 1;
            pbLength[i] = pbLength[i - 1] * 2 + 3;
        }

        long func(long n, long x)
        {
            if(x < pbLength[n])
            {
                var a = 0L;

                x--;
                if (x <= 0)
                    return a;
                
                a += func(n - 1, x);
                x -= pbLength[n - 1];
                if (x <= 0)
                    return a;
                
                a++;
                x--;
                if (x <= 0)
                    return a;

                a += func(n - 1, x);

                return a;
            }
            else
            {
                return pCount[n];
            }
        }

        var ans = func(N, X);

        WriteLine(ans);
    }
}


Measured memory_bytes: 28108
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

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

int main()
{
	rep(i, 9){
		char name[16];
		int am, pm;
		scanf("%s%d%d\n", name, &am, &pm);
		printf("%s %d %d\n", name, am+pm, 200*am + 300*pm);
	}
	return 0;
}

Measured memory_bytes: 0
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX / 2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;


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

  int N; cin >> N;

  string ans = "No";
  FOR(i,1,10) {
    FOR(j,1,10) {
      if (i*j == N) ans = "Yes";      
    }
  }

  cout << ans << endl;

  return 0;
}

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

int main() {
	ios :: sync_with_stdio(0);

	string s; getline(cin, s);
	for(int i = 0; i < s.size(); i ++) {
		if(s.substr(i, 5) == "apple") {
			for(char c : string("peach"))
				s[i ++] = c;
			i --;
		} else if(s.substr(i, 5) == "peach") {
			for(char c : string("apple"))
				s[i ++] = c;
			i --;
		}
	}
	cout << s << '\n';

	return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a;
  cin >> a;
  int k;
  cin >> k;
  vector<int> z(a);
  int d=0;
  for(int i = 0;i<a;i++){
    cin >> z.at(i);
    d+=z.at(i);
  }
  
  vector<int> s;
  for(int i = 1;i<=sqrt(d);i++){
    if(d%i==0){s.push_back(i);
               s.push_back(d/i);}
  }
  sort(s.begin(),s.end());

    int t = 1;
  for(int i = 0;i<s.size();i++){
    int p=0;
    vector<int> x(a);
    for(int j = 0;j<a;j++){
      p+=z.at(j)%s.at(i);
    x.at(j)=z.at(j)%s.at(i);}
    
    sort(x.begin(),x.end());
    reverse(x.begin(),x.end());
    int y = p;
    p/=s.at(i);
    for(int j = 0;j<p;j++){
      y -= x.at(j);}
    if(y<=k)t=s.at(i);
  }
    cout << t << endl;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

ll mod_pow(ll x, ll n){
    ll v = 1;
    for(; n; x=x*x%mod, n>>=1)
        if(n & 1) v = v * x % mod;
    return v % mod;
}
ll mod_inv(ll x){
    return mod_pow(x, mod-2);
}

struct Factorial{
    vector<ll> fact;
    vector<ll> factinv;
    Factorial(int n){
        fact = vector<ll>(n+1);
        factinv = vector<ll>(n+1);
        fact[0] = 1;
        REP(i,1,n+1) fact[i] = fact[i-1] * i % mod;
        factinv[n] = mod_inv(fact[n]);
        RREP(i,1,n+1) factinv[i-1] = factinv[i] * i % mod;
    }
    ll comb(int n, int k){
        return fact[n] * factinv[n-k] % mod * factinv[k] % mod;
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    int n,k; cin >> n >> k;
    Factorial fact(n);
    ll ans = 0;
    rep(i,min(k+1,n)){
        ll cnt = fact.comb(n,i) * fact.comb(n-1, n-i-1);
        ans = (ans + cnt) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
n=int(input())
*c,=map(int,input().split())
c=sorted(c)[::-1]
mod=10**9+7
ans=0
for i,x in enumerate(c,1):
  d=i*pow(2,i-1,mod)
  if i>1:d-=(i-1)*pow(2,i-2,mod)
  d*=pow(2,n-i,mod)*x%mod
  ans+=d%mod
  ans%=mod
ans*=pow(2,n,mod)
print(ans%mod)

Measured memory_bytes: 106912
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import pi, ceil, floor
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    n = int(input())
    ans = 1
    now = 1
    for i in range(2, int(n ** 0.5) + 1):
        j = 1
        while i ** j <= n:
            now = i ** j
            j += 1
        ans = max(ans, now)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12468
k=int(input())
a=list(map(int,input().split()))
if k==1:
    print(0)
else:
    dp = [0] * k
    dp[1] = abs(a[0]-a[1])
    for i in range(2,k):
        dp[i]=min(
            dp[i-1]+abs(a[i]-a[i-1]),
            dp[i-2]+abs(a[i]-a[i-2])
        )
    print(dp[-1])


Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    cin >> N;
    long long res = 1e18;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    long long ans = 1;
    for(int i = 0; i < N; i++){
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < N; i++){
        if(res / A[i] < ans){
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
#define ll long long
#define INF 0x7fffffff
using namespace std;
const int N = 1e6+5;

int main() {
  	int x;
  	cin>>x;
  	if(x>=30) cout<<"Yes\n";
  	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3592
def solve1():
    import re

    s = input()
    pattern = re.compile("(A?KIHA?BA?RA?)")

    ret = pattern.findall(s)


    #print(ret)
    if ret is not None and len(ret) ==  1 and len(ret[0]) == len(s):
        ans = "YES"
    else:
        ans = "NO"

    print(ans)


def solve2():
    s = input()

    base = "AKIHABARA"
    candidates = set()

    def rec(str_, index):
        fpos = str_.find('A',index)

        if fpos == -1:
            return 

        t = str_[:fpos] + str_[fpos+1:]

        candidates.add(str_)
        candidates.add( t )
        rec(str_, fpos+1)
        rec(t , fpos+1)

    rec(base,0)

#    print(len(candidates),candidates)
    
    ans = "YES" if s in candidates else "NO"
    print(ans)

solve2()

Measured memory_bytes: 3064
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

n=int(input())
for _ in range(n):
  a,b,c,d=map(int,input().split())
  if a<b or a%b>c or b>d:
    print('No')
  else:
    if b==d:
      print('Yes')
    elif a%b+d==a:
      print('Yes')
    else:
      if c+gcd(b,d)>=b:
        print('Yes')
      else:
        print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 200100;

typedef long double ld;
const ld inf = 1e18;

struct chtDynamic {  
	struct line {
		ll m, b; ld x; 
		ll val; bool isQuery; 
		line(ll _m = 0, ll _b = 0) : 
			m(_m), b(_b), val(0), x(-inf), isQuery(false) {} 
		
		ll eval(ll x) const { return m * x + b;	}
		bool parallel(const line &l) const { return m == l.m; }
		ld intersect(const line &l) const {
			return parallel(l) ? inf : 1.0 * (l.b - b) / (m - l.m);
		}
		bool operator < (const line &l) const {
			if(l.isQuery) return x < l.val;
			else return m < l.m; 
		}
	};

	set<line> hull; 
	typedef set<line> :: iterator iter; 

	bool cPrev(iter it) { return it != hull.begin(); }
	bool cNext(iter it) { return it != hull.end() && next(it) != hull.end(); }

	bool bad(const line &l1, const line &l2, const line &l3) {
		return l1.intersect(l3) <= l1.intersect(l2); 
	}
	bool bad(iter it) {
		return cPrev(it) && cNext(it) && bad(*prev(it), *it, *next(it));
	}

	iter update(iter it) {
		if(!cPrev(it)) return it; 
		ld x = it -> intersect(*prev(it));
		line tmp(*it); tmp.x = x;
		it = hull.erase(it); 
		return hull.insert(it, tmp);
	}

	void addLine(ll m, ll b) { 
		line l(m, b); 
		iter it = hull.lower_bound(l); 
		if(it != hull.end() && l.parallel(*it)) {
			if(it -> b < b) it = hull.erase(it); 
			else return;
		}

		it = hull.insert(it, l); 
		if(bad(it)) return (void) hull.erase(it);

		while(cPrev(it) && bad(prev(it))) hull.erase(prev(it));
		while(cNext(it) && bad(next(it))) hull.erase(next(it));

		it = update(it);
		if(cPrev(it)) update(prev(it));
		if(cNext(it)) update(next(it));
	}

	ll query(ll x) const { 
		if(hull.empty()) return -inf;
		line q; q.val = x, q.isQuery = 1;
		iter it = --hull.lower_bound(q);
		return it -> eval(x);
	}
} ds;

ll n, c;
ll h[maxn];
ll dp[maxn];

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

	dp[1] = 0LL;
	ds.addLine(2*h[1], -(h[1]*h[1] + dp[1]));

	// dp[i] = min(dp[j] + (h[i] - h[j])^2 + C)
	// dp[i] = min(dp[j] + h[i]^2 - 2*h[i]*2[j] + h[j]^2 + C)
	// slope: -2*h[j], extra = h[j]^2 + dp[j] 

	for(int i=2;i<=n;i++) {
		ll curr = -ds.query(h[i]);
		dp[i] = curr + c + h[i] * h[i];

		ds.addLine(2*h[i], -(h[i]*h[i] + dp[i]));
	}

	cout<<dp[n]<<"\n";
}

Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
int ans[100010];
int sz[100010], fa[1000010];
int find(int x)
{
    if (fa[x] == -1)
        return x;
    return fa[x] = find(fa[x]);
}
vector<int> g[100010];
int main()
{
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int x, y;
    for (int i = 1; i <= n; i++)
    {
        fa[i] = -1;
        sz[i] = 1;
    }
    for (int i = 1; i <= m; i++)
    {
        scanf("%d%d", &x, &y);
        ans[x]--;
        ans[y]--;
        int fx = find(x), fy = find(y);
        if (fx == fy)
            continue;
        sz[fx] += sz[fy];
        sz[fy] = 0;
        fa[fy] = fx;
    }
    for (int i = 1; i <= k; i++)
    {
        scanf("%d%d", &x, &y);
        int fx = find(x), fy = find(y);
        if (fx == fy)
            ans[x]--, ans[y]--;
    }
    for (int i = 1; i <= n; i++)
    {
        ans[i] += (sz[find(i)] - 1);
        printf("%d%c", ans[i], i == n ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 6272
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := NewScanner(os.Stdin)
	S := sc.Next()
	s := strings.Split(S, "/")
	y, _ := strconv.Atoi(s[0])
	m, _ := strconv.Atoi(s[1])
	d, _ := strconv.Atoi(s[2])
	if y < 2019 {
		fmt.Println("Heisei")
		return
	}
	if y == 2019 && m < 4 {
		fmt.Println("Heisei")
		return
	}
	if y == 2019 && m == 4 && d <= 30 {
		fmt.Println("Heisei")
		return
	}
	fmt.Println("TBD")
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  vector<pair<int, int>> CB(M);
  REP(i, M) cin >> CB[i].second >> CB[i].first;
  sort(CB.rbegin(), CB.rend());
  int k = 0;
  for (auto e : CB) {
    while (k < N && e.second > 0 && A[k] < e.first) {
      A[k] = e.first;
      k++;
      e.second--;
    }
  }
  long long ans = 0;
  REP(i, N) ans += A[i];
  cout << ans << '\n';
}


Measured memory_bytes: 1408
n,m=map(int,input().split())
INF=float('inf')
G=[]
for _ in range(m):
  a,b,c=map(int,input().split())
  G.append([a-1,b-1,-c])

def bellmanFord(G,s):
  D=[INF for i in range(n)]
  D[s]=0
  for i in range(1,n):
    for x,y,z in G:
      D[y]=min(D[y],D[x]+z)
  ans=-D[n-1]
  for x,y,z in G:
    D[y]=min(D[y],D[x]+z)
  if ans!=-D[n-1]:
    return -1
  else:
    return -D[n-1]

ans=bellmanFord(G,0)
if ans==-1:
  print('inf')
else:
  print(ans)

Measured memory_bytes: 74864
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >> getContents >>= print . sum . map ( \[ l, r ] -> r - l + 1 ) . map ( map read . words ) . lines


Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, m;
vector<int> h;
vector< vector< int > > edg;
int main(void){
    cin >> n >> m;
    h.assign(n, 0);
    edg.assign(n, vector<int>());
    for(int i=0;i<n;i++) cin >> h[i];
    for(int i=0;i<m;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        bool flg = true;
        for(int x: edg[i]){
            if(h[x] >= h[i]){ flg = false; break;}
        }
        if(flg) ans++;
    }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  long long ans = 0;
  while (true)
  {
    long long tmp = 0;
    bool ok = false;
    for (int i = 0; i < N; i++)
    {
      tmp += a[i] / N;
      if (N <= a[i])
        ok = true;
    }
    if (!ok)
      break;
    ans += tmp;
    for (int i = 0; i < N; i++)
      a[i] = a[i] % N + tmp - a[i] / N;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8

# In[42]:


import numpy as np


# In[100]:


N = int(input())
A = list(map(int, input().split()))


# In[104]:


sorted_A = np.sort(np.array(A))


# In[106]:


while len(sorted_A) != 1:
    tmp = sorted_A[1:] % sorted_A[0]
    sorted_A = np.sort(np.append(sorted_A[0], tmp[np.nonzero(tmp)[0]]))
print(sorted_A[0])



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

const int MOD = 1E9 + 7;

const int NMAT[7][7] = {
	{1, 0, 0, 0, 0, 0, 0},
	{0, 1, 0, 0, 0, 0, 0},
	{0, 0, 1, -1, 0, 0, 0},
	{0, 0, 0, 10, 0, 0, 0},
	{0, 0, 0, 0, 1, -1, 0},
	{0, 0, 0, 0, 0, 10, 0},
	{0, 0, 0, 0, 0, 0, 1}
};

const int MMAT[7][7] = {
	{1, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 1, 0, 0},
	{0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 1, 0, 0},
	{0, 0, 0, 0, 0, 0, 1},
};

const int AMAT[7][7] = {
	{1, 0, 0, 0, -1, 0, 0},
	{0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 1}
};

struct mat {
	int d[7][7];
	mat () { for (int i = 0; i < 7; ++i) for (int j = 0; j < 7; ++j) d[i][j] = 0; }
	int *operator [] (int x) { return d[x]; }
	int const *operator [] (int x) const { return d[x]; }
};

mat operator * (const mat &a, const mat &b) {
	mat res;
	for (int i = 0; i < 7; ++i)
		for (int j = 0; j < 7; ++j)
			for (int k = 0; k < 7; ++k)
				res[i][j] = (res[i][j] + 1ll * a[i][k] * b[k][j]) % MOD;
	return res;
}

mat id () {
	mat res;
	for (int i = 0; i < 7; ++i)
		res[i][i] = 1;
	return res;
}

mat nmat[10], mmat, amat, smat;

void init () {
	for (int digit = 0; digit < 10; ++digit)
		for (int i = 0; i < 7; ++i)
			for (int j = 0; j < 7; ++j)
				nmat[digit][i][j] = (NMAT[i][j] < 0) ? digit : NMAT[i][j];
	for (int i = 0; i < 7; ++i)
		for (int j = 0; j < 7; ++j)
			mmat[i][j] = MMAT[i][j];
	for (int i = 0; i < 7; ++i)
		for (int j = 0; j < 7; ++j)
			amat[i][j] = (AMAT[i][j] < 0) ? 1 : AMAT[i][j];
	for (int i = 0; i < 7; ++i)
		for (int j = 0; j < 7; ++j)
			smat[i][j] = (AMAT[i][j] < 0) ? MOD - 1 : AMAT[i][j];
}

int N;
int R[11000];
char S[11000][20];

int ans[7] = {0, 1, 0, 1, 0, 1, 1}, tmp[7];

int main () {
	init ();
	scanf ("%d", &N);
	for (int i = 0; i < N; ++i)
		scanf ("%d %s", &R[i], S[i]);
	for (int i = N - 1; i >= 0; --i) {
		mat mul = id (), ter = id ();
		for (int j = strlen (S[i]) - 1; j >= 0; --j) {
			if (S[i][j] >= '0' && S[i][j] <= '9') mul = nmat[S[i][j] - '0'] * mul;
			else if (S[i][j] == '*') mul = mmat * mul;
			else if (S[i][j] == '+') mul = amat * mul;
			else mul = smat * mul;
		}
		while (R[i]) {
			if (R[i] & 1) ter = mul * ter;
			mul = mul * mul;
			R[i] >>= 1;
		}
		for (int i = 0; i < 7; ++i) {
			tmp[i] = 0;
			for (int j = 0; j < 7; ++j)
				tmp[i] = (tmp[i] + 1ll * ans[j] * ter[i][j]) % MOD;
		}
		for (int i = 0; i < 7; ++i) ans[i] = tmp[i];
	}
	for (int i = 0; i < 7; ++i) {
		tmp[i] = 0;
		for (int j = 0; j < 7; ++j)
			tmp[i] = (tmp[i] + 1ll * ans[j] * amat[i][j]) % MOD;
	}
	for (int i = 0; i < 7; ++i) ans[i] = tmp[i];
	printf ("%d\n", ans[0]);
}

Measured memory_bytes: 3452
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

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

void solve(){
  int a, b;
  cin >> a >> b;
  if(a > b){
    cout << a-1 << endl;
  }else{
    cout << a << endl;
  }
}

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


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

int main( void )
{
    string a, b;
    while ( cin >> a >> b && a != "0" && b != "0" ) {
        int n = a.size();
        int H = 0, B = 0;
        bool used1[n], used2[n];
        fill( used1, used1+sizeof(used1), false );
        fill( used2, used2+sizeof(used2), false );

        for ( int i = 0; i < n; i++ ) {
            if ( a[i] == b[i] ) {
                H++;
                used1[i] = used2[i] = true;
            }
        }

        for ( int i = 0; i < n; i++ ) {
            if ( used1[i] ) continue;
            for ( int j = 0; j < n; j++ ) {
                if ( used2[j] ) continue;
                if ( a[i] == b[j] ) {
                    B++;
                    used1[i] = used2[j] = true;
                }
            }
        }

        cout << H << " " << B << endl;
    }
    return 0;
}

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

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    if(n > 9 || m > 9) cout << -1;
    else cout << n * m;

    return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

ll gcd(ll x,ll y){
  if(y==0)return x;
  if(x<=y) swap(x,y);
  if(x%y==0) return y;
  else return(gcd(y,x%y));//最大公約数
}

ll lcm(ll x,ll y){
  return (x/gcd(x,y))*y;//最小公倍数
}

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    //b以下a以上でcで割れる数
    ll num1 = b/c - (a-1)/c;
    //b以下a以上でdで割れる数
    ll num2 = b/d - (a-1)/d;
    //b以下a以上でcでもdでも割れる数
    ll num3 = b/lcm(c,d) - (a-1)/lcm(c,d);
    COUT((b-a+1)-num1-num2+num3);
    return 0;
} 

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

using namespace std;

int n, h[101], f[102], tmp[101];

int solve1() {
	int res = 0;
	for (int i = 1; i <= n; ++i)
		tmp[i] = h[i];
	while (true) {
		bool canContinue = false;
		for (int i = 1; i <= n; ++i)
			if (h[i])
				canContinue = true;
		if (!canContinue) break;
		for (int i = 1; i <= n;) {
			if (h[i] == 0) { ++i; continue; }
			int j = i + 1;
			while (j <= n && h[j] > 0) ++j;
			///seg[i, j - 1]
			int amin = 1e9 + 7;
			for (int z = i; z <= j - 1; ++z)
				amin = min(amin, h[z]);
			res += amin;
			for (int z = i; z <= j - 1; ++z)
				h[z] -= amin;
			i = j;
		}
	}
	for (int i = 1; i <= n; ++i)
		h[i] = tmp[i];
	return res;
}

int solve2() {
	int res = 0;
	f[1] = h[1];
	h[n + 1] = h[0] = 0;
	for (int i = 2; i <= n + 1; ++i)
		f[i] = h[i] - h[i - 1];
	for (int i = 1; i <= n + 1; ++i)
		if (f[i] < 0)
			res += f[i];
	return -res;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> h[i];
	cout << solve2();
	return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 0


int main(){

	string s,t;
	cin>>s>>t;
	if(s.size()<t.size()){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}

	lli pos=-1;
	for(lli i=0;i<=s.size()-t.size();i++){
		lli flag=0;
		for(lli j=0;j<t.size();j++){
			if(DEBUG)cout<<"i = "<<i<<" J= "<<j<<endl;
			if(s.at(i+j) == '?')continue;
			if(s.at(i+j) != t.at(j)){
				flag=1;
			}
		}
		if(flag==0){
			pos = i;
		}
	}
	if(pos == -1){
		cout<<"UNRESTORABLE"<<endl;
	}
	else{
		for(lli i=0;i<s.size();i++){
			if(s.at(i)=='?'){
				if(pos<=i && i< pos+t.size()){
					cout<<t.at(i-pos);
				}
				else cout<<"a";
			}
			else{
				cout<<s.at(i);
			}
		}
	}


	return 0;
}

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

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

using namespace std;

int main(){
	int n,v[20],c[20]; cin>>n;
	rep(i,n) cin>>v[i];
	rep(i,n) cin>>c[i];

	int ans=0;
	rep(i,n) if(v[i]>c[i]) ans+=v[i]-c[i];
	cout<<ans<<endl;

	return 0;
}


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

int main() {
  int X, Y;
  cin >> X >> Y;
  if (Y % 2 == 1 || Y < 2 * X || Y > 4 * X){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    string s;
    cin >> s;
    map<char, int> p;
    for(char i = 'a'; i <= 'z'; i++){
        p[i] = 0;
    }
    for(int i = 0; i < s.size(); i++){
        p[s[i]]++;
    }
    map<char, int>::iterator it;
    for(it=p.begin(); it!=p.end(); it++){
        if(it->second%2!=0){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

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



int main(){
  int N;
  cin>>N;
  vector<int> x(N),y(N);
  int ans=0;
  for(int i=0;i<N;i++){
    cin>>x[i];
  }
  for(int i=0;i<N;i++){
    cin>>y[i];
  }
  for(int i=0;i<N;i++){
    if(x[i]>y[i]) ans=ans+x[i]-y[i];
  }
  cout<<ans<<endl;
  return 0;
  
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, r;
    cin >> n >> r;
    if (n >= 10) {
        cout << r << endl;
    } else {
        cout << r + (100 * (10 - n)) << endl;
    }
    return 0;
}



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

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);

    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll temp1 = 0;

    temp1 = a*x + b * y;

    if (x < y) {
        swap(x, y);
        swap(a, b);
    }

    ll temp2 = 0;
    temp2 = x*2*c;

    ll temp3 = 0;
    ll temp4 = 0;
    ll temp5 = 0;
    temp3 = y*2*c + (x -y)*a;
    temp4 = y*2*c + (x-y)*2*c;
    temp5 = y*2*c + (x-y)*2*c;

    temp3 = min(temp3, temp4);

    cout << min(temp3,min(temp1, temp2));
    //cout << temp1 << endl;
    //cout << temp2 << endl;
    //cout << temp3 << endl;



    return 0;
}


Measured memory_bytes: 256