akhauriyash/Code-Regression huggingface dataset:
module Main where

import Control.Applicative
import Control.Monad
import Data.Maybe (catMaybes)

solve :: Int -> [(Int, Int, Int)] -> [Bool] -> Maybe Int
solve g ps qs = iter 0 0 Nothing (zip ps qs)
  where
    iter prob score Nothing [] = Just prob
    iter prob score (Just (i,p,c)) []
        | need <= 0   = Just prob
        | need > rmax = Nothing
        | otherwise   = Just (prob + k)
      where
        need = g - score
        rmax = 100 * i * (p - 1)
        k = head $ filter (\j -> 100 * i * j >= need) [1 .. p - 1]
    iter prob score rest (((i,p,c), False):rs)
        = iter prob score (Just (i,p,c)) rs
    iter prob score rest (((i,p,c), True):rs)
        = iter (prob + p) (score + (100 * i * p + c)) rest rs

main :: IO ()
main = do
    [d, g] <- fmap read . words <$> getLine :: IO [Int]
    ps <- forM [1 .. d] $ \i -> do
        [p, c] <- fmap read . words <$> getLine :: IO [Int]
        return (i, p, c)
    let ass = sequence $ replicate d [True, False]
    let ans = fmap (solve g ps) ass
    print $ minimum $ catMaybes ans


Measured memory_bytes: 1020
#include "bits/stdc++.h"
using ll = long long;
using namespace std;
int main(){
ll N,M,tmp,tmp1;
cin>>N>>M;
vector<ll> A;
vector<pair<ll,ll>> C;
for(ll i=0;i<N;i++){
cin>>tmp;
A.emplace_back(tmp);
}
for(ll i=0;i<M;i++){
cin>>tmp>>tmp1;
C.emplace_back(tmp1,tmp);
}

sort(A.begin(),A.end());
sort(C.begin(),C.end());
ll ans=0;
for(ll i=0;i<N;i++){
if(C.empty()||C.back().first<=A.back()){
ans+=A.back();
A.pop_back();
continue;
}
ans+=C.back().first;
if(!(--C.back().second))
C.pop_back();
}
cout<<ans<<endl;
}


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

long long N, A, B;
long long K;
long long mod = 998244353;
long long fac_memo[300001], fac_inv_memo[300001], C_memo[300001];


long long pow(long long a, long long x){
    a %= mod;
    if(x == 0){
        return 1;
    }
    long long tmp = pow(a * a % mod, x / 2);
    return ((x%2)? a : 1LL) * tmp % mod;  
}

long long inv(long long x){
    return pow(x % mod, mod - 2);
}

long long fac(long long n){
    n %= mod;
    if(fac_memo[n] != 0){
        return fac_memo[n];
    }
    if(n == 0){
        return fac_memo[0] = 1LL;
    }
    return fac_memo[n] = n * fac(n-1) % mod;
}

long long C(long long n, long long r){
    return fac(n) * fac_inv_memo[n-r] % mod * fac_inv_memo[r] % mod;
}

int main(){
    cin >> N >> A >> B >> K;
    long long ans = 0;
    fac(300000);
    for(int i = 0; i <= N; i++){
        fac_inv_memo[i] = inv(fac_memo[i]);
    }
    for(int a = 0; a <= N; a++){
        if((K - a * A) % B != 0 || (K - a * A < 0)){
            continue;
        }
        int b = (K - a * A) / B;
        if(b > N){
            continue;
        }
        ans += C(N, a) * C(N, b) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9984
n = int(input())
txy = [list(map(int, input().split())) for i in range(n)]
for i in txy:
    if i[0] % 2 != (i[1] + i[2]) % 2 or (i[1] + i[2]) > i[0]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 27300
package main

import "fmt"

var N, A, B int

func main() {
	fmt.Scan(&N, &A, &B)
	sum := 0
	for i := 1; i <= N; i++ {
		dSum := digitSum(i)
		if dSum >= A && dSum <= B {
			sum += i
		}
	}
	fmt.Println(sum)
}

func digitSum(i int) int {
	a := i % 10
	b := (i / 10) % 10
	c := (i / 100) % 10
	d := (i / 1000) % 10
	e := (i / 10000) % 10
	return a + b + c + d + e
}


Measured memory_bytes: 512
#include<stdio.h>


int main(){
    int a[128], b, i,  j, temp, count, min, number;
    
    scanf("%d", &b);
    
    for(i = 0; i < b; i++){
        scanf("%d", &a[i]);
    }
    
    count = 0;
    
    for(i=0; i < b; i++){
        min = a[i];
        number = i;
        for(j = i; j < b; j++){
            if( min > a[j]){
                min = a[j];
                number = j;
            }
        }
        if(i != number){
            temp = a[i];
            a[i] = a[number];
            a[number] = temp;
            count++;
        }
    }
    
     for( i = 0; i < b; i++){
        
         if(i != 0){
            printf(" ");
         }
        
        printf("%d", a[i]);
         }
        printf("\n%d\n", count);
    return 0;
}



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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int n;  cin >> n;
  ll ans = 0,sum = 0;
  VLL A(n);
  
  rep(i,n){
    cin >> A[i];
    if(A[i] > 0) sum += A[i];
    else ans += sum/2, sum = 0;
  }
  ans += sum/2;

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


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <bitset>
#include <stack>

using namespace std;

void boostIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

const int maxn = 3e3 + 5;
int n, m;
map<char, int> conv;

int main() {
    boostIO();

    int cnt5 = 0, cnt7 = 0;
    for (int i = 0; i < 3; ++i) {
        int a;
        cin >> a;
        if (a == 5) ++cnt5;
        if (a == 7) ++cnt7;
    }

    if (cnt5 == 2 && cnt7 == 1)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
p = [list(map(int,input().split())) for _ in range(m)]
p.sort()
a1 = p[0][0]
b1 = p[0][1]
ans = 1

for i in range(1,m):
    a2 = p[i][0]
    b2 = p[i][1]
    if b1 <= a2:
        ans += 1
        a1 = a2
        b1 = b2
    else:
        if a1 < a2:
            a1 = a2
        if b1 > b2:
            b1 = b2

print(ans)

Measured memory_bytes: 27872
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<iomanip>
using namespace std;
typedef long long LL;
int main(){
	LL a,b,h;
	cin >> a;
	cin >> b;
	cin >> h;
	cout << (a+b)*h/2;
	return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); ++i)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100005
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
typedef long long ll;
typedef pair<int, int> P;

int S[MAX_N];
int T[50005];
int A[50005];
int n, q;
bool mysearch(int key);

int main()
{
	int j = 0;
	int ans = 0;
	bool over;

	cin >> n;
	REP(i, n)cin >> S[i];
	cin >> q;
	REP(i, q)cin >> T[i];

	REP(i, q){
		over = false;
		REP(k, j){
			if (A[k] == T[i]){
				over = true; break;
			}
		}

		if (mysearch(T[i]) == true && over == false)
		{
			ans++;
			A[j] = T[i];
			j++;
		}
	}
	cout << ans  << endl;
	return 0;
}

inline bool mysearch(int key){
	int left = 0;
	int right = n;
	int mid;
	while (left < right)
	{
		mid = (left + right) / 2;
		if (S[mid] == key)return true;
		else if (key < S[mid])right = mid;
		else left = mid + 1;
		
	}
	return false;
}

Measured memory_bytes: 1916
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
const int N = 1e5 + 5;
const int mod = 1e9 + 7; 
using namespace std; 

int n, m, q, sum1[N], sum2[N]; 
char s[N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin);
#endif
	scanf("%s", s + 1), n = strlen(s + 1);
	for(int i = 1; i <= n; i++) sum1[i] = sum1[i - 1] + (s[i] == 'A' ? 2 : 1);
	scanf("%s", s + 1), m = strlen(s + 1);
	for(int i = 1; i <= m; i++) sum2[i] = sum2[i - 1] + (s[i] == 'A' ? 2 : 1);
	q = read <int> (); int a, b, c, d; 
	while(q--)
	{
		a = read <int> (), b = read <int> (), c = read <int> (), d = read <int> ();
		if((sum1[b] - sum1[a - 1]) % 3 == (sum2[d] - sum2[c - 1]) % 3) puts("YES");
		else puts("NO"); 
	}
	return 0; 
}


Measured memory_bytes: 3996
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
  
 
   cin >> n;
  
  if(n<1200){
    cout << "ABC" << endl;
  }else if(n>=1200&&n<2800){
    cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;
   
  }
  
   
   
  
  return 0;
}

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

int main(){
	int n,a[200000];
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	int s,t,si,ti;

	if(a[0] > a[1]){
		s = a[0];
		si = 0;
		t= a[1];
		ti = 1;
	}else{
		s = a[1];
		si = 1;
		t= a[0];
		ti = 0;
	}

	for(int i=2; i<n; i++){
		if(a[i] >= s){
			t = s;
			ti = si;
			s = a[i];
			si = i;
		}else if((a[i] < s) && (a[i] >= t)){
			t = a[i];
			ti = i;
		}
	}

	for(int i=0; i<n; i++){
		if(i != si){
			cout << s << endl;
		}else{
			cout << t << endl;
		}
	}
}

Measured memory_bytes: 2432
import java.util.*;
 
 
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arr [] = new int[n];
        for(int k = 0; k<n; k++) arr[k] = sc.nextInt(); //Reading inputs
   
        for( int i=0; i<n;i++)
        {
            int key = arr[i];
            int j  = i-1;
            while(j>=0 && arr[j]>key)
            {
                arr[j+1] = arr[j];
                j--;
            }
            arr[j+1] = key;    
                for(int k = 0; k<n; k++) 
                {
                    if(k<n-1) System.out.printf("%d ",arr[k]);
                    else System.out.println(arr[k]);  
                }
                
        }
    }
}   


Measured memory_bytes: 41396
#include <stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    char s[n+1];
    scanf("%s", &s);
    long long int R=0, G=0, B=0;

    for(int i=0;i<n;i++){
        if(s[i]=='R') R++;
        if(s[i]=='G') G++;
        if(s[i]=='B') B++;
    }

    long long int X=0;
    for(int d=1;d<n;d++){
        for(int i=0;i+d+d<n+1;i++){
            if(i+d+d >= n) continue;
            if(s[i] != s[i+d] && s[i+d] != s[i+d+d] && s[i] != s[i+d+d]){
                //printf("%c %c %c\n", s[i], s[i+d], s[i+d+d]);
                X++;
            }
        }
    }
    //printf("%d\n", R*G*B);
    //printf("%d\n", X);
    printf("%lld\n", R*G*B-X);
    return 0;
}


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

int main() {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, s.size()) {
		if(s[i]!=t[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
#define eps 1e-10
int main() {
  double w, h, x, y; cin >> w >> h >> x >> y;
  cout << w * h / 2 << " " << (abs(2 * x - w) < eps && abs(2 * y - h) < eps ? 1 : 0);
}

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

#define int long long

const int INF = 1e15;

class Dijkstra {
    private:
        struct edge {int to, cost;};
        vector <vector <edge>> G;
        vector <int> d;
        priority_queue <pair <int, int>, vector <pair <int, int>>, greater <pair <int, int>>> que;

    public:
        Dijkstra(int v) {
            G = vector <vector <edge>> (v);
            d = vector <int> (v);
        }

        void addEdge(int start, int end, int cost) {
            G[start].push_back({end, cost});
        }

        int dist(int n) {
            return d[n];
        }

        void execute(int start) {
            for (int i = 0; i < G.size(); i++)
                d[i] = i == start ? 0 : INF;
            que.push({0 , start});
            while(!que.empty()) {
                pair <int, int> p = que.top(); que.pop();
                int from = p.second;
                if(d[from] < p.first)continue;
                for(int i = 0; i < G[from].size(); i++) {
                    edge e = G[from][i];
                    if(d[e.to] > d[from] + e.cost) {
                        d[e.to] = d[from] + e.cost;
                        que.push({d[e.to], e.to});
                    }
                }
            }
        }
};

template< typename Monoid >
struct SegmentTree {
    using F = function< Monoid(Monoid, Monoid) >;

    int sz;
    vector< Monoid > seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x) {
        seg[k + sz] = x;
    }

    void build() {
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) L = f(L, seg[a++]);
            if(b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const {
        return seg[k + sz];
    }
};

signed main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--, t--;
    Dijkstra yen(n), sunuk(n);
    rep (i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        yen.addEdge(u, v, a);
        yen.addEdge(v, u, a);
        sunuk.addEdge(u, v, b);
        sunuk.addEdge(v, u, b);
    }


    yen.execute(s);
    sunuk.execute(t);


    SegmentTree <long long> seg(n, [](long long a, long long b) { return min(a, b); }, LLONG_MAX);
    rep (i, n) {
        seg.update(i, yen.dist(i) + sunuk.dist(i));
    }


    rep (i, n) {
        cout << 1000000000000000 - seg.query(0, n) << endl;
        seg.update(i, INF);
    }
    return 0;
}

Measured memory_bytes: 21496
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

int p[10];

void go(int i, int mx) {
  if (i + 1 == n) {
    for (int j = 0; j < n; ++j) {
      cout << char('a' + p[j]);
    }
    cout << '\n';
    return;
  }
  for (int j = 0; j <= mx; ++j) {
    p[i + 1] = j;
    go(i + 1, max(mx, j + 1));
  }
}

void solve(int) {
  cin >> n;
  go(0, 1);
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 1536
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
    int n, o, h, t;
    string s;
    cin >> n;
     
    while(n--)
	{
        o = h = t = 0;
        while(o < 3)
		{
            cin >> s;
            if(s == "HIT")
			{
                if(h == 3)
				{
                    t++;
                } 
				else 
				{
                    h++;
                }
            } 
			else if(s == "HOMERUN")
			{
                t = t + h + 1;
                 h=0;
            } 
			else 
			{
                o++;
            }
        }
        cout << t << endl;
    }
     
    return 0;
}

Measured memory_bytes: 1208
n, q = map(int, input().split())
s = input()

cnt = [0]*(n)

plus = 0
for i in range(n-1):
    if s[i:i+2] == "AC":
        plus += 1
    cnt[i+1] = plus

for j in range(q):
    l, r = map(int, input().split())
    print(cnt[r-1]-cnt[l-1])

Measured memory_bytes: 6060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    getline(cin,s);
    int j=700;
    for(int i=1;i<=3;i++)
    {
        if(s.at(i-1)=='o')
            j+=100;
    }
    cout<<j<<endl;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    ll mi=a[0],mx=a[n-1];
    bool j;
    if(mx-mi>1){
        j=false;
    }
    else if(mx==mi){
        j=mi<=n/2 || mi==n-1;
    }
    else{
        ll count=0;
        for(int i=0;i<n;i++){
            if(a[i]==mi){count++;}
        }
        j=count<mx && mx<=count+(n-count)/2;
    }
    cout<<(j?"Yes":"No")<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1024
s = input()
p = 0
g = 0
score = 0
for i in range(len(s)):
    if (g - p) >= 1:
        p += 1
        if s[i] == 'g':
            score += 1
    else:
        g += 1
        if s[i] == 'p':
            score -= 1
print(score)

Measured memory_bytes: 3316
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> bit(M), p(M);
	for(int i = 0; i < M; ++i) {
		int c, x;
		cin >> c;
		for(int j = 0; j < c; ++j) {
			cin >> x;
			bit[i] |= 1 << (--x);
		}
	}
	for(int i = 0; i < M; ++i) {
		cin >> p[i];
	}
	int ways = 0;
	for(int i = 0; i < (1 << N); ++i) {
		bool ok = true;
		for(int j = 0; j < M; ++j) {
			if((__builtin_popcount(i & bit[j]) & 1) != p[j]) {
				ok = false;
				break;
			}
		}
		if(ok) ++ways;
	}
	cout << ways << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
const ll LNF = 1e18;
const int INF = 1e9 + 1;
const ll M = 1e9 + 7;
typedef pair<int, int> P;
ll gcd(ll x, ll y)
{
    if (y == 0)
        return x;
    else
        return gcd(y, x % y);
}
int main()
{
    int n;
    cin >> n;
    P p[n];
    for (int i = 0; i < n; i++)
        cin >> p[i].second >> p[i].first;

    sort(p, p + n);
    int nw = 0;
    bool ok = true;
    for (int i = 0; i < n; i++)
    {
        if (nw + p[i].second <= p[i].first)
            nw += p[i].second;
        else
            ok = false;
    }
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 1792
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  ps <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    step :: (Int, Int) -> Int -> (Int, Int)
    step acc@(c, m) p | p <= m     = (succ c, p)
                      | otherwise = acc
  print . fst . foldl step (0, n) $ ps

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


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

using namespace std;

long long MOD = 1000000007;
int main()
{
  string S;

  cin >> S;

  int len = S.length();
  vector<vector<long long>> dp(len+1, vector<long long>(13));

  long long coef = 1;

  dp[0][0] = 1;
  for (int i = 0; i < len; i++) {
    char c = S.at(len - 1 - i);
    if (c == '?') {
      for (long long n = 0; n < 10; n++) {
        long long m = (coef * n) % 13;
        for (long long k = 0; k < 13; k++) {
          dp[i+1][(m+k) % 13] += dp[i][k];
          dp[i+1][(m+k) % 13] %= MOD;
        }
      }
    } else {
      long long n = c - '0';
      long long m = (coef * n) % 13;
      for (long long k = 0; k < 13; k++) {
        dp[i+1][(m+k) % 13] += dp[i][k];
        dp[i+1][(m+k) % 13] %= MOD;
      }
    }
    coef = (coef * 10) % 13;
  }

  cout << dp[len][5] << endl;

  return 0;
}


Measured memory_bytes: 13696
X, N = map(int,input().split())
p = list(map(int,input().split()))

n = X
i = 1

while 1 <= i:
    if n in p:
        if i % 2 == 0:
            n += i
        else:
            n -= i   
    else:
        print(n)
        break
    i += 1

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

#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
typedef long long ll;
const ll INF = 1LL<<60;
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; }
using pint = pair<int, int>;
using pstring = pair<int, string>;

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

    if( 400 <= N and N <= 599) cout << 8;
    else if( 600 <= N and N <= 799) cout << 7;
    else if( 800 <= N and N <= 999) cout << 6;
    else if( 1000 <= N and N <= 1199) cout << 5;
    else if( 1200 <= N and N <= 1399) cout << 4;
    else if( 1400 <= N and N <= 1599) cout << 3;
    else if( 1600 <= N and N <= 1799) cout << 2;
    else if( 1800 <= N and N <= 1999) cout << 1;
    cout << endl;
    return 0;
}


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

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;
#define vec vector
#define rep(_i,_n) for(ll _i = 0; _i < _n; _i++)
#define rep2(_i,_s,_n) for(ll _i = _s; _i < _n; _i++)
#define elif else if
#define push(_a) push_back(_a)
#define fullSort(_a) sort(_a.begin(), _a.end())
#define inputVecI(_name, _n) vec<int> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecL(_name, _n) vec<long> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecLL(_name, _n) vec<ll> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecS(_name, _n) vec<string> _name(_n);rep(_i, _n)cin >> _name[_i];
#define findMaxIdx(_name) distance(_name.begin(), max_element(_name.begin(), _name.end()))
#define printVec(_vec) cout << "{";rep(i, _vec.size()-1)cout << _vec[i] << ",";cout << _vec[_vec.size()-1];cout << "}\n";
#define append(_x) push_back(_x)
#define mapLoop(_i, _name) for(auto i = _name.begin(); i != _name.end(); i++)

int main()
{
    ull A, B, N;
    cin >> A >> B >> N;
    if(B - 1 <= N){
      cout << (ull)(A * (B - 1) / B) - A * (ull)((B - 1) / B) << endl;
    }
    else{
      cout << (ull)(A * N / B) - A * (ull)(N / B) << endl;
    }

		return 0;
}


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

#define int long long int
#define ff first
#define ss second
#define pb push_back

int bexp(int a, int b, int mod)
{
    int res = 1;
    if (mod <= 0)
        return 0;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

#define N 200010
#define MOD 1000000007

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n, d;
    cin >> n >> d;

    int x, y, ans = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> x >> y;
        if (x * x + y * y <= d * d)
            ans++;
    }

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


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;

int main() {
    LL n, k;
    cin >> n >> k;
    vector<LL> x(n);
    vector<LL> ax(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        ax[i] = abs(x[i]);
    }
    LL ans = 10000000000;
    for (int i = 0; i <= (n - k);i++) {
        if (x[i] >= 0 && x[i + k - 1] >= 0) {
            ans = min(ans, abs(x[i + k - 1]));
            //cout <<1<< ans << endl;
        }
        else if (x[i] <= 0 && x[i + k - 1] <= 0) {
            ans = min(ans,abs( x[i]));
            //cout <<2<< ans << endl;
        }
        else {
            if (abs(x[i]) >= abs(x[i + k - 1])) {
                ans = min(ans, (abs(x[i + k - 1]) * 2) + abs(x[i]));
            }
            else {
                ans = min(ans, (abs(x[i]) * 2) + abs(x[i + k - 1]));
            }
            //cout <<3<< ans << endl;
        }
    }

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

Measured memory_bytes: 1792
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  int n , x, t;
  cin >> n >> x >> t;
  cout << ((n + (x - 1)) / x) * t << endl;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
   ll n;
   cin >> n;
   vector<ll>a(n);
   vector<bool>che(n,true);
   ll ans = 0;
   for(int i=0;i<n;i++){
      cin >> a.at(i);
      a.at(i)--;
   }
   for(int i=0;i<n;i++){
      if(!che.at(i))continue;
      if(a.at(a.at(i))==i&&che.at(i)&&che.at(a.at(i))){
         ans++;
         che.at(i)=false;
         che.at(a.at(i))=false;
      }
   }
   cout << ans << endl;
}
    



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

using namespace std;

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

    int a[n]; 
    for(int i=0;i<n;i++) cin >> a[i];

    vector<int> dp(n,INT_MAX);

    dp[0] = 0;

    for(int i=0;i<n;i++){
        for(int j=i+1; j<i+3;j++){
            dp[j] = min(dp[j],dp[i] + abs(a[i] -a[j]));
        }
    }

    cout << dp[n-1] << endl;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end



int main(){
    ll n; scanf("%lld",&n);
    ll ans=INF;
    for(ll i=1;;i++){
        if(i*i>n)break;
        if(n%i==0)chmin(ans,i+n/i);
    }
    printf("%lld\n",ans-2);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
const ll mn=2e5+8;
ll a[mn];
ll t[2 * mn];
ll segn;
void build(ll n) {  // build the tree
	segn=n;
  for (ll i = segn - 1; i > 0; --i) t[i] = min(t[i<<1], t[i<<1|1]);
}

ll query(ll l, ll r) {  // min on interval [l,r]
	r++;
  ll res = INF;
  for (l += segn, r += segn; l < r; l >>= 1, r >>= 1) {
    if (l&1) res=min(res, t[l++]);
    if (r&1) res=min(res, t[--r]);
  }
  return res;
}
int main() {
	ios_base::sync_with_stdio(false);
	ll n; scanf("%lld",&n);
	a[0]=0;a[n+1]=0;
	for (ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	segn=n+2;
	for (ll i=0;i<segn;i++) t[i+segn]=a[i];
	build(n+2);
	ll ans=0;
	for (ll x=1;x<=n;x++) {
		ll l,r;
		{
			ll imin=x+1,imax=n+2;
			while(imin<imax) {
				ll imid=(imin+imax)/2;
				ll got=query(x+1,imid);
				//printf("Query: %lld %lld got %ld\n",x+1,imid,got);
				if (got>=a[x]) imin=imid+1;
				else imax=imid;
			}
			r=imin;
		}
		{
			ll imin=1,imax=x;
			while(imin<imax) {
				ll imid=(imin+imax)/2;
				ll got=query(x-imid,x-1);
				if (got>=a[x]) imin=imid+1;
				else imax=imid;
			}
			l=imin;
		}
		//printf("x:%lld dl:%lld dr:%lld (r:%lld)\n",x,l,r-x,r);
		ans+=(l*(r-x)*a[x]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4992
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define rep(i, a, N) for(int i = a; i < N; i++)
#define rrep(i, a, N) for(int i = a; i >= N; i--)

const int inf = 1000000000;

//#define DEBUG

int main() {
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    if (accumulate(a.begin(), a.end(), 0) >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
import sys
import bisect
A, B, Q = map(int, input().split())
S = [int(sys.stdin.readline().rstrip()) for _ in range(A)]
T = [int(sys.stdin.readline().rstrip()) for _ in range(B)]

def solver(S, A, x):
    d = []
    a = bisect.bisect_right(S, x)

    if a == A:
        d.append((-1, x - S[-1]))
    elif a == 0:
        d.append((1, S[0] - x))
    else:
        d.append((-1, x - S[a - 1]))
        d.append((1, S[a] - x))

    return d

for _ in range(Q):
    ans = 0
    x = int(sys.stdin.readline().rstrip())

    d_a = solver(S, A, x)
    d_b = solver(T, B, x)

    ans = 10**15
    for i, j in d_a:
        for k, l in d_b:
            if i == k:
                ans = min(ans, max(j, l))
            else:
                ans = min(ans, j + l + min(j, l))
    print(ans)

Measured memory_bytes: 67036
#include <cstdio>

int main(void)
{
	int n;
	int count;
	
	while (scanf("%d", &n), n){
		count = 0;
		while (n != 1){
			if (n % 2 == 0){
				n /= 2;
			}
			else {
				n = n * 3 + 1;
			}
			count++;
		}
		printf("%d\n", count);
	}
	return (0);
}

Measured memory_bytes: 1032
N = int(input())
A = list(map(int, input().split()))

Ca = [0] * (N+1)
# upper limit is N<10^5
cnt = 0
for a in A:
  if a > N:
    cnt += 1
  else:
    Ca[a] += 1

for i in range(1,N+1):
  if Ca[i] < i:
    cnt += Ca[i]
  else:
    cnt += Ca[i] - i

print(cnt)



Measured memory_bytes: 14212
#include <cstdint>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}
int h[100001];
int main(){
  uint_fast32_t n=read(),a=read(),b=read();a-=b;
  double a_=1.0/a;
  rep(i,n)h[i]=read();
  uint_fast32_t left=0,right=1000000000;
  int_fast64_t temp,cnt=0,mid;
  while (right>left+1) {
    mid=(right+left)>>1;
    cnt=0;
    rep(i,n){
      temp=h[i]-b*mid+a-1;
      if(temp>0)cnt+=temp*a_;
    }
    if(cnt<=mid)right=mid;
    else left=mid;
  }
  printf("%u\n",right);
}

Measured memory_bytes: 512
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007
ll fac[1000000];
ll finv[1000000];
ll inv[1000000];

void comb_init(){
  fac[0] = 1;
  fac[1] = 1;
  for(int i=2;i<1000000;i++){
    fac[i] = i*fac[i-1];
    fac[i] %= MOD;
  }
  inv[1] = 1;
  for(int i=2;i<1000000;i++){
    inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
  }
  finv[0] = 1;
  finv[1] = 1;
  for(int i=2;i<1000000;i++){
    finv[i] = inv[i]*finv[i-1];
    finv[i] %= MOD;
  }
}

ll comb(ll n,ll k){
  ll c;
  c = fac[n];
  c *= finv[k];
  c %= MOD;
  c *= finv[n-k];
  c %= MOD;
  return c;
}

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

  ll ans = r*r;
  cout << ans << endl;

  return 0;
}


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

int main()
{
    long long x,r,d,ans,i;
    cin>>r>>d>>x;
    ans=x;
    for(i=1;i<=10;i++){
        ans=r*ans-d;
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

type Items [][]int
func (A Items) Len() int { return len(A) }
func (A Items) Less(i, j int) bool {
  if A[i][0] == A[j][0] { return A[i][1] < A[j][1] }
  return A[i][0] < A[j][0]
}
func (A Items) Swap(i, j int) { A[i], A[j] = A[j], A[i] }

func Min(a, b int) int {
  if a < b { return a }
  return b
}
func Max(a, b int) int {
  if a > b { return a }
  return b
}

func main() {
  N := NextInt()
  LR := make([][]int, N)
  for i := range LR {
    LR[i] = NextIntVec()
  }
  sort.Sort(sort.Reverse(Items(LR)))
  U := make([]int, N)
  U[0] = LR[0][1]
  for i := 1; i < N; i++ {
    U[i] = Min(LR[i][1], U[i - 1])
  }
  U2 := make([]int, N)
  U2[N - 1] = 1000000007
  for i := N - 1; 0 < i; i-- {
    U2[i - 1] = Min(LR[i][1], U2[i])
  }
  ans := 0
  L0 := LR[0][0]
  for i := 1; i < N; i++ {
    U0 := U[i - 1]
    L1, U1 := LR[i][0], LR[i][1]
    a0 := Max(Min(U0, U2[i]) - L0 + 1, 0) + Max(U1 - L1 + 1, 0)
    a1 := Max(U0 - L0 + 1, 0) + Max(Min(U1, U2[i]) - L1 + 1, 0)
    ans = Max(Max(a0, a1), ans)
  }
  Write(ans)
  Output()
}

Measured memory_bytes: 10496
def hoge(S):
    cum = 0
    mi = 0
    for s in S:
        cum += 1 if s == '(' else -1
        mi = min(mi, cum)
    return (-mi, cum - mi)

N = int(input())
S = input()

l, r = hoge(S)
print('(' * l + S + ')' * r)

Measured memory_bytes: 3060
class dice:
  def __init__(self,dice_number_list):
    self.top,self.front,self.right,self.left,self.rear,self.bottom = dice_number_list
    self.dice_number_list = dice_number_list
    
  def roll(self,op):
    if   op=='N': 
      self.top, self.front, self.bottom, self.rear = \
      self.front, self.bottom, self.rear , self.top
    elif op=='E':
      self.top, self.left , self.bottom, self.right = \
      self.left , self.bottom, self.right, self.top
    elif op=='W': 
      self.top, self.right, self.bottom, self.left = \
      self.right, self.bottom, self.left , self.top
    elif op=='S': 
      self.top, self.rear , self.bottom, self.front = \
      self.rear , self.bottom, self.front, self.top
           
  def print_top(self):
    print(self.top)
  def print_right(self):
    print(self.right)
    
  def get_label(self):
    return([self.top, self.front, self.right, self.left, self.rear, self.bottom])
    
  #全パターン24通りの取得
  def get_all_number_list(self):
    #all_dice_number_list = []
    #while True:
    #  self.roll(random.choice("NEWS"))
    #  if self.get_label() not in all_dice_number_list:
    #    all_dice_number_list.append(self.get_label())
    #  if len(all_dice_number_list) == 24:
    #    return(all_dice_number_list)
    all_dice_number_list = []
    for op in "NNNNWNNNWNNNENNNENNNWNNN":
      self.roll(op)
      if self.get_label() not in all_dice_number_list:
        all_dice_number_list.append(self.get_label())
    return(all_dice_number_list)
  
  #2つのサイコロの一致判定
  def judge_equal(self,another):
    if(sorted(self.get_all_number_list()) == sorted(another.get_all_number_list())):
       return True
    else:
       return False

input1 = list(map(int,input().split()))
input2 = list(map(int,input().split()))
d1 = dice(input1)
d2 = dice(input2)

if d1.judge_equal(d2):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 5608
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val a = sc.next()
  val b = sc.next()

  println(abc086b(a, b))
}

private fun abc086b(a: String, b: String): String {
  val ab = (a + b).toInt()

  for (i in 1 .. 1000) {
    if (i * i == ab) return "Yes"
  }

  return "No"
}


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

int main() {
  ll a, b, c, k; cin >> a >> b >> c >> k;
  if (k <= a) {
    cout << k << endl;
  }else {
    if (k - a > b) {
      cout << a - (k - a - b) << endl;
    }else {
      cout << a << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;

int main() {
    ll n, a = 0, b = 0;
    cin >> n;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            a = i;
            b = n / i;
        }
    }
    cout << SZ(to_string(max(a, b))) << "\n";
}

Measured memory_bytes: 3684
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    rep(i, N) cin >> P[i];
    sort(all(P));
    int ans = 0;
    rep(i, K) ans += P[i];
    cout << ans << endl;
}

Measured memory_bytes: 3560
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	if(!n){
		cout << 0 << endl;
		return 0;
	}
	string res = "";
	while(n){
		int rem = n % -2;
		n /= -2;
		if(rem < 0){
			rem += 2;
			n++;
		}
		res += rem + '0';
	}
	reverse(all(res));
	cout << res << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
n = gets.to_i
s = gets.strip.to_s
i = 0
h = 0
alp = ("a".."z").to_a
while i < n-1 do
  mae = s[0..i]
  ushiro = s[i+1..n-1]
  k = 0
  cnt = 0
  while k < 26 do
    if mae.include?(alp[k])
      if ushiro.include?(alp[k])
        cnt += 1
      end
    end
    k += 1
  end
  if h < cnt
    h = cnt
  end
  i += 1
end
puts h

Measured memory_bytes: 14328
#include<bits/stdc++.h>
#define maxn 0x3f3f3f3f
using namespace std;
typedef long long ll;
int main()
{
	std::ios::sync_with_stdio(false);
	int a,i,ans=0;
	for(i=1;i<=5;i++)
	{
		cin>>a;
		if(a==0) ans=i;
	}
	cout<<ans;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n,m;
mat ab;
lli ans = 0;

int main(){
  cin >> n >> m;
  ab = mat(m,vll(2));
  for(lli i = 0;i < m;i++) cin >> ab[i][0] >> ab[i][1];
  sort(ab.begin(),ab.end());
  lli min_val = LONG_MAX;
  for(lli i = 0;i < m;i++){
    if(ab[i][0] >= min_val){
      ans++;
      min_val = LONG_MAX;
    }
    min_val = min(min_val,ab[i][1]);
  }

  cout << ans+1 << endl;

}


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

int main()
{
	string s, c, p;
	int q, a, b;

	cin >> s >> q;
	while (q--) {
		cin >> c >> a >> b;
		int l = b - a + 1;
		if (c == "print")
			cout << s.substr(a, l) << endl;
		else if (c == "reverse")
			reverse(s.begin() + a, s.begin() + b + 1);
		else {
			cin >> p;
			s = s.replace(a, l, p);
		}
	}

	return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    string s, t; cin >> s >> t;

    ll ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != t[i]) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
  priority_queue<ll> pqA;
  priority_queue<ll> pqB;
  priority_queue<ll> pqC;
  priority_queue<ll, vector<ll>, greater<ll> > pq;
  REP(i, A){
    ll a; cin >> a;
    pqA.push(a);
  }
  REP(i, B){
    ll b; cin >> b;
    pqB.push(b);
  }
  REP(i, C){
    ll c; cin >> c;
    pqC.push(c);
  }
  REP(i, X){
    pq.push(pqA.top()); pqA.pop();
  }
  REP(i, Y){
    pq.push(pqB.top()); pqB.pop();
  }
  while(pqC.top() > pq.top()){
    pq.push(pqC.top());
    pq.pop(); pqC.pop();
    if(pqC.empty()) break;
  }
  ll ans = 0;
  while(!pq.empty()){
    ans += pq.top(); pq.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 4852
from collections import defaultdict
from itertools import accumulate
import bisect


n,k = map(int, input().split())

a = list(map(int,input().split()))

s = list(accumulate([0]+a))

b = [s[i]-i for i in range(n+1)]

d = defaultdict(list)

for i in range(n+1):
    d[b[i]%k].append(i)

ans = 0
for x in d.keys():
    l = d[x]
    for j in range(len(l)):
        y = l[j]
        ans += max(0,bisect.bisect_right(l,k+y-1)-j-1)

print(ans)




Measured memory_bytes: 128696
N,K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]

INF = 10**20
dp = [0]*N
dp[0] = 0

for k in range(1,N):
    tmp = []
    for i in range(min(k,K)):
        tmp.append(dp[k-i-1]+abs(H[k]-H[k-i-1]))
    dp[k] = min(tmp)
print(dp[-1])


Measured memory_bytes: 54904
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

void dfs(const vector<vector<int>>& Graph, vector<int>& Ans, const vector<int>& Query, int now, int pre) {
	Ans[now] += Ans[pre] + Query[now];
	for (int v : Graph[now]) if (v != pre) dfs(Graph, Ans, Query, v, now);
}

int main() {
	int N, Q;
	cin >> N >> Q;
	vector<vector<int>> Graph(N);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		Graph[a - 1].push_back(b - 1);
		if (a > 1) Graph[b - 1].push_back(a - 1);
	}
	vector<int> Query(N);
	vector<int> Ans(N);
	for (int i = 0; i < Q; i++) {
		int p, x;
		cin >> p >> x;
		Query[p - 1] += x;
	}

	dfs(Graph, Ans, Query, 0, 0);

	for (int q : Ans) cout << q << " ";
	cout << endl;
}

Measured memory_bytes: 30464
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CIN(int, K);

    vector<int> countK(100, 0);
    countK[0] = max(0, N - K + 1);
    int sum = countK[0];
    int last = 0;

    for (int i = 1; i < 100; i++) {
        int k, k2;
        k2 = pow(2, i);
        k = (K + k2 -1) / k2;
        countK[i] = max(0, (N-k+1) - sum);
        sum += countK[i];
        if (k <= 1) {
            last = i;
            break;
        }
    }

    ll x = 0;
    for (int i = 0; i <= last; i++) {
        x += pow(2,last-i) * countK[i];
    }

    double ans = (double)x / (double)(N * pow(2, last));
    printf("%.15f\n", ans);
    return 0;
}

Measured memory_bytes: 256
array = []
for i in range(5):
  n = int(input())
  array.append(n)

min = 10
index = 0
for i in range(5):
  if (array[i]%10) < min and 0<(array[i]%10):
    min = array[i]%10
    index = i
    
sum = int(0)
for i in range(5):
  ans = array[i]//10
  amari = array[i]%10
  if i == index :
    sum += array[i]
  elif amari == 0:
    sum += int(ans*10)
  else:
    sum += int(ans*10 +10)
  
print(sum)

Measured memory_bytes: 3064