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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N, M;
    cin >> N >> M;

    map<ll,ll> nums;
    REP(i, N){ 
       ll A;
       cin >> A;
       nums[A]++;
    }
    REP(i, M){
       ll B, C;
       cin >> B >> C;
       nums[C] += B;
    }

    ll count = 0;
    ll total = 0;
    for( auto it = nums.rbegin(); it != nums.rend(); it++ ){
       ll n = min( N-count, it->second );
        total += n *(it->first);
       count += n;

       if( count == N ) break;
    }

    cout << total << endl;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>  
using namespace std;
const int INF = 999;
//世界一競技プログラミングができない人のソース2
#define int long long
int get_number(string str, int& idx){
  int ret = 0;
  while(isdigit(str[idx])){
    ret = ret * 10 + str[idx] - '0';
    ++idx;
  }
  return ret;
}

int Expression(string str, int& idx){
  int ret = get_number(str, idx);
  while(true){
    switch(str[idx]){
    case '*':
      ++idx;
      ret *= get_number( str, idx);
      break;
    default:
      return ret;
    }
  }
}

int nomal(string str, int idx = 0){
  int res = Expression(str, idx);
  while(true){
    switch(str[idx]){
    case '+':
      ++idx;
      res += Expression(str, idx);
      break;
    default:
      return res;
    }
  }
}
int special(string str, int pos = 0){
    stack < int > st;
    st.push(str[pos] - '0');
    for (int i = pos + 1; i < str.length(); i++){
        if (str[i] == '+'){
            int a = st.top(); st.pop();
            i++;
            a += (str[i] - '0');
            st.push(a);
        }
        else if (str[i] == '*'){
            int a = st.top(); st.pop();
            i++;
            a *= (str[i] - '0');
            st.push(a);
        }
    }
     
    return st.top();
}
signed main(){
  string str;
  cin >> str;
  str += "~";
  int digit;
  cin >> digit;

  bool judge_a = nomal(str) == digit;
  bool judge_b = special(str) == digit;
  if(judge_a & judge_b){
    cout << "U" << endl;
  } else if( judge_a){
    cout << "M" << endl;
  } else if( judge_b){
    cout << "L" << endl;
  } else {
    cout << "I" << endl;
  }
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100

int A,B;

char X[100][100];
// int dp[1000000001];

int main(void){
    // Your code here!
    cin >> A >> B;

    REP(i,0,100) {
        REP(j,0,100) {
            if (j < 50) {
                X[i][j] = '#';
            }
            else {
                X[i][j] = '.';
            }

        }
    }
    
    A -= 1;
    B -= 1;
    
    for (int i = 0; i < A; i++) {
        X[i * 2 % 100][(i / 50) * 2] = '.';
    }
    
    for (int i = 0; i < B; i++) {
        X[i * 2 % 100][(i / 50) * 2 + 51] = '#';
    }
    
    printf("%d %d\n",100,100);
    
    REP(i,0,100) {
        REP(j,0,100) {
            cout << X[i][j];
        }
        cout << "\n";
    }
    

    
   
    
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            long K = long.Parse(Console.ReadLine());
            char[] T = new char[S.Length];
            long res = 0;
            bool start = false;
            int count = 1;

            for (int i = 0; i < S.Length; i++)
            {
                T[i] = S[i];
                if (i >= 1)
                {
                    if (T[i] == T[i - 1])
                    {
                        T[i] = 'X';
                        res++;
                    }
                    if (start == false && S[i] == S[i - 1])
                    {
                        count++;
                    }
                    else
                    {
                        start = true;
                    }

                }
            }

            res = res * K;


            if (T[S.Length - 1] == T[0])
            {
                res = res + (K - 1);
                if (S.Length >= 3)
                {
                    if (S[0] == S[1] && count % 2 == 0)
                    {
                        res = res - (K - 1);
                    }

                }

            }

            if(count == S.Length)
            {
                res = S.Length * K / 2;
            }

            Console.WriteLine(res);

        }
    }
}

Measured memory_bytes: 11092
A = map(str,input().split())
s = []

for a in A:
    if a in ['+', '-', '*']:
        b = s.pop()
        c = s.pop()
        
        if a == '+':
            s.append(b+c)
        elif a == '-':
            s.append(c-b)
        else:
            s.append(b*c)
    else:
        s.append(int(a))

ans = s.pop()
print(ans)



Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    int tmp = n;
    int d[k];
    for (int i = 0; i < k; i++)
    {
        cin >> d[i];
    }
    while (n < 100000)
    {
        set<int> s;
        while (tmp != 0)
        {
            s.insert(tmp % 10);
            tmp /= 10;
        }
        bool flag = true;

        for (int i = 0; i < k; i++)
        {
            if (s.count(d[i]) == 1)
            {
                flag = false;
            }
        }
        if (flag)
        {
            cout << n << endl;
            break;
        }
        n++;
        tmp = n;
    }
    return 0;
}


Measured memory_bytes: 256
N =int(input())
X = [list(map(int, input().split())) for _ in range(N)]
A = [0]*N
B = [0]*N
C = [0]*N
A[0]=X[0][0]
B[0]=X[0][1]
C[0]=X[0][2]
for i in range(1, N):
  A[i]=max(B[i-1], C[i-1])+X[i][0]
  B[i]=max(A[i-1], C[i-1])+X[i][1]
  C[i]=max(B[i-1], A[i-1])+X[i][2]
print(max(A[N-1], max(B[N-1], C[N-1])))


Measured memory_bytes: 65752
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


long long GCD(long long a, long long b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    if (b == 0) return a;
    else return GCD(b, a % b);
}
const int MOD = 1000000007;
using pll = pair<long long, long long>;

int N;
vector<long long> A, B;
long long solve() {
    vector<long long> two(N+1, 1);
    for (int i = 0; i < N; ++i) two[i+1] = two[i] * 2 % MOD;
    map<pll, long long> neg, pos;
    long long zerozero = 0, azero = 0, bzero = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i] == 0 && B[i] == 0) ++zerozero;
        else if (A[i] == 0) ++azero;
        else if (B[i] == 0) ++bzero;
        else {
            long long g = GCD(A[i], B[i]);
            A[i] /= g, B[i] /= g;
            if (A[i] < 0) A[i] = -A[i], B[i] = -B[i];
            if (B[i] > 0) pos[pll(A[i], B[i])]++;
            else neg[pll(-B[i], A[i])]++;
        }
    }
    vector<pll> alt;
    for (auto it : neg) alt.push_back(it.first);
    for (auto it : pos) alt.push_back(it.first);
    sort(alt.begin(), alt.end());
    alt.erase(unique(alt.begin(), alt.end()), alt.end());
    long long res = (two[azero] + two[bzero] - 1 + MOD) % MOD;
    for (auto p : alt) {
        long long tmp = (two[neg[p]] + two[pos[p]] - 1 + MOD) % MOD;
        res = (res * tmp) % MOD;
    }
    res = (res + zerozero - 1 + MOD) % MOD;

    //COUT(zero); COUT(alt); COUT(neg); COUT(pos);

    return res;
}

int main() {
    while (cin >> N) {
        A.resize(N); B.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];
        cout << solve() << endl;
    }
}

















Measured memory_bytes: 35980
#include<iostream>
#include<string>
using namespace std;
char Toupper(char c) {
  if(int('a')<=int(c) && int('z')>=(int)c)
    return (char)toupper(c);
  return c;
}
int main() {
  string s;
  getline(cin,s);
  string tmp="";
    for(int i=0;i<(int)s.size();i++) 
      tmp+=Toupper(s[i]);
    cout<<tmp<<endl;
  return 0;
}


Measured memory_bytes: 2968
#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>;

// header area

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

    if(K*500 >= X) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
import math
count = int(input())
for i in range(count):
    x1,y1,r1,x2,y2,r2 =map(float,input().split())
    depth=(x1-x2)**2+(y1-y2)**2
    if depth> (r1+r2)**2:
        print(0)
    elif depth <(r1-r2)**2:
        if r1>r2:
            print(2)
        else:
            print(-2)
    else:
        print(1)

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++) cin >> a[i];
	double t=0.0;
	for(int i=0; i<n; i++) t+=1.0/a[i];
	printf("%.9f\n", 1.0/t);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 100007
#define MOD 1000000007

long long frog(long long arr[], int n, int k){
  long long output[n+1];
  for(int i=0;i<n;i++)
    output[i] = INT_MAX;
  output[0] = 0;
  for(int i = 1;i<min(k,n);i++){
   	for(int j = i-1;j>=0;j--){
      if(output[j] + abs(arr[i]-arr[j]) <output[i])
        output[i] = output[j]+ abs(arr[i]-arr[j]);
    }
  }
  for(int i=k;i<n;i++){
    for(int j=i-1;j>=i-k;j--){
      if(output[j] + abs(arr[i]-arr[j]) < output[i])
        output[i] = output[j] + abs(arr[i]-arr[j]);
    }
  }
  return output[n-1];
}

int main(){
  int n;
  cin>>n;
  int k;
  cin>>k;
  long long arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  
  cout<<frog(arr, n, k);
  
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define rep(i,a,b) for(int i = a;i < b; ++i)
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int N = 25;

bool g[N][N];
bool vis[N][N];
int h,w;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	scanf("%d %d",&h,&w);
	rep(i,1,h+1){
		rep(j,1,w+1){
			char c;
			scanf(" %c",&c);
			g[i][j] = c == '.';
		}
	}
	int ans = 0;
	rep(i,1,h+1){
		rep(j,1,w+1){
			if(g[i][j]){
				memset(vis,0,sizeof(vis));
				queue<pii> q;	
				int dist = -1;
				q.push({i,j});
				vis[i][j] = 1;
				while(q.size()){
					int cnt = q.size();
					++dist;
					while(cnt--){
						pii p = q.front();
						q.pop();
						int x = p.first;
						int y = p.second;
						if(g[x-1][y] && !vis[x-1][y]){
							vis[x-1][y] = 1;
							q.push({x-1,y});
						}
						if(g[x+1][y] && !vis[x+1][y]){
							vis[x+1][y] = 1;
							q.push({x+1,y});
						}
						if(g[x][y-1] && !vis[x][y-1]){
							vis[x][y-1] = 1;
							q.push({x,y-1});
						}
						if(g[x][y+1] && !vis[x][y+1]){
							vis[x][y+1] = 1;
							q.push({x,y+1});
						}
					}
				}
				gmax(ans,dist);
			}
		}
	}
	printf("%d\n", ans);
}


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

const int MAX_N = 100100;
int a[MAX_N], b[MAX_N];
int A, B, M;

int main()
{
    scanf("%d %d %d", &A, &B, &M);
    for(int i = 0; i < A; ++i) scanf("%d", &a[i]);
    for(int i = 0; i < B; ++i) scanf("%d", &b[i]);
    int res1 = 1000000009;
    for(int i = 0; i < M; ++i) {
        int x,y,c;
        scanf("%d %d %d", &x, &y, &c);
        --x, --y;
        res1 = min(res1, a[x] + b[y] - c);
    }
    int ma = 1000000, mb = 1000000;
    for(int i = 0; i < A; ++i) ma = min(ma, a[i]);
    for(int i = 0; i < B; ++i) mb = min(mb, b[i]);
    printf("%d\n", min(res1, ma + mb));
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  string s;
  cin >> s;
  if((s[0] == '7' || s[1] == '7') || s[2] == '7'){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int N,cnt=0;
    string S;

    cin>>N>>S;

    rep(i,N){
        if(S[i]=='A'){
            if(S[i+1]=='B'){
                if(S[i+2]=='C'){
                    cnt++;
                }
            }
        }
    }

    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
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 INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	long long int N;
	cin>>N;
	long long int t=0,f=0;
	REP(i,N){
		long long int A;
		cin>>A;
		if(A%4==0 && A>=4){//4の倍数をカウント
			f++;
			continue;
		}
		if(A%2==0 && A>=2)t++;//2の倍数をカウント
		
	}
	if(t%2==1 && f!=0)t--;
	if(N%2==1)t++;	
	if(t+f*2>=N)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


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

using namespace std;

int main()
{
    int a,b,k;
    
    cin>>k>>a>>b;
    
    int temp = 0;
    
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            temp=1;
            break;
        }
    }
    
    if(temp==1)
    cout<<"OK"<<endl;
    else
    cout<<"NG"<<endl;
}  

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int r = sc.nextInt();
		System.out.println(2*r*3.14159);
	}
}

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

using namespace std;

int main()
{
	for(int n,a,b;cin>>n>>a>>b,n|a|b;){
		vector<int> flg(n+1);
		queue<int> q;
		q.push(0);
		while(q.size()){
			int x=q.front(); q.pop();
			if(x>n || flg[x])
				continue;
			flg[x]=1;
			q.push(x+a);
			q.push(x+b);
		}
		int res=0;
		for(int i=1;i<=n;i++)
			res+=!flg[i];
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define PI 2.0*acos(0.0)
#define ll              long long int
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define MOD             1000000007
#define mx              123456789
using namespace std;
int main()
{
    int r;
    cin>>r;
    cout<<2*PI*r*1.0<<endl;
    return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e18;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

      ll x = max(b*c, b*d);
      ll w = max(a*c, a*d);

  cout << max(x,w) << endl;

  return 0;
}


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


int main() {
	long long n,mn;
	long long a,b,c,d,e;
	cin>>n;
	cin>>a>>b>>c>>d>>e;
  mn=min({ a,b,c,d,e});
	long long ans = ((n+ mn- 1) / mn);

	cout << ans+4 << endl;
}


Measured memory_bytes: 256
K,N=[int(i) for i in input().split(" ") ]
A = [int(i) for i in input().split(" ") ]

maxDistance = 0
for k,v in enumerate(A) :
   maxDistance = max(maxDistance, K - A[k] + A[0]) if ( k >= len(A)-1 ) else max(maxDistance, A[k+1] - A[k]) 

print(K - maxDistance)


Measured memory_bytes: 26444
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();
        int c = 0;
        for (int i = A; i <= B; i++) {
            System.out.println(i);
            c++;
            if(c==K)i=Math.max(i,B-K);
        }
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 23508
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void _main();
int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); return 0;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

void _main(){
  int N,K,Q;
  string s;
  cin >> N >> s >> Q;
  vl s1(N+1),s3(N+1);
  rep(i,N){
    s1[i+1] = int(s[i]=='D'); 
    s3[i+1] = int(s[i]=='C'); 
  }
  rep(i,N){
    s1[i+1] += s1[i];
    s3[i+1] += s3[i];
  }
  auto solve = [&]{
    int k; cin >> k ;
    ll ans = 0;
    ll cnt1,cnt2,cnt3;
    cnt1 = cnt3 = 0;
    REP(i,0,k){
      if(s[i]=='M'){
        cnt1 += s1[i];
        cnt3++;
        ans += s1[i]*(s3[k]-s3[i+1]);
        // dump(s1[i],s3[k]-s3[i+1]);
      }
    }
    cnt2 = s1[k];
    for(int i = 0; i+k<N; i++){
      if(s[i]=='D') cnt1 -= cnt3, cnt2--;
      else if(s[i]=='M') cnt3--;
      if(s[i+k]=='C') ans += cnt1;
      else if(s[i+k]=='D') cnt2++;
      else if(s[i+k]=='M') cnt1 += cnt2, cnt3++;
    }
    cout << ans << endl;
  };
  rep(i,Q) solve(); 
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int C;  
  vector<int> counts(N);
  
  for (int i = 0; i < M * 2; i++) {
    cin >> C;
    counts.at(C-1)++;
  }
  
  for (int i = 0; i < N; i++) {
    cout << counts.at(i) << endl;
  }
}


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

int main(){
	int x;
  	cin >> x;
  
  	int ans = 0;
  
  	ans += x / 500 * 1000;
  	ans += x % 500 / 5 * 5;
  
  	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var n = GetIntArray();
            var ans = (n[1] * 10 + n[2]) % 4 == 0 ? "YES" : "NO";

            Console.Write(ans);
        }



        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 11348
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  vector<ll> X(N);
  for (int i = 0; i < N; i++) cin >> X[i];
  sort(X.begin(), X.end());
  ll ans = INT32_MAX;
  ll cost;
  for (int i = X[0]; i <= X[N - 1]; i++) {
    cost = 0;
    for (int j = 0; j < N; j++) {
      cost += pow((X[j] - i), 2);
    }
    ans = min(cost, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long K = sc.nextLong();

		long ans = A - B;

		if (Math.abs(ans) <= Math.pow(10, 18)){
			if (K % 2 == 0){
				System.out.println(ans);
			} else {
				System.out.println(ans * -1);
			}

		} else {
			System.out.println("Unfair");
		}


	}
}

Measured memory_bytes: 20948
from itertools import accumulate
N=int(input())
s=list(accumulate(map(int,input().split())))
ans=s[-1]
p=0
q=2
for i in range(2,N-1):
    while abs(s[i-1]-2*s[p])>abs(s[i-1]-2*s[p+1]):
        p+=1
    while abs(s[q]*2-s[i-1]-s[-1])>abs(s[q+1]*2-s[i-1]-s[-1]):
        q+=1
    t=[s[i-1]-s[p],s[p],s[q]-s[i-1],s[-1]-s[q]]
    ans=min(ans,max(t)-min(t))
print(ans)    

Measured memory_bytes: 25972
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<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()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn gcd(a: usize, b: usize) -> usize {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let N: usize = read();
    let X: usize = read();
    let mut vec: Vec<usize> = vec![];
    vec.push(X);
    for _ in 0..N {
        vec.push(read());
    }
    vec.sort();
    let mut ans = vec[1] - vec[0];
    for v in vec.windows(2) {
        let before = v[0];
        let after = v[1];
        ans = gcd(ans, after - before);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
sx,sy,tx,ty=map(int,input().split())

def solve(sx,sy,tx,ty):
  dx=tx-sx
  dy=ty-sy
  return 'R'*dx+'U'*dy+'L'*dx+'D'*dy+'D'+'R'*(dx+1)+'U'*(dy+1)+'L'+'U'+'L'*(dx+1)+'D'*(dy+1)+'R'

print(solve(sx,sy,tx,ty))

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

// ------------------------------------------------------------------------------------------

signed main() {
  string s;
  string t = "2019/04/30";
  cin >> s;
  puts(s <= t ? "Heisei" : "TBD");

  return 0;
}

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

using namespace std;

int east[310000];
int west[310000];

int main() {
	int N;
	string S;

	cin >> N >> S;
	int cnt = 0;
	int ma = -1;

	//for(int i = 0; i < N; i++) cout << (S[i] == 'W' ? '<' : '>');
	//cout << endl;

	if(S[0] == 'W') {
		west[0] = 1;
		east[0] = 0;
	} else {
		west[0] = 0;
		east[0] = 1;
	}
	for(int i = 1; i < N; i++) {
		if(S[i] == 'W') {
			west[i] = west[i - 1] + 1;
			east[i] = east[i - 1];
		} else {
			west[i] = west[i - 1];
			east[i] = east[i - 1] + 1;
		}
	}

	int mi = 310000;
	//printf(">:%d, <:%d\n", 0, west[N - 1] - west[0]);
	for(int i = 1; i < N - 1; i++) {
		//printf(">:%d, <:%d\n", east[i - 1], west[N - 1] - west[i]);
		int tmp = east[i - 1] + (west[N - 1] - west[i]);
		mi = min(mi, N - tmp - 1);
	}
	//printf(">:%d, <:%d\n", east[N - 2], 0);
	mi = min(mi, N - (west[N - 1] - west[0]) - 1);
	mi = min(mi, N - east[N - 2] - 1);

	cout << mi << endl;

	/*for(int i = 0; i < N; i++) printf("%3d", west[i]);
	printf("\n");
	for(int i = 0; i < N; i++) printf("%3d", east[i]);*/

	return 0;
}


Measured memory_bytes: 3076
/* Coached by Dukkha */
#include <stdio.h>

#define N 200000

int main() {
	static int qq[N + N];
	int n, i, head, cnt;

	scanf("%d", &n);
	head = n, cnt = 0;
	for (i = 0; i < n; i++) {
		int a;

		scanf("%d", &a);
		if (i % 2 == 0)
			qq[head + cnt++] = a;
		else
			qq[cnt++, --head] = a;
	}
	if (n % 2 == 0)
		for (i = head; i < head + cnt; i++)
			printf("%d ", qq[i]);
	else
		for (i = head + cnt - 1; i >= head; i--)
			printf("%d ", qq[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 2816
N,m = gets.split.map(&:to_i)
drinks = [] #値段、本数
N.times{|i|
	drinks << gets.split.map(&:to_i)
}

d = drinks.sort{|a,b| a[0] <=> b[0]}

sum = 0


while m > 0
  if d[0][1] < m
	sum += d[0][0]*d[0][1]
  else
    sum += d[0][0]*m
  end
  m -= d[0][1]
  d.delete_at(0)
end

puts sum

Measured memory_bytes: 11128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie acos(-1)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x) for(auto &a:x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define w 100005

void solve()
{
    int l;
    cin>>l;
    double t=(double)l/3.0;
    cout<<fixed<<setprecision(6)<<(1.0)*(t)*t*t;
}
int main() {
	// your code goes here
	io;
    solve();
	return 0;
}
 

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M 1000000007
#define N 1000016
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define inf 9000000000000000000
ll d[1010][1010],n,m;
char mat[1010][1010];

ll dp(ll i, ll j) {

    if(i>n || j>m || mat[i][j]=='#')
        return 0;

    if(i==n && j==m)
        return 1;

    if(d[i][j]!=inf)
        return d[i][j];

    return d[i][j] = (dp(i+1, j) + dp(i, j+1))%M;
}

int main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
   cin>>n>>m;
   for(ll i=1; i<=n; i++) {
        for(ll j=1; j<=m; j++) {
            cin>>mat[i][j];
            d[i][j] = inf;
        }
   }

   cout<<dp(1, 1)<<"\n";

    return 0;
}


Measured memory_bytes: 9216
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"math/big"
	"os"
)

var reader *bufio.Reader
var writer *bufio.Writer

var inputFile = flag.String("input", "", "")

func init() {
	flag.Parse()
	var i io.Reader
	if *inputFile != "" {
		i, _ = os.Open(*inputFile)
	} else {
		i = os.Stdin
	}
	reader = bufio.NewReaderSize(i, 1<<20)
	writer = bufio.NewWriterSize(os.Stdout, 1<<20)
}

func println(a ...interface{}) {
	_, _ = fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	_, _ = fmt.Fprintf(writer, format, a...)
}

func scanf(format string, a ...interface{}) {
	_, _ = fmt.Fscanf(reader, format, a...)
}

func scan(a interface{}) {
	_, _ = fmt.Fscan(reader, a)
}

func NextInt64() int64 {
	var res int64
	scan(&res)
	return res
}

func NextInt() int {
	var res int
	scan(&res)
	return res
}

func NextIntArray(n int) []int {
	res := make([]int, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextString() string {
	var res string
	scan(&res)
	return res
}

func NextBigInt() *big.Int {
	n := new(big.Int)
	n, _ = n.SetString(NextString(), 10)
	return n
}

func AbsInt64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func MinInt64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func main() {
	defer writer.Flush()

	n := NextInt()
	
	h := NextInt64Array(n)
	
	dp := make([]int64, n)
	for i := 1; i < n; i++ {
		dp[i] = dp[i - 1] + AbsInt64(h[i] - h[i - 1])
		if i > 1 {
			dp[i] = MinInt64(dp[i], dp[i - 2] + AbsInt64(h[i] - h[i - 2]))
		}
	}
	println(dp[n - 1])
}


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

int main(){
  int H,W;
  while(cin>>H>>W){
    if(H==0&&W==0) break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cout<<'#';
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3020
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

string S;
int N;

int main() {
	cin >> S;
	N = S.size();
	LL ans = 0;
	LL bom = 0;
	for (int i = 0; i < N;) {
		if (S[i] == 'A') {
			++bom;
			++i;
		}
		else if (S[i] == 'B' && i < N - 1 && S[i + 1] == 'C') {
			ans += bom;
			i += 2;
		}
		else {
			bom = 0;
			++i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll A,B,C;cin >> A >> B >> C;
  ll K;cin >> K;
  if(K%2==0)cout << A-B << endl;
  else cout << B-A << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
B = list(map(int,input().split()))
ans = 0
if n == 2:print(B[0]*2)
else:
  for i in range(n-1):
    if i == 0:
      if B[i] > B[i+1]:
        ans += max(B[i],B[i+1])+min(B[i],B[i+1])
      else:
        ans += min(B[i],B[i+1])*2
    elif i == n-2:
      ans += B[-1]
    else:
      ans += min(B[i],B[i+1])
  print(ans)

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

#define mod 1000000007

int main()
{
    long long n,sum=0;
    cin>>n;

    long long ar[n];

    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        sum+=ar[i];
        sum%=mod;
    }

    long long ans=0;

    for(int i=0;i<n;i++)
    {
        sum-=ar[i];
        sum+=mod;
        sum%=mod;
        ans+=ar[i]*(sum+mod);
        ans%=mod;
    }

    cout<<ans;


}

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

using namespace std;

int main()
{
    int n, m, p, x;
    cin>>n;
    int A[n];
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
    }
    cin>>m;
    for(int i=0; i<m; i++)
    {
        cin>>p>>x;
        int sum=0;
        for(int j=0; j<n; j++)
        {
            if((j+1)==p)
            {
                sum+=x;
                continue;
            }
            sum+=A[j];
        }
        cout<<sum<<endl;
    }
    return 0;
}





Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner
var out *bufio.Writer

func main() {
	sc = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	buf := make([]byte, 1<<20)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n, d, a := nextInt(), nextInt(), nextInt()

	t := newTree(n)
	xi, hi := make([]int, n), make([]int, n)
	xpos := make(map[int]int, n)
	for i := 0; i < n; i++ {
		x, h := nextInt(), nextInt()
		xi[i] = x
		hi[i] = h
		xpos[x] = i
	}
	sort.Sort(sort.IntSlice(xi))
	for sortedIdx, x := range xi {
		i := xpos[x]
		t.set(sortedIdx, hi[i])
	}
	t.build()

	result := 0
	for i, x := range xi {
		hp := t.query(i, i+1)
		if hp <= 0 {
			continue
		}
		r := binSearch(xi[i:], x+2*d) + i + 1
		atkCnt := int(math.Ceil(float64(hp) / float64(a)))
		t.update(i, r, -a*atkCnt)
		result += atkCnt
	}

	fmt.Fprintln(out, result)
}
func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func binSearch(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r-1 {
		mid := l + (r-l)/2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid
		}
	}
	return l
}

type tree struct {
	node, lazy []int
	size       int
	ex, em     int
}

func newTree(n int) *tree {
	size := 1
	for size < n {
		size <<= 1
	}
	return &tree{
		node: make([]int, 2*size-1),
		lazy: make([]int, 2*size-1),
		size: size,
		ex:   0,
		em:   0,
	}
}
func (t *tree) set(i, v int) {
	t.node[i+t.size-1] = v
}
func (t *tree) build() {
	for k := t.size - 2; k >= 0; k-- {
		t.node[k] = t.node[2*k+1] + t.node[2*k+2]
	}
}
func (t *tree) eval(k, len int) {
	if t.lazy[k] != t.em {
		if k < t.size-1 {
			t.lazy[2*k+1] += t.lazy[k]
			t.lazy[2*k+2] += t.lazy[k]
		}
		t.node[k] = intMax(0, t.node[k]+t.lazy[k]*len)
		t.lazy[k] = t.em
	}
}
func (t *tree) update(a, b, v int) {
	t.ureq(a, b, v, 0, 0, t.size)
}
func (t *tree) ureq(a, b, v, k, l, r int) {
	t.eval(k, r-l)
	if b <= l || r <= a {
		return
	}
	if a <= l && r <= b {
		t.lazy[k] = v
		t.eval(k, r-l)
	} else {
		t.ureq(a, b, v, 2*k+1, l, (l+r)/2)
		t.ureq(a, b, v, 2*k+2, (l+r)/2, r)
		t.node[k] = intMax(0, t.node[2*k+1]+t.node[2*k+2])
	}
}
func (t *tree) query(a, b int) int {
	return t.qreq(a, b, 0, 0, t.size)
}
func (t *tree) qreq(a, b, k, l, r int) int {
	if b <= l || r <= a {
		return t.ex
	}
	t.eval(k, r-l)
	if a <= l && r <= b {
		return t.node[k]
	}
	vl := t.qreq(a, b, 2*k+1, l, (l+r)/2)
	vr := t.qreq(a, b, 2*k+2, (l+r)/2, r)
	return vl + vr
}

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}


Measured memory_bytes: 25328
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var input = ReadArrayInt();
            var A = input[0];
            var B = input[1];
            var P = ReadArrayInt();
            var one = 0;
            var two = 0;
            var three = 0;
            for (int i = 0; i < N; i++)
            {
                if (P[i] <= A) one++;
                else if (P[i] > B) three++;
                else two++;
            }

            Console.WriteLine(Math.Min(one, Math.Min(two, three)));
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13268
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Everything Starts With Your Vote
public class Main{

	class R implements Comparable<R>{
		String s;
		int x;
		public R(String s, int x) {
			this.s = s;
			this.x = x;
		}
		int win(R r){
			return s.compareTo(r.s)<0?r.x-x:(r.x-x+1);
		}
		public int compareTo(R o) {
			return x!=o.x?o.x-x:s.compareTo(o.s);
		}
		@Override
		public String toString() {
			return s+" "+x;
		}
	}
	
	int N, M, K, L, B;
	R[] r;
	boolean[] fav;
	Set<String> fn;
	
	long need(int x){
		if(x<=B)return 0;
		int n = x-B, c = 0;
		int k = K-1;
		for(;;){
			if(fav[k])n++;
			else c++;
			if(c==x-B)break;
			k--;
		}
		R tar = r[k];
		long res = 0;
		for(int i=k+1;i<N&&0<n;i++){
			if(!fav[i])continue;
			n--;
			res+=r[i].win(tar);
		}
		return res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		fav = new boolean[100000];
		for(;;){
			N = sc.nextInt(); M = sc.nextInt(); K = sc.nextInt(); L = sc.nextInt();
			if((N|M|K|L)==0)break;
			r = new R[N];
			for(int i=0;i<N;i++)r[i]=new R(sc.next(), sc.nextInt());
			Arrays.sort(r);
//			for(R x:r)System.out.println(x);
//			System.out.println(r[3].win(r[2]));
			Arrays.fill(fav, false);
			fn = new HashSet<String>();
			for(int i=0;i<M;i++)fn.add(sc.next());
			B = 0;
			for(int i=0;i<N;i++){
				if(fn.contains(r[i].s)){
					fav[i] = true;
					if(i<K)B++;
				}
			}
//			for(int i=0;i<N;i++){
//				System.out.print(r[i]);
//				System.out.println(fav[i]?" *":"");
//			}
			int left = B, right = Math.min(M, K);
			while(right-left>1){
				int m = (left+right)/2;
				if(L<need(m))right=m;
				else left=m;
			}
			System.out.println(need(right)<=L?right:left);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 37000
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
for i in range(N):
    A[i] -= 1

recode = [-1]*N
cnt = 0
current = 0
while True:
    if K <= 0:
        print(current+1)
        break
    if recode[current] == -1:
        recode[current] = cnt
        cnt += 1
        current = A[current]
        K -= 1
    else:
        loop = cnt-recode[current]
        K %= loop
        recode = [-1]*N


Measured memory_bytes: 32380
#include<stdio.h>

int linearSearch(int n, int S[], int key) {
    int i = 0;
    
    S[n] = key;
    
    while (S[i] != key) {
        i++;
    }
    
    return i != n;
}

int main() {
    int n, S[10000], q, key, ans = 0;
    int i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }
    
    scanf("%d", &q);
    
    for (i = 0; i < q; i++) {
        scanf("%d", &key);
        
        if (linearSearch(n, S, key)) {
            ans++;
        }
    }
    
    printf("%d\n", ans);
    
    return 0;
}



Measured memory_bytes: 1992
N,M=map(int,input().split())
ans=['0']*N
I=[]
for _ in range(M):
  s,c=input().split()
  index=int(s)-1
  if index==0 and N>1 and c=='0':
    print(-1)
    break
  if index in I and ans[index]!=c:
    print(-1)
    break
  ans[index]=c
  I.append(index)
else:
  if 0 not in I and N>1:
    ans[0]='1'
  print(''.join(ans))

Measured memory_bytes: 9124
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;

#define INF 1000000000000
#define MOD 10000007
#define int long long
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define pb push_back

void YesNo(bool b) { b ? cout << "Yes" << endl : cout << "No" << endl; return; }
void YESNO(bool b) { b ? cout << "YES" << endl : cout << "NO" << endl; return; }
void yesno(bool b) { b ? cout << "yes" << endl : cout << "no" << endl; return; }

signed main() {
	double k, a, b;
	int ik, ia, ib;
	cin >> k >> a >> b;
	ik = k;
	ia = a;
	ib = b;
	if (ia%ik==0)
	{
		cout << "OK" << endl;
		return 0;
	}
	if (ib % ik == 0)
	{
		cout << "OK" << endl;
		return 0;
	}
	if (a<=(k*(floor(a/k)+1)) && (k * (floor(a / k) + 1)) <= b)
	{
		cout << "OK" << endl;
	}
	else
	{
		cout << "NG" << endl;
	}
}

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

long long calc(long long A) {
	A++;
	long long ans = 0;
	for (int i = 0; i < 40; i++)
	{
		long long loop = pow(2, i+1);
		long long cnt = (A / loop) * (loop / 2);
		cnt += max(0LL, (A % loop) - (loop / 2));
		if (cnt % 2 == 1) {
			ans += 1LL << i;
		}
	}
	return ans;
}

int main() {
	long long A, B;
	cin >> A >> B;
	long long ans = calc(B) ^ calc(A - 1);
	cout << ans << endl;
}

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

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

Measured memory_bytes: 3596
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string n;

int main()
{
	in >> n;
	rep(i, 3) out << (n[i] == '1' ? "9" : "1");
	out << std::endl;
	return 0;
}


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

int main(){
    long int H,R,num;
    cin>> H >> R;
    
    if(H+R>0){
        cout<<1<<endl;
    }
    else if(H+R<0){
        cout<<-1<<endl;
    }
    else{
        cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  Int ans=0;
  map<Int, Int> m;
  Int s=0;
  m[s]++;
  for(Int i=0;i<n;i++){
    s+=a[i];
    ans+=m[s];
    m[s]++;
  }

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


Measured memory_bytes: 14336
def main():
    n=int(input())
    a = list(map(int, input().split()))
    ans = [0] * n
    base = xor(a)
    for i in range(len(a)):
        ans[i] = base ^ a[i]
    print(*ans)

def xor(x):
    r = 0
    for i in x:
        r ^= i
    return r

if __name__ == '__main__':
    main()

Measured memory_bytes: 31508
def solve( p, t ):
	global isExist, n, A
	isExist[ t ] = True
	if p < n:
		solve( p+1, t-A[p] )
		solve( p+1, t )
	else:
		return

isExist = [False]*2001 
n = int( input() )
A = [ int( val ) for val in input().rstrip().split( ' ' ) ]
q = int( input() )
M = [ int( val ) for val in input().rstrip().split( ' ' ) ]
s = sum( A )
solve( 0, s )
for i in range( 0, q ):
	if isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Measured memory_bytes: 6724
#include <iostream>
#include <iomanip>

int main()
{
  int a, b ;
  std::cin >> a >> b ;

  std::cout << (int)( a / b ) << " " << a % b << " " ;
  std::cout << std::fixed ;
  std::cout << std::setprecision(5) << (double)a / (double)b << std::endl ;

  return 0 ;
}

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


int main(){
    int H,W;
    while(1) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for (int i = 0; i < H ; i++){
            for ( int j = 0; j < W; j++ ){
                if ( i == 0 || i == H-1 || j == 0 || j == W-1){
                    printf("#");
                }else{
                    printf(".");
                }
    }
            cout << "\n";
        }
        cout << endl;
    }
         return 0;
}

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

int main(void)
{
    int N;
    
    cin >> N;

    vector<long long int> fk(N+1,1);

    for(int i = 2; i <= N; ++i)
    {
        for(int j = 1; j*i <=N; ++j)
        {
            ++fk[j*i];
        }
    }
    long long int ans = 0;
    for(int i = 1; i <= N; ++i)
    {
        ans+=fk[i]*i;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 81380