akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){

    int n;cin>>n;
    
    string s;cin>>s;
    
    int q;cin>>q;

    vector<set<int>>alpha(26);
    //alpha[i]=アルファベットiの登場する場所(string sでのindex+1)
    rep2(i,n){
        alpha[s[i-1]-'a'].insert(i);
    }

    rep(_,q){
        int type;
        cin>>type;

        if(type==1){
            int p;
            char c;
            cin>>p>>c;
            //auto it=alpha[s[p-1]-'a'].find(p);
            alpha[s[p-1]-'a'].erase(p);
            alpha[c-'a'].insert(p);
            s[p-1]=c;
        }
        else if(type==2){
            
            int l,r;
            cin>>l>>r;
            int ret=0;
            rep(k,26){
                if(alpha[k].empty())continue;

            auto it=alpha[k].lower_bound(l);

            if(it!=alpha[k].end() && *it<=r)ret++;

            }
            cout<<ret<<"\n";

            //cout << c << "\n";
            
        }
    }

    return 0;

}
/*
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 



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

int N, Q; string S;
cin >> N >> S >> Q;

vector<set<int>> pos(26, set<int>({1<<30}));
rep(i, 0, N) {
    pos[S[i] - 'a'].insert(i);
}

while(Q--){
    int q; cin >> q;
    if (q == 1){
        int i; char c; cin >> i >> c;
        pos[S[i-1] - 'a'].erase(i-1);
        pos[c - 'a'].insert(i-1);
        S[i-1] = c;
    }
    else {
        int l, r; cin >> l >> r;
        int c = 0;
        for(set<int> &p: pos) if (!p.empty())
            if (*p.lower_bound(l-1) < *p.lower_bound(r)) ++c;

        cout << c << "\n";
    }
}

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．




*/

Measured memory_bytes: 24196
n,*a=map(int,open(0).read().split())
flag=1
c=0
while flag:
    flag=0
    for j in range(n-1,0,-1):
        if a[j]<a[j-1]:
            a[j],a[j-1]=a[j-1],a[j]
            flag=1
            c+=1
print(*a)
print(c)



Measured memory_bytes: 5608
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

const char Q = 'Q';
const char _ = '.';

char board[8][9] = {
    "........",
    "........",
    "........",
    "........",
    "........",
    "........",
    "........",
    "........",
};

int n;
bool pre_x[8], pre_y[8];

inline bool check(int x, int y) {
    int p = x, q = y;
    while (--p >= 0 && --q >= 0) {  // upper left 
        if (board[q][p] == Q) return false;
    }

    p = x; q = y;
    while (++p < 8 && --q >= 0) {   // upper right 
        if (board[q][p] == Q) return false;
    }

    p = x; q = y;
    while (++p < 8 && ++q < 8) {    // lower right 
        if (board[q][p] == Q) return false;
    }

    p = x; q = y;
    while (--p >= 0 && ++q < 8) {   // lower left 
        if (board[q][p] == Q) return false;
    }

    return true;
}

bool solve(int row) {
    if (row == 8)
        return true;
    if (pre_y[row] && solve(row + 1)) {
        return true;
    }
    else {
        for (int i = 0; i < 8; ++i) {
            if (!pre_x[i] && check(i, row)) {
                board[row][i] = Q;
                pre_x[i] = true;
                if (solve(row + 1)) {
                    return true;
                }
                else {
                    board[row][i] = _;
                    pre_x[i] = false;
                }
            }
        }
    }
    return false;
}

int main(void) {

    scanf("%d", &n);

    for (int i = 0, x, y; i < n; ++i) {
        scanf("%d %d", &y, &x);
        board[y][x] = Q;
        pre_y[y] = pre_x[x] = true;
    }

    solve(0);

    for (int i = 0; i < 8; ++i) {
        printf("%s\n", board[i]);
    }

    return 0;
}

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

using namespace std;
typedef unsigned long long ull;

ull Len(ull a, ull b){
	return a >= b ? a - b : b - a;
}

ull Min(ull a, ull b){
	return a >= b ? b : a;
}

ull GetLength(ull a, ull b, ull x, ull y){
	ull ret1, ret2;
	ret1 = b - a;
	ret2 = Len(a, x) + Len(b, y) + 1;
	return Min(ret1, ret2);
}

vector<ull> MakeLengthList(ull n, ull x, ull y){
	vector<ull> lengths(n);
	ull len;

	for(ull i = 1; i <= n; ++i){
		for(ull j = i + 1; j <= n; ++j){
			len = GetLength(i, j, x, y);
			++(lengths[len]);
		}
	}

	return lengths;
}

int main(void){
	ull n, x, y;

	cin >> n >> x >> y;
	
	vector<ull> lengths = MakeLengthList(n, x, y);

	for(ull i = 1; i <= n - 1; ++i){
		cout << lengths[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int  n=scn.nextInt();
		int []arr =new int[n];
		int count=0;
		for(int i=0;i<n;i++){
			int val = scn.nextInt();
			if((i+1)%2!=0){
			if((i+1)%2==(val%2)){
				count++;
			}
			}
		}
		System.out.println(count);

	}

}

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

const int MAXN=10e5+10;
char s[MAXN];
int len=1;

void read()
{
	s[len]=getchar();
	while(s[len]>='a' && s[len]<='z')
		s[++len]=getchar();
	len-=1;
	return;
}

bool judge()
{
	bool f=true;
	for(int i=1;i<=len/2;i++)
	{
		if(s[i]!=s[len-i+1])
			f=false;
	}
	if(f)return true;
	else
	{
		int n=len;
		if(s[1]==s[len])
		n-=3;
		else n-=2;
		if(n%2==0)
		return true;
		else return false;
	}	
}

int main()
{
	read();
	if(judge())
	printf("Second");
	else printf("First");
	return 0;
}

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

const int INF = 1000000000;

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

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;     //How many towns are there?

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

		int d[10][10];
		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				d[i][j]=T[i][j];
			}
		}
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(d[i][j]>d[i][k]+d[k][j]){
						d[i][j]=d[i][k]+d[k][j];
					}
				}
			}
		} 

		int dis=INF,name=-1,tmp;
		for(int i=0;i<m;i++){
			tmp = 0;
			for(int j=0;j<m;j++){
				tmp += d[i][j];
			}
			if(dis>tmp){
				dis=tmp;
				name=i;
			}
		}
		cout << name << " " << dis << endl;


	}

	return 0;
}

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

const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

void printv(vector<ll> v) {
  for (ll i : v)
    cout << i << " ";
  cout << endl;
}

int main() {
  string s, t;
  cin >>s >>t;
  int ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != t[i])ans++;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3808
"""
Writer: SPD_9X2
https://atcoder.jp/contests/abc163/tasks/abc163_e

dpか？
なにを基準にdpすればよい？
まとめられる状態は？
小さいことを考えると貪欲かなぁ
かいてみるか

挿入dp?
前から決めていけば、累積和で減る量がわかる
&増える寄与も計算できる
O(N**2)

全探索はむり

======答えを見ました======
今より右に行く、左に行くの集合に分けたとすると
大きい奴をより左にする方が最適
よって、途中まで単調減少、途中から単調増加が最適であるとわかる

dp[大きい方からi番目まで見た][左にl個つめた] = 最大値
で解ける

"""


N = int(input())

A = list(map(int,input().split()))
ai = []
for i in range(N):
    ai.append([A[i],i])
ai.sort()
ai.reverse()

ans = 0

dp = [ [float("-inf")] * (N+1) for i in range(N+1) ]
dp[0][0] = 0

for i in range(N):

    na,nind = ai[i]

    for l in range(i+1):

        r = N-1-(i-l)
        dp[i+1][l+1] = max(dp[i+1][l+1] , dp[i][l] + na*abs(nind-l) )
        dp[i+1][l]   = max(dp[i+1][l] , dp[i][l] + na*abs(nind-r) )

print (max(dp[N]))


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define BELLMAN_FORD_MAX_E 10005
#define BELLMAN_FORD_MAX_V 10005

struct edge {
    int from, to, cost;
    edge() {}
    edge(int f, int t, int c) : from(f), to(t), cost(c) {}
};

edge es[BELLMAN_FORD_MAX_E];

int d[BELLMAN_FORD_MAX_V];
bool negative[BELLMAN_FORD_MAX_V];
int V, E;

void shortest_path(int s, bool is_find_negative_loop) {
    for (int i = 0; i < V; i++)
        d[i] = (1 << 30);

    d[s] = 0;
    for (int j = 0; j < V; j++) {
        bool update = false;
        for (int i = 0; i < E; i++) {
            const edge &e = es[i];
            if (d[e.from] != (1 << 30) && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if (!update)
            break;
    }

    if (is_find_negative_loop) {
        for (int i = 0; i < V; i++) {
            negative[i] = false;
        }

        for (int i = 0; i < V; i++) {
            for (int j = 0; j < E; j++) {
                const edge &e = es[j];
                if (d[e.from] != (1 << 30) && d[e.to] > d[e.from] + e.cost) {
                    negative[e.to] = true;
                }

                if (negative[e.from]) {
                    negative[e.to] = true;
                }
            }
        }
    }
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int p;
    cin >> V >> E >> p;
    REP(i, E) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        es[i] = edge(a, b, p - c);
    }

    shortest_path(0, true);

    if (negative[V - 1]) {
        cout << "-1" << endl;
    } else {
        cout << max(0, -d[V - 1]) << endl;
    }

    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
N = list(map(int, input()))
s = 0
sum = 0

for i in range(len(N)):
    sum += N[i]
    s += pow(10, len(N)-i-1) * N[i]

if s%sum == 0:
    print ("Yes")
else :
    print ("No")

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int x,y;
	public void solve() {
		x = nextInt();
		y = nextInt();

		if(x >= 0){
			if(y >= 0){
				if(x > y){
					if(y == 0){
						out.println(x-y+1);
					}else{
						out.println(x-y+2);
					}
				}else{
					out.println(y-x);
				}
			}else{
				out.println(Math.abs(Math.abs(y)-x)+1);
			}
		}else{
			if(y >= 0){
				if(y == 0){
					out.println(Math.abs(Math.abs(x)-y));
				}else{
					out.println(Math.abs(Math.abs(x)-y)+1);
				}
			}else{
				if(x > y){
					out.println(x-y+2);
				}else{
					out.println(y-x);
				}
			}
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 8148
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll N,M;
    cin >> N >> M;
    ll min = 1;
    ll max = N;
    ll L,R;
    rep(i,M){
        cin >> L >> R;
        if(L>min) min = L;
        if(R<max) max = R;
    }
    ll out = 0;
    if(min<=max) out = max - min + 1;
    cout << out << endl;
    return 0;
}


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

int main() {
   
  ll n,i;
  int flag=0;
  cin>>n;
  long double a;
  long double p=1;
  long double max=1000000000000000000;
  vector<long double> v;
  for(i=0;i<n;++i)
      { cin>>a;
        v.push_back(a);
        if(a==0)
           flag=1;
      }
      
    if(flag==1)
       cout<<"0";
       
    else
    {
      
    sort(v.begin(),v.end());
    
    for(i=v.size()-1;i>=0;--i)
      {
          p*=v[i];
          if(p>max)
             break;
             
      }
      if(i<0)
        cout<<(long long int )p;
        
      else
        cout<<"-1";
        
      
    }
      
  
      
       
	return 0;
}

Measured memory_bytes: 5436
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
    ]
k = int(input())
print(a[k-1])

Measured memory_bytes: 3060
seq = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())
print(seq[k - 1])


Measured memory_bytes: 2940
import math

x = int(input())


def check(x):
    i = 1
    while True:
        for j in range(i):
            if (i == j):
                continue
            elif (x % (i - j) == 0) and (x == ((i ** 5) - (j ** 5))):
                print(i, j)
                return
            elif (x % (i + j) == 0) and ( x == ((i ** 5) + (j ** 5))):
                print(i, -j)
                return
        i = i + 1

check(x)

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

int main(){
    int n;
    cin >> n;
    ll sum = 0;
    for (int i = 0; i < n;i++)
    {
        if(((i+1)%3==0)||((i+1)%5==0))
        {
            continue;
        }
        sum += i + 1;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll choco(ll H, ll W){
    ll ans = INF;
    vector<ll> pieces(0);
    if(H % 3 == 0){
        ans = 0;
    }
    else if(H % 3 == 1){
        pieces.push_back((H / 3 + 1) * W);
        pieces.push_back(2 * H / 3 * (W / 2));
        pieces.push_back(2 * H / 3 * W - 2 * H / 3 * (W / 2));
        sort(all(pieces));
        chmin(ans, pieces.at(2) - pieces.at(0));
        pieces.clear();
        pieces.push_back(H / 3 * W);
        pieces.push_back((2 * H / 3 + 1) * (W / 2));
        pieces.push_back((2 * H / 3 + 1) * W - (2 * H / 3 + 1) * (W / 2));
        sort(all(pieces));
        chmin(ans, pieces.at(2) - pieces.at(0));
        chmin(ans, W);
    }
    else if(H == 2){
        pieces.push_back(W);
        pieces.push_back(W / 2);
        pieces.push_back(W - W / 2);
        sort(all(pieces));
        chmin(ans, pieces.at(2) - pieces.at(0));
    }
    else{
        pieces.push_back((H / 3 + 2) * W);
        pieces.push_back(2 * (H / 3) * (W / 2));
        pieces.push_back(2 * (H / 3) * W - 2 * (H / 3) * (W / 2));
        sort(all(pieces));
        chmin(ans, pieces.at(2) - pieces.at(0));
        pieces.clear();
        pieces.push_back((H / 3 + 1) * W);
        pieces.push_back((2 * (H / 3) + 1) * (W / 2));
        pieces.push_back((2 * (H / 3) + 1) * W - (2 * (H / 3) + 1) * (W / 2));
        sort(all(pieces));
        chmin(ans, pieces.at(2) - pieces.at(0));
        pieces.clear();
        pieces.push_back((H / 3) * W);
        pieces.push_back((2 * (H / 3) + 2) * (W / 2));
        pieces.push_back((2 * (H / 3) + 2) * W - (2 * (H / 3) + 2) * (W / 2));
        sort(all(pieces));
        chmin(ans, pieces.at(2) - pieces.at(0));
        chmin(ans, W);
    }
    return ans;
}

int main()
{
    ll H, W;
    cin >> H >> W;
    ll ans = INF;
    chmin(ans, choco(H, W));
    chmin(ans, choco(W, H));
    cout << ans << endl;
}

Measured memory_bytes: 3624
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static PrintWriter writer = new PrintWriter(System.out);
  static final int TH = 200;

  public static void main(String[] args) {
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] sum = new int[M + 2];
    for (int i = 0; i < N; i++) {
      int L = Integer.parseInt(sc.next());
      int R = Integer.parseInt(sc.next());
      int prev = M + 100000;
      for (int j = 1; ; j++) {
        int l = (L + j - 1) / j;
        int r = R / j;
        if (r < TH) break;
        if (l <= r) {
          sum[Math.max(TH, l)]++;
          if (r >= prev) {
            sum[prev]--;
          } else {
            sum[r + 1]--;
          }
          prev = l;
        }
        if (l < TH) break;
      }
      for (int j = 1; j < Math.min(TH, M + 1); j++) {
        int lo = (L - 1) / j;
        int hi = R / j;
        if (lo != hi) {
          sum[j]++;
          sum[j + 1]--;
        }
      }
    }
    for (int i = 1; i <= M; i++) {
      sum[i] += sum[i - 1];
      writer.println(sum[i]);
    }
    writer.flush();
  }

}


Measured memory_bytes: 69296
n = int(input())
t, a = map(int, input().split())
li = list(map(int, input().split()))
x = 10**9
ind = 0
for i in range(n):
    mean = t - li[i] * 0.006
    sa = abs(mean - a)
    if sa < x:
        x = sa
        ind = i + 1
print(ind)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
  
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ll i,j,k,l,n;
    cin>>n;
    // a^5=n+b^5

    ll a,b;
    for(i=-1000;i<=1000;i++){
        for(j=-1000;j<=1000;j++){
            if(i*i*i*i*i==n+j*j*j*j*j){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"-1";
    return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			long a = array[0];
			long b = array[1];
			long k = array[2];

			if (b - a >= 2 * k) {
				for (var i = 0; i < k; ++i) {
					Console.WriteLine($"{a + i}");
				}

				for (var i = 1; i <= k; ++i) {
					Console.WriteLine($"{b - k + i}");
				}
			} else {
				for (var i = a; i <= b; ++i) {
					Console.WriteLine($"{i}");
				}
			}

			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
int main(){
  int d, g; cin >> d >> g;
  vector<int> p(d), c(d);
  for(int i = 0; i < d; i++) cin >> p[i] >> c[i];
  g /= 100;
  for(int i = 0; i < d; i++) c[i] /= 100;
  vector<int> f(1<<18, 1<<30);
  f[0] = 0;
  for(int i = 0; i < d; i++){
  	vector<int> nf = f;
    for(int j = 0; j < p[i]; j++){
    	for(int k = 0; k < 1<<18; k++){
          	int nk = k + (j + 1) * (i + 1);
          	if(j + 1 == p[i]) nk += c[i];
          	if(nk < nf.size())
				nf[nk] = min(nf[nk], f[k] + j + 1);
        }
    }
    f = nf;
  }
  int ans = 1<<30;
  for(int i = g; i < 1<<18; i++) ans = min(ans, f[i]);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();
    set<int> s;
    rep(i, 3){
        int x;
        cin >> x;
        s.insert(x);
    }
    cout << (s.size() == 2 ? "Yes":"No") <<endl;
}

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

using namespace std;

const int MAXN = 105;

int A[MAXN], n;

int main(){
    cin>>n;
    int ans=0x3f3f3f3f;
    for(int i=1;i<=n;++i)cin>>A[i];

    for(int i=0;i<=105;++i){
        int t=0;
        for(int j=1;j<=n;++j){
            t+=abs(A[j]-i)*abs(A[j]-i);
        }
        ans=min(ans, t);
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
/*
ID: skipian1
PROB: 
LANG: C++11
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF = 2000000000
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define X first
#define Y second

int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  int c[n];
  for (int i = 0; i <  n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  int dp[n][3];
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for (int i = 1; i < n; i++) {
    dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
  }
  cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << "\n";
}


Measured memory_bytes: 2560
import java.util.*;

class Board {
  int[] Q;
  boolean[] filled;

  Board() {
    Q = new int[8];
    filled = new boolean[8];
    Arrays.fill(Q, -1);
    Scanner sc = new Scanner(System.in);

    int k = sc.nextInt();
    for (int i = 0; i < k; ++i) {
      int r = sc.nextInt();
      filled[r] = true;
      int c = sc.nextInt();
      Q[r] = c;
    }
  }

  boolean solve(int row) {
    if (row >= 8) {
      return true;
    }
    if (filled[row]) {
      return solve(row + 1);
    }
    for (int c = 0; c < 8; ++c) {
      if (can_place(row, c)) {
        Q[row] = c;
        if (solve(row + 1)) {
          return true;
        }
        Q[row] = -1;
      }
    }
    return false;
  }

  // pre : *haven't* placed in the same row
  boolean can_place(int row, int col) {
    for (int r = 0; r < 8; ++r) {
      if (Q[r] == col) return false;
      int row_difference = Math.abs(r - row);
      if (Q[r] >= 0 && (Q[r] == col + row_difference || Q[r] == col - row_difference)) return false;
    }
    return true;
  }

  void print() {
    for (int r = 0; r < 8; ++r) {
      for (int c = 0; c < Q[r]; ++c) {
        System.out.print(".");
      }
      System.out.print("Q");
      for (int c = Q[r] + 1; c < 8; ++c) {
        System.out.print(".");
      }
      System.out.println();
    }
  }
}

public class Main {
  public static void main(String[] args) {
    Board b = new Board();
    b.solve(0);
    b.print();
  }
}


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

int main(){
    int n,a[110],sum;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum+=a[i];
    }
    double m=sum/(double)n;
    int ans=0;
    double dif=110;
    for(int i=0; i<n; i++){
        double k=m-(double)a[i];
        if(k<0)k*=-1;
        if(dif>k){
            dif=k;
            ans=i;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
main = do
  n<- (read::String->Int) <$> getLine
  ws <-  map readCard <$> (replicateM n getLine)
  putStr $ unlines $ map showCard (cards \\ ws)

readCard:: String -> (String, Int)
readCard c = (a, (read:: String->Int) b)
              where
                [a,b]= words c

showCard:: (String, Int) -> String
showCard (a,b) = a++ " "++(show b)

cards:: [(String,Int)]
cards=[(x,y) | x <- ["S","H","C","D"], y <- [1..13]]

Measured memory_bytes: 3988
/**
 *    author:  DFLMKWR
 */

#include <iostream>
#include <string>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int cnt = 0;
  if (s[0] == 'R') cnt = 1;
  for (int i = 1; i < 3; i++)
    if (s[i] == 'R')
      if (s[i - 1] == 'R') cnt++;
      else cnt = 1;
  cout << cnt << "\n";
  return 0;
}


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

const int mod = 1e9+7;

int main(){
	int s;
  	cin >> s;
  	vector<ll> dp(s+1);
  	dp[0] = 1;
  
  	for(int i = 1; i <= s; i++){
    	rep(j, i-2){
        	dp[i] += dp[j];
          	dp[i] %= mod;
        }
    }
  
  	cout << dp[s] << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<int,int> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int,pair<int,int> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000+7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e15
# define LG 20  
typedef pair<int,pair<int,int> > pii;
# define INF1 (int)1e9+2
# define maxn 5005
# define offset 5

int main()
{
	 int x;int y;
	 cin >> x >> y;
	 int d;
	 if(x==y)
	 {
	 	 cout << "0";
	 	 return 0;
	 }
	 if(x==-y)
	 {
	 	 cout << "1";
	 	 return 0;
	 }
	 int xx=abs(x);int yy=abs(y);
	 int rs;
	 if(xx<yy)
	 {
	 	rs=1;
	 }
	 else
	 	rs=-1;
	  d=(abs(xx-yy));
	 if(x*rs<0)
	 	d++;
	 if(y*rs<0)
	 	d++;
	 cout << d;
}

Measured memory_bytes: 256
n = int(input())
W = [int(i) for i in input().split()]
S1 = sum(W)
S2 = 0
ans = abs(S1-S2)
for w in W:
    S1 -= w
    S2 += w
    if(ans>abs(S1-S2)):
        ans = abs(S1-S2)
print(ans)


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

int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H);
    rep(i, H){
        cin >> S[i];
    }
    int ans[H][W];
    rep(i, H){
        rep(j, W){
            ans[i][j] = 0;
        }
    }
    int l = -1;
    int counter = 0;
    rep(i, H){
        rep(j, W){
            if(S[i][j] == '.'){
                if(counter == 0){
                    l = j;
                }
                counter++;
                if(j == W-1){
                    for (int k = W-1; k >= l; k--){
                        ans[i][k] += counter;
                    }
                }
            } else {
                if(counter != 0){
                    for (int k = j-1; k >= l; k--){
                        ans[i][k] += counter;
                    }
                }
                counter = 0;
            }
        }
        l = -1;
        counter = 0;
    }

    l = -1;
    counter = 0;
    rep(j, W){
        rep(i, H){
            if(S[i][j] == '.'){
                if(counter == 0){
                    l = i;
                }
                counter++;
                if(i == H-1){
                    for (int k = H-1; k >= l; k--){
                        ans[k][j] += counter;
                    }
                }
            } else {
                if(counter != 0){
                    for (int k = i-1; k >= l; k--){
                        ans[k][j] += counter;
                    }
                }
                counter = 0;
            }
        }
        l = -1;
        counter = 0;
    }

    int xx = 0;
    rep(i, H){
        rep(j, W){
            xx = max(xx, ans[i][j]);
            //cout << i << j << " " << ans[i][j] << endl;
        }
    }

    cout << xx-1 << endl;

    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  int mxi = 0, mni = 1e9;

  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    mxi = max(mxi, a), mni = min(mni, a);
  }

  cout << mxi - mni << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

int main() {
	ll h, w; cin >> h >> w;

	// h > w;
	if (!(h % 3) || !(w % 3)) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = ((h > w) ? w : h);

	ll s = MAX_L;
	rep(i, 1, h) {
		ll a = i * w;
		ll b = w / 2 * (h - i);
		ll c = (w / 2 + ((w & 1) ? 1 : 0)) * (h - i);
		ll maxS = max(a, max(b, c));
		ll minS = min(a, min(b, c));
		s = min(s, maxS - minS);
	}

	ll t = MAX_L;
	rep(i, 1, w) {
		ll a = i * h;
		ll b = h / 2 * (w - i);
		ll c = (h / 2 + ((h & 1) ? 1 : 0)) * (w - i);
		ll maxS = max(a, max(b, c));
		ll minS = min(a, min(b, c));
		s = min(s, maxS - minS);
	}
	cout << min(ans, min(s, t)) << endl;

	return 0;
}

Measured memory_bytes: 256
#ifdef lolipop
#define _GLIBCXX_DEBUG
#endif

/*
    This ain't a milly rock
    This a money dance
    And my D' ain't hard
    That's a '30 in my pants
*/

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <ctime>
#include <map>
#include <random>
#include <iomanip>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <bitset>
#include <deque>
#include <utility>

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ld long double

using namespace std;

// mt19937 rnd(time(nullptr));

inline void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

const int MOD = 2019;

void solve() {
    string s;
    cin >> s;
    int n = (int) s.size();
    vector <int> v(n, 0);
    for(int i = 0; i < n; ++i) {
        v[i] = s[i] - '0';
    }
    vector <int> p(n + 1, 0);
    int x = 1;
    for(int i = n - 1; i >= 0; --i) {
        p[i] = (p[i + 1] + v[i] * x) % MOD;
        x *= 10;
        x %= MOD;
    }
    int ans = 0;
    vector <int> cnt(MOD, 0);
    for(int i = n; i >= 0; --i) {
        ans += cnt[p[i]];
        cnt[p[i]]++;
    }
    cout << ans << '\n';
}

signed main() {
#ifdef lolipop
    freopen("input.txt", "r", stdin);
#else
    fastio();
#endif

    int T = 1;
//    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 6100
#include <cstdio>
int main(void)
{
    bool rowShow[100],colShow[100];
    char bitmap[100][100];
    int row,col,i,j;
    scanf("%d%d",&row,&col);
    
    for(i=0;i<100;i++)
    {
        rowShow[i]=false;
        rowShow[i]=false;
    }


    for(i=0;i<row;i++)
    {
        getchar();
        for(j=0;j<col;j++)
        {
            scanf("%c",&bitmap[i][j]);
        }
    }

   for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {

            if(bitmap[i][j]=='#')
            {
                rowShow[i]=true;
                colShow[j]=true;
            } 
        }
    }
    for(i=0;i<row;i++)
    {
        if(rowShow[i]){
            for(j=0;j<col;j++)
            {
                if(colShow[j])
                    printf("%c",bitmap[i][j]);
            }
        printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a == b && a != c){
    cout << "Yes" << endl;
  }
  else if (c == b && a != c){
    cout << "Yes" << endl;
  }
  else if (a == c && a != b){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n=int(input())
count=[0]*4

for i in range(n):
    s=input()
    if s=="AC":
        count[0]+=1
    elif s=="WA":
        count[1]+=1
    elif s=="TLE":
        count[2]+=1
    else:
        count[3]+=1


results=["AC", "WA", "TLE", "RE"]

for i in range(4):
    txt="{0} x {1}".format(results[i], count[i])
    print(txt)

Measured memory_bytes: 69896
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD  1000000007
#define ll long long
#define int long long
# define INF 1000005
#define ar array
# define fr first
# define sc second
#define wt(x) int x;cin>>x;while(x--)
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
//#define cerr if(false)cerr
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 }
 
int power(int a,int b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    int res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 
int  MMI(int p){
    return power(p,MOD-2,MOD);
}
const int SIZE = 1<<21;
int fac[SIZE],inv[SIZE];
int C(int x,int y){
    if(y<0||y>x)return 0;
    return fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
void build(){
   
    fac[0]=1;
    for(int i=1;i<SIZE;i++)fac[i]=fac[i-1]*i%MOD;
    inv[SIZE-1]=power(fac[SIZE-1],MOD-2,MOD);
    for(int i=SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%MOD;
}
void ADD(int& x,int y){x=(x+y)%MOD;if(x<0)x+=MOD;}
int32_t main()
{
    c_p_c();
    build();
    int K;
    string s;
     cin>>K>>s;
    int n=s.size();
    int an=0;
    for(int i=n;i<=K+n;i++){
       ADD(an,C(K+n,i)*power(25,K+n-i,MOD));
    
    }
   cout<<an;
   

    


 
    
      return 0;
       }
        
        

        


























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

void main() {
    int h, w, k;
    scan(h, w, k);
    auto c = iota(h).map!(i => readln.chomp).array;

    int ans;

    foreach (rs; 0 .. 1 << h) {
        foreach (cs; 0 .. 1 << w) {
            int cnt;
            foreach (i; 0 .. h) {
                foreach (j; 0 .. w) {
                    if (c[i][j] == '.')
                        continue;
                    if ((1 << i) & rs || (1 << j) & cs)
                        continue;
                    cnt++;
                }
            }
            ans += (k == cnt);
        }
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
    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);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 2740
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

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

  cout << max(a+b, max(a-b, a*b)) << endl;
  return 0;
} 

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

using namespace std;

const int N=4005;
int n,a[N],b[N],dp[N][N],pos[N][2],cost[N][N][2];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    n*=2;
    int numb=0;
    for(int i=1;i<=n;i++)
    {
        char c;
        cin>>c>>a[i];
        if(c=='B') b[i]=1;
        numb+=b[i];
        pos[a[i]][b[i]]=i;
    }
    int numw=n-numb;
    for(int i=1;i<=numw;i++)
    {
        int id=pos[i][0],val=0;
        for(int j=1;j<i;j++) val+=(pos[j][0]>id);
        for(int j=1;j<=numb;j++) cost[i][j][0]=cost[i][j-1][0]+(pos[j][1]>id);
        for(int j=0;j<=numb;j++) cost[i][j][0]+=val;
    }
    for(int i=1;i<=numb;i++)
    {
        int id=pos[i][1],val=0;
        for(int j=1;j<i;j++) val+=(pos[j][1]>id);
        for(int j=1;j<=numw;j++) cost[i][j][1]=cost[i][j-1][1]+(pos[j][0]>id);
        for(int j=0;j<=numw;j++) cost[i][j][1]+=val;
    }
    for(int i=0;i<=numw;i++)
    {
        for(int j=0;j<=numb;j++) dp[i][j]=1e9;
    }
    dp[0][0]=0;
    for(int i=0;i<=numw;i++)
    {
        for(int j=0;j<=numb;j++)
        {
            if(i+1<=numw) dp[i+1][j]=min(dp[i+1][j],dp[i][j]+cost[i+1][j][0]);
            if(j+1<=numb) dp[i][j+1]=min(dp[i][j+1],dp[i][j]+cost[j+1][i][1]);
        }
    }
    cout<<dp[numw][numb];
}


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

int main() {
  int N, L;
  cin >> N >> L;
  vector<int> v(N);
  for (int i = 0; i < N; ++i) {
    v.at(i) = L + i;
  }
  int sum1 = accumulate(v.begin(), v.end(), 0);
  int mn = INT_MAX;
  int idx;
  for (int i = 0; i < N; ++i) {
    int sum2 = sum1;
    sum2 -= v.at(i);
    if (abs(sum1 - sum2) < mn) {
      mn = abs(sum1 - sum2);
      idx = i;
    }
  }
  cout << sum1 - v.at(idx) << endl;
}


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

int a[2000];

int main(){
    int n, z, w; cin >> n >> z >> w;
    for(int i=0;i<n;i++) cin >> a[i];

    if(n==1) cout << abs(a[0]-w) << endl;
    else cout << max(abs(a[n-1]-w), abs(a[n-2]-a[n-1])) << endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a_ary = gets.chomp.split(" ").map(&:to_i)
b_ary = gets.chomp.split(" ").map(&:to_i)

if a_ary.inject(:+) < b_ary.inject(:+)
  puts -1
  exit
end

dif = []
n.times do |i|
  dif << a_ary[i] - b_ary[i]
end

dif = dif.sort
idx = dif.index{ |i| i >= 0 }
if idx == 0
  puts 0
else
  sm = dif[0..(idx-1)].inject(:+)
  c = 1
  sum = 0
  sz = dif.size
  (sz - idx).times do |i|
    sum += dif[sz-i-1]
    if sum + sm >= 0
      c += i
      break
    end
  end
  puts idx+c
end

Measured memory_bytes: 19588
function main(input) {
  input=input.trim();
  const op = input.split(" ")[0];
  if(op=="a"||op=="e"||op=="i"||op=="o"||op=="u"){
    console.log("vowel");
  }else{
    console.log("consonant");
  }

}



main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import std.stdio;

void main() {
	int n, k, s;
	scanf("%d %d %d\n", &n, &k, &s);
	if (s == 10^^9) {
		foreach(_;0..n-k) {
			write(1, " ");
		}
		foreach(_;0..k) {
			write(10^^9, " ");
		}
	}
	else {
		foreach(_;0..n-k) {
			write(s+1, " ");
		}
		foreach(_;0..k) {
			write(s, " ");
		}
	}
}


Measured memory_bytes: 1276
fun main(args:Array<String>) {
  val (h, w) = readLine()!!.split(" ").map(String::toInt)
  // y, x style composer
  val bs = (1..h).map { 
    readLine()!!.toList().map(Char::toString).toMutableList()
  }
  for( y in (0..h-1) ) {
    for( x in (0..w-1) ) {
      // 周辺をスキャン
      if( bs[y][x] != "#" ) {
        var count = 0
        if( y -1 >= 0 && x-1 >= 0 &&  bs[y-1][x-1] == "#" ) count += 1
        if( y -1 >= 0 && bs[y-1][x+0] == "#" ) count += 1
        if( y -1 >= 0 && x+1 <= w-1 && bs[y-1][x+1] == "#" ) count += 1

        if( x-1 >= 0 && bs[y+0][x-1] == "#" ) count += 1
        if( x+1 <= w-1 && bs[y+0][x+1] == "#" ) count += 1

        if( y+1 <= h-1 && x-1 >= 0 && bs[y+1][x-1] == "#" ) count += 1
        if( y+1 <= h-1 && bs[y+1][x+0] == "#" ) count += 1
        if( y+1 <= h-1 && x+1 <= w-1 && bs[y+1][x+1] == "#" ) count += 1
        
        bs[y][x] = count.toString()
      }
    }
  }
  bs.map { b ->
    b.joinToString("").run(::println)
  }
}

Measured memory_bytes: 37896
//????????¨?????????????????¢??°????????????

#include <iostream>
#include <string>
using namespace std;
//---------------------------------------
int compare(string t, string h);
void tokuten(int &num_t, int &num_h, int compare);
//---------------------------------------

int main(void)
{
	int n;  //??????????????°
	int tokuten_taro = 0;
	int tokuten_hanako = 0;
	
	//???????????°?????\???
	cin >> n;
	
	//??????????????±
	for(int i = 0; i < n; i++){
		string card_taro, card_hanako;
		cin >> card_taro;  //1????????§????????????
		cin >> card_hanako; //1????????§????????????
		
		//???????????????
		tokuten(tokuten_taro, tokuten_hanako, compare(card_taro, card_hanako));
	}
	
	//??¨???
	cout << tokuten_taro << ' ' << tokuten_hanako << endl;
	
	return 0;

}

//------------------------------------------------------------
int compare(string t, string h){

	int size_m, size_M;
	
	if(t.size() >=  h.size()){
		size_m = h.size();
	}
	else if(t.size() <= h.size()){
		size_m = t.size();
	}
	
	
	for(int i = 0; i < size_m; i++){
	
		if(t[i] > h[i]){
			return -1;  //?????????????????§-1
		}
		else if(h[i] > t[i]){
			return 1;  //??±??????????????§1
		}
	}
	//????????????????????§???????????£?????´???
	if(t.size() > h.size()){
		return -1;   //?????????????????§-1
	}
	else if(h.size() > t.size()){
		return 1;   //??±??????????????§1
	}
	else{
		return 0;  //?????????0?????????
	}
	
}
//------------------------------------------------------------
void tokuten(int &num_t, int &num_h, int compare){
	
	if(compare == -1){
		num_t += 3;
	}
	else if(compare == 1){
		num_h += 3;
	}
	else if(compare == 0){
		num_t += 1;
		num_h += 1;
	}
}
	

Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <sstream>

using namespace std;

int DESC(char a,char b){
	if(a > b){
		return -1;
	}else{
		return 1;
	}
}
int ASC(char a,char b){
	if(a > b){
		return 1;
	}else{
		return -1;
	}
}

void selectSort(string& str,int (*cmp)(char,char)){
	for(int i = 0;i < str.size();i++){
		int index = i;
		for(int j = i + 1;j < str.size();j++){
			if(cmp(str[index],str[j]) == 1){
				index = j;
			}
		}
		swap(str[i],str[index]);
	}
}

int main(void){
	int n;
	string str;
	cin >> n;
	cin.get();
	for(int i = 0;i < n;i++){
		getline(cin,str);
		string asc, dsc;
		asc = str;
		dsc = str;
		selectSort(asc,ASC);
		selectSort(dsc,DESC);
		long long d, a;
		stringstream ss1(dsc);
		ss1 >> d;
		stringstream ss2(asc);
		ss2 >> a;
		cout << (d - a) << endl;
	//	cout << (atoi(dsc) - atoi(asc)) << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
int main(void){
int n,x[3];cin>>n;
for(int i=0;i<3;i++){
    x[2-i]=n%10;
    n=n/10;
}
for(int i=0;i<3;i++){
    if(x[i]==1)
        x[i]=9;
    else
        x[i]=1;
}
cout<<x[0]*100+x[1]*10+x[2]<<endl;
return 0;}


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

int main()
{
    int i = 1;
    while (true)
    {
        int x;
        cin >> x;
        if (x == 0)
        {
            cout << i << endl;
            return 0;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 3616
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int X, Y, E;
	static int[] x, y;
	static ArrayList<Integer>[] g;
	static boolean[] vis;
	static int[] matchTo;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		X = sc.nextInt();
		Y = sc.nextInt();
		E = sc.nextInt();
		x = new int[E];
		y = new int[E];
		g = new ArrayList[X + Y];
		for (int i = 0; i < X + Y; ++i) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < E; ++i) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt() + X;
			g[x[i]].add(y[i]);
			g[y[i]].add(x[i]);
		}
		vis = new boolean[X + Y];
		matchTo = new int[X + Y];
		Arrays.fill(matchTo, -1);
		int match = 0;
		for (int i = 0; i < X; ++i) {
			Arrays.fill(vis, false);
			if (dfs(i))
				++match;
		}
		System.out.println(match);
	}

	static boolean dfs(int v) {
		if (v < 0)
			return true;
		for (int u : g[v]) {
			if (vis[u])
				continue;
			vis[u] = true;
			if (dfs(matchTo[u])) {
				matchTo[u] = v;
				matchTo[v] = u;
				return true;
			}
		}
		return false;
	}
}

Measured memory_bytes: 48752