akhauriyash/Code-Regression huggingface dataset:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    H,W = LI()
    f = [[0] * W for _ in range(H)]
    q = collections.deque()
    for i in range(H):
        for j,x in enumerate(sys.stdin.readline().rstrip()):
            if x == '#':
                f[i][j] = 1
                q.append((i,j,0))
    ans = 0
    while q:
        y,x,c = q.popleft()
        ans = max(ans,c)
        for dy,dx in ((0,1),(1,0),(-1,0),(0,-1)):
            if 0 <= x+dx < W and 0 <= y+dy < H:
                if f[y+dy][x+dx] == 0:
                    f[y+dy][x+dx] = 1
                    q.append((y+dy,x+dx,c+1))
    print(ans)

if __name__ == '__main__':
    main()

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

const int N = 2e5+10;
int n, B[N], a;

int main(){
	cin >> n;
	for(int i=2; i <= n; i++){
		cin >> a;
		B[a]++;
	}
	
	for(int i=1; i <= n; i++){
		cout << B[i] << endl;
	}
}


Measured memory_bytes: 4400
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
using namespace std;
#define ll long long
int main(){
	ll N;
	cin >> N;
	double x[N],y[N];
	for(ll i=0;i<N;i++){
		cin >> x[i] >> y[i];
	}
	double sum=0;
	for(ll i=0;i<N-1;i++){
		for(ll j=i+1;j<N;j++){
			sum+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
		}
	}
	cout <<  setprecision(10) << 2*sum/N ;
    return 0;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
	if (!y)
		return x;
	return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

vector<string> split(char d,string s)
{
	stringstream ss(s);
	string t;
	vector<string> words;
	while(getline(ss,t,d))
	{
		words.pb(t);
	}

	return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
	auto start = chrono::high_resolution_clock::now();
#endif
	
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int k;
	cin>>k;

	ll ans=0;
	for(int i=1;i<=k;++i)
	{
		for(int j=1;j<=k;++j)
		{
			for(int z=1;z<=k;++z)
			{
				ans+=__gcd(__gcd(i,j),z);
			}
		}
	}
	cout<<ans;


#ifdef LOCAL
	auto end = chrono::high_resolution_clock::now();
	double time_taken =
		chrono::duration_cast<chrono::nanoseconds>(end - start).count();

	time_taken *= 1e-9;

	cout << "Time taken by program is : " << fixed
		 << time_taken * 1000 << setprecision(9);
	cout << " sec" << endl;
#endif
	return 0;
}

Measured memory_bytes: 3656
n, q = map(int, input().split())
C = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  C[a-1].append(b-1)
  C[b-1].append(a-1)
dist = [-1]*n
dist[0] = 1
A = [0]*n
F = [0]*n
for _ in range(q):
  p, x = map(int, input().split())
  F[p-1] += x
S = [0]
T = [0]
while S:
  v = S.pop()
  for nv in C[v]:
    if dist[nv] == -1:
      dist[nv] = dist[v] + 1
      S.append(nv)
while T:
  v = T.pop()
  A[v] += F[v]
  for nv in C[v]:
    if dist[nv] > dist[v]:
      A[nv] += A[v]
      T.append(nv)
print(*A)

Measured memory_bytes: 111616
#include<bits/stdc++.h>
using namespace std;
//<<setprecision(20)

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  vector<string> p(3);
  rep(i,3)cin>>p.at(i);
  map<char,string> P;
  P['A'] = p.at(0);
  P['B'] = p.at(1);
  P['C'] = p.at(2);
  char next_p = 'A';
  map<char,int> i;
  i['A'] = 0;
  i['B'] = 0;
  i['C'] = 0;
  while(1){
    if(i[next_p]==(int)P[next_p].size()){
      cout<<next_p<<endl;
      return 0;
    }
    i[next_p]++;
    next_p=P[next_p].at(i[next_p]-1)-0x20;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  string s;
  cin >> s;
  ll ans = 0;
  ll sc = 0;
  rep(i,s.size()) {
    if (s[i] == 'S') {
      ++sc;
    }
    if (s[i] == 'T') {
      if (sc > 0) {
        --sc;
        ans += 2;
      }
    }
  }
  cout << s.size() - ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3748
import java.util.Scanner;

public class Main {
	private Scanner sc;

	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		while (sc.hasNextLine()) {
			int[] points = new int[102];
			
			int p0 = 0;
			int p1 = 0;
			while (sc.hasNextLine()) {
				String[] nico = sc.nextLine().split(" ");
				p0 = Integer.parseInt(nico[0]);
				p1 = Integer.parseInt(nico[1]);
				if ((p0 == 0) && (p1 == 0)) break;
				
				points[p0]++;
				points[p1]++;
			}
			
			String ans = "OK";
			if ((points[1] % 2 != 1) || (points[2] % 2 != 1)) {
				ans = "NG";
			} else {
				for (int i = 3; i < points.length; i++) {
					if (points[i] % 2 != 0) {
						ans = "NG";
						break;
					}
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 33348
n,m,x,y = map(int,input().split())
xi = list(map(int,input().split()))
yi = list(map(int,input().split()))
flagx, flagy, flagz = 0, 0,0
z = 0
for i in range(x+1,y+1):
    for j in range(n):
        if i <= xi[j]:
            flagx = 1
            break
    for k in range(m):
        if i > yi[k]:
            flagy = 1
            break
    if flagx == 0 and flagy == 0:
        flagz =1
        break
    flagx, flagy = 0, 0
if flagz == 0:
    print('War')
else:
    print('No War')

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

#define MAX_N 100000
int N;
int M;
int a[3 * MAX_N];

#define LL long long int
LL INF = 1L<<50;
int main() {
    cin >> N;
    for(int i=0;i<3*N;i++) {
        scanf("%d", a + i);
    }
    priority_queue<LL, vector<LL>, greater<LL>> q_left;
    priority_queue<LL> q_right;
    LL sum_left = 0;
    LL sum_right = 0;
    for(int i=0;i<N;i++) {
        q_left.push(a[i]);
        q_right.push(a[3*N-i-1]);
        sum_left += a[i];
        sum_right += a[3*N-i-1];
    }
    auto dl = vector<LL>(N+1);
    auto dr = vector<LL>(N+1);
    dl[0] = sum_left;
    dr[N] = sum_right;
    for(int i=0;i<N;i++) {
        q_left.push(a[i+N]);
        sum_left -= q_left.top();
        sum_left += a[i+N];
        q_left.pop();
        dl[i+1] = sum_left;
    }
    for(int i=0;i<N;i++) {
        q_right.push(a[2*N-i-1]);
        sum_right -= q_right.top();
        sum_right += a[2*N-i-1];
        q_right.pop();
        dr[N-i-1] = sum_right;
    }
    LL ans = -INF;
    for(int i=0;i<=N;i++) {
        ans = max(ans, dl[i] - dr[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4844
#include <stdio.h>

int trans(int n,int x){
  if(n % 2 == 0 && x > n / 2){
    return n / 2 - (x - n / 2 - 1);
  }
  if(n % 2 == 1 && x > (n + 1) / 2){
    return (n + 1) / 2 - (x - (n + 1) / 2);
  }
  return x;
}

int ans(int x,int y){
  if(y > x - 1){
    return (x - 1) % 3 + 1;
  }
  else{
    return (y - 1) % 3 + 1;
  }

  return -1;
}

int main(void){
  int i;
  int n,k;
  int x,y;

  while(scanf("%d%d",&n,&k) != EOF){
    for(i=0;i<k;i++){
      scanf("%d%d",&x,&y);

      x = trans(n,x);
      y = trans(n,y);

      printf("%d\n",ans(x,y));
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
#define rep_re(i,s,n)for(int i = n;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const int MAX = 4;

static const ll MAX_N = 100001;
static const ll MAX_M = 100001;

ll minV = INF;
ll l[8];
ll a, b, c;
ll N;
void dfs(ll i, ll A, ll B, ll C, ll M, ll T) {
	if (i == N - 1) {
		if (A == 0 || B == 0 || C == 0)return;

		ll v = abs(A - a) + abs(B - b) + abs(C - c) + T;
		if (v < minV) {
			minV = v;
			//cout << minV << endl;
			//cout << A << " " << B << " " << C << " " << M << " " << T << endl;
		}

		return;
	}

	ll I = i + 1;

	dfs(I, A + l[I], B, C, M, (A == 0) ? T : T + 10);
	dfs(I, A, B + l[I], C, M, (B == 0) ? T : T + 10);
	dfs(I, A, B, C + l[I], M, (C == 0) ? T : T + 10);
	dfs(I, A, B, C, M + l[I], T);
}
int main() {
	cin >> N >> a >> b >> c;
	rep(i, 0, N)cin >> l[i];

	dfs(-1, 0, 0, 0, 0, 0);

	cout << minV << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = int64_t;

__attribute__((constructor)) static void init()
{
    ios::sync_with_stdio(false);
    std::cin.tie(0);
}

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}


Measured memory_bytes: 3652
import math
N = int(input())

M_1 = (N+1)/1.08
M_2 = (N)/1.08
if M_2 - int(M_2) == 0 :
    print(int(M_2))
else :
    if math.floor(math.ceil(M_2) * 1.08 ) == N :
        print(math.ceil(M_2))
    else :
        print(':(')

Measured memory_bytes: 3060
program million_change
    implicit none
    character(200000) :: S
    character(200000) :: T
    integer i
    integer :: k = 0
    read *, S
    read *, T
    do i = 1, len_trim(S)
        if(S(i:i) /= T(i:i))then
            S(i:i) = T(i:i)
            k = k + 1
        end if
    end do
    print *, k
end program

Measured memory_bytes: 3388
import java.io.BufferedInputStream
import java.io.InputStream
import java.util.StringTokenizer


fun solve(N: Long, x: DoubleArray, u: Array<String>){
    val unit = u.map{ if (it == "JPY") 1 else 380000 }
    val ans = x.mapIndexed{ index, it -> it * unit[index] }.sum()
    println(ans)
    return
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val x = DoubleArray(N.toInt())
    val u = StringArray(N.toInt())
    for (i in 0 until N.toInt()) {
        x[i] = sc.next().toDouble()
        u[i] = sc.next()
    }
    solve(N, x, u)
}


Measured memory_bytes: 31496
import math
import queue
 
def readInt():
	return int(input())
 
def readInts():
	return list(map(int, input().split()))
 
def readChars():
	return input().split()

x = readInts()
n = x[0]
k = x[1]

def ts(l):
	return int((l*(l-1))/2)

def ts2(l):
	return int(l*(n+n-(l-1))/2)

s = 0

for i in range(k,n+2):
	s += ts2(i)+1-ts(i)

print(s%(1000000007))

Measured memory_bytes: 9648
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int D = sc.nextInt();
    int N = sc.nextInt();
    int ans = (int)Math.pow(100,D);
    
    if(N==100){
      System.out.println(ans*101);
    }
    else{
      System.out.println(ans*N);
    }

  }
}

Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = new int[n];
			int xorSum = 0;
			for (int i = 0; i < n; i++) {
				a[i] = scanner.nextInt();
				xorSum ^= a[i];
			}
			System.out.print((xorSum ^ a[0]));
			for (int i = 1; i < n; i++) {
				System.out.print(" " + (xorSum ^ a[i]));
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 63016
#include <stdio.h>

int main(void) {
int array[100];
int n, i;

scanf("%d", &n);

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

//output reverse array
for (i = n - 1; i > 0; i--) {
printf("%d ", array[i]);
}

printf("%d\n", array[0]);

return 0;
}


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

// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std

Jehian Norman Saviero;

// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;

// MACROS FOR ATTRIBUTE
#define fi first
#define se second

// MACROS FOR FUNCTION AND METHOD
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define ALL(x) (x).begin(), (x).end()
#define ALLSIZE(x,n) (x), (x)+(n)
#define SQR(x) ((x)*(x))
#define CUBE(x) (SQR(x)*(x))

// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main(){
	ll A, B;
	scll(A);
	scll(B);
	ll beff = 0;
	ll curr = 1;
	for (ll i = 2; i <= 100000; ++i){
		beff = curr;
		curr += i;
		if (i == B-A){
			cout << curr - B << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int A,B,K;
  cin >> K>> A >> B ;
  cout << ((B/K-(A-1)/K)>0 ? "OK" : "NG");
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define REP(i, n) for (LL i = 0; i < (LL)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(x.begin(), x.end(),0)
#define vLL(v,n) vector<LL> v(n); REP(i,n)cin>>v[i];
#define vstr(v,n) vector<string> v(n); REP(i,n)REP(i,n)cin>>v[i];
LL INF = 1e9 + 1;
LL MOD = 1e9+7;
  LL a,b,c,d,e,n,m,l,r,ans;
string s,S,t;
LL Func(LL H){
  LL ans2;
  if(H==1)ans2++;
    else {
    ans2+=2*Func(H/2)+1;
    }
  return ans2;
}


int main() {
ios_base::sync_with_stdio(false);
  cin >> n;
cout <<Func(n);
}

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

int main(){
	int q,c,a,n,t;
	cin>>q;
	for(int i=0;i<q;i++){
		t=0;
		cin>>c>>a>>n;
		while(1){
			if(c>0&&a>0&&n>0){
				t++;
				c--;
				a--;
				n--;
			}
			else if(c>1&&a>0){
				t++;
				c-=2;
				a--;
			}
			else if(c>2){
				t++;
				c-=3;
			}
			else break;
		}
		cout<<t<<endl;
	}
	return 0;
}


Measured memory_bytes: 3080
N = int(input())
h = list(map(int, input().split()))

dp = [-1 for _ in range(N)]

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

print(dp[N-1])

Measured memory_bytes: 13928
flag = False

s = input()
t = input()
A = []
finish = False
for i in reversed(range(0,len(s)-len(t)+1)):
    flag = True
    for j in range(len(t)):
        if s[i+j] != t[j] and s[i+j] != '?':
            flag = False
    if flag:
        finish = True
        ans = []
        for k in range(len(s)):
            if i <= k <=i + len(t) -1:
                ans.append(t[k-i])
            else:
                if s[k] == '?':
                    ans.append('a')
                else:
                    ans.append(s[k])
        A.append(ans)
if not finish:
    print('UNRESTORABLE')
else:
    A.sort()
    print(''.join(A[0]))

Measured memory_bytes: 3064
N = int(input())
h = []
for i in range(N):
    abc = [int(x) for x in input().split()]
    h.append(abc)
aDP = [0]*N
bDP = [0]*N
cDP = [0]*N
aDP[0] = h[0][0]
bDP[0] = h[0][1]
cDP[0] = h[0][2]
for i in range(1,N):
    aDP[i] = h[i][0] + max(bDP[i-1],cDP[i-1])
    bDP[i] = h[i][1] + max(aDP[i-1],cDP[i-1])
    cDP[i] = h[i][2] + max(bDP[i-1],aDP[i-1])
print(max(aDP[N-1],bDP[N-1],cDP[N-1]))
#pythonだととおらないのでpypyで通す

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e2 + 10;

int n;
char s[maxN];
bool dp[maxN][maxN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> (s + 1);
    n = strlen(s + 1);
    for1(i, n)
    {
        dp[i][i] = 1;
        if (i < n && s[i] == s[i + 1])
        {
            dp[i][i + 1] = 1;
        }
    }
    fore(len, 3, n)
    {
        for1(i, n - len + 1)
        {
            int j = i + len - 1;
            if (s[i] == s[j])
            {
                dp[i][j] = dp[i + 1][j - 1];
            }
        }
    }
    if (dp[1][n] && dp[1][(n - 1) / 2] && dp[(n + 3) / 2][n])
    {
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}


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

using ll = long long;

using namespace std;

#define maxi(a, b) a = max(a, b)

int main() {
    int n, t;
    cin >> n >> t;
    long a[n], b[n];
    for (int i=0; i<n; i++) cin >> a[i] >> b[i];
    long dp[n+1][t+1][2];
    fill(dp[0][0], dp[n+1][0], 0);
    for (int i=0; i<n; i++) {
        for (int j=0; j<t; j++) {
            if (j + a[i] <= t) {
                maxi(dp[i+1][j+a[i]][0], dp[i][j][0] + b[i]);
                maxi(dp[i+1][j+a[i]][1], dp[i][j][1] + b[i]);
            }
            maxi(dp[i+1][j][0], dp[i][j][0]);
            maxi(dp[i+1][j][1], dp[i][j][1]);
            maxi(dp[i+1][j][1], dp[i][j][0] + b[i]);
            // cerr << dp[i][j][0] << ' ' <<  dp[i][j][1] << '\n';
        }
    }
    long ans = 0;
    dp[n][t][1] = 0;
    for (auto &dpi:dp[n]) {
        ans = max({ans, dpi[0], dpi[1]});
    }
    cout << ans << '\n';
    return 0;
}

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


int main() {
    int  n,k,s;
    cin >> n >> k;
    vector < int > t;
    rep(i, n) {
        cin >> s;
        t.push_back(s);
    }
    sort(t.begin(), t.end());
    int p=0;
    rep(i, k) {
        p = p + t[i];
    }
    cout << p << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  if(n>=65&&n<=90) cout << 1 << endl;
  else if(n>=97&&n<=122) cout << 2 << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define INF INT_MAX
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int n;
string k;
double ans,x;
int main(){
   cin.tie(0);
   ios::sync_with_stdio(false);
   cin>>n;
   FOR(i,n){
     cin>>x>>k;
     if(k=="JPY"){
       ans+=x;
     }else{
       ans+=(x*380000.0);
     }
   }
   printf("%lf\n",ans);
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl q(n);
    rep(i, n) {
        ll p;
        cin >> p;
        p--;
        q[p] = i;
    }

    ll t = 0;
    ll now = 1;
    rep(i, n-1) {
        if(q[i] < q[i+1]) {
            now++;
        }
        else {
            chmax(t, now);
            now = 1;
        }
    }
    chmax(t, now);

    out(n-t);
    re0;
}

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

using namespace std;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
typedef long long LL;

struct edge{
    int to;LL cost;
    bool operator<(const edge& o)const {return cost < o.cost;}
    bool operator>(const edge& o)const {return cost > o.cost;}
};
typedef vector<int> V;
typedef vector<edge> E;
typedef vector<E> Graph;
const LL INF = 1e9;


E dijkstra(int s, Graph &g){
    int n = g.size();
    E dist(n,edge{-1,INF});
    priority_queue<edge, E, greater<edge>> que;
    que.push(edge{s,0});
    while (que.empty() == false){
        auto e = que.top(); que.pop();
        int v=e.to; 
        if (dist[v].cost < e.cost)continue;
	for (auto& d : g[e.to]){
            int u=d.to;
            int nc=e.cost+d.cost;
	    if (dist[u].cost <= nc)continue;
	    dist[u] = edge{v,nc};
	    que.push(edge{u,nc});
	}
    }
    return dist;
}

template<typename T>
void chmin(T& s,T t){
    s=min(s,t);
}
template<typename T>
void chmax(T& s,T t){
    s=max(s,t);
}


int main(){
    int N,K;
    cin>>N;
    Graph g(N+1);
    REP(i,N-1){
        int A,B;
        cin>>A>>B;
        g[A].push_back(edge{B,1});
        g[B].push_back(edge{A,1});
    }
    cin>>K;
    vector<int> v(N+1,-1);
    REP(i,K){
        int n,P;cin>>n>>P;
        v[n]=P;
        g[0].push_back(edge{n,P});
    }
    auto res=dijkstra(0,g);
    REP(i,N){
        if(v[i+1]!=-1&&res[i+1].cost!=v[i+1]){
            cout<<"No"<<endl;return 0;
        }
        v[i+1]=res[i+1].cost;
    }
    FOR(i,1,N+1){
        for(auto &e:g[i]){
            int a=i,b=e.to;
            if(abs(v[a]-v[b])!=1){
                cout<<"No"<<endl;return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    FOR(i,1,N+1){
        cout<<v[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 14320
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<random>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<unordered_map>
#include<time.h>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef long double ld;
signed main() {
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	int dx = gx - sx, dy = gy - sy;
	for (int i = 0; i < dy; i++)
		cout << "U";
	for (int i = 0; i < dx; i++)
		cout << "R";
	for (int i = 0; i < dy; i++)
		cout << "D";
	for (int i = 0; i < dx; i++)
		cout << "L";
	cout << "L";
	for (int i = 0; i < dy + 1; i++)
		cout << "U";
	for (int i = 0; i < dx + 1; i++)
		cout << "R";
	cout << "DR";
	for (int i = 0; i < dy + 1; i++)
		cout << "D";
	for (int i = 0; i < dx + 1; i++)
		cout << "L";
	cout << "U\n";
	getchar(); getchar();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int L, R;
  cin >> L >> R;
  int Lmod = L % 2019;
  int Rmod = R % 2019;
  int ans = 2019;
  if ((R-L) >= 2018){
    ans = 0;
  } else if (Lmod > Rmod){
    ans = 0;
  } else {
    for (int i = Lmod; i <= Rmod; i++){
      for (int j = Lmod; j <= Rmod; j++){
        if (i != j){
          ans = min(ans,(i*j) % 2019);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static String solve(int n) {
        if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9) {
            return "hon";
        } else if (n % 10 == 6 || n % 10 == 8 || n % 10 == 1 || n % 10 == 0) {
            return "pon";
        } else {
            return "bon";
        }
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String res = solve(n);
        System.out.println(res);
    }
}

Measured memory_bytes: 26924
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)

int main()
{
    FAST();
    int a,b, r;
    cin >> a >> b;
    if(a < b)swap(a,b);
    while(b)
        r = a % b,
        a = b,
        b = r;
    outl(a);

}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	if (s[2] != s[3]) {
		puts("No");
		return 0;
	}
	if (s[4] != s[5]) {
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
int main()
{
	SPEED
	char ch;
	int h, w, k;			//h for rows, w for columns
	cin >> h >> w >> k;
	int total_blacks = 0;

	vector<vector<int>> grid(h+1, vector<int>(w+1, 0));

	for (int i = 1; i <= h; ++i)
	{
		for (int j = 1; j <= w; ++j)
		{
			cin >> ch;
			if (ch=='#')
			{
				grid[i][j] = 1;
				total_blacks++;
			}
		}
	}

	vector<int> red_row(h+1, 0);
	vector<int> red_col(w+1, 0);

	for (int i = 1; i <= w; ++i)
	{
		int sum_col = 0;
		for (int j = 1; j <= h; ++j)
		{
			sum_col += grid[j][i]; 
		}

		red_col[i] = sum_col;
	}


	for (int i = 1; i <= h; ++i)
	{
		int sum_row = 0;
		for (int j = 1; j <= w; ++j)
		{
			sum_row += grid[i][j]; 
		}

		red_row[i] = sum_row;
	}


	int rows = 1;
	rows = rows << h;

	int cols = 1;
	cols = cols << w;

	int result = 0;

	for (int r = 0; r < rows; ++r)
	{
		for (int c = 0; c < cols; ++c)
		{
			int count_blacks = total_blacks;

			vector<int> row_index, col_index;

			int pointer = 1;
			int shift = 0;
			while(pointer <= r)
			{
				if (r&pointer)
				{
					count_blacks -= red_row[shift+1];
					row_index.push_back(shift+1);
				}
				pointer = pointer << 1;
				shift++;
			}


			pointer = 1;
			shift = 0;
			while(pointer <= c)
			{
				if (c&pointer)
				{
					count_blacks -= red_col[shift+1];
					col_index.push_back(shift+1);
				}
				pointer = pointer << 1;
				shift++;
			}

			for(int r2 : row_index)
			{
				for (int c2 : col_index)
				{
					if (grid[r2][c2]==1)
					{
						count_blacks++;
					}
				}
			}


			if (count_blacks==k)
			{
				result++;
			}
		}
	}

	cout << result;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long int n,d;
    cin>>n>>d;
    long long int ans=0;
    for(int i=1;i<=n;i++)
    {

        long long int x,y;
        cin>>x>>y;
        if(1LL*x*x+1LL*y*y<=1LL*d*d)
            ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3616
n = int(input())
s = []
ans = []
for i in range(n):
    si = input()
    s.append(si)
s_set = set(list(s[0]))
for si in s_set:
    mm = 10000
    for i in range(n):
        mm = min(mm, s[i].count(si))
    for j in range(mm):
        ans.append(si)
ans = sorted(ans)
value = ""
for s in ans:
    value += s
print(value)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		java.util.Scanner in = new java.util.Scanner(System.in);
		while (in.hasNext()) {
			int x = in.nextInt();
			int sum =0;
			for (int a =0 ; a< 10; a++) {
				for (int b =0;b<10;b++) {
					for (int c = 0;c<10 ;c++) {
						for (int d = 0;d<10;d++) {
							if (a+b+c+d == x) {
								sum++;}}}}}
			System.out.println(sum);}
    }
	
}



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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

ll n, k;
string hand = "rsp";
map<char, ll> score;
ll dp[100001][3];

ll Score(char t, char m) {
  if (t == m) {
    return 0;
  }
  if (t == 'r' && m == 's' ||
      t == 's' && m == 'p' ||
      t == 'p' && m == 'r') {
    return score[t];
  }
  return 0;
}

ll solve(const string& t) {
  dbg(t);
  rep(i, 3) dp[0][i] = 0;
  rep(i, t.size()) {
    rep(j, 3) {
      ll d = 0;
      rep(k, 3) {
        if (k != j) {
          d = max(d, dp[i][k]);
        }
      }
      dp[i + 1][j] = d + Score(hand[j], t[i]);
      dbg(i, j, hand[j], t[i], dp[i + 1][j]);
    }
  }
  ll ret = 0;
  rep(i, 3) ret = max(ret, dp[t.size()][i]);
  dbg(ret);
  return ret;
}

int main() {
  cin >> n >> k;
  rep(i, 3) cin >> score[hand[i]];
  in(string, t);
  vector<string> ts(k);
  rep(i, t.size()) {
    ts[i % k] += t[i];
  }
  ll ans = 0;
  rep(i, k) {
    ans += solve(ts[i]);
  }
  out(ans);
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,w,count=0;
    char a[1010][60];
    cin>>h>>w;
    for(int i=1;i<=h;i++)
        for(int k=1;k<=w;k++)
            cin>>a[i][k];
    for(int i=1;i<=h;i++)
    {
        for(int k=1;k<=w;k++)
        {
            if(a[i][k]=='#') cout<<a[i][k];
            else
            {
                if(a[i-1][k-1]=='#') count++;
                if(a[i-1][k]=='#') count++;
                if(a[i-1][k+1]=='#') count++;
                if(a[i+1][k]=='#') count++;
                if(a[i+1][k-1]=='#') count++;
                if(a[i+1][k+1]=='#') count++;
                if(a[i][k-1]=='#') count++;
                if(a[i][k+1]=='#') count++;
                cout<<count;
            }
            count=0;
        }
        cout<<endl;
    }
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    map<char, bool> entire;
    for(char i = 'a'; i <= 'z'; i++){
        entire[i] = true;
    }
    for(char x : S){
        entire.at(x) = false;
    }
    for(char i = 'a'; i <= 'z'; i++){
        if(entire.at(i)){
            cout << i << endl;
            return 0;
        }
    }
    puts("None");
}

Measured memory_bytes: 512
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll n, m;
	scanf("%ld %ld", &n, &m);
	char s[n+1], t[m+1];
	scanf("%s %s", s, t);

	ll g = n * m / std::__gcd(n, m);
	ll x = g / n, y = g / m;
	bool cant = false;
	std::map<ll,char> mp;
	for(int i=0; i<n; i++){
		if(mp.find(x*i)!=mp.end()){
			if(mp[x*i]!=s[i]) cant = true;
		}else mp[x*i] = s[i];
	}
	for(int i=0; i<m; i++){
		if(mp.find(y*i)!=mp.end()){
			if(mp[y*i]!=t[i]) cant = true;
		}else mp[y*i] = t[i];
	}
	if(cant) puts("-1");
	else printf("%ld\n", g);
	return 0;
}


Measured memory_bytes: 10752
#include<stdio.h>

int main(void){
int a, b, N;
if(scanf("%d %d %d", &N, &a, &b) == 1);
if((b-a)%2 != 0){
printf("Borys\n");
}else if((b-a)%2 == 0) {
printf("Alice\n");
}else{
printf("Draw\n");
}
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
  int i, j, k, l, n, b, f, r, v;
  int count[4][3][10] = {};
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d %d %d %d",&b, &f, &r, &v);
    for(j = 0; j < 4; j++){
      if(j == b - 1){
    for(k = 0; k < 3; k++){
      if(k == f - 1){
        for(l = 0; l < 10; l++){
          if(l == r - 1) count[j][k][l] += v;
        }
      }/*if*/
    }
      }/*if*/
    }
  }
  for(i = 0; i < 4; i++){
    for(j = 0; j < 3; j++){
      for(k = 0; k < 10; k++){
    printf(" %d",count[i][j][k]);
      }
      printf("\n");
    }
    if(i < 3) printf("####################\n");
  }
  return 0;
}

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

#define sz(a) ((int)a.size())
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define forse(i,s,e) for(int i=(int)s;i<(int)e;i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using dbl=double;
using ll=long long;
using pii=pair<int, int>;
using pll=pair<ll, ll>;

dbl PI=3.141592653589793;



void solve(){
	int n;
	cin >> n;
	vector<int> in(n);
	forn(i,n) cin >> in[i];
	sort(all(in));
	reverse(all(in));
	priority_queue<int> proc;
	proc.push(in.front());
	ll out=0;
	forse(i,1,n){
		out+=proc.top();
		proc.pop();
		proc.push(in[i]);
		proc.push(in[i]);
	}
	cout << out;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	for(int c=1;c<=T;c++){
		solve();
	}
}


Measured memory_bytes: 5064
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <utility>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef string str;
typedef vector<ll> vl;
typedef vector<str> vs;
typedef list<ll> listl;

#define min(A, B) min(static_cast<ll>(A), static_cast<ll>(B))
#define max(A, B) max(static_cast<ll>(A), static_cast<ll>(B))
#define all(x) (x).begin(), (x).end()
#define mp make_pair

#define _rep(i, m)		for(ll i = 0, i_max = m; i < i_max; i++)
#define _erep(i, m)		for(ll i = 0, i_max = m; i <= i_max; i++)
#define _brep(i, b, m)	for(ll i = b, i_max = m; i < i_max; i++)
#define _ebrep(i, b, m)	for(ll i = b, i_max = m; i <= i_max; i++)
#define _rrep(i, m)		for(ll i = m; i >= 0; i--)
#define _rerep(i, b, e)	for(ll i = b; i >= e; i--)

#define rep(m)			_rep(i, m)
#define erep(m)			_erep(i, m)
#define brep(b, m)		_brep(i, b, m)
#define ebrep(b, m)		_ebrep(i, b, m)
#define rrep(m)			_rrep(i, m)
#define rerep(b, e)		_rerep(i, b, e)

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

void in(ll& I)
{
	cin >> I;
}

void in(vl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(vs& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(listl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(str& s)
{
	cin >> s;
}

void out(ll O)
{
	cout << O;
}

void out(vl& O)
{
	for (auto& o : O)
	{
		cout << o;
	}
}

void rout(bool b, str True, str False)
{
	if (b) cout << True.c_str();
	else cout << False.c_str();
}

ll count(ll Num)
{
	ll r = 0;
	rep(6)
	{
		if (Num & 1 << i)r++;
	}
	return r;
}

int main()
{
	ll H, W, K;
	in(H);
	in(W);
	in(K);

	vl h(H);
	vl w(W);

	ll Max = 0;

	rep(H)
	{
		str buf;
		in(buf);

		h[i] = 0;

		_rep(j, W)
		{
			h[i] += (buf[j] == '#' ? 1 : 0) << j;
		}

		Max += count(h[i]);
	}

	rep(W)
	{
		w[i] = 0;

		_rep(j, H)
		{
			w[i] += ((h[j] & 1 << i) == 0 ? 0 : 1) << j;
		}
	}

	ll redu = Max - K;

	if (redu < 0) {
		out(0);
		return 0;
	}
	if (redu < 0) {
		out(1);
		return 0;
	}

	ll Num = 0;

	rep(pow(2,H))
	{
		ll c = redu;
		ll hb = pow(2, H) - 1;
		_rep(j, H)
		{
			if (i & 1 << j)
			{
				c -= count(h[j]);
				hb -= 1 << j;
			}
		}

		if (c < 0) continue;

		_rep(j, pow(2, W))
		{
			ll cc = c;

			_rep(i2, W)
			{
				if (j & 1 << i2)
				{
					cc -= count(w[i2] & hb);
				}
			}

			if (cc == 0)Num++;
		}
	}

	out(Num);

	return 0;
}


Measured memory_bytes: 4096
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 5e14;
const double eps = 1e-10;
const double PI = acos(-1);
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll a, b, c, n, m;
string s, t;

int main() {
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	bool fl = 0;
	int f = 0;
	for (int j = 0;j < 26;j++) {
		if (j + 'A' == s[1])f++;
	}
	for (int j = 0;j < 26;j++) {
		if (j + 'A' == s[s.size()-1])f++;
	}
	for (int i = 2;i < s.size() - 1;i++) {
		if (s[i] == 'C')fl = 1;
		for (int j = 0;j < 26;j++) {
			if (j + 'A' == s[i])f++;
		}
	}
	if (f == 1 && fl) {
		cout << "AC" << endl;
	}
	else {
		cout << "WA" << endl;
	}
	return 0;
}


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

//AOJ Daruma Otoshi
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1611&lang=jp


void rec(int n) {
    vector<int> w(n);
    rep(i,n) cin >> w[i];
    vector<vector<int>> dp(n+1,vector<int>(n+1));
    rep(i,n)rep(j,n) dp[i][j] = 0;
     
    for(int d=2;d <= n;d++){
        for(int l = 0;l < n;l++){
            int r = l+d;
            if(r>n)continue;
            if(dp[l+1][r-1]==d-2 && abs(w[l]-w[r-1])<=1) dp[l][r] = d;
            for(int mid = l;mid <= r;mid++) dp[l][r] = max(dp[l][r],dp[l][mid]+dp[mid][r]);
        }
    }

    cout << dp[0][n] << endl;
    
}

int main(){
    int n;
    cin >> n;
    while(n>0){
        rec(n);
        cin >> n;
    }
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x, y;
    cin>>x>>y;
    int sum=0;
    if(x==1){
        sum+=300000;
    }
    if(x==2){
        sum+=200000;
    }
    if(x==3){
        sum+=100000;
    }
    if(y==1){
        sum+=300000;
    }
    if(y==2){
        sum+=200000;
    }
    if(y==3){
        sum+=100000;
    }
    if(x==1&&y==1){
        sum+=400000;
    }
    cout<<sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,k;
  cin>>n;cin>>k;
  if(n<k)
  cout<<"0";
  else if((2*k)>=n)
  cout<<"0";
  else
  cout<<n-(2*k);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
long double lfabs(long double a)
{
   if(a < 0) a *= -1;
   return a;
}

int main()
{
   int i,j,k,l;
   long double x;
   int q;
   while(1) {
      cin >> q;
      if(q == -1) break;

      x = (long double)q/2;
      while(1) {
         x = x - (x*x*x - q) / (3*x*x) ;
         /* 3*x*x だと駄目だった */
         if( lfabs(x*x*x-q) < 0.00001*q ) break;
      }
      printf("%llf\n",x);
   }
   
   return 0;
}

Measured memory_bytes: 1188
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] a = sc.nextLine().split(" ");

        int ab = Integer.parseInt(a[0]+a[1]);

        for(int i=2; i<ab; i++) {
            if(Math.pow(i,2) == ab) {
                System.out.println("Yes");
                System.exit(0);
            }
        }
        System.out.println("No");
        sc.close();
    }
}


Measured memory_bytes: 21972
#include <stdio.h>

int main(void){
    int total_l, curtain_s;
    scanf("%d %d", &total_l, &curtain_s);

    int curt2 = 2* curtain_s;
    if (curt2 < total_l) {
        printf("%d\n", total_l - curt2);
    } else {
        printf("0\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long int ans=0;
	int t=n/500;
	ans+=t*1000;
	t=n%500;
	t/=5;
	ans+=5*t;
	cout<<ans<<endl;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define deb(x) cout<<#x<<" : "<<x<<endl;
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}


signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int n;
    cin>>n;
    vector<int> v(n);
    cin>>v;

    vector<int> pmin(n);

    pmin[0]=v[0];
    for(int i=1;i<n;i++)
    {
        pmin[i] = min(pmin[i-1],v[i]);
    }

    //cout<<pmin<<endl;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(v[i]<=pmin[i])ans++;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,A,B;
    cin >> N >> A >> B;
    cout << min(A,B) << " " << max(0, A + B - N) << endl;
}

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

int32_t main()
{
  string str[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI" ,"SAT"};
	string a; cin>>a;
  int i;
  for( i = 0; i < 7; i++)
  {
    if(str[i] == a) break;
  }
  	cout<<7 - i;
return 0;
}


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

using namespace std;

int main()
{
    int x,n,t;

    double t2;

    cin >> n >> x >> t;

   // t2 = (double)t*(n/x);
    double d = (double)n/x;

    t = t*ceil(d);
    cout << t << endl;

    return 0;
 }


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
set<int> s;
int n,a[maxn],ans[maxn];
void dfs(int u,int pre){
	auto it=s.lower_bound(a[u]);
	int del=-1;
	if(it!=s.end()){
		del=*it;
		s.erase(it);
	}	 
	s.insert(a[u]);
	ans[u]=s.size();
	for(int i=head[u];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(v!=pre) dfs(v,u);
	}
	s.erase(a[u]);
	if(del!=-1) s.insert(del);
}
int main(){
	cin>>n;mem(head,-1);
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<n;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	dfs(1,-1);
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
}

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

using namespace std;

int
main(void)
{
    int N;
    long long A[100001], B[100000];
    long long sum = 0;

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

    for(int i = 0; i < N; ++i) {
        for(int j = 0; j <= 1; ++j) {
            if(B[i] > A[i+j]) {
                B[i] -= A[i+j];
                A[i+j] = 0;
            }
            else {
                A[i+j] -= B[i];
                B[i] = 0;
            }
        }
    }

    for(int i = 0; i <= N; ++i) {
        sum -= A[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 1920
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {

	    int sum = stdin.nextInt();

	    if ( sum == 0 ) {
		break;
	    }

	    for ( int i = 0; i < 9; i++ ) {
		sum -= stdin.nextInt();
	    }
	    System.out.println( sum );
	}	
    }    
}

Measured memory_bytes: 17200
import bisect

n, q = map(int, input().split())
Q = [[] for i in range(n)]

for i in range(q):
    query = list(map(int, input().split()))
    
    if query[0] == 0: bisect.insort_left(Q[query[1]], query[2])
    elif query[0] == 1 and len(Q[query[1]]): print(Q[query[1]][-1])
    elif query[0] == 2 and len(Q[query[1]]): Q[query[1]].pop(-1)


Measured memory_bytes: 13204
n, y = map(int, raw_input().split())
for w in xrange(n + 1):
    for k_5 in xrange(n - w + 1):
        k = n - w - k_5
        if w * 10000 + k_5 * 5000 + k * 1000 == y:
            print w, k_5, k
            exit()
print -1, -1, -1


Measured memory_bytes: 2568