akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;

int main()
{
    ll n, k;
    cin >> n >> k;

    ll min_val = INF;
    ll n_last = INF;
    if (n > k) {
        ll d = (n - k) / k;
        n -= k * d;
    }
    do {
        n_last = n;
        n = llabs(n - k);
    } while (n < n_last);
    cout << n_last << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
G = [1 for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] < H[B-1]:
        G[A-1] = 0
    if H[A-1] > H[B-1]:
        G[B-1] = 0
    if H[A-1] == H[B-1]:
        G[A-1] = 0
        G[B-1] = 0
print(G.count(1))

Measured memory_bytes: 20112
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
  if A[i]%4==0:
    A[i]=0
  elif A[i]%2==0:
    A[i]=2
  else:
    A[i]=1

a=A.count(0)
b=A.count(2)
c=A.count(1)
if c<=a :
  print("Yes")
elif b==0 and c==a+1:
  print("Yes")
else:
  print("No")

  


Measured memory_bytes: 14252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
//		String[] tmpArray = br.readLine().split(" ");
//		int n = Integer.parseInt(br.readLine());
//		int b = Integer.parseInt(tmpArray[1]);
//		int c = Integer.parseInt(tmpArray[2]);
//		int y = Integer.parseInt(tmpArray[3]);
//		int r = Integer.parseInt(tmpArray[4]);

//		String[] tmpArray = br.readLine().split(" ");
//		int[] input = new int[n];
//		long sum = 0;
//		for(int i = 0; i < n; i++){
//			input[i] = Integer.parseInt(tmpArray[i]);
//			sum += input[i];
//		}
//		
//		Arrays.sort(input);
//		System.out.printf("%d %d %d\n", input[0], input[input.length - 1], sum);
//		
		while(true){
			String[] tmpArray = br.readLine().split(" ");
			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);
			if(a == 0 && b == 0){
				break;
			}
			
			for(int i = 0; i < a; i++){
				for(int j = 0; j < b; j++){
					if(i != 0 && i != a - 1 && j != 0 && j != b-1){
						System.out.print(".");
					}
					else{
						System.out.print("#");
					}
				}
				System.out.println();
			}
			System.out.println();
		}

		//		int[] array = new int[3];
//		array[0] = a; array[1] = b; array[2] = c;
//
//		Arrays.sort(array);
//		System.out.printf("%d %d %d\n", array[0], array[1], array[2]);
		/*
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}*/
	}

}

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

struct BIT {
  BIT() {}
  BIT(int n) : n(n + 1), v(n + 10, vector<int>(n + 10, 0)) {}

  int n;
  vector<vector<int>> v;

  long long sum(int y, int x) {
    long long ret = 0;
    for (int i = y; i; i -= i & -i) {
      for (int j = x; j; j -= j & -j) {
        ret += v[i][j];
      }
    }

    return ret;
  }

  long long sum(int y1, int x1, int y2, int x2) {
    return sum(y1, x1) - sum(y1, x2) - sum(y2, x1) + sum(y2, x2);
  }

  void add(int y, int x) {
    for (int i = y; i <= n; i += i & -i) {
      for (int j = x; j <= n; j += j & -j) {
        v[i][j]++;
      }
    }
  }
};

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

  vector<long long> x, y, a, b;
  map<long long, int> X, Y;
  for (int i = 0; i < n; ++i) {
    int s, t;
    cin >> s >> t;
    x.push_back(s);
    y.push_back(t);
  }

  a = x;
  b = y;

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (int i = 0; i < n; ++i) {
    X[a[i]] = i + 1;
    Y[b[i]] = i + 1;
  }

  BIT bit(n);
  for (int i = 0; i < n; ++i) {
    bit.add(Y[y[i]], X[x[i]]);
  }

  long long ans = 5001001001001001001;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        for (int l = k + 1; l < n; ++l) {
          if (bit.sum(Y[b[l]], X[a[j]], Y[b[k]] - 1, X[a[i]] - 1) >= K) {
            ans = min(ans, (b[l] - b[k]) * (a[j] - a[i]));
          }
        }
      }
    }
  }

  cout << ans << endl;
}


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

const double PI = acos(-1.0);
const int N = 501;
const int MOD = 1e9 + 7;
typedef long long ll;

int a[55];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  	int a, b;
  cin>>a>>b;
  if(a < b)
    swap(a,b);
  
  if((a - b) % 2 == 0)
  {
    cout<<(a + b) / 2;
  }
  else
    cout<<"IMPOSSIBLE";


}





Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <map>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

int n;
cin >> n;

string s[100010];
ll MARCH[5] = {};

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

for(int i = 0; i<n; i++){
 switch ( s[i][0] )  {  
case 'M':  
MARCH[0]++;  
break;  
case 'A':  
MARCH[1]++;  
break;  
case 'R':  
MARCH[2]++;  
break;  
case 'C':  
MARCH[3]++;  
break;  
case 'H':  
MARCH[4]++;  
break;  
      } 
}

ll ans = 0;

for(int i = 0; i<5; i++){
 for(int j = i+1; j < 5;j++){
   for(int k = j+1; k < 5;k++){
ans += MARCH[i]* MARCH[j]* MARCH[k];
  }
 }
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 6144
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
Mod = 1000000007



def main(): #startline--------------------------------------------
    N,M = map(int,input().split())
    AB = [list(map(int,input().split())) for i in range(N)]
    heap = []
    AB.sort(key = lambda x:x[0],reverse = True)
    ans = 0
    for i in range(1,M+1):
        while AB and AB[-1][0] <= i:
            heappush(heap,-AB.pop()[1])
        if heap:
            ans -= heappop(heap)

    print(ans)
    
if __name__ == "__main__":
    main() #endline===============================================




def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Measured memory_bytes: 31188
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    
    string S;
    cin >> S;
    
    sort(S.begin(),S.end());
    S.erase(unique(S.begin(),S.end()),S.end());
    
    string AZ[27] = {"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","None"};
    
    for(int i=0;i<27;i++){
        auto search = S.find(AZ[i]);
        if(search == string::npos){
            cout << AZ[i] << endl;
            break;
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 512
#include <stdio.h>

void Mawasuyatu(int x,int y);

int main(void){
    int  a,b;
    
    scanf("%d%d",&a,&b);    
    if(a == b)
        Mawasuyatu(a,b);
    else if(a < b)
        Mawasuyatu(a,b);
    else
        Mawasuyatu(b,a);
    
    return 0;
}

void Mawasuyatu(int x,int y){
    int For;
    
    for(For=0;For<y;For++)
        printf("%d",x);
        
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
		a[i] -= i + 1;
	}
	sort(a.begin(), a.end());
	int mid = a[n / 2];
	ll ans = 0;
	rep(i, n) {
      ans += abs(a[i] - mid);
    }
	cout << ans << endl;
}


Measured memory_bytes: 1024
a, b, ab, x, y = list(map(int, input().split()))

ab1 = ab * 2
abp = a + b
mins = min(x, y)
maxs = max(x, y)
nedan = min(ab1, abp) * mins

x -= mins
y -= mins
nedan_abp = x * a + y * b
nedan_ab = (maxs - mins) * ab1

if nedan_abp > nedan_ab:
  nedan += nedan_ab
else:
  nedan += nedan_abp
  
print(nedan)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    int n,x,t;
    cin>>n>>x>>t;
    int a=n/x;
    int b;
    (n%x!=0)? b=1 : b=0;
    cout<<t*(a+b);
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	if(n == m) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define YUGEN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lp(i,start,end) for(int i=start;i<end;i++)
#define MAX 105
#define BPC(x)  __builtin_popcountll(x)
#define test() ll t; cin>>t; while(t--)
#define gcd(a,b)  __gcd(a,b)
#define SIZE 26
ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}

int main()
 {
    YUGEN;
    string s;
    cin>>s;
    int n=s.size();
    if(s[n-1]=='s')
    {
    s.append("e");
    s.append("s");
    }
    else 
    s.append("s");
    cout<<s;
    

 }




Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define l long long
int main()
{
    l n, m;
    cin>>n>>m;
    if(m>=n)
    {
        cout<<"unsafe"<<endl;

    }
    else
    {
        cout<<"safe"<<endl;

    }
    return 0;
}


Measured memory_bytes: 3636
n=int(input())
k=map(int,input().split())
k = list(k)
co=0
wa=0
while True:
    for i in range(n):
        if k[i]%2==0:
            co+=1
    k=[nu//2 for nu in k]
    
    if co != n:
        break
    wa+=1
    co=0
print(wa)

Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  vector<int> x(a);
  int n = 0;
  for (int i = 0; i < a; i++) {
    cin >> x[i];
  }
  for (int i = 1; i < a - 1; i++) {
    if (x[i] != min({x[i - 1], x[i], x[i + 1]}) && 
        x[i] != max({x[i - 1], x[i], x[i + 1]})) {
      n++;
    }
  }
  cout << n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
  int n;
  while(cin>>n){
    if(n%10==n/100){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

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

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

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f)
{
  if (rest == 0)
  {
    f(indexes);
  }
  else
  {
    if (s < 0)
      return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f)
{
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int main()
{
  int h, w, k;
  cin >> h >> w >> k;
  char c[10][10];

  rep(i, h) rep(j, w)
  {
    cin >> c[i][j];
  }

  int ans = 0;

  for (int bit = 0; bit < (1 << (h + w)); ++bit)
  {
    char d[10][10];
    rep(i, h) rep(j, w)
        d[i][j] = c[i][j];

    vector<int> S;
    for (int i = 0; i < (h + w); ++i)
    {
      if (bit & (1 << i))
      { // 列挙に i が含まれるか
        S.push_back(i);
      }
    }

    // cout << "{";
    for (int i = 0; i < (int)S.size(); ++i)
    {
      // cout << S[i] << " ";
      if (S[i] <= (h - 1))
      {
        rep(j, w)
        {
          d[S[i]][j] = '.';
        }
      }
      else
      {
        rep(j, h)
        {
          d[j][S[i] - h] = '.';
        }
      }
    }
    // cout << "}" << endl;

    // チェック
    int count = 0;
    rep(i, h) rep(j, w)
    {
      if (d[i][j] == '#')
        count++;
    }

    if (count == k)
      ans++;
  }

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


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
int inf=1e5+9;
int main(){
	int n;
	cin >> n;
	string s;
	int a[n][26];
	FOR(i,n) FOR(j,26) a[i][j]=0;
	FOR(i,n){
		cin >>s ;
		FOR(j,s.length()) a[i][s[j]-97]++;
	}
	int m[26];
	FOR(j,26) m[j]=inf;
	FOR(i,26){
		FOR(j,n){
			m[i]=min(a[j][i],m[i]);
		}
	}
	FOR(i,26){
		FOR(j,m[i])
			cout << (char)(i+97);
	}

	return 0;
}

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

int main( int argc, char *argv[] )
{
int i;
int iPos;
char C;
char O[ 100 ];
char E[ 100 ];
char lpOut[ 200 ];

	// 入力
	cin >> O;
	cin >> E;

	// 生成
	i = 0;
	iPos = 0;
	while( true )
	{
		C = O[ i ];
		if( C == '\0' ) break;

		lpOut[ iPos ] = C;
		iPos++;

		C = E[ i ];
		if( C == '\0' ) break;
		lpOut[ iPos ] = C;
		iPos++;

		i++;
	}

	// 出力
	lpOut[ iPos ] = '\0';
	cout << lpOut << endl;

	return 0;
}






Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
    int h, w;
    cin >> h >> w;
    char m[h][w], M[h][w];
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            cin >> m[i][j];
            if(m[i][j] == '#') M[i][j] = '#';
            else M[i][j] = '0';
        }
    }
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            if(m[i][j] == '#') {
                if(i!=0 && M[i-1][j] != '#') M[i-1][j]++;
                if(i!=h-1 && M[i+1][j] != '#') M[i+1][j]++;
                if(j!=0 && M[i][j-1] != '#') M[i][j-1]++;
                if(j!=w-1 && M[i][j+1] != '#') M[i][j+1]++;
                if(i!=0 && j!=0 && M[i-1][j-1] != '#') M[i-1][j-1]++;
                if(i!=0 && j!=w-1 && M[i-1][j+1] != '#') M[i-1][j+1]++;
                if(i!=h-1 && j!=0 && M[i+1][j-1] != '#') M[i+1][j-1]++;
                if(i!=h-1 && j!=w-1 && M[i+1][j+1] != '#') M[i+1][j+1]++;
                
            }
        }
    }
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            cout << M[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 3680
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

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

    for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0) {
            std::cout << " " << i;
        } else {
            int x = i;
            while (true) {
                if (x % 10 == 3) {
                    std::cout << " " << i;
                    break;
                }
                x /= 10;
                if (x == 0) {
                    break;
                }
            }
        }
    }

    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main() {
	for (char c; (c = getchar()) != '\n';) 
        {
		if (c >= 65 && c <= 90)
			cout << (char)(c + 32);
		else if (c >= 97 && c <= 122)
			cout << (char)(c - 32);
		else
			cout << c;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3084
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

int main()
{
  int n, t;
  cin >> n >> t;
  ll a[100100];
  ll mina[100100];
  mina[0] = 1234567890;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    mina[i + 1] = min(mina[i], a[i]);
  }

  ll ans = 0;
  ll submax = 0;
  for (int i = 0; i < n; i++)
  {
    if (submax == a[i] - mina[i + 1])
    {
      ans++;
    }
    if (submax < a[i] - mina[i + 1])
    {
      submax = a[i] - mina[i + 1];
      ans = 1;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1792
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int h,i,j;
  int p,q;
  while(cin>>p>>q){
    int a[90],b[90];
    set<pair<int,int> > c;
    h=-1;
    for(i=0;;i++){
      p*=10;
      a[i]=p/q;
      b[i]=p=p%q;
      if(b[i]){
	if(c.count(make_pair(a[i],b[i]))){
	  for(h=0;a[h]!=a[i]||b[h]!=b[i];h++);
	  break;
	}else{
	  c.insert(make_pair(a[i],b[i]));
	}
      }else{
	i++;
	break;
      }
    }
    for(j=0;j<i;j++)
      cout<<a[j];
    cout<<endl;
    if(h!=-1){
      for(j=0;j<h;j++)
	cout<<" ";
      for(;j<i;j++)
	cout<<"^";
      cout<<endl;
    }
  }
  return 0;
}

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


int main(){
    int n; 
    std::vector<int>nums;
    std::cin >> n;
    int sizes = n ;
    while(n--){
        int temp;
        std::cin >> temp;
        nums.push_back(temp);
    }
    // - - - -
    // dp 
    std::vector<int>dp(sizes, INT_MAX);
    dp[0]=0;
    for(int i = 0; i < sizes ; i++ ){
        for(int j: {i+1 , i+2}){
            if(j < sizes){
                dp[j] = std::min(dp[j], dp[i] + abs(nums[i]-nums[j]));
               // std::cout << dp[j]<< std::endl;
            }   
        }
        
    }
    std:: cout << dp[sizes-1] << std::endl;


    return 0;
}

Measured memory_bytes: 1144
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

typedef pair<int, int> Pair;

const int kMaxN = 5000;

int n;
vector<Pair> hp;
int ans = 0;

long long dp[kMaxN+1][kMaxN+1];
const long long kInf = 5000000000012;

bool comp(Pair hp1, Pair hp2) {
  return hp1.first+hp1.second < hp2.first+hp2.second;
}

int main() {
  cin >> n;
  REP(i, n) {
    int hi, pi;
    cin >> hi >> pi;
    hp.push_back(Pair(hi, pi));
  }

  sort(hp.begin(), hp.end(), comp);
  fill(dp[0]+1, dp[1], kInf);
  REP(i, n) {
    REP(j, n) {
      if (dp[i][j] > hp[i].first) {
        dp[i+1][j+1] = dp[i][j+1];
      } else {
        dp[i+1][j+1] = min(dp[i][j+1], dp[i][j]+hp[i].second);
      }
    }
  }
  // REP(i, n+1) {
  //   REP(j, n+1) {
  //     cout.width(13);
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  RFOR(j, n, -1) {
    if (dp[n][j] < kInf) {
      ans = j;
      break;
    }
  }

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


Measured memory_bytes: 195712
#include <iostream>
#include <cstdio>

using namespace std ;
int flag ;
int q[11];

void dfs(int pos, int left,int right)
{
	if (pos==10) 
	{
		flag = 1 ;
		return ;
	}
	if (q[pos] > left )
	dfs(pos+1 , q[pos] , right);
	
	if (q[pos] > right)
	dfs (pos+1,left ,q[pos]);
	
}
int main ()
{
	
	int n;
	cin >> n ;
	for (int i=0;i<n;i++)
	{
		flag = 0 ;
		for (int i=0;i<10;i++)
			cin >> q[i];
		dfs(0,-1,-1);
		if (flag == 1)
		cout <<"YES"<<endl;
		else 
		cout <<"NO"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3104
package main

import "fmt"

func min(x, y int) int {
    if x > y {
        return y
    }
    return x
}

func calc(s string, start rune) int {
    ret := 0
    for i, c := range s {
        if c == start && i % 2 == 1 || c != start && i % 2 == 0 {
            ret++
        }
    }
    return ret
}

func main() {
    var s string
    fmt.Scan(&s)
    fmt.Println(min(calc(s, '0'), calc(s, '1')))
}


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

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

  vector<int>::iterator max = max_element(a.begin(), a.end());
  int maxValue = *max;
  sort(a.begin(), a.end());

  for (int i=0; i<n; i++) {
    if (a.begin()+i == max) {
      cout << a[n-2] << endl;
    } else {
      cout << maxValue << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
typedef long double LD;
typedef pair <int,int> pii;
typedef pair <int,LL> piL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=305;
int mod;
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int n,k;
int C[N][N];
int dp[N][N],s[N][N];
int main(){
	n=read()+1,k=read(),mod=read();
	For(i,0,n)
		C[i][0]=C[i][i]=1;
	For(i,1,n)
		For(j,1,i)
			Add(C[i][j]=C[i-1][j-1],C[i-1][j]);
	For(i,0,1)
		dp[0][i]=s[0][i]=1;
	For(i,1,k){
		dp[i][0]=dp[i][1]=1;
		Add(s[i][0]=s[i-1][0],1);
		Add(s[i][1]=s[i-1][1],1);
		For(j,2,n){
			For(t,1,j-1){
				Add(dp[i][j],(LL)s[i-1][t]*dp[i][j-t]%mod*C[j-2][t-1]%mod);
			}
			Add(s[i][j]=s[i-1][j],dp[i][j]);
		}
	}
	cout<<dp[k][n]<<endl;
	return 0;
}

Measured memory_bytes: 1280
# -*- coding: utf-8 -*-

import sys

'''

'''

def func():
    '''

    '''
    n = int(raw_input())

    for i in range(n):
        numstr1, numstr2 = raw_input().split()
        
        num1 = 0
        for index, c in enumerate(numstr1):
            if c == 'm':
                if index != 0 and numstr1[index-1].isdigit():
                    num1 += int(numstr1[index-1]) * 1000
                else:
                    num1 += 1000
            if c == 'c':
                if index != 0 and numstr1[index-1].isdigit():
                    num1 += int(numstr1[index-1]) * 100
                else:
                    num1 += 100
            if c == 'x':
                if index != 0 and numstr1[index-1].isdigit():
                    num1 += int(numstr1[index-1]) * 10
                else:
                    num1 += 10

            if c == 'i':
                if index != 0 and numstr1[index-1].isdigit():
                    num1 += int(numstr1[index-1])
                else:
                    num1 += 1

        num2 = 0
        for index, c in enumerate(numstr2):
            if c == 'm':
                if index != 0 and numstr2[index-1].isdigit():
                    num2 += int(numstr2[index-1]) * 1000
                else:
                    num2 += 1000
            if c == 'c':
                if index != 0 and numstr2[index-1].isdigit():
                    num2 += int(numstr2[index-1]) * 100
                else:
                    num2 += 100
            if c == 'x':
                if index != 0 and numstr2[index-1].isdigit():
                    num2 += int(numstr2[index-1]) * 10
                else:
                    num2 += 10

            if c == 'i':
                if index != 0 and numstr2[index-1].isdigit():
                    num2 += int(numstr2[index-1])
                else:
                    num2 += 1

        s = num1 + num2
        sstr = ''

        if s / 1000 == 0:
            pass
        elif s / 1000 == 1:
            sstr += 'm'
        else:
            sstr += str(s / 1000) + 'm'
                    
        if (s / 100) % 10 == 0:
            pass
        elif (s / 100) % 10 == 1:
            sstr += 'c'
        else:
            sstr += str((s / 100) % 10) + 'c'

        if (s / 10) % 10 == 0:
            pass
        elif (s / 10) % 10 == 1:
            sstr += 'x'
        else:
            sstr += str((s / 10) % 10) + 'x'
        
        if s % 10 == 0:
            pass
        elif s % 10 == 1:
            sstr += 'i'
        else:
            sstr += str(s % 10) + 'i'

        print sstr


if __name__ == '__main__':
    func()
    

Measured memory_bytes: 4404
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

template <typename T> void SortUnique(vector<T> &vs) {
  sort(vs.begin(), vs.end());
  vs.erase(unique(vs.begin(), vs.end()), vs.end());
}

struct Node {
  bool IsLeaf() const { return !m_left && !m_right; }

  Node *MoveLeft() {
    if (!m_left)
      m_left = new Node{};
    return m_left;
  }

  Node *MoveRight() {
    if (!m_right)
      m_right = new Node{};
    return m_right;
  }

  Node *m_left = nullptr;
  Node *m_right = nullptr;
};

void Add(Node *root, string const &s) {
  assert(root);

  for (auto const &c : s) {
    if (c == '0')
      root = root->MoveLeft();
    else
      root = root->MoveRight();
  }
}

uint64_t GetSG(uint64_t height) {
  height++;
  return height & ((~height) + 1);
}

void Dfs(Node *root, uint64_t depth, uint64_t maxLength,
         vector<uint64_t> &sgs) {
  if (!root)
    return;

  if (root->m_left)
    Dfs(root->m_left, depth + 1, maxLength, sgs);
  else if (depth < maxLength)
    sgs.push_back(GetSG(maxLength - depth - 1));

  if (root->m_right)
    Dfs(root->m_right, depth + 1, maxLength, sgs);
  else if (depth < maxLength)
    sgs.push_back(GetSG(maxLength - depth - 1));
}

int main() {
  ios_base::sync_with_stdio(0);

  // int const kMaxL = 100;

  // int g_table[kMaxL];
  // g_table[0] = 1;
  // for (int l = 1; l < kMaxL; ++l) {
  //   vector<int> mex;

  //   for (int p = 0; p <= l; ++p) {
  //     int x = 0;
  //     for (int i = 0; i < p; ++i)
  //       x = x ^ g_table[l - i - 1];
  //     mex.push_back(x);
  //   }
  //   SortUnique(mex);
  //   int i = 0;
  //   while (i < mex.size() && mex[i] == i)
  //     ++i;
  //   g_table[l] = i;
  // }

  // for (int i = 0; i < kMaxL; ++i)
  //   cout << i << ": " << g_table[i] << endl;

  int n;
  uint64_t maxLength;

  cin >> n >> maxLength;

  Node root;

  string s;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    Add(&root, s);
  }

  vector<uint64_t> sgs;
  Dfs(&root, 0 /* depth */, maxLength, sgs);

  uint64_t x = 0;
  for (auto const & sg : sgs)
    x = x ^ sg;

  if (x == 0)
    cout << "Bob" << endl;
  else
    cout << "Alice" << endl;
  return 0;
}


Measured memory_bytes: 12488
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;

int main(){
  vector<int>l(3);
  for(int i=0;i<3;++i){
    cin>>l[i];
  }
  sort(l.begin(),l.end());
  int ans= l[0]+l[1];
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    int a,b,i=0,k=1;cin>>a>>b;
    while(k<b){
        k+=a-1;
        ++i;
    }
    cout<<i<<endl;
    return 0;


}

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

int main () {
  int N, thou, hand, ten, one;

  cin >> N;

  thou = N / 1000;
  hand = (N - thou * 1000) / 100;
  ten = (N - thou * 1000 - hand * 100) / 10;
  one = N - thou * 1000 - hand * 100 - ten * 10;

  if ((thou == hand && hand == ten) || (hand == ten && ten == one)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n;
  cin>>n;
  map<int,int> mp;
  for(int j=2;j<=n;j++){
    int a=j;
    for(int i=2;i*i<=j+2;i++){
      while(a!=0&&a%i==0){
        mp[i]++;
        a/=i;
      }
    }
    if(a>2)mp[a]++;
  }

  vector<vector<int> > dp(mp.size()+1,vector<int>(76,0));
  dp[0][1]=1;
  vector<int> x;
  for(auto itr=mp.begin();itr!=mp.end();itr++){
    x.push_back(itr->second);
  }

  for(int i=0;i<x.size();i++){
    for(int j=0;j<76;j++){
      for(int k=1;k<=x[i]+1;k++){
        if(j*k>76)break;
        dp[i+1][j*k]+=dp[i][j];
      }
    }
  }
  cout<<dp[x.size()][75]<<endl;
}


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

using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;
    bool check = 1;
    
    if(S.at(0) != 'A') {
        check = 0;
    }
    int count = 0;
    int Ci = 0;
    for(int i = 2; i < S.size() - 1; i++) {
        if(S.at(i) == 'C') {
            count++;
            Ci = i;
        }
    }
    if(count != 1) {
        check = 0;
    }
    if(check) {
        for(int i = 0; i < S.size(); i++) {
            if(!(S.at(i) >= 'a' && S.at(i) <= 'z') && ((i != 0 && i != Ci))) {
                check = 0;
            }
            if(i == 0 || i == Ci) {
                //continue;
            }
        }
    }
    if(check) {
    cout << "AC" << endl;
    } else {
    cout << "WA" << endl;
    }


    return 0;
}

Measured memory_bytes: 3608
<?php
  

//$abc = explode(" ",trim(fgets(STDIN)));
fscanf(STDIN,"%d",$n);
fscanf(STDIN,"%d %d",$d,$x);

$a_li = array();
$sum=0;
for($i=0;$i<$n;$i++){
  $a_li[] = trim(fgets(STDIN));
}

for($i=0;$i<$n;$i++){
  if($d%$a_li[$i]==0){
    $sum+=(int)($d/$a_li[$i]);
  }else{
  	$sum+=(int)($d/$a_li[$i])+1;
  }
}

echo ($sum+$x)."\n";




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

int main()
{
	int K;
	cin >> K;
	cout << (K / 2) * ((K + 1) / 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main () {
    int a,b=1;
    cin>>a;
    int N[a];
    for(int i=0;i<a;i++){
        cin>>N[i];
    }
    sort(N,N+a);
    for(int i=0;i<a-1;i++){
        if(N[i]!=N[i+1])b++;
    }
    cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a==b) printf("%d\n",c);
  else if(b==c) printf("%d\n",a);
  else printf("%d\n",b);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
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<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
    ll X;
    cin >> X;

    vector<ll> divs = divisor(X);
    for(ll d: divs) {
        ll x = X / d, lb = -1e3, ub = 1e3;
        for(int c = -1e3; c <= 1e3; c++) {
            if(pow(c+d, 5) - pow(c,5) == X) {
                cout << c+d << " " << c << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

# AtCoder Beginner Contest 115：D - Christmas


# 各レベルの長さ
L = [1]+[0]*50
for i in range(50):
    L[i+1] = 3+L[i]*2
# print L

# 各レベルに含まれるパティの数
P = [1]+[0]*50
for i in range(50):
    P[i+1] = 1+P[i]*2
# print P


# 'B' + L[l-1] + 'P' + L[l-1] + 'B'
def lp(l, n):
    if l == 0:
        return 1
    elif n == 1:
        # 'B'
        return 0
    elif 1 < n <= 1+L[l-1]-1:
        # 'B' + L[l-1]の一つ手前まで
        return lp(l-1, n-1)
    elif n == 1+L[l-1]:
        # 'B' + L[l-1]
        return P[l-1]
    elif n == 1+L[l-1]+1:
        # 'B' + L[l-1] + 'P'
        return P[l-1]+1
    elif 1+L[l-1]+1 < n <= 1+L[l-1]+1+L[l-1]-1:
        # 'B' + L[l-1] + 'P' + L[l-1]の一つ手前まで
        return P[l-1] + 1 + lp(l-1, n-(1+L[l-1]+1))
    elif n == 1+L[l-1]+1+L[l-1]:
        # 'B' + L[l-1] + 'P' + L[l-1]
        return P[l-1] + 1 + P[l-1]
    elif n == 1+L[l-1]+1+L[l-1]+1:
        # 'B' + L[l-1] + 'P' + L[l-1] + 'B'
        return P[l-1] + 1 + P[l-1]
    else:
        print 'NG!'
        exit()


def main():
    N, X = [int(i) for i in raw_input().strip().split(' ')]

    print lp(N, X)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2696
Uses math;
var N,K,i,j:integer;
    H:array[1..100100] of integer;
    dp:array[1..100100] of integer;
begin
 read(N,K);
for i := 1 to N do read(H[i]);

 dp[1]:=0;
for i := 2 to K do
 dp[i]:=abs(H[i]-H[1]);
 
for i := 1 to N-1 do //i段目からのジャンプ
 begin
 for j := 1 to K do dp[i+j]:=min(dp[i+j],dp[i]+abs(H[i+j]-H[i]));
  dp[i+K]:=dp[i]+abs(H[i+K]-H[i]);
 end;
write(dp[N])
end.


Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

// AC
public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n, m;
	P[] cs;
	int[] rs;
	P t, s;

	void run(){
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			cs=new P[n];
			rs=new int[n];
			for(int i=0; i<n; i++){
				int x=sc.nextInt();
				int y=sc.nextInt();
				rs[i]=sc.nextInt();
				cs[i]=new P(x, y);
			}
			m=sc.nextInt();
			for(int i=0; i<m; i++){
				int tx=sc.nextInt();
				int ty=sc.nextInt();
				int sx=sc.nextInt();
				int sy=sc.nextInt();
				t=new P(tx, ty);
				s=new P(sx, sy);
				solve();
			}
		}
	}

	void solve(){
		boolean safe=false;
		for(int i=0; i<n; i++){
			P[] ps=isCL(cs[i], rs[i], t, s);
			for(P p : ps){
				if(between(t.x, s.x, p.x)&&between(t.y, s.y, p.y)){
					safe=true;
				}
			}
		}
		println(safe?"Safe":"Danger");
	}

	boolean between(double x1, double x2, double x){
		return (x1<x+EPS&&x<x2+EPS)||(x1+EPS>x&&x+EPS>x2);
	}

	P[] isCL(P c, double r, P p1, P p2){
		double x=p1.sub(c).dot(p2.sub(p1));
		double y=p2.sub(p1).abs2();
		double d=x*x-y*(p1.sub(c).abs2()-r*r);
		if(d<-EPS)
			return new P[0];
		if(d<0)
			d=0;
		P q1=p1.sub(p2.sub(p1).mul(x/y));
		P q2=p2.sub(p1).mul(Math.sqrt(d)/y);
		return new P[]{q1.sub(q2), q1.add(q2)};
	}

	class P{
		double x, y;

		P(){
			this(0, 0);
		}

		P(double x, double y){
			this.x=x;
			this.y=y;
		}

		P add(P p){
			return new P(x+p.x, y+p.y);
		}

		P sub(P p){
			return new P(x-p.x, y-p.y);
		}

		P mul(double m){
			return new P(x*m, y*m);
		}

		P div(double d){
			return new P(x/d, y/d);
		}

		double abs(){
			return Math.sqrt(abs2());
		}

		double abs2(){
			return x*x+y*y;
		}

		double arg(){
			return Math.atan2(y, x);
		}

		// inner product
		double dot(P p){
			return x*p.x+y*p.y;
		}

		// outer product
		double det(P p){
			return x*p.y-y*p.x;
		}

		P rot90(){
			return new P(-y, x);
		}

		// conjugation
		P conj(){
			return new P(x, -y);
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
h_numbers=[]
w_numbers=[]
while True:
    numbers=[]
    numbers=input().split()
    numbers[0]=int(numbers[0])
    numbers[1]=int(numbers[1])
    if numbers[0]==0 and numbers[1]==0:
        break
    h_numbers.append(numbers[0])
    w_numbers.append(numbers[1])

for i in range(0,len(h_numbers)):
    for j in range(0,h_numbers[i]):
        if j==0 or j==(h_numbers[i]-1):
            print('#'*w_numbers[i])
        else:
            print('#%s#'%((w_numbers[i]-2)*'.'))
    print()

Measured memory_bytes: 7596
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A = int(sys.stdin.buffer.readline().rstrip())
    print(A//2 if A%2 == 0 else A//2 + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
int a[200000];
int b[200000];
int c[200000];
int ma(int x) {
	x--;
	x %= m;
	x += m;
	x %= m;
	x++;
	return x;
}
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] < a[i + 1]) {
			ans += a[i + 1] - a[i];
			if (a[i + 1] < a[i] + 2) continue;
			b[a[i] + 2]++;
			b[a[i + 1] + 1]--;
			c[a[i + 1] + 1] += max_0(a[i + 1] - a[i] - 1);
		}
		else {
			ans += a[i + 1] + m - a[i];
			if (a[i] + 2 > m&&a[i + 1] < ma(a[i] + 2)) continue;
			if (a[i] + 2 > m) {
				b[ma(a[i] + 2)]++;
			}
			else {
				b[a[i] + 2]++;
				b[1]++;
				c[1] -= max_0(m - a[i] - 1);
			}
			b[a[i + 1] + 1]--;
			c[a[i + 1] + 1] += max_0(a[i + 1] + m - a[i] - 1);
		}
	}
	int res = 0;
	for (int i = 1; i <= m; i++) {
		if (i > 1) {
			b[i] += b[i - 1];
			c[i] += c[i - 1];
		}
		c[i] -= b[i];
		res = min(res, c[i]);
	}
	cout << ans + res << endl;
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
using namespace std;


int main(){
	ll H, W, h, w; cin >> H >> W >> h >> w;
	cout << (H - h)*(W - w) << endl;
	return 0;
}

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

int main() {
	long long X;
	cin >> X;
	long long NOW = 100;
	for (int i = 1; ; i++) {
		NOW += NOW / 100;
		if (NOW >= X) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;


void trace(int A[],int N){
    REP(i,N){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}


int main(){
    int N;
    cin >> N;
    int r[N];
    REP(i,N)cin >> r[i];
    int count = 0;
    bool flag = true;
    while (flag){
    flag = false;
    for(int j = N-1;j>=1;j--){
        if(r[j] < r[j-1]){
            int i= r[j];
            r[j] = r[j-1];
            r[j-1] = i;
            flag = true;
            count++;
            }
        }
    }
    trace(r,N);
    cout << count << endl;
}



Measured memory_bytes: 3164
package main

import (
	"bufio"
	"fmt"
	"os"
)

var h, w, n int
var blocks []int

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d", &h, &w, &n)

	blocks = make([]int, h+1)

	for ; n > 0; n-- {
		var x, y int
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &x, &y)
		if blocks[x] == 0 {
			blocks[x] = y
		} else {
			blocks[x] = min(blocks[x], y)
		}
	}

	right := 1
	for i := 1; i < h; i++ {
		if blocks[i+1] == 0 {
			right++
			continue
		}

		if blocks[i+1] <= right {
			fmt.Println(i)
			return
		}

		if right+1 < blocks[i+1] {
			right++
		}

	}
	fmt.Println(h)
}

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


Measured memory_bytes: 5888
#include <iostream>
#include <algorithm>
typedef long long LL;
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN], b[MAXN], c[MAXN];
LL dp[MAXN];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    for (int i = 0; i < n; i++) scanf("%d", &b[i]);
    for (int i = 0; i < n; i++) scanf("%d", &c[i]);
    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);
    for (int i = 0; i < n; i++) {
        int tmp = lower_bound(a, a+n, b[i]) - a;
        dp[i] = tmp;
        if (i > 0) dp[i] += dp[i-1];
    }
    LL ret = 0;
    for (int i = 0; i < n; i++) {
        int tmp = lower_bound(b, b+n, c[i]) - b;
        tmp--;
        if (tmp >= 0) {
            ret += dp[tmp];
        }
    }
    cout << ret << endl;


    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define int long long
void Digvijay()
{
    int n;
    cin>>n;
    if(n&1)cout<<0<<"\n";
    else{
        int res=0;
        int tmp=10;
        while(tmp<=n)
        {
            res+=n/tmp;
            tmp*=5;
        }
        cout<<res<<"\n";
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=0;__<_;__++)
    {
        Digvijay();
    }
}

Measured memory_bytes: 3568
N=gets.to_i
xus=N.times.map { gets.split }

xus.each do |xu|
  xu[0] = xu[0].to_f
end

sum=0

xus.each do |xu|
  if xu[1] == "JPY"
    sum += xu[0]
  elsif xu[1] == "BTC"
    sum += xu[0]*380000
  end
end

p sum


Measured memory_bytes: 1788
#include<stdio.h>
#include<string.h>
int main() {
    long long a,b,c,k;scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
    long long ans;
    if(a<k){
        ans=a;
        k-=a;
    }else{
        ans=k;
        printf("%lld\n",ans);
        return 0;
    }

    if(b<k){
        k-=b;
    }else{
        printf("%lld\n", ans);
        return 0;
    }

    ans-=k;
    printf("%lld\n", ans);

}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
#define read(x) scanf("%d",&x)
#define ll long long
using namespace std;
const int maxn = 1e3 + 50;

ll n,m;
int a[maxn], b[maxn];
int c[maxn];
int check[14];
int f[(1<<13)];


int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a[i]>>b[i];
        int sum = 0;
        for(int j=1,x;j<=b[i];j++){
            cin>>x;
            sum += (1<<(x-1));
        }
        c[i] = sum;
    }
    memset(f,0x3f,sizeof f);
    f[0] = 0;
    for(int i=0;i<(1<<n);i++){
        for(int j=1;j<=m;j++){
            // int flag = 0;
            // for(int k=0;k<n;k++){
            //     if(!((c[j]>>k)&1)) continue;
            //     if((i>>k)&1){
            //         f[i] = f[i-c[j]]
            //     }
            // }
            f[i|c[j]] = min(f[i|c[j]],f[i]+a[j]);
        
        }
    }
    if(f[(1<<n)-1]==0x3f3f3f3f){
        cout<<-1<<endl;
    }
    else
        cout<<f[(1<<n)-1]<<endl;
    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    int N; cin >> N;
    VI A(N); REP(i,N) cin >> A[i];
    int ans = 0; REP(i,N) ans += A[i]-1;
    cout << ans << endl;
    return 0;
}

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

int main(){
    int a, b, c;
    cin>>a>>b>>c;
    if(a<b&&b<c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3104