akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
string s;
cin>>n>>s;
ll cnt=0;
ll ans=0;
for(int i=0;i<s.size();i++){
    if(s[i]=='I'){
        cnt++;
    }else{
        cnt--;
    }
    chmax(ans,cnt);
}
cout<<ans<<endl;
}










Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		String tmp = "";
		
		for(int i = 0; i < str.length(); i++) {
			if(str.substring(i, i + 1).equals("0")) {
				tmp += "0";
			} else if(str.substring(i, i + 1).equals("1")) {
				tmp += "1";
			} else if(str.substring(i, i + 1).equals("B")) {
				if(tmp.length() == 0) {
					
				} else {
					tmp = tmp.substring(0, tmp.length() - 1);
				}
			}
		}
		
		System.out.println(tmp);
		
		scan.close();
	}

}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  string S; cin >> S;
  long long cnt = 0;
  for(int i = 0; i < S.size(); ++i) {
    for(int j = i; j < S.size(); ++j) {
      long long num = stoll(S.substr(i, j-i+1));
      long long K = 1;
      (i==0) ? K*=1 : K*=(1<<(i-1));
      long long L=S.size() - j - 1;
      (L==0) ? K*=1 : K*=(1<<(L-1));
      cnt+=num*K;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
import itertools
import sys
sys.setrecursionlimit(10000)

def main():
    n = int(input())

    if n == 0:
        print(0)
        return

    s = ''
    m = n
    while m != 0:
        if m % 2 == 0:
            s += '0'
        else:
            s += '1'
            m -= 1

        m //= -2

    print(s[::-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static int N;
    static int M;
    static Edge[] E;
    static final int INF = 10000;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        E = new Edge[M];
        for (int i = 0; i < M; i++) {
            E[i] = new Edge(sc.nextInt()-1, sc.nextInt()-1, sc.nextInt());
        }
        System.out.println( solve() );
    }

    private static long solve() {
        int[][] dist = new int[N][N];
        for (int[] array : dist) {
            Arrays.fill(array, INF);
        }
        for (Edge edge : E) {
            dist[edge.a][edge.b] = edge.cost;
            dist[edge.b][edge.a] = edge.cost;
        }

        for (int k = 0; k < N; k++) {
            for (int i = 0; i < N; i++) {
                if( dist[i][k] == INF ) continue;
                for (int j = 0; j < N; j++) {
                    if( dist[k][j] == INF ) continue;

                    if( dist[i][k] + dist[k][j] < dist[i][j] ) {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }

        int ans = 0;
        for (Edge edge : E) {
            if( dist[edge.a][edge.b] < edge.cost ) ans++;
        }
        return ans;
    }

    static class Edge {
        private final int a;
        private final int b;
        private final int cost;

        public Edge(int a, int b, int cost) {
            this.a = a;
            this.b = b;
            this.cost = cost;
        }
    }
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    long long n,a,b;
    cin>>n>>a>>b;

    long long ans=0;
    for(int i=1;i<=n;i++){
        int th=10000;
        int sum=0;
        int tmp=i;
        rep(_,5){
        sum+=tmp/th;
        tmp%=th;
        th/=10;
        }
        //cout<<sum<<" ";
        if(sum<=b && sum>=a){
        ans+=i;
        }
    }
    cout<<ans<<endl;

    return 0;

}
/*


*/


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long n;
long long a[1000];
int main()
{
	cin>>n;
	long long i=0,j=0,sum=0,min=0x3f3f3f3f,point ,max=0;
	for(i=1;i<=n;i++)
		cin>>a[i];
		for(i=1;i<=n;i++)
			if(a[i]>max)
			max=a[i];
	for(i=1;i<=max;i++)
	{
		sum=0;
		for(j=1;j<=n;j++)
		{
			sum=sum+(a[j]-i)*(a[j]-i);
		}
		if(sum<=min)
		min=sum;
	}
	cout<<min;	
}

Measured memory_bytes: 256
#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(){
    int n, k;
    cin >> n >> k;
    if((n-1)*(n-2)/2 < k){
        cout << -1 << endl;
        return 0;
    }
    vector<vector<int>> node(n+1, vector<int>(n+1));
    int cnt = (n-1)*(n-2)/2 - k;
    for(int i = 2; i <= n; i++) node[1][i] = 1;
    if(cnt > 0){
        for(int i = 2; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                node[i][j] = 1;
                cnt--;
                if(cnt == 0){
                    i = n+1;
                    break;
                }
            }
        }
    }
    int m = (n-1)*(n-2)/2 - k + n - 1;
    cout << m << endl;
    rep(i,n+1) rep(j,n+1) if(node[i][j] == 1) cout << i << ' ' << j << endl;
}

Measured memory_bytes: 3608
R, G, B, N = [int(a) for a in input().split()]

def func(n, boxes):
    b = boxes[0]

    if len(boxes) == 1:
        return 1 if n % b == 0 else 0
    else:
        return sum([func(n - i, boxes[1:]) for i in range(0, n+1, b)])
    
arr = [R, G, B]
arr.sort()
result = func(N, arr)

print(result)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
	public static void main(String[]args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int m = s.nextInt();
		if(m>= n) {
			System.out.print("Yes");
		}else {
			System.out.print("No");
		}
	}
}

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

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int N, M;
    cin >> N >> M;

    vector<int> X(M);
    rep(i,M) cin >> X[i];

    if (N >= M) { cout << 0 << endl; return 0; }

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

    vector<int> diff(M - 1);
    rep(i,M-1) diff[i] = abs(X[i] - X[i+1]);
    sort(diff.begin(), diff.end(), greater<int>());

    ll ans = 0;
    for (int i = N - 1; i < M - 1; i++) ans += diff[i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include<sstream>
 
using namespace std;
 
int main() {
    int N,A,B,Pass = 0,oversea = 0;
    string str;
    cin >> N >> A >> B >> str;
 
    for (int i = 0; i < N; i++)
    {
        if (str[i] == 'a')
        {
            if (Pass < A + B)
            {
                cout << "Yes" << endl;
 
                Pass++;
            }
            else
            {
                cout << "No" << endl;
            }
        }
            //ここから海外
        else if (str[i] == 'b')
        {
            oversea++;
            if (Pass < A + B && oversea <= B)
            {
                cout << "Yes" << endl;
 
                Pass++;
            }
            else
            {
                cout << "No" << endl;
            }
        }
        else
        {
            cout << "No" << endl;
        }
    }
 
    return 0;
}

Measured memory_bytes: 896
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H = sc.nextInt();
		int[] B = new int[N];
		int Amax = 0, ans = 0;
		for(int i = 0; i < N; i++) {
			int A = sc.nextInt();
			Amax = Math.max(Amax, A);
			B[i] = sc.nextInt();
		}
		Arrays.sort(B);
		for(int i = N-1; i >= 0; i--) {
			if(B[i] < Amax)
				break;
			H -= B[i];
			ans++;
			if(H <= 0) {
				System.out.println(ans);
				return;
			}
		}
		System.out.println(ans + (H + Amax - 1) / Amax);
	}

}


Measured memory_bytes: 65272
#!/usr/bin/python
# -*- coding: utf-8 -*-

import numpy as np

def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(input())
    return x

def int_map():
    return map(int,input().split())

def int_list():
    return list(map(int,input().split()))

A,B,C = int_map()

l = set()

for i in range(0,B+1):
    l.add((A*i)%B)

if C in l:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 27148
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n, l;
int x[114514];
int to[30][114514];
void init() {
	rep(i, n) {
		int index = upper_bound(x, x + n, x[i] + l) - x;
		index--;
		to[0][i] = index;
	}
	rep(i, 30) {
		rep(j, n) {
			to[i + 1][j] = to[i][to[i][j]];
		}
	}
}
int query(int s, int t) {
	int ans = 0;
	for (int i = 29; i >= 0; i--) {
		if (to[i][s] < t) {
			ans += 1 << i;
			s = to[i][s];
		}
	}
	return ans + 1;
}
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> x[i];
	}
	cin >> l;
	init();
	int q; cin >> q;
	while (q--) {
		int s, t; cin >> s >> t;
		s--; t--;
		if (s > t)swap(s, t);
		cout << query(s, t) << endl;
	}
}


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

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    sort(a,a+3);

    int ans = 0;
    while(max(a[0],a[1])<a[2]){
        ans++;
        a[0]++;
        a[1]++;
    }
    while(a[0]<a[2]){
        a[0] += 2;
        ans++;
    }
    while(a[1]<a[2]){
        a[1] += 2;
        ans++;
    }
    if(a[0]!=a[2] || a[1]!=a[2])ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
bool f[214514];
int main(){
	ll n,m;
	cin>>n>>m;
	vector<vector<ll>>v(n+m+1);
	for(int i=1;i<=n;i++){
		ll k;
		cin>>k;
		for(int j=0;j<k;j++){
			ll x;
			cin>>x;
			v[n+x].push_back(i);
			v[i].push_back(n+x);
		}
	}
	queue<ll>que;
	que.push(1);
	f[1]=1;
	ll cnt=1;
	while(!que.empty()){
		ll x=que.front();
		que.pop();
		for(ll p:v[x]){
			if(f[p])continue;
			f[p]=1;
			if(p<=n)cnt++;
			if(cnt==n){
				cout<<"YES\n";
				return 0;
			}
			que.push(p);
		}
	}
	cout<<"NO\n";
	return 0;
}


Measured memory_bytes: 12508
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

public class Main {

	final long MOD = (long) 1e9 + 7;

	void run() {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		long K = sc.nextLong();
		long[] A = new long[N];
		long[] sum = new long[N];
		HashMap<Long, Integer> map = new HashMap<>();
		map.put(0L, 1);
		long ans = 0;
		for (int i = 0; i < N; ++i) {
			if (i - K >= 0)
				map.put(sum[i - (int) K], map.get(sum[i - (int) K]) - 1);
			else if (i == K - 1) {
				map.put(0L, map.get(0L) - 1);
			}
			A[i] = sc.nextLong();
			--A[i];
			sum[i] = ((i > 0 ? sum[i - 1] : 0) + A[i]) % K;
			if (map.containsKey(sum[i])) {
				map.put(sum[i], map.get(sum[i]) + 1);
			} else {
				map.put(sum[i], 1);
			}
			long n = map.get(sum[i]);
			ans = (ans + n - 1);
		}
		System.out.println(ans);

	}

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<int> ar(n+1);
    rep(i,n){
        if (s.at(i) == 'A' || s.at(i) == 'G' || s.at(i) == 'C' || s.at(i) == 'T'){
            ar[i] = 1;
        }
        else{
            ar[i] = 0;
        }
    }
    int len = 0;
    int cnt;
    rep(j,n){
        if (ar[j] == 1){
            cnt = 1;
            while (ar[j + cnt] == 1){
                cnt++;
            }
            len = max(len, cnt);
        }
    }
    cout << len << endl;
}

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

int main(){
  int n;cin >> n;
  vector<int> v0;
  rep(i,n){
    int x; cin >> x;
    v0.push_back(x);
  }
  vector<int> v1(v0.size()); copy(v0.begin(), v0.end(), v1.begin());
  sort(v1.begin(),v1.end());
  int c1=v1[n/2 -1], c2=v1[n/2];
  rep(i,n){
    if(v0[i]<=c1) cout << c2 << endl;
    else cout << c1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3828
#include <stdio.h>

int main(){
	
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	int first[a][b],second[b][c];
	
	int d,e,f,g,h,i,j,k,m; //ループで使う定数一覧
	
	for(d=0;d<=a-1;d++){
		
		for(e=0;e<=b-1;e++){
			
			scanf("%*c%d",&first[d][e]);
			
		}
		
	}
	
	//一つ目の行列の入力完了
	
	for(f=0;f<=b-1;f++){
		
		for(g=0;g<=c-1;g++){
			
			scanf("%*c%d",&second[f][g]);
			
		}
		
	}
	
	//二つ目の行列の入力完了
	
	long long int answer[a][c];
	
	for(h=0;h<=a-1;h++){
		
		for(i=0;i<=c-1;i++){
			
			answer[h][i]=0;
			
			for(j=0;j<=b-1;j++){
				
				answer[h][i]+=first[h][j]*second[j][i];
				
			}
			
		}
		
	}
	
	//行列の積の計算完了
	
	for(k=0;k<=a-1;k++){
		
		for(m=0;m<=c-1;m++){
			
			printf("%lld",answer[k][m]);
			
			if(m!=c-1)
			
				printf(" ");
			
		}
		
		printf("\n");
		
	}
	
	return 0;
	
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  ll l = 1, r = 26;
  ll keta = 1;
  while(1){
    if(l <= n && n <= r){
      string ans;
      ll x = n-l;
      while(keta != 0){
        ll a = x/26;
        ll b = x%26;
        ans += 'a'+b;
        x = a;
        keta--;
      }
      reverse(ALL(ans));
      cout << ans << endl;
      return 0;
    }else{
      l = r+1;
      r = (r+1)*26;
      keta++;
    }
  }
  return 0;
}

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

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (999999999/2)


int main(){
    int m,n;
    cin>>m>>n;
    vector<int> man;
    rep(i,m){
        int a;
        cin>>a;
        man.pb(a);
    }
    vector<pii> box;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        box.pb(pii(a,b));
    }
    int dp[30010];
    rep(i,30010)dp[i]=INF;
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=30000;j>=0;j--){
            if(dp[j-box[i].first]!=INF&&j-box[i].first>=0){
                dp[j]=min(dp[j],dp[j-box[i].first]+box[i].second);
            }
        }
    }
    vector<int> data;
    rep(i,30000)data.pb(dp[i]);
    
    for(int i=30000-1;i>=1;i--){
        //        cout<<data[i]<<endl;
        if(data[i]<data[i-1])data[i-1]=data[i];
    }
    sort(all(man),greater<int>());
    
    for(int i=1;i<man.size();i++){
        man[i]=man[i-1]+man[i];
    }
    
    int ans=0;
    rep(i,m){
        ans=max(ans,man[i]-data[i+1]);
    }
    cout<<ans<<endl;
}

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

int main() {
  int N;
  cin >> N;
  
  int n_of_odd = 0; 
  n_of_odd = (N-1)/2 + 1;
  
  double ans = n_of_odd / (double)N;
  
  cout << std::fixed << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

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

    int n;
    cin >> n;
    vector<string> s(n);

    int ans = 0;
    int a = 0, b = 0, ab = 0;
    rep(i, n) {
        cin >> s[i];
        int t = s[i].length();
        rep(j, t - 1) {
            if (s[i][j] == 'A' && s[i][j+1] == 'B') ans++;
        }

        if (s[i][0] == 'B' && s[i][t-1] == 'A') ab++;
        else{
            if (s[i][0] == 'B') b++;
            if (s[i][t-1] == 'A') a++;
        }
    }

    if (ab > 0) {
        ans += ab - 1;
        if (a > 0) {
            ans++;
            a--;
        }
        if (b > 0) {
            ans++;
            b--;
        }
    }

    ans += min(a, b);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 768
if __name__ == '__main__':
    # ??????????????\???
    students = 30
    yet_to_submit = 2
    # submits = [3, 1, 4, 5, 7, 9, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
    submits = [int(input()) for _ in range(students - yet_to_submit)]
    all_members = set(range(1, students + 1)) #  ??¨???????????? 1???30?????§?????????

    # ???????????????????????????
    yet_to_submits = list(all_members.difference(set(submits)))

    # ???????????????
    yet_to_submits.sort()
    print('{0}\n{1}'.format(yet_to_submits[0], yet_to_submits[1]))

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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int n;
struct d{
	int x,l;
	bool operator < (const d &rhs) const{
		return x-l<rhs.x-rhs.l;
	}
}ds[100010];

struct p{
	int po,ans;
	bool operator < (const p &rhs) const{
		return po>rhs.po;
	}
};

int main() {
	read(n);
	for(int i=0;i<n;i++){
		read(ds[i].x);read(ds[i].l);
	}
	sort(ds,ds+n);
	priority_queue<p> Q;
	int cans = 0;
	for(int i=0;i<n;i++){
		//if(!Q.empty())cout<<Q.top().po<<' '<<Q.top().ans<<endl;
		//cout<<ds[i].x-ds[i].l<<endl;
		while((!Q.empty()) && Q.top().po<=ds[i].x-ds[i].l){
			//cout<<i<<' '<<Q.top().po<<endl;
			cans = max(cans,Q.top().ans);
			Q.pop();
		}
		Q.push((p){ds[i].x+ds[i].l,cans+1});
	}
	while(!Q.empty()){
		cans = max(cans,Q.top().ans);
		Q.pop();
	}
	cout<<cans<<endl;
	return 0;
}


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

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

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

typedef long long LL;

const int N=50,M=262144,C=18;

int n,m,san,sor,a[N+9];

void into(){
  scanf("%d%d%d%d",&n,&m,&san,&sor);
  for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
}

void Get_a(){
  int lst=0;
  for (int i=1;i<=n;++i){
	if (a[i]&san^san) continue;
	if ((a[i]|sor)^sor) continue;
    a[++lst]=a[i];
  }
  n=lst;
}

LL c[N+9][N+9];

void Get_c(){
  c[0][0]=1;
  for (int i=1;i<=n;++i){
	c[i][0]=c[i][i]=1;
	for (int j=1;j<i;++j) c[i][j]=c[i-1][j-1]+c[i-1][j];
  }
}

int mu[M+9];

void Get_mu(){
  mu[0]=1;
  for (int s=1;s<M;++s) mu[s]=s&1?-mu[s>>1]:mu[s>>1];
}

int vis[M+9],cnt[M+9];
LL ans;

void Get_ans(){
  if (!n) return;
  for (int cs=san^sor,s=cs;2333;s=s-1&cs){
	for (int i=1;i<=n;++i) ++cnt[a[i]&s];
	for (int i=1;i<=n;++i){
	  int t=a[i]&s;
	  if (vis[t]) continue;
	  vis[t]=1;
	  for (int j=1;j<=m;++j) ans+=c[cnt[t]][j]*mu[s];
	}
	for (int i=1;i<=n;++i) vis[a[i]&s]=cnt[a[i]&s]=0;
	if (!s) break;
  }
}

void work(){
  Get_a();
  Get_c();
  Get_mu();
  Get_ans();
}

void outo(){
  printf("%lld\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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

int main(){
  int n,k,num=1,j=0;
  cin>>n>>k;

  for(int i=0;i<n;i++)
  {
    if(num<k)
    {
      num*=2;
      j++;
    }
    else break;
  }

  for(int i=0;i<(n-j);i++)
  {
    num+=k;
  }

  cout<<num<<endl;
}

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

int main(void)
{
    int N;
    cin >> N;

    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 0) {
            if (A[i] % 3 != 0 && A[i] % 5 != 0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n, k;
    int *a;

    int i;

    scanf("%d %d", &n, &k);


    a = (int*)malloc(sizeof(int) * n);

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

    for(i = k; i < n; i++){
        if(a[i - k] < a[i])
            printf("Yes\n");
        else
            printf("No\n");
    }

    free(a);

    return 0;
}


Measured memory_bytes: 2248
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
	int x,a,b;
	cin>>x>>a>>b;
	x=x-a;
	a=x/b;
	x=x-(a*b);
	cout<<x<<endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
typedef long long ll;


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int r;
    cin >> r;
    cout << 3 * r * r << endl;

    return 0;
}


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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
  char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
  vector<char*> v({token});
  while(token = strtok(NULL,", ")) v.push_back(token);
  return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
  debug() << " [" << args.back() << ": " << H << "] ";
  args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

vi adj[int(2e5)+1];
int vis[int(2e5)+1],cnt;

void dfs(int i){
    vis[i]=1;
    cnt++;
    for(auto u:adj[i]){
        if(!vis[u]) dfs(u); 
    }
}

int main() {
    IOS;
    int n,m,i,u,v;
    cin>>n>>m;
    REP(i,1,m){
        cin>>u>>v;
        adj[u].EB(v);
        adj[v].EB(u);
    }
    int ans=0;
    REP(i,1,n){
        if(!vis[i]){
            cnt=0;
            dfs(i);
            ans=max(ans,cnt);
        }
    }
    cout<<ans;
    return 0;   
}

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

using namespace std;

#define PI 3.1415926535897932

int main(){
    int mod=1000000007;
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    printf("%s\n",b-a==c-b?"YES":"NO");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

bool CheckText(string x)
{
    if(x.find("this") < x.length())
    {
        return false;
    }
    else if(x.find("the") < x.length())
    {
        return false;
    }
    else if(x.find("that") < x.length())
    {
        return false;
    }
    else
    {
        return true;
    }
}

int main()
{
    string Alphabet = "abcdefghijklmnopqrstuvwxyza";
    string Text;

    while(getline(cin, Text))
    {
                while(CheckText(Text))
        {
            for(unsigned int a = 0; a < Text.length(); a++)
            {
                for(int b = 0; b < 26; b++)
                {
                    if(Text[a] == Alphabet[b])
                    {
                        Text[a] = Alphabet[b+1];
                        break;
                    }
                    else if(Text[a] == ' ')
                    {
                        break;
                    }
                }
            }

        }

        cout << Text << endl;
    }

}

Measured memory_bytes: 3104
import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int A[] = new int[N];
		int B[] = new int[N];
		int C[] = new int[N - 1];
		int sum = 0;
		int x = 51;
		int y = 0;
		for (int i  = 0; i < N; i++) {
			A[i] = scanner.nextInt();
		}

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

		for (int i  = 0; i < N - 1; i++) {
			C[i] = scanner.nextInt();
		}
		/*
		for (int k = 0; k < N; k++) {
			System.out.println(A[k]);
		}
		for (int k = 0; k < N; k++) {
			System.out.println(B[k]);
		}
		for (int k = 0; k < N-1; k++) {
			System.out.println(C[k]);
		}*/
		
		for (int j = 0; j < N; j++) {
			y = A[j];
			sum += B[y - 1];
			if (y - 1 == x) {
				sum += C[x - 1];
			}
			x = A[j];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21972
n = int(input())
a = []
b = []
for j in range(n):
    l = list(map(int, input().split()))
    a.append(l[0])
    b.append(l[1])
c = 0
for i in range(n-1, -1, -1):
    if (a[i]+c) % b[i] != 0:
        c += (b[i] - (a[i]+c) % b[i])
print(c)

Measured memory_bytes: 16968
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = Integer.parseInt(sc.next());
		String S = sc.next();
		sc.close();

		if(S.length() <= K) {
			System.out.println(S);
		}else {
			System.out.println(S.substring(0, K) + "...");
		}
	}

}

Measured memory_bytes: 38552
H, W, M = map(int,input().split())
h_count = [0] * (H+1)
w_count = [0] * (W+1)
memo = set()

for _ in range(M):
    h, w = map(int,input().split())
    memo.add((h,w))
    h_count[h] += 1
    w_count[w] += 1

h_memo = []
temp = 0
h_max = max(h_count)
for idx, i in enumerate(h_count):
    if i == h_max:
        h_memo.append(idx)

w_memo = []
temp = 0
w_max = max(w_count)
for idx, i in enumerate(w_count):
    if i == w_max:
        w_memo.append(idx)

for i in h_memo:
    for j in w_memo:
        if (i,j) not in memo:
            print(h_max + w_max)
            quit()
print(h_max + w_max - 1)

Measured memory_bytes: 166768
#include <iostream>
using namespace std;
string a, b;
int main(void){
    // Your code here!
    cin >> a >> b;
    int t = stoi(a + b);
    for (int i = 1; i < 1000; i++) {
        if (i * i == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N;
    cin>>N;
    //愚直に探す
    //N<10000よりx<=y<=zとするとxは最高でも100

    int ans=0;

    for(int i=1;i<=N;i++){
        ans=0;
        for(int x=1;x<=100;x++){
            for(int y=x;y<=100;y++){
                
                for(int z=y;z<=100;z++){
                    if(x*x+y*y+z*z+x*y+y*z+z*x==i){
                        if(x==y&&y==z){
                            ans++;
                        }else if(x!=y&&y==z){
                            ans+=3;
                        }else if(x==y&&y!=z){
                            ans+=3;
                        }else{
                            ans+=6;
                        }
                    }else if(x*x+y*y+z*z+x*y+y*z+z*x>i){
                        break;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    REP(i, N) {
        cin >> v[i];
    }
    sort(ALL(v), greater<int>());
    int alice = 0;
    int bob = 0;
    REP(i, N) {
        if(i%2 == 0) {
            alice += v[i];
        }else{
            bob += v[i];
        }
    }
    cout << alice - bob << endl;
    return 0;
}


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

int n;
set<vector<char> > st;
string str;
vector<char> res;
bool f[30];

void print(vector<char> vc){
  for(int i=0;i<vc.size();i++) cout << vc[i];
  cout << endl;
}

void func(int pos){
  if(pos >= n){
    st.insert(res);
    
  } else {
    if(str[pos] + 1 <= 'z' && !f[str[pos]-'a']){
      res.push_back(str[pos] + 1);
      f[str[pos]-'a'] = true;
      func(pos+1);
      f[str[pos]-'a'] = false;
      res.pop_back();
    } 

    if(str[pos] == 'a' || f[str[pos]-1-'a']){
      res.push_back(str[pos]);
      func(pos+1);
      res.pop_back();
    }
  }
}

void solve(){
  n = str.size();
  st.clear();
  
  res.clear();
  fill(f,f+30,false);
  func(0);
  /*
  for(int i=0;i<(1<<n);i++){
    string strf = "";
    for(int j=0;j<n;j++){
      if((i & (1 << j)) && str[j] + 1 <= 'z') strf += str[j] + 1;
      else if(!(i & (1 << j))) strf += str[j];
      else break;
    }
    if(strf.size() != n) continue;

    string strf2 = strf;
    bool f[30];
    fill(f,f+30,false);
    for(int j=0;j<n;j++){
      if(strf2[j] != 'a' && !f[strf2[j]-1-'a']){
        f[strf2[j]-1-'a'] = true;
        strf2[j]--;
      }
    }
    if(strf2 == str) st.insert(strf);
  }
  */
  
  cout << st.size() << endl;
  if(st.size() <= 10){
    for(set<vector<char> >::iterator it = st.begin(); it != st.end(); it++){
      print(*it);
    }
  } else {
    set<vector<char> >::iterator it = st.begin();
    for(int i=0;i<5;i++,it++) print(*it);
    it = st.end();
    for(int i=0;i<5;i++) it--;
    for(int i=0;i<5;i++,it++) print(*it);
  }
}

int main(){
  while(cin >> str && str != "#") solve();
}

Measured memory_bytes: 2864
#include<bits/stdc++.h>
using namespace std;
long long n,sum[100001],dp[100001][3];
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&sum[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				if(sum[i]>=j+k)
				dp[i][j]=max(dp[i][j],dp[i-1][k]+j+(sum[i]-j-k)/2);
			}
		}
	}
	printf("%lld\n",dp[n][0]);
	return 0;
}

Measured memory_bytes: 3328
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,k,i,j,ans=0;
	cin>>n>>k;
	string s;
	cin>>s;
	vi one,z;
	z.pb(0);
	one.pb(0);
	z.pb(0);
	one.pb(0);
	ll cnt=0;i=0;
	while(i<n){
		cnt=0;
		char c=s[i];
		if(s[i]=='0'){
			while(s[i]=='0'&&i<n)cnt++,i++;
		}else{
			while(s[i]=='1'&&i<n)cnt++,i++;
		}
		if(c=='0')z.pb(cnt);else one.pb(cnt);
	}
	for(i=1;i<one.size();i++){
		ans=max(ans,one[i]);
		one[i]+=one[i-1];
	}
	for(i=1;i<z.size();i++)
		z[i]+=z[i-1];
	if(z.size()-2<=k){
		cout<<n;return 0;
	}
	if(s[0]=='0'){
	for(i=k+1;i<z.size();i++){
		if(i<one.size())
		ans=max(ans,z[i]-z[i-k]+one[i]-one[i-k-1]);
		else ans=max(ans,z[i]-z[i-k]+one.back()-one[((i-k-1)>=0?(i-k-1):0)]);
	}
	}else{
		for(i=k+1;i<z.size();i++){
			if(i+1<one.size())
			ans=max(ans,z[i]-z[i-k]+one[i+1]-one[i-k]);
			else ans=max(ans,z[i]-z[i-k]+one.back()-one[i-k]);
		}
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n,m;cin>>n>>m;
  bool line[n][n];CLR(line,false);
  rep(i,0,m){
    ll a,b;cin>>a>>b;
    a--,b--;
    line[a][b]=line[b][a]=true;
  }

  ll dp[(1<<n)][n];
  CLR(dp,0);
  ll count=0;
  dp[1][0]=1;
  rep(i,0,(1<<n)){
    rep(j,0,n){
      if(dp[i][j]==0)continue;
      rep(k,0,n){
        if((i>>k)%2==1)continue;
        if(!line[j][k])continue;
        // out(bitset<8>(i)<<":"<<j<<":"<<k);
        count++;
        dp[i|(1<<k)][k]+=dp[i][j];
      }
    }
  }

  ll all=(1<<n)-1;
  ll ans=0;
  rep(i,1,n){
    if(dp[all][i]==-INF)continue;
    ans+=dp[all][i];
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF 1000000007

int main() {

  string s; cin >> s;

  int g = 0, p = 0;
  REP(i, s.size()) {
    if (s[i] == 'g') g++;
    else p++;
  }

  cout << (g-p)/2 << endl;

  return 0;

}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
	long long int a;
	long long int sum=0;
	scanf("%lld", &a);
	for(int i=1;i<=a;i++){
		if(i%3!=0&&i%5!=0){
			sum+=i;
		}
	}
	printf("%lld", sum);
	
	
	return 0;
}

Measured memory_bytes: 1700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int k, s;
  cin >> k >> s;
  int z;
  int count =0;

  for (int i = 0; i <= k; i++){
    for (int j = 0; j <= k; j++){
      z = s - (i + j);
      if ((z >= 0) && (k >= z)){
        count += 1;
      }
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n;
long long a,b,d;
long long gcd(long long a,long long b){
	if (b==0) return a;
	return gcd(b,a%b);
}
int main(){
	scanf("%d",&n);
	fo(x,1,3500)
		fo(y,1,3500){
			a=4*x*y-n*x-n*y;
			if (a<=0) continue;
			b=n*(long long)x*(long long)y;
			d=gcd(a,b);
			a/=d;
			b/=d;
			if (a==1){
				printf("%d %d %d\n",x,y,b);
				return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N, M, X = list(map(int, input().split()))

    book_cost  = []
    book_skill = []
    for i in range(N):
        l = list(map(int, input().split()))
        book_cost.append(l[0])
        book_skill.append(l[1:])

    ans = -1

    for i in range(2**N):
        skill = [0] * M
        cost = 0
        for j in range(N):
            if ((i>>j) & 1):
                cost += book_cost[j]
                for k in range(M):
                    skill[k] += book_skill[j][k]
        if all(s>=X for s in skill):
            if ans<0:
                ans = cost
            else:
                ans = min(ans, cost)
        #print(cost, skill)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9232
n,y=map(int,input().split())
f=True
for i in range(n+1):
     for j in range(n-i+1):
          k=n-i-j
          if k<0:
               continue
          y_=10000*i+5000*j+1000*k
          if y==y_:
               f=False
               print(i,j,k)
               break
     else:
          continue
     break
if f:
     print('-1 -1 -1')

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 main():
    N = I()
    A = LI()
    cumsum = [0]
    for i in range(N):
        cumsum.append(cumsum[i] + A[i])
    ans = 0
    for i in range(N):
        ans += (A[i] * ((cumsum[N] - cumsum[i+1]) % mod)) % mod
        ans %= mod
    print(ans)

main()



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

int main()
{
	constexpr int SIZE = 3;
	array<int, SIZE> point = { 1, 0, -1 };
	array<int, SIZE> card = {};
	int k = 0;

	for (int i = 0; i < SIZE; i++) cin >> card[i];
	cin >> k;

	int total = 0;
	for (int i = 0; i < SIZE; i++) {
		int num = card[i] < k ? card[i] : k;
		total += point[i] * num;
		k -= num;
		if (k <= 0) {
			break;
		}
	}

	cout << total << endl;

	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

struct event {
    ll t;
    ll type;
    ll idx;
};

void solve() {
    ll N, Q;
    cin >> N >> Q;
    vector<event> events;
    rep(i, N) {
        ll s, t, x;
        cin >> s >> t >> x;
        events.push_back({s - x, 0, x});
        events.push_back({t - x, 1, x});
    }
    rep(i, Q) {
        ll d;
        cin >> d;
        events.push_back({d, 2, i});
    }
    sort(events.begin(), events.end(), [](event a, event b) {
        if (a.t == b.t) {
            return a.type < b.type;
        }
        return a.t < b.t;
    });
    multiset<ll> block;
    vector<ll> ans(Q, -1);
    for (auto e : events) {
        if (e.type == 0) {
            block.insert(e.idx);
        } else if (e.type == 1) {
            block.erase(block.lower_bound(e.idx));
        } else {
            ans[e.idx] = block.empty() ? -1 : *block.begin();
        }
    }
    rep(i, Q) {
        cout << ans[i] << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 27236
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
#include<math.h>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

ll n;

bool is_ok(ll k){
	ll tmp = n;
	while(tmp % k == 0)tmp /= k;
	return tmp % k == 1;
}

int main(){
  cin >> n;
  ll cnt = 0;
  for(ll k = 1; k * k <= n; ++k){
    if(n % k)continue;
    if(k != 1)cnt += is_ok(k); 
    if(k * k != n)cnt += is_ok(ll(n / k)); 
  }

  --n;
  for(ll k = 1; k * k <= n; ++k){
    if(n % k)continue;
    if(k != 1)++cnt; 
    if(k * k != n)++cnt;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 384