akhauriyash/Code-Regression huggingface dataset:
// written by : soumya_27
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define mod ((int)1e9+7)//998244353//((int)1e18+7)
#define M_PI 3.14159265358979323846
// #define maxx ((int)1e7+7)
#define pb push_back
#define ins insert
#define F first
#define S second
#define ins insert
#define pii pair <int , int>
#define lb lower_bound
#define ub upper_bound
#define usefile freopen("input.txt","r",stdin); freopen("ou(tp)ut.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test int t; cin >> t; while(t--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
int exp(int x,int y,int p){ int res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
int expo(int x,int y){ int res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
int add(int a, int b) {return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b) {return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b) {return ((a%mod)*(b%mod) + mod)%mod;}
int inv(int x) {return expo(x, mod-2);}
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)     
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
using namespace std;
int fact[1000006];
int ncr(int n, int r)
{
	int res = fact[n];
	res = mul(res, inv(fact[r]));
	res = mul(res, inv(fact[n-r]));
	return res;
}
void solve()
{
    fast
    // test
    {
        int n, i, j, k;
        int x, y;
        fact[0] = 1;
        for(i=1 ; i<1000006 ; i++)
        	fact[i] = mul(fact[i-1], i);
        cin >> x >> y;
        if(y > x)
        	swap(x, y);
        if((x+y)%3 == 0 && (y >= (x+y)/3))
        {
        	cout << ncr((x+y)/3, y-((x+y)/3)) << "\n";
        }
        else cout << 0 << "\n";
    }
}

signed main()
{
    // time__("solve")
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 11416
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)

	var H, W, h, w int
	var err error
	if sc.Scan() {
		in := strings.Split(sc.Text(), " ")
		H, err = strconv.Atoi(in[0])
		if err != nil {
			// TODO panic以外の方法で処理すべきかも？
			panic(err)
		}
		W, err = strconv.Atoi(in[1])
		if err != nil {
			panic(err)
		}
	}
	if sc.Scan() {
		in := strings.Split(sc.Text(), " ")
		h, err = strconv.Atoi(in[0])
		if err != nil {
			panic(err)
		}
		w, err = strconv.Atoi(in[1])
		if err != nil {
			panic(err)
		}
	}

	cells := H * W
	filled := H*w + W*h - w*h
	notFilled := cells - filled

	fmt.Println(notFilled)
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
	int h[10], i, j, x;
	for(i=0; i<10; i++)
	{
		scanf("%d", &h[i]);
	}
	for(i=0; i<10; i++)
	{
		for(j=i+1; j<10; j++)
		{
			if(h[i]<h[j])
			{
				x=h[i];
				h[i]=h[j];
				h[j]=x;
			}
		}
	}
	for(i=0; i<3; i++)
	{
		printf("%d\n", h[i]);
	}
	
	return 0;
}


Measured memory_bytes: 2608
import java.util.*;
class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    
    int count = 0;
    
    while(a > 0 && c > 0){
      if(count % 2 == 0){
        c = c - b;
      }else{
        a = a - d;
      }
      count++;
    }
    
    if(a <= 0){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
    sc.close();
  }
}

Measured memory_bytes: 35712
#include <stdio.h>

int maxv(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int minv(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int main(void)
{
    int a, b, c;
    
    int max, min, sp;
    
    scanf("%d %d %d", &a, &b, &c);
    
    sp = maxv(a, b);
    
    max = maxv(sp, c);
    
    
    sp = minv(a, b);
    
    min = minv(sp, c);
    
    if(a != max && a != min) {
        sp = a;
    }
    
    if(b != max && b != min) {
        sp = b;
    }
    
    if(c != max && c != min) {
        sp = c;
    }
    
    printf("%d\n", min + sp + 10 * max);

    return 0;
}


Measured memory_bytes: 128
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit,i8


@njit(i8(i8,i8,i8,i8[:,:],i8[:],i8,i8))
def give_dp(N,K,mod,LR,dp,l,r):
    for i in range(N):
        if i > 0:
            dp[i] += dp[i-1]
            dp[i] %= mod
        for k in range(K):
            l = LR[k][0]
            r = LR[k][1]
            if i + l < N:
                dp[i+l] += dp[i]
                dp[i+1] %= mod
            if i + r < N:
                dp[i+r+1] -= dp[i]
                dp[i+1] %= mod
    return dp[-1]


def main():
    N,K = map(int,input().split())
    LR = [list(map(int,input().split())) for i in range(K)]
    LR = np.array(LR)

    mod = 998244353

    dp = [0 for i in range(N)]
    dp[0] = 1
    dp[1] = -1
    dp = np.array(dp)

    res = give_dp(N,K,mod,LR,dp,0,0)
    res %= mod

    print(res)



main()


Measured memory_bytes: 115664
from heapq import heappop,heappush,heapify
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=[]
for _ in range(m):
  b,c=map(int,input().split())
  s.append([b,c])
s.sort(key=lambda x:x[1],reverse=True)
heapify(a)
f=1
for i in range(m):
  if f:
    for j in range(s[i][0]):
        x=heappop(a)
        if x<s[i][1]:
            heappush(a,s[i][1])
        else:
          heappush(a,x)
          f=0
          break
print(sum(a))

Measured memory_bytes: 25648
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  ll K;
  while (cin >> N >> K) {
    vector<ll> A(N), F(N);
    for (auto& x : A) cin >> x;
    for (auto& x : F) cin >> x;
    sort(A.rbegin(), A.rend());
    sort(F.begin(), F.end());
    auto check = [&](ll X) -> bool {
      ll use = 0;
      for (int i = 0; i < N; i++) {
        ll lim = X / F[i];
        use += max(0ll, A[i] - lim);
      }
      return use <= K;
    };
    ll fail = -1, pass = 1ll << 60;
    while (pass - fail > 1) {
      ll X = (pass + fail) / 2;
      if (check(X)) {
        pass = X;
      } else {
        fail = X;
      }
    }
    cout << pass << endl;
  }
  return 0;
}


Measured memory_bytes: 3328
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x, y = map(int, readline().split())
if x <= y:
    if (x >= 0 and y >= 0) or (x <= 0 and y <= 0):
        ans = y - x
    else:
        ans = abs(abs(x) - y) + 1
else:
    if (x >= 0 and y >= 0) or (x <= 0 and y <= 0):
        ans = min(abs(x) + abs(y) + 1, abs(abs(y) - abs(x)) + 2)
    else:
        ans = abs(x - abs(y)) + 1
print(ans)


Measured memory_bytes: 3064
//QWsin
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

const int maxn=200000+10;

struct Monster{
	int x,h;
	void input(){cin>>x>>h;}
	bool operator < (const Monster &rhs)const{
		return x<rhs.x;	
	}
}a[maxn];

ll dt[maxn];

int main()
{
	int n,d,atk;cin>>n>>d>>atk;
	rep(i,1,n) a[i].input();
	sort(a+1,a+n+1);
	int pos=1;
	ll cur=0,ans=0;
	rep(i,1,n){
		cur+=dt[i];
		while(pos<n && a[pos+1].x<=a[i].x+2*d) {
			++pos;
		}
		a[i].h-=cur;//之前打的 
		if(a[i].h<=0) continue;
		ll times=ceil((double)a[i].h/atk);
		
		cur+=atk*times;
		dt[pos+1]-=atk*times;//现在再打 
		a[i].h=0;
		ans+=times;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>

typedef unsigned long long ll;

ll DENOM = 1000000000LL + 7LL;
using namespace std;

int main(){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}

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

public class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int arr[] = new int[3];
		for (int i = 0; i < 3; i++)
		{
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		System.out.println(arr[0] + " " + arr[1] + " " + arr[2]);
		sc.close();
	}
}


Measured memory_bytes: 26200
import java.util.*;

public class Main {
    public static void main(String[] args) {
        new Solver().solve(new Scanner(System.in));
//        new Solver().solve(new Scanner(ex));
    }

//    private static final String ex = "2002\n2017";
    private static final String ex = "4500\n0";
}

class Solver {
    void solve(Scanner scanner) {
        int R = Integer.parseInt(scanner.nextLine());
        int G = Integer.parseInt(scanner.nextLine());

        System.out.println(2 * G - R);
    }

    private int[] splitInt(String s) {
        String[] split = s.split(" ");
        int[] splitInt = new int[split.length];
        for (int i = 0; i < split.length; i ++) {
            splitInt[i] = Integer.parseInt(split[i]);
        }
        return splitInt;
    }

    private long[] splitLong(String s) {
        String[] split = s.split(" ");
        long[] splitLong = new long[split.length];
        for (int i = 0; i < split.length; i ++) {
            splitLong[i] = Long.parseLong(split[i]);
        }
        return splitLong;
    }
}


Measured memory_bytes: 24916
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)

int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, 0, n)
  {
    cin >> v[i];
  }
  rep(i, 0, n)
  {
    if (v[i] % 2 == 0)
    {
      if (v[i] % 3 == 0 || v[i] % 5 == 0)
      {
        continue;
      }
      else
      {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	public class Program
	{
		// ABC131-D
		static void Main(string[] args)
		{
			string str = Console.ReadLine();
			int n = int.Parse(str);
			List<int[]> list = new List<int[]>();
			for (int i = 0; i < n; i++) {
				str = Console.ReadLine();
				list.Add(str.Split().Select(p => int.Parse(p)).ToArray());
			}

			int time = 0;
			foreach (var work in list.OrderBy(p=>p[0]).OrderBy(p => p[1])) {
				time += work[0];
				if (  work[1] < time) {
					Console.WriteLine("No");
					return;
				}
			}
			Console.WriteLine("Yes");
			return;
		}
	}
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int k; std::cin >> k;
  vl que; rrep(i, 9) que.pb(i);
  for (int i = 0; i < k; i++) {
    ll now = que[i], d = now % 10;;
    if (d > 0) que.pb(now*10+d-1);
    que.pb(now*10+d);
    if (d < 9) que.pb(now*10+d+1);
  }
  std::cout << que[k-1] << "\n";
}


Measured memory_bytes: 6256
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N, H, W = [I() for _ in range(3)]
print((N - H + 1) * (N - W + 1))


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

int main() {
        int n;
        string s;
        int ans = 0;

        cin >> n;
        cin >> s;

        for (int i = 1; i < n; i++) {
                string x = s.substr(0, i);
                string y = s.substr(i);
                map<char, int> count;
                for (int j = 0; j < x.size(); j++) {
                        if (y.find(x[j]) != string::npos)
                                count.insert(make_pair(x[j], 1));
                }
                if (ans < count.size())
                        ans = count.size();
        }
        cout << ans << endl;
}

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

double W, H, x, y;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> W >> H >> x >> y;
    cout << fixed << setprecision(10) << W*H/2 << " ";
    if (x==W/2 && y==H/2) cout << 1 << endl;
    else cout << 0 << endl;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int main(){
	int x,y;
	cin>>x>>y;

	int ans=0;
	if(x==1){
		ans+=300000;
	}else if(x==2){
		ans+=200000;
	}else if(x==3){
		ans+=100000;
	}

	if(y==1){
		ans+=300000;
	}else if(y==2){
		ans+=200000;
	}else if(y==3){
		ans+=100000;
	}

	if(x==1&&y==1)ans+=400000;

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
int mod=1000000007;
int Power(int x,int y,int mod) {
	int ret=1;
	while(y) {
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod,y>>=1;
	}
	return ret;
}
int main(){
	int n,a,b; 
	cin>>n>>a>>b;
	int ans=1,ans2=1,aa=Power(2,n,mod);
	for(int i=1;i<=a;i++)ans=1ll*ans*Power(i,mod-2,mod)%mod*(n-i+1)%mod;
	for(int i=1;i<=b;i++)ans2=1ll*ans2*Power(i,mod-2,mod)%mod*(n-i+1)%mod;
	cout<<((0ll+aa-ans-ans2-1)%mod+mod)%mod;
}

Measured memory_bytes: 256
// C - Bugged
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(x) (x).begin(),(x).end()

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

	int MAX = 0;
	vi S(N+1);
	for(int i=1; i<=N; ++i){
		cin>>S[i];
		MAX += S[i];
	}

	sort(all(S));

	vvi dp(N+1, vi(MAX+1, false));
	dp[0][0] = true;
	for(int i=0; i<N; ++i){
		int s = S[i+1];
		for(int j=0; j<MAX; ++j){
			if(dp[i][j]){
				dp[i+1][j] = true;
				if(j+s<=MAX) dp[i+1][j+s] = true;
			}
		}
	}

	int ans = 0;
	for(int j=MAX; j>=0; --j){
		if(dp[N][j] && j%10){
			ans = j;
			break;
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 4224
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
ll ai, a0, at, aj, al, as, az;
ll f(ll x) {
    return 2 * (x / 2);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> ai >> a0 >> at >> aj >> al >> as >> az;
    ll ans = 0;
    ans += a0;
    ll best = 0;
    if (ai >= 1 && aj >= 1 && al >= 1) {
        best = max(best, 3 + f(ai - 1) + f(aj - 1) + f(al - 1));
    }
    best = max(best, f(ai) + f(aj) + f(al));
    cout << ans + best;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * https://abc050.contest.atcoder.jp/tasks/arc066_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] dp = new int[N];
		for(int i=0; i<N; i++) dp[Integer.parseInt(sc.next())]++;
		sc.close();
		
		boolean f = true;
		for(int i=N-1; i>=0; i-=2){
			if((i>0&&dp[i]!=2)||(i==0&&dp[i]!=1)){
				f = false;
				break;
			}
		}
		
		long ans = f ? getPower(2, N/2) : 0;
		System.out.println(ans);

	}
	
	static final int MOD = 1000000007;
	
	static long getPower(long n, long m) {
		if(m==0){
			return 1;
		}else if(m%2==0){
			return getPower(getMod(n*n), m/2);
		}else{
			return getMod(n*getPower(n,m-1));
		}
	}
	
	static long getMod(long a){
		return a>=0 ? a%MOD : MOD + a%MOD;
	}

}


Measured memory_bytes: 48472
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: i32 = read();
    let x: i32 = read();
    let m: Vec<i32> = (0..n).map(|_| read()).collect();

    let rest = x - m.iter().sum::<i32>();
    let min: i32 = *m.iter().min().unwrap();

    println!("{}", n + rest / min);
}

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


Measured memory_bytes: 4352
N = int(input())
ans = ''
az = [chr(i) for i in range(97, 97+26)]
while N>0:
    r = N%26
    if r==0:
        ans+='z'
        N = (N-26)//26
    else:
        ans+=az[r-1]
        N = (N-r)//26
print(ans[::-1])

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

int main(){
  int h, w, k;
  cin >> h >> w >> k;
  string s[h];
  rep(i,h) cin >> s[i];
  int ans = INF;
  rep(i,(1<<(h-1))) {
    vector<int> c(h,0);
    for(int j = 1; j < h; j++) {
      if(i & (1<<(j-1))) c[j] = c[j-1] + 1;
      else c[j] = c[j-1];  
    }
    int l = c[h-1] + 1;
    vector<vector<int>> num(l,vector<int>(w+1,0));
    rep(j,w) {
      rep(m,l) num[m][j+1] = num[m][j];
      rep(m,h) {
        if(s[m][j] == '1') num[c[m]][j+1]++;
      }
    }
    int res = 0, cur = 0;
    while(res < w) {
      int p = INF;
      rep(j,l) {
        int q = upper_bound(num[j].begin(),num[j].end(),num[j][res]+k) - num[j].begin() - 1;
        p = min(p,q);
      }
      if(res == p) {
        cur = INF;
        break;
      }
      res = p;
      if(res < w) cur++;
    }
    ans = min(ans,cur+l-1);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	string s;
	cin >> s;
	vector<char> a;
	rep(i, s.size()) {
		if(s[i] == 'B') {
			if(a.size() > 0) a.pop_back();
		} else {
			a.push_back(s[i]);
		}
	}
	rep(i, a.size()) cout << a[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> a(n);

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

    int ans = 0;

    for(int i = 0; i < n; i++) {
        if(a[i] != l) {
            ans++;
        } else {
            l++;
        }
    }

    if(ans == n) ans = -1;
    cout << ans << endl;

    return 0;
}


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

using namespace std;

using ll = long long;

vector<int> vi;

int main() {

	ll a, b;
	cin >> a >> b;
	
	vi.push_back(a + b);
	vi.push_back(a - b);
	vi.push_back(a * b);
	
	sort(vi.begin(), vi.end());
	cout << vi.back() << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s>>k;
    rep(i,Size(s)){
        if(s[i]=='a')continue;
        rep(j,Size(alph)){
            if(alph[j]==s[i])tmp=j;
        }
        ll cost=26-tmp;
        if(cost>k)continue;
        k-=cost;
        s[i]='a';
    }
    k%=26;
    s[Size(s)-1]+=k;
    Cout(s);
    return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
#include<cstdio>
using namespace std;

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

typedef pair<double, int> pp;

int main()
{
    vector<pp> t[3];
    vector<pp> ans;
    vector<pp> rest;

    double d;
    int n;
    REP(3)
    {
        rep(j,8)
        {
            cin >> n >> d;
            t[i].push_back(pp(d,n));
        }
        sort(all(t[i]));
        printf("%d %.2f\n", t[i][0].second, t[i][0].first);
        printf("%d %.2f\n", t[i][1].second, t[i][1].first);
        //ans.push_back(t[i][0]); ans.push_back(t[i][1]);
        for(int s = 2;s<8;s++)rest.push_back(t[i][s]);
    }
    sort(all(rest));
    //ans.push_back(rest[0]); ans.push_back(rest[1]);
    printf("%d %.2f\n", rest[0].second, rest[0].first);
    printf("%d %.2f\n", rest[1].second, rest[1].first);

    sort(all(ans));
    //REP(8) printf("%d %.2f", ans[i].second, ans[i].first);
    return 0;
}

Measured memory_bytes: 0
N,M = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i in range(N)]

AB.sort()
d_count = 0
money = 0
j = 0

for i in range(M):
    if d_count == AB[j][1]:
        d_count = 0
        j += 1

    money += AB[j][0]
    d_count += 1
    
print(money)

Measured memory_bytes: 27880
A, B, C, D, E, F = map(int, input().split())
W = set()
for a in range(0, F+1, 100*A):
    for b in range(0, F+1, 100*B):
        W.add(a+b)
S = set()
for c in range(0, F+1, C):
    for d in range(0, F+1, D):
        S.add(c+d)

rate = -1
for w in W:
    for s in S:
        if 0 < w + s <= F and s * 100 <= E * w:
            if s / (s + w) > rate:
                rate = s / (s + w)
                ans = w + s, s
print(ans[0], ans[1])

Measured memory_bytes: 3828
import java.util.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[]a=new int[n];
		Arrays.setAll(a,i->s.nextInt());
		Arrays.sort(a);

		double r=a[0];
		for(int i=1;i<n;++i)
			r=(r+a[i])*0.5;
		System.out.println(r);
	}
}


Measured memory_bytes: 26964
# ARC091D - Remainder Reminder
def main():
    # a, b := b ≥ K + 1
    N, K = tuple(map(int, input().split()))
    ans = 0
    for b in range(K + 1, N + 1):
        ans += N // b * (b - K)
        if K:
            ans += max(0, (N % b) - K + 1)
        else:
            ans += N % b
    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
  long N, A, B;
  cin >> N >> A >> B;
  
  if (A >= N) {
    cout << N << endl;
  }
  
  else {
    long n = N / (A + B);
    if (N % (A + B) >= A) {
      cout << n * A + A << endl;
    }
    else {
      cout << n * A + N % (A + B) << endl;
    }
  }
  
}

Measured memory_bytes: 256
from itertools import combinations
n, m, x = map(int, input().split())

a = []
for i in range(n):
    a.append(list(map(int, input().split())))

ans = 10**10
for i in range(1, n+1):
    for j in combinations(a, i):
        sm = list(map(sum, zip(*j)))
        if len(list(filter(lambda y: y >= x, sm[1:]))) >= m:
            if ans >= sm[0]:
                ans = sm[0]

if ans == 10**10:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9212
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        
        AtCoder problem = new AtCoder(sc);
        problem.solve(out);
        
        out.flush();
    }
    
}

class AtCoder {
    final int N;
    int[] d;
    AtCoder(FastScanner sc) {
        N = sc.nextInt();
        d = IntStream.range(0, N).map(i -> sc.nextInt()).toArray();
    }

    void solve(PrintWriter out) {
        long cnt = Arrays.stream(d).distinct().count();
        out.println(cnt);
    }
    
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {
    
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    
    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }
    
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }
    
    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 29524
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(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))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
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<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

typedef ll Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

const int MAXN = 1e5 + 1;
const ll INF = 1e9;

int n;
Graph g;

// 重心として使われてるかのフラグ
bool centroid[MAXN] = {};
// 部分木のサイズ
int subSize[MAXN] = {};

// 部分木のサイズを計算する
int getSubSize(int v, int p) {
	int& ret = subSize[v];
	ret = 1;
	for (int i = 0; i < g[v].size(); i++) {
		int ch = g[v][i].to;
		if (ch == p || centroid[ch]) continue;
		ret += getSubSize(ch, v);
	}
	return ret;
}

// 重心となる頂点を探す
// first: 最大サイズ second: 対応する頂点
pii getCentroid(int v, int p, int t) {
	pii ret(INF, -1);
	int sum = 1, m = 0;
	for (int i = 0; i < g[v].size(); i++) {
		int ch = g[v][i].to;
		if (ch == p || centroid[ch]) continue;
		m = max(m, subSize[ch]);
		sum += subSize[ch];
		pii p = getCentroid(ch, v, t);
		ret = min(ret, p);
	}
	m = max(m, t - sum);
	ret = min(ret, pii(m, v));
	return ret;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	cin >> n;
	g.resize(n);
	REP(i, n - 1)
	{
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		add_edge(g, a, b, c);
		add_edge(g, b, a, c);
	}
	getSubSize(0, -1);
	int r = getCentroid(0,-1,subSize[0]).second;
	getSubSize(r, -1);
	vi rr;
	pii maxsub(0, -1);
	pii mind(1e9 + 1, -1);
	for (auto e : g[r])
	{
		if (maxsub.first < subSize[e.to]) maxsub = pii(subSize[e.to], e.to);
		if (mind.first > e.cost) mind = pii(e.cost, e.to);
		rr.push_back(e.to);
	}
	ll sum = 0;
	queue<int> que;
	que.push(r);
	vector<bool> vis(n);
	vis[r] = true;
	while (!que.empty())
	{
		int v = que.front();
		que.pop();
		for (auto e : g[v])
		{
			int u = e.to;
			if (vis[u]) continue;
			vis[u] = true;
			sum += e.cost * subSize[u] * 2;
			que.push(u);
		}
	}
	ll ans = 0;
	int t = 0; ll c = 0;
	for (auto e : g[r])
	{
		if (e.to != maxsub.second) t += subSize[e.to];
		else c = e.cost;
	}
	if (maxsub.first > t)  ans = sum - c;
	else ans = sum - mind.first;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 17664
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  ll n,medianA,medianB;
  cin>>n;
  vector<ll>a(n),b(n);
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  if(n%2==0){
    medianA=a[a.size()/2]+a[(a.size()/2)-1];
    medianB=b[b.size()/2]+b[(b.size()/2)-1];
  }else{
    medianA=a[(a.size()/2)];
    medianB=b[(b.size()/2)];
  }
  cout<<abs(medianA-medianB)+1<<endl;
  return 0;
}


Measured memory_bytes: 6344
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int n;
	int[] a;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		n = readln().strip().to!int;
		a = readln().strip().split().map!(to!int).array();
	}
}

auto main2(Input* input)
{
	with (input)
	{
        foreach (ai; a)
        {
            if ((ai & 1) == 0)
                if (ai % 3 != 0 && ai % 5 != 0)
                    return "DENIED";
        }
        return "APPROVED";
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`5
6 7 9 10 31`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "APPROVED");
	}

	unittest // example2
	{
		string example =
`3
28 27 24`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "DENIED");
	}

	unittest // example3
	{
		string example =
``;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == _placeholder_);
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		struct Adapter
		{
			string[] _lines;
			this(string input) { _lines = input.splitLines(); }
			string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
		}
		parseInput(input, Adapter(example));
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	alias retType = ReturnType!main2;
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


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

string s;
bool vis[26];

int main( ){
	cin >> s;
	
	for (int i=0;i<s.size();i++) vis[s[i]-'a']=1;
	
	for (int i=0;i<26;i++) 
		if (vis[i]==0) {
			cout << (char)(i+'a') << endl;
			return 0;
		}
	
	cout << "None" << endl;
	return 0;
} 

Measured memory_bytes: 512
fun main(args: Array<String>) {
    solve(java.util.Scanner(System.`in`))
}

fun solve(sc: java.util.Scanner) {
    val K = sc.nextInt()
    val N = sc.nextInt()
    val A = Array(N) { sc.nextInt() }

    val d = Array(N) { 0 }
    d[0] = A[0]
    for (i in 1 until N) {
        d[i] = A[i] - A[i - 1]
    }
    d[0] += K - A.last()

    println(K - d.max()!!)
}


Measured memory_bytes: 81372
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int h, w;
	cin >> h >> w;
	int** grid = new int*[h];
	for (int i = 0; i < h; i++)
		grid[i] = new int[w];
	int n;
	cin >> n;
	vector<int> colors;
	int num = 0;
	while (n--)
	{
		num++;
		int k;
		cin >> k;
		for (int i = 1; i <= k; i++)
			colors.emplace_back(num);
	}
	int x = 0, y = 0;
	for (int i = 0; i < colors.size(); i++)
	{
		grid[x][y] = colors[i];
		if (y % 2 == 0)
		{
			if (x < h - 1)
			{
				x++;
				continue;
			}
			if (x == h - 1)
			{
				y++;
				continue;
			}
		}
		if (y % 2 == 1)
		{
			if (x > 0)
			{
				x--;
				continue;
			}
			if (x == 0)
			{
				y++;
				continue;
			}
		}
	}
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
			cout << grid[i][j] << " ";
		cout << endl;
	}
	return 0;
}

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

using i64 = long long int;

const i64 MOD = 1e9 + 7;

i64 height[100005]={0}, sup[100005]={0};
i64 t[100005]={0}, a[100005]={0};

int main(){
    int n;
    cin >> n;

    for(int i=0;i<n;++i)cin >> t[i];
    for(int i=0;i<n;++i)cin >> a[i];

    for(int i=0;i<n;++i){
        if(i == 0 || t[i] > t[i-1])height[i] = t[i];
        else sup[i] = t[i];
    }

    bool ok = true;

    for(int i=n-1;i>=0;--i){
        if(i == n-1 || a[i] > a[i+1]){
            if(height[i] != 0 && a[i] != height[i])ok = false;
            else height[i] = a[i];
        }else if(height[i] != 0 && a[i] < height[i]){
            ok = false;
        }else{
            sup[i] = min(sup[i], a[i]);
        }
    }

    i64 ans = (ok ? 1 : 0);
    if(ok){
        for(int i=0;i<n;++i){
            if(height[i] == 0){
                ans = (ans * sup[i]) % MOD;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007
#define MINP 0x00FF

int main(int argc, char const *argv[])
{
	int n,h[107];
	int l = 0,r = 0x7F;
	int cnt = 0,min = 0x7F,flag = 1;
	scanf("%d",&n);
	for (int i = 0; i < n; ++i)	scanf("%d",&h[i]);

	while(l < n){
		min = 0x7F;
		flag = 1;
		if(h[l] == 0){
			++l;
			continue;
		}
		for (int i = l; (i < n && flag); ++i)
		{
			for (r = l; r < n; ++r)
			{
				if(h[r] == 0){
					flag = 0;
					break;
				}
			}
		}
		for (int i = l; i < r; ++i)
		{
			if(min > h[i])	min = h[i];
		}
		for (int i = l; i < r; ++i)
		{
			h[i] -= min;
		}
		cnt += min;
	}
	printf("%d\n", cnt);
}


Measured memory_bytes: 128
#include <stdio.h>          // printf(), scanf(), getchar()
#include <string.h>         // memset()
#include <stdbool.h>

#define SZ_MATRIX 10

short lights[SZ_MATRIX][SZ_MATRIX];
short turn[SZ_MATRIX][SZ_MATRIX];

bool
get(int x, int y)
{
	const int dx[5] = {-1, 0, 0, 0, 1};
	const int dy[5] = { 0,-1, 0, 1, 0};

	int c = lights[y][x];
	for (int i = 0; i < 5; ++i)
	{
		int nx = x + dx[i], ny = y + dy[i];
		if (0 <= nx && nx < SZ_MATRIX && 0 <= ny && ny < SZ_MATRIX)
			c += turn[ny][nx];
	}

	return (c % 2) != 0;
}

bool
calc()
{
	for (int y = 1; y < SZ_MATRIX; ++y)
	{
		for (int x = 0; x < SZ_MATRIX; ++x)
		{
			if (get(x, y - 1))
				turn[y][x] = 1;
		}
	}

	for (int x = 0; x < SZ_MATRIX; ++x)
	{
		if (get(x, SZ_MATRIX - 1))
			return false;
	}

	return true;
}

void
solve()
{
	for (int i = 0; i < (1 << SZ_MATRIX); ++i)
	{
		memset(turn, 0, sizeof(turn));
		for (int j = 0; j < SZ_MATRIX; ++j)
			turn[0][SZ_MATRIX - j - 1] = (i >> j) & 1;

		if (calc())
			break;
	}
}

int
main(int argc, char **argv)
{
	int n;
	scanf("%d\n", &n);

	for (int i = 0; i < n; ++i)
	{
		for (int y = 0; y < SZ_MATRIX; ++y)
		{
			int c;
			for (int x = 0; x < SZ_MATRIX; ++x)
			{
				c = getchar();
				while (c == ' ')
					c = getchar();

				lights[y][x] = (c == '1') ? 1 : 0;
			}

			c = getchar();
		}

		solve();
		for (int y = 0; y < SZ_MATRIX; ++y)
		{
			for (int x = 0; x < SZ_MATRIX; ++x)
				printf("%d%c", turn[y][x], (x < SZ_MATRIX - 1) ? ' ' : '\n');
		}
	}

	return 0;
}

Measured memory_bytes: 1748
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;


int main()
{
    string s;
    cin >> s;
    int ret = 0;
    rep(i,4)
    {
        if(s.substr(i,1) == "+")
            ret++;
        else
            ret--;
    }
    cout << ret << endl;
    return 0;
}

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

int main(){
	int n, q;
	cin >> n;
	int S[n];
	for(int i = 0; i < n; i++){
		cin >> S[i];
	}
	cin >> q;
	int T[q];
	for(int i = 0; i < q; i++){
		cin >> T[i];
	}
	int count = 0;
	for(int i = 0; i < q; i++){
		for(int j = 0; j < n; j++){
			if(S[j] == T[i]){
				count++;
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}

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

#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  vector<int> a;

  while(true){
    vector<int> a;
    cin >> N;

    if(N == 0) break;

    int b;
    REP(i, N) {
      cin >> b;
      a.push_back(b);
    }

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

    int sum = 0;
    FOR(i, 1, N - 1) {
      sum += a[i];
    }
    sum = sum / (N - 2);
    
    cout << sum << endl;

  }




}



Measured memory_bytes: 3148
while True:
    n = input()
    if n == 0: break
    P = set(tuple(map(int, raw_input().split())) for i in range(n))
    ans = 0
    for xi, yi in P:
        for xj, yj in P:
            q = (xj - yj + yi, yj + xj - xi)
            r = (xi - yj + yi, yi + xj - xi)
            if q in P and r in P:
                ans = max(ans, (xi - xj) ** 2 + (yi - yj) ** 2)
    print ans

Measured memory_bytes: 5256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

ll rp = 0;

// 連長圧縮（ランレングス圧縮）：sの連長部分を{文字,個数}の配列で返す
vector<pair<char, long long>> rle(string s){
    vector<pair<char, long long>> ret;
    long long i = 0, n = s.size();
    while(i<n){
        char tmp = s[i];
        long long cnt = 1;
        while(i<n){
            i++;
            if(tmp == s[i]) cnt++;
            else break;
        }
        if(tmp == '0') rp++;
        ret.push_back(make_pair(tmp, cnt));
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll n, k, ans = 0; string s; cin >> n >> k >> s;
    auto rlev = rle(s);
    // 全部反転できる場合
    if(k >= rp){ cout << n << endl; return 0; }

    // 0の列をk個反転させた場合の長さを全探索
    ll rcnt, sum, cur, prev_sum = 0;
    rep(i, rlev.size()){
        if(i == 0){
            rcnt = 0, sum = 0, cur = i;
            while(cur<rlev.size()){
                if(rlev[cur].first == '0' && rcnt >= k) break;
                else{
                    sum += rlev[cur].second;
                    if(rlev[cur].first == '0') rcnt++;
                    cur++;
                }
            }
            chmax(ans, sum);
        }
        else{
            if(rlev[i-1].first == '0') rcnt--;
            sum -= rlev[i-1].second;
            while(cur<rlev.size()){
                if(rlev[cur].first == '0' && rcnt >= k) break;
                else{
                    sum += rlev[cur].second;
                    if(rlev[cur].first == '0') rcnt++;
                    cur++;
                }
            }
            chmax(ans, sum);
        }
    } 
    cout << ans << endl;

    // // 繋げて最も大きくなる部分を繋げていく
    // ll maxlen = -1, maxIdx = -1;
    // for(ll i=0; i<rlev.size(); i++){
    //     if(rlev[i].first == '1') continue;
    //     if(i == 0){
    //         if(max < r)
    //     }
    // }
}

Measured memory_bytes: 2744
# include <bits/stdc++.h>
# define ll long long
# define all(x) x.begin(), x.end()
# define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
# define MOD 1000000007
using namespace std;

int n,k;
int N=10;


int main(){
	fastio;
	cin>>n>>k;
	vector<int> a(n);
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(k*n+1,0)));
	dp[0][0][0]=1;
	for (int i=1;i<=n;i++){
		dp[i][0][0]=1;
		for(int j=1;j<=i;j++){
			for (int x=k*n;x>=1;x--){
				dp[i][j][x]=dp[i-1][j][x];
				if (x>=a[i-1])
				dp[i][j][x]+=dp[i-1][j-1][x-a[i-1]];
				// cout<<i<<' '<<j<<' '<<x<<' '<<dp[i][j][x]<<'\n';
			}
		}
	}
	ll re=0;
	for (int j=1;j<=n;j++){
		re+=dp[n][j][k*j];
		// cout<<re<<' ';
	}
	cout<<re<<'\n';
	return 0;
}

Measured memory_bytes: 55084