akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main() {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val x = sc.next().toInt()
        pw.println(1 - x)
    }
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> stin(H, vector<char>(W));
  for (int i =0; i< H; i++){
    for ( int j = 0; j< W;j++){
      cin >> stin.at(i).at(j);
    }
  }
  
  vector<vector<char>> pic(H + 2, vector<char>(W + 2, '#'));
  
  for ( int i = 1; i < H + 1 ; i++) {
    for (int j = 1; j < W + 1; j++){
      pic.at(i).at(j) = stin.at(i-1).at(j-1);
    }
  }
  
  for (int i = 0 ; i < H + 2; i++){
    for (int j = 0; j < W + 2; j++){
      if ( j == W + 1 ) {
        cout << pic.at(i).at(j) << endl;
      }
      else cout << pic.at(i).at(j);
    }
  }
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
	return *(int *)a - *(int *)b;
}

int main() {
	int N, i, ans;
	scanf("%d", &N);

	int d[N];
	for (i = 0; i < N; i++) {
		scanf("%d", &d[i]);
	}

	qsort(d, N, sizeof(int), asc);

	ans = d[N / 2] - d[N / 2 - 1];

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 892
use std::io::*;
use std::str::FromStr;

fn main() {
	let x: usize = read();
	let n: usize = read();
	let mut pn: Vec<usize> = vec![0; 102];
	let mut temp: usize;
	for _ in 0..n {
		temp = read();
		pn[temp] += 1;
	}
	for i in 0..51 {
		if pn[x-i] == 0 {
			println!("{}", x-i);
			return ();
		}
		if pn[x+i] == 0 {
			println!("{}", x+i);
			return ();
		}
	}
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 2152
from sys import stdin


def main():
    n = int(stdin.readline())
    p = list(map(int, stdin.readline().split()))

    ans = 0
    min = p[0]
    for i in p:
        if i <= min:
            ans += 1
            min = i
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 70480
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int X;

int main()
{
	scanf("%d", &X);
	int ret;
	for (int i = 180; i >= 1; --i) {
		if (360 % i == 0 && X % i == 0) {
			ret = 360 / i;
			break;
		}
	}
	printf("%d\n", ret);
	return 0;
}


Measured memory_bytes: 3216
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	ll d;
	cin >> d;
	// --d;
	string res = "";
	while (d) {
		--d;
		res += ((d%26) + 'a');
		d /= 26;
	}
	reverse(all(res));
	cout << res << endl;
}

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

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

void lcm( ll a, ll b ){
    if( a < b ) swap(a,b);
    ll s = a*b;
    ll c = b;
    while( a%b ){
        c = b;
        b = a%b;
        a = c;
    }

    printf ("%lld\n", s/b );
}

int main() {

    ll a,b;
    Scll2(a,b);
    lcm(a,b);


    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    char a[110];
    long long b,i=0;
    scanf("%s",a);
    scanf("%lld",&b);
    while(a[i]==49)i++;
    //printf("%lld",b);
    if(b<=i)printf("1");
    else printf("%d",a[i]-48);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> p(n),dp(n+1);
    rep(i,n)cin >> p[i];
    int ans=0;
    rep(i,n){
        dp[p[i]]=dp[p[i]-1]+1;
        ans=max(ans,dp[p[i]]);
    }
    cout << n-ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long int
#define pb push_back
#define bpc __builtin_popcount
#define f first
#define s second

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, k, a[mxn], dp[mxn][2], cnt = 0, mx = -inf;

int main(){
    cin >> n >> k;
    for (int i = 1; i <= n; i ++){
        cin >> a[i];
    }llong g = a[0];
    for (int i = 1; i <= n; i ++){
        g = __gcd(g, a[i]);
        mx = max(mx, a[i]);
    }if(k <= mx && k % g == 0){
        cout << "POSSIBLE";
        return 0;
    }cout << "IMPOSSIBLE";
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
//long long…2^64-1 = 9223372036854775807まで

void _main() {
	int A,B,C;
	cin >> A >> B >> C;

	int Cout = A - B;
	int ans = C - Cout;

	if (ans < 0) ans = 0;

	cout << ans << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k,n;
    cin>>n>>k;
    vec p(n);
    rep(i,n) cin>>p[i];
    sort(all(p));
    ll ans=0;
    rep(i,k) ans+=p[i];
    cout<<ans;
}

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

int main(){
  int n;
  cin >> n;
  string s;
  vector<int> a(4);
  for (int i = 0; i < n; i++){
    cin >> s;
    if (s == "AC") {
      a.at(0) ++;
    } else if (s == "WA") {
      a.at(1) ++;
    } else if (s == "TLE") {
      a.at(2) ++;
    } else {
      a.at(3) ++;
    }
  }

  cout << "AC x " << a.at(0) << endl;
  cout << "WA x " << a.at(1) << endl;
  cout << "TLE x " << a.at(2) << endl;
  cout << "RE x " << a.at(3) << endl;
  
}

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

void solve(){
  int n; cin >> n;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int l, r; cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forab(i, a, b) for(int i=(a);i<(b);++i)
#define foreach(i, n) for (__typeof(n.begin()) i = n.begin(); i != n.end(); ++i)
#define sqr(x) ((x)*(x))
#define clr(a, b) memset(a, b, sizeof(a))
#define SZ(a) ((int)a.size())
#define inf 0x3f3f3f3f
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
const double eps = 1e-8;
int dcmp(double x) { if (x < -eps) return -1; else return x > eps;}
#define se(x) cout<<#x<<" = "<<x<<endl

void solve(int a, int b) {
	int t = a * b;
	if (t % 2 == 0) {
		printf("No\n");
	} else {
		printf("Yes\n");
	}
}

int main(int argc, char *argv[]) {
	int a, b;
	while (scanf("%d%d", &a, &b) != EOF) {
		solve(a, b);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

int main()
{
    fastio;
    int x1, y1, x2, y2;

    cin >> x1 >> y1 >> x2 >> y2;

    int x3 = x2 + (y1 - y2);
    int x4 = x3 + (x1 - x2);
    int y3 = y2 - (x1 - x2);
    int y4 = y3 + (y1 - y2);

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	static int W,H,cnt,ans;
	static int map[][];
	static int dx[]={1,0,-1,0};
	static int dy[]={0,1,0,-1};
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		
		for(;;)
		{
			ans=0;
			W=in.nextInt();
			H=in.nextInt();
			if((W|H)==0)
				return;
			map=new int[H][W];
			for(int i=0;i<H;i++)
				for(int j=0;j<W;j++)
					map[i][j]=in.nextInt();
	
			for(int i=0;i<H;i++)
				for(int j=0;j<W;j++)
				{
					if(map[i][j]==1)
						solve(i,j,cnt);
				}
			System.out.println(ans);
		}
	}
	static void solve(int h,int w,int cnt)
	{
		map[h][w]=0;
		for(int i=0;i<4;i++)
		{
			 int nh=dy[i]+h;
			 int nw=dx[i]+w;
			if(nh>=0&&nh<H&&nw>=0&&nw<W)
			{
				if(map[nh][nw]==1)
					solve(nh,nw,cnt+1);
			}
		}
		ans=Math.max(ans,cnt+1);
		map[h][w]=1;
		return;
	}
}

Measured memory_bytes: 12000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

/**
 * A-Z Cat
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		line = br.readLine();
		Deque<Character> az = new ArrayDeque<>();

		boolean a = true;
		for (int i = 0; i < line.length(); i++) {
			char c = line.charAt(i);
			if (c == 'A' && a) {
				az.add(c);
				a = false;
			}
			if (c == 'Z' && !a) {
				az.add(c);
				a = true;
			}
		}
		if (!az.isEmpty() && az.peekLast() == 'A') {
			az.pollLast();
		}

		if (!az.isEmpty()) {
			for (char c : az) {
				System.out.print(c);
			}
			System.out.println();
		} else {
			System.out.println(-1);
		}
	}
}

Measured memory_bytes: 24540
<?php
$string = fgets(STDIN);
$array =  explode (' ', fgets(STDIN));

$sum = 1;

if (in_array('0', $array, true)) {
    echo 0;
} else {
    foreach ($array as $num) {
        $number = (int)$num;
        $sum *= $number;
    }

    if ($sum > 10 ** 18) {
        echo -1;
    } else {
        echo $sum;
    }
}

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

int main(){
  int a,b,c;
  char s[55];
  cin>>s;
  if(s[5]=='0'&&s[6]=='1')cout<<"Heisei";
  else if(s[5]=='0'&&s[6]=='2')cout<<"Heisei";
  else if(s[6]=='3')cout<<"Heisei";
  else if(s[6]=='4')cout<<"Heisei";
  else cout<<"TBD";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
    int n;cin>>n;
    ll sum=0;
    rep(i,n){
        ll k;cin>>k;
        sum+=k;
    }
    cout<<sum-n<<endl;
}

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

using namespace std;
typedef long long llong;

#define MAX 200001

int n;
string s;
llong pwm[MAX], pwp[MAX];
// memo化用変数
int mem[MAX];

// カウントアップする関数
int get(int x)
{
    // memo化
    if (mem[x] != -1)
        return mem[x];
    // 0なら終了
    if (x == 0)
        return 0;
    // 再起で繰り返すたびにカウントアップ
    return mem[x] = 1 + get(x % __builtin_popcount(x));
}

int main()
{
    cin >> n >> s;
    int cnt = count(s.begin(), s.end(), '1');
    int m = cnt - 1, p = cnt + 1;
    // popcount が0なら
    // 反転してpopcountが１のｎ桁で必ず割り切れるので
    // 桁数分1を出して終了
    if (m == -1)
    {
        for (int i = 0; i < n; i++)
            cout << 1 << endl;
        return 0;
    }
    // 2^nのあまりを計算しとく
    //
    pwm[0] = 1;
    pwp[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        pwp[i] = (2 * pwp[i - 1]) % p;
        // m = 0ならpwmは０の除算になるので０にする
        if (m)
            pwm[i] = (2 * pwm[i - 1]) % m;
        else
            pwm[i] = 0;
    }
    llong pv = 0, mv = 0;
    for (int i = 0; i < n; i++)
    {
        // += 2^n * bit
        pv += pwp[n - i - 1] * (s[i] == '1');
        // 余りを求める　a+b=a'+b'の性質を利用
        pv %= p;
        if (m)
        {
            mv += pwm[n - i - 1] * (s[i] == '1');
            mv %= m;
        }
    }
    memset(mem, -1, sizeof mem);
    for (int i = 0; i < n; i++)
    {
        // 1を反転するなら
        if (s[i] == '1')
        {
            // s[i]が１でmが０なら全桁０になるので、計算しない
            if (!m)
                cout << 0 << endl;
            else
                cout << 1 + get((mv - pwm[n - i - 1] + m) % m) << endl;
        }
        // 0を反転するなら
        else
        {
            cout << 1 + get((pv + pwp[n - i - 1]) % p) << endl;
        }
    }
}

Measured memory_bytes: 7576
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  //freopen("input.txt","r",stdin);
#endif

  ll n;
  cin>>n;
  ll sum=0;

  vector<ll> count(n+1,1);
count[0] = count[1] = 1;
for (ll i = 2; i <= n; i++) {
    for(ll j=i;j<=n;j+=i)
    {
        count[j]++;
    }
}

for(ll i=1;i<=n;i++)
{
  sum+=i*count[i];
}

cout<<sum<<endl;


  
  
  return 0;
}

Measured memory_bytes: 81304
import java.util.*;

public class Main {

    public static void main(String[] args){
        init();
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();

        long[] mpow = new long[max];
        mpow[0] = 1;
        for(int i=1; i<max; i++) {
            mpow[i] = mpow[i-1] * (m-1) % mod;
        }
        long res = 0;
        for(int i=0; i<=k; i++) {
            res += (conv(n-1, i) * m % mod) * mpow[n-1-i] % mod;
            res %= mod;
        }
        System.out.println(res);

    }

    static int max = 210000;
    static long mod = 998244353;
    static long[] fac;
    static long[] finv;
    static long[] inv;

    static void init() {
        fac = new long[max];
        finv = new long[max];
        inv = new long[max];
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for(int i=2; i<max; i++) {
            fac[i] = fac[i-1] * i % mod;
            inv[i] = mod - inv[(int)mod%i] * (mod / i) % mod;
            finv[i] = finv[i-1] * inv[i] % mod;
        }
    }
    static long conv(int n, int k) {
        if(n<k || n<0 || k<0) return 0;
        return fac[n] * (finv[k]*finv[n-k]%mod) % mod;
    }

}

Measured memory_bytes: 42388
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

int cmp(const void *a, const void *b){
    //return *(int*)a - *(int*)b;
    if(*(ll*)a > *(ll*)b)return 1;
    else return -1;
}

const ll INF = 1000000000000000000ll;
ll n, a[100100];

main(){
    scanf("%lld", &n);
    for(int i=0; i<n; i++){
        scanf("%lld", &a[i]);
    }
    qsort(a, n, sizeof(ll), cmp);
    __uint128_t ans = 1;
    for(int i=0; i<n; i++){
        ans *= a[i];
        if(ans > INF){
            puts("-1");
            return 0;
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 3100
#include<cstdio>
#include<cstring>
using namespace std;
int e;
int v[100010*2],first[100010],next[100010*2];
void AddEdge(int U,int V){
	v[++e]=V;
	next[e]=first[U];
	first[U]=e;
}
int n,fa[100010],dep[100010];
void dfs(int U){
	for(int i=first[U];i;i=next[i]){
		if(!fa[v[i]]){
			fa[v[i]]=U;
			dep[v[i]]=dep[U]+1;
			dfs(v[i]);
		}
	}
}
bool vis[100010];
int X,Y,ans[2];
void dfs(int U,int op){
	vis[U]=1;
	++ans[op];
	for(int i=first[U];i;i=next[i]){
		if(!vis[v[i]] && !(U==X && v[i]==Y) && !(U==Y && v[i]==X)){
			dfs(v[i],op);
		}
	}
}
int main(){
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;++i){
		scanf("%d%d",&x,&y);
		AddEdge(x,y);
		AddEdge(y,x);
	}
	fa[1]=-1;
	dfs(1);
	int U=n;
	while(dep[U]!=dep[n]/2+1){
		U=fa[U];
	}
	X=fa[U],Y=U;
	dfs(X,0);
	memset(vis,0,sizeof(vis));
	dfs(Y,1);
	if(ans[0]<=ans[1]){
		puts("Snuke");
	}
	else{
		puts("Fennec");
	}
	return 0;
}

Measured memory_bytes: 6144
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
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; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
int main() {
    int n;
    cin>>n;
    V dp(1e7,INF);
    dp[0]=0;
    rep(i,n+1){
        for(int j=1;j<=n;j*=6){
            if(i>=j){
                dp[i]=min(dp[i-j]+1,dp[i]);//もらってみたｂ
            }
        }
        for(int j=1;j<=n;j*=9){
            if(i>=j){
                dp[i]=min(dp[i-j]+1,dp[i]);
            }
        }
    }
    cout<<dp[n]<<endl;
}

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


#define vt vector
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define ar array
#define inf() ifstream cin("d.txt")
#define onf() ofstream cout("test.txt")
#define mod 1000000007
#define pb push_back
#define endl cout<<"\n";
#define prt1(a) cout<<a<<" "
#define prt2(a,b) cout<<a<<" "<<b<<" "
#define prt3(a,b,c) cout<<a<<" "<<b<<" "<<c<<" "
#define in(a) cin>>a
#define inn(a,b) cin>>a>>b
#define innn(a,b,c) cin>>a>>b>>c 
#define rep(i,st,end) for(int i=st;i<end;i++)
#define repv(i,st,end) for( i=st;i>=end;i--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define TEST ll tc;cin>>tc;while(tc--)
#define EACH(x, a) for (auto& x: a)

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x) {
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}

void solve()
{
  string s,t;
  read(s,t);
  ll ans = 1002;
  ll n=s.length();
  ll m =t.length();
  
  rep(i,0,n-m+1)
  {
    ll l = 0;
    string na = s.substr(i,m);
    rep(j,0,m)
    {
      if(na[j]!=t[j])
        l++;
    }
    ans=min(ans,l);
  }
  cout<<ans;

}

 int main()
 {
    fio;
    ll k = 1;
    ll tc;
    tc = 1;
    // cin>>tc;
    while(tc--){
       // cout<<"Case #"<<k<<": ";k++;
        solve();
        endl;
    }
    
 }




Measured memory_bytes: 3676
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    int n = nxt();
    int x = nxt(), y = nxt();
    VVI adjList(n, VI());
    REP(i, n-1) {
        adjList[i].push_back(i+1);
        adjList[i+1].push_back(i);
    }
    x--;y--;
    adjList[x].push_back(y);
    adjList[y].push_back(x);
    VI ans(n);
    REP(i, n){
        VI dist(n, INF);
        queue<PII> q; q.push({0, i});
        while(!q.empty()){
            auto front = q.front(); q.pop();
            int d = front.first, u = front.second;
            if(d > dist[u]) continue;
            dist[u] = d;
            for(int v : adjList[u]){
                if(dist[u] + 1 < dist[v]){
                    dist[v] = dist[u]+1;
                    q.push({dist[v], v});
                }
            }
        }
        for(int j = i+1; j < n; j++) {
            ans[dist[j]]++;
        }
    }
    for(int i = 1; i < n; i++) printf("%d\n", ans[i]);
    return 0;
}



Measured memory_bytes: 384
// Problem : C - H and V
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_c
// Memory Limit : 1024 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
using namespace std;
#define int         long long int
#define vi           vector<int>
#define pii          pair<int,int>
#define vpp          vector<pii>
#define mii          map<int,int>
#define pb           push_back
#define rep(i,a,bb)  for(int i=a;i<bb;i++)
#define ff           first
#define ss           second
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test         int T;cin>>T;while(T--)
#define __sort(v)    sort(v.begin(),v.end())
#define __rsort(v)   sort(v.rbegin(),v.rend())
#define setbits(x)   __builtin_popcount(x)
#define zrobits(x)   __builtin_ctzint(x)
#define endl '\n'
#define debug(x)  cerr<<"[ "<<#x<<" : "<<x<<" ]"<<endl
#define debugp(x) cerr<<"[ "<<#x<<".ff : "<<x.first<<", "<<#x<<".ss : "<<x.second<<" ]"<<endl
#define debugs(x) cerr<<"[ "; for(auto i:x) cerr<<i<<" "; cerr<<" ]"<<endl;
#define debugm(x) cerr<<"----------"<<endl; for(auto i:x) cerr<<i.ff<<":"<<i.ss<<endl; cerr<<"----------"; 
#define PI 3.14159265359
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int dxk[]={0,0,1,-1,1,1,-1,-1};
int dyk[]={1,-1,0,0,1,-1,1,-1};
const int inf = 1e+18;
const int mod = 1e+9 + 7;

int n, m, k;
vector<string> v;
void solve()
{
    cin>>n>>m>>k;
    v.resize(n);
    rep(i,0,n){
    	cin>>v[i];
    }	
    
    // _ _
    // 1 1 
    // _ _ _
    // 
    int res = 0;
    rep(i,0,pow(2, n)){
    	   rep(j,0,pow(2, m)){
    	   	  int black = 0, ans = 0;
    	   	  rep(k, 0, n){
    	   		 rep(l,0,m){
    	   			if(((i&1<<k)||(j&(1<<l)))&&v[k][l]=='#')
    	   			   ++ans;
    	   			if(v[k][l]=='#')
    	   			   ++black;
    	   			  
    	   		}
    	   	}
    	   	
    	   	if(black-ans==k)
    	   	  {
    	   	  	//cout<<i<<" "<<j<<endl;
    	   	  	++res;
    	   	}
    	   }
    }
    
    cout<<res<<endl;   
    
    
}


// 00, 01, 10, 11
// 000, 001, 010, 011, 

int32_t main()
{
  fast;
  //test
  solve();
  return 0;
}


Measured memory_bytes: 3980
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N, K;
    cin >> N >> K;

    ll answer = K * pow(K-1, N-1);
    p(answer);
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
ll a, b, v, w, t;
string s;

int main() {
    scanf(" %lld %lld", &a, &v);
    scanf(" %lld %lld", &b, &w);
    scanf(" %lld", &t);
    ll direction = 1;
    if (a > b) direction = -1;
    ll aafter = a + direction * v * t;
    ll bafter = b + direction * w * t;

    bool judge = false;
    if (a > b && aafter <= bafter) judge = true;
    if (a < b && aafter >= bafter) judge = true;
    if (judge) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 3684
A, B, C, D = input()
A1 = int(A)
B1 = int(B)
C1 = int(C)
D1 = int(D)
if A1+B1+C1+D1 == 7:
  print(A+'+'+B+'+'+C+'+'+D+'=7')
elif A1+B1+C1-D1 == 7:
  print(A+'+'+B+'+'+C+'-'+D+'=7')
elif A1+B1-C1+D1 == 7:
  print(A+'+'+B+'-'+C+'+'+D+'=7')
elif A1+B1-C1-D1 == 7:
  print(A+'+'+B+'-'+C+'-'+D+'=7')
elif A1-B1+C1+D1 == 7:
  print(A+'-'+B+'+'+C+'+'+D+'=7')
elif A1-B1+C1-D1 == 7:
  print(A+'-'+B+'+'+C+'-'+D+'=7')
elif A1-B1-C1+D1 == 7:
  print(A+'-'+B+'-'+C+'+'+D+'=7')
elif A1-B1-C1-D1 == 7:
  print(A+'-'+B+'-'+C+'-'+D+'=7')

Measured memory_bytes: 3064
from bisect import bisect_left

D = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(D)]
T = [int(input()) for _ in range(D)]
days = [[0] for _ in range(26)]

def init():
    global T, days
    score = 0
    last = [0] * 26
    for d, t in enumerate(T, 1):
        score += S[d - 1][t - 1]
        last[t - 1] = d
        for c, l in zip(C, last): score -= c * (d - l)
        days[t - 1].append(d)
    for i in range(26): days[i].append(D+1)
    return score

def diff(d, q):
    global score, T, C, S, days
    p = T[d - 1]
    score += S[d - 1][q - 1] - S[d - 1][p - 1]
    idx_p = bisect_left(days[p - 1], d)
    bef_p, aft_p = days[p - 1][idx_p - 1], days[p - 1][idx_p + 1]
    del days[p - 1][idx_p]
    idx_q = bisect_left(days[q - 1], d)
    bef_q, aft_q = days[q - 1][idx_q - 1], days[q - 1][idx_q]
    days[q - 1].insert(idx_q, d)
    score += C[q - 1] * (d - bef_q) * (aft_q - d) - C[p - 1] * (d - bef_p) * (aft_p - d)
    T[d - 1] = q
    return score
    
score = init()
M = int(input())
for _ in range(M):
    d, q = map(int, input().split())
    print(diff(d, q))

Measured memory_bytes: 9416
#include <bits/stdc++.h>
#define rep(i,n) for((i)=1;(i)<=(n);(i)++) 
using namespace std;
int n,m,i,j,px[405],py[405],qa[405],qb[405],s,t,tot;
char qt[405];
int mix[405],miy[405],mxx[405],mxy[405];
struct edge{
	int y,z;long long d;
}e[2000005];
int vis[405],iq[405];
long long ans,cst,dis[405],pv[405];
vector<int> adj[405];
void add(int x,int y,int z,long long d){
	++tot;
	adj[x].push_back(tot*2-2);
	adj[y].push_back(tot*2-1);
	e[tot*2-2]=(edge){y,z,d};
	e[tot*2-1]=(edge){x,0,-d}; 
}
bool bfs(int s,int t){
	memset(dis,-0x3f,sizeof(dis));
	dis[s]=0;queue<int> q;q.push(s);
	while(!q.empty()){
		int x=q.front();q.pop();iq[x]=0;
		for(int i=0;i<adj[x].size();i++){
			int t=adj[x][i];
			if(e[t].z&&dis[e[t].y]<dis[x]+e[t].d){
				dis[e[t].y]=dis[x]+e[t].d;
				if(!iq[e[t].y]){q.push(e[t].y);iq[e[t].y]=1;}
			}
		}
	}
	return dis[t]>dis[0];
}
int dfs(int x,int tt,int fw){
	if(!fw) return 0; 
	if(x==tt) return vis[x]=1,fw;
	if(vis[x]) return 0;vis[x]=1;
	int res=0;
	for(int i=0;i<adj[x].size();i++){
		int y=adj[x][i];
		if(e[y].z&&dis[e[y].y]==dis[x]+e[y].d){
			int t=dfs(e[y].y,tt,min(fw,e[y].z));
			fw-=t;res+=t;e[y].z-=t;e[y^1].z+=t;
			cst+=e[y].d*t;
		}
	}
	return res;
}
int dinic(int s,int t){
	int ans=0;
	while(bfs(s,t)){
		do{
			memset(vis,0,sizeof(vis));
			ans+=dfs(s,t,0x3f3f3f3f);
		}while(vis[t]);
	}
	return ans;
}
long long calc(int k){
	int i,j;
	rep(i,k){
		mix[i]=miy[i]=0;
		mxx[i]=mxy[i]=101;
	}
	rep(i,m){
		if(qb[i]<k){
			if(qt[i]=='L') mix[qb[i]+1]=qa[i]+1;
			if(qt[i]=='R') mxx[k-qb[i]]=qa[i]-1; 
			if(qt[i]=='D') miy[qb[i]+1]=qa[i]+1;
			if(qt[i]=='U') mxy[k-qb[i]]=qa[i]-1; 
		}
	}
	for(i=2;i<=k;i++){
		mix[i]=max(mix[i],mix[i-1]);
		miy[i]=max(miy[i],miy[i-1]);
	}
	for(i=k-1;i;i--){
		mxx[i]=min(mxx[i],mxx[i+1]);
		mxy[i]=min(mxy[i],mxy[i+1]);
	}
	rep(i,4*n+2){
		adj[i].clear();
	}
	tot=0;
	rep(i,k){
		add(s,n+i,1,0);
		add(n+n+i,t,1,0);
	}
	rep(i,n){
		add(i,n+n+n+i,1,pv[i]);
		rep(j,k){
			if(mix[j]<=px[i]&&px[i]<=mxx[j]){
				add(n+j,i,1,0);
			}
			if(miy[j]<=py[i]&&py[i]<=mxy[j]){
				add(n+n+n+i,n+n+j,1,0);
			}
		}
	}
	cst=0;
	if(dinic(s,t)!=k) return 0;
/*	if(k==4){
		for(i=0;i<tot*2;i+=2){
			if(1<=e[i].y&&e[i].y<=n&&n+1<=e[i^1].y&&e[i^1].y<=n+n&&!e[i].z){
				cerr<<e[i].y<<endl;
			}
		}
	}*/
	return cst;
}
int main(){
	cin>>n;s=4*n+1;t=4*n+2;
	rep(i,n){
		cin>>px[i]>>py[i]>>pv[i];
	}
	cin>>m;
	rep(i,m){
		cin>>qt[i]>>qa[i]>>qb[i];
	}
	rep(i,n){
		ans=max(ans,calc(i));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
         
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
const int N = 100001; 



void solve(){
	int n;cin>>n;
	string s;cin>>s;
	int w=0,w0=0;
	rep(i,0,n){
		if(s[i]=='W')w++;
	}
	rep(i,n-w,n){
		if(s[i]=='W')w0++;
	}
	cout<<w-w0;
    return;
}
         
signed main(){
        IOS;    
        

        int t=1;
        // cin>>t;
        // fac[0] = 1; 
        // for (int i=1 ; i<=2000001; i++) fac[i] = fac[i-1]*i%mod; 
        rep(i,0,t){
            solve();
            cout<<"\n";
        //   cout<<" * "<<t<<"\n";
        }
    //    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;

ll dp[52][52][2600] = {};



int main(){

    int n,a;
    cin >> n >> a;
    int x[n];
    for(int i=0; i<n; i++){
	cin >> x[i];
    }
    

//    cout << "debug"<< endl;

    dp[0][0][0] = 1;
    for(int i=0; i<n; i++){
	for(int num=0; num<50; num++){
	    for(int sum=0; sum<50*50; sum++){
		dp[i+1][num][sum] += dp[i][num][sum];
		dp[i+1][num+1][sum+x[i]] += dp[i][num][sum];
	    }
	}
    }
    ll ans = 0;
    for(int num=1; num<=n; num++){
	int sum = a*num;
	ans += dp[n][num][sum];
    }
    cout << ans << endl;

}


Measured memory_bytes: 52224
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
  string S, T;
  int s, i;
  cin >> S >> T;
  int ans = T.length();

  for (s = 0; s <= S.length() - T.length(); s++)
  {
    int count = 0;
    for (i = 0; i < T.length(); i++)
    {
      if (T[i] != S[s + i])
        count++;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}


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

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

	int count = 0;
	
	for (int i=100; i > 0; i--)
	{
		if (a % i == 0 && b % i == 0)
		{
			count++;
			if (count == k)
			{
				cout << i << endl;
			}
		}
	}

	return 0;
}

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

int main(void) {
	int N;
	cin >> N;
	int ans = 0;
	int minP = 200001;
	for (int i = 0; i < N; i++) {
		int P;
		cin >> P;
		if (P<=minP) ans++;
		minP = min(minP, P);
	}
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);

		boolean[] is_prime = new boolean[10001];
		
		for(int i = 2; i <= 10000; i++){
			is_prime[i] = true;
		}
		
		for(int i = 2; i <= 100; i++){
			if(is_prime[i]){
				for(int j = i * 2; j <= 10000; j += i){
					is_prime[j] = false;
				}
			}
		}
		
		ArrayList<Integer> p_list = new ArrayList<Integer>(); 
		for(int i = 2; i <= 10000; i++){
			if(is_prime[i]){
				p_list.add(i);
			}
		}
		
		int[] count = new int[10001];
		final int size = p_list.size();
		
		for(int len = 1; len <= size; len++){
			int sum = 0;
			for(int i = 0; i < len; i++){
				sum += p_list.get(i);
			}
			
			if(sum > 10000){
				break;
			}
			count[sum]++;
			
			for(int i = len; i < size; i++){
				sum += p_list.get(i);
				sum -= p_list.get(i - len);
				if(sum > 10000){
					break;
				}
				
				count[sum]++;
			}
		}
		
		/*
		for(int i = 0; i < 21; i++){
			System.out.println(i + " : " + dp[i] + " , ");
		}
		System.out.println();
		*/
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			System.out.println(count[n]);
		}
	}

}

Measured memory_bytes: 22024
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(Usize1,Usize1);m],
    }

    let mut nodes = vec![Vec::new(); n];
    for (a, b) in ab {
        nodes[a].push(b);
        nodes[b].push(a);
    }

    let mut queue = VecDeque::new();
    let mut prev = vec![None; n];
    queue.push_back(0);
    prev[0] = Some(0);
    while let Some(node) = queue.pop_front() {
        for &next in &nodes[node] {
            if prev[next].is_some() {
                continue;
            }
            queue.push_back(next);
            prev[next] = Some(node);
        }
    }

    println!("Yes");
    for i in 1..n {
        println!("{}", prev[i].unwrap() + 1);
    }
}


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

int store[200007];

ll again(ll n)
{
    ll cnt = 0;
    ll sum = store[1];
    if (store[1] >= 0) sum = -1, cnt = store[1] + 1;

    for (int i = 2; i <= n; i++) {
        if (sum < 0 && sum + store[i] <= 0) {
            cnt += 1 - (sum+store[i]);
            sum = 1;
        }
        else if (sum > 0 && sum + store[i] > 0) {
            cnt += (sum+store[i]) + 1;
            sum = -1;
        }
        else sum += store[i];
    }

    return cnt;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) scanf("%d", &store[i]);

    ll cnt = 0;
    ll sum = store[1];
    if (store[1] <= 0) sum = 1, cnt = 1 - store[1];

    for (int i = 2; i <= n; i++) {
        if (sum < 0 && sum + store[i] <= 0) {
            cnt += 1 - (sum+store[i]);
            sum = 1;
        }
        else if (sum > 0 && sum + store[i] > 0) {
            cnt += (sum+store[i]) + 1;
            sum = -1;
        }
        else sum += store[i];
    }

    ll cnt2 = again(n); ///ekbar 1st element neg nie arekbar pos nie

    cout << min(cnt, cnt2) << "\n";
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>


int *WORK;
int compare_count = 0;

int n;

void Merge_sort(int *S, int low, int high)
{
	int mid;
	int i, j, k;


	if(high <= low)
		return;

	mid = (low + high) / 2;

	// 左側の処理
	Merge_sort(S, low, mid);

	// 右側の処理
	Merge_sort(S, mid + 1, high);

	for(i = low; i <= mid; i++)
		WORK[i] = S[i];

	for(i = high, j = mid + 1; i > mid; i--, j++)
		WORK[i] = S[j];

	// マージ
	i = low;
	j = high;
	for(k = low; k <= high; k++){
		if(WORK[i] <= WORK[j])
			S[k] = WORK[i++];
		else
			S[k] = WORK[j--];
		compare_count++;
	}
}


int main()
{
	int *S;
	int i;


	scanf("%d", &n);

	S = (int *)malloc(sizeof(int) * n);
	WORK = (int *)malloc(sizeof(int) * n);

	for(i = 0; i < n; i++)
		scanf("%d", &S[i]);


	Merge_sort(S, 0, n - 1);


	for(i = 0; i < n; i++){
		printf("%d", S[i]);
		if(i != n - 1)
			printf(" ");
		else
			printf("\n");
	}
	printf("%d\n", compare_count);


	return 0;
}


Measured memory_bytes: 5760
INF  = Float::INFINITY
Edge = Struct.new(:from, :to, :cost)
 
class Graph
  attr :edges, :V, :E, :d
  def initialize(v,e)
    @V = v
    @E = e
    @edges = []
    @d = []
  end
 
  def add_graph_edge(u, v, w)
    @edges << Edge.new(u,v,w)
  end
 
  def bellman_ford(source=0)
    @d = Array.new(@V,INF)
    @d[source] = 0
 
    for count in 0...@V
      for i in 0...@edges.length
        v = edges[i].to
        u = edges[i].from
        c = edges[i].cost
 
        if @d[u] != INF and @d[u] + c < @d[v]
          @d[v] = @d[u] + c
          return false if (count >= @V-1 and v==@V-1)
        end
      end
    end
    true
  end
end
 
lines = $stdin.read
array = lines.split("\n")
V,E = array[0].split(" ").map(&:to_i)
graph = Graph.new(V,E)
 
array[1..E].each do |str|
  a,b,c = str.split(" ").map(&:to_i)
  u,v,w = a-1,b-1,-c
  graph.add_graph_edge(u,v,w)
end
 
if graph.bellman_ford()
  puts (-1 * graph.d[V-1])
else
  puts "inf"
end


Measured memory_bytes: 2172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String data[] = br.readLine().split(" ");
		int a = Integer.parseInt(data[0]);
		int b = Integer.parseInt(data[1]);
		int c = Integer.parseInt(data[2]);
		int count = 0;

		for (int i = a; i <= b; i ++) {
			if (c % i == 0){
			 count++;
			}

		}
		System.out.println(count);
	}
}

Measured memory_bytes: 24480
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
 
public class Main {
    static int n;
    static boolean[][] connected;
 
    static public int countPattern(int pos, Set<Integer> visited) {
        if (visited.size() == n) return 1;
 
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (connected[pos][i] && !visited.contains(i)) {
                visited.add(i);
                count += countPattern(i, visited);
                visited.remove(i);
            }
        }
        return count;
    }
 
    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int m = sc.nextInt();
 
        connected = new boolean[n][n];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
 
            connected[a][b] = true;
            connected[b][a] = true;
        }
 
        Set<Integer> visited = new HashSet<>();
        visited.add(0);
        int count = countPattern(0, visited);
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
def main():
    N, M = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    updates = list()
    for _ in range(M):
        B, C = list(map(int, input().split(' ')))
        updates.append((B, C))
    updates.sort(key=lambda x: x[1], reverse=True)
    for B, C in updates:
        A.extend([C] * B)
        if len(A) > 2 * N:
            break
    A.sort(reverse=True)
    print(sum(A[:N]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 24040
N,K = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]

ab.sort(key = lambda x:x[0])
idx = 0
i = 0
while True:
    if idx + ab[i][1] > K-1:
        ans = ab[i][0]
        break
    else:
        idx += ab[i][1]
    i += 1
    


print(ans)  
    

Measured memory_bytes: 29144
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  REP(i,s.size()) {
    char c = s[i] + n;
    if(c > 'Z') c -= 26;
    cout << c;
  }
  cout << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
n = int(input())
s = input()
num = 0
for i in range(1, n):
    q = s[:i]
    p = s[i:]
    tmp1 = set()
    for j in q:
        tmp1.add(j)
    tmp2 = set()
    for j in p:
        tmp2.add(j)

    num = max(num, len(tmp1 & tmp2))

print(num)


Measured memory_bytes: 3060
#include<stdio.h> 
int main() 
{ 
      int a,b,x,w; 
      while(scanf("%d %d",&a,&b)!=EOF) 
      { 
         x=a+b;
		 w=0; 
         while(x) 
           { 
		      w++; 
              x/=10; 
           } 
         printf("%d\n",w); 
      } 
      return 0; 
} 

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define pb push_back

using namespace std;

const int N = 1e5 + 10;

vector<int> G[N];
int n, sg[N];

void DFS(int o, int f){
	for(int v : G[o]){
		if(v == f) continue;
		DFS(v, o);
		sg[o] ^= sg[v] + 1;
	}
}

int main(){
	scanf("%d", &n);
	For(i, 2, n){
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].pb(v), G[v].pb(u);
	}
	DFS(1, 0);
	puts(sg[1] ? "Alice" : "Bob");
	return 0;
}

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

int main() {
  long long N,mod=1000000007,ans=1;
  cin >> N;
  unordered_map<int,int> M;
  M[-1] = 3;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    ans *= M[a-1]-M[a];
    ans %= mod;
    M[a]++;
  }
  
  cout << ans << endl;
  return 0;
}


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

int main(){
    string a, b;
    cin >> a >> b;
    if(a.size() > b.size()){
        cout << "GREATER" << endl;
    }else if(a.size() < b.size()){
        cout << "LESS "<< endl;
    }else if(a > b){
        cout << "GREATER" << endl;
    }else if(b >a){
        cout << "LESS "<< endl;
    }else{
        cout << "EQUAL" << endl;
    }
    return 0;
}





Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if((c%b>0?c/b+1:c/b)<=(a%d>0?a/d+1:a/d)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 27080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			StringTokenizer st = new StringTokenizer(line);

			int W, H, x, y, r;
			W = Integer.parseInt(st.nextToken());
			H = Integer.parseInt(st.nextToken());
			x = Integer.parseInt(st.nextToken());
			y = Integer.parseInt(st.nextToken());
			r = Integer.parseInt(st.nextToken());

			boolean res = true;
			if (x - r < 0 || x + r > W || y - r < 0 || y + r > H) res = false;
			System.out.println(res ? "Yes" : "No");
		}
	}
}

Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll gcd(ll a,ll b){
    if(b==0)
    return a;
    return gcd(b,a%b);
}

int main() {
    fastio
	ll n,t,i,j,x,k;
    cin>>n;
    ll b[1000001]={0};
    
    for(i=2;i*i<1000001;i++){
        if(b[i]==0){
            for(j=i*i;j<1000001;j+=i)
            b[j]=1;
        }
    }
    vector<ll> v(1000001,0);
    set<ll> st;
    for(i=2;i<1000001;i++)
    if(b[i]==0) st.insert(i);
    
    ll a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    
    ll ans=gcd(a[0],a[1]);
    set<ll>::iterator it;
    for(i=2;i<n;i++)
    if(ans!=1)
    ans=gcd(ans,a[i]);
    
    if(ans>1) cout<<"not coprime";
    else{
        sort(a,a+n);
        for(i=0;i<n;i++){
            for(it=st.begin();it!=st.end();it++){
                ll c=(*it);
                if(a[i]%c==0){
                    v[c]++;
                    if(v[c]>1){
                        cout<<"setwise coprime";
                        exit(0);
                    }
                    st.erase(c);
                }
                
                while(a[i]%c==0)
                a[i]/=c;
                if(a[i]==1) break;
            }
            if(a[i]!=1){
                cout<<"setwise coprime";
                exit(0);
            }
        }
        cout<<"pairwise coprime";
    }
    
	return 0;
}

Measured memory_bytes: 30668