akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
using namespace std;

int main(){
	while(1){
		int n;
		int map[11][11];
		int row[11];
		int line[11];
		int allSum = 0;
		scanf("%d", &n );
		if( n == 0 ) break;

		for( int y=0; y<n; y++ ){
			for( int x=0; x<n; x++ ){
				scanf("%d", &map[x][y]);
			}
		}
		for( int y=0; y<n; y++ ){
			line[y] = 0;
			for( int x=0; x<n; x++ ){
				line[y] += map[x][y];
			}
		}
		for( int x=0; x<n; x++ ){
			row[x] = 0;
			for( int y=0; y<n; y++ ){
				row[x] += map[x][y];
			}
		}
		for( int i=0; i<n; i++ ){
			allSum += row[i];
		}
		for( int y=0; y<n; y++ ){
			for( int x=0; x<n; x++ ){
				printf("%5d", map[x][y]);
			}
			printf("%5d\n", line[y] );
		}
		for( int x=0; x<n; x++ ){
			printf("%5d", row[x]);
		}
		printf("%5d\n", allSum );
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		List<String> list = new ArrayList<String>();
		for(int i = 0; i < 10; i++) {
			list.add(br.readLine());
		}
		Collections.sort(list, (s1, s2) -> Integer.parseInt(s2) - Integer.parseInt(s1));

		for(int i = 0; i < 3; i++) {
			System.out.println(list.get(i));
		}
	}
}

Measured memory_bytes: 30284
#include<stdio.h>
    
    int main(){
    	int n,i;
		int current = 1;
		int count = 0;
    	scanf("%d",&n);
        int a[n];

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

		while(current != 2){

			if(count > n){
	
				printf("-1");
				return 0 ;

			}
			current = a[current - 1];
			count ++;
		}


		printf("%d",count);

		return 0;

	}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

string s;
int n;

s64 dfs(int i, s64 partial, s64 sum)
{
    if (i == n - 1) return partial + sum;
    return dfs(i + 1, partial * 10 + (s64)(s[i + 1] - '0'), sum) + dfs(i + 1, (s64)(s[i + 1] - '0'), sum + partial);
}

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

    cin >> s;
    n = s.size();

    cout << dfs(0, (s64)(s[0] - '0'), 0) << "\n";
    return 0;
}



Measured memory_bytes: 256
import java.util.*
import kotlin.math.abs

fun main() {
    b()
}

fun a() {
    val x = readLong()
    if (x >= 30) {
        "Yes"
    } else {
        "No"
    }.let { println(it) }
}

fun b() {
    val (N, D) = readLongList()
    val D2 = D*D
    var ans = 0L
    repeat(N.toInt()) {
       readLine()!!.split(" ").map {it.toLong() * it.toLong()}.sum().let {
           if (it <= D2) ans++
       }
    }
    ans.print()
}
fun readLong() = readLine()!!.toLong()
fun readLongList() = readLine()!!.split(" ").map { it.toLong() }

fun Long.bitEach(action: (Int) -> Unit) {
    (0 until Long.SIZE_BITS).forEach { action(((this shr it) and 1).toInt()) }
}

fun Long.bitFilter(bit: Int) = (0 until Long.SIZE_BITS).filter { ((this shr it) and 1) == 1L }

fun <T1, T2> pairs(first: Iterable<T1>, second: Iterable<T2>) = first.flatMap { t1 -> second.map { t2 -> t1 to t2 } }

fun Long.print() {
    println(this)
}

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

int n;
void dfs(string s, char mx){
  if(s.size() == n){
    cout << s << endl;
    return;
  }
  for(char c = 'a'; c <= mx+1; c++){
    string t = s;
    t += c;
    dfs(t, max(c,mx));
  }
  
}


int main() {
  cin >> n;
  dfs("", 'a' - 1);
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int N;
int S;

int main(void) {
    scanf("%d", &N);
    int n = N;
    while(n != 0) {
      int r = n % 10;
      S += r;
    	n = (n-r) / 10;
    }
    
    if (N % S == 0) Yes;
    else No;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  double p=(n+1)/2;
  double oddans=p/n;
if(n%2==0) cout<<fixed<<setprecision(7)<<0.5<<endl;
else cout<<fixed<<setprecision(7)<<oddans<<endl;
return 0;
}

Measured memory_bytes: 256
package main

import (
"fmt"
)

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	b := false
	
	for c := 1; c < 10; c++ {
		if n%c == 0 && n/c < 10 {
			b = true
			break
		}
	}
	
	if b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
numlist = []
count = 0
for i in range(3):
    a,b = input().split()
    numlist.append(a)
    numlist.append(b)
if numlist.count("1") >= 3:
    print("NO")
elif numlist.count("2") >= 3:
    print("NO")
elif numlist.count("3") >= 3:
    print("NO")
elif numlist.count("4") >= 3:
    print("NO")
elif numlist.count("1") == 0:
    print("NO")
elif numlist.count("2") == 0:
    print("NO")
elif numlist.count("3") == 0:
    print("NO")
elif numlist.count("4") == 0:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3064
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

ll solve() {
    ll N;
    cin >> N;
    V<ll> A(N), B(N);
    for(auto &&e : A) cin >> e;
    for(auto &&e : B) cin >> e;
    priority_queue<PLL> pq;
    for(ll i = 0; i < N; i++) if(A[i] < B[i]) pq.emplace(B[i], i);
    ll ret = 0;
    while(pq.size()) {
        ll val, idx;
        tie(val, idx) = pq.top();
        pq.pop();
        ll l = B[(idx + N - 1) % N], r = B[(idx + 1) % N];
        if(val < l + r) break;
        if(l + r == 0) break;
        ll div = min(val / (l + r), (val - A[idx]) / (l + r));
        if(div == 0) break;
        ret += div;
        val -= div * (l + r);
        B[idx] = val;
        if(A[idx] < val) pq.emplace(val, idx);
    }
    return A == B ? ret : -1;
}

int main() {
    cout << solve() << endl;
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);

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

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

  int alice = 0;
  int bob = 0;
  int size = a.size()-1;

  for(int i = 0; i < n; i++){
    if(i % 2 == 0) alice += a[size - i];
    else bob += a[size - i];
  }

  cout << alice - bob << endl;

  return 0;

}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count  = 0

for an in range(a+1):
    for bn in range(b+1):
        for cn in range(c+1):
            if x == 500*an+100*bn+50*cn:
                count = count + 1
print(count)

Measured memory_bytes: 3060
/*input
P?P?
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 2e5+1;
int dp[N][2];
int where[N][2];
string s;
int n;

void solve(){
  	cin >> s;
  	n = s.size();
  	s = "$"+s;
  	RE(i,n){
  		if(s[i] == '?')cout << 'D';
  		else cout << s[i];
  	}
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    ll a, b; cin >> a >> b;
    ll aa = a; ll bb = b;
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    cout << aa * bb / b << endl;
}

Measured memory_bytes: 256
s = list(map(len, input().split('T')))
x, y = map(int, input().split())

dp = [set([s[0]]), set([0])]

for i in range(1, len(s)):
    nxt = set()
    for j in dp[i % 2]:
        nxt.add(j + s[i])
        nxt.add(j - s[i])
    dp[i % 2] = nxt

if x in dp[0] and y in dp[1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 50908
#include<stdio.h>
#include<math.h>
#define NUM 10000
int main()
{
  int prime[NUM];
  int pair[NUM];
  int i,j,k;
  int n,p;
  int temp;
  int min;
  j=2;
  for(i=0;i<NUM;i++)
    {
      while(1)
	{
	  for(k=2;k<=(int)sqrt(j);k++)
	    {
	      if(j%k==0) break;
	    }
	  if(k==(int)sqrt(j)+1) break;
	  j++;
	}
      prime[i]=j;
      j++;
    }

  while(1)
    {
      scanf("%d%d",&n,&p);
      if((n==-1)&&(p==-1)) break;
      for(i=0;i<NUM;i++) pair[i]=i;
      for(i=0;i<NUM;i++)
	{
	  if(prime[i]>n)
	    {
	      temp=prime[i]+prime[i];
	      pair[i]++;
	      //printf("1: %d\n",temp);
	      min=i;
	      break;
	    }
	}
      for(i=1;i<p;i++)
	{
	  temp=prime[min]+prime[pair[min]];
	  //printf("%d: %d\n",i+1,temp);
	  for(j=min;j<NUM;j++)
	    {
	      if(prime[j]+prime[pair[j]]<=temp)
		{
		  k=j;
		  temp=prime[j]+prime[pair[j]];
		  //printf("%d->%d\n",i+1,temp);
		}
	    }
	  pair[k]++;
	  //printf("%d: %d<Determined>\n",i+1,temp);
	}
      printf("%d\n",temp);
    }
  return 0;
}

Measured memory_bytes: 1772
import java.util.*;

public class Main {

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

	int n;
	int m;
	int q;
	int a[];
	int b[];
	int c[];
	int d[];
	int num[];
	long ans = 0;
	public void run() {
		Scanner sc = new Scanner(System.in);
		n=sc.nextInt();
		m=sc.nextInt();
		q=sc.nextInt();
		a = new int[q];
		b = new int[q];
		c = new int[q];
		d = new int[q];
		num = new int[n+1];
		for(int i=0; i<q; i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			c[i]=sc.nextInt();
			d[i]=sc.nextInt();
		}
		calc(1, 1);
		System.out.println(ans);
		sc.close();
	}

	private void calc(int cnt, int min) {
		if(cnt>n) {
			ans =Math.max(ans, a());
			return;
		}
		for(int i=min; i<=m; i++) {
			num[cnt]=i;
			calc(cnt+1, i);
		}
	}

	private long a() {
		long ret = 0;
		for(int i=0; i<q; i++) {
			if(num[b[i]]-num[a[i]]==c[i]) {
				ret += d[i];
			}
		}
		return ret;
	}
}

Measured memory_bytes: 36912
from sys import exit

N = int(input())
if N == 0:
    print(0)
    exit()

lst = []
i = 1
while N:
    n2 = N % 2
    lst.append(n2)
    N = (N - n2 * i) // 2
    i *= -1
print(''.join(map(str, reversed(lst))))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>

using namespace std;
const long long P = 1000000007;

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int count = 0;
  int abroad = 0;
  int people[n];
  for(int i = 0; i < n; i++) {
    people[i] = 0;
    if(s[i] == 'a' && count < a+b) {
      count++;
      people[i] = 1;
    }else if(s[i] == 'b' && count < a+b && abroad < b) {
      count++;
      abroad++;
      people[i] = 1;
    }
  }
  for(int i = 0; i < n; i++) {
    if(people[i]) {
      cout << "Yes" << endl;
    }else {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    gsort(a);
    ll ans = a[0];
    repSE(i,1,(n - 2)/2+1) {
        ans += 2*a[i];
    }
    if (n % 2 == 1) ans += a[(n-2)/2 + 1];
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

int main()
{
	int r, c;
	cin >> r >> c;

	vector< vector<int> > x(r, vector<int>(c));
	vector<int> sumr(c, 0);
	vector<int> sumc(r, 0);
	int temp, sumall = 0;

	for (vector<int>::size_type i = 0; i < r; i++) {
		for (vector<int>::size_type j = 0; j < c; j++) {
			cin >> x[i][j];
			sumall += x[i][j];
		}
	}

	for (vector<int>::size_type i = 0; i < r; i++) {
		for (vector<int>::size_type j = 0; j < c; j++) {
			sumc[i] += x[i][j];
		}
	}

	for (vector<int>::size_type i = 0; i < c; i++) {
		for (vector<int>::size_type j = 0; j < r; j++) {
			sumr[i] += x[j][i];
		}
	}

	for (vector<int>::size_type i = 0; i < r; i++) {
		for (vector<int>::size_type j = 0; j < c; j++) {
			cout << x[i][j] << " ";
			if (j == c - 1) {
				cout << sumc[i];
			}
		}
		cout << "\n";
		if (i == r - 1) {
			for (int i = 0; i < c; i++) {
				cout << sumr[i] << " ";
			}
			cout << sumall << "\n";
		}
	}
}

Measured memory_bytes: 1260
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<vector>
using namespace std;
int main() {

	//D
	/*long long int x, y;
	cin >> x >> y;
	if (abs(x - y) <= 1) {
		cout << "Brown" << endl;
	}
	else {

		cout << "Alice" << endl;

	}
	return 0;
	*/


	//C

	int n;
	cin >> n;
	long long int a[100000];
	int i;
	long long int sum = 0, counter = 0, counterB = 0;
	cin >> a[0];
	if (a[0] == 0) {
		sum = 1;
		counter = 1;
	}
	else {
		sum = a[0];
	}
	for(i = 1;i < n;i++){
		cin >> a[i];

		if (sum < 0) {
			if (sum + a[i] <= 0) {
				counter = counter + abs(-sum + 1 - a[i]);
				sum  = 1;
			}
			else {
				sum = sum + a[i];
			}
			
		}
		else if (sum > 0){
			if (sum + a[i] >= 0) {
				counter = counter + abs(-sum - 1 - a[i]);
				sum = -1;
			}
			else {
				sum = sum + a[i];
			}
		}
		else {
			sum = sum + a[i];
		}
		//sum = sum + a[i];
		//cout << counter << ' ';
	}
	//counterB = abs(a[0])+1;
	if (a[0] > 0){
		counterB = a[0] + 1;
		sum = -1;
	}
	else if(a[0]<0) {
		counterB = -a[0] + 1;
		sum = 1;
	}
	else {
		counterB = 1;
		sum = -1;
	}
	for (i = 1; i < n; i++) {
		//cin >> a[i];

		if (sum < 0) {
			if (sum + a[i] <= 0) {
				counterB = counterB + abs(-sum + 1 - a[i]);
				sum = 1;
			}
			else {
				sum = sum + a[i];
			}

		}
		else if (sum > 0) {
			if (sum + a[i] >= 0) {
				counterB = counterB + abs(-sum - 1 - a[i]);
				sum = -1;
			}
			else {
				sum = sum + a[i];
			}
		}
		//sum = sum + a[i];
		//cout << counter << ' ';
	}

	cout << min(counter, counterB) << endl;
	return 0;
	
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;

        if (aa == 0) {
            cout << 0 << endl;
            return 0L;
        }
    }

    int64_t s = 1;
    double sd = 1;
    for (auto aa : a) {
        s *= aa;
        sd *= aa;

        if (sd >= 2e18) {
            cout << -1 << endl;
            return 0;
        }
    }

    if (s > 1000000000000000000L) {
        cout << -1 << endl;
    } else {
        cout << s << endl;
    }
}

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

using namespace std;

int n, k;

bool need(int m, vector<int> a, int p) {
  a.erase(a.begin() + m);
  vector<vector<bool> > dp(n, vector<bool>(k + 1, false));

  dp[0][0] = true;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j <= k; j++) {
      if (j < a[i]) dp[i + 1][j] = dp[i][j];
      else dp[i + 1][j] = dp[i][j] | dp[i][j - a[i]];
    }
  }

  int flag = false;
  for (int i = max(0, k - p); i < k; i++) {
    if (dp[n - 1][i]) flag = true;
  }

  return flag;
}

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

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

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

  int l = -1, r = n;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (need(m, a, a[m])) r = m;
    else l = m;
  }

  cout << l + 1 << endl;

  return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

double length(double x1, double y1, double x2, double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

bool intersection(double x1, double y1, double x2, double y2, double ret[2][2]){
    double l = length(x1,y1,x2,y2);
    if(l>2.0) return false;
    double theat = atan2(y2-y1, x2-x1);
    double alpha = acos(l/2.0);
    ret[0][0]=x1+cos(theat+alpha);
    ret[0][1]=y1+sin(theat+alpha);
    ret[1][0]=x1+cos(theat-alpha);
    ret[1][1]=y1+sin(theat-alpha);
    return  true;
}
int main(){
    int n;
    double seals[100][2];
    while (true){
        cin >> n;
        if (n == 0) break;
        for(int i = 0; i < n; i++){
            scanf("%lf,%lf", &seals[i][0], &seals[i][1]);
        }
        int max_seals=0;
        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                double ret[2][2];
                if(intersection(seals[i][0], seals[i][1], seals[j][0], seals[j][1], ret)){
                    int counter = 0;
                    for(int k = 0; k < n; k++){
                        double l = length(ret[0][0], ret[0][1], seals[k][0], seals[k][1]);
                        if(l <= 1.000009)counter++;
                    }
                    max_seals = max(counter,max_seals);
                    counter = 0;
                    for(int k = 0; k < n; k++){
                        double l = length(ret[1][0], ret[1][1], seals[k][0], seals[k][1]);
                        if(l <= 1.000009)counter++;
                    }
                    max_seals = max(counter,max_seals);
                }
            }
        }
        if (max_seals == 0)
            cout<<1<<endl;
        else
            cout<<max_seals<<endl;
    }
}

Measured memory_bytes: 1372
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=1e6+10;
const int mod=1e9+7;
ll a[55],b[55],x[55],y[55];

int main()
{
    int n,k1;
    cin>>n>>k1;
    for(int i=0; i<n; i++)
    {
        cin>>a[i]>>b[i];
        x[i]=a[i],y[i]=b[i];
    }
    sort(x,x+n);
    sort(y,y+n);
    ll ans=1ll<<62;
    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            for(int k=0; k<n; k++)
            {
                for(int l=k+1; l<n; l++)
                {
                    ll sx = x[i];
                    ll gx = x[j];
                    ll sy = y[k];
                    ll gy = y[l];
                    int cnt=0;
                    for(int m=0;m<n;m++)
                    {
                        if(a[m]>=sx&&a[m]<=gx&&b[m]>=sy&&b[m]<=gy)
                        {
                            cnt++;
                        }
                    }
                    if(cnt>=k1)
                    {
                        ans=min(ans,(gx - sx)*(gy - sy));
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long 
#define pb push_back
#define fo(i,N) for(int i = 0 ; i < N ; i++)
#define foo(i,x,N) for (int i = x; i < N ; i++)
#define fill(a,val) memset(a,val,sizeof(a))
#define fastio()  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define MAX 1234567
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define inf 1e9+1
#define all(a) a.begin(),a.end()

long long int KnapSack(long long int wt[],ll val[],int N,long long int W)
{
   int n = 1000*N;

   ll dp[N][n+1];

   fo(i,n+1)
   {
    dp[0][i] = inf;
   }
   dp[0][0] = 0;
   dp[0][val[0]] = wt[0];


   foo(i,1,N)
   {
    fo(v,n+1)
    {
      dp[i][v] = dp[i-1][v];
      if ( val[i] <= v)
        dp[i][v] = min(dp[i][v],dp[i-1][v-val[i]]+wt[i]);
    }
   }

   ll ans = 0;
   fo(i,n+1)
   {
    if ( dp[N-1][i] <= W)
    {
      ans = i; 
    }
    
   }
   return ans;
}


int main()
{  
   
   int N;
   long long int W;
   cin >> N >> W;
   long long int wt[N];
   ll val[N];
   
   for (int i=0;i<N;i++)
   {
       cin >> wt[i] >> val[i] ;
       
   }
   cout << KnapSack(wt,val,N,W)  <<endl;
 
    return 0;
}



Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
int W, H, N, x, y, t;
int main() {
	cin >> W >> H >> N;
	int lx = 0, rx = W, ly = 0, ry = H;
	for(int i = 0; i < N; i++) {
		cin >> x >> y >> t;
		if(t == 2) rx = min(rx, x);
		if(t == 1) lx = max(lx, x);
		if(t == 4) ry = min(ry, y);
		if(t == 3) ly = max(ly, y);
	}
	cout << max(rx - lx, 0) * max(ry - ly, 0) << endl;
	return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }




int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int s;
	cin >> s;
	if (s==7||s==5||s==3) puts("YES");
	else puts("NO");
	return 0;
}


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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    string s;
    cin >> s;
    int n = (int)s.length();
    int ta=0, tb=n-1;
    for(int i=0; i<n; ++i){
        if(s[i]=='A'){
            ta = i;
            break;
        }
    }
    for(int i=n-1; i>=0; --i){
        if(s[i]=='Z'){
            tb = i;
            break;
        }
    }

    cout << tb-ta+1;
    return 0;
}


Measured memory_bytes: 3716
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var v = o.l().sort((a,b)=>a-b);
  var ans = v[0];
  for(var i = 1; i < n; i++){
    ans += v[i];
    ans /= 2;
  }
  return ans;
}

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

int main(void) {
	int n;
	int i = 0;
	int a[100];
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (i = n - 1; i > 0; i--) {
		cout << a[i] << ' ';
	}
	cout << a[0] << endl;
	return 0;
}


Measured memory_bytes: 3084
import java.util.*;

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

        int cnt = 0;
        for (int i=0; i<10; i++) {
            if (S.indexOf(Integer.toString(i))>-1) {
                String T = S.substring(S.indexOf(Integer.toString(i))+1);
                for (int j=0; j<10; j++) {
                    if (T.indexOf(Integer.toString(j))>-1) {
                        String U = T.substring(T.indexOf(Integer.toString(j))+1);
                        for (int k=0; k<10; k++) {
                            if (U.indexOf(Integer.toString(k))>-1) {
                                cnt++;
                            }
                        }
                    }
                }
    
            }
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 32176
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 4223352036854775007
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=10005;
const int NN=2005;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    int a,b,k;
    cin >> k;
    cin >> a >> b ;
    if (a/k!=b/k || a%k==0){
        cout << "OK";
    }else {
        cout << "NG";
    }
    cout << E;
    r0;
}
/*









*/


Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n;
    cin >> n;
    vector a(n,0);
    for (int i=0; i<n; i++) cin >> a[i];
    int xsum = accumulate(a.begin(), a.end(), 0, [](int acc, int x){return acc^x;});

    for (int i=0; i<n; i++) {
        cout << (xsum ^ a[i]) << (i==n-1? "\n" : " ");
    }
}

Measured memory_bytes: 3612
// ABC 148-D
// 2019.12.22 bal4u

#include <stdio.h>
#include <ctype.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0; int c;
	do c = gc();
	while (isspace(c));
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int main()
{
	int i, N, x, ans;
	
	x = 1, ans = 0;
	N = in();
	for (i = 0; i < N; ++i) {
		if (in() == x) ++x;
		else ++ans;
	}
	if (ans == N) puts("-1");
	else printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn main() {
    let v: Vec<i64> = read_line().split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (_, x) = (v[0], v[1]);
    let mut ls: Vec<i64> = read_line().split_whitespace().map(|x| x.parse().unwrap()).collect();
    ls.insert(0, 0);

    let count = ls.into_iter()
        .scan(0, |st, l| if *st + l <= x { *st += l; Some(*st) } else { None })
        .count();
    
    println!("{}", count);
}


Measured memory_bytes: 4476
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = Integer.parseInt(sc.next());
	int M = Integer.parseInt(sc.next());
	int C = Integer.parseInt(sc.next());
	int[] b = new int[M];
	for(int i = 0; i<M; i++) {
	    b[i] = Integer.parseInt(sc.next());
	}
	int cnt = 0;
	for(int i = 0; i<N; i++) {
	    int tmp = 0;
	    for(int j = 0; j<M; j++) {
		tmp += sc.nextInt() * b[j];
	    }
	    tmp += C;
	    if(tmp>0) cnt++;
	}
	System.out.println(cnt);
    }
}

Measured memory_bytes: 23380
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define ull unsigned long long
using namespace std;

const int nmax = 100100;
ull N, M;

void read(){
    cin >> N >> M;
    if( N < M) swap(N, M);
}
void pr(ull x)
{
    cout << x << endl;
    exit(0);
}
void solve(){
    if(N == 1 && M == 1) pr(1);
    if(M == 1) pr(N-2);
    pr(N*M - 2 *N - 2*M + 4);
}

int main(){
    read();
    solve();
}

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

q = int(readline())
xdn = list(map(int,read().split()))
mod = 1_000_003

## nCkのmodを求める関数
# テーブルを作る(前処理)
max = mod + 10
fac, finv, inv = [0]*max, [0]*max, [0]*max

def comInit(max):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,max):
      fac[i] = fac[i-1]* i% mod
      inv[i] = mod - inv[mod%i] * (mod // i) % mod
      finv[i] = finv[i-1] * inv[i] % mod

comInit(max)

def prod(l,r):
    #lからr-1までの累積
    res = (fac[r-1] * finv[l-1])%mod
    return res

def solve(x,d,n):
    if(d==0):
        return pow(x,n,mod)
    x0 = (x * inv[d])%mod
    xn = x0 + n
    if(xn > mod)|(x0==0):
        return 0
    res = (prod(x0,xn) * pow(d,n,mod))%mod
    return res


ans = []
for i in range(q):
    x,d,n = xdn[i*3:i*3+3]
    ans.append(solve(x,d,n))

print('\n'.join(map(str,ans)))

Measured memory_bytes: 132096
#include <bits/stdc++.h>
using namespace std;
int main() {
   // cout<<"Hello World!";
   int a,b,c;
   cin>>a>>b>>c;
   if(a+b+c > 22 || a+b+c==22)cout<<"bust";
   else
    cout<<"win";

    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		int a = reader.nextInt();
		int b = reader.nextInt();
		int h = reader.nextInt();
		System.out.println((a+b)*h/2);
	}

	public static void solver(int N, int x, int[] a) {
		int[] min = new int[N];

	}

	// Read Class
	static class FS {
		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() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}

		public boolean hasNext() { skipUnprintable(); 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 int nextInt() {
			return (int)nextLong();
		}
		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();
			}
		}
	}
}

Measured memory_bytes: 7636
N = int(input())
I = int(N**(0.5)//1)
a = []
for i in range(1, I+1):
  if N%i==0:
    j=N//i
    i = len(list(str(i)))
    j = len(list(str(j)))
    k = max(i, j)
    a.append(k)
print(min(a))

Measured memory_bytes: 9368
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

typedef pair<ll,ll> P;
#define INF 114514810

ll vec[2][4] = {{1,0,-1,0} , {0,1,0,-1}};
ll H,W;
vector<vector<ll>> d;
vector<vector<bool>> s;

ll bfs(){
  queue<P> que;
  d.resize(H,vector<ll>(W,INF));
  que.push(P(0,0));
  d[0][0] = 0;
  
  while(que.size()){
    P p = que.front(); que.pop();

    if(p.first == H-1 && p.second == W-1)break;

    for (int i = 0; i < 4; i++) {
      ll nx = p.first + vec[0][i] , ny = p.second + vec[1][i];
      if(0 <= nx && nx < W && 0 <= ny && ny < H && s[ny][nx] && d[ny][nx] == INF){
        que.push(P(nx,ny));
        d[ny][nx] = d[p.second][p.first] + 1;
      }
    }
  }
  return d[H-1][W-1];
}

int main(){
  ll white=0;
  cin >> H >> W;
  s.resize(H,vector<bool>(W));
  for (int i = 0; i < H; i++) {
    for (int l = 0; l < W; l++) {
      char x;
      cin >> x;
      if(x == '.'){
        white++;
        s[i][l] = true;
      }else{
        s[i][l] = false;
      }
    }
  }
  ll a = bfs();
  cout << (a != INF ? white - a - 1 : -1) << endl;
}


Measured memory_bytes: 256
#include <cstdio>

const long long mod=924844033ll;

void ad(long long &a,long long b){a+=b;a%=mod;}

int main()
{
  int n,K;
  scanf("%d%d",&n,&K);
  static long long M[2][2001][2]={0};
  bool b=0;
  M[b][0][0]=1ll;
  for(int i=0;i<2*K;i++){
    for(int j=i;j<n;j+=2*K){
      for(int k=0;k<=n;k++){
	if(k+1<=n&&K<=j){
	  ad(M[!b][k+1][0],M[b][k][0]);
	}
	if(k+1<=n&&j+K<n){
	  ad(M[!b][k+1][1],M[b][k][0]);
	  ad(M[!b][k+1][1],M[b][k][1]);
	}
	ad(M[!b][k][0],M[b][k][0]);
	ad(M[!b][k][0],M[b][k][1]);
	M[b][k][0]=M[b][k][1]=0ll;
      }
      b=!b;
    }
    for(int k=0;k<=n;k++){
      ad(M[b][k][0],M[b][k][1]);
      M[b][k][1]=0;
    }
  }
  static long long P[2001];
  P[0]=1ll;
  for(int k=1;k<=n;k++){
    P[k]=P[k-1]*k%mod;
  }
  long long ans=0ll;
  for(int k=0;k<=n;k++){
    //printf("%lld %lld %lld\n",M[b][k][0],P[n-k],ans);
    ad(ans,M[b][k][0]*P[n-k]%mod*(k%2==0?1:mod-1)%mod);
  }
  printf("%lld\n",ans);
  return 0;
}


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

int n;
string s[50];

int main() {
	while (cin >> n) {
		if (n == 0) { break; }
		
		int i, j, k;
		
		for (i = 0; i < n; i++) { cin >> s[i]; }
		
		for (i = 1; i <= 50; i++) {	//??????i??????
			set<string> codes;
			for (j = 0; j < n; j++) {	//j????????????????????????
				string str;
				str += s[j][0];
				for (k = 1; k < s[j].length(); k++) {
					if (s[j][k-1] == 'a' || s[j][k-1] == 'i' || s[j][k-1] == 'u' || s[j][k-1] == 'e' || s[j][k-1] == 'o') {
						if (str.length() < i) { str += s[j][k]; }
					}
				}
				codes.insert(str);
			}
			if (codes.size() == n) {
				cout << i << endl;
				break;
			}
		}
		if (i > 50) {
			cout << -1 << endl;
		}
	}
	return 0;
}

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

int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  string S;
  cin>>S;
  sort(S.begin(),S.begin()+3);
  cout<<(S=="abc"?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if (A <= 9 && B <= 9) {
        cout << A * B << endl; 
    } else {
        cout << -1 << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
# import sys


# fin = sys.stdin.readline
MOD = 10 ** 9 + 7
S = input()[::-1]
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
base = 1
for i, c in enumerate(S, start=1):
    if c != '?':
        d = int(c) * base % 13
        for r in range(13):
            c = (d + r) % 13
            dp[i][c] += dp[i - 1][r]
            dp[i][c] %= MOD
    else:
        for d in range(10):
            d = d * base % 13
            for r in range(13):
                c = (d + r) % 13
                dp[i][c] += dp[i - 1][r]
                dp[i][c] %= MOD
    base = base * 10 % 13
print(dp[-1][5])


Measured memory_bytes: 61532
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,m;
    cin >> n >> m;
    if(abs(n-m)>1) cout << 0 << endl;
    else if(abs(n-m)>0){
        long long int a=1,b=1;
        for(ll i=1;i<=n;i++) a=a*i%1000000007;
        for(ll i=1;i<=m;i++) b=b*i%1000000007;
        cout << a*b%1000000007 << endl;;
    }
    else{
        long long int a=1;
        for(ll i=1;i<=n;i++) a=a*i%1000000007;
        cout << a*a*2%1000000007 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    int D = scanner.nextInt();
	    int X[][] = new int[N][D];
	    for(int i=0;i<N;i++){
	      for(int j=0;j<D;j++){
	        X[i][j] = scanner.nextInt();
	      }
	    }

	    int resultNumber = 0;
	    int temp = 0;
	    for(int i=0;i<N-1;i++){
	      for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    }
	    System.out.println(resultNumber);
	    scanner.close();
	}

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x,n,p;	cin>>x>>n;
	int data[200]={};
	FOR(i,0,n){
		cin>>p;
		if(p-x>=0)	data[2*(p-x)]++;
		else{
			data[abs(p-x)*2-1]++;
		}		
	}

	FOR(i,0,200){
        
		if(data[i]==0){
			if(i%2==0)	cout<<x+i/2<<endl;
			else	cout<<x-(i+1)/2<<endl;
          return 0;
     }
		
	}

    return 0;
}




Measured memory_bytes: 3640
import sys
from io import StringIO
import unittest


def resolve():
    N, W = map(int, input().split())

    wv = [list(map(int, input().split())) for _ in range(N)]

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

    for i in range(W + 1):
        if i >= wv[0][0]:
            dp[0][i] = wv[0][1]

    # 選ぶ選ばないだと2^n
    for i in range(0, N - 1):
        w = wv[i + 1][0]
        v = wv[i + 1][1]
        for j in range(W + 1):
            if j - w >= 0:
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v)
            else:
                dp[i + 1][j] = dp[i][j]

    print(max([l[-1] for l in dp]))



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 8
3 30
4 50
5 60"""
        output = """90"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000"""
        output = """5000000000"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """6 15
6 5
5 6
6 4
6 6
3 5
7 2"""
        output = """17"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 179060