akhauriyash/Code-Regression huggingface dataset:
import numba
import numpy as np
N = int(input())
P = np.array([int(c)-1 for c in input().split()])

#from random import shuffle
#N = 500
#P = list(range(N*N))
#shuffle(P)
#P = np.array(P)

@numba.njit("i8(i8,i8[:])", cache=True)
def proc(N, P):
    ans = 0
    Removed = np.zeros((500, 500), dtype=np.int8)
    Mat = np.zeros((500, 500), dtype=np.int16)
    Dy, Dx = [1,0,-1,0], [0,1,0,-1]

    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N-1-y, x, N-1-x)
    #print(Mat)
    Buf = [(0, 0) for _ in range(1<<17)]
    Buf_idx = 0
    for i in range(N*N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y,x]
        Removed[y,x] = 1
        Buf[Buf_idx] = (y, x)
        Buf_idx += 1
        while Buf_idx:
            Buf_idx -= 1
            vy, vx = Buf[Buf_idx]
            vr = Removed[vy,vx]
            val = Mat[vy,vx]
            #for dy, dx in zip(Dy, Dx):
            for j in range(4):
                uy, ux = vy + Dy[j], vx + Dx[j]
                if not (0<=uy<N and 0<=ux<N):
                    continue
                ur = Removed[uy,ux]
                if vr:
                    if Mat[uy,ux] >= val+1:
                        Mat[uy,ux] = val
                        Buf[Buf_idx] = (uy, ux)
                        Buf_idx += 1
                else:
                    if Mat[uy,ux] >= val+2:
                        Mat[uy,ux] = val+1
                        Buf[Buf_idx] = (uy, ux)
                        Buf_idx += 1
    # for m in Mat:
    #     print(m)
    return ans
print(proc(N, P))



Measured memory_bytes: 123516
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
typedef long long ll;
using namespace std;

int main()
{
    long int s=0;
    long int n;
    cin>>n;
    for(ll i=2;i*i<=n;i++)
    {ll b=1;
        if(n%i==0)
        {ll c=0;
            b=b*i;
            while(n%i==0)
            {
                if(n%b==0)
                {c++;n=n/b;b=b*i;
                }
                else
                n=n/i;
            }
            s=s+c;
        }
    }
    if(n!=1)
    s=s+1;
    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 3644
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.insert(0,0)
C = {i:[] for i in range(1,N+1)}
for i in range(2,N+1):
    C[A[i]].append(i)
for i in range(1,N+1):
    print(len(C[i]))

Measured memory_bytes: 129520
MOD = 10 ** 9 + 7


def prepare(n):
    global MOD
    factorials = [0] * (n + 1)
    factorials[0] = 1
    for i in range(n):
        factorials[i + 1] = (factorials[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(factorials[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return factorials, invs


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

factorials, invs = prepare(N)

for i in range(1, K + 1):
    A = factorials[K - 1] * invs[i - 1] * invs[K - i] % MOD
    if N - K < i - 1:
        B = 0
    else:
        B = factorials[N - K + 1] * invs[i] * invs[N - K + 1 - i] % MOD
    print((A * B) % MOD)


Measured memory_bytes: 3444
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]*n
for i in range(n):
    if a[i] + a[i+1] >= b[i]:
        c[i] = b[i]
        if a[i] < b[i]:
            a[i+1] = a[i+1] + a[i] - b[i]
    else:
        c[i] = a[i] + a[i+1]
        a[i+1] = 0
print(sum(c))

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

int main() {
  std::string N;
  cin >> N;
  if ((N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3])) {
    cout << "Yes" << endl;
  }
  else
  {
      cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

#%%
ans = float('inf')
# 直感的にはAの平均周辺が最小値っぽい
mean = sum(A)//n
means = [mean-1, mean, mean+1]
for m in means:
    tmp = 0
    for a in A:
        tmp += (m - a)**2
    ans = min(ans, tmp)

print(ans)



Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    for (int i = N; i < 1000; i++)
    {
        string s = to_string(i);
        if (s[0] == s[1] && s[1] == s[2])
        {
            cout << s << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string S, T;
        cin >> S >> T;
        ll ans = 0;
        rep(i, 0, len(S)) {
                if (S[i] != T[i]) ++ans;
        }
        cout << ans << endl;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    vector<string> s(3);
    cin>>s[0]>>s[1]>>s[2];
    string ans="";
    ans+=s[0][0];
    ans+=s[1][1];
    ans+=s[2][2];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp28 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int n = st[0];
            int m = st[1];

            Console.WriteLine((n - 1) * (m - 1));
           
        }
    }
}

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

int n;
int p[4];
int t[4];

int main() {
	int i, j, k;
	
	cin >> n;
	rep(i, 4) cin >> t[i];
	rep(i, 4) cin >> p[i];
	
	int ans = 1145141919;
	rep(i, 101) {
		rep(j, 101) {
			rep(k, 101) {
				int l = n - (i * p[0] + j * p[1] + k * p[2]);
				if (l < 0) l = 0;
				l = (l + p[3] - 1) / p[3];
				int res = i * t[0] + j * t[1] + k * t[2] + l * t[3];
				ans = min(ans, res);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3112
//#1857601 Solution for 0146: Lupin The 4th by T1610

#include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = 10000000000000 ;
string e = "";
pll dp[(2 << 16)+1][16],ans;
ll w[(2 << 15)];
array<int,16> d,m,num;
void init(){
  rep(i,(2<<16)+1){
    rep(j,16)
    dp[i][j] = make_pair(inf,-1);
  }
  fill(all(d),0);
  fill(all(m),0);
}
ll n;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  init();
  cin >> n;
  rep(i,n){
    cin >> num[i] >> d[i] >> m[i];
    m[i] *= 20;
  }

  rep(i,1 << n){
    int sum = 0;
    rep(j,n){
      dp[i][j] = make_pair(inf,-1);
      if((i & (1<<j))) sum += m[j];
    }
    w[i] = sum;
  }
  rep(i,n) dp[1 << i][i].fi = 0;
  rep(i,1 << n){
    rep(now,n){
      if( (i & (1 << now)) == 0) continue;
      rep(nxt,n){
        if((i & (1 << nxt)) != 0) continue;
        dp[ i | (1 << nxt)][nxt] = min(dp[i | (1 << nxt)][nxt],make_pair(dp[i][now].fi + abs((d[now] - d[nxt]) * (70+w[i])),(ll)now));
      }
    }
  }
  ll suf = 0,mi = inf,last = (1 << n) -1;
  rep(i,n){
    if(mi > dp[last][i].fi){
      suf = i;
      mi = dp[last][i].fi;
    }
  }
  int prev = last;
  vector<ll> ans;
  while(suf != -1){
    ans.pb(num[suf]);
    int tmp = dp[prev][suf].se;
    prev -= (1 << suf);

    suf = tmp;
  }
  reverse(all(ans));
  rep(i,n){
    if(i != 0) cout << " " ;
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 36220
#include<cstdio>
using namespace std;
int main(void)
{
	char s[4];
	int x;
	scanf("%s",s);
	x=0;
	if(s[0]=='1')	x++;
	if(s[1]=='1')	x++;
	if(s[2]=='1')	x++;
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
package main

import (
    "fmt"
    "math"
    "sort"
)

func main() {
    var n, k int
    fmt.Scan(&n, &k)
    as := make([]int, n)
    var sum int
    for i := range as {
        fmt.Scan(&as[i])
        sum += as[i]
    }
    var divs []int
    sqrt := int(math.Sqrt(float64(sum)))
    for i := 1; i <= sqrt; i++ {
        if sum%i == 0 {
            divs = append(divs, i)
            if i != sum/i {
                divs = append(divs, sum/i)
            }
        }
    }
    sort.Sort(sort.Reverse(sort.IntSlice(divs)))
    for _, div := range divs {
        var bsum int
        bs := make([]int, n)
        for i := range as {
            bs[i] = as[i] % div
            bsum += bs[i]
        }
        sort.Sort(sort.Reverse(sort.IntSlice(bs)))
        var ksum int
        for i := 0; i < bsum/div; i++ {
            ksum += div - bs[i]
        }
        if ksum <= k {
            fmt.Println(div)
            break
        }
    }
}


Measured memory_bytes: 4736
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, T, A, ans = 0; cin >> N >> T >> A;
    long double diff = 10e7 * 1.0;
    for (int i = 0; i < N; ++i) {
        int h; cin >> h;
        long double temp = T - (h * 0.006);
        if (diff >= abs(A - temp)) {
            diff = abs(A - temp);
            ans = i + 1;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  string s;
  cin >> s;
  sort(ALL(s));
  cout << (s[0] == s[1] && s[2] == s[3] && s[0] != s[2] ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int k;
long long now;
int main()
{
  cin >> k;
  now = 7;
  if (now % k == 0) {puts("1"); return 0;}
  for (int i = 2; i <= k; i+=1)
  {
  	now = (1ll * now * 10 % k + 7) % k;
    if (!now) {cout << i << endl; return 0;}
  }
  puts("-1");
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N=in(),K=in();
	ll L=in<ll>(),R=in<ll>();
	auto A=vecin<ll>(N);

	ll H=N/2;
	ll PH=1LL<<H;
	vector<pair<ll,ll>> S(PH);
	REP(i,PH){
		ll v=i;
		ll sum=0,num=0,index=0;
		while(v){
			if(v&1){
				num++;
				sum += A[index];
			}
			v>>=1LL;
			index++;
		}
		S[i]=make_pair(num,sum);
	}
	sort(ALL(S),[](pair<ll,ll>& l,pair<ll,ll>& r){return l.first==r.first?l.second<r.second:l.first<r.first;});

	ll ans=0;
	ll F=1LL<<(N-H);
	REP(i,F){
		ll v=i;
		ll num=0,sum=0,index=0;
		while(v){
			if(v&1){
				num++;
				sum += A[H+index];
			}
			v>>=1LL;
			index++;
		}
		auto res = equal_range(ALL(S),make_pair(K-num,1LL<<60),PAIRCOMP(first,<));
		if(res.first!=S.end()){
			auto left = lower_bound(res.first,res.second,make_pair(K-num,L-sum),[](const pair<ll,ll>& l,const pair<ll,ll>& r){return l.first==r.first?l.second<r.second:l.first<r.first;});
			auto right = upper_bound(res.first,res.second,make_pair(K-num,R-sum),[](const pair<ll,ll>& l,const pair<ll,ll>& r){return l.first==r.first?l.second<r.second:l.first<r.first;});
			ans += distance(left,right);
		}
	}
	out(ans);
	return 0;
}



Measured memory_bytes: 19140
#include <vector>
#include <stack>
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <typeinfo>
#include <queue>

using namespace std;

typedef long long ll;



void ichi(){
	string s;
	cin >> s;
	int tmp_c = 0;
	int tmp_f = 0;
	for(int i=0;i<s.size();i++){
		if(s[i] == 'C'){
			tmp_c = 1;
		}
		else if(s[i] == 'F'){
			if(tmp_c == 1){
				cout << "Yes" << endl;
				tmp_f = 1;
				break;
			}
		}
	}
	if(tmp_f == 0){
		cout << "No" << endl;
	}

}




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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;

  if (k & 1) {
    cout << (n / k) * (n / k) * (n / k) << endl;
  } else {
    long long ans = (n / k) * (n / k) * (n / k);
    long long kk = k / 2;
    ans += ((n + kk) / k) * ((n + kk) / k) * ((n + kk) / k);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;

use itertools::Itertools;

#[proconio::fastout]
fn main() {
    input! {
    h:usize,
    w:usize,
    k:i32,
    board:[Chars;h],
    }

    let mut ans = 0;
    for num_lines in 0..=h {
        for lines in board.iter().combinations(num_lines) {
            let united_lines = lines.iter().fold(vec![0; w], |mut u, &l| {
                for j in 0..w {
                    if l[j] == '#' {
                        u[j] += 1;
                    }
                }
                u
            });

            for num_cols in 0..=w {
                for cols in united_lines.iter().combinations(num_cols) {
                    if cols.into_iter().sum::<i32>() == k {
                        ans += 1;
                    }
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2204
#include <bits/stdc++.h>
using namespace std;
     
#define int  long long
#define endl '\n'
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 25 + 1;

void solve(){
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++)
    cin >> l[i];
  sort(l.begin(), l.end());
  int ret = 0;
  for (int i = 0; i < n - 2; i++){
	  int idx = i + 2;
	  for (int j = i + 1; j < n; j++){
		  while (idx < n && l[i] + l[j] > l[idx])
		  idx++;
		  if (idx > j) 
		   ret += idx - j - 1;
		}  
	}
  cout << ret << endl;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();	
}


Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2019-07-11.
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int d,g,p[11],c[11];

    cin >> d >> g;
    for(int i = 0; i < d; ++i) {
        cin >> p[i] >> c[i];
    }

    int res = 1e9;
    for (int mask = 0; mask < (1 << d); mask++) {
        int accum = 0;
        int num = 0;
        int rest_max = -1;
        for (int i = 0; i < d; ++i) {
            if (mask >> i & 1) {
                accum += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            } else {
                rest_max = i;
            }
        }
        if (accum < g) {
            int score = 100 * (rest_max + 1);
            int need = (g - accum) / score + ((g - accum) % score > 0);
            if (need >= p[rest_max]) {
                continue;
            }
            num += need;
        }
        res = min(res, num);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#define DEBUG 0
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, m; std::cin >> n >> m;
  std::vector<std::vector<int>> graph(n), rgraph(n);
  loop(m) {
    int u, v; std::cin >> u >> v;
    graph.at(u).push_back(v);
    rgraph.at(v).push_back(u);
  }
  #if DEBUG
    rep(i,0,n) {
      debug(i, graph.at(i));
    }
  #endif

  auto ord = [&] {
    std::vector<int> ans;
    std::vector<int> ckd(n, false);
    auto dfs = [&] (auto&& dfs, int x) -> void {
      ckd.at(x) = true;
      for (int y : rgraph.at(x)) {
        if (ckd.at(y)) continue;
        dfs(dfs, y);
      }
      ans.emplace_back(x);
    };
    rep(i,0,n) {
      if (ckd.at(i)) continue;
      dfs(dfs, i);
    }
    return ans;
  }();
  std::reverse(all(ord));
  debug(ord);

  std::vector<int> cmp(n, -1);
  auto dfs = [&] (auto&& dfs, int x) -> void {
    for (int y : graph.at(x)) {
      if (cmp.at(y) != -1) continue;
      cmp.at(y) = cmp.at(x);
      dfs(dfs, y);
    }
  };
  for (int x : ord) {
    if (cmp.at(x) != -1) continue;
    cmp.at(x) = x;
    dfs(dfs, x);
  }
  debug(cmp);

  int q; std::cin >> q;
  loop(q) {
    int u, v; std::cin >> u >> v;
    bool ans = cmp.at(u) == cmp.at(v);
    std::cout << ans << std::endl;
  }
  return 0;
}


Measured memory_bytes: 4660
import java.util.Scanner;

class Main{

	static	int[] data;




	public static void main(String[] args) {





		Scanner sc = new Scanner(System.in);			//文字の入力
		String string = sc.next();
		StringBuilder sb = new StringBuilder(string);
		for(int i = 0;i < string.length();i++){
			if(sb.charAt(i) == ','){
				sb.setCharAt(i, ' ');
			}
		}
		string = new String(sb);
		System.out.println(string);



	}



	static void num(int n){


		int num = n;
		for(int i = 1;i <= n;i++){
			if(n % i == 0){
				data[i]++;
				n /= i;
				i = 1;
			}
		}
		return;

	}
}


class Pair implements Comparable{
	Character from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 23124
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto a = RD!char;

	writeln(a-'a' >= 0 && a-'a' <= 26 ? 'a' : 'A');
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 2680
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  z=pM(split(readline()))
  print(sum(z)-maximum(z))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 164860
//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <climits>

using namespace std;
using ll=long long;

void solve(){
  string str;
  cin >> str;
  int mod=(int)1e9+7;
  std::vector<ll> dp(4);
  dp[0]=1;
  for(int i=0;i<str.length();i++){
    vector<ll> newdp(4);
    for(int j=0;j<4;j++){
      if(j!=3&&(str[i]-'A'==j||str[i]=='?'))
        newdp[j+1]=dp[j];
      newdp[j]=(newdp[j]+(str[i]=='?'?3:1)*dp[j])%mod;
    }
    dp=newdp;
  }
  cout << dp[3] << endl;
}

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int a,b,c,vis[110],x;

int main(void)
{
	cin>>a>>b>>c;
	while(vis[x]==false)
	{
		vis[x]=true;
		if(x==c)
			return 0*puts("YES");
		x+=a;
		x%=b;
	}
	puts("NO"); 
}

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

int main(){
  int l[10];
  int t1,t2;
  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"
	      ,&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&t1,&t2)>0){
    float p=(accumulate(l,l+10,0)*t1)/(float)(t1+t2);
    for(int i=0;i<10;i++){
      p-=l[i];
      if(p<=0){
	printf("%d\n",i+1);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <numeric>

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    vector<int> a(n + 1);

    for (int i = 1; i < n; i++) {
        a[i + 1] = a[i] + (s[i - 1] == 'A' && s[i] == 'C');
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;

        int ans = a[r] - a[l - 1];

        if (a[l - 1] != a[l]) {
            ans--;
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 1472
import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
  
	static int dp[][] = new int[100000][3];
	
  	public static int helper(int a[][], int i, int j) {
  		if (i < 0) {
  			return 0;
  		} else if (dp[i][j] > -1) {
  			return dp[i][j];
  		} else if (j == 0) {
  			dp[i][j] = Math.max(a[i][j] + helper(a, i-1, 1), a[i][j] + helper(a, i-1, 2));
  		} else if (j == 1) {
  			dp[i][j] = Math.max(a[i][j] + helper(a, i-1, 0), a[i][j] + helper(a, i-1, 2));
  		} else {
  			dp[i][j] = Math.max(a[i][j] + helper(a, i-1, 0), a[i][j] + helper(a, i-1, 1));
  		}
  		
      	return dp[i][j];
    }
      
	public static void main(String args[]) throws IOException {
     	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int n = Integer.parseInt(br.readLine());
      	int a[][] = new int[n][3];
        for (int i = 0 ; i < n ; ++i) {
         	String in[] = br.readLine().split(" ");
          	a[i][0] = Integer.parseInt(in[0]);
          	a[i][1] = Integer.parseInt(in[1]);
          	a[i][2] = Integer.parseInt(in[2]);
        }
      	
      	for (int i = 0 ; i < 100000 ; ++i) {
      		dp[i][0] = dp[i][1] = dp[i][2] = -1;
      	}
      	int max = Integer.MIN_VALUE;
      	max = Math.max(max, helper(a, n-1, 0));
      	max = Math.max(max, helper(a, n-1, 1));
      	max = Math.max(max, helper(a, n-1, 2));
      	System.out.println(max);
    }
}

Measured memory_bytes: 67696
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;

  while(true){
    c-=b;
    if(c<=0)break;
    a-=d;
    if(a<=0)break;
  }

  Yes(c<=0);

  return 0;
}


Measured memory_bytes: 3640
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, k; cin >> n >> k;
    cout << n - k + 1 << endl;
    
}

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

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
    }

    if(a.at(0) != 0){
        cout << 0 << endl;
        return 0;
    }

    vector<int> r(n),b(n),g(n),ans(n);

    r.at(0) = 1;
    ans.at(0) = 3;
    
    for(int i = 1;i < n;i ++){

        if(a.at(i) == r.at(i-1)){
            r.at(i) = r.at(i-1) +1;
        }else if(a.at(i) == b.at(i-1)){
            b.at(i) = b.at(i-1) +1;
        }else{
            g.at(i) = g.at(i-1) +1;
        }

        if(r.at(i) == 0){
            r.at(i) = r.at(i-1);
        }
        if(b.at(i) == 0){
            b.at(i) = b.at(i-1);
        }
        if(g.at(i) == 0){
            g.at(i) = g.at(i-1);
        }

        int x = 0;
        if(a.at(i) == r.at(i-1)){
            x ++;
        }
        if(a.at(i) == b.at(i-1)){
            x ++;
        }
        if(a.at(i) == g.at(i-1)){
            x ++;
        }

        ans.at(i) = (ans.at(i-1) * x) % 1000000007;

    }

    cout << ans.at(n-1) << endl;

}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,a[200005],sum=0,l1=0,l,r,b=10000000000000000;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=0;i<n;i++){
        l1+=a[i];
        if(abs(sum-2*l1)<b){
            b=abs(sum-2*l1);
            r=sum-l1;
            l=l1;
        }
    }
    cout<<abs(l-r)<<endl;
    return(0);
}

Measured memory_bytes: 5168
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int N, res; cin >> N;
    vector<int> a;
    for (int i = 0; i < N; i++)
    {
        int ai; cin >> ai;
        a.push_back(ai);
    }
    sort(a.begin(), a.end());
    res = a[N-1] - a[0];
    cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>




int main()
{
	long long int A[3][300000],N=0,K=0,cnt=0,next=0,i=0;

	scanf("%lld %lld",&N,&K);


	for(i=0;i<N;i++){
		scanf("%lld", &A[0][i]);
		A[1][i]=0;
		A[2][i]=0;
	}

	//A[0][i]はiから行ける町の番号
	//A[1][i]は町iにきた回数
	//A[2][i]は最初に町iにきた時の移動回数


	long long int now=1;
	A[1][0]=1;

	while(cnt<K){
		cnt++;
		next=A[0][now-1];
		A[1][next-1]++;
		
		//printf("移動回数=%lld,%lldから%lldへ\n",cnt,now,next);

		if(A[1][next-1]==1){
			A[2][next-1]=cnt;
			//printf("移動回数=%lldで初めて町%lldにきた\n",cnt ,next);
		}
		else{
			//printf("移動回数=%lldで二回目に町%lldにきた\n",cnt ,next);
			now=next;
			break;
		}


		now=next;

	}

	long long int onecycle = cnt - A[2][now-1];

	//printf("onecycle=%lld\n",onecycle);

	if(onecycle==0){
		printf("%lld",now);
	}
	else{

		long long int surplus=(K-cnt)%onecycle;

		cnt=surplus;

		//printf("残り移動回数=%lld,現在町%lldに滞在中\n",cnt,now);



		while(cnt!=0){

			next=A[0][now-1];

			//printf("残り移動回数=%lld,%lldから%lldへ\n",cnt,now,next);

			now=next;

			cnt--;

		}

		printf("%lld", now);

	}

	return 0;
}


Measured memory_bytes: 6412
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << ", "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << ", "; cerr << "\n"; }
#define dbm(map) cerr << #map << ":"; for (auto p : map) cerr << "(" << p.first << ", " << p.second << "), "; cerr << "\n";
#define YN(f) cout << (f ? "YES" : "NO") << "\n"
#define Yn(f) cout << (f ? "Yes" : "No") << "\n"
#define yn(f) cout << (f ? "yes" : "no") << "\n"
using ll = long long;
using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vb = vector<bool>;
using vvi = vector<vi>; using vvl = vector<vl>; using vvb = vector<vb>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using vpii = vector<pii>; using vpll = vector<pll>;
using ti3 = tuple<int, int, int>; using tl3 = tuple<ll, ll, ll>;
using mii = map<int, int>; using mil = map<int, ll>; using mli = map<ll, int>; using mll = map<ll, ll>;

const int MOD = 1000000007; // 998244353;

ll modadd(ll x, ll y) {
	ll xp = x % MOD;
	if (x < 0) x += MOD;
	ll yp = y % MOD;
	if (y < 0) y += MOD;
	return (x + y) % MOD;
}

ll modsub(ll x, ll y) {
	return modadd(x, -y);
}

ll modmul(ll x, ll y) {
	return x * y % MOD;
}

// power(mod) x^n
ll modpow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = modmul(res, x);
		x = modmul(x, x);
		n >>= 1;
	}
	return res;
}

// inverse(mod) x^(-1)
ll inv(ll x) {
	return modpow(x, MOD - 2);
}

ll moddiv(ll x, ll y) {
	return modmul(x, inv(y));
}

pii divs(int N, int prm) {
	int deg = 0;
	while (N % prm == 0) {
		N /= prm; deg++;
	}
	pii res(N, deg);
	return res;
}

mii pf(int N) {
	mii res;
	int prm = 2, deg;
	if (N % prm == 0) {
		tie(N, deg) = divs(N, prm);
		res[prm] = deg;
	}
	prm = 3;
	while (prm * prm <= N) {
		if (N % prm == 0) {
			tie(N, deg) = divs(N, prm);
			res[prm] = deg;
		}
		prm += 2;
	}
	if (N > 1) res[N] = 1;
	return res;	
}

int main() {	
	int N; cin >> N;
	vector<int> A(N); rep(i, N) cin >> A.at(i);
	vector<mii> pfA(N);
	mii pfK;
	rep(i, N) {
		for (pii pd : pf(A[i])) {
			int prm, deg; tie(prm, deg) = pd;
			if (pfK.count(prm)) pfK[prm] = max(pfK[prm], deg);
			else pfK[prm] = deg;
		}
	}
	ll K = 1;
	for (pii pd : pfK) {
		int prm, deg; tie(prm, deg) = pd;
		K = modmul(K, modpow(prm, deg));
	}
	ll ans = 0;
	rep(i, N) ans = modadd(ans, moddiv(K, A[i]));
	cout << ans << endl;
}

Measured memory_bytes: 1280
H, W = map(int, input().split())
l = [list(input()) for _ in range(H)]

from collections import deque
q = deque([(0, 0)])
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
l[0][0] = 0

while q:
    y, x = q.popleft()
    for dy, dx in d:
        if 0 <= y+dy < H and 0 <= x+dx < W and l[y+dy][x+dx] == '.':
            l[y+dy][x+dx] = l[y][x] + 1
            q.append((y+dy, x+dx))

try:
    g = l[H-1][W-1]
    total = 0
    for _l in l:
        for i in _l:
            if i != '#':
                total += 1
    print(total - g - 1)
except:
    print(-1)

Measured memory_bytes: 3316
package main

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

func main() {
	n := nextInt()
	var p int
	for i := 6; i > -1; i-- {
		p = int(math.Pow(2, float64(i)))
		if p <= n {
			fmt.Println(p)
			return
		}
	}
}

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextInt() int {
	n, _ := strconv.Atoi(nextLine())
	return n
}
func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}


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

int main() {
      string s;
      cin >> s;
      int counter = 0;
      if(s[0] == '1') ++counter;
      if(s[1] == '1') ++counter;
      if(s[2] == '1') ++counter;
      cout << counter << endl;
}

Measured memory_bytes: 256
D,G = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(D)]

ans = float('inf')
for b in range(2**D):
    score = ac = 0
    for i in range(D):
        if b&(1<<i):
            p,c = src[i]
            u = (i+1)*100
            score += c + p*u
            ac += p
    if score >= G:
        ans = min(ans, ac)
        continue
    for i in range(D-1,-1,-1):
        if b&(1<<i): continue
        p,c = src[i]
        p -= 1
        u = (i+1)*100
        if score + p*u >= G:
            rem = G - score
            actmp = -(-rem//u)
            ac += actmp
            ans = min(ans, ac)
            break
        else:
            score += p*u
            ac += p
print(ans)

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

int main() {
  long long n,k;
  //  long long ans=LLONG_MAX;

  cin >> n >> k;

  long long ans=n;

  n%=k;

  while(1) {
    if(n > abs(n-k)) {
      n=abs(n-k);
    }
    else {break;}
  }


  cout <<n<< endl;

  return 0;
}


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

int main() {

	int N, K;
	vector<int> l;

	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		l.push_back(x);
	}

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

	int sum = 0;
	for (int i = N - 1; i >= N - K; i--) {
		sum += l[i];
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

signed main() {
    string s;
    cin >> s;
    string ans = "";
    for(int i = 0; i < sz(s) ; i++) {
        if(s[i] != 'B') {
            ans += s[i];
        }else if(sz(ans) > 0) {
            ans.pop_back();
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define M 1005
typedef long long ll;
ll H, W, K, V, E;
char s[M][M];
ll read() {
	char c = getchar(); ll ans = 0;
	while (c < '0' || c > '9') c = getchar();
	while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
	return ans;
}
void Write(ll x) {
	if (x < 10) putchar(x + '0');
	else Write(x / 10), putchar(x % 10 + '0');
}
ll power(ll x, ll y, ll ans = 1) {
	for (; y; y >>= 1, x = x * x % mod)
		if (y & 1) ans = ans * x % mod;
	return ans;
}
ll invs(ll x) {return x == 1 ? 1 : (mod - mod / x) * invs(mod % x) % mod;} 
int main() {
	H = read(), W = read(), K = read();
	for (ll i = 1; i <= H; i++) scanf("%s", s[i] + 1);
	ll p1 = 0, p2 = 0, p;
	for (ll i = 1; i <= H; i++) p1 += (s[i][1] == '#' && s[i][W] == '#');
	for (ll i = 1; i <= W; i++) p2 += (s[1][i] == '#' && s[H][i] == '#');
	p = p1 + p2;
	for (ll i = 1; i <= H; i++)
		for (ll j = 1; j <= W; j++) V += (s[i][j] == '#');
	if (!p1 && !p2) return Write(power(V, K - 1)), 0;
	if (p1 && p2) return putchar('1'), 0;
	for (ll i = 1; i <= H; i++)
		for (ll j = 1; j <= W; j++)
			E += (p1 && j < W && s[i][j] == '#' && s[i][j + 1] == '#'),
			E += (p2 && i < H && s[i][j] == '#' && s[i + 1][j] == '#');
	if (!E) Write(power(V, K - 1));
	else Write(((power(V, K - 1) - E * (power(V, K - 1) - power(p, K - 1)) % mod * invs(V - p)) % mod + mod) % mod);
	return 0;
}


Measured memory_bytes: 4676
#

import sys
input=sys.stdin.readline

def main():
    D=int(input())
    C=list(map(int,input().split()))
    S=[list(map(int,input().split())) for i in range(D)]
    last=[[0]*27 for i in range(D+1)]
    satsum=0
    for day in range(1,D+1):
        maxt=0
        maxsat=0
        for t in range(1,27):
            sat=0
            sat+=S[day-1][t-1]
            for j in range(1,27):
                if j==t:
                    continue
                sat-=C[j-1]*(day-last[day][j])
            if t==1:
                maxt=t
                maxsat=sat
            elif maxsat<sat:
                maxt=t
                maxsat=sat
            
        satsum+=maxsat
        for j in range(day,D+1):
            last[j][maxt]=day
        satsum+=maxsat
        print(maxt)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 74572
from bisect import bisect
n=int(input())
lst=sorted(map(int,input().split()))
m=lst[-1]
index=bisect(lst,m/2)
if m!=lst[index]:
    q=lst[index]
    if 0<=index-1:
        p=lst[index-1]
        if abs(m/2-p)>=abs(m/2-q):
            print(m,q)
        else:
            print(m,p)
    else:
        print(m,q)
else:
    print(m,lst[index-1])

Measured memory_bytes: 84844
import Control.Monad
import Data.List

burger 0 = 1
burger n = burger (n - 1) * 2 + 3

bun 0 = 1
bun n = bun (n - 1) * 2 + 1

patty n 0 = 0
patty 0 x = 1
patty n x =
    if x > t `div` 2
    then patty (n - 1) (x - t `div` 2 - 1) + bun (n - 1) + 1
    else patty (n - 1) (x - 1)
    where t = burger n

main = do
    [n, x] <- map read . words <$> getLine
    print $ patty n x

Measured memory_bytes: 636
N, T = list(map(int, input().split(" ")))
c = []
t = []

for i in range(N):
    ci, ti = input().split(" ")
    c.append(int(ci))
    t.append(int(ti))
if min(t) > T:
    print("TLE\n")

else:
    cost = 10000
    for i in range(N):
        if cost > c[i] and T >= t[i]:
            cost = c[i]
    print(cost)

Measured memory_bytes: 3064
#include <stdio.h>

int num[1000000]={1,1};
int main(){
    int i,j,n,total;
    for(i=2;i<1000;i++)  if(!num[i]) for(j=i*i;j<1000000;j+=i)    num[j]=1;
    while(~scanf("%d",&n)){
        total=0;
        for(i=0;i<=n;i++)    
			if(!num[i]) total++;
        printf("%d\n",total);
    }
    return 0;
}

Measured memory_bytes: 4500
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 300010
#define mod 998244353
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

int dp[maxn+5];
struct segtree
{
    #define ls i*2
    #define rs i*2+1
    int a[maxn*4+5];
    void pu(int i) {a[i]=max(a[ls],a[rs]);}
    void chg(int i,int l,int r,int p,int x)
    {
        if(p<=l && r<=p) 
        {
            a[i]=max(a[i],x);
            return;
        }
        if(p<l || r<p) return;
        int mid=(l+r)>>1;
        chg(ls,l,mid,p,x);
        chg(rs,mid+1,r,p,x);
        pu(i);
    }
    int ask(int i,int l,int r,int ql,int qr)
    {
        if(ql<=l && r<=qr) return a[i];
        if(qr<l || r<ql) return 0;
        int mid=(l+r)>>1;
        return max(ask(ls,l,mid,ql,qr),ask(rs,mid+1,r,ql,qr));
    }
}T;

int a[maxn+5];

int main()
{
    int n,k; scanf("%d%d",&n,&k);
    rep(i,1,n) scanf("%d",&a[i]);
    int ans=0;
    rep(i,1,n) 
    {
        dp[i]=T.ask(1,0,maxn,a[i]-k,a[i]+k)+1;
        T.chg(1,0,maxn,a[i],dp[i]);
        ans=max(ans,dp[i]);
    }
    printf("%d\n",ans);
    return 0;
}

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

int main()
{
    float l;
    cin>>l;
    // cout<<l/3<<"\n";
    // float ans = (l/3)*(l/3)*(l/3);
    cout<<std::setprecision(18) << std::showpoint;
    cout<<pow(l,3)/27<<"\n";
    // cout<<ans<<"\n";
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
const ll INF = 4e18;
const ll MOD = 1e9+7;

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

  int a,b;
  cin >> a >> b;
  if (b%a == 0) cout << a+b << endl;
  else cout << b- a << endl;

  return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> stick(N);
  for (int i = 0; i < N; i++) {
    cin >> stick.at(i);
  }
  sort(stick.begin(), stick.end()); 
  reverse(stick.begin(), stick.end());
  int sum = 0;
  
  for (int i = 0; i < K; i++) {
    sum += stick.at(i);
  }
    cout << sum << endl;
}

  


  

Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())
a = tuple(map(int, input().split()))

ans = 0
d = defaultdict(int)
d[0] = 1

t = 0
for aa in a:
    t += aa
    ans += d[t % M]
    d[t % M] += 1
print(ans)


Measured memory_bytes: 15048