akhauriyash/Code-Regression huggingface dataset:
/*
      author : Nishikawa
      created: 10.08.2020 13:28:48
*/

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


int main(){
    ll x;
    cin >> x;
    for(int a=1; a<=500; a++){
        ll sa = 1;
        rep(i,5) sa *= a;
        for(int b=-500; b<=500; b++){
            ll sb = 1;
            rep(i,5) sb*=b;
            if(sa - sb == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<LP, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

vector<int> dp(10001, 0);

int main(){
	int n, ww;
	cin >> n >> ww;
	vector<int> v(n);
	vector<int> w(n);
	REP(i, n)
		cin >> v[i] >> w[i];
	REP(i, n)
		FOR(j, w[i], ww + 1)
			dp[j] = max(dp[j],dp[j - w[i]] + v[i]);
	cout << *max_element(dp.begin(), dp.begin() + ww + 1) << endl;
	return 0;
}


Measured memory_bytes: 3128
n = int(input()) 
d = []
for i in range(n):
    d.append(int(input()))
    
d=list(set(d))
d.sort()
before=0
ans=0
for i in d:
    if i > before:
        ans += 1
    else:
        break
    before = i
    
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int dp[100000];

int main()
{
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = 0;
    ans += (n / (a+b)) * a;
    if(n % (a+b) == 0){
        cout << ans << endl;
    }else{
        ll tmp = n % (a+b);
        if(tmp < a){
            ans += tmp;
        }else{
            ans += a;
        }
        cout << ans;
    }
}

Measured memory_bytes: 256
n=int(input())
txy=[]
for _ in range(n):
    t,x,y=map(int, input().split())
    txy.append((t,x,y))

def isOk(txy):
    now_pos=0
    now_t=0

    for t,x,y in txy:
        move=x+y-now_pos
        time=t-now_t
        if time>=move and time%2==move%2:
            continue
        else:
            return False
    return True

print("Yes") if isOk(txy) else print("No")

Measured memory_bytes: 17312
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
num = 2
idx = 1
while num<n:
    if num+1==n:
        ans += a[idx]
        num += 1
    else:
        ans += a[idx]*2
        num += 2
        idx += 1
print(ans)

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < h.length; i++) {
            h[i] = sc.nextInt();
        }
        Arrays.sort(h);
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n - k + 1; i++) {
            int tmp = h[i + k - 1] - h[i];
            min = Math.min(min, tmp);
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 58900
import java.util.*;

public class Main{
    Scanner in = new Scanner(System.in);

    void move(int h, int w){
        int x = 0, y = 0;
        char[][] tile = new char[h][w];
        boolean[][] visited = new boolean[h][w];
        for(int i = 0; i < h; i++){
            tile[i] = in.nextLine().toCharArray();
        }
        while(tile[y][x] != '.' && !visited[y][x]){
            visited[y][x] = true;
            switch(tile[y][x]){
                case '>': x++; break;
                case '<': x--; break;
                case '^': y--; break;
                case 'v': y++; break;
            }
        }
        if(visited[y][x]){
            System.out.println("LOOP");
        }else{
            System.out.println(x + " " + y);
        }
    }

    void solve(){
        int h = in.nextInt(), w = in.nextInt(); in.nextLine();
        while(h + w > 0){
            move(h, w);
            h = in.nextInt(); w = in.nextInt(); in.nextLine();
        }
    }
    
    public static void main(String[] args){
        new Main().solve();    
    }

    int getInt(){
        return Integer.parseInt(in.nextLine());
    }
}

Measured memory_bytes: 28688
n, k = map(int, input().split())
A = [0] + list(map(int, input().split()))

pos = [1]

for i in range(2 * n):
	nxt = A[pos[-1]]
	pos.append(nxt)

if k < n + 1:
	print(pos[k])
	exit()

loop_end = n
loop_start = n - 1

while pos[loop_start] != pos[loop_end]:
	loop_start -= 1

period = loop_end - loop_start
k = k % period

while k < n:
	k += period

print(pos[k])

Measured memory_bytes: 114076
N, W = map(int, input().split())

dp = [[0]*(W+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
    v, w = map(int, input().split())
    for sum_w in range(W+1):
        if w <= sum_w:
            dp[i + 1][sum_w] = max(dp[i][sum_w], dp[i][sum_w - w] + v)
        else:
            dp[i + 1][sum_w] = dp[i][sum_w]

print(dp[N][W])


Measured memory_bytes: 25488
# abc166 C
n, m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

ab = m.times.map {
  gets.split.map(&:to_i)
}

ten = Array.new(n+1) { {rin: []} }

####

ab.each do |(a,b)|
  ten[a][:rin] << b
  ten[b][:rin] << a
end

cnt = 0

ten[1..-1].each_with_index do |t, ind|
  hh = h[ind]
  cnt += 1 if t[:rin].all? { |tr|
    h[tr-1] < hh
  }
end

p cnt




Measured memory_bytes: 48196
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,l;
	string a[110];
    cin>>n>>l;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    cout<<a[i];
    return 0;
}

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

using namespace std;

int main()
{
	int S, K;
	int x, y, z;
	int count = 0;
	cin >> K >> S;
	for (int i = 0; i <= K; i++) {
		x = i;
		for (int j = 0; j <= K; j++) {
			y = j;
			z = S - x - y;
			if (z >= 0 && z <= K) count++;
		}
	}
	cout << count << endl;
}

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

int main() {
  // 一年の秒数
  int a;
  int b;
  cin >> a;
  cin >> b;
  // 以下のコメント/* */を消して追記する
  if (a%500 <= b){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n, k = map(int, input().split())
d = [11, 16, 10, 25, 9, 24, 19, 13, 18, 12, 17]
e = 7 * (n - 1)
r = (e - d[k] - 1) // 77
print(5 * r + len([x for x in range(d[k] + 77 * r, e, 11) if x % 7 > 1]))

Measured memory_bytes: 3060
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

int _C(in string s, in string t) {
    int L = cast(int)(min(s.length, t.length));
    for (; L >= 0; L--) {
        if (s[$ - L .. $] == t[0 .. L]) return L;
    }
    assert(0);
}
alias memoize!_C C;

void main() {
    int N;
    string[] F;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        F = new string[N];
        foreach (i; 0 .. N) {
            F[i] = readln.chomp;
        }
        return true;
    }
    void removeDup() {
        auto R = new bool[N];
        foreach (i; 0 .. N) {
            foreach (j; 0 .. N) {
                if (i == j) continue;
                if (F[i].countUntil(F[j]) >= 0) R[j] = true;
            }
        }
        string[] nF;
        foreach (i; 0 .. N) {
            if (!R[i]) nF ~= F[i];
        }
        F = nF;
        N = cast(int)F.length;
    }
    const INF = int.max / 4;
    void solve() {
        removeDup;
        auto memo = new int[][](N, 1 << N);
        foreach (i; 0 .. N) memo[i][] = -1;
        int dfs(int v, int bit) {
            if (bit == (1 << N) - 1) return 0;
            if (memo[v][bit] >= 0) return memo[v][bit];
            int Ret = INF;
            foreach (int i; 0 .. N) {
                if (bit & (1 << i)) continue;
                Ret = min(Ret, dfs(i, bit | 1 << i) + F[i].length - C(F[v], F[i]));
            }
            return memo[v][bit] = Ret;
        }
        int Ans = INF;
        foreach (i; 0 .. N) {
            Ans = min(Ans, dfs(i, 1 << i) + cast(int)F[i].length);
        }
        writeln(Ans);
    }
    while (input) solve;
}

Measured memory_bytes: 4700
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

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

  // 隣接行列
  // int G[15][15];
  vector<vector<int>> G(N, vector<int>(N,0));
  REP(i,0,M) {
    int a,b;
    cin >> a >> b;
    --a; --b;
    G[a][b] = 1; G[b][a] = 1;
  }

  // 1~N-1の順列
  // vector<int> perm(N);
  int perm[15];
  REP(i,0,N) perm[i] = i;

  int ans = 0; // 1からのpathの数
  do {
    // perm[0:N] が繋がっているか？
    bool is_connected = true;
    REP(i,0,N-1) {
      if (G[perm[i]][perm[i+1]] == 0) {
        is_connected = false;
        break;
      }
    }
    if (is_connected) ++ans;
  } while (next_permutation(perm+1, perm+N)); // 先頭は0に固定

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    s = input()
    q = int(input())
    k = list(map(int, input().split()))
    for ki in k:
        ans = 0
        DMC = [0]*3
        for i in range(n):
            if s[i] == "D":
                DMC[0] += 1
            elif s[i] == "M":
                DMC[1] += 1
                DMC[2] += DMC[0]
            if i >= ki:
                j = i-ki
                if s[j] == "D":
                    DMC[0] -= 1
                    DMC[2] -= DMC[1]
                elif s[j] == "M":
                    DMC[1] -= 1
            if s[i] == "C":
                ans += DMC[2]
        print(ans)

if __name__ == "__main__":
    main()

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

using namespace std;

int main(){
    long long N, M, V, P;
    while(cin >> N >> M >> V >> P){
        vector<long long> A(N);
        for(auto& t : A) cin >> t;
        sort(A.begin(), A.end());
        int L = -1, R = N;
        while(R - L > 1){
            int mid = (L+R)/2;            
            if(N - mid <= P){
                R = mid;
                continue;
            }
            long long vote = M*V;
            bool ok = true;
            for(int i=N-1;i>=0;i--){
                if(i >= N-(P-1) || i == mid){
                    vote -= M;
                } else {
                    auto upper = A[mid] + M;
                    if(upper < A[i]) ok = false;
                    vote -= min(upper - A[i], M);
                }
            }
            if(ok && vote <= 0) R = mid;
            else L = mid;
        }
        cout << N-R << endl;
    }
}

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

int main(void) {
	int start, end;
	bool first = true;

	while(cin >> start >> end, start | end) {
		bool flag = false;
		if(!first)
			cout << endl;
		else
			first = false;
		for(int i = start; i < end + 1; i++) {
			if(i % 4 == 0 && (i % 100 != 0 || i % 400 == 0)) {
				cout << i << endl;
				flag = true;
			}
		}
		
		if(!flag)
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
using P = pair<int,int>;
#include <vector>
#include <algorithm>
using ll = long long;
#define rep(i,n) for (int i = 0; i<(n); i++)

int main(){
    int n;
    cin>>n;
    int list[n];
    rep(i,n){
        int p;
        cin >> p;
        list[i]=p;
    }
    bool what = false;
    int num = 0;
    int ans = 0;
    while(true){
        num = 0;
        for (int i = 0; i < n; i++) {
            if(list[i]%2==0){
                num ++;
            }
        }
        if(num==n){
            ans++;
            for (int i = 0; i < n; i++) {
                list[i]=list[i]/2;
            }
        }else{
            cout<<ans;

            break;
        }
    }



    return 0;
}


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

int main() {
  int N,A,s,r=999;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A;
    s=0;
    while(A%2==0){
      s++;
      A/=2;
    }
    if(s<r)r=s;
  }
  cout<<r<<endl;
}

Measured memory_bytes: 3608
#include <stdio.h>

//---------------------------------------
void zero(int array[]);                 //?????????????????????????????????
//---------------------------------------

int main(void)
{
	int r, c; 
	int num;       
	int r_sum = 0;          //?????????????¨?
	int c_sum[101]; 	//?????????????¨?
	
	zero(c_sum);
	
	scanf("%d %d", &r, &c);
	
	for(int i = 0; i < r; i++){
		r_sum = 0;
		for(int j = 0; j < c; j++){
			scanf("%d", &num);
			r_sum += num;
			c_sum[j] += num;
			printf("%d ", num);
		}
		printf("%d\n", r_sum);
		c_sum[c] += r_sum;
	}
    for(int j = 0; j < c; j++){
		printf("%d ", c_sum[j]);
	}
	printf("%d\n", c_sum[c]);
	
	return 0;
}
//---------------------------------------//?????????????????????????????????
void zero(int array[])
{
	for(int i = 0; i < 101; i++){
		array[i] = 0;
	}
}

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

int main()
{
	
	string odd, even, pass;
	int n, s=0, t=0;

	cin >> odd;
	cin >> even;

	n = odd.size() + even.size();

	
	for (int i = 1; i < n + 1; i++) {
		if (i % 2 != 0) {
			pass += odd[s];
			s++;
		}
		else {
			pass += even[t];
			t++;
		}
	}
	cout << pass;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vi s(n);
	int sum = 0;
	rep(i, 0, n) {
		cin >> s[i];
		sum += s[i];
	}
	if (sum % 10 == 0) {
		sort(all(s));
		rep(i, 0, n) {
			if ((sum - s[i]) % 10 != 0) {
				sum -= s[i];
				break;
			}
		}
	}
	if (sum % 10 == 0) {
		sum = 0;
	}
	cout << sum << endl;
	return 0;
}

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

int main (){
  int N,A,B,sum,cop;
  cin >> N >> A >> B;
  for (int i = 0;i < N;i++){
    cop = i + 1;
    int num = 0;
    for (int l =0;l < 5;l++){
      num += cop % 10;
      cop /= 10;
    }
    if (A <= num && num <= B)sum += i + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        XorSum2 solver = new XorSum2();
        solver.solve(1, in, out);
        out.close();
    }

    static class XorSum2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
            }

            long result = 0;
            long sum = 0;
            int right = 0;
            for (int left = 0; left < n; left++) {

                while (right < n && ((sum + a[right]) == (sum ^ a[right]))) {
                    sum = sum + a[right];
                    right++;
                }

                result += right - left;
                if (left == right) {
                    right++;
                } else {
                    sum -= a[left];
                }
            }

            out.print(result);
        }

    }
}



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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i=0; i<N; i++) {
        cin >> d[i];
    }
    
    set<int> st;
    for (int i=0; i<N; i++) {
        st.insert(d[i]);
    }
    
    cout << st.size() << endl;
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0'){
		t=(t<<3)+(t<<1)+v-48;
		v=getchar();
	}
	return t;
}
using namespace std;
int n,a[200002],b,k;
signed main(){
	k=read();n=read();
	for(re int i=1;i<=n;++i)a[i]=read(),b=max(b,a[i]-a[i-1]);
	b=max(b,k-a[n]+a[1]);
	printf("%d",k-b);
}

Measured memory_bytes: 1024
from collections import Counter

n = int(input())
c = Counter(input())
for _ in range(n-1):
    nc = Counter(input())
    for k, v in c.items():
        c[k] = min(v, nc[k])
s = ''
for k, v in c.items():
    s += k*v
print(''.join(sorted(list(s))))


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <cctype>

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

using namespace std;

typedef long long ll;

const int inf = 2000000;

string s;
int k;
int l[100];

int lexpr(int& i);
void expr(int& i, int k, char& c);

int lfactor(int& i){
    int p = 0;
    while(isdigit(s[i])){
        p = p * 10 + s[i++] - '0';
    }
    if(s[i] != '('){
        ++i;
        return p;
    }
    ++i;
    ll m = lexpr(i);
    ++i;
    return (int)min(m * p, (ll)inf);
}

int lterm(int& i){
    if(isdigit(s[i])){
        return lfactor(i);
    }
    i++;
    return 1;
}

int lexpr(int& i){
    int p = i;
    int m = 0;
    while(s[i] && s[i] != ')'){
        m += lterm(i);
        if(m > inf){
            m = inf;
            break;
        }
    }
    return l[p] = m;
}

int factor(int& i, int k, char& c){
    int p = 0;
    while(isdigit(s[i])){
        p = p * 10 + s[i++] - '0';
    }
    if(s[i] != '('){
        if(k < p){
            c = s[i];
        }
        ++i;
        return p;
    }
    ++i;
    ll m = l[i];
    if(k < m * p){
        expr(i, k % m, c);
        ++i;
        return k + 1;
    }
    expr(i, m + 1, c);
    ++i;
    return m * p;
}

int term(int& i, int k, char& c){
    if(isdigit(s[i])){
        return factor(i, k, c);
    }
    if(k == 0){
        c = s[i];
    }
    ++i;
    return 1;
}

void expr(int& i, int k, char& c){
    while(s[i] && s[i] != ')'){
        int m = term(i, k, c);
        if(k < m){
            break;
        }
        k -= m;
    }
}

int main(){
    while(1){
        cin >> s >> k;
        if(s == "0" && k == 0){
            break;
        }
        int i = 0;
        lexpr(i);
        i = 0;
        char c = '0';
        expr(i, k, c);
        cout << c << endl;
    }
    return 0;
}


Measured memory_bytes: 3064
let a = stdin.ReadLine() |> int
let b = stdin.ReadLine() |> int

match a, b with
| 1,2 -> 3
| 1,3 -> 2
| 2,1 -> 3
| 2,3 -> 1
| 3,1 -> 2
| 3,2 -> 1
| _, _ -> 0
|> printfn "%d"

Measured memory_bytes: 13916
sl = list(input())
tl = list(input())

n = len(sl)
from collections import defaultdict
dic = defaultdict(list) 

for idx, s in enumerate(sl):
   dic[s].append(idx)
   dic[s].append(idx+n)

for s in dic:
   dic[s] = sorted(dic[s])

import bisect

ans = 0
now = -1
for t in tl:
   if dic[t] == []:
      print(-1)
      import sys
      sys.exit()
   idx = bisect.bisect_left(dic[t], now+1)
   ans += dic[t][idx] - now
   now = dic[t][idx]
   if now >= n:
      now -= n
print(ans)

Measured memory_bytes: 14844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  vll h(n);
  for (ll i = 0; i < n; i++) cin >> h[i];

  vll dp(n, 0);
  for (ll i = 1; i < n; i++) {
    dp[i] = min(dp[max(0ll, i - 1)] + abs(h[max(0ll, i - 1)] - h[i]), dp[max(0ll, i - 2)] + abs(h[max(0ll, i - 2)] - h[i]));
  }
  cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
N = input()
N = int(N)
if N == 1:
    print(0)
else:    
    ans = 0
    lis = factorization(N)
    for l in lis:
        cnt = 1
        a = l[1]
        while a > 0:
            a = a - cnt
            if a >= 0:
                cnt = cnt + 1
            else:
                break
        ans = ans + cnt - 1
    print(ans)

Measured memory_bytes: 9504
#include <bits/stdc++.h>
using namespace std;
#define maxn 300005
#define ll long long

int n,m,flag;
struct node{
	int x,y,z;
}a[maxn];

bool cmp(node x,node y){
	return x.z<y.z;
}

int main()
{
    cin>>n>>m;
	for(int i=1;i<=n;i++){
		a[i].x=m+i-1;
		a[i].z=abs(a[i].x);
		a[i].y=i;
	}
	sort(a+1,a+n+1,cmp);
	int sum=0;
	for(int i=2;i<=n;i++)
		sum+=a[i].x;
	cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vi dp(n + 1, 1e9);
  dp[0] = 0;
  rep2(i, 1, n + 1) {
    dp[i] = min(dp[i], dp[i - 1] + 1);
    vi v = {6, 9};
    rep(k, 2) {
      int f = v[k];
      while(i >= f) {
        int pi = i - f;
        dp[i] = min(dp[i], dp[pi] + 1);
        f *= v[k];
      }
    }
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main() {
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];

    sort(all(A));
    int index = 0; ll S = A[0];
    for(int i=1; i<n; i++){
        if(S*2 < A[i]) index = i;
        S += A[i];
    }   
    cout << n - index << ln;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
	int K, A, B;
	cin >> K >> A >> B;

	for (int x = A; x <= B; ++x) {
		if (x % K == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;


int win_turn(int n, const vector<int> &rows, const vector<int> &cols,
             const vector<int> &ps, int w){
  if(n == 1 && w > 1) return ps.size();
  
  vector<int> rc(n, 0);
  vector<int> cc(n, 0);
  int d1 = 0, d2 = 0;
  
  REP(i, ps.size()){
    int r = rows[ps[i]];
    int c = cols[ps[i]];
    if(r >= 0 && c >= 0){
      if(++rc[r] == n) w--;
      if(++cc[c] == n) w--;
      if(r == c && ++d1 == n) w--;
      if(r + c + 1 == n && ++d2 == n) w--;
    }
    if(w <= 0){
      // cout << i << endl;
      return i;
    }
  }
  
  return ps.size();
}

int main(){
  int n, m, u, v, p;
  cin >> n >> u >> v >> m;
  const int PMAX = 1000 * 1000;
  vector<int> ur(PMAX, -1), uc(PMAX, -1);
  vector<int> nr(PMAX, -1), nc(PMAX, -1);
  vector<int> ps(m);
  
  REP(i, n)REP(j, n){
    cin >> p; --p;
    ur[p] = i;
    uc[p] = j;
  }
  REP(i, n)REP(j, n){
    cin >> p; --p;
    nr[p] = i;
    nc[p] = j;
  }
  REP(i, m) {
    cin >> ps[i]; ps[i]--;
  }
  
  int uw = win_turn(n, ur, uc, ps, u);
  int nw = win_turn(n, nr, nc, ps, v);
  if(uw < nw){
    cout << "USAGI" << endl;
  }else if(uw > nw){
    cout << "NEKO" << endl;
  }else{
    cout << "DRAW" << endl;
  }
  return 0;
}

Measured memory_bytes: 16944
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

int main() {
	int n;
	int n2;
	scanf("%d", &n);
	n2 = n;
	int keta = log10(n) + 1;
	int a = 0;
	for (int i = 0; i < keta; i++) {
		int tmp = n / pow(10, keta - 1 - i);
		a += tmp;
		n -= tmp * pow(10, keta - 1 - i);
	}
	if (n2 % a) {
		printf("No");
	}
	else {
		printf("Yes");
	}
}

Measured memory_bytes: 512
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        // Your code here!
        int N = int.Parse(Console.ReadLine());
        long num = 1;
        for(int i = 1; i <= N; i++)
        {
            num = (num * i) % 1000000007;
            
        }
        Console.WriteLine(num);
    }
}

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

using namespace std;
int s;

int str[1000002];
int f(int a){
  if(a%2==0){
    return a/2;
  }
  else{
    return (a*3)+1;
  }
}

int main(){
  cin >> s;
  str[0]=s;
  int i=0;
  while(1){
    i++;
    str[i]=f(str[i-1]);
    for(int j=0;j!=i;j++){
      if(str[i]==str[j]){
        cout << i+1 << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    ss = str(input().rstrip('\n'))
    nn = int(input().rstrip('\n'))
    s = 0
    sb = True
    e = 0
    eb = True
    t = 0
    cnt = 0
    if len(ss) == 1:
        print(len(ss) * nn // 2)
        exit()
    else:
        if ss[0] == ss[-1]:
            for i in range(len(ss)):
                if ss[i] == ss[0]:
                    if sb:
                        s += 1
                else:
                    sb = False
                if ss[-i-1] == ss[0]:
                    if eb:
                        e += 1
                else:
                    eb = False
        else:
            sb = False
            eb = False
        if sb and eb:
            if s % 2 == 0:
                cnt += ((s + e) // 2 // 2)
                s = 0
                e = 0
            else:
                print(s * nn // 2)
                exit()
        else:
            for i in range(max(s, 1), min(len(ss) - e + 1, len(ss))):
                if ss[i] == ss[i-1]:
                    t += 1
                else:
                    t += 1
                    cnt += (t // 2)
                    t = 0

            cnt += ((t + 1) // 2)
    print(cnt * nn + s // 2 + e // 2 + (s + e) // 2 * (nn - 1))


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    const U_INF: usize = 1 << 60;
    const I_INF: isize = 1 << 60;

    let n: usize = read!();
    let k: usize = read!();

    let mut a = vec![];
    for _ in 0..n {
        let ai: usize = read!();
        a.push(ai);
    }

    let mut dp = vec![false; k * 3];

    for i in 0..=k {
        let now = dp[i];
        for &ai in &a {
            dp[i + ai] = dp[i + ai] || !now;
        }
    }

    let ans = if dp[k] { "First" } else { "Second" };
    println!("{}", ans);
}


Measured memory_bytes: 2280
s = input()

front = int(s[:2])
back =  int(s[2:])


# YYMM 0 <= front <= 99 ,1 <= MM <= 12

def formatCheck(data):
	if  1 <= data and data <= 12 :
		return True
	else:
		return False

result_front = formatCheck(front)
result_back = formatCheck(back)

if result_front:
	if result_back:
		result = "AMBIGUOUS"
	else:
		result = "MMYY"
else:
	if result_back:
		result = "YYMM"
	else:
		result = "NA"

print(result)




Measured memory_bytes: 3060
n,ma,mb=map(int,input().split())
el=[list(map(int,input().split())) for i in range(n)]
sa=sum(i[0] for i in el)
sb=sum(i[1] for i in el)
#mi=min(sa//ma,sb//mb)
inf=10000000000
x=[[inf for j in range(sb+1)] for i in range(sa+1)]
x[0][0]=0
for i in range(n):
    now=el[i]
    x_sub=[[0 for j in range(sb+1)] for i in range(sa+1)]
    for k in range(sa+1):
        for l in range(sb+1):
            if x[k][l]!=inf and k+now[0]<sa+1 and l+now[1]<sb+1:
                x_sub[k+now[0]][l+now[1]]=x[k][l]+now[2]
    for k in range(sa+1):
        for l in range(sb+1):
                if x_sub[k][l]!=0:
                    x[k][l]=min(x[k][l],x_sub[k][l])
mi=min(sa//ma,sb//mb)
ans=inf
for i in range(1,mi+1):
    ans=min(ans,x[ma*i][mb*i])
if ans==inf:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 5480
#include <functional>
#include <queue>
#include <vector>
#include <iostream>
#include <cstdint>
#include <cstring>
using namespace std;

int main()
{
	int n;
	int d[50];
	int sum = 0;

	cin >> n;

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

	for (int x = 0; x < n; x++)
	{
		for (int y = (x + 1); y < n; y++)
		{
			sum += d[x]*d[y];
		}
	}

	cout << sum;

	return 0;
}

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

int main(void){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e - a > k){
        cout << ":(" << endl;
    }
    else{
        cout << "Yay!" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int A,B,C;cin >> A >> B >> C;
  if(A+B+C>= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int ans= 0;
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();

		if (K<=A) {
			ans=K;
		}
		else{
			if (A<K&&K<=A+B) {
				ans=A;
			}
			else{
				ans=A-(K-(A+B));
			}
		
		}
		System.out.println(ans);
		//System.out.print(ans);
		

    }
}

Measured memory_bytes: 35828
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int numa, numb;
    cin >> numa >> numb;
    int ans = 0;
    int current = 1;
    while(current<numb){
        ans ++;
        current += (numa-1);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 888
x, y, z = map(int, input().split())
x_swap_1 = y
y_swap_1 = x
x = x_swap_1
y = y_swap_1
x_swap_2 = z
z_swap_2 = x
x = x_swap_2
z = z_swap_2
print(str(x) + ' ' + str(y) + ' ' + str(z))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;


int main(){
    
    while(true){
    int N; cin>>N;
        if(N==0)break;
    vector< set<int> > p;
    REP(i,N){
        int M; cin>>M;
        set<int> pt;
        REP(j,M){
            int t; cin>>t;
            pt.insert(t);
        }
        p.push_back(pt);
    }
    
    int K; cin>>K;
    vector<int> l(K);
    REP(i,K)cin>>l[i];
    
    int cnt=0,id=-1;
    REP(i,N){
        REP(j,l.size()){
            if(p[i].find(l[j])==p[i].end())goto nextf;
        }
        id=i;
        cnt++;
    nextf:;
    }
    
    if(cnt==0||cnt>1)cout<<-1<<endl;
    else cout<<id+1<<endl;
    }
    
    return 0;
}

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

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

const ll MOD = 1000000007;

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

    //i(k~n+1)コ選ぶとき、その和は何パターンあるか？
    //最初の0, 1, ... i-1が最小でn-i, ...,n , n+1が最大
    //つまりiコを選ぶときにM-m+1パターンの数がとれる!

    ll ans = 0;
    for(ll i = k; i <= n+1; i++){
        ll m = (i-1)*i/2;
        ll M = (n+1 + n-i)*i/2;

        ans = (ans + M-m+1) % MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        //空読み
        sc.nextLine();

        String[] input = sc.nextLine().split(" ");
        int[] array = new int[n];
        for(int i = 0; i < n; i++) {
            array[i] = Integer.parseInt(input[i]);
        }
        insertionSort(array, n);
    }

    private static void insertionSort(int a[], int n) {
        
        StringBuilder sb = new StringBuilder();
        for(int value: a) {
            sb.append(value + " ");
        }
        System.out.println(sb.toString().trim());
        sb.setLength(0);
        for(int i = 1; i < n; i++) {
            int v = a[i];
            int j = i - 1;
            while( (j >= 0) && (a[j] > v) ) {
                a[j+1] = a[j];
                j--;
            }
            a[j+1] = v;

            sb = new StringBuilder();
            for(int value: a) {
                sb.append(value + " ");
            }
            System.out.println(sb.toString().trim());
            sb.setLength(0);
        }
    }
    
}


Measured memory_bytes: 30124
a, b, c = map(int, input().split())
if a>b:
    tmp = a;
    a = b;
    b = tmp;
if b>c:
    tmp = b;
    b = c;
    c= tmp;
if a>b:
    tmp = a;
    a = b;
    b = tmp;
print (a, b, c, sep=" ")


Measured memory_bytes: 5592
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007

int main(){
  char s[100001];
  scanf("%s",s);
  int n = strlen(s);
  long dp[100001][13] = {};
  int i,j;
  int c;
  int ten;
  if(s[0] == '?'){
    for(j=0;j<10;j++){
    dp[0][j] = 1;
    }
  }else{
    c = s[0] - '0';
    dp[0][c] = 1;
  }
  
  for(i=1;i<n;i++){
    if(s[i] == '?'){
      for(j=0;j<13;j++){
        for(ten=0;ten<10;ten++){
          dp[i][(10*j+ten)%13] += dp[i-1][j] % MOD;
        }
      }
    }else{
      c = s[i] - '0';
      for(j=0;j<13;j++){
        dp[i][(10*j+c)%13] += dp[i-1][j] % MOD;
      }
    }
  }
  long answer = dp[n-1][5] % MOD;
  printf("%ld",answer);
}

Measured memory_bytes: 10368
from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 0
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 0:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.appendleft(b[2])
if ans % 2 == 1:
  d.reverse()
print("".join(d))

Measured memory_bytes: 9460
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 1e5 + 5;

int n;
int f[maxn], g[maxn];
char s[maxn];

int main(){
	scanf("%s", s + 1);
	n = strlen(s + 1);
	f[0] = 1;
	REP(i, 1, n){
		if(s[i] == '0')
			f[i] = f[i - 1];
		else
			f[i] = (f[i - 1] * 2) % INF;
		g[i] = (1ll * g[i - 1] * 3) % INF;
		if(s[i] == '1')
			(g[i] += f[i - 1]) %= INF;
	}
/*	REP(i, 1, n)
		printf("%d ", f[i]);
	puts("");
	REP(i, 1, n)
		printf("%d ", g[i]);
	puts("");
*/	printf("%d\n", (f[n] + g[n]) % INF);
	return 0;
}



Measured memory_bytes: 1152
def solve(N, K, cards):
  min_elem = cards[0]

  # dp[i] == True: Current player will win if i stones left
  dp = [False for _ in range(K + 1)]
  for i in range(min_elem):
    dp[i] = False

  for k in range(1, K + 1):
    for c in cards:
      if c > k:
        break
      if k - c >= 0 and dp[k - c] == False:
        dp[k] = True

  print("First" if dp[K] else "Second")

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


N, K = iln()
cards = iln()
solve(N, K, cards)


Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int N,M;
vector<string> v;
queue<P> Q;
int main(){
    int N,K;
    cin>>N>>K;
    string S;
    cin>>S;
    vector<int> check;
    int count=0;
    //０と１の数を記録
    if(S.at(0)=='0') check.push_back(0);
   for(int i=0;i<S.size();){
       int j=i;
       while(j<S.size() && S.at(j)==S.at(i))j++;
           check.push_back(j-i);
       i=j;
   }
   if(S.back()=='0')check.push_back(0);
//累積テ－ブル
   vector<int> sum((int)check.size()+1,0);
  for(int i=0;i<check.size();i++){
      sum.at(i+1)=sum.at(i)+check.at(i);
  }
  int res=0;
  for(int left=0;left<check.size();left+=2){
      int right = left+K*2+1;
      if(right>=check.size()) right=(int)sum.size()-1;
      chmax(res,sum.at(right)-sum.at(left));
  }
    cout<<res<<endl;
} 


Measured memory_bytes: 1272
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> b;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < a[i]; j++) {
			b.push_back(i + 1);
		}
	}
	vector< vector<int> > c(h, vector<int>(w, 0));
	int t = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			c[i][j] = b[t];
			t++;
		}
	}
	for (int i = 0; i < h; i++) {
		if (i % 2 == 0) {
			cout << c[i][0];
			for (int j = 1; j < w; j++) {
				cout << ' ' << c[i][j];
			}
			cout << endl;
		}
		else {
			cout << c[i][w - 1];
			for (int j = w - 2; j >= 0; j--) {
				cout << ' ' << c[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;

    vector<int> v;
    vector<int> c;

    for (int i = 0; i < n; ++i) {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    for (int j = 0; j < n; ++j) {
        int tmp;
        cin >> tmp;
        c.push_back(tmp);
    }

    int count = 0;

    for (int k = 0; k < n; ++k) {
        if (v.at(k) > c.at(k)) count += v.at(k) - c.at(k);
    }

    cout << count << endl;
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int N;
	cin>>N;
	int P=N%10;
	if(P==3)
	{
		cout<<"bon";
	}
	if(P==0||P==1||P==6||P==8)
	{
		cout<<"pon";
	}
	if(P==2||P==4||P==5||P==7||P==9)
	{
		cout<<"hon";
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int a[maxn];
int b[maxn];
int ans[maxn],cnt=0;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int m=0;
    for(int i=n;i>=1;i--)
    {
        int sum=0;
        for(int j=i;j<=n;j+=i)
        {
            sum+=b[j];
        }
        sum%=2;
        if(sum!=a[i])
        {
            m++;
            ans[cnt++]=i;
            //cout<<"----"<<i<<endl;
            b[i]=1;
        }
    }
    cout<<m<<"\n";
    for(int i=0;i<m;i++)
        cout<<ans[i]<<" ";
	return 0;
}


Measured memory_bytes: 9728
#include <iostream>
#include <vector>
using namespace std;
int w, h;
vector<int> ans;
char c[55][55];

void dfs(int x, int y) {
    c[x][y] = '0';
    for (int dh = -1; dh <= 1; dh++) {
        for (int dw = -1; dw <= 1; dw++) {
            int nh = x + dh, nw = y + dw;
            if (0 <= nh && 0 <= nw && nh < h && nw < w && c[nh][nw] == '1') dfs(nh, nw);
        }
    }
    return;
}

int main() {
    while (1) {
        cin >> w >> h;
        if (w == 0 && h == 0) break;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) cin >> c[i][j];
        }
        int cnt = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (c[i][j] == '1') { 
                    dfs(i, j);
                    cnt++;
                }
            }
        }
        ans.push_back(cnt);
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
}   


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))




int main(){
	ll N,M;
	cin >> N >> M;
	priority_queue<ll> A;
	FOR(i,0,N){
		ll a;
		cin >> a;
		A.push(a);
	}
	FOR(i,0,M){
		ll a = A.top();
		A.pop();
		A.push(a/2);
	}
	ll ans = 0;
	while(A.size()){
		ans += A.top();
		A.pop();
	}
	cout << ans << endl;

}


Measured memory_bytes: 1400
A=int(input())
l=list(map(int,input().split()))
right=l[0]
left=sum(l[1:])
ans=left-right
for i in range(A-2):
    right+=l[i+1]
    left-=l[i+1]
    ans=min(ans,abs(right-left))
print(ans)

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) (n)*(n)

using namespace std;
typedef long long ll;

int main() {
    FAST;

    ll n,sum=0;
    cin>>n;
    ll a[200005];

     for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }

    for(ll i=0;i<n-1;i++)
    {
        if(a[i]>a[i+1])
        {
            sum+=a[i]-a[i+1];
            a[i+1]=a[i];
        }
       // cout<<sum<<endl;
    }
    cout<<sum<<endl;

    return 0;

}




Measured memory_bytes: 5196