akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;

const int maxn = 2005;

int dp[2][maxn][maxn];
int suf[2][maxn][maxn];
int n, z, w;
int a[maxn];

int main(){
    cin >> n >> z >> w;
    for(int i = 1;i <= n;i++){
        scanf("%d", &a[i]);
    } 
    a[0] = w;
    for(int j = n;j >= 1;j--){
        for(int i = j - 1;i >= 0;i--){
            for(int k = 0;k < 2;k++){
                if(j == n){
                    dp[k][i][j] = abs(a[i] - a[j]);
                    suf[k][i][j] = dp[k][i][j];
                }else{
                    dp[k][i][j] = suf[k ^ 1][j][j + 1];
                    if(k == 0){
                        suf[k][i][j] = max(suf[k][i][j + 1], dp[k][i][j]);
                    }else{
                        suf[k][i][j] = min(suf[k][i][j + 1], dp[k][i][j]);
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i = 1;i <= n;i++){
        ans = max(ans, dp[0][0][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 62464
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec() -> Vec<i32> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect()
}

fn main() {
    let N: usize = read_line().parse().unwrap();
    let H = read_vec();
    let mut ans = 0;
    let mut temp = 0;
    for i in 0..N-1 {
        if H[i] >= H[i+1] {
            temp += 1;
        } else {
            ans = std::cmp::max(ans, temp);
            temp = 0;
        }
    }
    ans = std::cmp::max(ans, temp);
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors  //GO FOR EVEN FOR 4 moves

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc;
    LL time;
    cin >> n >> t;
    time = t;
    LL dp[3001] = {0};
    vector<int> a(n), b(n);
    vector<pair<int, int>> data(n);
    for (i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
        data[i] = {a[i], b[i]};
    }
    sort(all(data));

    LL maxima = 0;
    bool visited[3001] = {false};
    visited[0] = true;
    for (i = 0; i < n; i++)
    {
        a[i] = data[i].second;
        b[i] = data[i].first;
        swap(a[i], b[i]);
       // debug(a[i]);
        //debug(b[i]);
        for (j = time - 1; j >= 0; j--)
        {
            LL now = j;
            if (visited[now])
            {
                //debug(now);
                LL final = now + a[i];
                //debug(final);
                //debug(dp[now]);

                if (final < time)
                {
                    dp[final] = max(dp[final], dp[now] + b[i]);
                    visited[final] = true;
                }
                else
                {

                    LL proposed = dp[now] + b[i];
                   // debug(proposed);
                    maxima = max(maxima, dp[now] + b[i]);
                }
            }
        }
        //part;
    }

    LL ans = 0;
    ans = maxima;
    for (i = 0; i < time; i++)
    {
        // debug(i);
        // debug(dp[i]);
        //part;
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
ll n, s;

ll f(ll p, ll q) {
	ll sum = 0;
	for (; p; p /= q) sum += p % q;
	return sum;
}

int main()
{
	ll i;
	cin >> n >> s;
	for (i = 2; i * i <= n; i++)
		if (f(n, i) == s) {cout << i; return 0;}
	for (i = sqrt(n - s); i > 0; i--)
		if ((n - s) % i == 0 && f(n, (n - s) / i + 1) == s) {cout << (n - s) / i + 1; return 0;}
	if (n == s) cout << n + 1;
	else cout << "-1";
    return 0;
}

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

int main() {
	int N, M, K;
	cin>>N>>M>>K;
	int A[M], B[M], C[K], D[K];
	for(int i=0;i<M;++i){
		cin>>A[i]>>B[i];
		A[i]--;
		B[i]--;
	}
	for(int i=0;i<K;++i){
		cin>>C[i]>>D[i];
		C[i]--;
		D[i]--;
	}
	vector<vector<int> >friends;
	stack<int> statestack;
	map<int, int> man;
	int state;
	vector<int>tmpfriends;

	map<int, vector<int> >friendsmap;
	for(int i=0;i<N;++i){
		friendsmap[i]=tmpfriends;
	}

	for(int i=0;i<M;++i){
		friendsmap[A[i]].push_back(B[i]);
		friendsmap[B[i]].push_back(A[i]);
	}

	/**
	for(int i=0;i<N;++i){
		for(int j=0;j<friendsmap[i].size();++j){
			cout<<friendsmap[i][j]<<" ";
		}
		cout<<endl;
	}
	**/

	for(int i=0;i<N;++i){
		if(man[i]==0){
			tmpfriends.push_back(i);
			man[i]++;
			statestack.push(i);
			while(!statestack.empty()){
				state = statestack.top();
				statestack.pop();
				for(int j=0;j<friendsmap[state].size();++j){
					if(man[friendsmap[state][j]]==0){
						tmpfriends.push_back(friendsmap[state][j]);
						statestack.push(friendsmap[state][j]);
						man[friendsmap[state][j]]++;
					}
				}
			}
			friends.push_back(tmpfriends);
			tmpfriends.clear();
		}
	}
	map<int, int> group;
	for(int i=0;i<friends.size();++i){
		for(int j=0;j<friends[i].size();++j){
			group[friends[i][j]] = i;
		}
	}
	map<int, int> blockmap;
	for(int i=0;i<K;++i){
		if(group[C[i]] == group[D[i]]) {
			blockmap[C[i]]++;
			blockmap[D[i]]++;
		}
	}
	for(int i=0;i<N;++i){
		cout<<friends[group[i]].size() - blockmap[i] - friendsmap[i].size() - 1<<" ";
	}
	cout<<endl;
	/**
	for(int i=0;i<friends.size();++i){
		for(int j=0;j<friends[i].size();++j){
			cout<<friends[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	**/
}


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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N =RD;
	auto W = RDR.ARR;
	auto a = new long[](N+1);
	foreach (i; 0..N)
	{
		a[i+1] = a[i] + W[i];
	}

	long ans = long.max;
	foreach (i; 0..N)
	{
		ans = min(ans, abs(a[N] - a[i] - a[i]));
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,double> P;
int main(){
  int n,m,p,a,b;
  while(cin>>n>>m>>p>>a>>b,n){
    a--,b--;

    double t[8],tp;
    vector<P> e[31];

    for(int i=0;i<n;i++)cin>>t[i];
    for(int j=0,x,y;j<p;j++){
      cin>>x>>y>>tp;
      x--,y--;
      e[x].push_back(P(y,tp)),e[y].push_back(P(x,tp));
    }

    double dp[1<<8][30];
    for(int i=0;i<1<<n;i++)
	for(int j=0;j<m;j++)dp[i][j]=1e4;
    dp[0][a]=0;

    for(int j=0;j<1<<n;j++)
      for(int k=0;k<m;k++)
	for(int l=0;l<n;l++)
	  if(!(j&1<<l))
	    for(int w=0;w<e[k].size();w++)
	      dp[j+(1<<l)][e[k][w].first]
		=min(dp[j+(1<<l)][e[k][w].first],dp[j][k]+e[k][w].second/t[l]);
    
    double ans=1e4;
    for(int i=0;i<1<<n;i++)ans=min(ans,dp[i][b]);
    if(ans==1e4)cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3284
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N, X;
	cin >> N >> X;
	vector<int>x(N);
	rep(i, N)cin >> x[i];
	sort(x.begin(), x.end());
	int ans = abs(X - x[0]);
	rep(i, N - 1) {
		ans = gcd(ans, abs(X - x[i + 1]));
	}
	cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 1; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)


int main()
{
    ll x;
    cin >> x;
    queue<ll> memo;
  ll karioki =sqrt(x);
    rep(i,karioki+1)
    {
        if (x % i == 0)
        {
            memo.push(i);
        }
    }
    bool flag = false;
    while (memo.size() > 0)
    {
        ll a = memo.front();
        memo.pop();
        ll m1 = x / a;
      ll m2=sqrt(m1); 
        rep(i, m2+1)
        {
            if (x == i * i * i * i * i - (i - a) * (i - a) * (i - a) * (i - a) * (i - a))
            {
                cout << i << " "<<i - a << endl;
                break;
                flag = false;
            }
            if (flag)
            {
                break;
            }
        }
    }
}

Measured memory_bytes: 3684
X = int(input())

import math

def isPrime(n):
	if n == 2:
		return True
	if n % 2 == 0:
		return False

	# nの平方根まで計算する
	m = math.floor(math.sqrt(n)) + 1
	for p in range(3, m, 2):
			if n % p == 0:
				return False
	return True

ans = X
while not (isPrime(ans)):
	ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a , b ;
    cin>>a>>b;
    if (a==b)
    {
        cout<<"Draw"<<endl;
    }
    else if (a==1)
    {
        cout<<"Alice"<<endl;
    }
    else if (b==1)
    {
        cout<<"Bob"<<endl;
    }
    else if (a>b)
    {
        cout<<"Alice"<<endl;
    }
    else if (a<b)
    {
        cout<<"Bob"<<endl;
    }
}


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

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	using vi = std::vector<int>;
	// restはM通り、quotientは10'000/M+1通り
	vi x_sum(M);
	std::vector<vi> X(M, vi(100'000 / M + 1));
	for (int i{}; i < N; i++)
	{
		int tmp;
		scanf("%d", &tmp);
		X[tmp % M][tmp / M]++;
		x_sum[tmp % M]++;
	}
	int ans{};
	ans = x_sum[0] / 2;
	if (~M & 1) ans += x_sum[M / 2] / 2;
	for (int i{1}; i < M - i; i++)
	{
		int less_i{i}, larger_i{M - i};
		if (x_sum[larger_i] < x_sum[less_i]) std::swap(less_i, larger_i);
		ans += x_sum[less_i];

		int count{};
		for (auto& e: X[larger_i]) count += e / 2 * 2;
		ans += std::min(count, x_sum[larger_i] - x_sum[less_i]) / 2;
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 6144
s=list(input())
t=list(input())

lens=len(s)
lent=len(t)

dp=[[0]*(lent+1) for _ in range(lens+1)]

for i in range(lens):
    for j in range(lent):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j]+1
        else:
            dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])

ans=''
i,j=lens,lent

while i>=0 and j>=0:
    if dp[i-1][j]==dp[i][j]:i-=1
    elif dp[i][j-1]==dp[i][j]:j-=1
    else:
        ans=s[i-1]+ans
        i,j=i-1,j-1
print(ans)

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

int main() {
  int N, K, count=0;
  
  cin >> N >> K;
  
  for(;N>0;){
    N/=K;
    count +=1;
  }
  
  cout << count;
}
      

Measured memory_bytes: 3632
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
	
#define int long long
#define double long double 
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
// Use for file I/O;
#define FIN string _fname = "paintbarn"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

using namespace std;

const int INF = 4e18 + 10;
const int INF2 = 2e18 + 10;
const int INF3 = 2e10;
const int MAXN = 305;
const int LOGN = 19;
const int MOD = 1e9 + 7;
const int EPS = 1e-9;
const int MULT = 2e5;
const int MCNST = MOD * MOD * 8;

int32_t main() {
	FAST;

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.rbegin(), a.rend());
	int ans = a[0];
	int lb = 1, ub = ans;
	while (lb <= ub) {
		int m = (lb + ub) / 2;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			cnt += (a[i] + m - 1) / m - 1;
		}
		//cout << m << ' ' << cnt << endl;

		if (cnt <= k) {
			ans = m;
			ub = m - 1;
		} else {
			lb = m + 1;
		}
	}
	cout << ans;
}

Measured memory_bytes: 4776
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>T(N);
  int sum=0;
  for (int i=0;i<N;++i){
    cin>>T[i];
    sum+=T[i];
  }
  int M;
  cin>>M;
  vector<int>P(M);
  vector<int>X(M);
  for (int i=0;i<M;++i){
    cin>>P[i];
    cin>>X[i];
  }
  int ans=0;  
  for (int i=0;i<M;++i){
    ans=sum-T[P[i]-1]+X[i];
    cout<<ans<<endl;
  }
}

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

using namespace std;

int n, a[200002];
long long sum[200002], sol;

void f (int i, int j, int k) {
  long long a = sum[i];
  long long b = sum[j] - sum[i];
  long long c = sum[k] - sum[j];
  long long d = sum[n] - sum[k];
  long long nr = max(max(a, b), max(c, d)) - min(min(a, b), min(c, d));
  sol = min(sol, nr);
}

int main()
{
  sol = LLONG_MAX;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = 1; i < n; i++) {
    int j = upper_bound(sum + 1, sum + i + 1, sum[i] / 2) - sum;
    int k = upper_bound(sum + i + 1, sum + n + 1, (sum[n] - sum[i]) / 2 + sum[i]) -sum;
    f(j, i, k);
    f(j - 1, i, k);
    f(j, i, k - 1);
    f(j - 1, i, k - 1);
  }
  cout << sol;
  return 0;
}


Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	private static int counter = 0;
	private static int upperOrder = 0;
	private static int lowerOrder = 0;
	
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int[] nums = new int[n];
		int base = 0;
		
		for (int i = 0; i < n; i++) {
			int m = sc.nextInt();
			nums[i] = m;
			base ^= m;
		}
		
		Set<Integer> set = new HashSet<>();
		
		for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				System.out.print(base^nums[i]);
				System.out.println();
			} else {
				System.out.print((base^nums[i]) + " ");
			}
		}
		
		
		System.exit(0);
	}
	
	public static void permuteHelper(int[] nums, int start, int end, List<String> ans) {
        if (start == end) {
            String str = "";
            for (int num: nums) {
                str += ("" + num);
            }
            ans.add(str);
        } else {
            for (int i = start; i < end; i++) {
                swap(nums, i, start);
                permuteHelper(nums, start + 1, end, ans);
                swap(nums, i, start);
            }
        }
    }
	
	static public void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
	
	static boolean isEqual(int[] a, int[] b) {
		for (int i = 0; i < a.length; i++) {
			if (a[i] != b[i]) {
				return false;
			}
		}
		return true;
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 60444
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, M, A;
	while (cin >> N >> M >> A) {
		if (N == 0 && M == 0 && A == 0) return 0;
		vector<pair<int, pair<int, int> > > V(M);
		for (int i = 0; i < M; i++) cin >> V[i].first >> V[i].second.first >> V[i].second.second;
		sort(V.begin(), V.end(), greater<pair<int, pair<int, int> > >());
		for (int i = 0; i < M; i++) {
			if (V[i].second.first == A) A = V[i].second.second;
			else if (V[i].second.second == A) A = V[i].second.first;
		}
		cout << A << endl;
	}
}


Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846

int main(){
	int n;
	cin>>n;
	int x,y;
	x=800*n;
	y=(n/15)*200;
	cout<<x-y<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n,d,x; cin >> n >> d >> x;

    vector<int> a(n); rep(i,n) cin >> a[i];

    rep(i,n){
        for(int j = 1; j <= d; j+=a[i]){
            x ++;
        }
    }

    cout << x << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    
    cin >> a >> b;
    if (a > b)
      cout << "a > b" << endl;
    else if (a < b)
      cout << "a < b" << endl;
    else if (a=b)
      cout << "a == b" << endl;
   
    return 0;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b > c+d){
    cout << "Left" << endl;
  }
  else if(a+b < c+d){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}

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

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

  if (n * a < b) {
    cout << n * a << endl;
  }else if (n * a > b) {
    cout << b << endl;
  }else if (n * a == b) {
    cout << b << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int A, B;
  while(cin >> A >> B, A||B){
    int D = B - A;
    int ans[] = {0,0,0};
    ans[2] = D/1000;
    D %= 1000;
    ans[1] = D/500;
    D %= 500;
    ans[0] = D/100;
    cout << ans[0];
    for(int i = 1; i < 3; ++i) cout << " " << ans[i];
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/



int main()
{
	cin >> n;
	vi v(n);
	REP(i, n) cin >> v[i];
	ll i = 0;
	while (1) {
		cnt++;
		if (v[i] == 0) {
			cout << -1 << endl;
			return 0;
		}
		ll a = v[i];
		v[i] = 0;
		if (a == 2) {
			break;
		}
		i = a - 1;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	int sum=0;
	while(n--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		sum+=b-a+1;
	}
	printf("%d\n",sum);
	return 0;
 } 

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

namespace Volume0 {
	class Program {
		public static void Main() {
			String input;
			while ((input = Console.ReadLine()) != null) {
				Console.WriteLine(Decode(input));
			}
		}

		static String Decode(String str) {
			String[] decoded =  ToChunk(str).Select(RunLength).ToArray();
			String result = String.Empty;
			foreach (String d in decoded) result += d;
			return result;
		}

		static String[] ToChunk(String str) {
			IList<String> chunk = new List<String>();
			int index;
			while((index = str.IndexOf('@')) != -1) {
				if(index == 0) {
					chunk.Add(str.Substring(0, 3));
					str = str.Substring(3, str.Length - 3);
				} else {
					chunk.Add(str.Substring(0, index));
					str = str.Substring(index, str.Length - index);
				}
			}
			chunk.Add(str);

			return chunk.ToArray();
		}

		static String RunLength(String chunk) {
			int num = 0;
			if(chunk.Length > 2 && chunk[0] == '@' && int.TryParse(chunk[1].ToString(), out num)) {
				return String.Empty.PadLeft(num, chunk[2]);
			}else return chunk;
		}
	}
}



Measured memory_bytes: 9428
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値取得
		int N = scan.nextInt();
		int[] a = new int[N];

		//WK変数
		int result = 0;

		//演算
		for (int x = 1; x * x < N; x++) {
			for (int y = 1; y * y < N - x * x; y++) {
				for (int z = 1; z * z < N - x * x - y * y; z++) {
					if (x * x + y * y + z * z + x * y + y * z + z * x - 1 < N) {
						a[x * x + y * y + z * z + x * y + y * z + z * x - 1] += 1;
					}
				}
			}
		}

		//結果出力
		for (int i = 0; i < N; i++) {
			System.out.println(a[i]);
		}
	}
}

Measured memory_bytes: 38952
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;

class StrTrans{
public:
  int getNOps(string s, string t){
    int nOps = 0;
    int cnt = 0;
    int len = s.length();
    for(int i=0;i<len;i++){
      if(s[i]!=t[i]){
	cnt++;
      }
    }
    return cnt;

  }
};

int main(int argc, const char*argv[]){
  StrTrans st;
  string s,t;
  getline(cin,s);
  getline(cin,t);
  int nOps = st.getNOps(s,t);
  cout<<nOps<<endl;
  return 0;
}


Measured memory_bytes: 4056
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    ans = 0
    pair = [False for i in range(N)]

    for i in range(N):
        if (A[A[i] - 1] - 1 == i) and (pair[A[i] - 1] == False):
            ans += 1
            pair[i] = True
            pair[A[i] - 1] = True

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 20532
#include <stdio.h>
int main(void){
    // Your code here!
    int K,S;
    int x,y,z;
    int cnt = 0;
    int sum;
    
    scanf("%d%d",&K,&S);
    
    for(x = 0;x<=K;x++){
        sum = S - x;
        for(y=0;y<=K;y++){
            z = sum - y;
            if(z <= K && z >= 0){
                cnt++;
            }
        }
    }
    
    printf("%d\n",cnt);
}


Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
#define IO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define m(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
	IO;
	int n,d,x,a[103],ans;
	while(cin>>n>>d>>x){
		ans=0;
		rep(i,n) cin>>a[i];
		rep(i,n){
			int s=1,cnt=1;
			while(s*a[i]+1<=d){
				s++;
				cnt++;
			}
			ans+=cnt;
		}
		cout<<ans+x<<endl;
	}
	return 0;
}

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

int main(){
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    vector<ll> p2, q2;
    rep(i, x) p2.push_back(p[i]);
    rep(i, y) q2.push_back(q[i]);
    p2.insert(p2.end(), q2.begin(), q2.end());

    sort(p2.begin(), p2.end());

    ll ans = 0;
    rep(i, x+y) ans += p2[i];

    queue<ll> que;
    rep(i, c) que.push(r[i]);

    rep(i, x + y){
        if (!que.empty() && que.front() > p2[i]){
            ans -= p2[i];
            ans += que.front();
            que.pop();
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5556
s = int(input())
num_set = set([s])

def f(x):
    if x % 2 == 0:
        return x // 2
    else:
        return 3 * x + 1

i = 1
while 1:
    i += 1
    s = f(s)
    if s in num_set:
        print(i)
        break
    num_set.add(s)
    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
const int mod=1e9+7;
typedef pair<int,int> P;
typedef tuple<int,int,int> TP;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> 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};
    int k;cin>>k;
    cout<<a[k-1]<<endl;
    return 0;
}


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

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

  string ans = "YES";
  int i = s.size();
  string dream, erase, dreamer, eraser;
  while (i > 0) {
    dream = s.substr(i - 5, 5);
    erase = s.substr(i - 5, 5);
    if (i >= 7) dreamer = s.substr(i - 7, 7);
    if (i >= 6) eraser  = s.substr(i - 6, 6);
    if (dream == "dream" || erase == "erase") i -= 5;
    else if (dreamer == "dreamer") i -= 7;
    else if (eraser == "eraser") i -= 6;
    else {
      ans = "NO";
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(a)

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1) * (-tmp_min // 2))

print(-sum(a))


Measured memory_bytes: 14252
<?php
  	$list = explode(' ', trim(fgets(STDIN)));
  	$n = $list[0];
  	$m = $list[1];
	for ($i = 0; $i < $n; $i++) {
      $favorite[$i] = explode(' ', trim(fgets(STDIN)));
      unset($favorite[$i][0]);
    }
	$correct = $favorite[0];
	for ($i = 0; $i < $n; $i++) {
      $correct = array_intersect($correct, $favorite[$i]);
    }

	echo count($correct);

Measured memory_bytes: 4728
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")


signed main(){
	cout<<fixed<<setprecision(7);
	int n, m;
	string s, t;
	cin>>s;
	
	if(s.size() == 2)cout<<s<<endl;
	else cout<<s[2]<<s[1]<<s[0]<<endl;
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll n, k;
    cin >> n >> k;
    vec h(n);
    loop(i, n) cin >> h[i];
    vec dp(n, 1e18);
    dp[0] = 0;
    loop(i, n)
    {
        Loop(j, 1, k + 1)
        {
            if ((i + j) >= n)
                break;
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    putout(dp[n - 1]);
    return 0;
}


Measured memory_bytes: 1792
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin >> s;
    s += "$";
    int pos = 0;
    ll ans = 0;
    while(s[pos] != '$'){
        ll a = 0, b = 0;
        while(s[pos] == '<'){
            a++;
            pos++;
        }
        while(s[pos] == '>'){
            b++;
            pos++;
        }
        ll mn = min(a, b);
        ll mx = max(a, b);
        ans += (mx * (mx + 1) / 2);
        ans += (mn * (mn - 1) / 2);
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<ll, ll> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};

signed main()
{
    ll n;
    cin >> n;
    multiset<ll> v;
    multiset<ll> now;

    rep(i, 1 << n)
    {
        ll x;
        cin >> x;
        v.insert(x);
    }

    now.insert(*(--v.end()));
    v.erase((--v.end()));

    while (n--)
    {
        multiset<ll> p = now;

        //cout<<"DE"<<endl;
        for (auto i = --p.end();;i--)
        {
            auto itr = v.lb(*i);
            //cout<<"D"<<*itr<<endl;
            if (itr == v.begin())
            {
                puts("No");
                return 0;
            }

            ll x = *(--itr);
            v.erase(itr);
            now.insert(x);

            if(i==p.begin()){
                break;
            }
        }
    }

    puts("Yes");
}


Measured memory_bytes: 18688
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n, x = 0;
    cin >> n;
    vector<int> a(n, 0), b(31, 0);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) x ^= a[i];
    
    for(int i=0;i<n;i++){
        for(int j=0;j<=30;j++){
            if(((a[i]>>j)&1) == 1){
                b[j]++;
                break;
            }
        }
    }
    
    int ans = 0;
    for(int i=30;i>=0;i--){
        if(((x>>i)&1) == 1){
            if(b[i] <= 0){
                ans = -1;
                break;
            }
            x ^= (1<<i)-1;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin);freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX 1005
#define v_n 5005
#define LL long long
#define e_n 5000005
#define MOD 1000000007
#define eps 0.000000001
#define Blen 32
using namespace std;
int main(void)
{
	int i, j, k;
	FAST_IO;
	//Relocate;
	int a, p;
	cin >> a >> p;
	a = a * 3 + p;
	cout << a / 2 << endl;
	return 0;
}

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

string calc(string s1, string s2){
  string res;
  int n = max(s1.size(), s2.size());
  while(s1.size() < n) s1 = '0' + s1;
  while(s2.size() < n) s2 = '0' + s2;
  //   cout << "s1 = " << s1 << endl;
  //cout << "s2 = " << s2 << endl;
  int c = 0;
  for(int i = n-1 ; i >= 0 ; i--){
    char ch = ((s1[i]-'0')+(s2[i]-'0')+c)%10 + '0';
    c = ((s1[i]-'0')+(s2[i]-'0')+c)/10;
    res += ch;
  }
  if(c) res += c+'0';
  reverse(res.begin(), res.end());
  while(res.size() > 1 && res[0] == '0') res.erase(res.begin());
  //cout << res << endl;
  return res;
}

string convert(string s, char n){
  for(int i = 0 ; i < s.size() ; i++){
    if(s[i] == 'X') s[i] = n;
  }
  return s;
}

int main(){    
  string op;
  while(cin >> op){  
    bool flag = false;
    for(char ii = '0' ; ii <= '9' ; ii++){
      string left1, left2, right;
      int index1, index2;
      index1 = op.find("+");
      index2 = op.find("=");
      left1 = op.substr(0, index1);
      left2 = op.substr(index1+1, index2-index1-1);
      right = op.substr(index2+1);
      
      left1 = convert(left1, ii);
      left2 = convert(left2, ii);
      right = convert(right, ii);
      
      if(left1.size() > 1 && left1[0] == '0' ||
	 left2.size() > 1 && left2[0] == '0' ||
	 right.size() > 1 && right[0] == '0') continue;
      
      //      while(left1.size() > 1 && left1[0] == '0') left1.erase(left1.begin());  
      //while(left2.size() > 1 && left2[0] == '0') left2.erase(left2.begin());  
      //     while(right.size() > 1 && right[0] == '0') right.erase(right.begin());
      //cout << left1 << '+' << left2 << '=' << right << endl;
            
      if(calc(left1, left2) == right){
	//cout << left1 << '+' << left2 << '=' << right << endl;
	cout << ii << endl;
	flag = true;
	break;
      }
    }
    if(!flag) cout << "NA" << endl;
  }
  return 0;
}
    

Measured memory_bytes: 1192
N = int(input())
ans = [[] for _ in range(N)]
for x in range(1, 101):
    for y in range(x, 101):
        for z in range(y, 101):
            n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if n > N:
                break
            ans[n - 1].append((x, y, z))

count = 0
# 複数パターンを考慮しているか？
for an in ans:
    if an == []:
        print(0)
    else:
        count = 0
        for a in an:
            if a[0] == a[1] and a[1] == a[2]:
                count += 1
            elif not a[0] == a[1] and not a[1] == a[2] and not a[2] == a[0]:
                count += 6
            else:
                count += 3
        print(count)


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

int main() {
  int N;
  cin >> N;
  int a[N], b[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> b[i];
  }
  priority_queue<int> que;
  
  int s = a[0];
  for (int i = 0; i < N; i++) {
    s += b[i];
  }
  
  que.push(s);
  
  for (int i = 1; i < N; i++) {
    s += (a[i] - b[i-1]);
    que.push(s);
  }
  
  int ans = que.top();
  cout << ans << endl;
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector <int> a(n);
  for (auto &i : a) cin >> i;
  long long int height = 0;
  for (int i = 1;i < n; ++i){
	if (a[i] < a[i-1]){
		height += a[i-1] - a[i];
		a[i] = a[i-1];
	}
  }
  cout << height << "\n"; 
return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  double d=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    d+=1.0/a[i];
  }
  double ans=1.0/d;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    int x[N], y[N], b[N], p[N];
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> b[i] >> p[i];
    }
    for (int i = 0; i < N; i++) {
        int s = x[i] * b[i] + y[i] * p[i];
        if (b[i] >= 5 && p[i] >= 2) {
            s = (s * 8) / 10;
        } else {
            int t = 0;
            if (b[i] < 5) t += 5 * x[i];
            else t += b[i] * x[i];
            if (p[i] < 2) t += 2 * y[i];
            else t += p[i] * y[i];
            t = (t * 8) / 10;
            s = min(s, t);
        }
        cout << s << "\n";
    }
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	char c[n][3];
	char d[n][3];
	for (int i = 0; i < n; i++) {
		cin >> c[i][0] >> c[i][1];
		c[i][2] = i;
		for (int j = 0; j < 3; j++){
			d[i][j] = c[i][j];
		}
	}

	for (int i = 0; i < n; i++){
		for (int j = n-1; j >= i+1; j--){
			if (c[j][1] < c[j-1][1]) swap(c[j], c[j-1]);
		}
	}

	bool flag = 1;
	for (int i = 0; i < n; i++){
		if (i != n-1) {
			cout << c[i][0] << c[i][1] << " ";
			if (c[i][1] == c[i+1][1] and c[i][2] > c[i+1][2]) flag = 0;
		}
		else cout << c[i][0] << c[i][1] << endl;
	}

	if (flag) cout << "Stable" << endl;
	else cout << "Not stable" << endl;

	for (int i = 0; i < n; i++){
		int minj = i;
		for (int j = i; j < n; j++){
			if (d[j][1] < d[minj][1]) minj = j;
		}
		swap(d[i], d[minj]);
	}

	flag = 1;

	for (int i = 0; i < n; i++){
		if (i != n-1) {
			cout << d[i][0] << d[i][1] << " ";
			if (d[i][1] == d[i+1][1] and d[i][2] > d[i+1][2]) flag = 0;
		}
		else cout << d[i][0] << d[i][1] << endl;
	}

	if (flag) cout << "Stable" << endl;
	else cout << "Not stable" << endl;


}



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

using namespace std;

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	long long sum = 0;
	for(int i = 0; i < k; i++){
		sum += a[i];
	}
	cout << sum << "\n";
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int n,q;
  cin>>n>>q;
  string s; cin>>s;
  int count[n];
  count[0]=0;
  rep(i,n-1){
    if(s[i]=='A'&&s[i+1]=='C') count[i+1]=count[i]+1;
    else count[i+1]=count[i];
  }
  rep(i,q){
    int l,r;
    cin>>l>>r;
    l--;r--;
    cout << count[r]-count[l] <<endl;
  }
  rep(i,n){
    //cout<<count[i]<<endl;
  }
}


Measured memory_bytes: 4120
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=26;
int n,a[M];
string s;

int main(){
	cin>>n>>s;
	for(int i=0;i<n;i++) a[s[i]-'a']++;
	ll t=1;
	for(int i=0;i<M;i++) (t*=a[i]+1)%=mod;
	cout<<(t+mod-1)%mod<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int C;
    scanf(" %d", &C);
    while(C--){
        ll n,k;
        scanf(" %lld %lld", &n, &k);

        if(n%2==0) --n;
        ll L = (n+1)/2;

        if(L < k){
            printf("-1\n");
            continue;
        }

        ll ng=0, ok=n;
        while(ok-ng>1){
            ll mid = (ng+ok)/2;

            ll t = n;
            ll ct = 0;

            ll d = 2;
            while(t>0){
                ll nt = t/3;
                if(nt%2==0) --nt;

                ll S = nt+2, E = t;
                if(S>E) S = 1;
                ll num = (E-S)/2 + 1;

                if(mid - S*d/2 >= 0){
                    ll i = (mid - S*d/2)/d;
                    ct += min(num,i+1);
                }

                t = nt;
                d *= 2;
            }

            if(ct >= k) ok = mid;
            else ng = mid;
        }
        printf("%lld\n", ok);
    }
    return 0;
}



Measured memory_bytes: 3216
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc= new Scanner (System.in);
		int N = sc.nextInt();
		int [] a = new int[N+2];
		a[0] = 0;
		a[N+1] = 0;
		for(int i = 1; i <= N; i++) {
			a[i] = sc.nextInt();
		}
		int total = 0;
		for (int i = 0; i < N + 1; i++) {
			total += Math.abs(a[i] - a[i + 1]);
		}
		for (int i = 1; i < N + 1; i++) {
			System.out.println(total - Math.abs(a[i] - a[i + 1]) - Math.abs(a[i - 1] - a[i]) + Math.abs(a[i - 1] - a[i + 1]));	
		}
	}
}

Measured memory_bytes: 50192
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$a = $key->A[0];
$b = $key->A[1];
$c = $key->A[2];
if (($b-$a) == ($c-$b)) {
  printf("YES\n");
}
else {
  printf("NO\n");
}

Measured memory_bytes: 3828
n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in range(n-1):
  idx = i + a[i] + 1
  if idx in dic:
    dic[idx] += 1
  else:
    dic[idx] = 1
ans = 0
j = n-1
while j > 0:
  target = j + 1 - a[j]
  idx = j + 1 + a[j]
  if target in dic:
    ans += dic[target]
  if j < n-1:
  	dic[idx] -= 1
  j -= 1
print(ans)


Measured memory_bytes: 40400
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<stack>
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef vector<P> VP;
typedef vector<int> VI;
typedef vector<VP> VVP;
typedef vector<VI> VVI;
class Pox
{
public:
  int cost,now;
  Pox():cost(0),now(0){}
  Pox(int now,int cost):now(now),cost(cost){}
};

class ope{
public:
  bool operator() (Pox a,Pox b)
  {
    return a.cost > b.cost;
  }
};

const int INF = (1<<28);
int N,M,K;
VVP G;
VI mincost;
//map<P,int> D;

int main()
{
  scanf("%d %d %d",&N,&M,&K);
  G.resize(N),mincost.resize(N);
  for(int i=0;i<N;i++)
      mincost[i] = INF;

  for(int i=0;i<M;i++)
    {
      int a,b,c;
      scanf("%d %d %d",&a,&b,&c);
      a--,b--;
      G[a].push_back(P(b,c));
      G[b].push_back(P(a,c));
      //D[P(a,b)] = D[P(b,a)] = c;
    }

  priority_queue<Pox,vector<Pox>,ope> Q;
  for(int i=0;i<K;i++)
    {
      int a;
      scanf("%d",&a);
      a--;
      Q.push(Pox(a,0));
      mincost[a] = 0;
    }

  while(!Q.empty())
    {
      Pox pox = Q.top(); Q.pop();
      int now = pox.now;
      int total = pox.cost;

      for(int i=0;i<G[now].size();i++)
	{     
	  P p = G[now][i];
	  int to = p.F;
	  int cost = p.S;
	  if(mincost[to] <= total + cost)
	    continue;

	  mincost[to] = total + cost;
	  Q.push(Pox(to,total+cost));
	}
    }


  double mex = 0;
  for(int i=0;i<N;i++)
    for(int j=0;j<G[i].size();j++)
	if(j != i && mincost[G[i][j].F] != INF && mincost[i] != INF && mex < (double)(mincost[i]+mincost[G[i][j].F]+G[i][j].S/*D[P(i,j)]*/)/2.0)
	  mex = (double)(mincost[i]+mincost[G[i][j].F]+G[i][j].S/*D[P(i,j)]*/)/2.0;
	    

  printf("%d\n",(int)round(mex));

  return 0;
}

Measured memory_bytes: 4180