akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vpll> vvpll;
typedef unordered_map<ll, ll> um;
typedef unordered_set<ll> us;

#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ts ll t; in(t) while (t--) solve();
#define ks ll t; in(t) FOR(i, 1, t+1) { cout << "Case #" << i << ": "; solve(); ln; }
#define endl '\n'
#define ln cout << endl;
#define in(x) cin >> x;
#define out(x) cout << x << endl;
#define flush cout << flush;
#define reset(a, b) memset(a, b, sizeof(a));
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FORI(i, a, b, c) for (ll i = a; i < b; i += c)
#define FORD(i, a, b) for (ll i = a; i > b; --i)
#define FOREACH(it, v, r) for (auto it = v.begin() + r; it != v.end(); it++)
#define FORALL(it, v) for (auto it : v)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define vin(v, x) vll v(x); FOR(i, 0, x) in(v[i])
#define all(v) v.begin(), v.end()
#define allr(v, r) v.begin(), v.begin() + r
#define showv(v) FORALL(it, v) cout << it << ' '; ln
#define printv(v) FORALL(it, v) out(it)
#define show2d(v) FORALL(it, v) { FORALL(j, it) cout << j << ' '; ln}
#define showm(v) FORALL(it, v) cout << it.F << ": " << it.S << ' '; ln
#define sortv(v) sort(all(v));
#define revv(v) reverse(all(v));
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))
#define gcd __gcd
#define checkbit(n, i) (n >> i) & 1               // check ith bit
#define bitcount __builtin_popcount               // count set bits
#define firstbitindex __builtin_ctz               // count trailing zeros
#define lastbitindex __builtin_clz                // count leading zeros
#define bitparity __builtin_parity                // check set bits are even or odd
#define findv(v, x) (find(all(v), x) != v.end())
#define findsm(u, x) (u.find(x) != u.end())
#define findstr(s, x) (s.find(x) != string::npos)
#define sz(a) a.size()
#define precise(x) cout << fixed << setprecision(x);

const ll MAXN = 1e5 + 1, MOD = 998244353, SIZE = 2e7, INF = 0x7f7f7f7f7f7f7f7f;
const double EPS = 1e-9, PI = acos(-1);
const int INFi = 0x7f7f7f7f;

//<<------Declare Variables Here----->>//
double n;

//<<-----Implement Functions Here---->>//
void solve()
{
	cin >> n, out(ceil(n / 1000) * 1000 - n)
}

//<<----------Start of Main---------->>//
int main()
{
	fastio
	precise(0)
	//ts
	solve();
    return 0;
}

Measured memory_bytes: 3800
function main(input) {
    var a = input[0].split(" ")[0]-0;
    var b = input[0].split(" ")[1]-0;
    var c = input[0].split(" ")[2]-0;
    var ans = 0;
    var max = Math.max(Math.max(a,b),c);
    if(b==max){
        b = a;
        a = max;
    }else if(c==max){
        c = a;
        a = max;
    }
    ans += a-Math.max(b,c);
    if((a - ans - Math.min(b,c))%2 == 0){
        ans += (a-ans-Math.min(b,c))/2;
    }else{
        ans += ~~((a-ans-Math.min(b,c))/2)+2;
    }
    console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


//1 2 3 4 5 6


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

struct edge { int to, cost; };

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	cout << (a == b && b == c ? "Yes" : "No") << endl;
	return 0;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mk make_pair
#define pb push_back
#define pf push_front
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, M, A[10], C[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
char S[10];
string dp[10010];

signed main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> A[i];
    }
    sort(A, A + M, greater<int>() );
    for(int i = 0; i < 10; i++){
        S[i] = '0' + i;
        //printf("%d %c\n", i, S[i]);
    }
    for(int i = 0; i < M; i++){
        int num = A[i];
        int cost = C[num];
        char add = S[num];
        //printf("%d %d %d %c\n", i, num, cost, add);
        for(int j = 0; j <= N; j++){
            if(j - cost >= 0){
                string s = dp[j - cost];
                string t = dp[j];
                if(j - cost != 0 && !s.size())continue;
                s += add;
                //printf("%d,%d ", i, j);
                //cout << s << endl;
                if(s.size() > t.size()){
                    dp[j] = s;
                }
                else if(s > t && s.size() == t.size()){
                    dp[j] = s;
                }
            }
        }
    }
    cout << dp[N] << endl;



    return 0;
}
/*

*/




Measured memory_bytes: 43264
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N := getInt()
	x := (N + 999) / 1000
	x *= 1000
	out(x - N)
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
# define lli long long int

int main(){
	lli i,j,k=0,l,n,m;
	cin >> n >> m;
	string s1="",s2="";
	char d=n+'0';
	char e=m+'0';
	for(i=0;i<m;i++){
s1=s1+d;
	}
	for(i=0;i<n;i++){s2=s2+e;
	}
	cout << min(s1,s2);
			return 0;
}



Measured memory_bytes: 256
Identification Division.
Program-ID. caddi2018d.

Data Division.
Working-Storage Section.

77 n pic 9(6).
77 a pic 9(10).
77 e pic 9 value zero.

Procedure Division.

accept n.

perform n times
  accept a
  if function mod(a 2) not= zero
    move 1 to e
    exit perform
  end-if
end-perform.

if e = 0
  display 'second'
else
  display 'first'
end-if.

stop run.


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using ll = long long;

ll n;
ll res = 0;

void dfs(ll num, ll a, ll b, ll c) {
	if (num>n) return;
	if (a&&b&&c) res++;
	dfs(num*10+3, 1, b, c);
	dfs(num*10+5, a, 1, c);
	dfs(num*10+7, a, b, 1);
}

int main() {
	cin >> n;
	dfs(0, 0, 0, 0);
	cout << res << endl;
}

Measured memory_bytes: 3572
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!(
    n: usize,
    m: usize,
    );
    let ns = if n > 1 {n * (n-1) / 2} else { 0 };
    let ms = if m > 1 {m * (m-1) / 2} else { 0 };
    print!("{}", ns+ms)
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>


int main(){
  int a,b,c;
  scanf("%d %d",&a,&b);
  c = a + b;
    if(c%2 == 1){
      c = c + 1;
    }
  printf("%d\n",c/2);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}
// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000
#define QUERY_MAX 50000
#define INF ((1e+9)+1)

int asc(const void *a1, const void *a2) {
    return *(int*)a1 - *(int*)a2;
}

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX+1];
    fget_array(arr, num);
    int qs = get_int();
    static int queries[NUM_MAX+1];
    fget_array(queries, qs);
    qsort(queries, qs, sizeof(int), asc);
    arr[num] = queries[qs] = INF;

    int k;
    int nidx = 0;
    int qidx = 0;
    int size = num + qs;
    int ans = 0;
    int prev = -1;
    for(k = 0; k < size; k++) {
        ans += (prev != arr[nidx] && arr[nidx] == queries[qidx]);
        if(arr[nidx] < queries[qidx]) {
            prev = arr[nidx];
            nidx++;
        } else {
            qidx++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2352
N,C=map(int,input().split())
from collections import defaultdict
Cbef=defaultdict(int)
time=defaultdict(int)
TV=[tuple(map(int,input().split())) for i in range(N)]
TV.sort(key=lambda x:x[0])
for s,t,c in TV:
    if Cbef[c]==s:
        time[s]+=1
        time[t]-=1
        Cbef[c]=t
    else:
        time[s-1]+=1
        time[t]-=1
        Cbef[c]=t
ans=0
now=time[0]
ans=now
for i in range(1,10**5+1):
    now+=time[i]
    ans=max(ans,now)
print(ans)

Measured memory_bytes: 27716
#include <stdio.h>
int main ()
{
	int i,n,np=0;
	float z;
	scanf("%d",&n);
	if(n%2==0)
	{
		np=n/2;
	}
	else if(n%2==1)
	{
		np=n/2+1;
	}
	z=(float)np/n;
	printf("%f",z);
}


Measured memory_bytes: 128
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void) {

	int sx = 0, sy = 0, tx = 0, ty = 0;
	cin >> sx >> sy >> tx >> ty;
	long long int A = 0, B = 0;

	A = sx*sy;
	B = tx*ty;

	if (A > B)
		cout << A << endl;
	if (A <= B)
		cout << B << endl;
	return 0;




}

Measured memory_bytes: 256
from collections import defaultdict

def yakusuu(i):
    res = list()
    for j in range(1, i+1):
        if i % j == 0:
            res.append(j)
    return res


k = int(input())

x = [[]]
for i in range(1, k+1):
    x.append(yakusuu(i))

s = 0
for i in range(1, k+1):
    for j in range(1, k + 1):
        y = list()
        for xx in x[i][-1::-1]:
            if xx in x[j]:
                y.append(xx)
        for k in range(1, k+1):
            for xx in y:
                if xx in x[k]:
                    s += xx
                    break

print(s)


Measured memory_bytes: 9488
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

// 最大公約数
// a > b
int gcd(int a, int b)
{
	if (a%b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a%b));
	}
}

int main(){
	long long count = 0;
	int K;
	cin >> K;

	int tmp;
	for (int i=1; i<=K; ++i){
		for (int j=1; j<=K; ++j){
			tmp = gcd(i, j);
			for (int k=1; k<=K; ++k){
				count += gcd(tmp, k);
			}
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
#include <climits>
#include <bitset>

#include <stack>
#include <queue>
// #include <deque>
#include <set>
#include <map>
#include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;


typedef long long ll;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef pair<int,long long> pil;
typedef pair<long long,int> pli;
typedef vector<vector<long long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef priority_queue<int, vector<int>, greater<int> > minq;
typedef priority_queue<int> maxq;
// to initialize PQs with a vector, do 
// minq(v.begin(),v.end()) or maxq(v.begin(),v.end())
// or minq(a,a+10) for arrays

#define emplace_back pb
const char el = '\n';


/*
Edge cases:



*/

//makes x, y equal to such that ax+by = gcd(a,b)
ll gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}


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

    ll a,b, n; cin>>a>>b>>n; cin.ignore();

    //for all x >= b, diff is zero;

    cout<< (a*min(n,b-1))/b <<el;

    // cout<<"working with special x = "<<x<<el;
    // cout<<a<<" times "<<x<<" equals "<<(a*x)%b<<" mod "<<b<<el;


    // cout<<"diff equals "<<diff<<el;



}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N, K;
	cin >> N >> K;
	double ans = 0.0;
	for (int i = 1; i <= N; i++) {
		double num = 1.0 / N;
		int tmp = i;
		while (tmp < K) {
			num /= 2;
			tmp *= 2;
		}
		ans += num;
	}
	printf("%.10f\n", ans);
}

Measured memory_bytes: 256
/*													   *********************
													   	     I. COINS	
													   *********************                   Atharva Tripathi                                 */
													   
import java.util.*;
import java.io.*;
public class Main
{
	static int mod=(int)(1e9+7);
	public static class pair
	{
		int x;
		int y;
		public pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}
	}
	
	public static void main(String args[]) throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		String input[]=br.readLine().split(" ");
		double pheads[]=new double[n];
		for(int i=0;i<n;i++)
			pheads[i]=Double.parseDouble(input[i]);
		
		double dp[][]=new double[n+1][n+1];
		dp[1][0]=1.0-pheads[0];
		dp[1][1]=pheads[0];
		
		for(int i=2;i<=n;i++)
		{
			for(int j=0;j<=i;j++)
			{
				if(j!=0)
					dp[i][j]=dp[i-1][j]*(1-pheads[i-1])+dp[i-1][j-1]*pheads[i-1];
				else
					dp[i][j]=dp[i-1][j]*(1-pheads[i-1]);
			}
		}
		
		double ans=0.0;
		for(int i=(n/2+1);i<=n;i++)
			ans+=dp[n][i];
		
		System.out.println(ans);
		
		
	}
}

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

using namespace std;
int a,b,c,d,q;
string s,t;
int ss[100005],tt[100005];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> s >> t;
    s = " " + s;
    t = " " + t;
    for (int i=1; i<(int)s.size(); ++i)
        ss[i] = ss[i-1] + 2 - (s[i]=='A');
    for (int i=1; i<(int)t.size(); ++i)
        tt[i] = tt[i-1] + 2 - (t[i]=='A');
    cin >> q;
    while (q--)
    {
        cin >> a >> b >> c >> d;
        if (((ss[b] - ss[a-1])%3) == ((tt[d] - tt[c-1])%3))
            cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

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

    const vector<int> coins = {500, 100, 50, 10, 5, 1};
    int N;
    while (cin >> N, N) {
        N = 1000 - N;
        int ans = 0;
        for (auto c : coins) {
            int tmp = N / c;
            ans += tmp;
            N -= tmp * c;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3104
N, M = (int(i) for i in input().split())
A = [0] * N
K = [0] * N
for n in range(N):
    A[n] = [int(i) for i in input().split()]
    K[n] = A[n][0]
    A[n] = A[n][1:]
K
A
ans = set(A[0])
for a in A[1:]:
     ans = ans & set(a)
print(len(ans))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
# define int long long int
const int N=2*1e6+10;
vector<int> fact;

const int mod=1e9+7;

//Using binary exponentiation to calculate x^n in log(n) time.
int binExp(int base, int power)
{
    int x = 1;
    while(power)
    {
        if(power%2 == 1)
            x = ((x % mod) * (base % mod)) % mod;
        base  = ((base % mod) * (base % mod)) % mod;
        power = power / 2;
    }
    return x;
}

int facto(int num)
{
    int result = 1;
    for(int i=1; i<=num; ++i)
    {
        result = ((result % mod) * (i % mod)) % mod;
    }
    return result;
}

int calculate_nCi(int N, int i)
{
    //nCi = ( n! ) / (( n-i )! * i!)
    // int nfact = fact(N);
    // int ifact = fact(i);
    // int dfact = fact(N-i);
    int nfact = fact[N];
    int ifact = fact[i];
    int dfact = fact[N-i];
    // Using Euler's theorem of 
    // Modular multiplicative 
    // inverse to
    // find the inverse of a number.
    // (1/a)%mod=a^(m−2)%mod
    int inv_ifact = binExp(ifact, mod-2);
    int inv_dfact = binExp(dfact, mod-2);

    int denm = ((inv_ifact % mod) * (inv_dfact % mod)) % mod;

    int answer = ( (nfact % mod) * (denm % mod)) %mod;
    return answer;
}

void solve(int N, int s, int k)
{
    //Number of ways to form all possible strings
    int allWays = binExp(26,N);

    //Number of ways to form strings that don't 
    //contain the input string as a subsequence.
    int noWays = 0;

    for(int i=0; i<s; ++i)
    {
        //to calculate nCi 
        int nCi = calculate_nCi(N,i);
        //selecting the remaining characters
        // 25 ^ (N-i)
        int remaining = binExp(25, N-i);

        int multiply = ( (nCi % mod) * (remaining % mod)) % mod;

        noWays = ( (noWays % mod) + (multiply % mod)) % mod;
    }

    //Answer is the difference of
    //allWays and noWays
    int answer = ((allWays % mod) - (noWays % mod)) % mod;

    if(answer < 0)
        answer += mod;

    cout<<answer;
}

void preprocess()
{
    fact[0]=1;
    for(int i=1; i<N; ++i)
        fact[i] = ((fact[i-1]%mod) * (i%mod))%mod;
}

int32_t main()
{
    fact = vector<int>(N);
    preprocess();
    //string str = "abc";
    //int k = 2;
    int k; string str; cin>>k>>str;
    int s = str.length();
    int N = s + k;
    solve(N,s,k);
}


Measured memory_bytes: 20952
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
 
class Main {
    
    public static void main(String[] args) throws IOException {
    	String[] s = in.nextLine().split(" ");
    	Arrays.sort(s);
    	sop(Integer.parseInt(s[2] + s[1]) + Integer.parseInt(s[0]));
    }
    
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        char nextChar() {
            return in.next().charAt(0);
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    
    static FastReader in = new FastReader();
    static OutputStream out = new BufferedOutputStream(System.out);
    
    public static byte[] toByte(Object o) {
        return String.valueOf(o).getBytes();
    }
    
    public static void sop(Object o) {
        System.out.print(o);
    }
} 

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

typedef long long ll;

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

int main() {
    int N,C;
    cin >> N >> C;
    
    vector<vector<int>> D(C,vector<int>(C));
    for ( int i = 0; i < C; ++i){
        for ( int j = 0; j < C; ++j){
            cin >> D[i][j];
        }
    }
    vector<vector<int>> c(N,vector<int>(N));
    vector<int> X(30,0),Y(30,0),Z(30,0);
    for ( int i = 0; i < N; ++i){
        for ( int j = 0; j < N; ++j){
            int cc;
            cin >> cc;
            c[i][j] = cc - 1;
            if ( (i+j)%3 == 0 ) X[c[i][j]] = X[c[i][j]] + 1;
            else if ( (i+j)%3 == 1 ) Y[c[i][j]] = Y[c[i][j]] + 1;
            else Z[c[i][j]] = Z[c[i][j]] + 1;
        }
    }
    
    ll ans = 1e+15;
    for ( int x = 0; x < C; ++x){
        for ( int y = 0; y < C; ++y){
            for ( int z = 0; z < C; ++z){
                if ( x == y or y == z or z == x ) continue;
                ll ans_sub = 0;
                for ( int i = 0; i < C; ++i ) {
                    ans_sub = ans_sub + X[i] * D[i][x];
                }
                for ( int i = 0; i < C; ++i ){
                    ans_sub = ans_sub + Y[i] * D[i][y];
                }
                for ( int i = 0; i < C; ++i ){
                    ans_sub = ans_sub + Z[i] * D[i][z];
                }
                chmin(ans,ans_sub);
            }
        }
    }
    
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4612
#include<stdio.h>
int main(void){
   int A, B, C, D, P, X, Y;
   scanf("%d %d %d %d %d", &A, &B, &C, &D, &P);
   X = P * A;
   if ( P <= C) Y = B;
   else Y = B + ( P - C ) * D;
   if ( X < Y ) printf("%d\n", X);
   else printf("%d\n", Y);
   return 0;
}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

static int dp[ 1000001 ];
static bool is_pm[ 1000001 ];
static int n, m;
static VI _array;

int solve( int now, int many ) {
	if ( dp[ many ] >= 0 ) {
		return dp[ many ];
	}
	if ( now == n ) {
		if ( is_pm[ many ] ) {
			return dp[many] = many;
		}
		return dp[many] = 0;
	}
	int res = 0;
	for ( int i = 0; many + _array[ now ] * i <= m; i++ ) {
		res = max( res, solve( now + 1, many + _array[ now ] * i ) );
	}
	return dp[ many ] = res;
}

int main() {
	NCLR( is_pm );
	for ( int i = 2; sq( i ) <= 1000000; i += 2 ) {
		if ( is_pm[ i ] ) {
			for ( int j = i * i; j <= 1000000; j += i ) {
				is_pm[ j ] = false;
				if ( i != 2 ) {
					j += i;
				}
			}
		}
		if ( i == 2 ) {
			--i;
		}
	}
	is_pm[ 0 ] = is_pm[ 1 ] = false;
	while ( ~scanf( "%d %d", &n, &m ) && n && m ) {
		_array.resize( n );
		for ( int i = 0; i < n; i++ ) {
			scanf( "%d", &_array[ i ] );
		}
		sort( _array.rbegin(), _array.rend() );
		_array.erase( unique( _array.begin(), _array.end() ), _array.end() );
		n = _array.size();
		NCLR( dp );
		int ans = solve( 0, 0 );
		if ( ans ) {
			printf( "%d\n", ans );
		}
		else {
			printf( "NA\n" );
		}
	}
	return 0;
}

Measured memory_bytes: 6096
local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1], x) then return 1 end
  if comp(ary[num], x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = (min + max) // 2
    if comp(ary[mid], x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n = io.read("*n")
local stage = {1}
local stagenum = {io.read("*n")}
local stagesum = {stagenum[1]}
local stageaddcnt = {1}
for i = 2, n do
  local a = io.read("*n")
  local pos = lower_bound(stagenum, a)
  if #stagenum < pos then
    table.insert(stage, i)
    table.insert(stagenum, a)
    table.insert(stagesum, a)
    table.insert(stageaddcnt, 1)
  else
    stagesum[pos] = stagesum[pos] + a
    stageaddcnt[pos] = stageaddcnt[pos] + 1
  end
end
local ret = {}
for i = 1, n do
  ret[i] = 0
end

for i = #stagesum, 2, -1 do
  local dst_i = stage[i]
  local num = stagenum[i]
  local sum = stagesum[i]
  local addcnt = stageaddcnt[i]
  ret[dst_i] = sum - addcnt * stagenum[i - 1]
  stageaddcnt[i - 1] = stageaddcnt[i - 1] + addcnt
  stagesum[i - 1] = stagesum[i- 1] + stagenum[i - 1] * addcnt
end
ret[1] = stagesum[1]

print(table.concat(ret, "\n"))


Measured memory_bytes: 17888
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

struct TopologicalSort {
private:
    int V;
    int E;
public:
    vector<vector<int>> table;

    TopologicalSort(int v, int e) {
        V = v;
        E = e;
        table.resize(v);
    }

    void add_edge(int from, int to) {
        table[from].push_back(to);
    }

    // if the size of vector is less than V, this graph is cyclic
    vector<int> sort() {
        vector<int> sorted_nodes;
        stack<int> st;

        vector<int> indegree(V, 0);
        for (int i = 0; i < V; i++) {
            for (int to : table[i]) {
                indegree[to]++;
            }
        }

        for (int i = 0; i < V; i++) {
            if (indegree[i] == 0) st.push(i);
        }

        while (st.size() > 0) {
            int popped = st.top();
            st.pop();

            sorted_nodes.push_back(popped);

            for (int to : table[popped]) {
                indegree[to]--;
                if (indegree[to] == 0) st.push(to);
            }
        }

        return move(sorted_nodes);
    }
};

signed main() {
    int N, M;
    cin >> N >> M;
    TopologicalSort ts(N, M);
    for (int i = 0; i < M; i++) {
        int from, to;
        cin >> from >> to;
        from--; to--;
        ts.add_edge(from, to);
    }

    vector<int> nodes = ts.sort();
    vector<int> dis(N, 0);

    for (int node : nodes) {
        for (int to : ts.table[node]) {
            dis[to] = max(dis[to], dis[node] + 1);
        }
    }

    int ret = -1;
    for (int i = 0; i < N; i++) {
        ret = max(ret, dis[i]);
    }

    cout << ret << endl;
}

Measured memory_bytes: 7672
import java.util.*;
import java.io.*;

class Main{
    static long MOD=1000000007;
    static long[] pow3;
    static char[] d;
    static int l;
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        d=fsc.next().toCharArray();
        l=d.length;
        fsc.close();
        pow3=new long[l+1];
        for(int i=0;i<=l;i++){
            if(i==0) pow3[i]=1;
            else if(i==1) pow3[i]=3;
            else pow3[i]=(pow3[i/2]*pow3[i-i/2])%MOD;
        }
        System.out.println(solve(0));
    }
    static long solve(int k){
        long res=0;
        if(k==l) return 1;

        if(d[k]=='1'){
            res+=pow3[l-k-1];
            res+=2*solve(k+1);
        }
        else res+=solve(k+1);
        res%=MOD;
        return res;
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}

Measured memory_bytes: 34132
#include<bits/stdc++.h>
#define ll long long
#define nes ios_base :: sync_with_stdio(0); cin.tie(0);
using namespace std;
const ll mo=1e9+7;
ll mod(ll n){
	return (n+mo)%mo;
}
int main(){
	nes;
	int n;
	cin>>n;
	vector<pair<int,int>>v(n);
	for(int i=0;i<n;++i){
		cin>>v[i].first;
		cin>>v[i].second;
	}
	int count=0;
	for(int i=0;i<n;++i){
		if(v[i].first==v[i].second) ++count;
		if(count>=3){
			cout<<"Yes";return 0;
		}
		if(v[i].first!=v[i].second) count=0;
	}
	if(count>=3) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <utility>
#include <limits>

class CDelta
{
public:
    CDelta() = delete;
    CDelta(int dx, int dy, int dCost)
        : m_dX(dx), m_dY(dy), m_dCost(dCost)
    {};

    int GetDx() const { return m_dX; }
    int GetDy() const { return m_dY; }
    int GetDCost() const { return m_dCost; }
private:
    int m_dX;
    int m_dY;
    int m_dCost;
};

int main()
{
    int h, w;
    std::cin >> h >> w;
    int gx, gy;
    std::cin >> gy >> gx;
    --gx;
    --gy;

    int x, y;
    std::cin >> y >> x;
    --x;
    --y;

    std::vector<std::vector<bool>> isRoad(h, std::vector<bool>(w, false));

    for (auto& r : isRoad)
    {
        std::string row;
        std::cin >> row;
        for (size_t index = 0; index < r.size(); ++index)
        {
            r[index] = (row[index] == '.');
        }
    }

    constexpr auto UNREACHABLE = std::numeric_limits<int>::max();
    std::vector<std::vector<int>> warpCount(h, std::vector<int>(w, UNREACHABLE));
    // bfsで検索
    std::deque<std::pair<int, int>> q;
    q.push_back(std::make_pair(x, y));
    warpCount[y][x] = 0;
    while (!q.empty())
    {
        auto pos = q.front();
        const auto cx = pos.first;
        const auto cy = pos.second;
        q.pop_front();

        // 移動チェック
        auto checkAndPush = [&](int x, int y, int penalty)
        {
            if (x < 0 || w <= x)
            {
                return;
            }

            if (y < 0 || h <= y)
            {
                return;
            }

            if (!isRoad[y][x])
            {
                return;
            }

            const auto cost = warpCount[cy][cx] + penalty;
            if (warpCount[y][x] > cost)
            {
                warpCount[y][x] = cost;
                if (penalty > 0)
                {
                    q.push_back(std::make_pair(x, y));
                }
                else
                {
                    q.push_front(std::make_pair(x, y));
                }
            }
        };

        static const std::vector<CDelta> wd = {
            // 徒歩
            CDelta(0, -1, 0),
            CDelta(-1, 0, 0), CDelta(1, 0, 0),
            CDelta(0, 1, 0),
            // ワープ
            CDelta(-2, -2, 1), CDelta(-1, -2, 1), CDelta(0, -2, 1), CDelta(1, -2, 1), CDelta(2, -2, 1),
            CDelta(-2, -1, 1), CDelta(-1, -1, 1), CDelta(1, -1, 1), CDelta(2, -1, 1),
            CDelta(-2, 0, 1), CDelta(2, 0, 1),
            CDelta(-2, 1, 1), CDelta(-1, 1, 1), CDelta(1, 1, 1), CDelta(2, 1, 1),
            CDelta(-2, 2, 1), CDelta(-1, 2, 1), CDelta(0, 2, 1), CDelta(1, 2, 1), CDelta(2, 2, 1)
        };

        for (const auto& dt : wd)
        {
            checkAndPush(cx + dt.GetDx(), cy + dt.GetDy(), dt.GetDCost());
        }
    }

    if (warpCount[gy][gx] == UNREACHABLE)
    {
        std::cout << -1;
    }
    else
    {
        std::cout << warpCount[gy][gx];
    }

    return 0;
}

Measured memory_bytes: 7816
#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 h,w;cin>>h>>w;
    while(h&&w){
        for(int i=0;i<h;i++){
            if(!(i==0||i==h-1)){
                for(int j=0;j<w;j++)
                if(j==0||j==w-1)cout<<'#';
                else cout<<'.';
            }
            else for(int j=0;j<w;j++)
            cout<<'#';
            cout<<endl;
        }
        cin>>h>>w;
        cout<<endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

































Measured memory_bytes: 3180
while True:
	try:
		while True:
			ints = raw_input()
			if ints != '':
				x = map(int,ints.split(' '))
				x.sort()
				a = x[1]
				b = x[0]
				while True:
					m=a%b
					if m!=0:
						a=b
						b=m
						continue
					else:
						break
				n = x[1]*x[0]/b
				print b,n
				continue
			else:
				break
	except: break

Measured memory_bytes: 4228
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	
	double x;
	
	cin>>x;
	double M=x,m=x;
	
	while(cin>>x){
		if(M<x)M=x;
		if(m>x)m=x;
	}
	
	cout<<M-m<<endl;
	return 0;
}

Measured memory_bytes: 0
# coding: utf-8
# 64
import math

a,b,c = map(float,input().split())
SC = math.sin(math.radians(c))
CC = math.cos(math.radians(c))
s = a**2+b**2-2*a*b*CC
S = math.sqrt(s)
print(0.5*a*b*SC)
print(a+b+S)
print(b*SC)



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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  double a, b; cin >> a >> b;
  printf("%.10f\n", a / b);
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int n, m, mx, t;
string a;
int main()
{
	int i, j;
//	freopen ("input.txt", "r", stdin);
	cin >> n >> m;
	mx = 0;
	for (i = 0; i < n; i++) {
		cin >> a;
		t = 0;
		for (j = 0; j < a.size(); j++) {
			if (a[j] == '#' && j < mx) {
				cout << "Impossible";
				return 0;
			}
			if (a[j] == '.' && j == mx) {
				cout << "Impossible";
				return 0;
			}
			if (a[j] == '#') t = j;
		}
		mx = t;
	}
	if (mx != m - 1) {
		cout << "Impossible";
		return 0;
	}
    cout << "Possible" << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect
INF = 10 ** 9 + 7
N, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aset = set(a)
bset = set(b)
ablst = [0] * ((N * M) + 1)
a.sort(), b.sort()

if len(aset) != len(a) or len(bset) != len(b):
    print(0)
    exit()

for i in range(N):
    ablst[a[i]] += 1

for j in range(M):
    ablst[b[j]] += 1

ans = 1
for i in range(N * M, 0, -1):
    ac = bisect.bisect_left(a, i)
    bc = bisect.bisect_left(b, i)
    if ablst[i] == 2:
        ans *= 1
    elif ablst[i] == 1 and ac < N and a[ac] == i:
        ans *= (M - bc)
    elif ablst[i] == 1 and bc < M and b[bc] == i:
        ans *= (N - ac)
    else:
        ans *= (N - ac) * (M - bc) - (N * M - i)
    ans %= INF
print(ans % INF)


Measured memory_bytes: 10996
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N;
    cin >> N;
    
    int S1[100],S2[100],ans[100],all=0;
    
    int W[100] = {};
    for(int i=1;i<=N;i++){
        cin >> W[i];
        all += W[i];
    }
    
    S1[0] = 0;
    
    for(int i=1;i<=N;i++){
        S1[i]= S1[i-1] + W[i];
        S2[i]= all - S1[i];
        ans[i] = abs(S1[i]-S2[i]);
    }
    
    int MIN = 2147483647;
    for(int i=1;i<=N;i++){
        MIN = min(MIN,ans[i]);
    }

    cout << MIN << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
 
using namespace std;
 
class Octahedra{
public:
    vector<int> x;
 
    Octahedra(){
	x.resize(8);
    }
   
    void rollLR(){
	int tmp = x[0];
	x[0] = x[3];
	x[3] = x[4];
	x[4] = x[1];
	x[1] = tmp;
 
	tmp = x[7];
	x[7] = x[6];
	x[6] = x[5];
	x[5] = x[2];
	x[2] = tmp;
    }
 
    void rollTF(){
	swap(x[0],x[7]);
	swap(x[1],x[2]);
	swap(x[4],x[5]);
	swap(x[3],x[6]);
    }
 
    void rollR(){
	int tmp = x[0];
	x[0] = x[7];
	x[7] = x[2];
	x[2] = x[1];
	x[1] = tmp;
     
	tmp = x[3];
	x[3] = x[6];
	x[6] = x[5];
	x[5] = x[4];
	x[4] = tmp;
    }
 
    bool equal(const Octahedra &o){
	for(int i = 0 ; i < 8 ; i++){
	    if(x[i] != o.x[i]) return false;
	}
	return true;
    }
 
    bool operator == (const Octahedra &o){
	for(int i = 0 ; i < 2 ; i++){
	    for(int j = 0 ; j < 4 ; j++){
		if(equal(o)) return true;
		rollLR();
	    }
	    rollTF();
	}
	for(int i = 0 ; i < 4 ; i++){
	    for(int j = 0 ; j < 4 ; j++){
		if(equal(o)) return true;
		rollLR();
	    }
	    rollR();
	}
	rollLR();
	for(int i = 0 ; i < 4 ; i++){
	    for(int j = 0 ; j < 4 ; j++){
		if(equal(o)) return true;
		rollLR();
	    }
	    rollR();
	}
	return false;
    }
 
    bool operator < (const Octahedra &o)const{
	for(int i = 0 ; i < 8 ; i++){
	    if(x[i] != o.x[i]){
		return x[i] < o.x[i];
	    }
	}
    }
};
 
int main(){
    map<string,int> mp;
    string s;
    while(cin >> s){
	Octahedra o;
	mp.clear(); mp[s] = 0;
	o.x[0] = 0;
	int idx = 1;
	set<Octahedra> st;
	for(int i = 0 ; i < 7 ; i++){
	    cin >> s;
	    if(mp.find(s) == mp.end()){
		mp[s] = idx++;
	    }
	    o.x[i+1] = mp[s];
	}
	sort(o.x.begin(),o.x.end());
	set<Octahedra>::iterator it;
	do{
	    bool found = false;
	    for(it = st.begin() ; it != st.end() ; ++it){
		Octahedra a = *it;
		if(a == o){
		    found = true;
		    break;
		}
	    }
	    if(!found){
		st.insert(o);
	    }
	}while(next_permutation(o.x.begin(),o.x.end()));
	cout << st.size() << endl;
    }
    return 0;
}

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

#define lld long long
#define pi pair<int, int>
#define pl pair<lld, lld>
#define mem0(x) memset(x, 0, sizeof(x))
#define fillnum(x, n) fill(begin(x), end(x), n)
#define asort(x) sort(x.begin(), x.end())
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>())

lld N, K;
lld A[200005];
bool flg[200005];
lld start;
lld endp;

void solved(lld n, lld bef) {
    if(flg[n] == true) {
        start = n;
        endp = bef;
        return;
    }
    flg[n] = true;
    solved(A[n], n);
}

lld cost_calc(lld s, lld e) {
    lld now = s;
    lld cost = 0;
    while(1) {
        if(now == e) {
            return cost;
        }
        now = A[now];
        cost++;
    }
}

int main() {
    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }
    mem0(flg);
    solved(0, -1);
    lld cost1 = cost_calc(0, start);
    lld cost2 = cost_calc(start, endp) + 1;
    if(K <= cost1) {
        lld ans = 0;
        while(K != 0) {
            ans = A[ans];
            K--;
        }
        cout << ans + 1 << endl;
    } else {
        K -= cost1;
        K %= cost2;
        lld ans = start;
        while(K != 0) {
            ans = A[ans];
            K--;
        }
        cout << ans + 1 << endl;
    }
}


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

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

    int n=s.size(), tmp=0, maxlen=0;

    for(int i=0; i<n; i++){
        if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T' ){
            tmp++;
        } else {
            tmp=0;
        } 
        maxlen = max (maxlen, tmp);
    }

    cout << maxlen << endl;

    return 0;
}

Measured memory_bytes: 3592
while True:
    a, op, b=input().split()
    a=int(a)
    b=int(b)
    if op == '+':
        print(a + b)
    if op == '-':
        print(a - b)
    if op == '*':
        print(a * b)
    if op == '/':
        print(a // b)
    if op == '?':
        break


Measured memory_bytes: 5592
while True:
	n = int(raw_input())
	if n == 0: break
	m = int(raw_input())
	s = [map(int, raw_input().split(",")) for i in range(m)]
	s = sorted(s, key=lambda x:x[2])
	ls = range(n)
	ref = ls[:]
	ans = 0
	while s:
	    x,y,d = s.pop(0)
	    a,b = ref[x],ref[y]
	    if a != b:
	        for j in ls:
	            if ref[j] == a: ref[j] = b
	        ans += d/100 - 1
	print ans 

Measured memory_bytes: 4996