akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    --x; --y;
    vector<int> ans(n,0);
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            int cur=abs(i-j);
            cur=min(cur,abs(x-i)+1+abs(y-j));
            cur=min(cur,abs(y-i)+1+abs(x-j));
            ++ans[cur];
        }
    }
    
    for(int i=1;i<n;++i) cout<<ans[i]<<endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n,a,b;cin>>n>>a>>b;
  reps(i,a,b+1){
    if(i%n==0){
      cout<<"OK";return 0;
    }
  }cout<<"NG";
}

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

typedef struct{
    int d;
    int p;
}SYUKUBA;


int struct_sort( const void *a, const void *b ){
    return ((SYUKUBA*)b)->p - ((SYUKUBA*)a)->p;
}



int main(){
    int N,sum;
    long int M,count;
    int i;
    SYUKUBA n[10003];

    while(1){
        scanf("%d %ld",&N, &M);
        if(N == 0 && M == 0){
            break;
        }

        for(i = 0; i < N ; i++){
            scanf("%d %d",&n[i].d,&n[i].p);
            //printf("d = %d p = %d\n",n[i].d,n[i].p);
        }
        qsort(n,N,sizeof(SYUKUBA),struct_sort);
        /*
        for(i = 0; i < N ; i++){
            printf("s.d = %d s.p = %d\n",n[i].d,n[i].p);
        }
        */
       count = M;
       sum = 0;
       for(i = 0; i < N ; i++){
           if(n[i].d <= count){
               count -= n[i].d;
           }else if(n[i].d > count && count != 0){
               sum += (n[i].d - count) * n[i].p;
               count = 0;
           }else if(count == 0){
               sum += n[i].p * n[i].d;
           }

       }
       printf("%d\n",sum);

    }


    return 0;

}



Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
#define INF 1e15
#define MOD 1000000007
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define END system("PAUSE");return 0
int n, ans;
signed main() {
	cin >> n;
	int a[3333];
	rep(i, n) {
		cin >> a[i];
		ans += a[i] - 1;
	}
	cout << ans << endl;
	END;
}


Measured memory_bytes: 504
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, m, l, r, a, b;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    b = 100009;
    for (int i = 0; i < m; i++) {
        cin >> l >> r;
        a = max(l, a); b = min(b, r);
    }
    cout << max(b - a + 1, 0) << "\n";
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int dfs(int bigger, int smaller) {
    int ret = 2 * smaller * (bigger / smaller);
    int next_smaller = bigger % smaller;
    if (next_smaller == 0) return ret - smaller;
    return ret + dfs(smaller, next_smaller);
}

signed main() {
    int N, X;
    cin >> N >> X;
    int bigger = max(N - X, X);
    int smaller = min(N - X, X);
    cout << dfs(bigger, smaller) + N << endl;
    return 0;
}

Measured memory_bytes: 384
n,q=list(map(int,input().split()))
p=[]
for i in range(n):
    name_,time_=input().split()
    p.append([str(name_),int(time_)])

done_=[]
time_passed=0
while len(p)>0:
    box_=[]
    del_index=[]
    for i,process_ in enumerate(p):
        amount_=process_[1]-q
        if amount_>0:
            box_.append([process_[0],amount_])
            time_passed+=q
        else:
            time_passed+=min(q,process_[1])
            done_.append([process_[0],time_passed])   
            del_index.append(i)
    cnt=0
    for d in del_index:
        del p[d-cnt]
        cnt+=1
    p=box_
    
for k in range(n):
    print(*done_[k])


Measured memory_bytes: 19692
N,K = map(int,input().split())
p = list(map(int,input().split()))
ex = [p[i] + 1 for i in range(N)]
total = [0]
for i in range(N):
	total.append(total[-1] + ex[i])
m = [total[i] - total[i-K] for i in range(K, N+1)]
print(max(m)/2)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int a;
    bool isPrime = true;
    cin >> a;
    while (1) {
        isPrime = true;
        for (int i = 2; i < a/2 + 1; i++) {
            if (a % i == 0) {
                isPrime = false;
                break;
            }
        }
        if (isPrime)break;
        a++;
    }
    cout << a << endl;
    return 0;
}

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

using ll = long long;

const int nax = 3005;
ll dp[nax][nax];

int main(){
	int n;
	cin >> n;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	for(int l = n-1;l>=0;l--){
		for(int r = l; r<n;r++){
			if(l==r){
				dp[l][r] = v[l];
			}
			else{
				dp[l][r] = max(v[l]-dp[l+1][r], v[r]-dp[l][r-1]);
			}
		}
	}
	/*for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cout << dp[i][j] << " ";
		}
		cout << "\n";
	}*/
	cout << dp[0][n-1] << "\n";
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  
  for (int &x : a) {
    x /= 400;
  }
  
  int max_count = 0;
  int min_count = 0;
  vector<int> already(8);
  for (int i = 0; i < n; i++) {
    if (a.at(i) >= 8) {
      max_count++;
    }
    for (int j = 0; j < 8; j++) {
      if (already.at(j) == 1) continue;
      if (a.at(i) == j) {
        max_count++;
        min_count++;
        already.at(j) = 1;
      }
    } 
  }
  
  if (max_count != 0 && min_count == 0) {
    min_count = 1;
  }
  
  cout << min_count << endl;
  cout << max_count << endl;
}


Measured memory_bytes: 3564
#include <stdio.h>

int main(void){
	long long unsigned int n, i;
	
	scanf("%lld",&n);
	
	for(i = n - 1; i > 1; i--){
		n = n*i;
		n=n %1000000007;
	}
	
	printf("%lld",n);
	
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin python3
# -*- coding: utf-8 -*-

#import sys
#input = sys.stdin.readline

def main():
    N = input()
    K = int(input())
    L = len(N)
    #dp[i][j][status]   status=0 は小さいのが未確定=i文字まで同じ
    #                   status=1 は小さいことが確定
    #i桁目まで決めて、0でない桁がj個
    #初期値は1 からスタート s=0,i=0,j=0
    dp = [[[0]*2 for j in range(K+1)] for i in range(L+1)]
    dp[0][0][0] = 1
    for i in range(L):
        n = int(N[i])
        for j in range(K+1):
#            dp[i][j][1]    #なんでもOK
            #0を選ぶとき
            dp[i+1][j][1] += dp[i][j][1]
            #1--9を選ぶとき
            if j+1<=K:
                dp[i+1][j+1][1] += dp[i][j][1]*9

#            dp[i][j][0]    #
            #n == 0 である場合
            if n == 0:
                #nを選ぶしかない
                dp[i+1][j][0] += dp[i][j][0]
            #n != 1 である場合
            else:
                #0 を選ぶとき
                dp[i+1][j][1] += dp[i][j][0]
                #1-(n-1) を選ぶとき
                if j+1<=K:
                    dp[i+1][j+1][1] += dp[i][j][0]*(n-1)
                #n を選ぶとき
                if j+1<=K:
                    dp[i+1][j+1][0] += dp[i][j][0]



    print(dp[L][K][0]+dp[L][K][1])
#    print(dp)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int A[3];
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  REP(i, 3) cin >> A[i];

  int sum = 0;
  REP(i, 3) sum += A[i];

  if (sum >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.String;

class Main{
   public static void main(String[] argv){
      String N;
      boolean palindrome = true;
      
      Scanner stdIn = new Scanner(System.in);
      N = stdIn.next();
      
      for(int i = 0; i <= N.length()/2; i++){
         if(N.charAt(i)!=N.charAt(N.length()-i-1)){
            palindrome = false;
         }
      }
      
      if(palindrome){
         System.out.print("Yes");
      }else{
         System.out.print("No");
      }
   }
}

Measured memory_bytes: 21972
/*  Bismillahir Rahmanir Rahim  */

#include <bits/stdc++.h>

using namespace std;

typedef pair <int, long long> pii;

const int N = 200005;

int n, sub[N];
long long dis[N];
long long tot;
vector <pii> g[N];

void init(int at, int par){
	sub[at] = 1;
	for(auto u : g[at]){
		if(u.first == par) continue;
		init(u.first, at);
		sub[at] += sub[u.first];
	}
}

int centroid(int at, int par){
	for(auto u : g[at]){
		if(u.first == par) continue;
		if(sub[u.first] > (n / 2)) return centroid(u.first, at);
	}
	return at;
}

void dfs(int at, int par){
	tot += dis[at] * 2LL;
	sub[at] = 1;
	for(auto u : g[at]){
		if(u.first == par) continue;
		dis[u.first] = dis[at] + u.second;
		dfs(u.first, at);
		sub[at] += sub[u.first];
	}
}

int main(){
	int x, y, c;
	scanf("%d", &n);
	for(int i = 2; i <= n; ++i){
		scanf("%d %d %d", &x, &y, &c);
		g[x].push_back({y, c});
		g[y].push_back({x, c});
	}
	init(1, 0);
	int cen = centroid(1, 0);	
	dfs(cen, cen);
	int mx = n / 2;
	if(n & 1) mx = n;
	long long aa = 1e18;
	long long bb = 1e18;
	for(auto u : g[cen]){
		if(sub[u.first] == mx) aa = min(aa, u.second);
		bb = min(bb, u.second);
	}
	if(aa != (long long)(1e18)) cout << tot - aa << endl;
	else cout << tot - bb << endl;
	return 0;
}

Measured memory_bytes: 17408
N, K = map(int, input().split())
n = sum([1 for x in range(K, N + 1, K)])
if K % 2 == 1:
    print(n ** 3)
else:
    m = sum([1 for x in range(K // 2, N + 1, K)])
    print(n ** 3 + m ** 3)

Measured memory_bytes: 4632
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;

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

template<class S,class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll A, B;

int main()
{
  std::cin >> A >> B;

  std::cout << std::max( 0ll, A-2*B ) << std::endl;

  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include <vector>

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

using namespace std;

int main(){
	int N, A[200000], bit = 0;
	ll l = 0, r = 0, ans = 0;

	scanf("%d", &N);
	REP(i, N){
		scanf(" %d", &A[i]);
	}
	for (l = 0; l < N;){
		if ((bit&A[r]) == 0 && r < N){
			bit |= A[r];
			if (r < N){
				++r;
			}
		}
		else{
			ans += (r - l);
			bit &= ~A[l];
			++l;
		}
	}
	
	printf("%ld\n", ans);


	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf = 1 << 61;
    static int[] x4 = {-1, 0, 0, 1};
    static int[] y4 = {0, -1, 1, 0};
    static int[] x8 = {-1, -1, 0, 1, 1, 1, 0, -1};
    static int[] y8 = {0, -1, -1, -1, 0, 1, 1, 1};

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        String t = in.next();

        int l = s.length();
        boolean cond = true;
        HashMap<Character, Character> mapFromS = new HashMap<>();
        HashMap<Character, Character> mapFromT = new HashMap<>();
        for(int i = 0; i < l; i++) {
            char si = s.charAt(i);
            char ti = t.charAt(i);
            if(!mapFromS.containsKey(si)) {
                mapFromS.put(si, ti);
            }
            if(!mapFromT.containsKey(ti)) {
                mapFromT.put(ti, si);
            }

            if(mapFromS.containsKey(si) && mapFromS.get(si) != ti) {
                cond = false;
                break;
            }

            if(mapFromT.containsKey(ti) && mapFromT.get(ti) != si) {
                cond = false;
                break;
            }
        }

        if(cond) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }

    static public void printArray2D(char[][] map) {
        for(int i = 0; i < map.length; i++) {
            for(int j = 0; j < map[i].length; j++) {
                System.out.format("%c\t", map[i][j]);
            }
            System.out.print("\n");
        }
    }

    static public void printArray2D(int[][] map) {
        for(int i = 0; i < map.length; i++) {
            for(int j = 0; j < map[i].length; j++) {
                System.out.format("%d\t", map[i][j]);
            }
            System.out.print("\n");
        }
    }
}


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

int main() {
    int n;
    cin >> n;
    int p[n];
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    
    for (int i = 1; i < n-1; i++)
    {
        if ((p[i-1] < p[i] && p[i] < p[i+1])
        ||  (p[i-1] > p[i] && p[i] > p[i+1]))
        {
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

int main(void) {
    string s; cin >> s; // 入力
    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else if (s == "Rainy") {
        cout << "Sunny" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	N := getStdinInt()
	d := getStdinIntArr()

	cnt := 0
	//prev := 0

	sort.Sort(sort.IntSlice(d))

	if d[N/2-1] == d[N/2] {
		fmt.Printf("0\n")
		return
	}

	cnt = d[N/2] - d[N/2-1]

	/*
		prev = d[N/2]
		for i := N/2; i >= 0; i-- {
			if prev > d[i] {
				break
			}
			cnt++
		}
	*/

	/*
		prev = d[N/2]
		for i := N/2 + 1; i < N; i++ {
			if prev != d[i] {
				break
			}
			cnt++
		}
	*/

	fmt.Printf("%d\n", cnt)
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  int a=1;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    if(a<k){
      a*=2;
    }else{
      a+=k;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
  int a, b, c, d;
 
  scanf("%d %d %d %d", &a, &b, &c, &d);
 
  while (a > 0 && c > 0) {
    c = c - b;
    if (c > 0) a = a - d;
  }
 
  if (c <= 0)
    printf("Yes\n");
  else
    printf("No\n");
 
  return 0;
}

Measured memory_bytes: 1644
// 1:02 -> 1:05
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
	ll a,b; 
	ll mx = 1000000;
	ll mn = -1000000;
	cin>>a>>b; 
	for(int i=max(mn,b-a+1);i<=min(mx,b+a-1);i++){
		cout<<i<<" ";
	}
	cout<<endl;
	return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

const int loose = 0;
const int tight = 1;

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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


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

	ll n, m;
	cin >> n >> m;
	Array s(n, -1);
	bool flag = true;
	REP(i, m) {
		ll ss, cc;
		cin >> ss >> cc;
		ss--;
		if (s[ss] != -1 && s[ss] != cc) flag = false;
		s[ss] = cc;
	}
	
	if (!flag) {
		cout << -1 << en;
		return 0;
	}

	ll ans = -1;
	if (n == 1) {
		rep(i, 0, 10) {
			flag = true;
			string t = to_string(i);
			REP(j, n) {
				if (s[j] != -1 && t[j] - '0' != s[j]) {
					flag = false;
				}
			}
			if (flag) {
				ans = i;
				break;
			}
		}
	}
	else if (n == 2) {
		rep(i, 10, 100) {
			flag = true;
			string t = to_string(i);
			REP(j, n) {
				if (s[j] != -1 && t[j] - '0' != s[j]) {
					flag = false;
				}
			}
			if (flag) {
				ans = i;
				break;
			}
		}
	}
	else {
		rep(i, 100, 1000) {
			flag = true;
			string t = to_string(i);
			REP(j, n) {
				if (s[j] != -1 && t[j] - '0' != s[j]) {

					flag = false;
				}
			}
			if (flag) {
				ans = i;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector <int> divisors[1000*1000+2];;
void precal()
{
    for(int i=1;i<=1000*1000;i++)
    {
        for(int j=i;j<=1000*1000;j+=i)
        {
            divisors[j].push_back(i);
        }
    }
}
int main()
{
    precal();
    int n;scanf("%d",&n);
    multiset <int> ms;
    vector <int> v;
    for(int i=0;i<n;i++)
    {
        int x;scanf("%d",&x);;ms.insert(x);
        v.push_back(x);
    }
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        ms.erase(ms.find(v[i]));
        bool ok=1;
        for(int d : divisors[v[i]])
        {
            if(ms.find(d)!=ms.end())
            {
                ok=0;
                break;
            }
        }
        ms.insert(v[i]);
        if(ok) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 125396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define all(obj) (obj).begin(), (obj).end()
static const int dx[4] = {0, 1, 0, -1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'u', 'r', 'd', 'l'};
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

signed main() {
  ll K, X;
  cin >> K >> X;
  if (500 * K >= X) {
    puts("Yes");
  }else {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int> > a(n, vector<int> (n));
    vector<vector<int> > b(m, vector<int> (m));
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        for(int j = 0; j < n; j++)
        a.at(i).at(j) = s.at(j);
    }
    for(int i = 0; i < m; i++){
        string s;
        cin >> s;
        for(int j = 0; j < m; j++)
        b.at(i).at(j) = s.at(j);
    }//入力完了
    bool c = false;
    for(int i = 0; i < n - m + 1; i++){
        for(int j = 0; j < n - m + 1; j++){
            for(int k = 0; k < m; k++){
                bool d = true;
                for(int l = 0; l < m; l++){
                    if(a.at(i + k).at(j + l) != b.at(k).at(l)){
                    d = false;
                    break;
                    }
                    else if(k == m - 1 && l == m - 1){
                    c = true;
                    }
                }
                if(d == false)
                break;
            }
        }
    }
    if(c == true)
    cout << "Yes" << endl;
    else 
    cout << "No" << endl;
    return 0; 
}

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
s = sorted(ab, key=lambda x: x[0])
ans = 0
for i in range(n):
    if m <= s[i][1]:
        ans += s[i][0] * m
        break
    else:
        ans += s[i][0] * s[i][1]
        m -= s[i][1]
print(ans)


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e18;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

ll mpow(ll x, ll n, ll m) {
	ll ans = 1; x %= m;
	while (n != 0) {
		if (n & 1) ans = ans * x % m;
		x = x * x % m;
		n = n >> 1;
	}
	return ans;
}

vector<ll> naive(int n, string s) {
	vector<ll> nums(n);
	rep(i, n) nums[i] = s[i] - '0';
	vector<ll> vals(n);
	for (int i = 0; i < n; i++) {
		ll value = 0;
		ll v = 1;
		nums[i] = (nums[i] + 1) % 2;
		ll pcount = 0;
		for (int j = 0; j < n; j++) {
			if (nums[j]) pcount++;
		}
		for (int j = n - 1; j >= 0; j--) {
			value += nums[j] * v;
			v *= 2;
		}
		nums[i] = (nums[i] + 1) % 2;
		vals[i] = value % pcount;
	}
	return vals;
}

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<ll> dp(n + 1, -1);
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		ll next = i % __builtin_popcountll(i);
		dp[i] = dp[next] + 1;
	}
	//string s に対して、bit反転したものを % popcount したときの余りは?
	//popcount = s の数 ± 1
	ll pcount = 0;
	rep(i, n) {
		if (s[i] == '1') {
			pcount++;
		}
	}
	vector<ll> m;
	for (auto p : { pcount + 1, abs(pcount - 1)}) {
		ll current = 0;
		if (p > 0) {
			rep(i, n) {
				current *= 2;
				current += (s[i] == '1' ? 1 : 0);
				current %= p;
			}
		}
		m.push_back(current);
	}
	rep(i, n) {
		if (s[i] == '1') {
			//minus
			const ll mod = pcount - 1;
			if (mod == 0) {
				cout << 0 << endl;
			}
			else {
				ll m2 = mpow(2, n - 1 - i, mod);
				ll ans = (m[1] - m2 + mod) % (mod);
				//cout << i << "," << ans << endl;
				cout << dp[ans] + 1 << endl;
			}
		}
		else {
			//plus
			const ll mod = pcount + 1;
			ll m2 = mpow(2, n - 1 - i, mod);
			ll ans = (m[0] + m2) % (mod);
			//cout << i << "," << ans << endl;
			cout << dp[ans] + 1 << endl;
		}
	}
	//cout << "debug" << endl;
	//auto a = naive(n, s);
	//for (auto p : a) {
	//	cout << p <<"," << dp[p] + 1 << endl;
	//}
	return 0;
}


Measured memory_bytes: 5184
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	static void solve(){//Here is the main function
		int S = nextInt();
		int[] dp = new int[2001];
		int mod = 1000000007;
		for(int i = 3; i <= S; i++){
			dp[i]++;
			for(int j = 3; j <= i - 3; j++){
				dp[i] += dp[j];
				dp[i] %= mod;
			}
		}
		myout(dp[S]);
	}
	//Method addition frame start



	//Method addition frame end

	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
}


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

bool check(string str){
    int l;
    l = str.length();
    for(int i=0;i<l;i++){
        if(str[i] != str[0])
            return false;
    }
    return true;
}

int main(){
    string s;
    cin >> s;
    
    int l, count, min = 100, l2;
    l = s.length();
    string shrink, org;
    char tmp;
    // a~zで全探索
    for(int i=0;i<26;i++){
        count = 0;
        shrink = s;
        l2 = l;
        while( !check(shrink) ){
            // 縮小操作 tmp → shrink
            org = shrink;
            shrink.erase();
            l2--;   // 縮小後の文字列長
            for(int j=0;j<l2;j++){
                if(org[j] == 'a' + i)
                    tmp = org[j];
                else
                    tmp = org[j+1];
                shrink.push_back(tmp);
            }
            count++;
        }
        if(count < min)
            min = count;
    }
    
    cout << min << endl;
    return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    bool flag = false;
  
  	if (a < b && b < c) {
      flag = true;
    }
  	else {
      int cnt = 0;
      if (a >= b) {
      	rep(i,k) {
        	b *= 2;
        	cnt++;
        	if (a < b) break;
        }
      }
      k -= cnt;
      rep(i,k) {
        c *= 2;
      }
      if (a < b && b < c) {
        flag = true;
      }
    }
          
  	if (flag) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    vector<long int>a;
    for(long int i=0;i<s.size();i++)
    {
        if(s[i]=='B'){
            a.push_back(i+1);
        }
    }
   long int y=s.size();
   long int x=a.size();
   long int ans=0,j=x-1;
   while(j>=0)
   {
       ans+=abs(y-a[j]);
       j--;
       y--;
    }
    cout<<ans<<endl;

}




Measured memory_bytes: 2700
#include<iostream>
#include<algorithm>
#include<math.h>
#define _USE_MATH_DEFINES

using namespace std;

int n;
char s[101];
int first[26] = {}, last[26] = {}, ans = 0, num = 0;

int main() {
	cin >> n >> s;
	for (int i = 0; i < 26; i++) {
		first[i] = 101;
		last[i] = -1;
	}

	for (int i = 0; i < n; i++) {
		first[s[i] - 'a'] = min(first[s[i] - 'a'], i);
		last[s[n - i - 1] - 'a'] = max(last[s[n - i - 1] - 'a'], n - i - 1);
	}

	for (float i = 0.5; i < n; i++) {
		num = 0;
		for (int j = 0; j < 26; j++) {
			if (first[j] < i && last[j] > i) {
				num++;
			}
		}
		ans = max(ans, num);
	}
	cout << ans << endl;

	return 0;
}

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

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

  bool flag = false;

  for (int i=0; i<=25; i++) {
    for (int j=0; j<=14; j++) {
      if (i*4 + j*7 == N) {
        flag = true;
        break;
      }
    }
    if (flag == true) break;
  }

  cout << ( flag ? "Yes" : "No" ) << endl;
}


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

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

	if (S=="Sunny") cout << "Cloudy" << endl;
	if (S == "Cloudy") cout << "Rainy" << endl;
	if (S == "Rainy") cout << "Sunny" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 3e3 + 3;
string s1, s2;
 
int n, m, ans, mx = 0;
int mem[N][N];
vector<char> v;
int solve(int i, int j)
{
	if(i >= n || j >= m)
	{
		return 0;
	}
	if(mem[i][j] != -1)	return mem[i][j];
	int opt1 = solve(i + 1, j);
	int opt2 = solve(i, j + 1);
	int opt3 = s1[i] == s2[j] ? solve(i + 1, j + 1) + 1 : 0;
	return mem[i][j] = max(opt1, max(opt2, opt3));
}//zzz
void trace(int i, int j)
{
	if(i >= n || j >= m)	return;
 
	int opt1 = solve(i + 1, j);
	int opt2 = solve(i, j + 1);
	int opt3 = s1[i] == s2[j] ? solve(i + 1, j + 1) + 1 : 0;
 
	if(opt3 >= opt2 && opt3 >= opt1)
	{
     	
		trace(i + 1, j + 1);
		if(s1[i] == s2[j])
      		v.push_back(s1[i]);
	}
	else if(opt2 >= opt1)
		trace(i, j + 1);
	else
		trace(i + 1, j);
 
}
int main()
{
	memset(mem, -1, sizeof mem);
	cin >> s1 >> s2;
	n = s1.size();
	m = s2.size();
	solve(0, 0);
	trace(0, 0);
	for(int i = v.size() - 1; i >= 0; --i)
		cout << v[i];
	return 0;
}

Measured memory_bytes: 35968
#include<stdio.h>

int main(){

	int c[3][3];
	scanf("%d %d %d", &c[0][0], &c[0][1], &c[0][2]);
	scanf("%d %d %d", &c[1][0], &c[1][1], &c[1][2]);
	scanf("%d %d %d", &c[2][0], &c[2][1], &c[2][2]);
	
	int a[3], b[3];
	int i,  k[2] = { 0 };
	int j = 0;
	for (a[0] = 0; a[0] <= 100; a[0]++){
		b[0] = c[0][0] - a[0];
		b[1] = c[0][1] - a[0];
		b[2] = c[0][2] - a[0];
		k[0] = 0;
		k[1] = 0;
		for (i = 1; i <= 2; i++){
			if (c[i][0] - b[0] == c[i][1] - b[1] && c[i][0] - b[0] == c[i][2] - b[2]){
				k[i - 1]++;
			}
		}
		if (k[0] == 1 && k[1] == 1){
			j = 1;
		}
	}

	if (j == 1){
		printf("Yes");
	}
	else{
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
// 検索タグ
int main() {
	// 入力
	ll A[2];
    REP(i,2)cin>>A[i];
    
	// 解法
	sort(A, A + 2);  // a[0:N] を大きい順にソート

	//出力
	if (A[0]==1 & A[1]==2) printf("3\n");
	else if (A[0]==2 & A[1]==3) printf("1\n");
	else printf("2\n");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
#define mod 1000000007
typedef long long ll;
using namespace std;  
int n;
int vis[205];
int main()
{
	cin>>n;
	char s[5];
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>s;
		if(vis[s[0]]==0) ans++;
		vis[s[0]]++;
	}
	if(ans==3) cout<<"Three";
	else
	cout<<"Four";
	return 0;  
}
/**/


Measured memory_bytes: 256
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
c=[list(map(int,input().split())) for _ in range(m)]
l=float('inf')
for i in range(n):
    for j in range(m):
        k=abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
        if k<l:
            l=k
            ans=j
    print(ans+1)
    l=float('inf')

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

int main()
{
	long long  m,n,k,s,c,yu;
	scanf("%lld %lld",&s,&c);
	long long count =0;

	if(c>=s*2)
	{
		yu=c-s*2;
		count += s;
		k = yu/4;
		count += k;
		printf("%lld",count);
	}
	else
	{
		printf("%lld",c/2);		
	}

	
	return 0;
}

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

int main() {
  int N,M,count;
  cin>>N>>M;
  vector<int>vec(2*M);
  for(int i=0;i<2*M;i++){
    cin>>vec.at(i);
  }
  for(int i=1;i<N+1;i++){
    count=0;
    for(int j=0;j<2*M;j++){
      if(vec.at(j)==i)count++;
    }
    cout<<count<<endl;
  }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll,int> P;

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

	ll p=1;
	for(ll i=1;i<n+1;++i){
		p=(p*i)%1000000007;
	}
	cout<<  p<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}




int main(){
  int N;
  cin>>N;
  vector<int>A;
  vector<int>B;
  vector<int>C;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    A.push_back(x);
    
  }
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    B.push_back(x);
    
  }
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    C.push_back(x);
    
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  long long sum=0;
  for(auto e:B){
    long long aBegin = lower_bound(A.begin(), A.end(), e) - A.begin();
		long long cBegin = C.end() - upper_bound(C.begin(), C.end(), e);
    sum+=aBegin*cBegin;


  }
  cout<<sum<<endl;
  

}



  
  

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

int main() {
  int n, k, s;
  cin >> n >> k >> s;
  for (int i = 0; i < k; i++) {
    cout << s << endl;
  }
  int x = s == 1000000000 ? 1 : s+1;
  for (int i = 0; i < n-k; i++) {
    cout << x << endl;
  }
}

Measured memory_bytes: 1280
n,z,w=map(int,input().split())
*a,=map(int,input().split())
b,c=max(a),min(a)
pb,pc=a.index(b),a.index(c)  
if n<=1:
  print(abs(a[0]-w))
else:
  print(max(abs(a[n-1]-w),abs(a[n-2]-a[n-1])))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.equals("AAA") || s.equals("BBB")) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }

    }

}

Measured memory_bytes: 23764
#include<map>
#include<cstdio>
#include<string>
#include<algorithm>

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

using namespace std;

struct Idol{
	int vote;
	bool love;
	string name;
	bool operator<(const Idol &I)const{
		if(vote!=I.vote) return vote>I.vote;
		return name<I.name;
	}
};

int main(){
	for(int n,m,k,l;scanf("%d%d%d%d",&n,&m,&k,&l),n;){
		map<string,int> f;
		static Idol I[100000];
		rep(i,n){
			char s[11]; scanf("%s%d",s,&I[i].vote);
			I[i].name=s;
			f[s]=i;
			I[i].love=false;
		}
		rep(i,m){
			char s[11]; scanf("%s",s);
			I[f[s]].love=true;
		}
		sort(I,I+n);

		int lo=0,hi=k;
		while(lo<hi){
			int mi=(lo+hi+1)/2;

			int thr=n-1,cnt=0;
			rep(i,n) if(!I[i].love) {
				if(cnt==k-mi){ thr=i; break; }
				cnt++;
			}

			cnt=0;
			int v=l;
			rep(i,n) if(I[i].love) {
				int tmp;
				if(i>thr) tmp=I[thr].vote-I[i].vote+(I[thr].name<I[i].name?1:0);
				else      tmp=0;

				if(v>=tmp) v-=tmp, cnt++;
				else break;
			}

			if(cnt>=mi) lo=mi; else hi=mi-1;
		}

		printf("%d\n",lo);
	}

	return 0;
}

Measured memory_bytes: 9876
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll X;
    cin>>X;
    ll mon=100,ans=0;
    while(mon<X){
        ans++;
        mon*=1.01;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int c[1410][1410];
int dp[1410][1410];

int main(void) {
  int h, w;
  cin >> h >> w;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c[i][j];
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!i || !j) {
        dp[i][j] = c[i][j] ? 0 : 1; 
      } else {
        dp[i][j] = c[i][j] ? 0 : min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans * ans << endl;

  return 0;
}


Measured memory_bytes: 18524
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N, Q; cin >> N >> Q;
    string S; cin >> S;
    vector<int>v(N+1);
    v[0]=0;
    v[1]=0;
    for(int n=0; n<N; n++){
        if(S[n-1]=='A'&&S[n]=='C'){
            v[n+1]=v[n]+1;
        }else{
            v[n+1]=v[n];
        }
    }
    
    for(int q=0; q<Q; q++){
        int left, right; cin >> left >> right;
        cout << v[right]-v[left] << endl;
    }
}

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    cout << a + b + c - max(a, max(b, c)) + max(a, max(b, c)) * pow(2, k) << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};



typedef tuple<ll, ll, ll> T;


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

    int N, M; cin >> N >> M;
    UnionFind uni(N);
 
    for(int i=0; i<M; i++){
        int x,y,z; cin >> x >> y >> z;
        --x; --y;
        uni.connect(x, y);
    }
 
    map<int, int> mp;
    for(int i=0; i<N; i++) mp[uni.root(i)]++;
    cout << mp.size() << endl;

	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 x;
  cin >> x;
  int64 ans = 0;
  ans += x / 500 * 1000;
  x %= 500;
  ans += x / 5 * 5;
  ANS(ans);
  return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
h = [int(input()) for i in range(n)]
ng = 0
ok = 10 ** 9
while ok - ng > 1:
  mid = (ok + ng) // 2
  s = 0
  for i in h:
    s += max(0, (i - mid * b + a - b - 1) // (a - b))
  if s <= mid:
    ok = mid
  else:
    ng = mid
print(ok)


Measured memory_bytes: 51032
import numpy
d = int(input())
c = list(map(int,input().split()))
s = [0]*d
for i in range(d):
    s[i] = list(map(int,input().split()))
t = [0]*d
for i in range(d):
    t[i] = int(input())
ans = 0
lis = [0]*26
for i in range(d):
    ans += s[i][t[i]-1]
    lis[t[i]-1] = -1
    for j in range(26):
        lis[j] += 1
        ans -= lis[j]*c[j]
            
    print(ans)

Measured memory_bytes: 27348
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int A, B, max = -200; cin >> A >> B;
  vector<int> v(3, 0);
  v[0] = A + B;
  v[1] = A - B;
  v[2] = A * B;
  for(int i = 0; i < 3; i++) {
    if(max < v[i]) max = v[i];
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256