akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main() {
	var k int
	fmt.Scan(&k)

	a := 7
	for i := 1; i <= k; i++ {
		if a%k == 0 {
			fmt.Println(i)
			return
		}
		a = a*10 + 7
		a %= k
	}
	fmt.Println(-1)
}


Measured memory_bytes: 1788
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }


int main() {
	// 入力
	ll N, K;
	cin >> N>>K;
	ll a[N];
	for (ll i = 0; i < N; ++i) cin >> a[i];
 
	// 解法
	ll beauty[N*N] = {0};
	// cout << beauty[0] << endl;
	for (ll l = 0; l < N; ++l){// 左
		for (int r = l+1; r <= N; ++r){ // 右 a[r]は含めない
			beauty[l*N+r] = beauty[l*N+r-1] + a[r-1];
		}
	}
	
	sort(beauty, beauty+N*N, greater<ll>());
	
	ll ans = 0;
	ll selection = N*(N+1)/2;
	for (ll i = 44; i >= 0; --i){
		if (beauty[K-1]>=pow(2,i)){
			ans += pow(2,i);
			REP(j,selection){
				if (beauty[j]<pow(2,i)){
					selection = j;
				}
			}
		}
		REP(j,selection){
			beauty[j] = beauty[j]%((ll)pow(2,i));
		}
		sort(beauty, beauty+selection, greater<ll>());
		// printf("%lld %lld sel %lld %lld\n", i, (ll)pow(2,i), selection, ans);
		// printf("beauty ");
		// REP(j,selection){
		// 	printf("%lld ", beauty[j]);
		// }
		// printf("\n");
		// cout << pow(2,i) << endl;
	}
	cout << ans << endl;
}


Measured memory_bytes: 8064
n = int(input())
S = input()
ans = n
num_list = []
W_count = 0

for i in range(n):
    if S[i] == 'W':
        W_count += 1
    num_list.append(W_count)

for i in range(1, n-1):
    left_w = num_list[i-1]
    right_e = n - num_list[n-1] - (1+i - num_list[i])
    pre_ans = left_w + right_e
    if ans > pre_ans:
        ans = pre_ans

ans_0 = n-num_list[n-1] - (1-num_list[0])
ans_n = num_list[n-2]
print(min(ans, ans_0, ans_n))


Measured memory_bytes: 15396
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	fast;
int a[3][3];
int n;
for(int i=0;i<3;i++)
{
	for(int j=0;j<3;j++)
	{
		cin>>a[i][j];
	}
}
cin>>n;
int x;
while(n--)
{
	cin>>x;
	for(int j=0;j<3;j++)
	{
		for(int k=0;k<3;k++)
		{
			if(x==a[j][k])
			{
				a[j][k]=-1;
			}
		}
	}
}

int c=0;
for(int i=0;i<3;i++)
{ c=0;
	for(int j=0;j<3;j++)
	{
		if(a[i][j]==-1)
		{
			c++;
		}
	}
		if(c==3)
		{
			cout<<"Yes";
			return 0;
		}
}
c=0;
for(int i=0;i<3;i++)
{ c=0;
	for(int j=0;j<3;j++)
	{
		if(a[j][i]==-1)
		{
			c++;
		}
	}
		if(c==3)
		{
			cout<<"Yes";
			return 0;
		}
}
if(a[0][0]=-1 && a[1][1]==-1 && a[2][2]==-1)
{
	cout<<"Yes";
	return 0;
}
if(a[0][2]==-1 && a[1][1]==-1 && a[2][0]==-1)
{
	cout<<"Yes";
	return 0;
}
cout<<"No";
return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	string s;
	ll ans = 0;

	cin >> s;

	ll sc = 0;
	ll tc = 0;

	REP(i, s.size()) {
		if (i != s.size() - 1 && s[i] == 'T' && s[i + 1] == 'S') {
			tc++;
			ans += min(sc, tc) * 2;
			if (sc < tc) {
				sc = 0;
				tc = 0;
			}
			else {
				sc -= tc;
				tc = 0;
			}
		}
		else if (s[i] == 'S') {
			sc++;
		}
		else if (s[i] == 'T') {
			tc++;
		}
	}

	ans += min(sc, tc) * 2;

	cout << s.size() - ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);



template <typename T>
class Seg_Tree{
public: // 0-index
  vector<T> dat;
  T initial,M;
  int n;
  T unite(T a,T b){//
    return a|b;
  }
  //Seg_Tree(int n0_=1,T initial_=1,T M_=1){
  //  initsize(n0_,initial_,M_);
  //}
  void initsize(int n0,T initial_,T M_){
    M = M_;
    initial = initial_;
    int k=1;
    while(1){
      if(n0<=k){
        n=k;
        dat.resize(2*n-1);
        for(int i=0;i<2*n-1;i++)dat[i]=initial;
        break;
      }
      k*=2;
    }
  }
  //i banme wo x nisuru
  void update(int i,T x){
    i += n-1;
    dat[i] = x;
    while(i>0){
      i = (i-1) / 2;
      dat[i] = unite(dat[i*2+1],dat[i*2+2]);
    }
  }
  //[a,b)
  T query0(int a,int b,int k,int l,int r){
    if(r<=a || b<=l)return initial;
    if(a<=l && r<=b)return dat[k];
    else{
      T vl = query0(a,b,k*2+1,l,(l+r)/2);
      T vr = query0(a,b,k*2+2,(l+r)/2,r);
      return unite(vl,vr);
    }
  }
  //return [a,b)
  T query(int a,int b){
    return query0(a,b,0,0,n);
  }
  T get_except(int ind){
    T vl = query(0,ind);
    T vr = query(ind+1,n);
    return unite(vl,vr);
  }
  T get_all(){
    return query(0,n);
  }
};


int main(){
  Seg_Tree<ll> sg;

  ll N,Q;
  string S;
  cin >> N >> S >> Q;
  sg.initsize(N+1,0,MOD);
  FOR(i,0,N){
    sg.update(i,(1<<(S[i]-'a')));
  }

  int x,l,r,i;
  char c;
  FOR(q,0,Q){
    cin >> x;
    if(x==1){
      cin >> i >> c;
      i--;
      sg.update(i,(1<<(c-'a')));
    }else{
      cin >> l >> r;
      l--,r--;
      cout << __builtin_popcount(sg.query(l,r+1)) << '\n';
    }
  }
}

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

int main(){

    int i,j,n,k;
    cin>>n>>k;

    double p = (double) (1.0/n);
    double sum=0;

    for(i=1;i<=n;i++){
        double num=i,c=0;
        while(1){
            num*=2;
            c++;
            if(num>=k) break;
        }

        if(i>=k) c--;
        double m = pow(0.5,c);
        sum+= m;
    }

        printf("%.10f\n",sum*p);

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
std::vector<ll> a(200);

int main() {
 	
 	ll i, j, k, l, test, n, pos;
 	
 	for(i='1';i<='9';i++) {
 	    a[i]=0;
 	}
 	
 	cin>>n>>k;
 	for(i=0;i<k;i++) {
 	    cin>>l;
 	    a[l]++;
 	} 
 	ll r,x,flag=1;
 	for(i=n;i;i++) {
 	    x=i;
 	    flag=1;
 	    while(x>0) {
 	        r=x%10;
 	        x/=10;
 	        if(a[r]>0) {
 	            flag=0;
 	        }
 	    }
 	    if(flag==1) {
 	        cout<<i<<"\n";
 	        break;
 	    }
 	}
}

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

ll dp[100002];
    

    
int main(){

    memset(dp,0,sizeof(dp));
    dp[0]=0;

    int n; cin>>n;
    vector <int> vi;
    
    for(int i=0;i<n;i++){
    int k; cin>>k;
    vi.push_back(k);
    }
    
    dp[1]=abs(vi[1]-vi[0]);

    for(int i=2;i<n;i++){
        dp[i]=min(abs(vi[i]-vi[i-1])+dp[i-1],abs(vi[i]-vi[i-2])+dp[i-2]);
    }

    cout<<dp[n-1]<<'\n';

    
}

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

//int nm[10001][10001] = {0};

map<pair<int,int>,int> nm;

long long c[10001];

int b[10000];

int main() {
    int n,m;

    cin >> n >> m;

    while(1){
        int s,t,e;
        scanf(" %d %d %d",&s,&t,&e);
        if( (s+t+e) == 0) break;
        //nm[s][t] = e;
        nm[make_pair(s,t)] = e;
    }

    int l;

    cin >> l;

    pair<int,int> tmp;

    while(l--) {

        for(int i=1;i<=m;i++){
            scanf(" %d",&b[i]);
        }

        int i, j;
        for (i = 1; i <= n; i++) {
            c[i] = 0;
            /*for (j = 0; j < m; j++) {
                c[i] = c[i] + nm[i][j+1] * b[j];
            }*/
        }
        for(map<pair<int,int>,int>::iterator itr = nm.begin(); itr != nm.end(); ++itr) {
            tmp = itr->first;
            c[tmp.first] += b[tmp.second] * itr->second;
            //cout << "I'm hungry " << c[tmp.first] << " " << tmp.first << " " << tmp.second << endl;
        }


        for(int i=1;i<=n;i++){
            //cout << c[i];
            printf("%d",c[i]);
            if(i!=n) printf(" ");//cout <<  ' ';
        }
        cout << endl;

    }
    return 0;
}

Measured memory_bytes: 6448
import java.util.Scanner;

public class Main {
    public void main(Scanner sc) {
        long x = sc.nextLong();
        long y = sc.nextLong();

        int cnt = 0;
        for (; x <= y; cnt++) {
            x *= 2;
        }

        System.out.println(cnt);
    }

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


Measured memory_bytes: 21844
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
//typedef cpp_int c_i;
#include<bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define p0(x) cout <<x <<" "
#define p1(x) cout <<x <<endl
#define p2(x,y) cout <<x <<" " <<y <<endl
#define p3(x,y,z) cout <<x <<" " <<y <<" " <<z <<endl
#define p4(w,x,y,z) cout <<w <<" " <<x <<" " <<y <<" " <<z <<endl
#define nl cout<<endl
# define pb push_back
#define mp make_pair
#define mp make_pair
# define vi vector<int>
# define vll vector<ll>
# define vvi vector< vector <int> >
#define ff first
#define ss second
# define vvll vector<vector <ll> >
# define srt(a) sort(a.begin(),a.end())
# define f(i,a,b) for(int i=a;i<b;i++)
# define frev(i,a,b) for(int i=a;i>=b;i--)
# define srtrev(a) sort(a.begin(),a.end(),cmp)
#define gcd(a,b) __gcd(a,b);
#define lcm(a,b)   (a/gcd(a,b))*b;
using namespace std;
#define Map map<int,int>
#define Umap unordered_map<int,int> 
ll limit = 1000000007;
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);  
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool cmp(ll a,ll b)
{
	return a>b;
}
ll Pow(ll a,ll b )  //for modulus power
{
	ll ans=1,mul=a;
	while(b)
	{
		if(b&1)ans=(ans*mul)%limit;
		mul=(mul*mul)%limit;
		b/=2;
	}
	return ans;
}
 
 
void solve()
{
	int a;
	cin>>a;
	cout<<3*a*a<<'\n';
}
//driver function
    int main()
    {
		//fast
		int t=1;
		//cin>>t;
		f(T,1,t+1)
		{
			//cout<<"Case #"<<T<<": ";
			solve();
		}
    }


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string S;
    int ans=0;
    cin >> S;
    if(S.find("R")!=-1)ans++;
    if(S.find("RR")!=-1)ans++;
    if(S.find("RRR")!=-1)ans++;
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3528
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m = map(int,input().split())
class InverseTable:
    __slots__ = ['In', 'fac', 'Ifac']

    def __init__(self, mod, maxnum):
        self.In = [0, 1]; self.fac = [1, 1]; self.Ifac = [1, 1]
        for i in range( 2, maxnum + 1 ):
            self.In.append( ( -self.In[mod % i] * (mod//i) ) % mod )
            self.fac.append( ( self.fac[-1] * i ) % mod )
            self.Ifac.append( (self.Ifac[-1] * self.In[-1]) % mod )
        
    def cmb(self, n, r):
        if ( r<0 or r>n ): return 0
        r = min(r, n-r)
        return self.fac[n] * self.Ifac[r] * self.Ifac[n-r] % mod
    
    def per(self, n, r):
        if ( r<0 or r>n ): return 0
        return self.fac[n] * self.Ifac[n-r] % mod

invt = InverseTable(mod, 10**6)
# maxnum=10**6だとテーブル生成に200ms程かかるので（Pythonだと1000msほど）
# 最大生成領域は問題ごとに要検討

def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        count=0
        while n % i==0:
            count+=1
            n = n//i
        if count!=0:
            ass.append((i,count))
    if n != 1:
        ass.append((n,1))
    return ass


ass = prime_factor(m)
ans = 1
for i, amount in ass:
  ans = ans * invt.cmb(amount+n-1,amount) % mod
print(ans)
# print(ass)


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

using namespace std;

int a, b;

int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> a >> b;
    if(a%2 != b%2)
        cout << "IMPOSSIBLE\n";
    else cout << (a+b)/2 << '\n';
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int K; string s; cin >> K >> s;
    int c = s.size();
    if(c <= K){
        cout << s << endl;
    }else{
        cout << s.substr(0, K) << "..." << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7712
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	D, N := getInt(), getInt()

	x := 1
	for i := 0; i < D; i++ {
		x *= 100
	}

	y := 0
	for i := 0; i < N; i++ {
		y += x
	}

	if x*100 == y {
		y += x
	}
	out(y)
}


Measured memory_bytes: 640
import math

def comb(n,r):
	if n >= r:
		return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
	else:
		return 0

N, K = map(int, input().split())

for i in range(1,K+1):
	print(comb(N-K+1,i)*comb(K-1,i-1)%(10**9+7))

Measured memory_bytes: 3316
#!/usr/bin/env python3
import sys
import math
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = 10**15

n, k = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
f = [int(item) for item in input().split()]
a.sort()
f.sort(reverse=True)

l = -1; r = 10**12 + 1 
while r - l > 1:
    mid = (l + r) // 2
    syugyo = 0
    for aa, ff in zip(a, f):
        target = mid // ff
        syugyo += max(aa - target, 0)
    if syugyo <= k:
        r = mid
    else:
        l = mid
print(r)

Measured memory_bytes: 109900
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <cstdlib>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;
#define llong long long int

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

    llong a, b, x; cin >> a >> b >> x;
    llong ans = 0;
    if (a==0) {
        ans = b / x + 1;
    } else {
        ans = b / x + 1 - ((a - 1) / x + 1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
w = list(map(int, input().split()))
ans = float("inf")
for i in range(1, 101):
    # smaller = [j for j in w if j <= i]
    # bigger = [j for j in w if j > i]
    # ans = min(sum(smaller), sum(bigger))
    # print(w[i:])
    # print(w[0:i])
    # if w[i-1] != w[i]:
    # print(w[i-1], w[i])
    tmp = abs(sum(w[i:]) - sum(w[0:i]))
    ans = min(tmp, ans)

print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

/**
 * Created by mizuk on 2017/07/26.
 */
public class Main {

    private static long x = 0;   //前者の和
    private static long y = 0;   //後者の和
    private static int N;
    private static int a[];
    private static long ans;

    public static void input(){
        Scanner scan = new Scanner(System.in);
        N = scan.nextInt();
        a = new int[N];

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

    public static void main(String args[]){
        //入力
        input();

        //x,y初期値
        x = a[0];
        for(int i=1;i<N;i++){
            y += a[i];
        }

        ans = Math.abs(x-y);
        for(int i=1;i<N-1;i++){
            x += a[i];
            y -= a[i];
            ans = Math.min(Math.abs(x-y) , ans);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 64260
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define classname SubtreeSumHash

const int maxn = 100000 + 10;
const ll mod = 1e+9 + 7;
ll x[maxn], y[maxn];
ll sx[maxn], sy[maxn];

void solve()
{
    int n, m;
    cin >> n >> m;
    
    for(int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    
    for(int i = 0; i < m; i++)
    {
        cin >> y[i];
    }
    
    ll r1 = 0, r2 = 0;
    
    for(int i = 0; i < n - 1; i++)
    {
        sx[i] = x[i + 1] - x[i];
        sx[i] %= mod;
    }
    
    for(int i = 0; i < n - 1; i++)
    {
        sx[i] *= ll(i + 1) * ll(n - 1 - i);
        sx[i] %= mod;
        r1 += sx[i];
        r1 %= mod;
    }
    
    for(int i = 0; i < m - 1; i++)
    {
        sy[i] = y[i + 1] - y[i];
        sy[i] %= mod;
    }
    
    for(int i = 0; i < m - 1; i++)
    {
        sy[i] *= ll(i + 1) * ll(m - 1 - i);
        sy[i] %= mod;
        r2 += sy[i];
        r2 %= mod;
    }
    
    cout << (r1 * r2) % mod << "\n";
    //cout << "\n";
}


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    solve();
    return 0;
}


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

int main(){
    int N,T;
    cin >> N >> T;
    vector<int> a(N);
    vector<int> b(N);
    long long ans=0;
    for(int i=0;i<N;i++){
        int t; cin >> t;
        a[i]=t;
        b[i]=t+T;
    }
    long long cnt=0;
    for(int i=1;i<N;i++){
        if(a[i]>b[i-1]){
            cnt+=a[i]-b[i-1];
        }
    }
    ans=b[N-1];
    ans-=cnt;
    cout << ans << endl;
}

Measured memory_bytes: 1792
n, l = map(int, input().split())
ans = [l + i - 1  for i in range(1,n+1)]

if (l >= 0):
    ans.pop(0)
    print(sum(ans))
elif(n > abs(l)):
    ans.pop(ans.index(0))
    print(sum(ans))
else:
    ans.pop(ans.index(max(ans)))
    print(sum(ans))

Measured memory_bytes: 9096
n = int(input())
li = list(map(int,input().split()))
li.sort(reverse=True)
ans = 0

for i in range(n//2):
    if i == 0:
        ans += li[i]
    else:
        ans += li[i]*2

if n%2 == 1:
    ans += li[i+1]

print(ans)


Measured memory_bytes: 94192
from collections import deque
N = int(input())
S = deque([3, 5, 7])
ans = 0
for _ in range(3**10):
    a = S.popleft()
    if a <= N:
        tmp = a
        j3, j5, j7 = False, False, False
        while tmp > 0:
            if tmp%10 == 3:
                j3 = True
            elif tmp%10 == 5:
                j5 = True
            else:
                j7 = True
            tmp //= 10
        if j3 and j5 and j7:
            ans += 1
    S.append(a*10+3)
    S.append(a*10+5)
    S.append(a*10+7)
print(ans)



Measured memory_bytes: 15520
#include <iostream>

using namespace std;

int main() {
	int x;
	cin >> x;
	
	for (int a = -118; a <= 119; a++) {
		for (int b = -118; b <= 119; b++) {
			if (a * a * a * a * a - b * b * b * b * b == x) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 3648
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<ll> f(n + 1, 0);
    f[0] = 2;
    f[1] = 1;
    for(int i = 2; i <= n; i++){
        f[i] = f[i - 1] + f[i - 2];
    }
    cout << f[n];
    return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = 998244353;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 200 * 1000 + 13;
const int M = 1000 * 1000 + 13;

int n;
int a[N];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n)
		scanf("%d", &a[i]);
	return true;
}

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

int mul(int a, int b){
	return a * li(b) % MOD;
}

int binpow(int a, int b){
	int res = 1;
	while (b){
		if (b & 1)
			res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int mu[M];

void precalc(){
	static int lst[M];
	forn(i, M)
		lst[i] = i;
	mu[1] = 1;
	for (int i = 2; i < M; ++i){
		if (lst[i] == i)
			mu[i] = -1;
		for (int j = 2 * i; j < M; j += i){
			lst[j] = min(lst[j], lst[i]);
			if (lst[j] == lst[i])
				mu[j] = 0;
			else
				mu[j] = -mu[i];
		}
	}
	forn(i, M){
		mu[i] = add(0, mu[i]);
	}
}

int sum[M], sum2[M];

void solve(){
	precalc();
	
	memset(sum, 0, sizeof(sum));
	memset(sum2, 0, sizeof(sum2));
	forn(i, n){
		int mm = mul(a[i], a[i]);
		for (int j = 1; j * j <= a[i]; ++j) if (a[i] % j == 0){
			sum[j] = add(sum[j], a[i]);
			sum2[j] = add(sum2[j], mm);
			if (j != a[i] / j){
				sum[a[i] / j] = add(sum[a[i] / j], a[i]);
				sum2[a[i] / j] = add(sum2[a[i] / j], mm);
			}
		}
	}
	
	int rev = binpow(2, MOD - 2);
	int ans = 0;
	fore(g, 1, M){
		int s = 0;
		int s2 = 0;
		int rev2 = binpow(g, MOD - 2);
		for (int i = g; i < M; i += g) if (mu[i / g] != 0){
			int tmp = mul(rev, add(mul(sum[i], sum[i]), -sum2[i]));
			s = add(s, mul(mu[i / g], mul(rev2, tmp)));
		}
		ans = add(ans, s);
	}
	
	printf("%d\n", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if(read()) {
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 16640
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return "".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

t = list(input()[:-1])

for i in range(len(t)):
	if t[i]== "?":
		t[i] = "D"
print(jo(t))





Measured memory_bytes: 91092
#include <iostream>
#include <algorithm>
#define ll long long int
using namespace std;
 
ll H,W;
 
ll maxfun(ll a, ll b , ll c){
  ll  result;
  a>b? (result = a):(result =b);
  return (result >c)? (result):c;
}
ll minfun(ll a, ll b , ll c){
  ll result;
  a<b? (result = a):(result =b);
  return   (result <c)? (result):c;
}

ll solve(ll h, ll w){
  ll result;
  for(int i = h/3; i < h/2+1;i++){
    int j= w/2;
    ll s1 = i*w;
    ll s2 = j*(h-i);
    ll s3 = (h-i)*(w-j);
    result = min(result,(maxfun(s1,s2,s3)-minfun(s1,s2,s3)));
  }
  return result;
}

int main(){
  ll result=100000;

  
  cin >> H >> W;
 
  if((H%3)*(W%3)==0){
    cout << "0" << endl;
    return 0;
  }

  else result = H<W? H:W;
  cout << "" ;  //これがないとバグるのなぜ？
  cout << minfun(solve(H,W),solve(W,H),result) << endl;
  return 0;
 
}


Measured memory_bytes: 256
// Problem : C - Attack Survival
// Contest : AtCoder Beginner Contest 141
// URL : https://atcoder.jp/contests/abc141/tasks/abc141_c
// Memory Limit : 1024,000000 MB
// Time Limit : 2000,000000 milisec
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

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

  cout.precision(16);
  cout << fixed;

  int n;
  int k;
  int q;
  cin >> n >> k >> q;

  map<int, int> correct;

  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;

    correct[--t]++;
  }

  for (int i = 0; i < n; ++i) {
    if (k - (q - correct[i]) <= 0) {
      cout << "No";
    } else {
      cout << "Yes";
    }

    cout << '\n';
  }
}


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

using namespace std;
typedef long long ll;

int main() {
  int n, m, c;
  cin >> n >> m >> c;

  int cnt = 0;
  int b[20];
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < n; ++i) {
    int sum = 0;
    for (int j = 0; j < m; ++j) {
      int a;
      cin >> a;
      sum += a * b[j];
    }
    sum += c;
    if (sum > 0) {
      ++cnt;
    }
  }

  cout << cnt;

  return 0;
}


Measured memory_bytes: 256
/* ITP1_6_D: Mtrix Vector Multiplication */

#include <iostream>

int main() {
    int row, col;
    std::cin >> row >> col;

    int matrix[row][col];
    int cvector[col];

    // Read the matrix.
    for (int i_r = 0; i_r < row; i_r++) {
        for (int i_c = 0; i_c < col; i_c++) {
            std::cin >> matrix[i_r][i_c];
        }
    }

    // Read the column vector.
    for (int i_c = 0; i_c < col; i_c++) {
        std::cin >> cvector[i_c];
    }

    // Output results.
    for (int i_r = 0; i_r < row; i_r++) {
        int ans_row = 0;
        for (int i_c = 0; i_c < col; i_c++) {
            ans_row += matrix[i_r][i_c] * cvector[i_c];
        }
        std::cout << ans_row << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <map>

int main()
{
    int n{}, m{};
    std::cin >> n >> m;
    int s{}, c{};
    std::map<int, int> keta;
    for (int i = 0; i < m; i++) {
        std::cin >> s >> c;
        const auto itr = keta.find(s);
        if (itr != keta.end() && itr->second != c) {
            std::cout << -1 << std::endl;
            return 0;
        } else {
            keta[s] = c;
        }
    }
    if (n > 1) {
        const auto itr = keta.find(1);
        if (itr != keta.end() && itr->second == 0) {
            std::cout << -1 << std::endl;
            return 0;
        }
    }

    int val{};
    int x = 1;
    for (int i = 0; i < n; i++) {
        const auto itr = keta.find(n - i);
        if (itr != keta.end()) {
            val += itr->second * x;
        }
        x *= 10;
    }
    int n2 = 1;
    int tmp = val;
    while (tmp >= 10) {
        tmp /= 10;
        n2++;
    }
    if (n == n2) {
        std::cout << val << std::endl;
    } else {
        std::cout << (val + x / 10) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
INF = 10 ** 18
dp = [INF] * (N + 1)
dp[0] = 0
dp[1] = 0
dp[2] = abs(h[1] - h[0])
for i in range(2, N):
    dp[i+1] = min(dp[i-1] + abs(h[i] - h[i-2]), dp[i] + abs(h[i] - h[i-1]))
print(dp[N])

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

int fail() {
	cout << "Impossible" << endl;
	return 0;
}

int main() {
	int H, W, minj, maxj, prevLast = 0;
	bool pos = true;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		string l;
		bool found = 0;
		int first, last, cnt = 0;
		cin >> l;
		for (int j = 0; j < W; j++) {
			if (l[j] == '#') {
				if (!found) {
					if(j < prevLast) return fail();
					found = true;
					first = j;
				}
				cnt++;
				if(first + cnt - 1 < j) return fail();
				last = j;
			}
		}
		prevLast = last;
	}
	cout << "Possible" << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;

int n;
int main()
{
	int i,now=7;
	scanf("%d",&n);
	if(n%2==0||n%5==0)
	{
		printf("-1");
		return 0;
	}
	for(i=1;;i++)
	{
		if(now%n==0)
		{
			printf("%d",i);
			return 0;
		}
		now=(now*10+7)%n;
	}
}

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

#define int long long 

int32_t main()
{
    int r,d,x;
    cin>>r>>d>>x;
    for(int i=0; i<10; i++)
    {
        x = r*x - d;
        cout<<x<<endl;
    }
    return 0;
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  lint n; cin >> n;
  cout  << (n-1)*n/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    string S; cin >> S;
    int num0 = 0, num1 = 0;
    for (int i = 0; i < (int) S.length(); ++i) {
		if (S[i] == '0') ++num0;
		else ++num1;
	}
	cout << 2 * min(num0, num1) << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3748
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=2e6+1e2;
int n;
int a[maxn],val[maxn];

inline void file() {
	freopen("pyramid.in","r",stdin);
	freopen("pyramid.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

inline bool check(int k) {
	For (i,1,2*n-1) val[i]=(a[i]<=k);
	For (i,0,n-2) {
		if (val[n-i] && val[n-i-1]) return 1;
		if (val[n+i] && val[n+i+1]) return 1;
		if (!val[n-i] && !val[n-i-1]) return 0;
		if (!val[n+i] && !val[n+i+1]) return 0;
	}
	return val[1];
}

int main() {
//	file();
	n=read();
	int l=0,r=0,mid;
	For (i,1,2*n-1) a[i]=read(),chkmax(r,a[i]);
	while (l<r) {
		mid=(l+r)/2;
		if (check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 5120
#include <cstdio>
#include <cmath>
#include <iostream>

#define rep( i, n, m ) for (int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for (int i = ( n ); i < ( m ); i--)

int main( void ){
	int n, k;
	if(!scanf( "%d%d", &k, &n ))
		return -1;
	int count = 0;
	rep( i, 0, k + 1 ){
		rep( j, 0, k + 1 ){
			int l = n - i - j;
			if (l > -1 && l < k + 1)
				count++;
		}
	}
	printf( "%d\n", count );
	return 0;
}


Measured memory_bytes: 764
///same with abc068c
#include <stdio.h>
#include <vector>
int n, m;
std::vector<int> e[400002];
int main()
{
	int a, b;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d", &a, &b);
		e[a].push_back(b);	e[b].push_back(a);
	}
	a = 0;
	for (auto& k : e[n])
	{
		for (auto& kk : e[k]) if (kk == 1) { a = 1; break; }
		if (a) break;
	}
	printf("%s\n", a ? "POSSIBLE" : "IMPOSSIBLE");
}

Measured memory_bytes: 16624
use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    
    let mut iter = buf.split_whitespace().map(|c| c.parse::<usize>().unwrap());
    let mut counts = HashMap::new();
    
    
    for c in iter {
        if let Some(x) = counts.get_mut(&c) {
            *x += 1;
            continue;
        }
        counts.insert(c, 1);
    }
    
    if counts.values().all(|&c| c >= 1 && c <= 2) {
        println!("YES");
    } else {
        println!("NO");
    }
}

Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    n = int(input())
    a = list(map(int, input().split()))
    total = 0
    ans = ['']*n
    for x in a:
        total ^= x
    for i in range(n):
        ans[i] = total ^ a[i]
    print(*ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 100392
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
#include <cstring>


int main() {
    int h, w; std::cin >> h >> w;
    std::vector<std::string> s(h);
    for (int i = 0; i < h; i++) std::cin >> s[i];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] != '.') continue;
            int cnt = 0;
            for (int u = -1; u <= 1; u++) {
                for (int v = -1; v <= 1; v++) {
                    if (!(0 <= i + u && i + u < h)) continue;
                    if (!(0 <= j + v && j + v < w)) continue;
                    cnt += s[i + u][j + v] == '#';
                }
            }
            s[i][j] = cnt + '0';
        }
    }
    for (auto &t : s) std::cout << t << std::endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

public class Test
{
	public static void Main()
	{
    string line = Console.ReadLine();
    int a = int.Parse(line[0].ToString());
    int b = int.Parse(line[1].ToString());
    int c = int.Parse(line[2].ToString());
    int d = int.Parse(line[3].ToString());

    if(a+b+c+d == 7){
      Console.WriteLine(a+"+"+b+"+"+c+"+"+d+"=7");
    } else if (a+b+c-d == 7){
      Console.WriteLine(a+"+"+b+"+"+c+"-"+d+"=7");
    } else if (a+b-c+d == 7){
      Console.WriteLine(a+"+"+b+"-"+c+"+"+d+"=7");
    } else if (a+b-c-d == 7){
      Console.WriteLine(a+"+"+b+"-"+c+"-"+d+"=7");
    } else if (a-b+c+d == 7){
      Console.WriteLine(a+"-"+b+"+"+c+"+"+d+"=7");
    } else if (a-b+c-d == 7){
      Console.WriteLine(a+"-"+b+"+"+c+"-"+d+"=7");
    } else if (a-b-c+d == 7){
      Console.WriteLine(a+"-"+b+"-"+c+"+"+d+"=7");
    } else if (a-b-c-d == 7){
      Console.WriteLine(a+"-"+b+"-"+c+"-"+d+"=7");
    }
  }                                                                                                                                                                       
}

Measured memory_bytes: 13140
S = str(input())
#021021334/51607/829410
YYYY=int(S[0:4])
MM=int(S[5:7])
DD=int(S[8:10])
#print(YYYY,MM,DD)

if YYYY>=2019 and MM>=5:
  print("TBD")
else:
  print("Heisei")
# 2019 年 4 月 30 日またはそれ以前なら 、そうでなければ TBD と出力するプログラムを書いてください。

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 1000000007;

map<int,int> mp;

void Divide(int n) {
  int np = n;
  for (int i = 2; i*i <= np; i++) {
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n != 1) {
    mp[n]++;
  }
  return ;
}

int main() {
  int N;
  cin >> N;
  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 2; i <= N; i++) {
    Divide(i);
  }
  ll ans = 1;
  for (auto p : mp) {
    ans *= p.S + 1;
    ans %= Mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#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 ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl
int gcd(int x, int y){
    if ((x==1)||(y==1)) return 1;
    if (x>y) {
        if (x%y==0) {
            return y;
        }else{
            return gcd(y, x%y);
        }
    }else{
        if (y%x==0) {
            return x;
        }else{
            return gcd(x, y%x);
        }
    }
}
int main() {
    IN(int, s);
    bool b1 = false;
    bool b2 = false;
    if (s/100>0 &&  s/100<13) {
        b1 = true;
    }
    if (s%100>0 &&  s%100<13) {
        b2 = true;
    }
    if (b1&&b2) {
        COUT("AMBIGUOUS");
    }else if (b1){
        COUT("MMYY");
    }else if (b2){
        COUT("YYMM");
    }else {
        COUT("NA");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int n,k;
string s;
signed main(){
	cin>>n>>k>>s;
	rep(i,n){
		if(i==k-1){
			if(s[i]=='A'){
				cout<<'a';
			}elif(s[i]=='B'){
				cout<<'b';
			}else{
				cout<<'c';
			}
		}else{
			cout<<s[i];
		}
	}
}

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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

class LazySegTree {
    int n = 1;
    vector<ll> node, lazy;

public:
    LazySegTree(vector<ll> v) {
        while (n < v.size()) n *= 2;
        node.resize(2*n-1, 0);
        lazy.resize(2*n-1, 0);

        for (int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
        for (int i = n-2; i >= 0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    ll eval(int k, int l, int r) {
        if (lazy[k] != 0) {
            node[k] += lazy[k];

            if (r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }

            lazy[k] = 0;
        }
        return node[k];
    }

    ll add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (b <= l || r <= a) return 0;

        if (a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            return eval(k, l, r);
        } else {
            add(a, b, x, k*2+1, l, (l+r)/2);
            add(a, b, x, k*2+2, (l+r)/2, r);
            return node[k] = node[k*2+1] + node[k*2+2];
        }
    }
    
    ll getSum(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (b <= l || r <= a) return 0;

        eval(k, l, r);
        if (a <= l && r <= b) return node[k];
        ll vl = getSum(a, b, k*2+1, l, (l+r)/2);
        ll vr = getSum(a, b, k*2+2, (l+r)/2, r);
        return vl + vr;
    }
};

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

    int N, Q;
    cin>>N>>Q;

    vector<ll> v(N, 0);
    LazySegTree lst(v);
    for (int q = 0; q < Q; q++) {
        int type;
        cin>>type;
        if (type == 0) {
            int s, t;
            ll x;
            cin>>s>>t>>x;
            lst.add(s-1, t, x);
        } else {
            int s, t;
            cin>>s>>t;
            cout<<lst.getSum(s-1, t)<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 8664
#include <iostream>

using namespace std;

int main(){
  int K,S; cin>>K>>S;
  int ans=0;
  for(int i=0;i<=S;i++){
    for(int j=0;j<=(S-i);j++){
      int C=S-i-j;
      if(C>=0&&C<=K&&i<=K&&j<=K) ans++;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256