akhauriyash/Code-Regression huggingface dataset:
N = int(input())
H = list(map(int, input().split()))

ans = 'Yes'
H_floor = 0
for h in H:
    if h - H_floor < 0:
        ans = 'No'
        break
    else:
        H_floor = max(H_floor, h - 1) 
        
print(ans)

Measured memory_bytes: 14396
n, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range (1, len(a)):
	if a[i-1] + a[i] < x:
		continue
	else:
		sa = a[i-1] + a[i] -x
		a[i] -= sa
		if(a[i] < 0):
			a[i-1] -= abs(a[i])
			a[i] = 0
		cnt += sa
print (cnt)

Measured memory_bytes: 14540
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Map<String,Integer> map = new HashMap<String,Integer>();

        String temp = sc.nextLine();

        String[] tempArr = temp.split(" ");

        int N = Integer.parseInt(tempArr[0]);
        int M = Integer.parseInt(tempArr[1]);
        int C = Integer.parseInt(tempArr[2]);

        int[] MList = new int[M];

        temp = sc.nextLine();
        tempArr = temp.split(" ");
        for (int j = 0; j < M; j++) {
            MList[j] = Integer.parseInt(tempArr[j]);
        }

        int sum = 0;
        int counter = 0;
        for (int i = 0; i < N; i++) {
            temp = sc.nextLine();
            tempArr = temp.split(" ");
            sum = 0;
            for (int j = 0; j < M; j++) {
                sum += Integer.parseInt(tempArr[j]) * MList[j];
            }
            if ((sum + C) > 0) {
                counter++;
            }
        }

        System.out.println(counter);





    }

}


Measured memory_bytes: 23124
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    x,y=split(readline())
    if x==y
        println("=")
    elseif x<y
        println("<")
    else
        println(">")
    end
end
main()

Measured memory_bytes: 114568
import sys
#N = I()
#A = [LI() for _ in range(N)]

a, b = list(map(int,sys.stdin.readline().rstrip().split()))

if a > 0:
    print('Positive')
elif a <= 0 and b >= 0:
    print('Zero')
else:
    if (a+b)%2 == 0:
        print('Negative')
    else:
        print('Positive')

Measured memory_bytes: 3060
fun main() {
    val inp = readLine()!!.split(" ")
    val N = inp[0].toInt()
    val K = inp[1].toLong()
    val A = readLine()!!.split(" ").map { it.toInt() - 1 }
    val visitedA = IntArray(N)

    var current = 0
    var shuuki = 0
    var currentTime = 0
    var flag = false
    for (i in 1..N) {
        current = A[current]

        if (i >= K) {
            flag = true
            break
        }

        if (visitedA[current] != 0) {
            shuuki = i - visitedA[current]
            currentTime = i
            break
        }

        visitedA[current] = i
    }

    if (flag) {
        println(current + 1)
    } else {
        val amari = (K - currentTime) % shuuki
        for (i in 0 until amari) {
            current = A[current]
        }
        println(current + 1)
    }
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    pair<int, int> edge[M];
    rep(i, M){
        int a, b; cin >> a >> b;
        a--; b--;
        edge[i] = make_pair(a, b);
    }
    int ans = 0;
    rep(i, M){
        UnionFind uf(N);
        rep(j, M){
            if(i == j) continue;
            uf.merge(edge[j].first, edge[j].second);
        }
        bool ok = true;
        rep(j, N){
            if(!uf.issame(0, j)) ok = false;
        }
        if(!ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] h = new int[N];
    for(int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }
    System.out.println(solve(h, K));
  }
  
  public static long solve(int[] array, int k){
    long[] ans = new long[array.length];
    Arrays.fill(ans, Long.MAX_VALUE);
    ans[0] = 0L;
    for(int i = 0; i < array.length; i++){
      for(int j = i + 1; j <= k + i && j < array.length; j++){
        long tmp = Math.abs(array[j] - array[i]) + ans[i];
        ans[j] = ans[j] < tmp ? ans[j] : tmp;
      }
    }
    return ans[array.length - 1];
  }
}

Measured memory_bytes: 53368
a = int(input())
b = round(a**0.5) + 1
x = []
for i in range(1,b):
    for j in range(1,b):
        for k in range(1,b):
            l = i**2 + j**2 + k**2 + i*j + j*k + k*i
            x.append(l)

t = [0] * a
for i in range(0,len(x)):
    if x[i] <= a:
        t[x[i]-1] = t[x[i]-1] + 1

for i in t:
    print(i)

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

int main(){
    int n, c;
    cin >> n >> c;
    unsigned long w[n+1], v[n+1], dp[n+1][c+1]; //dp[item][weight]
    w[0] = 0;
    v[0] = 0;
    for(int i=1; i<n+1; i++)
	cin >> w[i] >> v[i];
    
    for(int j=0; j<c+1; j++)
	dp[0][j] = 0;
    // main
    for(int i=1; i<n+1; i++){
	for(int j=0; j<c+1; j++){
	    if(j >= w[i]){
		dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j]);
	    }else{
		dp[i][j] = dp[i-1][j];
	    }
	}
    }
    //
    // for(int i=0; i<n+1; i++){
    // 	for(int j=0; j<c+1; j++){
    // 	    cout << dp[i][j] << " ";        
    // 	}
    // 	cout << endl;        
    // }


    cout << dp[n][c] << "\n";        
}


Measured memory_bytes: 79104
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>

using namespace std;



int main() {
	int m, n, s, w;
	cin >> m >> n >> s >> w;
	if (m == s) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func getInput() []int {
	sc.Split(bufio.ScanWords)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())

	A := make([]int, N)
	for i := 0; i < N; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		A[i] = a
	}
	return A
}

type ByValue []int

func (s ByValue) Len() int           { return len(s) }
func (s ByValue) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s ByValue) Less(i, j int) bool { return s[i] < s[j] }

func main() {

	A := getInput()

	// A is 1 <= A <= 100
	if len(A) == 1 {
		fmt.Println(A[0])
		return
	}
	// sort
	// sort.Slice(A, func(i, j int) bool { return A[i] < A[j] })
	sort.Sort(ByValue(A))

	// A's length is >= 2
	diff := 0
	i := len(A) - 1
	for ; 0 < i; i -= 2 {
		diff += (A[i] - A[i-1])
	}
	if i == 0 {
		diff += A[0]
	}

	fmt.Println(diff)
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        int N, Y;
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        Y = scanner.nextInt();
        int x, y, z = 0;

        boolean check = false;
        for (x = 0; x <= N; x++) {
            for (y = 0; y <= N - x; y++) {
                z = N - x - y;
                if (Y == x * 10000 + y * 5000 + z * 1000) {
                    System.out.println(x+" "+y+" "+z);
                    check = true;
                }
               if (check == true){
                   break;
               }
            }
            if(check == true) {
                break;
            }
        }
        if(check == false){
            System.out.println("-1 -1 -1");
        }

    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define f(i,s,e) for(int i=s;i<e;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
ll cnt[26];
int main(){
    fast;
    int n;
    ll pro=1;
    string s;
    cin>>n>>s;
    f(i,0,s.size())
        cnt[s[i]-'a']++;
    f(i,0,26)
        pro=(pro*(cnt[i]+1))%mod;
    pro--;
    pro=(pro+mod)%mod;
    cout<<pro;

}


Measured memory_bytes: 512
import re
s=input().replace("?",".")
t=input()
for i in range(len(s)-len(t),-1,-1):
    if re.match(s[i:i+len(t)],t):
        s=s.replace(".","a")
        print(s[:i]+t+s[i+len(t):])
        exit()
print("UNRESTORABLE")


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);    
    // 頻度計算用
    map<ll, ll> mpe;
    map<ll, ll> mpo;
    vector<pair<ll, ll>> ve;
    vector<pair<ll, ll>> vo;
    
    // 入力処理
    ll n, ans = 0; cin >> n;
    rep(i, n){
        ll in; cin >> in;
        // 偶奇判定
        (i%2 == 0) ? mpe[in]++ : mpo[in]++;
    }

    // (回数, 数字)のペアを回数をキーに降順でソート
    for(auto p: mpe) ve.push_back(make_pair(p.second, p.first));
    for(auto p: mpo) vo.push_back(make_pair(p.second, p.first));
    sort(all(ve), greater<pair<ll, ll>>());
    sort(all(vo), greater<pair<ll, ll>>());

    // 偶数列・奇数列でそれぞれ同じ数字しか存在しない場合
    if((n/2-ve[0].first == 0) && (n/2-vo[0].first == 0)){
        // 偶数列と奇数列の最頻値が異なる数字である場合
        if(ve[0].second != vo[0].second) ans = 0;
        // 同じ数字が使われる場合は書き換えが少ない数列側を変える
        else ans = min(n/2-ve[1].first, n/2-vo[1].first);
    }

    // 異なる数字が混在する場合
    else{
        // 偶数列と奇数列の最頻値が異なる数字である場合
        if(ve[0].second != vo[0].second) ans = n/2-ve[0].first + n/2-vo[0].first;
        // 同じ数字が使われる場合は書き換えが少ない数列側を変える
        else{
            // 偶数列を2番目に頻度の高い数字で書き換え、奇数列を最も頻度の高い数字で書き換える
            if(n/2-ve[1].first <= n/2-vo[1].first) ans = n/2-ve[1].first + n/2-vo[0].first;
            // 奇数列を2番目の頻度の高い数字で書き換え、偶数列を最も頻度の高い数字で書き換える
            else ans = n/2-vo[1].first + n/2-ve[0].first;
        }
    }

    // 出力
    cout << ans << endl;
}

Measured memory_bytes: 8824
#include<bits/stdc++.h>
using namespace std;
#define int long long
int N,answer;
int table[100000+10],ans[100000+10];
signed main(){
  cin >> N;
    for(int i=0;i<N;i++){
      int a,b;
      cin >> a >> b;
      a--,b--;
      table[a]++;
      table[b+1]--;
    }
    for(int i=1;i<=N;i++){
      ans[i]+=ans[i-1]+table[i];
      //cout << ans[i] << endl;
      if(i<=ans[i]) answer=i;
    }
    cout << answer << endl;
  return 0;
}



Measured memory_bytes: 4624
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

struct int_pair_more {
  bool operator()(const pair<int,int>& x, const pair<int,int>& y) const {
    return x.second > y.second;
  }
};

vector<pair<int,int> > answer(100);

int main()
{
    while(1){
        int n,m;
        scanf("%d %d", &n, &m);
        if(n == 0 && m ==0)return 0;
        for(int j=0;j<m;j++)answer[j] = make_pair(j, 0);
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                int tmp;
                scanf("%d",&tmp);
                answer[j].second += tmp;
            }
        }
        stable_sort( answer.begin(), answer.end(), int_pair_more());
        for (int i=0;i<m-1;i++){
             printf("%d ", answer[i].first+1);
        }
        printf("%d\n", answer[m-1].first+1);
    }
}

Measured memory_bytes: 1036
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N;
long long ans =0;
long long tmp =0;
bool isDevide=true;

int main(){
  cin >> N;
  vector<long long>a(N);
  for (int i =0; i<N; i++){
    cin >> a.at(i);
  }
  for (int i =0; i<N; i++){
    while(1){
      if (a.at(i)%2==1){
        break;
      } else{
        tmp++;
        a.at(i) /=2;
      }
    }
    ans = max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}



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

vector<string> s;

void Print(int n, int g, string str) {
    int n_ = 0;
    while (n - n_ >= 0) {
        if (n - n_ == 0) {
            if (n == 0)
                cout << str << endl;
            break;
        }
        if (g >= n - n_)
            Print(n_, n - n_, str + (str == "" ? "" : " ") + s[n - n_]);
        n_++;
    }
}

int main() {
    for (int i = 0; i <= 30; i++) {
        int num = i;
        string tmp = "";
        while (num) {
            int nn = num % 10;
            char ss = '0' + nn;
            tmp = ss + tmp;
            num /= 10;
        }
        s.push_back(tmp);
    }


    int n;
    while (cin >> n, n) {
        Print(n, n, "");
    }

    return 0;
}

Measured memory_bytes: 3076
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static boolean isPrime[]=new boolean[2<<15+1];
	static int primes[]=new int[12251];
	static{
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		for(int i = 2;i*i<=isPrime.length;i++){
			if(isPrime[i]){
				for(int j = i+i;j<isPrime.length;j+=i){
					isPrime[j]=false;
				}
			}
		}
		int count=0;
		for(int i = 0;i<isPrime.length;i++){
			if(isPrime[i]){
				primes[count++]=i;
			}
		}
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int n = cin.nextInt();
			if(n==0)break;
			int ans=0;
			ans=0;
			for(int i = 0;primes[i]<=n/2;i++){
				if(isPrime[n-primes[i]]){
					ans++;
				}
			}
			System.out.println(ans);
		}
		
	}

}

Measured memory_bytes: 12000
#x,y,z = list(map(int,input().split()))
n,k = list(map(int,input().split()))

n = n % k
f = True
ans = n
while f:
    t = abs(n-k)
    if t < ans:
        ans = t
        n = t
    else:
        f = False

print(ans)


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

vector<vector<int> >vec;

int main(){
    int n,m,s,g,d;
    while(cin>>n,n){
        vector<int>cost(n,100000);
        vector<bool>used(n,0);
        for(int i=0;i<n;i++)
            vec.push_back(cost);
        cin>>m;
        int ans=0;
        char c;
        for(int i=0;i<m;i++){
            cin>>s>>c>>g>>c>>d;
            vec[s][g]=d/100-1;
            vec[g][s]=d/100-1;
        }
        cost[0]=0;
        while(1){
            int u=-1;
            for(int i=0;i<n;i++)
                if(!used[i]&&(u==-1||cost[i]<cost[u]))u=i;
            if(u==-1)break;
            used[u]=1;
            for(int i=0;i<n;i++)
                cost[i]=min(cost[i],vec[u][i]);
            ans+=cost[u];
        }
        cout<<ans<<endl;
        vec.clear();
    }
}

Measured memory_bytes: 1276
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int ansA = 0;
		int ansB = 0;
		int ansC = 0;

		ansA = A + B;
		ansB = A - B;
		ansC = A * B;

		System.out.println(Math.max(ansC, Math.max(ansA, ansB)));

	}
}

Measured memory_bytes: 35672
using System;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = Converter(Console.ReadLine());
            Console.WriteLine(Calc(nums));
        }

        static int[] Converter(string str)
        {
            return Array.ConvertAll(str.Split(' '), int.Parse);
        }

        static int Calc(int[] array)
        {
            int count = 0;
            for (int i = array[0]; i <= array[1]; i++)
                if (array[2] % i == 0) count++;
            return count;
        }
    }
}


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



int main() {

  ll X;
  cin >> X;

  for(ll a=-1000;a<1000;a++){
    for(ll b=-1000;b<1000;b++){
      if(pow(a,5) - pow(b,5) == X){
        cout << a <<" " << b << endl;
        return 0;
      }
    }
  }

}

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

int main() {
  int n,count;
  cin >> n;
  char c;
  
  rep(i,n){
    cin >> c;
    if(c=='Y'){
      count++;
    }
  }
  
  if(count==0){
    cout << "Three" << endl;
  }else{
    cout << "Four" << endl;
  }    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    string S;
    cin >> S;
    int K;
    cin >> K;
    int n = S.length();
    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(K+2, vector<ll>(2, 0)));

    dp[0][0][0] = 1;
    REP(i, n){
        REP(j, K+1){
            REP(d, 10){
                if(S[i]=='0' && d == 0) dp[i+1][j][0] += dp[i][j][0];
                else if((S[i]-'0') == d) dp[i+1][j+1][0] += dp[i][j][0];
                else if(d < (S[i]-'0')) {
                    if(d != 0) dp[i+1][j+1][1] += dp[i][j][0];
                    else dp[i+1][j][1] += dp[i][j][0];
                }
                
                if(d==0)dp[i+1][j][1] += dp[i][j][1];
                else dp[i+1][j+1][1] += dp[i][j][1];
            }
        }
    }
    pr(dp[n][K][0]+dp[n][K][1]);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
typedef pair<int,int> P;
int n;
vector<P> vc;
int main(){
	while(true){
		cin>>n;
		if(n==0) break;
		vc.clear();
		rep(i,n){
			char t;
			cin>>t;
			if(t=='W'){
				int id,x;
				cin>>id>>x;
				rep(k,vc.size()){
					if(vc[k].fs==-1){
						if(x<vc[k].sc){
							vc[k].sc-=x;
							vc.insert(vc.begin()+k,P(id,x));
							x=0;
						}else{
							vc[k].fs=id;
							x-=vc[k].sc;
						}
					}
					if(x==0) break;
				}
				if(x>0){
					vc.pb(P(id,x));
				}
			}else if(t=='D'){
				int id;
				cin>>id;
				rep(k,vc.size()){
					if(vc[k].fs==id) vc[k].fs=-1;
				}
			}else{
				int x;
				cin>>x;
				int now=0;
				bool done=false;
				rep(k,vc.size()){
					now+=vc[k].sc;
					if(x<now){
						cout<<vc[k].fs<<endl;
						done=true;
						break;
					}
				}
				if(!done){
					puts("-1");
				}
			}
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1308
n, k = map(int, input().split())
dp=[0]*(n+1)
dp[1] = 1

rui=[0]*(n+1)
rui[1] = 1
p = 998244353
lr=[]
for i in range(k):
    lr.append(list(map(int, input().split())))

for i in range(2,n+1):
    for l, r in lr:
        dp[i] += rui[max(i-l, 0)] - rui[max(i-r-1, 0)]
        dp[i] %= p
    rui[i] = rui[i-1] + dp[i]
    rui[i] %= p
print(dp[n])


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

int a, b, C = ~(1<<31), M = (1<<16)-1;
int r() {
  a = 36969 * (a & M) + (a >> 16);
  b = 18000 * (b & M) + (b >> 16);
  return (C & ((a << 16) + b)) % 1000000;
}

struct Point {
  int x, y, z;
  Point(){}
  Point(int x, int y, int z):x(x), y(y), z(z){}
  bool operator == (const Point& rhs) const {
    return x==rhs.x && y==rhs.y && z==rhs.z;
  }
  bool operator < (const Point& rhs) const {
    if(x != rhs.x) return x < rhs.x;
    if(y != rhs.y) return y > rhs.y;
    return z > rhs.z;
  }
};

struct Point2D {
  int y, z;
  Point2D(){}
  Point2D(int y, int z):y(y), z(z){}
  bool operator == (const Point2D& rhs) const {
    return y==rhs.y;
  }
  bool operator < (const Point2D& rhs) const {
    return y < rhs.y;
  }
};


int main() {
  int m, n, A, B;
  while(cin >> m >> n >> A >> B, m+n) {
    a = A, b = B;

    int N = n+m;
    vector<Point> pts(N);
    for(int i = 0; i < m; ++i) {
      cin >> pts[i].x >> pts[i].y >> pts[i].z;
    }
    for(int i = m; i < N; ++i) {
      pts[i].x = r();
      pts[i].y = r();
      pts[i].z = r();
    }
    sort(pts.begin(), pts.end());

    vector<set<Point2D> > dp(N+1);
    int ans = 1;
    for(int i = 0; i < N; ++i) {
      Point2D p = Point2D(pts[i].y, pts[i].z);
      int lb = 0, ub = ans+1;
      while(lb+1 < ub) {
	int mb = (lb+ub)/2;
	auto it = dp[mb].lower_bound(p);
	if(it != dp[mb].begin() && (--it)->z < p.z) lb = mb;
	else ub = mb;
      }
      ans = max(ans, ub);
      if(!dp[ub].empty()) {
	auto it = dp[ub].lower_bound(p);
	while(it != dp[ub].end() && it->z >= p.z) {
	  it = dp[ub].erase(it);
	}
      }
      if(dp[ub].empty()) {
	dp[ub].insert(p);
      } else {
	auto it = dp[ub].lower_bound(p);
	if(it == dp[ub].begin() || (--it != dp[ub].end() && (it->y != p.y || it->z > p.z))) {
	  dp[ub].insert(p);
	}
      }
    }

    cout << ans << endl;
  }

  return 0;
}



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

void solve() {
	string cur; cin >> cur;
	if (cur.back() == 's')cur += 'e';
	cur += 's';
	cout << cur;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 3648
n = 1000000
pr = [1] * n
pr[0] = 0
pr[1] = 0

1.upto(n){ |i|
  if(pr[i] == 1)
    (i**2).step(n,i){ |j|
      pr[j] = 0
    }
  end
}

2.upto(n){ |i|
  pr[i] += pr[i-1]
}

while STDIN.gets do
  n = $_.to_i
  puts pr[n]
end

Measured memory_bytes: 10084
/*
 * Author       : YangDavid
 * Created Time : 2019年07月21日 星期日 21时41分16秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 7010101, MOD = 998244353;
int muln(int x, int y) { return 1LL * x * y % MOD; }
int qpow(int x, int y) {
    int ret = 1;
    for(; y; y >>= 1, x = muln(x, x))
        if(y & 1) ret = muln(ret, x);
    return ret;
}
int inv(int x) { return qpow(x, MOD - 2); }
int mo(int x) {
    if(x >= MOD) return x - MOD;
    if(x < 0) return x + MOD;
    return x;
}
int fac[maxn], ifac[maxn], n, m;
int C(int x, int y) {
    if(x < y) return 0;
    return muln(fac[x], muln(ifac[y], ifac[x-y]));
}

signed main() {
    fac[0] = ifac[0] = 1;
    for(int i = 1; i <= 6000020; ++i) {
        fac[i] = muln(fac[i - 1], i);
    }
    ifac[6000020] = inv(fac[6000020]);
    for(int i = 6000019; i >= 0; --i)
        ifac[i] = muln(ifac[i + 1], i + 1);

    scanf("%lld%lld", &n, &m);
    ll ans1 = C(3 * m + n - 1, n - 1);
    ll ans2 = muln(n, C(n+m-2, n-1));
    ll ans3 = 0, ans4 = 0;

    for(int k = m + 1; k <= 3 * m; ++k) {
        if((3 * m - k) & 1) continue;
        if(k > n) break;
        ans3 = mo(ans3 + muln(C(n, k), C((3*m-k)/2+n-1, n-1)));
    }
    ll ans = ans1 - ans2 - ans3 - ans4;
    //printf("%lld %lld %lld %lld\n", ans1, ans2, ans3, ans4);
    while(ans < 0) ans += MOD;
    while(ans >= MOD) ans -= MOD;
    printf("%lld\n", ans);


    return 0;
}


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

int H, W, diff[80][80], B, M = 12800, ans = 1e9;
bool dp[80][80][25601];

void dfs(int y, int x, int v) {
    if (dp[y][x][v+M]) return;
    dp[y][x][v+M] = true;

    int move1 = v + diff[y][x];
    int move2 = v - diff[y][x];
    if (y == H - 1 && x == W - 1) {
        ans = min({ans, abs(move1), abs(move2)});
    } else {
        if (y != H - 1) {
            dfs(y + 1, x, move1);
            dfs(y + 1, x, move2);
        }
        if (x != W - 1) {
            dfs(y, x + 1, move1);
            dfs(y, x + 1, move2);
        }
    }
}

int main() {
    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> diff[i][j];
    rep(i, H) rep(j, W) {
        cin >> B;
        diff[i][j] = abs(diff[i][j] - B);
    }

    dfs(0, 0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 159104
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________
	string s, t;
	cin >> s >> t;
	sort(all(s));
	sort(all(t), greater<char>());
	if (s < t)
	{
		cout << "Yes" << en;
	}
	else
	{
		cout << "No" << en;
	}



	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<' '<<x<<' '<<y<<endl;
}

Measured memory_bytes: 256
class Node():
    def __init__(self, parent=-1, left=-1, right=-1):
        self.parent = parent
        self.left = left
        self.right = right


class Tree(dict):
    def __init__(self, obj={}):
        if isinstance(obj, dict):
            super().__init__(obj)
        else:
            raise TypeError
        self.root = -1

    def insert_key(self, key):
        node = Node()
        parent = -1  # targetの親
        target = self.root  # 探索中のkey
        while target != -1:
            parent = target
            if key < target:
                target = self[target].left
            else:
                target = self[target].right
        node.parent = parent
        self[key] = node
        if parent == -1:  # Tが空の場合、最上位の場合
            self.root = key
        elif key < parent:
            self[parent].left = key
        else:
            self[parent].right = key

    def find(self, key):
        try:
            self[key]
            print("yes")
        except KeyError:
            print("no")

    def __preorder(self, id):
        if id == -1:
            return []
        return [id] + self.__preorder(self[id].left) + self.__preorder(self[id].right)

    def __inorder(self, id):
        if id == -1:
            return []
        return self.__inorder(self[id].left) + [id] + self.__inorder(self[id].right)

    def __postorder(self, id):
        if id == -1:
            return []
        return self.__postorder(self[id].left) + self.__postorder(self[id].right) + [id]

    def __preorder_print(self, id):
        if id == -1:
            pass
        else:
            print(" {}".format(id), end="")
            self.__preorder_print(self[id].left)
            self.__preorder_print(self[id].right)

    def __inorder_print(self, id):
        if id == -1:
            pass
        else:
            self.__inorder_print(self[id].left)
            print(" {}".format(id), end="")
            self.__inorder_print(self[id].right)

    def __postorder_print(self, id):
        if id == -1:
            pass
        else:
            self.__postorder_print(self[id].left)
            self.__postorder_print(self[id].right)
            print(" {}".format(id), end="")

    def order_list(self, order_type):
        if order_type == 0:
            return self.__preorder(self.root)
        elif order_type == 1:
            return self.__inorder(self.root)
        else:
            return self.__postorder(self.root)

    def print(self):
        # self.__inorder_print(self.root)
        # print("\n", end="")
        # self.__preorder_print(self.root)
        # print("\n", end="")
        print(" {}".format(" ".join(map(str, self.order_list(1)))))
        print(" {}".format(" ".join(map(str, self.order_list(0)))))


def main():
    n = int(input())
    tree = Tree()
    for _ in range(n):
        operation = input()
        if operation[0] == "i":
            tree.insert_key(int(operation.split()[1]))
        elif operation[0] == "f":
            tree.find(int(operation.split()[1]))
        else:
            tree.print()


if __name__ == "__main__":
    main()



Measured memory_bytes: 139048
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<complex>
using namespace std;
using ll = long long;
using ld = double;
using P = complex<ld>;
const ld eps = 1e-10;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}

ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }

using C = pair<ld, P>;
#define rad first
#define pnt second

C smallest_enclosing_disc(vector<P> ps){
    auto c3 = [](const P &a, const P &b, const P &c){
        ld A = norm(b - c);
        ld B = norm(c - a);
        ld C = norm(a - b);
        ld S = abs(cross(b - a, c - a));
        P p = (A*(B+C-A)*a + B*(C+A-B)*b + C*(A+B-C)*c) / (4*S*S);
        ld r = abs(p - a);
        return make_pair(r, p);
    };

    auto c2 = [](const P &a, const P &b){
        P c = (a + b) / (ld)2;
        ld r = abs(a - c);
        return make_pair(r, c);
    };

    auto in_circle = [](const P &a, const C &c){
        return norm(a - c.pnt) <= c.rad*c.rad + eps;
    };

    int n = ps.size();
    random_shuffle(ps.begin(), ps.end());
    C c = c2(ps[0], ps[1]);
    for(int i = 2; i < n; ++i){
        if(!in_circle(ps[i], c)){
            c = c2(ps[0], ps[i]);
            for(int j = 1; j < i; ++j){
                if(!in_circle(ps[j], c)){
                    c = c2(ps[j], ps[i]);
                    for(int k = 0; k < j; ++k){
                        if(!in_circle(ps[k], c)){
                            c = c3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}

signed main(){
  init_io();
  ll n,x,y;
  cin >> n;
  vector<P> ps;
  for(int i=0;i<n;i++){
    cin >> x >> y;
    ps.push_back(P(x,y));
  }
  C v = smallest_enclosing_disc(ps);
  cout << v.first<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define boost	    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

vector <vector <ll >> dp;

ll max(ll a, ll b)  { return a > b ? a : b; }
ll min(ll a, ll b)  { return a > b ? b : a; }

ll go(int i, int j, vector <ll> &a) {
	if(i > j) return 0;

	if(i == j) return a[i];

	if(dp[i][j] != -1) return dp[i][j];

	ll x = a[i] + min(go(i + 2, j, a), go(i + 1, j - 1, a));
	ll y = a[j] + min(go(i + 1, j - 1, a), go(i, j - 2, a));
	dp[i][j] = max(x, y);
	return dp[i][j];
}

void solve() {
	boost;
	int n;
	cin >> n;
	vector <ll> a(n);
	ll sum = 0;
	dp.resize(n, vector <ll > (n, -1));
	rep(i, 0, n) { 
		cin >> a[i];
		sum += a[i];
	}
	
	//cout << go(0, n - 1, a) << endl;
	//cout << sum << endl;
	ll x = go(0, n - 1, a);
	ll y = sum - x;
	cout << x - y << endl;
}

int main() {
	int t = 1;
	//cin >> t;
	while(t--)
		solve();

	return 0;
}


Measured memory_bytes: 70912
import bisect
n =int(input())
l =list(map(int, input().split()))
l.sort()
total = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    tmp = bisect.bisect_left(l,l[i]+l[j])
    total += tmp - j - 1
print(total)


Measured memory_bytes: 3188
#include <iostream>
#include <math.h>
#include <string> 
using namespace std;
#define NUM 200000
int main(){
    int n,a,sum=0;
    cin>>n;
    int m=n;
    while(m>0){
        sum+=m%10;
        m/=10;
    }
    if(n%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string s;
ll dp[1000005][2][12];

int main(void){
	cin >> s;
	s='0'+s;
	int n=s.size();
	for(int i=0;i<=n+1;i++){
		for(int j=0;j<2;j++){
			dp[i][0][j]=INF;
			dp[i][1][j]=INF;
		}
	}
	dp[0][0][0]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				if(dp[i][j][k]==INF)continue;
				//printf("%d %d %d %lld\n",i,j,k,dp[i][j][k]);
				int p=(s[i]-'0');
				for(int l=0;l<=9;l++){
					int hav=k*10+l;
					if(hav<p)continue;
					if(hav==p){
						dp[i+1][j][0]=min(dp[i+1][j][0],dp[i][j][k]+l);
					}else{
						dp[i+1][j][1]=min(dp[i+1][j][1],dp[i][j][k]+l+hav-p-1);
						dp[i+1][j][0]=min(dp[i+1][j][0],dp[i][j][k]+l+hav-p);
					}
				}
			}
		}
	}
	ll ans=dp[n][0][0];
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 188848
#include <bits/stdc++.h>  
#define lli long long 
using namespace std; 
long long mod2=1e9+7,mod=998244353;
lli power(lli x, lli y,lli m=mod) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%m; 
        y = y>>1; 
        x = (x*x)%m;  
    }
    if(res<0)
       res+=m; 
    return res; 
}
// lli fact[2000009];
// lli ncr(lli n,lli r){
//     lli ans=fact[n];
//     if(r>n)return 1;
//     if(r<0)return 0;
//     if(n<0)return 0;
//     ans=(ans*power(fact[n-r],mod-2))%mod;
//     ans=(ans*power(fact[r],mod-2))%mod;
//     return ans;
// }

int main() 
{ 
    // fact[0]=1;
    // for(int i=1;i<=2000005;i++)fact[i]=(i*fact[i-1])%mod;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        long long n;cin>>n;
        long long ans=0;
        for(int i=1;i<=n-1;i++){
            ans+=n/i-(n%i==0);
        }
        cout<<ans<<"\n";
    }
    return 0; 
} 

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

int N, K;
string S;

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

	vector<int> v;
	v.push_back( 0 );
	char c = '1';
	for( int i = 0; i < S.size(); i++ ) {
		if( S[i] != c ) {
			v.push_back( i );
			c = S[i];
		}
	}
	v.push_back( S.size() );
	int ans = 0;
	for( int i = 0; i < v.size() - 1; i += 2 ) {
		int l = i;
		int r = min( i + 2 * K + 1, (int)v.size() - 1 );
		int cnt = v[r] - v[l];
		ans = max( ans, cnt );
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1020
from sys import stdin

while True:
    n, x = [int(x) for x in stdin.readline().rstrip().split()]
    if n == 0 and x == 0:
        break
    else:
        count = 0
        for i in range(1, n-1):
            for j in range(i+1, n):
                if j < x-i-j <= n:
                    count += 1
        else:
            print(count)


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

int main() {
	long n,m,i,j,k,ans,cur,c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	vector<long> l(k),r(k);
	j=0;
	for(i=0; i<k; i++){
		while(s[j]=='x'){
			j++;
		}
		l[i]=j;
		j+=c+1;
	}
	j=n-1;
	for(i=k-1; i>=0; i--){
		while(s[j]=='x'){
			j--;
		}
		r[i]=j;
		j-=c+1;
	}
	
	for(i=0; i<k; i++){
		if(l[i]==r[i]){
			cout << l[i]+1 << endl;
		}
	}
	return 0;
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

int main(){
  ll p, q, r; cin >> p >> q >> r;
  ll ans = p + q;
  chmin(ans, p + r); chmin(ans, q + r);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

int main() {
  int k, a, b;
  cin >> k >> a >> b;

  bool ans = false;
  for(int i = a; i <= b; ++i) {
    if (i % k == 0) {
      ans = true;
      break;
    }
  }
  if (ans == true) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int n;
    cin >> n;
    map<string,int> mp;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << mp.size() << endl;
    return 0;
}

Measured memory_bytes: 19180
n, x = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) < x:
  print(n-1)
  exit()
a.sort()
cnt = 0
i = 0
while i < n and a[i] <= x:
  cnt += 1
  x -= a[i]
  i += 1
print(cnt)

Measured memory_bytes: 3064
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL V[100000];

LL ans = 0;

void solve(){
	vector<pair<LL,LL>> even(100001,pair<LL,LL>(0,0));
	vector<pair<LL,LL>> odd(100001,pair<LL,LL>(0,0));
	for(int i=0;i<N;i++){
		if(i%2==0){
			even[V[i]].first++;
			even[V[i]].second = V[i];
		}
		if(i%2==1){
			odd[V[i]].first++;
			odd[V[i]].second = V[i];
		}
	}
	sort(even.begin(),even.end(),greater<pair<LL,LL>>());
	sort(odd.begin(),odd.end(),greater<pair<LL,LL>>());

	if(even[0].second==odd[0].second){
		ans = min(N - even[0].first - odd[1].first,N - even[1].first - odd[0].first);
	}else{
		ans = N - even[0].first - odd[0].first;
	}
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> V[i];

    solve();
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4096
#define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

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

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int t;
    cin>>t;
    while(t--){
        int m,n;
        cin>>m>>n;
        int c=0;
        rep(i,300){
            rep(j,300){
                if(!i&&!j)continue;
                int t=i*i+j*j;
                if((m*i+n*j)%t==0&&(m*j-n*i)%t==0)c++;
            }
        }
        cout<<(2*c>8?'C':'P')<<endl;
    }
}


Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

using namespace std;

int main()
{
    int n;
    int res = 0;
    int ct = 1;
    cin >> n;
    while (res < n)
    {
        res += ct;
        ++ct;
    }

    cout << ct - 1 << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;
int cnt[200009];

int main(){
  int n;
  int a[200009];
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i];

  vector<int>ans;
  for(int i=n;i>0;i--){
    vector<int>d;
    int t=i;
    for(int j=1;j*j<=t;j++){
      if(t%j==0){
        d.push_back(j);
        if(j!=t/j)d.push_back(t/j);
      }
    }
    int now=0;
    if(cnt[i]%2!=a[i]){
      ans.push_back(i);
      now=1;
    }
    rep(i,d.size()){
      cnt[d[i]]+=now;
    }
  }

  cout<<ans.size()<<endl;
  rep(i,ans.size()){
    cout<<ans[i];
    if(i+1==ans.size())cout<<endl;
    else cout<<' ';
  }

  return(0);
}


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

using namespace std;

const int N = 2e5+5;

const int mod = 1e9+7;

int n;
int ar[N];

long long get(int x){
    long long cost = 0;
    for(int i = 1; i <= n; i++){
        cost += (x - ar[i]) * (x - ar[i]);
    }
    return cost;
}

int main(){
    cin >> n;
    long long av = 0;
    for(int i = 1; i <= n; i++){
        cin >> ar[i];
        av += ar[i];
    }
    av /= n;
    printf("%lld\n" , min(get(av) , get(av + 1)));
}

Measured memory_bytes: 3716
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: i64,
        K: i64,
        X: i64,
        Y: i64,
    }
    println!("{}", X*min(N,K) + max(0,N-K)*Y);
}


Measured memory_bytes: 4352