akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int) (n); i++)
#define _GLIBCXX_DEBUG

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

const int max_n = 10;
int n, a, b;
int p[max_n], q[max_n];
vector<int> v;

int main(){
    cin >> n;
    rep(i, n) cin >> p[i], v.push_back(i+1);
    rep(i, n) cin >> q[i];

    int cnt = 1;
    do{
        rep(i, n){
            if(v[i] != p[i]) break;
            if(i >= n-1) a = cnt;
        }
        rep(i, n){
            if(v[i] != q[i]) break;
            if(i >= n-1) b = cnt;
        }
        cnt++;
    }while(next_permutation(v.begin(), v.end()));

    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl

typedef pair<int, int> P;
typedef long long ll;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    vector<ll> a(n);
    int ans = 0;
    REP(i,n) {
        cin>>a[i];
        if (a[i]%2!=0) ans = 1;
        else continue;
    } 
    if (ans == 0) print("second");
    else print("first");
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
void Debug(auto a);

void reflesh(vector<int> &a){
    REP(i,a.size()){
        a[i] = 0;
    }
}


signed main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vec(a,26);
    vec(b,26);
    int ans = 0;
    REP(i,n){
        REP(j,n){
            if(j<=i){
                int x = s[j] - 'a';
                a[x]++;
            }
            else{
                int x = s[j] - 'a';
                b[x]++;
            }
        }
        int ans_w = 0;
        REP(k,26){
            if(a[k] != 0 && b[k] != 0){
                ans_w++;
            }
        }
        ans = max(ans,ans_w);
        reflesh(a);
        reflesh(b);

    }
    cout << ans << endl;

    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\????????????????????????
            
            String line = br.readLine();
            String[] dataArray = line.split(" ");
            int x = Integer.parseInt(dataArray[0]);
            int y = Integer.parseInt(dataArray[1]);
            if(x<y) System.out.println(Result.LessThan.getValue());
            if(x==y) System.out.println(Result.Equal.getValue());
            if(x>y) System.out.println(Result.GreaterThan.getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

   public enum Result{
    	LessThan("a < b"),
    	Equal("a == b"),
    	GreaterThan("a > b");
	   
		// Field
	    private String name;
	    
	    // Constructor
	    private Result(String name) {
	        this.name = name;
	    }
	    
	    // Method
        public String getValue() {
            return this.name;
        }
   };
}

Measured memory_bytes: 24288
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdint.h>
using namespace std;

const int32_t MAX = 200001;
const int32_t MOD = 1000000007;

int64_t fac[MAX], finv[MAX];

// ax + by = gcd(a, b) となるような (x, y) を求める
// 多くの場合 a と b は互いに素として ax + by = 1 となる (x, y) を求める
int64_t extGCD(int64_t a, int64_t b, int64_t &x, int64_t &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int64_t d = extGCD(b, a%b, y, x); // 再帰的に解く
    y -= a / b * x;
    return d;
}

// 負の数にも対応した mod (a = -11 とかでも OK) 
inline int64_t mod(int64_t a, int64_t m) {
    return (a % m + m) % m;
}

// 逆元計算 (ここでは a と m が互いに素であることが必要)
int64_t modinv(int64_t a, int64_t m) {
    int64_t x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}

// テーブルを作る前処理
void COMinitNoInv() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
    finv[MAX - 1] = modinv(fac[MAX - 1], MOD);
    for( int i = MAX - 1; i > 2; --i ){
        finv[i - 1] = finv[i] * i % MOD;
    }
} 

// 二項係数計算
int64_t COM(int32_t n, int32_t k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinitNoInv();

    int32_t Y0; cin >> Y0;
    int32_t X0; cin >> X0;
    int32_t Y1; cin >> Y1;
    int32_t X1; cin >> X1;

    int64_t result = 0;
    for( int x = X1 + 1; x <= X0; ++x ){
        int64_t t = COM( (x - 1) + (Y0 - Y1 - 1), (x - 1) ) * COM( (X0 - x) + (Y1 - 1), (Y1 - 1)) % MOD;
        result = (result + t) % MOD;
    }
    cout << result << endl;
    
    return 0; 
}

Measured memory_bytes: 3960
#include<stdio.h>
#include<string.h>
char a[100000010];
int main(){
    scanf("%s",a);
    int t=1;
    for(int i=0;i<=(strlen(a)-1)/2;i++){
        if((a[i]=='d'&&a[strlen(a)-i-1]=='b')||(a[i]=='b'&&a[strlen(a)-i-1]=='d')||(a[i]=='q'&&a[strlen(a)-i-1]=='p')||(a[i]=='p'&&a[strlen(a)-i-1]=='q'));
        else t=0;
    }
    if(t)printf("Yes");
    else printf("No");
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N;
ll dp[101][4][4][4];


int main() {
    cin >> N ;
    rep(i,4){
        rep(j,4){
            rep(k,4){
                dp[3][i][j][k] = 1;
            }
        }
    }
    dp[3][0][2][1] = 0;
    dp[3][0][1][2] = 0;
    dp[3][2][0][1] = 0;
    repi(p,4,101){
        rep(i,4){
            rep(j,4){
                rep(k,4){
                    dp[p][i][j][k] = 0;
                }
            }
        }
    }
    repi(p,3,100){
        rep(i,4){
            rep(j,4){
                rep(k,4){
                    ll checkC = 0;
                    ll checkG = 0;
                    if ((j == 0 && k == 2) || (i == 0 && j == 2) || (j==2 && k==0) || (i == 0 && k == 2)){
                        checkC = 1;
                    }
                    if (j == 0 && k == 1){
                        checkG = 1;
                    }
                    if (checkC == 1 && checkG == 0){
                        dp[p+1][j][k][0] += dp[p][i][j][k];
                        dp[p+1][j][k][2] += dp[p][i][j][k];
                        dp[p+1][j][k][3] += dp[p][i][j][k];
                        dp[p+1][j][k][0] %= inf;
                        dp[p+1][j][k][2] %= inf;
                        dp[p+1][j][k][3] %= inf;
                        
                    }
                    if (checkC == 0 && checkG == 1){
                        dp[p+1][j][k][0] += dp[p][i][j][k];
                        dp[p+1][j][k][1] += dp[p][i][j][k];
                        dp[p+1][j][k][3] += dp[p][i][j][k];
                        dp[p+1][j][k][0] %= inf;
                        dp[p+1][j][k][1] %= inf;
                        dp[p+1][j][k][3] %= inf;
                        
                    }
                    if (checkC == 1 && checkG == 1){
                        dp[p+1][j][k][0] += dp[p][i][j][k];
                        dp[p+1][j][k][3] += dp[p][i][j][k];
                        dp[p+1][j][k][0] %= inf;
                        dp[p+1][j][k][3] %= inf;
                    }
                    
                    
                    if (checkC == 0 && checkG == 0){
                        rep(q,4){
                            dp[p+1][j][k][q] += dp[p][i][j][k];
                            dp[p+1][j][k][q] %= inf;
                        }
                    }
                }
            }
        }
        
    }
    ll ans = 0;
    rep(i,4){
        rep(j,4){
            rep(k,4){
                ans += dp[N][i][j][k];
                ans %= inf;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//AOJ0515

import java.util.Scanner;

public class Main {
	
	static int a, b, n;
	static int[][] r = new int[16][16]; 
	static Scanner scan = new Scanner(System.in);		//入力
	
	public static void main(String[] args){
		while(read()){
			solve();
		}
	}


	public static boolean read()
	{
		
		a = scan.nextInt();
		b = scan.nextInt();
		// 余談だが, if文のブロックは正しくつけておいたほうがいいかも
		if(a==0 && b==0)
			return false;
		else{
			// 初期化を忘れている
			// このままだと, 前回の工事中のますが残ってしまう
			for (int i = 0; i < a; i++) {
				for (int j = 0; j < b; j++) {
					r[i][j] = 0;
				}
			}
			
			int n = scan.nextInt();
			for(int i=0; i<n; i++){
				int c = scan.nextInt();
				int d = scan.nextInt();
				r[c-1][d-1] = 1; 		//工事中の交差点に１を代入しておく
			}
			return true;
		}
	}

	
	public static void solve(){
		// (1, 1)は, 必ず工事中でないことが保証されている
		r[0][0] = 1;
		for(int i=1; i<a; i++) {
			//１行と１列を１で初期化
			// 初期化の際工事中であるマスを考慮できてなかった
			if (r[i][0] == 1) {
				r[i][0] = 0;
			} else {
				// 手前のマスの計算結果を利用
				r[i][0] = r[i - 1][0];
			}
		}
			
		for(int i=1; i<b; i++) {
			//１行と１列を１で初期化
			// 初期化の際工事中であるマスを考慮できてなかった
			if (r[0][i] == 1) {
				r[0][i] = 0;
			} else {
				// 手前のマスの計算結果を利用
				r[0][i] = r[0][i - 1];
			}
		}
	
		
		for(int i=1; i<a; i++)
			for(int j=1; j<b; j++){
				if(r[i][j] == 1)		//値が１なら、問答無用で０に
					r[i][j] = 0;
				else		//値が０なら、要素r[i][j]は左と下の要素を加えたもの
					r[i][j] = r[i-1][j] + r[i][j-1];
			}
		System.out.println(r[a-1][b-1]);	//出力
		
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#include<stdlib.h>
#define inf 1072114514

typedef struct{
  int a;
  int e;
  int r;
}dat;

int datsort(const void *a,const void *b){
  if(((dat*)a)->r < ((dat*)b)->r){return -1;}
  if(((dat*)a)->r > ((dat*)b)->r){return 1;}
  return 0;
}

int max(int a,int b){
  if(a>b){return a;}
  return b;
}

int min(int a,int b){
  if(a<b){return a;}
  return b;
}

int main(){
  int i,j,k,d,n,res;
  int a[128],e[128],r[128];
  int dp[128][128];
  dat data[128];
  while(scanf("%d%d",&d,&n),d!=0){
    for(i=0;i<n;i++){
      scanf("%d%d%d",&data[i].a,&data[i].e,&data[i].r);
    }
    qsort(data,n,sizeof(data[0]),datsort);
    for(i=0;i<n;i++){
      a[i]=data[i].a;
      e[i]=data[i].e;
      r[i]=data[i].r;
    }
    for(i=0;i<128;i++){
      for(j=0;j<128;j++){dp[i][j]=inf;}
    }
    dp[d][0]=0;
    for(j=d;j>0;j--){
      for(k=0;k<=100;k++){
        for(i=0;i<n;i++){
          if(k<r[i]){continue;}
          dp[max(j-a[i],0)][min(k+e[i],100)]=min(dp[j][k]+1,dp[max(j-a[i],0)][min(k+e[i],100)]);
        }
      }
    }
    res=inf;
    for(i=0;i<=100;i++){
      res=min(dp[0][i],res);
    }
    if(res==inf){printf("NA\n");}
    else{printf("%d\n",res);}
  }
}



Measured memory_bytes: 2036
#include<stdio.h>
#define N 10000

int main(void){
  int i,num,j,k;
  int c,sf;
  char map[4][4];
  char hoge;
  int count,ans[N];

  sf=0;
  for(i=0;;i++){
    for(j=0;j<3;j++){
      for(k=0;k<3;k++){
        c=scanf("%c",&map[j][k]);
        if(c==EOF){
          sf=1;
          break;
        }
      }
      if(sf==1)
        break;
    }
    if(sf==1)
      break;
    scanf("%c",&hoge);

    ans[i]=3;

    for(j=0;j<3;j++){
      for(k=0,count=0;k<3;k++)
        if(map[j][k]=='o')
          count++;
      if(count==3)
        ans[i]=1;
      for(k=0,count=0;k<3;k++)
        if(map[k][j]=='o')
          count++;
      if(count==3)
        ans[i]=1;
    }
    for(j=0,k=0,count=0;j<3;j++,k++)
      if(map[k][j]=='o')
        count++;
    if(count==3)
      ans[i]=1;
    for(j=0,k=2,count=0;j<3;j++,k--)
      if(map[k][j]=='o')
        count++;
    if(count==3)
      ans[i]=1;

    for(j=0;j<3;j++){
      for(k=0,count=0;k<3;k++)
        if(map[j][k]=='x')
          count++;
      if(count==3)
        ans[i]=2;
      for(k=0,count=0;k<3;k++)
        if(map[k][j]=='x')
          count++;
      if(count==3)
        ans[i]=2;
    }
    for(j=0,k=0,count=0;j<3;j++,k++)
      if(map[k][j]=='x')
        count++;
    if(count==3)
      ans[i]=2;
    for(j=0,k=2,count=0;j<3;j++,k--)
      if(map[k][j]=='x')
        count++;
    if(count==3)
      ans[i]=2;
  }
  num=i;
  for(i=0;i<num;i++){
    if(ans[i]==1)
      printf("o\n");
    else if(ans[i]==2)
      printf("x\n");
    else if(ans[i]==3)
      printf("d\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

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


int main() {
    ll N,L;
    cin >> N >> L;
    vector<string> S(N);
    rep(i,N){
        cin >> S[i];
    }

    sort(S.begin(),S.end());
    string ans = "";
    rep(i,N){
        ans += S[i];
    }

    cout << ans << endl;
}




Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>

using namespace std;

long long A, B, C, K;
int main(void) {
	scanf("%lld %lld %lld %lld", &A, &B, &C, &K);
	if (K % 2 == 0) { printf("%lld\n", A - B); }
	else { printf("%lld\n", B - A); }
	return 0;
}


Measured memory_bytes: 128
k=input().split()
n=int(k[0])
x=int(k[1])
a=[]
#a = list(map(int, input().rstrip().split("\n")))
for i in range(0,n):
  a.append(int(input()))
k=x-sum(a)
j=k//min(a)
print(j+n)
    

  



Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))

if N % 2 == 0: #偶数のとき
    B = [0] * (N // 2 + 1)
    W = [0] * (N // 2 + 1)
    for i in range(N // 2):
        B[i + 1] = B[i] + A[2 * i]
    for i in range(N // 2 - 1, -1, -1):
        W[i] = W[i + 1] + A[2 * i + 1]

    # print (B)
    # print (W)

    ans = -10 ** 16
    for i in range(N // 2 + 1):
        ans = max(ans, B[i] + W[i])

    print (ans)
    exit()

DP0 = [[-10 ** 16] * 2 for _ in range(N + 1)]
DP1 = [[-10 ** 16] * 2 for _ in range(N + 1)]
DP2 = [[-10 ** 16] * 2 for _ in range(N + 1)]

DP0[N][0] = 0 #右端の外側を0に設定してスタート

for i in range(N - 1, -1, -1):
    a = A[i]
    
    DP0[i][0] = DP0[i + 1][1]
    DP0[i][1] = DP0[i + 1][0] + a

    DP1[i][0] = max(DP1[i + 1][1], DP0[i + 1][0])
    DP1[i][1] = DP1[i + 1][0] + a

    DP2[i][0] = max(DP2[i + 1][1], DP1[i + 1][0])
    DP2[i][1] = DP2[i + 1][0] + a
    
if N % 2 == 1:
    print (max(DP1[0][0], DP2[0][1]))
else:
    print (max(DP0[0][0], DP1[0][1]))

# for i in DP0:
#     print (i)

# for i in DP1:
#     print (i)

# for j in DP2:
#     print (j)

Measured memory_bytes: 97432
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

K, X = get_ints

puts K * 500 >= X ? 'Yes' : 'No'


Measured memory_bytes: 14480
/*素数判定*/
#include <stdio.h>
#include <math.h>
#define N 10000
int isPrime(int);

int main(){
  int a[N], i, j, n, count=0;

  scanf("%d", &n);

  for (i=0; i<n; i++){
    scanf("%d", &a[i]);
    count += isPrime(a[i]);
  }
  printf("%d\n", count);

  return 0;
}

int isPrime(int x)
{
  int i;
  if(x<2) return 0;
  else if (x == 2) return 1;
  else if (x % 2 == 0) return 0;
  for(i=3; i<=sqrt(x); i+=2){
    if(x%i==0) return 0;
  }
  return 1;
}



Measured memory_bytes: 2140
#-*- coding: utf-8
#  -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(S):
    # oxoxoxoxoxoxox
    c = 0
    for s in S:
        if s == 'o': c+=1
    return 'YES' if 15 - len(S) + c >= 8 else 'NO'


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    #n = int(parsed_lines[0][0])
    S = parsed_lines[0][0]
    # k = int(parsed_lines[0][1])
    # S = parsed_lines[1][0]
    # return n, k, S
    return S


if not do_submit:
    S = input_parse("""
    oxoxoxoxoxoxox
    """)
    print(sol(S))

    S = input_parse("""
    xxxxxxxx
    """)
    print(sol(S))

else:
    # n, k = list(map(int, input().split()))
    # S = input().split()
    # print(sol(n, k, S))
    S = input().strip()
    # S = input().strip()
    print(sol(S))



Measured memory_bytes: 3688
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7,MAX=1e6,Primes[168]=
{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,
 73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,
 179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,
 283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,
 419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,
 547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,
 661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,
 811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,
 947,953,967,971,977,983,991,997};
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
struct T{int fact[1000001],inv[1000001];};
struct T MODINV;
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
static inline void init(void)
{
  MODINV.fact[0]=1;rep(i,MAX)MODINV.fact[i+1]=1l*MODINV.fact[i]*(i+1)%MOD;
  MODINV.inv[MAX]=MPow(MODINV.fact[MAX],MOD-2);
  rep(i,MAX)MODINV.inv[MAX-1-i]=1l*MODINV.inv[MAX-i]*(MAX-i)%MOD;
}
static inline void Radix32(int *a,const int sz)
{
  int x,shift=0,elem[256],temp[sz];
  while(shift<32)
  {
    int bucket[256]={0};
    rep(i,sz){x=(a[i]>>shift)&255;bucket[x]++;temp[i]=a[i];}
    elem[0]=0;rep(i,255)elem[i+1]=elem[i]+bucket[i];
    rep(i,sz){x=(temp[i]>>shift)&255;a[elem[x]]=temp[i];elem[x]++;}
    shift+=8;
  }
}
int main(void)
{
  int N=IN(),A=0,invsum=0,k=0,lcm=1,x=0,temp[10000],box[168]={};init();
  rep(i,N)
  {
    A=IN();invsum=(invsum+1l*MODINV.fact[A-1]*MODINV.inv[A]%MOD)%MOD;
    rep(j,168){x=0;while(A%Primes[j]==0){A/=Primes[j];if(box[j]<++x)box[j]=x;}}
    if(A!=1){temp[k++]=A;}
  }
  Radix32(temp,k);
  rep(i,168){rep(j,box[i]){lcm=1l*lcm*Primes[i]%MOD;}}
  x=-1;rep(i,k){if(x!=temp[i]){lcm=1l*lcm*temp[i]%MOD;x=temp[i];}}
  x=1l*lcm*invsum%MOD;return printf("%d\n",x),0;
}

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

template<typename T>
struct sum2d{
	int n,m;
	ll mod;
	vector<vector<T>>sum;
	bool flag=false;

	sum2d(){}
	sum2d(int n,int m,ll mod=-1)
		:n(n),m(m),mod(mod),sum(vector<vector<T>>(n+2,vector<T>(m+2))){}

	void add(int x,int y,T t){
		assert(!flag);
		x++;y++;
		sum[x][y]+=t;
	}
	
	void add(int x1,int y1,int x2,int y2,T t){
		assert(!flag);
		x1++;y1++;x2++;y2++;
		sum[x1][y1]+=t;
		sum[x1][y2+1]-=t;
		sum[x2+1][y1]-=t;
		sum[x2+1][y2+1]+=t;
		if(mod!=-1){
			sum[x1][y1]%=mod;
			(sum[x1][y2+1]+=mod)%=mod;
			(sum[x2+1][y1]+=mod)%=mod;
			sum[x2+1][y2+1]%=mod;
		}
	}
	
	void calc(){
		flag=true;
		rep(i,n+1)for(int j=1;j<=m;j++){
			sum[i][j]+=sum[i][j-1];
			if(mod!=-1)sum[i][j]%=mod;
		}
		rep(i,m+1)for(int j=1;j<=n;j++){
			sum[j][i]+=sum[j-1][i];
			if(mod!=-1)sum[j][i]%=mod;
		}
	}

	T get(int x1,int y1,int x2,int y2){
		if(!flag)calc();
		x1++;y1++;x2++;y2++;
		T res=sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1];
		if(mod!=-1){
			while(res<0)res+=mod;
			res%=mod;
		}
		return res;
	}

	T get(int x,int y){
		return get(x,y,x,y);
	}

	T imos(int x,int y){
		if(!flag)calc();
		x++;y++;
		return sum[x][y];
	}
};
P dat[20000];
int N;
void init(int n){
	N=1;while(N<n)N<<=1;
	for(int i=N-1;i<2*N-1;i++)dat[i].second=i-N+1;
}
void update(int k,int x){
	k+=N-1;
	dat[k].first=x;
	while(k){
		k=(k-1)/2;
		dat[k]=max(dat[k*2+1],dat[k*2+2]);
	}
}
P query(int a,int b,int k=0,int l=0,int r=N){
	if(b<=l||r<=a)return P(0,0);
	if(a<=l&&r<=b)return dat[k];
	P lb=query(a,b,k*2+1,l,(l+r)/2);
	P rb=query(a,b,k*2+2,(l+r)/2,r);
	return max(lb,rb);
}


ll a[6000],b[6000][300];
ll asum[6000];

sum2d<ll>sum;

void dfs(int l,int r){//[l,r]
	if(l>r)return;
	P p=query(l,r+1);
	sum.add(l,p.second,p.second,r,p.first);
	dfs(l,p.second-1);
	dfs(p.second+1,r);
}

int main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,n-1){
		scanf("%lld",&a[i]);
		asum[i+1]=asum[i]+a[i];
	}
	rep(i,n)rep(j,m)scanf("%lld",&b[i][j]);
	sum=sum2d<ll>(n,n);
	init(n);
	rep(i,m){
		rep(j,n)update(j,b[j][i]);
		dfs(0,n-1);
	}
	ll Max=0;
	rep(i,n)for(int j=i;j<n;j++){
		Max=max(Max,sum.imos(i,j)-(asum[j]-asum[i]));
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 208384
int main()
{
  int n;
  scanf("%d", &n);
  long a[n];
  long i, sum = 1;
  for (i = 0; i < n; i++)
  {
    scanf("%ld", &a[i]);
    if (a[i] == 0)
    {
      printf("0");
      return 0;
    }
  }
  long max = pow(10, 18);
  for (i = 0; i < n; i++)
  {
    if (sum <= max / a[i])
      sum *= a[i];
    else
    {
      printf("-1");
      return 0;
    }
  }
  printf("%ld", sum);
}

Measured memory_bytes: 2480
N=int(input())
Xl=list(map(int,list(input())))
#X=int(input())
#print(Xl)

def func(x):
  cnt=0
  while x>0:
    num1=0
    xcopy=x
    while xcopy:
      if xcopy&1:
        num1+=1
      xcopy>>=1
      
    #print(x,num1)
    x=x%num1
    cnt+=1
  return cnt

func_dic={}
for i in range(N+1):
  func_dic[i]=func(i)
#print(func_dic)

num1_X=Xl.count(1)
#print(num1_X)

mod_nminus=0
mod_nplus=0
for i in range(N):
  if num1_X-1>0:
    mod_nminus*=2
  mod_nplus*=2  
  if Xl[i]==1:
    mod_nminus+=1
    mod_nplus+=1

  if num1_X-1>0:
    mod_nminus%=num1_X-1
  mod_nplus%=num1_X+1
  
#print(mod_nminus,mod_nplus)

answer_list=[]
modpow_plus=1
modpow_minus=1
for i in reversed(range(N)):
  if Xl[i]==0:
    mod=(mod_nplus+modpow_plus)%(num1_X+1)
    answer_list.append(func_dic[mod]+1)
  else:
    if num1_X-1==0:
      answer_list.append(0)
    else:
      mod=(mod_nminus-modpow_minus)%(num1_X-1)
      answer_list.append(func_dic[mod]+1)
  
  modpow_plus*=2  
  modpow_plus%=num1_X+1
  if num1_X-1>0:
    modpow_minus*=2
    modpow_minus%=num1_X-1
  
for i in reversed(range(N)):
  print(answer_list[i])

Measured memory_bytes: 121332
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <atcoder/all>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, Q;

int main() {
  std::cin >> N >> Q;

  atcoder::dsu dsu(N+10);

  rep( q, Q ) {
    ll t, u, v;
    std::cin >> t >> u >> v;

    if( !t ) {
      dsu.merge( u, v );
    } else {
      std::cout << dsu.same( u, v ) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3976
#include <cstdio>
#include <algorithm>

#define ll long long
#define maxn 100000

ll v[maxn + 1];

int main() {
    int n, rez = 1;
    scanf("%d", &n);

    for (int i = 1; i <= n; i++) {
        scanf("%lld", &v[i]);
    }

    std::sort(&v[1], &v[n + 1]);
    int l = 0;
    for (int i = 2; i <= n; i++) {
        if (v[i] == v[i - 1]) {
            l = 1 - l;
        }
        else
            l = 0;
        if (l == 0) {
            rez++;
        }
        else {
            rez--;
        }
    }

    printf("%d", rez);
    return 0;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
#define ll long long

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

	if ( n == 1 ) {
		cout << p << endl;
		return 0;
	}

	ll ans = 1, lim = sqrt(p) + 1;
	for ( ll i = 2; i <= lim; i++ ) {
		ll cnt = 0;
		while ( p % i == 0 ) {
			p /= i;
			cnt++;
		}
		if ( cnt / n > 0 ) {
			ans *= pow(i, (cnt / n));
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;
int a[114514];
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
signed main() {
	int n, k;
	cin >> n >> k;
	rep(i, n) { cin >> a[i]; }
	int sum = gcd(a[0], a[1]);
	loop(i, 2, n) {
		sum = gcd(a[i], sum);
	}
	sort(a, a + n);
	if (a[n - 1] < k) { puts("IMPOSSIBLE"); endre; }
	else if ((a[n - 1] - k) % sum == 0) { puts("POSSIBLE"); endre; }
	else { puts("IMPOSSIBLE"); endre; }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    long d,n;
    cin>>d>>n;
    if(n==100)printf("%ld\n",(d==0?1:(d==1?100:10000))*(n+1));
    else printf("%ld\n",(d==0?1:(d==1?100:10000))*n);
    return 0;
}


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

int main() {
    int k;
    string s;
    cin >> k >> s;
    if(s.size() <= k)cout << s << endl;
    else cout << s.substr(0, k) << "..." << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int n; cin >> n;
  int p[n]; for(int i = 0; i < n; i++) cin >> p[i];
  int sum = 0;
  for(int i = 0; i < n - 2; i++){
    int maxp = p[i], minp = p[i];
    for(int j = 0; j < 3; j++){
      maxp = max(p[i + j], maxp);
      minp = min(p[i + j], minp);
    }
    if(p[i + 1] != maxp && p[i + 1] != minp) sum++;
  }
  cout << sum << endl;
  return;
}

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


Measured memory_bytes: 764
//hi
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long int LL;
int s[100005];
int main(void){
    int n;
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&s[i]);
    for(i=2;i<=n;i++)
		if(s[i-1]%2==1 && s[i]>0){
			s[i-1]--;
			s[i]++;
		}
	LL tot=0;
	for(i=1;i<=n;i++) tot+=s[i]/2;
	printf("%lld\n",tot);
    return 0;
}


Measured memory_bytes: 640
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
from random import randrange
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    if Counter(A + B).most_common()[0][1] > n:
        print("No")
        return

    for i in range(n):
        if A[i] != B[i]:
            continue
        while 1:
            j = randrange(0, n)
            if A[i] != B[j] and A[j] != B[i]:
                B[i], B[j] = B[j], B[i]
                break
    print("Yes")
    print(*B)
resolve()

Measured memory_bytes: 154304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 50;
int a[N];
int main()
{
    int k, n;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", a + i);
    sort(a, a + n);
    int ans = a[n - 1] - a[0];
    for (int i = k - 1; i < n; i++)
        ans = min(ans, a[i] - a[i - k + 1]);
    printf("%d", ans);
    return 0;
}

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

int main () {
	int x, y;
	int i, j;
	char a[101][9];
	char b[9];
	int c[101];

	while(1) {
		int sum = 0;
		cin >> x >> y;
		if(x == 0 && y == 0) {
			break;
		}
		for(size_t i = 0; i < x; i++) {
			cin >> a[i];
			cin >> c[i];
		}
		for(size_t j = 0; j < y; j++) {
			cin >> b;
			for(size_t i = 0; i < x; i++) {
				int flag = 1;
				for(size_t k = 0; k < 8; k++) {
					if(a[i][k] == '*' || a[i][k] == b[k]) {
						flag = 1;
					} else {
						flag = 0;
						break;
					}
				}
				if(flag) {
					sum += c[i];
				}

			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	ll H, W;
	cin >> H >> W;

	ll saishou = 1e18;

	if (H % 3 == 0) saishou = 0;
	if (W % 3 == 0) saishou = 0;
	saishou = min(saishou, H);
	saishou = min(saishou, W);

	rep1(i, H - 1) {
		ll S1 = W * i;
		ll S2 = (H - i) * (W / 2);
		ll S3 = (H - i) * ((W + 1) / 2);
		ll dai = max(S1, max(S2, S3));
		ll shou = min(S1, min(S2, S3));
		saishou = min(saishou, dai - shou);
	}
	rep1(i, W - 1) {
		ll S1 = H * i;
		ll S2 = (W - i) * (H / 2);
		ll S3 = (W - i) * ((H + 1) / 2);
		ll dai = max(S1, max(S2, S3));
		ll shou = min(S1, min(S2, S3));
		saishou = min(saishou, dai - shou);
	}
	co(saishou);

	Would you please return 0;
}

Measured memory_bytes: 256
def calc_digit_sum(num):
    result = 0
    while num > 0:
        result += num % 10
        num //= 10
    return result

n, a, b = map(int, input().split())
result = 0
for i in range(1, n+1):
    digit_sum = calc_digit_sum(i)
    if digit_sum >= a and digit_sum <= b:
        result += i

print(result)



Measured memory_bytes: 2940
N,L = map(int,input().split())
taste = [L+k for k in range(N)]
min_t = abs(taste[0])
ind = 0
for i in range(N):
    x = abs(taste[i])
    if min_t > x:
        min_t = x
        ind = i
taste[ind] = 0
print(sum(taste))

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
l = [1]
for i in range(n + 1):
    s -= a[i]
    m = min(s, (l[i] - a[i]) * 2)
    if m < 0:
        print(-1)
        exit()
    l.append(m)
print(sum(l))

Measured memory_bytes: 20012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//__uint128_t
const ll MOD = 1e9+7;

int main(){
    ll N; cin >> N;
    vector<__uint128_t> V(N), W(N);
    for(int i = 0; i < N; i++) {
        ll x; cin >> x;
        V[i] = W[i] = x;

    }
    for(int i = N-2; i >= 0; i--) V[i] = V[i] + V[i+1];
    __uint128_t ans = 0;
    for(int i = 0; i < N-1; i++) {
        //ans = (ans + W[i] * V[i+1]) % MOD;
        ans += W[i] * V[i+1];
        ans %= MOD;
    }
    cout << (ll)ans << endl;

}

Measured memory_bytes: 9456
def main():
    count_max = 0
    count = 0
    s = input()
    for c in s:
        if c in "ATGC":
            count += 1
        else:
            count_max = max(count, count_max)
            count = 0

    count_max = max(count, count_max)

    print(count_max)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n,m = map(int,input().split())
ll = []
rr = []
for i in range(m):
  l,r = map(int,input().split())
  ll.append(l)
  rr.append(r)
p = min(rr) - max(ll) + 1
if p < 0:
  print(0)
else:
  print(p)

Measured memory_bytes: 10996
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	scn := newScanner()
	H := scn.nextInt()
	W := scn.nextInt()
	a := make([]string, 0)
	red := make([][]byte, 0)
	blue := make([][]byte, 0)
	for i := 0; i < H; i++ {
		s := scn.nextLine()
		a = append(a, s)
		red = append(red, []byte(s))
		blue = append(blue, []byte(s))
	}
	for j := 0; j < H; j++ {
		for k := 0; k < W; k++ {
			// red
			if j%2 == 0 {
				red[j][k] = '#'
			}
			// blue
			if j%2 != 0 {
				blue[j][k] = '#'
			}
		}
		red[j][0] = '#'
		red[j][W-1] = '.'
		blue[j][0] = '.'
		blue[j][W-1] = '#'
	}
	for i := 0; i < H; i++ {
		fmt.Println(string(red[i]))
	}
	fmt.Println("")
	for i := 0; i < H; i++ {
		fmt.Println(string(blue[i]))
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) nextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) nextInt() int {
	v, _ := strconv.Atoi(s.next())
	return v
}

func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 2816
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a-b>c) cout << 0 << endl;
    else cout << c-(a-b) << endl;
    return 0;
}


Measured memory_bytes: 3156
def RuinedSquare(x1 , y1 , x2 , y2):

    x3 = x2 - (y2 - y1)
    y3 = y2 + (x2 - x1)
    x4 = x1 - (y2 - y1)
    y4 = y1 + (x2 - x1)

    return str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4)

def main():
    x1 , y1 , x2 , y2 = map(int , input().split())
    print(RuinedSquare(x1 , y1 , x2 , y2))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(  a < b && b < c  ){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}


	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int H,W;
    cin>>H>>W;
    int ch,cw,dh,dw;
    cin>>ch>>cw>>dh>>dw;
    ch--;
    cw--;
    dh--;
    dw--;
    string S[H];
    rep(i,H){
        cin>>S[i];
    }

    int dp[H][W]{};
    rep(i,H){
        rep(j,W){
            dp[i][j]=-1;
        }
    }

    queue<pair<int,int>> q;
    queue<pair<int,int>> w;
    int worp=0;
    q.push(make_pair(ch,cw));
    dp[ch][cw]=0;

    do{
        while(!q.empty()){
            pair<int,int> v=q.front();
            q.pop();
            int x=v.first;
            int y=v.second;
            rep(i,4){
                int nx=x+dx[i];
                int ny=y+dy[i];
                if(nx<0||nx>=H||ny<0||ny>=W) continue;
                if(S[nx][ny]=='#')continue;
                if(dp[nx][ny]==-1){
                    q.push(make_pair(nx,ny));
                    dp[nx][ny]=worp;
                }
            }
            for(int i=-2;i<=2;i++){
                for(int j=-2;j<=2;j++){
                    int nx=x+i;
                    int ny=y+j;
                    if(nx<0||nx>=H||ny<0||ny>=W) continue;
                    if(S[nx][ny]=='#')continue;
                    if(dp[nx][ny]==-1){
                        w.push(make_pair(nx,ny));
                }
                }
            }
        }
        worp++;
        while(!w.empty()){
            pair<int,int> v=w.front();
            w.pop();
            int x=v.first;
            int y=v.second;
            if(dp[x][y]==-1){
                dp[x][y]=worp;
                q.push(make_pair(x,y));
            }
        }

    }while(!q.empty());

    cout<<dp[dh][dw] << endl;



}


Measured memory_bytes: 13048
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int N;
	int s[111];

	cin >> N;
	int sum = 0;
	for(int i = 0; i < N; i++){
		cin >> s[i];
		sum += s[i];
	}
	
	sort(s, s + N);

	if(sum % 10 == 0) {
		int tmp = -1;
		for(int i = 0; i < N; i++) {
			if(s[i] % 10 != 0) {
				tmp = s[i];
				break;
			}
		}
		if(tmp != -1) {
			sum -= tmp;
		}
	}
	
	cout << (sum % 10 ? sum : 0) << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int solve(int N, vi &A){
	map<int,int> F;
	rp(i,0,N){
		F[A[i]]++;
	}
	int ans = 0;
	for(auto f:F){
		// printf("v %d c %d\n",f.first, f.second);//
		ans += f.second%2? 1:0;
	}
	return ans;
}

int main(){
	int N; cin>>N;
	vi A(N);
	rp(i,0,N)cin>>A[i];
	ote(solve(N, A));
}


Measured memory_bytes: 5376
#include <stdio.h>
#include <string.h>
int c;
int main () {
  char a[300000],b[300000];
  scanf("%s%s",a,b);
  for(int i=0;i<strlen(a);i++) {
    if (a[i]!=b[i]) c++;
  }
  printf("%d",c);
}

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

int main() {
  int A, B;
  int num;
  int counter = 0;
  cin >> A >> B;
  for(int i = 0; i < B - A + 1; i++){
    num = A + i;
    if(num % 10 == num / 10000 && num / 10 % 10 == num / 1000 % 10) counter++;
  }
  cout << counter << endl;
}


Measured memory_bytes: 384
a = gets.chomp.split(" ").map(&:to_i)
t = gets.chomp.split(" ").map(&:to_i)

n = a[0]
T = a[1]
sum = 0

for i in 0..n-2
    if(t[i+1] - t[i] > T)
        sum += T
    else
        sum += t[i+1] - t[i]
    end
end

sum += T

print(sum)

Measured memory_bytes: 17924
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll i,j,m,n=0;
    cin>>m;
    for(i=1;;i++)
    {
        n+=i;
        if(n>=m)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;

class MainClass
{
    public static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int N = int.Parse(s[0]);
        int K = int.Parse(s[1]);
        int[] b = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderBy(x => x).ToArray();
        int[] a = new int[N+1];

        for (int i = 0; i < N;i++)
        {
            
            a[b[i]]++;
        }

        Array.Sort(a);
        Array.Reverse(a);
        int cnt = 0;
        int now = 0;
        int ans = 0;


        for (int i = K; i < N;i++)
        {
            ans += a[i];
        }
        //for (int i = 0; i < N;i++)
        //{
        //    if(now!=a[i])
        //    {
        //        cnt++;
        //        now = a[i];
        //    }

        //    if (cnt <= K) continue;

        //    ans++;

        //}

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 37956
from collections import deque

def solve():
    N = int(input())
    Ss = list(map(int, input().split()))

    Ss.sort(reverse=True)

    Qs = [deque() for _ in range(N+1)]
    Qs[0].append(10**10)

    for S in Ss:
        for day in range(N+1):
            if not Qs[day]: continue
            if Qs[day][0] > S:
                Qs[day].popleft()
                for d in range(day+1, N+1):
                    Qs[d].append(S)
                break
        else:
            return False

    return True


if solve():
    print('Yes')
else:
    print('No')


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

using namespace std;

int main(){
	string str; cin >> str;
	int k; cin >> k;
	int stlen = str.size();
	vector<int> len(stlen );
	for(int i = 0; i < stlen; ++i)
		len[i] = (int)('z' - str[i] +1);
	string ans = str;
	for(int i = 0; i < stlen; ++i){
		if(len[i] <= k && str[i] != 'a'){
			ans[i] = 'a';
			k -= len[i];
		}
	}
	if(k != 0){
		ans[stlen -1] = 'a' + (k + ans[stlen-1] - 'a') % 26;
	}
	cout << ans << endl; 
	return 0;
}


Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner((os.Stdin))

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

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c, x := nextInt(), nextInt(), nextInt(), nextInt()

	fmt.Printf("%d\n", ABC087B(a, b, c, x))
}

// ABC087B ...
func ABC087B(a, b, c, x int) int {
	res := 0
	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 {
					res++
				}
			}
		}
	}

	return res
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define END(a) {cout << (a) << "\n"; return 0;}
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(1); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    ll n; cin >> n;
    ll ans = n - 1;
    for (ll i = 1; i * i <= n; i++) {
        if (!(n % i)) {
            chmin(ans, i + n / i - 2);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
/** 
If comrades that you trust gather around you, hope can take physical form and become visible. That’s what I believe.
*/
#include <bits/stdc++.h>
using namespace std;
/**
(▀̿Ĺ̯▀̿ ̿) (ง ͠° ͟ل͜ ͡°)ง
*/
const int N = 2e3 + 7;
const int MOD = 1e9 + 7;

int f[N], p[N];

int add(int a, int b) {
    a += b;
    a %= MOD;
    return a;
}
auto solve() -> void {
    int s; cin >> s;
    if (s < 3) {
        cout << 0 << '\n';
        return;
    }

    for (int i = 1; i <= s; ++i) {
        if (i >= 3) {
            f[i] = 1;
            f[i] = add(f[i], p[i - 3]);
        }
        p[i] = add(p[i-1], f[i]);
    }
    cout << f[s] << '\n';

}
auto main() -> int {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int tc = 1;
    while (tc--) {
        solve();
    }
    
    return 0;
}


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

using namespace std;

const int N = 105, K = 1e5 + 5, MOD = 1e9 + 7;
int n, p, dp[N][K], prefix[N][K], a[N];

inline int add(int a, int b){
	a += b;
	if(a >= MOD)a -= MOD;
	return a;
}

inline int sub(int a, int b){
	a -= b;
	if(a < 0)a += MOD;
	return a;
}

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

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

	for(int i=0;i<=n;++i)dp[i][0] = prefix[i][0] = 1;
	for(int j=0;j<=p;++j)prefix[0][j] = 1;

	for(int i=1;i<=n;++i)
		for(int j=1;j<=p;++j){
			// coefficient of x^j is prefix[i - 1][j - a[i] : j];

			int first = (j - a[i] - 1 >= 0)? prefix[i - 1][j - a[i] - 1] : 0;
			int last = prefix[i - 1][j];
			dp[i][j] = add(dp[i][j], sub(last, first));
			prefix[i][j] = add(prefix[i][j - 1], dp[i][j]);
		}

	cout<<dp[n][p]<<"\n";
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

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

int n, p[200004], dp[200004]{}, ans = 0, pos[200004];

int main() {
    cin >> n;
    REP(i, n) {
        cin >> p[i];
        pos[p[i]] = i;
    }
    if(n==1){
        cout << 0 << endl;
        return 0;
    }
    dp[1] = 1;
    for (int i = 2; i <= n; i++) {
        dp[i] = 1;
        if (pos[i] > pos[i - 1]) dp[i] += dp[i - 1];
        ans = max(ans, dp[i]);
    }
    cout << n - ans << endl;
    return 0;
}

Measured memory_bytes: 2560