akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <array>
#include <cstdlib>
#include <stack>
#include <string>
#include <queue>
#include <chrono>
#include <functional>
#include <limits>
#include <cmath>
#include <algorithm>
#include <random>
#include <regex>
#include <tuple>
#include <utility>
#include <bitset>
#include <complex>
#include <iomanip>
#include <ostream>
#include <sstream>
#include <ctime>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define index INDEX
#ifndef ONLINE_JUDGE
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, const string& NAME) {
	cerr << NAME << " = " << fixed << VARIABLE << "\n";
}
#else
#define print(x) 0 
#endif
#ifdef RAND_MAX
#undef RAND_MAX
#endif
#define RAND_MAX 999999937 
int generate_random() {
	const int MAX_RANDOM = (int)1e6;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution<int>(0, MAX_RANDOM)(rng);
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INFLL = 2 * (ll)1e18 + 100;
#define int ll
#ifdef int 
const int INFINT = INFLL;
#else
const int INFINT = 2 * (int)1e9 + 100;
#endif
const double PI = atan(1) * 4;
const double EPS = 1e-6;
const int SEED = (int)1e3 + 7;
const int MOD = (int)1e9 + 7;
const int NMAX = (int)1e6 + 5;

int32_t main() {
#ifndef ONLINE_JUDGE
	double START_PROGRAM = clock();
#endif
	srand(time(0));
	cout << setprecision(20) << fixed;
	FASTIO;
	int n, k;
	string s;
	cin >> n >> k >> s;
	char& c = s[k - 1];
	if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a';
	cout << s;






#ifndef ONLINE_JUDGE
	double END_PROGRAM = clock();
	double ELAPSED_TIME = (END_PROGRAM - START_PROGRAM) / CLOCKS_PER_SEC;
	cerr << "\n\nElapsed Time: " << ELAPSED_TIME * 1000 << "\n";
	system("pause");
#endif
	return 0;
}







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

int w[100005],v[100005],dp[100005],ans=0,V=100000;
const int INF = 0x3f3f3f3f;

int main()
{
	int W,n;
	cin >> n >> W;
	for(int i = 1; i <= n; i++)
		cin >> w[i] >> v[i];
	
	memset(dp,INF,sizeof(dp));
	dp[0]=0;

	for(int i = 1; i <= n; i++)
	{
		for(int j = V; j >= v[i]; j--)
		{
			dp[j] = min(dp[j], dp[j-v[i]] + w[i]);

			if(dp[j]<=W)
				ans = max(ans,j);
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;

int main() {
	int N; cin >> N;
	for (int i = 1; i <= 9; i++) {
		if (N % i == 0 && N / i < 10) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
 }

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

int main()
{
    ll n, i, j, p, x, a[20009], b[20009];
    cin >> n;
    for(i = 0; i < n; i++)
        a[i] = i+1;
    for(i = n-1; i >= 0; i--)
        b[i] = n-i;


    for(i = 0; i < n; i++)
    {
        cin >> p;
        a[p-1] += i;
        for(j = p-1; j < n; j++)
        {
            a[j] += n;
            b[j] -= n;
        }
    }

    x = 1 - b[n-1];
    for(i = 0; i < n; i++)
    {
        a[i] += x;
        b[i] += x;
    }

    for(i = 0; i < n; i++)
        cout << a[i] << " ";
    cout << "\n";
    for(i = 0; i < n; i++)
        cout << b[i] << " ";
}


Measured memory_bytes: 3940
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    string s;
    scan(s);
    string a = "2019/04/30";

    writeln(s <= a ? "Heisei" : "TBD");
}




int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {writeln(b ? "Yes" : "No");}
void YES(bool b) {writeln(b ? "YES" : "NO");}
T[] readArr(T)() {return readln.split.to!(T[]);}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
	int a, b;

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

	if (a < b){
		printf("a < b\n");
	}
	else if (a > b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}

	return 0;
}

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

int main() {
  int64_t A, B, C, K;
  cin >> A >> B >> C >> K;

  int64_t sum = 0;
  if (A >= K) {
    sum = K;
  } else {
    sum = A;
    if (A + B < K) {
      sum -= K - (A + B);
    }
  }

  cout << sum << endl;

  return 0;
}


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

int main() {
    int N, T;
    cin >> N >> T;
    int c[N], t[N];
    for (int i = 0; i < N; ++i) cin >> c[i] >> t[i];

    int ans = 100000;
    for (int i = 0; i < N; ++i) {
        if (t[i] <= T) ans = min(ans, c[i]);
    }

    if (ans <= 1000) cout << ans << endl;
    else cout << "TLE" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    double ans = v[0];
    for(int i=1;i < n; i++)ans = (ans+v[i])/2.0;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
fun main(){
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{ it.toInt()}
    var ans = "APPROVED"

    for(i in a){
        if(i%2 == 0){
            if(i%3 != 0 && i%5 != 0)
                ans = "DENIED"
        }
    }

    println(ans)

}

Measured memory_bytes: 37996
#include<cstdio>
#include<vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int isprime(int n){
	for(int i = 2; i * i <= n; i++) if(n % i == 0) return 0;
	return 1;
}

int main(){
	int n; scanf("%d", &n);
	vector<int> p;
	for(int i = 2; i <= n; i++) if(isprime(i)) p.push_back(i);
	vector<int> v;
	for(int i = 0; i < p.size(); i++){
		int b = p[i], s = 0;
		while(n / b > 0){ s += n / b; b *= p[i]; }
		v.push_back(s);
	}
	ll res = 1;
	for(int i = 0; i < v.size(); i++) res = res * (v[i] + 1) % MOD;
	printf("%lld\n", res);
	return 0;
}

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

const int mod = 1e9 + 7;

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) {
    return exp(x, mod - 2);
}
int fact[1000010], invf[1000010];
int comb(int n, int k) {
    if(n < k) return 0;
    return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod;
}

int N;

int main() {
    fact[0] = 1;
    for(int i = 1; i < 1000010; i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    for(int i = 0; i < 1000010; i++) {
        invf[i] = inv(fact[i]);
    }

    cin >> N;

    int ans = 0;
    for(int i = 0; i < N - 1; i++) {
        int tmp = comb(N - 1, i);
        tmp += mod - comb(i - 1, N - 1 - i);
        tmp %= mod;
        ans += 1LL * fact[i] * fact[N - 1 - i] % mod * tmp % mod;
        ans %= mod;
    }
    cout << ans;
}


Measured memory_bytes: 8064
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;
constexpr ll MOD = 1000000007;

#define rep(i, N) for(ll i=0; i<(N); ++i)

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


ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

template<typename T> inline string toString(const T &a) {
  ostringstream oss; oss << a; return oss.str();
}

ll gcd(ll x, ll y) { return x % y ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  
  rep(i, N) {
    if(A[i] % 2 == 0 && A[i] % 3 != 0 && A[i] % 5 != 0){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  
  cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val list = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }.reversed()

    val ans = mutableListOf<Long>()
    val uf = UnionFind(n)

    var cur = (n.toLong() * (n.toLong() - 1)) / 2

    for (ab in list) {
        ans.add(cur)

        val a = ab[0] - 1
        val b = ab[1] - 1

        if (uf.isSame(a, b)) {
            continue
        }

        val sizeA = uf.size(a)
        val sizeB = uf.size(b)
        cur -= sizeA * sizeB

        uf.merge(a, b)
    }

    ans.reversed().forEach{ println(it) }
}

private class UnionFind(n: Int) {
    val parent = Array(n) { -1 }

    fun root(x: Int): Int {
        return if (parent[x] < 0) {
            x
        } else {
            parent[x] = root(parent[x])
            parent[x]
        }
    }

    fun isSame(x: Int, y: Int): Boolean {
        return root(x) == root(y)
    }

    fun merge(x: Int, y: Int): Boolean {
        var xRoot = root(x)
        var yRoot = root(y)
        if (xRoot == yRoot) {
            return false
        }

        // merge technique
        if (parent[xRoot] > parent[yRoot]) {
            val tmp = yRoot
            yRoot = xRoot
            xRoot = tmp
        }

        parent[xRoot] += parent[yRoot];
        parent[yRoot] = xRoot
        return true
    }

    fun size(x: Int): Int {
        return -parent[root(x)]
    }
}


Measured memory_bytes: 81708
#include <iostream>
#include <algorithm>
#include <utility>
#include <iterator>
#include <set>
#include <vector>

using namespace std;

int main(){
	int N;
	cin >> N;
	vector<pair<long long, int>> P(N);
	for (int i = 0; i < N; i++){
		cin >> P[i].first;
		P[i].second = i;
	}
	sort(P.begin(), P.end());
	reverse(P.begin(), P.end());

	set<int> s;
	s.insert(-1);
	s.insert(N);
	s.insert(P[0].second);

	long long ans = 0;
	for (int i = 1; i < N; i++){
		auto y = s.lower_bound(P[i].second);
		auto z = next(y);
		auto x = prev(y);
		auto w = prev(x);

		if((*y) != N){
			ans += P[i].first * (P[i].second - (*x)) * ((*z) - (*y));
		}
		if((*x) != -1){
			ans += P[i].first * ((*x) - (*w)) * ((*y) - P[i].second);
		}
		s.insert(P[i].second);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		int N = int.Parse(str);
		int [] S = new int[N];
		S[0] = 2;
		int t = 1;
		for(var i=19;i<=55555;i+=10){
			if(IsPrime(i)){
				S[t] = i;
				t += 1;
				if(t >= N){
					break;
				}
			}
		}
		string a = S[0].ToString();
		for(var i=1;i<N;i++){
			a += " " + S[i];
		}
		Console.WriteLine(a);
	}
	
public static bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = Math.Sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}
}

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

int main() {
    string s;
    cin >> s;
    int counter = 0;
    if (s[0] == 'o') ++counter;
    if (s[1] == 'o') ++counter;
    if (s[2] == 'o') ++counter;
    cout << counter*100+700 << endl;
}

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

int main()
{
    int x,y;
    while(~scanf("%d%d",&x,&y))
    {
        if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12))
             printf("Yes\n");
        else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11))
            printf("Yes\n");
        else if((x==2)&&(y==2))
             printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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


def solve(N: int):
    from itertools import product
    from collections import defaultdict, Counter
    ans = defaultdict(int)
    def f(x_y_z):
        x, y, z = x_y_z
        return x * x + y * y + z * z + x * y + y * z + z * x
    c = Counter(map(f, product(range(1, 101), repeat=3)))    
    return [c[i] for i in range(1, N+1)]

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(*solve(N), sep="\n")

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 74292
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(void){
    // Your code here!
    ll h,w;
    cin>>h>>w;
    ll ans = (h*w+1)/2;
    if(h==1||w==1)cout<<1<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

int main() {
  int a, b, h, m;
  std::cin >> a >> b >> h >> m;

  double hr = M_PI * 2 / (12 * 60) * (h * 60 + m);
  double mr = M_PI * 2 / 60 * m;

  double hx = sin(hr) * a;
  double hy = cos(hr) * a;
  double mx = sin(mr) * b;
  double my = cos(mr) * b;

  std::cout << std::setprecision(11);
  std::cout << sqrt(pow(hx - mx, 2) + pow(hy - my, 2)) << std::endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
  int n, m;
  int sx, sy, h, w;
  
  cin >> n;
  while(n--){
    cin >> sx >> sy >> w >> h;
    cin >> m;
    int x, y;
    int cnt = 0;
    while(m--){
      cin >> x >> y;
      if(sx <= x && x <= sx+w && sy <= y && y <= sy+h) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main()
{
    int a[20];
    int wu,qi;
    while(cin>>a[1]>>a[2]>>a[3])
    {
        wu=0;
        qi=0;
        for(int i=1;i<=3;i++)
        {
            if(a[i]==5)
             wu++;
             if(a[i]==7)
            qi++;
        }
        if(wu==2&&qi==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
/*
No matter how long a night, dawn will always break.

Simular saying ... The darkest hour is just before the dawn.
 ***************************************   ************************8   **********************************
*/
#include <bits/stdc++.h>
using namespace std;

 
#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define sz(x)	    (int)(x).size()
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define hell        998244353
#define output(x) cout << (x ? "YES" : "NO")<<endl;
 
 
 
 
 
int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }  
bool mod(double a,double b) {return a/b - floor(a/b);}
 

 
 
 
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int i,j,x,a,b,c,n,m,k,sum=0;
  cin>>n>>m>>k;
  vi cst;
  int arr[n+1][m+1];
  _init0(arr);
  int ans=-1;
  fo(i,0,n){
  	cin>>x;
  	cst.pb(x);
  	fo(j,0,m){
  		cin>>x;
  		arr[i][j]=x;
  	}
  }
  fo(i,0,(1<<n)){
  	vi v(m+1);
  	b=0;
  	fo(j,0,n){
  		if(i&(1<<j)){
  			b+=cst[j];
  			fo(a,0,m){
  				v[a]+=arr[j][a];
  			}
  		}
  	}
  	bool ok=true;
  	fo(j,0,m){
  		if(v[j]<k)ok=false;
  	}
  	if(ok){
  		if(ans==-1||ans>b)ans=b;
  	}
  	v.clear();
  }
   
   cout<<ans;
   
   
   
    return 0;
}

Measured memory_bytes: 3656
fun main(arg: Array<String>) {
    val (A, B, C) = listOfInt()
    val ans = Math.max(C - (A - B), 0)
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 37740
#include<iostream>
#include<queue>
#include<cstring>

using namespace std;

struct process
{
    char name[10];
    int time;
};

int main()
{
    int n, q;
    int count = 0;
    struct process p[100000];
    queue<process> Q, result;

    cin >> n >> q;

    for( int i = 0; i < n; i++)
    {
        cin >> p[i].name >> p[i].time;
        Q.push( p[i] );
    }
    
    while( !Q.empty() )
    {
        count += min( q, Q.front().time);
        Q.front().time -= q;
	if( Q.front().time <= 0 )
        {
            struct process a;
	    strcpy( a.name, Q.front().name );
	    a.time = count;
            result.push( a );
            Q.pop();
        }
        else
        {
            Q.push( Q.front() );
	    Q.pop();
        }
    }
 
    while( !result.empty() )
    {
        cout << result.front().name << ' ' << result.front().time << endl;
	result.pop();
    }

    return 0;
}

Measured memory_bytes: 4372
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 100005
#define BT 1024*128*2
#define BB 20

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

struct segtree
{
	int seg[BT];
	int mum;
	
	void init(int n)
	{
		mum=1;
		while(mum<=n) mum<<=1;
		for(int i=0;i<mum*2;i++) seg[i]=BT;
	}
	void add(int k,int x)
	{
		k+=mum-1;
		seg[k]=x;
		while(k>0)
		{
			k=(k-1)/2;
			seg[k]=min(seg[k*2+1],seg[k*2+2]);
		}
	}
	int get(int a,int b,int k,int l,int r)
	{
		if(b<=l||r<=a) return BT;
		if(a<=l&&r<=b) return seg[k];
		else
		{
			int vl=get(a,b,k*2+1,l,(l+r)/2);
			int vr=get(a,b,k*2+2,(l+r)/2,r);
			return min(vl,vr);
		}
	}
	int get(int a,int b)
	{
		return get(a,b,0,0,mum);
	}
};
segtree seg;
int sum[SIZE];
int rk[SIZE];
int to[SIZE][BB];

int main()
{
	int X,n;
	scanf("%d%d",&X,&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&rk[i]);
		int L=rk[i]-(i==0?0:rk[i-1]);
		if(i%2==0) sum[i]=-L;
		else sum[i]=L;
		if(i>0) sum[i]+=sum[i-1];
	}
	//for(int i=0;i<n;i++) printf("%d ",sum[i]);puts("");
	vector <int> vx;
	for(int i=0;i<n;i++) vx.push_back(sum[i]);
	sort(vx.begin(),vx.end());
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	seg.init(vx.size()+2);
	for(int i=n-1;i>=0;i--)
	{
		//for(int j=0;j<3;j++) printf("%d ",seg.get(j,j+1));puts("");
		int x=lower_bound(vx.begin(),vx.end(),sum[i])-vx.begin();
		if(i%2==0)
		{
			//start 0
			int y=lower_bound(vx.begin(),vx.end(),sum[i]+X)-vx.begin();
			int pos=seg.get(0,x+1);
			if(y<vx.size()) pos=min(pos,seg.get(y,vx.size()));
			to[i][0]=min(n,pos);
		}
		else
		{
			//start X
			int y=upper_bound(vx.begin(),vx.end(),sum[i]-X)-vx.begin();
			int pos=seg.get(x,vx.size());
			if(y>0) pos=min(pos,seg.get(0,y));
			to[i][0]=min(n,pos);
		}
		seg.add(x,i);
	}
	for(int i=0;i+1<BB;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(to[j][i]==n) to[j][i+1]=n;
			else to[j][i+1]=to[to[j][i]][i];
		}
	}
	int Q;
	scanf("%d",&Q);
	for(int i=0;i<Q;i++)
	{
		int t,a;
		scanf("%d %d",&t,&a);
		int pos=n;
		int x=lower_bound(vx.begin(),vx.end(),X-a)-vx.begin();
		if(x<vx.size()) pos=min(pos,seg.get(x,vx.size()));
		int y=upper_bound(vx.begin(),vx.end(),-a)-vx.begin();
		if(y>0) pos=min(pos,seg.get(0,y));
		int last=lower_bound(rk,rk+n,t)-rk;
		if(pos>=last)
		{
			a+=(last==0?0:sum[last-1]);
			t-=(last==0?0:rk[last-1]);
			if(last%2==0) a-=t;
			else a+=t;
		}
		else//last>0
		{
			for(int j=BB-1;j>=0;j--)
			{
				if(to[pos][j]<last)
				{
					pos=to[pos][j];
				}
			}
			if(pos%2==0)
			{
				//start 0
				a=sum[last-1]-sum[pos];
			}
			else
			{
				//start X
				a=sum[last-1]-sum[pos]+X;
			}
			int z=t-rk[last-1];
			if(last%2==0) a-=z;
			else a+=z;
		}
		a=max(a,0);
		a=min(a,X);
		printf("%d\n",a);
	}
	return 0;
}


Measured memory_bytes: 11384
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main(){
    string str;
    cin >> str;
    int ans = str.size();
    stack<int> s;
    int g = 0;
    while(g < str.size()){
        if(str[g] == 'S'){
            s.push(g);
        }else{
            if(s.size() && str[s.top()]){
                s.pop();
                ans -= 2;
            }
        }
        g++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 900
using System;
using System.Linq;

namespace ATCoderPuzzles
{
    class AFrog2
    {
        static void Main()
        {
            var n = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
            var heights = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
            Console.WriteLine(Solve(n[0], n[1], heights));
        }

        static int Solve(int n, int k, int[] heights)
        {
            if (heights.Length < 2)
                return 0;
            else if (heights.Length == 2)
                return Math.Abs(heights[1] - heights[0]);

            int[] paths = new int[heights.Length];
            paths[heights.Length-1] = 0;

            for (int i = heights.Length - 2; i >= 0; i--)
            {
                paths[i] = GetMinCosts(heights, paths, i, k);
            }

            return paths[0];
        }

        static int GetMinCosts(int[] heights, int[] paths, int start, int k)
        {
            int minVal = int.MaxValue;
            for (int i = 1; (i <= k) && start + i < heights.Length; i++)
            {
                int val = Math.Abs(heights[start] - heights[start + i]) + paths[start+i];
                if (val < minVal)
                    minVal = val;
            }
            return minVal;
        }
    }
}


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

// ll A, B, C;
// scanf("%ld %ld %ld", &A, &B, &C);
// printf("%ld %ld %ld", A, B, C);

int main()
{
    string S, revS, pS, rev_pS, lS, rev_lS;
    ll N;
    cin >> S;
    revS=S;
    N = S.length();

    pS = S.substr(0, (N - 1) / 2);
    rev_pS = pS;
    lS = S.substr((N + 3) / 2 -1, (N - 1) / 2);
    rev_lS = lS;
    // cout << pS << endl;
    // cout << lS << endl;

    reverse(revS.begin(), revS.end());
    reverse(rev_pS.begin(), rev_pS.end());
    reverse(rev_lS.begin(), rev_lS.end());

    if (S == revS && pS==rev_pS && lS == rev_lS)
    {
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        string[] input1 = Console.ReadLine().Split(' ');
        int x = int.Parse(input1[0]);
        int n = int.Parse(input1[1]);

        string[] input2 = Console.ReadLine().Split(' ');
        
        int[] nums = new int[201];
        for (var i = 0; i<=102;i++)
        {
            nums[i] = i;
        }

        for (var i = 0; i <= 100; i++)
        {
            for (var j = 0; j < n; j++)
            {
                if(nums[i] == int.Parse(input2[j]))
                {
                    nums[i] = 201;
                    break;
                }
            }

        }
        int[] p2 = nums.Select(i => Math.Abs(i - x)).ToArray();

        int absMin = 101;
        int noMin=-1;

        if(n == 0)
        {
            noMin = x;
            goto label1;
        }

        for(var i = 0; i<=102; i++)
        {
            if(absMin > p2[i])
            {
                absMin = p2[i];
                noMin = i;
            }
        }
    label1:;
        Console.WriteLine(noMin);

    }
}


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

int main()
{
	int i,j,n,k,e[101][101],v[101],a,b,d[101],s;
	queue<int> Q;
	
	for(i=0;i<=100;i++)
	{
		for(j=0;j<=100;j++)
		{
			e[i][j]=0;
		}
		v[i]=0;
		d[i]=-1;
	}
	scanf("%d",&n);
	for(i=0;i<=n-1;i++)
	{
		scanf("%d%d",&a,&k);
		for(j=0;j<=k-1;j++)
		{
			scanf("%d",&b);
			e[a][b]=1;
		}
	}
	
	Q.push(1);
	d[1]=0;
	s=1;
	v[1]=1;
	while(Q.empty()!=1)
	{
		i=Q.front();
		for(j=1;j<=n;j++)
		{
			if(e[i][j]==1 && v[j]==0)
			{
				d[j]=d[i]+1;
				v[j]=1;
				Q.push(j);
			}
		}
		Q.pop();
	}
	for(i=1;i<=n;i++)
	{
		cout << i << " " << d[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

ll gumoji(std::string s){
    if(s.size()%2) return -1;
    if(s.substr(0,s.size()/2)==s.substr(s.size()/2)) return (ll)s.size();
    return -1;
}

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

    ll ans=0;
    for(;s.size()>0;){
        s.pop_back();
        ll b = gumoji(s);
        ans = std::max(ans, b);
    }
    std::cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

void solve(void){
    int N; string S;
    cin >> N >> S;
    string cand[] = {"SS", "SW", "WW", "WS"};
    rep(4, c) {
        string ans = cand[c];
        rep(N-2, i) {
            if ((S[i+1] == 'o' && ans[i+1] == 'S') || (S[i+1] == 'x' && ans[i+1] == 'W')) ans += ans[i];
            else ans += (ans[i]=='S'?"W":"S");
        }
        bool ok = false;
        if (ans[N-1] == 'S') {
            if ((S[N-1] == 'o' && ans[0] == ans[N-2]) || (S[N-1] == 'x' && ans[0] != ans[N-2])) {
                if (ans[0] == 'S') {
                    ok = (S[0] == 'o' && ans[1] == ans[N-1]) || (S[0] == 'x' && ans[1] != ans[N-1]);
                }
                else {
                    ok = (S[0] == 'x' && ans[1] == ans[N-1]) || (S[0] == 'o' && ans[1] != ans[N-1]);
                }
            }
        }
        else {
            if ((S[N-1] == 'x' && ans[0] == ans[N-2]) || (S[N-1] == 'o' && ans[0] != ans[N-2])) {
                if (ans[0] == 'S') {
                    ok = (S[0] == 'o' && ans[1] == ans[N-1]) || (S[0] == 'x' && ans[1] != ans[N-1]);
                }
                else {
                    ok = (S[0] == 'x' && ans[1] == ans[N-1]) || (S[0] == 'o' && ans[1] != ans[N-1]);
                }
            }
        }
        if (ok) {
            cout << ans << endl;
            return;
        }
    }

    cout << -1 << endl;
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


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

int main() {
    int N;
    int M;
    int count = 0;
    int sum = 0;

    cin >> N >> M;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    for(int i = 0; i < N; i++) {
        sum += A.at(i);
    }

    for(int i = 0; i < N; i++) {
        if(sum <= A.at(i)*4*M) {
            count++;

        }
    }
    if (count >= M) {
        cout << "Yes" << endl;

    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n;
    ll a,b;
    cin >> n >> a >> b;
    ll h[n];
    rep(i,n){
        cin >> h[i];
    }

    ll l = -1;
    ll r =  1000000007;

    while(r-l>0){
        ll mid = (l+r)/2;
        //cout << mid << endl;
        ll count = 0;
        rep(i,n){
            if(mid*b<h[i]){
                count += ceil((double)(h[i]-mid*b)/(a-b));
                //if((h[i]-mid*b)%(a-b)>0)count+=1;
            }
        }
        if(count<=mid){
            r = mid;
        }else{
            if(r-l==1){
                l = mid + 1;
            }else{
                l = mid;
            }
        }
    }

    cout << r << endl;


    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>


int ans,n;

void cal(int sum, int num){
	int i;
	if(num==0 && sum==n)ans++;
	else if(num>0){
		for(i=0;i<=9;i++){
			cal(sum+i,num-1);
		}
	}
}

int main(){
	
	while(scanf("%d",&n)!=EOF){
		ans=0;
		cal(0,4);
		printf("%d\n",ans);
	}
	
	return 0;
}


Measured memory_bytes: 596
#n, m = list(map(int,input().split()))

s = input()
f = True

if s[::-1] != s:
    f = False

t = s[:(len(s)-1)//2]
if t != t[::-1]:
    f = False

t = s[(len(s)+3) // 2 - 1:]
if t != t[::-1]:
    f = False

if f:
    print('Yes')
else:
    print('No')
    


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

bool is_contain_keywords(string str,vector<string>& keywords) {
  int cnt = 0;
  vector<string>::iterator key_itr = keywords.begin();
  while(key_itr != keywords.end()) {
    if(str.find(*key_itr) != string::npos) {
      return true;
    }
    key_itr++;
  }
  return false;
}

string decode(string cipher) {
  vector<string> keywords;
  keywords.push_back("the");
  keywords.push_back("this");
  keywords.push_back("that");

  int remind_shift = -1;
  int max_cnt = 0;
  int str_len = cipher.length();
  for(int shift = 0;shift < 'z' - 'a' + 1;shift++) {
    string str = cipher;
    for(int i=0;i<str_len;i++) {
      if('a' <= cipher[i] && cipher[i] <= 'z') {
        str[i] = (cipher[i] - 'a' + shift) % ('z' - 'a' + 1) + 'a';
      }
    }
    if(is_contain_keywords(str,keywords)) return str;
  }
  return "";
}

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

  string cipher;
  while(getline(cin,cipher)) {
    cout << decode(cipher) << endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

const int T[][7] = {
	{0, 1, 1, 1, 1, 1, 1},
	{0, 0, 0, 0, 1, 1, 0},
	{1, 0, 1, 1, 0, 1, 1},
	{1, 0, 0, 1, 1, 1, 1},
	{1, 1, 0, 0, 1, 1, 0},
	{1, 1, 0, 1, 1, 0, 1},
	{1, 1, 1, 1, 1, 0, 1},
	{0, 1, 0, 0, 1, 1, 1},
	{1, 1, 1, 1, 1, 1, 1},
	{1, 1, 0, 1, 1, 1, 1},
};

int n;
int a[7];

int main()
{
	while (cin >> n, ~n){
		memset(a, 0, sizeof(a));
		rep(i, n){
			int b;
			cin >> b;
			rep(j, 7){
				cout << (a[j] ^ T[b][j]);
				a[j] = T[b][j];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 1160
// Template //
#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 sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template<class T> lint gcd(T a, T b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T> lint lcm(T a, T b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //


int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    string S, sub;
    lint N;
    cin >> S >> N;
    if (S.size() == 1) {
        cou(N / 2); exit(0);
    }
    sub = S;
    lint cnt = 0;
    rep(i, S.size() - 1) {
        if (sub[i] == sub[i + 1]) {
            sub[i + 1] = 'A';
            cnt++;
        }
    }
    lint beginconseq = 1;
    lint endconseq = 1;
    if (S[0] == S[S.size() - 1]) {

        int k = 0;
        while (S[k] == S[k + 1]) {
            k++;
            beginconseq++;
            if (beginconseq == S.size()) {
                cou(S.size() * N / 2); exit(0);
            }
        }
        int l = S.size() - 1;
        while (S[l] == S[l - 1]) {
            l--;
            endconseq++;
        }
        lint cnt_beg = cnt - beginconseq / 2;
        lint cnt_end = cnt - endconseq / 2;
        lint cnt_beg_end = cnt - beginconseq / 2 - endconseq / 2;
        lint beg_end = (beginconseq + endconseq) / 2;
        cou(cnt_end + cnt_beg + (N - 2) * cnt_beg_end + (N - 1) * beg_end);
    }
    else cou(cnt * N);
}

Measured memory_bytes: 256
n=gets.to_i
h=gets.split.map(&:to_i)
ans=0
100.downto(1){|height|
  idx=[]
  connected=false
  h.each_with_index{|flower_height,i|
    if flower_height==height
      unless connected
        connected=true
        ans+=1
      end
      idx << i
    else
      connected=false
    end
  }
  idx.each{|i|h[i]-=1}
}

puts ans

Measured memory_bytes: 1788
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_C
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int p_taro=0, p_hanako=0;

int dictionary(string taro, string hanako){
  //taro??????????????°2
  //hanako??????????????°1
  //??????????????????0
  if(taro == hanako) return 0;
  else{
  vector<string> dic;
  dic.push_back(taro);
  dic.push_back(hanako);
  sort(dic.begin(), dic.end());
  if(dic[0] == hanako) return 2;
  else return 1;
  }
}




void match(string taro, string hanako){
  if(dictionary(taro,hanako) == 2){ p_taro += 3;}
  if(dictionary(taro,hanako) == 1){ p_hanako += 3;}
  if(dictionary(taro,hanako) == 0) {p_taro += 1; p_hanako += 1;}
}

int main(){
  int n;
  cin >> n;
  string taro, hanako;
  for(int i = 0; i<n; i++){
    cin >> taro >> hanako;
    match(taro, hanako);
  }
  cout << p_taro << " " << p_hanako << endl;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e18
#define dump(x) cerr<<#x<<"="<<x<<endl
#define int long long

using ll = long long;
const ll mod = LLONG_MAX;

int A,B;
signed main(){
  cin>>A>>B;
  if(A%3==0 || B%3==0 || (A+B)%3==0){
    cout<<"Possible"<<endl;
  }
  else{
    cout<<"Impossible"<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;
char s[8][8];

int sch(int a,int b,char o,char x){
  int res=0;
  for(int i=-1;i<2;i++)
	for(int j=-1;j<2;j++){
	  if(i==0&&j==0)continue;
	  int ti=i+a,tj=j+b;
	  int cnt=0;
	  while(1){
		if(ti<0||7<ti||tj<0||7<tj)break;
		if(s[ti][tj]=='.')break;
		if(s[ti][tj]==x)cnt++;
		if(s[ti][tj]==o){
		  res+=cnt;
		  break;
		}
		ti+=i;
		tj+=j;
	  }
	}
  return res;
}

void chg(int a,int b,char o,char x){
  s[a][b]=o;
  for(int i=-1;i<2;i++)
	for(int j=-1;j<2;j++){
	  if(i==0&&j==0)continue;
	  int ti=i+a,tj=j+b;
	  while(1){
		if(ti<0||7<ti||tj<0||7<tj)break;
		if(s[ti][tj]=='.')break;
		if(s[ti][tj]==o){
		  int tx=a+i,ty=b+j;
		  for(;s[tx][ty]!=o;tx+=i,ty+=j){
			s[tx][ty]=o;
		  }
		  break;
		}
		ti+=i;
		tj+=j;
	  }
	}
}

int main(){
  
  for(int i=0;i<8;i++)
	for(int j=0;j<8;j++)
	  cin>>s[i][j];
  
  while(1){
	int f=1;
	int ma=0;
	int x=-1,y=-1;

	for(int i=7;i>=0;i--){
	  for(int j=7;j>=0;j--){
		if(s[i][j]!='.')continue;
		int t=sch(i,j,'o','x');
		if(t==0)continue;
		f=0;
		if(t>=ma){
		  ma=t;
		  x=i,y=j;
		}
	  }
	}
	if(x!=-1)chg(x,y,'o','x');
	/*
  for(int i=0;i<8;i++){
	for(int j=0;j<8;j++){
	  cout<<s[i][j];
	}
	cout<<endl;
  }
	*/
	ma=0;
	x=-1,y=-1;
	
	for(int i=0;i<8;i++){
	  for(int j=0;j<8;j++){
		if(s[i][j]!='.')continue;
		int t=sch(i,j,'x','o');
		if(t==0)continue;
		f=0;
		if(t>=ma){
		  ma=t;
		  x=i,y=j;
		}
	  }
	}
	if(x!=-1)chg(x,y,'x','o');
	/*
  for(int i=0;i<8;i++){
	for(int j=0;j<8;j++){
	  cout<<s[i][j];
	}
	cout<<endl;
  }
	*/
	if(f)break;
  }
  
  for(int i=0;i<8;i++){
	for(int j=0;j<8;j++){
	  cout<<s[i][j];
	}
	cout<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3128
#include<stdio.h>

void merge(int num[], int pos[], int numbuf[], int posbuf[], int left, int right) {
	
	int center;
	int i, j, k;

	if (left == right) return;

	center = (left + right) / 2;
	merge(num, pos, numbuf, posbuf, left, center);
	merge(num, pos, numbuf, posbuf, center + 1, right);

	for (i = left, j = center + 1, k = 0; i <= center && j <= right; k++) {
		if (num[i] < num[j]) {
			numbuf[left + k] = num[i];
			posbuf[left + k] = pos[i];
			i++;
		}
		else {
			numbuf[left + k] = num[j];
			posbuf[left + k] = pos[j];
			j++;
		}
	}
	if (i > center) {
		for (; k <= right - left; k++, j++) {
			numbuf[left + k] = num[j];
			posbuf[left + k] = pos[j];
		}
	}
	if (j > right) {
		for (; k <= right - left; k++, i++) {
			numbuf[left + k] = num[i];
			posbuf[left + k] = pos[i];
		}
	}

	for (k = left; k <= right; k++) {
		num[k] = numbuf[k];
		pos[k] = posbuf[k];
	}
}

int main() {

	int N, A[100000], pos[100000], numbuf[100000], posbuf[100000], result;
	int i;

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

	merge(A, pos, numbuf, posbuf, 0, N - 1);

	result = 0;
	for (i = 0; i < N; i += 2) if (pos[i] % 2 == 1) result++;

	printf("%d\n", result);

	return 0;
}

Measured memory_bytes: 1664
package main

import "fmt"

func match(s string) bool {
	return s[:len(s)/2] == s[len(s)/2:]
}

func main() {
	var S string
	fmt.Scan(&S)
	var length int
	if len(S)%2 == 0 {
		length = len(S) - 2
	} else {
		length = len(S) - 1
	}
	result := 0
	for i := length; i > 0; i -= 2 {
		if match(S[:i]) {
			result = i
			break
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;
	int n;
	cin>>n;
	cout<<(n+1)/2;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        mp[a] = i+1;
    }

    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        cout << itr->second << " ";
    }
    cout << endl;
    return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y, m;
string s, t;

ll rem;
ll cnt[3];


// < ----------- func eh ---------------- ? //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n ;
	vll a(n+1);
	for(ll i=1;i<=n;i++) {
		cin>>x;
		a[x] = i;
	}
	for(ll i=1;i<=n;i++) cout<<a[i]<<" ";newl;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3972
#include <stdio.h>
#include <cmath>

using namespace std;

int N;
int boss[7],height[7];

int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}

void unite(int x,int y){
	int boss_x = get_boss(x);
	int boss_y = get_boss(y);

	if(boss_x == boss_y)return;

	if(height[x] > height[y]){

		boss[boss_y] = boss_x;

	}else if(height[x] < height[y]){

		boss[boss_x] = boss_y;

	}else{ //height[x] == height[y]

		boss[boss_y] = boss_x;
		height[x]++;
	}
}

void init(){
	for(int i = 0; i < 7; i++){
		boss[i] = i;
		height[i] = 0;
	}
}

int main(){

	int array[7],num_KI,num_boss;

	char buf[3];
	int a,b;

	while(scanf("%d",&N) != EOF){

		init();
		for(int i = 0; i < 7; i++)array[i] = 0;

		for(int i = 0; i < N; i++){
			scanf("%s",buf);
			a = buf[0] - '0';
			b = buf[1] - '0';
			array[a]++;
			array[b]++;
			unite(a,b);
		}

		num_KI = 0;

		for(int i = 0; i < 7; i++)if(array[i]%2 == 1)num_KI++;

		if(num_KI > 2){
			printf("No\n");
			continue;
		}

		num_boss = 0;
		for(int i = 0; i < 7; i++){
			if(array[i] > 0 && i == get_boss(i))num_boss++;
		}
		if(num_boss > 1){
			printf("No\n");
			continue;
		}

		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 2592
# ABC072d
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n):
    if p[i] == i+1:
        if i == n-1:
            ans += 1
            continue
        t = p[i]
        p[i] = p[i+1]
        p[i+1] = t
        ans += 1
print(ans)


Measured memory_bytes: 14068
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int a,b;
    cin >> a >> b;
    rep(i,1251){
        int c = i * 8/100;
        int d = i /10;
        if(a == c && b == d){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
 
    int N, X, Y; cin >> N >> X >> Y;
    int cnt[N];
    memset(cnt,0,sizeof(cnt));
    
    for (int i = 1; i <= N - 1; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            int num = min(abs(i - j), abs(i - X) + 1 + abs(Y - j));
            cnt[num]++;
        }
    }
    
    for (int i = 1; i < N; ++i) cout<<cnt[i]<<endl;
 
    
    return 0;
}


Measured memory_bytes: 256
n=int(input())

a=[]
for i in range(1,201):
    s=0
    for j in range(1,int(i**0.5)+1):
        if i%j==0:
            s+=1
            if j != i//j:
                s+=1
    a.append(s)

ans=0
for i in range(n):
    if a[i]==8 and i%2==0:
        ans+=1

print(ans)

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

using namespace std;

double rast(int x1,int y1,int x2,int y2)
{
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

map <string,int> d;
map <string,bool> used;
map <string,int> dpl;
int main()
{

   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    long long ans=0;
    for (int i=0;i<n;i++)
    {
        string s;
        cin >> s;
        sort(s.begin(),s.end());

        if (!used[s])
        {
            used[s]=true;
            dpl[s]=1;
            continue;
        }
ans+=dpl[s];

        dpl[s]++;

    }

    cout << ans;


}


Measured memory_bytes: 22144