akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

const int MOD = 1e9 + 7, N = 1e5 + 7;

int two[N] = { 1 }, three[N] = { 1 };

void solve() {
    loop1(i, N - 1) {
        two[i] = two[i - 1] * 2 % MOD;
        three[i] = three[i - 1] * 3 % MOD;
    }
    string s; cin >> s;
    int ans = 1;
    loop(i, s.size() - 1)
        ans = (ans + 2 * three[i]) % MOD;
    int cnt = 1;
    for (int i = 1; i < s.size(); ++i)
        if (s[i] == '1')
            ans = (ans + two[cnt++] * three[s.size() - 1 - i]) % MOD;
    ans = (ans + two[cnt]) % MOD;
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 5340
N = int(input())
colors = input()
data = [int(c == 'R') for c in colors]

lm = 0
rm = sum(data)
min_move = rm

for i in range(N):
    if data[i]:
        rm -= 1
    else:
        lm += 1
    move = min(lm, rm) + abs(lm - rm)
    min_move = min(min_move, move)

print(min_move)


Measured memory_bytes: 10924
n_list = list(map(int, input().split()))


n = n_list[0]
TIME = n_list[1]

x = 0
num = 1
costs = []

while num <= n:
    cost, time = list(map(int, input().split()))
    num += 1
    if TIME - time >= 0:
        costs.append(cost)

if len(costs) != 0:
    output = min(costs)
else:
    output = "TLE"
print(output)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <fstream>
#define ni(n) scanf("%d", &n)
#define nl(n) scanf("%I64d", &n)
#define nai(a,n) for (int i = 0; i < (n); i++) ni((a)[i])
#define nal(a,n) for (int i = 0; i < (n); i++) nl((a)[i])
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;
vector<pair<int, pii> > p;

int main()
{
    int n;
    ni(n);
    for (int i = 0; i < n; i++)
    {
        int t, x, y;
        ni(t), ni(x), ni(y);
        p.pb(mp(t, mp(x, y)));
    }
    sort(p.begin(), p.end(), [](pair<int, pii> o1, pair<int, pii> o2) -> bool
         {
             return o1.f < o2.f;
         });
    int flag = 1;
    int x = 0, y = 0, t = 0;
    for (int i = 0; i < n; i++)
    {
        int dist = abs(x - p[i].s.f) + abs(y - p[i].s.s);
        if (p[i].f - t < dist)
        {
            flag = 0;
            break;
        }
        else if ((p[i].f - t) % 2 != dist % 2)
        {
            flag = 0;
            break;
        }
        x = p[i].s.f;
        y = p[i].s.s;
        t = p[i].f;
    }
    if (flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 1912
#include<stdio.h>
int main(void)
{
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	if(a>=b) printf("delicious\n");
	else{
		if(x+(a-b)<0) printf("dangerous\n");
		else printf("safe\n");
	}
		return 0;
}

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

using namespace std;

namespace {
    int a, b;
    void input() {
        cin >> a >> b;
    }

    void solve() {
        cout << (a + b + 1) / 2 << endl;
    }
}

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



Measured memory_bytes: 256
n,m = map(int,input().split())
light_data = [[int(x) for x in input().split()][1:] for _ in range(m)] #読み込んだ行の先頭のデータは削除する
p_data = [int(x) for x in input().split()]

count = 0
for i in range(2**n):
    switch_state = i
    for i,l_data in enumerate(light_data):
        on_switch = 0
        for light_num in l_data:
            
            if switch_state & 1<<(light_num - 1):
                on_switch += 1
        
        if on_switch%2 == p_data[i]:
            continue
        else:
            break
            
    else: # M個の電球が全て点灯していたらcountを増やす
        count += 1
        
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define pb                  push_back
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)      type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
const double pi = 3.1415926535897932384626433;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
bool check(double mid,int a[],int n,int k){
int temp=0;
    for(int i=0;i<n;i++){

        if(a[i]>mid){

            temp+=ceil(a[i]*1.0)/mid;

        }
    }
    if(temp>k)
        return false;
    return true;
}
void JH(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int n,k;cin>>n>>k;
    int a[n];
    fo0(i,n){
        cin>>a[i];
    }
    sort(a,a+n);

    int l=1,h=a[n-1];

    while(l<=h){
        double mid=(l+h)*1.0/2;

        if(check(mid,a,n,k)){
            ans=ceil(mid);
            h=ceil(mid)-1;
        }
        else
            l=floor(mid)+1;
    }
    cout<<ans<<endl;

}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<fixed<<setprecision(3)<<(double)(clock()-beg)/1000<<"s ";
}

Measured memory_bytes: 5344
function Main(input){
  var tmp =  input.split('\n')[0]
  var A = parseInt(tmp.split(' ')[0]);
  var V = parseInt(tmp.split(' ')[1]);
  
  tmp =  input.split('\n')[1]
  var B = parseInt(tmp.split(' ')[0]);
  var W = parseInt(tmp.split(' ')[1]);
  
  var T = parseInt(input.split('\n')[2]);
  
  // console.log(A, V, B, W, T);
  
  // AとBの距離
  var D = A - B;
  if (D < 0) {
    D = -D;
  }
  
  // D+AがT秒間に逃げる距離をBがT秒間に移動できる距離が大きければBの勝ち
  if ((D + W*T) <= V*T ) {
    console.log('YES');
  } else {
    console.log('NO');
  }
}
 
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

int main() {
    int n;
    cin >> n;
    int a = n / 1000;
    int b = (n - a*1000) / 100;
    int c = (n - a*1000 - b*100) / 10;
    int d = n % 10;

    if(a+b+c+d == 7) {
        cout << a << "+" << b << "+" << c << "+" << d << "=7";
    } else if (a+b+c-d == 7) {
        cout << a << "+" << b << "+" << c << "-" << d << "=7";        
    } else if (a+b-c+d == 7) {
        cout << a << "+" << b << "-" << c << "+" << d << "=7";
    } else if (a-b+c+d == 7) {
        cout << a << "-" << b << "+" << c << "+" << d << "=7";        
    } else if (a-b-c+d == 7) {
        cout << a << "-" << b << "-" << c << "+" << d << "=7";
    } else if (a+b-c-d == 7) {
        cout << a << "+" << b << "-" << c << "-" << d << "=7";
    } else if (a-b-c-d == 7) {
        cout << a << "-" << b << "-" << c << "-" << d << "=7";
    } else {
        cout << a << "-" << b << "+" << c << "-" << d << "=7";        
    }

    return 0;
}
 

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

int main() {
  int N;
  cin >> N;
  vector<int> house(N);
  
  for(int i = 0; i < N; i++) {
    cin >> house.at(i);
  }
  
  sort(house.begin(), house.end());
  int x = house.at(house.size() - 1) - house.at(0);
  cout << x << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    D, T, S = [int(x) for x in input().strip().split()]
    if D / S <= T:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int x,y;
  while(true){
    cin>>x>>y;
    if(x==0 && y==0){
      break;
    }
    if(x>y){
      swap(x,y);
    }
    cout<<x<<' '<<y<<'\n';
  }
  return(0);
}



Measured memory_bytes: 3004
def main():
    n = int(input())
    primes = get_primenumber(55555)
    out = []
    num = 0
    for prime in primes:
        if prime%5 == 1:
           out.append(prime)
           num += 1
        if n == num:
            print(*out)
            return

def get_primenumber(number):
    prime_list = []
    if number < 2:
        return prime_list
    if number == 2:
        return [2]
    search_list = [2] + list(range(3, number+1, 2))
    while True:
      if search_list[0] > number**0.5:
        prime_list.extend(search_list)
        break
      else:
        head_num = search_list[0]
        prime_list.append(head_num)
        search_list.pop(0)
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list

        
if __name__ == "__main__":
    main()

Measured memory_bytes: 4340
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back


int solve(int n){
    string s=to_string(n);
    
    int maxi=-1;
    rep(i,s.size()-1){
        int tmp;
        tmp=stoi( s.substr(0,i+1) ) * stoi( s.substr(i+1,s.size()-i) );
        maxi=max(maxi,tmp);
    }
    
    return maxi;
}

int main(){
    int abcde;
    cin>>abcde;
    rep(i,abcde){
        int n;
        cin>>n;
        
        int c=0;
        for(int i=0;i<1000000;i++){
            if(i==1000000-1)c=-1;
            
            if(n<10)break;
            n=solve(n);
            c++;
        }
        cout<<c<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1244
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	string a, b; cin >> a >> b;
	ll count = 0;
	if (a[0] == b[0]) count++;
	if (a[1] == b[1]) count++;
	if (a[2] == b[2]) count++;
	cout << count << endl;
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N, K;

int main() {
	cin >> N >> K;
	cout << (int)ceil((double)N / K) - (int)floor((double)N / K) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
using namespace std;
typedef vector<int> vi;
vector<pair<pair<int,int>,int> >m;
vi result;
int result_size=-1;
int n,x;
void dfs(vi &v,int d){
	if(d==n){
		int i=0,j,w;
		for(i=0;i<m.size();i++){
			for(w=0,j=m[i].first.first;j<=m[i].first.second;j++){
				w+=v[j];
			}
			if(m[i].second!=w)break;
		}
		if(i==m.size()){
			for(w=i=0;i<n;i++)w+=v[i];
			if(w>result_size)result_size=w,result=v;
		}
	}else{
		for(int i=0;i<=x;i++){
			v.push_back(i);
			dfs(v,d+1);
			v.pop_back();
		}
	}
}
main(){
	int M,l,r,s;
	for(scanf("%d%d%d",&n,&x,&M);M--;){
		scanf("%d%d%d",&l,&r,&s);
		m.push_back(make_pair(make_pair(l-1,r-1),s));
	}
	vi v;
	dfs(v,0);
	if(result_size==-1){puts("-1");return 0;}
	printf("%d",result[0]);
	for(M=1;M<n;M++)printf(" %d",result[M]);
	puts("");
}

Measured memory_bytes: 1068
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

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; }
const long long INF = 1LL<<60;

int main() {
    long long N, Z, W; cin >> N >> Z >> W;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<vector<long long> > dp(N+1, vector<long long>(2));
    for (int i = N-1; i >= 0; --i) {
        // 先手番
        dp[i][0] = -INF; // 初期化
        long long Y = (i ? a[i-1] : W);
        chmax(dp[i][0], abs(Y - a[N-1]));
        for (int j = i+1; j < N; ++j) chmax(dp[i][0], dp[j][1]);

        // 後手番
        dp[i][1] = INF; // 初期化
        long long X = (i ? a[i-1] : Z);
        chmin(dp[i][1], abs(X - a[N-1]));
        for (int j = i+1; j < N; ++j) chmin(dp[i][1], dp[j][0]);
    }
    cout << dp[0][0] << endl;
}

Measured memory_bytes: 384
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    A = [0]
    B = [0]
    C = [0]
    for _ in range(N):
        a, b, c = map(int, input().split())
        A.append(a)
        B.append(b)
        C.append(c)
    dp = [[0 for _ in range(N + 1)] for _ in range(3)]

    for n in range(1, N + 1):
        a = A[n]
        b = B[n]
        c = C[n]
        dp[0][n] = max(dp[1][n - 1] + b, dp[2][n - 1] + c)
        dp[1][n] = max(dp[2][n - 1] + c, dp[0][n - 1] + a)
        dp[2][n] = max(dp[1][n - 1] + b, dp[0][n - 1] + a)

    print(max(dp[0][-1], dp[1][-1], dp[2][-1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 26832
#include<bits/stdc++.h> //ABC 161_d
using namespace std;
#define ll long long
ll a[100005];
int k,first=1,last=9;
int main(){
	cin>>k;
	for(int i=1;i<=9;i++)
		a[i]=i;
	if(k<=9){
		cout<<a[k];return 0;
	}
	while(1){
		ll t=a[first];
		for(int i=-1;i<=1;i++){
			if(t%10==0&&i==-1)continue;
			if(t%10==9&&i==1)continue;
			ll nt=t*10+t%10+i;
			a[++last]=nt;
			if(last>=k){
				cout<<a[k];
				return 0;
			}
		}
		first++;
	}
	return 0;
}


Measured memory_bytes: 1024
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))
void solve(); int main() { solve(); return 0; }

void solve() {
  vector<int> S;
  loop(i,0,3) {
    int a;
    cin >> a;
    S.push_back(a);
  }
  cout << min(S[0]*S[1], S[2]) << endl;
}


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

const int MOD = 1000000007;

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

  long long int ans=0;

  for (int i = 0; i < 60; ++i) {
    long long int cnt=0;
    for(int j=0;j<n;j++){
      long long int bit = a[j];
      if (bit & ((long long int)1 << i)) {
        cnt++;
      }
    }
    long long int b = cnt*(n-cnt);
    b %= MOD;
    long long int c = ((long long int)1 << i);
    c %= MOD;

    ans += b*c;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	a = inputInt()
	s = input()
	s = s[:-1]

	if a >= 3200:
		print(s)
	else:
		print("red")


if __name__ == "__main__":
	main()


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

#define f(i,a,b) for (int i =a; i < b ;i++)

const int mxn = 2000;

int n,m,q;
int board[mxn][mxn],dp[mxn][mxn],dp2[mxn][mxn],num[mxn][mxn];

// vertical
int sum(int x1, int y1, int x2, int y2) {
	return dp[x2][y2] - dp[x1][y2] - (y1?dp[x2][y1-1]-dp[x1][y1-1]:0);	
}

// horizontal
int sum2(int x1, int y1, int x2, int y2) {
	return dp2[x2][y2] - dp2[x2][y1] - (x1?dp2[x1-1][y2]-dp2[x1-1][y1]:0);
}

int numb(int x1, int y1, int x2, int y2) {
	int ans = num[x2][y2];
	if (x1) ans -= num[x1-1][y2];
	if (y1) ans -= num[x2][y1-1];
	if (x1 && y1) ans += num[x1-1][y1-1];
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	cin>>n>>m>>q;
	f(i,0,n) {
		string s; cin>>s;
		f(j,0,m) board[i][j] = s[j]-'0';
	}	
	f(i,0,n) f(j,0,m) dp[i][j] = dp2[i][j] = num[i][j] = 0;
	f(i,0,n) f(j,0,m) {
		if (i) dp[i][j] += dp[i-1][j] + board[i][j] * board[i-1][j];
		if (j) dp[i][j] += dp[i][j-1];
		if (i && j) dp[i][j] -= dp[i-1][j-1];
	}
	f(i,0,n) f(j,0,m) {
		if (i) dp2[i][j] += dp2[i-1][j];
		if (j) dp2[i][j] += dp2[i][j-1] + board[i][j] * board[i][j-1];
		if (i && j) dp2[i][j] -= dp2[i-1][j-1];
	}
	f(i,0,n) f(j,0,m) {
		num[i][j] = board[i][j];
		if (i) num[i][j] += num[i-1][j];
		if (j) num[i][j] += num[i][j-1];
		if (i && j) num[i][j] -= num[i-1][j-1];
	}

	stringstream ss;
	f(_,0,q) {
		int x1, y1, x2, y2; cin>>x1>>y1>>x2>>y2;
		x1--; y1--; x2--; y2--;
		ss << numb(x1,y1,x2,y2) - sum(x1,y1,x2,y2) - sum2(x1,y1,x2,y2) << endl;
	}
	cout << ss.str();
	

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 67588
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int gcd_impl(int a, int b) {
	if (b == 0) {
		return a;
	}
	
	return gcd_impl(b, a % b);
}

int gcd(int a, int b, int c) {
	return gcd_impl(gcd_impl(a, b), c);
}

int main(int argc, char* argv[])
{
	//ABC162 C
	int k, a,b,c;
	int ans = 0;
	// K (200まで)

	// X(赤食) Y(緑食) A(赤) B(緑) C(無)
	// p1 p2...赤
	// q1 q2...緑
	// r1 r2...無
	//cin >> x >> y >> a >> b >> c;

	cin >> k;

	for (a = 1; a <= k; a++) {
		for (b = 1; b <= k; b++) {
			for (c = 1; c <= k; c++) {
				ans += gcd(a, b, c);
			}
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3636
# フェルマーの小定理，逆元，（繰り返し二乗法）

n,a,b = map(int, input().split())
mod = 10**9 + 7
s = pow(2,n,mod) - 1 # どんな花束の数でもいい時の場合の数（花束を渡さない選択肢はないから，その分は省略）

# nCr
def fur(n,r):
    # ここはnCrの分数の分子と分母を計算
    x,y = 1,1
    for i in range(r):
        x = x*(n-i)%mod
        y = y*(i+1)%mod
    return x * pow(y,mod-2,mod) % mod # フェルマーの小定理を使うことで，割り算のmod計算を掛け算のmod計算にできた(逆元？)

print((s - fur(n,a) - fur(n,b)) % mod)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;
using ll = long long;

int main(){
    ll N;
    ll ans = 0;
    ll L[86];
    L[0] = 2;
    L[1] = 1;

    cin >> N;

    for(ll i = 2; i<=N; i++){
        L[i]=L[i-1]+L[i-2];
    }
    ans = L[N];
    cout << ans << endl;
    return 0 ;
}

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

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define UNIQUE(x)       x.erase(unique(all(x)), x.end())

#define fs              first
#define sc              second
#define pb              push_back

#define sz(x)           (int)x.size()
#define all(v)          v.begin(),v.end()
#define D(x)            cerr << #x " = " << x << '\n'
#define ms(a,b)         memset(a, b, sizeof(a))
#define valid(x,y,n, m)      x>=0 && y>=0 && x<n && y<m

#define input           freopen("/Users/shahadat/Desktop/input.txt", "r", stdin)
#define output          freopen("/Users/shahadat/Desktop/output.txt", "w", stdout)

#define endl            '\n'
#define eps             1e-5
#define yes             printf("Yes\n")
#define no              printf("No\n")

inline void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

#define int long long

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(10, 20)(rng);

int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
inline int Set(int n,int pos) { return n = n | (1 << pos); }
inline int Reset(int n,int pos) { return n = n & ~(1 << pos); }
inline bool Check(int n,int pos) { return (bool)(n & (1 << pos)); }
inline int Count(int n) {
    int res = 0;
    while(n){
        if(n & 1) res++;
        n >>= 1;
    }
    return res;
}

typedef pair<int,int> pint;

int const N = 3e5;
int const MOD = 1e9 + 7;

int ex = 0;
int ed[40][40];

int n, m;

int foo(int mask, int po, int p){
    int res = 0;
    for(int pos = 0; pos < m; pos++){
        if(Check(mask, pos))
           res += ed[pos][po] * abs(pos - p);
    }
    return res;
}

int fun(int mask){
    if(mask == (1 << m) - 1)
        return 0;
    
    int res = 1e9;
    int cnt = Count(mask);
    for(int pos = 0; pos < m; pos++){
        if(Check(mask, pos) == 0){
            res = min(foo(mask, cnt, pos) + fun(Set(mask, pos)), res);
        }
    }
    return res;
}

inline void solve(){
    cin >> n >> m;
    
    string str;
    cin >> str;
    
    for(int i = 1; i < n; i++){
        int cur = str[i] - 'a';
        int prev = str[i - 1] - 'a';
        ed[cur][prev]++;
    }
    for(int i = 0; i < n - 1; i++){
        int cur = str[i] - 'a';
        int nxt = str[i + 1] - 'a';
        ed[cur][nxt]++;
    }
    
    cout << fun(0) << endl;
}


map<int,int> cnt;

int32_t main(){
    int a, b;
    cin >> a >> b;
    
    int g = gcd(a, b);
    
    
    int cnt = 0;
    for(int i = 2; i * i <= g; i++){
        
        if(g % i == 0){
            while(g % i == 0){
                g /= i;
            }
            cnt++;
        }
    }
    if(g > 1) cnt++;
    
    cout << cnt + 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string s;
    cin >> s;
    int sum = 0;
    if(s[0]=='o')sum += 100;
    if(s[1]=='o')sum += 100;
    if(s[2] == 'o')sum += 100;
    cout << sum + 700 << endl;

    return 0;
}

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

int main() {
    int N;
    cin >> N;

    bool found = false;
    for (int i = 0; i <= N / 4; i++) {
        for (int k = 0; k <= N / 7; k++) {
            int total = 4 * i + 7 * k;
            if (total == N) {
                found = true;
            }
        }
    }

    cout << (found ? "Yes" : "No") << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int p[n];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int m = n, ans = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] <= m) {
      m = p[i];
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main (void){
	int a,b,c,d,e,f,g,h,i,j;
	int ans;
	
	scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
	ans=a+b+c+d+e+f+g+h+i+j;
	printf("%d\n",ans);
	
	
	
	
	
	
	
	return 0;
}

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

int main()
{
  ll n, W;
  cin >> n >> W;
  ll  wt[n];
  ll  val[n];
  for(ll i=0; i<n; i++){
    cin >> wt[i] >> val[i];
  }
  // ll f[n+1][w+1]={0};
  // for(ll i=0; i<=n; i++){
  //   for(ll j=0; j<=w; j++)
  //     f[i][j]=0;
  // }
  //cout << f[0][1] << endl;
  /*
  for(ll i=0; i<=n; i++){
    for(ll j=0; j<=w; j++){
      if(i==0 || j==0){
        f[i][j]=0;
      }
      else if(W[i-1]<=w){
        f[i][j]= max(f[i-1][j-W[i-1]]+V[i-1], f[i-1][j]);
      }
      else
        f[i][j]= f[i-1][j];
    }
  }
  cout << f[0][1] << endl;
  cout << f[n][w] << endl;
  */
   ll i, w;
   ll K[n+1][W+1];
   for (i = 0; i <= n; i++)
   {
       for (w = 0; w <= W; w++)
       {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }

  cout << K[n][W] << endl;
  return 0;
}


Measured memory_bytes: 79104
n = int(input())
s = str(input())
e_e = 0
w_w = 0
ans = len(s)
for i in range(len(s)):
  if s[i] ==  'E':
    e_e += 1
for i in range(len(s)):
  if s[i] == 'E':
    e_e -= 1
  ans = min(ans, e_e + w_w)
  if s[i] == 'W':
    w_w += 1
print(ans)

Measured memory_bytes: 3672
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] v = new int[n];
		for(int i = 0; i < n; i++)
			v[i] = in.nextInt();

		Arrays.sort(v);

		double s = v[0];
		for(int i = 1; i < n; i++) {
			s = (s + v[i]) / 2;
		}

		System.out.println(s);

	}
}

Measured memory_bytes: 23380
import java.util.*;
public class Main {
	static int day;
	static int Hn;
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			Hn=in.nextInt();
			day=in.nextInt();
			if(day+Hn==0)break;
			double[][] hyou=new double[Hn][Hn];
			for(int s=0;s<Hn;s++)for(int i=0;i<Hn;i++)hyou[s][i]=in.nextDouble();
			double[][] dp=new double[Hn][day];
			for(int i=0;i<Hn;i++)dp[i][0]=1.0;
			for(int hi=1;hi<day;hi++){
				for(int i=0;i<Hn;i++){
					//dp[i][hi]を考える
					double max=0;
					for(int k=0;k<Hn;k++){
						max=Math.max(max,hyou[k][i]*dp[k][hi-1]);
					}
					dp[i][hi]=max;
				}
			}
			double max=0;
			for(int i=0;i<Hn;i++)max=Math.max(max,dp[i][day-1]);
			System.out.printf("%.2f\n", max);
		}
	}
}

Measured memory_bytes: 65724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
inline int popcount(const int x) { return __builtin_popcount(x);}
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt_r = 0;
  rep(i, n) {
    if (s[i] == 'R') cnt_r++;
  }
  if (cnt_r == n or cnt_r == 0) drop(0);
  int aki = 0, red = 0;
  rep(i, n) {
    if (s[i] == 'W') aki++;
    else red++;
    if (aki + red == cnt_r) break;
    debug(i, aki);
  }
  cout << aki << endl;
  return 0;
}

Measured memory_bytes: 3904
#include <stdio.h>

typedef struct{
  char s;
  int n;
} card;

void bubble(card c[], int N)
{
  int i, j;
  card x;
  
  for (i = 0; i < N; i++)
    for (j = N-1; j > i; j--)
      if (c[j].n < c[j-1].n){
	x = c[j];
	c[j] = c[j-1];
	c[j-1] = x;
      }
}

void selection(card c[], int N)
{
  int i, j, min;
  card x;

  for (i = 0; i < N; i++){
    min = i;
    for (j = i; j < N; j++)
      if (c[j].n < c[min].n)
	min = j;
    x = c[i];
    c[i] = c[min];
    c[min] = x;
  }
}

int stable(card c1[], card c2[], int N)
{
  int i;
  
  for (i = 0; i < N; i++)
    if (c1[i].s != c2[i].s)
      return 0;
  return 1;
}

int main()
{
  int i, N;
  card c1[36], c2[36];
  
  scanf("%d",&N);
  for (i = 0; i < N; i++){
    scanf(" %c%d",&c1[i].s,&c1[i].n);
    c2[i] = c1[i];
  }
  bubble(c1,N);
  selection(c2,N);
  for (i = 0; i < N; i++){
    printf("%c%d",c1[i].s,c1[i].n);
    if (i < N-1)
      printf(" ");
    else
      printf("\n");
  }
  printf("Stable\n");
  for (i = 0; i < N; i++){
    printf("%c%d",c2[i].s,c2[i].n);
    if (i < N-1)
      printf(" ");
    else
      printf("\n");
  }
  if (stable(c1,c2,N) == 0)
    printf("Not stable\n");
  else
    printf("Stable\n");

  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
    
int n;
int h[101010];
int memo[101010];

int main(){
    scanf("%d",&n);
    
    for(int i=0;i<n;i++)
        scanf("%d",&h[i]);
    
    memo[0] = 0;
    memo[1] = abs(h[0]-h[1]);
    
    for(int i=2;i<n;i++)
        memo[i] = min( abs(h[i]-h[i-1])+memo[i-1] , abs(h[i]-h[i-2])+memo[i-2] );
    
    printf("%d\n",memo[n-1]);
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pi 2*acos(0.0)
#define mod 998244353

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

    ll n;
    cin >> n;

    if(n%2 == 0)
        cout << n<<endl;
    else
        cout << n*2<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }

int main() {
    cout << setprecision(20);
    ll n, a;
    cin >> n >> a;
    ll ans = n;
    for (int co = 1; co <= 300; co++) {
        ll buf = co * a;
        ll u = pow(n, 1.0/(co+1));
        for (int x = co+1; x >= 0; x--) {
            ll oo = 1;
            for (int j = 0; j < x; j++) {
                oo *= u;
                oo = min(oo, 2*n);
            }
            for (int j = x; j < co+1; j++) {
                oo *= (u+1);
                oo = min(oo, 2*n);
            }
            if (n <= oo) {
//                cout << co << " " << x << " " << u <<  " " << buf+u*x+(u+1)*(co+1-x) << endl;
                ans = min(ans, buf+u*x+(u+1)*(co+1-x));
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>

using namespace std;
char ch;
int main()
{
 cin>>ch;
 if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') cout<<"vowel";
 else cout<<"consonant";
 return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void TokioMarine2020C();

#if 1
int main()
{
	TokioMarine2020C();
	fflush(stdout);
	return 0;
}
#endif

static void TokioMarine2020C()
{
	int N, K;

	getint(N, K);
	std::vector<LLONG> ai(N, 0);
	for (int i = 0; i < N; i++) {
		getint(ai[i]);
	}

	for (int k = 0; k < K; k++) {
		std::vector<LLONG> bi(N, 0);
		for (int i = 0; i < N; i++) {
			LLONG left = std::max<LLONG>(0, i - ai[i]);
			LLONG right = std::min<LLONG>(N - 1, i + ai[i]);
			bi[left]++;
			if (right < N - 1) {
				bi[right + 1]--;
			}
		}

		ai[0] = bi[0];
		LLONG minRight = MOD_NUM;
		for (int i = 1; i < N; i++) {
			ai[i] = ai[i - 1] + bi[i];
			minRight = std::min(ai[i], minRight);
		}
		if (minRight >= N) {
			break;
		}
	}
	for (int i = 0; i < N; i++) {
		printf("%lld ", ai[i]);
	}
	putchar('\n');
}


Measured memory_bytes: 6324
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    vector<vector<vector<int>>> tou(4,vector<vector<int>>(3,vector<int>(10)));

    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        tou[a-1][b-1][c-1] += d;
    }




    for(int i = 0; i < tou.size(); i++){
        for(int j = 0; j < tou[i].size(); j++){
            for(int k = 0; k < tou[i][j].size(); k++){
                cout <<" "<< tou[i][j][k];
                
            }
            cout << endl;
        }
        if(i < tou.size() - 1){
            cout << "####################" << endl;
        }
    }
 //   cout << endl;





}


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

int main() {
	string s, t;
	cin >> s >> t;

	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == t.at(i)) ans++;
	}

	cout << ans << endl;
}


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

int main()
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long ans = a*c;
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans << endl;
}

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

int main()
{
    int R, C, K;
    cin >> R >> C >> K;

    vector<vector<int>> table(R + 1, vector<int>(C + 1, 0));

    while (K--)
    {
        int r, c, v;
        cin >> r >> c >> v;
        table[r][c] = v;
    }

    vector<vector<vector<ll>>> dp(R + 1, vector<vector<ll>>(C + 1, vector<ll>(4, 0)));
    for (int i = 1; i <= R; ++i)
    {
        for (int j = 1; j <= C; ++j)
        {
            if (table[i][j] == 0)
            {
                ll ref = 0;
                rep(k, 4) ref = max(ref, dp[i - 1][j][k]);
                rep(k, 4) dp[i][j][k] = max(ref, dp[i][j - 1][k]);
            }
            else
            {
                ll ref = 0;
                rep(k, 4) ref = max(ref, dp[i - 1][j][k]);
                dp[i][j][0] = ref;
                dp[i][j][1] = max(ref + table[i][j], dp[i][j - 1][1]);
                dp[i][j][2] = max(dp[i][j - 1][1] + table[i][j], dp[i][j - 1][2]);
                dp[i][j][3] = max(dp[i][j - 1][2] + table[i][j], dp[i][j - 1][3]);
            }
        }
    }
    ll ans = 0;

    rep(i, 4) ans = max(ans, dp[R][C][i]);
    cout << ans << endl;
}

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

using namespace std;

typedef long long int lli;

int calc(lli n) {
  int r = 0;
  while (n) {
    n /= 10;
    r++;
  }
  return r;
}

int main() {
  lli n;
  int a = INT_MAX;
  cin >> n;
  for (lli i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      a = min(a, max(calc(i), calc(n / i)));
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

int gcd(int a, int b){
    if(a % b == 0) return b;
    else return (gcd(b, a%b));
}



int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    for(int i = N - 1; i > 0; i--){
        if(a[i - 1] > a[i]){
            if(a[i - 1] - 1 != a[i]){
                cout << "No" << endl;
                return 0;
            }else{
                a[i - 1]--;
            }
        }
    }
    cout << "Yes" << endl;
}

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

int main() {
	int x;
	cin >> x;
	int m = x / 500;
	int r = x % 500;
	cout << m * 1000 + r / 5 * 5 << endl;


}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        String[] str = bf.readLine().split(" ");
        int N = Integer.parseInt(str[0]),
            K = Integer.parseInt(str[1]);
        int[] h = new int[N];
        for(int i = 0; i < N; i++){
            h[i] = Integer.parseInt(bf.readLine());
        }
        Arrays.sort(h);
        int min = h[N-1] - h[0];
        for(int i = 0; i < N-K+1; i++){
            int value = h[i+K-1] - h[i];
            if(value < min){
                min = value;
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 30988
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"
const int N = 1e6 + 10;


signed main()
{
    FAST;
    int t;
    t=1;
    
    while(t--)
    {
        int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
        int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
        int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
        int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
        int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
        
        cin>>n;
        int a[n];
        vector<int> mp(N,0),mp1(N,0);
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            mp[a[i]]++;
        }
        
        ans=0;
        
        if(mp[1])
        {
            if(mp[1]==1)
            {
                cout<<1<<endl;
            }
            
            else
            {
                cout<<0<<endl;
            }
            
            return 0;
        }
        
        for(j=2;j<N;j++)
        {
            if(mp[j])
            {
                int num = j;
                count = mp[j];
                
                for(i=2;i*num<N;i++)
                {
                    mp1[i*num]++;
                }
                
                if(count==1 && !mp1[num])
                ans++;
            }
            
            
        }
        
        cout<<ans<<endl;
        
        
    }
        
    
    
    
    
}


Measured memory_bytes: 20376
#include <stdio.h>
int main(void){
    int i,n,num;
    int max=-1000000;
    int min=1000000;
    long sum=0;
    
    scanf("%d\n",&num);
    
    for(i=1;i<=num;i++){
        scanf("%d",&n);
        if(n>max) max=n;
        if(n<min) min=n;
        sum+=n;
    }
    printf("%d %d %ld\n",min,max,sum);
    
    return 0;
}

Measured memory_bytes: 600
#include <iostream>                                                  
#include <cstdio>                                                    
#include <cstring>                                                   
using namespace std;                                                 
                                                                     
int main() {                                                         
  int house[4][3][10];                                               
  memset(house,0,sizeof(house));                                     
  int n;                                                             
  cin >> n;                                                          
  while (n--) {                                                      
    int b, f, r, v;                                                  
    cin >> b >> f >> r >> v;                                         
    house[b-1][f-1][r-1] += v;                                       
  }                                                                  
  for (int i=0; i<4; i++) {                                          
    for (int j=0; j<3; j++) {                                        
      for (int k=0; k<10; k++) {                                     
        cout << " " << house[i][j][k] << flush;                      
      }                                                              
      printf("\n");                                                  
    }                                                                
    if (i==3) {                                                      
      break;                                                         
    }                                                                
    for (int l=0; l<20; l++) {                                       
      cout << "#" << flush;                                          
    }                                                                
    printf("\n");                                                    
  }                                                                  
  return 0;                                                          
}                                                                    
                                                                     
                      

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k; cin >> n >> k;
  string s; cin >> s;
  vector<int> accum(n, 0);
  int acc = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '0' && (i == 0 || s[i - 1] != '0')) accum[i] = 1;
  }
  for(int i = 1; i < s.size(); i++) accum[i] += accum[i - 1];
  int lo = 1, hi = s.size(), ans = 1;
  while(lo <= hi){
    int mid = (lo + hi)/2;
    bool someone = false;
    for(int i = 0; i+mid <= s.size(); i++){
    	bool canDo = s[i] == '1' || (s[i] == '0' && (i == 0 || s[i - 1] != '0'));
      if(canDo){
        int V = accum[i + mid - 1] - (i ? accum[i - 1] : 0);
        if(V <= k) someone = true;
      }
    }
    if(someone) lo = mid + 1, ans = mid;
    else hi = mid - 1;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  string temp;
  string x,y,z;
  cin >> x >> y >> z;
  while(1){
    if(temp=="a"){
      if(x.size()==0){
        cout << "A" << endl;
        return 0;
      }
      temp=x[0];
      x=x.substr(1,x.size()-1);
    }
    else if(temp=="b"){
      if(y.size()==0){
        cout << "B" << endl;
        return 0;
      }
      temp=y[0];
      y=y.substr(1,y.size()-1);
    }
    else{
      if(z.size()==0){
        cout << "C" << endl;
        return 0;
      }
      temp=z[0];
      z=z.substr(1,z.size()-1);
    }
  }
  return 0;
}

Measured memory_bytes: 256