akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1000000000 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, l, q;
vector<int> x(100000 + 5, 1e10);
vector<vector<int>> step(100000+ 5, vector<int>(25, 1e10));

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) cin >> x[i];
    cin >> l;
    rep(i, n) {
        int nx = lower_bound(all(x), x[i] + l) - x.begin();
        if (x[nx] != x[i] + l) nx--;
        step[i][0] = nx;
    }
    rep(j, 20)rep(i, n) {
        step[i][j + 1] = step[step[i][j]][j];
    }
    cin >> q;
    rep(i, q) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);
        int ans = 0;
        int now = a;
        while (now < b) {
            int d = lower_bound(all(step[now]), b) - step[now].begin();
            if (x[step[now][d]] == b) ans += (int)pow(2, d);
            if (d == 0) {ans++; break;}
            ans += (int)pow(2, d - 1);
            now = step[now][d - 1];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 24320
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class Main{

	public static void main(String args[]){
		new Main().mainrun();
	}

	private Scanner scan;
	private String[] str;

	private int cursor = 0;

	private void mainrun() {
		scan = new Scanner(System.in);

		int n = Integer.parseInt(scan.nextLine());

		for(int i = 0;i < n;i++){
			cursor = 0;
			str = scan.nextLine().split("");
			System.out.println(looprun());
		}

		scan.close();
	}

	private Long looprun() {
		Deque<String> element = new LinkedList<String>();

		Deque<String> c = new LinkedList<String>();

		boolean numflag = false;

		for(int i = cursor;i < str.length;i++) {
			if(str[i].equals(" ")){
				continue;
			}
			if(str[i].equals("(")) {
				cursor = i + 1;
				element.add(Long.toString(looprun()));
				i = cursor;
				continue;
			}
			if(str[i].equals(")")) {
				cursor = i;
				break;
			}

			switch(str[i]) {
			case "+":
			case "-":
			case "*":
			case "/":
				if(!c.isEmpty()) {
					if(rank(c.getFirst()) >= rank(str[i])) {
						while(!c.isEmpty()) {
							if(rank(c.getFirst()) >= rank(str[i])) {
								element.add(c.remove());
							}else{
								break;
							}
						}
					}
				}

				c.push(str[i]);
				numflag = false;
				break;
			case "=":
				break;
			default: /*数値 0-9 */
				if(numflag) {
					String a = element.removeLast();
					element.add(a + str[i]);
				}else {
					element.add(str[i]);
					numflag = true;
				}
				break;
			}
		}

		while(!c.isEmpty()) {
			element.add(c.pop());
		}

		return cal(element);
	}

	private int rank(String s) {
		if(s.equals("*") || s.equals("/")) {
			return 2;
		}else { /* s.equals("+") || s.equals("-") */
			return 1;
		}
	}

	private Long cal(Deque<String> l) {
		Stack<String> c = new Stack<>();

		for(String s : l){
			switch(s) {
			case "+":
			case "-":
			case "*":
			case "/":
				long b = Long.parseLong(c.pop());
				long a = Long.parseLong(c.pop());
				if(s.equals("+")) {c.push(Long.toString(a + b));}
				if(s.equals("-")) {c.push(Long.toString(a - b));}
				if(s.equals("*")) {c.push(Long.toString(a * b));}
				if(s.equals("/")) {c.push(Long.toString(a / b));}
				break;
			default:
				c.push(s);
				break;
			}
		}

		return Long.parseLong(c.pop());
	}
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

const ll mod = 1000000007;

map<ll, ll> knapsack_combination(const vector<ll> & w, const vector<ll> & v) {
	const int inv = -1;
	const int n = w.size();
	const ll shift = 1LL << w.size();
	vector<pair<ll, ll>> dp;
	for (ll i = 0; i < shift; i++) {
		ll wSum = 0;
		ll vSum = 0;
		for (ll j = 0; j < n; j++) {
			if (i & (1LL << j)) {
				wSum += w[j];
				vSum += v[j];
			}
		}
		dp.emplace_back(wSum, vSum);
	}
	sort(dp.begin(), dp.end());
	ll pv = -1;
    map<ll, ll> r;
	for (auto p : dp) {
		if (pv >= p.second) {
			continue;
		}
		r[p.first] = max(r[p.first], p.second);
		pv = r[p.first];
	}
	return r;
}


int main(void)
{
	ll N, W;
	cin >> N >> W;
	vector<ll> v1(N / 2), w1(N/2), v2(N - N / 2), w2(N - N / 2);
	for (int i = 0; i < N/2; i++) {
		cin >> v1[i] >> w1[i];
	}
	for (int i = 0; i < N - N / 2; i++) {
		cin >> v2[i] >> w2[i];
	}

	auto f = knapsack_combination(w1, v1);
	auto s = knapsack_combination(w2, v2);
	auto v = 0LL;
	for (auto p : f) {
		ll rest = W - p.first;
		auto l = s.upper_bound(rest);
		if (l != s.begin()) {
			std::advance(l, -1);
			v = max(v, p.second + l->second);
		}
	}
	cout << v << endl;
}



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

namespace Math_Functions
{
    class Standard_Deviation
    {
        static void Main(string[] args)
        {
            while((int.Parse(Console.ReadLine())) != 0)
            {
                var score = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var score2 = score.Select(s => s * s).ToArray();
                Console.WriteLine(Math.Sqrt(score2.Average() - score.Average()*score.Average()));
            }
        }
    }
}

Measured memory_bytes: 9784
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) {  // 発見できたとき
    return 1;
  } else {  // 発見できなかったとき
    return 0;
  }
}
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  /*vector<int> a;
  int d;
  for (int i = 0; i < n; i++) {
    cin >> d;
    a.push_back(d);
  }*/
  for (int i = 0; i < k; i++) {
    if (a >= b) {
      b = b * 2;
      // cout << "b=" << b << endl;
    } else if (b >= c) {
      c = c * 2;
      // cout << "c=" << c << endl;
    }
  }
  if (a < b && b < c) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}

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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
double three (double n,int p){
	double m;
	m=(double)n-((pow(n,3)-p)/(3*pow(n,2)));
	if((fabs((m*m*m)-p))<0.00001*p)
		return m;
	else
		return (three(m,p));
}
int main(void)
{
	while(1){
		int q;
		double a;
		scanf("%d",&q);
		if(q==(-1)) break;
		a=(double)q/2;
		printf("%6f\n",three(a,q));
	}
	return 0;
}



Measured memory_bytes: 2048
while True:
  n, w, h = map(int, input().split())
  if w == 0:
    break
  lst = [(w, h)]
  for _ in range(n):
    p, s = map(int, input().split())
    wi, hi = lst.pop(p - 1)
    pos = s % (wi + hi)
    if pos < wi:
      w1, w2 = min(pos, wi - pos), max(pos, wi - pos)
      lst.append((w1, hi))
      lst.append((w2, hi))
    else:
      h1, h2 = min(pos - wi, hi - (pos - wi)), max(pos - wi, hi - (pos - wi))
      lst.append((wi, h1))
      lst.append((wi, h2))
  ans = sorted([wi * hi for wi, hi in lst])
  print(*ans)


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int N;
  cin >> N;
  ll Z, W;
  cin >> Z >> W;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  ll ans;
  if (N == 1) {
    ans = abs(a[0] - W);
  } else {
    ans = max(abs(W - a[N - 1]), abs(a[N - 2] - a[N - 1]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
k = int(input())
l = []
cnt = 0
for i in range(len(s)-1):
  cnt += 1
  if s[i] != s[i+1]:
    l.append(cnt)
    cnt = 0
else:
  cnt += 1
  l.append(cnt)

ans = 0
if len(set(list(s))) == 1:
  print(len(s)*k//2)
else:
  for i in range(len(l)):
    ans += l[i] // 2
  if s[0] != s[-1]:
    print(ans*k)
  else:
    fans = (k - 1) * ((l[0] + l[-1]) // 2) + ans
    ans = 0
    for i in range(1,len(l)-1):
      ans += l[i] // 2
    fans += (k - 1) * ans
    print(fans)

Measured memory_bytes: 3064
//
//  test_res.cpp
//  Atcoder1.cpp
//
//  Created by puneet raj raipuria on 31/07/20.
//  Copyright © 2020 puneet raj raipuria. All rights reserved.
//


#include <iostream>
#include<string>
using namespace std;

int main(){
    int n;
    cin>>n;
    string str;
    int a=0,b=0,c=0,d= 0;
    string ac = "AC";
    string wa = "WA";
    string tle = "TLE";
    string ra = "RA";
    while(n--){
        cin>>str;
        if(str==ac)
            a++;
        else if(str==wa)
            b++;
        else if(str==tle)
            c++;
        else
            d++;
    }
    
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;
    return 0;
}




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

vector<bool> used;
vector<vector<int>> G;

// G[e.to][e.rev]: 逆辺
void add_edge(int from, int to, int cap) {
	G[from][to] = cap;
	G[to][from] = 0;
}

// v -> t のパスをDFSで探し最大流量を求める
// mincap: 通った辺内での最小容量
int flow_dfs(int v, int t, int mincap) {
	if (v == t) return mincap;
	used[v] = true;
	for (int to=0;to<G[v].size();to++) {
		if (!used[to] and G[v][to] > 0) {
			int d = flow_dfs(to, t, min(mincap, G[v][to]));
			if (d > 0) {
				G[v][to] -= d;
				G[to][v] += d;
				return d;
			}
		}
	}
	return 0;
}

// s -> t の最大流
int max_flow(int s, int t) {
	int flow = 0;
	while(true) {
		used.assign(used.size(), false);
		int f = flow_dfs(s, t, INT_MAX);
		if (f == 0) return flow;
		flow += f;
	}
}

signed main() {
	int V, E;
	cin >> V >> E;
	G.assign(V, vector<int>(V, INT_MIN));
	used.assign(V, false);

	for(int i=0;i<E;i++) {
		int u, v, c;
		cin >> u >> v >> c;
		add_edge(u, v, c);
	}

	cout << max_flow(0, V - 1) << endl;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
typedef long double ld;
signed main(){
  int n,k;
  cin >>n>>k;
    if(n%k>abs(n%k-k)){
      cout <<abs(n%k-k);
    }else{
    cout <<n%k;
    }
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define pb push_back
const ll mod = 1e9 + 7;


int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cout<<"2018/"; char x;
    for(int i=1; i<=5; i++) cin>>x;
    cin>>x; cout<<x; cin>>x; cout<<x; cin>>x; cout<<x; cin>>x; cout<<x; cin>>x; cout<<x;
}


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

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

  int ans = 0;

  for (int i = 1; i < S.size(); i++) {
    if (S.at(i - 1) == S.at(i)) {
      if (S.at(i) == '0') S.at(i) = '1';
      else S.at(i) = '0';
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){

	int i, j, height, width;

	while(1){
		scanf("%d %d", &height, &width);

		if(height == 0 && width == 0){
			break;
		}

		for(i = 0; i < width; i++){
			printf("#");
		}

		printf("\n");

		for(i = 0; i < height - 2; i++){
			printf("#");
			for (j = 0; j < width - 2; j++){
				printf(".");
			}
			printf("#\n");
		}
		
		for(i = 0; i < width; i++){
			printf("#");
		}

		printf("\n");

		printf("\n");
	}

	return 0;

}

Measured memory_bytes: 1016
"""
解説見た
"""
from queue import Queue

q = Queue()

for i in range(1, 10):
    q.put(i)

k = int(input())

for i in range(k - 1):
    buf = q.get()
    if buf % 10 != 0:
        q.put(10 * buf + (buf % 10) - 1)
    q.put(10 * buf + buf % 10)
    if buf % 10 != 9:
        q.put(10 * buf + buf % 10 + 1)

print(q.get())


Measured memory_bytes: 12452
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <utility>
#include <queue>

using namespace std;
typedef long long signed int ll;

constexpr int inf = INT32_MAX / 2;
constexpr int mod = 1000000007;
constexpr int maxn = 100000;

class djikstra {
private:
	ll* d = nullptr;
	map<int, map<int, ll>> p;
	int sz = 0;
public:
	void add_path(int from, int to, ll cost) {
		p[from][to] = cost;
	}
	void compute(int from,int nodes) {
		sz = nodes;
		if (d != nullptr) delete d;
		d = new ll[nodes];
		auto cmp = [this](int a, int b) {return d[a] > d[b]; };
		priority_queue <ll, vector<ll>, decltype(cmp)> q(cmp);
		for (int i = 0; i < nodes; i++) d[i] = INT64_MAX / 2;
		d[from] = 0;
		q.push(from);
		while (!q.empty()) {
			for (auto& e : p[q.top()]) {
				if (d[e.first] > d[q.top()] + e.second) {
					d[e.first] = d[q.top()] + e.second;
					q.push(e.first);
				}
			}
			q.pop();
		}
	}
	ll operator[](int node) {
		if (node >= sz) return INT64_MAX/2;
		return d[node];
	}
};

ll n, m, a[100000],s[100001],res;
map<ll, vector<ll>> r;

int main() {
	cin >> n >> m;
	for (ll i = 0; i < n; i++)cin >> a[i];
	for (ll i = 1; i <= n; i++)s[i] = s[i - 1] + a[i - 1];
	for (ll i = 0; i <= n; i++) r[s[i] % m].emplace_back(i);
	for (auto& e : r) sort(e.second.begin(), e.second.end());
	for (ll i = 1; i <= n; i++) res += lower_bound(r[s[i] % m].begin(), r[s[i] % m].end(), i) - r[s[i] % m].begin();
	cout << res << endl;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    long long a,b,n;
    cin >> a >> b >> n;
    
    long long ans = (a*n/b)-a*(n/b);
    if(b-1 <= n){
        ans = max(ans,(a*(b-1)/b)-a*((b-1)/b));
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
vector<vector<int>> G;
vector<int> dep, dep2;
int u, v;
void dfs(int i, int p, int f) {
    for (auto &e : G[i]) {
        if (e == p) {
            continue;
        }
        if (f) {
            dep2[e] = dep2[i] + 1;
        } else {
            dep[e] = dep[i] + 1;
        }
        dfs(e, i, f);
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n >> u >> v;
    --u;
    --v;
    G.resize(n);
    dep.resize(n);
    dep2.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dep[v] = 0;
    dep2[u] = 0;
    dfs(v, -1, 0);
    dfs(u, -1, 1);
    int res = 0;
    for (int i = 0; i < n; i++) {
        if (dep2[i] < dep[i]) {
            chmax(res, dep[i] - 1);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 11648
import math

A,B=map(int, input().split())
Amin=int(math.ceil(A/0.08))
if A%2==0:
    Amax=int(math.floor((A+1)/0.08))
else:
    Amax=int(math.floor((A+1)/0.08)-1)
Bmin=int(math.ceil(B/0.1))
Bmax=int(math.floor((B+1)/0.1)-1)
if Amax<Bmin or Bmax<Amin:
    ans=-1
else:
    ans=max(Amin,Bmin)
print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

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

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

	int n, k;
	string s;

	cin >> n >> k >> s;

	int ans = 0;
	int l = 0, r = 0, lump = 0;
	for (; r < n; r++) {
		if (s[r] == '0') {
			if (r == 0 || s[r - 1] == '1' && s[r] == '0') {
				lump++;
			}
		}

		if (lump > k) {
			while (s[l] == '1') l++;
			while (s[l] == '0') l++;
			lump--;
		}

		ans = max(ans, r - l + 1);
	}

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


Measured memory_bytes: 512
import java.util.*;

public class Main {
	static int MAX_N = 40;
	static int MAX_a = 10;
	static int MAX_b = 10;
	static int MAX_mb = MAX_N*MAX_a;
	static int Big = 400000;
	static int[] a = new int[MAX_N];
	static int[] b = new int[MAX_N];
	static int[] c = new int[MAX_N];
	static int[][][] memo = new int[MAX_N+1][MAX_mb+1][MAX_mb+1];

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Ma = sc.nextInt();
		int Mb = sc.nextInt();
		for(int i=0; i<N; i++) {
			a[i] = sc.nextInt(); b[i] = sc.nextInt(); c[i] = sc.nextInt();
		}
		sc.close();
		for(int i=0; i<memo.length; i++) {
			for(int j=0; j<memo[i].length; j++) {
				Arrays.fill(memo[i][j], Big);
			}
		}
//		int ans = Integer.MAX_VALUE;
//		for(int i=1; i<memo[0].length; i++) {
//			for(int j=1; j<memo[0][0].length; j++) {
//				if(i*Mb == j*Ma && dp(N, i, j) != Big) {
//					ans = min(ans, dp(N, i, j));
//				}
//			}
//		}
		for(int i=0; i<memo.length; i++) {
			memo[i][0][0] = 0;
		}
		for(int i=1; i<memo.length; i++) {
			for(int ma=1; ma<memo[i].length; ma++) {
				for(int mb=1; mb<memo[i][ma].length; mb++) {
					if(ma-a[i-1]>=0 && mb-b[i-1]>=0) {
						memo[i][ma][mb] = min(memo[i-1][ma-a[i-1]][mb-b[i-1]]+c[i-1], memo[i-1][ma][mb]);
					} else {
						memo[i][ma][mb] = memo[i-1][ma][mb];
					}
				}
			}
		}
		int ans = Integer.MAX_VALUE;
		for(int i=1; i<memo[0].length; i++) {
			for(int j=1; j<memo[0][0].length; j++) {
				if(i*Mb == j*Ma && memo[N][i][j] != Big) {
					ans = min(ans, memo[N][i][j]);
				}
			}
		}
		if(ans >= Big)
			ans = -1;
		System.out.println(ans);
	}
	
	static int dp(int i, int ma, int mb) {
		if(memo[i][ma][mb]!=Big) return memo[i][ma][mb];
		if(ma==0&&mb==0) return memo[i][ma][mb] = 0;
		if(i<=0) return Big;
		if(ma-a[i-1]>=0 && mb-b[i-1]>=0) {
			return memo[i][ma][mb] = min(dp(i-1, ma-a[i-1], mb-b[i-1])+c[i-1], dp(i-1, ma, mb));
		} else {
			return memo[i][ma][mb] = dp(i-1, ma, mb);
		}
	}
	
	static int max(int...ls) {
		int ans = Integer.MIN_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.max(ans, ls[i]);
		}
		return ans;
	}
	
	static int min(int...ls) {
		int ans = Integer.MAX_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.min(ans, ls[i]);
		}
		return ans;
	}
	// end number lib
}

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

int dfs(int node, vector<vector<int>> &adj, vector<bool> &vis, vector<int> &dp){
    if (vis[node])
        return dp[node];
    vis[node] = true;
    for (auto it : adj[node])
        dp[node] = max(dp[node], 1+dfs(it, adj, vis, dp));

    return dp[node];
}

int main() {
    //freopen("input1.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m, x, y;
    cin >> n >> m;
    vector<vector<int>> adj(n);
    for(int i=0; i<m; i++){
        cin >> x >> y;
        adj[x-1].push_back(y-1);
    }
    vector<int> dp(n, 0);
    vector<bool> vis(n, false);

    int ans = 0;
    for (int i=0; i<n; i++)
        ans = max(ans, dfs(i, adj, vis, dp));

    cout << ans;

    return 0;
}

Measured memory_bytes: 11844
#include <stdio.h>

int main(int argc, const char * argv[]) {
    double x1,x2;
    double y1,y2;
    
    double x,y;
    
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    
    x=pow(x1-x2, 2.0);
    
    y=pow(y1-y2, 2.0);
    
    printf("%f",sqrt(x+y));
    return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;

bool is_integer(double A){
    if(floor(A) == A){
        return true;
    }
    else{
        return false;
    }
}
//15:14 A 15:16
//B 1WA 15
int main()
{
    int A, B;
    cin >> A >> B;
    int count = 1;
    int ans = 0;
    while (B > count)
    {
        count = count + A;
        count--;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/* #region template */
#![allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, stdout, Bytes, Read, Stdin, StdinLock, Stdout, StdoutLock, Write};
use std::iter::{repeat, repeat_with};
use std::mem::swap;
use std::str::FromStr;
#[allow(dead_code)]
struct Io<'a> {
    reader: Bytes<StdinLock<'a>>,
    writer: StdoutLock<'a>,
    in_buf: [u8; BUF_SIZE],
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn new(stdin: &'a Stdin, stdout: &'a Stdout) -> Io<'a> {
        Io {
            reader: stdin.lock().bytes(),
            writer: stdout.lock(),
            in_buf: [0; BUF_SIZE],
        }
    }
    fn r<T: FromStr>(&mut self) -> T {
        let mut count = 0;
        loop {
            match self.reader.next() {
                Some(Ok(b' ')) | Some(Ok(b'\n')) => break,
                Some(Ok(c)) => self.in_buf[count] = c,
                _ => panic!(),
            }
            count += 1;
        }

        let s = unsafe { std::str::from_utf8_unchecked(&self.in_buf[0..count]) };
        s.parse().unwrap_or_else(|_| panic!())
    }
    fn ru(&mut self) -> usize {
        self.r()
    }
    fn iter<'b, T>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter::new(self)
    }
    fn c<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        self.iter().take(n).collect()
    }
    fn cu(&mut self, n: usize) -> Vec<usize> {
        self.c(n)
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.writer, "{}", v).unwrap();
    }
    fn wn<T: std::fmt::Display>(&mut self, v: T) {
        write!(self.writer, "{}", v).unwrap();
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T> {
    io: &'b mut Io<'a>,
    m: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a: 'b, 'b, T> IoIter<'a, 'b, T> {
    fn new(io: &'b mut Io<'a>) -> IoIter<'a, 'b, T> {
        IoIter {
            io,
            m: std::marker::PhantomData,
        }
    }
}
impl<'a, 'b, T: FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let mut io = Io::new(&stdin, &stdout);
    unsafe {
        solve(&mut io);
    }
}
/* #endregion */

const BUF_SIZE: usize = 1024;

unsafe fn solve(io: &mut Io) {
    let n = io.r();

    let mut t = HashMap::<isize, isize>::new();
    let mut count = 0;
    for i in 1..=n {
        let ai: isize = io.r();
        if let Some(v) = t.get(&(i - ai)) {
            count += v;
        }

        let k = ai + i;
        if let Some(v) = t.get_mut(&k) {
            *v += 1;
        } else {
            t.insert(k, 1);
        }
    }

    io.w(count);
}


Measured memory_bytes: 8608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }

        static void SolveA(string[] args)
        {
            string s = Console.ReadLine();
            int n = 0;
            for(int i=0;i<s.Length;++i)
            {
                if( s[i] == 'o') { n++; }
            }
            int ans = 700 + n * 100;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
string s;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
	for(char c='a';c<='z';c++) {
		int dp = 0 , st = 0;
		for(int i=0;i<(int)s.size();i++) {
			dp += (s[i] == c) ? 1 : -1;
			if(dp < 0) {
				st = i + 1;
				dp = 0;
			}
			if(i - st + 1 >= 2 && dp >= 1) {
				cout << st + 1 << " " << i + 1 << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

#define N 100001
#define NIL -1

#define INNER_NODE 1
#define LEAF -1
#define ROOT 0

typedef struct {
	int parent;
	int left;
	int right;
} Node;

Node node[N];

void initNode(int n) {
	int i;

	for (i = 0; i < n; i++) {
		node[i].parent = NIL;
		node[i].left = NIL;
		node[i].right = NIL;
	}
}

void createTree(int n) {
	int nodeId, i;

	for (i = 0; i < n; i++) {
		scanf("%d", &nodeId);
		scanf("%d %d", &node[nodeId].left, &node[nodeId].right);
		if (node[nodeId].left != NIL) {
			node[node[nodeId].left].parent = nodeId;
		}
		if (node[nodeId].right != NIL) {
			node[node[nodeId].right].parent = nodeId;
		}
	}
}

int getSibling(int id) {

	if (node[id].parent != NIL) {
		if (node[node[id].parent].left == id) {
			return node[node[id].parent].right;
		} else {
			return node[node[id].parent].left;
		}
	}

	return NIL;
}

int getDegree(int id) {

	int degree = 0;

	if (node[id].left != NIL) {
		degree++;
	}
	if (node[id].right != NIL) {
		degree++;
	}

	return degree;
}

int getDepth(int d, int depth) {

	if (node[d].parent == NIL) {
		return depth;
	}

	depth++;
	getDepth(node[d].parent, depth);
}

int judgeNode(Node node) {

	if (node.parent == NIL) {
		return ROOT;
	} else if (node.left == NIL && node.right == NIL) {
		return LEAF;
	} else {
		return INNER_NODE;
	}

	return 0;
}

int getHeight(int id) {
	int leftHeight = 0;
	int rightHeight = 0;

	if (judgeNode(node[id]) == LEAF) {
		return 0;
	}

	if (node[id].left != NIL) {
		leftHeight = getHeight(node[id].left) + 1;
	}
	if (node[id].right != NIL) {
		rightHeight = getHeight(node[id].right) + 1;
	}

	if (leftHeight > rightHeight) {
		return leftHeight;
	} else {
		return rightHeight;
	}
}

void displayNode(int id) {

	printf("node %d: parent = %d, ", id, node[id].parent);
	printf("sibling = %d, ", getSibling(id));
	printf("degree = %d, ", getDegree(id));
	printf("depth = %d, ", getDepth(id, 0));
	printf("height = %d, ", getHeight(id));

	switch (judgeNode(node[id])) {
	// nodeが内部ノードの場合
	case INNER_NODE:
		puts("internal node");
		break;
	// nodeがリーフの場合
	case LEAF:
		puts("leaf");
		break;
	// nodeがルートの場合
	case ROOT:
		puts("root");
		break;
	}
}

int main() {
	int i, n;

	scanf("%d", &n);

	initNode(n);
	createTree(n);

	for (i = 0; i < n; i++) {
		displayNode(i);
	}

	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll X;
    cin >> X;
    ll a = 100;
    ll ans = 0;
    while(1){
        ans++;
        a += a / 100;
        if (a >= X) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(){
   int N, i;
   long int sum=0;
   int max=0;
   scanf("%d", &N);
   int a[N];
   for(i=0; i<N; i++) scanf("%d", &a[i]);
   for(i=0; i<N; i++){
      if(max<a[i]) max=a[i];
      else sum=sum+(max-a[i]);
   }
  printf("%ld", sum);
}

Measured memory_bytes: 2508
import java.util.*;
class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	String word = scan.next();
      	int ans = 0;
      	int subans =0;
      	for(int i=0;i<word.length();i++){
        	if(word.substring(i,i+1).equals("C") || word.substring(i,i+1).equals("G") || word.substring(i,i+1).equals("T") ||word.substring(i,i+1).equals("A")){
            	subans++;
            } else {
            	if(ans < subans){
                	ans = subans;
                }
              	subans = 0;
            }
        }
      	if(ans < subans){
                	ans = subans;
        }
      	System.out.println(ans);
    }
}

Measured memory_bytes: 21972
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x1 = sc.nextInt();
    int y1 = sc.nextInt();
    int x2 = sc.nextInt();
    int y2 = sc.nextInt();

    //x3
    System.out.println(x2-(y2-y1));
    //y3
    System.out.println(y1+(y2-y1)+(x2-x1));
    //x4
    System.out.println(x1-(y2-y1));
    //y4
    System.out.println(y1+(x2-x1));

  }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  ll N = s.size();
  ll ans = 0LL;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0 && s.at(i) == 'p') ans--;
    if(i % 2 != 0 && s.at(i) == 'g') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
        int n,k;
        cin>>n>>k;
        vector<int >has(n,0);
        for(int d,i=0;i<k;i++){
                cin>>d;
                for(int j=0,a;j<d;j++){
                        cin>>a;a--;
                        has[a]=1;
                }

        }
        cout<<n-accumulate(has.begin(),has.end(),0)<<endl;
}


Measured memory_bytes: 3584
n,k,*a=map(int,open(0).read().split())
def f(b):
    rt=[0]*-~n
    for i in range(n):
        d=b[i]
        rt[max(0,i-d)]+=1
        rt[min(n,i+d+1)]+=-1
    for i in range(n-1):
        rt[i+1]+=rt[i]
    return rt[:-1]

for i in range(k):
    a=f(a)
    if sum(a)==n**2:
        break
print(*a)


Measured memory_bytes: 219292
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}
  struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};
int main(){
 ll n;
 cin>>n;
 ll ans = 0;

 for(ll i=1; i<n;i++){
   ans+=(n-1)/i;
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
using namespace std;
typedef long long ll; typedef long double ld;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<10> fact;
constexpr Prime<10> prime;
constexpr int comb(int a, int b){long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b];return pos * pot % MOD * por % MOD;}
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr int sqrtN = 512, logN = 32;
constexpr ld PI = abs(acos(-1));
constexpr ll LINF=1e18;

int main(){
	int n, m; cin >> n >> m;
	vector<int> g[25];
	int h[25] = {};
	for(int i = 0; i < m; i++){
		int a, b; cin >> a >> b;
		g[a - 1].push_back(b - 1);
		h[b - 1]++;
	}
	
	queue<int> qu;
	vector<int> vec;
	for(int i = 0; i < n; i++) if(!h[i]) qu.push(i);
	while(!qu.empty()){
		auto p = qu.front(); qu.pop();
		
		vec.push_back(p);
		for(auto e:g[p]){
			h[e]--;
			if(!h[e]) qu.push(e);
		}
	}
	
	for(auto s:vec) cout << s + 1 << endl;
	return 0;
}



Measured memory_bytes: 3180
#include <iostream>
#include <string>

using namespace std;

int n;
string s;

int main() {
        cin >> s;
        n = s.size();

        if (s[0] != '1' || s[n-1] != '0') {
                cout << "-1\n";
                return 0;
        }

        for (int i=0; i<n-1; i++) {
                if (s[i] != s[n-2-i]) {
                        cout << "-1\n";
                        return 0;
                }
        }

        int last_node=1;
        for (int i=1; i<n; i++) {
                if (s[i] == '1') {
                        for (int j=last_node; j<i+1; j++) {
                                cout << j << " " << i+1 << endl;
                        }
                        last_node = i+1;
                }
        }

        for (int j=last_node; j<n; j++) {
                cout << j << " " << n << endl;
        }
}

Measured memory_bytes: 1664
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    s = gets.chomp.chars
    t = gets.chomp.chars

    ans = 0
    ans += 1 if s[0] == t[0]
    ans += 1 if s[1] == t[1]
    ans += 1 if s[2] == t[2]


    puts ans
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2044
n = int(input())
for i in range(n):
  xa, ya, ra, xb, yb, rb = map(float, input().split())
  d = ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5
  if rb < ra and d < ra - rb:
    print("2")
  elif ra < rb and d < rb - ra:
    print("-2")
  elif d <= ra + rb:
    print("1")
  else:
    print("0")


Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
#define INF 2147483647
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
void self_min(int &a,int b){
	a = min(a,b);
}

int main(){
	string s; cin >> s;
	int n = s.size();
	int l,r;
	if(n&1){
		l = n/2-1;
		r = n/2+1;
	}else{
		l = n/2 -1;
		r = n/2;
	}
	int count = 0;
	while(l>=0 && r <n){
		if(s[l] != s[r]) count++;
		--l;
		++r;
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<stdlib.h>
 
int main() {
  
  long int H,W;
  
  scanf("%ld %ld\n",&H,&W);
  
  long int S=H*W;
  
  if(H==1||W==1){
    printf("1\n");
  } else if(H%2==1&&W%2==1){
  	printf("%ld\n",(1+S)/2);
  }else{printf("%ld\n",S/2);}
    
  return 0;
  
}

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

using namespace std;

int main() {
    int N, X;
    cin >> N >> X;

    int sum_meter = 0;
    int bounce_cnt = 1;
    for(int i = 0; i < N; i++) {
        int bounce;
        cin >> bounce;
        sum_meter += bounce;
        if(sum_meter <= X) {
            bounce_cnt++;
        } else {
            break;
        }
    }
    cout << bounce_cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double 
int32_t main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n,s=0; cin>>n;
		for(int i=0;i<=n;++i){
			if(!(i%3==0 || i%5==0))
				s+=i;
		}
		cout<<s;
	return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#define N 36

typedef struct{
  int Num;
  char Role;
}Tramp;


int main(){
  Tramp tr[N],mp[N],temp;
  int loop;
  int i,j,min,count=0;
  int flag=1;
  
  scanf("%d",&loop);
  for(i=0;i<loop;i++){
    scanf(" %c%d",&tr[i].Role,&tr[i].Num);
    mp[i]=tr[i];
  }
  
  while(1){
    if(flag==0)break;
    flag=0;
    for(j=loop-1;j>0;j--){
      if(tr[j].Num<tr[j-1].Num){
	temp=tr[j];
	tr[j]=tr[j-1];
	tr[j-1]=temp;
	flag=1;
      }
    }
  }

  for(i=0;i<loop-1;i++){
    min=i;
    for(j=i;j<loop;j++){
      if(mp[j].Num<mp[min].Num){
	min=j;
      }
    }
    temp=mp[i];
    mp[i]=mp[min];
    mp[min]=temp;
  }

  for(i=0;i<loop-1;i++){
    printf("%c%d ",tr[i].Role,tr[i].Num);
  }
  
  printf("%c%d\n",tr[loop-1].Role,tr[loop-1].Num);
  printf("Stable\n");
  
  for(i=0;i<loop-1;i++){
    printf("%c%d ",mp[i].Role,mp[i].Num);
  }
  
  printf("%c%d\n",mp[loop-1].Role,mp[loop-1].Num);

  flag=0;
  while(count<loop){
    if(tr[count].Role!=mp[count].Role){
      flag=1;
      count++;
    }
    count++;
  }

  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");

  return 0;
}




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

using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
constexpr int NMAX = 3010;

ll bilang[NMAX][NMAX];

ll FMOD(ll x) { return (x % MOD + MOD) % MOD; }

int main() {
	int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d);
	for (int i = a; i <= c; ++i) {
		for (int j = b; j <= d; ++j) {
			if (i == a && j == b) bilang[i][j] = 1;
			else if (i == a) bilang[i][j] = (a * bilang[i][j-1]) % MOD;
			else if (j == b) bilang[i][j] = (b * bilang[i-1][j]) % MOD;
			else {
				bilang[i][j] = (j * bilang[i-1][j] % MOD + i * bilang[i][j-1] % MOD
						+ FMOD(- (i - 1) * (j - 1) * bilang[i-1][j-1])) % MOD;
			}
		}
	}
	printf("%lld\n", bilang[c][d]);
	return 0;
}



Measured memory_bytes: 74308
#include <bits/stdc++.h> 
using namespace std;
#define     mod             1e9+7
#define     ll              long long
#define     mp              make_pair
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     ii              pair<int,int>
#define     vi              vector<int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int>>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            '\n'

/*
	For Debugging we have define TRACE.
*/

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif  

const int N = 2e5 + 5;
int a[N];

void solve(){
	string s,t;
	cin>>s>>t;
	int cnt = 0;
	for(int i=0;i<s.size();i++){
		if(s[i] != t[i]) cnt++;
	}
	cout<<cnt;
}
 
int32_t main()
 
{  
    #ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif

    IOS;

    solve();


}

Measured memory_bytes: 3816
import sys
S=input()
T=input()
N=len(S)
a=ord('a')
R=[-1]*26
Q=[-1]*26
for i in range(N):
    s=ord(S[i])-a
    t=ord(T[i])-a
    if R[s]!=-1:
        if Q[t]!=R[s]:
            print('No')
            sys.exit()
    if Q[t]!=-1:
        if R[s]!=Q[t]:
            print('No')
            sys.exit()  
    if R[s]==-1:
        R[s]=i
    if Q[t]==-1:
        Q[t]=i
print('Yes')

Measured memory_bytes: 41968
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll k, n, m = 0;
    cin >> k >> n;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e;
    sort(a.begin(), a.end());
    a.push_back(k + a[0]);
    for (ll i = 0; i < n; i++)
        m = max(m, (a[i + 1] - a[i]));
    cout << k - m;
    return 0;
}

Measured memory_bytes: 4864
N=int(input())
A=list(map(int,input().split()))
X=1000
kabu=0
t=0
_a=A[0]
for a in A:
  if t==0:
    if _a>=a:
      pass
    else:
      kabu=X//_a
      X-=_a*kabu
      t=1
  else:
    if _a<=a:
      pass
    else:
      X+=_a*kabu
      kabu=0
      t=0
  _a=a
if kabu>0:
  X+=A[-1]*kabu
print(X)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
#define ll long long int     
int main(){
    ll n,y;
    cin>>n>>y;
    ll a[3]={10000,5000,1000};
    ll ans[3]={0};
    int f=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            int k=n-i-j;
            if((i*a[0]+j*a[1]+k*a[2]==y) && f!=1 && (i+j+k==n) && (k>=0)){
                ans[0]=i;
                ans[1]=j;
                ans[2]=k;
                //cout<<i<<" "<<j<<" "<<k;
                f=1;
            }
        }
    }
    if(f==1)cout<<ans[0]<<" "<<ans[1]<<" "<<ans[2];
    else cout<<-1<<" "<<-1<<" "<<-1;
}

Measured memory_bytes: 256
# Aizu Problem 0281: Formation

import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")



N = int(input())
for __ in range(N):
    c, a, n = [int(_) for _ in input().split()]
    ans = 0
    while min(a, c, n) > 0:
        ans += 1
        c -= 1
        a -= 1
        n -= 1
    while c > 1 and a > 0:
        ans += 1
        c -= 2
        a -= 1
    ans += c // 3
    print(ans)

Measured memory_bytes: 7840
#include<bits/stdc++.h>
using namespace std;
int sube[500],kasu[500],a,h;
int cut(int k){
    fill(kasu,kasu+500,0);
    for(int i=1;i<2*a-k+1 ;i++){
        kasu[i]=sube[k+i];
    }
    for(int i=1;i<k+1  ;i++){
        kasu[2*a-k+i]=sube[i];
    }
    for(int i=1;i<a*2+1;i++){
        sube[i]=kasu[i];
    }
}
int rif(){
    fill(kasu,kasu+500,0);
    for(int i=1,t=1,h=1;t<a+1;t++){

        kasu[i]=sube[h];i++;
        kasu[i]=sube[a+h];i++;h++;

    }
    for(int i=1;i<2*a+1;i++){
        sube[i]=kasu[i];
    }

}
int main(){
    int b=0,c;
    cin>>a;
    cin>>b;
    for(int i=1;i<a*2+1;i++){
        sube[i]=i;
    }
    for(int i=0;i<b;i++){
        cin>>c;
        if(c==0){rif();}else
        if(c!=0){cut(c);}
    }

    for(int i=1;i<2*a+1;i++){
        cout<<sube[i]<<endl;
    }

}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables **************/
int n, x;
vector<int> m;
/**********************************************/

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

    cin >> n >> x;
    m.resize(n);
    REP(i, n) cin >> m[i];

    REP(i, n) x -= m[i];
    sort(all(m));
    int ans = n;
    ans += x / m[0];
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')

//------------------------------------------------------------------------------
const int UF_SIZE = 100010;

int par[UF_SIZE];
int rnk[UF_SIZE];
int siz[UF_SIZE];

void union_find_init(int n) {
  REP(i, n) {
    par[i] = i;
    rnk[i] = 0;
    siz[i] = 1;
  }
}

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

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rnk[x] < rnk[y]) {
    par[x] = y;
    siz[y] += siz[x];
  } else {
    par[y] = x;
    siz[x] += siz[y];
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}

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

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

//------------------------------------------------------------------------------
const int N_MAX = 100000;
const int M_MAX = 100000;

int N, M;
int p[N_MAX];
int x[M_MAX];
int y[M_MAX];

void solve() {
  union_find_init(N);
  REP(i, M) unite(x[i], y[i]);
  int ans = 0;
  REP(i, N) {
    // if (size(i) == 1) {
    //   if (p[i] == i) ans++;
    // } else {
      if (find(i) == find(p[i])) ans++;
    // }
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, N) {
    scanf("%d", p + i);
    --p[i];
  }
  REP(i, M) {
    scanf("%d%d", x + i, y + i);
    --x[i];
    --y[i];
  }
}

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


Measured memory_bytes: 2560