akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
const int MaxN=200010,inf=1<<23;
int N,P[MaxN],Q[MaxN],mx[MaxN],hcnt[MaxN],hsum[MaxN],
	f[MaxN],T[1<<19],fmax[MaxN];
int max(int a,int b){return a>b?a:b;}
void upd(int i,int x){for(;i<=N;i+=i&-i)T[i]=max(T[i],x);}
int qry(int i){int x=-inf;for(;i;i-=i&-i)x=max(x,T[i]);return x;}
char ans[MaxN];
#define Def int o,int L,int R
#define Mid (L+R>>1)
#define Ls o<<1,L,Mid
#define Rs o<<1|1,Mid,R
void build(Def){
	if(R-L==1)T[o]=f[L];
	else build(Ls),build(Rs),T[o]=max(T[o<<1],T[o<<1|1]); 
}
void del(Def,int i){
	if(R-L==1)T[o]=-inf;
	else{
		i<Mid?del(Ls,i):del(Rs,i);
		T[o]=max(T[o<<1],T[o<<1|1]);
	}
}
int query(Def,int l,int r){
	if(l==L&&r==R)return T[o];
	if(r<=Mid)return query(Ls,l,r);
	if(l>=Mid)return query(Rs,l,r);
	return max(query(Ls,l,Mid),query(Rs,Mid,r));
}
bool chk(int i,int p2,int dl){
	int sz=hcnt[N]-hcnt[i],p1=mx[i];
	if(sz>=dl){
		if(sz>=-dl&&(sz+dl)%2==0)return 1;
		if(fmax[p1]>=-sz-dl)return 1;
	}
	if(sz>=-dl){
		if(fmax[p1]>=dl-sz||p2+1<p1&&query(1,1,N+1,p2+1,p1)+hcnt[i]*2>=dl-sz)return 1;
	}
	return 0; 
}
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%d",P+i);
		Q[P[i]]=i;
		mx[i]=max(mx[i-1],P[i]);
		hcnt[i]=hcnt[i-1]+(mx[i]==P[i]);
		if(mx[i]==P[i])hsum[P[i]]=1;
	}
	for(int i=1;i<=N;i++)hsum[i]+=hsum[i-1],T[i]=-inf;
	fmax[N+1]=-inf;
	for(int i=N,j;i;i--){
		if(mx[j=Q[i]]>i){
			upd(N-j+1,f[i]=1+max(-hcnt[j]*2+max(fmax[mx[j]],0),qry(N-j+1)));
			fmax[i]=max(fmax[i+1],f[i]+hsum[i]*2);
		}
		else f[i]=-inf,fmax[i]=fmax[i+1];
	}
	build(1,1,N+1);
	del(1,1,N+1,P[1]);
	int p2=0,dl=1;
	if(!chk(1,p2,dl))return puts("-1"),0;
	ans[1]='0';
	for(int i=2;i<=N;i++){
		del(1,1,N+1,P[i]);
		int p1=mx[i-1];
		bool ty=ans[Q[p1]]=='0';
		ans[i]=chk(i,ty?p2:mx[i]==P[i]?p1:max(P[i],p2),mx[i]==P[i]?ty?dl+1:1-dl:dl-(!ty&&P[i]>p2))?'0':'1';
		if(mx[i]==P[i]){
			if(ty==(ans[i]=='0'))dl++;
			else p2=p1,dl=1-dl;
		}
		else if(ty!=(ans[i]=='0')&&P[i]>p2)p2=P[i],dl--;
	}
	puts(ans+1);
}

Measured memory_bytes: 8064
N, X, Y = map(int, input().split())
c = [0 for i in range(N)]
for i in range(1,N):
  for j in range(i+1,N+1):
    x = abs(X-i)
    y = abs(Y-j)
    a = min(x+y+1,j-i)
    c[a]+=1

for i in range(1,N):
  ans = c[i]
  print(ans)
  


Measured memory_bytes: 3444
import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int V[] = new int[N];
		int C[] = new int[N];
		int ans = 0;

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

		System.out.println(ans);

		sc.close();
	}
};

Measured memory_bytes: 35800
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int b[101],n,p,q,w,h;
  list<pair<int,int> > a;
  list<pair<int,int> >::iterator it;
  while(cin>>n>>w>>h&&n+w+h){
    a.clear();
    a.push_back(make_pair(w,h));
    for(i=0;i<n;i++){
      cin>>p>>q;
      it=a.begin();
      for(j=0;j<p-1;j++)
	it++;
      q%=(*it).first+(*it).second;
      if(0){
      }else if(q<(*it).first){
	if(q<(*it).first-q){
	  a.push_back(make_pair(q,(*it).second));
	  a.push_back(make_pair((*it).first-q,(*it).second));
	}else{
	  a.push_back(make_pair((*it).first-q,(*it).second));
	  a.push_back(make_pair(q,(*it).second));
	}
      }else if(q<(*it).first+(*it).second){
	q-=(*it).first;
	if(q<(*it).second-q){
	  a.push_back(make_pair((*it).first,q));
	  a.push_back(make_pair((*it).first,(*it).second-q));
	}else{
	  a.push_back(make_pair((*it).first,(*it).second-q));
	  a.push_back(make_pair((*it).first,q));
	}
      }
      a.erase(it);
    }
    i=0;
    for(it=a.begin();it!=a.end();it++){
      b[i]=(*it).first*(*it).second;
      i++;
    }
    sort(b,b+n+1);
    for(i=0;i<n;i++)
      cout<<b[i]<<" ";
    cout<<b[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
t = set([])

for i in range(1,32):
    for s in range(2,32):
        if i**s<1001:
            t.add(i**s)
            
t = list(t)

t.append(1001)

t.sort(reverse = True)

x = int(input())

for i in range(len(t)-1):
    if t[i]>x>=t[i+1]:
        print(t[i+1])
        break
    

Measured memory_bytes: 9188
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
  public static void main(String args[] ) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String input;
    int x = 0;
    float y = 0;
    int s = 0;
    int c = 0;
    while((input = br.readLine()) != null){
      String[] inputArray = input.trim().split(",");
      int a = Integer.parseInt(inputArray[0]);
      float b = Float.parseFloat(inputArray[1]);
      x += a * b;
      y += b;
      c++;
    }
    int avg = (int)Math.round( y / c );
    System.out.println(x + "\n" +avg);
  }
}

Measured memory_bytes: 24148
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N, A, B, C := sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()
	L := sc.nextIntSlice(N)
	ans := int(1e+9)
	var dfs func(cur, a, b, c, cost int)
	dfs = func(cur, a, b, c, cost int) {
		if cur == N {
			if min(a, b, c) > 0 {
				cost += abs(A-a) + abs(B-b) + abs(C-c) - 30
				if cost < ans {
					ans = cost
				}
			}
			return
		}
		dfs(cur+1, a, b, c, cost)
		dfs(cur+1, a+L[cur], b, c, cost+10)
		dfs(cur+1, a, b+L[cur], c, cost+10)
		dfs(cur+1, a, b, c+L[cur], cost+10)
	}
	dfs(0, 0, 0, 0, 0)
	fmt.Println(ans)
}


Measured memory_bytes: 640
s = input()

if (s.find('00') > -1 or
	s.find('11') > -1 or
	s.find('22') > -1 or
	s.find('33') > -1 or
	s.find('44') > -1 or
	s.find('55') > -1 or
	s.find('66') > -1 or
	s.find('77') > -1 or
	s.find('88') > -1 or
	s.find('99') > -1):
	print('Bad')
else:
	print('Good')

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

bool prime[300001];
VI primeArray;
void makePrime(){
  int x = 6;
  while(x<300001){
    prime[x] = true;
    x+=7;
  }
  x = 8;
  while(x<300001){
    prime[x] = true;
    x+=7;
  }

  rep(i,300001){
    if(prime[i] == false) continue;
    int cnt = 2;
    while(i*cnt < 300001){
      prime[i*cnt] = false;
      cnt++;
    }
  }

  rep(i,300001){
    if(prime[i]) primeArray.push_back(i);
  }
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  makePrime();
  while(true){
    int x;
    cin >> x;
    if(x == 1) break;
    cout << x <<":";
    rep(i,primeArray.size()){
      if(x == 0) break;
      if(x % primeArray[i] == 0) cout <<" "<< primeArray[i];
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool C[100050];
vector<int> G[100050];
void DFS(int x) {
  C[x] = true;
  for (int i = 0; i < G[x].size(); i++) {
    if (C[G[x][i]] == false) {
      DFS(G[x][i]);
    }
  }
  return;
}


int main() {
  int N,M;
  cin >> N >> M;
  int X[M],Y[M],Z[M];
  for (int i = 0; i < N; i++) {
    C[i] = false;
  }
  for (int i = 0; i < M; i++) {
    cin >> X[i] >> Y[i] >> Z[i];
    X[i]--;
    Y[i]--;
    G[X[i]].push_back(Y[i]);
    G[Y[i]].push_back(X[i]);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (C[i] == false) {
      DFS(i);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10112
N,K=map(int, input().split())
a=list(map(int, input().split()))
x=0
len_bin=len(bin(K))-2

def bin_l(n,i):
    return (n>>(len_bin-i-1))%2

for i in range(len_bin):
    zero=0
    one=0
    for j in range(N):
        if bin_l(a[j],i)==0:
            zero+=1
        else:
            one+=1
    x=x<<1
    if zero>one and x<(K>>(len_bin-i-1)):
        x+=1

ans=0
for i in range(N):
    ans+=x^a[i]
print(ans)

Measured memory_bytes: 14708
import java.util.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		while(in.hasNext()){
			int n = in.nextInt(), k = in.nextInt();
			if(n == 0 && k == 0) return;
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = in.nextInt();
			int ans = 0 , t;
			for(int i = 0; i < k; i++){
				ans += a[i];
			}
			t = ans;
			int s = 0;
			for(int i = k; i < n; i++){
				t = t + a[i] - a[s];
				s++;
				ans = Math.max(ans,t);
			}
			System.out.println(ans);
		}
	}
	
	
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	vector<ll> a(3);
	for (int i=0; i<3; i++)
		cin>>a[i];
	ll ret=-1;
	sort(a.begin(), a.end());
	do {
		ll x=a[0]/2, y=a[0]-x;
		ll val=abs(x-y)*a[1]*a[2];
		if(ret==-1)
			ret=val;
		else
			ret=min(ret,val);
	} while(next_permutation(a.begin(),a.end()));
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input=lambda: sys.stdin.readline().strip()


n=int(input())
A=[]
#
PM=[[0,0] for i in range(n)]
for i in range(n):
    now=0
    mini=0
    for j in input():
        if j=="(": now+=1 
        else:
            now-=1 ; mini=min(mini,now)
    PM[i]=[mini,now]

if sum( [PM[i][1] for i in range(n)]  )!=0 : 
    print("No")
    exit()

MINI=0
NOW=0
PMf=[PM[i] for i in range(n) if PM[i][1]>=0]
PMf.sort()
for i in range(len(PMf)):
    MINI=min(MINI , NOW+PMf[-i-1][0] )
    NOW+=PMf[-i-1][1]
    if MINI<0 : print("No") ; exit()

PMs=[PM[i] for i in range(n) if PM[i][1]<0]
PMs=sorted(PMs , key=lambda x : x[1]-x[0])
for i in range(len(PMs)):
    MINI=min(MINI , NOW+PMs[-i-1][0] )
    NOW+=PMs[-i-1][1]
    if MINI<0 : print("No") ; exit()

print("Yes")


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


# def main():
#     n, m, k = map(int, input().split())
#     A = list(map(int, input().split()))
#     B = list(map(int, input().split()))
#     a = A[0]
#     A2 = [a]
#     b = B[0]
#     B2 = [b]
#     for i in range(1, n):
#         a += A[i]
#         A2.append(a)
# 
#     for i in range(1, m):
#         b += B[i]
#         B2.append(b)
#     max = -2
#     for ia, aa in enumerate(A2):
#         for ib, bb in enumerate(B2):
#             if aa + bb > k:
#                 break
#             if ia + ib > max:
# 
#                 max = ia + ib
#     print(max + 2)
# 

def answer():
    N, M, K = map(int, input().split())


    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
    for i in range(M):
        b.append(b[i] + B[i])

    ans, j = 0, M
    for i in range(N + 1):
        if a[i] > K:
            break
        while b[j] > K - a[i]:
            j -= 1
        ans = max(ans, i + j)
    print(ans)
if __name__ == '__main__':
    answer()

Measured memory_bytes: 132732
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.LongStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class E {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int X = in.nextInt();
            int Y = in.nextInt();
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            long[] p = in.nextLongArray(A);
            long[] q = in.nextLongArray(B);
            long[] r = in.nextLongArray(C);
            Arrays.sort(p);
            Arrays.sort(q);
            Arrays.sort(r);
            long[] ps = Arrays.copyOfRange(p, A - X, A);
            long[] qs = Arrays.copyOfRange(q, B - Y, B);
            long[] ls = new long[X + Y];
            System.arraycopy(ps, 0, ls, 0, X);
            System.arraycopy(qs, 0, ls, X, Y);
            Arrays.sort(ls);
            long sum = LongStream.of(ls).sum();
            for (int i = 0; i < X + Y && i < C; i++) {
                long v = ls[i];
                if (v < r[C - 1 - i]) {
                    sum += r[C - 1 - i] - v;
                }
            }
            out.println(sum);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

    }
}



Measured memory_bytes: 55268
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>

#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	int N;
	cin >> N;
	int H[N];
	int max=0;
	int count=0;
	rep(i,0,N){
		cin >> H[i];
		if(max <= H[i]){
			count++;
			max = H[i];
		}
	}
	cout << count << endl;
	
}

Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	int n;
	cin >> n;
	cout << (n - 2) * 180 << endl;
	return 0;
}


Measured memory_bytes: 3572
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main()
{
    int m, n, l, s, f, res;
    while (true) {
        scanf("%d", &l); if (l == 0) break;
        s = f = 0;
        rep(i, 12) {
            scanf("%d%d", &m, &n);
            s += (m - n);
            if (!f && s >= l) { res = i+1; f = 1; }
        }
        if (!f) puts("NA"); else printf("%d\n", res);
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W,N;
    cin >> H >> W >> N;
    cout << (N+max(H,W)-1)/max(H,W) << endl;
}

Measured memory_bytes: 256
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int H, A;
  cin >> H >> A;

  out((H + A - 1) / A)
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll output(ll a[], char mark)
{
    for(ll i=1; i<=13; i++)
    {
        if(a[i]==0) cout<<mark<<" "<<i<<endl;
    }
}
int main()
{
    char mark;
    ll S[14],H[14],C[14],D[14],t,n;
    for(int i=0; i<14; i++) S[i]=H[i]=C[i]=D[i]=0;
    cin>>n;
    while(n--)
    {
        cin>>mark>>t;
        switch(mark)
        {
            case 'S':
                S[t] = 1;
                break;
            case 'H':
                H[t] = 1;
                break;
            case 'C':
                C[t] = 1;
                break;
            case 'D':
                D[t] = 1;
                break;
        }
    }
    output(S,'S');
    output(H,'H');
    output(C,'C');
    output(D,'D');
    return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

//#####################
//Union-Find
//#####################

int uf_par[112345], uf_rnk[112345];

void uf_init(int size)
{
    REP(i, size)
    {
        uf_par[i] = i;
        uf_rnk[i] = 0;
    }
}

int uf_find(int x)
{
    if (uf_par[x] == x)
        return x;
    else
        return uf_par[x] = uf_find(uf_par[x]);
}

void uf_unite(int x, int y)
{
    x = uf_find(x);
    y = uf_find(y);
    if (x == y)
        return;

    if (uf_rnk[x] < uf_rnk[y])
    {
        uf_par[x] = y;
    }
    else
    {
        uf_par[y] = x;
        if (uf_rnk[x] == uf_rnk[y])
            uf_rnk[x]++;
    }
}

bool uf_same(int x, int y)
{
    return uf_find(x) == uf_find(y);
}

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

    int n, m, x[112345], y[112345], z[112345];

    cin >> n >> m;
    uf_init(n + 1);
    REP(i, m)
    {
        cin >> x[i] >> y[i] >> z[i];
        z[i] = (z[i] % 2);

        uf_unite(x[i], y[i]);
    }

    set<int> st;
    REP(i, n)
    {
        st.insert(uf_find(i + 1));
    }

    cout << st.size() << endl;

    return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;



int main() {
    ll n;
    cin >> n;
    ll a[n];
    ll c[n+1];
    ll ans = 0;
    REP(i,n) {
        c[i+1] = 0;
    }
    REP(i,n) {
        cin >> a[i];
        c[a[i]]++;
    }
    REP(i,n) {
        if(c[i+1] != 0) {
            ans += c[i+1]*(c[i+1] - 1)/2;
        }
    }
    REP(i,n) {
        ll tmp = ans;
        tmp -= c[a[i]]*(c[a[i]] - 1)/2;
        if (c[a[i]] > 2) {
            tmp += (c[a[i]] - 1 )*(c[a[i]] - 2)/2;
        }
        cout << tmp << endl;
    }
}

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

static const int INF=100000;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> y(N);
    vector<P> u(N);
    for(int i=0;i<N;i++){
        cin >> x[i] >> y[i];
        u[i]=make_pair(x[i],y[i]);
    }
    sort(u.begin(),u.end());
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            int dx=u[j].first-u[i].first;
            int dy=u[j].second-u[i].second;
            int cnt=0;
            for(int i=0;i<N;i++){
                for(int j=i+1;j<N;j++){
                    if(u[j].first-u[i].first==dx&&u[j].second-u[i].second==dy){
                        cnt++;
                    }
                }
            }
            ans=max(ans,cnt);
        }
    }
    cout << N-ans << endl;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
data = tuple(tuple(map(int, input().split())) for _ in range(N))
table = [dict() for _ in range(N + 1)]
table[0][0] = 0
for n in range(N):
    weight, value = data[n]
    for w, now in table[n].items():
        table[n + 1][w] = max(table[n + 1].get(w, 0), now)
        if w + weight <= W:
            table[n + 1][w + weight] = max(table[n + 1].get(w + weight, 0), now + value)
print(max(table[N].values()))

Measured memory_bytes: 11960
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX_N 500000
#define MAX_S 600
long long x[MAX_N];
long long TOP[MAX_S], n;
long long maxn1[MAX_N], maxn2[MAX_N];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x + n);
	long long cnt = 0;
	for (int i = n - MAX_S; i < n; i++) {
		if (i >= 0) {
			TOP[cnt] = x[i];
			cnt++;
		}
	}
	long long maxn = 0;
	for (int i = 0; i < cnt; i++) {
		for (int j = i + 1; j < cnt; j++) {
			for (int k = j + 1; k < cnt; k++) {
				if (TOP[i] + TOP[j] > TOP[k]) {
					maxn1[i] = max(maxn1[i], TOP[i] + TOP[j] + TOP[k]);
					maxn2[k] = max(maxn2[k], TOP[i] + TOP[j] + TOP[k]);
				}
			}
		}
	}
	for (int i = 0; i < cnt; i++) {
		for (int j = i + 1; j < cnt; j++) {
			maxn = max(maxn, maxn2[i] + maxn1[j]);
		}
	}

	for (int i = 0; i < cnt - 5; i++) {
		long long c[6], d[3], e[3];
		for (int j = 0; j < 6; j++) {
			c[j] = TOP[i + j];
		}
		long long cnt = 0, cnt1 = 0, cnt2 = 0;
		for (int j = 0; j < 64; j++) {
			cnt = 0;
			for (int k = 0; k < 6; k++) { cnt += (j / (1 << k)) % 2; }
			if (cnt == 3) {
				cnt1 = 0; cnt2 = 0;
				for (int k = 0; k < 6; k++) {
					if ((j / (1 << k)) % 2 == 0) {
						d[cnt1] = c[k];
						cnt1++;
					}
					else {
						e[cnt2] = c[k];
						cnt2++;
					}
				}
				if (d[0] + d[1]>d[2] && e[0] + e[1]>e[2]) {
					maxn = max(maxn, d[0] + d[1] + d[2] + e[1] + e[2] + e[0]);
				}
			}
		}
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 7320
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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 qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){
  int n;
 
  int m;
  int k;
  bool h=false;
  cin >> n >> m >> k;
  int ans = 0;
  FOR(i,n+1){
    FOR(j,m+1){
      ans = i*m + n*j - 2*i*j;
      if(ans ==k)
        h=true;
    }
  }
  if(h) cout <<"Yes\n";
  else cout <<"No\n";
        
  return 0;
}
 


struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;
string read()
{
	string res="";
	char c=0;
	while(c<'a'||'z'<c)c=getchar();
	while('a'<=c&&c<='z')res+=c,c=getchar();
	return res;
}
int n;
ll ans=0;
string s;
map<string,int>cnt;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		s=read();
		sort(s.begin(),s.end());
		ans+=(ll)cnt[s];
		cnt[s]++;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
//#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}


int main()
{
	int N, K, R;
	int a, b, c;
	int count = 0;
	int A[100000];

	//scanf("%d%d", &N, &K);
	scanf("%d%d", &N, &R);

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

	if (N < 10)
		printf("%d", R + 100 * (10 - N));
	else
		printf("%d", R);

}

Measured memory_bytes: 256
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe
import           Debug.Trace

main = do
  s <- BS.getLine
  let n = BS.length s
      solve score numG s | BS.length s == 0 = score
                          | otherwise
        =
        let
          c = BS.head s
          s' = BS.tail s
        in
          if      c=='g' && numG==0 then solve score (numG+1) s'
          else if c=='g'            then solve (score+1) (numG-1) s'
          else if c=='p' && numG==0 then solve (score-1) (numG+1) s'
          else                           solve score (numG-1) s'
  print $ solve 0 0 s

Measured memory_bytes: 3580
N = int(input())
graph = [[] for  _ in range(N)]
now = 0
for _ in range(N-1):
    x,y,w = map(int,input().split())
    x -= 1
    y -= 1
    graph[x].append((y,w))
    graph[y].append((x,w))
    now = x
    
vis = [0 for _ in range(N)]

even = set()
odd = set()
import sys
sys.setrecursionlimit(10000000)


def dfs(now):
    #print(now)
    for nv in graph[now]:
        if vis[nv[0]]: continue
        if nv[1] % 2 == 0:
            if now in even:
                even.add(nv[0])
            else:
                odd.add(nv[0])
        else:
            if now in even:
                odd.add(nv[0])
            else:
                even.add(nv[0])
        vis[nv[0]] = 1
        dfs(nv[0])
vis[x] = 1
even.add(x)
dfs(x)

for i in range(N):
    if i in even:
        print(1)
    else:
        print(0)



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

class P
{
public:
	double x,y;
	P(double x=0.0,double y=0.0):x(x),y(y){}
	P operator+(const P p)const{return P(x+p.x,y+p.y);}
	P operator-(const P p)const{return P(x-p.x,y-p.y);}
};

double dis(P p1,P p2)
{
	return hypot(p1.x-p2.x,p1.y-p2.y);
}

P getc(P p1,P p2)
{
	double theta=acos(dis(p1,p2)/2.0);
	double alpha=atan2(p2.y-p1.y,p2.x-p1.x);
	return P(p1.x+cos(alpha-theta),p1.y+sin(alpha-theta));
}

bool in(P c,P p)
{
	return dis(c,p)<1.0+1e-9;
}

int main()
{
	int n;
	while(cin>>n,n)
	{
		P p[300];
		for(int i=0;i<n;i++)
		{
			cin>>p[i].x>>p[i].y;
		}
		if(n==1)
		{
			cout<<1<<endl;
			continue;
		}
		int m=0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				P a=p[i],b=p[j];
				P c=getc(a,b);
				int cnt=0;
				for(int k=0;k<n;k++)
				{
					if(in(c,p[k]))cnt++;
				}
				m>cnt?:m=cnt;
			}
		}
		for(int i=0;i<n;i++)
		{
			P a=p[i];
			int cnt=0;
			for(int j=0;j<n;j++)
			{
				if(in(a,p[j]))cnt++;
			}
			m>cnt?:m=cnt;
		}
		cout<<m<<endl;
	}
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		s = s.replaceAll("eraser", "").replaceAll("erase", "").replaceAll("dreamer", "").replaceAll("dream", "");
		if(s.equals("")) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 28972
#include<stdio.h>
#include<stdlib.h>

int main(){
int N,i,s=0;
  scanf("%d",&N);
  int *p=(int*)malloc(sizeof(int)*N);
  for(i=0;i<N;i++){
    scanf("%d",&p[i]);
    if(p[i]!=(i+1))s++;
  }
  if(s<=2)printf("YES\n");
  else printf("NO\n");
  free(p);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define num(a) a-'0'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n,m;
	cin>>n>>m;
	vi s(m);
	vi a(n,-1);
	rep(i,0,m){
		int h;
		cin>>s[i]>>h;
		if(s[i]==1 && h==0 && n!=1){
			cout<<-1<<ln;
			return;
		}
		if(a[s[i]-1]==-1 || a[s[i]-1]==h){
			a[s[i]-1]=h;
		}
		else{
			cout<<-1<<ln;
			return;
		}
	}
	int h=1;
	if(n==1)
		h=0;
	rep(i,0,n){
		if(a[i]==-1){
			cout<<h;
			h=0;
		}
		else{
			cout<<a[i];
			h=0;
		}
	}
	cout<<ln;
}	

int main(){
	boost_io;
	cout<<setprecision(10);
	solve();
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)



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

  ll n;
  string s;
  cin >> n >> s;
  
  ll res=0;
  rep(i,0,n-2) if(s.substr(i,3)=="ABC") res++;
  
  cout << res << endl;
}


Measured memory_bytes: 256
#!python3.8
# -*- coding: utf-8 -*-
# abc170/abc170_d
import sys
from collections import Counter

i2s = lambda: sys.stdin.readline().rstrip()

def main():
    N = int(i2s())
    A = sorted(map(int, i2s().split(' ')))
    B = Counter(A)
    for a in A:
        if B[a] == 0:
            continue
        if B[a] > 1:
            B[a] = 0
        for i in range(2, A[-1] // a + 1):
            if B[a * i]:
                B[a * i] = 0
    print(sum(B.values()))
    return

main()


Measured memory_bytes: 36028
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(Clone, Debug)]
struct State {
    t: i64,
    lower: i64,
    upper: i64,
    lower_value: i64,
    upper_value: i64,
    dir: i64,
}

impl State {
    fn new(t: i64, lower: i64, upper: i64, lower_value: i64, upper_value: i64, dir: i64) -> State {
        State {
            t: t,
            lower: lower,
            upper: upper,
            lower_value: lower_value,
            upper_value: upper_value,
            dir: dir,
        }
    }
}

fn main() {
    let x = read::<i64>();
    let k = read::<usize>();
    let mut rseq = vec![0; k];
    for i in 0..k {
        rseq[i] = read::<i64>();
    }
    let q = read::<usize>();
    let mut query = vec![(0, 0); q];
    for i in 0..q {
        query[i] = (read::<i64>(), read::<i64>());
    }
    let mut state = State::new(0, 0, x, 0, 0, -1);
    let mut states = vec![];
    states.push(state.clone());
    for i in 0..k {
        let d = rseq[i] - state.t;
        let nt = rseq[i];
        let mut nlower = std::cmp::min(x, state.lower + d * state.dir);
        let mut nupper = std::cmp::max(0, state.upper + d * state.dir);
        let mut nlower_value = state.lower_value;
        let mut nupper_value = state.upper_value;
        let ndir = state.dir * -1;
        if nlower < 0 {
            nlower_value = std::cmp::min(x - nupper_value, nlower_value - nlower);
            nlower = 0;
        }
        if nupper > x {
            nupper_value = std::cmp::min(x - nlower_value, nupper_value - (x - nupper));
            nupper = x;
        }
        state = State::new(nt, nlower, nupper, nlower_value, nupper_value, ndir);
        // println!("{:?}", state);
        assert!(nupper >= nlower);
        assert!(nupper - nlower + nlower_value + nupper_value == x);
        states.push(state.clone());
    }
    for i in 0..q {
        let index = match states.binary_search_by(|state| state.t.cmp(&query[i].0)) {
            Ok(v) => v,
            Err(v) => v - 1,
        };
        let state = &states[index];
        let d = query[i].0 - state.t;
        let mut pos = query[i].1 - state.lower_value + state.lower;
        pos = std::cmp::max(pos, state.lower);
        pos = std::cmp::min(pos, state.upper);
        pos += d * state.dir;
        pos = std::cmp::max(pos, 0);
        pos = std::cmp::min(pos, x);
        println!("{}", pos);
    }
}


Measured memory_bytes: 15864
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	int N;
	cin >> N;
	if(N==3 || N==5 || N==7){
		cout << "YES" << endl;
    }else{
		cout << "NO" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n;		/* 文字列の長さN */
	char s[101];	/* ユーザー入力文字列S */
	char t[101];	/* ユーザー入力文字列T */

	scanf("%d", &n);
	scanf("%s %s", &s, &t);

	s[n] = '\0';
	t[n] = '\0';

	int index_s;		/* sのインデックス */
	int index_t;		/* tのインデックス */
	char result[201];	/* 生成した文字列の格納用 */
	int index;		/* resultのインデックス */
	
	index_s = 0;
	index_t = 0;
	index = 0;

	while(1){
		result[index] = s[index_s];
		++index;
		++index_s;

		result[index] = t[index_t];
		++index;
		++index_t;

		if(index_t == n)
			break;
	}
	result[n * 2] = '\0';	/* 終端文字を設定 */
	printf("%s\n", result);
	return 0;
}

Measured memory_bytes: 128
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split(); if (line.length < args.length) return;foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
//------------------------------
const coin = [10,50,100,500];
void main(){
	int total;
	for(read(total); total ; read(total), write(total ? "\n":"")){
		auto have = new int[4];
		readArray(have);
		int howMany = int.max; 
		auto uses = new int[4];
		foreach (I;cartesianProduct(iota(have[0]+1),iota(have[1]+1),iota(have[2]+1),iota(have[3]+1))){
			auto tmpuses = I.array;
			auto pay = coin.dotProduct(tmpuses);	
			if (pay < total) continue;
			int tmpHowMany = have.sum + howManyCoins(pay - total) - tmpuses.sum;
			if (tmpHowMany < howMany ){
				howMany = tmpHowMany;
				uses = tmpuses;
			}
		}
		foreach(i,u;uses){if(u >0)writeln(coin[i]," ",u);}
	}
}
int howManyCoins(int pay){
	int res;
	foreach_reverse(c;coin){
		while(pay >= c){ 
			pay -= c;res ++;
		}
	} 
	return res;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (auto& e : p) cin >> e;

  vector<double> v(n + 1);
  for (int i = 0; i < n; i++) {
    v[i + 1] = (p[i] + 1) / 2.0;
    v[i + 1] += v[i];
  }
  double r = 0;
  for (int i = 0; i + k < n + 1; i++) {
    r = max(r, v[i + k] - v[i]);
  }
  cout << fixed << setprecision(9);
  cout << r << endl;
}


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

int main(){
    string s;cin>>s;
    string t;cin>>t;
    bool isRotated=false;
    for(int i=0;i<=s.size()-1;i++){
        if(s.substr(i)+s.substr(0,i)==t){
            isRotated=true;
            break;
        }
    }
    if(isRotated) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int C0;
    C0= A%B;
    bool flag;

    flag=false;
    for(int i=0; i<B; i++){
        if( (i*C0-C)%B==0 ){
            //cout << "i C0 i*C0-C " << i << " " << C0 << " " << i*C0-C << endl;
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
struct P {
    ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//???£??\????????????¨???
    ll to, cost;
};
struct S {//????????????±?????\????????????°
    int from, to, cost;
};
struct H {
    int x, y;
};
ll gcm(ll i, ll j) {//??????§???¬??´????°
    if (i > j) swap(i, j);
    if (i == 0) return j;
    return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
    return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad??????§??¨???????2???????????????¢
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
struct A{
	int c,g;
};
bool operator<(A a,A b){
	if(a.g!=b.g) return a.g<b.g;
	return a.c>b.c;
}
A a[2000];
int n,k,g;
int c[11];
int dp[11][2000];
int solve(int i,int j){
	if(i==g+1||j==k) return 0;
	if(dp[i][j]!=-1) return dp[i][j];
	int sum=0,res=0;
	for(int z=0;z<=min(k-j,c[i]-c[i-1]);z++){
		if(z>0) sum+=a[c[i-1]+z-1].c;
		res=max(res,solve(i+1,j+z)+sum+max(0LL,(z-1)*z));
	}
	return dp[i][j]=res;
}
signed main() {
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i].c>>a[i].g;
	sort(a,a+n);
	g=a[n-1].g;
	for(int i=0;i<n;i++){
		c[a[i].g]=i+1;
	}
	for(int i=0;i<11;i++){
		for(int j=0;j<2000;j++)
			dp[i][j]=-1;
	}
	cout<<solve(1,0)<<endl;
    getchar(); getchar();
}

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

int main(){ 
  string S;
  cin >> S;
  
  bool flag = false;
  
  if (S.at(0) == '7') {
    flag = true;
  } else if (S.at(1) == '7') {
    flag = true;
  } else if (S.at(2) == '7') {
    flag = true;
  }
  
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
const double pie  =3.141592653589793238463;
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define POP(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(),A.end());
#define REV(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n" 
const ll dx[4] = { -1, 1, 0, 0};
const ll dy[4] = {0, 0, -1, 1};
ll XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
ll YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
#define precise(x) cout<<fixed<<setprecision(x)
#define t1(x)                cerr<<#x<<": "<<x<<endl
#define t2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define t4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define t5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define t6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
using namespace std;
void SieveOfEratosthenes(ll n) 
{ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // for (ll p=2; p<=n; p++) 
       // if (prime[p]) 
          // cout << p << " "; 
} 

ll power(ll x, ll y) 
{ 
    ll res = 1; 
    while (y > 0) 
    { 
        if (y & 1) 
            res = res * x; 
        y = y >> 1; 
        x = x * x; 
    } 
    return res; 
}
int main()
{
    fastio
    ll t,i,j,k,l,m,n,a,x,b,y,z,c,h,d,e,p,nl,np,q,r;
    string s;
    cin>>x;
    if(x%10==2 || x%10==4 || x%10==5 || x%10==7 || x%10==9)
        cout<<"hon"<<endl;
    else if(x%10==0 || x%10==1 || x%10==6 || x%10==8)
        cout<<"pon"<<endl;
    else if(x%10==3)
        cout<<"bon"<<endl;
}

Measured memory_bytes: 3648
/// ببِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم
#include<bits/stdc++.h>
using namespace std;
#define ll long long
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;
     string s,m;
     cin>>s;
     if(s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes"<<endl;
     }
     else{
        cout<<"No"<<endl;
     }

     return EXIT_SUCCESS;
}




Measured memory_bytes: 256