akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    h = [int(input()) for i in range(N)]
    H = sorted(h)

    ans = 10**9 +1
    for i in range(N-K+1):
        high = H[i+K-1] - H[i] 
        ans = min(ans, high)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 8280
# -*- coding: utf-8 -*-
from itertools import product
def inpl(): return list(map(int, input().split()))

N, A, B, C = inpl()
L = [int(input()) for _ in range(N)]

ans = float("INF")

for X in product(range(4), repeat=N):#4**n,無ABC,[0,1,3,1,2,3,0]
    P = [[] for _ in range(4)]
    for i, x in enumerate(X):
        P[x].append(L[i])

    if min(map(len, P[1:])) == 0:
        continue

    tmp = 0
    for Q, D in zip(P[1:], [A, B, C]):
        tmp += 10*(len(Q)-1) + abs(D-sum(Q))#2つを1つにするのに10かかる
    if tmp < ans:
        ans = min(tmp, ans)

print(ans)


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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
// https://scrapbox.io/ganariya/AtCoderBeginnerContest135_D%E5%95%8F%E9%A1%8C400%E7%82%B9_%E3%80%8CDigits_Parade%E3%80%8D
int main() {
  string s;
  cin >> s;

  int N = 13;
  string t = s;
  reverse(t.begin(), t.end());

  vector<ll> dp(N, 0);
  dp[0] = 1;

  ll base = 1;
  for (int i = 0; i < t.size(); i++) {
    vector<ll> next(N, 0);
    if (t[i] == '?') {
      for (int k = 0; k <= 9; k++) {
        ll d = k * base;
        for (int j = 0; j < N; j++) {
          next[(d + j) % N] += dp[j];
          next[(d + j) % N] %= MOD;
        }
      }
    } else {
      for (int j = 0; j < N; j++) {
        ll d = ((t[i] - '0') * base);
        next[(d + j) % N] += dp[j];
        next[(d + j) % N] %= MOD;        
      }
    }
    dp = next;
    base *= 10;
    base %= 13;
  }
  cout << dp[5] << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int N = scn.nextInt();
        String S = scn.next();
        int ans =0;

        for(int i=0;i<N-2;i++){
            if(i==N-2){
                break;
            }
            if(S.substring(i,i+3).equals("ABC")){
                ans +=1;
            }
        }

        System.out.println(ans);

        scn.close();

    }


}


Measured memory_bytes: 26984
#include<cstdio>
#include<algorithm>
using namespace std;
int n,c[25],v[25],ans;
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i) scanf("%d",&v[i]);for(int i=1;i<=n;++i) scanf("%d",&c[i]);
	for(int i=1;i<=n;++i) ans+=max(0,v[i]-c[i]);
	printf("%d",ans);
	return 0;
}

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

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

  sort(v.begin(), v.end());

  double ans = v[0];
  for (int i = 1; i < N; i++) {
    ans = (ans + v[i]) * 0.5;
  }
  printf("%.10lf\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()

using namespace std;

const int INF = 1e9;

int main() {
    int n,k;
    cin>>n>>k;
    vector<int>h(110000);
    rep(i,n)cin>>h[i];

    vector<int>dp(110000,INF);
    dp[0] = 0;
    rep(i,n){
        rrep(j,k){
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    cout<<dp[n-1]<<endl;


    return 0;
}

Measured memory_bytes: 4024
program sample
    implicit none
    character(100000)::s,t
    character::top,las
    integer(8) :: i,j,m,n,a,b,c0,c1
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) s
    n=len_trim(s)
    if(n==1)then
        write(*,*)0
        stop
    end if
    a=1
    b=n
    c0=0
    c1=0
    m=0

    do i=1,n
        do 
        if(s(a:a) .eq. 'x' .and. a<n)then
            a=a+1
            c0=c0+1
        elseif(a==n .and. s(n:n) .eq. 'x')then
            write(*,*)0
            stop
        else
            top=s(a:a)
            exit
        end if
        end do
        do
        if(s(b:b) .eq. 'x')then
            b=b-1
            c1=c1+1
        else
            las=s(b:b)
            exit
        end if
        end do
        if(top .ne. las)then
            write(*,*)-1
            stop
        else
            m=m+abs(c0-c1)
            a=a+1
            b=b-1
            c0=0
            c1=0
        end if
        if(a>=b)then
            exit
        endif
    end do

    write(*,*) m
  
    stop
end program sample
  



Measured memory_bytes: 3156
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int S,W;
    cin >> S >> W;
    string ans = "unsafe";
    
    if(S>W) ans = "safe";

    cout << ans << ln;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    int l[n];
    for(int i = 0; i<n; ++i){
        cin >> l[i];
    }
    sort(l,l+n);
    int result = 0;
    for(int i = 1; i<=k; ++i){
        result += l[n-i];
    }
    cout << result << endl; return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int l[100010];
int r[100010];
int main(){
	int n,m;
	cin>>n>>m;
	int cnt=0;
	int res=1e9;
	for(int i=0;i<m;i++){
		cin>>l[i]>>r[i];
		cnt=max(cnt,l[i]);
		res=min(res,r[i]);
	}
	if(cnt>res){
		cout<<0<<endl;
	}
	else if(res>=cnt){
		cout<<res-cnt+1<<endl;
	}
	return 0;
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int MOD = 998244353;
const int N = 200005;

int fac[N],ifac[N];

int mpower(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1){
            res = (res*x) % p;
        }
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    fac[0]=1;
    ifac[0]=1;
    for(int i=1;i<N;i++)fac[i]=(i*fac[i-1])%MOD,ifac[i]=mpower(fac[i],MOD-2,MOD);
    for(int ti=1;ti<=tc;ti++)
    {
        int n,m,k;
        cin>>n>>m>>k;
        int ans = 0,curr = m;
        for(int i=0;i<n;i++)
        {
            int now = (fac[n-1]*ifac[i])%MOD;
            now *= ifac[n-1-i];now %= MOD;
            now *= curr;now %= MOD;
            if(n-1-i<=k)ans+=now,ans%=MOD;
            curr *= (m-1);
            curr %= MOD;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 6736
T = int(input())
dct ={}
for z in range(T):
    s = "".join(sorted(input()))
    if s in dct:
        dct[s] += 1
    else:
        dct[s] = 1
v = 0
for elem in dct.values():
    v += (elem*(elem-1))//2
print(v)

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

ne=0
his=[None for i in range(n)]
l=False
for i in range(min(n,k)):
    if his[ne]!=None:
        back=his[ne]
        loop=i-back
        l=True
        break
    his[ne]=i
    #his.append(ne)
    ne=a[ne]-1

if l:
    ansidx=(k-back)%loop+back
    ans=his.index(ansidx)+1
else:
    ans=ne+1
print(ans)

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

int sp[10000];

int main() {
    FILE * fi, * fout;
    int i, a, b, c, d;
    //fi = fopen("A.in" ,"r");
    //fout = fopen("A.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d%d%d%d" ,&a,&b,&c,&d);
    sp[a]++;
    sp[b]--;
    sp[c]++;
    sp[d]--;
    int ans = 0;
    for(i = 0; i <= 2000; i++) {
        if(i > 0)
            sp[i] += sp[i - 1];
        if(sp[i] == 2)
            ans++;
    }
    fprintf(fout,"%d" ,ans);
    //fclose(fi);
    //fclose(fout);
    return 0;
}


Measured memory_bytes: 256
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()
    n,k=[parseInt(readline()) for i in 1:2]
    res=1
    for i in 1:n
        res=min(res*2,res+k)
    end
    println(res)
end
main()

Measured memory_bytes: 167424
/* AtCoder コピペ */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repEq(i, n) for (int i = 0; i <= (int)(n); i++)
#define repVector(i, v) for (auto i = v.begin(); i != v.end(); ++i)

#define ifBetween(n, a, b) if (n > a && n < b)
#define ifBetweenEq(n, a, b) if (n >= a && n <= b)

int main() {
	string sa, sb, sc;
  	char turn = 'a';

  	cin >> sa;
   	cin >> sb;
   	cin >> sc;
  
  	vector<char> va(sa.begin(), sa.end());
    vector<char> vb(sb.begin(), sb.end());
    vector<char> vc(sc.begin(), sc.end());

  
  	char x = 'a';
  	for (;;) {
    	if (turn == 'a') {
            if (va.size() == 0) {
            	break;
            }
        	x = va.front();
          	va.erase(va.begin());
          	turn = x;
        }
        if (turn == 'b') {
            if (vb.size() == 0) {
            	break;
            }
        	x = vb.front();
          	vb.erase(vb.begin());
          	turn = x;
        }
        if (turn == 'c') {
           	if (vc.size() == 0) {
            	break;
            }
        	x = vc.front();
          	vc.erase(vc.begin());
          	turn = x;
        }
    }

  	char result = toupper(turn);
  	cout << result << endl;
}


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

#define REP(idx, end) for(int idx = 0; idx < end; ++idx)
#define DBG(x) cerr << #x << ": " << x << "\n"

using namespace std;
typedef long long lint;
const int MOD = 1000000007;

int main() {

	cin.tie(0);

	int N, M;
	cin >> N >> M;

	vector<string> A(N);
	vector<string> B(M);
	REP(i, N) cin >> A[i];
	REP(i, M) cin >> B[i];
	
	REP(i, N - M + 1) {
		REP(j, N - M + 1) {
			if (A[i].substr(j, M) == B[0]) {
				REP(k, M) {
					if (A[i + k].substr(j, M) != B[k]) break;
					else if (k == M - 1) {
						cout << "Yes";
						return 0;
					}
				}
			}
		}
	}
	cout << "No";

	return 0;
}

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
if((10 * g + b) % 4 == 0) cout << "YES" << endl;
else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int gcd(int x,int y);

int main(){
  int x,y;

  scanf("%d %d",&x,&y);

  printf("%d\n",gcd(x,y));
  
  return 0;
}

int gcd(int x,int y){

  if(y==0){ return x;}

  
  if(x<y) {return gcd(x, y%x);}
  else {return gcd(y , x%y);}
  
}



Measured memory_bytes: 2756
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;
vector<int> fct;
int pw(int a, int b){
    if (b==1) return a;
    if (b%2==1) return (a*pw(a, b-1))%MOD;
    int kek = pw(a, b/2);
    return (kek*kek)%MOD;
}
int C(int n, int k){
    int A = fct[n], B = (fct[k] * fct[n-k])%MOD;
    return (A*pw(B, MOD-2))%MOD;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    fct.push_back(1);
    for (int i=0;i<2e5; i++){
        fct.push_back((fct.back() * (i+1))%MOD);
    }
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i < n; i++) cin >> v[i];
    int pref[n+1];
    pref[0] = 0;
    for (int i=0; i < n; i++) pref[i+1] = pref[i] + v[i];
    int S = 0, L = 1, R = n-2, len = 1, ans=0;
    while (true){
        if (len > (n-1)/2) break;
        S += pref[R+1] - pref[L];
        //cout << S << endl;
        S %= MOD;
        L++, R--;
        int kk = fct[n];
        int pp = C(len+2, 2);
        pp %= MOD;
       // cout << pw(2, MOD-2) << endl;
        int hh = (kk * pw(pp, MOD-2))%MOD;
        hh %= MOD;
        ans += hh*S;
        ans %= MOD;
        len++;
    }
    S = 0, L = 1, R = n-2, len = n-2;
    while (true){
        if (len <= (n-1)/2) break;
        S += pref[R+1] - pref[L];
        //cout << S << endl;
        S %= MOD;
        L++, R--;
        int kk = fct[n];
        int pp = C(len+2, 2);
        pp %= MOD;
        //cout << C(4, 2) << endl;
        int hh = (kk * pw(pp, MOD-2))%MOD;
        hh %= MOD;
        ans += hh*S;
        ans %= MOD;
        len--;
    }
    //cout << ans << endl;
    int kk = 0;
    for (int i=0; i < n-1; i++){
        kk += v[i];
        kk %= MOD;
        int k = kk;
        k *= fct[n];
        k %= MOD;
        int del = i+2;
        k *= pw(del, MOD-2);
        ans += k;
        ans %= MOD;
    }
    kk += v[n-1];
    ans += kk * fct[n];
    ans %= MOD;
    reverse(v.begin(), v.end());
    kk = 0;
    //cout << ans << endl;
    for (int i=0; i < n-1; i++){
        kk += v[i];
        kk %= MOD;
        int k=kk;
        k *= fct[n];
        k %= MOD;
        int del = i+2;
        k *= pw(del, MOD-2);
        ans += k;
        ans %= MOD;
    }
    cout << ans;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int a,b,h; cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
	char ch=getchar();int f=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {f=f*10+(ch^48);ch=getchar();}
	return f;
}
int a[100005],b[100005],n,m,last,x1,x2;
int cmp(int x,int y)
{
	return x>y;
}
int main()
{
	int n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		if(!last)
		{
			last=a[i];
		}
		else
		{
			if(last!=a[i])
			{
				last=a[i];
			}
			else
			{
				last=0;
				if(!x1)
				{
					x1=a[i];
				}
				else
				{
					long long ans=(long long)x1*(long long)a[i];
					printf("%lld",ans);
					return 0;
				}
			}
		}
	}
	printf("0");
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
template<typename T>
void print_to(std::ostream &os,const char *,const char *tail,const T &fst){
  os<<fst<<tail;
}
template<typename Fst,typename... Rst>
void print_to(std::ostream &os,const char *del,const char *tail,const Fst &fst,const Rst &... rst){
  os<<fst<<del;
  print_to(os,del,tail,rst...);
}
template<typename Iter>
void print_to_(std::ostream &os,const char *del,const char *tail,Iter bgn,Iter end){
  for(Iter it=bgn;it!=end;){
    os<<*it;
    if(++it!=end)os<<del;
    else os<<tail;
  }
}
template<typename Fst,typename... Rst>
void println(const Fst &fst,const Rst &... rst){
  print_to(std::cout,"\n","\n",fst,rst...);
}
template<typename Fst,typename... Rst>
void print(const Fst &fst,const Rst &... rst){
  print_to(std::cout," ","\n",fst,rst...);
}
template<typename Iter>
void println_(Iter bgn,Iter end){
  print_to_(std::cout," ","\n",bgn,end);
}
using namespace std;
//const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;
ll dp[301][301];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>dp[i][j];
    }
  }
  ll ans=0;
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(dp[i][j]>dp[i][k]+dp[k][j]){
          print(-1);
          return 0;
        }
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      bool flag=0;
      for(int k=0;k<n;k++){
        if(k==i || k==j)continue;
        if(dp[i][j]==dp[i][k]+dp[k][j])flag=1;
      }
      if(!flag)ans+=dp[i][j];
    }
  }
  print(ans);
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}






Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

int rec[100001];
int len[100001];

int main(){



    int con, ptr = 0, sum = 0;
    scanf("%d", &con);
    while(con--){
        scanf("%d", &rec[ptr]);
        //len[ptr] = 1;
        ptr++;
    }


    vector<int> v;
    v.push_back(rec[0]);

    for (int i = 1; i < ptr; ++i)
    {
        int n = rec[i];

        if (n > v.back())
            v.push_back(n);
        else{
            //printf("      %d\n", *lower_bound(v.begin(), v.end(), n));
            *lower_bound(v.begin(), v.end(), n) = n;
        }
        //for(int g = 0; g < v.size(); ++g)printf("%d ", v[g]);
        //printf("\n");

    }

    printf("%d\n" , v.size());



return 0;
}

Measured memory_bytes: 2060
import java.util.Scanner;


public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		System.out.println(gcd(x, y));
	}
	
	int gcd(int x, int y) {
		int rem;
		int largenum;
		if (x == 1 || y == 1) return 1;
		if (x > y) {
			rem = x % y;
			largenum = x;
		} else if (y > x) {
			rem = y % x;
			largenum = x;
		} else return x;
		for (int i = rem - 1; i > 0; i--)
			if (rem % i == 0 && largenum % i == 0) return i;
		return rem;
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 26176
n,a,b = map(int,input().split())
S = input()
passed = 0
f_passed = 0
for s in S:
  if s == "a":
    if passed < a + b:
      print("Yes")
      passed += 1
    else:
      print("No")
  elif s == "b":
    if passed < a + b and f_passed + 1 <= b:
      print("Yes")
      passed += 1
      f_passed += 1
    else:
      print("No")
  else:
    print("No")


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

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nq = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var s = Console.ReadLine();
            var aggregate = new long[s.Length + 1];
            for (var i = 1; i < s.Length; i++)
            {
                aggregate[i + 1] = aggregate[i] + (s[i] == 'C' && s[i - 1] == 'A' ? 1 : 0);
            }
            for (var i = 0; i < nq[1]; i++)
            {
                var lr = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
                var count = aggregate[lr[1]] - aggregate[lr[0]];
                Console.WriteLine(count);
            }
        }
    }
}


Measured memory_bytes: 19000
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

solve :: Int -> Int -> B.ByteString -> VU.Vector (Char, Char) -> Int
solve !n !q !s !tds =
  binsearchR (-1) (B.length s) - binsearchL (-1) (B.length s) + 1
 where
  remainLeft !n = simulate n >= 0
  remainRight !n = simulate n < B.length s

  simulate !n = VU.foldr'
    (\(!t, !d) !i -> if i < 0 || i >= B.length s
      then i
      else if t == B.index s i then (if d == 'L' then i - 1 else i + 1) else i
    )
    n
    (VU.reverse tds)

  -- search in (x,y]
  binsearchL !x !y
    | y - x == 1
    = y
    | otherwise
    = let !z = (x + y) `div` 2
      in  if remainLeft z then binsearchL x z else binsearchL z y

  -- search in [x,y)
  binsearchR !x !y
    | y - x == 1
    = x
    | otherwise
    = let !z = (x + y) `div` 2
      in  if remainRight z then binsearchR z y else binsearchR x z

main = do
  let readInt = fmap (second B.tail) . B.readInt

  (n, q) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  s   <- B.getLine
  tds <-
    VU.replicateM q
    $   ((\[x, y] -> (B.head x, B.head y)) . B.words)
    <$> B.getLine
  print $ solve n q s tds


Measured memory_bytes: 4604
N,K=map(int,input().split())
mod=10**9+7
GCD=[0 for _ in range(K+1)]
for i in range(1,K+1):
    GCD[i]=pow(K//i,N,mod)

ans=0
for i in range(K,0,-1):
    for j in range(2,K//i+1):
        GCD[i]-=GCD[i*j]
    ans+=(GCD[i]*i)%mod
print(ans%mod)

Measured memory_bytes: 82440
n = int(input())

for i in range(1, n+1):
    if i % 3 == 0:
        print(" " + str(i), end="")
    else:
        x = i
        while(x):
            if x % 10 == 3:
                print(" " + str(i), end="")
                break
            x //= 10

print()


Measured memory_bytes: 5872
#include<bits/stdc++.h>		
using namespace std;
typedef long long ll;
#define ff first
#define ss second
#define forl(n) for(int i=0;i<n;i++)
#define forp(i,n) for(int i=0;i<n;i++)
#define fort(i,m,n) for(int i=m;i<n;i++)
#define fora(arr,n) for(int i=0;i<n;i++) cin>>arr[i];
#define begud(k) cout<<"\t-->"<<#k<<" = "<<k<<"\n";
#define endl "\n";
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll res = power(a,b/2);
	if(b%2==0)
		return res*res;
	return a*res*res;
}
// bool cust(const pair<int,int> &a,const pair<int,int> &b)                
// {
//     return (a.first > b.first); 
// } 

//const int MX = 100005;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 	int n;
 	cin>>n;
 	int h[n];
 	fora(h,n)
 	ll dp[n];
 	dp[0] = 0;
 	dp[1] = abs(h[1]-h[0]);
 	fort(i,2,n)
 	{
 		dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]),dp[i-2] + abs(h[i]-h[i-2])); 		
 	}	
 	cout<<dp[n-1]<<endl;
    //cout<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main(void) {

	for (int n = 0; (cin >> n) && n != 0;) {
		int aPoint = 0, bPoint = 0;
		for (int i = 0; i < n; i++) {
			int aCardPoint = 0, bCardPoint = 0;
			cin >> aCardPoint >> bCardPoint;
			if (aCardPoint == bCardPoint) {
				aPoint += aCardPoint;
				bPoint += bCardPoint;
			} else if (aCardPoint > bCardPoint) {
				aPoint += aCardPoint + bCardPoint;
			} else if (aCardPoint < bCardPoint) {
				bPoint += aCardPoint + bCardPoint;
			}
		}
		cout << aPoint << " " << bPoint << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import sys

input = sys.stdin.readline


def is_prime_number(n):
    if n == 1:
        return False

    if n == 2:
        return True

    if n % 2 == 0:
        return False

    f = 3
    root_n = int(n ** 0.5) + 1
    while f <= root_n:
        if n % f == 0:
            return False
        f += 2

    return True


def main():
    n = int(input())
    ans = 0
    for _ in range(n):
        x = int(input())
        ans += is_prime_number(x)

    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5680
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;


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

bool is_kaibun(string S) {
    bool flag = true;
    REP(i, S.size()/2) {
        if(S[i] != S[S.size() - 1 - i]) {
            flag = false;
            break;
        }
    }
    return flag;
}

int main() {
    string S;
    cin >> S;
    string sp, sq;
    int n = S.size();
    REP(i, (n - 1)/2) {
        sp.push_back(S[i]);
    }
    FOR(i, (n + 3)/2 - 1, n) {
        sq.push_back(S[i]);
    }
    if(is_kaibun(S) and is_kaibun(sp) and is_kaibun(sq)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
x, y = map(int, input().split())
print("Yes" if (x in a and y in a) or (x in b and y in b) or (x in c and y in c) else "No")


Measured memory_bytes: 2940
import math

N = int(input())

def judge(n):
    if n <= 1:
        return False
    for i in range(2, int(math.sqrt(n))+1):
        if n % i == 0:
            n //= i
            while n != 1:
                if n % i != 0:
                    return False
                n //= i
            return True
    return True
ans = 0
i = 2
limit = int(math.sqrt(N))
while N != 1:
    
    if i > limit:
        if N > i:
            ans += 1
        break
    if N % i == 0 and judge(i): 
        N //= i
        ans += 1
        
    i += 1
    
print(ans)

Measured memory_bytes: 9224
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  ll n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for(int i = 0; i < n; i++){
    cin >> c[i];
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  int ans = 1001001001;
  for(int bit = 0; bit < (1 << n); bit++) {
    int sum = 0;
    vector<int> rikai(m, 0);
    for(int i = 0; i < n; i++) {
      if((bit >> i) & 1){
        sum += c[i];
        for(int j = 0; j < m; j++){
          rikai[j] += a[i][j];
        }
      }
    }
    bool ok = true;
    for(int i = 0; i < m; i++) {
      if(rikai[i] >= x){
        continue;
      }else{
        ok = false;
      }
    }
    if(ok == false){
      continue;
    }
    ans = min(ans, sum);
  }
  if(ans == 1001001001){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=0; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;

int main()
{
  int s ;
  cin >> s ;
  vector<int> vec(1000000) ;
  vec.at(0) = s ;
  vector<int> count(1000000,0) ;
  
  FOR(i,1,1000000){
    if(vec.at(i-1)%2==0){
      vec.at(i) = vec.at(i-1)/2 ;
    }
    else{
      vec.at(i) = vec.at(i-1)*3+1 ;
    }
  }
  
  for(int i=0;i<1000000-1;i++){
    for(int j=i+1; j<1000000;j++){
      if(vec.at(i)==vec.at(j)){
        count.at(i) = j+1 ;
        break ;
      }
    }
  }
  
  REP(i,1000000){
    if(count.at(i)==0){
      count.at(i) = 1000000 ;
    }
  }
  
  sort(ALL(count)) ;
  
  cout << count.at(0) <<endl ;

  return 0 ;
}




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

using namespace std;
int b[1000010];

long long ans = 0;

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i ++ ) 
		scanf("%d", &b[i]);
	b[0] = b[n] = 0x7f7f7f7f;
	for (int i = 1; i <= n; i ++ ) 
		ans += min(b[i - 1], b[i]);
	cout << ans << endl ;
	return 0;
}


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

bool searchEdge(const int a[][2], int n, int edge[]);
int calcArea(const int a[][2], const int edge[]);

int main(void)
{
	int a[20001][2];
	a[0][0] = 0;

	char ch;
	int cnt = 0;
	while (cin >> ch) {
		if (ch == '\\') a[cnt][1] = a[cnt][0] - 1;
		else if (ch == '/') a[cnt][1] = a[cnt][0] + 1;
		else if (ch == '_') a[cnt][1] = a[cnt][0];
		else break;
		a[cnt + 1][0] = a[cnt][1];
		cnt++;
	}

	int edge[2];
	edge[1] = -1;
	int area[10000];
	int k = 0;
	while (1) {
		if (searchEdge(a, cnt, edge)) {
			area[k] = calcArea(a, edge);
			k++;
		}
		if (edge[1] >= cnt - 1) break;
	}

	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += area[i];
	}

	cout << sum << endl;
	cout << k;
	for (int i = 0; i < k; i++) {
		cout << " " << area[i];
	}
	cout << endl;

	return 0;
}

bool searchEdge(const int a[][2], int n, int edge[])
{
	edge[0] = edge[1] = edge[1] + 1;
	int i;
	for (i = edge[0]; i < n; i++) {
		if (a[i][1] - a[i][0] == -1) {
			edge[0] = i;
			break;
		}
	}
	if (i >= n) {
		edge[1] = n - 1;
		return false;
	}

	int height = a[edge[0]][0];
	edge[1] = edge[0];
	int j;
	for (j = edge[1]; j < n; j++) {
		if (a[j][1] == height) {
			edge[1] = j;
			break;
		}
	}
	if (j >= n) return false;

	return true;
}

int calcArea(const int a[][2], const int edge[])
{
	int max = a[edge[0]][0];
	double area = 0;
	for (int i = edge[0]; i <= edge[1]; i++) {
		area += (-(a[i][0] - max));
		area += (-(a[i][1] - a[i][0]) / 2.0);
	}

	return (int)area;
}

Measured memory_bytes: 3248
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

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

int main(){
   int n,k,sum=0;
   cin>>n>>k;
   vector<int>a(1000000);
   for(int i=1;i<=n;i++){
       cin>>a[i];
       if(a[i]<=k/2){
           sum+=2*(a[i]);
       }
       else{
           sum+=2*(k-a[i]);
       }
   }
   cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 4096
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Algorithms.Intro as VA
main=print.solve.V.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve=V.foldl1' gcd.(V.zipWith(-)=<<V.tail).V.modify VA.sort.V.tail

Measured memory_bytes: 8852
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        mut a: u32,
        mut b: u32,
        mut c: u32,
        k: u32
    }
    let mut i = 0;
    loop {
        if a < b && b < c {
            println!("Yes");
            return;
        }
        if i == k {
            break;
        }
        if b >= c {
            c *= 2;
        } else if a >= b {
            b *= 2;
        }
        i += 1;
    }
    println!("No");
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int sum = a + b + c;
    if (sum >= 22)
        OP("bust");
    else
        OP("win");
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<int> p(N);
    rep(i, N) { cin >> p[i]; p[i]--; }
    vector<int> a(N), b(N);
    rep(i, N) { a[i] = N * (i + 1); }
    rep(i, N) { b[i] = (N - i) * N; }
    rep(i, N) {
        int idx = p[i];
        a[idx] += i;
        b[idx] += i;
    }
    rep(i, N) { if (i) cout << ' '; cout << a[i]; } cout << endl;
    rep(i, N) { if (i) cout << ' '; cout << b[i]; } cout << endl;
    return 0;
}


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

double solve(int x, int h){
    double h2 = sqrt((x/2.0)*(x/2.0) + h*h);
    return x*x + (x * h2 / 2) * 4;
}

int main(){
    int x, h;
    while(cin >> x >> h){
        if(x == 0 && h == 0) break;
        printf("%f\n", solve(x, h));
    }
    return 0;
}

Measured memory_bytes: 1184
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

ll dp[110][100010];

ll modadd(ll x, ll y) {
    return ((x + y) % mod + mod) % mod;
}

int main() {
    ll N, K;
    cin >> N >> K;
    ll a[N];
    REP(i, 0, N) {
        cin >> a[i];
    }
    REP(i, 0, 110) {
        fill(dp[i], dp[i] + 100010, 0);
    }
    dp[0][0] = 1;
    ll sum[100010];
    REP(i, 0, N) {
        fill(sum, sum + K + 1, 0);
        sum[0] = 0;
        REP(j, 0, K + 1) {
            if (j <= a[i]) {
                sum[j + 1] = (sum[j] + dp[i][j]) % mod;
            } else {
                sum[j + 1] = modadd(modadd(sum[j], dp[i][j]), - dp[i][j - a[i] - 1]);
            }
        }
        REP(j, 0, K + 1) {
            dp[i + 1][j] = sum[j + 1];
        }
    }
    // REP(i, 0, N + 1) {
    //     REP(j, 0, K + 1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll ans = dp[N][K];
    cout << ans << endl;
}


Measured memory_bytes: 86912
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int H,W,K;
  cin>>H>>W>>K;
  VS S(H);
  rep(i,H) cin>>S[i];
  int ans=0;
  rep(i,(1<<H)){
    rep(j,(1<<W)){
      VS T=S;
      rep(l,H) if(i&(1<<l)) rep(m,W) T[l][m]='.';
      rep(l,W) if(j&(1<<l)) rep(m,H) T[m][l]='.';
      int cnt=0;
      rep(l,H) rep(m,W) if(T[l][m]=='#') cnt++;
      if(cnt==K) ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3600
N=int(input())
A=list(map(int,input().split()))+[0]
A.insert(0,0)
cost=0
for i in range(N+1):
    cost+=abs(A[i+1]-A[i])
for i in range(1,N+1):
    print(cost-abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1]))

Measured memory_bytes: 14040
while 1:
    cnt = 0
    n,x = map(int,input().split())
    if n == x == 0:
        break
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    cnt += 1
    print(cnt)

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

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

  int ans = 0;
  for (int i = 1; i < N; i++) {
    set<char> st1;
    set<char> st2;
    int count = 0;
    for (int j = 0; j < i; j++) st1.insert(S[j]);
    for (int j = i; j < N; j++) st2.insert(S[j]);
    for (int j : st1)
      for (int k : st2) if (j == k) count++;
    ans = max(count, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import math

def cut(l, e):
    """全ての木片が長さl以下になるように切った時、
    eを処理するのに何回かかるか
    """
    return math.ceil(e / l) - 1


def judge(a, k, l):
    cuts = 0
    for e in a:
        cuts += cut(l, e)
    return cuts <= k


def submit():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    l = 0
    r = max(a)
    while abs(r - l) > 0.000001:
        m = (l + r) / 2
        if judge(a, k, m):
            r = m
        else:
            l = m

    print(math.ceil(m))


submit()


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

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

  vector<ll> A(N);
  vector<ll> B(N);

  rep0(i, N) {
    cin >> A[i];
    cin >> B[i];
  }

  sort(A.begin(), A.end(), greater<ll>());
  sort(B.begin(), B.end(), greater<ll>());

  ll ans = 0;
  ll temp = 0;
  rep0(i, N) {
    if (temp >= H) break;
    if (B[i] < A[0]) break;

    temp += B[i];
    ans++;
  }
  
  if (temp < H) {
    temp = H - temp;
    ans += (temp + A[0] - 1) / A[0];
  }

  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 1792
n=int(input())
xbox=[]
ybox=[]
for i in range(n):
    x,y = map(int,input().split())
    xbox.append(x)
    ybox.append(y)
xmax=max(xbox)
xmin = min(xbox)
ymax=max(ybox)
ymin=min(ybox)
box1=[]
box2=[]
box3=[]
box4=[]
for i in range(n):
    box1.append(xmax+ymax-xbox[i]-ybox[i])
    box2.append(-xmin + ymax + xbox[i] - ybox[i])
    box3.append(xmax - ymax - xbox[i] + ybox[i])
    box4.append(-xmax - ymax + xbox[i] + ybox[i])
print(max([max(box1)-min(box1),max(box2)-min(box2),max(box3)-min(box3),max(box4)-min(box4)]))


Measured memory_bytes: 150776
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<int> a(n);
  int cnt = 1, ans = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(a[i] == cnt){
      cnt++;
    }
    else ans++;
  }
  if(ans == n) cout << -1 << endl;
  else cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
    public static void main(String[] defargs) {
        Scanner scanner = new Scanner(System.in);
        int height = scanner.nextInt();
        int width = scanner.nextInt();
        int area = height * width;
        int syui = 2 *(height + width);
        System.out.println(area + " " + syui);
        scanner.close();
    }
}



Measured memory_bytes: 26144
class Dice(object):
    def __init__(self, nums):
        from collections import deque
        self.ns = deque([nums[4], nums[0], nums[1]])
        self.we = deque([nums[3], nums[0], nums[2]])
        self.bk = deque([nums[5]])

    def __str__(self):
        return str({"ns": self.ns, "we": self.we, "bk": self.bk})

    def operation(self, o):
        if o == "N":
            self.n()
        elif o == "S":
            self.s()
        elif o == "W":
            self.w()
        elif o == "E":
            self.e()
        else:
            raise BaseException("invalid", o)

    def n(self):
        self.ns.append(self.bk.popleft())
        self.bk.append(self.ns.popleft())
        self.we[1] = self.ns[1]

    def s(self):
        self.ns.appendleft(self.bk.pop())
        self.bk.appendleft(self.ns.pop())
        self.we[1] = self.ns[1]

    def w(self):
        self.we.append(self.bk.popleft())
        self.bk.append(self.we.popleft())
        self.ns[1] = self.we[1]

    def e(self):
        self.we.appendleft(self.bk.pop())
        self.bk.appendleft(self.we.pop())
        self.ns[1] = self.we[1]

    def get_top(self):
        return self.ns[1]


def resolve():
    nums = [int(i) for i in input().split()]
    ops = input()
    dc = Dice(nums)
    for o in ops:
        dc.operation(o)
    print(dc.get_top())


resolve()



Measured memory_bytes: 6020
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_087_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 X      PIC 9(5).
    01 A      PIC 9(4).
    01 B      PIC 9(4).
    01 D      PIC 9(3).
    01 R      PIC 9(3).
    01 ZS     PIC Z(3)9.
    01 ans    PIC X(3).
    01 DUMMY  PIC X(1).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT X.
    ACCEPT A.
    ACCEPT B.

    SUBTRACT A FROM X.
    DIVIDE B INTO X GIVING D REMAINDER R.

    MOVE R TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


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

const int MX = 200005;
int a[MX];
bool taken[MX];

int main()
{
	int n;
	ignore = scanf("%d", &n);
	
	int ans = 0;
	
	for (int i = 0; i < n; i++) {
		ignore = scanf("%d", a + i);
	}
	
	sort(a, a + n);
	
	for (int s = (1<<30); s >= 2; s /= 2) {
		int i = 0, j = n - 1;
		while (i < j) {
			if (taken[i]) i++;
			else if (taken[j]) j--;
			else if (a[i] + a[j] > s) {
				j--;
			}
			else if (a[i] + a[j] < s) {
				i++;
			}
			else {
				ans++;
				taken[i] = taken[j] = true;
			}
		}
	}
	
	printf("%d", ans);
}


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

int n,x,y,hd[2010],cnt,dis[2010],q[2010],l,r,f[2010],fa[2010],ans,siz[2010],col[2010],g[2010],c[2];
struct node{int to,next;}e[4010];
char s[2010];

void addedge(int x,int y)
{
	e[++cnt]=(node){y,hd[x]},hd[x]=cnt;
	e[++cnt]=(node){x,hd[y]},hd[y]=cnt;
}

void dfs(int x)
{
	int ma=0,maa,sum=0;
	siz[x]=(s[x]=='1');
	for (int i=hd[x]; i; i=e[i].next)
		if (e[i].to!=fa[x]) 
		{
			fa[e[i].to]=x,dfs(e[i].to),sum+=f[e[i].to]+siz[e[i].to],siz[x]+=siz[e[i].to];
			if (f[e[i].to]+siz[e[i].to]>ma) ma=f[e[i].to]+siz[e[i].to],maa=e[i].to;
		}
	if (!ma) f[x]=g[x]=0; else
	{
		f[x]=sum;
		if (sum-ma>=g[maa]+siz[maa]) g[x]=0; else g[x]=g[maa]+siz[maa]-(sum-ma);
	}
}

void getcol(int x)
{
	for (int i=hd[x]; i; i=e[i].next)
		if (e[i].to!=fa[x]) fa[e[i].to]=x,col[e[i].to]=col[x]^1,getcol(e[i].to);
}

int main()
{
	scanf("%d",&n),ans=1000000000,scanf("%s",s+1);
	for (int i=1; i<n; i++) scanf("%d%d",&x,&y),addedge(x,y);
	col[1]=0,getcol(1),c[0]=c[1]=0;
	for (int i=1; i<=n; i++) if (s[i]=='1') c[col[i]]++;
	if ((c[0]&1)&&(c[1]&1)) return puts("-1"),0;
	for (int i=1; i<=n; i++) if (!(c[col[i]^1]&1)) 
	{
		memset(fa,0,sizeof(fa)),dfs(i);
		if (g[i]==0) ans=min(ans,f[i]/2);
	}
	if (ans==1000000000) puts("-1"); else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << # x << "; "<< x << endl


int main() {
	int N, K, p;
	cin >> N >> K;
	int total;
	total = 0;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> p;
		vec.at(i) = p;
	}
	sort(vec.begin(), vec.end());
	for (int j = 0; j < K; j++) {
		total += vec.at(j);
	}
	cout << total << endl;
}

Measured memory_bytes: 3616
import sys
readline = sys.stdin.readline


def main():
    abk = list(map(int, input().split()))
    k = abk[2]

    for i in range(k):
        i2 = i % 2
        if abk[i2] % 2 == 1:
            abk[i2] -= 1
        v = abk[i2] // 2
        abk[i2], abk[1 - i2] = abk[i2] - v, abk[1 - i2] + v
    print(abk[0], abk[1])


if __name__ == '__main__':
    main()


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

#define st first
#define nd second
#define INF 0x3f3f3f3f

const int N = 1024;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int n, m; 
vector<int> g1[N]; 
int pair_g1[N], pair_g2[N], dist[N]; 

bool bfs() { 
    queue<int> q; 
    for (int u = 1; u <= n; u++) { 
        dist[u] = INF; 
        if (pair_g1[u] == 0) { 
            dist[u] = 0; 
            q.push(u); 
        } 
    } 
    dist[0] = INF; 
    while (!q.empty()) { 
        int u = q.front(); q.pop(); 
        for (int i = 0; i < g1[u].size(); i++) { 
            int v = g1[u][i]; 
            if (dist[pair_g2[v]] == INF) { 
                dist[pair_g2[v]] = dist[u] + 1; 
                q.push(pair_g2[v]); 
            } 
        } 
    } 
    return dist[0] != INF; 
}

bool dfs(int u) { 
    if (u == 0) 
        return 1; 
    for (int i = 0; i < g1[u].size(); i++) { 
        int v = g1[u][i]; 
        if (dist[pair_g2[v]] == dist[u] + 1 && dfs(pair_g2[v])) { 
            pair_g1[u] = v; 
            pair_g2[v] = u; 
            return 1; 
        } 
    } 
    dist[u] = INF; 
    return 0;
}

int hk() { 
    memset(pair_g1, 0, sizeof(pair_g1)); 
    memset(pair_g2, 0, sizeof(pair_g2)); 
    int matching = 0; 
    while (bfs()) 
        for (int u = 1; u <= n; u++) 
            if (pair_g1[u] == 0 && dfs(u)) 
                matching++; 
    return matching; 
}

int main() {
    cin >> n;
    m = n;
    vii a(n+1), b(n+1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i].st >> a[i].nd;
    for (int i = 1; i <= n; ++i)
        cin >> b[i].st >> b[i].nd;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (a[i].st < b[j].st and a[i].nd < b[j].nd) {
                g1[i].push_back(j+n);
            }
        }
    }
    printf("%d\n", hk());
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

ll size(ll x) {
    int cou = 0;
    while(x > 0) {
        x /= 10;
        cou++;
    }

    return cou;
}

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

    int ans = size(n);

    for(ll i = 1LL ;i * i <= n; i++) {
        if(n%i != 0) continue;

        ll b = n / i;

        int now = max(size(i), size(b));

        ans = min(ans, now);
    }

    cout << ans << endl;

    return 0;
}

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

int main(){

	int i=0,n;
	int a[10000];


	while(cin >> n){
		a[i]=n;
		i++;
	}
	sort(a, a + i, greater<int>());
	for(i=0;i<3;i++)
		cout << a[i] << endl;

    return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void f(ll n)
{
  if (n == 0)
    return;
  n--;
  f(n / 26);
  putchar('a' + (n % 26));
}

int main()
{
  ll n;
  scanf("%lld", &n);
  f(n);
}

Measured memory_bytes: 3748