akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
   
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  
  string in;
  
  for (int i = 0; i < N; i++) {
  	cin >> in;
    
    if (in == "AC") {
    	ac++;
    } else if (in == "WA") {
    	wa++;
    } else if (in == "TLE") {
    	tle++;
    } else if (in == "RE") {
    	re++;
    }
    
  }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x "  << re << endl;
 
}

Measured memory_bytes: 3636
import sys
def input(): return sys.stdin.readline().rstrip()
class Facts:
  def __init__(self, mod=10**9+7, n_max=1):
    self.mod     = mod
    self.n_max   = n_max
    self.fact    = [1, 1]
    self.inv     = [0, 1]
    self.factinv = [1, 1]
    if 1 < n_max:
      setup_table(n_max) 
  
  def cmb(self, n, r):
    if r < 0 or n < r:
      return 0
    if self.n_max < n:
      self.setup_table(n)
    return self.fact[n] * (self.factinv[r] * self.factinv[n-r] % self.mod) % self.mod
  
  def setup_table(self, t):
    for i in range(self.n_max+1,t+1):
      self.fact.append( self.fact[-1] * i % self.mod )
      self.inv.append( -self.inv[self.mod % i] * (self.mod // i) % self.mod )
      self.factinv.append( self.factinv[-1] * self.inv[-1] % self.mod )
    self.n_max = t

def main():
    n,m,k=map(int,input().split())
    mod=998244353
    f=Facts(mod)
    ans=0
    t=m*pow(m-1,n-1-k,mod)
    for kx in range(k,-1,-1):
        ans+=f.cmb(n-1,kx)*t%mod
        t=t*(m-1)%mod
    print(ans%mod)


if __name__=='__main__':
    main()

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

  int X,N;
  Scd2(X,N);
  vi a(101);
  int p;
  Rep(i,N) Scd(p), a[p]++;
  
  int ans = 114514;
  int ab = 114514;
  Rep(i,334){
    if( a[i] ) continue;
    if( abs(X-i) < ab ){
      ans = i;
      ab = abs(X-i);
    }
  }
  
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 3796
m,i,j,k,t[16],c[16],p,d;
main(n){
	for(*t=1;++i<16;)t[i]=n*=3;
	for(;scanf("%d%d",&n,&m),n;printf("%d\n",j>m?-1:j)){
		for(k=3;k--;)
			for(scanf("%d",&i);i--;c[j]=k)scanf("%d",&j);
		for(j=k=0;k++<n;p=i%2*2+p&3)
			j+=t[n-k]*abs(i=p-c[k]);
		j=fmin(j,t[n]+~j);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

int main() {
  int N;
  string S;
  cin >> N >> S;
  string mae = S.substr(0, N), ushi = S.substr(N, N);

  // 後ろ文字列たちから得られる反転ペアたちを作っておく
  map<pair<string,string>, long long > ma;
  for (int bit = 0; bit < (1<<N); ++bit) {
	string a = "", b = "";
	for (int i = 0; i < N; ++i) {
	  if (bit & (1<<i)) a += ushi[i];
	  else b += ushi[i];
	}
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	auto p = make_pair(a, b);
	++ma[p];
  }

  // 前半文字列から作られるペアが後ろにもあるかどうかを判定する
  long long res = 0;
  for (int bit = 0; bit < (1<<N); ++bit) {
	string a = "", b = "";
	for (int i = 0; i < N; ++i) {
	  if (bit & (1<<i)) a += mae[i];
	  else b += mae[i];
	}
	//cout << bitset<10>(bit) << ": " << a << ", " << b << ";; " << se.count(make_pair(a, b)) << endl;
	auto p = make_pair(a, b);
    res += ma[p];
  }

  cout << res << endl;
}


Measured memory_bytes: 87040
var n,s,max,i,left,right:longint;
  count:int64;
   x,p:array[1..100000]of int64;
begin
 readln(n,s);
 for i:=1 to n do
   begin
   readln(x[i],p[i]);
  end;
  if s<=x[1] then
    begin
    count:=x[n]-s;
    write(count);
    exit;
    end;
  if s>x[n] then
    begin
    count:=s-x[1];
    write(count);
    exit;
    end;
    left:=1;
    right:=n;
    if p[1]<p[n] then max:=2
    else max:=1;
    if p[1]<p[n] then begin p[n]:=p[n]+p[1]; count:=count+x[right]-x[left]; inc(left);  end
                  else begin p[1]:=p[1]+p[n]; count:=count+x[right]-x[left];dec(right); end;
  while(x[left]<s)and(x[right]>s)do begin
  if p[left]>=p[right] then
   begin
     p[left]:=p[left]+p[right];
     if max=2 then count:=count+x[right]-x[left];
     dec(right);
     if max=2 then max:=1;
   end
   else begin
     p[right]:=p[right]+p[left];
    if max=1 then count:=count+x[right]-x[left];
     inc(left);
     if max=1 then max:=2;
       end;
    end;
  if x[left]>s then write(count+x[right]-s)
               else write(count+s-x[left])
end.



Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << (x) << ", "
#define de(x) cout << #x << " = " << (x) << "\n"
#define endl "\n"

//-----
const int N = 40 + 7, MOD = 1e9 + 7;
void inc(int &a, int b) { if ((a += b) >= MOD) a -= MOD; }
int add(int a, int b) { if ((a += b) >= MOD) a -= MOD; return a; }
int mul(int a, int b) { return ll(a) * b % MOD; }
int n, x, y, z, dp[N][pw(5)][pw(7)][pw(4)], pw10[N];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	pw10[0] = 1; rep(i, 1, N) pw10[i] = mul(pw10[i - 1], 10);
	cin >> n >> x >> y >> z;
	dp[0][0][0][0] = 1;
	int ans = 0;
	rep(i, 0, n) {
		rep(mx, 0, pw(x)) {
			rep(my, 0, pw(y)) {
				rep(mz, 0, pw(z - 1)) {
					int d = dp[i][mx][my][mz]; if (!d) continue;
					rep(j, 1, 11) {
						int zx = 1, zy = mx >> (x - 1) & 1, zz = my >> (y - 1) & 1;
						int nmx = (mx << j | (zx << (j - 1))) & (pw(x) - 1);
						int nmy = (my << j | (zy << (j - 1))) & (pw(y) - 1);
						int nmz = (mz << j | (zz << (j - 1))) & (pw(z) - 1);
						if (nmz >> (z - 1) & 1)
							inc(ans, mul(d, pw10[n - i - 1]));
						else
							inc(dp[i + 1][nmx][nmy][nmz], d);
					}
				}
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 9856
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>

using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
typedef long long ll;

int k, n, ans;
int a[maxn];
int main(){
	cin >> k >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	ans = k - a[n] + a[1];
	for(int i = 1; i <= n; i++){
		ans = max(ans, a[i] - a[i-1]);
	}
	cout << k - ans << endl;
}


Measured memory_bytes: 1152
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

const MOD: i64 = 1_000_000_007;

fn calc(a: &[i64]) -> i64 {
    let n = a.len();
    let mut tot = 0;
    let mut acc = 0;
    for i in 0 .. n {
        tot += (a[i] + MOD) * i as i64 - acc + MOD;
        tot %= MOD;
        acc = (acc + a[i] + MOD) % MOD;
    }
    tot
}

fn solve() {
    let n = get();
    let m = get();
    let x: Vec<i64> = (0 .. n).map(|_| get()).collect();
    let y: Vec<i64> = (0 .. m).map(|_| get()).collect();
    println!("{}", calc(&x) * calc(&y) % MOD);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    ll tmp = 0;
    ll ans = 1e9;
    rep(i,n){
        cin >> a[i];
    }
    sort(ALL(a));
    for(int i = -100;i<=100;i++){
        tmp = 0;
        rep(j,n){
            tmp += (a[j]-i)*(a[j]-i);
        }
        ans = min(tmp,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	vector<ll> dl(n);
	rep(i, n) {
		cin >> dl[i];
	}
	sort(dl.begin(), dl.end());
	ll s = dl.size() / 2 - 1;
	ll e = dl.size() / 2;
	cout << dl[e] - dl[s] << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}


Measured memory_bytes: 4032
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstring>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

ll INF = 1LL << 60;

int main() {
	int X;
	cin >> X;
	if (X >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3624
H,W=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(H)]

operations=[]
N=0
for y in range(H):
    for x in range(W):
        if a[y][x]%2==0:
            continue
        else:
            flag=0
            for i,j in ([0,1],[0,-1],[1,0],[-1,0]):
                new_y,new_x=y+i,x+j
                if new_y<0 or new_y>=H or new_x<0 or new_x>=W:
                    continue
                elif a[new_y][new_x]%2!=0:
                    N+=1
                    a[y][x]-=1
                    a[new_y][new_x]+=1
                    operations.append([y+1,x+1,new_y+1,new_x+1])
                    flag=1
                    break
            if flag==0:
                if y!=H-1:
                    N+=1
                    a[y][x]-=1
                    a[y+1][x]+=1
                    operations.append([y+1,x+1,y+2,x+1])
                elif y==H-1 and x!=W-1:
                    N+=1
                    a[y][x]-=1
                    a[y][x+1]+=1
                    operations.append([y+1,x+1,y+1,x+2])

print(N)
for i in range(N):
    print(*operations[i])

Measured memory_bytes: 30168
#include<stdio.h>
#define N 1000000
#define NIL -1

struct Node{
  int p,
    l, 
    r;
};

struct Node T[N];
int a,f[N];

int getDepth(int b){
  int count = 0,i ;
  while(T[b].p!=NIL){
    b = T[b].p;
    count++;
  }
  return count;
}


void printChild(int u){
  int c;
  c = T[u].l;
  while(c != NIL){
    printf("%d, ",u);
    c = T[c].r;
  }
}


void print(int u){
  int i,c;
  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,getDepth(u));
  if(T[u].p == NIL)printf("root, ");
  else if(T[u].l == NIL)printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  for(i=0,c = T[u].l; c!=NIL;i++,c = T[c].r){ 
    if(i>=1) printf(", ");   
    printf("%d",c);
  }
  printf("]");
}




int main(){
  int i,j,a,b,c,d,k=0,l,n,r;
  scanf("%d",&a);
 for(i=0;i<a;i++){
   T[i].p = T[i].l = T[i].r = NIL;
 }
  for(i=0;i<a;i++){
    scanf("%d %d",&c,&d);

    for(j=0;j<d;j++){
      scanf("%d",&b);
      if(j==0)T[c].l = b;
      else T[k].r = b;
	k=b;
	T[b].p = c;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p == NIL) r = i;
  }
  for(i=0;i<a;i++){
    print(i);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1776
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
ll dp[10][20];
ll sum[20], pos;
ll k;
void dfs(ll num, ll lst) {
    if (num > pos) return;
    if (num == 1) {
        for (ll i = 1; i < 10; i++) {
            if (k > dp[i][pos - num + 1]) {
                k -= dp[i][pos - num + 1];
            } else {
                cout << i;
                dfs(num + 1, i);
                break;
            }
        }
    } else {
        for (ll i = lst - 1; i <= lst + 1; i++) {
            if (i < 0 || i > 9) continue;
            if (k > dp[i][pos - num + 1]) {
                k -= dp[i][pos - num + 1];
            } else {
                cout << i;
                dfs(num + 1, i);
                break;
            }
        }
    }
}
int main() {
    cin >> k;
    for (ll i = 0; i < 10; i++) {
        dp[i][1] = 1;
    }
    sum[1] = 9;
    for (ll j = 2; j <= 10; j++) {
        for (ll i = 0; i < 10; i++) {
            if (i != 0 && i != 9) dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1] + dp[i + 1][j - 1];
            else if (i != 0) dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
            else if (i != 9) dp[i][j] = dp[i][j - 1] + dp[i + 1][j - 1];
            if (i != 0) sum[j] += dp[i][j];
        }
    }
    for (ll i = 1; i <= 20; i++) {
        if (k > sum[i]) {
            k -= sum[i];
        } else {
            pos = i;
            break;
        }
    }
    dfs(1, 0);
    return 0;
}



Measured memory_bytes: 256
while True:
    n,x = [int(x) for x in input().split()]
    if (n,x)==(0,0): break
    cnt=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k == x: cnt+=1
    print(cnt)

Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;

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


int main(){
  int h,w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i,h){
    cin >> a[i];
  }
  vector<vector<mint>> dp(1010, vector<mint>(1010,0));
  dp[0][0]=1;
  rep(i,h)rep(j,w){
    if(a[i][j]=='#') continue;
    dp[i+1][j] += dp[i][j];
    dp[i][j+1] += dp[i][j];
  }
  ll ans = dp[h-1][w-1].x;
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 9344
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
using namespace std;

#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=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int main() {
    int n;
    cin >> n;
    string head = "MARCH";
    VL cnt(5);
    REP(i,n){
        string s;
        cin >> s;
        REP(j,5) if (s[0] == head[j]) cnt[j]++;
    }

    VI p(5);
    p[2] = p[3] = p[4] = 1;

    ll ans = 0;
    do {
        ll tmp = 1;
        REP(i,5) if (p[i]) tmp *= cnt[i];
        ans += tmp;
    }while(next_permutation(ALL(p)));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys, os
import math

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, k = f()
    ans = 0
    for i in range(1,n+1):
        if i<k:
            num = int(math.ceil(math.log(k/i)/math.log(2)))
            ans += 0.5**num/n
        else:
            ans += 1/n

    print(ans)

solve()


Measured memory_bytes: 3060
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
string s;
long l,i;
int main(void){
  getline(cin,s);
  l=s.size();
  for(i=0;i<l;i++){
    if(isupper(s[i]))cout<<(char)tolower(s[i]);
    else if(islower(s[i]))cout<<(char)toupper(s[i]);
    else cout<<s[i];
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
	// 頂点数と辺数
	int N, M; cin >> N >> M;

	// グラフ入力受取 (ここでは無向グラフを想定)
	Graph G(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		G[a-1].push_back(b-1);
		G[b-1].push_back(a-1);
	}

	// BFS のためのデータ構造
	vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
	queue<int> que;

	// 初期条件 (頂点 0 を初期ノードとする)
	dist[0] = 0;
	que.push(0); // 0 を橙色頂点にする

	// BFS 開始 (キューが空になるまで探索を行う)
	while (!que.empty()) {
		int v = que.front(); // キューから先頭頂点を取り出す
		que.pop();

		// v から辿れる頂点をすべて調べる
		for (int nv : G[v]) {
			if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

			// 新たな白色頂点 nv について距離情報を更新してキューに追加する
			dist[nv] = v;
			que.push(nv);
		}
	}

	// 結果出力 (各頂点の頂点 0 からの距離を見る)
	cout << "Yes"<<endl;
	for (int v = 1; v < N; ++v) cout << dist[v]+1 << endl;
}

Measured memory_bytes: 10332
#define _USE_MATH_DEFINES
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int test(int n, int s, int i){//n個でsを作る
	//cout << n <<" "<<s<<" "<<i<<endl;
	if(n==0){
		if(s==0){
			return 1;//作れた
		}else{
			return 0;
		}
	}
	if(i>=10 || s-i<0){
		return 0;
	}

	return test(n, s, i+1) + test(n-1, s-i, i+1);
}

int main(){
	
	int km[11][101]={0};
	
	for(int i=0;i<10;i++){
		km[1][i]=1;
	}
	/*
	for(int i=1;i<9;i++){
		for(int j=i-1;j<101;j++){
			for(int k=j;j+k<101;k++){
				if(i+1==3 && j+k==6) cout << i << " "<< j<<" "<<k<<" "<<km[i][j]<<endl;
				if(j!=k){
				km[i+1][j+k]+=km[i][j];
				}else{
					km[i+1][j+k]+=1;
				}
			}
		}
	}
	*/
	/*
	for(int i=2;i<=10;i++){
		/*
		for(int j=0;j<101;j++){
			if(km[i-1][j]){
				for(int k=j+1;k<=10&&j+k<101;k++){
					if(i==3 && j+k==6) cout << j<<" "<<k<<endl;
					
					km[i][j+k]+=km[i-1][j];
				}
			}
		}
		
		for(int j=0;j<10;j++){
			for(int k=0;k<101;k++){
				if(km[i-1][k]&&k>j){
					if(i==3 && k+j==1) cout << j<<" "<<k<<endl;;
					km[i][k+j]++;
				}
			}
		}
	}
	*/
	/*
	for(int i=2;i<=10;i++){//２個で作る組み合わせから計算
		for(int j=0;j<101;j++){//横に調べて行って
			if(km[i-1][j]){//もしあれば
				for(int k=i-1;k<10;k++){
					if(i==2 && k+j==3) cout << j<<" "<<k<<endl;
					km[i][j+k]++;
				}
			}
		}
	}

	for(int i=0;i<10;i++){
		for(int j=0;j<30;j++){
			cout << km[i][j]<<" ";
		}
		cout << endl;
	}
	cout << km[3][6];
	*/
	/*
	int n, s;
	while(cin >> n >> s){
		if(n==0 && s==0) break;
		cout << km[n][s] << endl;
	}
	*/

	int n,s;
	while(cin >> n >> s){
		if(n==0 && s==0) break;
		cout<<test(n,s,0)<<endl;
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  int d = *max_element(A.begin(), A.end());
  vector<int> C(d+1,0);
  for(int i = 0; i < N; ++i)
    ++C[A[i]];
  if(C.back() < 2){
    cout << "Impossible" << endl;
    return 0;
  }
  for(int i = 0; i < (d+1)/2; ++i){
    if(C[i]){
      cout << "Impossible" << endl;
      return 0;
    }
  }
  //cerr << "d = " << d << ", C[(d+1)/2] = " << C[(d+1)/2] << endl;
  if((d%2 and C[(d+1)/2] != 2) or (C[(d+1)/2] != 1 and not (d%2))){
    cout << "Impossible" << endl;
    return 0;
  }
  for(int i = (d+1)/2+1; i < d; ++i){
    if(C[i] < 2){
      cout << "Impossible" << endl;
      return 0;
    }
  }
  cout << "Possible" << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ChokudaiScanner
{
     class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            long N = cin.NextLong();
            string ans ="" ;

            while (N > 0)
            {
                N--;
                long a = N;
                N = N / 26;
                a -= N * 26;

                ans += (char)(((int)'a') + a);
            }
            string rev = new string(ans.Reverse().ToArray());

            Console.WriteLine(rev);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}



Measured memory_bytes: 28200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  int n, k;
  scanf("%d %d", &n, &k);

  int cnt = 0;
  while (n != 0) {
    n /= k;
    cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);
        BitArray flag = new BitArray(M, true);
        for(int i = 0; i < N; i++)
        {
            string[] input1 = Console.ReadLine().Split(' ');
            int K = int.Parse(input1[0]);
            BitArray f = new BitArray(M, false);
            for (int j = 1; j <= K; j++)
            {
                f.Set(int.Parse(input1[j]) - 1, true);
            }
            flag.And(f);
        }
        int n = 0;
        for(int i = 0; i < M; i++)
        {
            if (flag.Get(i) == true)
                n++;
        }
        Console.WriteLine(n);
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

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

    sort(A.begin(), A.end(), greater<ll>());

    ll l1 = 0, l2 = 0;
    for (int i = 0; i < N-1; i++) {
        if (A[i] == A[i+1]) {
            if (l1 == 0) {
                l1 = A[i];
                i++;
            } else {
                l2 = A[i];
                break;
            }
        } 
    }

    cout << l1 * l2 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
struct data{
  long a;
  long b;
  bool operator<(const data &another) const
  {
    return a < another.a;
  }; 
  
};

int main(){
  int n, m;
  cin >> n >> m;
  vector<data> ab(n);
  int i;
  for(i = 0; i < n; i++){
    cin >> ab[i].a >> ab[i].b;
  }
  sort(ab.begin(), ab.end());
  long sum = 0;
  int count = 0;
  for(i = 0; count != m; i++){
    if(m > count + ab[i].b){ 
      sum += ab[i].a * ab[i].b;
      count += ab[i].b;
    }
    else {
      sum += ab[i].a * (m - count);
      count = m;
    }
  }
    
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
template<class T> void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

const long long LLINF = 1LL << 60;
#define W_MAX 100010

int main(void) {
	LL N, W;
	cin >> N >> W;

	vector<LL> value(110);
	vector<LL> weight(110);
	rep(i, N) cin >> weight[i] >> value[i];

	vector<vector<LL> > dp(110, vector<LL>(W_MAX));
	for (int i = weight[0]; i <= W; i++) {
		dp[0][i] = value[0];
	} 

	for (int i = 1; i < N; i++) {
		for (int w = 0; w <= W; w++) {
			if (w - weight[i] >= 0) {
				dp[i][w] = max(dp[i - 1][w - weight[i]] + value[i], dp[i - 1][w]);
			}
			else {
				dp[i][w] = dp[i - 1][w];
			}
		}
	}

	cout << dp[N - 1][W] << endl;
}

Measured memory_bytes: 87296
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//templete
vint node[SIZE];
bool done[SIZE]={};
int ans[SIZE]={};
void DFS(int now){
	//cout<<now<<endl;
	for(int next:node[now]){
		if(done[next])
			continue;
		ans[next]+=ans[now];
		done[next]=1;
		DFS(next);
	}

	return;
}
int main() {
	int N,Q;
	cin>>N>>Q;
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		a--,b--;
		node[a].pb(b);
	}
	for(int i=0;i<Q;i++){
		int p,x;
		cin>>p>>x;
		p--;
		ans[p]+=x;
	}
	done[0]=1;
	DFS(0);
	for(int i=0;i<N-1;i++){
		cout<<ans[i]<<" ";
	}
	cout<<ans[N-1]<<endl;
	return 0;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  ll n,m;
  cin >> n >> m;
  if(n==1 && m==1){
    cout << 1 << endl;
    return 0;
  }
  if(n==1 || m==1){
    cout << n*m-2 << endl;
    return 0;
  }
  cout << (n*m)-(2*n+2*m - 4) << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

typedef struct{
    string n;
    int a, b;
}data;

int main(){
    int n, q;
    while(cin >> n >> q, n||q){
        data d[1001];
        rep(i,n){
            string s;
            int a, b;
            cin >> s >> a >> b;
            d[i].n = s;
            d[i].a = b - a + 1;
            d[i].b = b;
        }
        rep(i,q){
            int a;
            bool f = true;
            cin >> a;
            rep(j,n){
                if(a >= d[j].a && a <= d[j].b){
                    cout << d[j].n << ' ' << a - d[j].a + 1 << endl;
                    f = false;
                    break;
                }
            }
            if(f) cout << "Unknown" << endl;
        }
    }
}

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

int main(void) {
    int ans;
    ans = 0;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '+') ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll wt[101],v[101];

ll fun(int n,int W,ll **dp){
     if(W==0 || n <0)
        return 0;
     if(dp[n][W] != -1)
          return dp[n][W];
     if(W-wt[n] >=0){
         dp[n][W] = max(dp[n][W], fun(n-1,W-wt[n],dp)+v[n]);
     }
      
        dp[n][W] = max(dp[n][W],fun(n-1,W,dp));
    return dp[n][W];
}
int main() {
     int n,W;
     cin >> n >> W;
     
     for(int i=0; i<n; i++){
         cin >> wt[i] >> v[i];
     }
     ll **dp = new ll*[n];
        for(int i=0; i<n; i++)
            dp[i] = new ll[W+1];
        for(ll i=0; i<n; i++){ 
        for(ll j=0; j<W+1; j++){
            dp[i][j] = -1;
            }
        }

     cout << fun( n-1, W, dp);
     return 0;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

LL GCD(LL x, LL y){
        LL r=0;

        if( x<y ) swap(x, y);
        r = x % y;
        while(r!=0){
                x = y;
                y = r;
                r = x % y;
        }
        return y;
}

LL LCM(LL x, LL y){
        if( x<y ) swap(x, y);
        return (x/GCD(x, y))*y;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long A, B;

	cin >> A >> B;

	long long ans = LCM(A, B);
	printf("%lld\n", ans);
	return 0;
}

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,v;
  cin>>n>>v;
  vector<Int> x(n);
  for(Int i=0;i<n;i++) cin>>x[i];

  vector<vector<Int> > dpl,dpr;
  while(1){
    {
      vector<Int> dp(n);
      dp.back()=n;
      for(Int i=n-2;i>=0;i--){
	if(x[i+1]-x[i]<=v) dp[i]=dp[i+1];
	else dp[i]=i+1;
      }
      dpl.emplace_back(dp);
    }
    {
      vector<Int> dp(n);
      dp.front()=-1;
      for(Int i=1;i<n;i++){
	if(x[i]-x[i-1]<=v) dp[i]=dp[i-1];
	else dp[i]=i-1;
      }
      dpr.emplace_back(dp);
    }
    if(!v) break;
    v>>=1;
  }

  Int k=dpl.size();
  vector<Int> dp(1<<k,0);
  vector<Int> pd(1<<k,n-1);
  
  for(Int b=0;b<(1<<k);b++){
    for(Int i=0;i<k;i++){
      if((b>>i)&1) continue;
      chmax(dp[b|(1<<i)],(dp[b]<n?dpl[i][dp[b]]:n));
      chmin(pd[b|(1<<i)],(~pd[b]?dpr[i][pd[b]]:-1));
    }
  }

  vector<Int> ans(n+1);
  
  
  for(Int b=0;b<(1<<k);b+=2){
    Int a=((1<<k)-2)^b;
    Int c=dp[a]<n?dpl[0][dp[a]]:n;
    if(pd[b]>=c) continue;
    ans[dp[a]]++;
    ans[c]--;
    continue;
    cout<<a<<" "<<b<<endl;
    cout<<dp[a]<<" "<<pd[b]<<" "<<c<<endl;
    cout<<endl;
  }
  
  
  for(Int i=0;i<n;i++){
    cout<<(ans[i]?"Possible":"Impossible")<<endl;
    ans[i+1]+=ans[i];
  }
  return 0;
}


Measured memory_bytes: 73188
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    int n,m;cin>>n>>m;
    while(!(n==0&&m==0)){
        if(n>m)swap(n,m);
        cout<<n<<" "<<m<<endl;
        cin>>n>>m;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

































Measured memory_bytes: 3076
a = int(input())
b = int(input())
c = int(input())
d = int(input())

nn = a + c
nf = a + d
fn = b + c
ff = b + d

l = []
l.append(nn)
l.append(nf)
l.append(fn)
l.append(ff)

l.sort()

print(l[0])


Measured memory_bytes: 3060
<?php
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

$arr_s = str_split($s);
$arr_t = str_split($t);

sort($arr_s);
rsort($arr_t);

$new_s = implode("", $arr_s);
$new_t = implode("", $arr_t);

echo $new_s < $new_t ? "Yes" . "\n" : "No" . "\n";


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

int main()
{
    int x, y;
    cin >> x >> y;

    int a = y - 2 * x;
    if (a % 2 == 0 && a >= 0 && a / 2 <= x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3624
def main():
    # parse
    x, y = parse() 
    if y == 1:
        print(0)
    else:
        print(x - y)

def parse():
    vars = split_stdin(get_stdin())
    # var = get_stdin()
    return  int(vars[0]), int(vars[1]) 

def get_stdin():
    return input()

def split_stdin(stdin_val, delim = ' '):
    return [x for x in stdin_val.split(delim) if x != '']

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

bool winner(vector<int> v) {
    if(*max_element(ALL(v)) == 1) return 0;
    int odd = 0, even = 0;
    for(auto &&x : v)
        (x & 1 ? odd : even)++;
    if(even & 1) return 1;
    if(odd >= 2) return 0;
    int G = 0;
    for(auto &&x : v) {
        if(x == 1) return 0;
        if(x & 1) x--;
        G = gcd(G, x);
    }
    for(auto &&x : v)
        x /= G;
    return !winner(v);
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    cout << (winner(a) ? "First" : "Second") << "\n";

    return 0;
}

Measured memory_bytes: 12932
a=-1,A=65,d;
char
*N="GKSOCNWLDFVTBRXHAJUPEMQI",
*E="PHLTIDOXQAGWECSUMBKVJFNR",
*R="BCDAFGHEJKLINOPMRSTQVWXU",
s[9];
main(c)
{
for(;c-48&&scanf("%s",s);a+=d/4+1)
{
if((c=*s)<A)
~a&&printf("%d\n",a),
a=d=0;
if(c=='N')d=N[d]-A;
if(c=='E')d=E[d]-A;
if(c=='W')d=E[E[E[d]-A]-A]-A;
if(c=='S')d=N[N[N[d]-A]-A]-A;
if(c=='R')d=R[d]-A;
if(c=='L')d=R[R[R[d]-A]-A]-A;
}
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
 ll n,m;
  cin>>n>>m;
  cout<<(n*(n-1))/2 + (m*(m-1))/2;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <bitset>
#include <map>

#define rep(i, l, r) for(int i=l; i<=r; i++)
#define dow(i, l, r) for(int i=l; i>=r; i--)
#define clr(x, c) memset(x, c, sizeof(x))
#define travel(x) for(edge *p=fir[x]; p; p=p->n)
#define all(x) (x).begin,(x).end
#define pb push_back
#define fi first
#define se second
#define l(x) Left[x]
#define r(x) Right[x]
#define lowbit(x) (x&-x)

using namespace std;

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

inline int read()
{
	int x=0; bool f=0; char ch=getchar();
	while (ch<'0' || '9'<ch) f|=ch=='-', ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0', ch=getchar();
	return f?-x:x;
}

/* struct num
{
	int L, a[maxn];
	void input()
	{
		char s[maxn]; clr(s,0); scanf("%s", s);
		L=strlen(s);
		rep(i, 0, L-1) a[i]=s[L-1-i]-'0';
	}
	void output()
	{
		char s[maxn]; clr(s,0);
		rep(i, 0, L-1) s[i]=a[L-1-i]+'0';
		printf("%s", s);
	}
	void dec1()
	{
		a[0]--; 
		rep(i, 0, L-1) if (a[i]<0) a[i]+=10, a[i+1]--;
		if (a[L-1]==0) L--;
	}
	void div2()
	{
		dow(i, L-1, 1) a[i-1]+=(a[i]%2?10:0), a[i]/=2; a[0]/=2;
		if (a[L-1]==0) L--;
	}
	void mult2()
	{
		rep(i, 0, L-1) a[i]*=2;
		rep(i, 0, L-1) if (a[i]>9) a[i]-=10, a[i+1]++;
		if (a[L]) L++;
	}
}; */



#define maxn 100009
#define Q 1000000007

int n, A, B, b[maxn], ans[maxn], p[maxn], a[maxn];

inline int C(int x, int y){return 1LL*a[x]*p[y]%Q*p[x-y]%Q;}

int main()
{
	n=read();
	
	p[0]=p[1]=1;
	rep(i, 2, n+1) p[i]=Q-1LL*(Q/i)*p[Q%i]%Q;
	rep(i, 2, n+1) p[i]=1LL*p[i]*p[i-1]%Q;
	a[0]=a[1]=1;
	rep(i, 2, n+1) a[i]=1LL*a[i-1]*i%Q;
	
	rep(i, 1, n+1)
	{
		int x=read();
		if (!b[x]) b[x]=i; else A=b[x], B=i;
	}
	//p[0]=1; rep(i, 1, n+1) p[i]=p[i-1]*2%Q;
	rep(i, 1, n+1) ans[i]=C(n+1,i);
	rep(i, 0, (n+1)-(B-A+1)) ans[i+1]+=Q-C((n+1)-(B-A+1),i);
	rep(i, 1, n+1) printf("%d\n", ans[i]%Q);
	return 0;
}

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

using namespace std;
using ll =long long;

#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 debug(x)  cout << #x << " = " << (x) << endl;
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; }
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line
int getKeta(ll x){
	int count = 0 ;
	while(x > 0){
		count ++;
		x /= 10 ;
	}
	return count ;
}


const int mod = 1e9+7;
int main()
{
	cin >> n; 
	ll ans = 1;
	for(ll i = 1 ; i * i <= n ; i++){
		if(n % i != 0)continue;
		ans = n / i ;
	}
	//ansの桁数をゲットする
	int A = getKeta(ans);
	cout << A << endl;


}



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

class Program
{

    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var inputs = Console.ReadLine().Split(' ');
        var V = new int[inputs.Length];
        for(int i = 0; i < inputs.Length; i++)
        {
            V[i] = int.Parse(inputs[i]);
        }

        inputs = Console.ReadLine().Split(' ');
        var C = new int[inputs.Length];
        for(int i = 0; i < inputs.Length; i++)
        {
            C[i] = int.Parse(inputs[i]);
        }

        var sum = 0;
        for(int i = 0; i < inputs.Length; i++)
        {
            var diff = V[i] - C[i];
            if(diff > 0)
            {
                sum += diff;
            }
        }

        Console.WriteLine(sum);
    }

}



Measured memory_bytes: 11092
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

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

typedef long long int int64;
typedef unsigned long long int uint64;
typedef float float32;
typedef double float64;
typedef long double float128;


int main(){
    int X;
    cin >> X;
    int ans = 1;
    REP(i,X){
        FOR(j,2,10){
            if(pow(i,j)>X){
                break;
            }else if(pow(i,j)>ans){
                ans = pow(i,j);
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int l;
    cin>>l;
    if(l==2){
        cout<<"2 2\n1 2 0\n1 2 1"<<endl;
        return 0;
    }
    int n;
    for(int i=19;i>=0;i--){
        if((l-1)&(1<<i)){
            n=i+1;
            break;
        }
    }
    int m=n-1+n-1+1,t=1<<(n-1);
    vector<pair<int,int>> ans;
    for(int i=2;i<=n;i++){
        if((l-1)&(1<<(n-i))){
            ans.push_back({i,t});
            m++;
            t+=1<<(n-i);
        }
    }
    cout<<n<<" "<<m<<endl;
    for(int i=1;i<=n-1;i++){
        cout<<i<<" "<<i+1<<" "<<0<<endl;
    }
    for(int i=1;i<=n-1;i++){
        cout<<i<<" "<<i+1<<" "<<(1<<(n-i-1))<<endl;
    }
    for(auto p:ans){
        cout<<"1 "<<p.first<<" "<<p.second<<endl;
    }
    cout<<1<<" "<<n<<" "<<l-1<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

int maxq = 55;

int n = 10, m, q, ans;
int A[15], a[55], b[55], c[55], d[55];

void DFS(int now)
{
	if(now == n + 1) {
		int res = 0;
		for(int i = 1; i <= q; ++i) {
			if(A[b[i]] - A[a[i]] == c[i])
				res += d[i];
		}
		ans = std::max(ans, res);
		return;
	}
	for(int j = A[now - 1]; j <= m; ++j) {
		A[now] = j;
		DFS(now + 1);
	}
}

int main() {
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= q; ++i)
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
	
	A[0] = 1, DFS(1);
	
	printf("%d", ans);
}

Measured memory_bytes: 1736
#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {

    int count,random,box,i,dice[6],plane[6];

    for(i=0;i<6;i++){
        cin >> plane[i];
    }
    
    for(i=0;i<6;i++){
        cin >> dice[i];
    }

    for(i=0;i<10000;i++){
        count=0;
        for(int j=0;j<6;j++){
            if(dice[j] == plane[j]){
                count++;
            }
        }
        if(count==6){
            cout << "Yes" << endl;
            break;
        }

    random = rand() % 4 + 1;

             if(random == 1){
                 box=plane[0];
                 plane[0]=plane[4];
                 plane[4]=plane[5];
                 plane[5]=plane[1];
                 plane[1]=box;
             }
             else if(random == 2){
                 box=plane[0];
                 plane[0]=plane[1];
                 plane[1]=plane[5];
                 plane[5]=plane[4];
                 plane[4]=box;
             }
             else if(random == 3){
                 box=plane[0];
                 plane[0]=plane[2];
                 plane[2]=plane[5];
                 plane[5]=plane[3];
                 plane[3]=box;
             }
             else if(random == 4){
                 box=plane[0];
                 plane[0]=plane[3];
               plane[3]=plane[5];
                 plane[5]=plane[2];
                 plane[2]=box;
             }
    }

    if(count != 6){
        cout << "No" << endl; 
    }
    
    return 0;
}

Measured memory_bytes: 1160