akhauriyash/Code-Regression huggingface dataset:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

def comb(n,r,mod): #nが大きく、rが小さい時に活用
    ans = 1
    for i in range(r):
        ans *= n-i
        ans %= mod
    d = math.factorial(r)
    d %= mod
    d = pow(d,mod-2,mod)
    ans *= d
    ans %= mod
    return ans

N,A,B = MI()
ans = pow(2,N,MOD)-1
ans -= comb(N,A,MOD)
ans -= comb(N,B,MOD)
print(ans%MOD)


Measured memory_bytes: 7396
#include <iostream>
#define rep(i,a) for(i = 0; i < a; i++)
using namespace std;

int main(void) {

  int i,j,n,q,T,C;
  cin >> n;

  int S[n];
  rep(i,n){
    cin >> S[i];
  }

  cin >> q;
  C = 0;
  rep(i,q) {
    cin >> T;
    rep(j,n) {
      if(T == S[j]) {
	C++;
	break;
      }
    }
  }
  cout << C << endl;
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve(){
    ll n, k;
    cin >> n >> k;
    double p = 0.0;
    rep(i, n)
    {
        rep(j, 32)
        {
            ll c = (i+1)*(1ll<<j);
            if(c >= k)
            {
                p += (1.0/ (1ll<<j)); break;
            }
        }
    }
    cout << p /n;
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  /*
  和のbit AND
  普通に全探索すれば
  部分列の選び方O(N^2)
  
  部分列からbitを計算するので
  N^2 C K
  だからやばい
  
  
  まず和を計算したのち, ソート??
  bitで見れば早い
  
  */
  long N,K;cin>>N>>K;
  vector<long>A(N),S(N+1,0);
  for(long i=0;i<N;i++){
    cin>>A[i];S[i+1]=S[i]+A[i];
  }
  list<long>SS;
  for(long i=0;i<N;i++)for(long j=i;j<N;j++){
    SS.push_back(S[j+1]-S[i]);
  }

  long ans=0;
  for(long b=LONG_MAX-(LONG_MAX/2);b>0;b/=2){
    long c=0;
    for(auto itr=SS.begin();itr!=SS.end();itr++){
      if(b&(*itr))c++;
    }
    if(c>=K){
      for(auto itr=SS.begin();itr!=SS.end();itr++){
        if(!(b&(*itr))){
          itr=SS.erase(itr);itr--;
        }
      }ans|=b;
    }
  }
  cout<<ans;
    
}

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

#ifdef DEBUG
#define debug(...) __VA_ARGS__
#else
#define endl '\n'
#define debug(...)
#endif
#define debugf(...) debug(printf(__VA_ARGS__))

using ll = long long;
const ll mod = 1e9 + 7;
const int N = 5e5 + 5;

ll fexp(ll x, ll e) {
    ll ans = 1;
    for (; e > 0; e>>=1) {
        if (e & 1)
            ans = ans * x % mod;
        x = x * x % mod;
    }
    return ans;
}

ll fac[N], inv[N];

ll C(ll n, ll m) {
    return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

ll P(ll n, ll m) {
    return fac[n] * inv[n - m] % mod;
}

ll f(ll k, ll m, ll n) {
    return P(m, k) * P(m - k, n - k) % mod * P(m - k, n - k) % mod;
}

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

    fac[0] = 1;
    for (int i = 1; i < N; i++)
        fac[i] = fac[i-1] * i % mod;
    inv[N-1] = fexp(fac[N-1], mod-2);
    for (int i = N-2; i >= 0; i--) {
        inv[i] = inv[i+1] * (i+1) % mod;
    }

    int n, m;
    cin >> n >> m;

    if (n > m) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    ll include = 1;
    for (int k = 0; k <= n; k++) {
        ans += include * C(n, k) * f(k, m, n) % mod;
        ans = (ans + mod) % mod;
        include = -include;
    }

    cout << ans << endl;

	return 0;
%>

Measured memory_bytes: 11444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

 map<ll,ll>s,e;
int main() {
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		ll l,r;
		cin>>l>>r;
		if(l==1){
			s[r]++;
		}
		else if(r==n){
			e[l]++;
		}
	}
    for(auto itr = s.begin(); itr != s.end(); ++itr) {
        ll search= itr->first;
        if(e[search]!=0){
        	cout << "POSSIBLE";
        	return 0;
        }
    }
    cout << "IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 18944
N = int(input())
a = list(map(int, input().split(' ')))
#print(N)
#print(a)

min_a = min(a)
max_a = max(a)

min_cost = 10000 * 100
for num in range(min_a, max_a + 1):
    cost = 0
    for z in a:
        cost += (z - num) ** 2
    if min_cost > cost:
        min_cost = cost

print(min_cost)

Measured memory_bytes: 3060
import datetime

#intの場合
H1,M1,H2,M2,K = map(int,input().split())

wakeup = datetime.datetime(2020,5,30,H1,M1,0)
sleep = datetime.datetime(2020,5,30,H2,M2,0)

active = sleep - wakeup
delta = int((active.seconds)/60)

ans = delta - K
print(ans)

Measured memory_bytes: 9436
n=int(input())
a=[int(i) for i in input().split()]
li=[0]
li+=a
li+=[0]


dif1=[]
dif2=[]

for i in range(n+1):
    dif1+=[abs(li[i+1]-li[i])]
for i in range(n):
    dif2+=[abs(li[i+2]-li[i])]

total=sum(dif1)

for i in range(n):
    print(total-dif1[i]-dif1[i+1]+dif2[i])



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

int main(){
    int N,W,H;
    cin>>N>>W>>H;
    vector<int> wwi(W+1,0);
    vector<int> hwi(H+1,0);
    for(int i=0;i<N;i++){
        int x,y,w;
        cin>>x>>y>>w;
        wwi[max(x-w,0)]++;
        wwi[min(x+w,W)]--;
        hwi[max(y-w,0)]++;
        hwi[min(y+w,H)]--;
    }
    bool resw=true;
    int sum=0;
    for(int i=0;i<W;i++){
        sum+=wwi[i];
        if(sum<=0) resw=false;
    }
    bool resh=true;
    sum=0;
    for(int i=0;i<H;i++){
        sum+=hwi[i];
        if(sum<=0) resh=false;
    }
    cout<<(resw||resh ? "Yes" : "No")<<endl;
    return 0;
}

Measured memory_bytes: 3636
N = int(input())
A = [int(x) for x in input().split()]
m = max(A)+2
cnt = [0] * m
for a in A:
    cnt[a] += 1
    if cnt[a] == 1:
        for i in range(a+a, m, a):
            cnt[i] += 1
ans = 0
for a in A:
    ans += (cnt[a] == 1)
print(ans)


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const ll MOD = 1000000007;
const int MN = 1000010;

inline void add(ll &x, ll y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

int main() {
	int n; cin >> n;
	vector<ll> dp(n + 1), pref(n + 1);
	ll two = (ll)(n - 1) * (n - 1) % MOD;
	dp[1] = pref[1] = n;
	dp[2] = (ll)n * n % MOD; pref[2] = (pref[1] + dp[2]) % MOD;

	for (int i = 3; i <= n; ++i) {
		dp[i] = dp[i-1]; //a1=1
		add(dp[i], two); //a1!=1,a2!=1
		add(dp[i], n - i + 2); //a1!=1,a2=an=1
		add(dp[i], pref[i - 3]);
		pref[i] = pref[i-1];
		add(pref[i], dp[i]);
	}

	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 15872
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
    int x,y,r,W,H;
    
    cin >> W >> H >> x >> y >> r ;
    
    //水平
    if (((x-r)>=0 and (x+r)<=W) and ((y-r)>=0 and (y+r)<=H)){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
      return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  char op;
  cin >> A >> op >> B;
  if (op == '+') {
    cout << to_string(A + B) << endl;
  }
  else if(op == '-') {
    cout << to_string(A - B) << endl;
  }
  else {
    cout << "error" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
vector<pii>adj[305];
int mark[305],n,m,d[305],fl[305],L,ans[305][305];

void dijkstra(int v){

    fill(d,d + 305, inf);
    fill(fl,fl + 305, 0);
    d[v] = 0;
    fl[v] = L;
    priority_queue<pair<pii,int>,vector<pair<pii,int> >, greater<pair<pii,int> > > pq;
    pq.push({{0,-L}, v});
    while(!pq.empty()){
        int u = pq.top().se,cnt = pq.top().f.f,val = -1*pq.top().f.se;
        pq.pop();
      	if(cnt > d[u] || cnt == d[u] && val < fl[u])continue;
        for(auto &p : adj[u]) 
            if(fl[u] >= p.se){
                if(d[p.f] > d[u] || d[p.f] == d[u] && fl[p.f] < fl[u]-p.se){
                    d[p.f] = d[u];
                    fl[p.f] = fl[u]-p.se;
                    pq.push({{d[p.f],-fl[p.f]},p.f});
                } 
            }
            else {
                if(d[p.f] > d[u]+1 || d[p.f] == d[u]+1 && fl[p.f] < L-p.se){
                    d[p.f] = d[u]+1;
                    fl[p.f] = L-p.se;
                    pq.push({{d[p.f],-fl[p.f]},p.f});
                }   
            }
    }
}

signed main()
{
    showoff;
    cin >> n >> m >> L;
    FOR(i,1,m+1){
        int u,v,w;
        cin >> u >> v >> w;
      	if(w > L)continue;
        adj[u].pb({v,w});
        adj[v].pb({u,w});
    }
    FOR(i,1,n+1){
        dijkstra(i);
        FOR(j,1,n+1)ans[i][j] = d[j];
    }
    int q;
    cin >> q;
    while(q--){
        int x,y;
        cin >> x >> y;
        if(ans[x][y] != inf)cout << ans[x][y] << "\n";
        else cout << "-1\n";
    }
    return 0;

}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ....s


Measured memory_bytes: 4996
#include <stdio.h>
int main()
{
    int n = 0, k = 0, i=0;
    int p[1001];
    int temp = 0;
    int sum = 0;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &p[i]);
    }
    for (int i = 0; i < n-1; i++)
    {
        for (int j = 0; j <n-1; j++)
        {

            if (p[j] > p[j + 1])
            {
                temp = p[j];
                p[j] = p[j + 1];
                p[j + 1] = temp;
            }
        }
    }
    while (k--)
    {
        sum += p[i++];
    }
    
    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 1712
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H,P,L;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll a[1000000];
ll b[1000000];
ll c[1000000];
ll t[1000000];
ll p[1000000];
ll n[1000000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
int main() {
	rep(i,0,4){
		cin>>n[i];
	}
	sort(n,n+4);
	if(n[0]==1&&n[1]==4&&n[2]==7&&n[3]==9){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i =0; i < n ;i++)
using namespace std;
int c[3][3];


bool fb(int i, int j){
    if((c[0][i] - c[0][j] == c[1][i] - c[1][j])&
        (c[1][i] - c[1][j] == c[2][i] - c[2][j])&
        (c[2][i] - c[2][j] == c[0][i] - c[0][j]))
        {
             return true;
        }
    else{
        return false;
    }
    
}
bool fa(int i, int j){
    if((c[i][0] - c[j][0] == c[i][1] - c[j][1])&
        (c[i][1] - c[j][1] == c[i][2] - c[j][2])&
        (c[i][2] - c[j][2] == c[i][0] - c[j][0]))
        {
             return true;
        }
    else{
        return false;
    }
    
}

int main()
{
    rep(i, 3){
        cin >> c[i][0] >> c[i][1] >> c[i][2];
    }

    if(fb(0, 1) &fb(1, 2)& fb(2, 0)& fa(0, 1)& fa(1, 2)& fa(2, 0)){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
        }
    

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}
#define NUM_MAX 100000
#define BUF_SIZE (NUM_MAX+50)
#define STR_END ('z'+1)

struct pair {
    int left;
    int right;
};
int main(void) {
    static char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    int len = strlen(str);
    str[len] = STR_END;

    int left;
    int right = 0;
    static int map[30];
    struct pair ans = {-1, -1};
    for(left = 0; left < len+1;) {
        char prev = STR_END;
        for(; right < len+1; right++) {
            if(map[prev-'a'] == 2) { break; }
            prev = str[right];
            map[prev - 'a']++;
        }

#ifdef DEBUG
        printf("%d %d\n", left, right);
#endif
        if(right == len+1) break;
        // left forward
        while(left < len+1) {
            int ch = str[left];
            map[ch-'a']--;
            left++;
            if(ch == prev) {
                if(right - left <= 2) {
                    ans = (struct pair){left-1+1, right-1+1};
                    goto finish;
                }
                break;
            }
        }
    }
finish:
    printf("%d %d\n", ans.left, ans.right);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	string S;
	cin >> S;
	int N = S.length()+1;
	vector<int> A(N, 0);
	for(int i = 0; i < N-1; i++) if(S[i] == '<') A[i+1] = max(A[i+1], A[i]+1);
	for(int i = N-1; i >= 0; i--) if(S[i] == '>') A[i] = max(A[i], A[i+1]+1);
	cat ans = 0;
	for(int i = 0; i < N; i++) ans += A[i];
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 2844
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
typedef long long ll;


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

    vector<int> vi;
    for(int i = 0; i < n; ++i){
        int p;
        cin >> p;
        vi.push_back(p);
    }

    int ans = 0;
    int ret = 0;
    for(int i = 1; i < n-1; ++i){
        if((vi[i-1] > vi[i] && vi[i+1] < vi[i]) || (vi[i+1] > vi[i] && vi[i-1] < vi[i])){
            ++ans;
        }
        else{
            ans=ans;
        }
    }

//    if(ret >= ans){
//        cout << ans << "\n";
//    }
//    else{
//        cout << n-ret-1 << "\n";
//    }

    cout << ans;

}



Measured memory_bytes: 256
import java.util.*;

 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int x = sc.nextInt();
    int a[] = new int[N];
    // Integer a[] = new Integer[N];
    for(int i=0; i<N ;i++){
        a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    int sum =0;

    for(int j=0; j<N; j++){
        if (x >= a[j]) {
        x = x - a[j];
        sum++;
        }
    }
    if(x > 0 && sum == N){
        sum--;
    }
        System.out.println(sum); 
    }    
}


Measured memory_bytes: 21460
import sys
import collections
import itertools
import math
from collections import Counter
from collections import deque
MOD = 10 ** 9 + 7

S = input()

keys = ["dream", "dreamer", "erase", "eraser"]

s = S
while len(s) > 0:
    deleted = False
    for k in keys:
        idx = s.rfind(k)
        if idx+len(k) == len(s):
            s = s[0:idx]
            deleted = True
            break
    if deleted == False:
        break

if deleted == False or len(s) != 0:
    print("NO")
else:
    print("YES")


sys.exit(0)


Measured memory_bytes: 3572
import Data.Array


--エッジ、現在位置、現在までのステップ数、出力
solver::(Array Int Int,Int)->Int->Int->Int
solver (tab,n) now step = if now == 2 then step
                                      else if step >= n then (-1)
                                                        else solver (tab,n) (tab!now) (step+1)
nget::Int -> IO [Int]
nget 0=return []
nget n= do
  c<-getLine
  rest<-nget (n-1)
  return ((read c):rest)

main::IO()
main=do
  nc<-getLine
  let n = read nc
  dat<-nget n
  let i_dat= listArray (1,n) dat
  print (solver (i_dat,n) 1 0)


Measured memory_bytes: 40316
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
using namespace std;

int main()
{
    // 整数の入力
    long long R,C,N,x1,x2,y1,y2,i;
    vector<vector<long long>> dots;
    deque<long long> stack;
    cin >> R >> C >> N;
    for (i =0;i < N ;i++){
        cin >> x1 >> y1 >>x2 >>y2;
        if ((x1 == 0 || x1 == R ||y1== 0 || y1==  C ) && (x2 == 0 || x2 == R || y2== 0 || y2==  C )){
            dots.push_back({x1,y1,i} );
            dots.push_back({x2,y2,i} );
        }
    }
        auto sortValue = [&R,&C](vector<long long> v) {
            if (v[0] == 0){
                return v[1];
            }else if(v[1] == C){
                return C + v[0];
            }else if (v[0] == R){
                return C + R + (C - v[1]);
            }else{
                return 2 * C + 2 * R - v[0];
            }
        };

    sort(dots.begin(),dots.end(),[&sortValue](vector<long long> v1,vector<long long> v2){
        return sortValue(v1) < sortValue(v2);
    });
    for (i = 0;i< dots.size();i++){
        stack.push_back(dots[i][2]);
        if (stack.size() >= 2 && stack[stack.size()-1] == stack[stack.size()-2]){
            stack.pop_back();
            stack.pop_back();
        }
    }
    if (stack.size() == 0){
        cout << "YES" <<endl;
    }else{
        cout << "NO" <<endl;
    }
    return 0;
}

Measured memory_bytes: 12716
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
const int MAX = 2001;
const int MOD = 1000000007;
 
 



 
signed main(){
    int a,b;
    cin>>a>>b;
    if((a+b)%2==0)cout<<(a+b)/2;
    else cout<<"IMPOSSIBLE";
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	short f=1;x=0;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
int main(){
	int n,ans=1;read(n);
	while(ans<=n)ans*=2;
	cout<<ans/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;


int main() {
    string S; cin >> S;
    ll K; cin >> K;
    
    if(S[0]=='1'){
        for(int i=0; i<K; i++){
            if(S[i]!='1'){
                cout << S[i] << endl;
                return 0;
            }
        }
        cout << S[0] << endl;
        
    }else{
        cout << S[0] << endl;
    }
    return 0;
}





Measured memory_bytes: 256
def main():
    s = input()
    t = input()
    min = int(1e9)
    for i in range(len(s)-len(t)+1):
        cnt = 0
        for j in range(len(t)):
            if s[i+j] != t[j]:
                cnt += 1
        if min > cnt:
            min = cnt
    print(min)
            
if __name__ == "__main__":
    main()

Measured memory_bytes: 9056
N = int(input())
s = 'a'
def dfs(s,mx):
    if len(s) == N:
        print(s)
        return
    for diff in range(ord(mx)-ord('a')+2):
        nc = chr(ord('a')+diff)
        # print(diff)
        # print(nc)
        nmx = max(nc,mx)
        dfs(s+nc,nmx)
dfs('a','a')

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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> A(N); 
  int count=0;
  for(int i=0;i<N;i++){   
  	cin>>A.at(i);
    count+=A.at(i);
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  bool ans=true ;
  for (int i=0;i<M;i++){
  	if(A.at(i)*(4*M)<count){
  	  ans=false;
      break;
  	}
  }
  	if(ans){
    	cout<<"Yes"<<endl;
  	}
  	else{
    	cout<<"No"<<endl;
  	}
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

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



class Graph{
    struct edge{
        int vertice;
        ll weight;
    };

    vector<vector<edge>> g;
    unsigned int n;

public:
    Graph(unsigned int n): n{n}{
        g.resize(n);
    }

    void add_edge(int u, int v){
        g[u].emplace_back(edge{v, 1});
    };

    void add_edge(int u, int v, ll w){
        g[u].emplace_back(edge{v, w});
    }

    vector<edge>& get_edge(int v){
        return g[v];
    }

    unsigned int size(){
        return n;
    }

    vector<edge>& operator[](int v){
        return get_edge(v);
    }
};


int main(){
    int n;  ll k;   cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }

    vector<bool> hist(n, false);
    int cur = 0;
    while(!hist[cur]){
        hist[cur] = true;
        cur = a[cur];
    }

    ll x = 0, loop = 0;
    int cur2 = 0;
    vector<int> vec1, vec2;
    while(cur2 != cur){
        vec1.push_back(cur2);
        x++;
        cur2 = a[cur2];
    }

    while(a[cur2] != cur){
        vec2.push_back(cur2);
        loop++;
        cur2 = a[cur2];
    }
    vec2.push_back(cur2);
    loop++;

    if(k < x){
        cout << vec1[k] + 1 << endl;
    }
    else{
        cout << vec2[(k - x) % loop] + 1 << endl;
    }



    return 0;
}


Measured memory_bytes: 5132
N, D = map(int, input().split())
X = {}
for i in range(N):
    X[i] = list(map(int, input().split()))

pow2 = set()
for i in range(40**2*10):
    pow2.add(i**2)

ans = 0
for i in range(N):
    for j in range(i+1, N):
        xi = X[i]
        xj = X[j]
        sum = 0
        for k in range(D):
            sum += (xi[k] - xj[k])**2
        if sum in pow2:
            ans += 1

print(ans)

Measured memory_bytes: 39408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) <= (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n,k;
    cin>>n>>k;
    long long int result = 0,b,c;
    
    FOR(a,1,k){
        b = k - a;
        c = k - b;
        while(b<=0){
            b += k;
        }
        while(c<=0){
            c += k;
        }
        if(a<=n&&b<=n&&c<=n){
            if((a+c)%k==0){
                result+=((n)/k+(n%k>=a))*((n)/k+(n%k>=b))*((n)/k+(n%k>=c));
                
                
            }
        }
    }
    cout<<result<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int k;
  cin >> k;
  int a,b;
  cin >> a >> b;
  if(a/k!=b/k)cout << "OK" << endl;
  else if(a%k==0)cout << "OK" << endl;
  else cout << "NG" << endl; 
}


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

typedef long long int ll;
ll n, m, a[107];

int main() {
    cin >> n >> m;

    ll sum = 0;
    for(ll i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }

    sort(a, a + n, greater<ll>());

    ll cnt = 0;
    for(ll i = 0; i < m; ++i) {
        if(a[i] * 4 * m >= sum) cnt++;
        else break;
    }

    if(cnt == m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;

	for( int i = 0; i < n; ++i ) {
		int a, b, c;
		cin >> a >> b >> c;

		a *= a;
		b *= b;
		c *= c;

		if( a+b == c || a+c == b || b+c == a ) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}



Measured memory_bytes: 3148
#include<iostream>
#include<algorithm>
using namespace std;
 
int main()
{
	int n, s=0, a[20], b;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++)cin >> b, s += max(a[i] - b, 0);
	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int a[30]={};
  int n=s.size();
  for(int i=0;i<n;i++)
    a[s[i]-'a']++;
  bool ans=true;
  for(int i=0;i<30;i++)
    if(a[i]%2==1)
      ans=false;
  if(ans)
    cout<<"Yes";
  else cout<<"No";
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
 
int main()
{
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> score(N + 1, K - Q);
	for (int i = 1; i <= Q; i++) {
		int Ai;
		cin >> Ai;
		score[Ai]++;
	}

	for (int i = 1; i < N + 1; i++) {
		if (score[i] > 0) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
		cout << endl;
	}
  
	return 0;
}



Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func parseToArray2d(lines []string) [][]int64 {
	var result [][]int64
	for _, line := range lines {
		var parsedLine []int64
		for _, element := range strings.Split(line, " ") {
			n, err := strconv.ParseInt(element, 10, 64)
			if err != nil {
				fmt.Printf("Error: element = %v\n", element)
			}
			parsedLine = append(parsedLine, n)
		}
		result = append(result, parsedLine)
	}
	return result
}

func max(l, r int64) int64 {
	if l > r {
		return l
	}
	return r
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	content := []string{}
	for scanner.Scan() {
		line := scanner.Text()
		content = append(content, line)
	}
	arr := parseToArray2d(content)
	input := arr[1]
	sort.Slice(input, func(i, j int) bool { return input[i] < input[j] })

	var costMin int64 = math.MaxInt64
	nMin := input[0]
	nMax := input[len(input)-1]
	for x := nMin; x <= nMax; x++ {
		costCurrent := max(x - nMin, nMax - x)
		if costCurrent < costMin {
			costMin = costCurrent
		}
	}

	fmt.Println(costMin)
}



Measured memory_bytes: 1188
#include <iostream>
#include <string>
#include <limits>
#include <vector>

using namespace std;

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;
}

int numofbits(uint32_t bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
	int n, m;
  	cin >> n >> m;

	vector<uint32_t> slist;
	for (int i=0; i<m; i++) {
		uint k;
		cin >> k;
		int s = 0;
		for (int j=0; j<k; j++) {
			uint32_t x;
			cin >> x;
			x--;
			s = s | (1 << x);
		}
		slist.push_back(s);
	}
	vector<int> plist;
	for (int i=0; i<m; i++) {
		int p;
		cin >> p;
		plist.push_back(p);
	}

	int max = 0x1 << n;
	int r = 0;
	for (int i=0; i<max; i++) {
		bool on = true;
        for (int j=0; j<slist.size(); j++) {
			auto n = numofbits(i&slist[j]);
            //printf("i:0x%x, s:0x%x, n:%d\n", i,slist[j],n);
            if (n%2 != plist[j]) {
                on = false;
				break;
			}
		}
        if (on) {
            //printf("\t ON \n");
            r ++;
        }
 	}
	cout << r << endl;
}


Measured memory_bytes: 256
/*
  -> ossan
  -> Do Good Die Great
*/
#include <bits/stdc++.h>
#define int long long int
#define pii pair<int, int>
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define MOD 1000000007
#define Hiraishin                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr);
#define tests \
    int t;    \
    cin >> t; \
    while (t--)
using namespace std;

// global

void solve()
{
    int n, k;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n);
    int s = 0;
    for (int i = 0; i < k; i++)
        s += arr[i];
    cout << s;
}

signed main()
{
    Hiraishin
    // tests
    solve();
    return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n){
    cin >> a[i];
  }
  int s = a[0];
  int cnt=0;
  srep(i,1,n){
    if(s == a[i]){
      cnt++;
      s = a[i];
      a[i] = -1;
    }
    s = a[i];
    
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
fun main() {
    val (n, _) = readInts()
    val sum = readInts().sum()
    println(if (sum > n) -1 else n - sum)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInts() = readStrings().map { it.toInt() }


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

namespace AtCoders {
	class Program {
		static void Main(string[] args) {

		var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}

			var K = inputArray[0];
			var N = inputArray[1];

			var housePositions = retreiveLongArray();

			//基本的に湖の周りを同じ方向に回るように訪問することが最短
			//最初の家の距離と最後の家の間は移動しなく体よい
			//よって最大の家の距離を求めて、それを湖の全周から引く

			var houseDistances = new List<long>();

			//最初の家の距離と最後の家の距離
			var dis = (K - housePositions.Last())+ housePositions.First();
			houseDistances.Add(dis);

			for (int i = 0; i < N-1; i++) {
				houseDistances.Add(housePositions[i + 1] - housePositions[i]);
			}
			var maxDistance = houseDistances.Max();

			//答えの出力
			var ans = K- maxDistance;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 40692
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Array

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [h,w,d] <- getIntList
    as <- array (1, (h*w)) . flip zip [(x, y)| x <- [1..h], y <- [1..w]] . concat <$> replicateM h getIntList
    q <- getInt
    lr <- replicateM q $ do
        [l, r] <- getIntList
        return (l, r)
    let all = array (1, (h*w)) [(p, f p) | p <- [1..h*w]]
            where f p | p+d > h*w = 0
                      | otherwise = all ! (p + d) + abs (x1 - x0) + abs (y1 - y0)
                    where (x0, y0) = as ! p
                          (x1, y1) = as ! (p + d)
    forM_ lr $ \(l, r) -> do
        print $ all ! l - all ! r

Measured memory_bytes: 50372
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

const int idx = 1e5 + 10, sum = 101, tight = 2;
int mod = 1e9 + 7;

int dp[idx][sum][tight];

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

   string s;
   int d;
   cin >> s >> d;
   int n = s.length();
   vector <int> a;
   for (auto &i : s)
      a.push_back(i - '0');

   dp[n][0][0] = 1;
   dp[n][0][1] = 1;

   for (int i = n - 1; i >= 0; i--) {
      for (int m = 0; m < 2; m++) {
         for (int k = 0; k < d; k++) {
            for (int j = 0; j < 10; j++) {
               int x = (j + k) % d;
               if (i == 0) {
                  if (j < a[i] && m == 0)
                     dp[i][x][m] += dp[i + 1][k][m];
                  if (j == a[i] && m == 1)
                     dp[i][x][m] += dp[i + 1][k][m];
                  dp[i][x][m] %= mod;
                  continue;
               }
               if (m == 0) {
                  dp[i][x][m] += dp[i + 1][k][m];
               } else {
                  if (j < a[i])
                     dp[i][x][m] += dp[i + 1][k][!m];
                  else if (j == a[i])
                     dp[i][x][m] += dp[i + 1][k][m];
               }
               dp[i][x][m] %= mod;
            }
         }
      }
   }

   cout << ((dp[0][0][1] + dp[0][0][0]) % mod + mod - 1) % mod << endl;



   return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[1000];
int main()
{
   int n;
   int sum;
   while(scanf("%d",&n)!=EOF)
   {
   for(int i=0;i<n;i++)
   {
   	scanf("%d",&a[i]);
   }
   sum=0;
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<n;j++)
    	{
    		if(i==j)
    		{
    			continue;
			}
			else
			sum+=a[i]*a[j];
		}
	}
	printf("%d\n",sum/2);
}
	return 0;
	
}


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

int gcd(int x,int y){
  if(y==0)return x;
  return gcd(y,x%y);
}
int main(){
  int a,b;
  while(cin>>a>>b){
    int g=gcd(a,b);
    cout<<g<<' '<<a/g*b<<endl;
  }
}



Measured memory_bytes: 3080
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
// #define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

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

	string s;
	cin>>s;
	vi dp(1<<26,inf);
	dp[0]=0;
	int t=0;
	rep(i,s.size()){
		t^=1<<(s[i]-'a');
		int m=inf;
		rep(j,26)cmin(m,dp[t^(1<<j)]+1);
		cmin(dp[t],m);
	}
	cout<<max(1,dp[t])<<endl;
}


Measured memory_bytes: 262804
#include <iostream>
using namespace std;
 
int main(){
    int a, b;
    while(cin >> a >> b && !(a == 0 && b == 0)){
        bool check;
        for(int i = 0; i < a; i++){
            if(i%2)
                check = true;
            else
                check = false;
            for(int j = 0; j < b; j++){
                if(check){
                    cout << '.';
                    check = false;
                }
                else{
                    cout << '#';
                    check = true;
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
	char b;
	cin >> b;
	if (b == 'A')cout << 'T';
	else if (b == 'T')cout << 'A';
	else if (b == 'C')cout << 'G';
	else cout << 'C';
}

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

int main() {
    int N; cin >> N;
    int a[N], b[N];
    for (int i=0; i<N; ++i) cin >> a[i];
    for (int i=0; i<N; ++i) cin >> b[i];

    vector<int> c(N, 0);
    int sum = 0;
    for (int i=0; i<N; ++i) {
        sum += a[i];
        c[i] = sum;
        for (int j=i; j<N; ++j) {
            c[i] += b[j];
        }
    }
    sort(c.begin(), c.end());
    reverse(c.begin(), c.end());
    cout << c[0] << endl;
}

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, K;
	cin >> N >> K;
	vector<int> bit;
	for (int i = 30; i >= 0; i--) {
		if (K & (1 << i)) {
			bit.push_back(i);
		}
	}
	int b = bit.size();
	bit.push_back(0);
	vector<vector<ll>> dp(b + 1, vector<ll>(2));
	for (int i = 0, A, B; i < N; i++) {
		cin >> A >> B;
		int tmp = 0;
		for (int j = 0; j <= b; j++) {
			if (((A | tmp) - tmp) < (1 << bit[j])) {
				dp[j][1] += B;
			}
			tmp += 1 << bit[j];
		}
	}
	ll res = 0;
	for (auto t : dp) {
		res = max(res, max(t[0], t[1]));
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

ll A, B, C, K;

int main() {
	S3(A, B, C);
	S(K);
	if (K <= A) PL(K);
	else if (K <= A + B) PL(A);
	else {
		ll c = K - (A + B);
		PL(A - c);
	}
}

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

# min{|j − i|, |X − i| + 1 + |j − Y |, |Y − i| + 1 + |j − X|}

ans = [0] *n
for i in range(1, n):
    for j in range(i+1, n+1):
        mi = min([abs(j-i), (abs(x-i) +1 +abs(j-y)), abs(y-i) +1 +abs(j-x)])
        ans[mi] +=1
for a in range(1, len(ans)):
    print(ans[a])



Measured memory_bytes: 3444