akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int n;
	while(cin >> n, n) {
		vvi dist(10, vi(10, INF));
		int a, b, c, maxN = 0;
		REP(i, n) {
			cin >> a >> b >> c;
			dist[a][b] = dist[b][a] = c;
			maxN = max(maxN, max(a, b));
		}
		maxN++;
		REP(i, maxN) {
			REP(j, maxN) {
				REP(k, maxN) {
					dist[j][k] = min(dist[j][k], dist[j][i]+dist[i][k]);
				}
			}
		}
		
		int ans = -1, cost = INF;
		REP(i, maxN) {
			int tmp = 0;
			REP(j, maxN) {
				if(i != j) {
					tmp += dist[i][j];
				}
			}
			if(tmp < cost) {
				cost = tmp;
				ans = i;
			}
		}

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

Measured memory_bytes: 1216
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int[] sa = new int[26];
        int[] ta = new int[26];
        Arrays.fill(sa, -1);
        Arrays.fill(ta, -1);
        for (int i = 0; i < s.length(); i++) {
            int si = s.charAt(i) - 'a';
            int ti = t.charAt(i) - 'a';
            if (sa[si] != -1 || ta[ti] != -1) {
                if (!(sa[si] == ti && ta[ti] == si)) {
                    System.out.println("No");
                    return;
                }
            } else {
                sa[si] = ti;
                ta[ti] = si;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 27364
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <cmath>
#include <cassert>

#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, MOD = 1e9 + 7;

int N, h[MN], dp[MN];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> h[i];
    dp[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= N; i++) dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    cout << dp[N] << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll N;
    cin >> N;
    vector<int> ans;
    while (true) {
        N -= 1;
        ans.push_back(N % 26);
        N /= 26;
        if (N == 0) break;
    }
    reverse(ALL(ans));

    char alpha[26];
    REP(i, 26) alpha[i] = 'a' + i;
    for (int a : ans) cout << alpha[a];
    cout << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int h, w, hoge;
    cin >> h >> w >> hoge;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)  cin >> s[i];

    vector<int> row;
    vector<vector<int>> column(h);
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(s[i][j] == '.')  continue;
            column[i].emplace_back(j);
        }
        if(column[i].size()){
            row.emplace_back(i);
            column[i].emplace_back(w);
        }
    }
    row.emplace_back(h);

    vector<vector<int>> ans(h, vector<int>(w, 0));
    int n = column[row[0]].size();
    int GroupNumber = 1;
    for(int i = 0; i + 1 < n; ++i){
        int l, r;
        if(i == 0){
            l = 0, r = column[row[0]][i + 1];
        }
        else{
            l = column[row[0]][i], r = column[row[0]][i + 1];
        }
        for(int j = 0; j < row[1]; ++j){
            for(int k = l; k < r; ++k){
                ans[j][k] = GroupNumber;
            }
        }
        ++GroupNumber;
    }
    
    int rowsz = row.size();
    for(int i = 1; i + 1 < rowsz; ++i){
        int columnsz = column[row[i]].size();
        for(int j = 0; j + 1 < columnsz; ++j){
            int l, r;
            if(j == 0){
                l = 0, r = column[row[i]][j + 1];
            }
            else{
                l = column[row[i]][j], r = column[row[i]][j + 1];
            }
            for(int x = row[i]; x < row[i + 1]; ++x){
                for(int y = l; y < r; ++y){
                    ans[x][y] = GroupNumber;
                }
            }
            ++GroupNumber;
        }
    }

    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cout << ans[i][j];
            cout << ((j == w - 1) ? '\n' : ' ');
        }
    }
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll sum=0;
    map<ll,ll> m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        m[a[i]]++;
        sum+=a[i];
    }
    ll q;
    cin>>q;
    while(q--)
    {
        ll b,c;
        cin>>b>>c;
        ll count=m[b];
        sum=sum-b*count+c*count;
        m[b]=0;
        m[c]+=count;
        cout<<sum<<endl;
    }
}

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

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

using namespace std;

int main(void)
{
	int n;
	bool blank=false;
	int coin[4] = {10,50,100,500};
	while(cin >> n, n > 0){
		if (blank){
			cout << endl;
		}else{
			blank = true;
		}
		int num[4], use[4];
		rep(i, 4){
			cin >> num[i];
			use[i] = 0;
		}
		rep(i, 4){
			if (i == 3){
				while(n > 0){
					n -= coin[i];
					use[i]++;
				}
				break;
			}
			if ((n%coin[i+1])/coin[i] <= num[i]){
				use[i] += (n%coin[i+1])/coin[i];
				num[i] -= (n%coin[i+1])/coin[i];
				n -= n%coin[i+1];
				while(num[i]-=coin[i+1]/coin[i], num[i]>=0){
					use[i] += coin[i+1]/coin[i];
					n -= coin[i+1];
				}
			}else{
				n += coin[i+1] - (n%coin[i+1]);
			}
		}
		rep(i, 4){
			if (use[i] > 0){
				cout << coin[i] << " " << use[i] << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3004
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    long n,k;
    scanf("%ld",&n);
    k=0;
    vector<long long> a(n);
    long long pre,sum;
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a.begin(),a.end());
    pre=a[0];
    for(int i=1; i<n; i++)
    {
        sum=pre+a[i];
        //printf("%lld %lld %lld\n",a[i],pre,sum);
        if(2*pre<a[i]) k=i;
        pre=sum;
    }
    printf("%ld",n-k);


}


Measured memory_bytes: 1024
N = int(input())
alpha = "abcdefghijklmnopqrstuvwxyz"

dp = [-1]*N
dp[0] = 1


ans = []


def solve(x, n, l):  # n:種類
    if l == N:
        ans.append(x)
    else:
        for i in range(n):
            j = n
            if i == n-1:
                j += 1
            solve(x + alpha[i], j, l+1)


solve("", 1, 0)
ans.sort()
for x in ans:
    print(x)


Measured memory_bytes: 12656
#include <iostream>
#define int long long

using namespace std;

int s[5];

signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	s[1] = a * c, s[2] = a * d, s[3] = b * c, s[4] = b * d;
	int ans = s[1];
	for (int i = 2; i <= 4; ++i) ans = max(ans, s[i]);
	
	cout << ans << '\n';
	 
	return 0;
}

Measured memory_bytes: 3632
/*
                                Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
 
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
 
#include <bits/stdc++.h>
 
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
 
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x) % M;
        x=(x*x)% M;
        n=n/2;
    }
    return result % M;
}
signed main()
{   jaldi
	int n;
	cin>>n;
	string str;
	cin>>str;
	bool x=true;
	if(n==1 || n%2!=0)
	cout<<"No";
	else
	{	int y=(n+1)/2;
		for(int i=0;i<n/2;i++)
		{	if(str[i]!=str[y])
			x=false;
			y++;
		}
		if(x)
		cout<<"Yes";
		else
		cout<<"No";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()
 
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}
 
typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;

int main(){
      int n;
      cin >> n;
      vector<int> a(n);
      int sum = 0;
      rep(i,n){
            cin >> a[i];
            sum += a[i];
      }
      int ans = -1;
      int Min = INF;
      for(int i=0;i<n;i++){
            if(abs(a[i]*n - sum) < Min){
                  Min = abs(a[i]*n - sum);
                  ans = i;
            }            
      }
      cout << ans << endl;

      return 0;
}

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


    public static void main(String[] args) {


        Scanner scan = new Scanner(System.in);
       int N=scan.nextInt();
       int H=N%10;
       if (H==1){System.out.println("pon");}
        if (H==2){System.out.println("hon");}
        if (H==3){System.out.println("bon");}
        if (H==4){System.out.println("hon");}
        if (H==5){System.out.println("hon");}
        if (H==6){System.out.println("pon");}
        if (H==7){System.out.println("hon");}
        if (H==8){System.out.println("pon");}
        if (H==9){System.out.println("hon");}
        if (H==0){System.out.println("pon");}


    }

}



Measured memory_bytes: 27084
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

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

  int x = 0;
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'I') {
      ans++;
      if(ans > x){
        x = ans;
      }
    } else {
      ans--;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  int K;
  if((A+B)%2==0){
    K=(A+B)/2;
    cout<<K<<endl;
    return 0;
  }
  else{
    cout<<"IMPOSSIBLE"<<endl;
  }
}
  


Measured memory_bytes: 3564
n = int(input())
a = []
top = 1
two = 1
for i in range(n):
    line = int(input())
    a.append(line)
    if line >= top:
        top, two = line, top
    elif line >= two:
        two = line

for i in range(n):
    if a[i] != top:
        print(top)
    else:
        print(two)

Measured memory_bytes: 16864
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == '1')
        {
            ans++;
        }
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 764
s = gets.chomp.split("")
ACGT_ARRAY = %w(A C G T)
a = []
s.each do |i|
  if ACGT_ARRAY.include?(i)
    a.push(1.to_i)
  else
    a.push(0.to_i)
  end
end

b = []
n = a.length
n.times do |i|
  j = i
  count = 0
  while a[j] == 1
    j += 1
    count += 1
  end
  b.push(count)
end

puts b.max

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

int main() {
  int N, D, X;
  scanf("%d%d%d", &N, &D, &X);

  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A.at(i));
  }

  int ans = X;
  for (int i = 0; i < N; i++) {
    int eaten_cookies = (D - 1) / A.at(i) + 1;
    ans += eaten_cookies;
  }

  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 256
($A,$B,$C)=sort{$a-$b}glob<>;
while($A<$C&&$B<$C){
	++$A;
	++$B;
	++$%;
}
while($A<$C){
	$A+=2;
	++$%;
}
if($A>$C){
	++$B;
	++$C;
	++$%;
}
print$%


Measured memory_bytes: 768
a, b = map(int, input().split())
c = []
e = 0
for i in range(a):
    c.append(list(map(int, input().split())))
for i in range(a):
    for j in range(i + 1, a):
        d = 0
        for k in range(b):
            d += (c[i][k] - c[j][k]) ** 2
        d = d ** 0.5
        if d == int(d):
            e += 1
print(e)


Measured memory_bytes: 3060
N, Y = [int(i) for i in input().split()]

ans = []
for i in range(N+1):
    for j in range(N+1-i):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            ans.append([i, j, N-i-j])

if len(ans) == 0:
    print(-1, -1, -1)
else:
    print(ans[0][0], ans[0][1], ans[0][2])


Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	long long ans=0;
/*	for (int i=1; i<n; i++)
	 {
	 	int j=1;
	 	while (j*j<i)
	 	{
	 	  if ((i%j)==0) ans+=2;
	 	  j++;
	      }
	    if (j*j==i) ans++;
	 }
*/

    int i=1; 
    while (i*i<n)
    {
      int j=i+1;
      ans++;
	  while (j*i<n) 
	  {
	  	ans+=2;
	  	j++;
	  }
	  i++;
	}

    printf("%lld",ans); 
    return 0;
 } 

Measured memory_bytes: 3768
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque 

def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# ---------------------------------------

mod = 10**9 + 7

H, W = inpl()
a = []
for i in range(H):
    a.append(input().strip())

dp = [[0] * (W+1) for i in range(H+1)]
dp[0][0] = 1

for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            continue
        for x, y in ((1, 0), (0, 1)):
            dp[i+x][j+y] += dp[i][j]
            dp[i+x][j+y] %= mod

print(dp[H-1][W-1])

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

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

    if(n == 1){
        cout << 0 << endl;
        return 0;
    }

    long long ans = 0;
    for (auto i = 1; i <= n-1 ; i++)
    {
        ans += i;
    }

    cout << ans << endl;
}

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



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll m,k;
    cin>>m>>k;
    if((1LL<<m)-1 < k){
        cout << -1 << endl;
        return 0;
    }
    if(k==0){
        for(int i=0;i<(1LL<<m);i++){
            cout << i <<" " << i << " ";
        }
        cout <<endl;
        return 0;
    }
    vector<ll> v;
    ll x = 0;
    for(int i=0;i<(1LL<<m);i++){
        if(i==k) continue;
        v.push_back(i);
        x ^= i;
    }
    if(x!=k){
        cout << -1 << endl;
        return 0;
    }
    cout << k << " ";
    for(auto i:v){
        cout << i << " ";
    }
    cout << k << " ";
    reverse(v.begin(),v.end());
    for(auto i:v){
        cout << i << " ";
    }
    cout << endl;

    
}

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

using ll = long long;
const int INF = INT_MAX;//2147483647
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var)  std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(int i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(int i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


int main() {

	int N,W;
	cin >> N >> W;
	vector<ll> v(N,0),w(N,0);
	rep(i,N){
		cin >> w[i] >> v[i];
	}

	//dp[i][j] 商品iまで使える状態　重さjの中での最大値
	vector<vector<ll>> dp(N+1,vector<ll>(W+1,0));
	rep(i,N){
		repeq(j,W){
			if(j-w[i]<0){
				dp[i+1][j]=dp[i][j];
			}else{
				dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
			}
		}
	}

	p(dp[N][W]);

	return 0;
}



Measured memory_bytes: 80256
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int n, m,a;
string s;

int main() {
	cin >>a>> s;
	for (int i = 0; i < a; i++)
	{
		if (s[i]=='R')
		{
			m++;
		}
		else {
			n++;
		}
	}
	if (m>n)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x - 1; i < y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i - - )
#define eps 1e - 9
#define all(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == ' - ') f =  - 1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
typedef pair<int,int> P;

int n;
ll l[100001],r[100001];
multiset<ll> L, R;

int main()
{
	n = read();
	rep(i, 1, n)
		scanf("%lld%lld",&l[i],&r[i]);

	L.insert( - 1LL << 60);
	R.insert(1LL << 60);
	ll ol = 0, Or = 0;
	ll res = 0;
	rep(i, 1, n)
	{
		if(i > 0) ol  -= r[i] - l[i], Or += r[i - 1] - l[i - 1];
		if(l[i] < *L.rbegin() + ol) res += *L.rbegin() + ol - l[i];
		else if(*R.begin() + Or < l[i]) res += l[i] - (*R.begin() + Or);
		if(l[i]<*L.rbegin() + ol)
		{
			R.insert(*L.rbegin() + ol - Or);
			L.insert(l[i] - ol);
			L.insert(l[i] - ol);
			L.erase(L.find(*L.rbegin()));
		}
		else if(*R.begin() + Or < l[i])
		{
			L.insert(*R.begin() + Or - ol);
			R.insert(l[i] - Or);
			R.insert(l[i] - Or);
			R.erase(R.begin());
		}
		else
		{
			L.insert(l[i] - ol);
			R.insert(l[i] - Or);
		}
	}
	printf("%lld\n",res);
	return 0;
}


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

int a[1000000];
int main()
{
    int h,w;
    int n;
    cin>>h>>w;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int cnt=1;
    int b[105][105];
    for(int i=1;i<=h;i++)
    {
        if(i&1)
        {

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


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            boolean ok = true;
            for (int i = 0; i < n; i++) {
                int cur = in.nextInt();
                if (cur % 2 == 0) {
                    if (!(cur % 3 == 0 || cur % 5 == 0)) {
                        ok = false;
                    }
                }
            }
            if (ok) {
                out.println("APPROVED");
            } else {
                out.println("DENIED");
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 24788
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


// ローリングハッシュ
struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }
};

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

    int n; cin >> n;
    string S; cin >> S;

    RollingHash rh(S);

    auto check = [&](int d)->bool{
        map<pair<ll, ll>, int> mp;
        for(int i=0; i+d<=n; ++i){
            auto p=rh.get(i, i+d);
            if(mp.count(p)){
                if(i-mp[p]>=d) return true;
            }
            else mp[p]=i;
        }
        return false;
    };

    int left=0, right=n/2+2;
    while(right-left>1){
        int mid=(left+right)/2;
        if(check(mid)) left=mid;
        else right=mid;
    }

    cout << left << endl;
    
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    long long int sum=0;
    int d[100001];
    for(int i=0;i<=100000;i++)
    d[i]=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	d[a[i]]++;
    	sum+=a[i];
	}
	cin>>q;
	while(q--)
	{
		int b,c;
		cin>>b>>c;
		sum=sum+(c-b)*d[b];
		d[c]+=d[b];
		d[b]=0;
		cout<<sum<<"\n";
	}
}


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





int main()
{
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);*/

    long long int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;


    cin>>a>>b>>c>>d>>e;
    if(a==0)
        cout<<"1\n";
    else if(b==0)
        cout<<"2\n";
    else if(c==0)
        cout<<"3\n";
    else if(d==0)
        cout<<"4\n";
    else
        cout<<"5\n";



    return 0;


}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int N,ans=0;
  cin>>N;
  vector<int> C(N),V(N);
  for(int i=0;i<N;i++){
    cin>>V[i];
  }
  for(int i=0;i<N;i++){
    cin>>C[i];
  }
  for(int i=0;i<N;i++){
    if(V[i]>C[i])ans+=V[i]-C[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

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

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

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,a[3005];
ll dp[3005][3005];
//<<-----Implement Functions Here---->>//
ll solve(ll be,ll en,ll co)
{
	if(be>en)return 0;
	else if(dp[be][en]!=-1)return dp[be][en];
	dp[be][en] = max(a[be]+solve(be+1,en,co+1),a[en]+solve(be,en-1,co+1));
	if(co&1)
	{
		dp[be][en] = max(a[be]+solve(be+1,en,co+1),a[en]+solve(be,en-1,co+1));
	}
	else dp[be][en] = min(solve(be+1,en,co+1),solve(be,en-1,co+1));
	return dp[be][en];
}
//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n;mset(dp,-1);ll sum = 0;
		for(ll i=0;i<n;i++){cin>>a[i];sum+=a[i];}
		ll h = solve(0,n-1,1);
		cout<<h-(sum-h);
       
		
}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

  
}

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

pair<int,string>p[1000000];
vector<string>vs;
vector<string>vs2;
set<string>st;
set<string>::iterator it;
char str[100000];

int main()
{
    int t,i,c=0,cnt=1;
    string s;
    cin>>t;
    getchar();
    while(t--)
    {
        cin>>s;
        vs.push_back(s);
    }
    sort(vs.begin(),vs.end());
    for(i=0; i<vs.size()-1; i++)
    {
        if(vs[i]==vs[i+1])
            cnt++;
        else
        {
            p[c].first=cnt;
            p[c].second=vs[i];
            c++;
            cnt=1;
        }
    }
    //if(cnt!=1)
    //{
        p[c].first=cnt;
            p[c].second=vs[vs.size()-1];
            c++;
    //}
    sort(p,p+c);
    int a=p[c-1].first;
    for(i=0; i<c; i++)
    {
        if(a==p[i].first)
            st.insert(p[i].second);
    }
    //sort(st.begin(),st.end());
    for(it=st.begin(); it!=st.end(); it++)
        cout<<*it<<endl;
}


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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(b<=c){
    cout<<0<<endl;
  }
  else if(d<=a){
    cout<<0<<endl;
  }
  else{
    cout<<min(b,d)-max(a,c)<<endl;
  }
}
    


Measured memory_bytes: 256
import sys
#from me.io import dup_file_stdin

def gcd(x,y):
    t = x % y
    if(t==0):
        return y
    else:
        return gcd(y, t)

#@dup_file_stdin
def solve():
    for line in sys.stdin:
        x,y = map(int,line.split(" "))
        f = gcd(x,y)
        print("{} {}".format(f, x//f*y))
 
solve()
        

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int ans = 0;
  if (s == "SUN") {
    ans = 7;
  } else if (s == "MON") {
    ans = 6;
  } else if (s == "TUE") {
    ans = 5;
  } else if (s == "WED") {
    ans = 4;
  } else if (s == "THU") {
    ans = 3;
  } else if (s == "FRI") {
    ans = 2;
  } else {
    ans = 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,i,x1,y1,z1,w1,x2,y2,z2,w2,x[1000],y[1000],z[1000],w[1000];
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d %d %d %d %d %d %d %d",&x1,&y1,&z1,&w1,&x2,&y2,&z2,&w2);
			x[i]=(x1*x2)+(y1*y2*-1)+(z1*z2*-1)+(w1*w2*-1);
			y[i]=(x1*y2)+(y1*x2)+(z1*w2)+(w1*z2*-1);
			z[i]=(x1*z2)+(y1*w2*-1)+(z1*x2)+(w1*y2);
			w[i]=(x1*w2)+(y1*z2)+(z1*y2*-1)+(w1*x2);
		}
		for(i=0;i<n;i++){
			printf("%d %d %d %d\n",x[i],y[i],z[i],w[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll N,K;
    cin >> N >> K;
    ll cnt = 0;
    map<ll,ll> mp;
    for (ll i = 0;i<K;i++) {
        ll d;
        cin >> d;
        for (ll j = 0;j<d;j++) {
            ll a;
            cin >> a;
            if (mp[a] == 0) {
                mp[a]++;
                cnt++;
            }
        }
    }
    cout << N-cnt << endl;

}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void) {
	int i,t[4],n[4];
	for(i=0;i<4;i++){
		scanf("%d %d",&t[i],&n[i]);
	}
	int a;
	for(i=0;i<4;i++){
		if(t[i]==1){
			a=6000*n[i];
			printf("%d\n",a);
		}
		else if(t[i]==2){
			a=4000*n[i];
			printf("%d\n",a);
		}
		else if(t[i]==3){
			a=3000*n[i];
			printf("%d\n",a);
		}
		else{
			a=2000*n[i];
			printf("%d\n",a);
		}
	}
	return 0;
}


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

typedef signed long long ll;
const int N = 1e5 + 5;
char S[N];

int main() {
	int n, tot = 0;
	scanf("%d %s", &n, S);
	for(int i = 0; i < n; i++) {
		if((i - 1) >= 0 && S[i] == S[i - 1]) {
			
		} else {
			tot++;
		}
	}
	printf("%d\n", tot);
	return 0;
}

Measured memory_bytes: 384
s = int(input())

x0, y0 = 0, 0

ans = int(s**0.5) + 1
x1 = min(ans, 10**9)
y2 = min(ans, 10**9)


while True:
    tmp = x1*y2 - s
    cnt = 1
    while True:
        if tmp != 0 and tmp % 2 == 0:
            cnt *= 2
            tmp = tmp // 2
        else:
            a = cnt
            b = tmp
            if a <= 10**9 and b <= 10**9: 
                x2 = a
                y1 = b
                print(x0,y0,x1,y1,x2,y2)
                exit()
            else:
                x1 -= 1
                break
                

 


Measured memory_bytes: 38384
N, K = map(int, input().split())
A = sorted([int(i) for i in input().split()])
F = sorted([int(i) for i in input().split()], reverse=True)

if sum(A) <= K:
    print(0)
    exit()
else:
    OK = 10**12
    NG = 0

    while OK-NG > 1:
        mid = (OK+NG)//2
        cnt = 0

        for i, a in enumerate(A):
            cnt += max(0, a-mid//F[i])
        if cnt <= K:
            OK = mid
        else:
            NG = mid

print(OK)


Measured memory_bytes: 122828
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/8/ALDS1_8_A
# 次への伏線みたいなもの
# ここらへんはもうひたすら実装するだけ
import sys
sys.setrecursionlimit(2**20)  # 再帰回数上限の向上 かなり多くしないとREになる


class Node:
    def __init__(self,
                 parent=None,
                 left=None,
                 right=None):
        self.parent = parent
        self.left = left  # 左の子ノード
        self.right = right  # 右の**子**


def pre_parse(T: dict, u: int, pre_ls: list):
    # 深さ優先探索特有の即時終了条件
    if u == None:
        return
    pre_ls.append(u)
    pre_parse(T, T[u].left, pre_ls)  # より左の方から深さ優先探索
    pre_parse(T, T[u].right, pre_ls)


def in_parse(T, u, in_ls):
    if u == None:
        return
    # 左→中→右っていうちょっと気持ち悪い順番
    in_parse(T, T[u].left, in_ls)
    in_ls.append(u)
    in_parse(T, T[u].right, in_ls)


def insert(T, ROOT, z):
    '''
    zは接点番号(そしてその接点番号が内容でもある)
    この接点番号を二分探索木の条件に従うように挿入する。
    '''
    # もしTが空だった場合(最初の一回しか発動されない)
    if ROOT == z:
        T[z] = Node()
    # もしTにいくつか入っていた場合
    else:
        T[z] = Node()  # 初期化
        x = ROOT
        while x is not None:  # 子がNoneになったらbreakする
            next_parent = x  # 次のループではxの親になる。whileから抜けたときに使用する
            if z < x:  # もし新たなノードが現在のノードよりも小さければ左に移動する
                x = T[x].left
            else:
                x = T[x].right
        T[z].parent = next_parent
        # 親の右と左どっちにつける？
        if z < next_parent:
            T[next_parent].left = z
        else:
            T[next_parent].right = z


def print_result(T):
    pre_ls, in_ls = [], []
    in_parse(T, ROOT, in_ls)
    pre_parse(T, ROOT, pre_ls)
    print('', *in_ls)
    print('', *pre_ls)


    # データの読み込み
N = int(input())
T = {}
for i in range(N):
    tmp = input()
    if tmp.startswith('print'):
        print_result(T)
    else:
        if len(tmp.split()) == 1:
            raise ValueError(tmp)
        command, z = tmp.split()[0], tmp.split()[1]
        z = int(z)
        if i == 0:
            ROOT = z
        insert(T, ROOT, z)



Measured memory_bytes: 140988
import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
     public static void main(String[]args)throws IOException
     {
           BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
           String s = br.readLine();
           Map<Character,Integer> map = new HashMap<Character,Integer>();
            map.put('A',0);
            map.put('B',0);
           for(int i=0;i<3;i++)
           {
                char ch = s.charAt(i);
                if(ch=='A')
                {
                      int value=map.get('A');
                      value++;
                      map.put('A',value);
                }
                else
                {
                      int value=map.get('B');
                       value++;
                      map.put('B',value);
                }
           }
           if(map.get('A')==3 || map.get('B')==3)
           {
                System.out.println("No");
           }
           else
           {
                System.out.println("Yes");
           }
     }
}
             

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}
 
ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}
 
 
int main() {
    int n,m;
    cin >> n >> m;
    map<int,int> mp;
    vector<int> S(m);
    vector<char> C(m);
    int s;
    char c;
    rep(i,m) {
        cin >> S[i] >> C[i];
    }
    if (n==1 && m==0) {
        cout << 0 << "\n";
        return 0;
    }
    for(int i=0; i<=999; ++i) {
        string ss = to_string(i);
        int cnt = 0;
        rep(j,m) {
            if (ss[S[j]-1] == C[j]) {
                cnt++;
            }
        }
        if (ss.size() == n && cnt==m) {
            cout << ss << "\n";
            return 0;
        }
    }
    cout << -1 << "\n";
    

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	int p=k;
	for(int i=0;i<=k/10000;i++){
		for(int j=0;j<=k/5000;j++){
			int l=n-i-j;
			if(k==i*10000+j*5000+l*1000&&l>=0){
				cout<<i<<" "<<j<<" "<<l<<endl;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def solve(X, Y):
    if X % Y == 0:
        return -1
    else:
        return X


def main():
    inputs = sys.stdin.readlines()
    inputs = [s.rstrip('\n').lstrip(' ') for s in inputs]

    X, Y = tuple(map(int, inputs[0].split()))

    print(solve(X, Y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
<?php
fscanf(STDIN, "%d %d", $N, $Y);

for ($k10 = 0; $k10 * 10000 <= $Y; $k10++) {
    for ($k5 = 0; $k10 * 10000 + $k5 * 5000 <= $Y; $k5++) {
        $k1 = ($Y - $k10 * 10000 - $k5 * 5000) / 1000;
        // printf("k10:%d k5:%d k1:%d\n", $k10, $k5, $k1);
        if ($k10 + $k5 + $k1 == $N) {
            echo "{$k10} {$k5} {$k1}" . PHP_EOL;
            exit;
        }
    }
}
echo "-1 -1 -1" . PHP_EOL;


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

int main(){
	int hill;
	int tops[3] = {0};
	for(int i = 0; i < 10; i++){
		cin >> hill;
		int j;
		for(j = 0; j < 3; j++){
			if(tops[j] < hill){
				for(int k = 2; k > j; k--){
					tops[k] = tops[k - 1];
				}
				tops[j] = hill;
				break;
			}
		}
	}
	for(int i = 0; i < 3; i++){
		cout << tops[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3080
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){

    string s, t;
    cin >> s >> t;
    int count = 0;

    for(int i=0; i<3; i++){
        if(s[i]==t[i]){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int n;
	cin >> n;
	int arr[n];
	for(int i =0 ;i < n; i++){
		cin >> arr[i];
	}

	int count = 0;

	for(int i = 1; i < n-1; i++){
		if(arr[i] > arr[i-1] && arr[i] < arr[i+1])
			count++;
		if(arr[i] < arr[i-1] && arr[i] > arr[i+1])
			count++;
	}	

	cout << count << endl;




	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	int m;
	cin >> m;
	while (m--)
	{
		string s;
		cin >> s;

		set<string> used;
		int res = 0;
		for (int i = 1; i < s.size(); ++i)
		{
			string a[2], b[2];
			a[0] = s.substr(0, i), b[0] = s.substr(i);
			a[1] = a[0], b[1] = b[0];
			reverse(all(a[1]));
			reverse(all(b[1]));

			for (int j = 0; j < 2; ++j)
			{
				for (int k = 0; k < 2; ++k)
				{
					string c = a[j], d = b[k];
					for (int l = 0; l < 2; ++l)
					{
						string cat = c + d;
						if (!used.count(cat))
						{
							++res;
							used.insert(cat);
						}
						swap(c, d);
					}
				}
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1004
#include <bits/stdc++.h>
#define mst(a,b)    memset((a),(b), sizeof a)
#define lowbit(a)   ((a)&(-a))
#define IOS         ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e5+100;
int t[maxn],x[maxn],y[maxn];
int main(){
#ifdef local
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
    int n;scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d%d%d",&t[i],&x[i],&y[i]);
    bool ok=true;
    for(int i=1;i<=n;++i){
        int di=t[i]-t[i-1];
        int k=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
        if(di<k||(di-k)&1){
            ok=false;break;
        }
    }
    if(ok)printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 1408