akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
long long rui(long long n, long long k, long long p) {
	if (k == 0) {
		return 1;
	}
	else {
		long long a = rui(n, k / 2, p);
		if (k % 2 == 0) {
			return (a*a) % p;
		}
		return (((a*a) % p)*n) % p;
	}
}
int main(){
	string s;
	cin >> s;
	if (s[0] == 'a') {
		cout << "square1001" << endl;
	}
	else {
		cout << "e869120" << endl;
	}
}


Measured memory_bytes: 3044
n = int(input())
a_list = list(map(int, input().split()))

dai = 0

for i in range(1, n):
    if a_list[i] < a_list[i-1]:
        dai += a_list[i-1] - a_list[i]
        a_list[i] += a_list[i-1] - a_list[i]
#        print(dai)
        
    else:
        continue

print(dai)

Measured memory_bytes: 32124
n = int(input())
a_n = list(map(int, input().split(" ")))


def is_dividable(l):
    for i in l:
        if not i % 2 == 0:
            return False
    else:
        return True


def divide(l):
    return [i/2 for i in l]


count = 0
while is_dividable(a_n):
    a_n = divide(a_n)
    count += 1

print(count)

Measured memory_bytes: 38640
loop do
  sigma = 0

  n = gets.to_i
    exit 0 if n == 0

  s = gets.split(" ").map{|x| x.to_i}
  for i in 0..(s.length - 1)
    sigma += (s[i] - (s.inject(:+).to_f / s.length)) ** 2
  end
  puts Math::sqrt(sigma / n)
end

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

using namespace std;

const int N = 2e5;
int n, m;
long long k, a[N + 1], b[N + 1];

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

    cin >> n >> m >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i + 1];
        a[i + 1] += a[i];
    }
    for (int j = 0; j < m; ++j) {
        cin >> b[j + 1];
        b[j + 1] += b[j];
    }
    int ans = 0;
    for (int i = 0, j = m; i < n + 1; ++i) {
        if (a[i] > k)
            break;
        while (a[i] + b[j] > k)
            --j;
        ans = max(i + j, ans);
    }
    cout << ans;

}

Measured memory_bytes: 6728
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
桁DPでいけそう
101桁まで
そうでもないかな･･･。
最後の端数が難しい
2500
2
2400
0025
0011

9999から
2501までをひく
それできるなら2500までだせるか
うーん
1999まで確定
2500まで最後まで個別判断とかややこしい
2がきたら候補
1以下はOK

5がきたら候補
1-9以下きたらOK
1999と2000-2500にわけるとかか

25だとして
　 [2 5]
  0 1 2
0 1 1 1             1
1 0 1 10//10 01-09  11//20
2 0 0 9//11-19      13//21-24

うーん･･･
n-1いれて9倍まではよくて
i-1]+1
i]+nとかかな

256
　 [2 5  6]
  0 1 2  3
0 1 1 1  1
1 0 2 11 20
2 0 0 14 113
3 0 0 0  123//14*9-3(987)

時間かかるけどDP例書かないとわからないぽんこつ

100
　 [1 0  0]
  0 1 2  3
0 1 1 1  1
1 0 1 10 19
2 0 0 0  81(101~109)
3 0 0 0  0//
これだめだ

120
　 [1 2  0]
  0 1 2  3
0 1 1 1  1
1 0 1 10 19
2 0 0 2  92
3 0 0 0  9//

1000
　 [1  0  0   0]
  0 1  2  3   4
0 1 1  1  1   1  
1 0 1 10 19  28
2 0 0  0 81 243 (-9はここ）
3 0 0  0  0 729
4 0 0  0  0   0
これだめだ

最後の桁前で、
1010
1011-1019を除く＝j=3
1010101=1010102~1010109=DP[i][4]-=8
*/
int main(){
  string S; cin>>S;
  ll K,ssz=S.size(), cnt=1;
  cin>>K;
  vector<vector<ll>> DP(110,vector<ll>(110,0));
  for(ll i=0; i<=ssz; i++) DP[i][0]=1;
  for(ll i=1; i<=ssz; i++){
    ll n=S[i-1]-'0';
    for(ll j=1; j<=i; j++){
      DP[i][j]=DP[i-1][j];//0がくる
      DP[i][j]+=DP[i-1][j-1]*9;//確定したやつに1-9
    }
    DP[i][cnt]-=9-n;
    if(n>0) cnt++;
  }
  cout<<DP[ssz][K]<<endl;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

int main(void){
    lli n;
    cin >> n;
    lli nrt = sqrt(n);
    lli a, b;
    for(lli i = nrt; i > 0; i--){
        if(n%i == 0){
            a = i;
            b = n/i;
            break;
        }
    }
    cout << a+b-2 << endl;
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int x; cin >> x;
    cout << (x<1200 ? "ABC" : "ARC") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    long long int n, W, mv = 0;
    long long int ans = 0;
    cin>>n>>W;
    vector<long long int> w(n+1), v(n+1);
    for(long long int i = 1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
        mv += v[i];
    }
    vector<vector<long long int>> dp(n+1, vector<long long int> (mv+1, INT_MAX));
    // dp[i][j] = minimum wieght to get a value of atleast J after using Ith stone
    for(int i = 0;i<=n;i++)
    {
        dp[i][0] = 0;
    }
    for(long long int i = 1;i<=n;i++)
    {
        for(long long int j = 1;j<=mv;j++)
        {
            // if(j == v[i])
            // {
            //     dp[i][j] = min(w[i], dp[i-1][j]);
            // }
            if(j - v[i] >= 0)
            {
                dp[i][j] = min(dp[i-1][j-v[i]] + w[i], dp[i-1][j]);
            }
            else
            {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    // for(int i = 0;i<=n;i++)
    // {
    //     for(int j = 0;j<=mv;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    for(long long int i = 1;i<=mv;i++)
    {
        if(dp[n][i] <= W)
        {
            ans = i;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 83092
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))
M = 2
dt = 1 / M
R = sum(T)

maxSpeeds = [10**18] * (R * M + 1)
now = 0
for t, v in zip(T, V):
    for i in range(t * M + 1):
        maxSpeeds[now + i] = min(maxSpeeds[now + i], v)
    now += t * M

maxSpeeds[0] = 0
maxSpeeds[-1] = 0
for t in range(1, R * M + 1):
    maxSpeeds[t] = min(maxSpeeds[t - 1] + dt, maxSpeeds[t])
    maxSpeeds[-(t + 1)] = min(maxSpeeds[-t] + dt, maxSpeeds[-(t + 1)])

ans = 0
for l, r in zip(maxSpeeds, maxSpeeds[1:]):
    ans += (l + r) / M / 2
print(ans)

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

using namespace std;

int main(void){

    int n;
    cin >> n;
    vector<int> counts(100000);
    for(int i=0; i<n; i++) counts[i]=0;
    for(int i=0; i<n; i++) {
        int temp;
        cin >> temp;
        counts[temp]++;
    }
    
    int result = 0;
    for(int i=1; i<100000-1; i++) {
        int temp = 0;
        temp = counts[i-1] + counts[i] + counts[i+1];
        if(temp>result) result = temp;
    }

    cout << result << endl;

    return 0;
    
}


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  vector<int> a(3);for(int i=0;i<3;i++)cin>>a[i];
  sort(a.begin(), a.end());
  int res=1000000;
  res=min(res, abs(a[0]-a[1]) + abs(a[1]-a[2]));
  res=min(res, abs(a[1]-a[0]) + abs(a[0]-a[2]));
  res=min(res, abs(a[2]-a[0]) + abs(a[0]-a[1]));
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 
ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans;
ll a,b,c,d,e,h,w;
 
ll z[500005];
ll u[500005];
bool check[500005];
ll amari;
ll dp[305][305];
ll co[505][505];
ll iro[4][305];

int main(){
    cin>>n>>c;
	for(i=1;i<=c;i++){
		for(j=1;j<=c;j++){
			cin>>dp[i][j];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			cin>>co[i][j];
			iro[(i+j)%3][co[i][j]]++;
		}
	}
	ans = INF;
	for(i=1;i<=c;i++){
		for(j=1;j<=c;j++){
			for(k=1;k<=c;k++){
				if(i==j || j==k || k==i)continue;
				num = 0;
				for(a=1;a<=c;a++){
					//0 -> i
					//1 -> j
					//2 -> k
					num += iro[0][a] * dp[a][i];
					num += iro[1][a] * dp[a][j];
					num += iro[2][a] * dp[a][k];
				}
				ans = min(ans,num);
			}
		}
	}
	p(ans);
	
	
	return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    int n,a;
    cin >> n;
    a=n;
    int c=0;
    while(a!=0){
        a/=10;
        c++;
    }
    if(c==1) print(n);
    if(c==2) print(9);
    if(c==3) print(n-90);
    if(c==4) print(909);
    if(c==5) print(n-9090);
    if(c==6) print(90909);
    return 0;
}

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

int f(unsigned long A, unsigned long B) { return log10(max(A, B)) + 1; }

int main() {
  unsigned long N;
  cin >> N;

  int min_f = INT_MAX;

  for (unsigned long i = 1; i <= sqrt(N); i++) {
    unsigned long A = i;
    if (N % i != 0) continue;
    unsigned long B = N / i;
    min_f = min(min_f, f(A, B));
  }

  cout << min_f << endl;
}

Measured memory_bytes: 3912
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def isOK(A):
    A.sort()
    for i in range(len(A) - 1):
        if A[i] + 1 != A[i + 1]:
            return False
    return True


def solve():
    N, K = Scanner.map_int()
    print(min(N % K, K - N % K))


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


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

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

    if(a>=3200)cout << s << endl;
    else cout << "red" << endl;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }
    val uf = UnionFind(n)

    repeat(q) {
        val (t, u, v) = readLine()!!.split(" ").map { it.toInt() }

        if (t == 0) {
            uf.merge(u, v)
        } else {
            println(if (uf.isSame(u, v)) 1 else 0)
        }
    }
}

// Union Find
// NOTE: initSize is the number of elements
private data class UnionFind(val initSize: Int) {
    private val parents = IntArray(this.initSize) { it }
    private val sizes = LongArray(this.initSize) { 1L }

    fun root(idx: Int): Int {
        if (idx == parents[idx]) return idx

        val rootP = root(parents[idx])
        parents[idx] = rootP
        return rootP
    }

    // NOTE: merge to the larger group
    fun merge(p1: Int, p2: Int) {
        if (this.isSame(p1, p2)) return

        val rootP1 = root(p1)
        val rootP2 = root(p2)

        if (this.sizes[rootP1] >= this.sizes[rootP2]) {
            this.sizes[rootP1] += this.sizes[rootP2]
            this.parents[rootP2] = this.parents[rootP1]
        } else {
            this.sizes[rootP2] += this.sizes[rootP1]
            this.parents[rootP1] = this.parents[rootP2]
        }
    }

    fun isSame(p1: Int, p2: Int): Boolean {
        return this.root(p1) == this.root(p2)
    }

    fun size(idx: Int): Long {
        return this.sizes[this.root(idx)]
    }
}

Measured memory_bytes: 65948
def func():
  ABCD = list(input())
  A = int(ABCD[0])
  B = int(ABCD[1])
  C = int(ABCD[2])
  D = int(ABCD[3])
  for a in range(2):
    for b in range(2):
      for c in range(2):
        sum_ = A
        text = str(A)

        if a == 0:
          sum_ += B
          text = text + "+"
        else:
          sum_ -= B
          text = text + "-"
        text = text + str(B)

        if b == 0:
          sum_ += C
          text = text + "+"
        else:
          sum_ -= C
          text = text + "-"
        text = text + str(C)

        if c == 0:
          sum_ += D
          text = text + "+"
        else:
          sum_ -= D
          text = text + "-"
        text = text + str(D)

        if sum_ == 7:
          return text + "=7"
print(func())
        
      


Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n;
string s, t;

int main(){
	cin >> n;
	cin >> s >> t;
	
	for(int i = 0; i < n; i++){
		cout << s[i] << t[i];
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
char s[10005];
int dp[10005][105];
int d, n;
int dfs(int i, int rem, bool check){
    if(i == n+1){
        if(rem == 0) return 1;
        return 0;
    }

    if(!check && dp[i][rem] != -1) return dp[i][rem];
    int l = 9;
    if(check) l = s[i]-'0';

    int ans = 0;
    for(int j=0;j<=l;j++){
        if(check && j == l) ans = (ans + dfs(i+1, (rem+j)%d, 1))%mod;
        else ans = (ans + dfs(i+1, (rem+j)%d, 0))%mod;
    }
    if(!check) dp[i][rem] = ans;
    return ans;
}
int main(){
    memset(dp, -1, sizeof(dp));
    scanf("%s%d", s+1, &d);
    n = strlen(s+1);
    printf("%d\n", (dfs(1, 0, 1)-1+mod)%mod);
}


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

using namespace std;

string s,t;

int m,n;

int f[5555][5555];

int F(int x, int y)
{
  if (x < 1 || y < 1) return 0;
  if (f[x][y]>-1)
    return f[x][y];
  if (s[x] == t[y])
  {
    f[x][y] = 1 + F(x-1,y-1);
  }
  else
  {
    f[x][y] = max(F(x,y-1), F(x-1,y));
  }
  return f[x][y];

}

int main()
{
    cin >> s>> t;
    m = s.size(); n = t.size();
    s = "%" + s;
    t = "#" + t;
    for (int i=0; i<=m; i++)
    {
        for (int j=0; j<=n; j++)
        {
            f[i][j] = -1;
        }
    }
    F(m,n);
    string r = "";
    int x = m, y = n;
    while (x >= 1 && y >= 1)
    {
        while (f[x-1][y] == f[x][y] || f[x][y-1] == f[x][y])
        {
            while (x > 0 && f[x-1][y] == f[x][y]) x--;
            while (y > 0 && f[x][y-1] == f[x][y]) y--;
            if (x < 1 || y < 1) break;
        }
        if (x <1 || y < 1) break;
        if (f[x][y] == 0)
            break;
        r = s[x] + r;
        x--;y--;

    }
    cout << r;
  	return 0;
}


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


using namespace std;

int main(){

    ll n,k;
    cin >> n >> k;
    
    vector<int> digit(45);
    vector<ll> a;

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

        rep(j,45){
            if(tmp & (ll)1<<j) digit[44 - j]++;
        }
        a.pback(tmp);
    }

    rep(i, 45) cerr << digit[i] << " ";
    cerr << endl;

    ll x = 0;

    for(int i = 44; i >= 0; i--){
        ll tmp = x;
        if(digit[44 - i] < (n + 1) / 2){
            tmp = tmp + ((ll)1<<i);
            if(tmp <= k){

                x = tmp;
                cerr << i << " " << x << endl;
            }
        }
    }
    
    cerr << x << endl;

    ll ans = 0;

    rep(i,n){
        ans = ans + (a[i] xor x);
    }

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

Measured memory_bytes: 1400
import sys

S = input()
for i in range(len(S) + 1):
    for j in range(i, len(S) + 1):
        erased = S[:i] + S[j:]
        # print(i, j, erased)
        if erased == "keyence":
            print("YES")
            sys.exit()
print("NO")




Measured memory_bytes: 9004
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private int kyotu(String a, String b) {
		Set<Character> ac = new HashSet<>();
		for (char c : a.toCharArray()) {
			ac.add(c);
		}
		Set<Character> bc = new HashSet<>();
		for (char c : b.toCharArray()) {
			bc.add(c);
		}

		ac.retainAll(bc);

		return ac.size();

	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		String S = sc.next();
		sc.close();

		int ans = 0;
		for (int i = 2; i < N; i++) {
			String a = S.substring(0, i);
			String b = S.substring(i);

			ans = Math.max(ans, kyotu(a, b));
		}
		out.println(ans);

	}

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


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
 
int main(){
    ll x; cin >> x;
    if(x==7||x==5||x==3) puts("YES");
    else puts("NO");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N,K;
P B[200005];
ll calc(ll skip,ll m){
	ll ret=1;
	for(ll i=N-1; i>=N-K; i--){
    ll mul;
    if(i==skip){
        mul=B[m].first;
        if(B[m].second==-1) mul=-mul+mod;
    }
    else{
        mul=B[i].first;
        if(B[i].second==-1) mul=-mul+mod;
    }
    ret=ret*mul%mod;
    }
    return ret;
}
int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>K;
bool neg=true;
rep(i,N){
    ll a;
    cin>>a;
    if(a>0){
        B[i].first=a;
        B[i].second=1;
        neg=false;
    }
    if(a==0){
        B[i].first=a;
        B[i].second=0;
        neg=false;
    }
    if(a<0){
        B[i].first=-a;
        B[i].second=-1;
    }
}
sort(B,B+N);
if(neg&&K%2==1){
    ll ans=1;
    rep(i,K) ans=ans*(mod-B[i].first)%mod;
    cout<<ans<<endl;
    exit(0);
}
bool zero=false;
ll ncnt=0;
for(ll i=N-1; i>=N-K; i--){
    if(B[i].second<0) ncnt++;
    if(B[i].second==0) zero=true;
}
if(N==K||ncnt%2==0||zero){
    ll ans=1;
    for(ll i=N-1; i>=N-K; i--){
        if(B[i].second>=0) ans=ans*B[i].first%mod;
        else ans=ans*(mod-B[i].first)%mod;
    }
    cout<<ans<<endl;
    exit(0);
}
ll p1=INF;
ll n1=INF;
ll p2=INF;
ll n2=INF;
for(ll i=N-1; i>=N-K; i--){
    if(B[i].second==-1) n1=i;
    if(B[i].second==1) p1=i;
}
rep(i,N-K){
    if(B[i].second>=0) p2=i;
    if(B[i].second==-1) n2=i;
}
if(p2==INF){
    cout<<calc(p1,n2)<<endl;
}
else if(n2==INF||p1==INF){
    cout<<calc(n1,p2)<<endl;
}
else{
    if(B[p1].first*B[p2].first>=B[n1].first*B[n2].first){
        cout<<calc(n1,p2)<<endl;
    }else{
        cout<<calc(p1,n2)<<endl;
    }
}
 
}
    


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var n = nk[0];
            var k = nk[1];

            var maxNum = k - 1;
            var result = 1;
            while (true)
            {
                var pow = (int) Math.Pow(k, result - 1) * maxNum;
                if (pow < n)
                {
                    result++;
                    n -= pow;
                }
                else
                {
                    break;
                }
            }
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 28628
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = 3e18;
const int inf = (1<<29);

int main() {

    int n;
    cin >> n;
    vector<ll> a(n);
    bool zero = 0;
    REP(i, n) {
        cin >> a[i];
        if (a[i] == 0) zero = 1;
    }

    if (zero) {
        cout << 0 << endl;
        return 0;
    }
    
    ll res = 1;
    for(int i = 0; i < n; i++) {
        if (res > INF/a[i]) {
            cout << -1 << endl;
            return 0;
        } else {
            res *= a[i];
        }
        
    }

    if(res > ll(1e18)) cout << -1 << endl;
    else cout << res << endl;

    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int G1[7] = { 1, 3, 5, 7, 8, 10, 12 };
int G2[4] = { 4, 6, 9, 11 };

int main()
{
	int x, y;
	int grp_x = 3, grp_y = 3;
	cin >> x >> y;

	rep(i, 7) {
		if (G1[i] == x) grp_x = 1;
		if (G1[i] == y) grp_y = 1;
	}
	rep(i, 4) {
		if (G2[i] == x) grp_x = 2;
		if (G2[i] == y) grp_y = 2;
	}
	if (grp_x == grp_y) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;
ll p[100100], q[100100], r[100100];
ll d[1001001];
int main(int argc, char const *argv[]) {
    ll x, y, a, b, c;
    ll ans=0;
    bool flg=true;
    cin >> x >> y >> a >> b >>c ;
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
    for(int i=0;i<b;i++){
        cin >> q[i];
    }
    for(int i=0;i<c;i++){
        cin >> r[i];
    }
    sort(p, p+a, greater<ll>());
    sort(q, q+b, greater<ll>());
    sort(r, r+c, greater<ll>());
    int i=x-1, j=y-1;
    int idx=0;
    while(flg){
        if(i<0&&j<0){
            flg=false;
        }else if(i<0){
            if(r[idx]>q[j]){
                q[j]=r[idx];
                j--;
                idx++;
            }else{
                flg=false;
            }
        }else if(j<0){
            if(r[idx]>p[i]){
                p[i]=r[idx];
                i--;
                idx++;
            }else{
                flg=false;
            }
        }else if(p[i]<q[j]){
            if(r[idx]>p[i]){
                p[i]=r[idx];
                i--;
                idx++;
            }else if(r[idx]>q[j]){
                q[j]=r[idx];
                j--;
                idx++;
            }else{
                flg=false;
            }
        }else{
            if(r[idx]>q[j]){
                q[j]=r[idx];
                j--;
                idx++;
            }else if(r[idx]>p[i]){
                p[i] = r[idx];
                i--;
                idx++;
            }else{
                flg=false;
            }
        }
    }
    for(int w=0;w<x;w++){
        ans+=p[w];
    }
    for(int w=0;w<y;w++){
        ans+=q[w];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int n;
    cin >> n;
    long long S = 0;
    map<ll, ll> memo;
    rep(i, 0, n) {
        ll x;
        cin >> x;
        S += x;
        memo[x]++;
    }
    int q;
    cin >> q;
    rep(i,0,q) {
        ll b, c;
        cin >> b >> c;
        ll qnt = memo[b];
        S -= (qnt * b);
        memo[b] = 0;
        S += (qnt * c);
        memo[c] += qnt;
        cout << S << '\n';
    }
    return 0;
}



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

int main() {
	int n;
	int discount=0;
	int paid=0;
	cin>>n;
	paid = n*800;	
	while(n-15>=0){
		n=n-15;
		discount = discount + 200;
	}
	paid = paid - discount;
	cout<<paid<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define append push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define pb push_back
#define print(a) cout<<a<<endl
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define all(x) x.begin(), x.end()
#define loop(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;
void solve(int);
signed main(){

	int i=1,t = 1;
	//cin>> t;
	while(i<=t){
		solve(i++);
	}

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
vector< pair<int,int> > graph[100001];
int vis[100001];

void dfs(int u,int c)
{
	if(vis[u]>=0)
		return;
	vis[u]=c;
	for(auto x:graph[u])
	{
		if(x.S%2==0)
			dfs(x.F,c);
		else
			dfs(x.F,c^1);
	}
}
void solve(int tcnum)
{
	mem(vis,-1);
	int n;	
	cin>>n;
	loop(i,n-1)
	{
		int x,y,w;
		cin>>x>>y>>w;
		graph[x].pb({y,w});
		graph[y].pb({x,w});		
	}
	dfs(1,0);
	loop(i,n)
		cout<<vis[i+1]<<"\n";
}







Measured memory_bytes: 8448
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b, c,d; cin >> a >> b >> c;
	if (a + b >= c) cout << "Yes";
	else cout << "No";


	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

const ll mod = static_cast<ll>(1e9) + 7;

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

    vector<ll> A(N);
    for (auto& a : A) { cin >> a; }

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

    ll x = -1, y = -1, z = -1;
    ll xn = 0, yn = 0, zn = 0;

    bool ok = true;

    for (const auto& a : A)
    {
        if (x == -1 || x == a)
        {
            x = a;
            ++xn;
        }
        else if (y == -1 || y == a)
        {
            y = a;
            ++yn;
        }
        else if (z == -1 || z == a)
        {
            z = a;
            ++zn;
        }
        else
        {
            ok = false;
        }
    }

    // 全部 0 パターン
    if (x == 0 && xn == N)
    {
        cout << "Yes" << endl;
        return 0;
    }

    // X 0 X 0 X or X 0 X X 0 X のパターン
    if (x == 0 && yn != -1 && z == -1 && (xn + 1 == yn || xn * 2 == yn || xn * 2 + 1 == yn))
    {
        cout << "Yes" << endl;
        return 0;
    }

    // 他に 0 があるとダメ
    if (x == 0)
    {
        cout << "No" << endl;
        return 0;
    }

    // 3種類の数字を使っているかどうか
    if (x == -1 || y == -1 || z == -1)
    {
        ok = false;
    }

    // 3種類の数字の出現頻度が同じかどうか
    if (!(xn == yn && yn == zn))
    {
        ok = false;
    }

    if (!((x ^ z) == y && (y ^ x) == z && (z ^ y) == x))
    {
        ok = false;
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;
using P3 = std::tuple<int,int,int>;

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

int N;
vector<P3> v;

set<int> s;
priority_queue<int, vector<int>, greater<int> > pq;

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        int x, y;
        std::cin >> x >> y;

        v.emplace_back(x, y, 0);
    }

    for(int i=0;i<N;++i){
        int x, y;
        std::cin >> x >> y;

        v.emplace_back(x, y, 1);        
    }

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

    // for(int i=0;i<2*N;++i){
    //     int x, y, c;
    //     tie(x, y, c) = v[i];

    //     std::cout << x << ", " << y << ", " << c << std::endl;
    // }

    int res = 0;
    for(int i=0,j=0;i<2*N;i=j){
        while(j < 2*N && thd(v[j]) == 0){
            s.emplace(-snd(v[j]));
            ++j;
        }

        while(j < 2*N && thd(v[j]) == 1){
            int x = -snd(v[j]);
            auto it = s.lower_bound(x);
            if(it != s.end()){
                ++res;
                s.erase(it);
            }
            
            ++j;
        }
    }

    std::cout << res << std::endl;
}


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

using namespace std;

int n,dp[50];

int fib(int n)
{
    if(n==0||n==1){
        return dp[n]=1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    return dp[n]=fib(n-1)+fib(n-2);
}

int main()
{
    for(int i=0;i<50;i++){
        dp[i]=-1;
    }
    scanf("%d",&n);
    printf("%d\n",fib(n));
    return 0;
}


Measured memory_bytes: 3216
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let nw: Vec<usize> = read_vec();
    let n = nw[0];
    let w = nw[1] as u64;
    let mut wvv: Vec<Vec<u64>> = read_vec2(n);
    let w0 = wvv[0][0];
    for i in 0..n {
        wvv[i][0] -= w0;
    }
    wvv.sort_by(|x, y| y[1].partial_cmp(&x[1]).unwrap());
    let mut vv: Vec<Vec<u64>> = vec![vec![0]; 4];
    for i in 0..n {
        vv[wvv[i][0] as usize].push(wvv[i][1]);
    }

    let mut ans = 0;
    let mut tmpv: Vec<u64> = vec![0; 4];
    tmpv[0] = 0;
    let mut tmpw: Vec<u64> = vec![0; 4];
    tmpw[0] = 0;
    for i0 in 0..vv[0].len() {
        tmpv[0] += vv[0][i0];
        tmpv[1] = 0;
        tmpw[1] = 0;
        for i1 in 0..vv[1].len() {
            tmpv[1] += vv[1][i1];
            tmpv[2] = 0;
            tmpw[2] = 0;
            for i2 in 0..vv[2].len() {
                tmpv[2] += vv[2][i2];
                tmpv[3] = 0;
                tmpw[3] = 0;
                for i3 in 0..vv[3].len() {
                    tmpv[3] += vv[3][i3];

                    let tw = tmpw[0] + tmpw[1] + tmpw[2] + tmpw[3];
                    let tv = tmpv[0] + tmpv[1] + tmpv[2] + tmpv[3];

                    if tw <= w && ans < tv {
                        ans = tv;
                    }

                    tmpw[3] += w0 + 3;
                }
                tmpw[2] += w0 + 2;
            }
            tmpw[1] += w0 + 1;
        }
        tmpw[0] += w0;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import bisect

n = int(input())
a = [int(i) for i in input().split()]

target = 0
l = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199]
cnt = [0 for i in range(len(l))]

for i in range(n):
    if a[i] >= 3200:
        target += 1
    else:
        x = bisect.bisect_left(l, a[i])
        # print ("value = " + str(a[i]) + ", x = " + str(x))
        cnt[x] += 1

mi = 0
ma = 0
for i in range(len(l)):
    if cnt[i] != 0:
        mi += 1

ma = mi + target
if mi == 0:
    mi = 1

print (str(mi) + " " + str(ma))

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

struct SegmentTree_max {
  vector< int > st;
  int N, IVAL;
  SegmentTree_max(int n, int ival = 0) {
    N = 1; IVAL = ival;
    while (N < n) N *= 2;
    st.resize(2*N-1);
    REP(i,N) st[i] = IVAL;
  }
  void add( int i, int val ) {
    i = i + N-1;
    st[i] = val;
    while( i > 0 ) {
      i = (i-1)/2;
      st[i] = max(st[i], val);
    }
  }
  int get( int a, int b, int i, int l, int r ) {
    if ( (b <= l) || (r <= a) ) return IVAL;
    if ( (a <= l) && (r <= b) ) return st[i];
    int lv = get(a,b, i*2+1, l, (l+r)/2 );
    int rv = get(a,b, i*2+2, (l+r)/2, r );
    return max(lv,rv);
  }
  int getN() { return N; }
  void disp() {
    int i = 1, m=0;
    while (1<<(i-1) <= N) {
      REP(j, 1<<(i-1))
        cout << st[m++] << " ";
      cout << endl;
      i++;
    }
  }
};
struct SegmentTree_min {
  vector< int > st;
  int N, IVAL;
  SegmentTree_min(int n, int ival = 10000000) {
    N = 1; IVAL = ival;
    while (N < n) N *= 2;
    st.resize(2*N-1);
    REP(i,N) st[i] = IVAL;
  }
  void add( int i, int val ) {
    i = i + N-1;
    st[i] = val;
    while( i > 0 ) {
      i = (i-1)/2;
      st[i] = min(st[i], val);
    }
  }
  int get( int a, int b, int i, int l, int r ) {
    if ( (b <= l) || (r <= a) ) return IVAL;
    if ( (a <= l) && (r <= b) ) return st[i];
    int lv = get(a,b, i*2+1, l, (l+r)/2 );
    int rv = get(a,b, i*2+2, (l+r)/2, r );
    return min(lv,rv);
  }
  int getN() { return N; }
  void disp() {
    int i = 1, m=0;
    while (1<<(i-1) <= N) {
      REP(j, 1<<(i-1))
        cout << st[m++] << " ";
      cout << endl;
      i++;
    }
  }
};


int main() {
  int N,K;
  cin >> N >> K;
  vector< int > P(N);
  vector< bool > s(N, true);
  SegmentTree_max stmax(N);
  SegmentTree_min stmin(N);
  REP(i,N) {
    cin >> P[i];
    stmax.add(i,P[i]);
    stmin.add(i,P[i]);
  }
  int ans = 1;
  // K個が昇順かを調べておく
  int cnt = 1;
  REP(i,N-1) {
    if ( P[i] <= P[i+1] ) cnt++;
    else cnt = 1;
    if ( i - (K-2) >= 0 ) {
      if (cnt >= K) s[i-(K-2)] = true;
      else s[i-(K-2)] = false;
    }
  }
  bool flg = false;
  if ( s[0] ) flg = true;
  REP(i,N-K) {
    int ma = stmax.get(i,i+K+1,0,0,stmax.getN());
    int mi = stmin.get(i,i+K+1,0,0,stmax.getN());
//    cout << i << " : " << ma << " " << mi << endl;
    if ( (P[i] == mi) && (P[i+K] == ma) ) continue;
    if ( s[i+1] ) {
      if ( flg ) continue;
      else flg = true;
    }
    ans++;
  }
  cout << ans << endl;
//  stmax.disp();
//  stmin.disp();
}




Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n;
	vi d(n);
	REP(i, n) cin >> d[i];
	int ans = MOD;
	for (int i = -100; i <= 100; i++) {
		int sum = 0;
		for (int x : d) {
			sum += (x - i) * (x - i);
		}
		chmin(ans, sum);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

MOD = 1000000007

n,m = get_nums_l()
breaks = map(int, sys.stdin.readlines())

dp = [0] * (n+1)

for a in breaks:
    dp[a] = -1

dp[n] = 1

for i in range(n-1, -1, -1):
    if dp[i] == -1:
        continue
    
    x = 0
    if dp[i+1] != -1:
        x += dp[i+1]
    
    if i <= (n-2) and dp[i+2] != -1:
        x += dp[i+2]
    
    dp[i] = x % MOD

print(dp[0])

Measured memory_bytes: 52316
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
   string s;
   map<int,int>mp;
   set<int>st;
   cin>>s;
   for(int i=0;i<s.length();i++)
   {

       st.insert(s[i]);
       mp[s[i]]++;
   }
   for(auto it:st)
   {
       if(mp[it]%2)
       {
           cout<<"No"<<endl;
           return 0;
       }
   }
   cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 3560
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(){
  char s[100],p[100];
  int i,k,n,cnt=0,t=0,lens,lenp;
  scanf("%s %s",s,p);
  lens=strlen(s);
  lenp=strlen(p);
  for(i=0;i<lens;i++){
    cnt=0;
    if(s[i]==p[0]){
      cnt++;
      for(k=1;k<lenp;k++){
        if(p[k]==s[(i+k)%lens]){
          cnt++;
        }
      }
      if(cnt==lenp)t++;
    }
  }
  if(t>=1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
}

Measured memory_bytes: 2664
#include<bits/stdc++.h>
#define LL long long
#define MAXN 300005
#define INF (1<<25)
#define P int(1e9+7)
using namespace std;

int N;
int a[MAXN];

LL cal(int y){
	LL ans = 0;
	for(int i=1;i<=N;i++){
		ans += (a[i]-y)*(a[i]-y);
	}
	return ans;
}

int main(){
	
	ios::sync_with_stdio(0);
	
	cin>>N;
	
	
	for(int i=1;i<=N;i++){
		cin>>a[i];
	}
	
	sort(a+1,a+1+N);
	
	int y;
	if(N%2==0){
		y = (a[N/2+1] + a[N/2])/2;
	}
	else{
		y = a[N/2+1];
	}
	
	LL ans = 1e9;
	for(int i=-100;i<=100;i++){
		ans = min(ans, cal(i));
	}
	
	//ans = min(min(cal(y-1), cal(y+1)), cal(y));
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
from fractions import gcd

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


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


def main():
    N, M = map(int, input().split())
    S = input()
    T = input()
    L = M // gcd(M, N) * N
    G = gcd(M, N)
    n = N // G
    m = M // G

    for i in range(G):
        if S[n * i] == T[m * i]:
            continue
        else:
            print(-1)
            return

    print(L)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5560