akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int CMAX = 1005;
const int RMAX = (1 << 12) + 5;
/* global variables */
vector<vector<int> > dp(RMAX, vector<int>(CMAX, INF));
vector<int> cost(RMAX);
vector<bitset<12> > open(RMAX);
int N, M;
int upper;
/* function */
void initDPTable() {
    upper = 1 << N;
    for (int r = 0; r < upper; r++)
        for (int c = 0; c <= M; c++)
            dp[r][c] = INF;
    dp[0][0] = 0;
}
void calcDPTable() {
    for (int c = 1; c <= M; c++) {
        for (int r = 0; r < upper; r++)
            dp[r][c] = min(dp[r][c], dp[r][c - 1]);
        for (int r = 0; r < upper; r++) {
            bitset<12> pb(r);
            bitset<12> nb = pb | open[c - 1];
            int pi = pb.to_ulong();
            int ni = nb.to_ulong();
            int nextCost = dp[pi][c - 1] + cost[c - 1];
            dp[ni][c] = min(dp[ni][c], nextCost);
        }
    }
}
int calcAns() {
    if (dp[upper-1][M] == INF) return -1;
    else return dp[upper-1][M];
}
/* main */
int main(){
    cin >> N >> M;
    int m;
    for (int i = 0; i < M; i++) {
        cin >> cost[i] >> m;
        int k;
        bitset<12> bs(0);
        for (int j = 0; j < m; j++) {
            cin >> k;
            bs.set(k - 1);
        }
        open[i] = bs;
    }

    initDPTable();
    calcDPTable();
    cout << calcAns() << '\n';
}


Measured memory_bytes: 16512
def m():
    N = int(input())
    A = list(map(int, input().split()))
    prev = 0
    cur = 1
    maximum = mini = A[prev]
    stock, money = 0, 1000
    while cur < N:
        while A[prev] <= A[cur]:
            maximum = max(maximum, A[cur])
            prev = cur
            cur += 1
            if cur >= N:
                stock += (money // mini)
                money -= (money // mini) * mini
                money += (stock * maximum)
                return  money

        stock += (money // mini)
        money -= (money // mini) * mini
        money += (stock*maximum)
        stock = 0

        mini = A[cur]
        maximum = A[cur]
        prev = cur
        cur += 1

    return money

print(m())


Measured memory_bytes: 9056
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10

const ll MAX = 510000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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/gcd(a,b)*b;
}

struct Info{
    Info(ll arg_to,ll arg_cost){
        to = arg_to;
        cost = arg_cost;
    }
    bool operator<(const struct Info &arg) const{
            return cost > arg.cost;
    };
    ll to,cost;
};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b;
    cin>>a>>b;
    if(abs(a-b)>=2){
        cout<<0<<endl;
        return 0;
    }else if(a==b){
        cout<<factorial(a)*factorial(b)*2%mod<<endl;
    }else{
        cout<<factorial(a)*factorial(b)%mod<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    char s[10];scanf("%s",s);
    int i=0;int min=1e3;int abs;
    
    while(s[i+2]!='\0'){
        abs=(int)((s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0'));
        if(abs>753){
            abs-=753;
        }else{
            abs=753-abs;
        }   
        if(min>abs){
            min=abs;
        }   
        i++;
    }   
    printf("%d\n",min);
    return 0;
}   

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	string s;
	cin >> s;
	bool flag = true;
	REP(i, 3) {
		if (s[i] == s[i + 1]) {
			flag = false;
		}
	}
	if (flag) {
		cout << "Good" << endl;
	}
	else {
		cout << "Bad" << endl;
	}
	return 0;
}

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

int main() {
    string o, e;
    cin >>o >>e;
    for (int i = 0; i < e.size(); i++) {
        cout << o.at(i) << e.at(i);
    }
    if (o.size() != e.size()) {cout << o.at(o.size()-1);}
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k;
    long long int a,b,c,t,d;
    cin>>a>>b;
       d=a*b;
        if(d%2==0)
        {
            cout<<"Even"<<endl;
        }
        else{
            cout<<"Odd"<<endl;
        }
    return 0;
}


Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline
# import re
# import itertools
import collections

def main():
    n = int(input())
    s = input_list()
    sc = collections.Counter(s)
    q = int(input())
    data = []
    for i in range(q):
        b, c = input_list()
        sc[c] += sc[b]
        if i > 0:
            data.append(c*sc[b] - b * sc[b])
        if b in sc:
            sc.pop(b)
    ans = 0
    for k, v in sc.items():
        ans += k*v
    aa = [ans]
    for i, v in enumerate(data[::-1]):
        aa.append(aa[i] - v)
    for a in aa[::-1]:
        print(a)


def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()


Measured memory_bytes: 103148
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int H, W;
int main() {
	cin >> H >> W;
	long long ret = 1LL << 60;
	for (int t = 0; t < 2; t++) {
		for (int i = 1; i < H; i++) {
			int h = H - i, w = W;
			if (h % 2 == 0 || w % 2 == 0) {
				ret = min(ret, max(1LL * i * W, 1LL * h * w / 2) - min(1LL * i * W, 1LL * h * w / 2));
			}
			else if (h >= w) {
				ret = min(ret, max(1LL * i * W, 1LL * w * (h + 1) / 2) - min(1LL * i * W, 1LL * w * (h - 1) / 2));
			}
			else {
				ret = min(ret, max(1LL * i * W, 1LL * h * (w + 1) / 2) - min(1LL * i * W, 1LL * h * (w - 1) / 2));
			}
		}
		swap(H, W);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define ll long long int
#define pb push_back
#define mp make_pair
#define all(X) X.begin(), X.end()
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)

using namespace std;
using mii=map<int, int>;
using mll=map<ll, ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int mod = 1000000007;

ll desc(ll x, ll y)
{
    return x > y;
}

int main() {
    fastIO
    int n, i;
    cin >> n;

    vector<int> arr(n, 0);

    fo(i, n)
    cin >> arr[i];

    if(n == 1)
        cout << 0 << endl;
    else {
        int max_count = INT_MIN;
        int cur = 0;
        for (i = n - 2; i >= 0; i--) {
            if (arr[i] >= arr[i + 1])
                cur += 1;
            else
                cur = 0;

            max_count = max(max_count, cur);
        }
        cout << max_count << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
 
  for (int i = A; i <= B; i++){
    int a, b, c, d, e;
    a = i % 10;
    b = (i - a) % 100 / 10;
    c = (i - b * 10 - a) % 1000 / 100;
    d = (i - c * 100 - b * 10 - a) % 10000 / 1000;
    e = (i - d * 1000 - c * 100 - b * 10 - a) % 100000 / 10000;
    
    if (a == e && b == d){
      count++;
    }
  }
  cout << count << endl;
  
}

Measured memory_bytes: 3568
n,x=map(int,input().split())

#lレベルバーガーの下からx層に含まれるパティーの数
a=[1]*(n+1)
p=[1]*(n+1)
for i in range(1,n+1):
  a[i]=a[i-1]*2+3
  p[i]=p[i-1]*2+1

def count(l,x):
  if l==0:
    if x>=1:
      return 1
    else:
      return 0
  else:
    if x==1:
      return 0
    elif x<a[l-1]+2:
      return count(l-1,x-1)
    elif x==a[l-1]+2:
      return p[l-1]+1
    elif a[l]>x:
      return count(l-1,x-a[l-1]-2)+p[l-1]+1
    else:
      return p[l]
    
print(count(n,x))    
    

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

bool prime(int n) {
  if (n == 0) return false;
  if (n == 1) return false;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int q;
  cin >> q;
  vector<int> l(q);
  vector<int> r(q);
  vector<int> sum(100000, 0);
  for (int i = 0; i < q; i++) {
    cin >> l.at(i) >> r.at(i);
  }

  for (int i = 3; i <= 99999; i += 2) {
    if (prime(i) && prime((i + 1) / 2)) {
      sum.at(i) = sum.at(i - 2);
      sum.at(i)++;
    } else {
      sum.at(i) = sum.at(i - 2);
    }
  }
  for (int i = 0; i < q; i++) {
    if (prime(l.at(i)) == true && prime((l.at(i) + 1) / 2) == true)
      cout << sum.at(r.at(i)) - sum.at(l.at(i)) + 1 << endl;
    else
      cout << sum.at(r.at(i)) - sum.at(l.at(i)) << endl;
  }
  return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s;
	cin >> s;
	int n = s.size();
	int k;
	cin >> k;
	set<string> pos;
	rep(i, n) repn(j, 1, min(6, n - i + 1)){
		string cur = s.substr(i, j);
		pos.insert(cur);
	}
	int cnt = 0;
	for(string x : pos){
		cnt++;
		if(cnt == k){
			cout << x << endl;
			return 0;
		}
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int a=0;
  int b=0;
  for(int i=0;i<N;i++){
    if(S[i]=='1') a++;
    else b++;
  }
  if(a>b) cout << 2*b << endl;
  else cout << 2*a << endl;
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define int long long int
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define tr(k,st,en) for(int k = st; k <= en ; ++k)
#define trb(k,en,st) for(int k = en; k >= st ; --k)
using namespace std;

// n* k^k

void add_self(int& a, int b){
    a+=b;
    if (a >= mod) {
        a -= mod;
    }
    if (a < 0) {
        a += mod;
    }
}

int dp[402][402];

int32_t main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<vector<int>> can(n,vector<int>(n));
    tr(i,0, n-1){
        tr(j,0,n-1){
            cin>>can[i][j];
        }
    }
    int sz = 1ll<<n;
    vector<int> dp(sz);
    dp[0] = 1;
    tr(mask,0,sz - 2){
        int men = (int)__builtin_popcount(mask);
        tr(women,0,n-1){
            if (can[men][women] && !(mask & (1ll<<women))) {
                int newmask = mask^(1ll<<women);
                dp[newmask] = (dp[newmask] + dp[mask])%mod;
            }
        }
    }
    cout<<dp[sz-1]<<endl;
}



Measured memory_bytes: 19584
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ n, m ] <- readInts
	hs <- readInts
	[ as, bs ] <- map ( map pred ) . transpose <$> replicateM m readInts
	print $ solve n as bs hs

solve n as bs hs' = runST $ do
	let
		m = length as
	hs <- newArray ( 0, n - 1 ) 0 :: ST s ( STUArray s Int Int )
	higher <- newArray ( 0, n - 1 ) 0 :: ST s ( STUArray s Int Int )
	forM_ ( zip [ 0 .. ] hs' ) $ \( i, h ) -> do
		writeArray hs i h
	forM_ ( zip as bs ) $ \( a, b ) -> do
		ha <- readArray hs a
		hb <- readArray hs b
		when ( ha <= hb ) $ do
			modifyArray higher a succ
		when ( ha >= hb ) $ do
			modifyArray higher b succ
	length . filter  ( == 0 ) <$> getElems higher

Measured memory_bytes: 57172
#include <stdio.h>
int main(){
	int a, b, c,i,count=0;
	scanf("%d %d %d", &a, &b, &c);
	for ( i = a; i <= b; i++)
	{
		if (c%i == 0)
		{
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 596
from sys import exit, stderr, stdin
input = stdin.readline
from collections import defaultdict
from sys import stderr
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return
def main():
    N = int(input())
    S = [int(a) for a in input().split()]
    S = sorted(S)
    exist = [S.pop()]
    debug(S)
    debug(exist)
    for i in range(N):
        next_exist = []
        next_s = []
        for p in exist[::-1]:
            while S:
                x = S.pop()
                if x < p:
                    next_exist.append(x)
                    break
                else:
                    next_s.append(x)
        exist += next_exist
        exist.sort()
        S += next_s[::-1]

    if len(exist) == 2**N:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if __name__ == "__main__":
    main()


Measured memory_bytes: 34188
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,h,w = map(int, input().split())
    res = 0
    for _ in range(n):
        a,b = map(int, input().split())
        if a>=h and b>=w:
            res += 1
    print(res)

if __name__ == '__main__':
    main()

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

int n, x, a[10009], r = (1 << 30);

int main() {
	cin >> n >> x;
	for (int i = 1; i <= n; i++) {
		cin >> a[i]; r = min(r, a[i]);
		x -= a[i];
	}
	cout << n + (x / r) << endl;
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	cout << N * M << endl;
}


Measured memory_bytes: 3620
A, B, C, D = list(input())

for i in range(8):
    op1 = "+" if i & 1 else "-"
    op2 = "+" if i & 2 else "-"
    op3 = "+" if i & 4 else "-"
    S = A + op1 + B + op2 + C + op3 + D
    if eval(S) == 7:
        print(S + "=7")
        quit()


Measured memory_bytes: 2940
// AOJ 0216
#include<iostream>

int w;
const int ps[3] = { 125, 140, 160 };

int main()
{
	while( std::cin >> w, w != -1 )
	{
		int ans = 1150;
	
		for( int i = 0; i != 3; ++i )
		{
			const int border = ( i + 1 ) * 10;
			
			if( w >= border )
				ans += ps[i] * ( i == 2 ? w - border : std::min( w - border, 10 ) ); 
		}

		std::cout << 4280 - ans << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1160
N, M, X = map(int, input().split())
books = [input().split() for i in range(N)]
min_costs = float('inf')

for i in range(2 ** N):
    tmp_costs = 0
    skills = [0 for i in range(M)]
    for j in range(N): 
        if ((i >> j) & 1):
            tmp_costs += int(books[j][0])
            for k in range(M):
                skills[k] += int(books[j][k+1])
    
    if len([i for i in skills if i >= X]) == M:
        min_costs = min(min_costs, tmp_costs)

if min_costs == float('inf'):
    print(-1)        
else:
    print(min_costs)

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

int num(long n, int cnt=0){
  if (n==1) return cnt;
  else {
    cnt++;
    return num(n/2, cnt);
  } 
}

int main(){
  long n;
  cin >> n;
  long ans;
  ans = 2*pow(2,num(n))-1;
  cout << ans << endl;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << a.back() - a[0];
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
    fio;
    ll t, a, n, q, k, i, l, m, c, u, f, j, p, r, x, y, s, b, d;
    cin >> n>>d;
    vector<pair<ll,ll>>v(n,{0,0});
    for ( i = 0; i < n; i++)
    cin>>v[i].ff>>v[i].ss;
    
    c=0;
    for ( i = 0; i < n; i++)
    if(sqrt(v[i].ff*v[i].ff+v[i].ss*v[i].ss)<=d)c++;
    cout<<c;
    
    return 0;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
#define PB push_back
#define MP make_pair
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int64_t> A, B, C;
  for (int i = 0; i < n; ++i) {
    int64_t t;
    cin >> t;
    if (t == 0)
      C.PB(t);
    else if (t > 0)
      A.PB(t);
    else
      B.PB(t);
  }
  int N = SZ(B) / 2 * 2;
  while (N > k) N -= 2;
  if (N + SZ(A) < k) {
    if (SZ(C)) {
      cout << 0;
    } else {
      vector<int64_t> D;
      int64_t res = 1;
      for (auto &i : A) D.PB(i);
      for (auto &i : B) D.PB(i);
      sort(D.begin(), D.end(), [](int64_t a, int64_t b) { return abs(a) < abs(b); });
      for (int i = 0; i < k; ++i) res = res * D[i] % MOD;
      cout << (res % MOD + MOD) % MOD << '\n';
    }
    return 0;
  }
  vector<int64_t> D;
  for (auto &i : A) D.PB(i);
  for (auto &i : B) D.PB(i);
  sort(D.begin(), D.end(), [](int64_t a, int64_t b) { return abs(a) > abs(b); });
  vector<int64_t> D1, D2;
  for (int i = 0; i < k; ++i) {
    if (D[i] > 0)
      D1.PB(D[i]);
    else
      D2.PB(D[i]);
  }
  if (SZ(D2) % 2 == 0) {
    int64_t res = 1;
    for (int i = 0; i < k; ++i) res = res * D[i] % MOD;
    cout << (res % MOD + MOD) % MOD;
    return 0;
  }
  if (SZ(D1) == 0) {
    for(int i=k;i<SZ(D);++i){
      if(D[i]>0){
        D1.PB(D[i]);D2.pop_back();break;
      }
    }
  }else{
    int idx1=-1,idx2=-1;
    for(int i=k;i<SZ(D);++i){
      if(D[i]>0){
        idx1=i;break;
      }
    }
    for(int i=k;i<SZ(D);++i)if(D[i]<0){idx2=i;break;}
    if(idx1==-1||D[idx1]*D1.back()<D[idx2]*D2.back()){
      D2.PB(D[idx2]);
      D1.pop_back();
    }else{
      D1.PB(D[idx1]);
      D2.pop_back();
    }
  }
  int64_t res=1;
  for(auto i:D1)res=res*i%MOD;
  for(auto i:D2)res=res*i%MOD;
  cout<<(res%MOD+MOD)%MOD<<'\n';
  return 0;
}
//2020.07.05 20:28:44


Measured memory_bytes: 9460
/*
No matter how long a night, dawn will always break.

Simular saying ... The darkest hour is just before the dawn.
 ***************************************   ************************8   **********************************
*/
#include <bits/stdc++.h>
using namespace std;

 
#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define sz(x)	    (int)(x).size()
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define hell        998244353
#define output(x) cout << (x ? "YES" : "NO")<<endl;
 
 
 
 
 
int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }  
bool mod(double a,double b) {return a/b - floor(a/b);}
 

 
 
 
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int i,j,x,k,a,b;
   cin>>k;
   cin>>a>>b;
   x=(b/k)*k;
   if(x>=a){
   	cout<<"OK";
   }
   else{
   	cout<<"NG";
   }
   
   
   
   
   
    return 0;
}

Measured memory_bytes: 3648
s = input()
q = int(input())
for i in range(q):
    tmp = input()
    if tmp[:3] == 'pri':
        o, a, b = tmp.split()
        a = int(a)
        b = int(b)
        print(s[a:b+1])
    elif tmp[:3] == 'rev':
        o, a, b = tmp.split()
        a = int(a)
        b = int(b)
        sl = list(s)
        sl[a:b+1] = reversed(sl[a:b+1])
        s = ''.join(sl)
    else :
        o, a, b, p = tmp.split()
        a = int(a)
        b = int(b)
        sl = list(s)
        sl[a:b+1] = p
        s = ''.join(sl)


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

int N;

int main(void){
    
    cin >> N;
    
    if(N < 105) cout << 0 << endl;
    else if(N < 135) cout << 1 << endl;
    else if(N < 165) cout << 2 << endl;
    else if(N < 189) cout << 3 << endl;
    else if(N < 195) cout << 4 << endl;
    else cout << 5 << endl;
      
    return 0;
}


Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 171 D - Replacing
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/21
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <algorithm>
#include <numeric>
using namespace std;

int n;
int a[100000];
int q;
int b[100000];
int c[100000];

int bin[100001];
long long sum;

void solve() {
    long long e;
    for (int i=0;i<q;i++) {
        e = c[i] * bin[b[i]] - b[i] * bin[b[i]];
        sum += e;
        bin[c[i]] += bin[b[i]];
        bin[b[i]] = 0;
        printf("%lld\n",sum);
    }
}

int main() {

    sum = 0;
    scanf("%d", &n);
    for (int i=0;i<n;i++) {
        scanf("%d", &a[i]);
        bin[a[i]]++;
        sum += a[i];
    }
    scanf("%d", &q);
    for (int i=0;i<q;i++) {
        scanf("%d", &b[i]);
        scanf("%d", &c[i]);
    }

    solve();
}

Measured memory_bytes: 4748
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Edge
    {
        internal int from, to, cost;

        public Edge(int from, int to, int cost)
        {
            this.from = from;
            this.to = to;
            this.cost = cost;
        }
    }

    class Union_Find
    {
        internal int[] parents, rank;

        public Union_Find(int n)
        {
            parents = Enumerable.Range(0, n).ToArray();
            rank = new int[n];
        }

        public int Find(int x)
        {
            if (parents[x] == x) return x;
            else return parents[x] = Find(parents[x]);
        }

        public void Unite(int x, int y)
        {
            x = Find(x);
            y = Find(y);

            if (x == y) return;

            if (rank[x] < rank[y])
            {
                parents[x] = y;
            }
            else
            {
                parents[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }

        public bool Same(int x, int y)
        {
            return Find(x) == Find(y);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int V = int.Parse(Console.ReadLine());

                if (V == 0) break;

                int E = int.Parse(Console.ReadLine());

                Edge[] edges = new Edge[E];

                for (int i = 0; i < E; i++)
                {
                    string[] input = Console.ReadLine().Split(',');
                    int s = int.Parse(input[0]);
                    int t = int.Parse(input[1]);
                    int w = int.Parse(input[2]) / 100 - 1;

                    edges[i] = new Edge(s, t, w);
                }
                sb.AppendLine(Kruskal(edges, V).ToString());
            }
            Console.Write(sb);
        }

        static int Kruskal(Edge[] edges, int V)
        {
            Array.Sort(edges, (a, b) => a.cost - b.cost);

            Union_Find UF = new Union_Find(V);

            int totalCost = 0;

            for (int i = 0; i < edges.Length; i++)
            {
                Edge e = edges[i];

                if (!UF.Same(e.from, e.to))
                {
                    UF.Unite(e.from, e.to);
                    totalCost += e.cost;
                }
            }
            return totalCost;
        }
    }
}

Measured memory_bytes: 9872
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	int A, B, C, D;
	cin >> A >> B >> C >> D;

	int Aok = ceil((double)C / (double)B);
	int Tak = ceil((double)A / (double)D);
	if (Aok <= Tak) {
		printf("Yes");
	}
	else {
		printf("No");
	}


EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for(ll i=a;i <= b;i++)
#define rep(i,n) for(ll i=0;i < n;i++)
#define sz(x) x.size()
#define accuracy ll precision = numeric_limits<double>::digits10
#define fast_io ios_base::sync_with_stdio(false)

ll n,m;

int main() {
	fast_io;
	accuracy;
	cin >> n >> m;
	ll ans = 100ll*(n + 18ll*m);
	ans *= pow(2,m);
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const char *dat = "RDLU";

int w[6][6][4];

int main() {
    rep (i, 9) {
        char t;
        if (i % 2 == 0) {
            rep (j, 4) {
                scanf(" %c", &t);
                if (t == '1') w[i/2][j][0] = w[i/2][j+1][2] = 1;
            }
        }
        else {
            rep (j, 5) {
                scanf(" %c", &t);
                if (t == '1') w[i/2][j][1] = w[i/2+1][j][3] = 1;
            }
        }
    }
    int x = 0, y = 0, d = 0;
    do {
        rep (i, 4) {
            const int nd = (d+i) % 4;
            if (w[y][x][nd]) {
                putchar(dat[nd]);
                x += dx[nd];
                y += dy[nd];
                d = (nd + 3) % 4;
                break;
            }
        }
    } while (x != 0 || y != 0);
    putchar('\n');
    return 0;
}

Measured memory_bytes: 0
// ABC 152-B
// 2020.1.19 bal4u

#include <stdio.h>
#include <string.h>

char A[20], B[20];

int main()
{
	int i, a, b;
	
	scanf("%d%d", &a, &b);
	for (i = 0; i < b; ++i) A[i] = '0'+a;
	for (i = 0; i < a; ++i) B[i] = '0'+b;
	puts((strcmp(A, B) <= 0)? A: B);
	return 0;
}


Measured memory_bytes: 128
/*=============================================================================================================================/*
                                               Bismillahir Rahmanir Rahim

      _     ____  ___  ____   _   _  _         ___  ____   _         _     __  __
     / \   / ___||_ _|| __ ) | | | || |       |_ _|/ ___| | |       / \   |  \/  |
    / _ \  \___ \ | | |  _ \ | | | || |        | | \___ \ | |      / _ \  | |\/| |
   / ___ \  ___) || | | |_) || |_| || |___     | |  ___) || |___  / ___ \ | |  | |
  /_/   \_\|____/|___||____/  \___/ |_____|   |___||____/ |_____|/_/   \_\|_|  |_|

   _   __           __  __  __
  |_) (_  _  o__   /   (_  |_
  |_)o__)(_  || |  \__ __) |__

    ___                    _   _      _                _ _               __   ___                 _         _        _
   / __|_ _ ___ ___ _ _   | | | |_ _ (_)_ _____ _ _ __(_) |_ _  _   ___ / _| | _ ) __ _ _ _  __ _| |__ _ __| |___ __| |_
  | (_ | '_/ -_) -_) ' \  | |_| | ' \| \ V / -_) '_(_-< |  _| || | / _ \  _| | _ \/ _` | ' \/ _` | / _` / _` / -_|_-< ' \
   \___|_| \___\___|_||_|  \___/|_||_|_|\_/\___|_| /__/_|\__|\_, | \___/_|   |___/\__,_|_||_\__, |_\__,_\__,_\___/__/_||_|
                                                            |__/                           |___/


   FB: https://facebook.com/SIAsibul
   Gmail: asibulislam8@gmail.com

/*=============================================================================================================================*/

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(int i=0;i<(n);i++)
#define f1(i,n) for(int i=1;i<=(n);i++)
#define f2(i,a,n) for(int i=(a);i<=(n);i++)
#define fr(i,n,a) for(int i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define nl "\n"


const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;

int main(){
    int n; cin >> n;
    if(n%1000)cout << 1000-n%1000 << nl;
    else cout << 0 << nl;

	return 0;
}


Measured memory_bytes: 3624
a = list(map(int,input()))

b = len(a)
c = a[0]*100+a[1]*10+a[2]


aa = a[0]*100
aaa = a[1]*10
aaaa = a[2]
for i in range(3,b):
	aa = aaa*10
	aaa = aaaa*10
	aaaa = a[i]
	if abs(c - 753) >= abs(753 -(aa + aaa + aaaa)):
		c = aa + aaa + aaaa
print(abs(c-753))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000009
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)

bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}


ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

int main(){
    ll n;
    cin>>n;
    ll answer=0;
    answer=n%1000;
    if(answer!=0)answer=1000-answer;
    cout<<answer<<endl;

}


Measured memory_bytes: 81208
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;


int main(){
    ll N,M,cn=0;cin>>N>>M;
    priority_queue<ll> pq;
    rep(i,0,N){
        int a;cin>>a;
        pq.push(a);
    }
    rep(i,0,M){
        int a=pq.top();
        pq.pop();
        pq.push(a/2);
    }
    rep(i,0,N){
        cn+=pq.top();
        pq.pop();
    }
    cout<<cn<<endl;
}






Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
#include<string>
#include<unordered_map>
#include<map>
using namespace std;

int dis[10] = { 63,6,91,79,102,109,125,39,127,111 };
int main()
{
	int a;
	while (cin >> a, a != -1) {
		int now = 0;
		for (int b = 0; b < a; b++) {
			int c;
			cin >> c;
			int d = now^dis[c];
			for (int k = 64; k != 0; k >>= 1) {
				if (d&k)cout << 1;
				else cout << 0;
			}
			cout << endl;
			now = dis[c];
		}
	}
}

Measured memory_bytes: 3044
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int n,m,k; cin >>n >>m >>k;
  vector<li> a(n),b(m);
  rep(i,n) cin >>a[i];
  rep(i,m) cin >>b[i];
  vector<li> sa(n+1,0),sb(m+1,0);
  rep(i,n) sa[i+1]=sa[i]+a[i];
  rep(i,m) sb[i+1]=sb[i]+b[i];
  int ans=0;
  rep(i,n+1){
    if(sa[i]>k) break;
    auto itr=upper_bound(sb.begin(),sb.end(),k-sa[i]);
    chmax(ans,itr-sb.begin()+i-1);
  }
  print(ans);
}


Measured memory_bytes: 9524
#include<stdio.h>
int main(void)
{
  int a[10000],n;
  int flg=0;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0){
        flg=1;
        break;
      }
    }
  }
  if(flg==1){
    printf("DENIED\n");
  }
  else{
    printf("APPROVED\n");
  }
  return 0;
}
  

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s; cin>>s;
    int n=s.size();
    reverse(al(s));
    vector<int> dp_d(n,0),dp_x(n,0);
    rep(i,n){
        if(i==0){
            if(s[i]=='0') dp_d[i]=inf;
            else{
                dp_d[i]=10-(s[i]-'0');
                if(i==n-1) dp_d[i]++;
            }
            dp_x[i]=s[i]-'0';
            continue;
        }
        int d=inf,x=inf;
        d=min(d,dp_d[i-1]+9-(s[i]-'0'));
        if(s[i]!='0') d=min(d,dp_x[i-1]+10-(s[i]-'0'));
        if(s[i]!='9') x=min(x,dp_d[i-1]+s[i]-'0'+1);
        x=min(x,dp_x[i-1]+s[i]-'0');
        dp_d[i]=d; dp_x[i]=x;
        if(i==n-1) dp_d[i]++;
    }
    cout<<min(dp_d[n-1],dp_x[n-1])<<endl;
}

Measured memory_bytes: 12136
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;


ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}

// unsigned long long power(unsigned long long x, 
//                          int y, int p) 
// { 
//     unsigned long long res = 1; // Initialize result 
  
//     x = x % p; // Update x if it is more than or 
//     // equal to p 
  
//     while (y > 0) { 
//         // If y is odd, multiply x with result 
//         if (y & 1) 
//             res = (res * x) % p; 
  
//         // y must be even now 
//         y = y >> 1; // y = y/2 
//         x = (x * x) % p; 
//     } 
//     return res; 
// } 
  
// // Returns n^(-1) mod p 
// unsigned long long modInverse(unsigned long long n, int p) 
// { 
//     return power(n, p - 2, p); 
// } 
  
// // Returns nCr % p using Fermat's little 
// // theorem. 
// unsigned long long nCrModPFermat(unsigned long long n, 
//                                  int r, int p) 
// { 
//     // Base case 
//     if (r == 0) 
//         return 1; 
  
//     // Fill factorial array so that we 
//     // can find all factorial of r, n 
//     // and n-r 
//     unsigned long long fac[n + 1]; 
//     fac[0] = 1; 
//     for (int i = 1; i <= n; i++) 
//         fac[i] = (fac[i - 1] * i) % p; 
  
//     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
#define mod 1000000007
ll fun(ll n,ll k){
  ll res;
  res=((n-k+1)%mod)*(k%mod);
   res=(res+1)%mod;
  return res;
}
 int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  ll n,k;
  ll ans=0;
  cin>>n>>k;
  for(int i=k;i<=n+1;i++){
  	ans=(ans+fun(n,i))%mod;
  }
  cout<<ans;
}



  


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;

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

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("cowland.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int w, h, k;
    cin >> w >> h >> k;
    vector<string> vec(w);
    for (string& s: vec)
        cin >> s;
    int ans = 0;
    for (int m1 = 0; m1 < (1 << w); m1++) {
        for (int m2 = 0; m2 < (1 << h); m2++) {
            int decl = 0;
            for (int i = 0; i < w; i++) {
                if ((m1 >> i) & 1)
                    continue;
                for (int j = 0; j < h; j++) {
                    if ((m2 >> j) & 1)
                        continue;
                    decl += int(vec[i][j] == '#');
                }
            }
            ans += int(decl == k);
        }
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 3664
import sys,string
A="abcdefghijklmnopqrstuvwxyza"
tbl=string.maketrans(A[:-1],A[1:])
for s in sys.stdin:
    while not("the" in s or "that" in s or "this" in s):
        s=s.translate(tbl)
    print s[:-1]

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

int main(){
	char s, ans;
	cin >> s;
	if(s == 'A') ans = 'T';
	if(s == 'T') ans = 'A';
	if(s == 'C') ans = 'G';
	if(s == 'G') ans = 'C';
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<vector<pii>> drop = {
  {{-1, 0}, {0, -1}, {0, 0}, {0, 1}, {1, 0}},
  {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 0}, {0, 1}, {1, -1}, {1, 0}, {1, 1}},
  {{-2, 0}, {-1, -1}, {-1, 0}, {-1, 1}, {0, -2}, {0, -1}, {0, 0}, {0, 1}, {0, 2}, {1, -1}, {1, 0}, {1, 1}, {2, 0}}
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int x, y, s;
  char c;
  int a[10][10] = {};
  while (cin >> x >> c >> y >> c >> s) {
    s--;
    for (auto i : drop[s]) {
      int ny = y + i.first, nx = x + i.second;
      if (ny >= 0 && ny < 10 && nx >= 0 && nx < 10) a[ny][nx]++;
    }
  }
  int sum = 0;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) sum += a[i][j] == 0;
  }
  cout << sum << endl;
  cout << *max_element((int*)a, (int*)(a + 10)) << endl;

  return 0;
}


Measured memory_bytes: 3176
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
ans = 0
for i in range(n):
    if (i+1) % 2:
        if a[i] % 2:
            ans += 1
print(ans)

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

#define INFTY (1 << 30)

//???????????????
enum Color {
	WHITE,
	GRAY,
	BLACK,
};


//SSSP
void Dijkstra(int verValWeight[][100], int verNum) {

	//???????¨????
	int distance[100];
	Color color[100];
	int parent[100];
	for (int i = 0; i < verNum; i++) {
		color[i] = WHITE;
		distance[i] = INFTY;
		parent[i] = -1;
	}
	distance[0] = 0;

	//SSSP??????
	while (true) {

		//??°??¬????????????????????????????°?????????????????????¶
		int min_cost = INFTY;
		int subScript;
		for (int i = 0; i < verNum; i++) {
			if (color[i] != BLACK && distance[i] < min_cost) {
				min_cost = distance[i];
				subScript = i;
			}
		}

		//??????
		if (min_cost == INFTY)
			break;

		//?????????????????????
		color[subScript] = BLACK;

		//??£??\?????°??¬??????
		for (int i = 0; i < verNum; i++) {
			if (color[i] != BLACK && verValWeight[subScript][i] != INFTY) {
				if (distance[subScript] + verValWeight[subScript][i] < distance[i]) {
					distance[i] = distance[subScript] + verValWeight[subScript][i];
					parent[i] = subScript;
					color[i] = GRAY;
				}
			}
		}
	}

	//??????
	int weight_sum = 0;
	for (int i = 0; i < verNum; i++) {
		cout << i << " " << distance[i] << endl;
	}
}


int main() {

	int verNum;
	int verValWeight[100][100];
	int parent[100];

	//???????¨????
	cin >> verNum;
	for (int i = 0; i < verNum; i++)
		for (int j = 0; j < verNum; j++)
			verValWeight[i][j] = INFTY;

	//??\?????????
	for (int i = 0; i < verNum; i++) {
		int verVal, outNum;
		cin >> verVal >> outNum;
		for (int j = 0; j < outNum; j++) {
			int outVerVal, weight;
			cin >> outVerVal >> weight;
			verValWeight[i][outVerVal] = weight;
		}
	}

	//SSSP
	Dijkstra(verValWeight, verNum);

	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define reps2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

#define NMAX 2002

int M[NMAX][NMAX];
int B[NMAX];

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    reps(i, n - 1){
        B[i] = 0;
    }
    reps(i, n){
        reps(j, n){
            if(i > j){
                B[min(abs(i - j), abs(i - y) + abs(j - x) + 1)]++;
            }
        }
    }
    reps(i, n - 1){
        printf("%d\n", B[i]);
    }
    return 0;
}

Measured memory_bytes: 256