akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <cassert>

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

using namespace std;

tuple<int, char> parsel(string s) {
    return make_tuple(s.size() - 1, s.back());
}
int c = 0;
int solve(int level,  const vector<tuple<int, char>>& code) {
    int l; char op; tie(l, op) = code[c]; c+=1;
    assert(level == l);
    if(isdigit(op)) {
        int num = op - '0';
        return num;
    }
    assert(op == '+' || op == '*');
    vector<int> vs;
    while (c < code.size() && get<0>(code[c]) > level){
        vs.push_back(solve(level + 1, code));
    }
    if (op == '+') {
        int res = 0;
        REP(i, vs.size()) res += vs[i];
        return res;
    }else{
        int res = 1;
        REP(i, vs.size()) res *= vs[i];
        return res;
    }
}
int main() {
    while(true) {
        int n; cin >> n;
        if (n == 0) break;
        vector<tuple<int, char>> code(n);
        REP(i, n) {
            string k; cin >> k;
            code[i] = parsel(k);
        }
        c = 0;
        cout << solve(0, code) << endl;
    }
}


Measured memory_bytes: 3152
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);

			int k = sc.nextInt();
			int x = sc.nextInt();
			long sum = k*500;
			
			if(sum>=x) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}

		}

	}
	

	

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;


int main(){
    int A, B;
    cin >> A >> B;
    int h = 100, w = 100;

    string res[100];

    for(int i = 0; i < 100; i++){
        res[i] = string(100, (i < 50? '#':'.'));
    }

    int cnt = 0;
    for(int i = 0; i < 100 && cnt < A-1; i+=2){
        for(int j = 0; j < 100 && cnt < A-1; j+=2){
            cnt++;
            res[i][j] = '.';
        }
    }
    cnt = 0;
    for(int i = 52; i < 100 && cnt < B-1; i+=2){
        for(int j = 0; j < 100 && cnt < B-1; j+=2){
            cnt++;
            res[i][j] = '#';
        }
    }

    cout << h << " " << w << endl;
    for(int i = 0; i < h; i++){
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(br.readLine());

		for(int i = 1; i <= n; i++){

			int x = i;

			if(x % 3 == 0){
				sb.append(" " + i);
			}else{
				while(x != 0){
					if(x % 10 == 3){
						sb.append(" " + i);
						break;
					}else{
						x /= 10;
					}
				}
			}
		}

		System.out.println(sb);


	}
}

Measured memory_bytes: 25868
#include <iostream>

using namespace std;

int main() {
    int x;
    cin >> x;
    int i=1;
    while(i<=x)
    {
        if(i%3==0|i%10==3)
            cout << " " << i;
            
        else if(i<100 && i/10==3) 
        cout << " " << i;
        
        else if (i>=100 && i<1000){ 
        if( i/100==3|i/10%10==3)
        cout << " " << i;
        }
        
        else if (i>=1000 && i<10000 ){
            if(i/10%10==3|i/100%10==3|i/1000==3)
            cout << " " << i;
        }
        
      i++;
    }
    cout << endl;
}


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

int main()
{
    long long W, H, x, y;
    cin >> W >> H >> x >> y;

    cout << setprecision(20) << double(W * H) / 2. << " ";
    cout << (x * 2 == W && y * 2 == H) << endl;
}


Measured memory_bytes: 256
s = [int(_) for _ in input().strip()]
diff = 2222222


def abs(x):
    if x < 0:
        return -x
    else:
        return x


for i in range(len(s)-2):
    x = 100 * s[i] + 10 * s[i+1] + s[i+2]
    if abs(x-753) < diff:
        diff = abs(x-753)
    else:
        continue
print(diff)


Measured memory_bytes: 2940
/*
█████████───███─────────███───███─────────████████████───███████████████───████████████───████████████───█████████───────
█████████───███─────────███───███─────────████████████───███████████████───████████████───████████████───█████████───────
█████████───███─────────███───███─────────████████████───███████████████───████████████───████████████───█████████───────
███─────────███─────────███───███─────────███──────███───███───███───███───███──────███───███──────███───███─────────────
███─────────███─────────███───███─────────███──────███───███───███───███───███──────███───███──────███───███─────────────
███─────────███─────────███───███─────────███──────███───███───███───███───███──────███───███──────███───███─────────────
█████████──────███───███──────███─────────████████████───███───███───███───████████████───███──────███───█████████───────
█████████──────███───███──────███─────────████████████───███───███───███───████████████───███──────███───█████████───────
█████████──────███───███──────███─────────████████████───███───███───███───████████████───███──────███───█████████───────
███────────────███───███──────███─────────███──────███───███───███───███───███────────────███──────███─────────███───────
███────────────███───███──────███─────────███──────███───███───███───███───███────────────███──────███─────────███───────
███────────────███───███──────███─────────███──────███───███───███───███───███────────────███──────███─────────███───────
█████████─────────███─────────█████████───███──────███───███───███───███───███────────────████████████───█████████───────
█████████─────────███─────────█████████───███──────███───███───███───███───███────────────████████████───█████████───────
█████████─────────███─────────█████████───███──────███───███───███───███───███────────────████████████───█████████───────
*/
/**

**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fori(n) for ( int i = 0; i < (n);i++)
#define forj(n) for ( int j = 0; j < (n);j++)
#define fork(n) for ( int k = 0; k < (n);k++)
#define forghj(n) for ( int ghj = 0; ghj < (n);ghj++)
#define fori1(n) for ( int i = (n)-1; i >= 0;i--)
#define all(vector) (vector).begin(),(vector).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define INF 1e9+7
#define EPS 1e-7
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize "-O3"



int main() {
    int M, D;
    cin >> M >> D;
    int ans = 0;
    for (int d = 22; d <= D; d++) {
        if (d % 10 <= 1) continue;
        if ((d % 10) * (d / 10) <= M) ans++;
    }
    cout << ans;
}

















Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0

for i in range(N-1):
    while a[i]+a[i+1] > x:
        if a[i]>x:
           count += a[i]-x
           a[i] = x
        else:
           count += a[i+1] - (x-a[i])
           a[i+1] = x - a[i]

print(count)

Measured memory_bytes: 14252
let n = Int(readLine()!)!
let p = readLine()!.characters.split(" ").map{Int(String($0))!}
var ans = 0
for i in 1..<n-1 {
    let arr = [p[i-1], p[i], p[i+1]].sort()
    if p[i] == arr[1] {
        ans += 1
    }
}
print(ans)


Measured memory_bytes: 4208
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a[5], i, b=0, c=0, ans=0;
    for(i=0; i<5; i++)
    {
        cin >> a[i];
        c=(a[i]/10);
        if(a[i]%10!=0)
        {
            ans=max(ans,c*10+10-a[i]);
            b+=c*10+10;
        }
        else
            b+=a[i];
    }
    cout << b-ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define here(x) cout << " #x = " << x << endl;
#define show(x) {for( auto ii : x) cout << ii << en; cout << endl;}
#define shop(n,x) {for(int i = 0; i < n; i++) cout << x << en; cout << endl;}
#define ff first
#define ss second
#define sq(x) (x*x)
#define endl '\n'
#define en " "
#define pb push_back
#define mpair make_pair
ll mod=1000000007;
double pi=3.1415926536;
ll n;
int main()
{
	fastio();
	int tt = 1;
	//cin >> tt;
	while(tt--)
	{
		// go fast 		check		//		CHECK -> if()   else if()
		
		ll x=0, m=0, y=0, d=1, k=mod;
		cin >> n;
		ll abc[n][3], dp[n][3];

		for(int i = 0; i < n; i++)
			cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
		
		for(int i = 0; i < 3; i++)
			dp[n - 1][i] = abc[n - 1][i];

		for(int i = n - 2; i >= 0; i--)
			for(int j = 0; j < 3; j++)
				dp[i][j] = abc[i][j] + max(dp[i + 1][(j + 1) % 3], dp[i + 1][(j + 2) % 3]);
	
		for(int i = 0; i < 3; i++)
			x = max(x, dp[0][i]);

		cout << x << endl;
	}
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

long long nCb(long long n, long long b){
    long long ans = 1LL;
    for (long long i = 0; i < b; ++i){
        ans *= n - i;
        ans /= i + 1LL;
    }
    return ans;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    vector<long long> vs(N, 0);
    for (auto &v : vs) cin >> v;
    sort(vs.begin(), vs.end(), greater<long long>());

    long long total = 0;
    for (int i = A - 1; i >= 0; --i) total += vs[i];
    double avg = double(total) / A;
    long long t = vs[A - 1];
    int idx1 = 0;
    for (; vs[idx1] != t; ++idx1);
    int idx2 = A - 1;
    for (; (idx2 < N) && (vs[idx2] == t); ++idx2);

    long long ans = 0;
    if (idx1 == 0){ // 降順にA個が全てtであるとき。
        int maxK = min(idx2, B);
        for (int k = A; k <= maxK; ++k) ans += nCb(idx2, k);
    }else{
        long long n = idx2 - idx1; // 値が t であるものの個数
        long long b = A - idx1;    // 値が t であるものを最低何個選ぶ必要があるか
        ans = nCb(n, b);
    }
    cout << fixed << avg << endl;
    cout << dec << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
	val k = readLine()!!.toInt()
  	val (a, b) = readLine()!!.split(" ").map(String::toInt)
  	var i = 0
  	var flg = 0
  
  	val count = 1000 / k
  
  	for (i in 0..count) {
     	val len = i * k
      	if(len >= a && len <= b) {
        	print("OK")
          	flg = 1
          	break;
        }
    }
  	if (flg == 0) {
     	print("NG") 
    }
}

Measured memory_bytes: 36304
def plus(pl):
    if len(pl) == 1:
        return pl[0]
    pl.sort()
    tmp = pl.pop(0)
    while len(pl) > 1:
        tmp2 = pl.pop(0)
        print(tmp, tmp2)
        tmp -= tmp2
    print(pl[0], tmp)
    return pl[0]-tmp


def minas(mi):
    if len(mi) == 1:
        return mi[0]
    mi.sort()
    tmp = mi.pop()
    while len(mi) > 1:
        tmp2 = mi.pop()
        print(tmp, tmp2)
        tmp -= tmp2
    print(tmp, mi[0])
    return tmp-mi[0]


n = int(input())

mi = []
pl = []

for i in [int(j) for j in input().split()]:
    if i < 0:
        mi.append(i)
    else:
        pl.append(i)

if len(pl) == 0:
    print(2*max(mi)-sum(mi))
    minas(mi)
elif len(mi) == 0:
    print(sum(pl)-2*min(pl))
    plus(pl)
else:
    print(abs(sum(mi))+sum(pl))
    mi.sort()
    pl.sort(reverse=True)
    while len(pl) > 1:
        tmp = pl.pop()
        print(mi[0], tmp)
        mi[0] -= tmp

    while len(mi) > 1:
        tmp = mi.pop()
        print(pl[0], tmp)
        pl[0] -= tmp

    print(pl[0], mi[0])


Measured memory_bytes: 13864
import java.util.*;
import java.math.BigInteger;

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

  private void run() {
    int n = sc.nextInt();

    for(int i = 0; i < n; i++) {
      BigInteger a = sc.nextBigInteger();
      BigInteger b = sc.nextBigInteger();

      BigInteger sum = a.add(b);

      if(sum.compareTo(bound) >= 0) System.out.println("overflow");
      else System.out.println(sum);
    }
  }

  private final Scanner sc = new Scanner(System.in);
  private final BigInteger bound = BigInteger.TEN.pow(80);
}

Measured memory_bytes: 12000
#include <iostream>
#include <climits>

using namespace std;


int main() {
	int N, W;

	cin >> N >> W;

	int *weight = new int[N], *value = new int[N];

	for (int i = 0; i < N; i++) {
		cin >> weight[i] >> value[i];
	}

	int vmax = value[0];
	for (int i = 1; i < N; i++) {
		vmax += value[i];
	}


	int **DP = new int*[vmax + 1];

	for (int i = 0; i <= vmax; i++) {
		DP[i] = new int[N];
	}

	for (int i = 0; i < N; i++)
		DP[0][i] = 0;

	for (int i = 1; i <= vmax; i++)
		if (value[0] >= i)
			DP[i][0] = weight[0];
		else
			DP[i][0] = INT_MAX / 2;

	for (int i = 1; i < N; i++) {
		for (int j = 1; j <= vmax; j++) {
			if (j - value[i] < 0) {
				if (weight[i] < DP[j][i - 1])
					DP[j][i] = weight[i];
				else
					DP[j][i] = DP[j][i - 1];
			}
			else if (DP[j - value[i]][i - 1] + weight[i] < DP[j][i - 1])
				DP[j][i] = DP[j - value[i]][i - 1] + weight[i];
			else
				DP[j][i] = DP[j][i - 1];
		}
	}

	int ans = 0;
	for (int i = vmax; i >= 0; i--) {
		if (DP[i][N - 1] <= W) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;

	delete[] value;
	delete[] weight;
	for (int i = 0; i <= vmax; i++)
		delete[] DP[i];
	delete[] DP;

	return 0;
}

Measured memory_bytes: 41600
#include <bits/stdc++.h>
#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() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    vector<vector<int>> c(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> c[i][j];

    vector<int> x, y;
    x = y = vector<int>(3);

    x[0] = 0;
    rep(i, 3) y[i] = c[0][i] - x[0];
    for(int i = 1; i < 3; ++i) x[i] = c[i][0] - y[0];
    rep(i,3) rep(j,3) {
        if(c[i][j] != x[i] + y[j]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3636
s = list(input())
n = len(s)
dp = [[0]*13 for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    flag = 1 if s[i]=='?' else 0
    for a in range(10):#i+1桁目の数字(0-9)
        if flag==1 or s[i]==str(a):
            for j in range(13): #あまり(0-12)
                dp[i+1][(j*10+a)%13] += dp[i][j] #i桁目の余りの10倍とi桁目を足して余りをだす
    for j in range(13):
        dp[i+1][j]%=10**9+7
print(dp[n][5])


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

int main(){
  int n;
  cin >> n;
  std::vector<int64_t> a(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  // 最小値、最大値、合計値
  int64_t minV = *std::min_element(begin(a), end(a));
  int64_t maxV = *std::max_element(begin(a), end(a));
  int64_t sumV = std::accumulate(begin(a), end(a), 0LL); // long long
  cout << minV << " " << maxV << " " << sumV << endl;
}



Measured memory_bytes: 3172
import fractions
n=int(input())
a=list(map(int,input().split()))
l=[a[0]]
for i in range(1,n):
    l.append(fractions.gcd(l[-1],a[i]))
    if l[-1]==1:
        for j in range(n-len(l)):l.append(1)
        break
r=[a[-1]]
for i in range(n-2,-1,-1):
    r.append(fractions.gcd(r[-1],a[i]))
    if r[-1]==1:
        for j in range(n-len(r)):r.append(1)
        break
r=r[::-1]
ans=max(l[-2],r[1])
for i in range(1,n-1):ans=max(ans,(fractions.gcd(l[i-1],r[i+1])))
print(ans)

Measured memory_bytes: 16124
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

struct Edge
{
    int to, cost;
};


int main(){
    int V, E; cin >> V >> E;
    vector<vector<Edge> > g(V);
    for (int i = 0; i < E; i++){
        int s, t, w; cin >> s >> t >> w;
        Edge e; e.to = t; e.cost = w;
        g[s].push_back(e);
        e.to = s;
        g[t].push_back(e);
    }    
    int allCost = 0;
    vector<int> minCost(V, MM);
    minCost[0] = 0;
    vector<bool> visited(V, false);

    while (true){
        int v = -1;
        for (int u = 0; u < V; u++){
            //距離が最小の頂点を探す
            if (!visited[u] && (v == -1 || minCost[u] < minCost[v])) v = u;
        }
        if (v == -1) break;
        visited[v] = true;
        allCost += minCost[v];
        for (int u = 0; u < g[v].size(); u++){
            Edge now = g[v][u];
            minCost[now.to] = min(minCost[now.to], now.cost); 
        }
    }
    cout << allCost << endl;
}


Measured memory_bytes: 5904
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1e18;

int n;
vector<long long> a(440, 0);
vector<long long> sum(440, 0);
vector< vector<long long> > dp(440, vector<long long>(440, -1));

long long rec(int l, int r) {
    long long res = INF;
    if(dp[l][r] != -1) return dp[l][r];
    if(abs(l-r) <= 1) return 0;
    for(int mid = l+1; mid <= r-1; ++mid) {
        chmin(res, (rec(l, mid)+rec(mid, r)));
    }
    return dp[l][r] = res + (sum.at(r)-sum.at(l));
}

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a.at(i);
        sum.at(i+1) = sum.at(i)+a.at(i);
    }

    cout << rec(0, n) << endl;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	cin >> N;
	int rate[9];
	memset(rate, 0, sizeof(rate));
	rep(i, 0, N) {
		int a;
		cin >> a;
		rate[min(a / 400, 8)]++;
	}

	ll rsl = 0;
	rep(i, 0, 8) if(rate[i] > 0) rsl++;
	cout << max(rsl, 1ll) << " " << rsl + rate[8] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<30)

int N, M;
int a[8];
int d[8+1][8+1];

signed main(){
	cin >> N >> M;
	for (int i = 0; i < M; i++){
		int s, t;
		cin >> s >> t;
		d[s][t] = d[t][s] = 1;
	}

	int r = 0;
	for (int i = 0; i < N; i++) a[i] = i + 1;
	do{

		if (a[0] != 1) continue;
		bool f = true;
		for (int i = 0; i < N-1; i++){
			if (d[a[i]][a[i + 1]] == 0) f = false;
		}
		if (f == false) continue;
		r++;

	} while (next_permutation(a, a + N));

	cout << r << endl;

	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair

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

const ll INF= ll (1e18);
const int MOD= 1e9+7;

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

    int a,b;
    cin>>a>>b;

    if(a==1&&b!=1)
        cout<<"Alice";
    else if(a!=1&&b==1)
        cout<<"Bob";
    else if(a==b)
        cout<<"Draw";
    else if(a>b)
        cout<<"Alice";
    else
        cout<<"Bob";


    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())


ans = 0
for i in range(2, n+1):
    if i-1 < k:
        continue
    else:
        #print((i-k)*(n//i), n % i-(i-k))
        ans += (i-k)*(n//i)
        ans += max(0, n % i-(k-1))

if k == 0:
    ans+=1
print(ans)


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

typedef long long ll;
typedef vector<ll> vl;
ll h,w;

int main(int argc, char const *argv[]) {
  int T;
  scanf("%d", &T);
  for(int unko=0;unko<T;unko++){
    string s;
    cin >> s;
    stack<int> po;
    int num = 0;
    for(int i=0;i<s.size();i++){
      if(s[i] == '['){
        po.push(-1);
      }
      else if(s[i] == ']'){
        if(num != 0){
          po.pop();
          po.push((num + 1)/2);
          num = 0;
        }
        else{
          vector<int> v;
          while(po.top() != -1){
            v.push_back(po.top());
            po.pop();
          }
          po.pop();
          sort(v.begin(), v.end());
          int n = 0;
          for(int j=0;j<(v.size() + 1)/2; j++)n += v[j];
          po.push(n);
        }
      }
      else{
        num *= 10;
        num += s[i] - '0';
      }
    }
    printf("%d\n", po.top());
  }
  return 0;
}



Measured memory_bytes: 3248
using System;

namespace WelcomeToAtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long k = long.Parse(Console.ReadLine());
            String s = Console.ReadLine();
            Char[] split = s.ToCharArray();

            String ret = "";

            if (s.Length <= k) ret = s;
            else
            {
                for(int i = 0; i < k; i++)
                {
                    ret += split[i];
                }
                ret += "...";
            }

            Console.WriteLine(ret);
            
        }

    }
}


Measured memory_bytes: 27548
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let _ = lines.next();
    let a = lines
        .next()
        .unwrap()
        .unwrap()
        .split_whitespace()
        .map(|s| s.parse::<i32>().unwrap())
        .collect::<Vec<i32>>();

    let mut ans = 0;
    let mut i = 1;
    for &ai in a.iter() {
        if i != ai {
            ans += 1;
        } else {
            i += 1;
        }
    }
    if i == 1 {
        ans = -1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
char ai[300005];
int  qw[300005];
int  qe[300005];
int main()
{
    int a;
    scanf("%d",&a);
    scanf("%s",ai);
    int  e=0,r=0,sum=1100000;
    for(int i=0;i<a;i++)
    {
        if(ai[i]=='W')
            e++;
        qw[i] = e;
    }
    for(int i = a-1;i>=0;i--)
    {
      if(ai[i]=='E')
            r++;
        qe[i] = r;
    }
    for(int i=0;i<a;i++)
    {
        int su  = qe[i] + qw[i]-1;
        sum = min(su,sum);
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<stack>
#include<iomanip>
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define drep(i,n) for(int i=((int)n)-1;i>-1;i--)
#define Rep(i,n0,n) for(int i=n0;i<((int)n);i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<((int)n);j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
#define INF2 (long long)8*(long long)INF*(long long)INF
#define mod 1000000007
typedef long long ll;

using namespace std;


int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){if(y>x)return y;else return x;}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
long long fact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i;}
int gcd(int x, int y)
{
    if(x%y==0)return y;
    else if(y%x==0)return x;
    else return gcd(x%y,y%x);
}
ll gcd(ll x, ll y)
{
    if(x%y==0)return y;
    else if(y%x==0)return x;
    else return gcd(x%y,y%x);
}


int main()
{
    string S;
    cin>>S;//scanfと同じ
    bool Flag=true;
    int count_C=0,index_C=-1;
    if(S[0]=='A')
    {
        for(int i=2;i<S.size()-1;i++)
        {
            if(S[i]=='C')
            {
                count_C++;
                index_C=i;
            }
            else{}
                
        }
        if(count_C==1)
        {
            for(int i=1;i<S.size();i++)if(i!=index_C)
            {
                if((int)S[i]<123&&(int)S[i]>96)
                {
                    Flag=Flag&&true;
                }
                else
                {
                    Flag=false;
                }
            }
        }
        else
        {
            Flag=false;
        }
    }
    else
    {
        Flag=false;
    }
    if(Flag)
    {
        cout<<"AC"<<endl;
    }
    else
    {
        cout<<"WA"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N;
    cin >> N;
    long long ans = 0;
    for(int i = 1; i <= N; i++){
        if(i%3 != 0 && i%5 != 0) ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
  s.append(list(map(int, input().split())))
  
sdictlist = []
sdictlistsorted = []
for i in range(D):
  onedict = {}
  for j in range(26):
    onedict[j] = s[i][j]
  sdictlist.append(onedict)
  onesorteddict = sorted(onedict.items(), key=lambda x:x[1], reverse=True)
  sdictlistsorted.append(onesorteddict)

lenpastmax = 25
pastlist = []
for i in range(D):
  j = 0
  while(sdictlistsorted[i][j][0] in pastlist):
    j += 1
  print(sdictlistsorted[i][j][0]+1)
  pastlist.append(sdictlistsorted[i][j][0])
  if(len(pastlist)==lenpastmax):
    pastlist.pop(0)

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


int main(){
  int n,i;
  cin >> n;
  vector<int> a(n+1),b(n+1);
  for(i=0;i<n;++i){
    cin >> a[i+1];
  }
  for(i=n;i>=1;--i){
    int sum=0;
    for(int j=i+i;j<=n;j+=i){
      sum ^= b[j];
    }
    b[i]=sum^a[i];
  }
  vector<int> ans;
  for(i=1;i<=n;++i){
    if(b[i])ans.push_back(i);
  }
  cout << ans.size() << endl;
  for(i=0;i<ans.size();++i){
    printf("%d%c",ans[i],i+1==ans.size()?'\n':' ');

  }
  return 0;

}


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

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

const int N = 55;
int dp[N][N][N*N];
int arr[N] , x , n;
int go(int tot , int id , int sum)
{
	if(tot < 0 || id < 0 || sum < 0) return 0;
	if(tot == 0 && sum == 0 && id == 0) return 1;
	int ans = dp[tot][id][sum];
	
	if(ans != -1)   return ans;
	ans = go(tot-1 , id , sum)  + go(tot - 1 , id - 1 , sum - arr[tot]);
	
	return dp[tot][id][sum] = ans;
	
}
int32_t main(){
	fast;

	cin >> n >> x;
	for(int i = 1 ; i<=n ; i++) cin >> arr[i];
	
	memset(dp,-1,sizeof(dp));
	
	int ans = 0;
	for(int i=1 ; i<=n ; i++)  ans += go(n,i,x*i);
	
	cout << ans;
}







Measured memory_bytes: 71808
def main():
    from math import ceil
    N, A, B = (int(i) for i in input().split())
    h = [int(input()) for i in range(N)]

    def is_ok(h,bomb,N,A,B):
        K = bomb
        cur = 0
        for i in range(N):
            cur += ceil((max(h[i] - B * K,0))/(A - B))
        return (cur <= K)

    def binary_search_meguru(Arr,N,A,B):
        left = -1
        right = 10**9 + 1
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(Arr,mid,N,A,B): right = mid
            else: left = mid
        return right
    
    print(binary_search_meguru(h,N,A,B))

if __name__ == '__main__':
    main()

Measured memory_bytes: 51800
from sys import stdin
import math
N = int(stdin.readline().rstrip())
t,a = 1,1
 
for _ in range(N):
    T,A = [int(x) for x in stdin.readline().rstrip().split()]
    n = max((t + T - 1) // T,(a + A - 1) // A)
    t = n*T
    a = n*A
    
print(t+a)

Measured memory_bytes: 3060
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/*
 * メモ
 * Scanner:nextは空白か改行までの単語
 * String[][] c = new String[h][w];
 * TemplateMain,"template_input.txt"
 * 0.5 == 1.0/2
 * Integer.valueOf(char)はダメ、(String)
 */

public class Main {
	
	public static void printlnYN(boolean b){
		if(b) System.out.println("Yes");
		else System.out.println("No");
	}

	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		int len = s.length();
		
		for(int i = 0; i <= 0b111; i++){
			int sum = 0;
			String ans = "";
			sum += Integer.valueOf(""+s.charAt(0));
			ans += s.charAt(0);
			for(int j = 2; j >= 0; j--){
				if((1&(i>>j)) == 1){
					sum -= Integer.valueOf(""+s.charAt(3-j));
					ans += "-" + s.charAt(3-j);
				}else{
					sum += Integer.valueOf(""+s.charAt(3-j));
					ans += "+" + s.charAt(3-j);
				}
			}
			
			if(sum == 7){
				ans += "=7";
				System.out.println(ans);
				break;
			}
		}
	}

}

Measured memory_bytes: 22100
s=int(input())
if s<6:
  print(int(s>2))
  exit()
dp=[0]*(s+1)
dp[3]=1
dp[4]=1
dp[5]=1
for i in range(6,s+1):
  dp[i]=dp[i-1]+dp[i-3]
print(dp[s]%(10**9+7))

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

const int MAXN    = 21;			//maximum number of couples
const int MAXL    = 1<<21+2;	//maximum number of couples
const int BIG_NUM = 1000000007;

int N;					//number of couples
int dp[MAXN][MAXL];	//dp lookup table
int comp[MAXN];		//compatibility

int solve(int currI,int usedJ){
	if(currI==N)
		return (__builtin_popcount(usedJ)==N);//if all are used
	
	if(dp[currI][usedJ]!=-1)
		return dp[currI][usedJ];

	int total = 0;

	for(int j=0;j<N;j++)
		if( !(usedJ&(1<<j)) && comp[currI]&(1<<j) )
			total = (total+solve(currI+1,usedJ|(1<<j)))%BIG_NUM;

	return dp[currI][usedJ] = total;
}

int main(){
	cin>>N;

	memset(dp  ,-1,sizeof(dp));
	memset(comp, 0,sizeof(comp));

	int temp;
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++){
			cin>>temp;
			comp[i]|=temp<<j;
		}

	cout<<solve(0,0)<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;
const int INF = 1e5;

int pow(int t, int n){
    int ret = 1;
    REP(i,n) ret *= t;
    if(ret == 1) ret = 0;
    return ret;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> S(M);
    vector<int> C(M);
    REP(i,M){
        int s, c;
        cin >> s >> c;
        S[i] = s;
        C[i] = c;
    }

    int ans = INF;
    REPi(x, pow(10, N-1), pow(10,N)){
        bool valid = true;
        vector<int> X(N);
        int y = x;
        REP(i,N){
            X[i] = y % 10;
            y /= 10;
        }
        reverse(X.begin(), X.end());

        REP(i,M){
            int s, c;
            s = S[i];
            c = C[i];
            if(c != X[s-1])
                valid = false;
            //if(N != 1 && s == 1 && c == 0)
            //    valid = false;
        }
        if(valid){
            chmin(ans, x);
        }
    }

    if(ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan=new Scanner(System.in);
		String n=scan.next();
		String oomoji=n.toUpperCase();
		String komoji=n.toLowerCase();
		if(n==oomoji) {
			System.out.println("A");
		}else {
			System.out.println("a");
		}
	}

}


Measured memory_bytes: 35708
#include <stdio.h>

int main(void){
  int N, K, X, Y;
  scanf("%d %d %d %d",&N, &K, &X, &Y);
  if(1<=Y<=X<=10000 && 1<=N<=10000 && 1<=K<=10000){
    if (N<=K){
    printf("%d\n", X*N);
  	} else if (N>K){
    printf("%d\n", X*K+Y*(N-K));
   }
   } else {
        printf("%s\n","Invalid.");
   }
      return 0;    
 }
                   
                    


Measured memory_bytes: 1732
require 'prime'

N = gets.to_i
factors = {}
for i in 2..N
    ifacts = i.prime_division
    ifacts.each do |fac|
        if !(factors.has_key?(fac.first))
            factors.store( fac.first, fac.last )
        else
            factors[fac.first] += fac.last
        end
    end
end

# p factors

cnt = 1
factors.each_value do |exp|
    cnt *= exp + 1
    cnt %= 10**9 + 7
end
puts cnt

Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 9e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);

    int n;
    cin >> n;
    vector<pair<int, int> > s1, s2;

    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        for(auto it = s.find("()"); it != string::npos; it = s.find("()")) {
            s.erase(it, 2);
        }

        int l = count(all(s), ')');
        int r = count(all(s), '(');

        if (r - l >= 0) {
            s1.push_back(make_pair(l, r));
        }
        else {
            s2.push_back(make_pair(l, r));
        }
    }

    sort(all(s1), [](const auto& l, const auto& r){
        return l.fi < r.fi;
    });
    sort(all(s2), [](const auto& l, const auto& r){
        return l.se > r.se;
    });

    int l = 0, r = 0;
    for (auto s: s1) {
        l = l + s.fi - min(s.fi, r);
        r = r - min(s.fi, r) + s.se;
    }
    for (auto s: s2) {
        l = l + s.fi - min(s.fi, r);
        r = r - min(s.fi, r) + s.se;
    }


    if (l == 0 && r == 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 11252
#include<cstdio>
#include<algorithm>
using namespace std;
int n, t, x, y;
int nt, nx, ny;
int main() {
	int i;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d%d", &t, &nx, &ny);
		int d = abs(nx - x) + abs(ny - y);
		if (d > t || d % 2 != t % 2) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}

Measured memory_bytes: 128
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from heapq import heappop, heappush
import sys
def main(X, Y, Z, K, A, B, C):
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
    used = set()
    q = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
    used.add((0, 0, 0))
    for i in range(K):
        v, ai, bi, ci = heappop(q)
        print(-v)
        for nai, nbi, nci in [(ai + 1, bi, ci), (ai, bi + 1, ci), (ai, bi, ci + 1)]:
            if nai >= X or nbi >= Y or nci >= Z: continue
            if (nai, nbi, nci) in used: continue
            used.add((nai, nbi, nci))
            heappush(q, (-(A[nai] + B[nbi] + C[nci]), nai, nbi, nci))

if __name__ == '__main__':
    input = sys.stdin.readline
    X, Y, Z, K = map(int, input().split())
    *A, = map(int, input().split())
    *B, = map(int, input().split())
    *C, = map(int, input().split())
    main(X, Y, Z, K, A, B, C)


Measured memory_bytes: 77072
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <sstream>
using namespace std;

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const LL mod=1000000007;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=100005;

int main()
{
    int a,b,c;
    while(~scanf("%d%d%d", &a, &b, &c)){
        printf("%d\n", a+b+c-max(max(a, b), c));
    }
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    S = input()
    ans = 0
    val = 0
    for c in S:
        if c == 'I':
            val += 1
            ans = max(ans, val)
        else:
            val -= 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62008
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)

typedef pair<int, int> Pi;
#define fi first
#define se second

int mx[] = {1, 0, -1, 0};
int my[] = {0, 1, 0, -1};

signed main()
{
  int N;
  int X[205], Y[205];
  int n, d;
  int miny, maxy, minx, maxx;
  while(cin >> N, N) {
    miny = maxy = minx = maxx = X[0] = Y[0] = 0;
    for(int i = 1; i < N; i++) {
      cin >> n >> d;
      X[i] = X[n] + mx[d], Y[i] = Y[n] + my[d];
      miny = min(miny, Y[i]); minx = min(minx, X[i]);
      maxy = max(maxy, Y[i]); maxx = max(maxx, X[i]);
    }

    cout << maxx - minx + 1 << " " << maxy - miny + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3060
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
seq = [int(x) for x in input().split()]
ans = 0
curmin = seq[0]
for i in xrange(1,n):
    if seq[i] < curmin:
        ans += curmin - seq[i]
    else:
        curmin = seq[i]
print(ans)

Measured memory_bytes: 113680
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T, typename U> inline void chmax(T &x, U y) { if (x < y) x = y; }
template<typename T, typename U> inline void chmin(T &x, U y) { if (x > y) x = y; }

struct UnionFind {
    vector<int> p;
    UnionFind(int n) : p(n, -1) {};
    bool unite(int u, int v) {
        if ((u = root(u)) == (v = root(v))) return false;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v]; p[v] = u;
        return true;
    }
    bool find(int u, int v) { return root(u) == root(v); }
    int root(int u) { return p[u] < 0 ? u : p[u] = root(p[u]); }
    int size(int u) { return -p[root(u)]; }
};

struct Edge {
    int from, to, cost;
    Edge(int a, int b, int c) : from(a), to(b), cost(c) {};
};

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<Edge> es;
    rep(i, m) {
        int a, b; scanf("%d%d", &a, &b);
        a--; b--;
        es.emplace_back(a, b, 0);
    }

    int ans = 0;
    rep(i, m) {
        UnionFind uf(n);
        rep(j, m) if (j != i) uf.unite(es[j].from, es[j].to);
        ans += uf.size(0) != n;
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
N, K = [int(i) for i in input().split(" ")]

def replace(a,b):
    if a < abs(a - b):
        return a
    else:
        return replace(abs(a - b), b)

if K == 0:
    print(N)
elif N % K == 0:
    print(0)
else:
    print(replace(N%K, K))

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	private int N;
	private int K;
	private int[] x;
	private int[] y;
	private char[] c;

	private long[,] csum;

	public Solver()
	{
		N = GetInt();
		K = GetInt();
		x = new int[N];
		y = new int[N];
		c = new char[N];
		for(int i = 0; i < N; i++)
		{
			x[i] = GetInt();
			y[i] = GetInt();
			c[i] = GetString()[0];
		}
	}

	public void Solve()
	{
		for(int i = 0; i < N; i++)
		{
			if(c[i] == 'W')
				y[i] += K;
			
			x[i] = (x[i] % (2 * K)) + 1;
			y[i] = (y[i] % (2 * K)) + 1;
		}

		csum = new long[4 * K + 1, 4 * K + 1];

		for(int i = 0; i < N; i++)
			for(int j = 0; j < 2; j++)
				for(int k = 0; k < 2; k++)
					csum[x[i] + 2 * K * j, y[i] + 2 * K * k]++;

		for(int i = 0; i <= 4 * K; i++)
			for(int j = 0; j < 4 * K; j++)
				csum[i, j + 1] += csum[i, j];

		for(int i = 0; i < 4 * K; i++)
			for(int j = 0; j <= 4 * K; j++)
				csum[i + 1, j] += csum[i, j];

		long ans = 0;
		for(int i = 1; i <= 2 * K; i++)
		{
			for(int j = 1; j <= 2 * K; j++)
			{
				long tmp = sum(i, j, i + K - 1, j + K - 1) + 
				           sum(i + K, j + K, i + 2 * K - 1, j + 2 * K - 1);
				ans = Math.Max(ans, tmp);
			}
		}

		Console.WriteLine(ans);
	}

	private long sum(int lowX, int lowY, int highX, int highY)
	{
		return csum[highX, highY] + 
		       csum[lowX - 1, lowY - 1] -
		       csum[highX, lowY - 1] - 
			   csum[lowX - 1, highY];
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 139076
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int N,K,X,Y;

	scanf("%d %d %d %d",&N,&K,&X,&Y);

	if(N>K){
		printf("%lld\n",K*X+(N-K)*Y);
	}else{
		printf("%lld\n",N*X);
	}

	return 0;
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}
int no = 1, n1;
int recu(int n, int k, int val) {


	if (n == n1) {
		return min(val * 2, val + k);
	}
	return min( recu(n + 1, k, 2 * val), recu(n + 1, k, val + k)              );


}
int digit(int n) {

	int temp = 0;
	while (n) {
		// temp += n % 10;
		n = n / 10;
		temp++;
	}



	return temp;
}

bool check(int a[], int n) {
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if (a[i] % 2)
			return false;
	}
	return true;
}
bool ispalin(int n){


	string  str =to_string(n);
	// cout<<str<<endl;


	for (int i = 0; i < str.size()/2; ++i)
	{
		/* code */
		// watch2(str[i],str[str.size()-i-1]);
		if(str[i]!=str[str.size()-i-1]){
			return false;
		}
	}


	return true;


}

int main() {
	int i,  n, k, c = 0, sum = 0;
	c_p_c();
	// cout<<"Sd"<<endl;>
	cin>>n>>k;
	for (int i = n; i <=k; ++i)
	{
		 // code /
		if(ispalin(i)){
			c++;
		}
	}
	// ispalin(1111);
	cout<<c<<endl;


}

Measured memory_bytes: 3736
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	int n, k;
	int t[50];
	cin >> n >> k;

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

	rep(i, 0, n) {
		rep(j, i + 1, n) {
			if (t[i] < t[j]) { swap(t[i], t[j]); }
		}
	}

	

	int ans = 0;
	rep(i, 0, k) {
		ans += t[i];
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
N, M, Q = list(map(int, input().split()))

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

def dfs(A, max_a):
    if len(A) == N:
        num = 0
        for a, b, c, d in conditions:
            if A[b-1] - A[a-1] == c:
                num += d
        return num
    ans = 0
    for i in range(max_a, M+1):
        ans = max(ans, dfs(A + [i], i))
    return ans

print(dfs([1], 1))

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

typedef long long ll;
typedef pair<int, int> P;

int MOD = 1e9 + 7;
ll INF = 1e18;

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

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

    int cnt=0;
    for(int i=0; i<n; i++){
        if(p[i] == i+1){
            if(i == n-1){
                swap(p[n-2], p[n-1]);
            }
            else{
                swap(p[i], p[i+1]);
            }
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640