akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int R,G,B,K,i=0;cin>>R>>G>>B>>K;
  if(B>G&&G>R){
    cout<<"Yes"<<endl;
    return 0;
  }
  else{
    while(G<=R){
      G*=2;i++;
    }
    while(B<=G){
      B*=2;i++;
    }
    cout<<(i>K?"No":"Yes")<<endl;
  }
}
    


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) ll(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<ll,ll>;
using Pl = pair<ll,ll>;
using vi = vector<ll>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const ll dx[] = {0,1,0,-1,1,1,-1,-1};
const ll dy[] = {1,0,-1,0,1,-1,-1,1};
const ll inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



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

  ll n, m;
  cin >> n >> m;
  vector<Pl> c(n);
  rep(i,n) cin >> c[i].fi >> c[i].se;
  sort(all(c));
  ll ans = 0;
  ll idx = 0;
  while(m > 0) {
    ans += c[idx].fi * min(m, c[idx].se);
    m -= min(m, c[idx].se);
    idx++;
  }
  cout << ans << endl;

}

Measured memory_bytes: 1792
dim = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

d1 = [abs(x - y) for x, y in zip(a, b)]
print(sum(d1))

d2 = [(x - y)**2 for x, y in zip(a, b)]
print(pow(sum(d2), 1/2))

d3 = [(abs(x - y))**3 for x, y in zip(a, b)]
print(pow(sum(d3), 1/3))

print(max(d1))


Measured memory_bytes: 5648
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<long double, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << #i <<" "<<i<< std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;


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

  ll n,m;
  std::cin>>n>>m;

  std::vector<std::vector<ll>> dp(m+1,std::vector<ll>(1ll<<n,MOD));

  dp[0][0]=0;

  rep(i,0,m){
    ll a,b;
    std::cin>>a>>b;

    ll mask=0;
    rep(i,0,b){
      ll c;
      std::cin>>c;
      mask+=(1ll<<(c-1));
    }

    rep(j,0,1ll<<n){
      if((j|mask)!=j){
        dp[i+1][j]=dp[i][j];
      }else{
        ll val=dp[i][j];
        if(j==mask)chmin(val,a);
        for(ll k=j; k>0; k=(k-1)&j) {
          if((k|mask)==j)chmin(val,dp[i][k]+a);
		    }

        dp[i+1][j]=val;
      }
    }
  }

  if(dp[m][(1ll<<n)-1]!=MOD)std::cout<<dp[m][(1ll<<n)-1]<<"\n";
  else std::cout<<-1<<"\n";

  return 0;
}





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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[202020];
ll S[202020];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		S[i+1]=S[i]+A[i];
	}
	
	ll mi=1LL<<60;
	for(i=1;i<N;i++) {
		ll a=S[i];
		ll b=S[N]-a;
		mi=min(mi,abs(a-b));
	}
	cout<<mi<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 2560
X, K, D = map(int, input().split())

if(X >= 0):
    times = X//D
    if(times <= K):
        min_r = X%D
        min_l = min_r-D
    
        if(times%2 == K%2):
            print(abs(min_r))
        else:
            print(abs(min_l))
    else:
        print(abs(X-D*K))
    
else:
    times = abs(X//D)
    if(times <= K):
        min_l = X%D
        min_r = min_l-D

        if(times%2 == K%2):
            print(abs(min_l))
        else:
            print(abs(min_r))
    else:
        print(abs(X+D*K))

Measured memory_bytes: 9220
#include<stdio.h>
int main()
{
	int X, Y;
	scanf("%x %x",&X,&Y);
	if(X < Y)
	{
		printf("<\n");
	}
	 else if(X > Y)
	 {
		printf(">\n");
	 }
	else if(X == Y)
	{
		printf("=\n");
	}
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var K int
	var S string
	fmt.Scan(&K)
	fmt.Scan(&S)

	if len(S) > K {
		str := S[:K] + "..."
		fmt.Println(str)

	} else {
		fmt.Println(S)
	}

}

Measured memory_bytes: 1756
from sys import stdin


def main():
    c = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(3)]
    for a, b in [(0, 1), (1, 2), (2, 0)]:
        if (c[0][a] - c[0][b]) == (c[1][a] - c[1][b]) == (c[2][a] - c[2][b]):
            pass
        else:
            print('No')
            return

    for a, b in [(0, 1), (1, 2), (2, 0)]:
        if (c[a][0] - c[b][0]) == (c[a][1] - c[b][1]) == (c[a][2] - c[b][2]):
            pass
        else:
            print('No')
            return

    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>

#define SS string
#define BB break
#define JK j + k

using namespace std;

int main() {

	SS cnt;
	cin >> cnt;
	int N, ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		SS S;
		cin >> S;
		for (int j = 0; j < 10; j++) {
			SS L;
			int flag = 0;
			for (int k = 0; k < cnt.size(); k++) {
				if ((JK) < 10)
					L += S[JK];
				else if ((JK) >= 10)L += S[JK - 10];
				if (cnt == L) {
					flag++; BB;
				}
			}
			if (flag == 1) {
				ans++; BB;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3164
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	ll a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]&a[1]&a[2]&1)cout<<a[0]*a[1]<<endl;
	else cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	string s;
	cin >> s;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == ',') s[i] = ' ';
	}
	cout << s << endl;
	return 0;
}

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

typedef long long ll;

#include <random>
vector<int> edg[100003];
bool used[100003];
int deg[100003];
vector<int> ans;
random_device rnd;
mt19937 mt(rnd());

bool func(int start, int pos) {
	for (int i = 0; i < (int)edg[pos].size(); ++i) --deg[edg[pos][i]];

	if (deg[start] == 0 && deg[pos] == 0) {
		ans.push_back(pos);
		return true;
	}
	used[pos] = true;
	for (int i = 0; i < (int)edg[pos].size(); ++i) {
		if (used[edg[pos][i]]) continue;
		if (func(start, edg[pos][i])) {
			ans.push_back(pos);
			return true;
		}
	}
	used[pos] = false;
	for (int i = 0; i < (int)edg[pos].size(); ++i) ++deg[edg[pos][i]];
	return false;
}

int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		--a; --b;
		edg[a].push_back(b);
		edg[b].push_back(a);
		++deg[a]; ++deg[b];
	}
	set<int> s;
	int pos;
	do {
		do {
			pos = mt() % n;
		} while (s.count(pos));
		s.insert(pos);
	} while (!func(pos, pos));
	cout << ans.size() << endl;
	for (int i = ans.size() - 1; i >= 0; --i) cout << ans[i] + 1 << (i == 0 ? "\n" : " ");
	return 0;
}


Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, y = 0; cin >> N;
  vector<int> A1(N), A2(N);
  for(int i = 0; i < N; i++) cin >> A1.at(i);
  for(int i = 0; i < N; i++) cin >> A2.at(i);
  for(int i = 0; i < N; i++) {
    int x = 0;
    for(int j = 0; j < N; j++) {
      x += ((j < i) ? A1.at(j) : A2.at(j));  
    }
    x += A1.at(i);
    y = max(x, y);
  }
  cout << y << endl;
}

Measured memory_bytes: 256
check :: String -> Bool
check s = checkEven s
checkEven [] = True
checkEven (c:s) = (c == 'R' || c == 'U' || c == 'D') && checkOdd s
checkOdd [] = True
checkOdd (c:s) = (c == 'L' || c == 'U' || c == 'D') && checkEven s

main = do
  s <- getLine :: IO String
  putStrLn $ if check s then "Yes" else "No"


Measured memory_bytes: 380
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#define rep(i,n) for(int i(0);i<n;i++)
using namespace std;
typedef long long ll;

bool dp(string s, int n){
	bool ans = false;
	
	if(n == s.length()) ans = true;

	if(s.substr(n,11) == "dreameraser") ans = dp(s,n+11);
	else if(s.substr(n,10) == "dreamerase") ans = dp(s,n+10);
	else if(s.substr(n,7) == "dreamer") ans = dp(s,n+7);
	else if(s.substr(n,5) == "dream") ans = dp(s,n+5);
	else if(s.substr(n,6) == "eraser") ans = dp(s,n+6);
	else if(s.substr(n,5) == "erase") ans = dp(s,n+5); 

	return ans;
};

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

	if(dp(s,0)) cout << "YES" << endl;
	else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
	char str[30];
	if(fgets(str, 30, stdin) == NULL){
		printf("error\n");
		exit(1);
	}

	int len = strlen(str);
	int count = 0;
	char* ans = "yes";
	for(int i=0;i<len;i++){
		for(int j=0;j<i;j++){
			if(str[i] == str[j]) ans = "no";
		}
	}

	printf("%s\n", ans);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

//#pragma GCC target("avx2")
//#pragma GCC optimization("unroll-loops")
//#pragma GCC optimize("O2")
//#pragma GCC optimize("O3")

#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define make_unique(v) v.erase(unique(all(v)),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa

const int N=2e5; 
const ll MOD=1e9+7;
int tv[10],zr=N-1,mk=N-2;
struct oper{
	char type;
	int i,j,k;
	oper(){}
	oper(char _type,int _i,int _j,int _k){
		type=_type;
		i=_i;
		j=_j;
		k=_k;
	}
};
vector<oper> ans;
void add(int a,int b,int c){
	ans.ad({'+',c,b,a});
}
void harc(int a,int b,int c){
	ans.ad({'<',c,b,a});
}
void plant(int ind){
	harc(tv[0],0,zr);
	harc(tv[1],1,zr);
	add(tv[2],tv[0],tv[1]);
	harc(ind,tv[2],zr);
}
void multp2(int ind,int pw){
	FOR(i,pw){
		add(ind,ind,ind);
	}
}
int cnt=3;
int ba[70],bb[70];
int pa[70],pb[70];
void represent(int ind,int* bn,int* pw){
	int bsch=cnt++;
	int tiv=cnt++;
	FORD(i,32){
		pw[i]=cnt++;
		plant(pw[i]);
		multp2(pw[i],i);
		add(bsch,tiv,pw[i]);
		harc(pw[i],ind,bsch);
		multp2(pw[i],i);
		add(tiv,tiv,pw[i]);
		bn[i]=cnt++;
		harc(bn[i],pw[i],zr);
	}
}
int main(){
	srng;
	fastio;
	FOR(i,10){
		tv[i]=N-i-4;
	}
	plant(mk);
	add(0,0,mk);
	add(1,1,mk);
	represent(0,ba,pa);
	represent(1,bb,pb);
	FOR(i,32){
		FOR(j,32){
			add(tv[0],ba[i],bb[j]);
			harc(tv[0],tv[0],mk);
			multp2(tv[0],i+j);
			add(2,2,tv[0]);
		}
	}
	cout<<ans.size()<<endl;
	FOR(i,ans.size()){
		cout<<ans[i].type<<" "<<ans[i].i<<" "<<ans[i].j<<" "<<ans[i].k<<endl;
	}
	return 0;
}	


Measured memory_bytes: 4260
#include<stdio.h>
#include<string.h>
int main(void) {
	int a[10000],n,b=0,i,x,d=3;
	char r[10000];
	char s[10000];
	scanf("%d", &n);
	sprintf(s, "%d", d);
	for(i = 1; i <= n; i++) {
		sprintf(r,"%d", i);
		if (i % 3 == 0) {
			a[b] = i;
			b++;
		}
		else if (strstr(r,s) != NULL) {
			a[b] = i;
			b++;
	}

	}
	for (x = 0; x < b; x++) {
		if (x == 0) {
			printf(" ");
	}
		printf("%d",a[x]);
		if (x == b - 1) {
			printf("\n");
		}
		else {
			printf(" ");
		}
	}
	return 0;
}


Measured memory_bytes: 2732
a,b=map(int,input().split())
s=input()
t=True
if s[a]=="-":
    x,y=s[:a],s[a+1:]
    if len(x) != a or len(y) != b or "-" in x or "-" in y:
        t=False
else:
    t=False
print("Yes" if t else "No")

Measured memory_bytes: 9184
import sys
from bisect import bisect_left

N, K, *X = map(int, open(0).read().split())

# 0 を除外
X = [x for x in X if x != 0]

zero_index = bisect_left(X, 0)
# 0 にロウソクがある場合、Kを減らしてよい
K -= N - len(X)

# 座標 0 にロウソクがあるとき、開始時点でクリアしている場合がある
if K <= 0:
  print(0)
  sys.exit()

ret = float("inf")

# しゃくとり法で解く 
# 0 がどこに入るかでループの開始位置が変わる
if zero_index > K:
  head_start = zero_index - K
  tail_start = zero_index - 1
else:
  head_start = 0
  tail_start = K - 1
  
# 必要な時間は両端のロウソクの近い方を2倍して長い方を足したもの
# ループは O(K) = O(10^5) なので間に合う
for head, tail in zip(X[head_start:], X[tail_start:]):
  if head < 0 and tail < 0:
    ret = min(ret, -head)
  elif head < 0 and tail > 0:
    tmp = min(2 * tail - head, tail - 2 * head) 
    ret = min(ret, tmp)
  else: # head > 0 and tail > 0
    ret = min(ret, tail)

print(ret)

Measured memory_bytes: 14436
nkc=input().split()
K=int(nkc[1])
C=int(nkc[2])
s=input()
workday_list=[]
for i,youso in enumerate(s) :
  if youso=='o' :
    workday_list.append(i+1)
    

s=1

current_num=0
current_num1=1
list1=[]
list1.append(workday_list[0])
while(s<K) :
  
  if current_num1>=len(workday_list):
    break
  elif workday_list[current_num1]-workday_list[current_num]>C :
    current_num=current_num1
    list1.append(workday_list[current_num1])
    s+=1
  else :
    current_num1=current_num1+1
m=1  

current_num2=len(workday_list)-1
current_num3=len(workday_list)-2
list2=[]
list2.append(workday_list[-1])
while(m<K) :
  
  if current_num3<0:
    break
  elif workday_list[current_num2]-workday_list[current_num3]>C :
    current_num2=current_num3
    list2.append(workday_list[current_num3])
    m+=1
  else :
    current_num3=current_num3-1

list2.reverse()

flag=True
for i in range(len(list1)) :
  if list1[i]==list2[i] :
    flag=False
    print(list1[i])
if flag :
  print()


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

using namespace std;

int main() {
  int A, B;

  cin>>A>>B;

  if(A<=5) {
    B = 0;
  } else if(A>=6 && A<=12) {
    B = B / 2;
  } else {
    B = B;
  }

  cout<<B<<endl;

  return 0;
}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		int ans=0;
		if(X%(Y+Z)>=Z) {
			ans=X/(Y+Z);
		}else {
			ans=X/(Y+Z)-1;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, m, ans;
bool g[10][10];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    vector<int> a;
    erep(i, 1, n) a.pb(i);
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        g[a][b] = g[b][a] = true;
    } 
    do {
        bool flag = true;
        if (a[0] != 1) continue;
        rep(i, 0, a.size()-1) {
            if (!g[a[i]][a[i+1]]) flag = false;
        }
        if (flag) ans++;
    } while (next_permutation(all(a)));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
 
signed main(){
    int N,D,X;cin>>N>>D>>X;
    REP(i,N){
        int a;cin>>a;
        X+=1+(D-1)/a;
    }
    cout<<X<<endl;
}

Measured memory_bytes: 256
// C - Green Bin 2019/8/16

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct tnode{
    char key[21];
    long int count;
    struct tnode *left,*right;
}tnode;

tnode *root = NULL;

//昇順にソート
void insertionSort(char a[],int n){
    int i,j;
    char v;
    for(i=1;i<n;i++){
        v=a[i];          //v:未ソート部分の先頭
        j=i-1;
        while(j>=0&&a[j]>v){
            a[j+1]=a[j];    //vより大きい要素を後方へ移動
            j--;
        }
        a[j+1]=v;
    }
}

//単語ノードの作成
tnode *createTNode(char str[]){
    tnode *new;
    new = malloc(sizeof(tnode));
    if(new == NULL){               //メモリが確保できたか確認
        printf("Can not allocate memory\n");
        return NULL;
    }
    strcpy(new->key,str);
    new->left = NULL;
    new->right = NULL;
    new->count=0;
    return new;
}

//二分探索木への単語の追加
void insertTerm(char str[],long int *ans){
    tnode *new = createTNode(str);   //単語ノードを作成
    tnode *temp1 = root;
    tnode *temp2 = NULL;
    //newの親を見つける
    while(temp1!=NULL){
        temp2=temp1;     //親を設定
        if(strcmp(new->key,temp1->key)<0){    //new->keyの方が小さいとき左に進む
            temp1 = temp1->left;
        }else if(strcmp(new->key,temp1->key)>0){                          //new->keyの方が大きいとき右に進む
            temp1 = temp1->right;
        }else{
            temp1->count++;
            (*ans)+=temp1->count;
            free(new);
            return;
        }
    }
    //newがrootかどうか,左子か右子か
    if(temp2==NULL){   //newがrootのとき
        root = new;
    }else{
        if(strcmp(new->key,temp2->key)<0){   //newがyの左子のとき
            temp2->left = new;
        }else{                     //newがyの右子とき
            temp2->right = new;
        }
    }
}

int main(void){
    int n,i;
    long int ans=0;
    char str[11];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",str);
        insertionSort(str,10);
        //printf("%s\n",str);
        insertTerm(str,&ans);
    }
    printf("%ld\n",ans);
    return 0;
}


Measured memory_bytes: 6400
#include <stdio.h>

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

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

  int V[N],C[N];
  for(int i = 0;i < N;i++){
    scanf("%d",&V[i]);
  }
  for(int i = 0;i < N;i++){
    scanf("%d",&C[i]);
  }

  int ans = 0;
  for(int i = 0;i < N;i++){
    ans += max(0,V[i]-C[i]);
  }

  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int i,ct1,ct2,flag = 0;
  char s[100001];
  scanf("%s",s);
  for(i = 0;s[i] != 0;i++){
    if(s[i]-'0'!=flag){ct1++;}flag = 1-flag;
  }flag = 1;
  for(i = 0;s[i] != 0;i++){
    if(s[i]-'0'!=flag){ct2++;}flag = 1-flag;
  }
  printf("%d\n",ct1 > ct2?ct2:ct1);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
using namespace std;
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define PER(i, a, b) for(int i = a; i >= b; i--)
#define LL long long
inline int read() {
    int x = 0, flag = 1;char ch = getchar();
    while(!isdigit(ch)) {
        if(ch == '-') flag = - 1;
        ch = getchar();
    }
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return x * flag;
}

int n, k;

int main() {   
    n = read(); k = read();
    if(k <= (n + 1) / 2) cout << "YES" << endl;
    else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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! 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")
    };
}

fn main() {
    input! {
        s: String,
    }
    unsafe {
        let ans = format!("{}{}", "2018", s.slice_unchecked(4, s.len()));
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int n,m;
int z[maxn];
int main()
{
    scanf("%d%d", &n, &m);
    while (m--)
    {
        int tmp1,tmp2;
        scanf("%d%d", &tmp1, &tmp2);
        ++z[tmp1];
        ++z[tmp2];
    }
    int flag = 1;
    for (int i = 1; i <= n; ++i)
        if (z[i] % 2)
            flag = 0;
    if (flag)
        puts("YES");
    else
        puts("NO");
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std ;
typedef int Read ; // Here to change the type of numbers
inline Read Readin() {
	Read K = 0 , F = 1 ; char C = ' ' ;
	while( C < '0' or C > '9' ) F = C == '-' ? -1 : 1 , C = getchar() ;
	while( C <= '9' and C >= '0' ) K = ( K << 1 ) + ( K << 3 ) + C - '0' , C = getchar() ;
	return F * K ;
}
inline Read Min( Read A , Read B ) { return A < B ? A : B ; }
inline Read Max( Read A , Read B ) { return A > B ? A : B ; }
inline Read Abs( Read A ) { return A < 0 ? -A : A ; }

int main() {
	
	int N ;
	N = Readin() ;
	if( N - 7 == 0 or N - 5 == 0 or N - 3 == 0 ) printf( "YES\n" ) ;
	else printf( "NO\n" ) ;
	return 0 ; 
	
}

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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100000 + 10;

const int64 mod = 1000000007;

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

	int n; cin >> n;

	int64 answer = 1;
	int remaining = 0;
	int last = 1;

	for (int i = 0; i < n; ++i){
		int x; cin >> x;

		if (x >= last){
			remaining++;
			last += 2;
		}
		else if (x + 1 == last){
			answer = answer * (remaining + 1) % mod;
		}
	}

	while (remaining)
		answer = answer * remaining-- % mod;

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

bool prime(int x) {
  if (x == 2) return 1;
  if (x % 2 == 0) return 0;
  if (x == 1) return 1;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return 0;
  }
  return 1;
}

int main() {
  int x;
  cin >> x;
  for (int i = x; i; i++) {
    if (prime(i)) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
typedef long long ll;
typedef long double ld;
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	string x = s + s;
	if (x.find(t) == -1)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

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

int main(){
  vector<string> S;
  vector<int> cnt;

  string s, ans1, ans2; int mode = 0, longest = 0;
  while(cin >> s){
    bool new_word = true;

    for(int i=0; i<S.size(); i++){
      if(S[i] == s){
        new_word = false;
        cnt[i]++; 
        break;
      }
    }

    if(new_word){
      S.push_back(s);
      cnt.push_back(1);
      if(s.length() > longest){
        longest = s.length();
        ans2 = s;
      }
    }
  }

  for(int i=0; i<cnt.size(); i++) mode = max(mode, cnt[i]);

  for(int i=0; i<cnt.size(); i++){
    if(mode == cnt[i]) ans1 = S[i];
  }

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


Measured memory_bytes: 3024
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;

int n;
ll arr[110][110] = {};
ll flow[110][110] = {};
ll capacity[110][110] = {};

ll solve() {
	n += 2;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			capacity[i][j] += arr[i][j];
		}
	}

	const int s = 0;
	const int t = n-1;

	ll total = 0;
	while (1) {
		//cout << total << endl;
		queue<int> Q; Q.push(s);
		vector<int> prev(n, -1); prev[s] = s;
		while (!Q.empty() && prev[t] < 0) {
			int u = Q.front(); Q.pop();
			for (int i = 0; i < n; i++) {
				if (prev[i] < 0 && capacity[u][i] - flow[u][i] > 0) {
					prev[i] = u;
					Q.push(i);
				}
			}
		}
		if (prev[t] < 0) return total;
		ll inc = pow(10, 12);
		for (int j = t; prev[j] != j; j = prev[j]) {
			//cout << j << " ";
			inc = min(inc, capacity[prev[j]][j] - flow[prev[j]][j]);
		}
		//cout << endl << endl;
		for (int j = t; prev[j] != j; j = prev[j]) {
			flow[prev[j]][j] += inc, flow[j][prev[j]] -= inc;
		}
		total += inc;
	}


}


int main() {
	cin >> n;
	ll answer = 0;

	for (int i = 1; i <= n; i++) {
		int input;
		cin >> input;
		if (input > 0) {
			arr[i][n+1] = input;
			answer += input;
		}
		else {
			arr[0][i] = -1*input;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 2; i*j <= n; j++) {
			arr[i][j*i] = pow(10, 12);
		}
	}

	cout << answer - solve() << endl;

	return 0;
}

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

int main(){
   int n;
   cin>>n;
   int a,last=-1,re=0,sum=0,c[20],cc[20];
   for(int i=0;i<n;i++){
	   cin>>a;
	   if(a==last+1){
		   cc[re]=last;
			re++;
	   }
	   last=a;
   }
   for(int i=0;i<n;i++){
	   cin>>a;
	   sum+=a;
   }
   for(int i=0;i<n-1;i++){
	   cin>>c[i];
   }
   for(int i=0;i<re;i++){
	   sum+=c[cc[i]-1];
   }
   cout<<sum<<endl;
   return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};
struct Prob {
    n: usize,
    m: usize,
    x: Vec<(usize, usize, i32, i32)>,
}

impl Prob {
    fn dfs(&self, v: &mut Vec<i32>, i: usize) -> i32 {
        if i == self.n {
            let mut res: i32 = 0;
            for (a, b, c, d) in &self.x {
                let a = *a - 1;
                let b = *b - 1;
                if v[b] - v[a] == *c {
                    res += d;
                }
            }
            return res;
        }
        let tail: i32 = if i == 0 { 1 } else { v[i - 1] };
        let mut res = 0;
        for j in (tail as usize)..(self.m + 1) {
            v[i] = j as i32;
            res = res.max(self.dfs(v, i + 1));
        }
        return res;
    }
}
#[fastout]
fn main() {
    input! {
        n:usize,
        m:usize,
        q:usize,
        x:[(usize, usize, i32, i32); q],
    }

    let p = Prob { n, m, x };

    let mut v: Vec<i32> = vec![0; n];
    let ans = p.dfs(&mut v, 0);
    println!("{}", ans);
}


Measured memory_bytes: 2208
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<functional>
#include<numeric>
#include<random>
 
using namespace std;

int main() { 
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	for (auto& e : x) {
		cin >> e;
	}
	int ans = { 1000000000 };
	for (int j = 0; j + k - 1 < n; j++) {
		int a = x[j];
		int b = x[j+k-1];
		if (a >= 0) {
			ans = min(ans, b);
			break;
		}
		if (b <= 0) {
			ans = min(ans, -a);
		}
		else {
			ans = min(ans, b - a + min(-a, b));
		}

	}


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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    ll l,r; cin>>l>>r;
    ll mod=2019;
    ll mini=INF;
    int cnt=0;
    for(ll i=l; i<r; i++){
        for(ll j=i+1; j<=r; j++){
            ll x=i%mod;
            ll y=j%mod;
            ll e=y*x%mod;
            mini=min(mini, e);
            cnt++;
            if(cnt>2019*2019){
                cout<<mini<<endl;
                return 0;
                 
  }
        }
    }
    cout << mini << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int r = sc.nextInt();
            if (n == 0 && r == 0) break;
            int[] huda = new int[n];

            for (int i = 0; i < n; i++)
                huda[i] = n - i;
            for (int j = 0; j < r; j++) {
                int p = sc.nextInt();
                int c = sc.nextInt();
                int[] temp = new int[p-1];
                for (int k = 0; k < p - 1; k++)
                    temp[k] = huda[k] + 0;
                for (int l = 0; l < c; l++)
                    huda[l] = huda[l + p - 1] + 0;
                for (int m = 0; m < p -1; m++)
                    huda[m + c] = temp[m];
            }
            System.out.println(huda[0]);
        }
    }
}


Measured memory_bytes: 38228
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	int x, y, z;
	scanf("%d%d", &x, &y);
	if ((x>0 && y>0 && x<=y) || (x<0 && y<0 && x<=y)) {
		z = y - x;
	} else if ((x>0 && y>0) || (x<0 && y<0)) {
		z = x - y + 2;
	} else if (x == 0 && y>0) {
		z = y;
	} else if (x<0 && y == 0) {
		z = abs(x);
	} else {
		z = abs(abs(y)-abs(x)) + 1;
	}

	printf("%d\n", z);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll accm = {0};
    for (ll i = 1; i <= 100; i++) {
        accm.emplace_back(accm.back() + i);
    }
    ll ans = 0;
    for (ll i = 2; i * i <= n; i++) {
        ll tmp = 0;
        if (n % i == 0) {
            while (n % i == 0) {
                tmp++;
                n /= i;
            }
            ll num = lower_bound(ALL(accm), tmp + 1) - accm.begin();
            // cout << num << '\n';
            ans += num - 1;
        }
    }
    if (n > 1) ans++;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3648
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#x = int(input())
n, k = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

c = []
for i in range(k):
    d = int(input())
    a = list(map(int, sys.stdin.readline().split()))
    for j in range(len(a)):
        c.append(a[j])

x = collections.Counter(c)
print(n-len(x))


Measured memory_bytes: 9588
a,b,c,k = map(int,input().split())
res = 0
tmp = min(a, k)
res += tmp
k -= tmp
if k <= 0:
    print(res)
    exit(0)
tmp = min(b, k)
k -= tmp
if k <= 0:
    print(res)
    exit(0)
tmp = min(c, k)
res -= tmp
print(res)

Measured memory_bytes: 61612
N = int(input())
X = list(map(int, input().split()))
min_total = 0
X_ = sum(X) // len(X)

for i in range(2):
    total = 0
    for j in range(N):
        total += (X[j] - (X_ + i)) ** 2
    if i == 0 or min_total >= total:
        min_total = total
print(min_total)

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

bool isPrime[300001] = {true};

void eratos(void) {
  for (int i = 0; i < 300001; i++)
    isPrime[i] = true;
  
  isPrime[0] = isPrime[1] = false;
  
  for (int i = 6; i * i < 300001; i++) {
    if (i % 7 != 1 && i % 7 != 6) continue;
    for (int j = i * 2; j < 300001; j += i)
      isPrime[j] = false;
  }
}

int main() {
  eratos();
  while (true) {
    int n;
    cin >> n;
    if (n == 1) return 0;

    cout << n << ":";
    for (int i = 6; i <= n; i++) {
      if (i % 7 != 1 && i % 7 != 6) continue;
      if (!isPrime[i]) continue;
      if (n % i == 0) cout << ' ' << i;
    }
    cout << endl;
  }
}

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

int main(){
	string s;
	cin >> s;
	rep(i, 3){
		cout << s.at(i);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3624
fn main() {
    let line = read();
    if line == "AAA" || line == "BBB" {
        println!("No");
    } else {
        println!("Yes");
    }
}
fn read() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;
int dem[4005][3];

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    int n;
    cin>>n>>s;
    for(int i=n-1;i>=0;i--)
    {
        dem[i][0]=dem[i+1][0]+(s[i]=='B');
        dem[i][1]=dem[i+1][1]+(s[i]=='G');
        dem[i][2]=dem[i+1][2]+(s[i]=='R');
    }
    int res=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(s[i]==s[j]) continue;
            char c='B'+'G'+'R'-s[i]-s[j];
            int k=2*j-i;
            int val;
            if(c=='B') val=dem[j][0];
            else if(c=='G') val=dem[j][1];
            else val=dem[j][2];
            if(k>=j&&k<n&&s[k]==c) res+=val-1;
            else res+=val;
        }
    }
    cout<<res;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

// a^n mod pを計算　O(log n)
long long int pow_mod(long long int a, long long int n, long long int p) {
    if (n == 0) {
        return 1;
    } else {
        long long int temp = pow_mod(a, n / 2, p);
        return n & 1 ? (((temp * temp) % p) * a) % p : (temp * temp) % p;
    }
}

// Z_pでのaの逆元を計算 O(log p)
// depend:pow_mod
long long int inv_mod(long long int a, long long int p) {
    return pow_mod(a, p - 2, p);
}

// 階乗テーブルを作ってコンビネーションをキビキビ計算する
// depend:inv_mod
struct combination_mod {
    using lint = long long int;
    int sz;
    vector<lint> data;
    lint mod;
    combination_mod(int _sz, lint _mod) : sz(_sz), mod(_mod) {
        data.assign(sz + 1, 1);
        for (lint i = 1; i <= sz; i++) data[i] = (data[i - 1] * i) % mod;
    }
    lint query(int n, int r) {
        lint res = 1;
        res = (res * data[n]) % mod;
        res = (res * inv_mod(data[r], mod)) % mod;
        res = (res * inv_mod(data[n - r], mod)) % mod;
        return res;
    }
};

int main() {
    lint mod = 998244353;
    lint n, a, b, k;
    cin >> n >> a >> b >> k;
    combination_mod cm(n, mod);
    lint ans = 0;
    // Aでi箇所塗る
    for (int i = 0; i <= n; i++) {
        // m:Bの数
        lint rem = k - a * i;
        lint m = rem / b;
        if (rem < 0 || rem % b != 0 || m > n) continue;
        lint temp = cm.query(n, i) * cm.query(n, m);
        temp %= mod;
        ans += temp;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define int long long 
signed main(void){
    int N;
    cin>>N;
    vector<int> s[1010];
    int sum = 0;
    int h;
    for (int i = 0; i < 1010; i++) {
        /* code */
        sum += i;
        h = i;
        if(sum > N){
            std::cout << "No" << std::endl;
            return 0;
        }
        if(sum ==N)break;
    }
    int now = 1;
    int w = 2 * N / h;
    for (int i = 0;; i++) {
        for (int j = i+1; j < w; j++) {
            s[i].push_back(now);
            s[j].push_back(now);
            now++;
            if(now == N+1)goto LOOP;
        }
    }
    LOOP:
    std::cout << "Yes" << std::endl;
    std::cout << w << std::endl;
    for (int i = 0; i < w; i++) {
        cout<<h<<" ";
        for (int j = 0; j < h; j++) {
            cout<<s[i][j]<<" ";
        }
        std::cout << "" << std::endl;
    }
    
    return 0;    
}


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

class Dice{
public:
  int f[6]; // face
  Dice(){} // instance
  void roll(int i,int j,int k,int l){
    int t = f[i];
    f[i] = f[j];
    f[j] = f[k];
    f[k] = f[l];
    f[l] = t;
  }
  void roll_y(){ roll(0, 2, 5, 3); } // to W
  void roll_x(){ roll(0, 1, 5, 4); } // to N
  void roll_z(){ roll(1, 2, 4, 3); }
};

bool eq( Dice d1, Dice d2 ){
  int i;
  for( i = 0; i < 6; i++ )
    if( d1.f[i] != d2.f[i] ) return false;
  return true;
}

bool equal( Dice d1, Dice d2 ){
int i, j;
  for( i = 0; i < 6; i++ ){
    for( j = 0; j < 4; j++ ){
      if( eq(d1, d2) ) return true;
      d1.roll_z();
    }
    if( i % 2 == 0 ) d1.roll_y();
    else d1.roll_x();
  }
  return false;
}

Dice D[100]; int n;

bool check(){
  int i, j;
  for( i = 0; i < n-1; i++ )
    for( j = i+1; j < n; j++ ) if( equal(D[i],  D[j]) )return false;
  return true;
}

int main(){
  cin >> n;
  int i, j;

  for( i = 0; i < n; i++ )
    for( j = 0; j < 6; j++ ) cin >> D[i].f[j];

  if( check() ) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


signed main()
{
int a,b,c;
std::cin >> a >> b >> c;
int out = 0;
out += b;
if(c <= b + a + 1){
    out += c;
} else {
    out += b + a + 1;
}
std::cout << out << std::endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
int main(){

	ll n, k, q;
	cin >> n >> k >> q;
	vector<ll> a(q);
	vector<ll> b(n,0);

	for (int i = 0; i < q; i++)	{
		cin >> a[i];
		b[a[i]-1]++;
	}

	for (int i = 0; i < n; i++){
		if (k-(q-b[i]) <= 0)	cout << "No" << endl;
		else cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, m, p;
    while (cin >> n >> m >> p && n){
        m--;
        int s = 0, x;
        REP(i,n){
            int a;
            cin >> a;
            s += a;
            if (i == m) x = a;
        }
        int ans = (x == 0 ? 0 : s * (100-p) / x);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3044
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	int H, W;
	cin >> H >> W;
	vector< vector< int > > A(H, vector< int >(W));
	vector< vector< int > > B(H, vector< int >(W));
	rep(i, H) rep(j, W) cin >> A[i][j];
	rep(i, H) rep(j, W) cin >> B[i][j];
	vector< vector< int > > C(H, vector< int >(W));
	rep(i, H) rep(j, W) C[i][j] = abs(A[i][j] - B[i][j]);
	vector< vector< vector< int > > > dp(H, vector< vector< int > >(W, vector< int >((H + W) * 80, 0)));
	dp[0][0][C[0][0]] = 1;
	rep(i, H) rep(j, W) {
		rep(k, dp[0][0].size()) {
			int a = abs(k - C[i][j]);
			int b = abs(k + C[i][j]);
			if (i > 0) {
				dp[i][j][k] |= dp[i - 1][j][a] | dp[i - 1][j][b];
			}
			if (j > 0) {
				dp[i][j][k] |= dp[i][j - 1][a] | dp[i][j - 1][b];
			}
		}
	}
	int ans = LINF;
	rep(k, dp[0][0].size()) {
		if (dp[H - 1][W - 1][k]) {
			ans = k;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 650752
n, q = map(int, input().split())
tasks = []
sumtime = 0

for _ in range(n):
    task = input().split()
    time = int(task[1])
    if time <= q:
        sumtime += time
        print(task[0], sumtime)
    else:
        sumtime += q
        time = time - q
        tasks.append([task[0], time])

while tasks:
    command = []
    for j, task in enumerate(tasks[:]):
        time = task[1]
        if time <= q:
            sumtime += time
            print(task[0], sumtime)
            del tasks[tasks.index(task)]
        else:
            sumtime += q
            time = time - q
            tasks[(tasks.index(task))] = [task[0], time]


Measured memory_bytes: 9032