akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
#include<map>
#include<vector>
#include<cmath>
#include<set>
#include<unordered_set>
#include<algorithm>
#define int long long int
#define mod 1000000007
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int a,b,c;
	cin>>a>>b>>c;
	int k;
	cin>>k;
	while(k!=0&&b<=a)
	{
		k--;
		b*=2;
	}
	while(k!=0&&c<=b)
	{
		k--;
		c*=2;
	}
	if(b>a&&c>b)
	{
		cout<<"Yes"<<endl;
	}
	else
	   cout<<"No"<<endl;
}


Measured memory_bytes: 3532
N=int(input())

D=list(map(int,input().split()))
flg =False
A = [0 for i in range(13)]
A[0]=1
for i in range(N):
    j = min(D[i],24-D[i])
    if j==0:
        flg=True
        break
    elif j==12:
        if A[j]==1:
            flg=True
            break
        else:
            A[j]+=1
    else:
        if A[j]==2:
            flg=True
            break
        else:
            A[j]+=1

import copy

if flg:
    print(0)
else:
    count=0
    one_times=[]
    times=[0]
    for i in range(1,12): 
        if A[i]==1:
            count+=1
            one_times.append(i)
        if A[i]==2:
            times.append(i)
            times.append(24-i)
    if A[12]==1:
        times.append(12)
    score_max=0
    for i in range(2**count):
        t=copy.copy(times)
        for j in range(count):
            if (i//(2**j))%2==0:
                t.append(one_times[j])
            else:
                t.append(24-one_times[j])
        t.sort()
        
        score_min=24
        for j in range(len(t)):
            if j==len(t)-1:
                score_min=min(t[0]+24-t[len(t)-1],score_min)
            else:
                score_min=min(t[j+1]-t[j],score_min)
        score_max=max(score_min,score_max)
    print(score_max)

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

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




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

int main(){
  int n;
  cin >> n;
  vector<int> mochis(n);
  for(int i = 0; i < n; i++){
  	cin >> mochis.at(i);
  }
  
  sort(mochis.begin(), mochis.end());
  
  int cnt = 0, tmp = 0;
  for(int i = 0; i < n; i++){
  	if(tmp < mochis.at(i)){
      cnt++;
      tmp = mochis.at(i);
    }
  }
  cout << cnt;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int64_t act(int64_t h){
  if(h == 1 ) return 1;

  int64_t x = (int64_t)(h/2);
  return act(x) + act(x);
}

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


  int64_t c = 0;
  int64_t i = 0;
  while(H > 1){
    c += pow(2,i);
    H /= 2;
    i++;
  }
  c += pow(2,i);
  cout << c << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int S[100];
int top = 0;
void push(int);
int main(){
  char c;
  int a,b;
  int x;
  int flug=0;
  while( flug==0){
    c=getchar();
    if(isdigit(c)){
      ungetc(c,stdin);
      scanf("%d",&x);
      push((int)x);
    }
    else {
      switch(c){
      case '+':
	a = pop();
	b = pop();
	push(b+a);
	break;
      case '-':
	a = pop();
	b = pop();
	push(b-a);
	break;
      case '*':
	a = pop();
	b = pop();
	push(b*a);
	break;
      case ' ':
	break;
      case '\n':
	printf("%d\n",pop());
	flug = 1;
	break;
      default:
	printf("no entery\n");
	break;
      }
	
    }
  }
  
  
  return 0;
}

int pop(){
  //   printf("popped\n");
  return S[--top];
}

void push(int c){
  // printf("pushed\n");
  S[top++]=c;
  //  printf("Current top is %d\n",S[top]);
 
}




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

int main(void){
  int n, harshad = 0;
  cin >> n;

  int tmp = n;
  while(tmp != 0){
    harshad += (tmp % 10);
    tmp /= 10;
  }

  if(n % harshad == 0){ cout << "Yes" << endl; }
  else{ cout << "No" << endl; }
  
  return 0;
}


Measured memory_bytes: 256
using System;

public class B
{
	public static void Main()
	{
		string[] list = new string[]
		{
			"erase",
			"dream",
			"eraser",
			"dreamer"
		};
		string s = Console.ReadLine();
		while(0 < s.Length)
		{
			bool flag = false;
			for (int i = 0; i < list.Length; i++)
			{
				if(s.LastIndexOf(list[i]) == s.Length - list[i].Length)
				{
					flag = true;
					s = s.Substring(0, s.Length - list[i].Length);
					break;
				}
			}
			if (flag) continue;
			Console.WriteLine("NO");
			return;
		}
		Console.WriteLine("YES");
	}
}

Measured memory_bytes: 31860
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

if n%a == 0:
    train = n // a
else:
    train = 1 + (n // a)
    
if n%b == 0:
    bus = (n // b)
else:
    bus = 1 + (n // b)
    
if n%c == 0:
    taxi = (n // c)
else:
    taxi = 1 + (n // c)
    
if n%d == 0:
    plane = (n // d)
else:
    plane = 1 + (n // d)
    
if n%e == 0:
    boat = (n // e)
else:
    boat = 1 + (n // e)

vehicles = [train, bus, taxi, plane, boat]

latest = train
for i in range(len(vehicles)):
    if latest < vehicles[i]:
        latest = vehicles[i]

if latest == train:
    an = train + 4
elif latest == bus:
    an = bus + 4
elif latest == taxi:
    an = taxi + 4
elif latest == plane:
    an = plane+ 4
else:
    an = boat + 4

print(an)

Measured memory_bytes: 3064
n = int(input())

if n == 0:
    print('0')
else:
    ans = []
    x = n
    while x != 1:
        if x % -2 == 0:
            ans.append('0')
            x //= -2
        else:
            ans.append('1')
            x //= -2
            x += 1
    ans.append('1')
    t_ans = ''
    for i in range(len(ans)-1, -1, -1):
        t_ans += ans[i]
    print(t_ans)


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

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 3e5;
int n, k, a[nsz + 5], ans;

struct segment_tree {
	#define ls (u << 1)
	#define rs (u << 1 | 1)
	#define md ((l + r) >> 1)
	#define lp ls, l, md
	#define rp rs, md + 1, r
	
	int mx[4 * nsz + 5];
	
	void set(int id, int w, int u = 1, int l = 1, int r = nsz) {
		if (l == r) { mx[u] = w; return; }
		id <= md ? set(id, w, lp) : set(id, w, rp);
		mx[u] = max(mx[ls], mx[rs]);
	}
	
	int qry(int el, int er, int u = 1, int l = 1, int r = nsz) {
		if (l >= el && r <= er) return mx[u];
		int res = 0;
		if (el <= md) res = qry(el, er, lp);
		if (er > md)  res = max(res, qry(el, er, rp));
		return res;
	}
};
segment_tree tr;

int main() {
	scanf("%d%d", &n, &k);
	cont (i, n) scanf("%d", &a[i]);
	cont (i, n) {
		int l = max(1, a[i] - k), r = min(nsz, a[i] + k);
		tr.set(a[i], tr.qry(l, r) + 1);
	}
	ans = tr.qry(1, nsz);
	printf("%d\n", ans);
}

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

int main() {
  long N;
  long K;
  cin >> N >> K;
  
  long A;
  A = N%K;
  if( A > K/2){
    cout << K-A << endl;
  }
  else{
    cout << A << endl;
  }
  return 0;
}

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

c = {}
for k in a:
    if c.get(k) is None:
        c[k] = 1
    else:
        c[k] += 1


def nc2(x):
    return (x*(x-1)) // 2


ans = 0
for cn in c.values():
    ans += nc2(cn)

for k in a:
    print(ans - (nc2(c[k]) - nc2(c[k]-1)))


Measured memory_bytes: 25716
#include "cstdio"
#include "algorithm"
using namespace std;
long long s[55],sss,maxx,i,a,b,n,ss[55][55],ss1,ss2,j;
bool cmp(long long a,long long b){
	return a>b;
}
int main(){
	scanf("%lld",&n);scanf("%lld%lld",&a,&b);ss[0][0]=1;
	for(i=1;i<=50;i++){
		ss[i][0]=1;
		for(j=1;j<=i;j++)ss[i][j]=ss[i-1][j]+ss[i-1][j-1];
	}
	for(i=1;i<=n;i++)scanf("%lld",&s[i]);
	sort(s+1,s+1+n,cmp);
	for(i=1;i<=a;i++)sss+=s[i];
	for(i=1;i<=n;i++){
	    if(s[i]==s[a])ss1++;if(s[i]==s[a]&&i<=a)ss2++;
	}
	if(s[1]==s[a])
	for(i=a;i<=b;i++)maxx+=ss[ss1][i];
	else maxx=ss[ss1][ss2];
	printf("%lf %lld\n",sss*1.0/a,maxx);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	long long k;
	long long n = 7;
	cin >> k;
	long long count = 1;
	unordered_set<long long> m;
	m.insert(7 % k);
	while(n % k != 0) {
		n = (n * 10 + 7) % k;
		if(m.count(n)) {
			cout << "-1\n";
			return 0;
		}
		m.insert(n);
		count++;
	}
	cout << count << "\n";
	return 0;
}


Measured memory_bytes: 47008
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();

        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int num1;
        int num2;
        List<Integer> dame = new ArrayList<>();

        long[] height = new long[N];
        for (int i = 0; i < N; i++) {
            height[i] = Integer.parseInt(sc.next());
        }

        for (int i = 0; i < M; i++) {
            num1 = Integer.parseInt(sc.next());
            num2 = Integer.parseInt(sc.next());
            if (height[num1 - 1] < height[num2 - 1]) {
                dame.add(num1);
            } else if (height[num1 - 1] > height[num2 - 1]) {
                dame.add(num2);
            } else {
                dame.add(num1);
                dame.add(num2);
            }
        }
        List<Integer> listB = new ArrayList<Integer>(new HashSet<>(dame));

        System.out.println(N - listB.size());
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i=1; i<s.size(); i++){
    string left,right;
    vector<int> vec1(125,0);
    vector<int> vec2(125,0);
    left = s.substr(0,i);
    right = s.substr(i,s.size()-i);
    for(int j=0; j<right.size(); j++){
      vec1.at(right.at(j)) = 1;
    }
    for(int j=0; j<left.size(); j++){
      vec2.at(left.at(j)) = 1;
    }
    int tmp = 0;
    for(int i=97; i<=122; i++){
      tmp += vec1.at(i)*vec2.at(i);
    }
    ans = max(tmp, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define mod 1000000007
#define INF 2147483647
#define fi first
#define se second
int abs(int a,int b){ 
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
  return true;
}
int q[100000000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c=0;
  cin>>a>>b;
  if(a<=b*2) cout<<"0";
  else cout<<a-b*2;
  cout<<"\n";
}


Measured memory_bytes: 256
def call(n):
    s = ""
    i = 1
    while i <= n:
        x = i
        if x%3 == 0:
            s += " {0}".format(i)
        else:
            while x > 0:
               if x%10 == 3:
                   s += " {0}".format(i)
                   break
               x = x // 10
        i += 1
    print(s)

m = int(input())
call(m)

Measured memory_bytes: 7704
if __name__ == '__main__':
    N = int(input())
    B, AandB = [], []
    for n in range(N):
        a, b = map(int, input().split())
        B.append(b)
        AandB.append(a+b)

    AandB.sort(reverse=True)
    ans = -sum(B)

    for i in range(0, N, 2):
        ans += AandB[i]

    print(ans)


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

using namespace std;

#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) loop(i,0,n)

typedef string::const_iterator State;
class ParseError {};

int expression(State &begin);
int term(State &begin);
int number(State &begin);
int factor(State &begin);

int number(State &begin) {
	int ret = 0;

	while (isdigit(*begin)) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	return ret;
}

int term(State &begin) {
	int ret = factor(begin);

	for (;;) {
		if (*begin == '*') {
			begin++;
			ret *= factor(begin);
		} else if (*begin == '/') {
			begin++;
			ret /= factor(begin);
		} else {
			break;
		}
	}
	return ret;
}

int expression(State &begin) {
	int ret = term(begin);

	for (;;) {
		if (*begin == '+') {
			begin++;
			ret += term(begin);
		} else if (*begin == '-') {
			begin++;
			ret -= term(begin);
		} else {
			break;
		}
	}

	return ret;
}

int factor(State &begin) {
	if (*begin == '(') {
		begin++;
		int ret = expression(begin);
		begin++;
		return ret;
	} else {
		return number(begin);
	}
}

string itos(int number) {
	stringstream ss;
	ss << number;
	return ss.str();
}

int main(void) {
	vector<int> v(4);
	while(true){
		for(int i=0; i < 4; i++) cin >> v[i];
		if(v[0]+v[1]+v[2]+v[3] == 0) break;

		string symbol = "+-*";

		rep(i, 3)rep(j, 3)rep(k, 3){
			if(i+j-k < 0 || j != 0 && k != 0) continue;
			rep(l, 3)rep(m, 3){
				if(i+j-k+l-m < 0 || l != 0 && m != 0) continue;
				for(int n=0; n < 3; n++){ //)4
					if(i+j-k+l-m-n != 0 || 6 < i+j+k+l+m+n) continue;

					do{
						rep(a, 3)rep(b, 3)rep(c, 3){
							string ex;
							for(int p=0; p < i; p++) ex += "(";
							ex += itos(v[0]);
							ex += symbol[a];
							for(int p=0; p < j; p++) ex += "(";
							ex += itos(v[1]);
							for(int p=0; p < k; p++) ex +=  ")";
							ex += symbol[b];
							for(int p=0; p < l; p++) ex +=  "(";
							ex += itos(v[2]);
							for(int p=0; p < m; p++) ex +=  ")";
							ex += symbol[c];
							ex += itos(v[3]);
							for(int p=0; p < n; p++) ex +=  ")";

							State begin = ex.begin();
							if(expression(begin) == 10){
								rep(q, ex.size()-1){
									if(symbol.find(ex[q+1]) != string::npos){
										cout << ex[q] << " " << ex[q+1] << " ";
										q++;
									}
									else cout << ex[q];
								}
								cout << ex[ex.size()-1] << endl;
								goto end_state;
							}
						}
					}while(next_permutation(v.begin(), v.end()));
				}
			}
		}
		cout << 0 << endl;
end_state:;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <vector>

int main(void) {
	// input
	int n;
	std::cin >> n;
	std::string s;
	std::cin >> s;

	// count
	std::vector<int> n_char(26);
	for(int i = 0; i < n; ++i) {
		n_char[s[i] - 'a'] += 1;
	}

	// combination
	long long c = 1;
	for(int j = 0; j < 26; ++j) {
		c *= (n_char[j] + 1);
		c %= 1000000007;
	}
	c += 1000000006;
	c %= 1000000007;

	std::cout << c << std::endl;

	return 0;
}


Measured memory_bytes: 512
/*
author: madhav_1999 aka orthodoxparadox
30 May 2020 at 5:34 PM
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define dbl long double
#define int ll
#define ll long long
#define pii pair<int, int>
#define len(x) (int) x.size()
#define rev(a) reverse(all(a))
#define oiint ostream_iterator<int>(cout, " ") 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define onlyunique(v) v.erase(unique(all(v)), v.end()); //only for sorted vector
#define inf 2e18
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef MADHAV
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define dbg(...) 42
#endif
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(int i=0;i<(int)v.size();++i) x<<v[i]<<" ";return x;} 
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;} 
template <typename X> ostream& operator << (ostream& x,const multiset<X>& v){for(auto it:v) x<<it<<" ";return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct pair_hash {inline std::size_t operator()(const std::pair<int, int> & v) const {return v.first*31+v.second;}};
const int MOD = 1e9 + 7;

int takemod(int a, int mod = MOD){a%=mod;if(a<0)a+=mod;return a;}

int fast_exp(int base, int expo, int mod = MOD) {
	int res=1;
	while(expo>0) {
		if(expo&1) res=(res*base)%mod;
		base=(base*base)%mod;
		expo>>=1;}
	return res;}

int modinv(int a, int mod = MOD){return takemod(fast_exp(takemod(a, mod), mod-2, mod), mod);}


void solve()
{
	string s;
	cin >> s;
	for(char &c : s) {
		if(c == '?') c = 'D';
	}
	cout << s;
}

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	#ifdef MADHAV
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
	#endif
	clock_t t1, t2;
	t1 = clock();

	int tt = 1;
	// cin >> tt;
	while(tt--)
	{
		solve();
	}
	#ifdef MADHAV
	t2 = clock(); cout << "\n\ntime taken: " << (t2-t1)/(dbl)CLOCKS_PER_SEC;
	#endif
	return 0;
}

Measured memory_bytes: 3808
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var M = cin.ReadIntArray(4);
			var tt = (M[2]+M[1]-1)/M[1];
			var ta = (M[0]+M[3]-1)/M[3];
			Console.WriteLine(tt<=ta?"Yes":"No");
		}
	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x]=A[y];
			A[y]=tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length);
		public static IEnumerable<int> Indices<T>(this T[,] X, int dim)
			=> Enumerable.Range(0, X.GetLength(dim));
		public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n")
			=> X.Indices(0).Select(
				i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)
			).Join(separatorD1);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}
}

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

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    string s;
    ll k;
    cin >> s >> k;

    REP(j, s.size()) {
        int i = s[j] - '0';
        if (j < k and i != 1) {
            cout << i << endl;
            return 0;
        }
    }

    cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
 
int main(void){
	int r, d, x;
	std::cin >> r>>d>>x;
	for(int i=0;i<10;i++){
		x=r*x - d;
		std::cout << x << std::endl;
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define modn 1000000007

#define SZ 10005
using namespace std;


int main()
{
    int arr[12] = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};
    int n;
    cin>>n;
    int dp[n+1];
    for(int j=0; j<=n; j++) dp[j] = INT_MAX;
    dp[0] = 0;
    for(int s=1; s<=n; s++)
    {
        for(int i=0; i<12; i++)
        {
            if(s >= arr[i])
            {
                int x = dp[s-arr[i]];
                if(x != INT_MAX and x+1 < dp[s]) dp[s] = x+1;
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.next());
		int t = Integer.parseInt(scan.next());
		int old = Integer.parseInt(scan.next());
		long ans =0;
		int time;
		for(int i = 0; i < n-1; ++i){
			time =Integer.parseInt(scan.next());
			ans+=Math.min(t,time-old);
			old = time;
		}
		System.out.print(ans+t);

	}
}
//end


Measured memory_bytes: 46432
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int a, b;
	scanf("%lld %lld", &a, &b);
	if(a * b <= 0LL) printf("Zero\n");
	else if(b < 0LL && (b - a) % 2 == 0) printf("Negative\n");
	else printf("Positive\n");
	return 0;
}


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

#define ll long long
#define db double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 123, MOD = 1e9 + 7;
int n, k, dp[N];

int binpow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = (ll)res * x % MOD;
		}
		x = (ll)x * x % MOD;
		y /= 2;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> k;
	int res = 0;
	for (int i = k; i >= 1; i--) {
		dp[i] = binpow(k / i, n);
		for (int j = i + i; j <= k; j += i) {
			dp[i] -= dp[j];
			if (dp[i] < 0) {
				dp[i] += MOD;
			}
		}
		res += (ll)dp[i] * i % MOD;
		if (res >= MOD) {
			res -= MOD;
		}
	}
	cout << res;
}


Measured memory_bytes: 4040
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
hei(string) ans;
int n;
void dfs(int s, string t,int x) {
	if (s == n)ans.push_back(t);
	else {
		rep(i, 97, x + 2) {
			string New = t;
			New += i;
			dfs(s + 1, New,max(x,i));
		}
	}
}

int main() {
	cin >> n;
	dfs(1, "a",97);
	sort(ans.begin(), ans.end());
	rep(i, 0, ans.size())
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 7328
#include<stdio.h>
#define N 100
int G[N][N],d[N],f[N],color[N];
int n,time;

void visit(int u){
  int i;
  color[u]=1;
  d[u]=++time;
  for(i=0;i<n;i++){
    if(G[u][i]!=0){
    if(color[i]==0)
      visit(i);
    }
  }
  color[u]=2;
  f[u]=++time;
  
}

void dfs(){
  int i;
  for(i=0;i<n;i++)
    color[i]=0;
  time=0;
  for(i=0;i<n;i++)
    if(color[i]==0)
      visit(i);
  for(i=0;i<n;i++)
  printf("%d %d %d\n",i+1,d[i],f[i]);    
}

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      G[i][j]=0;

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      G[u-1][v-1]=1;
    }
  }
  dfs();

  
  return 0;
}

Measured memory_bytes: 636
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<stack>
#include<tuple>
using namespace std;
#define INF 1100000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

double dp[310][310][310];
int n[4];

int main(){
    int N; cin>>N;
    for(int i=0;i<N;i++){
        int a; cin>>a;
        n[a]++;
    }
    
    for(int i=0;i<=300;i++){ //3個
        for(int j=0;j<=300;j++){
            for(int k=0;k<=300;k++){
                if(i==0 && j==0 && k==0) continue;
                dp[i][j][k]=( (double)1/ (i+j+k) ) *( (double)(N-i-j-k ) + i*(dp[max(i-1,0)][j+1][k] +1 )+ j*(dp[i][max(j-1,0)][k+1]+1) + k*(dp[i][j][max(k-1,0)]+1) );
            }
        }
    }
    //cout<<dp[1][0][0]<<endl;
    printf("%.10lf\n",dp[n[3]][n[2]][n[1]]);

}



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

int main(){
	string s,x,a="keyence";
	cin>>s;
	int n=s.length();
	int f=0;
	for(int i=0;i<=7;i++){
		x=s.substr(0,i)+s.substr(n-7+i,7-i);
		if(x==a) f=1;
	}
	if(f) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
} 

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import heapq

class BinaryIndexedTree:
    # Initialize BIT with non-zero value
    def __init__(self, array):
        self.len = len(array)
        self.data = [0] + array
        self.build()

    def build(self):
        for i in range(1, self.len):
            if i + (i & -i) > self.len:
                continue
            self.data[i + (i & -i)] += self.data[i]

    # Add w to a[x] (0-indexed)
    def add(self, x, w):
        x += 1
        while x <= self.len:
            self.data[x] += w
            x += x & -x

    # Get Sum of a[0 : x) (0-indexed)
    def sum(self, x):
        ret = 0
        while x > 0:
            ret += self.data[x]
            x -= x & -x
        return ret

    # Get first index s.t. sum a[0 : index) >= w
    def bisect_left(self, w):
        if w <= 0:
            return 0
        x = 0
        delta = pow(2, (self.len - 1).bit_length())
        while delta > 0:
            if x + delta <= self.len and self.data[x + delta] < w:
                w -= self.data[x + delta]
                x += delta
            delta >>= 1
        return x

t = int(input())
for _ in range(t):
    n = int(input())
    q = []
    base = 0
    left = BinaryIndexedTree([0] * n)
    right = BinaryIndexedTree([0] * n)
    left_bag = [[] for _ in range(n)]
    right_bag = [[] for _ in range(n)]
    for _ in range(n):
        k, l, r = map(int, input().split())
        if k == n:
            base += l
            continue
        if l == r:
            base += l
        elif l > r:
            q.append((l-r, 0, k-1))
            base += r
            left_bag[k-1].append(l-r)
        else:
            q.append((r-l, 1, n-k-1))
            base += l
            right_bag[n-k-1].append(r-l)
    
    left_bag.reverse()
    hq = []
    for bag in left_bag:
        if bag:
            for item in bag:
                heapq.heappush(hq, -item)
        if hq:
            base += -heapq.heappop(hq) 
    right_bag.reverse()
    hq = []
    for bag in right_bag:
        if bag:
            for item in bag:
                heapq.heappush(hq, -item)
        if hq:
            base += -heapq.heappop(hq) 
    print(base)

Measured memory_bytes: 130308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

    string s;
    cin >> s;

    if(p==2){
        ll ans = 0;
        for(int i = 0; i < n; i++){
            ll tmpnum = s[i]-'0';
            if(tmpnum%2 == 0){
                ans += i+1;
            }
        }
        cout << ans << endl;
    }else if(p==5){
        ll ans = 0;
        for(int i = 0; i < n; i++){
            ll tmpnum = s[i]-'0';
            if(tmpnum%5 == 0){
                ans += i+1;
            }
        }
        cout << ans << endl;
    }else{
        map<ll, ll> mp;
        mp[0] = 1;
        ll coef = 1;
        ll num = 0;
        ll ans = 0;
        for(int i = 0; i < n; i++){
            ll tmpnum = s[n-1-i]-'0';
            num += coef*tmpnum;
            num %= p;
            coef *= 10;
            coef %= p;
            mp[num]++;
        }
        for(auto itr = mp.begin(); itr != mp.end(); ++itr){
            ans += itr->second*(itr->second-1LL)/2;
        }
        cout << ans << endl;
    }


    return 0;

}


Measured memory_bytes: 4156
//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib>      // srand,rand
#include <random>
#include <functional>

using namespace std;
using namespace std;
int main(void) {
	int N;
	cin >> N;
	string S;
	cin >> S;
	map<char, long long> mp;
	for (int i = 0; i < N; i++) {
		mp[S[i]]++;
	}
	long long ans = mp['R'] * mp['G'] * mp['B'];
	long long Notans = 0;
	for (int k = 2; k < N; k++) {
		for (int j = 1; j < k; j++) {
			int i = 2 * j - k;
			if (0 <= i && i < j ) {
				if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) Notans++;
			}
		}
	}
	cout << ans - Notans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    int a[n], b[n];
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }
    int ans = 0;
    int ma[n], mb[n];
    for (int i = 0; i <= 28; i++) {
        int T = 1 << i;
        rep(i, n) {
            ma[i] = a[i] % (2 * T);
        }
        rep(i, n) {
            mb[i] = b[i] % (2 * T);
        }
        sort(mb, mb + n);
        ll sum = 0;
        rep(i, n) {
            sum += lower_bound(mb, mb + n, 2 * T - ma[i]) -
                   lower_bound(mb, mb + n, T - ma[i]);
            sum += lower_bound(mb, mb + n, 4 * T - ma[i]) -
                   lower_bound(mb, mb + n, 3 * T - ma[i]);
        }
        if (sum % 2) {
            ans += T;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6740
#include <stdio.h>

int main(){
 int a,b,c,d,e,k;

 scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);

 if((e-a) <= k){
  printf("Yay!");
 }else{
  printf(":(");
 }
}

Measured memory_bytes: 128
//
// Created on 2020/09/05.
//

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    string s,t;
    cin>>s>>t;
    int ans = INF;
    for (int i = 0; i < s.size(); ++i) {
        int cnt = 0;
        for (int j = 0; j < t.size(); ++j) {
            if(i + j >= s.size()){
                cnt = INF;
                break;
            }
            if(s[i+j] != t[j]){
                cnt ++;
            }
        }
        chmin(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORX(i,n) for(int i=1;i<=n;i++) 
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
const int N=2e5+200;
struct node{
	int s,t,x;
}a[N];
int ans[N],n,m,value;
set<pair<int,int> >vis;
int cmp(const node &a,const node &b){
	return a.x<b.x;
}
int main(){
	scan(n);scan(m);
	FOR(i,n){
		scan(a[i].s);scan(a[i].t);scan(a[i].x);
		a[i].s-=a[i].x;a[i].t-=a[i].x;
	}
	sort(a,a+n,cmp); 
	memset(ans,-1,sizeof(ans));
	FOR(i,m){
	scan(value);
	vis.insert({value,i});}
	FOR(i,n){
		set<pair<int,int> >::iterator it;
		it=vis.lower_bound({a[i].s,0});
		while(it!=vis.end()){
			if(it->first>=a[i].t)break;
			ans[it->second]=a[i].x;
			vis.erase(it++);
		}
	}
	FOR(i,m) print(ans[i]);
}

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

const ll MAXN = 200000;

ll N, K, ans=1000000000000, tmp=-1;
vector<ll> A, B;

signed main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        if(a<0) A.push_back(a);
        else B.push_back(a);
    }
    reverse(A.begin(), A.end());
    ll As = (ll)A.size();
    ll Bs = (ll)B.size();
    for(int i=0;i<min(K, As);i++) {
        if(Bs-1>=K-i-2&&K-i-2>=0) {
            ans = min(ans, 2*min(abs(A[i]), abs(B[K-i-2])) + max(abs(A[i]), abs(B[K-i-2])));
        }
    }
    if(As>=K) ans = min(ans, abs(A[K-1]));
    for(int i=0;i<min(K, Bs);i++) {
        if(As-1>=K-i-2&&K-i-2>=0) {
            ans = min(ans, 2*min(abs(B[i]), abs(A[K-i-2])) + max(abs(B[i]), abs(A[K-i-2])));
        }
    }
    if((ll)B.size()>=K) ans = min(ans, abs(B[K-1]));
    /*
    if(K>tmp+1) {
        for(int i=0;i<=tmp;i++) {
            if(K+i-1<=N-1) ans = min(ans, 2*min(abs(A[i]), abs(A[K+i-1])) + max(abs(A[i]), abs(A[K+i-1])));
        }
    }
    if(K>N-tmp-1) {
        for(int i=tmp+1;i<N;i++) {
            if(i+1-K>=0) ans = min(ans, 2*min(abs(A[i]), abs(A[i+1-K])) + max(abs(A[i]), abs(A[i+1-K])));
        }
    }
    */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1656
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

template<typename T> 
struct presum_2D{
  int h,w;
  V<V<T>> sum;
  presum_2D(const V<V<T>>& _sum):h(_sum.size()),w(_sum[0].size()),sum(_sum){
    sum.insert(sum.begin(),V<int>(w+1,0));
    rep(i,1,h+1)sum[i].insert(sum[i].begin(),0);

    rep(i,0,h+1)rep(j,0,w)sum[i][j+1]+=sum[i][j];
    rep(j,0,w+1)rep(i,0,h)sum[i+1][j]+=sum[i][j];
  }

  inline T get_sum(int lg,int lr,int rg,int rr){
    return sum[rg+1][rr+1]+sum[lg][lr]-sum[rg+1][lr]-sum[lg][rr+1];
  }//元のindexを渡す 閉区間
};


signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  ll n,m,q;cin>>n>>m>>q;

  VV<int> v(n,V<int>(m)),eg(n,V<int>(m)),er=eg;
  rep(i,0,n)rep(j,0,m){
    char c;
    cin>>c;
    v[i][j]=c-'0';
  }

  rep(i,0,n-1){
    rep(j,0,m){
      if(v[i][j]==1 && v[i+1][j]==1)eg[i][j]++;
    }
  }

  rep(i,0,n){
    rep(j,0,m-1){
      if(v[i][j]==1 && v[i][j+1]==1)er[i][j]++;
    }
  }

  presum_2D<int> vsum(v),egsum(eg),ersum(er);

  while(q--){
    int a,b,c,d;cin>>a>>b>>c>>d;
    --a;--b;--c;--d;
    cout<<vsum.get_sum(a,b,c,d)-egsum.get_sum(a,b,c-1,d)-ersum.get_sum(a,b,c,d-1)<<ENDL;
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 133064
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n>>m>>x;
    rep(i,m)cin>>a[i];
    rep(i,m){
        if(a[i]<x)tmp++;
        else tmpp++;
    }
    Cout(min(tmp,tmpp));
    return 0;
}


Measured memory_bytes: 256
<?php
  
  
$c_500 = (int)trim(fgets(STDIN));
$c_100 = (int)trim(fgets(STDIN));
$c_50 = (int)trim(fgets(STDIN));
$total = (int)trim(fgets(STDIN));

$count = 0;

for ($x = 0; $x <= $c_500; ++$x) {
    for ($y = 0; $y <= $c_100; ++$y) {
        for ($z = 0; $z <= $c_50; ++$z) {
            $r = 500 * $x + 100 * $y + 50 * $z;
            if ($total === $r) ++$count;
        }
    }
}

echo $count;


Measured memory_bytes: 4604
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;
const int NMAX = 111;
const int VMAX = 100100;
ll dp[NMAX][VMAX];

int main() {
    int N;
    ll W;
    cin >> N >> W;
    vector<ll> w(N);
    vector<int> v(N);
    rep(i,N) cin >> w[i] >> v[i];
    
    int V = 0;
    rep(i,N) V += v[i];
    rep(i,NMAX)rep(j,VMAX) dp[i][j] = LINF;
    dp[0][0] = 0;
    rep(i,N) {
        for (int j = 0; j <= V; ++j) {
            if (j-v[i]<0) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i]);
        }
    }
    ll ans = 0;
    for (int i = 0; i <= V; ++i) {
        if (dp[N][i]<=W) ans = i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 87040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



namespace ConsoleApplication3
{
    class Program
    {

        static void Main(string[] args)
        {
            string temp;
            string[] input;
            var list = new List<int>();
            int position = -1,parm1,parm2,result=0;
            temp = Console.ReadLine();
            input = temp.Split(' ');

            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] == "+" || input[i] == "-" || input[i] == "*")
                {
                    parm2 = list[position];
                    list.RemoveAt(position--);
                    parm1 = list[position];
                    list.RemoveAt(position--);
                    
                    switch (input[i])
                    {
                        case "+":
                            result = parm1 + parm2;
                            break;
                        case "-":
                            result = parm1 - parm2;
                            break;
                        case "*":
                            result = parm1 * parm2;
                            break;

                    }
                    list.Add(result);
                    position++;
                }
                else
                {
                    list.Add(int.Parse(input[i]));
                    position++;
                }


            }


            Console.WriteLine(result);



        }
    }
}



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

long long N, M, A, B, C, I[100000], n, i;

main(){
    scanf("%lld%lld", &N, &M);
    scanf("%lld", &A);
    for(; i < M - 1; ++i){
        scanf("%lld", &B);
        --I[max(A, B) - 1];
        ++I[min(A, B) - 1];
        swap(A, B);
    }
    for(i = 0, M = 0; i < N - 1; ++i){
        n += I[i];
        scanf("%lld%lld%lld", &A, &B, &C);
        M += min(A * n, B * n + C);
    }
    cout << M << endl;
    return 0;
}

Measured memory_bytes: 3928
#include<stdio.h>
int main()
{
    int n, i;
    long long x, y, z, a[10000];
    scanf("%d", &n);
    scanf("%ld", &a[0]);
    x = a[0];
    y = a[0];
    z = a[0];
    for(i = 1;i < n;i++){
        scanf("%ld", &a[i]);
        if(a[i] < x){
            x = a[i];
        }
        else if(a[i] > y){
            y = a[i];
        }
        z = z + a[i];
    }
    printf("%ld %ld %ld\n", x, y, z);
    return 0;
}


Measured memory_bytes: 2136