akhauriyash/Code-Regression huggingface dataset:
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};const isPrime=(n:number):boolean=>{if(n<2)return false;const suq=Math.sqrt(n);for(let i=2;i<=suq;i++){if(n%i==0){return false;}}return true;};
const main=()=>{
  to(tn()*500>=tn()?'Yes':'No')
}
main()


Measured memory_bytes: 7372
"use strict"
function main(arg) {
    var data = arg.trim().split("\n")
    var p = data[1].split(" ")
    var q = data[2].split(" ")
    var records = permutation(p, p.length)
    p = p.join("")
    q = q.join("")
    var pi,qi
    for (var i = 0; i < records.length; i++) {
        records[i] = records[i].join("")
    }
    records.sort()
    for (var i = 0; i < records.length; i++) {
        if (p == records[i]) {
            pi = i
        }
        if (q == records[i]) {
            qi = i
        }
    }
    console.log(Math.abs(pi - qi))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function permutation(nums, k) {
    var ans = []
    if (nums.length < k) {
        return []
    }
    if (k === 1) {
        for (var i = 0; i < nums.length; i++) {
            ans[i] = [nums[i]]
        }
    } else {
        for (var i = 0; i < nums.length; i++) {
            var parts = nums.slice(0)
            parts.splice(i, 1)[0]
            var row = permutation(parts, k - 1)
            for (var j = 0; j < row.length; j++) {
                ans.push([nums[i]].concat(row[j]))
            }
        }
    }
    return ans;
}

Measured memory_bytes: 47248
#include<bits/stdc++.h>
using namespace std;
int main()
{
   
    
    int t,i,j,sum,cnt,k=0,s;
      string s1,s2;
   cin>>s1;
    for(i=0;i<s1.size();i++){
     for(j=i+1;j<s1.size();j++){
        if(s1[i]==s1[j]){k=1;break;}
    }
  }
    if(k==0){cout<<"yes\n";}
    else{cout<<"no\n";}
  
            
        
    }

   



Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 1e7+10;
const int maxm = 210;

int p[4100000],pri;
bool v[maxn];

void pre()
{
	for(int i=2;i<maxn;i++)
	{
		if(!v[i]) p[++pri]=i;
		for(int j=1,k=i*p[j];j<=pri;j++,k=i*p[j])
		{
			if(k>=maxn) break;
			v[k]=true;
			if(i%p[j]==0) break;
		}
	}v[1]=v[2]=true;
}

int n,m;
int a[maxm],b[maxm];
bool s[maxn];
int p1[maxm],p2[maxm];
int p1n,p2n;

bool mp[maxm][maxm],ev[maxm];
int match[maxm],bel[maxm];
bool Find(const int x)
{
	if(ev[x]) return false;
	ev[x]=true;
	for(int i=1;i<=p2n;i++) if(mp[x][i])
	{
		if(!bel[i]||Find(bel[i])) { bel[i]=x; return true; }
	}
	return false;
}

int main()
{
	pre();
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),s[a[i]]=true;
	for(int i=1;i<maxn;i++)
		if(s[i]!=s[i-1]) b[++m]=i;
	
	for(int i=1;i<=m;i++)
	{
		if(b[i]&1) p1[++p1n]=b[i];
		else p2[++p2n]=b[i];
	}
	for(int i=1;i<=p1n;i++)
	{
		for(int j=1;j<=p2n;j++) if(!v[abs(p1[i]-p2[j])]) mp[i][j]=true;
	}
	int k=0;
	for(int i=1;i<=p1n;i++) if(!match[i])
	{
		for(int j=1;j<=p1n;j++) ev[j]=false;
		if(Find(i)) k++;
	}
	p1n-=k; p2n-=k;
	int re=k;
	re+=p1n/2*2+p2n/2*2;
	re+=p1n%2*3;
	printf("%d\n",re);
	
	return 0;
}


Measured memory_bytes: 20864
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<bool> used;

void dfs(vector<vector<int> > &g, int v = 0){
  used[v] = true;
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if(used[u])continue;
    dfs(g, u);
  }
}

int main(){
  int n, m;
  std::cin >> n >> m;
  vector<vector<int> > g(n + m);
  for (int i = 0; i < n; i++) {
    int k;
    std::cin >> k;
    for (int j = 0; j < k; j++) {
      int to;
      std::cin >> to;
      g[i].push_back(--to + n);
      g[to + n].push_back(i);
    }
  }
  used.resize(n + m, false);
  dfs(g);
  std::cout << (all_of(used.begin(), used.begin() + n,[](bool b){return b;})?"YES":"NO") << std::endl;
  return 0;
}


Measured memory_bytes: 8440
#data=list(input().split())
a,b,c,d=map(int,input().split())
def gcd(x , y):
    if y == 0:
        return x 
    else:
        return gcd(y, x%y)

def gys(a,b):
    remainder = gcd(a,b)
    return a*b//remainder

lcmm=gys(c,d)
def ans(n,k):
    return n//k
def x(s):
    return ans(s,c)+ans(s,d)-ans(s,lcmm)
#print(x(b),x(a))

print(b-a+1-x(b)+x(a-1))




Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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 main(){
	ll n,k;
	cin >> n >> k;
	
	const ll MOD = 1000000007;
	ll ans = 0;
	for(ll i=k; i<=n+1 ;i++){
		ll minimum = i*(i-1)/2;
		ll maximum = (2*n-i+1)*i/2;
		
		ans += maximum-minimum+1;
		ans %= MOD;
	}
	
	cout << ans << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define eni(x) template < class c > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; return * this; }
eni(==) return * this << range(begin(i), end(i)); }
template < class c, class b > debug & operator <<(pair < b, c > d) {
  return * this << "(" << d.first << ", " << d.second << ")";
}
template < class c > debug & operator <<(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  return * this << "]";
}
#else
template < class c > debug & operator <<(const c&) { return * this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

ll n;
ll fact[mx],inv[mx];

ll bigmod(ll a, ll p, ll m){
    ll res=1,x=a;
    while(p){
        if(p&1) res=(res*x)%m;
        x=(x*x)%m;
        p=p>>1;
    }
    return res;
}

void precalc(){
    fact[0]=1;
    for(int i=1;i<mx;i++) fact[i]=(fact[i-1]*i)%mod;
    inv[mx-1]=bigmod(fact[mx-2],mod-2,mod);
    for(int i=mx-2;i>=0;i--) inv[i]=(inv[i+1]*(i+1))%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    precalc();
    cin>>n;
    ll ans=bigmod(10,n,mod);
    ans=(ans+bigmod(8,n,mod))%mod;
    ll tmp=bigmod(9,n,mod);
    tmp=(tmp*2)%mod;
    ans=(ans-tmp)%mod;
    ans+=mod;
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 19280
import sys
from bisect import bisect_right

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def is_ok_m(x):
        cnt = 0
        for P in plus:
            t = x // P
            cnt += bisect_right(minus, t)
        return cnt >= k

    def is_ok_p(x):
        cnt = 0
        for i, P in enumerate(plus):
            t = x // P
            idx = bisect_right(plus, t)
            if i < idx:
                idx -= 1
            cnt += idx

        for i, M in enumerate(minus):
            t = x // M
            idx = bisect_right(minus, t)
            if i < idx:
                idx -= 1
            cnt += idx
        cnt //= 2
        return cnt >= k

    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    minus, plus = [], []
    z = 0
    for a in A:
        if a < 0:
            minus.append(a)
        elif a > 0:
            plus.append(a)
        else:
            z += 1
    m, p = len(minus), len(plus)

    m_cnt = m * p
    z_cnt = m * z + p * z + ((z - 1) * z) // 2
    if k <= m_cnt:
        minus.sort()
        ng, ok = -10 ** 18 - 1, -1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok_m(mid):
                ok = mid
            else:
                ng = mid
        res = ok
    elif k <= m_cnt + z_cnt:
        res = 0
    else:
        k -= m_cnt + z_cnt
        plus.sort()
        minus = [num * -1 for num in minus]
        minus.sort()
        ng, ok = -1, 10 ** 18
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok_p(mid):
                ok = mid
            else:
                ng = mid
        res = ok
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 118048
#pragma GCC optimize("O3")
#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 <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    string s; cin>>s;

    vector<vector<int>> sum(n+2, vector<int>(11, 0));

    for(int i=0; i<n; i++){
        for(int j=0; j<10; j++){
            if(s[i] - '0' == j){
                sum[i+1][j] = sum[i][j] + 1;
            }
            else{
                sum[i+1][j] = sum[i][j];
            }
        }
    }

    // mid
    set<int> ans;
    for(int i=1; i<n-1; i++){
        int cur = s[i] - '0';
        for(int j=0; j<10; j++){
            for(int k=0; k<10; k++){
                int l = sum[i][j];
                int r = sum[n][k] - sum[i+1][k];

                if(l != 0 && r != 0){
                    int num = j * 100 + cur * 10 + k;
                    ans.emplace(num);
                }
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    sort(RALL(a));
    if (n == 1) {
        cout << (a[0] % 2 ? "first" : "second") << endl;
    } else {
        bool f = false;
        REP(i, n) {
            f |= a[i] % 2;
        }
        cout << (f ? "first" : "second") << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1001001001;
vector<P> res;
int dp[3300][3300];
int dfs(int x,int time){
    //x個目までみて、time以下
    if(x == 0)return 0;
    if(dp[x][time] != -1)return dp[x][time];
    
    int ret = 0;
    ret = max(ret,dfs(x-1,time));
    if(time - res[x].first >= 0)ret  = max(ret,dfs(x-1,time - res[x].first) + res[x].second);
    return dp[x][time] = ret;

}
signed main(){
    int n,t;cin >> n >> t;
    res.resize(n+1);
    res[0] = P(-INF,-INF);
    rep(i,3300)rep(j,3300)dp[i][j] = -1;
    rep(i,n)cin >> res[i+1].first >> res[i+1].second;
    sort(res.begin(),res.end());
    int ret = 0;
    for(int i = 1;i <= n;i++){
        ret = max(ret,dfs(i-1,t-1) + res[i].second);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 88868
k,a,b=list(map(int, input().split()))

ans = 0
if a >= b:
    ans = 1+k
elif a+2 <= b:
    k=k-(a-1) #1の操作を行う
    if k%2==0:
        ans = a + (k//2)*(b-a)
    else:
        ans = a + (k//2)*(b-a) + 1
else:

    ans = 1+k


print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

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

	if (a == b){
		printf("%d\n", c);
	}else if(a == c){
		printf("%d\n", b);
	}else if(b == c){
		printf("%d\n", a);
	}else{
		printf("There is no same numbers\n");
	}
	return 0; 
}

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

using ll = long long;

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define FORR(i,a,b) for(int i=b-1;i>=a;i--)

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl

int f(int v, int x){
    return v * (100+x) / 100;
}

int main(){
    while(true){
        int x,y,s;
        cin>>x>>y>>s;
        if(x+y+s==0)break;
        int ans = 0;
        FOR(u,1,s){
            int u2 = f(u,x);
            if(u2>=s)continue;
            int v2 = s-u2;
            int v = -1;
            FOR(vv,1,s)if(f(vv,x)==v2)v=vv;
            if(v==-1)continue;
            ans = max(ans, f(u,y)+f(v,y));
            // DEBUG(u); DEBUG(u2);
            // DEBUG(v); DEBUG(v2);
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 3092
import sys, math
mod = 10**9+7
X, Y = map(int, input().split())
if X>Y:
    X, Y = Y, X
if (X+Y)%3 !=0:
    print(0)
    sys.exit()
n = (X+Y)//3
d = (Y-X)
if n<d or (n-d)%2 != 0:
    print(0)
    sys.exit()
a = (n-d)//2
def make_fact(n):#0~nの階乗を求める
    fact = [1]*(n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1]*i%mod
    return fact
fact = make_fact(n)  
def make_fact_inv(n):#0~nの階乗のmodに関する逆元を求める
    fact_inv = [1]*(n+1)
    fact_inv[n] = pow(fact[n], mod-2, mod)#フェルマーの小定理
    for i in range(n, 0, -1):
        fact_inv[i-1] = fact_inv[i]*i%mod
    return fact_inv
fact_inv = make_fact_inv(n)

def comb(n, k):#nCk
    return fact[n]*fact_inv[k]*fact_inv[n-k]%mod

print(comb(n, a))

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    if (d == 0) {
        cout << setprecision(20) << (m - 1) * n / (double)(n * n) << endl;
    } else {
        cout << setprecision(20) << (m - 1) * 2 * (n - d) / (double)(n * n)
             << endl;
    }
}

Measured memory_bytes: 256
object Main{
	def main(A:Array[String]){
		val s = new java.util.Scanner(System.in)
		val n,m,c=s.nextInt
		val b=Seq.fill(m)(s.nextInt)
		def f=Seq.tabulate(m)(o=>b(o)*s.nextInt).sum+c>0

		println(1 to n count(_=>f))
	}
}


Measured memory_bytes: 25800
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n;
	cin >> n;
	int a[n + 1];
	forr(i,n + 1) cin >> a[i];
	int b[n];
	forr(i,n) cin >> b[i];
	int ans = 0;
	for(int i = 0; i < n; i++){
		int take = min(a[i],b[i]);
		ans += take;
		a[i] -= take;
		b[i] -= take;
		take = min(a[i + 1], b[i]);
		ans += take;
		a[i + 1] -= take;
		b[i] -= take;
	}
	cout << ans;
}

Measured memory_bytes: 5216
from sys import stdin

str = stdin.readline().rstrip()
target = "keyence"
status = 0
for i in range(6):
    before = target[0:i+1]
    after =target[i+1:]
    bindex = str.find(before)
    if bindex > 0:
        if bindex == str.find("keyence"):
            status += 1
    elif bindex == 0:
        aindex = str.rfind(after)
        if aindex == (len(str) - len(after)):
            status += 1
        elif aindex == len(before):
            status += 1
if status == 0:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3064
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

class Main {
    final Scanner sc = new Scanner(System.in);
    Map<String, Integer> map = new LinkedHashMap<>();
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int n = sc.nextInt();
        IntStream.range(0, n).forEach(i -> {
            String str = sc.next();
            Integer val = map.get(str);
            if (val == null) {
                map.put(str, 1);
            } else {
                map.put(str, val.intValue()+1);
            }
        });
        int max = 0;
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            max = Math.max(entry.getValue(), max);
        }

        Set<String> set = new TreeSet<>();
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (entry.getValue() == max) set.add(entry.getKey());
        }
        set.forEach(System.out::println);
    }
}


Measured memory_bytes: 105148
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int a[15],b[15],c[15],d[10][10],f[10][10],n,w,h;
int fn(int p){
  int i,j,k,l,m;
  int ct=0;
  if(p==n){
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(d[j][i]==0)
	  break;
      }
      if(j!=w)
	break;
    }
    if(i==h){
      for(i=0;i<h;i++){
	for(j=0;j<w;j++)
	  f[j][i]=d[j][i];
      }
      ct=1;
    }
  }else{
    for(i=1;i<a[p]+1;i++){
      if(a[p]%i==0){
	for(j=0;j<i;j++){
	  if(b[p]-j>-1&&b[p]+i-j-1<w){
	    for(k=0;k<a[p]/i;k++){
	      if(c[p]-k>-1&&c[p]+a[p]/i-k-1<h){
		for(l=0;l<i;l++){
		  for(m=0;m<a[p]/i;m++){
		    if(d[b[p]-j+l][c[p]-k+m])
		      break;
		  }
		  if(m!=a[p]/i)
		    break;
		}
		if(l==i){
		  for(l=0;l<i;l++)
		    for(m=0;m<a[p]/i;m++)
		      d[b[p]-j+l][c[p]-k+m]=p+1;
		  ct+=fn(p+1);
		  for(l=0;l<i;l++)
		    for(m=0;m<a[p]/i;m++)
		      d[b[p]-j+l][c[p]-k+m]=0;
		  if(ct>1)
		    return ct;
		}
	      }
	    }
	  }
	}
      }
    }
  }
  return ct;
}
int main(){
  int i,j;
  while(cin>>w>>h>>n&&w+h+n){
    for(i=0;i<n;i++){
      int p,q;
      cin>>p>>q;
      p--;
      a[p]=q;
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	int p;
	cin>>p;
	if(p){
	  p--;
	  b[p]=j;
	  c[p]=i;
	}
      }
    }
    memset(d,0,sizeof(d));
    if(fn(0)==1){
      for(i=0;i<h;i++){
	for(j=0;j<w-1;j++)
	  cout<<f[j][i]<<" ";
	cout<<f[j][i]<<endl;
      }
    }else
      cout<<"NA"<<endl;
  }
  return 0;
}

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

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

  int d = a/b;
  int r = a%b;
  double f = (double)a/b;

  cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;
}



Measured memory_bytes: 3248
import sys , math

N,K=list(map(int, input().split()))
Ws=list(map(int, input().split()))
Ws.sort(reverse=True)

l=0
r=10**9

def check (m):
    now=0
    for i in range(N):
        now += (Ws[i] - 1) // m
    return now <= K

while r - l > 1:
    m = ( l + r ) // 2

    if check(m):
        r = m
    else:
        l = m
print(r) 

Measured memory_bytes: 103624
function main(arg) {
    
    let n = arg
    
    let sum=0
    for(let i=0; i < n.length; i++) {
        sum+=Number(n[i])
    }
    
    console.log(sum%9==0 ? "Yes" : "No")


}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  int c5, c7;
  c5 = 0;
  c7 = 0;
  
  if(a == 5) c5++;
  if(b == 5) c5++;
  if(c == 5) c5++;

  if(a == 7) c7++;
  if(b == 7) c7++;
  if(c == 7) c7++;
  
  if(c5 == 2 && c7 == 1) {
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}


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

int main() {
    int N,K,A,B,X,Ans;
    cin >> N >> K;
    Ans=0;
    A=0;
    B=0;
    for (int i=0; i<N; i++){
    cin >> X;
    A = 2 * X;
    B = 2 *(X - K);
      if (B<0){
        B*=-1;
      }
      if(A>=B){
        Ans+=B;
      }
      else{
        Ans+=A;
      }
    }
    cout << Ans << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.stream.Collectors;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E solver = new E();
        solver.solve(1, in, out);
        out.close();
    }

    static class E {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int[] a = in.Int(N);

            int[] ans = new int[N];
            int all = 0;
            for (int i = 0; i < N; i++) {
                all ^= a[i];
            }
            for (int i = 0; i < N; i++) {
                ans[i] = a[i] ^ all;
            }

            out.println(IntStream.of(ans).mapToObj(Integer::toString).collect(Collectors.joining(" ")));
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}



Measured memory_bytes: 69580
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <bitset>

using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	// Absolute
	template<class T> inline T abs(const T &a){ return (a>0) ? a : -a; }
	// GCD: a > b
	ul gcd(ul a,ul b) { return (!b) ? a : gcd(b,a%b); }
}

int main(int argc,char *argv[])
{
	ll n;
	std::cin >> n;

	std::vector<ll> p(n,0);
	for(ll i = 0;i < n;++i) std::cin >> p[i];

	ll ans = 0;
	ll min = p[0];
	for(ll i = 0;i < n;++i)
	{
		if(min >= p[i])
		{
			++ans;
			min = p[i];
		}
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>
#include <math.h>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 998244353;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector <ll> a(n);
    REP(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    ll res1 = 0;
    ll res2 = 0;
    
    // パターン p1 ≥ p2 ≤ p3 ≥ ...
    ll right = a.size() - 1;
    ll left = 0;
    ll i = 0;
    while(right >= left)
    {
        if(i % 2 == 0)
        {
            //大きいものを2回足す
            res1 += 2 * a[right];
            --right;
        }
        else
        {
            //小さいものを2回ひかれる(0i0)
            res1 -= 2 * a[left];
            ++left;
        }
        ++i;
    }

    //全部2回ずつ足し引きしちゃってるので帳尻合わせ
    ll center = a.size() / 2;
    if(n % 2 == 0)
    {
        res1 -= a[center];//i%2 == 0の方
        res1 += a[center - 1];//i%2 == 1の方
    }
    else
    {
        //
        res1 -= a[center];
        res1 -= a[center + 1];//right側で*2しちゃっている
    }

    //パターンp1 ≤ p2 ≥ p3 ...
    right = a.size() - 1;
    left = 0;
    i = 0;
    while(right >= left)
    {
        if(i % 2 == 0)
        {
            //小さいものを2回ひかれる(0i0)
            res2 -= 2 * a[left];
            ++left;
        }
        else
        {
            //大きいものを2回足す
            res2 += 2 * a[right];
            --right;
        }
        ++i;
    }
    //全部2回ずつ足し引きしちゃってるので帳尻合わせ
    if(n % 2 == 0)
    {
        res2 -= a[center];//i%2 == 1の方
        res2 += a[center - 1];//i%2 == 0の方
    }
    else
    {
        res2 += a[center];
        res2 += a[center - 1];//left側で*2しちゃっている
    }

    cout << max(res1, res2) << endl;

    return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(1000000000)
n=int(input())
al=[chr(ord('a') + i) for i in range(15)]
def dfs(c,i):
    if i==n:
        print(c)
        return
    p=0
    for k in c:
        p=max(p,ord(k))
    for k in range(p-ord('a')+2):
        dfs(c+al[k],i+1)
dfs("a",1)

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

#define INF 1145141919
typedef pair<int, int> P;
typedef pair<int, P> P2;

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

int R;
int M[500][500];
bool V[500][500];

int main() {
  while (cin >> R) {
    if (R == 0) break;
    vector<P> S[2];

    for (int k=0; k<=1; k++) {
      S[k%2].push_back(P(0, 0));

      int w, h, x, y;
      cin >> w >> h >> x >> y;
      x--, y--;
      for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
          cin >> M[j][i];
        }
      }
      for (int i=0; i<w; i++) {
        for (int j=0; j<h; j++) {
          V[i][j] = false;
        }
      }
      priority_queue< P2, vector<P2>, greater<P2> > q;
      V[x][y] = true;
      q.push(P2(M[x][y], P(x, y)));
      int c = -1;

      while (!q.empty()) {
        int r = q.top().first,
            sx = q.top().second.first,
            sy = q.top().second.second; q.pop();
        P last = S[k%2][S[k%2].size()-1];
        if (c == r) {
          S[k%2][S[k%2].size()-1] = P(last.first + 1, r);
        }
        else {
          S[k%2].push_back(P(last.first + 1, r));
          c = r;
        }

        for (int i=0; i<4; i++) {
          int tx = sx + DX[i], ty = sy + DY[i];
          if (tx < 0 || tx >= w || ty < 0 || ty >= h) continue;
          int g = max(r, M[tx][ty]);
          if (!V[tx][ty]) {
            V[tx][ty] = true;
            q.push(P2(g, P(tx, ty)));
          }
        }
      }
      S[k%2].push_back(P(INF, INF));
    }
    int m = INF;
    for (auto x : S[0]) {
      int r = max(0, R - x.first);
      auto it = lower_bound(S[1].begin(), S[1].end(), P(r, 0));
      P y = *it;
      m = min(m, x.second + y.second);
    }
    cout << m << "\n";
  }
  return 0;
}

Measured memory_bytes: 6920
func gcd(x: Int, _ y: Int) -> Int {
    return y>0 ? gcd(y, x%y) : x
}
let N = Int(readLine()!)!
let A = readLine()!.characters.split(" ").map{Int(String($0))!}
var L = [0]
var R = [0]
for i in 0..<N {
    L += [gcd(L[i], A[i])]
    R += [gcd(R[i], A[N-i-1])]
}
var ans = 0
for i in 0..<N {
    ans = max(ans, gcd(L[i], R[N-i-1]))
}
print(ans)

Measured memory_bytes: 7628
import itertools
import sys
N,K=map(int,input().split())
Max = (N-1) * (N-2) // 2
Hen = N * (N-1)//2
if K>Max:
    print(-1)
    sys.exit()
rinsetsu = [[True]*N for i in range(N)]
#点0をまもる
OnetoN = range(1,N)
c = itertools.combinations(OnetoN,2)
if K!=0:
    for n,(a,b) in enumerate(c,start = 1):#辺a,bを消す
        rinsetsu[a][b] = 0
        rinsetsu[b][a] = 0
        if n == K:break
print(Hen-K)
for i in range(N):
    for j in range(i):
        if i!=j and rinsetsu[i][j]:
            print(i+1,j+1)
3 

Measured memory_bytes: 42864
n = int(input())
l = [0]
r = [0]
for _ in range(n):
    l1, r1 = map(int, input().split())
    l.append(l1)
    r.append(r1)

l = sorted(l)[::-1]
r.sort()
result = 0
for i in range( n + 1):
    if l[i] > r[i]:
        result += l[i] - r[i]
print(result * 2)

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

int main(){
    int a,b;
    cin>>a>>b;
    if(a==1)a=14;
    if(b==1)b=14;
    if(a>b)cout<<"Alice"<<endl;
    else if(b>a)cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

int N,M,H[111111],ans=0;
vector<int>adj[111111];

int main() {
	cin>>N>>M;
	for(int i=1;i<=N;i++)cin>>H[i];
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for(int i=1;i<=N;i++){
		bool tmp=true;
		for(int j:adj[i])if(H[i]<=H[j])tmp=false;
		if(tmp)ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 9412
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

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

    string ans = s.substr(s.size()-1) == "s" ? s + "es" : s + "s";
    cout << ans << endl;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define pi pair<int,int>
#define mk make_pair
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,a,n) for(int i=a;i<n;i++)
#define fr(i,a,n) for(int i=a;i>=n;i--)
#define ll long long
#define N 1000000007
using namespace std;

int h,w;
vector<vector<int>> dp(1005,vector<int> (1005,-1));
char grid[1005][1005];

ll path_cost(int i,int j)
{
    if(i==h&&j==w)
        return 1;
    if(grid[i][j]=='#')
        return 0;
    if(i>h||j>w)
        return 0;

    if(dp[i][j]==-1)
        dp[i][j] = (path_cost(i+1,j)+path_cost(i,j+1))%N;
    return dp[i][j];
}


int main()
{
    //int h,w;
    cin>>h>>w;
    //char grid[h+1][w+1];
    fo(i,1,h+1)
    {
        fo(j,1,w+1)
        {
            cin>>grid[i][j];
        }
    }
    ll ans=path_cost(1,1);
    cout<<ans;
}


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

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define input_txt() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define si set<int>
#define msi map<string, int>
#define test ll t; cin>>t; while(t--)
#define input(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define sqr(a) (a)*(a)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
const double PI = acos(-1);
const int inf=2000000000;
const ll infLL=9000000000000000000;


void case_i()
{
    int x,y;cin>>x>>y;
    if((x==4 || x==6 || x==9 || x==11) && (y==4 || y==6 || y==9 || y==11) && x!=y)
        cout<<"Yes"<<endl;
    else if(x==2 || y==2)
        cout<<"No"<<endl;
    else if((x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12) && (y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12) && x!=y)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

int main()
{
    IOS;
    //    input_txt();
    //test
    case_i();
    /**/
    return 0;
}



//End up here once more;







Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main(){
  ll n,k,ans=0;
  cin>>n>>k;
  ll x=max(n,k);
  if(n*k==1)cout<<1;
  else if(n==1||k==1)cout<<x-2;
  else cout<<(n-2)*(k-2);
}


Measured memory_bytes: 256
//周♂雨扬是最强的！！！
//大佬祝您AK
//沈哲♂贝是最强的！！！
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<fstream>
using namespace std;
int n,m;
int head[2000003],nxt[2000003],to[2000003],tot;
inline void add(int a,int b){
	to[++tot]=b;  nxt[tot]=head[a];  head[a]=tot;
}
bool yes=false;
void dfs(int x,int len){
	if(len>=3||yes){
		return;
	}
	if(x==n){
		yes=true;
		return;
	}
	for(int i=head[x];i;i=nxt[i]){
		dfs(to[i],len+1);
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int a,b;
		cin>>a>>b;
		add(a,b);
	}
	dfs(1,0);
	if(yes){
		cout<<"POSSIBLE"<<endl;
	}else{
		cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}
//沈♂哲贝是最强的！！！
//大佬祝您AK
//周♂雨扬是最强的！！！

Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<deque>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef deque<int> di;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

int f();

string s,pass;
int ind;


int f(){
    int ret;
    if(s[ind] >= 'a' && s[ind] <= 'd'){
        ret = pass[s[ind]-'a'] - '0';
        ind++;
        return ret;
    }else{
        ind++;

        if(s[ind] == '+'){
            ind++;
            int a = f();
            int b = f();
            ret = a | b;
        }else if(s[ind] == '*'){
            ind++;
            int a = f();
            int b = f();
            ret = a & b;
        }else if(s[ind] == '^'){
            ind++;
            int a = f();
            int b = f();
            ret = a ^ b;
        }
        ind++;
    }
    return ret;
}

signed main(void) {
    while(cin >> s, s != "."){
        cin >> pass;
        ind = 0;
        int ret = f();
        int ans = 0;
        rep(a,10)rep(b,10)rep(c,10)rep(d,10){
            pass = "";
            pass += char('0' + a);
            pass += char('0' + b);
            pass += char('0' + c);
            pass += char('0' + d);
            ind = 0;
            if(f() == ret)ans++;
        }
        cout << ret << " " << ans << endl;
    }

}



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

int main() {
  int a,b;
  cin >> a >> b;
  int s=a*b;
  int l=2*(a+b);
  cout << s << " " << l <<endl;
  return 0;
 
}


Measured memory_bytes: 3076
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>

int main() {
  size_t H, W;
  int D;
  scanf("%zu %zu %d", &H, &W, &D);

  std::vector<std::pair<int, int>> B(H*W);

  for (size_t i = 0; i < H; ++i) {
    for (size_t j = 0; j < W; ++j) {
      int a;
      scanf("%d", &a);
      --a;
      B[a] = {i, j};
    }
  }

  std::vector<std::vector<std::pair<int, int>>> C(D);
  for (size_t i = 0; i < H*W; ++i)
    C[i % D].push_back(B[i]);

  std::vector<std::vector<int>> acc(D);
  for (int i = 0; i < D; ++i) {
    acc[i] = {0};
    for (size_t j = 1; j < C[i].size(); ++j) {
      int dy = std::abs(C[i][j-1].first - C[i][j].first);
      int dx = std::abs(C[i][j-1].second - C[i][j].second);
      acc[i].push_back(acc[i][j-1]+dx+dy);
    }
  }

  int Q;
  scanf("%d", &Q);

  for (int i = 0; i < Q; ++i) {
    int L, R;
    scanf("%d %d", &L, &R);
    --L;
    --R;
    printf("%d\n", acc[R % D][R / D] - acc[L % D][L / D]);
  }
}


Measured memory_bytes: 11008
#include<stdio.h>
 
int main(){
	int y, m, d;
	while(scanf("%d %d %d", &y, &m, &d) != EOF){
		if(y < 1868) printf("pre-meiji\n");
		else if(y == 1868){
			if(m < 9) printf("pre-meiji\n");
			else if(m == 9){
				if(d < 8) printf("pre-meiji\n");
				else printf("meiji %d %d %d\n", y - 1867, m, d);
			}
			else printf("meiji %d %d %d\n", y - 1867, m, d);
		}
		else if(y < 1912) printf("meiji %d %d %d\n", y - 1867, m, d);
		else if(y == 1912){
			if(m < 7) printf("meiji %d %d %d\n", y - 1867, m, d);
			else if(m == 7){
				if(d <= 29) printf("meiji %d %d %d\n", y - 1867, m, d);
				else printf("taisho %d %d %d\n", y - 1911, m, d);
			}
			else printf("taisho %d %d %d\n", y - 1911, m, d);
		}
		else if(y < 1926) printf("taisho %d %d %d\n", y - 1911, m, d);
		else if(y == 1926){
			if(m < 12) printf("taisho %d %d %d\n", y - 1911, m, d);
			else if(m == 12){
				if(d <= 24) printf("taisho %d %d %d\n", y - 1911, m, d);
				else printf("showa %d %d %d\n", y - 1925, m, d);
			}
		}
		else if(y < 1989) printf("showa %d %d %d\n", y - 1925, m, d);
		else if(y == 1989){
			if(m == 1){
				if(d <= 7) printf("showa %d %d %d\n", y - 1925, m, d);
				else printf("heisei %d %d %d\n", y - 1988, m, d);
			}
			else printf("heisei %d %d %d\n", y - 1988, m, d);
		}
		else printf("heisei %d %d %d\n", y - 1988, m, d);
	}
	return 0;
}

Measured memory_bytes: 1036
# -*- coding:utf-8 -*-
n, m = map(int, input().split())

road = []
for _ in range(m):
    a, b = map(int, input().split())
    road.append([a, b])

for i in range(n):
    cnt = 0
    for rd in road:
        if rd.count(i+1) > 0:
            cnt+=1
    print(cnt)

Measured memory_bytes: 3060
import math

a,b,C= [ float( val ) for val in input().split( ' ' ) ]
radiansC = math.radians(C)
h = math.sin(radiansC)*b
S = (a*h)/2
c = math.sqrt( a*a+b*b-2*a*b*math.cos(radiansC) )
L = a+b+c
print( S )
print( L )
print( h )


Measured memory_bytes: 5700
s=input()
ss=input()

snum = [0 for i in range(26)]
ssnum = [0 for i in range(26)]
#print(ord("a")-97)
for i in range(len(s)):
  snum[ord(s[i])-97] +=1
  ssnum[ord(ss[i])-97] +=1
snum.sort()
ssnum.sort()
for i in range(26):
  if snum[i]!=ssnum[i]:
    print("No")
    break
else:
  print("Yes")
  
#print(snum)
#print(ssnum)

Measured memory_bytes: 3632
N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
dp = [0 for i in range(N)]

mod = 10**9+7
stair_set = set(range(0, N)[::-1])
stair_set = stair_set - set(a)
stair_list = list(stair_set)
stair_list.sort(reverse=True)

for i in stair_list:
    if i == N-1:
        dp[N - 1] = 1
        continue
    if i == N-2:
        dp[N - 2] = 1 + dp[N - 1]
        continue
    dp[i] = (dp[i+1] + dp[i+2])%mod

print(dp[0])


Measured memory_bytes: 64896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0); }
 
int main() {
  string s;
  cin >> s;
 
  auto f = stoi(s.substr(0, 2));
  auto b = stoi(s.substr(2, 2));
 
  bool yymm = false;
  bool mmyy = false;
  if (0 <= f && f <= 99) {
    if (1 <= b && b <= 12) {
      yymm = true;
    }
  }
  if (1 <= f && f <= 12) {
    if (0 <= b && b <= 99) {
      mmyy = true;
    }
  }
 
  if (yymm && mmyy) {
    cout << "AMBIGUOUS" << endl;
  } else if (yymm) {
    cout << "YYMM" << endl;
  }  else if (mmyy) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }
 
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
vector<tuple<string , ll,ll>> x;
void solve(long long N, std::vector<std::string> S, std::vector<long long> P){
  sort(all(x),[](const auto a , const auto b){return (get<0>(a) == get<0>(b) ? get<1>(a) > get<1>(b) : get<0>(a) < get<0>(b));});
  for (int i = 0; i < N; i++) {
    cout << get<2>(x[i]) << endl;
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
        scanf("%lld",&P[i]);
        x.pb(make_tuple(S[i],P[i],i+1));
    }
    solve(N, std::move(S), std::move(P));
}


Measured memory_bytes: 256