akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

struct UnionFind {
    vector<int> d;

    UnionFind(int n = 0) : d(n, -1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }

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

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return -d[find(x)]; }
};

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

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int func(vector<int> &A, vector<int> &B, int k) {
    int res = 0;
    vector<ll> a(A.size() + 1), b(B.size() + 1);
    for (int i = 0; i < A.size(); ++i) a[i + 1] = a[i] + A[i];
    for (int i = 0; i < B.size(); ++i) b[i + 1] = b[i] + B[i];
    int j = B.size();
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] > k)break;
        while (b[j] > k - a[i])j--;
        res = max(i + j, res);
    }
    return res;
}

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> A(n), B(m);
    for (int i = 0; i < n; ++i) cin >> A[i];
    for (int i = 0; i < m; ++i) cin >> B[i];
    int ans = 0;
    ans = max(ans, func(A, B, k));
    ans = max(ans, func(B, A, k));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc134_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<int> c(N);
  rep(i, N) { cin >> c[i]; }
  vector<int> sorted(c.begin(), c.end());

  sort(sorted.begin(), sorted.end(), greater<int>());

  rep(i, N) {
    int a = c[i];
    if (a == sorted[0])
      cout << sorted[1] << endl;
    else
      cout << sorted[0] << endl;
  }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll k,a,b;
  cin >>k>>a>>b;
  if(b-a<2) cout <<k+1<<endl;
  else {
     ll sum=a;
     k-=(a-1);//a枚になるまで使った残り回数
     if(k%2==1) sum++,k--;
     sum+=(b-a)*(k/2);
     cout <<sum<<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        
        int X;
        
        if(A > B){
            X = A;
            A = B;
            B = X;
        }
        
        if(B > C){
            X = B;
            B = C;
            C = X;
        }
        
        for(int i = 0; i < K; i++){
            C = C * 2;
        }
        
       System.out.println(A + B + C);
    }
}

Measured memory_bytes: 21716
//2018-01-07
//LZYeah
//
#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define Forr(i,a,b) for(register int i=a;i>=b;i--)
using namespace std;
inline void File()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
inline void read(int &x)
{
	int p=1;
	x=0;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+(c^'0');c=getchar();}
	x*=p;
}
#define N 100010
struct node
{
	int a,b;
}o[N*2];
int n,h,tot,cnt;
inline int cmp(node x,node y){return x.a>y.a;}
int main()
{
//	File();
	read(n),read(h);
	For(i,1,n)o[i+n].b=1;
	For(i,1,n)read(o[i].a),read(o[i+n].a);
	sort(o+1,o+1+n*2,cmp);
	For(i,1,2*n)
	{
		if(tot>=h)break;
		if(o[i].b==1)
		{
			tot+=o[i].a;
			cnt+=1;
		}
		else
		{
			int res=h-tot;
			tot=h;
			cnt+=res/o[i].a;
			if(res%o[i].a!=0)cnt+=1;
			break;
		}
	}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 1792
object Main {

  object Scanner {
    private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
    @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
    @inline private def hasNextByte(): Boolean =
      if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
    @inline private def hasNext(): Boolean = {
      while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
      hasNextByte()
    }
    @inline private def readByte(): Byte =
      if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
    def next(): String = {
      if(!hasNext()) ???
      val sb = new StringBuilder; var b = readByte()
      while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
      sb.toString
    }
    def nextInt(): Int = {
      val n = nextLong()
      if (n < Int.MinValue || Int.MaxValue < n) ???
      n.toInt
    }
    def nextLong(): Long = {
      if(!hasNext()) ???
      var minus = false; var b = readByte()
      if (b == '-') { minus = true; b = readByte() }
      def go (b: Byte, n: Long = 0): Long =
        if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
        else if (minus) { -n } else { n }
      go(b)
    }
    def nextDouble(): Double = next.toDouble
  }

  def main(args: Array[String]): Unit = {
    val H, W = Scanner.nextInt()
    val S = Array.fill(H)(Scanner.next())
    val dph = Array.fill[Short](H, W)(-1) // 未計算の場合-1, dp(i)(j)(0) 縦の数 dp(i)(j)(1)横の数
    val dpw = Array.fill[Short](H, W)(-1)
    var i = 0
    while (i < H) {
      var j = 0
      while (j < W) {
        if (S(i)(j) == '.') { // 障害物ではない場合
          if (dph(i)(j) == -1) { // 縦方向未計算の場合のみ計算
            var di = 0
            while (i + di < H && S(i+di)(j) == '.') { // 障害物に当たるか壁に当たるかまで
              di += 1
            }
            var dii = 0
            val hoge = (di - 1).toShort
            while (dii < di) {
              dph(i+dii)(j) = hoge
              dii += 1
            }
          }
          if (dpw(i)(j) == -1) { // 横方向未計算の場合のみ計算
            var dj = 0
            while (j + dj < W && S(i)(j+dj) == '.') { // 障害物に当たるか壁に当たるかまで
              dj += 1
            }
            var djj = 0
            val hoge = (dj - 1).toShort
            while (djj < dj) {
              dpw(i)(j+djj) = hoge
              djj += 1
            }
          }
        }
        j += 1
      }
      i += 1
    }

    var max = 0
    i = 0
    while (i < H) {
      var j = 0
      while (j < W) {
        if (S(i)(j) == '.') { // 障害物ではない場合
          max = Math.max(max, dph(i)(j) + dpw(i)(j) + 1)
        }
        j += 1
      }
      i += 1
    }
    println(max)
  }

}



Measured memory_bytes: 72656
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int int64_t

signed main(){
	int n,l;cin>>n>>l;
	vector<int> v(n);
	rep(i,n)cin>>v[i];
	int start=-1;
	rep(i,n-1){
		if(v[i]+v[i+1]>=l)start=i;
	}
	if(start==-1){cout<<"Impossible"<<endl;return 0;}
	cout<<"Possible"<<endl;
	for(int i=0; i<start; i++){
		cout<<i+1<<endl;
	}
	for(int i=n-1; i>start+1; i--){
		cout<<i<<endl;
	}
	cout<<start+1<<endl;
}

Measured memory_bytes: 1664
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($N,$M) =  explode(" ",trim(fgets(STDIN)));
//$A = explode(" ",trim(fgets(STDIN)));
$jp=0;
$bt=0;
for($i=0;$i<$N;$i++) {
  $A = explode(" ",trim(fgets(STDIN)));
  if ($A[1]=="JPY") {
    $jp+=$A[0];
  }
  else {
    $bt+=$A[0];
  }
}
printf("%f\n",$jp+($bt*380000.0));


Measured memory_bytes: 4728
A = [0] * 5
for i in range(5):
    A[i] = int(input())

from itertools import permutations

Z = list(range(5))

Z = list(permutations(Z))

ans = float("inf")
for z in Z:
    time = 0
    for i,x in enumerate(z):
        time += A[x]
        if i == 4:
            break
        while time % 10 != 0:
            time += 1
    ans = min(ans, time)

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
using ll = long long;

using pii = pair<ll, ll>;
ll n, k;
pii s[100000];
vector<ll> u, v;
int main() {
	scanf("%lld %lld", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%lld %lld", &s[i].first, &s[i].second);
	sort(s, s + n);
	for (int i = 0; i < n; i++) {
		if (n <= i + 1 || s[i].first != s[i + 1].first)
			u.emplace_back(s[i].second);
		else
			v.emplace_back(s[i].second);
	}
	sort(u.begin(), u.end(), greater<ll>());
	sort(v.begin(), v.end(), greater<ll>());
	priority_queue<ll> hoketu;
	while (k < u.size() + v.size()) {
		if (v.empty()) {
			hoketu.emplace(u.back());
			u.pop_back();
		}
		else {
			hoketu.emplace(v.back());
			v.pop_back();
		}
	}

	ll max_r = 0, cur = 0;
	for (ll e : u)
		cur += e;
	for (ll e : v)
		cur += e;
	while (!u.empty()) {
		max_r = max(max_r, cur + ((ll)u.size()) * ((ll)u.size()));
		cur -= u.back();
		hoketu.emplace(u.back());
		u.pop_back();

		cur += hoketu.top();
		hoketu.pop();
	}
	printf("%lld\n", max(max_r, cur));
}

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

g = [[-1]*N for i in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = [int(n) for n in input().split(' ')]
        g[i][x-1] = y

ans = 0
for i in range(1<<N):
    d = [0]*N
    for j in range(N):
        if i>>j&1:
            d[j]=1
    ok = True
    for j in range(N):
        if d[j]:
            for k in range(N):
                if g[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok=False
    if ok:
        ans = max(ans, bin(i).count("1"))

print(ans)
        


Measured memory_bytes: 3064
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from math import gcd
    input = sys.stdin.readline

    NN = 10**6
    prime = [[] for _ in range(NN+1)]
    is_prime = [1] * (NN+1)
    is_prime[1] = 0
    for i in range(2, NN+1):
        if not is_prime[i]:
            continue
        prime[i].append(i)
        for j in range(2, NN+1):
            if i*j > NN:
                break
            is_prime[i*j] = 0
            prime[i*j].append(i)

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

    P = 1
    g = A[0]
    seen = [0] * (NN+1)
    for a in A:
        g = gcd(g, a)
        for p in prime[a]:
            if seen[p]:
                P = 0
            seen[p] = 1
    if g != 1:
        print("not coprime")
    else:
        if P == 1:
            print("pairwise coprime")
        else:
            print("setwise coprime")


if __name__ == '__main__':
    main()


Measured memory_bytes: 311164
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  ll x = 0, n;
  string s;
  cin >> n >> s;

  ll ans = 0;
  rep(i, (ll)s.size()) {
    if (s[i] == 'I') {
      x++;
      chmax(ans, x);
    } else
      x--;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c[10000], i, j;
	char op;
	
	for (i = 0;;  i++) {
		scanf("%d %c %d", &a, &op, &b);
		if (op == '?') {
			break;
		} else if (op == '+') {
			c[i] = a + b;
		} else if (op == '-') {
			c[i] = a - b;
		} else if (op == '*') {
			c[i] = a * b;
		} else if (op == '/') {
			c[i] = a / b;
		}
	}
	for (j = 0; j < i; j++) {
		printf("%d\n", c[j]);
	}
	return 0;
}



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

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         int N=gi();
         int[] a=new int[N];

         for(int i=0; i<N;i++) {
        	 a[i]=gi();
          }

         Arrays.parallelSort(a);

         if(N%3==0) {
        	 int a1=a[0];
        	 int a2=a[N/3];
        	 int a3=a[N*2/3];
        	 int[] as= {a1,a2,a3};
        	 int t=a1^a2^a3;
        	 if(t!=0) {
    		     System.out.println("No");
    		     return;
    	     }
             for(int i=0; i<3;i++) {
            	 for(int j=i*N/3; j<(i+1)*N/3;j++) {
            	     if(as[i]!=a[j]) {
            		     System.out.println("No");
            		     return;
            	     }
                  }
              }
         } else {
        	 for(int i=0; i<N;i++) {
        	     if(a[i]!=0) {
        		     System.out.println("No");
        		     return;
        	     }
              }
         }

         System.out.println("Yes");
     }


     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define f first
#define s second

#define all(s) s.begin(),s.end()
#define spresent(s,v) ((s).find(v)!=s.end())
#define present(s,v) (find(all(s),v)!=s.end())

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)

#define dout(i,s) cout<<"Case "<<i<<": "<<s<<"\n"

typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;

// typedef struct{
// 	int ind;
// 	bool cl=true;
// }guest;


const int M = 998244353;

int main(){

	int m,d;
	cin>>m>>d;
	int cnt=0;

	for(int i=22;i<=d;++i){
		int j=i/10, k=i%10;
		if(j>=2 && k>=2 && j*k<=m)
			++cnt;
	}

	cout<<cnt;





	return 0;
}







Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int p,q,r;
    scanf("%d %d %d",&p,&q,&r);
    if(p+q <= p+r && p+q <=q+r){
        printf("%d\n",p+q);
    }
    else if(p+r <= p+q && p+r <= q+r){
        printf("%d\n",p+r);
    }
    else{
        printf("%d\n",q+r);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;



int main(){
	int d[4][2];
	while(cin>>d[0][0]>>d[1][0]>>d[2][0]>>d[3][0]>>d[0][1]>>d[1][1]>>d[2][1]>>d[3][1]){
		int h=0,b=0;
		
		for(int i=0;i<4;i++){
			if(d[i][0]==d[i][1])h++;
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				
				if(d[i][0]==d[j][1] && i!=j)b++;
			}
		}
		cout<<h<<" "<<b<<endl;
	}
}

Measured memory_bytes: 1160
N = int(input())
if N <= 9:
  print(N)
elif N >= 10 and N <= 99:
  print(9)
elif N >= 100 and N <= 999:
  print(9+N-100+1)
elif N >= 1000 and N <= 9999:
  print(909)
elif N >= 10000 and N <= 99999:
  print(909+N-10000+1)
elif N == 100000:
  print(90909)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <bitset>
#include <algorithm>

int main(int argc, char *argv[]) {
    std::string s;
    std::cin >> s;
    std::reverse(s.begin(), s.end());
    const auto len = s.length();
    int64_t result{};
    for (uint64_t pattern = 0; pattern < (1ULL << len - 1); pattern++) {
        int64_t digit = 1;
        std::bitset<32> bits(pattern);
        for (size_t i = 0; i < len; i++) {
            result += digit * (s[i] - '0');
            digit = (bits[i]) ? 1 : digit * 10;
        }
    }
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()
// #pragma comment(linker, "/stack:2000000000")
 
typedef long long ll;
 
typedef long double ld;
 
using namespace std;
 
const ll maxn = 1e6;
const ll inf = 1e9;
 
ll n, m, k, t;

int main() {
    ll q, w, e, a, b, c, d;
    string s;
    cin >> a >> b;
    if (a == 1 || b == 1) {
        cout << 1;
        return 0;
    }
    cout << (a * b + 1) / 2;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long INF = 2_000_000_000_000_000_000L;
        int N = Integer.parseInt(sc.next());
        long C = Long.parseLong(sc.next());
        long[] x = new long[2*N];
        long[] v = new long[2*N];
        for (int i=0;i<N;i++) {
            x[i] = Long.parseLong(sc.next());
            x[i+N] = x[i]+C;
            v[i] = Long.parseLong(sc.next());
            v[i+N] = v[i];
        }
        long[] profit = new long[2*N];
        profit[N-1] = v[N-1]-(C-x[N-1]);
        profit[N] = v[N]-(x[N]-C);
        for (int i=N-2;i>=0;i--) {
            profit[i] = profit[i+1] + v[i]-(x[i+1]-x[i]);
        }
        for (int i=N+1;i<2*N;i++) {
            profit[i] = profit[i-1] + v[i]-(x[i]-x[i-1]);
        }

        // serach index
        int[] max_index = new int[2*N];
        max_index[N]=N;
        max_index[N-1]=N-1;
        for (int i=N+1;i<2*N;i++) {
            if (profit[max_index[i-1]]<profit[i]) {
                max_index[i]=i;
            } else {
                max_index[i]=max_index[i-1];
            }
        }
        for (int i=N-2;i>=0;i--) {
            if (profit[max_index[i+1]]<profit[i]) {
                max_index[i]=i;
            } else {
                max_index[i]=max_index[i+1];
            }
        }

        long ans=0L;
        ans = Math.max(ans, profit[2*N-1]);
        ans = Math.max(ans, profit[0]);
        for (int i=N;i<2*N-1;i++) {
            long tmp = profit[i];
            ans = Math.max(ans, tmp);
            ans = Math.max(ans, tmp+profit[max_index[i-N+1]]-(x[i]-C));
        }
        for (int i=N-1;i>0;i--) {
            long tmp = profit[i];
            ans = Math.max(ans, tmp);
            ans = Math.max(ans, tmp+profit[max_index[i+N-1]]-(C-x[i]));
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 63508
#include<stdio.h>
int search(int a[],int n,int key){
  int i;
  for(i=0;i<n;i++){
    if(a[i]==key)
      return 1;
  }
  return 0;
}
int main(){
  int i,n,m,a[10000],key;
  int sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&key);
    if(search(a,n,key)==1){
      sum++;
    }
  }
    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 2080
#include<iostream>
#include<algorithm>
#include<map>
#include<math.h>
#include<set>
#include<string>
#include<vector>
using namespace std;

#define int long long

void fastio()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	fastio();
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	int s = 0;
	for (int i = 0; i < k; ++i)
	{
		s = s + a[i];
	}
	cout << s;

	return 0;
}


Measured memory_bytes: 3196
n,m=map(int, input().split())
ac,wa=0,0
if m==0:
    print(ac,wa)
else: #一度飛ばして新たな問題を解いたうえで戻ってくる場合があるのか？
    l=[0]*n #正解処理の配列
    r=[0]*n #誤答カウンター
    for i in range(m):
        pa,s=map(str, input().split())
        p=int(pa)
        if l[p-1]==0 and s=='AC': #初正解時の処理
            l[p-1]=1
            ac+=1
        elif l[p-1]==0 and s=='WA': #誤答時の処理
            r[p-1]+=1
        else:
            continue
    for i in range(n):
        if l[i]==1:
            wa+=r[i]
        else:
            continue
    print(ac,wa)

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

void solve() 
{
    ll n,a,b;cin>>n>>a>>b;
    ll sum=a+b;
    if(sum==0){cout<<0<<endl;return;}
    ll ans=n/sum;
    ans*=a;
    ll r=n%sum;
    if(r>a)ans+=a;
    else ans+=r;
    cout<<ans<<endl;
}

int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define MOD 1000000007

ll fac[2222222];
ll invfac[2222222];

ll extGCD(ll a, ll b, ll &x, ll &y){
	if(b==0){
		y=0;x=1;
		return a;
	}
	ll d=extGCD(b, a%b, y, x);
	y -= ((a/b)*x)%MOD;
	y%=MOD;
	return d;
}

ll modinv(ll a, ll p)
{
	ll x, y;
	extGCD(a, p, x, y);
	return (x%p+p)%p;
}

void init()
{
	fac[0]=1;
	FOR(i, 1, 2222221){
		fac[i] = (fac[i-1]*i)%MOD;
	}
	invfac[2222221] = modinv(fac[2222221], MOD);
	RREP(i, 2222221){
		invfac[i]=(invfac[i+1]*(i+1))%MOD;
	}
}

ll comb(ll a, ll b){
	if(a<b)return 0;
	return (((fac[a]*invfac[a-b])%MOD)*invfac[b])%MOD;
}

signed main()
{
	init();
	ll r1, r2, c1, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	ll g11, g12, g21, g22;
	g11=0;
	REP(i, c1){
		g11+=comb(r1-1+i+1, r1-1);
		g11%=MOD;
	}
	g12 = 0;
	REP(i, c2+1){
		g12+=comb(r1-1+i+1, r1-1);
		g12%=MOD;
	}
	g21 = 0;
	REP(i, c1){
		g21+=comb(r2+i+1, r2);
		g21%=MOD;
	}
	g22 = 0;
	REP(i, c2+1){
		g22+=comb(r2+i+1, r2);
		g22%=MOD;
	}
	cout << ((g22-g21-g12+g11)%MOD+MOD)%MOD << endl;
}


Measured memory_bytes: 34944
#!/usr/bin/env python3
import sys


def solve(a: int, b: int, c: int, d: int, e: int, k: int):
    print('Yay!' if e - a <= k else ':(')



# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    e = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(a, b, c, d, e, k)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9156
#include<iostream>
#include<string>
#define INFTY (1<<20)
#define MAX 51
using namespace std;

int H, W;
int D[MAX][MAX], L[MAX][MAX];

void compute(){
    for ( int i = 1; i <= H; i++ ) {
        for ( int j = 1; j <= W; j++ ) {
            if ( i * j == 1 ) L[i][j] = 0;
            else L[i][j] = D[i][j] + min(L[i - 1][j], L[i][j - 1]);
        }
    }
    return;
}

int main(){
    cin >> H >> W;
    for ( int i = 0; i <= H; i++ ) L[i][0] = INFTY;
    for ( int i = 0; i <= W; i++ )  L[0][i] = INFTY;
    for ( int i = 1; i <= H; i++ ) {
        string s; cin >> s;
        for ( int j = 1; j <= W; j++ ) {
            D[i][j] = s[j - 1] - '0';
        }
    }
    
    compute();
    cout << L[H][W] << endl;
    return 0;
}


Measured memory_bytes: 3248
//https://qiita.com/wing-x/items/187e988125a3bd7b2b32
/*
"2 5\n"と入力するとsc.nextInt()は2, 5のみを読み取り、scに\nが残る.
nextLint()はその\nを読み取るから、実質的にnextLine()を5本用意しても
文字列入力を受け付けるのは4本になってしまう.
よって, \nを片付けるためにblankを使う
*/

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    String blank = sc.nextLine();
    char[][] array1 = new char[h][w];
    List<Integer> arylist = new ArrayList<>();

    for(int i = 0; i < h; i++){
      String s = sc.nextLine();
      array1[i] = s.toCharArray();
    }

    for(int i = 0; i < h; i++){
      boolean flag = true;
      char standard = 's';
      for(int j = 0; j < w; j++){
        if(j == 0){
          standard = array1[i][j];
          if(standard != '.'){
            flag = false;
            break;
          }
        }
        else if(standard != array1[i][j]){
          flag = false;
          break;
        }
      }
      if(flag == false){
        arylist.add(i);
      }
    }
    //System.out.println(arylist.size());


    char[][] array2 = new char[w][arylist.size()];
    for(int i = 0; i < w; i++){
      for(int j = 0; j < arylist.size(); j++){
        char tmp = array1[arylist.get(j)][i];
        array2[i][j] = tmp;
      }
    }

    /*for(int i = 0; i < w; i++){
      for(int j = 0; j < arylist.size(); j++){
        System.out.print(array2[i][j]);
      }
      System.out.println("");

    }*/

    //System.out.println("/////////////////");

    int size = arylist.size();
    arylist.clear();
    for(int i = 0; i < w; i++){
      boolean flag = true;
      char standard = 's';
      for(int j = 0; j < size; j++){
        if(j == 0){
          standard = array2[i][j];
          if(standard != '.'){
            flag = false;
            break;
          }
        }
        else if(standard != array2[i][j]){
          flag = false;
          break;
        }
      }
      if(flag == false){
        arylist.add(i);
      }
    }

    char[][] array3 = new char[size][arylist.size()];
    for(int i = 0; i < size; i++){
      for(int j = 0; j < arylist.size(); j++){
        char tmp = array2[arylist.get(j)][i];
        array3[i][j] = tmp;
        System.out.print(array3[i][j]);
      }
      System.out.println("");
    }


  }
}



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

double distance(int d, int* xi, int* xj){
    double ans = 0;
    for(int i=0; i<d; i++){
        ans += (xi[i]-xj[i])*(xi[i]-xj[i]);
    }
    ans = sqrt(ans);
    return ans;
}

int main(void){
    int i, j, n, d;
    int **x;
    cin >> n >> d;
    x = new int*[n];
    x[0] = new int[n*d];
    for(i=0; i<n; i++){
        x[i] = x[0] + i*d;
    }
    for(i=0; i<n; i++){
        for(j=0; j<d; j++){
            cin >> x[i][j];
        }
    }
    // compute
    int count = 0;
    double dist;
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            dist = distance(d, x[i], x[j]);
            if(dist-int(dist) == 0){
                count++;
            }
        }
    }
    cout << count << endl;
     return 0;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

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



int main(){
    int N;
    string str;
    cin >> str;
    N = str.length();
    vector<int> L(N + 1, 0), R(N + 1, 0);
    for(int i = 1; i < N + 1; i++){ 
        if(str[i - 1] == '<'){
            L[i] = L[i - 1] + 1;
        }else{
            L[i] = 0;
        }
    }
    for(int i = N - 1; i > 0; i--){ 
        if(str[i] == '>'){
            R[i] = R[i + 1] + 1;
        }else{
            R[i] = 0;
        }
    }
    if(str[0] == '>') R[0] = R[1] + 1;
    ll ans = 0;
    rep(i, N + 1) ans += max(L[i],R[i]);
    cout << ans << endl;
}

Measured memory_bytes: 4740
/*
 *    author:  Gary Shih
 *    created: 2020-05-07 15:29:12
 */
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
  int n;
  cin >> n;
  vector<tuple<int, int, int, int>> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> get<1>(a[i]) >> get<2>(a[i]) >> get<3>(a[i]);
    get<0>(a[i]) = get<1>(a[i]) + get<2>(a[i]);
  }
  sort(a.rbegin(), a.rend());
  vector<long long> dp(2e4 + 1);
  for (int i = 0; i < n; ++i) {
    int w = get<1>(a[i]), s = get<2>(a[i]), v = get<3>(a[i]);
    for (int j = 0; j <= s; ++j)
      if (j + w < (int)dp.size()) dp[j] = max(dp[j], dp[j + w] + v);
    for (int j = dp.size() - 2; j >= 0; --j) dp[j] = max(dp[j], dp[j + 1]);
  }
  cout << dp[0] << '\n';
}


Measured memory_bytes: 384
fun main(args: Array<String>) = yorukatsu13d()

fun yorukatsu13d() {
    val n = readLine()!!.toLong()

    val list = setOf('3', '5', '7')

    var answer = 0

    fun dfs(num: String) {
        if (num.isNotEmpty() && num.toLong() > n) return
        if (num.isNotEmpty() && num.toSet() == list) answer++
        for (c in list) dfs(num + c)
    }

    dfs("")

    println(answer)
}


Measured memory_bytes: 43552
#include <iostream>
#include <random>
#include <algorithm>
# define Die_not_equal_auth die.A_One != auth.A_One || die.B_Two != auth.B_Two ||die.C_Three != auth.C_Three || die.D_Four != auth.D_Four ||die.E_Five != auth.E_Five || die.F_Six != auth.F_Six
const int HOUSES = 4;
const int STORIES = 3;
const int ROOMS = 10;
int house[HOUSES][STORIES][ROOMS];
struct Die
{
	int A_One;
	int B_Two;
	int C_Three;
	int D_Four;
	int E_Five;
	int F_Six;
};
Die GoNorth(Die pips)
{
	int tmp = pips.A_One;
	pips.A_One = pips.B_Two;
	pips.B_Two = pips.F_Six;
	pips.F_Six = pips.E_Five;
	pips.E_Five = tmp;
	return pips;
}
Die GoSouth(Die pips)
{
	int tmp = pips.A_One;
	pips.A_One = pips.E_Five;
	pips.E_Five = pips.F_Six;
	pips.F_Six = pips.B_Two;
	pips.B_Two = tmp;
	return pips;
}
Die GoEast(Die pips)
{
	int tmp = pips.D_Four;
	pips.D_Four = pips.F_Six;
	pips.F_Six = pips.C_Three;
	pips.C_Three = pips.A_One;
	pips.A_One = tmp;
	return pips;
}
Die GoWest(Die pips)
{
	int tmp = pips.A_One;
	pips.A_One = pips.C_Three;
	pips.C_Three = pips.F_Six;
	pips.F_Six = pips.D_Four;
	pips.D_Four = tmp;
	return pips;
}
Die Roll(Die die, char c)
{
	if (c == 'N')
	{
		die = GoNorth(die);
	}
	else if (c == 'W')
	{
		die = GoWest(die);
	}
	else if (c == 'S')
	{
		die = GoSouth(die);
	}
	else
	{
		die = GoEast(die);
	}
	return die;
}
Die RandomShake(Die die)
{
	std::random_device rnd;
	if (rnd() % 2 == 1)
	{
		return GoNorth(die);
	}
	else
	{
		return GoWest(die);
	}
}
std::string authDice(Die auth, Die die)
{
	for (auto i = 0;Die_not_equal_auth;++i)
	{
		die = RandomShake(die);
		if (i == 1000)
		{
			return "No";
		}
	}
	return "Yes";
}
int main()
{
	int a, b, c, d, e, f, g, h, i, j, k, l;
	std::cin >> a >> b >> c >> d >> e >> f;
	std::cin >> g >> h >> i >> j >> k >> l;
	Die auth{ a,b,c,d,e,f };
	Die die{ g,h,i,j,k,l };
	std::cout << authDice(die, auth) << std::endl;;
	return 0;
}


Measured memory_bytes: 3180
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int n = input.nextInt();
        int[] ar = new int[n];
        for(int i = 0; i < n; i++){
            ar[i] = input.nextInt();
        }
        for(int i = ar.length-1; i >= 0; i--){
            build.append(ar[i]);
            if(i==0){
                break;
            }
            build.append(" ");
        }
        System.out.println(build);
    }
}

Measured memory_bytes: 26132
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;

// ------ graph ------ //
using Weight = int;
using Array = vector<Weight>;
using Matrix = vector<Array>;

// ------ WarshallFloyd ------ //
void WarshallFloyd(Matrix &d) {
    int n = d.size();
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
            if (d[i][k] != INF && d[k][j] != INF) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int n, m; cin >> n >> m;
    Matrix dist(n, vector<Weight>(n, INF));
    for (int i = 0; i < n; i++) dist[i][i] = 0;
    while (m--) {
        int a, b, c; cin >> a >> b >> c; a--, b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    Matrix shortest = dist;
    WarshallFloyd(shortest);

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (dist[i][j] == INF) continue;
            if (shortest[i][j] < dist[i][j]) cnt++;
        }
    }
    cout << cnt / 2 << endl;
    return 0;
}

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

#define vi vector<int>
#define vvi vector<vi>

int main() {

    int N;
    cin >> N;

    vi p;
    int tmp;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        p.push_back(tmp);
    }

    vi q = p;
    sort(p.begin(), p.end());

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (p[i] != q[i]) count++;
    }

    if (count <= 2) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

string s;
ll mem,ans;

int main(){
  cin >> s;
  mem = 0;
  for(ll i = 0;i < s.size();i++){
    if(s[i] != '0'+(i%2)){
      mem++;
    }
  }
  ans = mem;
  mem = 0;
  for(ll i = 0;i < s.size();i++){
    if(s[i] != '0'+((i+1)%2)){
      mem++;
    }
  }
  ans = min(mem, ans);
  cout << ans << endl;
}


Measured memory_bytes: 512
//@author yash2040
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define pb push_back
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int dp[2002][670];
int getans(int sum,int dig,int S)
{
	if(sum==S)
	return 1;
	if(dp[sum][dig]!=-1)
	return dp[sum][dig];
	int ans=0;
	for(int i=3;i<=S;i++)
	{
		if(i+sum>S)
		break;
		else
		{
			int x=getans(sum+i,dig+1,S);
			ans+=x;
			if(ans>=mod)
			{
				ans-=mod;
			}
			//ans=((ans%mod)+(getans(sum+i,dig+1,S)%mod))%mod;
		}
	}
	return dp[sum][dig]=ans;
}
int32_t main()
{
	fast();
	memset(dp,-1,sizeof(dp));
	int S;
	cin>>S;
	cout<<getans(0,0,S)<<"\n";
}








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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1)res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}

ll comb(ll n, ll a){
	ll res=1;
	rep(i,a){
		res*=(n-i); res%=mod;
		res*=mod_pow(a-i,mod-2); res%=mod;
	}
	return res;
}

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

 	ll N, A, B;
 	cin>>N>>A>>B;
 	ll res=mod_pow(2,N)-1+mod;
 	res%=mod;
 	res%=mod;
 	res+=mod-comb(N,A); res%=mod;
 	res+=mod-comb(N,B); res%=mod;
 	cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	int count_max = 0;
	int count_tmp = 0;
	rep(i, n + 1) {
		if(s[i] == '1') {
			count_tmp++;
			count_max = max(count_tmp, count_max);
		}
		else {
			count_tmp = 0;
		}
	}
	if(count_max >= m) {
		cout << -1 << endl;
		return 0;
	}

	vi dp(n + 1, -1);
	dp[n] = 0;
	int step = 0, pos = n;
	bool reached = false;
	while(!reached) {
		int next_pos = pos;
		step++;
		for(int i = 1; i <= m; i++) {
			if(pos - i < 0) break;
			dp[pos - i] = step;
			if(s[pos - i] == '0') next_pos = pos - i;
			if(pos - i == 0) reached = true;
		}
		pos = next_pos;
	}
	pos = 0;
	step = dp[pos];
	vi ans;
	for(step = dp[pos] - 1; step >= 0; step--) {
		int pre_pos = pos;
		while(dp[pos] != step) pos++;
		ans.push_back(pos - pre_pos);
	}
	rep(i, ans.size()) {
		cout << ans[i] << ' ';
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 1528
N,K = map(int, input().split())
S = input()

kukan = []
cnt0 = 0
cnt1 = 0
for n in range(N):
        if S[n] == '0':
                cnt0 +=1
                if cnt1 > 0:
                        kukan.append(cnt1)
                cnt1 = 0
        if S[n] == '1':
                cnt1 +=1
                if cnt0 > 0:
                        kukan.append(cnt0)
                cnt0 = 0

kukan.append(max(cnt1,cnt0))

#print(kukan)
ans = []

if S[0] == '0':
        start = 1
else:
        start = 0

l = len(kukan)

if l == 1:
        print(N)
        exit()

cnt = [0]*(l+1)
for i in range(1,l+1):
        cnt[i] = cnt[i-1] + kukan[i-1]

#print(cnt)
        


for i in range(1,l-K+1):
        if (i+start)%2 == 1:
                #print(i+2*K)
                ans.append(cnt[min(l,i+2*K)]-cnt[i-1])
        else:
                #print(i+2*K-1)
                ans.append(cnt[min(l,i+2*K-1)]-cnt[i-1])


print(max(ans))

Measured memory_bytes: 11556
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll target;

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

    ll maxi=0,f=0,mini=INF,sum=0;
    string stra,str2;
    ll h,w;
    ll n,x,m;
    ll a,b,d,c;
    multiset<int> s;
    cin>>h>>w;
    vector<string> str(h);
    rep(i,h) cin>>str[i];
    for(ll i=-1;i<=h;i++){
        if(i==-1||i==h){
            rep(i,w+2)cout<<"#";
        }else{
            cout<<"#";
            cout<<str[i];
            cout<<"#";
        }
        ln;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	h := getNextInt(scanner)
	w := getNextInt(scanner)
	geta := 10000
	aa := make([][]int, h)
	for i := 0; i < h; i++ {
		aa[i] = make([]int, w)
		for j := 0; j < w; j++ {
			aa[i][j] = getNextInt(scanner)
		}
	}
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			aa[i][j] = absint(aa[i][j] - getNextInt(scanner))
		}
	}
	grid := makeGrid(h, w)
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			grid[i][j] = big.NewInt(0)
		}
	}
	grid[0][0].SetBit(grid[0][0], geta+aa[0][0], 1)
	grid[0][0].SetBit(grid[0][0], geta-aa[0][0], 1)
	for i := 1; i < w; i++ {
		grid[0][i].Or(grid[0][i], big.NewInt(0).Lsh(grid[0][i-1], uint(aa[0][i])))
		grid[0][i].Or(grid[0][i], big.NewInt(0).Rsh(grid[0][i-1], uint(aa[0][i])))
	}
	for i := 1; i < h; i++ {
		grid[i][0].Or(grid[i][0], big.NewInt(0).Lsh(grid[i-1][0], uint(aa[i][0])))
		grid[i][0].Or(grid[i][0], big.NewInt(0).Rsh(grid[i-1][0], uint(aa[i][0])))
	}
	for i := 1; i < h; i++ {
		for j := 1; j < w; j++ {
			grid[i][j].Or(grid[i][j], big.NewInt(0).Lsh(grid[i-1][j], uint(aa[i][j])))
			grid[i][j].Or(grid[i][j], big.NewInt(0).Rsh(grid[i-1][j], uint(aa[i][j])))
			grid[i][j].Or(grid[i][j], big.NewInt(0).Lsh(grid[i][j-1], uint(aa[i][j])))
			grid[i][j].Or(grid[i][j], big.NewInt(0).Rsh(grid[i][j-1], uint(aa[i][j])))
		}
	}

	for i := 0; i < geta; i++ {
		if grid[h-1][w-1].Bit(geta+i) == 1 {
			fmt.Fprintln(writer, i)
			return
		}
		if grid[h-1][w-1].Bit(geta-i) == 1 {
			fmt.Fprintln(writer, i)
			return
		}
	}
}
func absint(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func makeGrid(h, w int) [][]*big.Int {
	index := make([][]*big.Int, h, h)
	data := make([]*big.Int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

unordered_map<ll, ll> amap;


ll a[200100];


int main(void)
{
  ll n;
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    amap[a[i]] ++;
  }
  ll sum = 0;
  for(auto itr  = amap.begin(); itr != amap.end(); itr++) {
    sum += itr->second * (itr->second - 1) / 2;
  }

  REP(i, n) {
    cout << sum - (amap[a[i]] - 1) << endl;
  }
}


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

const int INF = 1<<21;

int main(){
    static int dp[1000000], dpo[1000000];
    for(int i = 1; i < 1000000; i++)    dp[i] = dpo[i] = INF;

    vector<int> tetra;
    for(int i = 1; i*(i+1)*(i+2)/6 < 1000000; i++){
        tetra.push_back(i*(i+1)*(i+2)/6);
    }

    for(int i = 0; i < tetra.size(); i++){
        for(int j = tetra[i]; j < 1000000; j++){
            if(dp[j-tetra[i]] == INF)   continue;
            
            dp[j] = min(dp[j], dp[j-tetra[i]]+1);
            if(tetra[i] % 2)    dpo[j] = min(dpo[j], dpo[j-tetra[i]]+1);
        }
    }

    int n;
    while(cin >> n, n){
        cout << dp[n] << " " << dpo[n] << endl;
    }

    return 0;
}


Measured memory_bytes: 10856
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int N = 2e5 + 100;
char a[N], b[N];
int n;


bool firstRemove(int sx, int w, char dl, char dr)
{
    int winl = 0, winr = w + 1; 
    for (int i = n - 1; i >= 0; i--)
    {
        if (b[i] == dl)
        {
            winr = min(w + 1, winr + 1);
        }
        else if (b[i] == dr)
        {
            winl = max(0, winl - 1);
        }

        if (a[i] == dl)
        {
            winl++;
        }
        else if (a[i] == dr)
        {
            winr--;
        }

        //eprintf("%c %c %d %d\n", b[i], a[i], winl, winr);
        if (winl >= winr - 1)
            return true;
    }
    //eprintf("%d] %d [%d\n", winl, sx, winr);
    return sx <= winl || sx >= winr;
}

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int h, w;
    scanf("%d%d%d", &h, &w, &n);
    int si, sj;
    scanf("%d%d", &si, &sj);

    scanf("%s", a);
    scanf("%s", b);

    if (firstRemove(si, h, 'U', 'D') || firstRemove(sj, w, 'L', 'R'))
        printf("NO\n");
    else
        printf("YES\n");

	return 0;
}




Measured memory_bytes: 640