akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    private Scanner stdin;
    private PrintWriter stdout;

    public void execute() {
        this.stdin = new Scanner(new BufferedInputStream(System.in));
        this.stdout = new PrintWriter(new BufferedOutputStream(System.out));

        while (this.stdin.hasNext()) {
            int n = stdin.nextInt();
            if (n == 1) {
                stdout.printf("Hello World\n");
            } else {
                int a = stdin.nextInt();
                int b = stdin.nextInt();
                stdout.printf("%d\n", a + b);
            }
        }

        this.stdin.close();
        this.stdout.close();
    }

    public static void main(String[] args) throws Exception {
        Main instance = new Main();
        instance.execute();
    }

}

Measured memory_bytes: 21204
from pprint import pprint
import sys

n = int(sys.stdin.readline().strip())
h = list(map(int, sys.stdin.readline().strip().split(" ")))
# pprint(h)

inf = 10 ** 10
costs = [inf] * n

costs[0] = 0
costs[1] = abs(h[1] - h[0])
# print("n", n)
for i in range(2, n):
    costs[i] = min(costs[i-1] + abs(h[i] - h[i-1]), costs[i-2] + abs(h[i] - h[i-2]))

# pprint(costs)
print(costs[n-1])

Measured memory_bytes: 52560
//#define _GLIBCXX_DEBUG
//#define _CRTDBG_MAP_ALLOC
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

const ll LINF = 9187201950435737471;
const ll nLINF = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const int MAXN = 2e4 + 15;
const ll MOD = 1e9  ;
const double EPS = 1e-9;
const double PI = acos(-1);
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(seed);

#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) (_v * _v)
#define vi vector <int>
#define vii vector <pair <int, int> >
#define eb emplace_back
#define pb push_back


inline void IO() {
#if(DEBUG_LEVEL > 0)
    freopen("../input.txt", "r", stdin);
    freopen("../out.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
}

template <typename T>
istream& operator >> (istream& in, vector<T>& a) {
    for (auto& i : a)
        in >> i;
    return in;
}

template <typename T>
ostream& operator << (ostream& out, const vector<T>& a) {
    for (auto& i : a) {
        out << i << " ";
    }
    return out;
}

template <typename T, typename D>
istream& operator >> (istream& in, pair<T, D>& a) {
    in >> a.first >> a.second;
    return in;
}

template <typename T, typename D>
ostream& operator << (ostream& out, const pair<T, D>& a) {
    out << a.first << " " << a.second;
    return out;
}

inline void solve() {
    string s;
    cin >> s;
    for (int i = 0; i < sz(s); ++i) {
        cout << "x";
    }
}

signed main() {
    IO();
    int t = 1;
   // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;


struct UnionFind
{
    int n;
    vector<int> parent;
    vector<int> rank;
    UnionFind(int _n) :n(_n)
    {
        parent.assign(n, -1);
        rank.assign(n, 1);
    }

    int find(int i)
    {
        if (parent[i] == -1)
            return i;
        else
            return parent[i] = find(parent[i]);
    }

    void unite(int i, int j)
    {
        i = find(i);
        j = find(j);

        if (i == j) return;

        if (rank[i] == rank[j])
        {
            parent[j] = i;
            ++rank[i];
        }
        else
        {
            if (rank[i] < rank[j]) swap(i, j);
            parent[j] = i;
        }
    }

    bool is_same(int i, int j)
    {
        return find(i) == find(j);
    }
};

int main()
{
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    rep(i, 0, M) {
        int A, B;
        cin >> A >> B;
        --A, --B;
        uf.unite(A, B);
    }

    vector<int> cnt(N, 0);
    rep(i, 0, N) ++cnt[uf.find(i)];
    cout << *max_element(cnt.begin(), cnt.end()) << endl;
    return 0;
}


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


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

    for(int i = a; i <=b; i++){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, M;
	cin >> N >> M;
	vector<ll> X(M);
	REP(i, M) cin >> X[i];

	if(N>=M){
		cout << 0 << endl;
		return 0;
	}

	sort(X.begin(), X.end());
	vector<pll> sa(M-1);
	REP(i, M-1) sa[i] = {X[i+1] - X[i], i};
	sort(sa.rbegin(), sa.rend());
	vector<ll> kire;
	REP(i, N-1){
		kire.push_back(sa[i].second);
	}
	kire.push_back(-1);
	kire.push_back(M-1);
	sort(kire.begin(), kire.end());
	ll res = 0;
	REP(i, kire.size()-1){
		ll haji = kire[i]+1;
		ll owa = kire[i+1];
		ll cnt = (haji+owa)/2;
		//dump(cnt)
		//dump(X[haji])
		//dump(X[cnt])
		//dump(X[owa])
		res += (X[cnt] - X[haji]);
		res += (X[owa]-X[cnt]);
	}
	cout << res << endl;
	//vprint(kire);
    return 0;
}

Measured memory_bytes: 3704
fun main(arr: Array<String>) {
    val s = readLine()!!.toMutableList()
    var idx = 0
    var ans = 0
    while (idx < s.size - 1) {
        if(s[idx] != s[idx+1]) {
            s.removeAt(idx)
            s.removeAt(idx)
            ans += 2
            idx = Math.max(0, idx-1)
        } else {
            idx++
        }
    }
    println(ans)
}


Measured memory_bytes: 38468
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;
using ll = unsigned long long;
using p = pair<int, int>;

int main()
{
    string S, T;
    cin >> S >> T;

    ll size = S.size();

    ll count = 0;
    for (ll i = 0; i < size; ++i)
    {
        if (S[i] != T[i])
        {
            ++count;
        }
    }

    std::cout << count << endl;

    return 0;
}


Measured memory_bytes: 3916
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <ctime>
#include<list>
#include <numeric>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include <array>
using namespace std;

#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; }
	template<class c> typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
		cerr << boolalpha << i; return *this;
	}

	template<class c, int=0> typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
		return *this << 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 << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define watch(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(int i = 0; i < n; i++)
#define FORAB(i, a, b) for(int i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int128 LLL;
typedef long long LLL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PLL > VPL;
typedef vector<PII > VP;
typedef vector<double> VD;
typedef vector<vector<int>> VVI;
typedef long double ld;

const LL MOD = 998244353;

void solve(int ks) {
	LL n, m;
	cin >> n >> m;
	LL ans = MIN(n, m / 2);
	n -= ans;
	m -= ans * 2;
	ans += m / 4;
	cout << ans << endl;
}

int main()
{
#ifdef LOCAL
	double start_time = clock();
	freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin);
	//	freopen("out.out", "w", stdout);
#endif


	if (0) {
		int T;
		scanf("%d", &T);
		//AIN(T, 1, 25);
		for (int ks = 1; ks <= T; ks++) {
			solve(ks);
			fprintf(stderr, "%d done\n", ks);
		}
	}
	else {
		solve(0);
	}

#ifdef LOCAL
	double end_time = clock();
	fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <math.h>
int main()
{
  long int n,m;
  scanf("%ld %ld",&n,&m);
  if(n>=m/2)
  {
    printf("%ld\n",m/2);
    return 0;
  }
  printf("%ld\n",n+(m-n*2)/4);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

ll a[N][4], dp[N][4];
int n;
ll f(int id, int pre)
{
	if(id > n)
		return 0;
	ll ans = dp[id][pre];
	if(ans != -1)
		return ans;
	for(int i = 1; i <= 3; i ++)
		if(i != pre)
			umax(ans, a[id][i] + f(id + 1, i));
	return dp[id][pre] = ans;
}

int main()
{
	memset(dp, -1, sizeof dp);
	cin >> n;
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= 3; j ++)
			cin >> a[i][j];
	cout << f(1, 0);
}

Measured memory_bytes: 18304
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int a,b,c,d;
 	cin >> a>>b>>c>>d;
 	cout << (a-c)*(b-d) << endl;
 }

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

#define L 6
#define putchar_buf(X) do{ buf[point] = X; point++; }while(0)
#define putlong_buf(X) \
    do{ \
        long n=X; \
        char c[L]; \
        long i=L-1; \
        do{ c[i]=n%10+'0'; n/=10; i--; }while(n>0); \
        for(i++;i<L;i++){ putchar_buf(c[i]); } \
    }while(0)
#define puts_buf(X) \
    do { \
        for(size_t i=0; X[i]!='\0'; i++){ \
            putchar_buf(X[i]); \
        } \
        putchar_buf('\n'); \
    }while(0)

char buf[819200];
size_t point;

static void solve(const long a, const long b, const size_t sp, const size_t ep, long mask, const long common){
    if(ep-sp<=2){
        putlong_buf(common|a);
        putchar_buf(' ');
        putlong_buf(common|b);
        putchar_buf(' ');
    }else{
        const long t = a^b;
        const long d = t&(-t);
        mask ^= d;
        const long aa = a & mask;
        const long ab = aa ^ (mask&(-mask));
        const size_t mp = (sp+ep)/2;
        solve(aa,     ab, sp, mp, mask, common|(a&d));
        solve(ab, b&mask, mp, ep, mask, common|(b&d));
    }
}

int main(void){
    long n, a, b;
    scanf("%ld %ld %ld", &n, &a, &b);
    if(__builtin_parity(a) == __builtin_parity(b)){
        puts("NO");
    }else{
        const size_t m = 1<<n;
        puts_buf("YES");
        solve(a, b, 0, m, 0xFFFFFFFFFFFFFFFF, 0);
        write(1, buf, point);
    }
    return 0;
}


Measured memory_bytes: 1664
N, L = map(int, input().split())

apples = []

should_eat_score = float("inf")

for i in range(N):
    apples.append(L+i)
    if abs(should_eat_score) > abs(L+i):
        should_eat_score = L+i

apples.remove(should_eat_score)

print(sum(apples))


Measured memory_bytes: 38256
n = int(input())
arr = [0] + list(map(int,input().split())) + [0]

tmp = 0
for i in range(1, n+2):
    tmp += abs(arr[i-1] - arr[i])
    
for j in range(1, n+1):
    ans = tmp - (abs(arr[j-1] - arr[j]) + abs(arr[j] - arr[j+1])) + abs(arr[j-1] - arr[j+1])
    print(ans)

Measured memory_bytes: 14176
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main() 
{
	lli n;
	cin >> n;
	
	lli a[n];
	
	lli addition  = 0;
	for(lli i=0;i<n;i++)
	{
		cin >> a[i];
		if (addition == 0)
		{
			addition = a[i];
		}
		else
		{
			addition ^= a[i];
		}
	}
	
	for(lli i = 0; i < n; i++)
	{
		cout << (addition ^ a[i]) << " ";
	}
	
	return 0;
}

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

using ll = long long;
const ll INF = 2e18;

const int MAXN = 1010;
int N, M;
ll A[MAXN][3];

ll dp[MAXN];

ll go(vector<int> coeffs) {
	fill(dp + 1, dp + M+1, -INF);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		ll delta = 0;
		for (int j = 0; j < 3; j++) {
			delta += coeffs[j] * A[i][j];
		}
		for (int a = M-1; a >= 0; a--) {
			dp[a+1] = max(dp[a+1], dp[a] + delta);
		}
	}
	return dp[M];
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}

	ll ans = 0;
	for (int m = 0; m < 8; m++) {
		vector<int> coeffs(3);
		for (int i = 0; i < 3; i++) {
			coeffs[i] = ((m & (1 << i)) ? 1 : -1);
		}
		ans = max(ans, go(coeffs));
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>

using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int N;
int C[1010], W[1010], dp[1010],sm[1010];
int can[1010][1010];
int get(int a, int b) { // [a,b]
	int res = sm[b];
	if (a) res -= sm[a - 1];
	return res;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	cin >> N;
	REP(i, N) cin >> C[i] >> W[i];
	sm[0] = W[0];
	FOR(i, 1, N) sm[i] = sm[i - 1] + W[i];
	REP(i, N)can[i][i] = 1;
	FOR(len, 2, N + 1) {
		REP(L, N - len + 1) {
			int R = L + len - 1;

			if (get(L, R - 1) <= C[R] && can[L][R - 1])can[L][R] = 1;
			if (get(L + 1, R) <= C[L] && can[L + 1][R])can[L][R] = 1;
		}
	}
	REP(i, N)dp[i] = LLINF;
	dp[0] = 0;

	REP(i, N) {
		dp[i] = LLINF;
		REP(j, i + 1) {
			if (can[j][i]) {
				if (j)dp[i] = min(dp[i], dp[j - 1] + 1);
				else dp[i] = min(dp[i], 1LL);
			}
		}
	}

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

	return 0;
}





Measured memory_bytes: 7836
def n_c_2(n):
    if n < 1:
        return 0
    else:
        return n * (n - 1) // 2

N = int(input())
A = [int(x) for x in input().split()]

n_balls = [0 for _ in A]
for a_i in A:
    n_balls[a_i - 1] += 1

n_combinations = [n_c_2(n) for n in n_balls]
total_combinations = sum(n_combinations)

for i, a_i in enumerate(A):
    diff = n_c_2(n_balls[a_i - 1]) - n_c_2(n_balls[a_i - 1] - 1)
    print(total_combinations - diff)


Measured memory_bytes: 25764
read a1 a2 a3 a4 a5;

if [ $a1 -eq 0 ] ; then
    echo 1;
    exit 0;
fi
if [ $a2 -eq 0 ] ; then
    echo 2;
    exit 0;
fi
if [ $a3 -eq 0 ] ; then
    echo 3;
    exit 0;
fi
if [ $a4 -eq 0 ] ; then
    echo 4;
    exit 0;
fi
if [ $a5 -eq 0 ] ; then
    echo 5;
    exit 0;
fi


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

int main() {
	int dcnt[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
	int cnt = 0;
	int j = 1;
	int tot[366];
	int day[33][33];
	int a, b;
	cin >> a >> b;
	memset(&day,0,sizeof(day));
	memset(&tot,0,sizeof(tot));
	for(int i = 1; i <= 365; i++)
	{
		cnt++;
		tot[i] = tot[i-1];
		if(cnt == j)
		{
			//cout << j << " " << cnt << endl;
			tot[i] ++;
		}
		day[j][cnt] = i;
		if(a == j && b == cnt)
		{
			//cout << j << " " << cnt << endl;
			break;
		}
		if(cnt == dcnt[j])
		{
			j++;
			cnt = 0;
		}
	}
	cout << tot[day[a][b]] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int N; cin >> N;
    string X; cin >> X;
    int cnt = 0;
    rep(i, N) cnt += (int)(X[i] - '0');
    ll minus = 0, plus = 0;
    for (int i = 0; i < N; i++) {
        if (cnt > 1) minus = (minus * (ll)(2) + (ll)(X[i] - '0')) % (cnt-1);
        plus = (plus * (ll)(2) + (ll)(X[i] - '0')) % (cnt+1);
    }
    int ans;
    ll tmp;
    rep(i, N) {
        ans = 0;
        if (X[i] == '0') {
            tmp = (plus + modpow(2, N-1-i, cnt+1))%(cnt+1);
        }
        else {
            if (cnt <= 1) {
                cout << 0 << endl;
                continue;
            }
            tmp = (minus - modpow(2, N-1-i, cnt-1) + cnt-1)%(cnt-1);
        }
        ans++;
        while (tmp > 0) {
            int now=0;
            int j = 0;
            while (tmp >= ((ll)(1)<<j)) {
                if (tmp & ((ll)(1)<<j)) now++;
                j++;
            }
            tmp %= now;
            ans++;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3760
import java.util.*;

public class Main{

	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		int[] d = new int[6];
		for(int i = 0; i < 6; i++){
			d[i] = scan.nextInt();
		}
		Dice dice = new Dice(d);
		int q = scan.nextInt();
		for(int i = 0; i < q; i++){
			int n = scan.nextInt();
			int m = scan.nextInt();
			dice.setTop(n);
			dice.setSouth(m);
			list.add(dice.show(Dice.EAST));
		}

		for(int n : list){
			System.out.println(n);
		}
	}
}

class Dice{
	int[] d_ = new int[6];
	public static final int
		TOP = 0, SOUTH = 1, EAST = 2,
		WEST = 3, NORTH = 4, BOTTOM = 5;

	public Dice(int[] d){
		for(int i = 0; i < 6; i++){
			d_[i] = d[i];
		}
	}

	public void setTop(int num){
		if(num == d_[EAST]){
			this.rollWest();
		} else if(num == d_[WEST]){
			this.rollEast();
		} else if(num == d_[SOUTH]){
			this.rollNorth();
		} else if(num == d_[NORTH]){
			this.rollSouth();
		} else if(num == d_[BOTTOM]){
			this.rollEast();
			this.rollEast();
		}
	}

	public void setSouth(int num){
		if(num == d_[EAST]){
			this.rollRight();
			this.rollRight();
			this.rollRight();
		} else if(num == d_[WEST]){
			this.rollRight();
		} else if(num == d_[NORTH]){
			this.rollRight();
			this.rollRight();
		}
	}

	public int show(int side){
		return d_[side];
	}

	public void rollEast(){
		int work = d_[TOP];
		d_[TOP] = d_[WEST];
		d_[WEST] = d_[BOTTOM];
		d_[BOTTOM] = d_[EAST];
		d_[EAST] = work;
	}

	public void rollWest(){
		int work = d_[TOP];
		d_[TOP] = d_[EAST];
		d_[EAST] = d_[BOTTOM];
		d_[BOTTOM] = d_[WEST];
		d_[WEST] = work;
	}

	public void rollSouth(){
		int work = d_[TOP];
		d_[TOP] = d_[NORTH];
		d_[NORTH] = d_[BOTTOM];
		d_[BOTTOM] = d_[SOUTH];
		d_[SOUTH] = work;
	}

	public void rollNorth(){
		int work = d_[TOP];
		d_[TOP] = d_[SOUTH];
		d_[SOUTH] = d_[BOTTOM];
		d_[BOTTOM] = d_[NORTH];
		d_[NORTH] = work;
	}

	public void rollRight(){
		int work = d_[SOUTH];
		d_[SOUTH] = d_[WEST];
		d_[WEST] = d_[NORTH];
		d_[NORTH] = d_[EAST];
		d_[EAST] = work;
	}
}

Measured memory_bytes: 26008
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] a = new long[n];
		for(int i=0;i<n;i++) a[i] = in.nextLong();
		long[] ans = new long[n];
		for(int i=0;i<n;i++) {
			if(i%2==0) ans[0] += a[i];
			else ans[0] -= a[i];
		}
		System.out.print(ans[0]);
		for(int i=1;i<n;i++) {
			ans[i] = a[i-1]*2 - ans[i-1];
			System.out.print(" "+ans[i]);
		}
		
		in.close();

	}

}


Measured memory_bytes: 66504
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	//入力
	int N;
	cin >> N;
	std::vector<int> X(N);
	for (int i = 0; i < N; i++) cin >> X[i];
	//整列した配列
	std::vector<int> A = X;
	std::sort(A.begin(), A.end());

	int l = A[(N / 2) - 1];
	int r = A[(N / 2)];

	for (int i = 0; i < N; i++) {
		if (X[i] <= l) { cout << r << endl;}
		else { cout << l << endl; }
	}
	return 0;
}

Measured memory_bytes: 3712
#include<stdio.h>
int main(void)
{
    int imp,in[101]={0},i,j=1,f=0,s=1,t=2,l[101]={0};
    for(i=0;scanf("%d",&imp)!=EOF;i++)
    {
        in[imp]++;
    }
    f=1;
    for(i=1;i<101;i++)
    {
            if(in[f]<in[i])
            {
                f=i;
            }
    }

    l[0]=f;
    for(i=1;i<101;i++)
    {
        if(in[f]==in[i]&&f!=i)
        {
            l[j]=i;
            j++;
        }
    }
    if(l[1]!=0)
    {
        for(i=0;i<j;i++)
        {
            printf("%d\n",l[i]);
        }
    }
    else
    {
        printf("%d\n",f);
    }

    return 0;
}

Measured memory_bytes: 596
<?php

fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s);

if ($n % 2 === 1) {
    echo 'No';
} else {
    $first = substr($s, 0, floor(strlen($s) / 2));
    $last = substr($s, ceil(strlen($s) / 2));

    echo strcmp($first, $last) === 0 ? 'Yes' : 'No';
}



Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=1e9;
const int mod=1e9+7;



void solve()
{
    ll a;
    cin>>a;
    ll ans=a+a*a+a*a*a;
    cout<<ans<<endl;
}


int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--)
        solve();
}
    
    
    
    


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	long long x,ans;
	bool flag = false;
	cin >> x;

	for (long long i = 0; i <= x; i++)
	{
		if ((long long)(i * 1.08) == x)
		{
			ans = i;
			flag = true;
			break;
		}
	}

	if (flag)
		cout << ans << endl;
	else
		cout << ":(" << endl;
}

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

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


int main(void) {
  int n, k;
  cin >> n >> k;
  int count = 0;
  vector<int> data(n);
  rep(i,n) {
    cin >> data.at(i);
  }
  rep(i,n) {
    if(data.at(i) >= k) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 640
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*; 
import java.util.*;
import java.util.regex.*;

/*
			  br = new BufferedReader(new FileReader("input.txt"));
			  pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
			  br = new BufferedReader(new InputStreamReader(System.in));
			  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++) {
			String s = readToken();
			int ret = s.length()-1;
			for(char ch = 'a'; ch <= 'z'; ch++) {
				if(s.indexOf(ch) == -1) continue;
				String curr = s;
				int ans = 0;
				while(!valid(curr)) {
					StringBuilder sb = new StringBuilder();
					for(int i = 0; i < curr.length()-1; i++) {
						if(curr.charAt(i) == ch || curr.charAt(i+1) == ch) {
							sb.append(ch);
						}
						else {
							sb.append('?');
						}
					}
					curr = sb.toString();
					ans++;	
				}
				ret = Math.min(ret, ans);
			}
			pw.println(ret);
		}
		exitImmediately();
	}

	public static boolean valid(String s) {
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) != s.charAt(0)) return false;
		}
		return true;
	}
	
	private static void exitImmediately() {
		pw.close();
		System.exit(0);
	}

	private static long readLong() throws IOException {
		return Long.parseLong(readToken());
	}

	private static double readDouble() throws IOException {
		return Double.parseDouble(readToken());
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(readToken());
	}

	private static String readLine() throws IOException  {
		String s = br.readLine();
		if(s == null) {
			exitImmediately();
		}
		st = null;
		return s;
	}

	private static String readToken() throws IOException  {
		while(st == null || !st.hasMoreTokens())  {
			st = new StringTokenizer(readLine().trim());
		}
		return st.nextToken();
	}
}

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

int main(){
    long long N ,M;
    cin >> N >> M;
    double A[N],res=0,sum=0;
    for(int i=0;i<N;i++) {
        cin >> A[i];
        sum = sum + A[i];
    }
    for(int i=0;i<N;i++) {
        if (A[i] >= sum/(4 * M)) {
            res++;
        }
    }
    if (res>=M){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    long H;
    H = input.front.to!long;
    input.popFront;

    long W;
    W = input.front.to!long;
    input.popFront;

    long M;
    M = input.front.to!long;
    input.popFront;

    long[] h = new long[](cast(size_t)(M));
    long[] w = new long[](cast(size_t)(M));
    foreach (i; 0 .. cast(size_t)(M))
    {
        h[i] = input.front.to!long;
        input.popFront;
        w[i] = input.front.to!long;
        input.popFront;
    }

    solve(H, W, M, h, w);
}

void solve(long H, long W, long M, long[] h, long[] w)
{
    long ans;
    {
        long[long] DH;
        foreach (i; 0 .. M)
        {
            DH[h[i]] = DH.get(h[i], 0) + 1;
        }
        long ansy;
        long cnty;
        foreach (key, value; DH)
        {
            if (cnty < value)
                ansy = key, cnty = value;
        }
        long[long] DW;
        foreach (i; 0 .. M)
        {
            if (h[i] != ansy)
                DW[w[i]] = DW.get(w[i], 0) + 1;
        }
        long ansx;
        long cntx;
        foreach (key, value; DW)
        {
            if (cntx < value)
                ansx = key, cntx = value;
        }
        dprint(cnty, cntx);
        ans = ans.max(cnty + cntx);
    }
    {

        long[long] DW;
        foreach (i; 0 .. M)
        {
            DW[w[i]] = DW.get(w[i], 0) + 1;
        }
        long ansx;
        long cntx;
        foreach (key, value; DW)
        {
            if (cntx < value)
                ansx = key, cntx = value;
        }
        long[long] DH;
        foreach (i; 0 .. M)
        {
            if (w[i] != ansx)
                DH[h[i]] = DH.get(h[i], 0) + 1;
        }
        long ansy;
        long cnty;
        foreach (key, value; DH)
        {
            if (cnty < value)
                ansy = key, cnty = value;
        }
        dprint(cnty, cntx);
        ans = ans.max(cnty + cntx);
    }
    writeln(ans);
}


Measured memory_bytes: 71664
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,M,i,res,most_right;
vector<pair<int,int>>C;
int main(){
  cin>>N>>M;
  C.resize(M);
  for(i=0;i<M;++i)cin>>C[i].second>>C[i].first;
  sort(C.begin(),C.end());
  for(i=0;i<M;++i){
    if(C[i].second>=most_right){
      most_right=C[i].first;
      ++res;
    }
  }
  cout<<res<<endl;
}


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

int m,n;
int p[7];

int main(){
	while(true){
		cin >> n;
		if(!n)
			return 0;
		for(int i=0; i<7; i++)
			p[i] = 0;
		for(int i=0; i<n; i++){
			cin >> m;
			if(m>=70)
				m = 60;
			p[m/10]++;
		}
		for(int i=0; i<7; i++)
			cout << p[i] << endl;
	}
}

Measured memory_bytes: 868
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const int mod=1e9+7;
const int M=10100;
string a,b,c,tmp="";
int asz,bsz,csz;
 int dp1[M][2007];
 int dp2[M][2007];
 int dp3[M][2007];
bool chk(int bl,int br,int cl,int cr)
{
    if(br<cl || cr<bl)return true;
    int lft=max(bl,cl);
    int rgt=min(br,cr);
    int len=rgt-lft+1;
    int bst=lft-bl;
    int cst=lft-cl;
    if(dp3[bst][cst]>=len)return true;
    return false;
}
 main()

{
    //fast
    //freopen("005.txt", "r", stdin);
    cin>>a;
    cin>>b;
    cin>>c;
//    cout<<"#"<<a<<endl;
//    cout<<"#"<<b<<endl;
//    cout<<"#"<<c<<endl;
    int ctmp=4002;
    while(ctmp--)tmp+="?";
    int alen=a.size();
    a=a+tmp;
    a=tmp+a;
    asz=a.size();
    bsz=b.size();
    csz=c.size();
   // cout<<alen<<" "<<bsz<<" "<<csz<<endl;
    int al=4002;
    int ar=al+alen-1;
    rf(i,asz-1,0)
    {
        rf(j,bsz-1,0)
        {
            if(a[i]==b[j] || a[i]=='?' ||  b[j]=='?')
            {
                dp1[i][j]=1+dp1[i+1][j+1];
            }
        }
    }
    rf(i,asz-1,0)
    {
        rf(j,csz-1,0)
        {
            if(a[i]==c[j] || a[i]=='?' ||  c[j]=='?')
            {
                dp2[i][j]=1+dp2[i+1][j+1];
            }
        }
    }
    rf(i,bsz-1,0)
    {
        rf(j,csz-1,0)
        {
            if(b[i]==c[j] || b[i]=='?' || c[j]=='?')
            {
                dp3[i][j]=1+dp3[i+1][j+1];
            }
        }
    }
    int ses=alen+bsz+csz;
   f(bst,0,asz-1)
   {
       f(cst,0,asz-1)
       {
           if(dp1[bst][0]==bsz && dp2[cst][0]==csz)
           {
               int bl=bst;
               int br=bst+bsz-1;
               int cl=cst;
               int cr=cst+csz-1;
               if(chk(bl,br,cl,cr)){

               int lft=min(al,bl);
               lft=min(lft,cl);
               int rgt=max(ar,br);
               rgt=max(rgt,cr);
               int sz=rgt-lft+1;
               ses=min(ses,sz);

               }
           }
       }
   }
   cout<<ses<<endl;
    return 0;

}




































Measured memory_bytes: 176164
# -*- coding:utf-8 -*-

def solve():
	N = int(input())
	INF = 100000

	# dp[N] := N円にするのに必要な枚数の最小値
	dp = [INF] * (N+10)
	dp[0] = 0
	for n in range(1, N+1):
		# 1円使うとき
		dp[n] = min(dp[n], dp[n-1]+1)

		power = 6
		while (power <= n):
			dp[n] = min(dp[n], dp[n-power]+1)
			power *= 6
		
		power = 9
		while (power <= n):
			dp[n] = min(dp[n], dp[n-power]+1)
			power *= 9
	
	print(dp[N])



if __name__ == "__main__":
	solve()


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e11
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    pair<ll,ll> itv[n];
    rep(i,n){
        ll x,l;
        cin>>x>>l;
        itv[i].first=x+l;
        itv[i].second=x-l;
    }
    sort(itv,itv+n);
    ll ans=0,t=-INF;
    rep(i,n){
        if(t<=itv[i].second){
            ans++;
            t=itv[i].first;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

class UnionFind {
public:
    vector<int> par;
    vector<int> rnk;
    vector<int> sze;

    UnionFind(ll n): par(n), rnk(n, 0), sze(n, 1) {
        for (ll i = 0; i < n; ++i) par[i] = i;
    }

    void init(int n) {
        for (int i = 0; i < n; i++) {
            par.resize(n);
            rnk.assign(n, 0);
            sze.assign(n, 1);
        }
    }

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

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return 0;
        if (rnk[x] < rnk[y]) {
            sze[y] = sze[x] + sze[y];
            par[x] = y;
        }
        else {
            sze[x] = sze[x] + sze[y];
            par[y] = x;
            if (rnk[x] == rnk[y]) rnk[x]++;
        }
        return 1;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    bool size(int x) {
        return sze[find(x)];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    UnionFind uf = UnionFind(n);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }

    vector<ll> G[n], other;
    for (int i = 0; i < n; i++) {
        G[uf.find(i)].push_back(a[i]);
    }
    ll ans = 0, tree = 0;
    for (int i = 0; i < n; i++) {
        sort(all(G[i]));
        if (G[i].size() != 0) {
            tree++;
            ans += G[i][0];
            for (int j = 1; j < G[i].size(); j++) {
                other.push_back(G[i][j]);
            }
        }
    }
    if (tree == 1) {
        cout << 0 << endl;
        return 0;
    }
    cerr << ans << endl;
    if (other.size() < tree - 2) {
        cout << "Impossible" << endl;
    }
    else {
        sort(all(other));
        for (int i = 0; i < tree - 2; i++) {
            ans += other[i];
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 7680
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int[] p;

	static int[] d;

	static int e[];

	static int a(int a, int b, int e) {
		switch (e) {
		case 0:
			return a + b;
		case 1:
			return a - b;
		case 2:
			return a * b;
		}
		return 0;
	}

	static String s(int e) {
		switch (e) {
		case 0:
			return " + ";
		case 1:
			return " - ";
		case 2:
			return " * ";
		}
		return "";
	}

	static int so(int depth) {
		if (depth == 4)
			return so2(0);
		for (int i = 0; i < 4; i++) {
			if (d[i] >= 0)
				continue;
			d[i] = depth;
			if (so(depth + 1) > 0)
				return 1;
			d[i] = -1;
		}
		return 0;
	}

	static int so2(int depth) {
		if (depth == 3)
			return ((calc() == 10 || calc2() == 10) ? 1 : 0);
		for (int i = 0; i < 3; i++) {
			e[depth] = i;
			if (so2(depth + 1) > 0)
				return 1;
		}
		return 0;
	}

	static int calc() {
		int[] t = new int[4];
		for (int i = 0; i < 4; i++)
			t[d[i]] = p[i];
		int s = t[0];
		for (int i = 0; i < 3; i++)
			s = a(s, t[i + 1], e[i]);
		return s;
	}

	static int calc2() {
		int[] t = new int[4];
		for (int i = 0; i < 4; i++)
			t[d[i]] = p[i];
		return a(a(t[0], t[1], e[0]), a(t[2], t[3], e[2]), e[1]);
	}

	static String str() {
		StringBuffer sb = new StringBuffer();
		int[] t = new int[4];
		for (int i = 0; i < 4; i++)
			t[d[i]] = p[i];
		sb.append("(((" + t[0]);
		for (int i = 0; i < 3; i++) {
			sb.append(s(e[i]) + t[i + 1] + ")");
		}
		return sb.toString();
	}

	static String str2() {
		int[] t = new int[4];
		for (int i = 0; i < 4; i++)
			t[d[i]] = p[i];
		return "(" + t[0] + s(e[0]) + t[1] + ")" + s(e[1]) + "(" + t[2] + s(e[2]) + t[3] + ")";
	}

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		p = new int[4];
		d = new int[4];
		e = new int[3];
		while (sc.hasNextInt()) {
			for (int i = 0; i < 4; i++)
				p[i] = sc.nextInt();
			if (p[0] == 0 && p[1] == 0 && p[2] == 0 && p[3] == 0)
				break;
			Arrays.fill(d, -1);
			if (so(0) > 0) {
				if (calc2() == 10) {
					System.out.println(str2());
				} else {
					System.out.println(str());
				}
			} else {

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

Measured memory_bytes: 12000
#include<stdio.h>

int main(void)

{

  int a,b;

  scanf("%d %d",&a,&b);

  if(a<b)

  {

    printf("a < b\n");

  }

  if(a>b)

  {

    printf("a > b\n");

  }

  if(a==b)

  {

    printf("a == b\n");

  }

  return 0;

}

Measured memory_bytes: 580
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll q;
  cin >> q;
  rep(iter,q) {
    string s;
    string t;
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();
    // dp[i][j] .. LCS using [0,i) and [0,j)
    vector<vector<ll>> dp(n+1, vector<ll>(m+1));
    rep(i,n)rep(j,m) {
      chmax(dp[i+1][j+1], dp[i][j]);
      chmax(dp[i+1][j+1], dp[i][j+1]);
      chmax(dp[i+1][j+1], dp[i+1][j]);
      if (s[i] == t[j]) {
        chmax(dp[i+1][j+1], dp[i][j]+1);
      }
    }
    cout << dp[n][m] << endl;
  }
}



Measured memory_bytes: 10844
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462
int main(){
	int a,b;
	string op;
	while(1){
	   cin>>a>>op>>b;
	  if(op=="?")
	      break;
	  if(op=="+")
		  cout<<a+b<<endl;
	  else if(op=="-")
		  cout<<a-b<<endl;
	  else if(op=="*")
		  cout<<a*b<<endl;
	  else if(op=="/")
		  cout<<a/b<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
n = int(input())
t_N = input().split()
list_Time = []
for id in range(n):
    list_Time.append(int(t_N[id]))
sum = sum(list_Time)
m = int(input())
for id in range(m):
    p, x = map(int, input().split())
    answer = sum + x - list_Time[p - 1]
    print(answer)


Measured memory_bytes: 3060
import math
while True:
	n=int(input())
	if n==0:
		break
	else:
		s=list(map(float,input().split()))
		sum=0
		hen=0
		for i in s:
			sum+=(i/n)			
		for i in s:
			hen+=((i-sum)**2)/n
		print(round(math.sqrt(hen),8))


Measured memory_bytes: 5772
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
    return (a<b)?a:b;
}
int max(int a,int b){
    return (a>b)?a:b;
}
int fp(int a,int b){
    if(b==0) return 1;
    int x=fp(a,b/2);
    x=(x*x)%mod;
    if(b&1) x=(x*a)%mod;
    return x;
}


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 srand(time(0));
 int n;
 cin>>n;
 n-=400;
 int x=8-(n/200);
 cout<<x;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string p,q;
    int a,b;
    string l;
    cin>>p>>q;
    cin>>a>>b;
    cin>>l;
    if(l==p)
    {
        cout<<a-1<<" "<<b;

    }
    else
    {

        cout<<a<<" "<<b-1;
    }

}


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

using namespace std;
typedef long long ll;

ll n,arr[100005],mem[100005],k;

ll dp(ll pos){
    if(pos==n-1)return 0;
    if(pos>=n)return 10000000000;
    ll res=10000000000;
    if(mem[pos]!=-1)return mem[pos];
    for(int i=pos+1;i<=pos+k;i++){
        if(i<n)res=min(res,dp(i)+abs(arr[pos]-arr[i]));
    }
    return mem[pos]=res;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    memset(mem,-1,sizeof(mem));
    for(int i=0;i<(int)n;i++)cin>>arr[i];
    cout<<dp(0);
}

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

int main() {
    int n;
    cin >> n;
    set<string> st;
    rep(i, n) {
        string temp;
        cin >> temp;
        st.insert(temp);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 19212
#include <bits/stdc++.h>
using namespace std;
int main() {
    // 入力受け取り, 入次数も管理する
int n;
    cin >> n;

int c[n],v[n];
int maxi=0;
for(int i=0;i<n;i++){
cin >> v[i] ;
}
for(int i=0;i<n;i++){
cin >> c[i] ;
}

 for (int bit = 0; bit < (1<<n); ++bit) {
        vector<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                S.push_back(i);
            }
        }
       int X=0,Y=0;
// cout << bit << ": {";
        for (int i = 0; i < (int)S.size(); ++i) {
//            cout << S[i] << " ";
		X+=v[S[i]];Y+=c[S[i]];
        }
//cout << "}" << endl;
	
	maxi=max(maxi,X-Y);
    }
cout <<maxi;





}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,a,b;
    cin>>n>>a>>b;
    cout <<min(a*n,b)<<"\n";
}

Measured memory_bytes: 256
X, K, D = map(int, input().split())
s = (abs(X) // D)
t = abs(abs(X) - D*s)
u = abs(abs(X) - D*(s+1))
if abs(X) > (K*D):
    print(abs(X) - K*D)
else:
    if (K-s) % 2 == 0:
        print(t)
    else:
        print(u)

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int data[N];
  for(int i=0;i<N;i++)cin >> data[i];
  
  int count=0;
  
  for(int i=0;i<N;i++){
    if(data[i]==count+1){
    	count++;
    }
  }
  if(count > 0){
  cout << N-count << endl;
  }else{
  cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int N,K;
int a[100];
bool dp[100001];
int main(void){
    cin >> N >> K;
    rep(i,N) cin >> a[i];
    sort(a,a+N);
    
    rep(i,a[0]) dp[i] = false;
    for (int i=0;i<=K;i++){
        for(int j=0;j<N;j++){
            if(i+a[j] > K) continue;
            if(!dp[i]) dp[i+a[j]]=true; 
        }
    }
    if(dp[K]) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}




Measured memory_bytes: 384
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

X,N = map(int,readline().rstrip().split())
p = set([int(i) for i in readline().rstrip().split()])
if N == 0:
    print(X)
    exit()
for j in range(X+1):
    if not ((X-j) in p):
        print(X-j)
        exit()
    if not ((X+j) in p):
        print(X+j)
        exit()

Measured memory_bytes: 9108
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x1 = sc.nextInt()
    val y1 = sc.nextInt()
    val x2 = sc.nextInt()
    val y2 = sc.nextInt()
    println(problem108b(x1, y1, x2, y2))
}

fun problem108b(x1: Int, y1: Int, x2: Int, y2: Int): String {
    val x3 = x2 - x1
    val y3 = y2 - y1
    return listOf(x2 - y3, y2 + x3, x1 - y3, y1 + x3).joinToString(" ")
}

Measured memory_bytes: 34000
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  int sum=0;
  int max=0;
  
  for(int i=0;i<N;i++){
    if(S.at(i)=='I'){
sum++;
      
      if(sum>max){
        max=sum;
      }
    }
    
    else{
      sum--;
    }
  }
  
  cout<<max<<endl;
}

    
  

Measured memory_bytes: 256