akhauriyash/Code-Regression huggingface dataset:
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion


ll appear_count[200001] = {0};
ll arr[200000];
int main() {
  cin >> N;
  rep(i, N){
    int num;
    cin >> num;
    appear_count[num]++;
    arr[i] = num;
  }
  ll count_sum = 0;
  rep(i, N){
    if(appear_count[i+1] == 0) continue;
    count_sum += appear_count[i+1]*(appear_count[i+1]-1)/2;
  }

  rep(i, N){
    if(appear_count[arr[i]] == 1){
      cout << count_sum << endl;
      continue;
    }
    ll temp = count_sum;
    temp -= appear_count[arr[i]]*(appear_count[arr[i]]-1)/2;
    temp += (appear_count[arr[i]]-1)*(appear_count[arr[i]]-2)/2;
    cout << temp << endl;
  }
} 



Measured memory_bytes: 4736
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <stack>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
#include <array>
#include<random>
using namespace std;

int main(){
	uint32_t N;
	cin >> N;
	vector<uint32_t> fp(N + 1);
	for (size_t i = 0; i < N + 1; i++)fp[i] = 0;
	uint32_t maxLen = 0;
	for (size_t i = 0; i < N; i++)
	{
		uint32_t p;
		cin >> p;
		fp[p] = fp[p - 1] + 1;
		maxLen = max(maxLen, fp[p]);
	}
	cout << (N - maxLen);
 	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string s;
    int k;
    cin>>s>>k;
    rep(i,s.size()){
        if(i!=s.size()-1&&s[i]=='a') continue;
        else if(i!=s.size()-1&&26-(s[i]-'a')<=k){
            k-=26-(s[i]-'a');
            s[i]='a';
        }
        else if(i==s.size()-1){
            k%=26;
            s[i]='a'+(s[i]-'a'+k)%26;
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    ll x;
    cin >> x;
    ll tmp = x/11;
    //cout << tmp << endl;
    ll tmp2 = x-tmp*11;
    //cout << tmp2 << endl;
    /*
    tmp2が0の時2*tmp
    tmp2が1~6の時2*tmp*1
    tmp2が7~10の時2*tmp+2
    */
    ll tmp3;
    if(tmp2==0) tmp3=0;
    else if(1<=tmp2 && tmp2 <=6) tmp3 = 1;
    else tmp3=2;
    //cout << tmp3 << endl;

    cout << 2*tmp+tmp3 << endl; 
}

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


Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int a,b,c,d,e,f,k,l,m,n,x,y,z;
	int ans;
	String[] S;

	Main(){
		// 出力
		System.out.println((int)(Math.pow(sc.nextInt(),2)*3));
	}

	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 22356
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <forward_list>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() { return numeric_limits<long long>::min(); }
ll mal() { return numeric_limits<long long>::max(); }

#define R3(i, a, b) for (long long i = (a); i < (b); ++i)
#define R2(i, b) for (long long i = 0; i < (b); ++i)
#define R1(b) for (long long i = 0; i < (b); ++i)
#define RR(i, a, b) for (long long i = a; i > b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

// build: ctrl + f9

// run: shift + f10
// sanitize: shift + f11
// debug: shift + f9

void A() {
    ll N;
    cin >> N;

    R1(3) {
        ll nd = N-(floor(N/10)*10);
        if(nd == 7) {
            cout << "Yes" << endl;
            return;
        }
        N/=10;
    }

    cout << "No" << endl;
}

void B() {
    ll N;
    cin >> N;

    ll sum = 0;
    R1(N+1) {
        if((i%3 == 0) || (i%5 == 0))
            continue;
        sum+=(i);
    }

    cout << sum << endl;
}

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

}

void C() {
    ll K;

    cin >> K;

    int tuple[3];
    ll totGcd = 0;

    for(int i = 1; i <=K; ++i) {
        tuple[0] = i;
        for(int j = 1; j <=K; ++j) {
            tuple[1] = j;
            for(int k = 1; k <=K; ++k) {
                tuple[2] = k;
                ll subgcd = gcd(tuple[1], tuple[2]);
                totGcd += gcd(tuple[0], subgcd);
            }
        }
    }

    cout << totGcd << endl;
}

int main()
{
    C();
}

Measured memory_bytes: 3608
// 4/29
// Greedyな過去問攻略

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

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

    sort(A, A + N);
    int max_dist = 0;

    for (int i = 0; i < N; i++) {
        int dist;

        if (i != N - 1) {
            dist = A[i + 1] - A[i];
        } else {
            dist = A[0] + K - A[i];
        }
        
        max_dist = max(max_dist, dist);
    }

    cout << K - max_dist << endl;
}

Measured memory_bytes: 1024
N = int(input())
S = input()
from itertools import permutations
r = []
g = []
b = []
for i, s in enumerate(S):
    if s == 'R':
        r.append(i)
    elif s == 'G':
        g.append(i)
    else:
        b.append(i)

ans = len(r)*len(g)*len(b)

for A, B, C in permutations([r,g,b]):
    for i in A:
        for j in B:
            k = 2 * j - i
            if k < N and i < j < k and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]: 
                ans -= 1
print(ans)


Measured memory_bytes: 68616
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;

class Solve{
private:
  int n,w,d;
  vector<P> info;
public:
  Solve(int _n,int _w,int _d):n(_n),w(_w),d(_d){info.pb(P(w,d));}
  ~Solve(){info.clear();}

  int getN(){
    return n;
  }

  int getW(){
    return w;
  }

  int getD(){
    return d;
  }

  void printAll(){
    cout << "n = " << n << ",w = " << w << ",d = " << d << endl;
    cout << "info---" << endl;
    rep(i,info.size()){
      cout << i << " - th : " << info[i].F << "," << info[i].S << endl;
    }
    cout << "end---" << endl;
  }

  void getAns(){
    sortVector(info);
  }


  void cutInfo(int p,int s){
    P store = info[p];
    eraseMethod(p);    
    int Mod = store.F*2 + store.S*2;
    s = s%Mod;

    P A,B;
    if(0< s && s < store.F){
    
      A = P(s,store.S);         // left
      B = P(store.F-s,store.S); // right

    }
    else if(store.F < s && s < store.F+store.S ){

      A = P(store.F,s-store.F);           // top
      B = P(store.F,(store.F+store.S)-s); // bottom

    }
    else if(store.F+store.S < s && s < store.F*2+store.S){

      A = P(s-(store.F+store.S),store.S);
      B = P((store.F*2+store.S)-s,store.S);

    }
    else if(store.F*2+store.S < s && s < store.F*2+store.S*2){

      A = P(store.F,s-(store.F*2+store.S));
      B = P(store.F,(store.F*2+store.S*2)-s);

    }
    else assert(false);

    if(A.F*A.S < B.F*B.S) info.pb(A),info.pb(B);
    else info.pb(B),info.pb(A);

  }

  void eraseMethod(int p){
    vector<P>::iterator it = info.begin();
    for(int cnt = 0;cnt != p;it++,cnt++)
      if(cnt > info.size())assert(false);
    info.erase(it);
  }

  void sortVector(vector<P> vec){
    vector<int> area;
    rep(i,vec.size())area.pb(vec[i].F*vec[i].S);
    sort(all(area));
    printVector(area);
  }

  void printVector(vector<int> vec){
    rep(i,vec.size()){
      cout << vec[i];
      if(i != vec.size()-1)cout << ' ';
    }
    cout << endl;
  }

  int getInfoSize(){
    return info.size();
  }


};



int main(){

  while(true){
    int _n,_w,_d;
    cin >> _n >> _w >> _d;
    //cerr << _n << " " << _w << " " << _d << endl;
    if(_n+_w+_d == 0)break;
    
    Solve ans(_n,_w,_d);

    rep(i,ans.getN())
      {
	int p,s;
	cin >> p >> s;	
	//cerr << p << " " << s << endl;
	ans.cutInfo(p-1,s);
      }
    //cerr << endl;

    ans.getAns();
 
  }

return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int N, M;
short t[5002][5002];

int area(int x){
  return x * (x + 1) / 2;
}

int main(){
  while(scanf("%d%d", &N, &M) != EOF){
    memset(t, 0, sizeof(t));

    for(int i = 0; i < M; i++){
      int a, b, x;
      scanf("%d%d%d", &a, &b, &x);
      a--;
      b--;
      t[a][b] = max((int)t[a][b], x + 1);
    }

    int ans = 0;

    for(int i = 0; i < N; i++){
      for(int j = 0; j <= i; j++){
        int l = 0, r = 0;

        if(1 <= i){
          if(j < i) r = t[i - 1][j];
          if(0 <= j - 1) l = t[i - 1][j - 1];
        }

        int top = max((int)t[i][j], max(l, r) - 1);

        if(top > 0) ans++;
        t[i][j] = top;

        //printf("%3d",t[i][j]);
      }
      //cout<<endl;
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 48000
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    p = 1
    LIMIT =  10 ** 18
    for a in A:
        p *= a
        if p > LIMIT:
            print(-1)
            return
    
    print(p)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21788
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <cstdlib>

using namespace std ;
using ll = long long;

const ll INF = numeric_limits<ll>::max()/2;
const ll SIZE = 100010;

int main(){

    int N;
    ll h[100010];
    ll dp[100010];
    cin >> N;

    for(int i=0; i<N; ++i){
        cin >> h[i];
    }
    for(int i=0; i<100010; ++i){
        dp[i] = INF;
    }

    dp[0] = 0;

    for(int i=0; i<N; ++i){
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll n, a, b, ans = 0;
  scanf("%lld%lld%lld", &n, &a, &b);
  printf("%lld\n", n / (a + b) * a + MIN(a, (n - n / (a + b) * (a + b))));
}


Measured memory_bytes: 128
#include<stdio.h>
long long int dp[1001][1001];
int main(void)
{
	long long int min,a[1001],b[1001],n,m,i,j;
	min=9223372036854775806;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++) scanf("%lld",&a[i]);
	for(j=0;j<m;j++) scanf("%lld",&b[j]);
	for(i=0;i<=m;i++){
		for(j=0;j<=n;j++) dp[i][j]=min;
	}
	dp[0][0]=0;
	for(i=0;i<m;i++){
		for(j=0;j<=n;j++){
			if(dp[i][j]!=min){
				if(dp[i][j]<dp[i+1][j]) dp[i+1][j]=dp[i][j];
				if(dp[i+1][j+1]>dp[i][j]+a[j]*b[i]){
					dp[i+1][j+1]=dp[i][j]+a[j]*b[i];
				}
			}
		}
	}
/*	for(i=0;i<=m;i++){
		for(j=0;j<=n;j++)printf("%d ",dp[i][j]);
		printf("\n");
	}*/	
	for(i=0;i<=m;i++){
		if(min>dp[i][n]) min=dp[i][n];
	}
	printf("%lld\n",min);
	return 0;
}

Measured memory_bytes: 10572
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

bool flag[303][303][303]={};
int x[4]={},a,n;
double dp[303][303][303]={};
double f(int x,int y,int z){
	if(x==0&&y==0&&z==0)return dp[x][y][z]=0;
	if(flag[x][y][z])return dp[x][y][z];
	flag[x][y][z]=true;
	double fans=1;
	if(x>0)fans+=f(x-1,y,z)*x/n;
	if(y>0)fans+=f(x+1,y-1,z)*y/n;
	if(z>0)fans+=f(x,y+1,z-1)*z/n;
	fans=(double)(fans*n/(x+y+z));
	return dp[x][y][z]=fans;
}

int main(){
	cin>>n;
	rep(i,0,n)cin>>a,x[a]++;
	double ans=f(x[1],x[2],x[3]);
	print(setprecision(20)<<ans);
}



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

int main(){
	long long int n,k;
	cin >> n >> k;
	if(n%k==0){
		cout << 0 << endl;
	}else{
		if(n>k){
			n=n%k;
		}
		cout << min(n,k-n) << endl;
	}
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

r = []

if A%10 != 0:
    r.append(10 - A%10)
    A += 10 - A%10
if B%10 != 0:
    r.append(10 - B%10)
    B += 10 - B%10
if C%10 != 0:
    r.append(10 - C%10)
    C += 10 - C%10
if D%10 != 0:
    r.append(10 - D%10)
    D += 10 - D%10
if E%10 != 0:
    r.append(10 - E%10)
    E += 10 - E % 10

if r:
    print(A+B+C+D+E-max(r))
else:
    print(A+B+C+D+E)


Measured memory_bytes: 9216
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int N=s.nextInt();
		long p=1;
		
		for(int i=1;i<=N;i++){
			p=(int)(p*i%(Math.pow(10,9)+7));
			if(p==0){
				System.out.println(i);
				break;
			}
		}
	
		System.out.println(p);

	}

}


Measured memory_bytes: 21844
# ABC105 B

def main():
    n = int(input())
    res = 'No'

    for i in range(100 // 4):
        for j in range((100-i) // 7):
            if 4 * i + 7 * j == n:
                res = 'Yes'
                break
    
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	int A,B,C,X;
	cin >>A>>B>>C>>X;
	int cnt;
	cnt = 0;
	int i,j,k;
	for(i=0;i<=A;i++){
		for(j=0;j<=B;j++){
			for(k=0;k<=C;k++){
				if(500*i+100*j+50*k==X){
					cnt++;
				}
				
			}
		}
	}
	cout<<cnt<<endl;


	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
    long long A,B,c,x,y,ans,maxv;
    cin >> A >> B >> c >> x >> y;

    ans = A*x+B*y;

    if(x > y && ans > 2*c*y+A*x-A*y){
        ans = 2*c*y+A*x-A*y;
    }
    if(y > x && ans > 2*c*x+B*y-B*x){
        ans = 2*c*x+B*y-B*x;
    }
    maxv = max(x,y);
    if(ans > 2*c*maxv){
        ans = 2*c*maxv;
    }
    cout << ans << endl;
}

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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    cout << vec.at(i);
    if (i < vec.size() - 1)
    {
      cout << ", ";
    }
  }
  cout << "]...size: " << vec.size() << endl;
}

int main()
{
  vector<pair<int, int>> vec;

  while (true)
  {
    int h, w;
    cin >> h >> w;
    if (h == 0 && w == 0)
    {
      break;
    }

    vec.push_back(make_pair(h, w));
  }

  for (auto &&p : vec)
  {
    int h = p.first;
    int w = p.second;

    rep(i, h)
    {
      rep(j, w)
      {
        printf("#");
      }
      printf("\n");
    }

    printf("\n");
  }
}



Measured memory_bytes: 3040
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;


int main() {
	
	string s[5];
	cin >> s[0] >> s[1] >> s[2];
	cout << (char)(s[0][0] + 'A' - 'a') << (char)(s[1][0] + 'A' - 'a') << (char)(s[2][0] + 'A' - 'a');
}


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

int main(void)
{
	string s;
	int n, k;
	int i, j;
	int zero[100000],zerocnt=0;
	int one[100000], onecnt = 0;
	int renzokunum;
	char renzoku;
	cin >> n >> k;
	cin >> s;
	
	if (s[0] == '0') {
		one[0] = 0;
		onecnt++;
	}

	renzokunum = 1;
	renzoku = s[0];
	for (i = 1; i < n; i++) {
		if (s[i] == renzoku) {
			renzokunum++;
		}
		else {
			if (s[i] == '1') {
				zero[zerocnt++] = renzokunum;
				renzokunum = 1;
				renzoku = '1';
			}
			else {
				one[onecnt++] = renzokunum;
				renzokunum = 1;
				renzoku = '0';
			}
		}
	}

	if (s[n-1] == '0') {
		zero[zerocnt++] = renzokunum;
		renzokunum = 1;
	}
	else {
		one[onecnt++] = renzokunum;
		renzokunum = 1;
	}

	if (zerocnt == 0) {
		cout << n << endl;
		return 0;
	}
	else if (zerocnt == onecnt && zerocnt == 1) {
		cout << n << endl;
		return 0;
	}

	int tmp = one[0];
	for (i = 1; i <= min(k, onecnt-1); i++) {
		tmp += one[i] + zero[i - 1];
	}
//	cout << tmp << endl;
	int ans = tmp;
	for (i = k + 1; i < onecnt; i++) {
		tmp += one[i] + zero[i - 1] - one[i - k - 1] - zero[i - k - 1];
		ans = max(ans, tmp);
	}

	if (onecnt == zerocnt) {
			tmp += zero[onecnt - 1] - one[i - k - 1] - zero[i - k - 1];
			ans = max(ans, tmp);
	}
	
	/*
	cout << "zero :";
	for (i = 0; i < zerocnt; i++) {
		cout << " " << zero[i];
	}
	cout << endl << "one  :";
	for (i = 0; i < onecnt; i++) {
		cout << " " << one[i];
	}
	cout << endl;
	*/

	cout << ans << endl;
	return 0;
}


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

dp=[0 for i in range(max(a)+1)]
for i in range(n):
    dp[a[i]]+=1
 
ans=0

if len(dp)==1:
    ans=dp[0]
else:
    for i in range(1,len(dp)-1):
        ans=max(ans,dp[i-1]+dp[i]+dp[i+1])
 
print(ans)

Measured memory_bytes: 20780
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;
const int maxN=1e9+5;

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

	int n;
	cin>>n;
	vector<int> dp(n,maxN);
	int h[n];
	
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
	}
	
	dp[0]=0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < i+3; j++)
		{
			if(j<n)
			{
				dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
			}
		}
	}
	
	cout<<dp[n-1]<<endl;
	
	return 0;
}



Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define ll long long
#define N 10010
#define mr make_pair
using namespace std;
int n,g[2],s[N][2],w[N];
string dp[N];
char ch[N];
string que(int l,int r){string no="";for (int i=0;i<2*n;i++)if (w[i]>=l&&w[i]<=r)no+=ch[i];return no;}
int main(){
	cin>>n;
	for (int i=0;i<2*n;i++){
		ch[i]=getchar();while (ch[i]!='a'&&ch[i]!='b')ch[i]=getchar();
		g[ch[i]-'a']++;s[g[ch[i]-'a']][ch[i]-'a']=i;w[i]=g[ch[i]-'a'];
	}
	for (int i=n;i>=1;i--){
		dp[i]=dp[i+1];
		if (s[i][0]<s[i][1]){
			int x=i+1;
			while (x<=n&&s[x][0]<s[i][1])x++;
			dp[i]=max(dp[i],"ab"+dp[x]);
		}else{
			int x=i+1,y=s[i][0];
			while (x<=n&&s[x][1]<y)y=s[x][0],x++;
			dp[i]=max(dp[i],que(i,x-1)+dp[x]);
		}
	}
	cout<<dp[1]<<endl;
	return 0;
}

Measured memory_bytes: 14720
while True:
    n = int(input())
    if n == 0:
        break
    Num_lis = []
    cou = 0
    for i in range(n):
        Num_lis.append(int(input()))
    S_lis = sorted(Num_lis)
    while Num_lis != S_lis:
        
        for j in range(n - 1):
            if Num_lis[j] > Num_lis[j + 1]:
                Num_lis[j],Num_lis[j + 1] = Num_lis[j + 1],Num_lis[j]
                cou += 1
    print(cou)

Measured memory_bytes: 7684
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); ++i)
using ll = long long ;
using namespace std;
const int INF = 1001001001;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
    int h,w ;
    cin >> h >> w ;
    int si,sj ;
    cin >> si >> sj ;
    --si ; --sj ;
    int ti,tj ;
    cin >> ti >> tj ;
    --ti ; --tj ;
    vector<string> s(h) ;
    rep(i,h) cin >> s[i] ;
    vector<vector<int>> dist(h,vector<int>(w,INF)) ;
    deque<pair<int,int>> q ;
    dist[si][sj] = 0 ;
    q.emplace_back(si,sj) ;
    while(!q.empty()){
        int i = q.front().first;
        int j = q.front().second;
        int d = dist[i][j];
        q.pop_front();
        rep(v,4){
            int ni = i + di[v] ; 
            int nj = j + dj[v] ;
            if(ni >= h || ni < 0 || nj<0 || nj >= w) continue ; 
            if(s[ni][nj]=='#') continue ; 
            if(dist[ni][nj]<=d) continue ; 
            dist[ni][nj] = d ;
            q.emplace_front(ni,nj) ;
        }
        for(int ei = -2;ei<=2 ;ei++){
            for(int ej = -2;ej<=2;ej++){
             int ni = i + ei; 
             int nj = j + ej;
             if(ni >= h || ni < 0 || nj<0 || nj >= w) continue ; 
             if(s[ni][nj]=='#') continue ; 
             if(dist[ni][nj]<=d+1) continue ; 
             dist[ni][nj] = d+1 ;
             q.emplace_back(ni,nj) ;            
            }
        }
    }

    int ans = dist[ti][tj] ;
    if(ans==INF) cout << -1 << endl ;
    else cout << ans << endl ;

    return 0 ;
}

Measured memory_bytes: 9580
#include <stdio.h>
int ans;
void f(int n,int l,int s){
	if(n==0){
		if(s==0)ans++;
		return;
	}
	for(int i=l;i<=9;i++)f(n-1,i+1,s-i);
	return;
}
int main(){
	int n,s;
	while(1){
		scanf("%d%d",&n,&s);
		if(n==0&&s==0)return 0;
		ans=0;
		f(n,0,s);
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 2620
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;


int main(){
int N,M,X;
cin >> N >> M >> X ;
vector<int> A(M);
int fcost = 0;
int bcost = 0;
for(int i = 0; i < M; i++){
    cin >> A[i];
}
for(int i = X; i < N; i++){
    for(int j = 0; j < M; j++){
        if(i == A[j]){
            fcost++;
        }
    }
}
for(int i = X; i != 0; i--){
    for(int j = 0; j < M; j++){
        if(i == A[j]){
            bcost++;
        }
    }
}
cout << min(fcost,bcost) << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
vector <int> l;
vector <int> abc(3);
int dfs(int i,int a,int b,int c){
    if(i == n){
        if(min(a,min(b,c))==0){
            return 1000000000;
        }
        return abs(abc[0]-a) + abs(abc[1]-b) + abs(abc[2]-c)-30;
    }
    int opt1 = dfs(i+1,a,b,c);
    int opt2 = dfs(i+1,a+l[i],b,c)+10;
    int opt3 = dfs(i+1,a,b+l[i],c)+10;
    int opt4 = dfs(i+1,a,b,c+l[i])+10;
    return min(opt1,min(opt2,min(opt3,opt4)));
}

int main(){
    cin >>n;
    for(int i=0;i<3;i++){
        cin >> abc[i];
    }
    for(int i=0;i<n;i++){
        int tmp;
        cin >> tmp;
        l.push_back(tmp);
    }
    int ans = 0;
    ans = dfs(0,0,0,0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  for (int i=a; i<= b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }

  cout << "NG" << endl;
  return 0;
}


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

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

  if(a.find("a") != string::npos && a.find("b") != string::npos && a.find("c") != string::npos){
  cout << "Yes" << endl;
}else{
  cout << "No" << endl;
}
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using lint=int64_t;
using namespace std;

int main()
{
	int N,D;
	int X[20][20]={};
	cin >> N >> D;
	for(int i=0;i<N;i++)
		for(int j=0;j<D;j++)
			cin >> X[i][j];
	
	int ans=0;
	for(int i=0;i<N;i++)
	{
		for(int j=i+1;j<N;j++)
		{
			int dist=0;
			for(int k=0;k<D;k++)
				dist+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
			int s=sqrt(dist);
			if(s*s==dist)
				ans++;
		}
	}

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        int[] arr = nextIntArray(br, n);
        int setGcd = arr[0];
        for(int i = 1; i < n; i++){
            setGcd = gcd(setGcd, arr[i]);
        }
        if(setGcd > 1){
            sb.append("not coprime");
        }else {
            int[] vals = new int[1000005];
            Arrays.fill(vals, -1);
            vals[1] = 1;
            for(int i = 2; i < vals.length; i++){
                for(int j = i; j < vals.length; j+=i){
                    if(vals[j] == -1){
                        vals[j] = i;
                    }
                }
            }

            Set<Integer> divisors = new HashSet<>();
            boolean isPair = true;
            for(int i = 0; i < n; i++){
                int val = arr[i];
                List<Integer> currentDiv = new ArrayList<>();
                while (val > 1){
                    int div = vals[val];
                    if(divisors.contains(div)){
                        isPair = false;
                        break;
                    }
                    currentDiv.add(div);
                    val /= div;
                }
                divisors.addAll(currentDiv);
                if(!isPair) break;
            }
            if(isPair){
                sb.append("pairwise coprime");
            }else {
                sb.append("setwise coprime");
            }
        }
        System.out.print(sb.toString());
    }

    private static int gcd(int a, int b){
        if(a < b) return gcd(b, a);
        if(a % b == 0) return b;
        return gcd(b, a % b);
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


Measured memory_bytes: 76056
import numpy as np
n, k = map(int,input().split())

# np.int64をつけないと、後でA**2を計算したときに桁あふれする
A = np.array(sorted(list(map(int,input().split()))), np.int64)
posA = A[A > 0] # 正の数のみの配列
negA = A[A < 0] # 負の数のみの配列
z = (A==0).sum() # 0の個数

left = -10**18
right = 10**18

while left+1 < right:
    num = (left+right)//2
    # ペア積の配列の中で、numより小さいものの数を数えていく。
    count = 0 # まずは0で初期化する。
    # もしnumが0以上であれば、積がゼロになるペア積の数を足しこむ
    if num >= 0:
        # この段階では値がゼロのものについて自分との積をあえてカウントする
        count += z*n 
    # 正の数に対して、かけてもnumを超えない最大の数字のリスト
    limit_pos = num // posA
    # limit_posの各数字を下回る数がAの中に何個あるかのリスト
    limit_idx = np.searchsorted(A, limit_pos, side='right')
    count += limit_idx.sum()

    # 負の数に対して、かけてもnumを超えない最大の数字のリスト
    limit_neg = -(-num // negA)
    # limit_negの各数字を下回る数がAの中に何個あるかのリスト
    limit_idx = n - np.searchsorted(A, limit_neg, side='left')
    count += limit_idx.sum()
    
    duplicate_cases = (A ** 2 <= num).sum()

    count -= duplicate_cases
    count //= 2

    if count >= k:
        right = num
    else:
        left = num

print(right)



Measured memory_bytes: 32332
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  vector<tuple<ll, ll, ll>> data;
  int j;
  REP(i, n){
    ll x, y, h;
    cin >> x >> y >> h;
    data.emplace_back(x, y, h);
    if(h > 0) j = i;
  }

  FORe(y, 0, 100) FORe(x, 0, 100){
    ll xi, yi, hi;
    tie(xi, yi, hi) = data[j];
    ll h = hi + labs(xi-x) + labs(yi-y);
    bool ok = true;
    REP(i, n){
      tie(xi, yi, hi) = data[i];
      ll t = hi + labs(xi-x) + labs(yi-y);
      if(hi > 0 && h != t) ok = false;
      if(hi == 0  && h > t) ok = false; 
    }
    if(ok){
      cout << x << " " << y << " " << h << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second

using namespace std;

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

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

    int n;
    cin>>n;

    vector<pii> v;

    int x,y;//x is time to complete 
    //y is deadline time
    for(int i =0;i<n;i++){
    	cin>>x>>y;
    	v.push_back({y,x});
    }

    //sort by deadline
    sort(v.begin(),v.end());

    int cur_time = 0;

 	int i;
    for(i =0;i<n;i++){
    	if(cur_time + v[i].s <= v[i].f){
    		cur_time = cur_time+v[i].s;
    	}
    	else
    		break;
    }
    
    if(i == n)
    	cout<<"Yes";
    else
    	cout<<"No";


	return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    ll sum = 0;
    ll del = 0;
    ll end = 0;
    rep(i, 1, n + 1){
        sum += i;
        if(sum >= n){
            del = sum - n;
            end = i;
            break;
        }
    }

    rep(i, 1, end + 1){
        if(i != del){
            cout << i << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main(void) {
	cin >> n;
	for (int k = 0; k < n; k++) {
		cin >> s;
		bool f = true;
		if (s[0] == '>' && s[1] == '\'') {
			int c = 0;
			int i;
			for (i = 2; s[i] == '='; i++)
				c++;
			if (c && s[i] == '#') {
				for (i += 1; s[i] == '='; i++)
					c--;
				if (!c && (int) s.size() == i + 1 && s[i] == '~') {
					cout << 'A' << endl;
					f = false;
				}
			}
		} else if (s[0] == '>' && s[1] == '^' && s[2] == 'Q' && s[3] == '=') {
			int i;
			for (i = 4; s[i] == 'Q' && s[i + 1] == '='; i += 2)
				;
			if ((int) s.size() == i + 2 && s[i] == '~' && s[i + 1] == '~') {
				cout << 'B' << endl;
				f = false;
			}
		}
		if (f) {
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 3196
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){

    int H,W,N;
    cin >> H >> W >> N;

    vector<vector<char> > F(H,vector<char>(W));


    map<char,int> M;
    int nx,ny;
    rep(i,H) rep(j,W){
        cin >> F[i][j];
        if(F[i][j] == 'S'){
            F[i][j] = '0';
            ny = i;nx = j;
        }
    }

    int cnt = 0;
    for(int i='1';i<=N+'0';i++){
        vector<vector<char> > A(H,vector<char>(W,false));
        //y x depth
        queue<pair<pair<int,int>,int> >  Q;
        Q.push(mp(mp(ny,nx),0));
        while(not Q.empty()){
            int y = Q.front().first.first;
            int x = Q.front().first.second;
            int d = Q.front().second;
            Q.pop();

            if(A[y][x]) continue;
            A[y][x] = true;

            if(F[y][x] eq i){
                cnt += d;
                ny = y;nx = x;
                break;
            }
            for(int j=0;j<4;j++){
                int nowx = x + dx[j];
                int nowy = y + dy[j];
                if(nowx >= W or nowx < 0 or nowy >= H or nowy < 0) continue;
                if(F[nowy][nowx] eq 'X') continue;
                Q.push(mp(mp(nowy,nowx),d+1));
            }
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3116
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int W = scan.nextInt();
    int[][] weightValues = new int[2][N];

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 2; j++) {
        weightValues[j][i] = scan.nextInt();
      }
    }
    scan.close();

    System.out.println(knapsack2(weightValues, N, W));
  }

  private static long knapsack2(int[][] weightValues, int N, int W) {
    if (N == 0 || W == 0)
      return 0;

    int maxPossibleSum = 0;
    for (int i = 0; i < N; i++)
      maxPossibleSum += weightValues[1][i];

    long MAX_VAL = Long.MAX_VALUE;
    long[] dp = new long[maxPossibleSum + 1];
    Arrays.fill(dp, MAX_VAL);
    dp[0] = 0;

    for (int i = 0; i < N; i++) {
      int currentValue = weightValues[1][i];
      int currentWeight = weightValues[0][i];
      for (int j = dp.length - 1; j >= 0; j--) {
        if (dp[j] == MAX_VAL) continue;
        int combinedValue = currentValue + j;
        long combinedWeight = currentWeight + dp[j];
        if (combinedWeight < dp[combinedValue]) {
          dp[combinedValue] = combinedWeight;
        }
      }
    }
    for (int i = dp.length - 1; i >= 0; i--) {
      if (dp[i] <= W) return i;
    }

    return 0;
  }

}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

constexpr auto INF = 1000000000;
using Pi = pair<int, int>;

class Edge {
public:
	int souce;
	int destination;
	int cost;

	Edge(int _souce=0,int _destination=0,int _cost=0) 
		:souce(_souce),destination(_destination),cost(_cost)
	{
	}
};

int N,M,P;

vector<Edge> E;
vector<Pi> V;

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


	V = vector<Pi>(N+1,Pi(0,INF));//(predecessor,cost)
	E = vector<Edge>(M+1);//
	V[1].second = 0;

	for (int i = 1; i <= M; i++) {
		int a, b, c;
		cin >> a;
		cin >> b;
		cin >> c;

		E[i]=Edge(a,b, -(c - P));
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			Pi& s = V[E[j].souce];
			Pi& d = V[E[j].destination];

			if (s.second != INF && d.second > s.second + E[j].cost) {
				d.second = s.second + E[j].cost;
				d.first = E[j].souce;
			}
			
		}
	}

	vector<bool> close(N + 1, false);
	for (int i = 1; i <= M ; i++) {
		Pi& s = V[E[i].souce];
		Pi& d = V[E[i].destination];

		if (s.second != INF && s.second + E[i].cost < d.second) {
			close[E[i].souce] = true;
			close[E[i].destination] = true;
		}
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			if (close[E[j].souce]) {
				close[E[j].destination] = true;
			}
		}
	}

	int ans = 0;
	if (close[N]) {
		ans = -1;
	}
	else {
		ans = max(0, -V[N].second);
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
def main():
    N, M = map(int,input().split())
    H = list(map(int,input().split()))
    A = [list(map(int,input().split())) for _ in range(M)]

    way = [ [] for _ in range(N+1)]

    for i in range(M):
        a = A[i][0]
        b = A[i][1]
        way[a].append(b)
        way[b].append(a)

    #print(way)
    ans = 0
    for j in range(N):
        cnt = 0
        if way[j+1] == []:
            ans += 1
            continue
        for k in way[j+1]:
            if H[j] <= H[k-1]:
                break
            cnt += 1
            if cnt == len(way[j+1]):
                ans += 1

    return ans

print(main())


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


int main() {
	long double sum = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		long double x;
		cin >> x;
		sum += (long double)1 / x;
	}
	sum = (long double)1 / sum;
	cout << fixed << setprecision(10) << sum;
	return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
// using ll = boost::multiprecision::int128_t;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;


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

  rep(i, n) if (a[i] == 0) {
    cout << 0 << "\n";
    return 0;
  }

  ll ans = 1;
  rep(i, n) {
    if (ans >= (ll(1e18) + 1 + a[i] - 1)  / a[i]) {
      cout << -1 << "\n";
      return 0;
    }
    ans *= a[i];
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3992
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M, X = MAP()
A = LIST()
idx = bisect(A, X)
print(min(idx, M-idx))


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

int main(){
	int ary[20]={};
	int spd[2]={};
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&ary[1],&ary[2],&ary[3],&ary[4],&ary[5],&ary[6],&ary[7],&ary[8],&ary[9],&ary[10],&spd[0],&spd[1])!=EOF){
		for(int i=2;i<=10;i++){
			ary[i]+=ary[i-1];
		}

		double piy=(double)(ary[10]*spd[0])/(double)(spd[0]+spd[1]);
		int hog=ceil(piy);
		int res;
		for(int i=0;i<=10;i++){
			if(hog<=ary[i]){
				res=i;
				break;
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int N, d = 0; std::cin >> N;
  for(int i = 0; i < N; ++i) {
    int p; std::cin >> p;
    if(p != i+1 && ++d > 2) fin("NO");
  }
  fin("YES");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int vmax=100005;
int par[vmax];
void init(int x){
  for(int i=0;i<x;i++){
    par[i]=i;
  }
}
int root(int x){
  if(par[x]==x){
    return x;
  }
  return par[x]=root(par[x]);
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y){
    return ;
  }
  par[x]=y;
}
typedef long long ll;
int main(){
  int n;cin >> n;
  init(n);
  vector<pair<int,int>> a(n),b(n);
  for(int i=0;i<n;i++){
    int x,y;cin >> x >> y;
    a[i]=make_pair(x,i);
    b[i]=make_pair(y,i);
  }
  vector<pair<int,pair<int,int>>> c;
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  for(int i=0;i<n-1;i++){
    int s=abs(a[i].first-a[i+1].first);
    int t=abs(b[i].first-b[i+1].first);
    c.push_back(make_pair(s,make_pair(a[i].second,a[i+1].second)));
    c.push_back(make_pair(t,make_pair(b[i].second,b[i+1].second)));
  }
  sort(c.begin(),c.end());
  ll ans=0;
  for(int i=0;i<c.size();i++){
    int u=c[i].second.first;
    int v=c[i].second.second;
    if(root(u)!=root(v)){
      ans+=c[i].first;
      unite(u,v);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6900
from sys import stdin, stdout 
from math import *
import itertools
import sys

k, n = map(int, input().split())
a = [int(i) for i in input().split()]
d = 0
for i in range(1, n):
    d = max(d, a[i] - a[i-1])

d = max(d, k - a[-1] + a[0])
print(k - d)


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

int hextodec(char c){
    if(c <= '9')    return c-'0';
    return 10 + c-'a';
}

string dec(char x){
    int num = hextodec(x);
    string res = "";
    for(int i = 0; i < 4; i++){
        if(num & (1<<i))    res += "1";
        else                res += "0";
    }
    reverse(res.begin(), res.end());
    return res;
}


int main(){
    int bias[32] = {};
    for(int i = 1; i < 25; i++){
        bias[i] = 1<<(24-i);
    }
    bias[25] = 5000000;
    for(int i = 26; i < 32; i++){
        bias[i] = bias[i-1]/2;
    }

    int q;
    cin >> q;
    
    string s;

    while(q-- > 0){
        cin >> s;
        string bin = "";
        for(char c : s) bin += dec(c);
        int a = 0, b = 0;
        for(int i = 1; i < 25; i++){
            if(bin[i] == '1')   a += bias[i];
        }
        for(int i = 25; i < 32; i++){
            if(bin[i] == '1')   b += bias[i];
        }

        string sb = to_string(b);
        while(sb.length() != 7) sb = "0" + sb;
        while(sb.length() > 0 && sb[sb.length()-1] == '0')  sb = sb.substr(0, sb.length()-1);
        if(sb == "")    sb = "0";
        
        if(bin[0] == '1')   cout << "-";
        cout << a << "." << sb << endl;
    }

    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ff first
#define ss second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define forn(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;



int32_t main()
{
    fast

   int test=1;
    //cin>>test;
  
   

  while(test--)
  {
    
    int n,x,t;
    cin>>n>>x>>t;

    if(x>=n)
    {
        cout<<t;
        return 0;
    }

    int times=ceil((double)n/(double)x);

    cout<<times*t;

// while ending
   }
  

return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b, k;
    cin >> a >> b >> k;
    int i;
    map<int, int> M;
    for(i=a; i<=(a+k-1); i++){
        if(i>b) return 0;
        else if(M[i]==1) continue;
        else{
            cout << i << "\n";
            M[i]++;
        }
    }
    int j = b-k+1;
    if(j<0){
        return 0;
    }
    else{
        for(i=j; i<=b; i++){
            if(M[i]) continue;
            else{
                cout << i << "\n";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3636
use std::io;

fn main() {
    let mut S = String::new();
    let mut K = String::new();

    io::stdin().read_line(&mut S).expect("ee");
    io::stdin().read_line(&mut K).expect("ee");
    let K:usize = K.trim().parse().unwrap();

    for i in 0..K{
        let c = S.remove(0);
        if c!='1' {
            println!("{}", c);
            return;
        }
    }
    println!("1");
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);

int main()
{
    int a[3] = {0};
    for(int i=0; i<3; i++) std::cin >> a[i];
    int sum = 0;
    for(int i=0; i<3; i++) sum += a[i];

    if(sum>=22) std::cout << "bust" << std::endl;
    else std::cout << "win" << std::endl;
    return 0;
}

Measured memory_bytes: 256