akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

ll f(ll N, ll P){
    vector<ll> A(N);
    ll i = 0;

    // Pは定数
    // stoneは変更可能
    ll stone = P;

    for(;;){
        if(stone>0){
            A[i]++;
            stone--;
            if(A[i]==P){
                // win
                return i;
            }
        }
        else{
            stone += A[i];
            A[i] = 0;
        }

        // 次の人へ
        i++;
        i %= N;
    }
}

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

    // input
    for(;;){
        ll N, P;
        cin >> N >> P;

        if(N==0 && P==0){
            return 0;
        }

        ll ans = f(N, P);
        p(ans);
    }
    
    return 0;
}


Measured memory_bytes: 3116
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    num_list = i_list()

    count = 0

    max_num = num_list[0]

    for i in range(1,n):
        if num_list[i] < max_num:
            count += max_num - num_list[i]
        else:
            max_num = num_list[i]

    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 109100
# include <iostream>
#include <math.h>

using namespace std;

typedef long long ll;

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

	ll x, y;

	int count = 0;

	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		long double z = sqrtl(x * x + y * y);
		if (z <= d) {
			count++;
		}
	}

	cout << count;
}


Measured memory_bytes: 3676
import math
S = input().split(" ")
N = int(S[0])
X = int(S[1])
Y = int(S[2])


def calculate(n, x, y):
    result = []
    x = x - 1
    y = y - 1
    for i in range(1, n):
        result.append(0)

    for i in range(n):
        for j in range(i+1,n):
            distance1 = int(math.fabs(x-i) + math.fabs(y-j) + 1)
            distance2 = j - i
            distance = min(distance1,distance2)

            result[distance-1] = result[distance-1] + 1


    for res in result:
        print(res)


calculate(N, X, Y)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll(i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll(i)=(a),(i##_len)=(b);(i)<=(i##_len);(i)++)
#define rrep(i,n) ll(i)=(n);ll now=-1;while((i)--&&(now++||1))
#define Yes(n) cout<<((n)?"Yes\n":"No\n")
#define vll vector<ll>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T abs(T x){return max(x,-x);}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm(T m,T n) {return m*n/gcd(m,n);}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm<T>(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

void solve(ll N, ll M, ll X, vector<ll> A){
    int cost_l = 0, cost_r = 0;
    rep(i, M) {
        if (A.at(i) > X) {
            cost_l = i;
            break;
        }
    }
    rrep(i, M) {
        if (A.at(i) < X) {
            cost_r = now;
            break;
        }
    }
    cout << min(cost_l, cost_r) << "\n";
}

int main() {
    ll N;
    ignore_ret(scanf("%lld",&N));
    ll M;
    ignore_ret(scanf("%lld",&M));
    ll X;
    ignore_ret(scanf("%lld",&X));
    vector<ll> A(M);
    for(int i = 0 ; i < M ; i++){
        ignore_ret(scanf("%lld",&A[i]));
    }
    solve(N, M, X, move(A));
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(int argc, const char * argv[]) {
   
    int a,b,x;
    
    scanf("%d %d %d",&a,&b,&x);
    
    if(a>x) printf("NO\n");
    else{
        if(a+b >= x) printf("YES\n");
        else printf("NO\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
 
#define MIN_SIZE 1
#define MAX_SIZE 100
#define MIN_POS -100
#define MAX_POS  100
#define IS_ERR_SIZE(size) (size < MIN_SIZE || size > MAX_SIZE)
#define IS_ERR_POS(pos)   (pos  < MIN_POS  || pos  > MAX_POS )
 
int main(void)
{
    int W, H, x, y, r;
    int xr, yr, rx, ry;
 
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if(IS_ERR_SIZE(W) || IS_ERR_SIZE(H) || IS_ERR_POS(x) || IS_ERR_POS(y) || IS_ERR_SIZE(r))
    {
        return -1;
    }
 
    xr = x + r;
    rx = x - r;
    yr = y + r;
    ry = y - r; 
 
    if(rx < 0 || xr > W || ry < 0 || yr > H)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }
 
    return 0;
}


Measured memory_bytes: 2136
package main

import (
	"fmt"
)

func main() {
	var a, b int
	var op string

LOOP:
	for {
		fmt.Scan(&a, &op, &b)
		//fmt.Println(op)
		switch op {
		case "+":
			fmt.Println(a + b)
		case "-":
			fmt.Println(a - b)
		case "*":
			fmt.Println(a * b)
		case "/":
			fmt.Println(a / b)
		case "?":
			break LOOP
		}
	}
}



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

int main()
{string s;
    cin >> s;
    
    if (s[2]==s[3] && s[4]==s[5]){
        cout <<"Yes";
    }
    else{
         cout <<"No";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort
#include <math.h>

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

string tar = "E869120";
int main(){
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    int N;
    cin >> N;
    int res = 0;
    REP(i,N)
    {
        string s;
        cin >> s;
        if(tar == s)++res;
    }

    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3196
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    
    int ans = 0;
    if(N <= 111){
      ans = 111;
    }else if(N <= 222){
      ans = 222;
    }else if(N <= 333){
      ans = 333;
    }else if(N <= 444){
      ans = 444;
    }else if(N <= 555){
      ans = 555;
    }else if(N <= 666){
      ans = 666;
    }else if(N <= 777){
      ans = 777;
    }else if(N <= 888){
      ans = 888;
    }else if(N <= 999){
      ans = 999;
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
import math
while True:
    n = int(input())
    if n == 0:
        break
    a = list(map(int, input().split()))
    a2 = list(map(lambda x: x**2, a))
    av = sum(a) / len(a)
    print(math.sqrt(sum(a2) / len(a2) - av**2))



Measured memory_bytes: 5700
INTEGER N,M,X
INTEGER,ALLOCATABLE,DIMENSION(:)::A
INTEGER U,D
READ*,N,M,X
ALLOCATE(A(M))
READ*,A
U=0
D=0
DO I=1,M
  IF(A(I)>X)U=U+1
  IF(A(I)<X)D=D+1
END DO
PRINT"(I0)",MIN(U,D)
END

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int arr[1000000] = {};
    int pos_r = 500000; 
    int pos_l = 500001;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int v1, v2, v3;
        cin >> v1;
        if (v1==0)
        {
            cin >> v2 >> v3;
            if (v2 == 0)
                arr[--pos_l] = v3;
            else if (v2==1)
                arr[++pos_r] = v3;
        }
        else if (v1 == 1)
        {
            cin >> v2;
            cout << arr[pos_l+v2] << endl;
        }
        else if (v1 == 2)
        {
            cin >> v2;
            if (v2 == 0)
                ++pos_l;
            else if (v2 == 1)
                --pos_r;
        }
    }
    return EXIT_SUCCESS;
}



Measured memory_bytes: 7020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
class mint{
    public:
        long long x;
 
    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a; 
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,k;cin >> h >> w >> k;
    vector<vector<int>> a(h,vector<int>(w,-1));
    int cnt=1;
    for(int i=0;i<h;i++){
        string s;cin >> s;
        for(int j=0;j<s.size();j++){
            if(s[j]=='#'){
                a[i][j]=cnt;
                cnt++;
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w-1;j++){
            if(a[i][j+1]==-1){
                a[i][j+1]=a[i][j];
            }
        }
        for(int j=w-1;j>0;j--){
            if(a[i][j-1]==-1){
                a[i][j-1]=a[i][j];
            }
        }
    }
    for(int j=0;j<w;j++){
        for(int i=0;i<h-1;i++){
            if(a[i+1][j]==-1){
                a[i+1][j]=a[i][j];
            }
        }
        for(int i=h-1;i>0;i--){
            if(a[i-1][j]==-1){
                a[i-1][j]=a[i][j];
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
#空白区切りで複数の値をリストとして入力
input_list = list(map(int,input().split()))
#input_listの値を昇順に並び替え
sort_list = sorted(input_list)

if(sum(sort_list) == 17):
    if(sort_list[0]==5 and sort_list[1]==5 and sort_list[2]==7):
        print("YES")
    else:
        print("NO")
else:
    print("NO")


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

int N, ans;

int main() {
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		int a; cin >> a;
		while (a % 2 == 0) { a /= 2; ++ans; }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n), b(n);
  REP(i, n) { cin >> a[i] >> b[i]; }

  vector<ll> ks;
  ks.push_back(k);
  ll t = k;
  // number of digits(bit)
  ll d = 30;
  REP(i, d) {
    if (((1LL << i) & k)) {
      t -= (1LL << i);
      ks.push_back(t);
    }
    t += (1LL << i);
  }

  ll ans = 0;

  for (ll t : ks) {
    ll s = 0;
    REP(i, n) {
      bool ok = true;
      REP(j, d) {
        ll r = (1LL << j) & t;
        ll l = (1LL << j) & a[i];
        if (l > r) {
          ok = false;
          break;
        }
      }
      if (ok) {
        s += b[i];
      }
    }
    ans = max(ans, s);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4836
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define  all(v)            v.begin(), v.end()
#define  sz(x)             (int)x.size()
#define  debug(x)          cout << '>' << #x << ':' << x << endl;
#define  rep(i,n)          for(int i = 0; i <  n ; i++)
#define  reps(i,n)         for(int i = 1; i <= n ; i++)
#define  make_unique(v)    sort(all(v));v.erase(unique(all(v)), v.end());
#define  rot(v)            rotate(v.begin(), v.begin() + k, v.end());
#define  rmv(v,a)          v.erase(remove(v.begin(),v.end(), a), v.end());
#define  pb                push_back
#define  eb                emplace_back
#define  mp                make_pair
#define  endl              '\n'
#define  fi                first
#define  se                second
#define  ajs(a)            (a<0)?(-1*a):a


using namespace std;
typedef long long          ll;
typedef vector<long long>  vll;
typedef pair<ll,ll>        pll;
typedef vector<int>        vi;


const ll MOD = 1e9+7;
const double PI  = acos(-1.0);
const double EPS = (1e-10);
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = { -1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = { -1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int X, int Y) {return X > Y;}
int dcp(double A, double B){return fabs(A-B)<=EPS ? 0 : A<B ? -1:1;}



ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}





int main(){

	ll n,w;
    cin>>n>>w;
    ll wt[n+1],val[n+1];
    ll v = 0;
    reps(i,n){
        cin>>wt[i]>>val[i];
        v+=val[i];
    }

    ll dp[n+1][v+1];
    for (ll i = 0; i <= n; i++)
    {
        
        dp[i][0] = 0;
        for (int j = 1; j <= v; j++)
            dp[i][j] = MOD;
    }
  
   
   
   

   for(ll i = 1 ; i<=n ; i++){
    for(ll j = 1 ; j<=v ; j++){
    	
    dp[i][j] = dp[i-1][j];
        if(j-val[i] >=0 && dp[i - 1][j - val[i]] != MOD){
        dp[i][j] = min(dp[i][j] , dp[i-1][j-val[i]] + wt[i]);
        }
    }


   }


   ll ans=0;
   for(ll i = v; i>=0 ; i--){
    if(dp[n][i]<=w ){
        ans  = i;
        break;
    }
   }


   cout<<ans;






	



























}

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

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

const int N = 2e5 + 77;
int A[N];
string s;
int32_t main(){
    fast;
    cin >> s;
    int n = s.size() ;
    int ans = 0 , c = 0;
    for(int i = 0; i < n ; ++i){
        if(s[i]=='B') c++;
        else ans += c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n, ans = 0;
	cin >> n;
	vector<int> v(n + 1);
	for (int i = 1; i <= n; ++i)
	{
		cin >> v[i];
		ans += abs(v[i] - v[i - 1]);
	}
	ans += abs(v[n]);
	v.push_back(0);
	for (int i = 1; i <= n; ++i)
	{
		cout << ans - abs(abs(v[i] - v[i - 1]) + abs(v[i + 1] - v[i]) - abs(v[i - 1] - v[i + 1])) << endl;
	}
}

Measured memory_bytes: 1656
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
char str[110];
int l;
bool f;
int main()
{
    f = 1;
    scanf("%s",str);
    if(strlen(str) <= 3)
        f = 0;
    else
        if(str[0] == 'Y' && str[1] == 'A' && str[2] == 'K' && str[3] == 'I')
            f = 1;
    else 
        f = 0;
    if(f)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

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

int h, w;
int ma[80][80], mb[80][80], ch[80][80];
bool ans[80][80][16000];

int main(){
    cin >> h >> w;
    rep(i,h) rep(j,w) cin >> ma[i][j];
    rep(i,h) rep(j,w) cin >> mb[i][j];
    rep(i,h) rep(j,w) ch[i][j] = abs(ma[i][j]-mb[i][j]);

    ans[0][0][ch[0][0]] = true;
 
    rep(i,h) rep(j,w) rep(k,16000){
        if(ans[i][j][k]){
            if(i+1 < h){
                ans[i+1][j][k+ch[i+1][j]] = true;
                ans[i+1][j][abs(k-ch[i+1][j])] = true;
            }
            if(j+1 < w){
                ans[i][j+1][k+ch[i][j+1]] = true;
                ans[i][j+1][abs(k-ch[i][j+1])] = true;
            }
        }
    }
    rep(k,640000) if(ans[h-1][w-1][k]){
      cout << k << endl;
      return 0;
    }
}

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

int main()
{
  int n;
  long long x[55], y[55];
  cin >> n;
  set < pair<long long,long long> > flag;
  for (int i = 0; i < n; i++)
  {
    cin >> x[i] >> y[i];
    flag.insert({x[i], y[i]});
  }

  int ans = n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i != j)
      {
        long long p = x[j] - x[i], q = y[j] - y[i];
        int res = 0;
        for (int k = 0; k < n; k++)
          if (!flag.count({x[k] - p, y[k] - q}))
            res++;
        ans = min(ans, res);
      }

  cout << ans << endl;
}

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

int main()
{
    int N,K;
    cin >> N >> K;

    vector<int> L(N);

    for(int i = 0; i < N; i++)
    {
        cin >> L.at(i);
    }

    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    
    int sum = 0;
    for(int i = 0; i < K; i++)
    {
        sum += L.at(i);
    }

    cout << sum << endl;
}

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

int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        if(a+b==15)
            printf("+\n");
        else if(a*b==15)
            printf("*\n");
        else
            printf("x\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<utility>
#include<algorithm>
#include<map>
using namespace std;
typedef long long int ll;
int main(void) {
	int n; cin >> n;
	std::map<ll, ll> mp;
	int a, b, max = 0;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (max < a)max = a;
		mp.emplace(a, b);
	}
	auto iter = mp.find(max);
	cout << iter->first + iter->second << endl;
	return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
int main(){
  int cnt=0,i,j,k,n,flag=0,num;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    flag=1;
    scanf("%d",&num);
    for(j=2;j*j<=num;j++){
      if(num%j==0){
	flag=0;
	break;
      }
	}
    if(flag==1)
      cnt++;
  }
  printf("%d\n",cnt);

  return 0;

}


Measured memory_bytes: 2048
import java.util.*;

public class Main {

    public static void main(String[] args) {
        
        Scanner sn = new Scanner(System.in);
        int byTime = sn.nextInt();
        int count = sn.nextInt();
        double limitTime = sn.nextInt() + 0.5;
        
        System.out.println((int)(limitTime / byTime) * count);
        
    }
}

Measured memory_bytes: 21844
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, A, B = map(int, input().split())
    X = list(map(int, input().split()))

    ans = 0
    for i in range(N-1):
        tmp = A * (X[i+1]-X[i])
        ans += min(tmp,B)
    print(ans)

if __name__ == "__main__":
    main()


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

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


int main(){
  string s, p;
  cin >> s >> p;
  s += s;
  if(s.find(p) != -1) cout << "Yes" << endl;
  else cout << "No" << endl;
}






Measured memory_bytes: 3212
def check(n):

    if n <= P-1:
        return True


    if A[n]+M < A[P-1]:
        return False
    
    votes = (P+N-1-n)*M + sum([A[n]+M-A[i] for i in range(P-1,n)])

    if votes < M*V:
        return False
    else:
        return True

N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse=True)

right = N
left = -1


##
"""
if check(right):
    print(N)
    exit()
"""
while abs(right-left) > 1:

    mid = (right+left)//2

    if check(mid):
        left = mid
    else:
        right = mid

print(left+1)

Measured memory_bytes: 14480
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int s = scanner.nextInt();

        int[][] dp = new int[2][s + 1];
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            int v = scanner.nextInt();
            for (int j = 0; j < s + 1; j++) {
                dp[i % 2][j] = (dp[(i + 1) % 2][j] * 2) % 998244353;
            }
            for (int j = 0; j < s + 1 - v; j++) {
                if (dp[(i + 1) % 2][j] > 0) {
                    dp[i % 2][j + v] = (dp[i % 2][j + v] + dp[(i + 1) % 2][j]) % 998244353;
                }
            }
        }
        System.out.println(dp[n % 2][s]);
    }
}

Measured memory_bytes: 41128
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) {
      cout << k << '\n';
    } else if (k <= a + b) {
      cout << a << '\n';
    } else {
      cout << a - (k - (a + b)) << '\n';
    }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

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


def g(x):
    return x * (x + 1) // 2


def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    ans = 0

    # See: https://www.youtube.com/watch?v=v8ppNGf49Nk&feature=youtu.be
    # KeyInsight:
    # ①約数⇄倍数と言い換え
    # 1の倍数: 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
    # 2の倍数: 2, 4, 6, 8, ...
    # 3の倍数: 3, 6, ...
    # ...

    # ②1の倍数の和を基準に、等価な式変形を行う
    # 1の倍数の和は、g(x) = n * (n + 1) // 2
    # 2の倍数の和は、2 * (1, 2, 3, 4, ...)と考えることで、 2 * g(x / 2)
    # 以降、同様

    for i in range(1, n + 1):
        ans += i * g(n // i)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63448
#include <cstdio>
#include <algorithm>
using namespace std;
typedef pair<int, int> ii;
int n;
bool even[999999], arr[999999];
bool compute() {
	bool ans = false;
	for (int i = 0; i < n - 1; ++i) {
		if (!even[i] && arr[i]) ans = !ans;
	}
	return ans;
}
int main() {
	char c;
	scanf("%d", &n);
	int a[n], x[n - 1];
	for (int i = 0; i < n; ++i) scanf(" %c", &c), a[i] = c - '0';
	for (int i = 0; i < n - 1; ++i) x[i] = abs(a[i + 1] - a[i]);
	for (int i = 0; i < n - 1; ++i) even[i] = i & (n - 2 - i);
	for (int i = 0; i < n - 1; ++i) arr[i] = x[i] == 1;
	if (compute()) {
		printf("1");
		return 0;
	} else {
		for (int i = 0; i < n - 1; ++i) {
			if (x[i] == 1) {
				printf("0");
				return 0;
			} else arr[i] = x[i] == 2;
		}
		if (compute()) {
			printf("2");
			return 0;
		} else {
			printf("0");
			return 0;
		}
	}
}

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

int main() {

    char s[999999];
    cin>>s;
    for(int i=0; s[i] != '\0'; i++) {
            cout<<(char)('a' + ((s[i] - 'a' + 1) % 26));
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
 
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

int main()
{
  ll N;cin>>N;
  ll a,b,c,d,e;cin>>a>>b>>c>>d>>e;
  
  ll mn = min({a,b,c,d,e});
  //水流はmn/分
  //何回で全員ゴールに行けるか？
  ll ans=0;
  if (N%mn==0) ans = N/mn+4;
  else ans = N/mn+5;

  cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
buttons = [int(input()) for _ in range(N)]
count = 1
tmp = buttons[0]
flag = True
while count < N+2:
    if tmp == 2:
        print(count)
        flag = False
        break
    else:
        tmp = buttons[tmp - 1]
        count += 1
if flag:
    print(-1)

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

pair<vector<char>, vector<int>> Block(string s) {
  int num = 1;

  vector<char> v1;
  vector<int> v2;

  rep (i, 0, s.size()) {
    char c = s[i];
    if (i == 0) {
      v1.pb(c);
    } else if (c == s[i - 1]) {
      num++;
    } else {
      v2.pb(num);
      v1.pb(c);
      num = 1;
    }

    if (i == s.size() - 1) v2.pb(num);
  }

  return make_pair(v1, v2);
};

int main() {
  string s, t;
  cin >> s >> t;
  auto block_s = Block(s);
  auto ch_s = block_s.first;
  auto num_s = block_s.second;
  auto block_t = Block(t);
  auto ch_t = block_t.first;
  auto num_t = block_s.second;
  if (ch_s.size() != ch_t.size()) {
    cout << "No" << endl;
    return 0;
  }

  bool flag = true;
  map<int, int> m_s;
  map<int, int> m_t;
  rep(i, 0, ch_s.size()) {
    if (num_s[i] != num_t[i]) {
      flag = false;
      break;
    }
    int i_s = (int) ch_s[i];
    int i_t = (int) ch_t[i];

    if (Find(m_s, i_s)) {
      if (m_s[i_s] != i_t) {
        flag = false;
        break;
      }
    } else {
      m_s.emplace(i_s, i_t);
    }

    if (Find(m_t, i_t)) {
      if (m_t[i_t] != i_s) {
        flag = false;
        break;
      }
    } else {
      m_t.emplace(i_t, i_s);
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
};


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

using namespace std;

int main() {
    int n, k; cin >> n >> k;
    
    int arr[200]; memset(arr, 0, sizeof arr);
    
    int d;
    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a; cin >> a;
            arr[a] = 1;
        }
    }
    
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (arr[i] == 0) ans++;
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3624
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = [list(map(int, input().split()))]
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n = int(input())
    x = list(map(int, input().split()))

    ans = [0 for i in range(101)]

    for i in range(1, 101):
        for xin in x:
            ans[i] += pow(xin - i, 2)

    ans = ans[1:]
    print(min(ans))


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2
1 4"""
        output = """5"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """7
14 14 2 13 56 2 37"""
        output = """2354"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 77560
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
  
  	double n,x,t;
  	cin>>n>>x>>t;
  	int time =0;
  	while((n-x) >0)
    {
      time=time + t;
      n-=x;
    }
  
    if(n!=0){
      time=time+t;
    }
  	cout<<time;
  	return 0;
  
}

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

 
 
//----------------------------MACROS-------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 1e5 + 1;//                                                             |
//----------------------------------------------------------------------------------




void solve()
{
    ll n;cin>>n;
    string s;cin>>s;
    string tmp=s;
    sort(all(tmp));
    ll a=0,b=0;
    for(int i=0;i<n;i++){
        if(s[i]!=tmp[i]){
            if(s[i]=='R') a++;
            else b++;
        }
    }
    cout<<max(a,b);
    
}
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    
	return 0;
}

Measured memory_bytes: 3844
package main

import (
	"fmt"
	"sort"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	v := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &v[i])
	}

	sort.Ints(v)

	var max float64 = float64(v[0])
	for i := 0; i < N-1; i++ {
		max = ((max + float64(v[i+1])) / 2.0)
	}

	fmt.Println(max)
}


Measured memory_bytes: 1840
#include<cstdio>
#define MAX 31
#define NIL -1

// arrays for height and depth
int H[MAX], D[MAX];

struct Node { int parent, leftChild, rightChild; };
// array for nodes 
Node T[MAX];

void setDepth(int node, int depth) {
	D[node] = depth;
	if (T[node].leftChild != NIL)
		setDepth(T[node].leftChild, depth + 1);
	if (T[node].rightChild != NIL)
		setDepth(T[node].rightChild, depth + 1);
}

int getSibling(int node) {
	int parent = T[node].parent;
	if (parent != NIL) {
		if (T[parent].rightChild != node && T[parent].rightChild != NIL)
			return T[parent].rightChild;
		else if (T[parent].leftChild != node && T[parent].leftChild != NIL)
			return T[parent].leftChild;
	}
	return NIL;
}

int getHeight(int node) {
	int heightFromLeft = 0, heightFromRight = 0;
	if (T[node].rightChild != NIL)
		heightFromRight = getHeight(T[node].rightChild) + 1;
	if (T[node].leftChild != NIL)
		heightFromLeft = getHeight(T[node].leftChild) + 1;

	return H[node] = 
	heightFromLeft > heightFromRight 
	? heightFromLeft
	: heightFromRight;
}

void printNode(int node) {
	printf("node %d: ", node);
	printf("parent = %d, ", T[node].parent);
	printf("sibling = %d, ", getSibling(node));
	int degree = 0;
	if (T[node].leftChild != NIL)
		degree++;
	if (T[node].rightChild != NIL)
		degree++;
	printf("degree = %d, ", degree);
	printf("depth = %d, ", D[node]);
	printf("height = %d, ", H[node]);

	if (T[node].parent == NIL){
		printf("root\n");
	}
	else if (T[node].leftChild == NIL && T[node].rightChild == NIL){
		printf("leaf\n");
	}
	else {
		printf("internal node\n");
	}
}


int main() {
	int i, n, id, child_1, child_2, root;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		T[i].parent = NIL;

	for (i = 0; i < n; i++){
		scanf("%d %d %d", &id, &child_1, &child_2);
		T[id].leftChild = child_1;
		T[id].rightChild = child_2;

		if (child_1 != NIL)
			T[child_1].parent = id;
		if (child_2 != NIL)
			T[child_2].parent = id;
	}

	for (i = 0; i < n; i++) {
		if (T[i].parent == NIL) {
			root = i;
			break;
		}
	}

	setDepth(root, 0);
	getHeight(root);

	for (i = 0; i < n; i++) {
		printNode(i);
	}

	return 0;
}

Measured memory_bytes: 2748
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong();
        if((a * b) % 2 == 0) {
            System.out.println("Even");
        }
        else{
            System.out.println("Odd");
        }
    }
}


Measured memory_bytes: 21716
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = 0;
    for(int i = 0; i < n; i++) {
      int a = sc.nextInt();
      ans += a;
    }
    ans -= n;
    System.out.println(ans);
  }
}

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

int main(){
	int n;
	scanf("%d", &n);
	int x;
	string cmd;
	list<int> ls;
	for(int i = 0; i < n; i++) {
		cin >> cmd;
		if(cmd == "insert") {
			cin >> x;
			ls.push_front(x);
		}else if(cmd == "delete") {
			cin >> x;
			for(auto itr = ls.begin(); itr != ls.end(); itr++) {
				if(*itr == x) {
					ls.erase(itr);
					break;
				}
			}
		}else if(cmd == "deleteFirst") {
			ls.erase(ls.begin());
		}else if(cmd == "deleteLast") {
			ls.erase(--ls.end());
		}
	}
	for(auto itr = ls.begin(); itr != ls.end(); itr++) {
		if(itr != ls.begin()) printf(" ");
		printf("%d", *itr);
	}
	printf("\n");
}



Measured memory_bytes: 34524
#include<stdio.h>
#define N 2000000

int v,data[N+1];

void maxHeapify(int i)
{
  int l,r,large;
  int tmp;

  l = 2*i;
  r = 2*i+1;

  if(l<=v && data[l]>data[i])
    large = l;
  else
    large = i;

  if(r<=v && data[r]>data[large])
    large = r;

  if(large != i){
    tmp = data[i];
    data[i] = data[large];
    data[large] = tmp;

    maxHeapify(large);
  }
}

int main()
{
  int i;

  scanf("%d",&v);
  for(i=1; i<=v; i++)
    scanf("%d",&data[i]);

  for(i=v/2; i>=1; i--)
    maxHeapify(i);

  for(i=1; i<=v; i++)
    printf(" %d",data[i]);

  printf("\n");

  return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in1[105];
char in2[105];

int main() {
	scanf("%s %s", in1, in2);
	int N = strlen(in1), i, j;
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) if (in1[j] != in2[(i + j) % N]) break;
		if (j >= N) return !printf("Yes\n");
	}
	return !printf("No\n");
}

Measured memory_bytes: 256
# カードごとの配列の作成
spade, heart, daia, club = Array.new(13, "NG"), Array.new(13, "NG"), Array.new(13, "NG"), Array.new(13, "NG")

# カードの枚数
N = gets.chomp.to_i

# 何が足りないか
def unknown(arr)
	ans_arr = Array.new
	for i in 0..12
		if arr[i] == "NG"
			ans_arr +=  [i]
		end
	end
	return ans_arr
end

# 存在するカード
for i in 1..N
	card = gets.chomp.split("\s")
	number = card[1].to_i - 1

	case card[0]
		when "S"
			spade[number] = "OK"
		when "H"
			heart[number] = "OK"
		when "C"
			club[number] = "OK"
		else
			daia[number] = "OK"
	end
end

# 出力
def output(arr, suit)
	#配列の要素を調べる
	arr_int = arr.length
	
	for k in 0..arr_int - 1
		print(suit, "\s", arr[k] + 1, "\n")
	end
end

s_unknown = unknown(spade)
output(s_unknown, "S")

h_unknown = unknown(heart)
output(h_unknown, "H")

c_unknown = unknown(club)
output(c_unknown, "C")

d_unknown = unknown(daia)
output(d_unknown, "D")

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll N, K;
ll W[100005];

bool check(ll p) {

    ll s = 0;
    ll k = 1;
    REP(i, N) {
        if (p < W[i])
            return false;
        if (s + W[i] > p) {
            k++;
            s = 0;
        }
        s += W[i];
    }

    return k <= K;
}

int main() {
    cin >> N >> K;
    REP(i, N) {
        cin >> W[i];
    }

    ll ok = INF, ng = 0;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 3876
import numpy as np

def calc_div(N):
    sq = int(N**.5 + 10)
    x = np.arange(1, sq)
    x = x[N % x == 0]
    x = np.concatenate((x, N // x))
    return np.unique(x)

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

def is_pow(n):
  cnt=0
  for i in range(100):
    if n&(2**i):
      cnt+=1
  if cnt==1:
    return True
  else:
    return False

n=int(input())
if is_pow(n)==True:
  print(2*n-1)
  exit()
div=calc_div(n*2)
ans=10**18
for val in div:
  a=val
  b=(2*n)//val
  if a==1 or b==1 or gcd(a,b)!=1:
    continue
  _,x,y=xgcd(a,b)
  tmp=min(abs(a*x),abs(b*y))
  ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 766680
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;
const int maxn = 105;
int a[maxn];
int main()
{
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		int l, r;
		cin >> l >> r;
		a[l]++;
		a[r]++;
	}
	for(int i = 1; i <= n; i++)
		cout << a[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, a[1001010];
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++){
        scanf("%d", &a[i]);
    }
    for(int i = 1; i <= n; i ++){
        if(a[i] >= i || a[i] - a[i-1] > 1){
            printf("-1");
            return 0;
        }
    }
    long long int ans = 0;
    for(int i = n; i > 0; i --){
        ans += a[i];
        /*
        if(a[i] < maxv){
            printf("-1");
            return 0;
        }
        maxav = max(maxv, a[i]);
        */
        while(a[i-1] == a[i]-1){
            i --;
        }
    }
    printf("%lld", ans);
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using static System.Math;

class Program
{
    static int N;
    static int Q;
    static int[] A;
    static int[] B;

    static void Main()
    {
        string[] s = Console.ReadLine().Split();
        N = int.Parse(s[0]);
        Q = int.Parse(s[1]);
        A = new int[Q];
        B = new int[Q];
        for (int i = 0; i < Q; i++)
        {
            s = Console.ReadLine().Split();
            A[i] = int.Parse(s[0]);
            B[i] = int.Parse(s[1]);
        }

        SortedList<int, int> sl = new SortedList<int, int>();
        int no_magic = 1; // 超能力なしでいる場所
        sl.Add(2, 0);
        for (int i = 0; i < Q; i++) //クエリの処理
        {
            int a = A[i];
            int b = B[i];
            /* 本来いる場所を変更 */
            if (no_magic == a) no_magic = b;
            else if (no_magic == b) no_magic = a;
            /* slの変更 */
            int indexa, indexb;
            indexa = sl.IndexOfKey(a);
            indexb = sl.IndexOfKey(b);
            if (indexa != -1 && indexb == -1)
            {
                sl.RemoveAt(indexa);
                sl.Add(b, 0);
            }
            else if (indexa == -1 && indexb != -1)
            {
                sl.RemoveAt(indexb);
                sl.Add(a, 0);
            }
            /* 超能力の使用 */
            if (no_magic > 1)
            {
                try
                {
                    sl.Add(no_magic - 1, 0);
                }
                catch { }
            }
            if (no_magic < N)
            {
                try
                {
                    sl.Add(no_magic + 1, 0);
                }
                catch { }
            }
        }

        try
        {
            sl.Add(no_magic, 0);
        }
        catch { }

        Console.WriteLine(sl.Count);
    }
}

Measured memory_bytes: 18332
#include <stdio.h>
#include <string.h>

int main()
{
   int t;
    float sum=0;
  scanf("%d",&t);
  while(t--)
  {
    char s[4];
    float x;
     
    scanf("%f%s",&x,&s);
    if(strcmp(s,"JPY")==0)
        sum+=x;
    
    else
       sum+=(x*380000);
  }
  
  printf("%f",sum);
  
}

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

int main(){
  string s;
  cin>>s;
  int out=0;
  int n=s.size();
  int ans=(n+1)/2;
  if(n%2){
    for(int i=1;i<=n/2;i++){
      if(s[n/2-i]==s[n/2]&&s[n/2+i]==s[n/2])ans++;
      else break;
    }
  }
  else{
    if(s[n/2-1]==s[n/2])ans++;
    else out++;
    for(int i=1;i<=n/2-1&&out==0;i++){
      if(s[n/2-1-i]==s[n/2+i])ans++;
      else break;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 512