akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> P(N);


  pair<pair<string,int>,int> r[110];

  for(int i = 0; i < N; i++){
    cin >> S[i] >> P[i];
    r[i] = make_pair(make_pair(S[i],-P[i]),i);
  }

  sort(r,r + N);

  for(int i = 0; i < N; i++){
    cout << r[i].second + 1 << endl;
  }

  return 0;

  

}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
   int a,b;
   scanf("%d%d",&a,&b);
   if(a<b){
      printf("a < b\n");
   }else{ if(a>b){
      printf("a > b\n",a,b);
   }else{ 
      printf("a == b\n",a,b);
   }}
   return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

void evaluate(const string & s, int i, vector<int>& dst, const vector<int>& ref)
{
	if (i == 1) {
		FOR_LT(j, 0, s.size()) {
			if (s[j] == 'R') dst[j] = j + 1;
			if (s[j] == 'L') dst[j] = j - 1;
		}
		return;
	}

	FOR_LT(j, 0, s.size()) {
		dst[j] = ref[ref[j]];
	}
}

struct Process {
	int i;
	vector<int> dp;
};

vector<int> dp(100000);
vector<int> dp_val(100000);


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

	string s; cin >> s;

	vector<Process> process;

	int i = 1;
	while (i <= 100000) {
		evaluate(s, i, dp_val, dp);
		dp = dp_val;
		process.push_back({ i, dp });
		i *= 2;
	}
	i /= 2;

	auto it = process.end() - 1;
	while (i < 100000) {
		auto cur = process.begin();
		while (cur + 1 != process.end()) {
			if ((cur + 1)->i + it->i > 100000) break;
			cur++;
		}

		FOR_LT(j, 0, s.size()) {
			dp[j] = cur->dp[it->dp[j]];
		}

		i = it->i + cur->i;
		process.push_back({ i, dp });
		it = process.end() - 1;
	}

	vector<int> ans(s.size());
	vector<int>& last = process.back().dp;
	FOR_LT(j, 0, s.size()) {
		ans[last[j]]++;
	}

	FOR_LT(j, 0, s.size()) {
		cout << ans[j] << " ";
	}
	cout << endl;



	return 0;
}


Measured memory_bytes: 10448
from collections import defaultdict

def main():
    a = list(input())
    b = list(input())
    move_dic = defaultdict(str)

    flg = 1
    for i in range(len(a)):
        char_a = a[i]
        char_b = b[i]

        if char_a in move_dic:
            if move_dic[char_a] != char_b:
                flg = 0
                break
        else:
            move_dic[char_a] = char_b
    if len(list(move_dic.values())) != len(set(list(move_dic.values()))):
        flg = 0
    if flg:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 6960
#include <cstdio>
const int N = 3e5;
char s[N];

int main()
{
	scanf("%s", s);
	int res = 0;
	bool flag = true;
	for (int l = 0, r = 0; true; ++r)
		if (s[r] != s[l])
		{
			int run = r - l;
			if (run % 3 == 0)
				res += run * 2 / 3;
			if (run % 3 == 1)
				res += (run * 2 + 1) / 3, flag = true;
			if (run % 3 == 2)
				res += (run * 2 - 1) / 3, res += flag ^= true;
			if (!s[l = r])
				break;
		}
	printf("%d\n", res);
}

Measured memory_bytes: 384
#[cfg(debug_assertions)]
include! {"./debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

macro_rules! read {
    ([$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ([$t:ident]) =>
        (rl().split_whitespace().map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    (_, [$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!(_, [$t])).collect::<Vec<_>>());
    (_, [$t:ident]) =>
        (rl().split_whitespace().skip(1).map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    ($($t:ident),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ($t:ident) => (read_type!(rl(), $t));
    ($($t:ident),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(read_type!(w.next().unwrap(), $t)),*)
    }};
}

macro_rules! read_type {
    ($s:expr, chars) => {
        $s.chars().collect::<Vec<char>>()
    };
    ($s:expr, usize1) => {
        read_type!($s, usize) - 1
    };
    ($s:expr, $t:ty) => {
        $s.parse::<$t>().unwrap()
    };
}

fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

////////////////////////////////////////////////////////////////////////////////

fn main() {
    let (n, m) = read!(usize, usize);
    let s = read!(_, [usize1]; m);
    let p = read!([usize]);

    let s = s
        .iter()
        .map(|v| v.iter().map(|x| 1usize << x).fold(0usize, |x, y| x | y))
        .collect::<Vec<_>>();

    let ans = (0..1 << n)
        .filter(|sw| {
            (0..m).all(|lgt| {
                let l = sw & s[lgt];
                (0..n).filter(|i| l & (1usize << i) != 0).count() % 2 == p[lgt]
            })
        })
        .count();

    println!("{}", ans);
}


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

int main(){
  int k;
  string s;
  cin >> k >> s;
  
  int n=s.size();
  string ans="";
  if (k>=n) cout << s << endl;
  else {
    for (int i=0;i<k;++i){
      ans+=s[i];
    }
    string s1 = "...";
    string s2 = ans + s1;
    cout << s2 << endl;
  }
}

Measured memory_bytes: 3628
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 1000000007;
constexpr ll MOD = 1000003;


// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

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

vector<ll> fact(2*MOD), factinv(2*MOD);

ll exp(ll b, int e) {
    ll ans = 1;
    while (e) {
        if (e&1) ans *= b;
        ans %= MOD;
        e >>= 1;
        b *= b;
        b %= MOD;
    }
    return ans;
}

void pp(void) {
    fact[0] = 1;
    fact[1] = 1;
    for (int i=2;i<2*MOD;i++) {
        fact[i] = fact[i-1]*i % MOD;
    }
    factinv[0] = 1;
    factinv[1] = 1;
    for (int i=2;i<2*MOD;i++) {
        factinv[i] = exp(fact[i],MOD-2) % MOD;
    }
}

int main(void) {
    int Q;
    ll x, d, n;
    cin >> Q;
    pp();
    for (int i=0;i<Q;i++) {
        cin >> x >> d >> n;
        if (x == 0) cout << 0 << endl;
        else if (d == 0) cout << exp(x,n) << endl;
        else if (d == 1) {
            if (n >= MOD) cout << 0 << endl;
            else {
                ll ans = fact[(x+n-1) % (2*MOD)];
                cout << ans*factinv[x-1]%MOD << endl;
            }
        } else {
            if (n >= MOD) cout << 0 << endl;
            else {
                ll xd = x*exp(d,MOD-2)%MOD;
                if (xd == 0) cout << 0 << endl;
                else {
                    ll ans = fact[(xd+n-1)%(2*MOD)]%MOD;
                    ans = ans*factinv[xd-1]%MOD;
                    ans = ans*exp(d,n%MOD)%MOD;
                    cout << ans << endl;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 32128
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(int i=0;i<n;++i)
const int MOD=1e9+7;

long mpow(long x, long n){
    long ans=1;
    while(n!=0){
        if(n%2==1) ans=ans*x%MOD;
        x=x*x%MOD;
        n=n/2;
    }
    return ans;
}

long mfact(long n){
    long a=1;
    for(int i=2;i<=n;++i) a=a*i%MOD;
    return a;
}

long mcomb(long n,long m){
    if(n==0 && m==0) return 1;
    if(n<m || n<0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

int main(){
    long n;
    cin >> n;
    long a[n];
    F(n) cin >> a[i];
    sort(a,a+n);
    long mid=a[n-1]/2,maxi=0;
    for(int i=1;i<n;++i){
        if(abs(a[i]-mid)>abs(a[i-1]-mid)){
            maxi=i-1;
            break;
        }
    }
    cout << a[n-1] << " " << a[maxi] << endl;
    return 0;
}

Measured memory_bytes: 1024
class UnionFind:
    # 初期化
    def __init__(self, n_nodes):
        # 親要素のノード番号を格納する.
        # self.parent[x] == x の時，そのノードは根.
        self.parent = [i for i in range(n_nodes)]

        # 木の高さを格納する．
        self.rank = [0] * n_nodes

    # 検索. 根を返す.
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 一度調べた値は，根に繋ぎ直す.
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    # 併合.
    # 木の高さが低くなるように.
    # 親要素の書き換えは少ない方がいい
    def unite(self, x, y):
        # 根を探す．
        x = self.find(x)
        y = self.find(y)

        # 根が同じ場合はそのまま
        if x == y:
            return

        # 木の高さを比較し，低い方を高い方の根に貼る.
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
        else:
            self.parent[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    # 同じ集合に属するか判定
    def check(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
p = list(map(int, input().split()))

tree = UnionFind(N)

for _ in range(M):
    x, y = map(int, input().split())
    tree.unite(x - 1, y - 1)

ans = 0
for i in range(N):
    if tree.check(i, p[i] - 1):
        ans += 1

print(ans)


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

struct play{
	char team;
	int win;
	int lose;
};

bool cmp(play lhs, play rhs)
{
	if (lhs.win == rhs.win){
		return (lhs.lose < rhs.lose);
	}
	
	return (lhs.win > rhs.win);
	
}

int main()
{
	int n;
	
	while (cin >> n, n){
		vector<play> a(n, (play){' ', 0, 0});
		
		for (int i = 0; i < n; i++){
			cin >> a[i].team;
			for (int j = 0; j < n - 1; j++){
				int num;
				cin >> num;
				a[i].win += num == 0 ? 1 : 0;
				a[i].lose += num == 1 ? 1 : 0;
			}
		}
		
		sort(a.begin(), a.end(), cmp);
		
		for (int i = 0; i < n; i++){
			cout << a[i].team << endl;
		}
	}
	
	return (0);
}

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

int main(){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> score(n,0);
    for(int i=0; i<q; i++){
        int a;
        cin >> a;
        score[a-1]++;
    }
    for(int i=0; i<n; i++){
        if(k-(q-score[i])>0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1024
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
a =[0] +list(map(int, input().split()))
count =0
for i in range(1,N+1):
    if i %2 ==1:
        if a[i] %2 ==1:
            count +=1
print(count)

Measured memory_bytes: 9032
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int a, b, k;
	cin >> a >> b >> k;

	Int cnt = 0;
	for (Int i = 100; i > 0; i--) {
		if (a%i==0&&b%i==0) {
			cnt++;
			if (cnt==k) {
				cout << i << "\n";
				return 0;
			}
		}
	}

}


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

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

using namespace std;

typedef vector<int> vi;
typedef long long ll;

int main(){
	//freopen("test.txt", "r", stdin);
	int n, p;
	while(cin >> n >> p, n|p){
		vi v(n, 0);
		int turn = 0;
		while(1){
			if(p){
				p--;
				v[turn]++;
			}else{
				p = v[turn];
				v[turn] = 0;
			}
			if(!p){
				int cnt = 0;
				rep(i, n){
					cnt += (v[i]!=0);
				}
				if(cnt == 1)break;
			}
			turn = (turn+1)%n;
		}
		rep(i, n){
			if(v[i]) cout << i << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 1196
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

signed main(){
    int n,m;
    cin>>n>>m;
    V<int> deg(n,0);
    while(m--){
        int a,b;
        cin>>a>>b;
        a--;b--;
        deg[a]++;deg[b]++;
    }
    rep(i,n) cout<<deg[i]<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def splitSeries(s:str):
    result = []
    last = ""
    count = 0
    for c in s:
        if last == c:
            count+=1
        else:
            if last != "":
                result.append((last,count))
            last = c
            count = 1
    if last != "":
        result.append((last,count))
    return result



def solve(S: str, K: int):
    if len(S) == 1:
        print(K//2)
    else:
        count = 0
        series = splitSeries(S)
        sp = 0
        if len(series) > 1:
            for s in series:
                if s[1] > 1:
                    sp += s[1]//2
            count += sp * K
            if series[0][0] == series[-1][0]:
                count -= (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2)
            print(count)
        else:
            print(series[0][1]*K//2)
    return


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(S, K)

if __name__ == '__main__':
    main()


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)


int main(){
  int k;
  cin >> k;
  cout << k/2 * (k-k/2) << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n;
	cin>>n;
	map<int,int> x;
	for(int i=0;i!=n;++i){
		int k;
		cin>>k;
		++x[k];
	}
	int ans=0;
	for(auto i:x){
		if(i.second>i.first)
			ans+=i.second-i.first;
		else if(i.first>i.second)
			ans+=i.second;
	}
	cout<<ans;
}


Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_N 100

using namespace std;
typedef pair<int, int> ipair;

int N;
class restaurant {
public:
    string S;
    int p;
    int index;

    bool operator<(restaurant right) {
        if(S != right.S)
            return S.compare(right.S) < 0;
        else
            return p > right.p;
    }
};
restaurant rt[MAX_N];

int main(int argc, char **argv) {
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> rt[i].S >> rt[i].p;
        rt[i].index = i + 1;
    }

    sort(rt, rt + N);
    for(int i = 0; i < N; ++i) {
        cout << rt[i].index << endl;
    }
        
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {
    
    
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    set<int> s;
    rep(i,n)s.insert(a[i]);
    if(s.size()!=n)fin("NO");
    else fin("YES");
}


Measured memory_bytes: 10368
S = list(input())
T = list(input())
R1 = [-1]*26
R2 = [-1]*26
ans = "Yes"

for i in range(len(S)):
    s = ord(S[i])
    t = ord(T[i])
    if R1[s-97] >= 0:
        if R1[s-97] != t:
            ans = "No"
            break
    else:
        R1[s-97] = t
    if R2[t-97] >= 0:
        if R2[t-97] != s:
            ans = "No"
            break
    else:
        R2[t-97] = s

print(ans)

Measured memory_bytes: 6704
program ds
    implicit none
    integer(4) n,ntmp
    integer :: i=0,digit=0,tmp=0,sn=0
    
    read(*,*) n
    ntmp = n
    
    if(n<1 .or. 10**9<n)then
    else
        do i=0,9
        if(.not. n/(10**i)==0)then
            digit = digit + 1
        else
        endif
        enddo

        do i=0,digit
            tmp = ntmp/(10**(digit-i))
            sn = sn + tmp
            ntmp = ntmp - tmp*10**(digit-i)
        enddo

        if(mod(n,sn) == 0)then
            write(*,*) 'Yes'
        else
            write(*,*) 'No'
        endif
    endif

end program ds 

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int w, a, b;
	cin >> w >> a >> b;
	if ((a <= b && a + w >= b) || (a <= b + w && a + w >= b + w)) cout << 0 << endl;
	else if (a + w < b) cout << (b - (a + w)) << endl;
	else cout << (a - (b + w)) << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

N, A = map(int, raw_input().split())
ans = 10 ** 18

for num in range(1, 65):
    p = int(N ** (1.0 / num))
    ls = [p] * num
    pos = 0
    while True:
        cnt = 1
        for p in ls:
            cnt *= p
        if cnt >= N:
            break
        ls[pos] += 1
        pos += 1
        pos %= num
    ans = min(ans, sum(ls) + A * (num - 1))
print ans

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

string S, T;

void dfs(string &p, ll d) {
  if(d == 0) return;
  dfs(p, d - 1);
  REP(i, 0, T.length()) {
    p += T[i];
    dfs(p, d - 1);
  }
}

bool sub(string &p) {
  ll cnt = 0;
  REP(i, 0, S.length()) {
    if(S[i] == p[cnt]) cnt++;
  }
  return cnt == p.size();
}

int main(void) {
  cin >> S >> T;

  ll ans = 0;
  ll sum = 0;
  for(ll i = 1;; i++) {
    sum = sum * (T.length() + 1) + T.length();
    if(sum > S.length()) break;
    string p = "";
    dfs(p, i);
    // cerr << p << endl;

    if(sub(p)) ans = i;
  }
  cout << ans << endl;
}



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

namespace Contest
{


    class Program
    {

        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = input[0];
            var m = input[1];
            var k = input[2];

            input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long[] a = new long[input.Length];
            a[0] = input[0];
            var ans = a[0] <= k ? 1 : 0;
            int[] maxBooks = { 1, 1};
            for (int i = 1; i < input.Length; i++)
            {
                a[i] = a[i - 1] + input[i];
                if (a[i] <= k)
                {
                    ans = i + 1;
                    maxBooks[0] = i + 1;
                }
            }

            input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long[] b = new long[input.Length];
            b[0] = input[0];
            ans = b[0] <= k ? Math.Max(ans, 1) : ans;
            for (int i = 1; i < input.Length; i++)
            {
                b[i] = b[i - 1] + input[i];
                if(b[i] <= k)
                {
                    ans = Math.Max(ans, i + 1);
                    maxBooks[1] = i + 1;
                }
                
            }




            for (int i = 0; i < maxBooks[0]; i++)
            {

                for (int j = maxBooks[1] - 1; j >= 0; j--)
                {
                    if (a[i] + b[j] > k) continue;
                    else
                    {
                        ans = Math.Max(ans, i + j + 2);
                        maxBooks[1] = j + 1;
                        break;
                    }
                }
            }

            Console.WriteLine(ans);
            
        }
    }
}

Measured memory_bytes: 71756
#include<stdio.h>
int main()
{
    int h,w;
    scanf("%d%d",&h,&w);
    int i,j;
    int flag;
    while(h!=0||w!=0)
    {
        flag=1;
        for(i=0;i<h;i++)
        {
            for(j=0;j<w;j++)
            {
                if(flag==1) printf("#");
                else printf(".");
                flag=-flag;
            }
            printf("\n");
            if(w%2==0) flag=-flag;
        }
        printf("\n");
        scanf("%d%d",&h,&w);
    }
    return 0;
}



Measured memory_bytes: 2680
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n; cin >> n;
	vi a(n); rep(i,n) cin >> a[i];
	SORT(a);
	ll ans = 0;
	ll sum = 0;
	int mid;
	if(n%2==0){
		mid = n/2;
		rep(i,n){
			if(i<mid-1) sum -= 2*a[i];
			else if(i==mid-1) sum -= a[i];
			else if(i==mid) sum += a[i];
			else sum += 2*a[i];
		}
		ans = sum;
	}else{
		mid = n/2;
		rep(i,n){
			if(i<mid-1) sum -= 2*a[i];
			else if(i==mid-1) sum -= a[i];
			else if(i==mid) sum -= a[i];
			else sum += 2*a[i];
		}
		ans = max(ans,sum);
		sum = 0;
		mid = (n+1)/2;
		rep(i,n){
			if(i<mid-1) sum -= 2*a[i];
			else if(i==mid-1) sum += a[i];
			else if(i==mid) sum += a[i];
			else sum += 2*a[i];
		}	
		ans = max(ans,sum);			
	}
	cout << ans << endl;	
}


Measured memory_bytes: 640
use std::iter;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn walkDistFrom(graph: &Vec<Vec<i32>>, source: i32) -> Vec<i32> {
    fn go<'a>(graph: &Vec<Vec<i32>>, i: i32, prev: i32, depth: i32, vec: &'a mut Vec<i32>) -> &'a mut Vec<i32> {
        let targets = &graph[i as usize];
        for t in targets {
            if *t == prev {
                continue
            }

            vec[*t as usize] = depth;
            go(&graph, *t, i, depth+1, vec);
        }

        vec
    }

    let mut vec: Vec<i32> = iter::repeat(0).take(graph.len()).collect();
    vec[source as usize] = 0;

    go(&graph, source, -1, 1, &mut vec);
    vec
}

fn main() {
    input!{
        n: i32,
        abn: [[i32; 2]; n-1]
    }

    let mut graph: Vec<Vec<i32>> = iter::repeat(Vec::new()).take(n as usize).collect();

    for (i,val) in abn.iter().enumerate() {
        let a = val[0];
        let b = val[1];
        graph[(a-1) as usize].push(b-1);
        graph[(b-1) as usize].push(a-1);
    }

    let s = walkDistFrom(&graph, 0);
    let t = walkDistFrom(&graph, n-1);

    let mut count = 0;
    for i in 0..n-1 {
        if s[i as usize] <= t[i as usize] {
            count += 1;
        }
    }

    println!("{}", if count <= n - count { "Snuke" } else { "Fennec" });
}


Measured memory_bytes: 24444
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);
    String s = scanner.nextLine();
    scanner.close();

    if (s.charAt(s.length() - 1) != 's'){
      s = s + "s";
    } else {
      s = s + "es";
    }

    System.out.println(s);
  }
}

Measured memory_bytes: 26980
a, b, c, x, y = map(int, input().split())
ans = 0

def Cal(A, B, C, D, E): 
    if (A+B) >= 2*C:
        ans = min(2*C*E + A*(D-E), 2*C*D)
    else:
        ans = A*D+B*E
    return ans


if x >= y:
    ans = Cal(a, b, c, x, y)
else:
    ans = Cal(b, a, c, y, x)

print(ans)

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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    for (int i=A; i<=B; i++) {
        if (i<A+K) cout << i << "\n";
        else if (i>B-K) cout << i << "\n";
    }
}

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

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	std::vector<bool> possible(N);
	std::vector<int> counter(N, 1);
	possible[0] = true;
	for (int i{}; i < M; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--; y--;
		possible[y] = (possible[y] | possible[x]);
		counter[x]--;
		counter[y]++;
		if (counter[x] == 0) possible[x] = false;
	}
	printf("%d\n", std::count(possible.begin(), possible.end(), true));

	return 0;
}

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

using namespace std;
int main(){
    int n;
    cin >> n;
    int v[n],c[n];
    for(int i=0; i<n; i++){
       cin >> v[i];}
    for(int i=0; i<n; i++){
       cin >> c[i];}
    int sum=0;
    for(int i=0; i<n; i++){
       if(v[i]-c[i]>0){
          sum+=v[i]-c[i];
       }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        var n = int.Parse(Console.ReadLine());
        int[] t = new int[n];
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++)
        {
            int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            t[i] = tmp[0];
            x[i] = tmp[1];
            y[i] = tmp[2];
        }

        string ans = "Yes";
        for (int i = 0; i < n; i++)
        {
            if (t[i] < x[i] + y[i])
            {
                ans = "No";
            }

            if (t[i] % 2 == 0 && (x[i] + y[i]) % 2 != 0)
            {
                ans = "No";
            }
            else if (t[i] % 2 != 0 && (x[i] + y[i]) % 2 == 0)
            {
                ans = "No";
            }

            //一つ前との距離を図る
            if (i != 0 && t[i] - t[i-1]< Math.Abs(x[i] - x[i-1]) + Math.Abs(y[i] - y[i-1]))
            {
                ans = "No";
            }
        }

        Console.WriteLine(ans);

    }
}


Measured memory_bytes: 16352
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 405;

LL ans, ways, f[MAXN], tmp[4];
map <LL, int> cnt;
int n, a[MAXN][4];

inline LL Get(int a, int b, int c, int d)
{
	int e[4] = {a, b, c, d};
	LL ret = 1LL << 60;
	for (int i = 0; i < 4; i ++)
	{
		LL cur = 0;
		for (int j = 0; j < 4; j ++)
			cur = cur << 10 | e[i + j & 3];
		ret = min(ret, cur);
	}
	return ret;
}

inline int Get(LL x)
{
	if (x >> 20 == (x & (1 << 20) - 1))
	{
		if (x >> 30 == (x & (1 << 10) - 1))
			return 4;
		return 2;
	}
	return 1;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i <= n; i ++)
	{
		for (int j = 0; j < 4; j ++)
			a[i][j] = Read();
		cnt[f[i] = Get(a[i][0], a[i][1], a[i][2], a[i][3])] ++;
	}
	for (int i = 1; i <= n; i ++)
	{
		cnt[f[i]] --;
		for (int j = i + 1; j <= n; j ++)
		{
			cnt[f[j]] --;
			for (int k = 0; k < 4; k ++)
			{
				ways = 1;
				for (int l = 0; l < 4; l ++)
				{
					tmp[l] = Get(a[i][l + 1 & 3], a[i][l], a[j][k - l + 5 & 3], a[j][k - l + 4 & 3]);
					if (!cnt[tmp[l]])
						tmp[l] = -1, ways = 0;
					else
						ways *= cnt[tmp[l]] * Get(tmp[l]), cnt[tmp[l]] --;
				}
				ans += ways;
				for (int l = 0; l < 4; l ++)
					if (~tmp[l])
						cnt[tmp[l]] ++;
			}
			cnt[f[j]] ++;
		}
		cnt[f[i]] ++;
	}
	return printf("%lld\n", ans / 3), 0;
}


Measured memory_bytes: 80128
#include<stdio.h>
#include<iostream>
#include<numeric>
#include<cmath>
using namespace std;

int N;
long long T[100];
long long ans;

long long gcd(long long a, long long b){
  long long r;
  while((r = a%b)!=0){
    a = b;
    b = r;
  }
  return b;
}

long long lcm(long long a, long long b){
  return (a/gcd(a,b))*b;
}

long long getMiria(int i,long long hoge){
  long long tmp = lcm(T[i],hoge);
  if(i==N-1){
    return tmp;
  }
  return getMiria(i+1,tmp);
}

int main(){

  cin >> N;
  for(int i=0;i<N;i++){
    cin >> T[i];
  }
  cout << getMiria(0,1) << endl;
  return 0;
}

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

void swap(int& x, int& y){
    int t = x;
    x = y;
    y = t;
}
int main(){
    int height[10];
    //入力
    for(int i = 0;i < 10;i++){
        cin >> height[i];
        if(height[i] < 0 || height[i] > 10000){
            i--;
        }
    }
    //ソート
    for(int i = 0;i < 10;i++){
        for(int j = i;j > 0;j--){
            if(height[j] > height[j-1]){
                swap(height[j], height[j-1]);
            }
        }
    }
    //出力
    for(int i = 0;i < 3;i++){
        cout << height[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 3120
mod = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    dp[i][0] = dp[i-1][0]*2%mod

for i in range(1,N+1):
    for j in range(1,S+1):
        dp[i][j] = dp[i-1][j]*2%mod
        if j>=A[i-1]:
            dp[i][j] += dp[i-1][j-A[i-1]]

ans = dp[-1][-1]%mod
print(ans)

Measured memory_bytes: 132520
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
        int ans = 0;
        
        if(n == 1){
        System.out.println(n);             
        }else{
          ans = n * (1 + n) / 2;
          System.out.println(ans);   
        }

    }
}

Measured memory_bytes: 35568
a=int(input())
s=input()

if a>=3200:
  print(s)
else:
  print('red')
#L=list(map(int,input().split()))
#a,b=map(int,input().split())
#A=[[0 for i in range()] for j in range()]
#l = [int(input()) for i in range(N)]


Measured memory_bytes: 2940
from heapq import nsmallest


def get_add_list():
    cache = {}

    def add_list(s, t):
        global new_lists, removables
        l = t - s
        if l >= k:
            new_lists.append((s, t))

            if (s, t) in cache:
                removables.extend(cache[s, t])
                return

            cache[s, t] = nsmallest(l - k + 1, aaa[s:t])
            removables.extend(cache[s, t])

    return add_list


n, k, q = map(int, input().split())
aaa = list(map(int, input().split()))
srt = sorted(set(aaa))
lists = [(0, n)]
ans = float('inf')
add_list = get_add_list()
for a in srt:
    new_lists = []
    removables = []
    for s, t in lists:
        r = s
        for i, b in enumerate(aaa[s:t]):
            if a > b:
                add_list(r, s + i)
                r = s + i + 1
        add_list(r, t)
    if len(removables) < q:
        break
    removables.sort()
    ans = min(ans, removables[q - 1] - a)
    lists = new_lists

print(ans)


Measured memory_bytes: 11868
#include <iostream>
using namespace std;
const int INF=1e9;

int main() {
  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  int a[41], b[41], c[41];
  for (int i=1; i<=N; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  int dp[41][401][401];
  for (int i=0; i<=400; i++) {
    for (int j=0; j<=400; j++) {
      dp[0][i][j]=INF;
    }
  }
  dp[0][0][0]=0;
  for (int k=1; k<=N; k++) {
    for (int i=0; i<=400; i++) {
      for (int j=0; j<=400; j++) {
        dp[k][i][j]=dp[k-1][i][j];
        if (i>=a[k] && j>=b[k]) {
          dp[k][i][j]=min(dp[k][i][j],dp[k-1][i-a[k]][j-b[k]]+c[k]);
        }
      }
    }
  }
  int ans=INF;
  for (int i=0; i<=400; i++) {
    for (int j=0; j<=400; j++) {
      if (i*j==0) {
        continue;
      }
      if (i*Mb==j*Ma) {
        ans=min(ans,dp[N][i][j]);
      }
    }
  }
  if (ans==INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 25984
N, T = map(int, input().split())
c = []
t = []
for i in range(N):
    cn, tn = map(int, input().split())
    c.append(cn)
    t.append(tn)
count=0
for j in range(N):
    ans = min(c)
    if(t[c.index(ans)]>T):
        c[c.index(ans)] = 1001
        count+=1
    else:
        print(ans)
        break
if(count==len(c)):
    print('TLE')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int n;

void dfs(string s, char end){
    if(s.size() == n){
        cout << s << endl;
        return;
    }
    for(char i='a'; i<=end; i++){
        char nxt = end;
        if(i == end) nxt++;
        dfs(s+i, nxt);
    }
}

int main(){
    fastcin();

    cin >> n;
    dfs("", 'a');
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int n;
char s[5000020];
int a[5000020];
int f[5000020];
int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++) {
		if (s[i] == '1') {
			a[i] = a[i - 1];
		} else {
			a[i] = i;
		}
	}
	for (int i = 1; i <= n; i++) {
		f[i] = f[i - 1];
		if (s[i] == '1') {
			if (s[i - 1] == '0' && s[i - 2] == '1') {
				f[i] = max(f[i], f[a[i - 2]] + i - 2 - a[i - 2]);
				f[i] = max(f[i], f[a[i - 2] + 1] + i - 2 - (a[i - 2] + 1));
			}
			if (s[a[i] - 1] == '1') {
				f[i] = max(f[i], f[a[i] - 2] + i - a[i]);
			}
		}
	}
	printf("%d\n", f[n]);
	return 0;
}

Measured memory_bytes: 8448
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,m,a[100],b[100][100];
	int s[100];
	cin>>n>>m;
	for(int i=0;i<m;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		s[i]=0;
	for(int i=0;i<m;i++)
		for(int j=0;j<n;j++)
			cin>>b[i][j];
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(a[i]==b[i][j])
				s[j]+=1;
			else
				s[a[i]-1]+=1;
		}
	}
	for(int i=0;i<n;i++)
		cout<<s[i]<<endl;
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char s[100000];
cin>>s;
int len=strlen(s);
int count=0,a=0,b=0,c=0,d=0;
for(int i=0;i<len;i++)
{
if(i%2==0)
{
if(s[i]==49)
a++;
else
c++;
}
else
{
if(s[i]==49)
b++;
else
d++;
}
}
if(d>=b && d>=c &&d>=a)
{
count=len/2-d;
if(len%2==0)
count+=(len/2-a);
else
count+=(len/2+1-a);
}
else if(a>=b && a>=c &&a>=d)
{
count=len/2-d;
if(len%2==0)
count+=(len/2-a);
else
count+=(len/2+1-a);
}
else if(b>=d && b>=c &&b>=a)
{
count=len/2-b;
if(len%2==0)
count+=(len/2-c);
else
count+=(len/2+1-c);
}
else if(c>=b && c>=a &&c>=d)
{
count=len/2-b;
if(len%2==0)
count+=(len/2-c);
else
count+=(len/2+1-c);
}
cout<<count;
return 0;
}



Measured memory_bytes: 384
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef pair<int,int> P;
queue<P> q;
map<int,int> m;
map<int,int>::iterator ite;
int A,B,a[8],Q,n0,kaisu,dummy[9];
int* tens;
int main()
{
	tens=&dummy[1];
	tens[7]=1;
	for(int i=6;i>=-1;i--) tens[i]=tens[i+1]*10;
	m.insert(make_pair(1234567,0));
	q.push(P(1234567,0));
	while(!q.empty()){
		A=q.front().first;
		kaisu=q.front().second;
		q.pop();
		for(int i=0;i<8;i++) if( ( A/tens[i] ) % 10 == 0 ) n0 = i;
		if(n0<4){
			B = A - tens[n0+4]*( ( A/tens[n0+4] ) % 10) + tens[n0]*( ( A/tens[n0+4] ) % 10);
			ite=m.find(B);
			if(ite==m.end()){
				m.insert(make_pair(B,kaisu+1));
				q.push(P(B,kaisu+1));
			} 
		}
		
		if(4<=n0){
			B = A - tens[n0-4]*(( A/tens[n0-4] ) % 10)+ tens[n0]*(( A/tens[n0-4] ) % 10);
			ite=m.find(B);
			if(ite==m.end()){
				m.insert(make_pair(B,kaisu+1));
				q.push(P(B,kaisu+1));
			}
		}
		
		if(n0!=0&&n0!=4){
			B = A - tens[n0-1]*(( A/tens[n0-1] ) % 10)+ tens[n0]*(( A/tens[n0-1] ) % 10);
			ite=m.find(B);
			if(ite==m.end()){
				m.insert(make_pair(B,kaisu+1));
				q.push(P(B,kaisu+1));
			}
		}
		
		if(n0!=3&&n0!=7){
			B = A - tens[n0+1]*(( A/tens[n0+1] ) % 10) + tens[n0]*(( A/tens[n0+1] ) % 10);
			ite=m.find(B);
			if(ite==m.end()){
				m.insert(make_pair(B,kaisu+1));
				q.push(P(B,kaisu+1));
			}
		}
	}
	while(1){
		Q=0;
		for(int i=0;i<8;i++) {
			if(scanf("%d",&a[i])==EOF) return 0;
			Q+=tens[i]*a[i];
		}
		printf("%d\n",m[Q]);
	}
}

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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define rsrt(s) sort(s.rbegin(),s.rend())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    ll a,b,c,d;
    cin >> a >> b >> c >> d ;
    ll t1,t2,t3,t4;
    t1=max(a,b);
    t2=max(c,d);
    t3=min(a,b);
    t4=min(c,d);
    cout << max(t1*t2,max(t1*t4,max(t2*t3,t3*t4))) << endl;
    //---------------------------------
    
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

const ll N = 5e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

ll modfac[N];
ll modfacinv[N];
ll invsi[N];

void simake(){
	invsi[0]=1;
	invsi[1]=1;

	modfac[0]=1;
	modfac[1]=1;

	modfacinv[0]=1;
	modfacinv[1]=1;

	for(ll i=2;i<N;i++)
	{
		invsi[i] = mul(invsi[mod%i], (mod-(mod/i)));
		modfac[i] = mul(i, modfac[i-1]);
		modfacinv[i] = mul(invsi[i], modfacinv[i-1]);
	}
}

ll nCrm(ll n,ll r){
	if(n==r||r==0) return 1;
	if(n<r) return 1;
	return mul(mul(modfac[n], modfacinv[r]), modfacinv[n-r]);
}
ll nPrm(ll n,ll r){
	ll op;
	if(n==r||r==0) op = 1;
	if(n<r) return 0;
	op =  mul(mul(modfac[n], modfacinv[r]), modfacinv[n-r]);
	return mul(op, modfac[r]);
}

int main() {
	simake();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);

	ll n, m;
	cin>>n>>m;

	ll ans=0;
	
	for(int i=0;i<=n;i++){
		ll op = mul(nPrm(m, n), nPrm(m-i, n-i));
		op = mul(op, nCrm(n, i));
		if(i&1) ans = sub(ans, op);
		else ans = add(ans, op);
	}

	cout<<ans;
	

    return 0;
}


Measured memory_bytes: 15368
#include<stdio.h>

int M[100][100];
int p[101];
 
void m(int);
 
int main(){

  int i, n;

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++){ 
    scanf("%d %d", &p[i], &p[i+1]);
  }

  m(n);

  printf("%d\n", M[1][n]);

  return 0;

}

void m(int n){

  int i,j,b,a,q;

  for(i = 1 ; i < n + 1 ; i++){
    M[i][i] = 0;
  }

  for(a = 2 ; a < n + 1 ; a++){

    for(i = 1 ; i < n - a + 2 ; i++){

      j = i + a - 1;

      M[i][j] = 1000000000;

      for(b = i ; b < j ; b++){
	q = M[i][b] + M[b + 1][j] + p[i - 1] * p[b] * p[j];
	if(M[i][j] <= q) M[i][j] = M[i][j];
	else M[i][j] = q;
      }

    }

  }

}

Measured memory_bytes: 636
N = int(input())
s = []
Flag = True
for _ in range(N):
    p = int(input())
    s.append(p)
    if p % 10 != 0:
        Flag = False
if Flag:
    print("0")
    exit()

ans = sum(s)
if ans % 10 != 0:
    print(ans)
    exit()
else:
    s.sort()
    for val in s:
        if val % 10 == 0:
            continue
        ans -= val
        print(ans)
        exit()

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int n,a[100],i,j,box,sum,b;
	scanf("%d",&n);
	sum=0;
	b=0;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(a[i]<a[j]){
			box=a[i];
			a[i]=a[j];
			a[j]=box;
			}
		}
	}
	for(i=0;i<n;i++){
		if(i==0 || i%2==0){
			sum=sum+a[i];
		}
		if(!(i%2==0)){
			b=b+a[i];
		}
	}
	printf("%d\n",sum-b);
	return 0;
}

Measured memory_bytes: 128
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

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

	while (cin >> N >> M >> K, N) {
		int g = 0;
		g = gcd(g, N);
		g = gcd(g, M);
		g = gcd(g, K);
		N /= g, M /= g, K /= g;
		int a = MOD, b = MOD;
		for (long long int i = 0; i <= 100000; i++) {
			if ((i*N + K) % M == 0) {
				if (a + b > i + (i*N + K) / M) {
					a = i, b = (i*N + K) / M;
				}
				if (a + b == i + (i*N + K) / M) {
					if (a*N + b * M > i*N + i * N + K) {
						a = i, b = (i*N + K) / M;
					}
				}
			}
			if ((i*N - K) % M == 0) {
				if (a + b > i + abs(i*N - K) / M) {
					a = i, b = abs(i*N - K) / M;
				}
				if (a + b == i + abs(i*N - K) / M) {
					if (a*N + b * M > i*N + abs(i * N - K)) {
						a = i, b = abs(i*N - K) / M;
					}
				}
			}
		}
		cout << a << " " << b << endl;
	}
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    string s;
    cin >> s;
    map<char, int> mp;
    bool check = true;
    for (int i = 0; i < s.size(); i++){
        if (mp.find(s[i]) != mp.end()) check = false;
        else ++mp[s[i]]; 
    }
    if (check) cout << "yes" << endl;
    else cout << "no" << endl;
    return 0;
}

Measured memory_bytes: 256