akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	int a,b,c,d;

	scanf("%d%d%d%d",&a,&b,&c,&d);

	while(true)
	{
		c-=b;
		if(c<=0)
		{
			puts("Yes");
			break;
		}
		a-=d;
		if(a<=0)
		{
			puts("No");
			break;
		}
	}

	return 0;

}

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

int main() {
	int N,M,sum,sup;
	cin >> N;
	vector<string>sn(N); 
	sum =0;
	sup =0;
	string ele;
	
	for (int i=0;i<N;i++){
		sup=sum;
		cin>>sn.at(i);
	}
	cin >>M;
	vector <string>tm(M);
	
	for(int i=0;i<M;i++){
		cin >>tm.at(i);
	}
	
	for(int i=0; i<N;i++){
		sum = 0;
		ele = sn.at(i);
		
		for (int j=0 ;j<N;j++){
			if (ele == sn.at(j)){
				sum++;
			}
		}
		
		for(int j=0; j<M;j++){
			if (ele == tm.at(j)){
				sum = sum -1;
			}
		}
		
		if(sum>sup){
			sup = sum;
		}
	}
cout << sup << endl;
}


Measured memory_bytes: 256
n = int(input())
if 400<=n<=599:
    print(8)
elif 600 <= n <= 799:
    print(7)
elif 800 <= n <= 999:
    print(6)
elif 1000 <= n <= 1199:
    print(5)
elif 1200 <= n <= 1399:
    print(4)
elif 1400 <= n <= 1599:
    print(3)
elif 1600 <= n <= 1799:
    print(2)
elif 1800 <= n <= 1999:
    print(1)


Measured memory_bytes: 9176
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int p = a % b;
		int n = p;
		while (true) {
			n = (n + p) % b;
			if(n == p){
				System.out.println("NO");
				break;
			}else if( n == c){
				System.out.println("YES");
				break;
			}
		}
	}
}

Measured memory_bytes: 23252
#include <functional>
#include <queue>
#include <vector>
#include <iostream>
#include <cstdint>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
  	long long int h, w;

	cin >> h;
	cin >> w;
	
  	if ((h == 1) || (w == 1))
    {
      cout << 1;
    }
  	else
    {
    	cout << (long long int)((double)(h*w)/2+0.5);
    }  
  	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(void){
    vector<int> buf(3);

    rep(i,3){
        cin >> buf.at(i);
    }

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

    cout << buf.at(0) + buf.at(1) << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  4 21:48:09 2020

@author: Kanaru Sato
"""

k = int(input())

gl = list(map(str,[0,1,2,3,4,5,6,7,8,9]))

starti = 0
endi = len(gl)
l=[]

while len(l) < k:
    ngl = gl[starti:endi]
    for i in range(len(ngl)):
        if ngl[i][0] == "0":
            gl.append("0"+ngl[i])
            gl.append("1"+ngl[i])
        elif ngl[i][0] == "9":
            gl.append("8"+ngl[i])
            gl.append("9"+ngl[i])
        else:
            gl.append(str(int(ngl[i][0])-1)+ngl[i])
            gl.append(str(int(ngl[i][0]))+ngl[i])
            gl.append(str(int(ngl[i][0])+1)+ngl[i])
    starti = endi
    endi = len(gl)
    
    l = []
    for i in gl:
        if i[0] != "0":
            l.append(int(i))

l.sort()
print(l[k-1])

Measured memory_bytes: 26944
N = int(input())
b=str(N)
a=b[len(b)-1]
if a=="2" or a=="4" or a=="5" or a=="7" or a=="9" :
    print("hon")
elif a=="0" or a=="1" or a=="6" or a=="8":
    print("pon")
elif a=="3":
    print("bon")

Measured memory_bytes: 9184
var
 s1,s2,s3:ansistring;
 i:longint;
begin
 readln(s1);
 readln(s2);
 for i:=length(s2) downto 1 do s3:=s3+s2[i];
 if s3=s1 then writeln('YES')
          else writeln('NO');
end.

Measured memory_bytes: 128
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]
 
large = np.max([C, D])
small = np.min([C, D])
 
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
def lcm(a, b):
    return a * b // gcd (a, b)
 
num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // lcm(large, small)
 
num_A_1 = (A-1) // C
num_A_2 = (A-1) // D
num_A_3 = (A-1) // lcm(large, small)
 
numB = num_B_1 + num_B_2 - num_B_3
numA = num_A_1 + num_A_2 - num_A_3
 
print((B-A+1) - (numB - numA))

Measured memory_bytes: 12520
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()

i = 0
sevens = 0
while True:
    sevens += 7 * pow(10, i, K)
    sevens %= K
    i += 1
    if sevens == 0:
        break
print(i)


Measured memory_bytes: 9196
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "3\n8 12 40\n" => "2",
    "4\n5 6 8 10\n" => "0",
    "6\n382253568 723152896 37802240 379425024 404894720 471526144\n" => "8",
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: u32,
        v: [u32; n],
    }

    v
        .iter()
        .map(|x| x.trailing_zeros())
        .min()
        .unwrap()
        .to_string()
}


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

int		main(void)
{
	int n;
	
	cin >> n;
	int ans = 1;

	for (int i = 1; i < 34000; i++)
	{
		if (i * i <= n)
			ans = i * i;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	ios
	int n,a,b;
	cin>>n;

	if(n==1){
		cout<<"Hello World";return 0;
	}
	if(n==2){
		cin>>a>>b;
		cout<<a+b;
	}

	
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <cstdio>
#include <utility>
#include <bitset>
 
using namespace std;
typedef long long ll;
 
struct UnionFind {
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) { }
  bool unionSet(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};
 
int main(){
	ll N,M;
	cin >> N >> M;
	UnionFind uf(M+1);
	vector<ll> used(M+1,0);
	ll base;
	for(ll i=0;i<N;i++){
		ll K;
		cin >> K;
		vector<ll> m(K);
		for(ll j=0;j<K;j++){
			cin >> m[j];
			used[m[j]]=1;
			base=m[j];
		}
		for(ll j=1;j<K;j++)
			uf.unionSet(m[0],m[j]);
	}
	bool ans=true;
	for(ll i=0;i<=M;i++){
		if(used[i] && !uf.findSet(base,i))
			ans = false;
	}
	if(ans)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	long N, A, B, C, D;
	cin >>N >>A >>B >>C >>D;
	long MA, MI;
	long d=abs(A-B);
	MA=D*(N-1);
	MI=C*(N-1);
	if ((d<=MA)&&(d>=MI)) {
		cout <<"YES" <<endl;
		return 0;
	}
	for (long i=1; i<=N; i++) {
		MA -=D+C;
		MI -=C+D;
		if ((d<=MA)&&(d>=MI)) {
			cout <<"YES" <<endl;
			return 0;
		}
	}
	cout <<"NO" <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  ll n,m;
  cin >> n >> m;
  int l[1000000],r[1000000];
  int d[1000000]={0};
  FOR(i,m){
    cin >> l[i] >> r[i];
    d[l[i]]++;
    d[r[i]+1]--;
  }

  FOR(i,100010){
    d[i]+=d[i-1];
  }

int ans=0;
FOR(i,100010){
  if(d[i]==m){
    ans++;
  }
}

cout << ans << endl;
  
}

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF INT_MAX;
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  ll R,G,B,N;
  cin>>R>>G>>B>>N;
  ll ans=0;
  for(int i=0;i*R<=N;i++){
    for(int j=0;j*G<=N;j++){
      if(N-(i*R+j*G)>=0&&(N-(i*R+j*G))%B==0){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab=[list(map(int,input().split())) for _ in range(n)]

ab.sort()
num = 0
ans = 0

for i in range(n):
    num += ab[i][1]
    if num >= m:
        ab[i][1] -= num-m
    ans += ab[i][0]*ab[i][1]
    if num >= m:
        break

print(ans)

Measured memory_bytes: 27760
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T> T expo(T base, T e, T mod) { T res = 1;
  while(e > 0) { if(e&1) res = res * base % mod; base = base * base % mod; e >>= 1; }
  return res;
}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}

const int INF = 1e9;

int try_for(string input, char x) {
	bool ok = false;
	for(int i = 0; i < input.size(); i++) {
		if(input[i] == x) {
			ok = true; break;
		}
	}
	if(!ok) return INF;
	int res = 0;
	while(true) {
		bool ok = true;
		for(int i = 0; i < input.size(); i++) {
			if(input[i] != x) {
				ok = false;
			}
		}
		if(ok) return res;
		res++;
		string n_input;
		for(int i = 0; i < int(input.size()) - 1; i++) {
			if(input[i] == x || input[i+1] == x) {
				n_input.push_back(x);
			} else {
				n_input.push_back(input[i]);
			}
		}
		input = n_input;
	}
	return res;
}

int main() {
  ios_base::sync_with_stdio(false);
	string input;
	cin >> input;
	int res = INF;
	for(char x = 'a'; x <= 'z'; x++) {
		res = min(res, try_for(input, x));
	}
	cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define mod 1000000007
#define PI acos(-1)
int main()
{
	IOS
	string s;
	int k;
	cin>>k;
	cin>>s;
	int i=0;
	k--;
	for(i=0;i<s.length();i++)
	{
		if(i<=k)
		cout<<s[i];
		else
		break;
	}
	if(i!=s.length())
	cout<<"...";
}

Measured memory_bytes: 3652
N,M = map(int,input().split())
d=[0]*M
res = []
for i in range(M):
    P,Y = map(int,input().split())
    res.append((P,Y,i))
c=0
res.sort()
t = str(res[0][0])
for i in res:
    x = str(i[0])
    tmp = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    if x == t:
        c+=1
    else:
        c=1
        t = x
    d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)

for i in d:
    print(i)

Measured memory_bytes: 30388
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
int n,tot;
string now;
void dfs(int x,char t){
	if(x==n){
		cout<<now<<endl;tot++;
		return;
	}
	for(char j='a';j<=t+1;j++){
		now+=j;dfs(x+1,max(t,j));now.pop_back();
	}
}
int main(){
	cin>>n;
	now="a";
	dfs(1,'a');
	cerr<<tot<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int d;
  d = c % a;
  if(c - b >= d){
    cout << "OK" << endl;  
  }else
  {
    cout << "NG" << endl;
  }

}

Measured memory_bytes: 3636
H, W = map(int, input().split())
s = [input() for i in range(H)]

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

for i in range(H):
    for j in range(W):
        if i == j == 0:
            if s[i][j] == '#':
                dp[i][j] = 1
            continue
        c = []
        if 0 <= i - 1 < H:
            c.append(dp[i - 1][j]
                     + (1 if s[i - 1][j] == '.' and s[i][j] == '#' else 0))
        if 0 <= j - 1 < W:
            c.append(dp[i][j - 1]
                     + (1 if s[i][j - 1] == '.' and s[i][j] == '#' else 0))
        if len(c) > 0:
            dp[i][j] = min(c)

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


Measured memory_bytes: 3064
#include<stdio.h>

#define MAX 45

int fib(int);

int array[MAX];
int main(){
  int n,i;
  scanf("%d",&n);
  array[0]=array[1]=1;
  if(n>1)array[n]=fib(n);
  printf("%d\n",array[n]);
  return 0;
}

int fib(int n){
  int i;
  for(i=2;i<=n;i++)array[i]=array[i-2]+array[i-1];
  return array[n];
}



Measured memory_bytes: 2112
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,c;
    long int k;
    scanf("%d %d %d %d\n",&a,&b,&c,&k);
    
    int ans=0;
    if(k%2==0){
        ans=a-b;
    }else{
        ans=b-a;
    }
    
    if(abs(a-b)>1000000000000000000){
        printf("Unfair\n");
    }else{
        printf("%d\n",ans);
    }
    
}

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

int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; ++i){
    cin >> a[i];
  }
  int sum = 0;
  for(int i=0; i<(n-1); ++i){
    for(int j=i+1; j<n; ++j){
      sum += a[i]*a[j];
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define INPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in"
#define OUTPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

vector<pair<int, int>> v;

bool cmp(string &s, pair<int, int> a, pair<int, int> b)
{
    for(int i = a.first, k = b.first; i <= a.second && k <= b.second; i++, k++)
    {
        if(s[i] < s[k])
        {
            return false;
        }
        
        if(s[i] > s[k])
        {
            return true;
        }
    }
    
    return (a.second - a.first > b.second - b.first);
}

bool equal(string &s, pair<int, int> a, pair<int, int> b)
{
    if(a.second - a.first != b.second - b.first)
    {
        return false;
    }
    
    for(int i = a.first, k = b.first; i <= a.second && k <= b.second; i++, k++)
    {
        if(s[i] != s[k])
        {
            return false;
        }
    }

    return true;
}

vector<int> vis;

pair<int, int> get_min(string &s)
{
    int m = (int) v.size();
    int l = -1, r = -1;
    
    for(int i = 0; i < m; i++)
    {
        if(!vis[i] && (l == -1 || (cmp(s, mp(l, r), v[i]))))
        {
            l = v[i].first;
            r = v[i].second;
        }
    }
    
    for(int i = 0; i < m; i++)
    {
        if(!vis[i] && equal(s, mp(l, r), v[i]))
        {
            vis[i] = 1;
        }
    }
    
    return mp(l, r);
}

void solve()
{
    string s;
    int K;
    
    cin >> s >> K;
    
    int n = (int) s.length();
    
    for(int l = 1; l <= n; l++)
    {
        for(int i = 0; i + l - 1 < n; i++)
        {
            int j = i + l - 1;
            v.pb(mp(i, j));
        }
    }
    
    int m = (int) v.size();
    
    vis.assign(m, 0);
    
    pair<int, int> ans;
    for(int i = 0; i < K; i++)
    {
        ans = get_min(s);
    }
    
    for(int i = ans.first; i <= ans.second; i++)
    {
        cout << s[i];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    //freopen(INPUT, "r", stdin);freopen(OUTPUT, "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 148568
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <queue>
#include <stack>
#include <tuple>

using namespace std;


typedef long long ll;
const int INT_INF = 1 << 29;
const ll INF = 1LL<<55;

typedef pair<int, int> P;
struct edge {
	int to;
	int cap;
	ll cost;
	int rev;
};

const int MAX_V = 20010;
int V;
vector<edge> G[MAX_V];
ll h[MAX_V], dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

void add_edge(int from, int to, int cap, ll cost) {
	G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
	G[to].push_back((edge){from, 0, -cost, (int)G[from].size()-1});
}

ll min_cost_flow(int s, int t, int f, bool bell = false) {
	ll res = 0;
	fill_n(h, V, 0);
	while (f > 0) {
		fill_n(dist, V, INF);
		dist[s] = 0;
		if (bell) {
			bell = false;
			bool update;
			do {
				update = false;
				for (int v = 0; v < V; v++) {
					if (dist[v] == INF) continue;
					for (int i = 0; i < G[v].size(); i++) {
						edge &e = G[v][i];
						if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
							dist[e.to] = dist[v] + e.cost;
							prevv[e.to] = v;
							preve[e.to] = i;
							update = true;
						}
					}
				}
			} while (update);
			for (int v = 0; v < V; v++) {
				h[v] += dist[v];
			}
		}
		
		fill_n(dist, V, INF);
		dist[s] = 0;
			priority_queue<P, vector<P>, greater<P>> que;
			que.push(P(0, s));
			while (!que.empty()) {
				P p = que.top(); que.pop();
				int v = p.second;
				if (dist[v] < p.first) continue;
				for (int i = 0; i < G[v].size(); i++) {
					edge &e = G[v][i];
					if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
						dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
						prevv[e.to] = v;
						preve[e.to] = i;
						que.push(P(dist[e.to], e.to));
					}
				}
			}		
		
		if (dist[t] == INF) {
			return -1;
		}
		for (int v = 0; v < V; v++) {
			h[v] += dist[v];
		}

		int d = f;
		for (int v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * h[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

const int MAX_N = 10010, MAX_K = 10010;

int main(int argc, char *argv[]) {
	int M, N, K;
	cin >> M >> N >> K;
	int w[MAX_N];
	for (int i = 0; i < N; i++) {
		scanf("%d", &w[i]);
	}
	int a[MAX_K], r = 0;
	for (int i = 0; i < K; i++) {
		scanf("%d", &a[i]);
		a[i]--;
		r+= w[a[i]];
	}
	int b[MAX_N];
	fill_n(b, MAX_N, -1);
	for (int i = 0; i < K; i++) {
		add_edge(i, i+1, INT_INF, 0);
		int j = b[a[i]];
		if (j != -1) {
			if (j == i) {
				r -= w[a[i]];
			} else {
				add_edge(b[a[i]], i, 1, -w[a[i]]);
			}
		}
		b[a[i]] = i+1;
	}
	V = K+1;
	printf("%lld\n", r + min_cost_flow(0, K, M-1, true));
    return 0;
}

Measured memory_bytes: 3260
/*package whatever //do not write package name here */
import java.util.*;
import java.io.*;

class Main{
	public static void main (String[] args) {
// 		System.out.println("GfG!");
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		int k=input.nextInt();
		int[] a=new int[n+1];
		for(int i=1;i<=k;i++)
		{
		    int x=input.nextInt();
		    for(int j=1;j<=x;j++)
		    {
		        int y=input.nextInt();
		        a[y]=a[y]+1;
		    }
		}
		int count=0;
		for(int i=1;i<=n;i++)
		 {
		     if(a[i]==0)
		        count++;
		  }
		  System.out.println(count);
		  input.close();
	}
}

Measured memory_bytes: 46112
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

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;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007; 
const long long INF = 1LL << 50;
// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

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

int h, w;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> h >> w;
	vector<string>field(h);
	rep(i, h)cin >> field[i];
	vector<VE>dist(h, VE(w, -1));
	queue<P>que;
	rep(i, h)rep(j, w) {
		if (field[i][j] == '#') {
			dist[i][j] = 0; que.push(P(i, j));
		}
	}
	while (!que.empty()) {
		P p = que.front(); que.pop();
		rep(i, 4) {
			int nx = p.first + dx[i]; int ny = p.second + dy[i];
			if (0 <= nx && nx < h && 0 <= ny && ny < w && dist[nx][ny]==-1) {
				dist[nx][ny] = dist[p.first][p.second] + 1;
				que.push(P(nx, ny));
			}
		}
	}
	int ans = 0;
	rep(i, h)rep(j, w)chmax(ans, dist[i][j]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 25524
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    vector<int> x(M), y(M), c(M);
    rep(i, M) cin >> x[i] >> y[i] >> c[i];
    int ans = inf;
    rep(i, M){
        chmin(ans, a[x[i]-1]+b[y[i]-1] - c[i]);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    chmin(ans, a[0]+b[0]);

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

Measured memory_bytes: 2176
#include<stdio.h>

int map[10][10],c,x,y,N=10;

int main(){
  for(x=0;x<10;x++){
    for(y=0;y<10;y++){
      map[x][y]=x?map[x-1][y+1]+1:y?map[x][y-1]+y:1;
    }
  }
  for(;scanf("%d",&N),N;){
    printf("Case %d:\n",++c);
    for(x=0;x<N;x++){
      for(y=0;y<N;y++){
        if(x+y<N){
          if((x+y)%2){
            printf("%3d",map[x][y]);
          }
          else{
            printf("%3d",map[y][x]);
          }
        }
        else{
          if((x+y)%2){
            printf("%3d",N*N-map[N-1-x][N-1-y]+1);
          }
          else{
            printf("%3d",N*N-map[N-1-y][N-1-x]+1);
          }
        }
      }
      printf("\n");
    }
  }
}

Measured memory_bytes: 616
import java.util.*;
import java.util.Arrays;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        String[] a = new String[N];
        for(int i = 0 ; i < N ; i++){
            a[i] = sc.next();
        }

        Arrays.sort(a);
        for(int j = 0 ; j < N ; j++){
            System.out.print(a[j]);
        }
    }
}


Measured memory_bytes: 24148
# -*- coding: utf-8 -*-
# import numpy as np

n, m = map(int, input().split())

l_min = 1
r_max = n+1

for i in range(m):
    l, r = map(int, input().split())
    l_min = max(l_min, l)
    r_max = min(r_max, r)

ans = r_max - l_min + 1
if ans > 0:
    print(ans)
else:
    print(0)



Measured memory_bytes: 3060
// 二部マッチング
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_7_A
// https://beta.atcoder.jp/contests/abc091/tasks/arc092_a
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }

void main() {
    struct Point { int x, y; }
    int n = readint();
    auto ps = new Point[2 * n];
    foreach (ref p ; ps) readf("%d %d\n", &p.x, &p.y);

    auto bm = new BipartiteMatching();
    int s = 2 * n, t = s + 1;
    foreach (i; 0..n) {
        bm.add_edge(s, i, 1);
        bm.add_edge(n + i, t, 1);
    }
    foreach (i; 0..n) foreach (j; 0..n) {
        if (ps[i].x < ps[n + j].x && ps[i].y < ps[n + j].y)
            bm.add_edge(i, n + j, 1);
    }

    writeln(bm.max_flow(s, t));
    auto _ = readln(); // dbg
}

class BipartiteMatching {
    immutable int INF = 114514810;
    immutable int VMAX = 300;

    struct Edge { int to, cap, rev; }
    Edge[][] G;
    bool[] used; // dfs したか

    this() {
        used.length = G.length = VMAX;
    }

    void add_edge(int from, int to, int cap) {
        G[from] ~= Edge(to, cap, G[to].length.to!int);
        G[to]   ~= Edge(from, 0, G[from].length.to!int - 1);
    }
    // 増加パスを探す
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = true;
        foreach (ref e; G[v]) if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
        return 0;
    }
    int max_flow(int s, int t) {
        int flow;
        while (1) {
            fill(used, false);
            int f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
        assert(false);
    }
}

Measured memory_bytes: 508
#include<stdio.h>
int main(void){
	int n,m,i,ans=0,d[101]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){scanf("%d",&m);d[m]=1;}
	for(i=0;i<101;i++){ans+=d[i];}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[4];
	int b[4];
	int as;
	int bs;
	
	scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
	scanf("%d %d %d %d", &b[0], &b[1], &b[2], &b[3]);
	
	as = a[0] + a[1] + a[2] + a[3];
	bs = b[0] + b[1] + b[2] + b[3];
	
	printf("%d\n", ((as > bs) ? as : bs));
	
	return (0);
}

Measured memory_bytes: 592
S = list(input()*2)
T = list(input())
ans = 'No'
for i in range(len(S)//2):
    check = 1
    for j in range(len(S)//2):
        if S[i+j] != T[j]:
            check = 0
    if check == 1:
        ans = 'Yes'
        break
print(ans)
    

Measured memory_bytes: 3060
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail

    int n;
    cin >> n;
    bool sol = true;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for (int i = n - 1; i > 0; i--)
    {
        if (arr[i - 1] <= arr[i])
        {
            continue;
        }
        else if (arr[i - 1] - 1 > arr[i])
        {
            sol = false;
        }
        else
        {
            arr[i - 1]--;
        }
    }
    if (sol)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}

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

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  int N;
 
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>A.at(i).at(j);
    }
  }
  cin>>N;
  vector<int> B(N);
  for(int i=0;i<N;i++){
    cin>>B.at(i);
  }
  vector<vector<int>> C(3,vector<int>(3,0));
    for(int k=0;k<N;k++){
      for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
          if(B.at(k)==A.at(i).at(j)){
            C.at(i).at(j)=A.at(i).at(j);
          }
        }
      }
    }
  for(int i=0;i<3;i++){
    if(C.at(i).at(0)!=0 && C.at(i).at(1)!=0 && C.at(i).at(2)!=0){
      cout<<"Yes"<<endl;
      return 0;
    }
    if(C.at(0).at(i)!=0 && C.at(1).at(i)!=0 && C.at(2).at(i)!=0){
      cout<<"Yes"<<endl;
      return 0;
    }
    if(C.at(0).at(0)!=0 && C.at(1).at(1)!=0 && C.at(2).at(2)!=0){
      cout<<"Yes"<<endl;
      return 0;
    }
    if(C.at(2).at(0)!=0 && C.at(1).at(1)!=0 && C.at(0).at(2)!=0){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}
      
      
  

     
        
 


Measured memory_bytes: 256
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,p=INT_MAX,j=0,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     string s,st;
     cin>>n>>k;
     p=n%k;
     l=k-p;
     cout<<min(p,l)<<endl;

     return EXIT_SUCCESS;
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
using namespace std;
// #include "prettyprint.hpp"

typedef long long ll;

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

    if (A > B + 1)
    {
        cout << A * 2 - 1 << endl;
    }
    else if (abs(A - B) <= 1)
    {
        cout << A + B << endl;
    }
    else if (A < B + 1)
    {
        cout << B * 2 - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    ll sum = 0;
    rep(i,N){
        int k;
        cin >> k;
        a[i] = k - i - 1;
    }
    sort(all(a));
    ll b = a[N/2];
    vector<ll> ans(11);
    rep(k,11)
        rep(i,N) ans[k] += abs(a[i] - b - 5 + k);
    cout << min(ans) << endl;
}

Measured memory_bytes: 4024
class Team
  def initialize tid, problem_num
    @tid = tid
    @correct_num = 0
    @penalty = 0
    @problems = {}
    1.upto(problem_num) do |pid|
      @problems[pid] = 0
    end
  end

  def correct pid, time
    @correct_num += 1
    @penalty += @problems[pid] * 1200 + time
  end

  def wrong pid
    if @problems[pid].nil?
      @problems[pid] = 1
    else
      @problems[pid] += 1
    end
  end

  def <=> team
    return 1 if @correct_num > team.correct_num
    return -1 if @correct_num < team.correct_num
    return 1 if @penalty < team.penalty
    return -1 if @penalty > team.penalty
    return 1 if @tid < team.tid
    return -1 if @tid > team.tid
    return 0
  end

  attr_reader :tid, :correct_num, :penalty
end

def main
  loop do
    t,p,r = gets.chomp.split(' ').map(&:to_i)
    break if (t|p|r) == 0

    teams = make_teams(t, p)
    log_analyze(teams, r)
    print_ranking(teams)
  end
end

def make_teams t, p
  teams = []
  t.times do |i|
    teams << Team.new(i+1, p)
  end
  teams
end

def log_analyze teams, r
  r.times do
    tid,pid,time,message = gets.chomp.split(' ')
    if message == 'CORRECT'
      teams[tid.to_i-1].correct(pid.to_i, time.to_i)
    else
      teams[tid.to_i-1].wrong(pid.to_i)
    end
  end
end

def print_ranking teams
  ranking = teams.sort{|a, b| b <=> a}
  ranking.each do |team|
    puts "#{team.tid} #{team.correct_num} #{team.penalty}"
  end
end

main

Measured memory_bytes: 6260
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


int N;
int A[100001];



//---------- にぶたん[f,f,f,f,'t',t,t,t] ----------
bool isOK(int n)
{
	multiset<int, greater<int>> s;
	int count = 0;

	for (int i = 0; i < N; i++)
	{
		int a = A[i];
		auto it = s.upper_bound(a);
		if (it == s.end())
		{
			s.insert(a);
			count++;
		}
		else
		{
			s.erase(it);
			s.insert(a);
		}
	}

	return count <= n;
}

int binary_search(int n)
{
	int left = -1;
	int right = n;
	while (right - left > 1)
	{
		int mid = left + (right - left) / 2;
		if (isOK(mid))
			right = mid;
		else
			left = mid;
	}
	return right;
}


signed main()
{
	cin >> N;
	REP(i, N) cin >> A[i];

	int ans = binary_search(100001);

	cout << ans << endl;
}



Measured memory_bytes: 8564
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

// iで爆発させてiからi+2Dの2D+1箇所に攻撃するとみる

P X[200009];
int Y[200009];
ll sum[200009]; // sum[i]:1からi番目の位置までで何回爆発させたか

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

	ll N, D, A; cin >> N >> D >> A;
	X[0].first = -1000000000;
	for (int i = 1; i <= N; i++) cin >> X[i].first >> X[i].second;
	sort(X + 1, X + N + 1);
	for (int i = 0; i <= N; i++) Y[i] = X[i].first;
	for (int i = 1; i <= N; i++) {
		int pos = X[i].first;
		int* p = lower_bound(Y, Y + N + 1, X[i].first - 2 * D);
		int left = p - Y; // X[i]から2*D内にある最も遠い点
		//cout << left << endl;
		X[i].second -= (sum[i - 1] - sum[left - 1]) * A;
		sum[i] = sum[i - 1];
		if (X[i].second > 0) {
			int cnt = X[i].second / A;
			if (X[i].second % A != 0) cnt++;
			sum[i] += cnt;
		}
	}
	cout << sum[N] << endl;


	return 0;
}

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

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

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                               \
  cerr << #v << ": ";                              \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", "; \
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vector<pair<ll, char>> pqr;
  REP(i, A + B + C) {
    char type;
    if (i < A)
      type = 'A';
    else if (i < A + B)
      type = 'B';
    else
      type = 'C';

    ll tmp;
    cin >> tmp;
    pqr.emplace_back(tmp, type);
  }

  sort(pqr.begin(), pqr.end());
  reverse(pqr.begin(), pqr.end());
  int XY = X + Y;
  ll ans = 0;
  for (int i = 0; i < A + B + C; i++) {
    ll val = pqr[i].first;
    char type = pqr[i].second;

    if (XY == 0) break;

    if (type == 'A') {
      if (X == 0) continue;
      X--;
      XY--;
    } else if (type == 'B') {
      if (Y == 0) continue;
      Y--;
      XY--;
    } else {
      XY--;
    }

    ans += val;

  }

  cout << ans << endl;
}


Measured memory_bytes: 10604
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
#define int long long
using namespace std;
int A,B,C,X,Y,H,G,D;
int top,q1[555],q2[555],q3[555];
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
void exgcd(int x,int y,int &a,int &b){
	if (!y){
		a=1; b=0;
		return;
	}
	exgcd(y,x%y,b,a);
	b-=x/y*a;
}
int getinv(int x,int y){
	int a,b;
	exgcd(x,y,a,b);
	return (a%y+y)%y;
}
void get_seq(int C,int D){
	top=q1[0]=q2[0]=0;
	int len=1,x,a=1,b=0;
	for (;D;){
		//cout<<"debug "<<C<<' '<<D<<' '<<a<<endl;
		++top;
		q1[top]=q1[top-1]+C/D*a;
		q2[top]=q2[top-1]+C/D*D;
		q3[top]=C/D;
		For(T,1,2){
			if (T==1) b+=C/D*a;
			else a+=C/D*b;
			x=C%D; C=D; D=x;
			if (!D) break;
		}
	}
}
ll Mydiv(ll x,ll y){
	return x<0?-1:x/y;
}
void solve(){
	scanf("%lld%lld%lld%lld%lld",&A,&X,&B,&Y,&C);
	G=gcd(A,B); A/=G; B/=G; C/=gcd(C,G);
	G=gcd(A,C); A/=G; C/=G;
	H=gcd(G,B); B/=H; Y/=G/H;
	G=gcd(B,C); B/=G; C/=G;
	H=gcd(G,A); A/=H; X/=G/H;
	A%=C; B%=C;
	if (C==1) return cout<<X+Y<<endl,void(0);
	D=1ll*A*getinv(B,C)%C; get_seq(C,D);
	if (q1[top]!=C) q1[++top]=C,q2[top]=C,q3[top]=1;
	//For(i,1,top) cout<<q1[i]<<' '<<q2[i]<<' '<<q3[i]<<endl;
	int ans=0;
	For(i,1,top){
		int lx=q1[i-1],rx=q1[i];
		int ly=C-q2[i-1],ry=C-q2[i];
		int dx=(rx-lx)/q3[i],dy=(ly-ry)/q3[i];
		int l=ans+1,r=X+Y+1;
		//cout<<lx<<' '<<ry<<' '<<dx<<' '<<dy<<' '<<ans<<endl;
		while (l<=r){
			int mid=(l+r)/2;
			ll p=Mydiv(X-1ll*mid*lx,dx);
			ll q=Mydiv(Y-1ll*mid*ry,dy);
			if (p>=0&&q>=0&&p+q>=1ll*q3[i]*mid)
				ans=max(ans,mid),l=mid+1;
			else r=mid-1;
		}
	}
	cout<<ans<<endl;
}
signed main(){
	int T;
	scanf("%lld",&T);
	while (T--) solve();
}


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

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

vector<set<ll>> S(20);
int lunlun(int n){
    if(n == 1){
        for(ll i = 1; i <= 9; i++) S[n].insert(i);
    }
    for(ll i : S[n-1]){
        ll last = i % 10;
        if(last != 0) S[n].insert(i * 10 + last - 1);
        S[n].insert(i * 10 + last);
        if(last != 9) S[n].insert(i * 10 + last + 1);
    }
    return S[n].size();
}

int main(){
    int K;
    cin >> K;
    int digit = 1;
    while(1){
        int c = lunlun(digit);
        if(K <= c){
            auto itr = S[digit].begin();
            advance(itr, K - 1);
            cout << *itr << endl;
            break;
        }
        K -= c;
        digit++;
    }

}

Measured memory_bytes: 12960
m,a[9][2],S[2499];D(d,s){int i=d==m?++S[s]+99:0;for(;i<=a[d][1];i++)D(d+1,s+i**a[d]);}main(i){for(;scanf("%d",&m),m;){for(i=0;i<m;i++)scanf("%d%d",a[i],a[i]+1);memset(S,0,9996);D(0,0);for(scanf("%d",&i);i;i--)scanf("%d",&m),printf("%d\n",S[m]);}exit(0);}

Measured memory_bytes: 616
#include<iostream>
#include<cmath>
#include<string>
using namespace std;

int main()
{
     string str,str1;
     cin>>str>>str1;
     for(int i=0;i<str1.size();i++)
     {
     	cout<<str1[i];
     	
     }
       for(int i=0;i<str.size();i++)
     {
     	cout<<str[i];
     	
     }
     
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "
const int MXN = 1e6+6;
string s[MXN];
int mi[MXN];
int mi_rev[MXN];
int sum[MXN];

int main()
  {
  ios_base::sync_with_stdio(0); 
  int n;
  cin >> n;
  VI all;
  REP(i, n)
    {
    cin >> s[i];
    for(auto j: s[i])
        {
        sum[i] += (j == '(') ? 1 : -1;
        mini(mi[i], sum[i]);
        }
    all.PB(i);

    reverse(ALL(s[i]));
    int ss = 0;
    for(auto j: s[i])
      {
      ss += j == ')' ? 1 : -1;
      mini(mi_rev[i], ss);
      }
//    debug(mi_rev[i], sum[i], mi[i]);
//    assert(abs(mi_rev[i]) == sum[i] - mi[i]);
    }
  sort(ALL(all), [&](int a, int b){
    if((sum[a] >= 0) != (sum[b] >= 0))return (sum[a] >= 0) > (sum[b] >= 0);
    if(sum[a] >= 0)
      {
      return mi[a] > mi[b];
      }
    else
      {
//      return mi_rev[a] < mi_rev[b];
      return sum[b] - mi[b] < sum[a] - mi[a];        
      }
  });

  int s = 0;
  for(auto i: all)
    {
    if(s + mi[i] < 0)
      {
      puts("No");
      return 0;
      }
    s += sum[i];
    }
  if(s == 0)puts("Yes");
  else puts("No");
  }


Measured memory_bytes: 50412
#include<bits/stdc++.h>
using namespace std;
int main(){
	int c0=0,c1=0,c2=0,c3=0;
	int n;
	string s;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s=="AC")
		c0++;
		else if(s=="WA")
		c1++;
		else if(s=="TLE")
		c2++;
		else 
		c3++;
	}
	cout<<"AC x "<<c0<<endl
	    <<"WA x "<<c1<<endl
	    <<"TLE x "<<c2<<endl
	    <<"RE x "<<c3<<endl;
	return 0;
}

Measured memory_bytes: 3608