akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

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

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...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int a, b, t; cin >> a >> b >> t;
	cout << (t / a)*b;

	return 0;
}

Measured memory_bytes: 3140
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c;
    cin >> a >> b >> c;
    
    if( a <= b && b <= c){
        cout << a << " " << b << " " << c << endl;
    }else if( a <= c && c <= b){
        cout << a << " " << c << " " << b << endl;
    }else if( b <= a && a <= c){
        cout << b << " " << a << " " << c << endl;
    }else if( b <= c && c <= a){
        cout << b << " " << c << " " << a << endl;
    }else if( c <= a && a <= b){
        cout << c << " " << a << " " << b << endl;
    }else if( c <= b && b <= a){
        cout << c << " " << b << " " << a << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3112
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();

        int[] n = new int[5];
        n[0] = cin.nextInt();
        n[1] = cin.nextInt();
        n[2] = cin.nextInt();
        n[3] = cin.nextInt();
        n[4] = cin.nextInt();

        int k = 10;
        int min = 10;
        for (int i = 0; i < 5; i++)
        {
            if (n[i] % 10 < min && n[i] % 10 > 0)
            {
                min = n[i] % 10;
                k = i;
            }
        }

        int ret = 0;
        for (int i = 0; i < 5; i++)
        {
            if (i != k && n[i] % 10 != 0)
            {
                ret += (n[i] / 10 + 1) * 10;
            }
            else
            {
                ret += n[i];
            }
        }
        Console.WriteLine(ret);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }

    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

Measured memory_bytes: 11092
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = [[set(), set()] for _ in range(N)]
    for i in range(N):
        m = int(input())
        for j in range(m):
            x, y = map(int, input().split())
            A[i][y].add(x)

    ans = 0
    for i in range(1 << N):
        h, u = set(), set()
        for j in range(N):
            if (i >> j) & 1:
                h.add(j+1)
                h |= A[j][1]
                u |= A[j][0]
            else:
                u.add(j+1)
        if not (h & u):
            ans = max(ans, bin(i).count("1"))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    long long int a,b,x;
    cin >> a >> b >> x;
    long long int c,d;
    c = a/x;
    d = b/x;
    c = d-c;
    if(a%x==0)
        c++;
    cout << c;
}

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

int main()
{
    int a,b;
    cin>>a>>b;
    int k = a-1;
    int bb = b;
    set<int>s;
    set<int>::iterator it;
    s.insert(b);
    for(int i=1;i<=k;i++)
    {
        b--;
        s.insert(b);

    }
    for(int i=1;i<=k;i++)
    {
        bb++;
        s.insert(bb);

    }
    for( it=s.begin();it!=s.end();it++)
        cout<<*it<<" ";





    return 0;
}



Measured memory_bytes: 256
import math
from decimal import *

def main():
    a, b = input_list()
    print(int(a*b))

def yogen(a, b, angle):
    coss = math.cos((angle/180)*math.pi)
    return math.sqrt(a**2 + b**2 - 2*a*b*coss)


def get_angle(hour, minute):
    h = (hour * 360) / 12 + (minute * 360) / (12 * 60)
    m = (minute * 360) / 60
    angle = abs(h-m)
    return min(angle, 360-angle)

def has(v, l):
    for vl in l:
        if v == vl:
            return True
    return False

def input_list():
    return list(map(Decimal, input().split()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 71428
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

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



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}

signed main() {
	int n;cin >> n;
	string s;cin >> s;
	string ss;
	int cnt[26];
	REP (i,26) cnt[i] = 0;
	ss = s;
	REP (i,ss.size()) {
		cnt[ss[i]-'a']++;
	}
	ll ans = 1;
	REP (i,26) {
		ans *= (ll)(cnt[i]+1);
		ans %= (ll)mod;
	}
	ans--;
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>

main(){
   
  int x; 
  int y;
  scanf("%d",&x);
  
  struct AAA{
  	int *xp;
  }aaa;
  
  aaa.xp = &x;
  
  y = *aaa.xp;
  
  

   printf("%d\n",y*y*y);
   
   return 0;

}

Measured memory_bytes: 596
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val A = readLine()!!.split(" ").map(String::toDouble)
    val border = A.sum() / (4.0 * M)
    val cand = A.filter { it >= border }
    println(if (cand.size >= M) "Yes" else "No")
}

Measured memory_bytes: 38016
#include<iostream>
using namespace std;
int main(){
  long long H, N;
  cin>>H>>N;
  long long A[N];
  long long sum=0;
  for(long long i=0;i<N;i++){
    cin>>A[i];
    sum+=A[i];
  }
  if(H>sum){
    cout<<"No";
    return 0;
  }
  cout<<"Yes";
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define MAX 101

int main()
{
	int x;
	int n;
	scanf("%d%d", &x, &n);

	int n2 = n / 2 + 2;

	short pos[n2];
	short neg[n2];

	int i;
	for (i = 0; i < n2; i++) {
		pos[i] = 0;
		neg[i] = 0;
	}

	for (i = 0; i < n; i++) {
		int val;
		scanf("%d", &val);
		if (val - x >= 0 && val - n2 < x) {
			pos[val - x] = 1;	
//			printf("pos: %d %d\n", val, val - x);
		}
		if (val - x <= 0 && val + n2 > x)  {
			neg[x - val] = 1;	
//			printf("neg: %d %d\n", val, x - val);
		}
	}

//	for (i = 0; i < n2; i++) {
//		printf("pos[%d]: %d\n", i, pos[i]);
//		printf("neg[%d]: %d\n", i, neg[i]);
//	}

	for (i = 0; i < n2; i++) {
		if (neg[i] == 0) {
			printf("%d\n", x - i);
			break;
		} else if (pos[i] == 0) {
			printf("%d\n", x + i);
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 1736
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
import numpy as np

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

sum_A = sum(A)
A = np.array(A)

cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr



tot = 0
for i in range(N):
    tot += int(A[i]) * (sum_A - int(cum_A[i]))
        
print(tot % 1000000007)

Measured memory_bytes: 50256
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
vector<int> v;
signed main(){
	double n,ans=0;
	cin>>n;
	for(double i=1;double((double)(n/i/i)-(double)(2/i)+(double)(1/n))>1;i++){
		if((int)(n)%(int)(i)==0){
			v.push_back(i);
		}
	}
	f(i,v.size()){
		ans+=n/v[i]-1;
	}
	cout<<(int)(ans)<<endl;
	return 0;
}


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

string a = "";
string b = "";

int n;
long long fat[11];
long long amount[11];

void calc(){
	fat[0] = 1LL;
	for(long long i = 1 ; i <= 10 ; i ++){
		fat[i] = i*fat[i - 1];
		amount[i] = fat[i]/i;
	}
	return;
}

void solve(){
	
	calc();
		
	long long pos_a = 0LL;
	bool done_a[11];
	memset(done_a, false, sizeof done_a);
	
	for(int i = 0 ; i < n ; i ++){
		int ldm = 0;
		int curr = (int)(a[i] - '0');
		for(int j = 1 ; j < curr ; j ++){
			if(!done_a[j]) ldm++;
		}
		done_a[curr] = true;
		pos_a += amount[n - i]*(ldm);
	}
	++pos_a;
	
	long long pos_b = 0LL;
	bool done_b[11];
	memset(done_b, false, sizeof done_b);
	
	for(int i = 0 ; i < n ; i ++){
		int ldm = 0;
		int curr = (int)(b[i] - '0');
		for(int j = 1 ; j < curr ; j ++){
			if(!done_b[j]) ldm++;
		}
		done_b[curr] = true;
		pos_b += amount[n - i]*(ldm);
	}
	++pos_b;
	
	cout << abs(pos_a - pos_b) << "\n";
	
	return;
}

int main(){
	
	cin >> n;
	
	for(int x, i = 0 ; i < n ; i ++){
		cin >> x;
		a += (char)(x + '0');
	}
	
	for(int x, i = 0 ; i < n ; i ++){
		cin >> x;
		b += (char)(x + '0');
	}
	
	solve();
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <list>
#include <stack>
#include <set>
using namespace std;

typedef long long int int64;

int main(int argc,char** argv) {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    int res = a[0] + a[1] + a[2] + (9 * max(max(a[0],a[1]),a[2]));
    cout << res ;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <math.h>
#include <vector>
#include <cstdio>
using namespace std;

int main ()
{
    int n, h, w;
    cin >> n >> h >> w;
    int ctr = 0;
    for (int i = 0; i <n; ++i) {
        int a, b;
        cin >> a >> b;
        if (a >= h && b >= w) {
            ctr++;
        }
    }
    cout << ctr;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

int main() {
	int N, P; string S;
	cin >> N >> P >> S;
	assert (N == S.size());
	ll answer = 0LL;
	
	if (P == 2 || P == 5) {
		for (int i = 0; i < N; i++) {
			int current_digit = S[i] - '0';
			if (current_digit % P == 0) {
				answer += (i + 1);
			}
		}
		cout << answer << endl;
		return 0;
	}
	
	vector < int > dp (P);
	dp[(S[N - 1] - '0') % P] = 1;
	answer += dp[0];
	int pow10 = 1;
	int zero = 0;
	for (int i = N - 2; i >= 0; i--) {
		int current_digit = S[i] - '0';
		pow10 = (pow10 * 10) % P;
		int current_number = (current_digit * pow10) % P;
		zero = (zero - current_number + P) % P;
		dp[(current_number + zero) % P]++;
		answer += dp[zero];
		//cout << i << " => " << dp[zero] << endl;
	}
	cout << answer << endl;
	return 0;
}

/**
 * 55 + 6 + 5 + 1 + 1*/


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;
int main(){
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    for(int i=0; i<N; i++){
       cin >> V[i]; 
    }
    for(int i=0; i<N; i++){
        cin >> C[i];    
    }
    vector<int> dif(N);
    int ans=0;
    for(int i=0; i<N; i++){
        dif[i] = V[i] - C[i];
        if(dif[i]>0){
            ans += dif[i];
        }
    }
    cout << ans;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  bool up = false, down = false;
  rep(i, n) cin >> a[i];
  int cn = 0;
  rep(i,n-1){
    if (a[i] < a[i+1]){
      if(down) {
        cn++, up = false, down = false;
        continue;
      }
      up = true;
    }else if(a[i] > a[i+1]){
      if(up){
        cn++, up = false, down = false;
        continue;
      }
      down = true;
    }
  }
  cn++;
  cout << cn << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define N 20000
#define O 0
#define I 1

typedef struct Data{
  int area, pos;
} Data;
Data t[N],B,X;
int i,n,u[N],T,U,a,A;
char str[N+I];

void D_push(Data);
Data D_pop(void);
void Push(int);
int Pop(void);
void Init(void);
Data MakeData(int,int);

int main(){
  Init();
  scanf("%s",str);
  n=strlen(str);
  for(i=O;i<n;i++){
    if(str[i]=='/'){
      if(U==O){
	continue;
      }
      A=Pop();
      X=MakeData(i-A,A);
      a+=i-A;
      while(T>O){
        B=D_pop();
        if(B.pos<A){
          D_push(B);
          break;
        }
        X.area+=B.area;
        if(B.pos<X.pos){
	  X.pos=B.pos;
	  }
      }	
      D_push(X);
    }
    else if(str[i]=='\\'){
    Push(i);
    }
  }
printf("%d\n%d",a,T);
 for(i=O;i<T;i++){
    printf(" %d",t[i].area);
 }
 printf("\n");
 return 0;
}
void D_push(Data data){
  t[T++]=data;
}
Data D_pop(){
  return t[--T];
}
void Push(int x){
  u[U++]=x;
}
int Pop(){
  return u[--U];
}
void Init(){
  a=T=U=O;
}
Data MakeData(int x,int y){
  Data res;
  res.area=x;
  res.pos=y;
  return res;
}



Measured memory_bytes: 2096
n,a,b,c,d = map(int,input().split())
n -= 1

target = b-a

for i in range(n+1):
    left = c*i - d*(n-i)
    right = d*i - c*(n-i)
    if(left <= target <= right):
        print('YES')
        exit()

print('NO')

Measured memory_bytes: 64320
import java.util.*;
public class Main{

  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      if(n == 1) {
        System.out.println(1);
        return;
      }

      int[] arr = new int[100001];
      for(int i = 0; i < n; i++)
        arr[sc.nextInt()]++;
      
      int max = 0;
      for(int i = 1; i < arr.length - 1; i++) {
          max = Math.max(max, arr[i-1] + arr[i] + arr[i+1]);
      }

      System.out.println(max);
  }
}


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

#define N_MAX 200002
#define Q_MAX 200002

#define ll long long

using namespace std;

const ll INF = 1000000000000000;

int n, q, a, b;

int pos[Q_MAX];

struct SGTNode
{
    ll mindp;
    ll min1, min2;
    ll lazy;
};

SGTNode dp[N_MAX * 3];

void split (int node)
{
    int lson = (node << 1), rson = (lson | 1);
    dp[lson].mindp += dp[node].lazy;
    dp[lson].min1 += dp[node].lazy;
    dp[lson].min2 += dp[node].lazy;
    dp[lson].lazy += dp[node].lazy;
    dp[rson].mindp += dp[node].lazy;
    dp[rson].min1 += dp[node].lazy;
    dp[rson].min2 += dp[node].lazy;
    dp[rson].lazy += dp[node].lazy;
    dp[node].lazy = 0;
}

SGTNode join (SGTNode a, SGTNode b)
{
    SGTNode ans;
    ans.mindp = min(a.mindp, b.mindp);
    ans.min1 = min(a.min1, b.min1);
    ans.min2 = min(a.min2, b.min2);
    ans.lazy = 0;
    return ans;
}

void update (int node, int l, int r, int ul, int ur, ll val)
{
    if(ul <= l && r <= ur)
    {
        dp[node].mindp += val;
        dp[node].min1 += val;
        dp[node].min2 += val;
        dp[node].lazy += val;
        return;
    }
    int mid = (l + r) / 2, lson = (node << 1), rson = (lson | 1);
    split(node);
    if(ul <= mid)
        update(lson, l, mid, ul, ur, val);
    if(mid + 1 <= ur)
        update(rson, mid + 1, r, ul, ur, val);
    dp[node] = join(dp[lson], dp[rson]);
}

void update1 (int node, int l, int r, int pos, ll val)
{
    if(l == r)
    {
        dp[node].mindp = val;
        dp[node].min1 = val - pos;
        dp[node].min2 = val + pos;
        return;
    }
    int mid = (l + r) / 2, lson = (node << 1), rson = (lson | 1);
    split(node);
    if(pos <= mid)
        update1(lson, l, mid, pos, val);
    if(mid + 1 <= pos)
        update1(rson, mid + 1, r, pos, val);
    dp[node] = join(dp[lson], dp[rson]);
}


SGTNode query (int node, int l, int r, int ql, int qr)
{
    if(ql <= l && r <= qr)
        return dp[node];
    int mid = (l + r) / 2, lson = (node << 1), rson = (lson | 1);
    split(node);
    if(ql <= mid && mid + 1 <= qr)
        return join(query(lson, l, mid, ql, qr), query(rson, mid + 1, r, ql, qr));
    else if(ql <= mid)
        return query(lson, l, mid, ql, qr);
    else
        return query(rson, mid + 1, r, ql, qr);
}

int main()
{
    cin >> n >> q >> a >> b;
    for(int i = 1; i <= q; i++)
        cin >> pos[i];
    pos[0] = a;
    for(int i = 1; i < N_MAX * 3; i++)
        dp[i].min1 = dp[i].min2 = dp[i].mindp = INF;
    update1(1, 1, n, b, 0);
    for(int i = 1; i <= q; i++)
    {
        ll diff = abs(pos[i] - pos[i - 1]);
        ll mi = min(query(1, 1, n, pos[i], pos[i]).mindp + diff, min(query(1, 1, n, 1, pos[i]).min1 + pos[i], query(1, 1, n, pos[i], n).min2 - pos[i]));
        if(pos[i - 1] - 1 >= 1)
            update(1, 1, n, 1, pos[i - 1] - 1, diff);
        if(pos[i - 1] + 1 <= n)
            update(1, 1, n, pos[i - 1] + 1, n, diff);
        update1(1, 1, n, pos[i - 1], mi);
        update1(1, 1, n, pos[i], INF);
    }
    cout << dp[1].mindp << "\n";
    return 0;
}


Measured memory_bytes: 19840
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
long long int a[200005], sum=0;
int main(void){
  int n;
  cin >> n;
  for(int i =0; i< n; i++){
      cin >> a[i];
      sum += a[i];
  }
  long long b = sum /2, c =0, ans=1e18;
  for(int i= 0; i< n; i++){
      c+=a[i];
      ans = min(ans,abs(b-c)+abs(sum-c-b));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

ll binexp (ll x, ll y)
{
    ll r=1;
    while (y)
    {
        if (y&1)
            r=r*x;
        x=x*x;
        y>>=1;
    }
    return r;
}

main()
{
    fast;
    int n,k;
    cin>>n>>k;
    ll ans=k;
    ans=ans*binexp(k-1,n-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x[100],y[100],h[100];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i]>>y[i]>>h[i];
	int pos;
	for(pos=0;h[pos]==0;pos++);
	for(int cx=0;cx<=100;cx++){
		for(int cy=0;cy<=100;cy++){
			int H=h[pos]+abs(x[pos]-cx)+abs(y[pos]-cy);
			bool ok=true;
			for(int i=0;i<n;i++)
				if(h[i]!=max(H-abs(x[i]-cx)-abs(y[i]-cy),0))
					ok=false;
			if(ok){
				cout<<cx<<' '<<cy<<' '<<H<<endl;
				return 0;
			}
		}
	}
}


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

typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--)
    // {

    // }

    int x, y;
    cin >> x >> y;
    string ans = "Yes";
    if (y % 2 == 1)
        ans = "No";
    int mi = 2 * x;
    int ma = 4 * x;
    if (y < mi || y > ma)
        ans = "No";
    cout<<ans<<endl;
    //system("pause");
}

Measured memory_bytes: 3576
n = int(input())
dp = [float('inf')]*n
draw = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
for a in draw:
    if a-1 < n:
        dp[a-1] = 1
for i in range(n):
    for j in draw:
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i]+1)
print(dp[-1])


Measured memory_bytes: 3828
N = gets.to_i
nums = gets.split.map(&:to_i)
min = Float::INFINITY
cnt = 0
nums.each do |pi|
  # piがこれまでの数で最小であればpjは条件を満たす
  if pi < min
    # 最小を値を更新
    min = pi
    cnt += 1
  end
end
p cnt


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans[] = {1, 2, 3};
    for (int i = 0; i < 3; i++)
    {
        if (ans[i] != a && ans[i] != b)
        {
            cout << ans[i] << endl;
            return 0;
        }
    }
}

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

int main() {
    int n, x, y;
    cin >> n >> x >> y, x--, y--;
    vector<vector<int>> graph(n, vector<int>(n, 1e9+7));
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            graph[i][j] = abs(x - i) + 1 + abs(y - j);
        }
    }
    vector<int> ans(n*n);
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            graph[i][j] = min(graph[i][j], j - i);
            ans[graph[i][j]]++;
        }
    }
    for(int i = 1; i <= n - 1; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int32_t main(){
    fast_io;
    int n;
    cin >> n;
    int a[n], tot = 0;
    for (int i = 0; i < n; ++i)
    {
    	cin >> a[i];
    	tot += a[i];
    }
    tot %= MOD;
    int ans = 0;
    int prev = 0;
    for (int i = 0; i < n; ++i)
    {
    	prev += a[i];
    	prev %= MOD;
    	ans += a[i] * (tot - prev);
    	ans %= MOD;
    }
    ans += MOD;
    ans %= MOD;
    show(ans);
    return 0;
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
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; }
#define rep(i, n) for (int i = 0; i < (int)n; i++)
typedef long long ll;
const ll MOD = 1e9+7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e9;
const ll mlnf = -1e9;

void debug_vector(vector<int>& v){
    int n = v.size();
    for (int i = 0; i < n; i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

void solve();
vector<int> make_divisor(int n);

int main(void){
    solve();
    return 0;
}

void solve(){
    int N; cin >> N;
    int res = 0;
    for (int i = 3; i <= N; i+=2){
        vector<int> q;
        q = make_divisor(i);
        //debug_vector(q);
        if (make_divisor(i).size() == 8) res++;
    }
    printf("%d\n", res);
}

vector<int> make_divisor(int n){
    vector<int> ret;
    for (int i = 1; i * i <= n; i++){
        if (n % i == 0) {
            ret.push_back(i);
            if (i != (n/i)) ret.push_back(n / i);
            }
        }
    sort(ret.begin(), ret.end());
    return ret;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

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

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

// const int C ;
// const int M = 1000000007;

int H, W;
string a[510];
string A[510];
string B[510];

bool valid(int i, int j) {
  return (0 <= i && i < H && 0 <= j && j < W);
}

int main () {
  cin >> H >> W;
  for (auto i = 0; i < H; i++) {
    cin >> a[i];
    A[i] = a[i];
    B[i] = a[i];
  }
  for (auto i = 0; i < H; i++) {    
    for (auto j = 1; j < W-1; j++) {
      if (i%2 == 0) {
        A[i][j] = '#';
      } else {
        B[i][j] = '#';
      }
    }
  }
  for (auto i = 0; i < H; i++) {
    A[i][0] = '#';
    B[i][W-1] = '#';
  }
  for (auto i = 0; i < H; i++) {
    cout << A[i] << endl;
  }
  for (auto i = 0; i < H; i++) {
    cout << B[i] << endl;
  }
}


Measured memory_bytes: 1536
#include <stdio.h>

int main (void){
	int H[100],W[100];
	int dataset = 0;
	
	while (H != 0 && W !=0){
		
		scanf("%d %d", &H[dataset], &W[dataset]);
		if (H[dataset] == 0 && W[dataset] == 0) break;
		dataset++;
	}
	
//	printf("%d", dataset);

	for (int data = 0; data < dataset; data++){				
		for (int i = 0; i < H[data]; i++){
			if(i == 0 || i % 2 == 0){
				int flag1 = 1;
				for (int j = 0; j < W[data]; j++){
					if(flag1 == 1){
						printf ("#");
						flag1 = 0;
					}
					else if(flag1 == 0){
						printf (".");
						flag1 = 1;
					}
				}
			}
			else{
				int flag2 = 0;
				for (int j = 0; j < W[data]; j++){
					if(flag2 == 1){
						printf ("#");
						flag2 = 0;
					}
					else if(flag2 == 0){
						printf (".");
						flag2 = 1;
					}
				}
			}
			
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
	
}


Measured memory_bytes: 2052
#include <stdio.h>

#define lli long long int

int main() {
	lli r, d, a;
	scanf("%lld %lld %lld", &r, &d, &a);
	for (int i = 0; i < 10; i++) {
		a = (r * a) - d;
		printf("%lld\n", a);
	}
	return 0;	
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;

int main() {
    unordered_set<char> odd = {'R', 'U', 'D'};
    unordered_set<char> even = {'L', 'U', 'D'};
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) {
        if (i % 2 == 1) {
            if (!even.count(s[i])) {
                cout << "No" <<endl;
                return 0;
            }
        } else {
            if (!odd.count(s[i])) {
                cout << "No" <<endl;
                return 0;
            }
        }
    }
    cout << "Yes" <<endl;
    return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>    // PBDS
#include <ext/pb_ds/tree_policy.hpp>        // PBDS

using namespace std;
using namespace __gnu_pbds;                 // PBDS

/* typedef starts */

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> PBDS_INT;               // PBDS for int
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> PBDS_LL;    // PBDS for long long

/* typedef ends */

/* macro starts */

#define PI acos(-1)
#define EPS 1e-9
#define fastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define sinD(degree) sin((degree * PI) / 180.0)
#define cosD(degree) cos((degree * PI) / 180.0)
#define tanD(degree) tan((degree * PI) / 180.0)
#define cotD(degree) (1.0 / tanD(degree))
#define secD(degree) (1.0 / cosD(degree))
#define cosecD(degree) (1.0 / sinD(degree))
#define asinD(value) (asin(value) * 180.0) / PI
#define acosD(value) (acos(value) * 180.0) / PI
#define atanD(value) (atan(value) * 180.0) / PI
#define forn(i,n) for(int i=0;i<n;i++)
#define value_at_index(x) find_by_order(x)
#define index_of(x) order_of_key(x)
#define pb push_back
#define set0(add) memset(add,0,sizeof(add));

/* macro ends */

/* function starts */

/// calculates n-th (0-based) Gray Code
template<typename dataType>
dataType nthGrayCode(dataType n)
{
    return (n ^ (n >> 1));
}

/// generates all possible subsets for the given set
template<typename dataType>
void generateAllSubset(vector<dataType> &data)
{
    int i, j, n;
    n = data.size();

    for (i = 0; i < (1 << n); i++) {
        for (j = 0; j < n; j++) {
            if (i & (1 << j)) {
                cout << data[j] << " ";
            }
        }
        cout << "\n";
    }
}


void swap(int a, int b){
	int temp;
	temp=a;
	a=b;
	b=temp;
}

int fact(int n){
	if(n<=1)
		return 1;
	else 
	return n*fact(n-1);
}


int n;

int a[100005][3],dp[100005][4];

int func(int ind,int prev)
{
    if(ind==n) return 0;
    if(dp[ind][prev]!=-1)return dp[ind][prev];
    else
	{    int left=-1,right=-1;
		if(prev==1){
		 left=a[ind][1]+func(ind+1,2);
		 right=a[ind][2]+func(ind+1,3);
		}
		else if(prev==2){
		 left=a[ind][0]+func(ind+1,1);
		 right=a[ind][2]+func(ind+1,3);
		}
		else if(prev==3){
           left=a[ind][0]+func(ind+1,1);
		 right=a[ind][1]+func(ind+1,2);
		}
		else if(prev==0){
			int ty;
			ty=a[0][0]+func(ind+1,1);
			int fy=a[0][1]+func(ind+1,2);
			left=max(ty,fy);
			right=a[0][2]+func(ind+1,3);
		}
		return dp[ind][prev]=max(left,right);
	}
	
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    fastIO;
    
    cin >> n ;
    for(int i=0;i<n;i++){
     cin >> a[i][0] >> a[i][1] >> a[i][2];
     dp[i][0]=-1;
     dp[i][1]=-1; dp[i][2]=-1; dp[i][3]=-1;
    }
    
    int ans=func(0,0);
    cout << ans;
   
   return 0;
   
   
   	}
    


Measured memory_bytes: 11036
#include <stdio.h>

int
main(void)
{
	char line[80];
	int n;

	while (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%d", &n) == 1) {
			int r = 0;
				
			for (int a = 0; a <= 9; a++) {
				for (int b = 0; b <= 9; b++) {
					for (int c = 0; c <= 9; c++) {
						for (int d = 0; d <= 9; d++) {
							if (a + b + c + d == n) {
								r ++;
							}
						}
					}
				}
			}

			printf("%d\n", r);
		}
	}

	return 0;
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    int n;
    cin>>n;
    if(n>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3564
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	vector<long long> a;
	REP(i, 3) {
		int b;
		cin >> b;
		a.push_back(b);
	}
	sort(a.begin(), a.end());
	if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


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


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		HashMap<Integer, Double>	result = new HashMap<Integer, Double>();
		int							key    = 0;
		double						value  = 0;

		while ((key = parseKey()) != -1) {
			if (result.containsKey(key)) {
				value = result.get(key);
			}
			else {
				value = calc(key);
				result.put(key, value);
			}
			System.out.printf("%.6f\n", value);
		}
	}

	private static double calc(int key) {
		double	x = (double)key / 2.0;

		while (true) {
			x -= (Math.pow(x, 3.0) - (double)key) / (3 * Math.pow(x, 2.0));
			if (Math.abs(Math.pow(x, 3.0) - (double)key) < (1e-5f * (double)key)) {
				break;
			}
		}
		
		return x;
	}

	private static int parseKey() {
		int		key   = -1;
		String	stdin = null;

		if ((stdin = parseStdin()) != null) {
			if (!stdin.isEmpty()) {
				key = Integer.parseInt(stdin);
			}
		}
		
		return key;
	}

	private static String parseStdin() {
		String	stdin = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					stdin = line;
				}
			}
		}
		catch (IOException e) {}

		return stdin;
	}
}

Measured memory_bytes: 17008
import java.io.*;
import java.util.*;

public class Main {
  private static boolean solve(int n, int m, int xc, int yc, int[] xs, int[] ys) {
    int xMax = xc;
    for (int x : xs) {
      xMax = Math.max(xMax, x);
    }
    
    int yMin = yc;
    for (int y : ys) {
      yMin = Math.min(yMin, y);
    }
    
    return xMax < yMin;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int m = reader.nextInt();
    int xc = reader.nextInt();
    int yc = reader.nextInt();
    int[] xs = reader.nextInt(n);
    int[] ys = reader.nextInt(m);
    out.println(solve(n, m, xc, yc, xs, ys) ? "No War" : "War");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 21332
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	char table[8][9];

	while(scanf("%s",table[0])!=EOF){
		for(int i=1;i<8;i++){
			scanf("%s",table[i]);
		}
		getchar();
		bool FLG = false;
		for(int i=0; i < 8; i++){
			for(int k=0; k<8; k++){
				if(table[i][k] == '1'){
					if(i <= 6 && k <= 6 && table[i][k+1] == '1' && table[i+1][k] == '1' && table[i+1][k+1] == '1'){
						printf("A\n");
						FLG = true;
						break;
					}else if(i <= 4 && table[i+1][k] == '1' && table[i+2][k] == '1' && table[i+3][k] == '1'){
						printf("B\n");
						FLG = true;
						break;
					}else if(k <= 4 && table[i][k+1] == '1' && table[i][k+2] == '1' && table[i][k+3] == '1'){
						printf("C\n");
						FLG = true;
						break;
					}else if(i <= 5 && k >= 1 && table[i+1][k-1] == '1' && table[i+1][k] == '1' &&
							table[i+2][k-1] == '1'){
						printf("D\n");
						FLG = true;
						break;
					}else if(i <= 6 && k <= 5 && table[i][k+1] == '1' && table[i+1][k+1] == '1' &&
							table[i+1][k+2] == '1'){
						printf("E\n");
						FLG = true;
						break;
					}else if(i <= 5 && k <= 6 && table[i+1][k] == '1' && table[i+1][k+1] == '1' &&
							table[i+2][k+1] == '1'){
						printf("F\n");
						FLG = true;
						break;
					}else{
						printf("G\n");
						FLG = true;
						break;
					}
				}
			}
			if(FLG)break;
		}

	}


	return 0;
}

Measured memory_bytes: 2528
package main

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

func main() {
	sc := NewScanner()
	N, A := sc.NextInt(), sc.NextInt()
	S := sc.NextLine()

	queue := make([]int, 0)
	q := S[0]
	if q == '0' {
		queue = append(queue, 0)
	}
	count := 0
	for i := 0; i < N; i++ {
		if q == S[i] {
			count++
		} else {
			queue = append(queue, count)
			q = S[i]
			count = 1
		}
	}
	queue = append(queue, count)
	if S[N-1] == '0' {
		queue = append(queue, 0)
	}
	//fmt.Printf("%+v\n", queue)
	sum := 0
	i := 0
	for ; i < 2*A+1 && i < len(queue); i++ {
		sum += queue[i]
	}
	k := 0
	mx := sum
	for ; i+1 < len(queue); i += 2 {
		sum -= queue[k]
		sum -= queue[k+1]
		sum += queue[i]
		sum += queue[i+1]
		k += 2
		if mx < sum {
			mx = sum
		}
	}
	fmt.Println(mx)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 6016
import sys
import bisect


def main():
    n, K, L, R = map(int, sys.stdin.readline().split())
    a = tuple(map(int, sys.stdin.readline().split()))
    m = n//2
    ls = [[] for _ in range(m+1)]
    for i in range(1 << m):
        cnt = 0
        val = 0
        for j in range(m):
            if i >> j & 1:
                cnt += 1
                val += a[j]
        ls[cnt].append(val)
    for i in range(m+1):
        ls[i].sort()
    ans = 0
    for i in range(1 << n-m):
        cnt = 0
        val = 0
        for j in range(n-m):
            if i >> j & 1:
                cnt += 1
                val += a[m+j]
        if K-m <= cnt <= K:
            ans += bisect.bisect_right(ls[K-cnt], R-val) - bisect.bisect_right(ls[K-cnt], L-val-1)
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 56768