akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<i64>();
    }
    let ans = solve(&seq);
    println!("{}", ans);
}

fn solve(seq: &Vec<i64>) -> i64 {
    let n = seq.len();
    let mut ret = 0;
    let mut visit = vec![false; n];
    for skip in 1..n {
        let mut sum = 0;
        let mut max_k = 0;
        for k in 1..n {
            let a = n - 1 - skip * k;
            if a < skip {
                break;
            }
            let mut l = skip * k;
            if skip * k >= n - 1 {
                break;
            }
            let mut r = n - 1 - skip * k;
            if visit[l] || visit[r] || l == r {
                break;
            }
            visit[l] = true;
            visit[r] = true;
            sum += seq[l] + seq[r];
            ret = std::cmp::max(ret, sum);
            max_k = k;
        }
        for k in 1..(max_k + 1) {
            let mut l = skip * k;
            let mut r = n - 1 - skip * k;
            visit[l] = false;
            visit[r] = false;
        }
    }
    return ret;
}

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


int main() {
  long long a, b , n ;
  cin >> a >> b >> n ;
  
  if(b<=n){
    cout << (a*(b-1))/b << endl;
  }
  
  else{
    cout << (a*n)/b << endl;
  }

}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<stdio.h>
#include<vector>
#include<set>
#include<utility>
#include<ctype.h>
#include<ctime>
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
# define ll long long
using namespace std;
int gcd(int a,int b){
    int r;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int GCD(int a,int b)
{
    if(a==0) return b;
    else return GCD(b%a,a);
}
long long int power(long long int a,long long int b){
    long long int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}
int palindrome(char *s,int len)
{
    int i,j,k,count=0,c=0;
    for(i=0,j=len-1;i<len,j>=0;i++,j--){
        if(s[i]==s[j]) count++;
    }
	if(count==len) return 1;
    	else return 0;
}
long long int binary(char *s,long long int len)
{
    long long int i,j,k,r=0,p=0,num;
    for(i=len-1;i>=0;i--){
        num=s[i]-'0';
        r+=(num*power(2,p));
        p++;
    }
    return r;
}
int binary_search(int *ara,int size,int n)
{
    int high,mid,low;
    low=0;
    high=size-1;
    while(low<=high){
        mid=(low+high)/2;
        if(ara[mid]==n){
            return 1;
        }
        else if(n>ara[mid]) low=mid+1;
        else if(n<ara[mid]) high=mid-1;
    }
    return -1;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int i,j,k,m,n,T,q,count=0;
	cin>>n>>m;
	string s1[n],s2[m];
	for(i=0;i<n;i++) cin>>s1[i];
	for(i=0;i<m;i++) cin>>s2[i];
	for(i=0;i<m;i++){
        count=0;
        if(s1[i].find(s2[0])!=string::npos){
            for(j=0;j<m;j++){
                if(s1[i+j].find(s2[j])!=string::npos) count++;
                }
                if(count>=m) break;
            }
        }
	(count>=m)?cout<<"Yes"<<endl:cout<<"No"<<endl;
}




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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int count = 0;
  for(;A % 2 == 0 && B % 2 ==0 && C % 2 ==0;){
    if(A == B && B == C){
      cout << -1 << endl;
      return 0;
    }
    int a, b, c;
    a = A / 2;
    b = B / 2;
    c = C / 2;
    A = b + c;
    B = a + c;
    C = a + b;
    count++;
  }
  cout << count << endl;
}


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

typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;

map <string, ll> mp ;
pair <ll, string> pt[200005] ;

bool comp(const pair<ll,string> &x, const pair<ll,string> &y) {
    if (x.first == y.first) return x.second < y.second ;
    else    return x.first > y.first ;
}

int main()
{
    ll n, j = 0, val ;
    cin >> n ;
    string s, p ;

    for (int i = 0; i < n; i++) {
        cin >> s ;
        mp[s]++ ;
    }
    for (auto it = mp.begin(); it != mp.end(); it++) {
        pt[j].first = it->second, pt[j].second = it->first ;
        j++ ;
    }
    sort(pt, pt + j, comp) ;
    val = pt[0].first ;
    for (int i = 0; i < j; i++) {
        if (pt[i].first == val)    cout << pt[i].second << endl ;
    }
}


Measured memory_bytes: 28672
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int selectionSort(int* list, int size);

int main() {
	int n=3,a[3];

	for (int i = 0; i < n; i++)
		scanf("%d", a + i);

    selectionSort(a, 3);

	for (int i = 0; i < n; i++)
		printf("%d%c", *(a + i), i < n - 1 ? ' ' : '\n');

	return 0;
}

int selectionSort(int* list, int size) {
	for (int i = 0; i < size; i++) {
		int min = INT_MAX, index = i, temp = 0;
		for (int j = i; j < size; j++) {
			if (list[j] < min) {
				min = list[j];
				index = j;
			}
		}
		if (index != i) {
			temp = list[i];
			list[i] = list[index];
			list[index] = temp;
		}
	}
	return 0;
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int n;
LL l,r;
vector <int> input;
LL before(LL x,int kel){
	return x-(x%kel);
}
LL after(LL x,int kel){		//yang pertama >= x kelipatannya kel
	LL ret=before(x,kel);
	if(ret==x)
		return ret;
	ret+=kel;
	return ret;
}
int main()
{
	l=r=2;
	scan(n);
	input.resize(n);
	for(int i=0;i<n;i++)
		scan(input[i]);
	reverse(all(input));
	for(int i=0;i<n&&l<=r;i++)
	{
		l=after(l,input[i]);
		r=before(r,input[i]);
		r+=input[i]-1;
		if(l>r)
			break;
	}
	if(l>r)
		cout<<-1<<endl;
	else
		cout<<l<<" "<<r<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
int n;
void dfs(string s,int t){
    if(s.size()==n){
        cout<<s<<endl;
        return;
    }
    for(int i=0;i<=t;i++)
        dfs(s+char('a'+i),t+(i==t));
}
signed main(){
    cin>>n;
    dfs(string(),0);
}


Measured memory_bytes: 1536
#include<cstdio>

using namespace std;
const int N = 1E5 + 10;

int n;
int ans;

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n ; i ++)
    {
        int x;
        scanf("%d", &x);
        ans ^= x;
    }
    if(ans == 0) puts("Yes");
    else         puts("No");
    
    return 0;
}

Measured memory_bytes: 128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,t,l,b = LI()
        if n == 0:
            break
        ls = set([I() for _ in range(l)])
        bs = set([I() for _ in range(b)])
        r = [[0] * (n+1) for _ in range(t+2)]
        r[0][0] = 1
        for i in range(t):
            for j in range(n):
                if r[i][j] == 0:
                    continue
                for k in range(1,7):
                    nj = j+k
                    if nj > n:
                        nj = n - (nj-n)
                    ni = i + 1
                    if nj in ls:
                        ni += 1
                    if nj in bs:
                        nj = 0
                    if nj == n:
                        ni = t
                    r[ni][nj] += r[i][j] / 6.0
        rr.append('{:0.9f}'.format(r[t][n]))

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9328
#include <iostream>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
    int N;
    set<string> s;

    cin >> N;

    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        s.insert(S);
    }
    cout << s.size() << endl;

    return 0;
}

Measured memory_bytes: 19120
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A


if __name__ == '__main__':
    N=int(input())
    A = InputToInt()
    su = 0
    for i in range(N):
        su += 1.0/A[i]
    print(1.0/su)
    


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

using pii = pair<int, int>;

enum {
    LEFT, RIGHT, FRONT, BACK, DOWN, UP
};

class dice {
public:
    dice(vector<int> score) : score(score) { assert(score.size() == 6); }

    void roll(char dir) {
        assert(dir == 'L' || dir == 'R' || dir == 'B' || dir == 'F');
        vector<int> nscore = score;
        if(dir == 'L') {
            nscore[LEFT] = score[UP];
            nscore[UP] = score[RIGHT];
            nscore[RIGHT] = score[DOWN];
            nscore[DOWN] = score[LEFT];
        } else if(dir == 'R') {
            nscore[RIGHT] = score[UP];
            nscore[UP] = score[LEFT];
            nscore[LEFT] = score[DOWN];
            nscore[DOWN] = score[RIGHT];
        } else if(dir == 'F') {
            nscore[FRONT] = score[UP];
            nscore[UP] = score[BACK];
            nscore[BACK] = score[DOWN];
            nscore[DOWN] = score[FRONT];
        } else {
            nscore[BACK] = score[UP];
            nscore[UP] = score[FRONT];
            nscore[FRONT] = score[DOWN];
            nscore[DOWN] = score[BACK];
        }
        score = move(nscore);
    }

    int get_value(int dir) const {
        return score[dir];
    }

private:
    vector<int> score;
};

int main() {
    const string dirs = "LRFB";
    constexpr int dx[4] = {-1, 1, 0, 0};
    constexpr int dy[4] = {0, 0, -1, 1};
    int n;
    while(cin >> n, n) {
        // (x, y -> value);
        using traj = map<pii, int>;
        vector<traj> trajs;
        for(int i = 0; i < n; ++i) {
            int x, y;
            cin >> x >> y;
            vector<int> score(6);
            for(int j = 0; j < 6; ++j) {
                cin >> score[j];
            }
            string rot;
            cin >> rot;
            dice d(score);
            traj t;
            t[make_pair(x, y)] = d.get_value(DOWN);
            for(char to : rot) {
                int dir = dirs.find(to);
                x += dx[dir], y += dy[dir];
                d.roll(to);
                t[make_pair(x, y)] = d.get_value(DOWN);
            }
            trajs.push_back(move(t));
        }

        vector<int> dp(1 << n);
        for(int S = 0; S < (1 << n); ++S) {
            set<pii> used;
            for(int i = 0; i < n; ++i) {
                if(S & (1 << i)) {
                    for(auto& p : trajs[i]) {
                        used.insert(p.first);
                    }
                }
            }
            for(int i = 0; i < n; ++i) {
                if(S & (1 << i)) continue;
                map<pii, int> new_values;
                for(auto& p : trajs[i]) {
                    if(used.count(p.first)) continue;
                    new_values[p.first] = p.second;
                }
                int value = 0;
                for(auto& p : new_values) {
                    value += p.second;
                }
                dp[S | (1 << i)] = max(dp[S | (1 << i)], dp[S] + value);
            }
        }

        cout << dp.back() << endl;
    }
}



Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll N;
    cin >> N;
    ll end_num;
    end_num = (ll)sqrtl(N);
    ll max_num = 0;
    for(int i=1;i<=end_num;i++){
        if(N%i==0){
            if(max_num < i){
                max_num = i;
            }
        }
    }
    cout << max_num-1 + (N/max_num)-1 << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
T,A = map(int,input().split())
H = [int(i) for i in input().split()]
mini = 1000
ind = 0
for i in range(N):
  new_mini = min(mini, abs(A-(T-H[i]*0.006)))
  if new_mini != mini:
    ind = i
  mini = new_mini
print(ind+1)

Measured memory_bytes: 3060
#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_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}



int main(){
    ll n,d;
    cin>>n>>d;
    cout<<(n+2*d)/(2*d+1)<<endl;
    
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
ll po(ll a, ll n) {
	if (n == 0)return 1;
	ll d = po(a, n / 2);
	if (n & 1)return a * d%MOD*d%MOD;
	return d * d%MOD;
}
vl fact, rfact;
ll comb(ll n, ll r) {
	return fact[n] * rfact[r] % MOD*rfact[n - r] % MOD;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w, n;
	cin >> h >> w >> n;
	vector<pii> v(n);
	REP(i, n)cin >> v[i].first >> v[i].second;
	sort(ALL(v));
	v.push_back({ h,w });
	fact.resize(h + w + 1, 1);
	rfact.resize(h + w + 1);
	REP(i, h + w)fact[i + 1] = fact[i] * (i + 1) % MOD;
	REP(i, h + w + 1)rfact[i] = po(fact[i], MOD - 2);
	vl dp(n + 1);
	REP(i, n + 1) {
		ll tmp = comb(v[i].first + v[i].second - 2, v[i].first - 1);
		REP(j, i) {
			if (v[j].first <= v[i].first&&v[j].second <= v[i].second) {
				tmp = (tmp - dp[j] * comb(v[i].first - v[j].first + v[i].second - v[j].second, v[i].first - v[j].first) % MOD + MOD) % MOD;
			}
		}
		dp[i] = tmp;
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ll n, a, b; cin >> n >> a >> b;
    if(n==1) {
        if(a==b) cout << 1 << endl;
        else cout << 0 << endl;
    }
    else {
        if(a>b) cout << 0 << endl;
        else {
            cout << (n-2)*(b-a)+1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iostream>
#include<queue>
#include<map>
#include<ctime>
#define mod 1000000007
using namespace std;
int n,a[2005];
long long ans,cnt[2005],k;
int main(){
	scanf ("%d%d",&n,&k);
	for (int i = 1;i <= n;i ++)
		scanf ("%d",&a[i]);
	for (int i = 1;i <= n;i ++)
		for (int j = 1;j <= n;j ++)
			if (i != j)
				if (a[j] < a[i])
					cnt [i] ++;
	for (int i = 1;i <= n;i ++){
		long long tot = 0;
		for (int j = i + 1;j <= n;j ++)
			if (a[i] > a[j])
				tot ++;
		ans = (ans + (tot * k) % mod) % mod;
	}
	for (int i = 1;i <= n;i ++)
		ans = (ans + ((k - 1) * k % mod * cnt[i] % mod * 500000004 % mod)) % mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
#!/usr/bin/env python3
#EDPC B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
h = LI()
dp = [inf]*n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
    for j in range(1,k+1):
        if i - j < 0:
            break
        dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]))
print(dp[-1])

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ta, ao;
    ta = (c + (b - 1)) / b;
    ao = (a + (d - 1)) / d;
    if (ta > ao)
        cout << "No";
    else
        cout << "Yes";
}

Measured memory_bytes: 3636
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String arg[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int H = Integer.parseInt(st.nextToken());
        int W = Integer.parseInt(st.nextToken());
        int N = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int sr = Integer.parseInt(st.nextToken());
        int sc = Integer.parseInt(st.nextToken());
        String S = br.readLine();
        String T = br.readLine();
        int tr = sr;
        int tc = sc;
        boolean remove = false;
        for(int i=0;i<N;i++){
            if(S.charAt(i)=='L'){
                tc--;
                if(tc<=0){
                    remove = true;
                    break;
                }
            }
            if(T.charAt(i)=='R'){
                tc = Math.min(W,tc+1);
            }
        }
        tr = sr;
        tc = sc;
        for(int i=0;i<N;i++){
            if(S.charAt(i)=='R'){
                tc++;
                if(tc>W){
                    remove = true;
                    break;
                }
            }
            if(T.charAt(i)=='L'){
                tc = Math.max(1,tc-1);
            }
        }
        tr = sr;
        tc = sc;
        for(int i=0;i<N;i++){
            if(S.charAt(i)=='U'){
                tr--;
                if(tr<=0){
                    remove = true;
                    break;
                }
            }
            if(T.charAt(i)=='D'){
                tr = Math.min(H,tr+1);
            }
        }
        tr = sr;
        tc = sc;
        for(int i=0;i<N;i++){
            if(S.charAt(i)=='D'){
                tr++;
                if(tr>H){
                    remove = true;
                    break;
                }
            }
            if(T.charAt(i)=='U'){
                tr = Math.max(1,tr-1);
            }
        }
        if(remove){
            System.out.println("NO");
        }else{
            System.out.println("YES");
        }
    }
}


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

const int M = int(1e9) + 7;

string S;
int dp[100002][13];

int to_i(char c){
	return (c - '0');
}

int main(){
	cin >> S;
	dp[0][0] = 1;
	for(unsigned i = 0; i < S.length(); i++){
		if(S[i] == '?') {
			for(int m = 0; m < 13; m++){
				for(int d = 0; d < 10; d++){
					dp[i+1][(m * 10 + d) % 13] += (dp[i][m]);
					dp[i+1][(m * 10 + d) % 13] %= M;
				}
			}
		}
		else {
			for(int m = 0; m < 13; m++){
				dp[i+1][(m * 10 + to_i(S[i])) % 13] += (dp[i][m]);
				dp[i+1][(m * 10 + to_i(S[i])) % 13] %= M;
			}
		}
	}
	//--
	cout << dp[S.length()][5];
}

Measured memory_bytes: 5504
#include <iostream>
using namespace std;
int dp[105][10005];
int main(){
      int n,sum,a,b;
      cin >> n >> sum;
      for (int i = 0;i < n;i++){
            cin >> a >> b;
            for (int j = 0;j<= sum;j++){
            if(j>=b)
                  dp[i+1][j] = max(dp[i][j],dp[i][j-b]+a);
            else
                  dp[i+1][j] = dp[i][j];
            }
      }
      cout <<dp[n][sum]<<endl;
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=100010;
int x,y,a,b,c,t,tot;
ll p[MAXN*3],q[MAXN],r[MAXN],ans;
int main () {
    scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
    for (int i=1;i<=a;i++) {
        scanf("%d",&q[i]);
    }
    sort(q+1,q+a+1);
    for (int i=a;i>=a-x+1;i--) {p[++tot]=q[i];}
    for (int i=1;i<=b;i++) {
        scanf("%d",&r[i]);
    }
    sort(r+1,r+b+1);
    for (int i=b;i>=b-y+1;i--) {p[++tot]=r[i];} 
    for (int i=1;i<=c;i++) {
        scanf("%d",&t);
        p[++tot]=t;
    }
    sort(p+1,p+tot+1);
    for (int i=tot;i>=tot-x-y+1;i--) {
        ans+=p[i];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3968
use proconio::input;
use proconio::marker::Bytes;

fn main() {
  input! {
    n: usize,
    s: String
  }
  let mut s: Vec<char> = s.chars().collect();
  let mut index = 0;
  
  while index + 1 < s.len() {
    if s[index] == s[index + 1] {
      s.remove(0);
    } else {
      index += 1;
    }
  }
  println!("{}", s.len());
}

Measured memory_bytes: 2672
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n<600)cout<<8;
  else if(n<800)cout<<7; 
  else if(n<1000)cout<<6;
  else if(n<1200)cout<<5;
  else if(n<1400)cout<<4;
  else if(n<1600)cout<<3;
  else if(n<1800)cout<<2;
  else cout<<1;
  }

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int n,t;cin>>n>>t;
  	vector<int> c(n);
  	vector<int> d(n);
  	int ans=1001;
  	for(int i=0;i<n;i++){
      	cin>>c.at(i)>>d.at(i);
    	if(t>=d.at(i)){
        	ans=min(ans,c.at(i));
        }
    }
	if(ans==1001){
    	cout<<"TLE"<<endl;
    }else{
    	cout<<ans<<endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
using namespace std;

#define rep(i,N) for(int (i)=0; (i)<(N); (i)++)
#define revrep(i,N) for(int (i)=(N)-1; (i)>=0; (i)--)
#define dump(vec) for(int i = 0; i < (vec).size(); i++){cout << vec.at(i) << ",";}cout << endl

typedef long long ll;

int main(void)
{
    
    vector<int> v(3);
    cin >> v.at(0) >> v.at(1) >> v.at(2);
    sort(v.begin(), v.end());
    cout << v.at(0)+v.at(1) << endl;

    return 0;
}


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

a = [0 for i in range(1000)]
b = [0 for i in range(1000)]

ans = 0

for i in range(n):
    a[l[i]-1] += 1

b[0] = a[0]

for i in range(1, 1000):
    b[i] = a[i] + b[i-1]

for i in range(1000):
    ans += a[i] * (a[i]-1) * (a[i]-2) // 6
    ans += a[i] * (a[i]-1) // 2 * (b[min(2*i, 999)]-a[i])

for i in range(1, 998):
    for j in range(i+1, 999):
        ans += a[i] * a[j] * (b[min(999, i+j)]-b[j])

print(ans)


Measured memory_bytes: 3188
def bubbleSort(c,n):
    for i in range(n):
        for j in range(i+1,n)[::-1]:
            if int(c[j-1][1]) > int(c[j][1]): c[j],c[j-1] = c[j-1],c[j]
    return

def selectionsSort(c,n):
    for i in range(n):
        minj = i
        for j in range(i,n):
            if int(c[minj][1]) > int(c[j][1]): minj = j
        c[i],c[minj] = c[minj],c[i]
    return 

def isStable(inp,outp,n):
    for i in range(n):
        for j in range(i+1,n):
            for k in range(n):
                for l in range(k+1,n):
                    if all((inp[i][1] == inp[j][1],inp[i] == outp[l],inp[j] == outp[k])): return False
    return True

if __name__ == "__main__":
    n = int(input())
    lst = [i for i in input().split()]
    a = lst[:]
    b = lst[:]
    bubbleSort(a,n)
    print(" ".join(a))
    print("Stable" if isStable(lst,a,n) else "Not stable")
    selectionsSort(b,n)
    print(" ".join(b))
    print("Stable" if isStable(lst,b,n) else "Not stable")


Measured memory_bytes: 5616
S = list(input())
K = int(input())

S = S + S + S
N = len(S)

a = 0
b = 0
c = 0
for i in range(1, N) : 
    if S[i] == S[i-1] :
        if i < N // 3 :
            a += 1
        elif i < N // 3 * 2 :
            b += 1
        else :
            c += 1
        S[i] = '#'
        
ret = a + K // 2 * b + (K - K // 2 - 1) * c
print(ret)

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

int main(){
  string s;
  cin >> s;
  int len= s.size(); 
  ll ans=0; 

  for(int t=0; t<1<<(len-1); t++){
    ll num=s[0]-'0'; 
    for(int i=0; i<len-1; i++){
      if(t&(1<<i)){
        ans+=num;
        num=0;
      }
      num=num*10+s[i+1]-'0';
    }
    ans+=num;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

long long dp[10][105];
int main(){
  int n; cin >> n;
  for(int j=0;j<10;j++) dp[j][0] = 0;
  dp[0][0] = 1;
  
  for(int i=1; i <= 100; i++){
  	dp[0][i] = dp[0][i-1]*2+dp[1][i-1]*2 + dp[6][i-1]+ dp[5][i-1]+dp[7][i-1]*2+dp[9][i-1]*2;
    dp[1][i] = dp[1][i-1]+dp[0][i-1]+dp[6][i-1]+dp[5][i-1];
    dp[2][i] = dp[1][i-1]+dp[4][i-1]+dp[5][i-1];
    dp[3][i] = dp[6][i-1]+dp[3][i-1]*4+dp[4][i-1]+dp[5][i-1]+dp[2][i-1]+dp[9][i-1];
    dp[4][i] = dp[2][i-1]+dp[8][i-1];
    dp[5][i] = dp[4][i-1]+dp[7][i-1];
    dp[6][i] = dp[4][i-1];
    dp[7][i] = dp[2][i-1]+dp[8][i-1];
    dp[8][i] = dp[7][i-1]+dp[0][i-1]+dp[2][i-1]+dp[8][i-1]+dp[9][i-1]+dp[6][i-1];
    dp[9][i] = dp[8][i-1];
    for(int j=0;j<10;j++) dp[j][i] %= MOD;
  }
  long long int ans = 0;
  for(int i=0;i<10;i++) ans = (ans + (i!=3 ? dp[i][n]: 0)) % MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/*Author- Soumak Poddar*/

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

#define ll long long int
#define sll signed long long int
#define ull unsigned long long int
#define um unordered_map
#define us unordered_set
#define mm multimap
#define mp make_pair
#define pb push_back
#define M 1000000007

bool comp(pair<int,int> a,pair<int,int> b)
{
   return a.second<b.second;
}

void solve();
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

   #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("error.txt", "w", stderr);
      freopen("output.txt", "w", stdout);
   #endif
   
   int t=1;
   // cin>>t;
   while(t--)
   {
      solve();
      cout<<"\n";
   }
   cerr<<"Time Taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
   return 0;
}
void solve()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=1;i<=n;i++)
      cin>>a[i];
   int c=0;
   for(int i=1;i<=n;i+=2)
   {
      if(a[i]%2!=0)
         c++;
   }
   cout<<c;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(void) {
  int ans = 0, i, n;
  scanf("%d", &n);
  int a[n];
  for(i = 0; i < n; ++i) scanf("%d", &a[i]), a[i]--;
  for(i = 0; i < n; ++i) if(a[a[i]] == i) ++ans;
  printf("%d", ans / 2);
  return 0;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

string s;

int main() {
	cin >> s;
	repi(i, 0, s.length()) {
		if (i % 2 == 0) wr(s[i]);
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll v[100010];
ll ans[100010]={};
ll y[100010];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll N=n;
    ll tot=0;
    while(N--){
        ll x;
        cin>>x;
        y[tot]=x;
        v[tot++]=x;
    }
    sort(v,v+tot);
    ll cnt=unique(v,v+tot)-v;
    for(ll i=0;i<tot;++i){
        ll pos=lower_bound(v,v+cnt,y[i])-v;
        ans[pos]++;
    }
    ll res=0;
    for(ll i=0;i<cnt;++i){
        if(ans[i]&1)
            res++;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 2560
import static java.util.Arrays.binarySearch;

import java.io.IOException;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		int n = nextInt();
		int m = nextInt();
		int[] xs = new int[n];
		int[] ys = new int[n];
		for (int i = 0; i < n; i++) {
			xs[i] = nextInt();
			ys[i] = nextInt();
		}

		TreeSet<Integer> xSet = new TreeSet<Integer>();
		TreeSet<Integer> ySet = new TreeSet<Integer>();

		for (int i = 0; i < n; i++) {
			xSet.add(xs[i]);
			ySet.add(ys[i]);
		}
		xSet.add((int) 1e9);
		ySet.add((int) 1e9);
		xSet.add((int) -1e9);
		ySet.add((int) -1e9);

		Integer[] xss = xSet.toArray(new Integer[0]);
		Integer[] yss = ySet.toArray(new Integer[0]);

		int w = xss.length;
		int h = yss.length;

		int[][] a = new int[h + 1][w + 1];
		for (int i = 0; i < n; i++) {
			int x = binarySearch(xss, xs[i]);
			int y = binarySearch(yss, ys[i]);
			a[y + 1][x + 1]++;
		}

		for (int j = 0; j < h; j++) {
			for (int i = 0; i < w; i++) {
				a[j + 1][i + 1] += a[j + 1][i] + a[j][i + 1] - a[j][i];
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < m; i++) {
			int x1 = binarySearch(xss, xSet.ceiling(nextInt()));
			int y1 = binarySearch(yss, ySet.ceiling(nextInt()));
			int x2 = binarySearch(xss, xSet.floor(nextInt())) + 1;
			int y2 = binarySearch(yss, ySet.floor(nextInt())) + 1;
			sb.append(a[y2][x2] - a[y1][x2] - a[y2][x1] + a[y1][x1]);
			sb.append('\n');
		}
		System.out.print(sb.toString());
	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}

}

Measured memory_bytes: 211348
//url:
//problem name: 

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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 namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,M;
    cin >> N >> M;
    map<ll,ll> mp;
    REP(i,N) {
        ll a;
        cin >> a;
        if(mp.count(a)) mp[a]++;
        else mp[a] = 1;
    }
    REP(i,M) {
        ll b,c;
        cin >> b >> c;
        if(mp.count(c)) mp[c] += b;
        else mp[c] = b;
    }
    vector<pair<ll,ll>> res;
    ll ans = 0;
    for(auto x : mp) res.push_back(x);
    sort(res.begin(),res.end(),greater<pair<ll,ll>>());
    for(auto x : res) {
        ll c = x.first;
        ll b = x.second;
        if(b < N) ans += c*b;
        else {
            ans += c*N;
            break;
        }
        N -= b;
    }
    cout << ans << endl;
}


Measured memory_bytes: 17520
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  int v = 0;
  vector<int> j(a+1);
  j.at(0) = 171104;
  j.at(a) = 1341398;
  for(int i = 1;i < a;i++){
    cin >> j.at(i);
  }
  for(int i = 0;i < a;i++){
    v += min(j.at(i),j.at(i+1));
  }
  cout << v << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
ll a[100000],b[100000],c[100000];
ll bb[100000];

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  ll ans=0;
  REP(i,n)cin>>a[i];
  REP(i,n)cin>>b[i];
  REP(i,n)cin>>c[i];
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);

  REP(i,n){
    int t1=upper_bound(c,c+n,b[i])-c;
    bb[i]=n-t1;
    // P(bb[i]);
    // P(t1);
    // P("--");
  }
  reverse(bb,bb+n);
  REP(i,n)bb[i+1]+=bb[i];
  reverse(bb,bb+n);
  // REP(i,n)P(bb[i]);
  REP(i,n){
    int t2=upper_bound(b,b+n,a[i])-b;
    if(t2==n)continue;
    ans+=bb[t2];
    // P(bb[t2]);
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 3328
import math
from functools import reduce
#数値ひとつ
#I = int(input())
#数値空白区切りで欲しいとき
N, K = map(int, input().split())
#文字欲しいとき
#N = input()
#それをListにしたいとき
#list = list(N)
#数値を受け取る数が未定かつリストにしたいとき
#list = list(map(int, input().split()))
#受け取る文字列が未定かつリストにしたいとき(Iは回数)
#list = [input() for i in range(I)]
lista = []
for i in range(K):
    S = input()
    l = list(map(int, input().split()))
    lista.append(l)

lista = reduce(lambda a, b: a + b, lista)
lista = list(set(lista))
print(N - len(lista))

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

#define ll long long
#define ar array

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

	string s, t;
	cin >> s >> t;
	int ans=0;
	for(int i=0; i<s.size(); ++i)
		if(s[i]^t[i])
			++ans;
	cout << ans;
}

Measured memory_bytes: 3884
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int read();
void Add(int &x, int y) { (x += y) >= mod ? x -= mod : x; }
int n, m;
int a[100005], b[100005];
struct P {
    int x, y;
} p[100005];
bool cmp(P a, P b) { return a.x == b.x ? a.y > b.y : a.x < b.x; }
int st[100005], top, cnt;
struct Bit {
    int s[100005];
    void add(int p, int v) {
        for (; p <= top; p += p & -p) Add(s[p], v);
    }
    int qry(int p) {
        int rt = 0;
        for (; p; p -= p & -p) Add(rt, s[p]);
        return rt;
    }
} bit;
int main() {
    n = read(), m = read();
    for (int i = 1; i <= n; ++i) a[i] = read();
    for (int i = 1; i <= m; ++i) b[i] = read();
    for (int i = 1, j = 1; i <= n; ++i) {
        if (a[i] < b[1]) continue;
        if (a[i] > b[m]) break;
        while (a[i] > b[j + 1]) ++j;
        p[++cnt].x = a[i] - b[j], st[cnt] = p[cnt].y = b[j + 1] - a[i];
    }
    sort(st + 1, st + 1 + cnt), top = unique(st + 1, st + 1 + cnt) - st - 1;
    sort(p + 1, p + 1 + cnt, cmp);
    for (int i = 1; i <= cnt; ++i) {
        p[i].y = lower_bound(st + 1, st + 1 + top, p[i].y) - st;
        if (p[i].x == p[i - 1].x && p[i].y == p[i - 1].y) continue;
        bit.add(p[i].y, bit.qry(p[i].y - 1) + 1);
    }
    printf("%d\n", (bit.qry(top) + 1) % mod);
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
int read() {
    int x = 0, f = 1;
    char c = gc;
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x * f;
}

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


int main(void){
    
    char S[202] = {0},s[100] = {0},p[100] = {0};
    
    scanf("%s",s);
    scanf("%s",p);
    
    strcpy(S,s);
    strcat(S,s); //??????????????£???
    
    if(strstr(S,p)) printf("Yes\n");
     else printf("No\n");
}   

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

using vi = vector<int>; 
using vvi = vector<vi>;

int main() {
  string s;
  cin >> s;
  int n = stoi(s);
  int ret = 0;
  int m = (s.size() +1) / 2;
  if (s.size() %2 == 1) {
    for(int i = 1; i < m; i++){
      // cout << "add" << 9 * pow(10, 2*(i-1)) << endl;
      ret += 9 * pow(10, 2*(i-1));
    }
  }
  else {
      for(int i = 1; i <= m; i++){
	// cout << "add" << 9 * pow(10, 2*(i-1)) << endl;
	ret += 9 * pow(10, 2*(i-1));
      }
    }
  if(s.size()%2 == 1){
    // cout << "residue " << (n +1 - pow(10, s.size()-1)) << endl;
    ret += (n +1 - pow(10, s.size()-1));
  }
  // cout << s.size() << " " << n << endl;
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
ll longinf=(1ll<<31)-1;

int main(){
      ll n,a,b;
      cin>>n>>a>>b;
      ll ok = 1e9;
      ll ng = -1;
      ll h[n];
      rep0(i,n) cin>>h[i];
      sort(h,h+n);
      while(ok - ng > 1){
            ll pos=(ok+ng)/2;
            ll pp=pos;
            ll q[n]; 
            rep0(i,n){
                  q[i]=h[i]-(b*pos);
            }
            rep0(i,n){
                  pp-=max(0ll,((q[i]+a-b-1)/(a-b)));
            }
            if(pp>=0) ok=pos;
            else ng=pos;
      }
      cout<<ok<<endl;


      return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in);
		int[] l = new int[4];
		int[] r = new int[4];
		while (in.hasNext()) {
			set(in.nextDouble(), l);
			set(in.nextDouble(), r);
		}
		for (int i = 0; i < 4; i++) {
			System.out.print(l[i]);
			System.out.print(' ');
			System.out.println(r[i]);
		}
		in.close();
	}

	static void set(double p, int[] g) {
		if (p >= 1.1) {
			g[0]++;
		} else if (p >= 0.6) {
			g[1]++;
		} else if (p >= 0.2) {
			g[2]++;
		} else {
			g[3]++;
		}
	}
}

Measured memory_bytes: 20648
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int Mod=1000000007;
int n,k;
char s[110];
bool vis[110];
bool book[110];
int a[110];
bool check(int m)
{
	memset(vis,0,sizeof(vis));
	memset(book,0,sizeof(book));
	int cnt=0;
	for(int i=1;i<=m&&a[i]==1;i++)cnt++;
	int nowr=1,nowb=1;
	for(int i=1;i<=m-cnt;i++)
	{
		while(nowr<=k&&(vis[nowr]||s[nowr]!='r'))nowr++;
		while(nowb<=k&&(vis[nowb]||s[nowb]!='b'||nowb<=nowr))nowb++;
		if(nowr>k||nowb>k)return false;
		vis[nowr]=true;
		vis[nowb]=true;
		book[nowb]=true;
	}
	int tmp=cnt;
	for(int i=1;i<=k&&tmp;i++)
		if(!vis[i]&&s[i]=='r'){
			vis[i]=true;
			tmp--;
		}
	if(tmp)return false;
	int now=cnt+1,num=0;
	for(int i=k;now<=m;i--)
	{
		if(!vis[i])num++;
		if(book[i]){
			num-=a[now]-2;
			if(num<0)return false;
			now++;
		}
	}
	return true;
}
int fpow(int a,int b)
{
	int ans=1,t=a;
	while(b)
	{
		if(b&1)ans=1ll*ans*t%Mod;
		t=1ll*t*t%Mod;
		b>>=1;
	}
	return ans;
}
int ans;
int fac[2010],inv[2010];
void init()
{
	int N=2000;
	fac[0]=1;
	for(int i=1;i<=N;i++)
		fac[i]=1ll*fac[i-1]*i%Mod;
	inv[N]=fpow(fac[N],Mod-2);
	for(int i=N;i>=1;i--)
		inv[i-1]=1ll*inv[i]*i%Mod;
	return ;
}
int C(int x,int y)
{
	if(x<0||y<0||x-y<0)return 0;
	return 1ll*fac[x]*inv[y]%Mod*inv[x-y]%Mod;
}
void solve(int m,int len)
{
	int s=m+1;//block-1
	for(int i=1;i<=m;i++)
		if(a[i]==1)s++;
		else s+=(a[i]-1)*2+1;
	int res=1ll*C(n-len+s-1,s-1)*fac[m]%Mod;
	for(int i=1,j;i<=m;i=j)
	{
		j=i;
		while(j<=m&&a[j]==a[i])j++;
		res=1ll*res*inv[j-i]%Mod;
	}
	ans=(ans+res)%Mod;
	return ;
}
int cntr;
bool dfs(int m,int lst,int sum,int len)
{
	if(!check(m-1))return false;
	if(m-1>cntr)return true;
	solve(m-1,len);
	for(a[m]=lst;a[m]<=k-sum;a[m]++)
	{
		int tlen=len;
		if(m>1)tlen++;
		if(a[m]==1)tlen++;
		else tlen+=(a[m]-1)*2-1;
		if(tlen>n)break;
		if(!dfs(m+1,a[m],sum+a[m],tlen))
			break;
	}
	return true;
}
int main()
{
	init();
	scanf("%d %d",&n,&k);
	scanf("%s",s+1);
	for(int i=1;i<=k;i++)
		if(s[i]=='r')cntr++;
	dfs(1,1,0,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 764
import math  # noqa: F401
from typing import Dict, List, Optional, Tuple, Union  # noqa: F401


def main(N: int, M: int, A: List[int]):
    x = sum(A) * 1 / (4 * M)
    chooseables: List[bool] = [a >= x for a in A]
    print(["No", "Yes"][sum(chooseables) >= M])


if __name__ == "__main__":
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    main(N, M, A)


Measured memory_bytes: 10224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX = 1000000000;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll h[100010];
    for (ll i = 1; i <= n;i++){
        cin >> h[i];
        
    }
    bool bad[100010];
    for (int i = 0; i < 10000;i++){
        bad[i] = false;
    }
        ll a[100010], b[100010];
    for (ll i = 0; i < m;i++){
        cin >> a[i] >> b[i];
        if(h[a[i]] > h[b[i]]){
            bad[b[i]] = true;
        }
        else if(h[a[i]] < h[b[i]]){
            bad[a[i]] = true;
        }
        else{
            bad[a[i]] = true;
            bad[b[i]] = true;
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= n;i++){
        if (bad[i] == true){
            ans++;
        }
        else{
            //cout << i << endl;
        }
    }
    cout << n - ans;
} 


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    string line;
    while (true) {
        getline(cin, line);
        if (cin.eof()) break;

        stack<double> st;
        stringstream ss(line);
        while (!ss.eof()) {
            string S; ss >> S;

            if (isdigit(S[0]) || S.size() > 1) {
                int num = stoi(S);
                st.push(num);
            } else {
                double b = st.top(); st.pop();
                double a = st.top(); st.pop();
                if (S == "-") st.push(a - b);
                if (S == "+") st.push(a + b);
                if (S == "*") st.push(a * b);
                if (S == "/") st.push(a / b);
            }
        }

        cout << fixed << setprecision(10) << st.top() << endl;
    }
}

Measured memory_bytes: 3212
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
#define NJ !((i>>(j-1))&1)
#define SJ i^(1<<(j-1))
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int K=200005;
const int N=25;
const int M=(1<<19)+5;
int n,V,X[K],s[N],f[M],g[M];
int tot,L[K][N],R[K][N],FM[K];
inline void MX(int &x,int y) {if(y>x) x=y;}
inline void MN(int &x,int y) {if(y<x) x=y;}
int main( )
{
  int i,j,x,y,t;
  n=read( );V=read( );
  for(i=1;i<=n;i++) X[i]=read( );
  for(j=V;;j>>=1)
    {
      s[++tot]=j;
      for(i=1,t=1;i<=n;i++)
	{
	  t=max(t,i);
	  while(t<n&&X[t+1]-X[t]<=j) t++;
	  L[i][tot]=t;
	}
      L[n+1][tot]=n;
      for(i=n,t=n;i>=1;i--)
	{
	  t=min(t,i);
	  while(t>1&&X[t]-X[t-1]<=j) t--;
	  R[i][tot]=t;
	}
      R[0][tot]=1;
      if(!j) break;
    }
  int S=1<<tot;
  for(i=0;i<S;i++) g[i]=n+1;
  for(i=0;i<S;i++)
    for(x=f[i],y=g[i],j=1;j<=tot;j++)
      if(NJ) MX(f[SJ],L[x+1][j]),MN(g[SJ],R[y-1][j]);
  int ALL=S-2,MF=-n;
  for(i=0;i<=n+1;i++) FM[i]=-n;
  for(j=1,i=0;i<=ALL;i++) 
    if(NJ) x=(!g[i])?0:((g[i]==n+1)?n+1:g[i]),MX(FM[x],f[ALL-i]);
  for(t=0,i=1;i<=n;i++)
    {
      while(t<=n+1&&L[i][1]+1>=t) MX(MF,FM[t]),t++; 
      puts(R[i][1]<=MF+1?"Possible":"Impossible");
    }
  return 0;
}
  

Measured memory_bytes: 47104
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll N, K;
ll A[100010];
ll g, ma;

ll gcd( ll a, ll b )
{ return b ? gcd(b,a%b) : a; }

int main()
{
  std::cin >> N >> K;

  rep( i, N )
    std::cin >> A[i], g = gcd( g, A[i] ), chmax( ma, A[i] );

  std::cout << (K % g == 0 && K <= ma ? "POSSIBLE" : "IMPOSSIBLE") << std::endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    long long n;
    cin >> n;
    string ans = "";
    while (n > 0) {
        n--;
        ans += char('a' + n % 26);
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, x;
    long ans = 0;
    cin >> a >> b >> c >> x;
    for (int i=0; i<=min(x/500, a); i++)
            for (int j=0; j<=(x-500*i)/100; j++)
                if (j <= b && (x - 500*i - 100*j)/50 <= c)
                    ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    double r;
    cin >> r;
    printf("%.10f\n", 2 * r * M_PI);
    return 0;
}


Measured memory_bytes: 3784