akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x = int(read())
temp = x
while True:
    flag = True
    for i in range(2, int(temp ** 0.5)):
        if (temp % i == 0):
            flag = False
            break
        else:
            continue
    if (flag is False):
        temp += 1
    else:
        print(temp)
        exit()


Measured memory_bytes: 9376
s1=input()
s2=input()
if s1 == s2:
    print('No')
    exit()
s1 = list(s1)
s1.sort()
s1 = ''.join(map(str,s1))
s2 = list(s2)
s2.sort(reverse=True)
s2 = ''.join(map(str,s2))
check = [s1,s2]
check.sort()

if check[0] == s1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input);

    let input = input
        .split_whitespace()
        .map(|num| num.parse::<i32>().unwrap())
        .collect::<Vec<i32>>();
    println!("{}", input[0] + input[1] / 2);
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int gcd(int a, int b){
    while(b != 0){
        int tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

int main()
{
    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;

    int x = gcd(n, m);
    for(int i=0; i<x; ++i){
        if(s[i*n/x] != t[i*m/x]){
            cout << -1 << endl;
            return 0;
        }
    }

    long long ans = n / x * (long long)m;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
	int N,A[200001],n[200001]={0},p=1;
	bool flag[200001]={0};
	long long int K,loop;
	cin>>N>>K;
	for(int i=1;i<=N;i++)cin>>A[i];
	if(K<=N){
		for(int i=1;i<=K;i++)p=A[p];
		cout<<p;
		return 0;
	}
	for(int i=1;i<=N;i++){
		if(flag[p]){
			loop=i-n[p];
			K-=(long long int)(n[p]-1);
			break;
		}
		n[p]=i;
		flag[p]=true;
		p=A[p];
	}
	K%=loop;
	for(int i=1;i<=N;i++){
		if(n[i]==n[p]+K){cout<<i;break;}
	}
	return 0;
}

Measured memory_bytes: 5388
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for _ in range(n)]

ans = 0
for i in range(n):
    if d % a[i] != 0:
        ans += d // a[i] + 1
    else:
        ans += d // a[i]
print(ans+x)


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

int main() {
  int n;
  cin >> n;

  int minv = 10000000, maxv = -10000000, x;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += x;
    if (x < minv) minv = x;
    if (maxv < x) maxv = x; 
  }

  cout << minv << " " << maxv << " " << sum << endl;  
  return 0;
}


Measured memory_bytes: 3096
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(int[]);
    auto BS = readln.split.to!(int[]);
    auto CS = readln.split.to!(int[]);
    sort(AS);
    sort(BS);
    sort(CS);

    long res;
    foreach (b; BS) {
        long l, r = N;
        if (AS[0] >= b) continue;
        while (l+1 < r) {
            auto m = (l+r)/2;
            if (AS[m] < b) {
                l = m;
            } else {
                r = m;
            }
        }
        auto a = r;
        l = 0;
        r = N;
        if (CS[0] > b) r = 0;
        while (l+1 < r) {
            auto m = (l+r)/2;
            if (CS[m] <= b) {
                l = m;
            } else {
                r = m;
            }
        }
        auto c = N - r;
        res += a * c;
    }
    writeln(res);
}

Measured memory_bytes: 13384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    vector<ll> check(4);
    rep(i, 3) {
        ll a, b;
        cin >> a >> b;
        check[--a]++;
        check[--b]++;
    }

    sort(check.begin(), check.end());
    if (check[0] == 1 && check[1] == 1 && check[2] == 2 && check[3] == 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

//Period
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int p = sc.nextInt();
			int q = sc.nextInt();
			int[] a = new int[q];
			StringBuilder sb = new StringBuilder();
			int k = 1;
			int r = p%q;
			int s = -1;
			int t = -1;
			a[r] = k++;
			r*=10;
			sb.append(r/q);
			r%=q;
			while(true){
				if(r==0)break;
				if(a[r]>0){
					s = a[r];
					t = k;
					break;
				}
				a[r] = k++;
				r *= 10;
				sb.append(r/q);
				r %= q;
			}
			System.out.println(sb);
			if(s!=-1){
				for(int i=0;i<t-1;i++){
					if(s-1<=i)System.out.print("^");
					else System.out.print(" ");
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 93044
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    ll n,ans = 1e6;
    string s;
    cin >> n >> s;
    vector<ll> l(n + 1),r(n + 1);
    l[0] = 0;
    r[n] = 0;
    rep1(i, n){
        l[i] = l[i - 1];
        if(s[i - 1] == '#')++l[i];
    }
    
    rrep0(i, n){
        r[i] = r[i + 1];
        if(s[i] == '.')++r[i];
    }
    rep0(i, n + 1){
        ans = min(ans, l[i] + r[i]);
    }
    pf(ans);
    return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define mp make_pair
#define len(s) s.length()

typedef long long ll;

void solve() {
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  pair<double,double> min,hrs;
  double pi=3.14159265359;
  min.first = b*cos((m/60.0)*2*pi);
  min.second = b * sin((m/60.0)*2*pi);
  hrs.first = a * cos((h*60+m)/720.0*pi*2);
  hrs.second =a * sin((h*60+m)/720.0*pi*2);
  double ans = sqrt((min.first-hrs.first)*(min.first-hrs.first) +(min.second-hrs.second)*(min.second-hrs.second));
  cout<<setprecision(20)<<ans<<'\n';
}

int main() {
    int t=1;
  //  cin>>t;
    rep(i,t)  solve();
    return 0;
}


Measured memory_bytes: 4096
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

vector<int> rec[100010];

signed main() {
    int N, K; cin >> N >> K;

    vector< pair<int, int> > elems;
    for(int i=0; i<N; i++) {
        int t, d; cin >> t >> d; t--;
        rec[t].push_back(d);
        elems.emplace_back(d, t);
    }

    sort(elems.rbegin(), elems.rend());
    for(int i=0; i<N; i++) {
        sort(rec[i].rbegin(), rec[i].rend());
    }

    vector< pair<int, int> > tops;
    for(int i=0; i<N; i++) {
        if(rec[i].size() == 0) continue;
        tops.emplace_back(rec[i][0], i);
    }
    sort(tops.rbegin(), tops.rend());

    int sum = 0, ans = 0;

    // 消していいものの集合
    multiset< pair<int, int> > S;
    for(int i=0; i<K; i++) {
        int val, id; tie(val, id) = elems[i];
        if(i > 0) S.emplace(elems[i]);
        sum += val;
    }

    int M = tops.size();
    for(int i=1; i<=min(K, M); i++) {
        chmax(ans, sum + i * i);
        // fprintf(stderr, "size = %zu, i = %lld, value = %lld\n", S.size(), i, sum + i * i);
        if(i != min(K, M)) {
            // 絶対に追加する要素
            int val, id; tie(val, id) = tops[i];

            // すでに入っているとき
            auto itr = S.find(tops[i]);
            if(itr != S.end()) {
                S.erase(itr);
            }
            // 入っていないなら、削除できるものの中で最もコストが低いものを取る
            else {
                assert(S.size());
                
                auto e = S.begin();
                sum -= e->first;
                sum += tops[i].first;
                // fprintf(stderr, "i = %lld, in = %lld, out = %lld\n", i, tops[i].first, e->first);

                S.erase(e);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int a, b, c, d, e, f;
	cin >> a >> b >> c;

	if (a<b&&b<c) {
		d = a, e = b, f = c;
	}
	else if (a < c&&c < b) {
		d = a, e = c, f = b;
		}
	else if ( b< a&&a < c) {
		d =b, e =a, f = c;
	}
	else if (b < c&&c < a) {
		d =b, e =c, f = a;
	}
	else if (c < a&&a < b) {
		d =c, e =a, f = b;
	}
	else if (c < b&&b < a) {
		d =c, e =b, f = a;
	}
	
	else if (a == b&&b < c) {
		d = a, e = b, f = c;
	}
	else if (a == b&&b > c) {
		d = c, e = a, f = b;
	}
	else if (a < b &&b== c) {
		d = a, e = b, f = c;
	}
	else if (a > b &&b== c) {
		d = b, e = c, f = a;
	}
	else if (a == c &&c> b) {
		d = a, e = c, f = b;
	}
	else {
		d = a, e = c, f = b;
	}
	cout << d << " " << e << " " << f << endl;
	return 0;
}

Measured memory_bytes: 3084
//
// Low-Link を用いた、橋・関節点列挙, O(V + E)
//
// cf.
//   hos: グラフ探索アルゴリズムとその応用
//     http://hos.ac/slides/20110504_graph.pdf
//
// verified:
//   AOJ Course GRL_3_B Connected Components - Bridges
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B&lang=jp
//
//   Connected Components - Articulation Points
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A&lang=jp
//
//


/*
    アイディア: DFS をしたとき、DFS 後退辺は橋とはなりえない
 
    ・ord[v] := 頂点を訪れた順番
    ・low[v] := v から「DFS 木の根から葉へ進む」or「後退辺を葉から根へ進む」ことによって辿り着ける頂点の ord の最小値
 
    DFS で u -> ... -> v と来て、v から u への後退辺があると、このサイクルの low がすべて ord[u] (以下) になる感じ
    このtことから、
 
        DFS-search で、辺 v - ch を v -> ch の順に探索したときに、
            辺 v-to が橋　⇔　ord[v] < low[ch]
 
        DFS-search で、
            頂点 v が関節点　⇔
                ・v が根のとき、deg[v] > 1
                .それ以外のとき、u のある子供 ch が存在して、ord[v] <= low[ch]
*/


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


using Graph = vector<vector<int> >;
struct LowLink {
    // main results
    vector<int> aps; // articulation points
    vector<pair<int,int> > brs; // brideges
    
    // intermediate results
    vector<int> seen, ord, low;
    void dfs_lowlink(const Graph &G, int v, int p = -1) {
        static int time = 0;
        seen[v] = true;
        ord[v] = low[v] = time++;
        int num_of_child = 0;
        bool exist = false; // for articulation point
        for (auto ch : G[v]) {
            if (seen[ch]) {
                if (ch != p) low[v] = min(low[v], ord[ch]); // back edge
                continue;
            }
            dfs_lowlink(G, ch, v);
            low[v] = min(low[v], low[ch]); // forward edge of DFS-tree
            if (ord[v] < low[ch]) brs.emplace_back(v, ch);
            if (ord[v] <= low[ch]) exist = true;
            ++num_of_child;
            //cout << v << "' s child: " << ch << endl;
        }
        //cout << v << ": " << ord[v] << ", " << low[v] << endl;
        if ((p == -1 && num_of_child > 1) || (p != -1 && exist)) aps.emplace_back(v);
    }
    void solve(const Graph &G) {
        int N = (int)G.size();
        seen.assign(N, 0); ord.resize(N); low.resize(N);
        aps.clear(); brs.clear();
        for (int v = 0; v < N; ++v) if (!seen[v]) dfs_lowlink(G, v);
    }
};


int main() {
    int V, E; cin >> V >> E;
    Graph G(V);
    for (int i = 0; i < E; ++i) {
        int s, t; cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    LowLink ll;
    ll.solve(G);
    
    // 橋
    for (auto &br : ll.brs) if (br.first > br.second) swap(br.first, br.second);
    sort(ll.brs.begin(), ll.brs.end());
    //for (auto br : ll.brs) cout << br.first << " " << br.second << endl;
    
    // 関節点
    sort(ll.aps.begin(), ll.aps.end());
    for (auto v : ll.aps) cout << v << endl;
}


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

int main()
{
    int N,K; cin>>N>>K;
    vector<ll> v(N);
    for(int i=0;i<N;i++) cin>>v[i];
    ll maxv=0;
    for(int i=0;i<=N&&i<=K;i++){
        for(int j=0;j<=(N-i)&&j<=(K-i);j++){
            vector<ll> tmp;
            //左
            for(int l=0;l<i;l++) tmp.emplace_back(v[l]);
            //右
            for(int r=0;r<j;r++) tmp.emplace_back(v[N-r-1]);
            //判定
            int cnt=K-tmp.size();
            for(int t=0;t<cnt;t++){
                ll minv=0;
                int idx=-1;
                for(int s=0;s<tmp.size();s++){
                    if(tmp[s]<0&&minv>tmp[s]){
                        minv=tmp[s];
                        idx=s;
                    }
                }
                if(idx!=-1) tmp[idx]=0;
            }
            //更新
            ll a=0;
            for(int p=0;p<tmp.size();p++) a+=tmp[p];
            maxv=max(maxv,a);
        }
    }
    cout<<maxv<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    while(true) {
        int N;
        scanf("%d", &N);
        if(!N) break;
        int field[N][N];
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                field[i][j] = -1;
            }
        }
        int r = N/2 + 1, c = N/2;
        field[r][c] = 1;
        for(int num = 2; num <= N*N; ++num) {
            ++r;
            ++c;
            while(!(0 <= r && r < N && 0 <= c && c < N && field[r][c] == -1)) {
                if(c >= N) c = 0;
                if(c < 0) c = N-1;
                if(r >= N) r = 0;
                if(0 <= r && r < N && 0 <= c && c < N && field[r][c] != -1) {
                    ++r;
                    --c;
                }
            }
            field[r][c] = num;
        }
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                printf("%4d", field[i][j]);
            }
            puts("");
        }
    }
    return 0;
}

Measured memory_bytes: 1048
#include <iostream>
#include <algorithm>
using namespace std;
int N,M,R;
long long d[201][201];
static const long long MAX = 1LL<<31;
void wf() {
    int i,j,k;

    for (k =1; k <= N; k++) {
        for (i = 1; i <= N; i++) {
            for (j = 1; j <= N; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

}

void printr(int* r, int R) {
for (int i = 0; i < R; i ++) {
cout <<r[i];
}
cout << endl;
}
void printd(int N) {
for (int i =0; i <= N; i ++) {
for (int j = 0; j <= N; j ++) {
cout <<d[i][j];
}
cout << endl;
}
}
int main() {
    int i,j,A,B;
    long long C;
    int r[8];
    cin >> N >> M >> R;

    for (i = 0; i < R; i++) {
        cin >> r[i];
    }
    sort(r, r+R);
//    printr(r, R);
    for (i = 1; i <= N; i++) {
        for (j = 1; j <= N; j++) {
            d[i][j] = MAX;
        }
        d[i][i]=0;
    }

    for (i = 0; i < M; i++) {
        cin >> A >> B >> C;
        d[A][B] = C;
        d[B][A] = C;
    }
//printd( N);
    wf();
// printd( N);   
    long long mind = MAX;
    do {
  //      printr(r, R);
        long long tmp = 0;
        for (j = 0; j < R-1; j++) {
            
           tmp += d[r[j] ][r[j+1] ];
        }
        mind = min(mind, tmp);
    } while ( next_permutation(r,r+R) );

    cout << mind << endl;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define int long long

signed main() {
	string s;
	int w;
	cin >> s >> w;
	int N = s.size();

	for ( int i = 0; i < N; i += w ) {
		cout << s[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int W;
int a, b;

int main(void)
{
	cin >> W;
	cin >> a >> b;
	
	int ans = 0;
	if(a+W < b) ans = b - (a+W);
	if(b+W < a) ans = a - (b+W);
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    H, W, K = map(int, input().split())
    C = [input() for _ in range(H)]
    zenbu = 0
    for h in range(H):
        for w in range(W):
            if C[h][w] == '#':
                zenbu += 1
    
    if K > zenbu:
        print(0)
        exit()
    ans = 0
    for h in range(2 ** H):
        yoko = []
        for i in range(H):
            if ((h >> i) & 1):
                yoko.append(i)

        for w  in range(2 ** W):
            tate = []

            for j in range(W):
                if (w >> j) & 1:
                    tate.append(j)
            tmp = 0
            for k in range(H):
                for l in range(W):
                    if k in yoko:
                        continue
                    if l in tate:
                        continue
                    if C[k][l] == '#':
                        tmp += 1
            if tmp == K:
                ans += 1

    print(ans)
        




if __name__ == "__main__":
    main()

Measured memory_bytes: 68404
import numpy as np

n,m,c=map(int,input().split())
b=np.array(list(map(int,input().split())))
ans=0
for i in range(n):
    a=np.array(list(map(int,input().split())))
    if np.dot(a,b)+c>0:
        ans+=1
    
print(ans)

Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> s(h);
	REP(i, h) {
		cin >> s[i];
		s[i].push_back('#');
	}
	vector<int> cnt(h, 0);
	vector<vector<int>> t(h);
	REP(i, h) {
		REP(j, w + 1) {
			if (s[i][j] == '#') {
				cnt[i]++;
				t[i].push_back(j);
			}
		}
	}
	int c = 1;
	vector<vector<int>> res(h, vector<int>(w,0));
	REP(i, h) {
		if (t[i].size()==1) {
			continue;
		}
		REP(k, t[i][0]) {
			res[i][k] = c;
		}
		REP(j, t[i].size()-1) {
			//int pre = 0;
			
			FOR(k,t[i][j], t[i][j+1]) {
				res[i][k] = c;
			}
			c++;
			//pre = t[i][j];
		}
		
	}
	/*vector<vector<int>> st(w);
	REP(j, w) {
		REP(i, h) {
			if (res[i][j] != 0) {
				st[j].push_back(i);
			}
		}
	}*/
	REP(j, w) {
		FOR(i, 1, h) {
			if (res[i][j] == 0) {
				res[i][j] = res[i - 1][j];
			}
		}
	}
	REP(j, w) {
		for (int i = h-2; i >= 0; --i) {
			if (res[i][j] == 0) {
				res[i][j] = res[i + 1][j];
			}
		}
	}
	REP(i, h) {
		put(res[i]);
	}
	return 0;
}


Measured memory_bytes: 1920
cnt = 0
input()
num = [int(n) for n in input().split()]
for i in range(len(num) - 1):
    for j in range(len(num) - 1, i, -1):
        if num[j] < num[j - 1]:
            num[j], num[j - 1] = num[j - 1], num[j]
            cnt += 1
print(' '.join([str(n) for n in num]))
print(cnt)

Measured memory_bytes: 7748
#include <iostream>
#include <algorithm>
using namespace std;
float arr[1005];
int main(){
	
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	
	sort(arr,arr+n);
	
	for(int i=1;i<n;i++){
		arr[i]=(arr[i]+arr[i-1])/2.0;
	}
	
	printf("%f\n",arr[n-1]);
	return 0;
}





















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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a >= 10 || b >= 10)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << a * b << endl;
}

Measured memory_bytes: 3600
def solve():
    a, b, c = read()
    result = think(a, b, c)
    write(result)


def read():
    return read_int(3)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b, c):
    m_seed = a % b
    while m_seed >= b:
        m_seed %= b

    visited = set()
    m_accumulated = m_seed
    while True:
        if m_accumulated == c:
            return True
        if m_accumulated in visited:
            return False
        visited.add(m_accumulated)
        m_accumulated += m_seed
        while m_accumulated >= b:
            m_accumulated %= b


def write(result):
    if result:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
/**
 *    author:  math2do
 *    created: 26.08.2020 15:19:22
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int x, n;
  cin >> x >> n;
  vector <int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  } 
  sort(arr.begin(), arr.end());
  int dif = (int) 1e9;
  int ans = -1;
  for (int i = -1001; i <= 1001; i++) {
    if (!binary_search(arr.begin(), arr.end(), i)) {
      if (abs(x - i) < dif) {
        dif = abs(x - i);
        ans = i;
      } 
    } 
  } 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int n, m, h[100005], ans=0;
vector<int> r[100005];
int main() {
    cin >> n >> m;
    for (int i=1; i<=n; i++) cin >> h[i];
    for (int i=0; i<m; i++) {
        int a, b; cin >> a >> b;
        r[a].push_back(b);
        r[b].push_back(a);
    }
    bool ok=1;
    for (int i=1; i<=n; i++) {
        ok=1;
        for (int j=0; j<r[i].size(); j++) {
            if (h[i]<=h[r[i][j]]) ok=0;
        }
        if (ok) ans++;
    }
    
    cout << ans;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vll A(N);
  REP(i,N) IN(A[i]);
  sort(ALL(A));
  reverse(ALL(A));

  ll pos = 0;
  ll count = 0;
  ll ans = 0;
  while(count<N-1){
    ans += A[pos];
    count++;
    if(pos==0){
      pos++;
      continue;
    }
    if(count==N-1) break;
    ans += A[pos];
    count++;
    pos++;
  }

  OUT(ans);


  return 0;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int n,Y;
	cin>>n>>Y;
	For(a,0,Y/10000)
	{
		For(b,0,Y/5000)
		{
			int c=(Y-a*10000-b*5000)/1000;
			if(a+b+c==n && c>=0)
			{
				cout<<a<<" "<<b<<" "<<c<<endl;
				return 0;
			}
		}
	}
	puts("-1 -1 -1");
	return 0;
}



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


int main(){
int N,D,X,eaten_n;

int A[110];

cin >> N >> D >> X;
for(int i = 0; i < N; ++i){
cin >>A[i];
}

eaten_n = N;

for(int i = 0; i < N; ++i){
  for(int j = 1; j <= D; ++j){
    if(j*A[i]+1 <= D){
        eaten_n = eaten_n + 1;
    }
  }
}  

cout << eaten_n+X << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
using namespace std;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lint long long int
using namespace std;
int main() 
{
	lint n=0;
	lint ans=0;
	cin>>n;
	vector<string> v(n);
	map<string,lint> m{};
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
		m[v[i]]=1;
	}
	for(auto itr=m.begin();itr!=m.end();++itr)
	{
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

const int MAX = 100;

int BubbleSort(int A[], int n){
	int count = 0; // 定义一个计数器 
	int flag = 1;
	while(flag){
		flag = 0;
		for(int i = n-1; i >= 1; i--){
			if( A[i-1] > A[i] ){
				swap(A[i-1], A[i]);
				count++; 
				flag = 1;
			}
		}
	}
	return count;
}

void PrintfInfo(int A[], int n){
	for(int i = 0; i < n; i++){
		if( i > 0 ) 
			cout << " ";
		cout << A[i];
	}
	cout << "\n";
}

int main()
{
	int n;
	cin >> n;
	int A[MAX];
	for(int i = 0; i < n; i++)
		cin >> A[i];
	int count = BubbleSort(A, n);
	PrintfInfo(A, n);
	cout << count << "\n";
	return 0;
} 


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std ;
const int N=200006;
int a[N],n,l[N];
long long ans = 0 ;
inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
int main(){
    n=read();
    int left=0;
    for(int i=1;i<=n;i++){
        a[i]=read();
        l[i]=left;
        if(a[i])left=i;
    }
    for(int i=1;i<=n;i++){
        int now=a[i];
        int j;
        for(j=l[i];j;j=l[j]){
            if(now&a[j])
                break;
            now^=a[j];
        }
        ans+=(long long)(i-j);
    }
    cout << ans << endl ;
}

Measured memory_bytes: 1792
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main() {
    val (n, m) = intList()
    val count = hashMapOf<Int, Int>()
    repeat(m) {
        val (a, b) = intList()
        count[a] = count.getOrDefault(a, 0) + 1
        count[b] = count.getOrDefault(b, 0) + 1
    }
    if (count.values.all { it % 2 == 0 }) {
        println("YES")
    } else {
        println("NO")
    }
}


Measured memory_bytes: 67528
N,A,B = map(int,input().split())
if abs(A-B)%2 == 0:
    print(abs(A-B)//2)
else:
    if N-A > B-1:
        ans  = 1
        ans += A-1
        ans += (B-A-1)//2
        ans = min(ans,B-1)
    else:
        ans = 1
        ans += N-B
        ans += (B-A-1)//2
        ans = min(ans,N-A)
    print(ans)

Measured memory_bytes: 3064
H,W =map(int,input().split())
S=[[] for _ in range(H+2)]
for i in range(H):
    S[i+1]="#"+input()+"#"
S[0]="#"*(W+2)
S[-1]="#"*(W+2)

hori=[[0]*(W+2) for _ in range(H+2)]
ver=[[0]*(W+2) for _ in range(H+2)]


def count(i,j):
    if hori[i][j-1]==0:
        count=0
        for k in range(W):
            if S[i][j+k]==".":
                count+=1
            else:
                break
        hori[i][j]=count
    else:
        hori[i][j]=hori[i][j-1]
        
    if ver[i-1][j]==0:
        count=0
        for k in range(H):
            if S[i+k][j]==".":
                count+=1
            else:
                break
        ver[i][j]=count
    else:
        ver[i][j]=ver[i-1][j]
    return hori[i][j]+ver[i][j]-1
    
ans=0
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]==".":
            ans=max(ans,count(i,j))
print(ans)

Measured memory_bytes: 124376
#include<iostream>
#include<stdio.h>
using namespace std;

int main(void) {
	int N;
	cin >> N;
	if (N == 1) {
		cout << "Hello World" << "\n";
	} else if (N == 2) {
		int	A, B;
		cin >> A >> B;
		cout << A + B << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
P=[0]*(N+1)
for i in range(N):
    P[i+1]=P[i]+A[i]
dd=defaultdict(int)
for p in P:
    dd[p%M]+=1
ans=0
def dou(x):
    return (x*(x-1))//2
for s in dd.values():
    ans+=dou(s)
print(ans)


Measured memory_bytes: 16836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    string S;
    cin >> S;
    int n = S.size();
    int s = 0, t = 0;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(S[i] == 'T') t++;
        else s++;
        if(t > s)
        {
            ans++;
            t = s = 0;
        }
        if(t == s)
        {
            t = s = 0;
        }
    }
    ans += s-t;
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>

using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
int ata[10];
int H;
int ima;
int input;
int flag;
int zu[5][10];
int ans;
int main()
{
	while(1)
	{
	cin>>H;if(H==0)break;
	rep(i,5)rep(j,10)zu[i][j]=0;
	ans=0;
	rep(i,H)
	{
		rep(j,5)
		{
			cin>>input;
			ans+=input;
			zu[j][H-i-1]=input;
		}
	}
	while(1)
	{
		flag=0;
		rep(i,H)
		{
			int t=zu[2][i];
			if(zu[2][i]!=0&&((zu[2][i]==zu[1][i]&&zu[0][i]==zu[1][i])||(zu[2][i]==zu[1][i]&&zu[2][i]==zu[3][i])||(zu[2][i]==zu[3][i]&&zu[2][i]==zu[4][i])))
			{
				flag=1;
				for(int j=1;j>=0;j--)
				{
					if(zu[j][i]==t)zu[j][i]=0;
					else break;
				}
				for(int j=3;j<5;j++)
				{
					if(zu[j][i]==t)zu[j][i]=0;
					else break;
				}
				zu[2][i]=0;
			}
		}
		rep(i,5)
		{
			rep(j,10)ata[j]=0;
			ima=0;
			rep(j,H)
			{
				if(zu[i][j]!=0)
				{
					ata[ima]=zu[i][j];
					ima++;
				}
			}
			rep(j,H)
			{
				zu[i][j]=ata[j];
			}
		}
		if(flag==0)break;
	}
	rep(i,5)
	{
		rep(j,10)
		{
			ans-=zu[i][j];
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define str string
#define sec .second
 
ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30;
ll A[1000000] = {}, B[1000000] = {}, weight[1000] = {}, value[1000] = {};
ll dp[1000][100100] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, n = 0, su = 0, ma = INF, mi = -1;
double ans;
pair<str, ll> S[1000];
bool an = true, bn = false;
long long mod = 1e9 + 7;
 
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;
}
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Code Line
	cin >> n >> a;
	for (int i = 0; i < n; i++)cin >> weight[i] >> value[i];
 
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= a; j++) {
			
			if (j >= weight[i])dp[i + 1][j] = max(dp[i][j - weight[i]] + value[i], dp[i][j]);
			dp[i + 1][j] = max(dp[i][j],dp[i+1][j]);
		}
	}
	cout << dp[n][a] << endl;
 
		return 0;
}


Measured memory_bytes: 81408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, b, a) for(int i = (b); i >= (a); i--)
using namespace std;
const int N = 1e5 + 9, P = 1e9 + 7;
int n, l, r;
ll A, B, ans, minn, a[N], dp[N], sum[N];//dp[i]:第一个集合最后一个是i的方案数
int main(){
    scanf("%d%lld%lld", &n, &A, &B);
    rep(i, 1, n) scanf("%lld", &a[i]);
    if(B > A) swap(A, B);
    sort(a + 1, a + n + 1);
    rep(i, 1, n - 2) if(a[i + 2] - a[i] < B){
        printf("0");
        return 0;
    }
    dp[1] = sum[1] = 1, minn = a[2] - a[1], dp[2] = a[2] - a[1] >= A ? 2 : 1, sum[2] = dp[2] + 1;
    rep(i, 3, n){
        while(a[i] - a[r + 1] >= A) r++;
        if(a[i - 1] - a[i - 2] < B) l = i - 2;
        if(l == 0) {
            if(r == 0) dp[i] = minn >= B;
            else dp[i] = (sum[r] + 1) % P;
        }
        else dp[i] = l <= r ? (sum[r] - sum[l - 1] + P) % P : 0; 
        sum[i] = (sum[i - 1] + dp[i]) % P, minn = min(minn, a[i] - a[i - 1]);
        //cout << i << " " << l << " " << r << " " << dp[i] << endl;
    }
    per(i, n - 1, 1) {
        ans = (ans + dp[i]) % P;
        if(a[i + 1] - a[i] < B) break;
    }
    bool ok = true;
    rep(i, 2, n) ok = ok && (a[i] - a[i - 1] >= B);
    printf("%lld", (ans + dp[n] + ok) % P);
    return 0;
}

Measured memory_bytes: 2560
def solve(X, Y, Z, V, E, A):
    dp = [[0.0] * 6001 for _ in range(Y + 11)]
    dp[0][0] = 1.0
    for i in range(Y):
        for j in range(5001):
            if dp[i][j] <= 0.0:
                continue
            for k in V:
                t = i + k
                if t > Y:
                    dp[Y][j] += dp[i][j]/X
                elif E[t] == 1:
                    dp[min(Y, t+A[t])][j] += dp[i][j]/X
                else:
                    dp[t][max(0, j+A[t])] += dp[i][j]/X

    s = 0
    for i in range(5001):
        s += i * dp[Y][i]
    print(int(s))

if __name__ == "__main__":

    while True:
        X, Y, Z = map(int, input().split())
        if X | Y | Z == 0:
            break
        V = list(map(int, input().split()))
        E = [0] * 100
        A = [0] * 100
        for _ in range(Z):
            n, e, a = map(int, input().split())
            E[n] = e
            if e == 3:
                A[n] = -a
            else:
                A[n] = a
        solve(X, Y, Z, V, E, A)

Measured memory_bytes: 10944
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, a[MAX][MAX];

int prim(){
  int u, min;
  int d[MAX], p[MAX], color[MAX];

  for(int i=0;i<n;i++){
    d[i] = INFTY;
    p[i]=-1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    min = INFTY;
    u = -1;
    for(int i=0;i<n;i++){
      if(min > d[i] && color[i] != BLACK){
	u = i;
	min = d[i];
      }
    }
    if(u == -1)break;
    color[u] = BLACK;
    for(int v=0;v<n;v++){
      if(color[v] != BLACK && a[u][v] != INFTY){
	if(d[v]>a[u][v]){
	  d[v] = a[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }

    } //end of (for)

  } // end of while
  int sum = 0;
  for(int i=0;i<n;i++){
    if(p[i] != -1) sum += a[i][p[i]];
  }
  
  return sum;
}

int main(){
  cin >> n;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e;
      cin >> e;
      a[i][j] = (e == -1) ? INFTY : e;
    }
  }
  
  cout << prim() <<endl;
  
  return 0;
}



Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int main()
{
	int k,a,b,c;
	cin>>a>>b>>c>>k;
	int t;
	if(k<=a) t=k;
	else if(k>a&&k-a<=b) t=a;
	else t=a-(k-a-b);
	cout<<t;
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;
constexpr int MAXN = 18;
constexpr int INF = 1e6;

int memo[1<<MAXN][51];
int a[MAXN], b[MAXN], n;
vector<int> posbits[1<<MAXN];

int dp(int bm, int l) {
  if (bm == 0) return 0;
  int& ans = memo[bm][l];
  if (~ans) return ans;

  ans = INF;
  const vector<int>& v = posbits[bm];
  int pos = n - posbits[bm].size();
  for (int x : v) {
    int izq0 = __builtin_popcount((bm ^ ((1 << n) - 1)) & ~((1 << (1 + x)) - 1));
    int currpos = x + izq0;

    int num = (currpos - pos + izq0) & 1 ? b[x] : a[x];
    if (num >= l) {
      ans = min(ans, currpos - pos + dp(bm ^ (1 << x), num));
    }
  }

  return ans;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  cin >> n;
  foi (i,0,n) cin >> a[i];
  foi (i,0,n) cin >> b[i];
  foi (i,0,1<<MAXN) {
    foi (j,0,MAXN) {
      if ((i >> j) & 1) {
        posbits[i].push_back(j);
      }
    }
  }

  memset(memo, -1, sizeof memo);
  cout << (dp((1<<n)-1,0) >= INF ? -1 : dp((1<<n)-1,0)) << '\n';
  return 0;
}


Measured memory_bytes: 75776
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<string>
using namespace std;


int main() {

	int n;

	int min;
	int d;
	int count;
	while (cin >> n) {
		if (n < 9) {
			min = n;
		}
		else {
			min = 9;
		}
		count = 0;

		for (int i = 0; i <= min; i++) {
			for (int j = 0; j <= min; j++) {
				for (int k = 0; k <= min; k++) {
					d = n - i - j - k;
					if (d >= 0 && d <= 9) count++;

				}
			}
		}

		printf("%d\n", count);
	}

	//system("pause");
	return 0;
}


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

int sum_of_digit(int x) {
  int d, t = x, sum = 0;
  while (t) {
    d = t % 10;
    sum += d;
    t /= 10;
  }
  return sum;
}

int main() {
  int a, n, m, ans = 0;
  vector<int> list;
  cin >> a >> n >> m;
  for (int i = 1; ; i++) {
    if (pow(i, n) <= m) {
      list.push_back(pow(i, n));
    } else break;
  }
  for (const auto& x : list) {
    if (pow(sum_of_digit(x) + a, n) == x) ans++;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3304
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int N;
	cin >> N;

	vll A(N), B(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
	}

	ll ans = 0;
	for (int i = N - 1; i >= 0; i--) {

		if ((A[i] + ans) % B[i] != 0) {
			ans += B[i] - (A[i] + ans) % B[i];
		}


	}

	cout << ans;
}


Measured memory_bytes: 1792
N, M, K = [int(_) for _ in input().split()]

MOD = 998244353
L = 200001

Fm = {}

inverseFm = {}
x = 1
for i in range(L):
    Fm[i] = x
    x = x * (i + 1) % MOD

def inverseFm(x, cache={}):
    if x in cache:
        return cache[x]
    result = pow(Fm[x], MOD - 2, MOD)
    cache[x] = result
    return result

def C(n, r):
    result = Fm[n] * inverseFm(r) * inverseFm(n - r) % MOD
    return result

result = 0


for i in range(K + 1):
    result = (result + C(N - 1, i) * M * pow(M - 1,  N - i - 1,  MOD)) % MOD

print(result)


Measured memory_bytes: 64912
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, m;
    cin >> n >> m;
    auto k = initVec2<int>(m, 0);
    rep(i, m){
        int x;
        cin >> x;
        rep(j, x){
            int s;
            cin >> s;
            s--;
            k[i].push_back(s);
        }
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];

    int ans = 0;
    rep(s, 1 << n){
        bool ok = true;

        rep(i, m){
            int cnt = 0;
            rep(j, SZ(k[i])){
                if((s >> k[i][j]) % 2){
                    cnt++;
                }
            }
            if(cnt % 2 != p[i]){
                ok = false;
            }
        }
        if(ok){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(long long N, std::vector<std::string> S){

    set<string> ss;
    REP(i,0,N)ss.insert(S[i]);

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

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    func(N, std::move(S));
    return 0;
}


Measured memory_bytes: 25084
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL A, B;
	in >> A >> B;

	LL ans;
	if (A >= 13) ans = B;
	if (6 <= A && A <= 12) ans = B / 2;
	if (A <= 5) ans = 0;
	out << ans << std::endl;
}


Measured memory_bytes: 764
split _ [] = []
split c xs = if s==[] then [f] else f : (split c (tail s))
  where
    l = break (==c) xs
    f = fst l
    s = snd l

main = do
  (y:m:d:_) <- getLine >>= return . split '/'
  putStrLn $ "2018/" ++ m ++ "/" ++ d


Measured memory_bytes: 380
#include<stdio.h>
#include<stdlib.h>
int binarySearch(int n,int key,int *S);
int main(){
  int n,*S,q,*T,i,N,count=0;
  scanf("%d\n",&n);
  S=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d\n",&q);
  T=(int *)malloc(q*sizeof(int));
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    N=binarySearch(n,T[i],S);
    if(N!=7777){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}
int binarySearch(int n,int key,int *S){
  int mid,left=0,right=n;
  while(left<right){
    mid=(left+right)/2;
    if(S[mid]==key){
      return mid;
    }
    else if(key<S[mid]){
      right=mid;
    }
    else{
      left=mid+1;
    }
  }
  return 7777;
}



Measured memory_bytes: 2372