akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    ll N,K;
    ll A[200100];
    ll B[200100] = {-1};
    int now = 1;
    ll cnt = 0;
    cin >> N >> K;
    REP(i,N){
        cin >> A[i+1];
    }
    REP(i,200100){
        B[i] = -1;
    }
    //途中でどっかに合流したら抜ける
    ll j;
    B[1] = 0;
    for(j = 1; j <= K; j++){
        //cout << now << " -> " << A[now] << endl;
        now = A[now];
        if(B[now] == -1){
            //cout << "未到達だった" << endl;
            B[now] = j;
        }else{
            //cout << "到達済みだった" << endl;
            //cout << "B[now] = " << B[now] << endl;
            cnt = j;
            //cout << "cnt = " << cnt << endl;
            break;
        }
    }
    if(j < K){
        ll tmp;
        tmp = (K - B[now]) % (cnt -B[now]);
        //cout << "あと " << tmp << "回移動すればいい" << endl;
        //B[now]からtmp回ワープしたところが終着点
        for (ll j = 0; j < tmp; j++)
        {
            now = A[now];
        }
    }
    fin(now);
    return 0;
}

Measured memory_bytes: 6308
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810364364
#define PI 3.14159265358979
#define ERR 0.00000000000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL i,ans=0,X;
  scanf("%lld",&X);
  ans+=1000*(X/500);
  X%=500;
  ans+=5*(X/5);

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


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

int main(){
    int n,i,count=1;
    char str[200005][15]={};
    scanf("%d",&n);
    for (i=0; i<n; i++) scanf("%s",str[i]);
    qsort(str, n, sizeof(char[15]), strcmp);
    for (i=0; i<n-1; i++) if (strcmp(str[i], str[i+1])) count++;
    printf("%d\n",count);
    return 0;
}


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

int n;
string zeroi;

string query(int i) {
    cout << i << endl;
    string res; cin >> res;
    return res;
}

void bsearch(int l, int r) { 
    if (l == r) {
        string ans = query(l);
    } else if (l + 1 == r) {
        if (query(r) != "Vacant")
            string ans = query(l);
    } else {
        int m = (l + r) / 2;
        string res = query(m);
        if (res == "Vacant") return;
        if ((m % 2 && res != zeroi) || (!(m % 2) && res == zeroi)) bsearch(m + 1, r);
        else bsearch(l, m - 1);
    }
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    cout << 0 << endl;
    cin >> zeroi;
    if (zeroi == "Vacant") return 0;
    bsearch(1, n - 1);
}



Measured memory_bytes: 852
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace cf16b
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());
            var bufout = new StreamWriter(Console.OpenStandardOutput());

            var v = new List<int>();

            int i = 1, sum = 0;
            while (sum < input)
            {
                v.Add(i);
                sum += i;
                ++i;
            }
            
            for (int j = 0; sum > input && j < i; ++j)
            {
                v[j] -= sum - input;
                sum -= j + 1;
            }
            
            foreach (var val in v.Where(c => c > 0)) bufout.WriteLine(val);

            bufout.Close();
        }
    }
}


Measured memory_bytes: 13268
func readInts(separator: String.Element = " ") -> [Int] {
    return readLine()!.split(separator: separator).map { Int($0)! }
}

func mainA() {
    let LRd = readInts()
    let L = LRd[0]
    let R = LRd[1]
    let d = LRd[2]

    var count = 0
    (L...R).forEach { number in
        if number.isMultiple(of: d) {
            count += 1
        }
    }

    print(count)

}

mainA()

Measured memory_bytes: 8112
k, n = map(int, input().split())
a = list(map(int, input().split()))

diff = [0] * n
for i in range(n):
    if i + 1 == n:
          diff[i] = a[0] + (k - a[i])
    else:
        diff[i] = abs(a[i] - a[(i + 1)])

print(k - max(diff))

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
typedef unsigned long long ull;
typedef long long ll;

const ll MOD=1e9+7;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

 	int n,m;
 	cin >> n >> m;
 	ll A[100005];
 	A[0]=1;
 	FORN(i,1,100005)
 		A[i]=(A[i-1]*i)%MOD;
 	int c=0;
 	if(abs(n-m)==1)
 		c=1;
 	if(abs(n-m)==0)
 		c=2;

 	cout << (c*A[n]*A[m])%MOD << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long double n,k;
  cin >> n >> k;
  long double ans=0;
  for(int i=1;i<=n;i++){
    int x=i;
    long double y=1/n;
    while(x<k){
      x*=2;
      y/=2.0;
    }
    ans+=y;
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

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

int main() {
    string S;
    cin>>S;
    int arr[S.size()+1];
    arr[0] = 0;
    for(int i=0;i<S.size();++i){
        arr[i+1] = S[i]-'0';
    }
    long ans = 0;
    for(int i=S.size();i>=1;--i){
        if(arr[i]==5){
            if(arr[i-1]<=4){
                ans += arr[i];
            }
            else{
                ans += 10 - arr[i];
                arr[i-1]++;
            }
        }
        else if(arr[i]<=4){
            ans += arr[i];
        }
        else {
            ans += 10 - arr[i];
            arr[i-1]++;
        }
    }
    if(arr[0]>0)ans+=arr[0];
    cout<<ans<<endl;
}


Measured memory_bytes: 5252
import sys
from sys import stdin

n = int(stdin.readline().rstrip())
a, b = map(int, stdin.readline().rstrip().split())
p = list(map(int, stdin.readline().rstrip().split()))
ans1 = 0
ans2 = 0
ans3 = 0
p.sort()

for pi in p:
    if pi <= a:
        ans1 += 1
    elif pi > a and pi <= b:
        ans2 += 1
    else:
        ans3 += 1

print(min(ans1, ans2, ans3))

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

using namespace std;

typedef long long ll;

inline ll read(){
	char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

char ch[1010011];

int main(){
	int ans=0x7fffffff;
	cin>>ch+1;
	int l=strlen(ch+1);
	for(int i=1;i<=l;i++){
		int d=i+3-1;
		if(d>l) break;
		int v=abs((ch[i]-'0')*100+(ch[i+1]-'0')*10+(ch[i+2]-'0')-753);
		if(v<ans){
			ans=v;
		}
	}
	cout<<ans;
	return 0;
}





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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        long x,y; cin>>x>>y;
        int cnt=0;
        while(x<=y)
        {
                x*=2;
                cnt++;
        }
        cout<<cnt<<endl;
}

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

int main(){
	string a, left, right;
	int h,m;
	while (1){
		cin >> a;
		if (a == "-")break;
		cin >> m;
		for (int i = 0; i < m;i++){
			cin >> h;
			left = a.substr(0, h);
			right = a.substr(h, a.size());
			a = right + left;
		}
		cout << a << endl;
	}

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  ll size=a[0];
  int ans=n;
  for(int i=1;i<n;i++){
    if(size*2<a[i]){
      ans=n-i;
    }
    size+=a[i];
  }
  cout << ans;
  return 0;
}

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

//ABC161
int main(void) {
  int n, k, i, cou=0, tmp;
  scanf("%d %d %d", &n, &k, &i);
  printf("%d %d %d", i, n, k);
  return 0;
}

Measured memory_bytes: 128
from itertools import combinations
import numpy as np


h, w, k = map(int, input().split())

c = np.array([[1 if s == '#' else 0 for s in input()] for _ in range(h)])

hs = [list(hs) for hh in range(1, h + 1) for hs in combinations(range(h), hh)]
ws = [list(ws) for ww in range(1, w + 1) for ws in combinations(range(w), ww)]

a = 0
for hss in hs:
    cc = c[hss]
    for wss in ws:
        if np.sum(cc[:, wss]) ==k:
            a += 1
print(a)


Measured memory_bytes: 26800
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		String[] list = new String[n];
		for (int i = 0; i < list.length; i++) {
			list[i] = scan.next();
		}

		char previous = list[0].charAt(list[0].length() - 1);

		String ans = "Yes";

		Set<String> linkedHashSet = new LinkedHashSet<String>();
		for (int i = 0; i < list.length; i++) {
			linkedHashSet.add(list[i]);
		}
		
		if(linkedHashSet.size() != list.length) {
			ans = "No";
		} else {
			for (int i = 1; i < list.length; i++) {
				if (previous != list[i].charAt(0)) {
					ans = "No";
					break;
				}
				previous = list[i].charAt(list[i].length() - 1);
			}
		}

		System.out.println(ans);
	}
}

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

using namespace std;

int main() {

    float n;
    vector<float> m;

    while(cin >> n) {
        m.push_back(n);
    }

    sort(m.begin(), m.begin() + m.size(), greater<float>());

    printf("%.1f\n", m[0] - m[m.size() - 1]);

}

Measured memory_bytes: 1252
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <bitset>
typedef unsigned long long int ll;
const ll INF = 876543210987654321;
const int MOD = 1000000007;
#define REP(i,n) for(int i=0;i<n;++i)
#define pd(x) cout<<x<<endl
using namespace std;
//vector<vector<int>>(h, vector<int>(w, f));


int main() {
	string s;
	cin >> s;
	ll a[30] = {};
	ll n = s.size();
	for (int i = 0; s[i]; ++i)	a[s[i] - 'a']++;
	ll ans = n*(n - 1) / 2;
	for (int i = 0; i < 26; ++i) {
		if (a[i] > 1)ans -= a[i] * (a[i] - 1) / 2;
	}
	cout << ans+1 << endl;
	int aa;
	cin >> aa;
	return 0;

}

Measured memory_bytes: 640
import bisect
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
#aa = sorted(a,reverse=True)

#print(bisect.bisect_left(a,x))
#print(bisect.bisect_left(aa,x))

left = bisect.bisect_left(a,x)
print(min(left,len(a)-left))

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

class fast_Fourier_transform{
    private:
    const double PI=3.14159265358979; 
    
    vector<complex<double>> DFT(vector<complex<double>> A){
        int N=A.size();
        if(N==1)return A;
        vector<complex<double>> A0(N/2),A1(N/2),iA0,iA1,iA(N);
        for(int i=0;i<N;i++){
            if(i%2==0){
                A0[i/2]=A[i];
            }else{
                A1[i/2]=A[i];
            }
        }
        iA0=DFT(A0);
        iA1=DFT(A1);
        
        for(int i=0;i<N;i++){
            complex<double> ith_zeta = complex<double>(cos(2*PI*i/N),sin(2*PI*i/N));
            iA[i]=(iA0[i%(N/2)]+ ith_zeta*iA1[i%(N/2)]);
        }
        return iA;
    }
    
    vector<complex<double>> iDFT(vector<complex<double>> iA){
        int N=iA.size();
        vector<complex<double>> A,dA,rA;
        dA=DFT(iA);
        for(int i=0;i<N;i++){
            rA.push_back(dA[(N-i)%N]);
            A.push_back(rA[i]/complex<double>(N,0));
        }
        return A;
    }
    
    public:
    vector<int> convolution(vector<int> A,vector<int> B){
        int deg = A.size() + B.size() -1;
        int N=1;
        while(N<deg){N<<=1;}
        A.resize(N);B.resize(N);
        vector<complex<double>> dC(N),iC(N),dA,iA,dB,iB;
        vector<int> C(N);
        for(int i=0;i<A.size();i++){
            dA.push_back(A[i]);
        }
        for(int i=0;i<B.size();i++){
            dB.push_back(B[i]);
        }
        iA=DFT(dA);iB=DFT(dB);
        for(int i=0;i<N;i++){
            iC[i]=iA[i]*iB[i];
        }
        dC=iDFT(iC);
        for(int i=0;i<dC.size();i++){
            C[i]=(int)(0.1+dC[i].real());
        }
        return C;
    }
    
};


signed main(void){
    int N,M,a,Amax=0;
    vector<int> A;
    cin >> N >> M;
    REP(i,N){
        cin >> a;
        Amax=max(Amax,a);
        A.push_back(a);
    }
    
    vector<int> B,C;
    B.resize(Amax+1,0.0);
    REP(i,N){
        B[A[i]]++;
    }
    fast_Fourier_transform FFT;
    C=FFT.convolution(B,B);
    
    /*REP(i,C.size()){
        if(C[i]==0)continue;
        cout <<i MM C[i] << endl;
    }*/
    
    int Ans=0;
    int now=0;
    RREP(i,C.size()){
        int d=C[i];
        if(M-now>=d){
            Ans+=d*i;
            now+=d;
        }else{
            Ans+=(M-now)*i;
            break;
        }
    }
    cout << Ans << endl;
    return 0;
}



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

int main(){
  int64_t N;
  cin >> N;
  vector <int64_t> H(N);
  priority_queue <int64_t> pq;
  int64_t n=0;
  cin >> H.at(0);
  for(int64_t i=1;i<N;i++){
    cin >> H.at(i);
    if(H.at(i-1)>=H.at(i)){
      n++;
    }else{
      pq.push(n);
      n=0;
    }
  }
  pq.push(n);
  cout << pq.top() << endl;
  return 0;
}


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

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

    int r = 32;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        for (int j = 0; j < 32; j++) {
            if (a % 2 != 0) {
                r = min(r, j);
                break;
            }
            a /= 2;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(typeof(a) i=a;i!=(b);++i)
#define CLEAR(a,v) memset(a,v,sizeof(a))
#define SORT(a) sort(a,a+sizeof(a)/sizeof(a[0]))
using namespace std;

int main(){
    string S;
    cin >> S;
    int s = 0, t = 0;
    int len = S.size();
    REP(i,len){
        if(S[i] == 'S'){
            s++;
        }else{
            if(s == 0){
                t++;
            }else{
                s--;
            }
        }
    }
    cout << s+t << endl;
}

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

int main(){
    int N;
    cin >> N;
    int t[N+1];
    int x[N+1];
    int y[N+1];
    t[0] = x[0] = y[0] = 0;
    for(int i = 0; i < N; i++) {
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }

    bool flag = true;

    for(int i = 0; i < N; i++){
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);

        if(dist > dt) flag = false;
        if(dt%2 != dist%2) flag = false;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408
while True:
    n= int(input())
    if n== 0: break
    m, s= int(input()), input()
    ioi= "IOI" if n==3 else "IOI"+"OI"*(n-1)
    n= 2*n+1
    print(sum(1 for i in range(m-n+1) if s[i:i+n]==ioi))

Measured memory_bytes: 9452
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

const LL INF = 0x3ffffffff;

int N;
LL H[11451];
LL P[11451];
int ord[11451];
LL dp[5010][5010];

int main() {
  scanf("%d", &N);
  rep(i, N) {
    scanf("%lld%lld", &H[i], &P[i]);
    ord[i] = i;
  }

  sort(ord, ord+N, [](int a, int b) {
    int p = H[a] + P[a];
    int q = H[b] + P[b];
    if (p != q) return p < q;
    return H[a] < H[b];
  });

  fill(dp[0], dp[N+1], INF);

  dp[0][0] = 0;
  rep(i, N) {
    int idx = ord[i];
    rep(j, N+1) {
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
      if (dp[i][j] <= H[idx]) {
        dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + P[idx]);
      }
    }
  }

  rrep(i, N+1) {
    if (dp[N][i] != INF) {
      printf("%d\n", i);
      break;
    }
  }
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }

  sort(A.begin(),A.end());
  int pac = 0;
  int point = 0;
  vector<int> pac_num(N,N+1);
  for(int i=0; i<N; i++){
    pac++;
    if(i < N-1){
      if(A.at(i) != A.at(i+1)){
        pac_num.at(point) = pac;
        pac = 0;
        point++;
      }
    }else{
      pac_num.at(point) = pac;
    }
  }

  sort(pac_num.begin(),pac_num.end());
  int kind = 0;
  for(int i=0; i<N; i++){
    if(pac_num.at(i) != N+1){
      kind++;
    }
  }
  int dif_kind = kind - K;
  int cnt = 0;
  if(dif_kind > 0){
    for(int i=0; i<dif_kind; i++){
      cnt += pac_num.at(i);
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, m, s, t; scanf("%lld %lld %lld %lld", &n, &m, &s, &t);
  V<V<P<ll, ll>>> anode(n, V<P<ll, ll>>()), bnode(n, V<P<ll, ll>>());
  REP(i, m) {
    ll u, v, a, b; scanf("%lld %lld %lld %lld", &u, &v, &a, &b);
    anode.at(u-1).push_back({a, v-1});
    anode.at(v-1).push_back({a, u-1});
    bnode.at(u-1).push_back({b, v-1});
    bnode.at(v-1).push_back({b, u-1});
  }
  vll ad(n, HIGHINF), bd(n, HIGHINF);

  priority_queue<P<ll, ll>, V<P<ll, ll>>, greater<P<ll, ll>>> quea;  // cost, edge
  ad[s-1] = 0; quea.push({0, s-1});
  while (!quea.empty()) {  // yenのsからの最短経路長
    P<ll, ll> q = quea.top(); quea.pop();
    ll v = q.second;
    if (ad[v] < q.first) continue;  // コストが大きいなら更新の必要なし
    REP(i, anode[v].size()) {
      P<ll, ll> to = anode[v][i];
      if (ad[to.second] > ad[v] + to.first) {
        ad[to.second] = ad[v] + to.first;
        quea.push({ad[to.second], to.second});
      }
    }
  }

  priority_queue<P<ll, ll>, V<P<ll, ll>>, greater<P<ll, ll>>> queb;  // cost, edge
  bd[t-1] = 0; queb.push({0, t-1});
  while (!queb.empty()) {  // yenのsからの最短経路長
    P<ll, ll> q = queb.top(); queb.pop();
    ll v = q.second;
    if (bd[v] < q.first) continue;  // コストが大きいなら更新の必要なし
    REP(i, bnode[v].size()) {
      P<ll, ll> to = bnode[v][i];
      if (bd[to.second] > bd[v] + to.first) {
        bd[to.second] = bd[v] + to.first;
        queb.push({bd[to.second], to.second});
      }
    }
  }

  vll ans(n);
  ll minc = HIGHINF;
  for (ll i=n-1; i>=0; i--) {
    ll tmpc = ad[i] + bd[i];
    minc = min(minc, tmpc);
    ans[i] = 1e15 - minc;
  }
  REP(i, n) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 20216
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int h,w,k;cin>>h>>w>>k;
  vector<string> c(h);rep(i,h)cin>>c[i];
  
  int ans = 0;
  rep(bit1,(1 << h)){
    rep(bit2,(1 << w)){
      bitset<6> bs1(bit1);
      bitset<6> bs2(bit2);

      int cnt = 0;
      rep(i,h){
        rep(j,w){
          if(!bs1[i] && !bs2[j] && c[i][j] == '#')cnt++;
        }
      }
      if(cnt == k)ans++;
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

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

int bubbleSort(int A[],int N) {
    int i,j;
    int sw = 0;
    unsigned short flag = 1;
    for(i=0;flag;i++) {
        flag = 0;
        for(j=N-1;j>=i+1;j--) {
            if(A[j]<A[j-1]) {
                swap(&A[j],&A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(void) {
    int i, A[100], N, sw;
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = bubbleSort(A,N);

    for(i=0;i<N;i++) {
        if (i) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",sw);

    return 0;
}


Measured memory_bytes: 2116
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[100]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k-1]; 
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i=0; i<N; ++i) {
        cin >> A[i];
    }

    vector<long long> acum(N+1);
    acum[0] = 0;
    for (int i=1; i<=N; ++i) {
        acum[i] = acum[i-1] + A[i-1];
    }

    long long hi = acum[N];
    long long lo = 0;
    while (hi - lo > 1) {
        long long mi = (hi + lo) / 2;

        int j = 0, k = 0;
        bool ok = false;
        for (int i=0; i<N; ++i) {
            j = max(j, i);
            while (j <= i+N && (acum[j%(N+1)]-acum[i%(N+1)]+acum[N]) % acum[N] < mi) {
                j++;
            }
            k = max(k, j);
            while (k <= i+N && (acum[k%(N+1)]-acum[j%(N+1)]+acum[N]) % acum[N] < mi) {
                k++;
            }
            long long p1, p2, p3;
            p1 = (acum[j%(N+1)]-acum[i%(N+1)]+acum[N]) % acum[N];
            p2 = (acum[k%(N+1)]-acum[j%(N+1)]+acum[N]) % acum[N];
            p3 = (acum[i%(N+1)]-acum[k%(N+1)]+acum[N]) % acum[N];
            if (min(min(p1, p2), p3) >= mi) {
                ok = true;
                break;
            }
        }

        if (ok) {
            lo = mi;
        } else {
            hi = mi;
        }
    }
    cout << lo << endl;

    return 0;
}


Measured memory_bytes: 4408
/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<stdio.h>
#include<vector>

#define INF 0x3f3f3f3f

using namespace std;

void Swap(int & x, int & y) {
    int t = x;
    x = y;
    y = t;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << "\n";
    return 0;

}



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

#define INF 1050000000
#define MOD 1000000007

using namespace std;


int main() {
	long long int n, a;
	cin >> n >> a;
	int x[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	long long int dp[n + 1][n + 1][n*a + 1];
	memset(dp, 0, sizeof(dp));
	dp[0][0][0] = 1;

	for (int i = 0; i < n + 1; i++) {
		for (int j = 0; j < n + 1; j++) {
			for (int k = 0; k < n * a + 1; k++) {
				if (i > 0 && x[i - 1] > k) dp[i][j][k] = dp[i - 1][j][k];
				else if (i > 0 && j > 0 && x[i - 1] <= k)
					dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
			}
		}
	}

  	long long int ans = 0;

	for (int i = 1; i < n + 1; i++) {
		ans += dp[n][i][i*a];
	}

	cout << ans << endl;

}

Measured memory_bytes: 51072
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
	8
	ABABBABA
										`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	n := nextInt()
	l := nextInts(n)

	ans := 0
	for i := 0; i < n-2; i++ {
		for j := i + 1; j < n-1; j++ {
			for k := j + 1; k < n; k++ {
				if l[i] != l[j] && l[k] != l[j] && l[k] != l[i] && l[i]+l[j] > l[k] && l[k]+l[i] > l[j] && l[j]+l[k] > l[i] {
					//fmt.Fprintln(out, "[DEBUG]", l[i], l[j], l[k])
					ans++
				}
			}
		}
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)

}

// 挿入ソート配列
type slist struct {
	l []int
}

func makeSlist() slist {
	return slist{[]int{}}
}

func (s *slist) add(a int) {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	if pos < len(s.l) {
		s.l = append(s.l[:pos+1], s.l[pos:]...)
		s.l[pos] = a
	} else {
		s.l = append(s.l, a)
	}
}
func (s slist) contains(a int) bool {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	return pos < len(s.l) && s.l[pos] == a
}

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

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func printArray(a []int) {
	for i := 0; i < len(a); i++ {
		if i >= 1 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, a[i])
	}
	fmt.Fprintln(out)
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}
func divCeil(shi, bo int) int {
	ans := shi / bo
	if shi%bo != 0 {
		ans++
	}
	return ans
}


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

using namespace std;

int main() {
	string s;
	cin >> s;
	vector<int> a;
	int c=0,i;
	for(i=0;i<s.size();i++) {
		if(s[i]=='R') {
			c++;
		}
		else {
			a.push_back(c);
			c=0;
		}	
	} 
	a.push_back(c);
	cout<<*max_element(a.begin(),a.end());
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <string>
#include <stdio.h>
#include <cstdlib>

using namespace std;

int main() {
    int a = 0;
    int b  = 0;
    cin >> a;
    if (a % 10 == 7){
        b = 1;
    }
    a = a / 10;
    if (a % 10 == 7){
        b = 1;
    }
    a = a / 10;
    if (a == 7){
        b = 1;
    }
    if (b == 1){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}



Measured memory_bytes: 3624
using System;

namespace JKTX_AOJ2015
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            int s, len;

            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);

            s = a * b;
            len = (2 * a) + (2 * b);

            Console.WriteLine("{0} {1}", s, len);
        }
    }
}

Measured memory_bytes: 5620
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

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


ll gcd_3(ll a,ll b, ll c){
    ll tmp=0;
    tmp = gcd(a,b);
    return gcd(c,tmp);
}

int main(void){
    ll k;
    ll ans =0;
    cin >> k;
    for(ll a=1; a<=k; a++){
        for(ll b=1; b<=k; b++){
            for(ll c=1; c<=k; c++){
                ans+=gcd_3(a,b,c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <set>
#include <cassert>
#include <map>
#include <queue>
#include <algorithm>
#include <cctype>
#include <cstring>
using namespace std;

struct NODE{
	int x,y,cost,bit;
	NODE(int x,int y,int cost,int bit) :  x(x) , y(y) , cost(cost) , bit(bit) {}
};

bool done[30][30][1<<8];


int main(){
	char c[30][30];
	int W,H;
	while(cin >> W >> H && W){
		int sx,sy;
		map<char,int> dd;
		set<char> exist;
		for(int i = 0 ; i < H ; i++)
			for(int j = 0 ; j < W ; j++){
				cin >> c[i][j];
				if(c[i][j] == '@'){
					c[i][j] = '.';
					sx = j , sy = i;
				}
				if(islower(c[i][j])){
					char t = c[i][j] | 32;
					int w = dd.size();
					if(!dd.count(t)) dd[t] = w;
				}
			
				exist.insert(c[i][j]);
			}	
		queue<NODE> Q;
		Q.push(NODE(sx,sy,0,0));
		memset(done,0,sizeof(done));
		while(Q.size()){
			NODE q = Q.front(); Q.pop();
			if(done[q.y][q.x][q.bit]) continue;
			else done[q.y][q.x][q.bit] = true;
			if( c[q.y][q.x] == '<' ){
				cout << q.cost << endl;
				goto end;
			}
			int dx[] = {-1,0,1,0} , dy[] = {0,-1,0,1};
			for(int i = 0 ; i < 4 ; i++){
				int tx = q.x + dx[i] , ty = q.y + dy[i];
				char t = c[ty][tx];
				if(t=='#')continue;
				if(isupper(t) && !exist.count(c[ty][tx]|32)) continue;
				if(isupper(t) ){
					if(!(q.bit&(1<<(dd[t|32]))))continue;
				}
				int bit = q.bit;
				if(islower(t)){
					bit ^= 1<<dd[t|32];
				}
				Q.push(NODE(tx,ty,q.cost+1,bit));
			}
		}
		cout << -1 << endl;
		end:;
		
	}
}

Measured memory_bytes: 1612
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, M;
    cin >> N >> M;

    // cが足りない場合
    if (N * 2 > M)
    {
        cout << M / 2 << endl;
    }

    // Sが足りない場合
    else
    {
        ll ans = N + (M - N * 2) / 4;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define ll long long
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " is " << (x) << endl

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

    int n, k, q, x;
    cin >> n >> k >> q;
    int a[n + 3]{};
    ll res;

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

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

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		while(true){
			int m=scan.nextInt();
			int f=scan.nextInt();
			int r=scan.nextInt();
			
			if(m==-1 && f==-1 && r==-1)break;
			
			if(m==-1 || f==-1 || m+f<30)System.out.println("F");
			
			else {
				if(m+f >= 80)System.out.println("A");
				else if(65<=m+f && m+f<80)System.out.println("B");
				else if(50<=m+f && m+f<65)System.out.println("C");
				else if(30<=m+f && m+f<50){
					if(r>=50)System.out.println("C");
					else System.out.println("D");
				}
			}
		}
	}
}


Measured memory_bytes: 26180
N,M,Q = map(int,input().split())
memo = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
    l,r = map(int,input().split())
    memo[l][r] += 1
for i in range(N):
    for j in range(N):
        memo[i+1][j+1] += memo[i][j+1] + memo[i+1][j] - memo[i][j]
for i in range(Q):
    p,q = map(int,input().split())
    print(memo[q][q] - memo[p-1][q] - memo[q][p-1] + memo[p-1][p-1])

Measured memory_bytes: 13420
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,d,a,c=0;


    cin>>n>>k;
    vector<int> v(n+1);
    for(int i=0;i<k;i++)
    {
        cin>>d;
        for(int j=0;j<d;j++)
        {
            cin>>a;
            v[a]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(v[i]==0)
            c++;
    }
    cout<<c<<endl;
    return 0;
}

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

if 0 in a:
    print(0)
    sys.exit()

    
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        print(-1)
        sys.exit()

print(ans)
        


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

int main() {
	int N, Q;
	cin >> N >>Q;
	vector<long long> a(N),x(Q);
	for(int i = 0; i < N; i++) {
		cin >> a.at(i);
	}
	for(int i = 0; i < Q; i++) {
		cin >> x.at(i);
	}
	for(int i = 0; i < Q; i++) {
        long long res = 0;
        int right = 0;     
        long long sum = 0; 
        for (int left = 0; left < N; ++left) {
            while (right < N && sum + a[right] <= x.at(i)) {
                sum += a[right];
                ++right;
            }
            res += (right - left);
            if (right == left) ++right;
            else sum -= a[left];
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll INF=1e18;
vector<ll> x[210005];
vector<ll> used(210005,0);
vector<ll> c(2);


void dfs(ll t){
  //used[n][t]=1;
  if (t>=100005)c[0]++;
  if (t<100005)c[1]++;
  used[t]=1;
  for(ll to:x[t]){
    if (used[to])continue;
    dfs(to);
  }
}


int main() {
  ll N;
  cin >> N;
  vector<P> v(N);


  rep(i,N){
    ll a1,b1;
    cin>>a1>>b1;
    a1--;b1+=100005;
    v[i]=make_pair(a1,b1);
    x[a1].push_back(b1);
    x[b1].push_back(a1);
  }
ll ans=0;
  rep(i,N){
    c[0]=0;c[1]=0;

    dfs(v[i].first);
  //  cout<<"i"<<i<<cx<<" "<<cy<<endl;
    ans+=c[0]*c[1];

  }

  ans-=N;
  cout<<ans;

}


Measured memory_bytes: 17380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> x(m);
    vector<int> kyori(m-1);
    ll zentai = 0;
    rep(i,m) cin >> x[i];
    
    if(n>=m){
        cout << 0 <<endl;
        return 0;
    }
    
    sort(x.begin(),x.end());

    rep(i,m-1){
        int l = abs(x[i]-x[i+1]);
        kyori[i] = l;
        zentai += l;
    }
    sort(kyori.rbegin(),kyori.rend());
    
    int jokyo = n-1;
    rep(i,jokyo){
        zentai -= kyori[i];
    }
    cout << zentai <<endl;
    return 0;
    
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int H, W;
	scanf("%d %d", &H, &W);

	int A[H + 1][W + 1];
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			scanf("%d", &A[i][j]);
		}
	}
	int C[H + 1][W + 1];
	for (int i = 0; i <= H; ++i) {
		C[i][0] = 0;
	}
	for (int i = 0; i <= W; ++i) {
		C[0][i] = 0;
	}

	int maxWidth = 0;
	for (int j = 1; j <= W; ++j) {
		for (int i = 1; i <= H; ++i) {
			if (A[i][j] == 0) {
				C[i][j] = min(C[i][j - 1], min(C[i - 1][j - 1], C[i - 1][j])) + 1;
			} else {
				C[i][j] = 0;
			}
			maxWidth = max(maxWidth, C[i][j]);
		}
	}
	cout << maxWidth * maxWidth << endl;

	return 0;
}

Measured memory_bytes: 18476
import java.util.*;
public class Main{
	public static boolean check(long p, long w[], long k, int n){
		int id = 0;
		while(k > 0L){
			long sum = 0;
			while(id < n && sum + w[id] <= p)
				sum += w[id++];
			if(id == n)
				return true;
			else
				k--;
		}
		return false;
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long w[] = new long[n];
		for(int i =0  ;i < n ; i++)
			w[i] = sc.nextLong();
		long min = 0;
		long max = 1000000000;
		while(max - min > 1L){
			long mid = (min + max) / 2L;
			if(check(mid,w,k,n)){	
				max = mid;
			}
			else{
				min = mid;
			}
		}
		System.out.println(max);
	}
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

class UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> size;
    vector<vector<int>> group;
public:
    UnionFind(int n = 1) {
        par.resize(n + 1);
        rank.resize(n + 1);
        size.resize(n + 1);
        group.resize(n + 1);
        for (int i = 0; i <= n; ++i) {
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
            group[i].push_back(i);
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            int r = find(par[x]);
            return par[x] = r;
        }
    }

    bool is_same(int x, int y) {
        return find(x) == find(y);
    }

    bool unit(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        } else {
            if (rank[x] < rank[y]) {
                swap(x, y);
            }
            if (rank[x] == rank[y]) {
                ++rank[x];
            }
            par[y] = x;
            size[x] += size[y];
            return true;
        }
    }

    int get_size(int x) {
        return size[find(x)];
    }

    void merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (group[x].size() > group[y].size()) {
            swap(x, y);
        }
        copy(group[y].begin(), group[y].end(), back_inserter(group[x]));
        group[y].clear();
        par[y] = x;
    }
};

void solve() {
    ll N, M, K;
    cin >> N >> M >> K;
    UnionFind friends(N), block(N);
    map<ll, set<ll>> F, B;
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        friends.unit(a, b);
        F[a].insert(b);
        F[b].insert(a);
    }
    rep(i, K) {
        ll c, d;
        cin >> c >> d;
        c--;
        d--;
        block.unit(c, d);
        B[c].insert(d);
        B[d].insert(c);
    }
    rep(i, N) {
        ll c = friends.get_size(i) - F[i].size() - 1;
        for (ll b : B[i]) {
            if (friends.is_same(i, b)) {
                c--;
            }
        }
        cout << c << ' ';
    }
    cout << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 51584
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];


int main()
{
	ll n;
	cin >> n;
	vector<ll> v(n);
	rep(n, v);
	sort(v.begin(), v.end());
	double sum = 0;
	for (ll i = n - 1; 1 <= i ; i--)
	{
		sum += v[i] / pow(2, n-i);
	}
	sum += v[0] / pow(2, n - 1);
	cout << sum << "\n";
	
	return 0;
}

Measured memory_bytes: 4224
s = input().rstrip()
n = len(s)

def value(m):
    num = s[0]
    ans = 0
    for i in range(1, n):
        t = (m>>(i-1)) & 1
        if t ==1:
            ans += int(num)
            num = s[i]
        else:
            num = num + s[i]
    ans += int(num)
    return ans

count = 0
for i in range(2**(n-1)):
    count +=value(i)

print(count)

Measured memory_bytes: 9104
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	cin>>n;
	int k=(int)((-1+sqrt(1+8*n))/2);
	int res=n-k*(k+1)/2;
	int rm,push;
	bool check=(n==k*(k+1)/2)?true:false;
	loop(i,k+1,n+1){
		if((i-res)<=k){
			rm=i-res;
			push=i;
			break;
		}
	}
	loop(i,1,k+1){
		if(i==rm)continue;
		cout<<i<<endl;
	}
	if(!check)cout<<push<<endl;
	return 0;
}

Measured memory_bytes: 384
N = int(input())
h = list(map(int, input().split()))
ans = 0

while True:
    if 0 not in h:
        for i in range(N):
            h[i] -= 1
        ans += 1
    elif set(h) == {0}:
        break
    else:
        tmp = 0
        for i in range(N):
            if h[i] > 0:
                h[i] -= 1
                tmp = 1
            elif tmp == 0:
                continue
            else:
                break
        ans += tmp
print(ans)

Measured memory_bytes: 3064