akhauriyash/Code-Regression huggingface dataset:
#include<atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    dsu uf(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.merge(a, b);
    }
    vector<vector<int>> g = uf.groups();
    cout << (int)g.size() - 1 << endl;
}


Measured memory_bytes: 8840
rates  = [399,799,1199,1599,1999,2399,2799,3199]
from collections import defaultdict


def return_index(score):
  for i in rates:
    if score <= i:
      return rates.index(i)
  else:
    return 8

N = int(input())
A = list(map(int,input().split()))
d = defaultdict(int)
for a in A:
  d[return_index(a)] += 1
key_len = len(d.keys())
num_of_9s = d[8]
has_9 = 1 if num_of_9s > 0 else 0
print("{} {}".format(max(1,key_len-has_9),key_len-has_9+num_of_9s ))

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

using namespace std;


int main(){
    int n;
    cin >> n;
    
    vector<vector<int>> a(2,vector<int>(n));
    
    for (int i = 0; i < 2; i++){
        for (int j = 0; j < n; j++) cin >> a[i][j];
    }
    
    int ans = 0;
    
    // 下へ進む場所を全通り試す
    for (int i = 0; i < n; i++){
        int candies = 0;
        
        for (int j = 0; j <= i; j++) candies += a[0][j];
        
        for (int k = i; k < n; k++) candies += a[1][k];
        
        ans = max(ans, candies);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

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


Measured memory_bytes: 256
function Main(input) {
    var input_arr = input.split("\n");
    var n = parseInt(input_arr[0]);
    var h = input_arr[1].split(" ");
    h = h.map(x => parseInt(x))

    var count = 1;
    var max = h[0];
    for (var i = 1; i < n; i++) {
        if (h[i] >= max) {
            count += 1
        }
        max = Math.max(max, h[i])
    }
    console.log(count)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
n, y = map(int, input().split())

i, j, k = -1, -1, -1

for a in range(n + 1):
    for b in range(n+1-a):
        sum = (10000*a) + (5000*b) + (1000 * (n-(a+b))) if n-(a+b) >= 0 else None
        if sum == y:
            i, j, k = a, b, n-(a+b)
            break


print(i, j, k)


Measured memory_bytes: 3316
import os, sys, re, math

(L, R) = [int(n) for n in input().split()]

R = min(R, L + 2019)
result = 2018
for i in range(L, R):
    for j in range(i + 1, R + 1):
        result = min(result, i * j % 2019)

print(result)


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

int max(int a, int b)
{
	return a > b ? a : b;
}

int main()
{
	int n, r = 0, g = 0;
	char t;
	cin >> n;
	while (n--)
	{
		cin >> t;
		r += (t == 'I' ? 1 : -1);
		g = max(g, r);
	}
	cout << g << '\n';
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var N int
	fmt.Scan(&N)
	min := len(strconv.Itoa(N))
	for i := 1; i < N; i++ {
		if N%i == 0 {
			min = Min(min, len(strconv.Itoa(Max(i, N/i))))
		}
		if i >= N/i {
			break
		}
	}
	fmt.Println(min)
}

func Min(a, b int) int {
	if b < a {
		return b
	}
	return a
}

func Max(a, b int) int {
	if b > a {
		return b
	}
	return a
}


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

#define ALL(a) (a).begin(), (a).end()
#define int long long

using namespace std;

signed main(){
	
	int n; cin >> n;
	vector<int> a(n);
	vector<int> w(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}

	for(int i = 0; i < n; i++){
		cin >> w[i];
	}

	vector<int> p(n);
	for(int i = 0; i < n; i++) p[i] = i;
	int ans = 1000000000000000007;
	
	do{
		int tmp = 0;
		for(int i = 0; i < n; i++){
			int val = a[p[i]];
			if(val == 0){
				// みぎきき
				// int idx = 
				int idx = (i + 1) % n;
				int val2 = a[p[idx]];
				if(val2 == 1) tmp += w[p[i]];
			}else{

				int idx = (i + n - 1) % n;
				int val2 = a[p[idx]];
				if(val2 == 0) tmp += w[p[i]];
			}
		}

		ans = min(ans, tmp);
	}while(next_permutation(p.begin(), p.end()));
	
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 3116
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
const int MAX = 2000;
const int MOD = 1e+9+7;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n,int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(){
	COMinit();
	int N,A,B,C,D;
	scan(N);scan(A);scan(B);scan(C);scan(D);
	ll dp[1001]={};
	dp[0]=1;
	for(int i=A;i<=B;i++){
		ll dpb[1001];
		fill(dpb,dpb+1001,0);
		rep(j,N+1){
			if(dp[j]==0) continue;
			ll way=1;
			for(int k=0;k<=N-j;k+=i){
				if(k==0||(C<=k/i&&k/i<=D)){
					dpb[j+k]+=dp[j]*way%MOD;
					dpb[j+k]%=MOD;
				}
				if(N-j-k<i) break;
				way=way*COM(N-j-k,i)%MOD*inv[k/i+1]%MOD;
			}
		}
		rep(j,N+1) dp[j]=dpb[j];
	}
	prin(dp[N]);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(), y = sc.nextInt();
        int res = Math.abs(Math.abs(x) - Math.abs(y));
        if(Math.abs(x) < Math.abs(y)) {
            if(x < 0 && y < 0) res += 2;
            else if(x < 0 && y == 0);
            else if(!(x >= 0 && y >= 0)) res += 1;
        }
        if(Math.abs(x) > Math.abs(y)) {
            if(x > 0 && y == 0) res += 1;
            else if(x > 0 && y > 0) res += 2;
            else if(!(x < 0 && y <= 0)) res += 1;
        }
        if((Math.abs(x) == Math.abs(y)) && ((x < 0 && y > 0) ||( x > 0 && y < 0))) res += 1;
        System.out.println(res);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define REP(i, n) for(int i = 0; (i) < (n); ++(i))
#define FOR(i, n) for(int i = 1; (i) <= (n); ++(i))
#define dump(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9 + 7;
// const lint LINF = 1e18;
const double eps = 0.000000001;  //もとの値の10^(-16)まで

using namespace std;

// typedef pair<int, int> P;
// priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
// cout << fixed << setprecision(10) << ans << endl;

signed main() {
  int n;
  cin >> n;
  string ans = "No";
  REP(i, 10) {
    if(i == 0) continue;
    if(n % i == 0) {
        if(n/i < 10){
            ans = "Yes";
        }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)
#define int long long

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

int n,a[410]={0},s[410]={0},dp[410][410]={0};

int cal(int l,int r){
    if(dp[l][r]!=-1)return dp[l][r];
    if(r-l==1)return 0;
    if(r-l==2){
        return dp[l][r]=s[r]-s[l];
    }
    else{
        dp[l][r]=1e+18;
        FOR(i,l+1,r){
            dp[l][r]=min(dp[l][r],cal(l,i)+cal(i,r)+s[r]-s[l]);
        }
        return dp[l][r];
    }
}

signed main() {
	cin>>n;
    rep(i,n){
        cin>>a[i];
        s[i+1]=s[i]+a[i];
    }
    rep(i,n+1){
        rep(j,n+1){
            dp[i][j]=-1;
        }
    }
	
    cout<<cal(0,n)<<endl;
	
	return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int main(){
    int d=in();
    int n=26;
    vec c(n);
    rep(i,n)c[i]=in();
    vector<vec> s(d,vec(n));
    rep(i,d)rep(j,n)s[i][j]=in();
    rep(i,d){
        int id=0;
        int k=0;
        rep(j,n){
            if(k<s[i][j]){
                id=j+1;
                k=s[i][j];
            }
        }
        cout<<id<<endl;
    }
}

Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	ll ans=0;
	rep(i,n){
		if(s[i]=='L' && i>0 && s[i-1]=='L')ans++;
		if(s[i]=='R' && i<n-1 && s[i+1]=='R')ans++;
	}
	cout<<min(n-1,ans+2*k)<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i,m) cin >> b[i];
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,n) rep(j,m) cin >> a[i][j];
    int ans = 0;
    rep(i,n){
        int total = 0;
        rep(j,m){
            total += a[i][j]*b[j];
        }
        if(total+c > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 510;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, m, a[MAXN][MAXN];
vector<II> res;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,n) FOR(j,1,m) cin >> a[i][j];
    FOR(i,1,n) {
        FOR(j,1,m-1) {
            if (a[i][j] % 2) {
                res.emplace_back(II(i, j));
                res.emplace_back(II(i, j+1));
                a[i][j+1]++;
                a[i][j]--;
            }
        }
    }
    bool p = false;
    FOR(i,1,n-1) {
        if (a[i][m] % 2) {
            res.emplace_back(II(i, m));
            res.emplace_back(II(i+1, m));
            a[i+1][m]++;
            a[i][m]--;
        }
    }
    cout << SZ(res)/2 << "\n";
    for (int i = 0; i < SZ(res); i += 2) {
        cout << res[i].FI << ' ' << res[i].SE << ' ';
        cout << res[i+1].FI << ' ' << res[i+1].SE << "\n";
    }
    return 0;
}

Measured memory_bytes: 5232
def factorial(i)
  k = 1
  j = 1
  while j < i
    k *= j + 1
    if k > (10**9) + 7
      k %= (10**9) + 7
    end
    j += 1
  end
  k
end
n,m = gets.chomp.split(' ').map(&:to_i)
if n == m
  puts (2 * factorial(n) * factorial(m)) % ((10**9)+7)
elsif (n-m).abs > 1
  puts 0
else
  l = [n,m].max
  s = n+m-l
  puts (factorial(s) * factorial(l)) % ((10**9) + 7)
end

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

typedef long long lli;
typedef pair<lli,lli> pll;
typedef vector<lli> vcL;
typedef vector<pll> vPL;


void solve() {
	lli n;
	cin >> n;
	
	string s( 100, '0' );
	int tok = 0, check = ( n >= 0 );
	n = abs(n);
	
	while ( n ) {
		s[ tok++ ] = ( n%2 + 48 );
		n >>= 1;
	}
	
	for (int i = 0; i < 98; ++i) {
		if ( s[i] == '2' ) {
			s[i] = '0';
			s[ i+1 ]++ ;
		}
		if ( i%2 == check ) {
			if ( s[i] == '1' ) s[ i+1 ]++ ;
		}
	}
	
	bool flag = false;
	
	for (int i = 99; i >= 0; --i) {
		if ( i == 0 or s[i] == '1' ) flag = true;
		if ( flag ) cout << s[i];
	}
	
	cout << '\n';
}

int main() {
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}



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

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  int ans = INF;
  for (int i = 0; i <= s.size() - 3; i++) {
    string subs = s.substr(i, 3);
    ans = min(ans, abs(753 - stoi(subs)));
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;

ll evaluation(ll N, ll b, ll A[])
{

  ll acc = 0;
  for (ll i = 0; i < N; i++)
  {
    acc += abs((A[i] - (i + 1)) - b);
  }

  return acc;
}

bool compare(ll i, ll j)
{
  if (i < j)
  {
    return true;
  }
  return false;
}

int main()
{

  ll N;

  cin >> N;

  ll A[N];
  vector<ll> B;

  for (ll i = 0; i < N; i++)
  {
    cin >> A[i];
    B.push_back(A[i] - (i + 1));
  }
  sort(B.begin(), B.end(), compare);

  ll mid = (N - 1) / 2;
  ll b = B[mid];

  cout << evaluation(N, b, A);

  return 0;
}

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		if(2*b > a) {
			System.out.println(0); 
		}
		else System.out.println(a - 2*b);
	}
}


Measured memory_bytes: 20948
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.regex;
import std.range;
import core.exception;

void main() {
	auto N = readln.chomp.to!int;
	auto a = new int[](N);
	foreach(i; 0..N) {
		a[i] = readln.chomp.to!int;
	}
	bool[int] b;
	foreach(i; 0..N+1) b[i] = false;
	
	int current = 1, count;
	while(true) {
		if(b[current]) {
			(-1).writeln;
			return;
		}
		if(current == 2) {
			count.writeln;
			return;
		}
		b[current] = true;
		current = a[current-1];
		count++;
	}
}


Measured memory_bytes: 7676
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[][] c = new int[N][3];
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < 3; ++j) {
				c[i][j] = sc.nextInt();
			}
		}
		for (int i = 0; i < N; ++i) {
			int p = 0;
			for (int j = 0; j < 3; ++j) {
				int count = 0;
				for (int k = 0; k < N; ++k) {
					if (c[i][j] == c[k][j]) ++count;
				}
				if (count == 1) p += c[i][j];
			}
			System.out.println(p);
		}
	}

}

Measured memory_bytes: 20820
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int D;
  cin >> D;
  string ans;
  switch (D) {
    case 25:
      ans = "Christmas";
      break;
    case 24:
      ans = "Christmas Eve";
      break;
    case 23:
      ans = "Christmas Eve Eve";
      break;
    case 22:
      ans = "Christmas Eve Eve Eve";
      break;
  }
  cout << ans << endl;
  return 0;
}


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

int fourNum(int n);

int main(void){
  int n;
  int ans;

  while(cin >> n){
    ans = fourNum(n);
    cout << ans << "\n";
  }

}

int fourNum(int n){
  int sum;
  int cnt = 0;

  for(int i = 0; i <= 9; i++){
    if(i > n){
      break;
    }

    for(int j = 0; j <= 9; j++){
      if((i+j) > n){
        break;
      }

      for(int k = 0; k <= 9; k++){
        if((i+j+k) > n){
          break;
        }

        for(int l = 0; l<= 9; l++){
          sum = i + j + k + l;
          if(sum > n){
            break;
          }

          if(sum == n){
            cnt++;
            break;
          }
        }
      }
    }
  }
 return cnt;
}

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

int main() {
    int n ;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n);
    for (int i = 0; i < n+1; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    long cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j <= i+1; j++) {
            if (b[i] == 0) break;
            if (a[j] >= b[i]) {
                a[j] -= b[i];
                cnt += b[i];
                b[i] = 0;
                break;
            } else {
                b[i] -= a[j];
                cnt += a[j];
                a[j] = 0;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>

#include <map>

using namespace std;

typedef long long LL;

int n, m, k;

int q;

int main() {

    cin >> n;
    for (; n--; ) {
        int x;
        cin >> x;
        if (x % 2 == 0 && !(x % 3 == 0 || x % 5 == 0)) {
            cout << "DENIED";
            return 0;
        }
    }
    cout << "APPROVED";
    
}

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

using ll = long long;
using namespace std;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);

#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}


void init();
void solve();

signed main()
{
	init();
	solve();
}

void init()
{
	int A, B;
	cin >> A >> B;
	if (B % A == 0) {
		cout << A + B << endl;
	} else {
		cout << B - A << endl;
	}
}

void solve()
{
}




Measured memory_bytes: 256
/*
                    NAYEEM
    Information and Communication Engineering ,
            University of Rajshahi
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define ll long long
#define pii pair<int,int>
#define uu first
#define vv second


#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)

#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x)
#define ps printf(" ")
#define pn printf("\n")
#define pb(x) push_back(x)
#define ppb(x) pop_back(x)
#define pf(x) push_front(x)
#define ppf(x) pop_front(x)
#define in(x,y) insert({x,y})
#define sv(a) sort(a.begin(),a.end())
#define zero(arr,a) memset(arr,a,sizeof arr)
#define mx 1005

int fx[]={0,1,1,1,0,-1,-1,-1};
int fy[]={1,1,0,-1,-1,-1,0,1};



int main()
{
    //IOS
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c;
    cin>>a>>b>>c;
    int k = b+c;
    int mm = min(a,k);
    cout<<c-(mm-b)<<endl;
    return 0;
}


Measured memory_bytes: 256
// AOJ 0023
#include<iostream>
#include<cmath>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

const long double EPS = 1e-8;

long double sq(long double x) {
  return x * x;
}

long double abs(long double x) {
  return (x > 0 ? x : -x);
}
/*
bool eq(long double x, long double y) {
  return abs(x - y) < EPS;
}*/

long double dist(long double xa, long double ya, long double xb, long double yb) {
  return sq(xa - xb) + sq(ya - yb);
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    long double xa, ya, ra, xb, yb, rb;
    cin >> xa >> ya >> ra >> xb >> yb >> rb;

    long double d = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
    
    if (ra - rb > d + EPS) {
      cout << 2 << endl;
    } else if (rb - ra > d + EPS) {
      cout << -2 << endl;
    } else if (d > ra + rb + EPS) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  }
}

Measured memory_bytes: 1232
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(I,N) for (int I = 0; I < (N); ++I)
#define fornd(I,N) for (int I = (N) - 1; I >= 0; --I)
#define forab(I,A,B) for (int I = (A); I <= (B); ++I)
#define forabd(I,A,B) for (int I= (B); I >= (A); --I)
#define FOREACH(I,A) for (__typeof__(A)::iterator I=A.begin(); I<A.end(); I++)
#define all(V) (V).begin(), (V).end()
#define pb push_back
#define mp make_pair

typedef long long int ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

const ll mod = 1000000007;

int main() {
  int A, P;
  cin >> A >> P;

  cout << (A * 3 + P) / 2 << endl;

  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define de(x) cout<<#x<<" = "<<x<<endl
using namespace std;
typedef long long ll;
int a,b,c,d,e,f;
double gl=0;
double g=0;
int main()
{
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
    int water=0,suger=0;
    int watter=0;
    ll ro=0;
    int ans1=0,ans2=0;

    for(int i=0;i<=35;i++)
    {
        water=i*a;
        for(int j=0;j<=35;j++)
        {
            water=water+j*b;
            watter=water*100;
            for(int k=0;k<=1500;k++)
            {
                ro=water*e;
               // suger=k*c;
                for(int z=0;z<=1500;z++)
                {
                    suger=k*c+d*z;
                    if(suger>3000) break;
                   // if(suger==934) {de(11);return 0;}
                    if(suger+watter!=0&&suger<=ro&&suger+watter<=f)
                    {
                        g=1.0*suger/watter;
                        //de(g);
                        if(gl<=g)
                        {
                          //  de(111);
                        gl=g;
                        ans1=watter+suger;ans2=suger;
                        }
                    }

                }
            }
        }

    }
    cout<<ans1<<" "<<ans2<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		sc.close();
		
		if(N.charAt(0) == N.charAt(1)) {
			if(N.charAt(1) == N.charAt(2)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			if(N.charAt(1) == N.charAt(2) && N.charAt(2) == N.charAt(3)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}


Measured memory_bytes: 23380
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main() {
    int n;
    vector<pair<long long,long long> > v;
    cin>>n;
    v.PB(MP(-2000000000,0));
    int dp[100100];
    REP(i,n){
        long long x,l;
        cin>>x>>l;
        v.PB(MP(x+l,l));
    }
    sort(v.begin(),v.end());
    REP(i,n+1){
        if(i==0){
            dp[i]=0;
        }else{
            long long x=v[i].first-2*v[i].second;
            int l=0,r=i;
            while(r-l>1){
                int mid=(l+r)/2;
                if(v[mid].first>x)r=mid;
                else l=mid;
            }
            dp[i]=max(dp[i-1],dp[l]+1);
        }
    }
    // REP(i,n+1)cout<<dp[i]<<" ";cout<<endl;
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=998244353;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int nmax=400005;
ll fac[nmax],finv[nmax],inv[nmax];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
// modintを使うときはllをmintに
ll com(int n,int k){
  if(n<k||n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
ll pow_mod(ll n,ll k,ll m){
  ll res=1;
  for(;k>0;k>>=1){
    if(k&1){
      res=(res*n)%m;
    }
    n=(n*n)%m;  
  }
  return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,k;cin >> n >> m >> k;
    COMinit();
    ll ans=0;
    for(ll i=0;i<=k;i++){
        (ans+=m*pow_mod(m-1,n-i-1,mod)%mod*com(n-i-1+n-(n-i),n-i-1)%mod)%=mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13024
#include <iostream>
#include <iomanip>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
int main (void){
    int N, tmp;
    long double total = 0;
    scanf("%d" , &N);
    vector<int> A(N);
    rep(i, N){
        scanf("%d", &tmp);
        A[i] = tmp;
    }

    rep(i, N)
        total += 1/(long double)A[i];

    cout << fixed;
    cout << setprecision(10) << 1 / total << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*; 
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//入力文字列
		String w = sc.next();
		final String orgChars="abcdefghijklmnopqrstuvwxyz";

		String ans;
		if(w.length() % 2 == 1){
			ans = "No";
		}else{
			int flag = 0;
			int i = 0;
			while(flag == 0 && i != 26){
				if((w.length() - w.replaceAll(orgChars.substring(i,i+1),"").length()) % 2 != 0){
					flag = 1;
				}
				i++;
			}
			if(flag == 1){
				ans = "No";
			}else{
				ans = "Yes";
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 9424
N,M = map(int, input().split())
xs,ys,zs = [], [], []
"""
sum000 +++
sum001 ++-
sum010 +-+
sum011 +--
sum100 -++
sum101 -+-
sum110 --+
sum111 ---
"""


sum000, sum001, sum010,sum011 = [], [], [], []
sum100, sum101, sum110,sum111 = [], [], [], []
sums = [[] for i in range(8)]
for i in range(N):
    x,y,z = map(int, input().split())
    sums[0].append(x+y+z)
    sums[1].append(x+y-z)
    sums[2].append(x-y+z)
    sums[3].append(x-y-z)
    sums[4].append(-x+y+z)
    sums[5].append(-x+y-z)
    sums[6].append(-x-y+z)
    sums[7].append(-x-y-z)

ans = 0
for s in sums:
    s1 = sorted(s,reverse=False)
    s2 = sorted(s,reverse=False)
    x = max(abs(sum(s1[:M])),abs(sum(s2[:M])))
    ans = max(ans,x)
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using i64 = long long;

template <class T>
T pow(T x, T n, T mod) {
    T ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <class T>
T inverse(T x, T p) { return pow(x, p - 2, p); }

int h, w, n;
constexpr i64 mod = 1000000007;
std::vector<i64> fact, inv;
std::vector<std::pair<int, int>> b;
std::vector<std::deque<int>> q;
std::vector<i64> memo;

i64 calc(int v) {
    if (memo[v]) return memo[v];
    i64 ret = 0;
    for (auto to : q[v]) {
        auto ways = fact[b[to].first - b[v].first + b[to].second - b[v].second] % mod * inv[b[to].first - b[v].first] % mod * inv[b[to].second - b[v].second] % mod;
        ret = (ret + mod - calc(to) * ways % mod) % mod;
    }

    return memo[v] = ret;
}

int main() {
    std::cin >> h >> w >> n;

    int m = h + w + 2;
    fact.resize(m + 1);
    inv.resize(m + 1);
    fact[0] = 1;
    for (auto i = 1; i <= m; i++) fact[i] = fact[i - 1] * i % mod;
    inv[m] = inverse(fact[m], mod);
    for (auto i = m; i > 0; i--) inv[i - 1] = inv[i] * i % mod;

    b.emplace_back(0, 0);
    b.emplace_back(h - 1, w - 1);
    for (int i = 0; i < n; i++) {
        int r, c;
        std::cin >> r >> c;
        r--;
        c--;
        b.emplace_back(r, c);
    }

    q.resize(b.size());
    memo.resize(b.size());
    memo[1] = -1;
    for (int i = 0; i < b.size(); i++) {
        for (int j = 0; j < b.size(); j++) {
            if (i == j) continue;
            if (b[i].first <= b[j].first && b[i].second <= b[j].second) {
                q[i].push_back(j);
            }
        }
    }

    i64 ret = calc(0);

    std::cout << ret << std::endl;

    return 0;
}

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

int main(){
	
	int L, R, d;
	int count=0;
	cin >> L >> R >> d;
	
	for(int i=L;i<=R;i++){
		if(i%d == 0){
			count++;
		}
	}
	
	cout << count ;
	
	
	return 0;
}

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

int bubbleSort(vector<int>& A, int N){
  int res =0;
  for(int i=0; i<N; i++){//while 使えば短縮できるが。まずはforで愚直にやるのも良い
    for(int j = N-1; j > i; j--){
      if(A.at(j) < A.at(j - 1)){
        swap(A.at(j), A.at(j-1));
        res ++;
      }
    }
  }
  return res;
}



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

  int res = bubbleSort(A, N);
  for(int i=0; i<N; i++){
    if(i)
      cout<<' ';
    cout << A.at(i);
  }
  cout << endl << res << endl;
}


                                                          


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	char a,b;
	cin>>a>>b;
	char f[]={'H','D'};
	if(a=='H')
	{if(b=='H')
	cout<<f[0];
	else
	cout<<f[1];	
	
	}
	else
	{
		if(b=='H')
	cout<<f[1];
	else
	cout<<f[0];
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    int co=0;
    long long ans=1;
    bool state=s[0]==t[0];
    while(co<n){
        if(s[co]==t[co]){
            if(!state){
                ans=(ans*2)%1000000007;
            }
            state=false;
            co++;
        }
        else{
            if(state){
                ans=(ans*3)%1000000007;
            }
            else{
                ans=(ans*2)%1000000007;
            }
            state=true;
            co+=2;
        }
    }
    cout << (ans*3)%1000000007 << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]
b = 1
flag = True
for i in range(n):
    b = a[b-1]
    if b == 2:
        print(i+1)
        flag = False
        break
    elif b == 1:
        print(-1)
        flag = False
        break
if flag:
    print(-1)

Measured memory_bytes: 7084
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);


int main(){
    IOS;
    string s;cin>>s;
    if(s[s.size()-1]=='s'){s+='e';s+='s';}
    else s+='s';
    cout<<s;
    return 0;  
} 



Measured memory_bytes: 3660
#include <stdio.h>

int toSum(int a)
{
  int b = a;
  int c = 0;
  while(b > 0)
  {
    c += b % 10;
    b /= 10;
  }
  return c;
}

int main()
{
  int a;
  scanf("%d", &a);
  if(a % toSum(a) == 0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

int main()
{
  char s[4];
  int res=0;
  cin >> s;

  rep(i,4){
    if(s[i]=='+') res++;
    else res--;
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

const int MOD = 1e9 + 7, LIM = 2001;
int N, M, S[LIM], T[LIM], ans = 1;
int64_t sum[LIM][LIM], dp[LIM][LIM];

int main() {
    cin >> N >> M;
    rep(i, N) cin >> S[i];
    rep(i, M) cin >> T[i];

    rep(i, N) rep(j, M) {
        if (S[i] == T[j]) {
            dp[i+1][j+1] = (sum[i][j] + 1) % MOD;
        }
        sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1] + MOD) % MOD;
        ans += dp[i+1][j+1];
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 62592
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> T(N + 1, 0), X(N + 1, 0), Y(N + 1, 0);
    rep(i, N) cin >> T[i + 1] >> X[i + 1] >> Y[i + 1];
    bool judge = true;
    rep(i, N) {
        if (T[i + 1] - T[i] < abs(X[i + 1] - X[i]) + abs(Y[i + 1] - Y[i])) judge = false;
        if ((abs(X[i + 1] - X[i]) + abs(Y[i + 1] - Y[i])) % 2 != (T[i + 1] - T[i]) % 2) judge = false;
    }
    cout << (judge ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
using namespace std;
int n,Q;
struct p{
	int l,r;
	p*next;
};
main()
{
	cin>>n>>Q;
	vector<int>a(n),id(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		id[--a[i]]=i;
	}
	p*root=(p*)calloc(1, sizeof(struct p));
	root->l=0,root->r=n;
	for(int i=0;i<Q;i++)
	{
		int q;cin>>q;q--;
		p*now=root;
		while(!(now->l<=id[q]&&now->r>id[q]))now=now->next;
		p*End=now;
		while(End->next!=NULL)End=End->next;
		End->next=(p*)calloc(1,sizeof(struct p));
		p*qq=End->next;
		p*r=(p*)calloc(1,sizeof(struct p));
		qq->l=id[q];
		qq->r=id[q]+1;
		r->l=id[q]+1,r->r=now->r;
		now->r=id[q];
		r->next=now->next;
		qq->next=root;
		now->next=NULL;
		root=r;
		if(i%300==299||i==Q-1)
		{
			p*now=root;
			vector<int>an(n);
			int cnt=0;
			while(now!=NULL)
			{
				for(int j=now->l;j<now->r;j++)
				{
					an[cnt++]=a[j];
				}
				now=now->next;
			}
			for(int j=0;j<n;j++)
			{
				id[an[j]]=j;
			}
			a=an;
			root->l=0;
			root->r=n;
			root->next=NULL;
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<a[i]+1<<(i==n-1?"\n":" ");
	}
}



Measured memory_bytes: 10308
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main()
{
    int a,b,c;
    int ch[4];
    while(cin >> a >> b >> c)
    {
        ch[0] = a;
        ch[1] = b;
        ch[2] = c;
        sort(ch,ch+3);
        if(ch[0] == 5&&ch[1] == 5&&ch[2] == 7)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  int K;
  cin >> K >> S;
  string shortS = "";
  
  if (S.size() <= K) {
    cout << S << endl;
  } else {
    for (int i = 0; i < K; i++) {
      shortS += S[i];
    }
    cout << shortS + "..." << endl;
  }
}

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

#define int long long
using namespace std;

#define deb(x) cout << #x << " = " << x << endl
template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

int power(int a, int b, int mod) {
    int ans = 1;
    while(b>0) {
        if(b&1) {
            ans = (ans*a)%mod;
        }
        a = (a*a)%mod;
        b=b>>1;
    }
    return ans;
}

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

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

    vector<int> dp(2e6 + 5);
    dp[0] = 0;
    for(int i=1; i<=2e6; i++) {
        dp[i] = (1 + dp[i%__builtin_popcount(i)]);
    }

    int ans1 = 0;       /// when s[i] == '1'
    int ans2 = 0;       /// when s[i] == '0'

    int c = 0;
    for(int i=0; i<n; i++) c += (s[i]-'0');

    if(c > 0) {
        for(int i=0; i<n; i++) {
            if(s[i] == '0') continue;
            if(c > 1) ans1 = ( ans1 + power(2, n-i-1, c-1) )%(c-1);
            ans2 = ( ans2 + power(2, n-i-1, c+1) )%(c+1);
        }
    }
    //deb(ans1);
    //deb(ans2);

    for(int i=0; i<n; i++) {
        if(s[i] == '1') {
            if(c == 1) cout << 0 << endl;
            else {
                cout << (1 + dp[ ( ( ans1 - power(2, n-i-1, c-1) )%(c-1) + c-1)%(c-1) ]) << endl;
            }
        } else {
            //deb(dp[ans2 + power(2, n-i+1, c+1)%(c+1)]);
            cout << (1 + dp[ ( ans2 + power(2, n-i-1, c+1) )%(c+1) ]) << endl;
        }
    }

    return 0;
}


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

int main()
{
    long int n,k,x,y;
    cin >> n >> k >> x >> y;
    if(n<k){
        cout << n*x << '\n';
    }else{
        cout << k*x+(n-k)*y << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
X, K, D = map(int, input().split())
X = abs(X)

quotient = X // D
if quotient >= K:
    print(X - K * D)
else:
    X -= quotient * D
    K -= quotient
    
    if K % 2 == 0:
        print(X)
    else:
        print(abs(X - D))

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main(){
  ll n ;cin>>n;
  vector<ll> A(n) ;rep(i,n) cin>>A[i] ;
 ll ans=0;
 map<ll,ll> mp ;
 rep(i,n){
    ans+=mp[A[i]-i-1] ;
    mp[-i-1-A[i]] ++ ;
 }
  
   cout<<ans<<endl ;
   return 0 ;
}

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

P p[200010];
int main(){ 
    ll n,d;
    ll dis = 0;
    int res = 0;
    cin >> n >> d;
    for(int i = 0;i<n;i++){
        cin >> p[i].first >> p[i].second;
    }
    for(int i = 0;i<n;i++){
        ll x = p[i].first;
        ll y = p[i].second;
        dis = x * x + y * y;
        if(dis <= d * d) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6652
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  int N,M,sum=0; cin >> N >> M;
  vector<int> a(N);
  rep(i,N){
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(all(a));
  reverse(all(a));

  rep(i,M){
    if(a.at(i)*(4*M)<sum){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 256
mp = {}
MAXN = 1010
mini =  100000
w = [0] * MAXN
done = [False] * MAXN

n = int(input())
w1 = [int(i) for i in input().split()]

for index, value in enumerate(w1):
    w[index] = value

for i in range(n):
    mp[w[i]] = 0
    mini = min(mini, w[i])

k = 0
for i in sorted(w1):
    mp[i] = k
    k += 1

ans = 0
for i in range(n):
    if done[i]: continue
    cnt = 0
    now = i
    mi = 100000
    total = 0
    while (True):
        if done[now]: break
        cnt += 1
        done[now] = True
        mi = min(mi, w[now])
        total += w[now]
        now = mp[w[now]]
    tmp = total + (cnt - 2) * mi
    tmp = min(tmp, total + mi + mini * (cnt + 1))
    ans += tmp
print(ans)



Measured memory_bytes: 5768
# Your code here!
num = gets.to_i
val = gets.split.map(&:to_i)
# p val


# numbers = [1, 2, 3, 4]
# p val.combination(2) {|a, b| printf("(%d, %d) ", a, b) }
sum = 0
a = val.combination(2) {|a, b| sum += (a * b) }
p sum

Measured memory_bytes: 1788
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def contains_odd(A):
    for x in A:
        if x % 2 == 1:
            return True
    return False


def check(A, count):
    if contains_odd(A):
        return count

    count += 1
    return check([x / 2 for x in A], count)


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

print(check(A, 0))


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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s,t;
	cin >> s >> t;
	int ans = 1e9;
	for (int i = 0;i <= (int)s.size() - (int)t.size();i++) {
		string now = s.substr(i,(int)t.size());
		int res = 0;
		assert(now.size() == t.size());
		for (int j = 0;j < (int)t.size();j++) {
			if (now[j] != t[j]) ++res;
		}
		ans = min(ans,res);
	}
	cout << ans;
} 

Measured memory_bytes: 3660
//32
#include<iostream>
#include<string>

using namespace std;

int main(){
  for(string s;cin>>s;){
    int o=0,x=0;
    for(int i=0;i<9;i++){
      o|=(s[i]=='o')<<i;
      x|=(s[i]=='x')<<i;
    }
    int i;
    for(i=0;i<2;i++){
      int b=((i==0)?o:x);
      if(b&0x124&b<<1&b<<2)break;
      if(b&b<<3&b<<6)break;
      if(b&1<<8&b<<4&b<<8)break;
      if(b&1<<6&b<<2&b<<4)break;
    }
    char r[]={'o','x','d'};
    cout<<r[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
/*
    Friday | 24 July 2020
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define TryUntillAC ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int main(){
    TryUntillAC
    ll a,b,c; cin>>a>>b>>c;
    ll k; cin>>k;
    ll op = 0;
    while(a >= b)
    {
        b = b * 2;
        op++;
    }
    while(b >= c)
    {
        c = c * 2;
        op++;
    }
    if(op > k)
    {
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
}

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

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
    
    double a;
    cin >> a;
    cout << 2 * a * 3.1415926535 << endl; 

return 0;}
/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 

Measured memory_bytes: 3784
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main(void){
    int r, c;
    cin >> r >> c;
    vector<vector<int>> sheet(r + 1, vector<int>(c + 1));
    for (int i = 0; i <= r; i++) {
        int rowSum = 0;
        for (int j = 0; j < c; j++) {
            cin >> sheet[i][j];
            rowSum += sheet[i][j];
            if (i != r) sheet[r][j] += sheet[i][j];
        }
        
        sheet[i][c] = rowSum;
    }

    for (auto row : sheet) {
        ostringstream oss;    
        for (auto col : row) {
            if (oss.str() != "") oss << " ";
            oss << col;
        }
        
        cout << oss.str() << endl;
    }

    return 0;
}

Measured memory_bytes: 3140
h,w=map(int,input().split())
a=["."*(w+2)]
for i in range(h):
	x=input()
	a.append("."+x+".")
a.append("."*(w+2))
for i in range(h):
	for j in range(w):
		if a[i+1][j+1]=="#":
			if a[i][j+1]=="#" or \
a[i+2][j+1]=="#" or a[i+1][j+2]=="#" or\
a[i+1][j]=="#":
				continue
			else:
				print("No")
				exit()
print("Yes")

Measured memory_bytes: 3064