akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD 1000000007


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

int main(){
    int N, K;
    cin >> N >> K;
    for(int i=1;i<=K;i++){
        if(N-K+1<i){
            cout << 0 << endl;
        }else{
            ll ans = 1;
            rep(j, K-1){
                ans *= j+1;
                ans %= MOD;
            }
            rep(j, K-i){
                ans *= mpow(j+1, MOD-2);
                ans %= MOD;
            }
            
            rep(j, i-1){
                ans *= mpow(j+1, MOD-2);
                ans %= MOD;
            }

            rep(j, N-K+1){
                ans *= j+1;
                ans %= MOD;
            }
            rep(j, i){
                ans *= mpow(j+1, MOD-2);
                ans %= MOD;
            }
            
            rep(j, N-K+1-i){
                ans *= mpow(j+1, MOD-2);
                ans %= MOD;
            }            
            printf("%d\n", ans);
        }
    }
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    B = S.count("#")
    W = S.count(".")

    # 左からi文字目までの白の数
    n_white = []
    if S[0] == ".":
        n_white.append(1)
    else:
        n_white.append(0)
    for i in range(1, N):
        if S[i] == ".":
            n_white.append(n_white[-1] + 1)
        else:
            n_white.append(n_white[-1])

    # ....##### の並びにする.境目に関して全探索
    ans = min(B, W)
    for i in range(N):
        # 白に変える数
        cnt = i + 1 - n_white[i]

        # 黒に変える数
        cnt += n_white[-1] - n_white[i]

        if cnt < ans:
            ans = cnt

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

static const int MAX_SIZE = 1 << 18;

typedef long long Int;

Int segMax[2 * MAX_SIZE - 1], segAdd[2 * MAX_SIZE - 1];

void add(int a, int b, Int x, int k = 0, int l = 0, int r = MAX_SIZE)
{
	if (r <= a || b <= l) return;
	
	if (a <= l && r <= b) {
		segAdd[k] += x;
		return;
	}
	
	add(a, b, x, k * 2 + 1, l, (l + r) / 2);
	add(a, b, x, k * 2 + 2, (l + r) / 2, r);

	segMax[k] = max(segMax[k * 2 + 1] + segAdd[k * 2 + 1], segMax[k * 2 + 2] + segAdd[k * 2 + 2]);
}

Int getMax(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE)
{
	if (r <= a || b <= l) return (LLONG_MIN);
	
	if (a <= l && r <= b) return (segMax[k] + segAdd[k]);
	
	Int left = getMax(a, b, k * 2 + 1, l, (l + r) / 2);
	Int right = getMax(a, b, k * 2 + 2, (l + r) / 2, r);
	
	return (max(left, right) + segAdd[k]);
}

Int black[200001], white[200001];
int main()
{
  int n, m;
  
  scanf("%d %d", &n, &m);
  
  vector< pair<pair<int, int>, int> > v;
  
  long long tot = 0;
  for (int i = 0; i < m; i++) {
    int l, r, a;
    scanf("%d %d %d", &l, &r, &a);
    tot += a;
    v.push_back(make_pair(make_pair(r, l), a));
  }
  sort(v.begin(), v.end());
  int p = 0;
  long long black_max, white_max;
  black_max = white_max = 0;
  for (int i = 1; i <= n; i++) {
    black[i] = max(black_max, white_max);
    black_max = max(black_max, black[i]);
    while (p < m && v[p].first.first == i) {
      add(0, v[p].first.second, -v[p].second);
      p++;
    }
    white[i] = getMax(0, i);
    white_max = max(white_max, white[i]);
    add(i, i + 1, black[i]);
  }
  
  printf("%lld\n", tot + max(black_max, white_max));
  return 0;
}


Measured memory_bytes: 13552
#include<stdio.h>

double inv(int n){
  return 1/(double)n;
}

int main(void){
  int n,a[100];
  double ans=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",a+i);
    ans+=inv(a[i]);
  }
  printf("%f\n",1/ans);
  return 0;
}
  

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int type   = sc.nextInt(); //ドーナツ種類
    int powder = sc.nextInt(); //粉
    int mini   = 0;            //一番小さいドーナツ
    int count = 0;
    
    for(int i = 0 ; i < type ; i++){
      int temp = sc.nextInt();
      powder -= temp;
      if(mini == 0){mini=temp;}
      else if(mini > temp){mini=temp;}
    }
    
    while(mini <= powder){
      powder -= mini;
      count++;
    }
    System.out.println(count + type);
  }
}


Measured memory_bytes: 22612
#include <stdio.h>
#define MAX_N (50)
#define rep(i, n) for(int i = 0; i < n; i++)

int main(void) {
  int N;
  scanf("%d", &N);

  int P[MAX_N];
  rep(i, N) {
    scanf("%d", &P[i]);
  }
  int count = 0;
  rep(i, N) {
    if(P[i] != (i+1)) {
      count++;
    }
  }

  if(count <= 2) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128
from copy import deepcopy
n,W = map(int,input().split())
dp = [0] * (W+1)
for i in range(n):
  w,v = map(int,input().split())
  pdp = deepcopy(dp)
  for j in range(w,W+1):
    dp[j] = max(pdp[j-w]+v,dp[j])
print(max(dp))

Measured memory_bytes: 124024
n=int(input())
#a,b=map(int,input().split())
vl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

dic1={};dic2={}

for i in range(n):
    v=vl[i]
    if i%2==0:
        dic1[v]=dic1.get(v,0)+1
    else:
        dic2[v]=dic2.get(v,0)+1

dic1=sorted(dic1.items(),reverse=True,key=lambda x:x[1])
dic2=sorted(dic2.items(),reverse=True,key=lambda x:x[1])

#dic1の最頻値
mx1_val,mx1_count=dic1[0]
if len(dic1)==1:
    mx1_count2=0
else:
    mx1_count2=dic1[1][1]

mx2_val,mx2_count=dic2[0]
if len(dic2)==1:
    mx2_count2=0
else:
    mx2_count2=dic2[1][1]

ans=0
ansl=[]
total=n//2
if n==2:
    if vl[0]==vl[1]:
        ans=1
    else:
        ans=0
    print(ans)
else:
    if mx1_val != mx2_val:
        ans=n-(mx1_count+mx2_count)
    else:
        ans=min(n-mx1_count-mx2_count2,
        n-mx1_count2-mx2_count)
    print(ans)

Measured memory_bytes: 17636
#include <stdio.h>
#define BIG ((long long)(1e9+7))

long long C[2001][2001];

int main(void) {
    int N, K;
    scanf("%d %d", &N, &K);
    for (int i = 0; i <= 2000; i++) {
        C[i][0] = 1;
        C[i][i] = 1;
    }

    for (int i = 2; i <= 2000; i++) {
        for (int j = 1; j <= i; j++) {
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % BIG;
        }
    }

    long long res;

    for (int i = 1; i <= K; i++) {
        if (i <= N-K+1) {
            res = (C[N-K+1][i] * C[K-1][i-1]) % BIG;
            printf("%lld\n", res);
        } else {
            printf("0\n");
        }
    }

    return 0;
}

Measured memory_bytes: 29952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
    int a,b,m;
    cin >> a >> b >> m;
    vector<int> A,B;
    int tmp;
    int ma=100000;
    int mb=100000;
    rep(_,a){
        cin >> tmp;
        A.push_back(tmp);
        ma=min(ma,tmp);
    }
    rep(_,b){
        cin >> tmp;
        B.push_back(tmp);
        mb=min(mb,tmp);
    }
    int ans = ma + mb;
    int x,y,c;
    rep(_,m){
        cin >> x >> y >> c;
        ans = min(ans, A[x-1]+B[y-1]-c);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;



int main(){

    int n;
    cin >> n;

    int tmp_min = INT_MAX;
    int ans = 0;

    rep(i,n){
        int tmp;
        cin >> tmp;

        tmp_min = min(tmp_min, tmp);

        if(tmp == tmp_min) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int A[200000];
int sudeni_tsuita[200000];

int main(void) {

    int N;
    unsigned long int K;
    unsigned long int iter;

    scanf("%d %lu",&N,&K);

    for(int i = 0; i < N; i++){
        scanf("%d",&A[i]);
        sudeni_tsuita[i] = 0;
    }

    int next_index = 1;
    int loop_count = 0;
    for(iter = 0;iter < K;iter++){
        //printf("twon %d\n",next_index);
        if(sudeni_tsuita[next_index - 1] == 3){
            //printf("loop %d,\n",loop_count);
            int nokori_teleport = (K - iter)%loop_count;
            //printf("nokori_teleport: %d\n",nokori_teleport);
            //printf("visit: %d\n",next_index);
            //next_index = A[next_index-1];
            for(int i = 0;i < nokori_teleport;i++){
                //printf("visit: %d\n",next_index);
                next_index = A[next_index-1];
            }
            break;
        }

        sudeni_tsuita[next_index - 1] += 1;
        //printf("visit: %d\n",next_index);
        next_index = A[next_index-1];
        if(sudeni_tsuita[next_index - 1] == 2){
            loop_count ++;
        }
    }

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

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

int arr[3];
int brr[3];

int main(){
	ios::sync_with_stdio(false);
	for(int i = 0;i < 3;++i){
		cin >> arr[i];
	}
	brr[0] = arr[0]-arr[1];
	brr[1] = arr[0]-arr[2];
	brr[2] = arr[1]-arr[2];
	
	for(int i = 0;i < 3;++i){
		if(brr[i] < 0){
			brr[i] = -brr[i];
		}
	}
	
	sort(brr,brr+3);
	int ans = 0;
	
	for(int i = 0;i <2;++i){
		ans += brr[i];
	}
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

int main() {
	ll A,B,C,K;
    cin >> A >> B >> C >> K;
    ll ret = 0;
    ret += min(A,K);
    if(A < K) {
        K -= A;
        if(B < K) {
            ret -= K - B;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 3632
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::marker::*;
use proconio::*;

#[fastout]
fn main() {
    input! {
        x: i32,
    }
    let ans = (x / 500) * 1000 + ((x % 500) / 5) * 5;
    println!("{}", ans);
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define Int int64_t
#define pb push_back
using namespace std;
const int MAXN=500005;
vector<int> A(MAXN);
Int N,M,X,Y,B,K,Z,T;
int main()
{
   cin>>N;
   vector<string> v(N);
   map<string,int> mp;
   for(int i=0;i<N;++i){
       cin>>v[i];
       mp[v[i]]++;
   }
   cout<<"AC"<<" x "<<mp["AC"]<<"\n";
   cout<<"WA"<<" x "<<mp["WA"]<<"\n";
   cout<<"TLE"<<" x "<<mp["TLE"]<<"\n";
   cout<<"RE"<<" x "<<mp["RE"]<<"\n";
}

Measured memory_bytes: 8276
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void){
	int a,b,c,d,e,f,w=0,s=0,i,j,k,l;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	a *= 100;	b *= 100;
	
	for(i=0;a*i<=f;i++){
		for(j=0;a*i+b*j<=f;j++){
			int x = a*i + b*j;
			for(k=0;x+c*k<=f;k++){
				for(l=0;x+c*k+d*l<=f;l++){
					int y = c*k + d*l;
					if(x*e>=100*y && x+y<=f){
						if(s*(x+y) <= w*y){
							w = x+y;
							s = y;
						}
					}
				}
			}
		}
	}
	
	printf("%d %d",w,s);
	return 0;
}

Measured memory_bytes: 128
//Bismillahir Rahmanir Rahim 
#include<bits/stdc++.h>

using namespace std;

#define ll long long 
#define gcd(a,b) __gcd(a,b)
#define endl '\n'
const int N=2e5+10;
const int inf=1e9;
const int mod=1e9+7;

int  main(int argc, char const *argv[])
{
	/*#ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);*/

	int a, b, c;
	cin >> a >> b >> c;

	cout << c << " " << a << " " << b << endl;
	
	return 0;
}

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

int main(void){
  int N, K;
  std::cin >> N >> K;
  std::vector<int> h;

  for(int i=0;i<N;i++){
    int tmp;
    std::cin>>tmp;
    h.push_back(tmp);
  }
  std::vector<int> dp(N, 1e9);
  dp[0]=0;
  for(int i=0;i<N;i++){
    int from_num=std::max(0, i-K);
    for(int j=from_num;j<i;j++){
      dp[i]=std::min(dp[i], std::abs(h[i]-h[j])+dp[j]);
    }
  }
  std::cout << dp[N-1];
  return 0;
}


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

int main() {
    
    string s1, s2;

    cin >> s1 >> s2;
    int ans = 0;
    int n = s1.length();
    for (int i = 0; i < n; i++) {
        if (s1[i] != s2[i])
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3856
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    deque<int> dque;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (i % 2 == 0) dque.push_back(x);
        else dque.push_front(x);
    }

    if (n % 2 != 0) reverse(dque.begin(), dque.end());

    for (int i = 0; i < n; ++i) {
        if (i != 0) cout << " ";
        cout << dque[i];
    }
    cout << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

//a,b x
int main(){
	ll N; cin>>N;
  ll ans=1;
    vector<ll> A((N+1)/2);
    rep(i,N){
		ll tmp; cin>>tmp;
		A[tmp/2]++;
	}
	if(N%2==1){
		if(A[0]!=1){
			cout<<0;
			return 0;
		}
		rep1(i,(N+1)/2-1){
			if(A[i]!=2){
				cout<<0;
				return 0;
			}
		}
		rep(i,N/2) ans=(ans*2)%MOD;
		cout<<ans;
	}else{
		rep(i,N/2){
			if(A[i]!=2){
				cout<<0;
				return 0;
			}
		}
		rep(i,N/2) ans=(ans*2)%MOD;
		cout<<ans;
	}
}

Measured memory_bytes: 640
import sys; from collections import deque; readline = sys.stdin.readline

H, W, A, B = map(int, readline().split())

#for s in range(W):
#    a = (H - 2*B) * s + W*B - H*A
#    b = W - 2*A
#    if a % b == 0 and a // b >= 0:
#        t = a // b
#        break
#
#if s == W:
#    print('No')
#else:
#    count = []

for y in range(B):
    print(''.join(map(str, [1]*A + [0]*(W-A))))

for y in range(B, H):
    print(''.join(map(str, [0]*A + [1]*(W-A))))

Measured memory_bytes: 42588
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().solve();
		return;
	}

	private void solve() {
		// 入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		List<Integer> lengthList = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			lengthList.add(sc.nextInt());
		}
		sc.close();

		// 計算
		Collections.sort(lengthList, Collections.reverseOrder());
		int sumLength = 0;
		for (int i = 0; i < K; i++) {
			sumLength += lengthList.get(i);
		}

		// 出力
		System.out.println(sumLength);

		return;
	}
}


Measured memory_bytes: 22868
#include <stdio.h>

int main(){
	int n, total = 0, a[100005], b[100005];
	scanf("%d", &n);
	
	for(int i = 0; i < n; ++i)
		scanf("%d %d", &a[i], &b[i]);

	for(int j = 0; j < n; ++j){
		total = total + (b[j] - a[j]) + 1;
	}

	printf("%d\n", total);
	
	return 0;
}




Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
        int sec =sc.nextInt();
        int h =sec/3600;
        int m = (sec%3600)/60;
        int s = sec % 60;
        System.out.println(h+":"+m+":"+s);
	}
}


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

int main() {
    int n, c;
    cin >> n >> c;
    vector<vector<pair<int, int>>> st(c);
    for (int i = 0; i < n; i++) {
        int si, ti, ci;
        cin >> si >> ti >> ci;
        st[ci-1].emplace_back(si, ti);
    }

    vector<int> imos(1e5+10);
    for (auto& e : st) {
        sort(begin(e), end(e));
        for (int l = 0, r = 0; r < e.size(); r++) {
            if (r + 1 < e.size() && e[r].second == e[r+1].first) continue;
            imos[e[l].first-1]++, imos[e[r].second]--;
            l = r + 1;
        }
    }

    partial_sum(begin(imos), end(imos), begin(imos));
    cout << *max_element(begin(imos), end(imos)) << endl;
}


Measured memory_bytes: 1920
import java.util.*;
import static java.lang.Math.abs;
import static java.lang.Math.min;

public class Main{
public static void main(String... argv){
Scanner sc=new Scanner(System.in);
String n=sc.next();
for(char c:n.toCharArray()){
if(c=='9'){
System.out.println("Yes");
return ;
}
}
System.out.println("No");
}
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

bool dp[100005];
int a[101];

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (a[j] <= i && !dp[i-a[j]]) dp[i] = true;
		}
	}
	printf("%s\n", dp[k] ? "First" : "Second");
}


Measured memory_bytes: 384
import sys
from collections import defaultdict

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

def rec(u):
    if dist[u] != INF:
        return dist[u]
    if u == 0:
        return 0
    res = abs(u)*d
    if u >= 5:
        x = u % 5
        v = (u-x) // 5
        res = min(res, rec(v) + c+d*x)
        if u % 5 != 0:
            x = 5 - u % 5
            v = (u+x) // 5
            res = min(res, rec(v) + c+d*x)
    if u >= 3:
        x = u % 3
        v = (u-x) // 3
        res = min(res, rec(v) + b+d*x)
        if u % 3 != 0:
            x = 3 - u % 3
            v = (u+x) // 3
            res = min(res, rec(v) + b+d*x)
    if u >= 2:
        x = u % 2
        v = (u-x) // 2
        res = min(res, rec(v) + a+d*x)
        if u % 2 != 0:
            x = 2 - u % 2
            v = (u+x) // 2
            res = min(res, rec(v) + a+d*x)
    dist[u] = res
    return res

for _ in range(INT()):
    N, a, b, c, d = MAP()

    dist = defaultdict(lambda: INF)
    ans = rec(N)
    print(ans)


Measured memory_bytes: 85868
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int pow(int a, int i){
	if(i==0) return 1;
	return a*pow(a,i-1);
}

int main(void){
	int n; cin >> n;
	vi md(1,1);
	for(int i=1;;i++){
		int a = pow(6,i);
		if(a>100000) break;
		md.push_back(a);
	}
	for(int i=1;;i++){
		int a = pow(9,i);
		if(a>100000) break;
		md.push_back(a);
	}
	SORT(md);
	vi dp(n+1,INF);
	dp[0] = 0;
	rep(i,n){
		rep(j,md.size()){
			int b = md[j];
			if(i+b>n) break;
			dp[i+b] = min(dp[i+b],dp[i]+1);
		}
	}
	cout << dp[n] << endl;
}


Measured memory_bytes: 640
N=parse(Int,readline())
V=map(x->parse(Int,x),split(readline()))
A=zeros(Int,10^5)
B=zeros(Int,10^5)
for i=1:N
	if i%2==1
		A[V[i]]+=1
	else
		B[V[i]]+=1
	end
end
AA=[(A[i],i) for i=1:10^5]
BB=[(B[i],i) for i=1:10^5]
sort!(AA)
reverse!(AA)
sort!(BB)
reverse!(BB)
ans=0
if AA[1][2]!=BB[1][2]
	ans=AA[1][1]+BB[1][1]
else
	ans=max(AA[1][1]+BB[2][1],AA[2][1]+BB[1][1])
end
println(N-ans)


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

int main() {
    int num;
    cin >> num;
    vector<int> kagamiMochis(num);
    for(int i = 0; i < num; i++)  cin >> kagamiMochis.at(i);

    int count = 0;
    for(int i = 0; i < num; i++) {
        for(int j = i + 1; j < num; j++) {
            if(kagamiMochis.at(i) == kagamiMochis.at(j)) {
                count++;
                break;
            }
        }
    }  
    int ans = kagamiMochis.size() - count;

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
//#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


//namespace mp = boost::multiprecision;

//using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	vector<int>len(N);
	rep(i, N) {
		int scan=scanf("%d", &len[i]);
	}
	int ans = 1e6;
	int i = 0;
	while (i < pow(4, N)) {
		deque<int>base4;
		vector<int>abc(3);
		int tmpi = i;
		while (tmpi > 0) {
			base4.push_front(tmpi % 4);
			tmpi /= 4;
		}
		while (base4.size() < N) {
			base4.push_front(0);
		}
		int count = 0;
		rep(j, N) {
			rep(k, 3) {
				if (base4[j] == k+1) {
					if (abc[k] != 0) {
						count++;
					}
					abc[k]+=len[j];
				}
			}
		}
		bool flag = true;
		rep(k, 3) {
			if (!abc[k]) {
				flag = false;
			}
		}
		if (flag) {
			int a = abs(A - abc[0]);
			int b = abs(B - abc[1]);
			int c = abs(C - abc[2]);
			ans = min(ans, a + b + c + count * 10);
		}
		i++;
	}
	cout << ans << endl;


}


Measured memory_bytes: 384
# include<stdio.h>

char S[500000];
int W[500000];
int E[500000];

int main(void){
	int N, i, j, min = 1000000000;
	scanf("%d",&N);
	scanf("%s",S);
	W[0]=0;
	E[0]=0;
	for(i=0; i<N;i++){
			if(S[i]=='W'){
				W[i+1]=W[i]+1;
				E[i+1]=E[i];
				}
			else{
				E[i+1]=E[i]+1;
				W[i+1]=W[i];
			}
			
	}
	
	for(j=1;j<=N;j++){
		if(min>W[j-1]+E[N]-E[j]){
		min=W[j-1]+E[N]-E[j];
		}
	}
	printf("%d\n",min);
	return 0;
}
	



Measured memory_bytes: 3584
#include <stdio.h>
#include <string.h>

int main()
{ 
    
    char x[255];
    scanf("%s",x);
    int a= strlen(x);  
    for(int i=0;i<a;i++){
        if(x[i]==',')
        printf(" ",x[i]);
        else{
        printf("%c",x[i]);
		}
    }   
    return 0;
}



Measured memory_bytes: 3156
def main():
    A,V = map(int,input().split())
    B,W = map(int,input().split())
    T = int(input())
    B -= A
    B = abs(B)
    A=0
    if V*T>=B+W*T:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>=13) cout<<b<<endl;else
	if(6<=a&&a<=12) cout<<b/2<<endl;
	else cout<<0<<endl;
	rt0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define N 1000005
#define rep(i,j,k) for (ll i=j;i<=k;++i)
#define per(i,j,k) for (ll i=j;i>=k;--i)
using namespace std;
inline ll read(){
	char ch=getchar(); ll x=0,f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}
ll a[N],b[N],n,ans,num;
int main(){
	n=read();
	rep(i,1,n){
		a[i]=read();
		b[i]=read();
	}
	per(i,n,1){
		if ((a[i]+ans)%b[i]==0) continue;
		ll tmp=b[i]-(a[i]+ans)%b[i];
		ans+=tmp;
	}
	printf("%lld",ans);
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  set<string> se;
  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    se.insert(s);
  }
  cout << (se.size() == 3 ? "Three" : "Four") << endl;

  return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if(a <= 8 && b <= 8) cout << "Yay!\n";
	else cout << ":(\n";
	return 0;
}


Measured memory_bytes: 256
def is_prime(num):
  i = 5
  while (i * i <= num):
      if num % i == 0 or num % (i+2) ==0:
          return False
      i+=6
  return True if num > 1 and num <=3 else False if num % 2 == 0 or num % 3 == 0 or num <=1 else True

k = int(input())
if is_prime(k):
  print(k)
else:
  while(not is_prime(k)):
    k +=1
  print(k)

Measured memory_bytes: 2568
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    string s,t;
    cin>>s>>t;
    string ans="No";
    
    for(int i=0;i<s.size();i++){
        string pre=s;
        for(int j=0;j<s.size();j++){
            if(j==0) s.at(0)=pre.at(pre.size()-1);
            else s.at(j)=pre.at(j-1);
        }
        if(s==t){
            ans="Yes";
            break;
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    vector<pair<int, int> > v(w+h);
    for(int i=0; i<w; ++i){
        cin >> v[i].first;
        v[i].second = 0;
    }
    for(int i=w; i<w+h; ++i){
        cin >> v[i].first;
        v[i].second = 1;
    }
    sort(v.begin(), v.end());

    long long ans = 0;
    int w2 = w;
    int h2 = h;
    for(int i=0; i<w+h; ++i){
        if(v[i].second == 0){
            ans += v[i].first * (h2 + 1LL);
            -- w2;
        }
        else{
            ans += v[i].first * (w2 + 1LL);
            -- h2;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	int n,a[10000],s,d,max,z,x[10000],i,j;
	while(1){
	scanf("%d",&n);
	if(n==0)	break;
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[i],&s,&d);
		  x[i]=s+d;
	}
	max=0;
	for(i=0;i<n;i++){
		if(max<x[i])	{
				max=x[i];
				z=a[i];
		}
	}	
	printf("%d %d\n",z,max);
   }
  return 0;
}

Measured memory_bytes: 1104
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
	int i,j,n,cnt=0,*num,flag;
	scanf("%d",&n);
	num = (int *)malloc(n * sizeof(int));
	for(i=0;i<n;i++){
		scanf("%d",&num[i]);
	}
	for(i=0;i<n;i++){
		flag = 0;
		if(num[i] == 2){
			cnt++;
			//printf("num[i] = 2のとき cnt->%d\n",cnt);
			continue;
		}
		if(num[i] < 2 || num[i]%2 == 0){
			continue;
		}
		j=3;
		while(j<=sqrt(num[i])){
		if(num[i]%j == 0){
			flag = 1;
			break;
			}
			j+=2;
	}
	if(flag == 0)cnt++;
	//printf("cnt = %d\n",cnt);
}
	free(num);
	printf("%d\n",cnt);
	return 0;
 }


Measured memory_bytes: 2128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    c = collections.defaultdict(int)
    r = 0
    for i,t in enumerate(a):
        r += c[t-i]
        c[-t - i] += 1

    return r


print(main())





Measured memory_bytes: 62836
h, w = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)
s = []
s << [-1] * (w + 4)
s << [-1] * (w + 4)
h.times do
  s << [-1] * 2 + gets.chomp.chars.map { _1 == '#' ? -1 : 0 } + [-1] * 2
end
s << [-1] * (w + 4)
s << [-1] * (w + 4)
u = [[-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2],
    [-1, -2], [-1, -1], [-1, 1], [-1, 2],
    [0, -2], [0, 2],
    [1, -2], [1, -1], [1, 1], [1, 2],
    [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]
  ]
que = []
wqu = []
que << [c[0] + 1, c[1] + 1]
s[c[0] + 1][c[1] + 1] = 1
while que.size > 0 || wqu.size > 0
  while que.size > 0
    y, x = que.shift
    cnt = s[y][x]
    if s[y + 1][x] == 0
      s[y + 1][x] = cnt
      que << [y + 1, x]
    elsif s[y + 1][x] == -1
      wqu << [y, x]
    end
    if s[y - 1][x] == 0
      s[y - 1][x] = cnt
      que << [y - 1, x]
    elsif s[y - 1][x] == -1
      wqu << [y, x]
    end
    if s[y][x + 1] == 0
      s[y][x + 1] = cnt
      que << [y, x + 1]
    elsif s[y][x + 1] == -1
      wqu << [y, x]
    end
    if s[y][x - 1] == 0
      s[y][x - 1] = cnt
      que << [y, x - 1]
    elsif s[y][x - 1] == -1
      wqu << [y, x]
    end
  end
  while wqu.size > 0
    y, x = wqu.shift
    cnt = s[y][x]
    u.each do |j, i|
      if s[y + j][x + i] == 0
        s[y + j][x + i] = cnt + 1
        que << [y + j, x + i]
      end
    end
  end
end
puts s[d[0] + 1][d[1] + 1] - 1

Measured memory_bytes: 25532
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string S;
    cin >> S;
    int len = S.size();
    S = S + "dream";
    int count = 0;
    bool possible = true;
    while (true){
        if (count == len){
            break;
        }
        else if (S.substr(count,10) == "dreamdream" || S.substr(count, 12) == "dreamdreamer" || S.substr(count, 10) == "dreamerase" || S.substr(count, 11) == "dreameraser") count += 5;
        else if (S.substr(count,12) == "dreamerdream" || S.substr(count, 14) == "dreamerdreamer" || S.substr(count, 12) == "dreamererase" || S.substr(count, 13) == "dreamereraser") count += 7;
        else if (S.substr(count, 10) == "erasedream" || S.substr(count, 12) == "erasedreamer" || S.substr(count, 10) == "eraseerase" || S.substr(count, 11) == "eraseeraser") count += 5;
        else if (S.substr(count, 11) == "eraserdream" || S.substr(count, 13) == "eraserdreamer" || S.substr(count, 11) == "erasererase" || S.substr(count, 12) == "erasereraser") count += 6;
        else{
            possible = false;
            break;
        }
    }
    if (possible) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 512
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") 
///#pragma GCC target("avx2")
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>
#include <numeric>

using namespace std;
#define open_streams ifstream fin("olympiad.in");ofstream fout("olympiad.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define UNIQ(a) a.resize(unique(all(a)) - a.begin())
#define eps 1e-6
//const double PI = M_PI;
const int INF = INT_MAX;
const ll limit = 1LL * 4e18;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
//---------------------------------------------------------------------------
const int mod = 1e9 + 7;
const int maxn = 1e6 + 100;






signed main() {
	speed;
	string s;
	cin >> s;
	deque<char> d;
	for (auto &i : s) {
		d.pb(i);
	}
	int q;
	cin >> q;
	int ok = 1;
	while (q--) {
		int t, f;
		cin >> t;
		if (t == 1) {
			ok = 1 - ok;
			continue;
		}
		cin >> f;
		char c;
		cin >> c;
		if (f == 1) {
			if (ok) {
				d.push_front(c);
			}
			else {
				d.push_back(c);
			}
		}
		else {
			if (!ok) {
				d.push_front(c);
			}
			else {
				d.push_back(c);
			}
		}
	}
	s.clear();
	if (ok) {
		while (!d.empty()) {
			s.pb(d.front());
			d.pop_front();
		}
	}
	else {
		while (!d.empty()) {
			s.pb(d.back());
			d.pop_back();
		}
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 1168
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 550;
int A[MAX_N][MAX_N] = {};
int H, W, h, w;

const int LARGE = 5000000;

bool solve() {
    if (H % h == 0 && W % w == 0) {
        return false;
    }

    if (H % h == 0) {
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if (j % w == 1) {
                    A[i][j] = LARGE;
                } else if (j % w == 0) {
                    A[i][j] = - LARGE - 1;
                }
            }
        }
    } else if (W % w == 0) {
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if (i % h == 1) {
                    A[i][j] = LARGE;
                } else if (i % h == 0) {
                    A[i][j] = - LARGE - 1;
                }
            }
        }
    } else {
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if (i % h == 1 && j % w == 1) {
                    A[i][j] = LARGE;
                } else if (i % h == 0 && j % w == 0) {
                    A[i][j] = LARGE - 1;
                } else if (i % h == 1 && j % w == 0) {
                    A[i][j] = - LARGE;
                } else if (i % h == 0 && j % w == 1) {
                    A[i][j] = - LARGE;
                }
            }
        }
    }
    return true;

}

int main(int argc, char **argv) {
    std::cin >> H >> W >> h >> w;

    if (solve()) {
        std::cout << "Yes" << std::endl;
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                std::cout << A[i][j] << " ";
            }
            std::cout << std::endl;
        }
    } else {
        std::cout << "No" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 3328
#!/usr/bin/env python3
import sys


def solve(N, K, A):
    s = set()
    for a in A:
        for x in a:
            s.add(x)
    print(N - len(s))
    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    K = int(next(tokens))
    A = [[] for _ in range(K)]
    for i in range(K):
        d = int(next(tokens))
        for j in range(d):
            A[i].append(int(next(tokens)))
    solve(N, K, A)

if __name__ == '__main__':
    main()


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

main(){
  int i,j,n;
  double ans;
  cin >> n;
  vector<int> v(n);
  for(i=0;i<n;i++) cin >> v[i];
  sort(v.begin(),v.end());
  
  ans=v[0];
  for(i=1;i<n;i++) ans = (ans+v[i])/2;
  
  printf("%.10lf",ans);
  
  
  
}
      

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

int main() {
  int D, N;
  cin >> D >> N;
  int answer;
  if (D == 0) {
    if (N != 100) {
      answer = N;
    }
    else {
      answer = 101;
    }
  }
  else if (D == 1) {
    if (N != 100) {
      answer = 100*N;
    }
    else {
      answer = 10100;
    }
  }
  else {
    if (N != 100) {
      answer = 10000*N;
    }
    else {
      answer = 1010000;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
import math

n, m = map(int, input().split())


def get_divisors(n):
    ret = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


# m の約数を全列挙
divs = get_divisors(m)
divs.sort(reverse=True)

for d in divs:
    if d * n <= m:
        print(d)
        break


Measured memory_bytes: 3060
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();

    ArrayList<Integer> a = new ArrayList<Integer>(n);
    ArrayList<Integer> b = new ArrayList<Integer>(n);
    ArrayList<Integer> c = new ArrayList<Integer>(n-1);

    
    for (int i=0 ; i<n ; i++){
      a.add(sc.nextInt());
    }
    for (int i=0 ; i<n ; i++){
      b.add(sc.nextInt());
    }
    for (int i=0 ; i<n-1 ; i++){
      c.add(sc.nextInt());
    }

    //処理
    int p = 0;
    
    for (int i=0 ; i<n ; i++){
      p += (int)b.get(a.get(i)-1);

      if(i>0){
        if((int)a.get(i-1) == (int)a.get(i) -1){
          p += (int)c.get((int)a.get(i-1)-1);
        }
      }
    }
    System.out.println(p);
  }
}

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

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

	vector<int> I((N+1)*(N+1));
	int count=0;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<=i;j++){
			I.at(i*N+j)=H.at(i)-H.at(j);
			if(I.at(i*N+j)<0){
				count++;
				break;
			}
		}
		
	}
	
	cout << N-count << endl;

}

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

int main() {
  int n;
  cin>>n;
  int p[n];
  int idx[n+1];
  for (int i=0; i<n; i++) {
    cin>>p[i];
    idx[p[i]] = i;
  }
  long long ans = 0;
  set<int> used_idx;
  used_idx.insert(idx[n]);
  used_idx.insert(n);
  used_idx.insert(-1);
  for (int i=n-1; i>=1; i--) {
    auto rit = used_idx.upper_bound(idx[i]);
    int r1 = *rit;
    int r2;
    if (r1 != n) {
      ++rit;
      r2 = *rit;
    } else {
      r2 = n;
    }
    auto lit = used_idx.upper_bound(idx[i]);
    --lit;
    int l1 = *lit;
    int l2;
    if (l1 != -1) {
      --lit;
      l2 = *lit;
    } else {
      l2 = -1;
    }
    int cnt = (r2 - r1) * (idx[i] - l1) + (r1 - idx[i]) * (l1 - l2);
    ans += (long long)i * cnt;
    used_idx.insert(idx[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int K;
    cin >> K;
    queue<ll> que;
    vector<ll> vec;
    for(int i = 1; i < 10; i++)
        que.push(i);
    while(1) {
        ll num = que.front();
        que.pop();
        vec.pb(num);
        if(num == 3234566667)
            break;
        ll last = num % 10;
        if(last == 0) {
            que.push(num * 10);
            que.push(num * 10 + 1);
        } else if(last == 9) {
            que.push(num * 10 + 8);
            que.push(num * 10 + 9);
        } else {
            que.push(num * 10 + last - 1);
            que.push(num * 10 + last);
            que.push(num * 10 + last + 1);
        }
    }
    cout << vec[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 2548
#include <stdio.h>
#include <string.h>
int main() {
	char a[5] = "", b[5] = "";
	int i, hit, blow;
	while (scanf(" %c %c %c %c", &a[0], &a[1], &a[2], &a[3]) != EOF) {
		scanf(" %c %c %c %c", &b[0], &b[1], &b[2], &b[3]);
		if (!strcmp(a, b)) {
			puts("4 0");
			continue;
		}
		hit = blow = 0;
		for (i = 0; i < 4; i++) {
			hit += a[i] == b[i];
			blow += strchr(a, b[i]) != NULL;
		}
		printf("%d %d\n", hit, blow - hit);
	}
	return 0;
}

Measured memory_bytes: 560
#include <stdio.h>
#define SIZE 2001

char resultTable[SIZE];
int n,q,elems[20];

void calc(int sum,int index){
	if(index == n){
		if(sum >= 1 && sum <= 2000){
			resultTable[sum] = 'y';
		}
	}else{
		calc(sum+elems[index],index+1);
		calc(sum,index+1);
	}
}

int main(){

	for(int i = 0;i < SIZE; i++) resultTable[i] = 'n';

	scanf("%d",&n);
	for(int i = 0; i < n; i++) scanf("%d",&elems[i]);
	calc(0,0);

	scanf("%d",&q);

	int tmp;
	for(int i = 0; i < q; i++){
		scanf("%d",&tmp);
		if(resultTable[tmp] == 'y'){
			printf("yes\n");
		}else{
			printf("no\n");
		}
	}
}

Measured memory_bytes: 1008
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,q,k,a[100005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    cout<<((n>=30) ? "Yes" : "No");
}



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

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

    int N, M;
    cin >> N >> M;
    if(N < 10 && M < 10) cout << N * M;
    else cout << -1;
    return 0;
}

Measured memory_bytes: 256
numdict = dict()
while True:
	try:
		num = input()
		if num not in numdict:
			numdict[num] = 0
		else:
			numdict[num] += 1
	except EOFError:
		break
most = max(numdict.values())
mostlist = list()
for key in numdict:
	if most == numdict[key]:
		mostlist.append(int(key))
mostlist.sort()
for item in mostlist:
	print(item)

Measured memory_bytes: 7616
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N,K;cin >> N >> K;
    LL ans = 0;
    vector<LL> rui(N+2);
    rep(i,N+1){
        rui[i+1] = rui[i] + i+1;
    }

    for(int i = K;i <= N+1;i++){
        LL mini = rui[i];
        LL maxi = rui[N+1] - rui[N+1-i];
        LL tmp = maxi - mini + 1;
        ans += tmp;
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4784
from bisect import bisect_right
a, b, q = map(int, input().split())
INF = 10 ** 18
s = [-INF]
for i in range(a):
    s.append(input())
s.append(INF)
s = [int(m) for m in s]#int型に直す
t = [-INF]
for i in range(b):
    t.append(input())
t.append(INF)
t = [int(m) for m in t]#int型に直す
x = []
for i in range(q):
    x.append(input())
x = [int(m) for m in x]#int型に直す

for i in range(q):
    b, d = bisect_right(s, x[i]), bisect_right(t, x[i])
    a, c = b - 1, d - 1
    res = INF
    for j in [a, b]:
        for k in [c, d]:
            res = min(res, abs(x[i] - s[j]) + abs(s[j] - t[k]), abs(x[i] - t[k]) + abs(t[k] - s[j]))
    print(res)

Measured memory_bytes: 22068
# coding: utf-8
N, K = map(int, input().split())
lst = sorted([int(input()) for _ in range(N)], reverse=True)

ans = 10000000000
for i in range(N-K+1):
    l = lst[i]-lst[i+K-1]
    if l < ans:
        ans = l
print(ans)



Measured memory_bytes: 8276
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var cnt = 0;
            var result = "No";
            for (var i = 0; i < n; i++)
            {
                var pair = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
                if (pair[0] == pair[1]) cnt++;
                else
                {
                    cnt = 0;
                    continue;
                };

                if (cnt > 2) result = "Yes";
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 28276
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


a, b, c = LI()
print(min([i + j for i, j in list(combinations([a, b, c], 2))]))




Measured memory_bytes: 39152
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	ll x;
	cin >> x;
	
	ll ans = 0;
	ll coin = 0;
	coin = x / 500;
	ans += 1000 * coin;
	x -= 500 * coin;
	coin = x / 5;
	ans += 5 * coin;
	x -= 5 * coin;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
def solve():
    n = int(input())
    a = map(int, input().split())
    even = [e for e in a if e % 2 == 0]
    for i in even:
        if i % 3 != 0 and i % 5 != 0:
            print('DENIED')
            exit()
    print('APPROVED')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940