akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D;
    cin >> D;
    vi c(26);
    rep(i, 26) cin >> c[i];
    vvi s(D, vi(26));
    rep(i, D) rep(j, 26) {
        cin >> s[i][j];
    }

    vi t(D);
    vi last(26);
    rep(d, D) {
        int ma = INT_MIN, nn = 23;
        rep(i, 26) {
            int ggh = 0;
            ggh += s[d][i];
            rep(j, 26) {
                if(i == j) continue;
                ggh -= c[j]*(d+1-last[j]);
            }
            if(chmax(ma, ggh)) {
                nn = i;
            }
        }
        last[nn] = d+1;
        t[d] = nn;
    }
    last.assign(26, 0);
    vector<set<int> > se(26);
    rep(i, 26) {
        se[i].insert(D);
    }
    ll gh = 0;
    rep(d, D) {
        se[t[d]].insert(d);
        gh += s[d][t[d]];
        last[t[d]] = d+1;
        rep(j, 26) {
            gh -= c[j]*(d+1-last[j]);
        }
    }

    vvi bits(26, vi(D+1));
    auto add = [&](int al, int d, int x) {
        while(d <= D) {
            bits[al][d] += x;
            d += d&-d;
        }
    };
    auto sum = [&](int al, int d) {
        if(d == 0) return 0;
        int res = 0;
        while(d) {
            res += bits[al][d];
            d &= d-1;
        }
        return res;
    };


    rep(i, D) {
        rep(j, 26) {
            add(j, i+1, 1);
        }
    }

    rep(i, D) {
        int now = sum(t[i], i+1);
        add(t[i], i+1, -now);
    }

    int X = 1000000;
    while(X--) {
        int nowd = D-X%D-1;
        int nowal = X%26;
        if(t[nowd] == nowal) continue;
        ll nowgh = gh;
        nowgh += s[nowd][nowal]-s[nowd][t[nowd]];
        auto itr = se[nowal].lower_bound(nowd);
        nowgh += (*itr - nowd)*sum(nowal, nowd+1) * c[nowd];
        itr = se[t[nowd]].upper_bound(nowd);
        nowgh -= (*itr-nowd)*(sum(t[nowd], nowd)+1) * c[t[nowd]];
        if(nowgh > gh or X%501 == 0) {
            add(t[nowd], nowd+1, sum(t[nowd], nowd)+1);
            add(nowal, nowd+1, -sum(nowal, nowd+1));
            se[t[nowd]].erase(nowd);
            se[nowal].insert(nowd);
            t[nowd] = nowal;
            gh = nowgh;
        }
    }

    rep(i, D) {
        cout << t[i]+1 << endl;
    }
}


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

ans = 0
r = 0
tmp = 0
for l in range(N):
    while r < N and (tmp&A[r]) == 0:
        tmp += A[r]
        r += 1
    tmp -= A[l]
    ans += r - l
print(ans)

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000000;
int PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;



int main(){
 int X;cin >> X;
 if(X < 100){
     cout << 0 << endl;
     return 0;
 }
 int Y = X % 100;
 if(Y == 0){
     cout << 1 << endl;
     return 0;
 }
 int P[6];
 for(int i = 5;i >= 1;i--){
     int cnt = 0;
     while(Y >= i){
         cnt++;
         Y-=i;
     }
     P[i] = cnt;
 }
 int min = 0;
 for(int i = 1;i < 6;i++){
     min += 100 * P[i];
     //cout << P[i] << ' ';
 }
 //cout << endl;
 if(min <= X){
     cout << 1 << endl;
 }else{
     cout << 0 << endl;
 }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[110], b[100];
map< pair<int, int>, int > mp;
int main(){
    int n;
    while(cin>>n){
        int ans=0;
        for(int i=0; i<n; ++i){
            scanf("%d%d",a+i,b+i);
            for(int j=0; j<i; ++j){
                mp[mk(a[i]-a[j],b[i]-b[j])]++;
                mp[mk(a[j]-a[i],b[j]-b[i])]++;
                ans=max(ans, mp[mk(a[j]-a[i],b[j]-b[i])]);
                ans=max(ans, mp[mk(a[i]-a[j],b[i]-b[j])]);
            }
        }
        ans=n-ans;
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 384
package main

import "fmt"

func isPrime(x int) bool {
	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}
func countPrime(x []int) int {
	var cnt int
	for _, v := range x {
		if isPrime(v) {
			cnt++
		}
	}
	return cnt
}

func main() {
	var n int
	fmt.Scan(&n)
	numbers := make([]int, n)
	for i := range numbers {
		fmt.Scan(&numbers[i])
	}
	fmt.Println(countPrime(numbers))

}


Measured memory_bytes: 1768
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringJoiner;

public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public static void main(String[] args) throws Exception {
		int n = Integer.parseInt(br.readLine());
		int[] array = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		
		trace(array);
		
		for(int i = 1; i < n; i++){
			int v = array[i];
			int j = i - 1;
			
			while(j >= 0 && array[j] > v){
				array[j+1] = array[j];
				j--;
			}
			array[j+1] = v;
			
			trace(array);
		}
	}
	
	public static void trace(int[] array){
		StringJoiner sj = new StringJoiner(" ");
		Arrays.stream(array).forEach(i -> sj.add(String.valueOf(i)));
		System.out.println(sj.toString());
	}
}



Measured memory_bytes: 31544
#include<bits/stdc++.h>
using namespace std;
bitset<2005> dpl[2005],dpr[2005],g[2005],s[2005];
int n,i,j,a,l,ans;
int main()
{
	scanf("%d",&n);
	for(i=2;i<=n;++i)
		for(j=1;j<i;++j)
		{
			scanf("%1d",&a);
			g[i][j]=a;
			g[j][i]=a^1;
		}
	for(i=1;i<=n;++i)
	{
		s[i]=s[i-1];
		s[i][i]=1;
	}
	for(i=1;i<=n;++i)
		dpl[i][i]=dpr[i][i]=1;
	for(l=1;l<n;++l)
	{
		for(i=l+1;i<=n;++i)
			dpr[i-l][i]=(dpr[i-l]&dpl[i-1]&(s[i-1]^s[i-l-1])&g[i]).count();
		for(i=1;i<=n-l;++i)
			dpl[i+l][i]=(dpl[i+l]&dpr[i+1]&(s[i+l]^s[i])&g[i]).count();
	}
	for(i=1;i<=n;++i)
		if(dpl[n][i]&dpr[1][i])
			++ans;
	cout<<ans;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    while(n>0){
        n /= k;
        ++cnt;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3540
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;
        static void Main(string[] args)
        {
            N = Sarray()[0];
            a = new long[N][];
            for (var i = 0; i < N; ++i)
                a[i] = Sarray();
            var states = (long)(1 << (int)N);
            flag = new bool[states];
            dp = new long[states];
            var ans = f(states - 1);
            WriteLine(ans);
        }
        static bool[] flag;
        static long[] dp;
        static long N;
        static long[][] a;

        static long ansnum = 0;
        static long f(long s)
        {
            ++ansnum;
            if (flag[s]) return dp[s];
            flag[s] = true;
            long fans = 0L;
            for (long i = 0; i < N; ++i)
                if (bit(s, (int)i))
                    for (long j = i + 1; j < N; ++j)
                        if (bit(s, (int)j)) fans += a[i][j];
            for (long t = (s - 1) & s; 0 < t; t = (t - 1) & s)
                fans = Max(fans, f(t) + f(s ^ t));
            return dp[s] = fans;
        }
        static bool bit(long n, int k) => 0 != ((n >> k) & 1);
    }
}

Measured memory_bytes: 14036
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 5*200005;

int n, f[N], a[N],ans,fnd1;

void init()
{
	f[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		f[i] = f[i - 1];
		int c = i;
		while (c)
		{
			if (c % 2)
				break;
			f[i]++;
			c /= 2;
		}
	}
}

int c(int n, int k)
{
	if (n < k)
		return 0;
	return (f[n] - f[k] - f[n - k] < 1);
}

int main()
{
	cin >> n;
	init();
	for (int i = 1; i <= n; i++)
	{
		char x;
		scanf(" %c", &x);
		a[i] = x - '0' - 1;
		ans ^= ((a[i] % 2) * c(n - 1, i-1)) % 2;
		fnd1 += (a[i] == 1);
	}

	if (ans == 1)
		cout << ans << endl;
	else if (fnd1)
		cout << 0 << endl;
	else
	{
		ans = 0;
		for (int i = 1; i <= n; i++)
		{
			a[i] /= 2;
			ans ^= (a[i] * c(n - 1, i-1)) % 2;
			ans %= 2;
		}
		cout << ans * 2 << endl;
	}

	return 0;
}



/*

10
2311312312


	
3
1 3 1
2 2
0

*/

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

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

    vector<pair<int, int>> v;
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }

    sort(v.begin(), v.end());
    queue<pair<int ,int>> q;
    for(int i=0; i<N; i++){
        q.push(make_pair(v[i].first, v[i].second));
    }

    priority_queue<int> l;

    int ans = 0;
    for(int i=0; i<=M; i++){
        while(q.front().first == i){
            l.push(q.front().second);
            q.pop();
        }
        if(!l.empty()){
            ans += l.top();
            l.pop();
        }
    }   

    cout << ans;

    return 0;
}

Measured memory_bytes: 2804
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

int main(void){
  int n,i,j,k,l,c;

  string s;
  cin>>n>>s;

  int first[10];
  int last[10];
  for(i=0;i<10;i++){
    first[i]=last[i]=-1;
  }

  for(i=0;i<n;i++){
    c=s[i]-'0';
    if(first[c]==-1){
      first[c]=i;
    }
    if(last[c]<i){
      last[c]=i;
    }
  }

  int ans=0;

  for(i=0;i<10;i++){
    for(j=0;j<10;j++){
      for(k=0;k<10;k++){
        if(first[i]==-1||first[i]>last[k])continue;
        c=j+'0';
        for(l=first[i]+1;l<last[k];l++){
          if(s[l]==c){
            ans++;
            break;
          }
        }
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <array>
#include <cstdint>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

void bfs(array<array<uint32_t, 30>, 30> &maze, vector<vector<uint32_t>> &vwalls,
         vector<vector<uint32_t>> &pwalls) {
  queue<pair<int32_t, int32_t>> q;

  q.push({0, 0});
  maze[0][0] = 1;

  while (!q.empty()) {
    pair<int32_t, int32_t> p = q.front();
    q.pop();
    int32_t h = p.first;
    int32_t w = p.second;
    uint32_t step = maze[h][w];
    if (pwalls[h][w] == 0 && maze[h][w + 1] == 0) {
      q.push({h, w + 1});
      maze[h][w + 1] = step + 1;
    }
    if (vwalls[h][w] == 0 && maze[h + 1][w] == 0) {
      q.push({h + 1, w});
      maze[h + 1][w] = step + 1;
    }
    if (w - 1 >= 0 && pwalls[h][w - 1] == 0 && maze[h][w - 1] == 0) {
      q.push({h, w - 1});
      maze[h][w - 1] = step + 1;
    }
    if (h - 1 >= 0 && vwalls[h - 1][w] == 0 && maze[h - 1][w] == 0) {
      q.push({h - 1, w});
      maze[h - 1][w] = step + 1;
    }
  }
}

int32_t main() {
  while (true) {
    int32_t w, h;
    cin >> w >> h;
    if (w == 0) break;

    array<array<uint32_t, 30>, 30> maze;
    for (uint32_t i = 0; i < maze.size(); i++) {
      for (uint32_t j = 0; j < maze.size(); j++) {
        maze[i][j] = 0;
      }
    }

    vector<vector<uint32_t>> vwalls;
    vector<vector<uint32_t>> pwalls;
    for (uint32_t i = 0; i < 2 * h - 1; i++) {
      uint32_t block;
      if (i % 2 == 0) {
        vector<uint32_t> walls;
        for (uint32_t j = 0; j < w - 1; j++) {
          cin >> block;
          walls.push_back(block);
        }
        walls.push_back(1);
        pwalls.push_back(walls);
      } else {
        vector<uint32_t> walls;
        for (uint32_t j = 0; j < w; j++) {
          cin >> block;
          walls.push_back(block);
        }
        vwalls.push_back(walls);
      }
    }

    vector<uint32_t> senti;
    for (uint32_t j = 0; j < w; j++) {
      senti.push_back(1);
    }
    vwalls.push_back(senti);

    bfs(maze, vwalls, pwalls);

    cout << maze[h - 1][w - 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 3060
N = int(input())

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

A.sort()

num = 0

for i in range(N-1):

    if A[i] == A[i+1]:
        num += 1

if num % 2 == 0:
    print (N - num)

else:
    print (N - num - 1)


Measured memory_bytes: 52916
'use strict';
console.log(function(args){
  const tmp = args.trim().split('\n');
  const NM = tmp.shift().split(' ').map( v=>v|0 );
  const N = NM[0], M = NM[1];
  const a = tmp.map( v=>v|0 );
  const dp = Array(N+2).fill(0);
  dp[0] = 1;
  for ( let i = 0; i < N; i++ ) {
    if ( a.length && a[0] === i ) {
      a.shift();
      dp[i+2] = 0;
    } else {
      dp[i+1] = (dp[i+1] + dp[i]) % (1e9+7);
      dp[i+2] = (dp[i+2] + dp[i]) % (1e9+7);
    }
  }
  return dp[N].toString();
}(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 16868
words = lambda t : list(map(t, input().split()))
n,t = words(int)
xys = []
for i in range(n):
    x,y = words(int)
    xys.append((x,y))

xys.sort()
dp = [[0]*(t+1) for i in range(n)]

def show(dp):
  for row in dp:
      print(row)

for i in range(n):
    for j in range(1,t+1):
        dp[i][j] = dp[i-1][j]
        if xys[i][0] <= j:
            dp[i][j] = max(dp[i][j], xys[i][1] + dp[i-1][j-xys[i][0]])

#show(dp)
ans = xys[0][1]
for i in range(1,n):
    ans = max(ans, dp[i-1][t-1]+xys[i][1])

print(ans)


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

int main() {
  int N, Sum=0;
  cin >> N;
  vector<int> B(N-1);
  for (int i=0; i<N-1; i++) cin >> B.at(i);
  Sum = B.at(0);
  for (int i=0; i<N-2; i++){
    Sum = Sum + min(B.at(i), B.at(i+1));
  }
  Sum = Sum + B.at(N-2);
  cout << Sum << endl;
}

Measured memory_bytes: 256
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char *argv[]) {
  uint64_t X, Y;
  std::cin >> X >> Y;
  for(int i = 0; ; i++){
    if((X << i) > Y ) {
      std::cout << i << std::endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

int getWholeCost(const vector<int>& deg, const string& s){
	const int N = deg.size();
	int res = 0;
	for(int i=0;i<N;i++){
		if(deg[i] == 0) continue;
		res += deg[i];
		if((s[i]=='B')^(deg[i]%2 == 0)) res++;
	}
	return res;
}

int getDec(const vector<vector<int>>& g, const vector<int>& deg, const string& s){
	const int N = g.size();
	int start = 0;
	int res = 0;
	for(int i=0;i<N;i++){
		if(deg[i] > 0) start = i;
	}
	for(int _=0;_<2;_++){
		queue<int> qu; qu.push(start);
		vector<int> dist(N, -1);
		dist[start] = 0;
		while(!qu.empty()){
			int p = qu.front(); qu.pop();
			for(auto& t : g[p]){
				if(deg[t] <= 0) continue;
				if(dist[t] >= 0) continue;
				dist[t] = dist[p] + 2 * (((s[t]=='B')^(deg[t]%2 == 0)));
				qu.push(t);
			}
		}
		for(int i=0;i<N;i++){
			if(deg[i] <= 0) continue;
			if(dist[start] < dist[i] || (dist[start] == dist[i] && deg[start] > deg[i])) start = i;
		}
		res = max(res, dist[start]);
	}
	return res;
}

int solve(const vector<vector<int>>& g, const string& s){
	const int cntW = count_if(s.begin(), s.end(), [](char c){ return c == 'W';});
	if(cntW <= 1) return cntW;

	const int N = g.size();
	vector<int> deg(N, 0);
	for(int i=0;i<N;i++) deg[i] = g[i].size();
	queue<int> qu;
	for(int i=0;i<N;i++){
		if(deg[i] == 1 && s[i] == 'B') qu.push(i);
	}
	while(!qu.empty()){
		int p = qu.front(); qu.pop();
		deg[p]--;
		for(const int& t : g[p]){
			if(deg[t] <= 0) continue;
			deg[t]--;
			if(deg[t] == 1 && s[t] == 'B') qu.push(t);
		}
	}
	return getWholeCost(deg, s) - getDec(g, deg, s);
}

int main(){
	int N;
	while(cin >> N){
		vector<vector<int>> g(N);
		for(int i=0;i<N-1;i++){
			int x, y; cin >> x >> y;
			--x; --y;
			g[x].push_back(y);
			g[y].push_back(x);
		}
		string s; cin >> s;
		cout << solve(g, s) << endl;
	}
}

Measured memory_bytes: 7416
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
typedef ll Weight;
typedef int Flow;
struct Edge {
	int src, dest, rev;
	Flow cap;
	Weight cost;
	bool operator < (const Edge &rhs) const
	{
		return cost > rhs.cost;
	}
	Edge(int s, int d) : src(s), dest(d) { ; }
	Edge(int s, int d, int c) : src(s), dest(d), cost(c) { ; }
	Edge(int s, int d, int r, Flow cp, Weight cst) : src(s), dest(d), rev(r), cap(cp), cost(cst) { ; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int src, int dest, Flow cap)
{
	g[src].push_back(Edge{ src, dest, (int)g[dest].size(), cap, 0 });
	g[dest].push_back(Edge{ dest, src, (int)g[src].size() - 1, 0, 0 });
}

void add_edge(Graph &g, int from, int to, Flow cap, Weight cost)
{
	g[from].push_back(Edge(from, to, (int)g[to].size(), cap, cost));
	g[to].push_back(Edge(to, from, (int)g[from].size() - 1, 0, -cost));
}
Weight mincost_flow(Graph &g, int s, int t, Flow f)
{
	const int n = g.size();
	Weight res = 0;
	Array dist(n);
	vi prevv(n), preve(n);
	while (f > 0)
	{
		REP(i, n) dist[i] = (i == s) ? 0 : INF;
		bool update = true;
		while (update)
		{
			update = false;
			for (int v = 0; v < n; v++)
			{
				if (dist[v] == INF) continue;
				REP(i, g[v].size())
				{
					Edge& e = g[v][i];
					if (e.cap > 0 && dist[e.dest] > dist[v] + e.cost)
					{
						dist[e.dest] = dist[v] + e.cost;
						prevv[e.dest] = v;
						preve[e.dest] = i;
						update = true;
					}
				}
			}
		}
		if (dist[t] == INF) return -1; // cannot flow
		Flow d = f;
		for (int v = t; v != s; v = prevv[v])
		{
			d = min(d, g[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * dist[t];
		for (int v = t; v != s; v = prevv[v])
		{
			Edge &e = g[prevv[v]][preve[v]];
			e.cap -= d;
			g[v][e.rev].cap += d;
		}
	}
	return res;
}


int main()
{
	int n;
	while (cin >> n, n)
	{
		Graph g(368);
		int source = 366, sink = 367;
		REP(i, 365)
		{
			add_edge(g, i, i + 1, 2, 0);
		}
		add_edge(g, source, 0, 2, 0);
		add_edge(g, 365, sink, 2, 0);
		REP(i, n)
		{
			int a, b, c; cin >> a >> b >> c;
			a--;
			add_edge(g, a, b, 1, -c);
		}
		cout << -mincost_flow(g, source, sink, 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 3192
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}
 
const int MAXN = 1e6 + 5;
const ull P = 41;
 
vector <ull> p;
 
void init_p() {
    p.resize(MAXN);
    p[0] = 1;
    forn (i, 1, sz(p))
        p[i] = p[i - 1] * P;
}
 
ull char_to_int(char c) {
    return (c - 'a' + 1);
}
 
vector <ull> init_h(const string& s) {
    vector <ull> h(sz(s) + 1);
    forn (i, 1, sz(h))
        h[i] = h[i - 1] * P + char_to_int(s[i - 1]);
    return h;
}
 
ull get(const vector <ull>& h, int l, int r) {
    return h[r] - h[l] * p[r - l];
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    init_p();
    int n;
    cin >> n;
    vector <vector <string>> by_sz(MAXN);
    forn (i, 0, n) {
        string s;
        cin >> s;
        by_sz[sz(s)].pb(s);
    }
    long long ans = 0;
    map <ull, array <int, 26>> cnt;
    for (int sz = MAXN - 1; sz > 0; --sz) {
        for (auto& s : by_sz[sz]) {
            auto h = init_h(s);
            ull t = get(h, 1, sz(s));
            ans += cnt[get(h, 1, sz(s))][s[0] - 'a'];
        }
        for (auto& s : by_sz[sz]) {
            auto h = init_h(s);
            vector <int> cur(26);
            for (char c : s)
                cur[c - 'a']++;
            for (int i = sz(s) - 1; i >= 0; --i) {
                auto& mp = cnt[get(h, i + 1, sz(s))];
                forn (j, 0, 26)
                    if (cur[j])
                        mp[j]++;
                cur[s[i] - 'a']--;
            }
        }
        // cerr << sz << " ";
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 195052
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
typedef long long ll;

int main(){
  string S;
  cin >> S;
  cout << ((S<="2019/04/30")? "Heisei":"TBD") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int N,M;
int A[1010];
int V[11]={2,5,5,4,5,6,3,7,6};
string dp[1000000];
bool F[1000000];

string comp(string s,string t){
	if(s.size()>t.size()){
		return s;
	}
	else if(s.size()<t.size()){
		return t;
	}
	else{
		if(s>t){
			return s;
		}
		else{
			return t;
		}
	}
}

string DP(int a){
	string res;
	vector<string> v,v2;
	if(F[a]!=false){
		return dp[a];
	}
	if(a>=N){
		if(a==N){
			return "s";
		}
		else{
			return "!";
		}
	}
	REP(i,M){
		string s;
		s=DP(a+V[A[i]-1])+to_string(A[i]);
		bool flag=false;
		REP(j,s.size()){
			if(s[j]=='!'){
				flag=true;
			}
		}
		if(flag!=true){
			v.push_back(s);
		}
	}
	REP(i,v.size()){
		if(comp(res,v[i])==v[i]){
			res=v[i];
		}
	}
	F[a]=true;
	return dp[a]=res;
}

signed main(){
	cin>>N>>M;
	REP(i,M){
		cin>>A[i];
	}
	string ans=DP(0);
	string ans2;
	REP(i,ans.size()){
		if(ans[i]!='s'){
			ans2+=ans[i];
		}
	}
	cout<<ans2<<endl;
	return 0;
}


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

using namespace std ;

#define	Hex_5		0x55555555
#define	Hex_3		0x33333333
#define	Hex_0f		0x0f0f0f0f
#define	Hex_00ff	0x00ff00ff
#define	Hex_ffff	0x0000ffff

inline int BitCount( int bits )
{
	bits = (bits & Hex_5	) + ((bits >>  1) & Hex_5	) ;
	bits = (bits & Hex_3	) + ((bits >>  2) & Hex_3	) ;
	bits = (bits & Hex_0f	) + ((bits >>  4) & Hex_0f	) ;
	bits = (bits & Hex_00ff	) + ((bits >>  8) & Hex_00ff) ;
	bits = (bits & Hex_ffff	) + ((bits >> 16) & Hex_ffff) ;

	return bits ;
}

int main()
{
    int R, C;
    while (cin >> R >> C, R | C) {
        vector<int> a(C);
        for (int i = 0; i < R; i++) {
            for (int j = 0; j < C; j++) {
                int b;
                cin >> b;
                a[j] |= b << i;
            }
        }
        int res = 0;
        for (int i = 0; i < (1 << R); i++) {
            int cnt = 0;
            for (int j = 0; j < C; j++) {
                int x =	BitCount( a[ j ] ^ i ) ;	//	builtin_popcount(a[j] ^ i);
                cnt += max(x, R - x);
            }
            res = max(res, cnt);
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int n,a,count=0;
    bool check;
    cin>>n;
    for(int i=0;i<n;i++){
        check=true;
        cin>>a;
        if(a%2==0 && a!=2) check=false;
        else{
            for(int j=3;j<=sqrt(a);j+=2){
                if(a%j==0) check=false;
            }
            if(check) count++;
        }
    }
    cout<<count<<endl;
}



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

int main(){
    int n, m;
    cin >> n >> m;
    
    vector<int> s[m];
    vector<int> p(m);
    for(int i = 0; i < m; i++){
        int k; cin >> k;
        for(int j = 0; j < k; j++){
            int x; cin >> x; x--;
            s[i].emplace_back(x);
        }
    }
    for(int i = 0; i < m; i++) cin >> p[i];

    int ans = 0;
    for(int bit = 0; bit < (1<<n); bit++){
        bool ok = true;
        for(int i = 0; i < m; i++){
            int on = 0;
            for(int x : s[i]){
                if((bit>>x)&1) on++;
            }
            if(on % 2 != p[i]) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int n, q;
  cin >> n >> q;
  queue<int> que[1000];
  rep(qi, q)
  {
    int type;
    cin >> type;
    if (type == 0)
    {
      int t, x;
      cin >> t >> x;
      que[t].push(x);
    }
    else if (type == 1)
    {
      int t;
      cin >> t;
      if (!que[t].empty())
        cout << que[t].front() << endl;
    }
    else
    {
      int t;
      cin >> t;
      if (!que[t].empty())
        que[t].pop();
    }
  }

  return 0;
}



Measured memory_bytes: 4220
#include<stdio.h>
int main()
{
	int n , m, i;
	scanf("%d %d", &n, &m);
	if(n>=m){
		for(i=0; i<n; i++)
		printf("%d",m);
		printf("\n");
	}
  if(m>n){
                for(i=0; i<m; i++)
                printf("%d",n);
                printf("\n");
  }

	return 0;
}


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

bool vd[10];

bool check(int x)
{
	while (x > 0) {
    	if (vd[x % 10])
            return false;
        x /= 10;
    }
    return true;
}

int main()
{
    int n, k, d;
    
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> d;
        vd[d] = true;
    }
  	
	int x = n;
    while (1) {
        if (check(x)) {
            cout << x << endl;
            break;
        }
        x++;
    }
  	
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [0 for i in range(max(6, N+1))]
MOD = 10**9+7
A[0] = A[3] = A[4] = A[5] = 1
if N <= 5:
  print(A[N])
  exit()
before_sum = 1
for i in range(6, N+1):
  A[i] = (before_sum + A[i-3])%MOD
  before_sum = (before_sum+A[i-3])%MOD
print(A[N])

Measured memory_bytes: 64376
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int N, res;
  long long KL2GvlyY, Lj4PdHRW, Q5VJL1cS;
  rd(N);
  Lj4PdHRW = 0;
  KL2GvlyY = 100000;
  while(Lj4PdHRW < KL2GvlyY){
    if((Lj4PdHRW + KL2GvlyY)%2==0){
      Q5VJL1cS = (Lj4PdHRW + KL2GvlyY) / 2;
    }
    else{
      Q5VJL1cS = (Lj4PdHRW + KL2GvlyY - 1) / 2;
    }
    if(Q5VJL1cS*(Q5VJL1cS+1)/2 >= N){
      KL2GvlyY = Q5VJL1cS;
    }
    else{
      Lj4PdHRW = Q5VJL1cS + 1;
    }
  }
  res =KL2GvlyY;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190829-1

// --- original code ---
// {
//   int N, res;
//   rd(N);
//   res = bsearch_min[ll,i,0,1d5](i*(i+1)/2 >= N);
//   wt(res);
// }


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);
	final int n = Integer.parseInt(stdin.nextLine());
	for (int i = 0; i < n; i++) {
	    System.out.println(stdin.nextLine().replace("Hoshino", "Hoshina"));
	}		
    }
}

Measured memory_bytes: 17264
def LI():
    return list(map(int, input().split()))


K, A, B = LI()
if A+2 >= B:
    ans = K+1
else:
    K = K-(A-1)
    nokori = K % 2
    ans = A+(B-A)*(K//2)
    ans += nokori


print(ans)


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

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

	ll N,K;
	ll ans=0;
	int i,k;

	cin >> N >> K;

	vector<ll> gv(N);
	rep(i,N) cin >> gv[i];

	sort(gv.begin(),gv.end(),greater<ll>());

	if(N<=K) ans=0;
	else ans=accumulate(gv.begin()+K,gv.end(),0LL);

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 4780
#include <iostream>
#include <algorithm>
#define R 1001
using namespace std;

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

		//rの入力
		int r, t[R], n[R], m[R], s[R], q, ts, te, qm;
		fill(t, t + R, 0);
		fill(n, n + R, 0);
		fill(m, m + R, 0);
		fill(s, s + R, 0);

		cin >> r;
		for (int i = 0; i < r; i++){
			cin >> t[i] >> n[i] >> m[i] >> s[i];
		}
		cin >> q;

		//qの入力と計算
		for (int c = 0; c < q; c++){
			cin >> ts >> te >> qm;

			//記録
			int tm[1300];
			int pc[1300];
			fill(tm, tm + 1300, 0);
			fill(pc, pc + 1300, 0);
			for (int i = 0; i < r; i++){
				if (m[i] == qm){
					if (s[i] == 1){
						pc[n[i]] = t[i];
					}
					if (s[i] == 0){
						for (int j = pc[n[i]]; j < t[i]; j++){
							tm[j] = 1;
						}
					}
				}
			}

			//カウント
			//bool login = false;
			int counter = 0;
			//int temp;
			for (int i = ts; i < te; i++){
				counter += tm[i];
				
				/*
				if (tm[i] == 1 && login == false){
					temp = i;
					login = true;
				} 
				if (tm[i] == 0 && login == true){
					counter += i - 1 - temp;
					login = false;
				}
				*/
			//	cout << "i:" << i << " tm[i]:" << tm[i] << " login:" << login << " temp:" << temp << endl;
			}
			/*
			if (login == true){
				counter += te - temp;
			}
			*/
			cout << counter << endl;
		}
	}
	return 0;
}

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long

using namespace std;

int n=0,k=0;
int arr[100001];
int pref[100001];
int suf[100001];
int fact[100001];
int obr[100001];

int pw(int a, int b, int m)
{
	int res=1;
	while (b)
	{
		if (b%2==0)
		{
			a = a*a%m;
			b/=2;
		}
		else
		{
			res = res*a%m;
			b--;
		}
	}
	return res;
}

int c(int n, int k)
{
	if (k>n)
		return 0;
	if (k==0)
		return 1;
	return fact[n]*obr[k]%MOD*obr[n-k]%MOD;
} 

signed main()
{
	cin >> n >> k;	
	if (k==1){
		cout << 0;
		exit(0);
	}
	fact[0] = 1;
	fact[1] = 1;
	for (int i=2; i<=n; i++)
		fact[i] = (fact[i-1]*i)%MOD;
	for (int i=0; i<=n; i++)
	{
		obr[i] = pw(fact[i], MOD-2, MOD);
	}
	for (int i=0; i<n; i++)	
	{
		cin >> arr[i];
	}	
	sort(arr, arr+n);
	pref[0] = arr[0];
	for (int i=1; i<n; i++)
		pref[i] = (pref[i-1]+arr[i])%MOD;
	suf[n-1] = arr[n-1];
	for (int i=n-2; i>=0; i--)
		suf[i] = (suf[i+1]+arr[i])%MOD;
	int res=0;
	for (int diff=k-1; diff<n; diff++)
	{
		int mn = min(diff, n-diff);
		int sm = (MOD+suf[n-mn]-pref[mn-1])%MOD;
		int x = (sm*c(diff-1, k-2))%MOD;
		res = (res+x)%MOD;
	}	
	cout << res;
	return 0;
}



Measured memory_bytes: 4096
#include<iostream>

 int main() {
  int n,t,i,costmin;
  costmin=-1;
  std::cin >> n;
  std::cin >> t;
  int cost,times;
  for(i=0;i<n;i++){
    std::cin >> cost;
    std::cin >> times;
    if(times<=t){
      if(costmin==-1){
        costmin=cost;
      }else if (costmin>cost) {
        costmin=cost;
      }
    }
  }
  if (costmin==-1) {
    std::cout << "TLE" << '\n';
    return 0;
  }
  std::cout << costmin << '\n';
  return 0;
}

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

int main(void)
{
  int N;
  int M;
  int A;

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

  if (N - sum >= 0)
  {
    cout << N - sum << endl;
  }
  else
  {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int D = sc.nextInt();
        int x2000 = sc.nextInt();

        int curX;
        int prevX = x2000;
        for (int i = 2001; i <= 2010; i++) {
            curX = r * prevX - D;
            System.out.println(curX);
            prevX = curX;
        }
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

Measured memory_bytes: 25300
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll=long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template<typename T>
vector<T> zeta(const vector<T> &A, int n){
  vector<T> ret = A;
  for(int i=1;i<(1<<n);i<<=1){
    for(int j=0;j<(1<<n);j++){
      if((j&i) == 0){ret[j] += ret[j|i];}
    }
  }
  return ret;
}

template<typename T>
vector<T> zeta2(const vector<T> &A, int n){
  vector<T> ret = A;
  for(int i=1;i<(1<<n);i<<=1){
    for(int j=0;j<(1<<n);j++){
      if((j&i) == 0){ret[j|i] += ret[j];}
    }
  }
  return ret;
}
//INSERT ABOVE HERE

signed main(){
  ll N;
  cin>>N;
  vector<int> A(1LL<<N);
  for(auto &I:A){cin>>I;}
  vector<int> B=zeta(A,N);
  for(int i=0;i<(1<<N);i++){
    if(A[i]==1 && B[i]!=(1LL<<(N-__builtin_popcount(i)))){
      cout<<-1<<endl;
      return 0;
    }
  }
  vector<int> C=zeta2(A,N);
  int ans=0;
  for(int i=0;i<(1<<N);i++){
    if(C[i]==1){ans++;}
  }
  cout<<ans<<endl;

  return 0;
}



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

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

using namespace std;

typedef long long ll;

int main()
{
    string S;
    cin >> S;
    string ans;
    if (S[2] == S[3] && S[4] == S[5]) ans ="Yes";
    else ans = "No";

    cout << ans << endl;
}


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

int main()
{
  string s;
  cin >> s;
  int c = 0;
  int a[4];
  for (int i = 0; i < 4; i++)
  {
    a[i] = 0;
  }
  string b[4], ans;

  for (int i = 1; i < 4; i++)
  {
    if (s[0] == s[i])
    {
      a[0] = 1;
      a[i] = 1;
    }
  }
  for (int i = 0; i < 4; i++)
  {
    if (a[i] == 0)
    {
      c++;
      b[c - 1] = s[i];
    }
  }
  ans = (c == 2 && b[0] == b[1]) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}

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;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
 
const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;
 
int main() {
  int n;
  cin >> n;

  vl a(n, 0);
  rep(i, n) {
    cin >> a[i];
  }

  vl b(n, 0);
  vl b_ind(n, 0);
  int box_ind = 0;

  for(int i = n; i >= 1; i--) {
    bool box = false;
    if (i > (n / 2)) {
      if (a[i-1] == 1) {
        box = true;
      }
    } else {
      int sum = 0;
      for(int j = 2; j <= (n / i); j++) {
        sum += b[(i * j)-1];
      }
      if ((sum % 2) != a[i-1]) {
        box = true;
      }
      // cout << i << ": " << sum << " " << box << endl;
    }

    if (box) {
      b[i-1] = 1;
      b_ind[box_ind] = i;
      box_ind += 1;
    }
  }


  if (box_ind == 0) {
    cout << 0 << endl;
  } else {
    cout << box_ind << endl;
    rep(i, box_ind) {
      cout << b_ind[i] << " ";
    }
  }

  return 0;
}

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

int main(){
    int r, g, b;
    cin >> r >> g >> b ;
    if (b==0 && g==0 && r==0){
        cout << "NO" << endl;
    }else if (b%2==1){
        cout << "NO" << endl;
    }else if(g%2==0&&b%4==0){
        cout << "YES" << endl;
    }else if(g%2==1&&b%4==2){
        cout << "YES" << endl;
    }else if(g%2==0&&b%4==2){
        cout << "NO" << endl;
    }else if(g%2==1&&b%4==0){
        cout << "NO" << endl;
    }
    
}

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

using namespace std;


template< typename T >
struct edge
{
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

template< typename G >
struct LowLink
{
  const G &g;
  vector< int > used, ord, low, parent;

  LowLink(const G &g) : g(g), used(g.size()), ord(g.size()), low(g.size()), parent(g.size(), -1) {}

  void dfs(int idx, int &k, int par = -1)
  {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];

    for(auto &to : g[idx]) {
      if(!used[to]) {
        dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        parent[to] = idx;
      } else if(to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
  }

  void dfs()
  {
    int k = 0;
    dfs(0, k);
  }
};

template< typename G >
struct ArticulationPoints : LowLink< G >
{
  using LL = LowLink< G >;

  ArticulationPoints(const G &g) : LL(g) {}

  vector< int > build()
  {
    LL::dfs();
    vector< int > vs;
    int sum = 0;
    for(int i = LL::g.size() - 1; i >= 1; i--) {
      if(LL::parent[i] == 0) ++sum;
      else if(LL::ord[LL::parent[i]] <= LL::low[i]) {
        vs.emplace_back(LL::parent[i]);
      }
    }
    if(sum > 1) vs.push_back(0);
    sort(begin(vs), end(vs));
    vs.erase(unique(begin(vs), end(vs)), end(vs));
    return (vs);
  }
};

int main()
{
  int V, E;
  cin >> V >> E;
  WeightedGraph< int > g(V);
  while(E--) {
    int a, b;
    cin >> a >> b;
    g[a].emplace_back(b, 1);
    g[b].emplace_back(a, 1);
  }
  ArticulationPoints< WeightedGraph< int > > ap(g);
  for(auto &k : ap.build()) cout << k << endl;
}


Measured memory_bytes: 5576
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		long[] ans = new long[W.length()];
		Arrays.fill(ans, 0);
		int indexL=0;
		int indexR=0;

		long countR=0;
		long countL=0;

		long befIndx=0;
		for(int i=0;i<W.length();i++){

			if(i!=0 && W.charAt(i)=='R' && W.charAt(i-1)=='L'){
				if((countL+countR)%2==0){
					ans[indexR]=(countL+countR)/2;
					ans[indexL]=(countL+countR)/2;
				}else{
					if((indexR-befIndx)%2==1){
						//RLのRが奇数の場合
						ans[indexR]=(countR+countL)/2 ;
						ans[indexL]=(countR+countL)/2 +1;
					}else{
						ans[indexR]=(countR+countL)/2 +1;
						ans[indexL]=(countR+countL)/2 ;

					}
				}

				countR=0;
				countL=0;
				befIndx=i;
			}

			if(W.charAt(i)=='R'){
				countR++;
				indexR=i;
			}else{
				countL++;
				indexL=indexR+1;
			}
		}

		if((countL+countR)%2==0){
			ans[indexR]=(countL+countR)/2;
			ans[indexL]=(countL+countR)/2;
		}else{
			if((indexR-befIndx)%2==1){
				//RLのRが奇数の場合
				ans[indexR]=(countR+countL)/2 ;
				ans[indexL]=(countR+countL)/2 +1;
			}else{
				ans[indexR]=(countR+countL)/2 +1;
				ans[indexL]=(countR+countL)/2 ;

			}
		}

		StringBuffer sb = new StringBuffer();
		for(int i=0;i<ans.length;i++){
			sb.append(ans[i]+" ");
		}
		sb.deleteCharAt(sb.length()-1);

		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 39924
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
signed main(){
	string s;
	cin>>s;
	string t="keyence";
	if(s==t){
		puts("YES");
		return 0;
	}
	rep(i,s.size()){
		for(int j=i;j<s.size();j++){
			string a="";
			rep(k,s.size()){
				if(k<i||j<k)a+=s[k];
			}
			if(a==t){
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll h, n;
    cin >> h >> n;
    
    vl a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    
    vvl dp(n+1, vl(h+1, INF));  // dp[i+1][j] : i番目の魔法まででj以上ダメージを与えるときの魔力の総和の最小値
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, h+1) {
            chmin(dp[i+1][j], dp[i][j]);
            if(j + a[i] <= h) {
                chmin(dp[i+1][j + a[i]], dp[i+1][j] + b[i]);
            }
            else {
                chmin(dp[i+1][h], dp[i+1][j] + b[i]);
            }
        }
    }
    
    out(dp[n][h]);
    re0;
}

Measured memory_bytes: 78592
from collections import Counter
H, W = map(int,input().split())
d = Counter()
for _ in range(H):
  d.update(list(input()))

# check palindrome
def main():
  num1 = (H*W) % 2 
  num2 = (W % 2)*H//2 + (H % 2)*W//2
  num4 = ((H*W) - num1 - num2*2)//4
  #print(num1,num2,num4)

  check1 = sum([val % 2 for key,val in d.items()])
  #print(check1)
  if check1 != num1:
    return False
  
  check4 = 0
  for key,val in d.items():
    if val >= 4:
      deduct = min(num4-check4,val//4)
      d[key] = val - deduct*4
      check4 += deduct
      
      if check4 == num4:
        break
    
  #print(check4)
  if check4 != num4:
    return False
  
  check2 = sum([val//2 for key,val in d.items()])
  #print(check2)
  if check2 != num2:
    return False
      
  return True
      
  
ans = main()
if ans:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9476
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

string s;
int a[100005];
vector<int>vec;
int main(){
	cin >> s;
	int n = s.size();
	rep(i,n){
		if(i == 0) a[i] = s[i]-'0';
		else a[i] = s[i] - s[i-1];
	}
	a[n] = s[n-1]-'0';
	
	rep(i,n+1) if(a[i]) vec.pb(i);
	
	int L = 0, R = n,ans = 0;
	for(int i=0;;i++){
		L++; R--;
		int a = POSL(vec,L);
		if(a < vec.size() && vec[a] <= R){
			ans++;
		}
		else{
			cout << n-ans << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int f(int x,int k)
{
	if(x%k==0)return x/k;
	else if(x<k)return 0;
	int t=x/k+1;
	x-=(x%k+t-1)/t*t;
	return f(x,k);
}
main()
{
	int N,s=0;cin>>N;
	for(int i=0;i<N;i++)
	{
		int a,k;cin>>a>>k;
		s^=f(a,k);
	}
	cout<<(s?"Takahashi":"Aoki")<<endl;
}

Measured memory_bytes: 256