akhauriyash/Code-Regression huggingface dataset:
def selection_sort(arr, n):
    count = 0
    for i in range(n):  # 0からn−1まで
        min_idx = i
        for j in range(i, n):
            if arr[j] < arr[min_idx]:
                min_idx = j
        if i != min_idx:
            arr[i], arr[min_idx] = arr[min_idx], arr[i]
            count += 1
    return arr, count


def main():
    n = int(input())
    arr = list(map(int, input().split()))
    # n = 6
    # arr = [5, 6, 4, 2, 1, 3]
    arr, count = selection_sort(arr, n)
    print(" ".join(map(str, arr)))
    print(count)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    int x, y;
    cin >> x >> y;
    string u;
    cin >> u;
    if (u == s)
        x--;
    else
        y--;
    cout << x << " " << y;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, c, dp[1001][1001];
size_t a, b;
string s, t;
int main() {
	cin >> s >> t;
	a = s.length(), b = t.length();
	for (int i = 1; i <= a; ++i) dp[i][0] = i;
	for (int i = 1; i <= b; ++i) dp[0][i] = i;
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < b; ++j) {
			if (s[i]==t[j]) c = 0; else c = 1;
			dp[i+1][j+1] = min(dp[i][j+1]+1, min(dp[i+1][j]+1, dp[i][j]+c));
		}
	}
	cout << dp[a][b] << "\n";
}

Measured memory_bytes: 7108
N=int(input())
K=int(input())

S=str(N)
l=len(S)

dp=[[[0]*4 for __ in range(2)] for _ in range(l)]
dp[0][0][1]=1
dp[0][1][0]=1
dp[0][1][1]=int(S[0])-1

for i in range(1, l):
  if S[i]=='0':
    for k in range(1, 4):
      dp[i][0][k]=dp[i-1][0][k]
      dp[i][1][k]=dp[i-1][1][k]+dp[i-1][1][k-1]*9
    dp[i][1][0]=dp[i-1][1][0]
  else:
    dp[i][0][2]=dp[i-1][0][1]
    dp[i][0][3]=dp[i-1][0][2]
    dp[i][1][0]=1
    dp[i][1][1]=dp[i-1][1][1]+dp[i-1][1][0]*9+dp[i-1][0][1]
    dp[i][1][2]=dp[i-1][1][2]+dp[i-1][1][1]*9+dp[i-1][0][2]+dp[i-1][0][1]*(int(S[i])-1)
    dp[i][1][3]=dp[i-1][1][3]+dp[i-1][1][2]*9+dp[i-1][0][3]+dp[i-1][0][2]*(int(S[i])-1)
    
print(dp[-1][0][K]+dp[-1][1][K])

Measured memory_bytes: 3192
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int K,N;cin>>K>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int m=0;
  for(int i=0;i<N-1;i++){
    m=max(m,A[i+1]-A[i]);
  }
  m=max(m,K-A[N-1]+A[0]);
  cout<<K-m<<endl;
  return 0;
}

Measured memory_bytes: 1152
from collections import deque


def main():
    stack = deque()
    diagram = input()
    square = []

    for index, value in enumerate(diagram):
        if value == '\\':
            stack.append(-index)
        elif value == '/':
            if len(stack) > 0:
                tmp = []
                while True:
                    tmp.append(stack.pop())
                    if tmp[-1] <= 0:
                        stack.append(sum(tmp[:-1]) + index + tmp[-1])
                        break
                if len(stack) == 1:
                    square.append(stack.pop())
    square.extend([i for i in stack if i > 0])

    print(sum(square))
    if sum(square) == 0:
        print(0)
    else:
        print('{} {}'.format(len(square), ' '.join([str(i) for i in square])))


if __name__ == '__main__':
    main()



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

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

	    
      long long n,i,j,k,sum=0,count=0,ans=0,x=0,y=0,l,r;
      string s,t;
      cin>>s>>t;
      n=s.length();
      for(i=0;i<n;i++)
      {
          if(s[i]!=t[i])
          count++;
      }
      cout<<count;
	return 0;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b,c;
  cin>>a>>b>>c;
 if(a*a+b*b+c*c-2*a*b-2*b*c-2*c*a>0&&c-a-b>0){
cout<<"Yes"<<endl;
 }
else{
cout<<"No"<<endl;
}
  return 0;
}


Measured memory_bytes: 256
a,b,c,k=map(int,open(0).read().split())
import sys
count=0
while b<=a:
    b*=2
    count+=1
    if count>k:
        print('No')
        sys.exit()
while c<=b:
    c*=2
    count+=1
    if count>k:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 9188
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		
		List<List<Queri>> qss=new ArrayList<>();
		for(int i=0;i<=n;i++){
			qss.add(new ArrayList<Queri>());
		}
		
		int[] a=new int[m];
		int[] b=new int[m];
		for(int i=0;i<m;i++){
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			qss.get(b[i]-1).add(new Queri(a[i],b[i]));
		}
		int cnt=0;
		for(int i=1;i<n;i++){
			for(int j=qss.get(i).size()-1;j>=0;j--){
				Queri q=qss.get(i).get(j);
//				System.out.println(""+q.a+q.b+q.ext);
				if(q.ext){
					for(List<Queri> qs:qss){
						for(Queri q2:qs){
							q2.cut(i);
						}
					}
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	}
}
 
class Queri{
	Queri(int a,int b){
		this.a=a;
		this.b=b;
	}
	int a;
	int b;
	boolean ext=true;
	void cut(int c){
//		System.out.println("cut"+c);
		if(a<=c&&c<b){
			ext=false;
		}
	}
}

Measured memory_bytes: 347576
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
MAX_N = 2 * 10**6 + 10

# Construct factorial table
fac = [1] + [0] * MAX_N
for i in range(1, MAX_N+1):
    fac[i] = fac[i-1] * (i) % MOD

fac_inv = [1] + [0] * MAX_N
# Femrmat's little theorem says a**(p-1) mod p == 1
# then, a * a**(p-2) mod p == 1
# it means that a**(p-2) is the inverse element
# Here, Get 1 / n! first
fac_inv[MAX_N] = pow(fac[MAX_N], MOD-2, MOD)
for i in range(MAX_N, 1, -1):
    fac_inv[i-1] = fac_inv[i] * i % MOD

def mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD

k = int(input())
s = input().rstrip()
n = len(s)

ans = 0
for i in range(n, k + n + 1):
    ret = mod_nCr(i-1, n-1) * pow(25, i - n, MOD) * pow(26, k + n - i, MOD)
    ans += ret
    ans %= MOD
print(ans)

Measured memory_bytes: 153964
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

bool comp(const string& i, const string& j){
	return (i > j);
}
int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n, ans = 0;
	cin >> n;
	vector<int> v(n);
	vector<int> c(n);
	rep(i,n) cin >> v[i];
	rep(i,n) cin >> c[i];
	rep(i,n){
		if(v[i] - c[i] > 0) ans += (v[i] - c[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
class kawaii{
	#define boi(X)(X&-X)
	public:
	kawaii(int N=0){
	poldo.resize(N+1,0);	
	};
	long long int qry(int pos){
		long long int x=-1;
		for(;pos>0;pos-=boi(pos)){
			x=max(x,poldo[pos]);
		}
		return x;
	}
	void upd(int pos,long long int val){
		for(;pos<poldo.size();pos+=boi(pos)){
			poldo[pos]=max(poldo[pos],val);
		}
	}
	private:
		vector<long long int>poldo;
};
int main()
{
	#ifdef EVAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int N;
	cin>>N;
	kawaii kono(200002);
	long long int h[N],vet[N];
	for(int i=0;i<N;i++){
		cin>>h[i];
	}
	for(int i=0;i<N;i++){
		cin>>vet[i];
	}
	long long int sol=-1;
	for(int i=0;i<N;i++){
		kono.upd(h[i],kono.qry(h[i])+vet[i]);
		sol=max(kono.qry(h[i]),sol);
	}
	cout<<sol;
}

Measured memory_bytes: 4992
#include<iostream>
#include<queue>

int n;
int a, b;
int c;
int ans;
std::priority_queue<int> p, q;

int main()
{
	std::cin >> n;
	std::cin >> a >> b;
	std::cin >> c;
	for( int i = 0; i < n; i++ ){
		int d;
		std::cin >> d;
		p.push( d );
	}
	
	q = p;
	
	for( int k = 0; k <= n; k++ ){
		int s = c;
		for( int i = 0; i < k; i++ ){
			s += q.top(); q.pop();
		}
		ans = std::max( ans, s / ( a + b * k ) );
		q = p;
	}
	
	std::cout << ans << std::endl;

 	return 0;
}

Measured memory_bytes: 1220
import java.util.*;
     
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n = sc.nextInt();
    		int[] a = new int[n];
    		for(int i = 0; i < n; i++)
    			a[i] = sc.nextInt();
    		int min = a[0];
    		int max = a[0];
    		for(int i = 1; i < n; i++) {
    			if(a[i] < min)
    				min = a[i];
    			else if(a[i] > max)
    				max = a[i];
    		}
    		boolean[] hash = new boolean[max - min + 1];
    		for(int i = 0; i < hash.length; i++)
    			hash[i] = false;
    		int identity = 0;
    		for(int i = 0; i < n; i++) {
    			if(!hash[a[i] - min]) {
    				identity++;
    				hash[a[i] - min] = true;
    			}
    		}
    		System.out.println(String.valueOf(identity - ((identity + 1)%2)));
    	}
    }

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

int main()
{
	string s;
	stack<char>st;
	cin>>s;
	string s2 = "";
	for(ll i  = 0 ; i<s.length();i++)
	{
		if(s[i] == 'B' and !s2.empty())
		{
			s2.pop_back();
		}
		if(s[i]!= 'B')s2+=s[i];
	}
	cout<<s2<<endl;
}


Measured memory_bytes: 3632
// ※※※ 解答不能 ※※※
// MMNMM氏
// https://atcoder.jp/contests/agc039/submissions/7879606
#include <bits/stdc++.h>
#include <boost/math/constants/constants.hpp>

int main(){
    using namespace std;
    constexpr double pi = boost::math::constants::pi<double>();
    unsigned long N, L;
    cin >> N >> L;
    vector<unsigned long> T(N);
    copy_n(istream_iterator<unsigned long>(cin), N, T.begin());
    double x{0}, y{0};
    vector<double> C(N), S(N);
    transform(T.begin(), T.end(), C.begin(), [&pi, &L](auto t){return cos(pi * t / L);});
    transform(T.begin(), T.end(), S.begin(), [&pi, &L](auto t){return sin(pi * t / L);});
    for(long i = 1; i < N; ++i)for(long j = 0; j < i; ++j){
        long t = N + 2 * (j - i);
        x += t * (C[i] * C[j] - S[i] * S[j]);
        y += t * (C[i] * S[j] + C[j] * S[i]);
    }
    unsigned long t = N * (N - 1) * (N - 2) / 6;
    x /= t;
    y /= t;
    cout << setprecision(15) << fixed;
    cout << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var C = cin.ReadInt;
            var X = cin.ReadInt;
            int ans = 0;
            for (int a = 0; a <= A; a++)
            {
                for (int b = 0; b <= B; b++)
                {
                    for (int c = 0; c <= C; c++)
                    {
                        int total = 500 * a + 100 * b + 50 * c;
                        if (total == X) { ++ans; }
                    }
                }
            }
            WriteLine(ans);

        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13268
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var num = cin.ReadInt;
            var solved = cin.ReadInt;
            if (num == solved) WriteLine("Yes");
            else WriteLine("No");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
#include <stdio.h>

int main(void){
 int k[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int a;
  scanf("%d", &a);
  printf("%d", k[a-1]);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))




signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n + 1), b(n); rep(i, n + 1)cin >> a[i];
	rep(i, n)cin >> b[i];
	int ans = 0;
	rep(i, n) {
		if (a[i] <= b[i]) {
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
		}
		else {
			ans += b[i];
			continue;
		}
		if (a[i + 1] <= b[i]) {
			ans += a[i + 1];
			b[i] -= a[i + 1];
			a[i + 1] = 0;
		}
		else {
			ans += b[i];
			a[i + 1] -= b[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
A = []
B = []
for i in range(n):
    A.append(a[i][0])
    B.append(a[i][1])
A = sorted(A)
B = sorted(B)
if n%2 == 0:
    ca = (A[int((n/2)-1)] + A[int(n/2)]) / 2
    cb = (B[int((n/2)-1)] + B[int(n/2)]) / 2
    ans = (cb - ca) * 2 + 1
else:
    ca = A[int(((n+1)//2)-1)]
    cb = B[int(((n+1)//2)-1)]
    ans = (cb - ca) + 1
print(int(ans))

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

int32_t main() {
	
	int n;	cin >> n;
	int a[n+1] , ans[n+1];
	for(int x=1;x<=n;x++)	cin >> a[x];
	
	for(int x=1;x<=n;x++){
		ans[a[x]] = x;
	}
	
	for(int x=1;x<=n;x++)
		cout << ans[x] << " ";
	
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::greater<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  cin >> n >> m;
  string a = to_string(n), b = to_string(m);
  string s, t;
  for (int i = 0; i < m; ++i) {
    s += a;
  }
  for (int i = 0; i < n; ++i) {
    t += b;
  }
  cout << min(s, t) << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int main() {
    // string s[2];
    // cin >> s[0] >> s[1];
    // cout << (s[0][0] == s[1][2] && s[0][1] == s[1][1] && s[0][2] == s[1][0] ? "YES" : "NO") << endl;
 
    int n;
    cin >> n;
    int x = sqrt(n);
    cout << x * x << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N, D;
	cin >> N >> D;

	int k = 1 + D * 2;

	int ans = N / k;

	if (N % k != 0) {
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
    int value;
    char mark;
}CARD;

void bubbleSort(CARD c[],int N){
    int i,j;
    int v;
    char m;
    for(i=0;i<N;i++){
        for(j=N-1;j>=i+1;j--){
            if(c[j].value<c[j-1].value){
                v=c[j].value;
                c[j].value=c[j-1].value;
                c[j-1].value=v;
                m=c[j].mark;
                c[j].mark=c[j-1].mark;
                c[j-1].mark=m;
            }
        }
    }
}
void selectionSort(CARD c[],int N){
    int i,j;
    int minj;
    int v;
    char m;
    for(i=0;i<N;i++){
        minj=i;
        for(j=i+1;j<N;j++){
            if(c[j].value<c[minj].value)minj=j;
        }
        v=c[i].value;
        c[i].value=c[minj].value;
        c[minj].value=v;
        m=c[i].mark;
        c[i].mark=c[minj].mark;
        c[minj].mark=m;
    }
}
void checkStable(CARD c[],CARD o[],int N){
    int i,j;
    char flag[N];
    for(i=0;i<N;i++)flag[i]='n';
    
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(c[i].value==o[j].value&&flag[j]=='n'){
                if(c[i].mark!=o[j].mark){
                    printf("Not stable\n");
                    return;
                }
                flag[j]='y';
                break;
            }
        }
    }
    printf("Stable\n");
}
int main(void){
    int i;
    
    int N;
    scanf("%d",&N);
    CARD o[N],c1[N],c2[N];
    for(i=0;i<N;i++){
        scanf("\n%c%d ",&o[i].mark,&o[i].value);
        c1[i].mark=o[i].mark;
        c1[i].value=o[i].value;
        c2[i].mark=o[i].mark;
        c2[i].value=o[i].value;
    }
    
    bubbleSort(c1,N);
    printf("%c%d",c1[0].mark,c1[0].value);
    for(i=1;i<N;i++)printf(" %c%d",c1[i].mark,c1[i].value);
    printf("\n");
    checkStable(c1,o,N);
    
    selectionSort(c2,N);
    printf("%c%d",c2[0].mark,c2[0].value);
    for(i=1;i<N;i++)printf(" %c%d",c2[i].mark,c2[i].value);
    printf("\n");
    checkStable(c2,o,N);
    
    
    return 0;
}


Measured memory_bytes: 2044
N = int(input())
As = list(map(int, input().split()))
As.sort(reverse=True)

i_plus = 0
# 最後のプラスになるタイミングを持っておく
plusflg = True
for i,A in enumerate(As):
    if A < 0:
        i_plus = i
        plusflg = False
        break

if plusflg:
    i_plus = N-1

ans = sum(As)
for i,A in enumerate(As[::-1]):
    if i == N-1:
        continue
    elif i == 0 or A < 0:
        ans -= 2*A
print(ans)

now = As[-1]
for i,A in enumerate(As[:-1]):
    if i+1 < i_plus:
        print(now,A)
        now -= A
    elif i+1 == i_plus:
        print(A, now)
        now = (A-now)
    else:
        print(max(A,now),min(A,now))        
        now = max(A,now)-min(A,now)


Measured memory_bytes: 14016
s = input()

def is_palindrome(s):
    return s == s[::-1]

n = len(s)
#print(len(s))

if is_palindrome(s) and is_palindrome(s[:(n - 1) // 2]) and is_palindrome(s[(n + 3) // 2 - 1]):
    print("Yes")
else:
    print("No")
    

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

int main(){
    int n; cin >> n;
    int sum = 0;
    vector<int> value(n);
    vector<int> cost(n);
    rep(i,n) cin >> value[i];
    rep(i,n) cin >> cost[i];
    rep(i, n){
        if(value[i] > cost[i]){
            sum += value[i] - cost[i];
        }
    }
    cout << sum << endl;;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))
c = 0
List = []
check = [-1]*N
tmp = 1
for i in range(min(N+1,K)):
    tmp2 = A[tmp-1]
    List.append(tmp2)
    if(check[tmp2-1] >= 0):
        tmp3 = check[tmp2-1]
        del List[-1]
        break
    else:
        check[tmp2-1] = i
        tmp = tmp2
        c += 1
if(c >= K):
    print(List[K-1])
else:
    List2 = List[tmp3:]
    if(c == len(List2)):
        print(List2[(K%len(List2))-1])
    else:
        K -= c
        print(List2[(K%len(List2))-1])

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

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

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

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

     for(int i=0;i<n;i++){
        cout << s[i];
     }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;

public class Main {
    public static void main(String args[]) {
        int a, b, c, k;
        int max = 0;
        int sum = 0;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        k = sc.nextInt();

        int[] array = {a,b,c};
        for (int i = 1; i <= k; i++) {
            for (int j = 0; j < array.length; j++) {
                max = Math.max(max,array[j]);
            }
            for (int j = 0; j < array.length; j++) {
                if (max == array[j]) {
                    array[j] *= 2;
                    break;
                }
            }
        }
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 21588
city = Array.new(4, 0)

3.times do
    line = gets.chomp.split(" ").map(&:to_i)
    city[line[0] - 1] += 1
    city[line[1] - 1] += 1
end

flag = false
city.each do |num|
    flag = true if num % 2 ==0
end

puts flag ? "YES" : "NO"


Measured memory_bytes: 1788
import sys
from collections import Counter
N = int(input())
D = Counter([int(c) for c in input().split()])
M = int(input())
T = Counter([int(c) for c in input().split()])
for t in T.items():
  if D[t[0]] < t[1]:
    print('NO')
    sys.exit()
print('YES')

Measured memory_bytes: 55264
#include <iostream>
//#include <utility>
//#define int long long
//#define _DEBUG
#define m_v 1000
using namespace std;
int gx, gy, p, T[m_v][m_v];
//pair<pair<int,int>,pair<int,int>> m[m_v];
struct _line{
    int x1;
    int y1;
    int x2;
    int y2;
};
struct _line m[m_v];
bool mH[m_v][m_v], mV[m_v][m_v];
int solve(){
    for(int y=0; y<=gy; y++){
        for(int x=0; x<=gx; x++){
            if(x==0 && y==0){
                T[0][0] = 1;
            }else if((x==0 || mH[x-1][y]) && (y==0 || mV[x][y-1])){
                T[x][y] = 0;
            }else if(x==0 || mH[x-1][y]){
                T[x][y] = T[x][y-1];
            }else if(y==0 || mV[x][y-1]){
                T[x][y] = T[x-1][y];
            }else{// if(x>0 && y>0 && !mV[x-1][y] && !mH[x][y-1]){
                T[x][y] = T[x-1][y] + T[x][y-1];
            }
        }
    }
#ifdef _DEBUG
    for(int y=0; y<=gy; y++){
        for(int x=0; x<=gx; x++){
            cout << T[x][y] << " ";
        }
        cout << endl;
    }
    for(int y=0; y<=gy; y++){
        for(int x=0; x<=gx; x++){
            cout << ((mV[x][y])?"x":"0") << " ";
        }
        cout << endl;
    }
    for(int y=0; y<=gy; y++){
        for(int x=0; x<=gx; x++){
            cout << ((mH[x][y])?"x":"0" )<< " ";
        }
        cout << endl;
    }
    
    for(int y=0; y<=gy; y++){
        for(int x=0; x<=gx; x++){
            cout << T[x][y] << " " << ((mH[x][y])?"x":" " ) << " ";
        }cout << endl;
        for(int x=0; x<=gx; x++){
            cout << ((mV[x][y])?"x":" " ) << "   ";
        }
        cout << endl;
    }

#endif
    return T[gx][gy];
}
void get(){
    cin >> gx >> gy >>p;
    for(int i=0; i<p; i++){
        cin >> m[i].x1 >> m[i].y1 >> m[i].x2 >> m[i].y2;
        if(m[i].x1 == m[i].x2){
            mV[m[i].x1][min(m[i].y1,m[i].y2)] = true;
        }else{
            mH[min(m[i].x1,m[i].x2)][m[i].y1] = true;
        }
    }
}
void clear(){
    for(int i=0; i<p; i++){
        mV[m[i].x1][min(m[i].y1,m[i].y2)] = false;
        mH[min(m[i].x1,m[i].x2)][m[i].y1] = false;
    }
    for(int y=0; y<gy; y++){
        for(int x=0; x<gx; x++){
            T[x][y] = 0;
        }
    }
}

signed main(){
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        get();
        int s = solve();
        if(s==0){
            cout << "Miserable Hokusai!" << endl;
        }else{
            cout << s << endl;
        }
        clear();
    }
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	string s; cin>>s;
	int ans = 0;
	if(s[0]=='1')ans++;
	if(s[1]=='1')ans++;
	if(s[2]=='1')ans++;
	ote(ans);
}


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

using namespace std;

typedef unsigned long long ll;

ll p[1200];
const ll P=1000000007;
class RollingHash{
public:
  ll a[1200];
  RollingHash(char *fp,int W){
    a[0]=0;
    for(int j=1;j<=W;j++)a[j]=a[j-1]*P+(fp[j-1]);
  }
  RollingHash(){};
  ll getHashValue(int x,int y){
    return a[y+1]-a[x]*p[y-x+1];
  }
};
int w,h,m;
char field[1200][1200];
char pattern[110][110];
void rotatePattern(){
  char nxtPattern[1200][1200];
  for(int i=0;i<m;i++)
    for(int j=0;j<m;j++)
      nxtPattern[i][m-1-j]=pattern[j][i];
  for(int i=0;i<m;i++)
    for(int j=0;j<m;j++)
      pattern[i][j]=nxtPattern[i][j];
}
void reversePattern(){
  char nxtPattern[1200][1200];
  for(int i=0;i<m;i++)
    for(int j=0;j<m;j++)
      nxtPattern[i][j]=pattern[i][m-1-j];
  for(int i=0;i<m;i++)
    for(int j=0;j<m;j++)
      pattern[i][j]=nxtPattern[i][j];
}
int charToInt(char ch){
  if(ch>='A'&&ch<='Z')return ch-'A';
  else if(ch>='a'&&ch<='z')return ch-'a'+26;
  else if(ch>='0'&&ch<='9')return ch-'0'+52;
  else if(ch=='+')return 62;
  return 63;
}

RollingHash patternHash[110];
RollingHash imageHash[1200];
bool used[1200][1200];
int sums[1200][1200];
int main(){
  p[0]=1;
  for(int i=1;i<1200;i++)p[i]=p[i-1]*P;
  while(cin>>w>>h>>m&&(w|h|m)){
    memset(used,0,sizeof(used));
    memset(sums,0,sizeof(sums));
    for(int i=0;i<h;i++){
      int cnt=0;
      for(int j=0;j<(w+5)/6;j++){
	char ch;
	cin>>ch;
	int a=charToInt(ch);
	string s;
	for(int k=0;k<6;k++){
	  if((a>>k)&1)s+='1';
	  else s+='0';
	}
	for(int k=0;k<s.size();k++){
	  field[i][cnt++]=s[s.size()-1-k];
	  if(cnt==w)break;
	}
      }
    }
    for(int i=0;i<m;i++){
      int cnt=0;
      for(int j=0;j<(m+5)/6;j++){
	char ch;
	cin>>ch;
	int a=charToInt(ch);
	string s;
	for(int k=0;k<6;k++){
	  if((a>>k)&1)s+='1';
	  else s+='0';
	}
	for(int k=0;k<s.size();k++){
	  pattern[i][cnt++]=s[s.size()-1-k];
	  if(cnt==m)break;
	}
      }
    }
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	sums[i+1][j+1]=sums[i][j+1]+sums[i+1][j]
	  -sums[i][j]+field[i][j]-'0';
    int patternOne=0;
    for(int i=0;i<m;i++)
      for(int j=0;j<m;j++)
	if(pattern[i][j]=='1')patternOne++;
    // imageのhash値を計算しておく
    for(int i=0;i<h;i++)imageHash[i]=RollingHash(field[i],w);
    int res=0;
    for(int rev=0;rev<2;rev++){
      for(int rot=0;rot<4;rot++){
	// rolling hashを計算
	for(int i=0;i<m;i++)patternHash[i]=RollingHash(pattern[i],m);
	// 一致する箇所を探す
	for(int i=0;i+m<=h;i++){
	  for(int j=0;j+m<=w;j++){
	    if(used[i][j])continue;
	    int cnt=sums[i+m][j+m]-sums[i+m][j]-sums[i][j+m];
	    cnt+=sums[i][j];
	    if(cnt!=patternOne)continue;
	    bool ok=true;
	    for(int k=0;k<m;k++){
	      if(!(imageHash[i+k].getHashValue(j,j+m-1)
		   ==patternHash[k].getHashValue(0,m-1))){
		ok=false;
		break;
	      }
	    }
	    if(ok){
	      res++;
	      used[i][j]=true;
	    }
	  }
	}
	rotatePattern();
      }
      reversePattern();
    }
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 19000
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
    int i,j,k, n;
    char buf[5000];
    char s[4001];
    long ans = 0;
    long all = 0;
    
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d\n", &n);
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%s\n", s);
    all = 0;
    long r=0,g=0,b=0;
    rep(i,n){
        switch(s[i]){
            case 'R':
                r++;
                break;
            case 'G':
                g++;
                break;
            case 'B':
                b++;
                break;
        }
    }
    fprintf(stderr, "%ld %ld %ld\n",r,g,b);
    all = r*g*b;
    ans = all;
    for(i=0; i<n-2; i++){
        for(j=i+1; 2*j-i<n; j++){
            k = j + j-i;
            if(s[k] != s[i] && s[k] != s[j] && s[i] != s[j]){
                --ans;
            }
        }
    }
    fprintf(stderr,"%ld %ld\n",all,ans);
    printf("%ld\n",ans);
    return 0;
}


Measured memory_bytes: 1752
#include <stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(( a==1 || a==3 || a==5 || a==7 || a==8 || a==10 || a==12) && ( b==1 || b==3 || b==5 || b==7 || b==8 || b==10 || b==12)){
        printf("Yes\n");
    }
    else if((a==4 || a==6 || a==9 || a==11 )&&(b==4 || b==6 || b==9 || b==11 )){
            printf("Yes\n");
        }
    else if(a==2 && b==2){
        printf("Yes\n");
    }
    else printf("No\n");


    return 0;
}


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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int h,w;
char a[110][110];
int main(){
  scanf("%d %d",&h,&w);
  REP(i,h) scanf("%s",a[i]);
  REP(i,w+2){
    printf("#");
  }
  printf("\n");
  REP(i,h){
    printf("#");
    printf("%s",a[i]);
    printf("#\n");
  }
  REP(i,w+2){
    printf("#");
  }
  printf("\n");
}


Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑



int n, k[55], ma, mon;
int main() {
	cin >> n;
	cout << 2 * n - 1 << endl;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
		if (i == 0) { ma = abs(k[0]); }
		else if (ma < abs(k[i])) { ma = abs(k[i]); mon = i; }
	}

	for (int i = 0; i < n; ++i) {
		k[i] += k[mon];
		cout << mon + 1 << " " << i + 1 << endl;
	}
	if (k[mon] > 0) {
		for (int i = 1; i < n; ++i) {
			cout << i << " " << i + 1 << endl;
		}
	}
	else {
		for (int i = n; i > 1; --i) {
			cout << i << " " << i - 1 << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	ll A, B, K;
	cin >> A >> B >> K;
	for(int i = 0; i < K; i ++){
		if(i % 2 == 0){
			if(A % 2 == 1)A --;
			B += A / 2;
			A /= 2;
		}
		else{
			if(B % 2 == 1)B --;
			A += B / 2;
			B /= 2;
		}
	}
	cout << A << " " << B << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if ( a+b >= a-b && a+b >= a*b)
    cout << a+b;
  else if (a-b >= a+b && a-b >= a*b)
    cout << a-b ;
  else
    cout << a*b;
    return 0;
}

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

using namespace std;

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

    int q;
    cin>>q;

    multimap<string,int> mp;
    while(q--){
        int op;
        string s;
        cin>>op>>s;
        switch(op)
        {
            case 0:
                int x;
                cin>>x;
                mp.insert(make_pair(s,x));
                break;
            case 1:

                {auto range=mp.equal_range(s);
                for(auto i=range.first;i!=range.second;i++)
                {
                    cout<<i->second<<endl;
                }}
                break;
            case 2:
                mp.erase(s);
                break;
            case 3:
                string l=s,r;
                cin>>r;
                for(auto i=mp.lower_bound(l),e=mp.upper_bound(r);i!=e;i++)
                {
                    cout<<i->first<<" "<<i->second<<endl;
                }
                break;
        }
    }

    return 0;
}






Measured memory_bytes: 24900
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))

n = int(input())
h = list(map(int, input().split()))
dp = [0 for i in range(n+1)]
dp[2] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i+1] = min(dp[i]+abs(h[i]-h[i-1]), dp[i-1]+abs(h[i]-h[i-2]))
print(dp[n])

Measured memory_bytes: 52808
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, D, A, X[201010], H[201010];
ll buf[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> D >> A;
	rep(i, 0, N) cin >> X[i] >> H[i];

	D *= 2;

	vector<pair<int, int>> xh;
	rep(i, 0, N) xh.push_back({X[i], H[i]});
	sort(all(xh));

	ll ans = 0;
	int R = 0;
	rep(L, 0, N) {
		if (L) buf[L] += buf[L - 1];

		int x = xh[L].first;
		int h = xh[L].second;

		if (buf[L] < h) {
			chmax(R, L + 1);
			while (R < N and xh[R].first - x <= D) R++;

			ll d = h - buf[L];

			ll cnt = (d + A - 1) / A;

			buf[L] += cnt * A;
			buf[R] -= cnt * A;
			ans += cnt;
		}
	}

	cout << ans << endl;
}







Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;



int main() {
    ll n; cin >> n;
    unordered_map<ll, ll> as;
    ll tot = 0;
    rep(i, n) {
        ll a;
        cin >> a;
        tot += a;
        as[a]++;
    };
    ll q; cin >> q;
    vector<ll> bs(q), cs(q);
    rep(i, q) cin >> bs[i] >> cs[i];

    rep(i, q) {
        ll b = bs[i]; ll c = cs[i];
        if (as[b] > 0) {
            tot += (c-b)*as[b];
            as[c] += as[b]; 
            as[b] = 0;
        }
        cout << tot << endl;
    }
    return 0;
}

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

int main() {
  int n,k,q;cin>>n>>k>>q;
  vector<int> a(q);
  rep(i,q)cin>>a[i];
  vector<int> ans(n);
  rep(i,q){
    ans[a[i]-1]++;
  }
  rep(i,n){
    if(q-ans[i]<k)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 4024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
typedef pair<int,int> P;
typedef pair<int,P> PP; 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1e9+7;

signed main(){
  int R,C,n;
  cin>>R>>C>>n;
  vector<P> v;
  for(int i=0;i<n;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a!=0&&a!=R)&&(b!=0&&b!=C))continue;
    if((c!=0&&c!=R)&&(d!=0&&d!=C))continue;
    int p1,p2;
    if(a==0)p1=b;
    if(a==R)p1=C+R+C-b;
    if(b==C)p1=C+a;
    if(b==0)p1=C+R+C+R-a;
    if(c==0)p2=d;
    if(c==R)p2=C+R+C-d;
    if(d==C)p2=C+c;
    if(d==0)p2=C+R+C+R-c;
    v.pb(P(p1,i));
    v.pb(P(p2,i));
  }
  if(sz(v)==0){
    cout<<"YES"<<endl;
    return 0;
  }
  sort(all(v));
  vector<bool> used(n,false);
  stack<int> st;
  for(int i=0;i<sz(v);i++){
    int x=v[i].se;
    if(used[x]){
	 if(st.top()==x)st.pop();
	 else {
	   cout<<"NO"<<endl;
	   return 0;
	 }
    }else{
	 used[x]=true;
	 st.push(x);
    }
  }
  cout<<"YES"<<endl;
  return 0;
}


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

const int N = 100010;

int n, k;
int f[N], a[N];

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for(int i = 2; i <= n; ++i) {
		f[i] = 0x3f3f3f3f;
		for(int j = max(i - k, 1); j < i; ++j) {
			f[i] = min(f[i], f[j] + abs(a[i] - a[j]));
		}
	}
	printf("%d\n", f[n]);
}

Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define LL  long long 
#define Pi 3.14159265358979;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int i = 0, j = 0;//ループ用配列
	int n,arc=0,abc=0;
	int dmax = 0,x;
	vector<int> d;
	int ans = 0;//何通り？

	cin >> n;
	rep(i,n) {
		cin >> x;
		d.push_back(x);
	}

	sort(d.begin(),d.end());
	ans = d[d.size() / 2] - d[d.size() / 2 - 1];
	cout << ans << "\n";
}


Measured memory_bytes: 892
#include<iostream>

using namespace std;

int main() {

	int A, B;
	cin >> A >> B;

	int X = A + B, Y = A - B, Z = A * B;

	if (X > Y)
		if (X > Z)
			cout << X << endl;
		else
			cout << Z << endl;
	else
		if (Y > Z)
			cout << Y << endl;
		else
			cout << Z << endl;

	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;

  string S;
  string ans;
  rep(i, H) {
    rep(j, W) {
      cin >> S;
      if (S == "snuke") {
        ans = (char)('A' + j) + to_string(i + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3664
S = list(input())
N = len(S)

def f(x):
    print(x)
    exit()

if N < 5:
    f("NO")
elif S[0] == "d":
    w = 1
elif S[0] == "e":
    w = -1
else:
    f("NO")

i = 0
while True:
    if w > 0:
        if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "dream":
            i += 5
            if i == N:
                f("YES")
            elif S[i] == "d":
                pass
            elif S[i] == "e":
                if i+1 <= N-1:
                    if S[i+1] == "r":
                        if i+1 == N-1:
                            f("YES")
                        elif S[i+2] == "a":
                            w *= -1
                        elif S[i+2] == "e":
                            i += 2
                            w *= -1
                        elif S[i+2] == "d":
                            i += 2
                        else:
                            f("NO")
                    else:
                        f("NO")
                else:
                    f("NO")
            else:
                f("NO")
        else:
            f("NO")
    elif w < 0:
        if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "erase":
            i += 5
            if i == N:
                f("YES")
            if S[i] == "r":
                i += 1
                if i == N:
                    f("YES")
            if S[i] == "d":
                w *= -1
            elif S[i] == "e":
                pass
            else:
                f("NO")
        else:
            f("NO")
    if i+4 > N-1:
        f("NO")


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

#define rep(i,beg,end)   for (auto i=(beg);i<(end);i++)
#define all(cont)           begin(cont), end(cont)
#define rall(cont)           rbegin(cont), rend(cont)
using ll = long long;
using vi = vector<ll>;
const ll INFMAX = LLONG_MAX;
const ll INFMIN = LLONG_MIN;
const ll MOD = 1000000007;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, l;
	cin >> n >> l;
	ll sum = 0;
	ll near0 = INFMAX;
	for (ll i = l; i < l+n; i++) {
		sum += i;
		if (abs(i) < abs(near0))
			near0 = i;
	}
	cout << sum-near0 << endl;
	return 0;
}


Measured memory_bytes: 256