akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
 
double solve(int x,int y, int z, int &n){

    if(x<0 || y<0 || z<0){
        return 0;

    }

    if(dp[x][y][z]>-0.9){
        return dp[x][y][z];
    }

    if(x==0 && y==0 && z==0){
        return 0;

    }

    double exp=n+x*solve(x-1,y,z,n)+y*solve(x+1,y-1,z,n)+z*solve(x,y+1,z-1,n);

    return dp[x][y][z]=(exp)/(x+y+z);





}

int main() {
    int n;
    cin>>n;
    int one=0,two=0,three=0;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x==1){
            one++;
        }else if(x==2){
            two++;
        }else if(x==3){
            three++;

        }
    }

    cout<<fixed<<setprecision(10)<<solve(one,two,three,n);






}


Measured memory_bytes: 216868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,p,Q;

ll calc(ll a,ll l,ll n){return (a+l)*n/2;}

int main(){
  cin>>n>>p>>Q;
  vector<ll> V;
  
  for(int i=0;i<n;i++){
    ll C;
    cin>>C;
    V.push_back(C-p*(Q+i)-2*p*(n-i-1));
  }

  sort(V.begin(),V.end(),greater<ll>());
  ll sum = p*calc(Q,Q+n-1,n);
  ll ans = sum;
  for(int i=0;i<n;i++){
    sum += V[i]+ 2*p*i ;
    ans =max(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n, q;
vector<llong> vt;
vector<pll> pv[100001];

int find(llong x) {
    return lower_bound(vt.begin(), vt.end(), x) - vt.begin();
}

void compress(vector<pll> &v) {
    sort(v.begin(), v.end());
    int i = 0;
    for (int j = 1; j < v.size(); ++j) {
        if (v[i].first == v[j].first) v[i].second += v[j].second;
        else v[++i] = v[j];
    }
    v.resize(i + 1);
}

llong sum[100001];
int main() {
    scanf("%d%d", &n, &q);
    llong x;
    vt.push_back(n);
    for (int i = 0; i < q; ++i) {
        scanf("%lld", &x);
        while (!vt.empty() && x <= vt.back()) vt.pop_back();
        vt.push_back(x);
    }
    pv[vt.size() - 1].emplace_back(vt.back(), 1);
    for (int i = vt.size(); --i; ) {
        if (pv[i].empty()) continue;
        compress(pv[i]);
        for (pll j : pv[i]) {
            llong cnt = j.first / vt[i - 1];
            llong res = j.first - cnt * vt[i - 1];
            pv[i - 1].emplace_back(vt[i - 1], cnt * j.second);
            pv[find(res)].emplace_back(res, j.second);
        }
    }
    
    for (pll i : pv[0]) {
        sum[i.first] += i.second;
    }
    for (int i = n; --i; ) sum[i] += sum[i + 1];
    for (int i = 1; i <= n; ++i) printf("%lld\n", sum[i]);
	return 0;
}


Measured memory_bytes: 23668
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

struct hako {
	int tate;
	int yoko;
};
bool biggerthan(hako a, hako b) {
	int a2 = (a.tate)*(a.tate) + (a.yoko)*(a.yoko);
	int b2 = (b.tate)*(b.tate) + (b.yoko)*(b.yoko);
	if (a2 != b2) return a2 > b2;
	return a.tate > b.tate;
}
bool smallerthan(hako b, hako a) {
	int a2 = (a.tate) * (a.tate) + (a.yoko) * (a.yoko);
	int b2 = (b.tate) * (b.tate) + (b.yoko) * (b.yoko);
	if (a2 != b2) return a2 > b2;
	return a.tate > b.tate;
}
int main() {
	hako inp;
	hako hyouka;
	int a, b;
	int n, count;
	int resulttate[200] = {};
	int resultyoko[200] = {};
	hako tmp[30000];
	int nanko;
	for (count = 0; true; count++) {
		
		cin >> a >> b;
		inp.tate = a;
		inp.yoko = b;
		nanko = 0;
		if (a == 0 && b == 0) break;
		for (int i = 2; i < 150; i++) {
			for (int j = i-1; j > 0; j--) {
				hyouka.tate = j;
				hyouka.yoko = i;
				if (biggerthan(hyouka, inp)) {
					tmp[nanko].tate = j;
					tmp[nanko].yoko = i;
					nanko++;
				}
			}
		}
		sort(tmp, tmp + nanko, smallerthan);
			resulttate[count] = tmp[0].tate;
			resultyoko[count] = tmp[0].yoko;
	}
	for (int i = 0; i < count; i++) {
		cout << resulttate[i] << " " << resultyoko[i] << endl;
	}
}
	/*
	int n;
	long long int sumer = 0;
	int temp;
	int ave;
	int data[60000];
	int result[60000] = {};
	int count;
	for (count = 0; true; count++) {
		cin >> n;
		sumer = 0;
		temp = 0;
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			cin >> temp;
			data[i] = temp;
			sumer += temp;
		}
		ave = sumer / n;
		for (int i = 0; i < n; i++) {
			if (data[i] <= ave) {
				result[count]++;
			}
		}
		
	}
	for (int i = 0; i < count; i++) {
		cout << result[i] << endl;
	}
	return 0;
}
/*
//単一連結リストの実装
struct ListNode {
	int data;
	struct ListNode* next;
};*//*
int ListLength(struct ListNode* head) {
	struct ListNode* current = head;
	int count = 0;
	while (current != NULL) {
		count++;
		current = current -> next;
	}
	return count;
}


int main()
{
	int n = 0;
	int owari = 11451414;
	int result[50010] = {};
	int sa = owari;
	int count = 0;
	while (true) {
		int dataset[50010];
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			cin >> dataset[i];
		}
		sort(dataset, dataset + n);
		sa = owari;
		for (int i = 1; i < n; i++) {
			if (abs(dataset[i] - dataset[i - 1]) < sa) {
				sa = abs(dataset[i] - dataset[i - 1]);
			}
		}
		result[count] = sa;
		count++;
	}
	for (int i = 0; i < count; i++) {
		cout << result[i] << endl;
	}
	return 0;
}
*/


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

typedef pair<int64_t, int64_t> P;
const int64_t INF = 1e18;

vector<int64_t> dijkstra(int N, int s, vector<P> edges[]){
    vector<int64_t> dist(N, INF);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, s});
    while(que.size()){
        auto p = que.top(); que.pop();
        int i = p.second;
        int64_t d = p.first;
        if(d > dist[i]) continue;
        for(auto& e : edges[i]){
            int j = e.first;
            int64_t d2 = d + e.second;
            if(d2 < dist[j]){
                dist[j] = d2;
                que.push({d2, j});
            }
        }
    }
    return dist;
}

int main(){
    int K;
    cin >> K;
    vector<P> edges[100000];
    for(int i=1; i<K; i++){
        edges[i].emplace_back((i+1)%K, 1);
        edges[i].emplace_back(10*i%K, 0);
    }
    auto dist = dijkstra(K, 1, edges);
    cout << dist[0]+1 << endl;
}

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

using ll=long long;

int main() {
  int N; cin >>N;
  set<string> a;
  rep(i,0,N) {
    string b; cin >>b;
    a.insert(b);
  }
  cout <<a.size() <<endl;
  return 0;
}


Measured memory_bytes: 19188
#include <iostream>

using namespace std;

int main()
{
    char s[4];
    cin >> s;

    for (int i = 0; i < 4; i++)
    {
        for (int j = i + 1; j < 4; j++)
        {
            char x;
            if (s[i] < s[j])
            {
                x = s[i];
                s[i] = s[j];
                s[j] = x;
            }
        }
    }
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main()
{
    char a[4];
    cin>>a;
    for (int i=1; i<4; i++)
    {
        if(a[i]==a[i-1])
        {
            cout<<"Bad";
            return 0;
        }
    }
    cout<<"Good";
}


Measured memory_bytes: 256
input = gets.chomp.split(" ")
period = input[0].to_i
bsc = input[1].to_i
t = input[2].to_i

tm = 0
sum = 0
while tm <= (t + 0.5) do
    sum += bsc if (tm % period == 0) && (tm != 0)
    tm += 1
end

puts sum

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

i64 gcd(i64 a, i64 b){
    //
    if(a < b) swap(a, b);
    if(a % b == 0) return b;
    else return gcd(b, a % b);
}

void solve(long long N, long long X, std::vector<long long> x){
    i64 g = abs(x[0] - X);
    rep(i, 1, N) g = gcd(g, abs(x[i] - X));
    cout << g << endl;
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> x(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, X, std::move(x));
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

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

		int X = sc.nextInt();

		if (X == 7) {
			System.out.println("YES");
		} else if (X == 5) {
			System.out.println("YES");
		} else if (X == 3) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21972
count = 0

def merge(a, left, mid, right):
    global count

    l = a[left:mid]
    r = a[mid:right]
    l.append(10**9+1)
    r.append(10**9+1)

    i = 0
    j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
            count += mid - left - i

def mergeSort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(a, left, mid)
        mergeSort(a, mid, right)
        merge(a, left, mid, right)


if __name__ == '__main__':
    n = int(input())
    a = [int(x) for x in input().split()]

    mergeSort(a, 0, n)

    print(count)


Measured memory_bytes: 27476
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define all(a) a.begin(), a.end()
#define put(i) cout << fixed << i << endl
using namespace std;
using ll = long long;

//pdf見て解答


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

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

    ll ans = 1;

    vector<pair<ll,ll>> v = prime_factorize(p);

    for(ll i = 0; i < v.size(); i++){
        ans *= pow(v[i].first,floor(v[i].second / n));
    }

    put(ans);
    return 0;
}

Measured memory_bytes: 3972
class priorityQueue {
  constructor() {
    this.keys = [];
    Number.prototype.parentIdx = function() { return Math.ceil(this/2 - 1); };
    Number.prototype.leftIdx = function() { return this * 2 + 1; };
    Number.prototype.rightIdx = function() { return this * 2 + 2; };
  }

  insert(key) { this.heapIncrease(this.keys.push(key) - 1); }

  heapIncrease(idx) {
    const keys = this.keys;
    for (let i=idx, p=idx.parentIdx(); i > 0 && keys[i] > keys[p]; i=p, p=i.parentIdx()) {
      keys[p] = [keys[i], keys[i] = keys[p]][0];
    }
  }

  extract() {
    const res = this.keys[0];
    this.keys[0] = this.keys.pop();
    this.maxHeapify(0);
    return res;
  }

  maxHeapify(idx) {
    const keys = this.keys, n = keys.length;
    const innerMaxHeapify = (i) => {
      let left, right, largest = i;
      left = i.leftIdx();
      right = i.rightIdx();
      if (left < n && Number(keys[left]) > Number(keys[largest])) largest = left;
      if (right < n && Number(keys[right]) > Number(keys[largest])) largest = right;
      if (largest != i) {
        keys[largest] = [keys[i], keys[i] = keys[largest]][0];
        innerMaxHeapify(largest);
      }
    };
    innerMaxHeapify(idx);
  }
}

(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n').slice(0,-1);
//   lines.pop();
  const queue = new priorityQueue();
  let str = '';
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
      case 'i': queue.insert(Number(cmd.split(' ')[1])); break;
      case 'e': str += `${queue.extract()}\n`; break;
    }
  });
  process.stdout.write(str);
})();




Measured memory_bytes: 203992
N = int(input())
A = list(map(int, input().split()))
memo = [0]*(10**6+1)

for a in A:
    memo[a] += 1
    if memo[a] < 2:
        for i in range(2*a, 10**6+1, a):
            memo[i] += 1

ans = 0
for a in A:
    if memo[a] == 1:
        ans += 1

print(ans)


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

#define ll  long long
#define PII pair<ll,ll>
#define VI  vector<ll>
#define VB  vector<bool>
#define VC  vector<char>
#define VVI vector<vector<ll>>
#define VVC vector<vector<char>>
#define VS  vector<string>
#define VP  vector<PII>
#define lf(i,a,b) for(ll i=a;i<=b;i++)
#define lr(i,a,b) for(ll i=a;i>=b;i--)
#define lfl(i,v) for(ll i=0;i<v.size();i++)
#define lrl(i,v) for(ll i=(ll)(v.size())-1;i>=0;i--)
#define chk2(a,b) cout<<"check :  "<<a<<" "<<b<<endl
#define chk3(a,b,c) cout<<"check :  "<<a<<" "<<b<<" "<<c<<endl
#define chk4(a,b,c,d) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define chk5(a,b,c,d,e) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl
#define l_b(v,k)  lower_bound(v.begin(),v.end(),k)-v.begin()
#define u_b(v,k)  upper_bound(v.begin(),v.end(),k)-v.begin()
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define p_b push_back
#define p_f push_front
#define m_p make_pair
#define fir first
#define sec second
#define sz size()


int main() 
{	ll T;
	T=1;
	while(T--)
	{	ll n;cin>>n;
		VI v(n+1,0);
		lf(i,1,n)
			cin>>v[i];
		ll sum=0;
		lf(i,1,n)
		{	ll temp=(v[i-1]*v[i])%mod;
			sum=(sum+temp)%mod;
			v[i]=(v[i]+v[i-1])%mod;
		}
		cout<<sum<<endl;
	}  		
}      


Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
int n,m,p[15],ans;
vector<int> k[15];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x;
		cin>>x;
		for(int j=1;j<=x;j++)
		{
			int y;
			cin>>y;
			k[i].push_back(y);
		}
	}
	for(int i=1;i<=m;i++)
		cin>>p[i];
	for(int i=0;i<pow(2,n);i++)
	{
		vector<int> sw;
		int t=i;
		while(t)
		{
			sw.push_back(t%2);
			t/=2;
		}
		while(sw.size()!=n)
			sw.push_back(0);
		bool flag=true;
		for(int j=1;j<=m&&flag;j++)
		{
			int sum=0;
			for(int l=0;l<k[j].size();l++)
				sum+=sw[k[j][l]-1];
			if(sum%2!=p[j])
				flag=false;
		}
		if(flag)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

ans = 0
sum = 0

left = 0
right = 0

while(left < n):
    while(right < n and (sum ^ a[right] == sum + a[right])):
        sum = sum + a[right]
        right = right + 1

    ans = ans + right - left
    if(left == right):
        right = right + 1
    else:
        sum = sum - a[left]

    left = left + 1

print(ans)

Measured memory_bytes: 24424
S_ = input()
T = input()
len_T = len(T)
len_S = len(S_)

A = []
for i in range(len_S - len_T + 1):
    flg = True
    for t, s in zip(T, S_[i:i + len_T]):
        if s != '?' and s != t:
            flg = False
    if flg == True:
        S = ''
        for j in range(len_S):
            if i <= j < i + len_T:
                S += T[j - i]
            elif S_[j] == '?':
                S += 'a'
            else:
                S += S_[j]
        A.append(S)

ans = 'z' * (len_S + 1)
for S in A:
    if S < ans:
        ans = S
if ans == 'z' * (len_S + 1):
    print('UNRESTORABLE')
else:
    print(ans)

Measured memory_bytes: 9036
fn read<T: std::str::FromStr>() -> T
{
    std::io::Read::bytes(std::io::stdin())
                    .map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>()
                    .parse().ok().unwrap()
}

fn main() {
    let n: usize = read();
    let s: String = read();
    let wmax: usize = s.chars().fold(0, |acc, c| if c == 'W' {acc + 1} else {acc});

    let mut w: usize = 0;

    let mut a = vec![0; n];

    for (i, c) in s.chars().enumerate() {
        let wl = w;
        let wr = if c == 'W' {w+1} else {w};

        a[i] = wl + (n-(i+1) - (wmax-wr));
        if c == 'W' {w = w+1;}
    }

    println!("{}", a.into_iter().min().unwrap());
}


Measured memory_bytes: 8444
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

const int MAX_=500000;
map<int,bool> is_mon_sat_prime;
vector<int> mon_sat_prime;
vector<int> mon_sat_number;

void sieve(){
	for(auto it=mon_sat_number.begin(); it!=mon_sat_number.end(); ++it){
		is_mon_sat_prime[*it]=true;
	}
	is_mon_sat_prime[1]=false;
	for(auto it=mon_sat_number.begin(); it!=mon_sat_number.end(); ++it){
		if(it==mon_sat_number.begin()) ++it;
		if(is_mon_sat_prime[*it]){
			mon_sat_prime.push_back((*it));
			for(auto it_=mon_sat_number.begin(); (*it_)*(*it)<MAX_; ++it_){
				if(it_==mon_sat_number.begin()) ++it_;
				is_mon_sat_prime[(*it_)*(*it)]=false;
			}
		}
	}
}

void init(){
	for(int i=0; 6+i<MAX_ ; i+=7){
		mon_sat_number.push_back(6+i);
		mon_sat_number.push_back(1+i);
	}
	sort(mon_sat_number.begin(),mon_sat_number.end());
	sieve();
}

void solve(int n){
	vector<int> ans;
	int tmp=n;
	for(auto it=mon_sat_prime.begin(); (*it)<=n; ++it){
		if(n%(*it)==0){
			ans.push_back(*it);
		}
	}
	sort(ans.begin(),ans.end());
	cout << tmp << ": ";
	for(auto it=ans.begin(); it!=ans.end(); ++it){
		cout << *it;
		if(++it==ans.end()){
			cout << endl;
		} else {
			cout << ' ';
		}
		--it;
	}
}

int main(){
	init();
	int N;
	while(cin >> N&&N!=1){
		solve(N);
	}
	return 0;
}

Measured memory_bytes: 10688
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll power(ll k, ll n, int M) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * k % M;
    k = k * k % M;
    n /= 2;
  }
  return res;
}

int main() {
  int N, P, d;

  scanf("%d%d", &N, &P);

  ll ans = 0;

  if (P == 2 || P == 5) {
    for (int i = 0; i < N; i++) {
      scanf("%1d", &d);
      if (d % P == 0) ans += i + 1;
    }
  } else {
    int now = 0;
    int inv10 = power(10, P - 2, P);
    int t = 1;

    map<int, int> counter;
    counter[0]++;

    for (int i = 0; i < N; i++) {
      scanf("%1d", &d);
      now = (now * 10 + d) % P;
      ans += counter[now * t % P];
      counter[now * t % P]++;
      t = t * inv10 % P;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
// ---------- begin SegmentTree Point update Range query ----------
mod segment_tree {
    pub struct PURQ<T, F> {
        n: usize,
        a: Vec<T>,
        id: T,
        op: F,
    }
    #[allow(dead_code)]
    impl<T: Clone, F: Fn(&T, &T) -> T> PURQ<T, F> {
        pub fn new(n: usize, id: T, op: F) -> PURQ<T, F> {
            let mut k = 1;
            while k < n {
                k *= 2;
            }
            PURQ {
                n: k,
                a: vec![id.clone(); 2 * k],
                id: id,
                op: op,
            }
        }
        pub fn update(&mut self, x: usize, v: T) {
            let mut k = self.n + x;
            let a = &mut self.a;
            a[k] = v;
            k >>= 1;
            while k > 0 {
                a[k] = (self.op)(&a[2 * k], &a[2 * k + 1]);
                k >>= 1;
            }
        }
        pub fn update_tmp(&mut self, x: usize, v: T) {
            self.a[x + self.n] = v;
        }
        pub fn update_all(&mut self) {
            let a = &mut self.a;
            for k in (1..(self.n)).rev() {
                a[k] = (self.op)(&a[2 * k], &a[2 * k + 1]);
            }
        }
        pub fn find(&self, mut l: usize, mut r: usize) -> T {
            let mut p = self.id.clone();
            let mut q = self.id.clone();
            l += self.n;
            r += self.n;
            let a = &self.a;
            while l < r {
                if (l & 1) == 1 {
                    p = (self.op)(&p, &a[l]);
                    l += 1;
                }
                if (r & 1) == 1 {
                    r -= 1;
                    q = (self.op)(&a[r], &q);
                }
                l >>= 1;
                r >>= 1;
            }
            (self.op)(&p, &q)
        }
    }
}
// ---------- end SegmentTree Point update Range query ----------

use proconio::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        k: usize,
        a: [usize; n],
    }
    let w = 300_000 + 1;
    let mut seg = segment_tree::PURQ::new(w, 0, |a, b| std::cmp::max(*a, *b));
    for a in a {
        let l = if a >= k {
            a - k
        } else {
            0
        };
        let r = if a + 1 + k <= w {
            a + k + 1
        } else {
            w
        };
        let v = seg.find(l, r);
        seg.update(a, v + 1);
    }
    let ans = seg.find(0, w);
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 8848
day=input()

if day=="SUN":
    print(7)
if day=="MON":
    print(6)
if day=="TUE":
    print(5)
if day=="WED":
    print(4)
if day=="THU":
    print(3)
if day=="FRI":
    print(2)
if day=="SAT":
    print(1)

Measured memory_bytes: 3060
//Wrong answer on test inf.
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define per(i,x,y) for (int i=(x);i>=(y);i--)
#define ll long long
#define inf 1000000001
#define INF 1000000000000000001ll
#define y1 y1___
using namespace std;
char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
ll read(){
	char ch=gc();ll x=0;int op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 200005
int n,a[N];ll sum[N],mx1[N],mx2[N],mi1[N],mi2[N],ans;
int main(){
	n=read();
	rep (i,1,n) a[i]=read(),sum[i]=sum[i-1]+a[i];
	int pos=0;
	rep (i,1,n){
		while (pos<i&&abs(sum[pos]-(sum[i]-sum[pos]))>abs(sum[pos+1]-(sum[i]-sum[pos+1])))
			pos++;
		mx1[i]=max(sum[pos],sum[i]-sum[pos]);
		mi1[i]=min(sum[pos],sum[i]-sum[pos]);
	}
	pos=n;
	per (i,n,1){
		while (pos>i&&abs(sum[n]-sum[pos]-(sum[pos]-sum[i-1]))>abs(sum[n]-sum[pos-1]-(sum[pos-1]-sum[i-1])))
			pos--;
		mx2[i]=max(sum[n]-sum[pos],sum[pos]-sum[i-1]);
		mi2[i]=min(sum[n]-sum[pos],sum[pos]-sum[i-1]);
	}
	ans=INF;
	rep (i,1,n-1) ans=min(ans,max(mx1[i],mx2[i+1])-min(mi1[i],mi2[i+1]));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8832
#include <stdio.h>
int main(){
  int i, n, min, max, x, y;
  scanf("%d",&n); 
  for(i = 0 ; i < n ; i++){
    scanf("%d",&x);
    if(i == 0){
      y = x;
    }
    if(i == 1){
      max = x - y;
    }
    else if (max < x - min){
      max = x - min;
    }
    if(i == 0){
      min = x;
    }
    else if (min > x){
      min = x;
    }
  }
  printf("%d\n", max);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int N,M;
  cin>>N>>M;
  cout<<(--N)*(--M)<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
L = list(map(int, input().split()))
ans = 0

for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i] and L[i]<L[j]+L[k] and L[j]<L[i]+L[k] and L[k]<L[i]+L[j]:
                ans += 1

print(ans)

Measured memory_bytes: 74452
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        n: usize,
        s_vec: [String; n],
    }

    let mut map: HashMap<String, usize> = HashMap::new();
    
    for s in s_vec.into_iter() {
        *map.entry(s).or_insert(0) += 1;
    }


    println!("AC x {}", map.get("AC").unwrap_or(&0));
    println!("WA x {}", map.get("WA").unwrap_or(&0));
    println!("TLE x {}", map.get("TLE").unwrap_or(&0));
    println!("RE x {}", map.get("RE").unwrap_or(&0));
}


Measured memory_bytes: 7944
# -*- coding: utf-8 -*-

import sys
import os
import math

def day_to_num(y, m, d):
    s = "{:04d}{:02d}{:02d}".format(y, m, d)
    return int(s)

for s in sys.stdin:
    y, m, d = list(map(int, s.split()))

    n = day_to_num(y, m, d)

    if n < 18680908:
        gengo = 'pre-meiji'
    elif 18680908 <= n <= 19120729:
        gengo = 'meiji'
        Y = y - 1868 + 1
    elif 19120730 <= n <= 19261224:
        gengo = 'taisho'
        Y = y - 1912 + 1
    elif 19261225 <= n <= 19890107:
        gengo = 'showa'
        Y = y - 1926 + 1
    else:
        Y = y - 1989 + 1
        gengo = 'heisei'

    if gengo == 'pre-meiji':
        print(gengo)
    else:
        print(gengo, Y, m, d)

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

int main(){



  int N;
  int M;

  cin>>N>>M;

  int C;

  cin>>C;

  int b[21],a[21][21];

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

  int ans=0;
  
  for(int i=0;i<N;i++){
    int cnt=0;
    for(int j=0;j<M;j++){
      cin>>a[i][j];

      cnt+=(a[i][j]*b[j]);
    }
    if(cnt+C>0){
      ans++;
    }
  }

  cout<<ans<<endl;

  
	
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>
 
using namespace std;

int r,c,n;
int x1,x2,y1,y2;
bool vis[100005];

inline bool border(int x,int y) {
	return x==0 || x==r || y==0 || y==c;
}

struct node {
	int val,side,pos;
	bool operator<(const node& rhs) const {
		if (side!=rhs.side) return side<rhs.side;
		if (side==1||side==2) return pos<rhs.pos;
		else return pos>rhs.pos;	
	}
};

vector<node> vec;
void add(int x,int y,int idx) {
	if (x==0) vec.pb({idx,1,y});
	else if (x==r) vec.pb({idx,3,y});
	else if (y==c) vec.pb({idx,2,x});
	else vec.pb({idx,4,x});
}

int main() {
	scanf("%d%d%d",&r,&c,&n);
	for (int i=0;i<n;i++) {
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if (border(x1,y1)&&border(x2,y2)) {
			add(x1,y1,i);
			add(x2,y2,i);
		}
	}
	sort(vec.begin(),vec.end());
	bool flag=true;
	stack<int> st;
	for (int i=0;i<vec.size();i++) {
		if (!vis[vec[i].val]) {
			vis[vec[i].val]=1;
			st.push(vec[i].val);
		} else {
			if (vec[i].val!=st.top()) {
				flag=false;
				break;
			} else {
				st.pop();
			}
		}
	}
	if (flag) printf("YES\n");
	else printf("NO\n");
}


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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll big = 10e12 + 11 ;

int  main (  ) {

    FASTIO ;

    int n ;
    cin >> n ;

    ll  ans = 0 ;

    ans += ( n / 500 ) * 1000 ;

    n %= 500 ;

    ans += ( n / 5 ) * 5 ;

    cout << ans <<  endl ;

    return  0 ;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define vll vector<ll>
int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	if(b<a)
	{
		cout<<0<<endl;
		return 0;
	}
	if(a==b and n==1)
	{
		cout<<1<<endl;
		return 0;
	}
	else if(n==1 and a!=b)
	{
		cout<<0<<endl;
		return 0;
	}
	ll mi,ma;
	mi=a+b+(n>2?(n-2)*a:0);
	ma=a+b+(n>2?(n-2)*b:0);
	cout<<ma-mi+1<<endl;
}

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

int main() {

    long long int n,k;

    cin >> n >> k;

    if(k==0){
        cout << n*n << endl;
        return 0;
    }

    long long int ans = 0;

    for(long long int b=k+1; b<=n; b++){
        long long int tmp = n/b;
        ans += max(static_cast<long long int>(0),tmp*(b-k));
        if(n%b>=k) {
            ans += max(static_cast<long long int>(0), n % b - k + 1);
        }
    }



    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<int> a(n - 1);
    rep(i, n -1) cin >> a[i];
    vector<int> z(n);
    rep(i, n-1) {
        z[a[i]-1] += 1;    
    }
    rep(i, n) {
        cout << z[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4844
#include <stdio.h>

int a,b,c,d ;

int main(void){
    
    scanf ("%d%d%d%d",&a,&b,&c,&d) ;
    
    if ( a+b>c+d ){
        printf ("Left\n") ;
    } else if ( a+b==c+d ){
        printf ("Balanced\n") ;
    } else {
        printf ("Right\n") ;
    }
    
    return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1000000007;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
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 (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

const int INF = 1e9;
const ll LLINF = 1e16;
 
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
 
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}


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


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //auto a = make_v<ll>(n, m);
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    while(n > 0){
      n /= k;
      ans++;
    }
    print(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,ans;
char s[100010];
int main(){
	cin>>n>>s+1;
	for(int i=0;i<=9;i++){
		for(int j=0;j<=9;j++){
			for(int k=0;k<=9;k++){
				int mk=0;
				for(int l=1;l<=n;l++){
					int nowp=s[l]-'0';
					if(mk==0&&nowp==i) mk++;
					else if(mk==1&&nowp==j) mk++;
					else if(mk==2&&nowp==k) mk++;
				}
				if(mk>=3) ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

ll S;
ll ans = 0;

int main() {
    cin >> S;
    ll three_num = S / 3;
    rep(i, three_num) {
        //i + 1が数列の長さ
        ll tmpS = S - 3 * (i + 1);

        //tmpSをどう分配するか
        //i本の仕切りがあるとする
        //この仕切りでくぎったi + 1の空間に重複を許して1をおく
        //(tmpS + i)! / tmpS! * i!

        ll tmp_ans = 1;

        for (int j = 1; j <= i; j++) {
            tmp_ans *= tmpS + j;
            tmp_ans %= MOD;
            //cout << tmp_ans << endl;
        }
        for (int j = 1; j <= i; j++) {
            tmp_ans *= modInv(j);
            tmp_ans %= MOD;
            //cout << tmp_ans << endl;
        }
        //cout << endl;
        ans += tmp_ans;
        ans %= MOD;
        //cout << ans << endl;
        //cout << endl;

    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
// << left shift *2 and >>right shift /2
long long int mod97=1000000007;
double pi=3.1415926536;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
bool rev(long long int a,long long int b)
{
    if(a>b)return true;
    else return false;
}
bool compa(pair<string,pair<int,int>>a,pair<string,pair<int,int>>b)
{
    if(a.first==b.first)
    {
        if(a.second.first>b.second.first)
        return true;
        else
        return false;
    }
    if(a.first<b.first)
    return true;
    else 
    return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}

void solve()
{
    long long int n,m;cin>>n>>m;
    char c[n][m];
    for(long long int i=0;i<n;i++)for(long long int j=0;j<m;j++)cin>>c[i][j];
    long long int dp[n][m];
    for(long long int i=0;i<n;i++)
    {
        for(long long int j=0;j<m;j++)
        {
            if(i==0 && j==0)
            dp[i][j]=1;
            else if(i==0)
            {
                if(c[i][j]=='#')
                dp[i][j]=0;
                else
                dp[i][j]=dp[i][j-1];
            }
            else if(j==0)
            {
                if(c[i][j]=='#')
                dp[i][j]=0;
                else
                dp[i][j]=dp[i-1][j];
            }
            else
            {
                if(c[i][j]=='#')
                dp[i][j]=0;
                else
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod97;
            }
        }
    }
    for(long long int i=0;i<0;i++)
    {
        for(long long int j=0;j<m;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    long long int ans=dp[n-1][m-1];
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;
    //cin>>t;long long int temp=t;
    while(t--)
    {
        //cout<<"Case "<<temp-t<<": ";
        solve();
    }
}


Measured memory_bytes: 12360
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
signed main(){
  int n;
  cin>>n;
  vector<vector<int>> adj(n);
  vector<int> color(n,0);
  color[0]=1,color[n-1]=2;
  for(int i=0;i<n-1;++i){
    int a,b;
    cin>>a>>b;
    --a;--b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  vector<int> path(n,-1);
  path[0]=n+1;
  queue<int> que,dumq;
  que.push(0);
  while(!que.empty()){
    int q=que.front(); que.pop();
    if(q==n-1)break;
    for(auto i:adj[q])if(path[i]<0)que.push(i),path[i]=q;
  }
  cerr<<"path\n";
  for(auto i:path)cerr<<i<<" ";
  cerr<<endl;
  int c=n-1,l=1;
  while(c!=0){
    c=path[c];
    color[c]=3;
    ++l;
    cerr<<"c:"<<c<<endl;
  }
  for(int i=0,c=n-1;i<l;++i,c=path[c]){
    if(i<l/2)color[c]=2;
    else color[c]=1;
  }
  cerr<<"l:"<<l<<endl;
  for(auto i:color)cerr<<i<<" ";
  cerr<<endl;
  int fennec=l%2,snuke=0;
  que=dumq;
  que.push(0);
  while(!que.empty()){
    int q=que.front();que.pop();
    for(auto i:adj[q])if(color[i]==0||color[i]==1)++fennec,que.push(i),color[i]=4;
  }
  que=dumq;
  que.push(n-1);
  while(!que.empty()){
    int q=que.front();que.pop();
    for(auto i:adj[q])if(color[i]==0||color[i]==2)++snuke,que.push(i),color[i]=5;
  }
  if(fennec>snuke)cout<<"Fennec";
  else cout<<"Snuke";
}

Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int a[10];
int c[10];
int n,k,b;
bool ok(int q){
b=q;
int i=0;
while(b>0){
c[i]=b%10;
b/=10;
i++;
}
for(int d=0;d<i;d++)
for(int s=0;s<k;s++)
if(c[d]==a[s])
return false;
return true;}
int main(){
cin>>n>>k;
for(int i=0;i<k;i++)
cin>>a[i];
for(int i=n;i<=999999;i++)
if(ok(i)){
cout<<i;
return 0;
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
  
int main() {
  int N,K;
  cin >> N >> K;
  int x,sum=0;
  
  rep(i,N){
    cin >> x;
    if (2*x < K) {
      sum += 2*x;
    }else sum += 2*(K-x);
  }
  cout << sum;
}

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

int main() {
    int k, s, count = 0;
    cin >> k >> s;

    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            if((i + j <= s) && (s - k <= i + j)){
                count++;
            }
        }
    }

    cout << count << endl;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort(reverse=True)
    return divisors

d = make_divisors(n)
ans = 0
for a in d:
    if a == 1:
        continue
    else:
        q = n//a
        m = a-1
        if 0 <= q <= m-1:
            ans += m
print(ans)


Measured memory_bytes: 39024
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    s = get_str()
    b = int("0" + s, 2)
    zo = "01" * ((len(s) // 2) + 1)
    x = int("0" + zo[0:len(s)], 2)
    y = int("0" + zo[1:len(s)+1], 2)
    print(min(bin(b ^ x).count("1"), bin(b ^ y).count("1")))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5644
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll N, num[2] = {}, L = 0, ans = 1;
string S;
bool isLeft[200000] = {};

ll fact(ll num) {
	if (num == 1) {
		return 1;
	}
	else {
		return (num * fact(num - 1)) % 1000000007;
	}
}

int main() {
	cin >> N;
	cin >> S;
	rep(i, sz(S)) {
		if (i % 2 == 0) {
			if (S[i] == 'W') {
				isLeft[i] = false;
			}
			else {
				isLeft[i] = true;
			}
		}
		else {
			if (S[i] == 'W') {
				isLeft[i] = true;
			}
			else {
				isLeft[i] = false;
			}
		}
		num[isLeft[i]]++;
	}
	if (num[0] != num[1] || S[0] == 'W' || S[sz(S) - 1] == 'W') {
		cout << 0 << endl;
		return 0;
	}
	rep(i, sz(S)) {
		if (isLeft[i]) {
			L++;
		}
		else {
			ans *= L;
			ans %= 1000000007;
			L--;
		}
	}
	cout << (ans* fact(N)) % 1000000007 << endl;
	return 0;
}

Measured memory_bytes: 2308
N=int(input())
A,B=map(int,input().split())
P=list(map(int,input().split()))
r=[0]*3
for p in P:
  if p<=A:
    r[0]+=1
  elif p>B:
    r[2]+=1
  else:
    r[1]+=1
print(min(r))

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

int main() {
  int N,M;cin>>N>>M;
  int Lmax=0,Rmin=10000000;
  
  int L,R;
  rep(i,M){
    cin>>L>>R;
    Lmax=max(Lmax,L);
    Rmin=min(Rmin,R);
  }
  
  if(Rmin-Lmax+1<1) cout << 0 << endl;
  else cout << Rmin-Lmax+1 << endl;
}


Measured memory_bytes: 3636
#!/usr/bin/perl
#A - Christmas Eve Eve Eve - AtCoder Beginner Contest 115

use strict;
use warnings;

# データ取得
my ($data);
my (@ret) = ('Christmas Eve Eve Eve' , 'Christmas Eve Eve' , 'Christmas Eve' , 'Christmas');

my $arg;

    {
        $data = <STDIN>;
        chomp($data);
    }
    # ほんとうはチェック必要
    $arg = $data - 22;

print("$ret[$arg]\n");

exit(0);


Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut seq = vec![vec![0 as usize; n]; 3];
    for i in 0..3 {
        for j in 0..n {
            seq[i][j] = read();
        }
        seq[i].sort();
        seq[i].reverse();
    }
    let mut cnts = vec![vec![1 as usize; n]; 3];
    let mut total = 0;
    for i in (0..2).rev() {
        let mut sum = 0;
        let mut offset = 0;
        for j in 0..n {
            while offset < n && seq[i][j] < seq[i + 1][offset] {
                // println!("{} {} {}", i, j, offset);
                sum += cnts[i + 1][offset];
                offset += 1;
            }
            cnts[i][j] = sum;
            if i == 0 {
                total += sum;
            }
        }
    }
    println!("{}", total);
}


Measured memory_bytes: 10620
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)  //  rep
#define repr(i,a,n) for(int i=a;i>n;i--)  //  repリバース
#define leng(n) (int)(log10(n)+1)  //  桁数leng
#define INF 9000000000000000000 //  巨大数INF
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int N, T;
  cin >> N >> T;
  priority_queue<int> pq;
  rep(i, 0, N) {
    int c, t;
    cin >> c >> t;
    if (t > T) continue;
    pq.push((-1)*c);
  }
  if(pq.size()==0) cout << "TLE" << endl;
  else cout << (-1)*(pq.top()) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 int main(){
 int n;
 char s[101],j[101];
 scanf("%d",&n);
 scanf("%s %s",s,j);
 int i;
 for(i=0;i<n;i++){
    printf("%c%c",s[i],j[i]);


 }
return 0;
 }


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

int main(void)
{
    int n, k, q, a_i;
    cin >> n >> k >> q;
    vector<int> aVector;
    for (int i = 0; i < n; i++)
    {
        aVector.push_back(k-q);
    }
    for (int i = 0; i < q; i++)
    {
        cin >> a_i;
        aVector[a_i-1]++;
    }
    for (int i = 0; i < n; i++)
    {
        cout << ((aVector[i] > 0) ? "Yes":"No") << endl;
    }
}


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

int main(){
	int h, w;
	cin >> h >> w;
	string a[h];
	for(int i = 0; i < h; i++) cin >> a[i];
	for(int i = 0; i + 1 < h; i++) for(int j = 0; j + 1 < w; j++) if((a[i + 1][j] == '#' && a[i + 1][j + 1] == '#' && a[i][j + 1] == '#') || (a[i][j] == '#' && a[i + 1][j] == '#' && a[i][j + 1] == '#')){
		cout << "Impossible" << endl;
		return 0;
	}
	cout << "Possible" << endl;
}

Measured memory_bytes: 256
V, E = map(int, input().split())

D = [[float("INF")]*V for _ in range(V)]

for i in range(V):
    D[i][i] = 0

for i in range(E):
    s, t, d = map(int, input().split())
    D[s][t] = d

for k in range(V):
    for i in range(V):
        for j in range(V):
            if D[i][k] != float("INF") and D[k][j] != float("INF"):
                D[i][j] = min(D[i][j], D[i][k] + D[k][j])

for i in range(V):
    if D[i][i] < 0:
        print('NEGATIVE CYCLE')
        exit()

for i in range(V):
    for j in range(V):
        if D[i][j] == float("INF"): 
            D[i][j] = "INF"
    print(*D[i])


Measured memory_bytes: 6276