akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if(H==0 && W==0){break;}
        
        for(int h=0;h<H;h++){
            for(int w=0;w<W;w++){
                if((h+w)%2==0){cout << "#";}
                else{cout << ".";}
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

#define FOR(_i, s, e) for(_i = s; _i < e; ++_i)
#define FOR_INV(_i, s, e) for(_i = e - 1; _i >= s; --_i)

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


using pos = std::pair<LONG, LONG>;



int main(){
    LONG i, j, k;
    LONG A, B;

    cin >> A >> B;

    cout << A * B;

}


Measured memory_bytes: 3620
import numpy as np


N, M = map(int, input().split())

demands = [0]*M
for i in range(0, M):
    demands[i] = list(map(int, input().split()))

demands = np.array(demands)

arr = np.argsort(demands, axis=0) # 列でsort
lvl = arr[:,1] # 1列目を取得（終了時間が早い順のindexを取得）

start = 1
end = 1
cnt = 0
for i in lvl:    
    # 既に切られている範囲にいるならskip
    if demands[i][0] < end:
        continue
    
    # 今までで切れていない場合は新しく切る
    end = demands[i][1]
    cnt += 1
        
print(cnt)

Measured memory_bytes: 37876
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << (x) << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

void f(int a, int b, int s) {
	if (s) {
		int d = (a ^ b) & s;
		s ^= d &= -d;
		int c = a ^ (s & -s);
		f(a, c, s), f(c ^ d, b, s);
	} else print(a, ' ');
}

int main() {
	int n, a, b;
	rd(n, a, b);
	if (__builtin_parity(a ^ b)) prints("YES"), f(a, b, (1 << n) - 1);
	else prints("NO");
	return 0;
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define in insert
#define sz(x) ((in)(x).size())
using namespace std;
const int N = 1e5 + 123;


void read_file()
{
    freopen("text.in","r",stdin);
    freopen("text.out","w",stdout);
}
bool cnt(int n)
{
    int cnt = 0;
    while(n)
    {
        n/=10;
        cnt++;
    }
    return (cnt % 2 != 0);
}
void solve()
{
    int n;
    cin >> n;
    int ans = 0;
    //int col = cnt(n);
    for (int i = 1; i <= n; i++)
    {
        int ii = i;
        if (cnt(ii))
            ans++;
    }
    cout << ans << endl;
  /*  if (n > 9 && n < 100)
    {
        cout << 9 << endl;
    }else if (n > 100 && n < 10000)
    {
        cout << (n % 1000) - 90 << endl;
    }else
        cout << (n % 1000000) - 9091 << endl;*/
}

int main()
{
    solve();
    //cerr << printf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
    return (0);
}

//1 - 9
//100 - 199
//10000 - 99999


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	for (int i = 0; i < N.length(); i++) {
		if (N[i] == '7') {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

}






Measured memory_bytes: 3620
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;
int n,m,k;

using ll = long long;
const int mod = 1e9 + 7;
int fac[N], finv[N];

ll quick_pow(ll a, ll b) {
    ll res = 1;
    a %= mod;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init_fac_mod(int to){
    //only when mod is prime
    fac[0] = finv[0] = 1;
    for(int i = 1; i <= to; ++i)
        fac[i]=(ll)fac[i-1]*i%mod;
    finv[to] = quick_pow(fac[to], mod-2);
    for(int i = to-1; i; --i)
        finv[i] = (ll)finv[i+1]*(i+1)%mod;
}

int comb(int n, int m){
    //n!/(m!(n-m)!)
    init_fac_mod(n);
    return (ll)fac[n] * finv[m] % mod * finv[n - m]% mod;
}



int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m>>k;
    
    
    ll d = 0;
    for (int i = 1; i < n; i++){
        d += (ll)i*(n-i)%mod*m%mod*m%mod;
        d%= mod;
    }
    
    for (int i = 1; i < m; i++){
        d += (ll)i*(m-i)%mod*n%mod*n%mod;
        d %= mod;
    }
    
    cout<<d*comb(n*m-2, k-2)%mod<<endl;
    
    
    
    
    
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bitset>
#include <math.h>

typedef long long ll;
typedef unsigned long long ull;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    int X, K=1;
    std::cin >> X;

    for(int i = 1; i <= 360; ++i)
    {
        if((X*i) >= 360)
        {
            if((X*i) % 360 == 0)
                break;

            if((X*i) % 180 == 0)
            {
                K *= 2;
                break;
            }
        }
        K++;
    }

    print(K);
    return 0;
}

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

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,r;
  cin >> n >> r;
  if (n > 10)
    cout << r << "\n";
  else
    cout << r+100*(10-n) << "\n";
    return 0;
}

Measured memory_bytes: 3644
n=int(input())
h=list(map(int,input().split()))

INF=10**23
dp=[INF]*n

dp[0]=0
dp[1]=abs(h[0]-h[1])

for i in range(2,n):
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])

print(dp[-1])

Measured memory_bytes: 52336
program Half_and_Half
    implicit none
    integer(4):: a,b,c
    integer(4):: x,y
    
    read*, a,b,c,x,y

    print*, min(x,y) * min(a+b, 2*c) + abs(x-y)*min(extra(),2*c)

contains
    function extra() result(ret)
        integer(4):: ret

        if (x==y) then
            ret=0
        else if (x > y) then
            ret=a
        else
            ret=b
        end if
    end function
end program Half_and_Half

Measured memory_bytes: 640
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <math.h>
typedef long long ll;
const int MYINF = 1e9+7;

int main(int argc, char **argv)
{
        double x1, y1, x2, y2;

        scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
        printf("%f\n", sqrt((x2 - x1) * (x2 - x1)
                                + (y2 - y1) * (y2 - y1)));
        return 0;
}

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

def crt(rs,ms):
    def _inv_gcd(a,b):
        if a==0: return (b,0)
        s,t,m0,m1 = b,a,0,1
        while t:
            u = s // t
            s -= t * u
            m0 -= m1 * u
            tmp = s
            s = t
            t = tmp
            tmp = m0
            m0 = m1
            m1 = tmp
        if m0 < 0: m0 += b//s
        return (s, m0)
    assert len(rs) == len(ms)
    n = len(rs)
    r0,m0 = 0,1
    for i in range(n):
        assert 1 <= ms[i]
        r1,m1 = rs[i] % ms[i], ms[i]
        if m0 < m1:
            r0,r1,m0,m1 = r1,r0,m1,m0
        if m0 % m1 == 0:
            if r0 % m1 != r1: return (0,0)
            continue
        g,im = _inv_gcd(m0,m1)
        u1 = m1 // g
        if (r1-r0) % g: return (0,0)
        x = (r1-r0) // g % u1 * im % u1
        r0 += x * m0
        m0 *= u1
        if r0 < 0: r0 += m0
    return (r0,m0)

divs = set()
m = 1
NN = 2*N
while m*m <= NN:
    if NN%m == 0:
        divs.add(m)
        divs.add(NN//m)
    m += 1

ans = NN-1
for x in divs:
    y = NN//x
    if y==1: continue
    r,m = crt([0,-1], [x,y])
    if r==m==0: continue
    ans = min(ans, r)

print(ans)

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

int main() {
  bool flag=true;
  int h,w;
  cin >> h >> w;
  vector<vector<char>> c(h,vector<char>(w,0));
  vector<vector<int>> v(h+2,vector<int>(w+2,0));
  r(i,h){
    r(j,w){
      cin >> c[i][j];
      if(c[i][j]=='#'){
        v[i][j+1]++; v[i+1][j]++; v[i+2][j+1]++; v[i+1][j+2]++;
      }
    }
  }
  r(i,h){
    r(j,w){
      if(c[i][j]=='#'&&v[i+1][j+1]==0)flag=false;
    }
  }
  if(flag)cout<< "Yes"<<endl;
  else cout<< "No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int x, y;
    int temp;
    
    while(1) {
        scanf("%d %d", &x, &y);
        if (x==0 && y==0) break;
        if (x > y) {
            temp = x;
            x = y;
            y = temp;
        }
        printf("%d %d\n", x, y);
    }
    return 0;
}


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)

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

const int MAXN = 2e5 + 5;
const int INF = 1e9;
const int off = 1 << 18;

int n, q, cnt;
vector <int> l[MAXN];
int dp[MAXN], a[MAXN];

struct Tournament{
    vector <point> t[2 * off];
    bool bio[2 * off];

    void build(int x){
        bio[x] = true;
        vector <point> v;
        sort(t[x].begin(), t[x].end());

        v.pb(point(0, INF));
        for(auto it : t[x])
            if(it.second < v.back().second)
                v.pb(it);
        t[x] = v;
    }

    void add(int x, int left, int val){
        x += off;
        while(x){
            t[x].pb(point(left, val));
            x >>= 1;
        }
    }

    int get(int x, int left){
        if(!bio[x])
            build(x);

        auto pos = lower_bound(t[x].begin(), t[x].end(), point(left, -INF));
        return (*(--pos)).second;
    }

    int query(int x, int lo, int hi, int a, int b){
        if(lo >= a && hi <= b)
            return get(x, a);
        if(lo >= b || hi <= a)
            return INF;

        int mid = (lo + hi) >> 1;
        int X = query(x * 2, lo, mid, a, b);
        int Y = query(x * 2 + 1, mid, hi, a, b);
        return min(X, Y);
    }
}T;

void load(){
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n;
    FOR(i, 1, n + 1)
        cin >> a[i];
    cin >> q;
    REP(i, q){
        int A, B; cin >> A >> B;
        l[B].pb(A);
    }
}

void solve(){
    FOR(i, 1, n + 1){
        cnt += 1 - a[i];

        for(auto it : l[i]){
            int val = min(T.query(1, 0, off, it, i), dp[it - 1]);
            T.add(i, it, val);
        }
        int add = a[i] == 1 ? 1 : -1;
        T.add(i, i, dp[i - 1] + add);
        T.build(i + off);
        dp[i] = T.t[i + off].back().second;
    }
    cout << dp[n] + cnt;
}

int main(){
    load();
    solve();
}


Measured memory_bytes: 109900
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;
const ll INF = 1LL << 60;

int main(){
  ll n,m;
  ll h[100100];
  ll a[100100],b[100100];
  vector<bool> j(100100,true);
  cin >> n >> m;
  rep(i,n) cin >> h[i+1];
  rep(i,m){
    cin >> a[i] >> b[i];
    if(h[a[i]]>h[b[i]]){
      j[b[i]]=false;
    }else if(h[a[i]]<h[b[i]]){
      j[a[i]]=false;
    }else{
      j[a[i]]=false;
      j[b[i]]=false;
    }
  }
  int ans=0;
  repi(i,1,n+1){
    if(j[i]) ans++;
  }
  cout << ans << endl;
  
  
}


Measured memory_bytes: 5952
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
 
int main(){
  int N;
  cin>>N;
  if(N/100==7 or N%100/10==7 or N%10==7) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main()
{
    int n;
    char str[][8] = {
        "",
        "No",
        "No",
        "No",
        "Yes",
        "No",
        "No",
        "Yes",
        "Yes",
        "No",
        "No",
        "Yes",
        "Yes",
        "No",
        "Yes",
        "Yes",
        "Yes",
        "No",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes",
        "Yes"};

    scanf("%d", &n);
    printf("%s\n", str[n]);

    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))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    vector<int> b(n);
    b[0] = a[0];
    for (int i=1; i<n; ++i) {
        if (a[0]/2 <= a[i]) {
            b[i] = a[0]-a[i];
        }
        else {
            b[i] = a[i];
        }
    }
    ll ma = -1, idx = 0;
    for (int i=1; i<n; ++i) {
        if (ma < b[i]) {
            ma = b[i];
            idx = i;
        }
    }
    cout << a[0] << " " << a[idx] << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, string> pls;

int main()
{
	string N;
	cin >> N;
	cout << "ABC" << N << endl;
	return 0;
}

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

int main()
{
	int n,k;
	cin>>n>>k;
	vector<int>v(n,0),v1(n,INT_MAX);
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		v[i]=x;
	}
	v1[0]=0;
	for(int i=1;i<=min(k,n-1);i++)
		v1[i]=abs(v[i]-v[0]);
	for(int i=k+1;i<n;i++)
		for(int j=i-k;j<i;j++)
		v1[i]=min(v1[i],v1[j]+abs(v[j]-v[i]));
	cout<<v1[n-1];
}

Measured memory_bytes: 4056
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,j,k) for(int (i)=(j);(i)<(k);++(i))

int main(){
    int N,ans;
    cin>>N;
    vector<int> A(N),B(N);
    rep(i,0,N)cin>>A[i];
    rep(i,0,N)cin>>B[i];
    rep(i,1,N)A[i]=A[i]+A[i-1];
    rep(i,1,N)B[i]=B[i]+B[i-1];
    ans = A[0]+B[N-1];
    rep(i,1,N) ans = max(ans,A[i]+B[N-1]-B[i-1]);
    cout<<ans<<endl;
}

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

int main(){
	int a,b,c;
	int ans=0;
	int d,e,f;
	scanf("%d %d %d",&a,&b,&c);
	while(a%2==0&&b%2==0&&c%2==0){
		d=a;e=b;
		a=b/2+c/2;b=c/2+d/2;c=d/2+e/2;ans++;
		if(a==b&&b==c){printf("%d\n",-1);return 0;}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true) {
			int h=sc.nextInt();
			int w=sc.nextInt();
			if(h==0 && w==0) {
				break;
			}
			for(int i=0;i<h;i++) {
				for(int j=0; j<w; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 34504
//
//	Created by shamim_nik
//

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

typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,
		tree_order_statistics_node_update> indexed_set;

#define br printf("\n")

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

//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	long long a, b, n, x;
	cin >> a >> b >> n;
	x = min(b - 1, n);
	cout << (floor((a * x) / b) - a * floor(x / b)) << endl;
	return 0;
}


Measured memory_bytes: 3768
def cmb(m, n):
    if m - n < n:
        n = m - n
    if n == 0:
        return 1
    if n == 1:
        return m
    
    numerator = [m - n + k + 1 for k in range(n)]
    denominator = [k + 1 for k in range(n)]

    for p in range(2, n+1):
        pivot = denominator[p-1]
        if pivot > 1:
            offset = (m-n) % p
            for k in range(p-1, n, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    
    result = 1
    for k in range(n):
        if numerator[k] > 1:
            result = result * int(numerator[k]) % (10**9 + 7)

    return result

X, Y = map(int, input().split())

if (X+Y) % 3 != 0:
    print(0)
else:
    m = int((2*X - Y) / 3)
    n = int((2*Y - X) / 3)
    if m < 0 or n < 0:
        print(0)
    else:
        ans = cmb(m+n, n)
        print(int(ans))

Measured memory_bytes: 44148
#include <iostream>

using namespace std;

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

    int ans = 0;
    bool b = false;
    for (int i = 1; i <= N; i++)
    {
        int t;
        cin >> t;
        if(t == i && b == false)
        {
            ans++;
            b = true;
        }
        else if(t == i && b == true)
        {
            b = false;
        }
        else
        {
            b = false;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,A,B,C;
  cin >> n >> A >> B >> C;
  vec l(n);
  for(ll i=0;i<n;i++) cin >> l[i];
  ll ans=inf;
  for(ll i=0;i<(1<<n*2);i++) {
    ll a=0,b=0,c=0;
    ll bit=i;
    ll tans=0;
    for(ll j=0;j<n;j++) {
      ll check=bit%4;
      bit/=4;
      if(check==1) {
        if(a) tans+=10;
        a+=l[j];
      }
      if(check==2) {
        if(b)tans+=10;
        b+=l[j];
      }
      if(check==3) {
        if(c) tans+=10;
        c+=l[j];
      }
    }
    if(a*b*c==0) continue;
    tans+=abs(A-a)+abs(B-b)+abs(C-c);
    ans=min(ans,tans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#define M
#define ll long long
using namespace std;

int read() {
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}
int n, w, h;
int main() {
	//freopen(".in", "r", stdin), freopen(".out", "w", stdout);
	n = read(), w = read(), h = read();
	if(w > n || h > n) {
		cout << "0";
	} else {
		cout << 1ll * (n - w + 1) * (n - h + 1);
	}

	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

string my_readln() { return chomp(readln()); }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto S = my_readln;
	auto tokens = my_readln.split;
	auto K = tokens[0].to!ulong;

	string ans;
	foreach (i, e; S)
	{
		if (i == K - 1 || e != '1')
		{
			ans ~= e;
			break;
		}
	}

	writeln(ans);
	stdout.flush();
}

Measured memory_bytes: 256
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   N : Integer;
   H : Integer;
   W : Integer;
begin
   Get (N);
   Get (H);
   Get (W);
   Put_Line (Integer'Image ((N-H+1)*(N-W+1)));
end Solve;

Measured memory_bytes: 3608
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int, int>P;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,-1,0,1 };
#define INF 100000000
int e[35][35][35][35] = { 0 };
int d[105][105] = { 0 };
int w, h;
void dfs(int x, int y) {
	if (x == h - 1 && y == w - 1) return;
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (0 <= nx && nx < h && 0 <= ny && ny < w && e[x][y][nx][ny] == 0) {
			if (d[nx][ny] > d[x][y] + 1) {
				d[nx][ny] = min(d[nx][ny], d[x][y] + 1);
				dfs(nx, ny);
			}
		}
	}
	return;
}

int main() {
	while (true) {
		for (int i = 0; i < 35; i++)
			for (int j = 0; j < 35; j++)
				for (int k = 0; k < 35; k++)
					for (int l = 0; l < 35; l++) e[i][j][k][l] = -1;
		
		for (int i = 0; i < 105; i++)
			for (int j = 0; j < 105; j++) d[i][j] = INF;
		cin >> w >> h;
		if (w == 0) return 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w - 1; j++) {
				cin >> e[i][j][i][j + 1];
				e[i][j + 1][i][j] = e[i][j][i][j + 1];
			}
			if (i != h - 1) {
				for (int j = 0; j < w; j++) {
					cin >> e[i][j][i + 1][j];
					e[i + 1][j][i][j] = e[i][j][i + 1][j];
				}
			}
		}
		d[0][0] = 1;
		dfs(0, 0);
		if (d[h - 1][w - 1] == INF) {
			cout << 0 << endl;
		}
		else {
			cout << d[h - 1][w - 1] << endl;
		}
	}
	return 0;
}


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

for i in range(19):
    if 10**i <= n and 10**(i+1) > n:
        r = i 
w = n //(10**r)


if r == 0:
    print(n)
else:
    if n == (w+1)*(10**r)-1:
        print(w+r*9)
    else:
        print(w-1+r*9)


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>

using namespace std;

int dp[18][301];
int value[18];


void makedata(void){
  for(int i = 0; i < 18; i++){
    value[i] = i*i;
  }
}

void makedp(void){

  for(int i = 0; i < 18; i++){
    for(int j = 0; j < 300; j++){
      dp[i][j] = 0;
    }
  }

  dp[0][0] = 1;

  for(int i = 1; i < 18; i++){
    for(int j = 0; j < 301; j++){
      dp[i][j] += dp[i-1][j];
      if(j - value[i] >= 0) dp[i][j] += dp[i][j-value[i]];
    }
  }
}

int main(){
  makedata();
  makedp();
  int in;
  while(cin >> in){
    if(in == 0) break;
    cout << dp[17][in]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
long long int egcd(long long int a,long long int b,long long int &x,long long int &y)
{
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    long long int x1, y1;
    long long int d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
long long int ModuloInverse(long long int a,long long int n)
{
  long long int x,y;
  long long int d=egcd(a,n,x,y);
  x=x%n;
  x=(x+n)%n;
  return x;
}
long long int bigmod(long long int a,long long int b,long long int m)
{
  if(b==0) return 1;
  long long int ans=bigmod(a,b/2,m);
  ans=(ans*ans)%m;
  if(b%2) ans=(ans*a)%m;
  return ans;
}
long long int C(long long int n,long long int a)
{
  long long i,nom=1,den=1;
  for(i=1;i<=a;i++)
  {
    nom=(nom*(n-i+1))%MOD;
    den=(den*i)%MOD;
  }
  den=ModuloInverse(den,MOD);
  return (nom*den)%MOD;
}
int main()
{
  long long int n,a,b,i;
  scanf("%lld %lld %lld",&n,&a,&b);
  long long int ans=bigmod(2,n,MOD);
  ans=(ans-1-C(n,a)-C(n,b))%MOD;
  ans=(ans+MOD)%MOD;
  printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int testcasenum = sc.nextInt();
		for(int testcase = 0;testcase<testcasenum;testcase++) {
			int gx = sc.nextInt();
			int gy = sc.nextInt();
			boolean[][] wall = new boolean[gx*2+1][gy*2+1];
			for(int x=0;x<gx;x++) {
				for(int y=0;y<gy;y++) {
					wall[x*2+1][y*2+1] = true;
				}			
			}
			int p = sc.nextInt();
			for(int i=0;i<p;i++) {
				int x1 = sc.nextInt();
				int y1 = sc.nextInt();
				int x2 = sc.nextInt();
				int y2 = sc.nextInt();
				wall[x1+x2][y1+y2] = true;
			}
			//printArray(wall);
			long[][] dp = new long[gx*2+1][gy*2+1];
			dp[0][0] = 1;
			for(int x=0;x<dp.length;x++) {
				for(int y=0;y<dp[0].length;y++) {
					if(x!=0) {
						if (!wall[x-1][y]) {
							dp[x][y] += dp[x-1][y];
						}
					}
					if (y!=0) {
						if (!wall[x][y-1]) {
							dp[x][y] += dp[x][y-1];
						}
					}
				}
			}
			long ans = dp[gx*2][gy*2];
			System.out.println(ans == 0 ? "Miserable Hokusai!" : ans);
		}
	}

	public static void printArray(boolean[][] o) {
		for(int i=0;i<o.length;i++) {
			for(int j=0;j<o[0].length;j++) {
				System.out.print(o[i][j] + "\t");
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26056
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	while(1){
        double x;
        double h;
        double h1;
        cin >> x >> h;
        if(x == 0 && h == 0) break;
        double sum = 0;

        h1 = hypot((x/2),h);
        sum += x * x;
        sum += x * h1 * 2;
        printf("%.6lf\n",sum);
	}
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(),a.end());
    ll ans = 0;
    for(ll mid = n - 1; mid >= 0; mid--) {
        for(ll low = mid - 1; low >= 0; low--) {
            auto itr = lower_bound(a.begin(), a.end(), a[mid] + a[low]);
            ll ng = distance(itr, a.end());
            ans += (n - 1 - mid) - ng;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
main(require("fs").readFileSync("/dev/stdin", "utf8").replace(/\r?\n$/, "").split(/\r?\n/));

function main(lines){
	lines.some(function(str){
		if(str == "0 0") return true;
		console.log(str.split(" ").map(Number).sort(function(a,b){return a-b;}).join(" "));
	});
}

Measured memory_bytes: 18616
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, K, Q; cin >> N >> K >> Q;
  int ans = max(-1, Q-K);
  int right[N] = {};
  rep(i, Q) {
    int p; cin >> p; 
    right[p-1]++;
  }

  rep(i, N){
    // cout << i << " " << right[i];
    if (right[i]>ans) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
import fractions
a, b, c, d = map(int, input().split())
lcm = (c*d)//fractions.gcd(c, d)
a -= 1
ans1 = b - b//c - b//d + b//lcm
ans2 = a - a//c - a//d + a//lcm
print(ans1 - ans2)


Measured memory_bytes: 5728
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w=map(int,input().split())
    A=[input() for _ in range(h)]
    dp=[[0]*w for _ in range(h)] 
    dp[0][0]=1
    mod=10**9+7
    for i in range(h):
        for j in range(w):
            if A[i][j]=="#":continue
            if i>=1 and j>=1:    
                dp[i][j]+=(dp[i-1][j]+dp[i][j-1])%mod
            elif j==0:
                dp[i][j]+=dp[i-1][j]%mod
            else:
                dp[i][j]+=dp[i][j-1]%mod
    print(dp[-1][-1]%mod)

if __name__=='__main__':
    main()

Measured memory_bytes: 51056
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int k,t;
    cin>>k>>t;
    vi v(t);
    rep(i,t)cin>>v[i];
    Sort(v);
    int sum=0;
    for(int i=0;i<t-1;i++){
        sum+=v[i];
    }
    cout<<max(v[t-1]-sum-1,0)<<endl;

    
    
//////////////////////////////////////////////////////
return 0;}


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

using ll = long long;
const int INF = 1e9+100;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin>>s;
	int res = 0;
	for (auto it: s){
		res += it-'0';
	}
	if (res % 9 == 0){
		cout<<"Yes\n";
	}else{
		cout<<"No\n";
	}
	return 0;
}

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

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

int freq[1000001];

int main(){
    IOS;
    int k;
    cin >> k;
    if(!(k%2)){
        cout << -1 << endl;
        return 0;
    }
    int a = 7;
    for(int i=0;;i++){
        if(a % k == 0){
            cout << i + 1 << endl;
            return 0;
        }
        else{
            int b = a % k;
            if(freq[b]) break;
            freq[b]++;
            a = (a * 10 + 7) % k;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 7548
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
#include <map>
#include <list>
#include <bitset>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

int calcDistance(int a, int b, int c, int d){
    return abs(a - c) + abs(b - d);
}


int solve(int a, int b, int m, V& cs, V& ds){
    V distances(m);
    iota(begin(distances), end(distances), 0);
    transform(begin(distances), end(distances), begin(distances), [&](int i){return calcDistance(a, b, cs[i], ds[i]);});
    return min_element(begin(distances), end(distances)) - begin(distances) + 1;
}

V solve(int n, int m, V& as, V& bs, V& cs, V& ds){
    V ps(n);
    iota(begin(ps), end(ps), 0);
    transform(begin(ps), end(ps), begin(ps), [&](int i){return solve(as[i], bs[i], m, cs, ds);});
    return ps;
}


int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    V as(n);
    V bs(n);
    V cs(m);
    V ds(m);
    for(int i = 0; i < n; i++){
        cin >> as[i] >> bs[i];
    }
    for(int i = 0; i < m; i++){
        cin >> cs[i] >> ds[i];
    }

    const V& ps = solve(n, m, as, bs, cs, ds);
    for(auto p : ps){
        cout << p << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <vector>
#include <queue>
using namespace std;
#define loop(i,n) for(int i=0;i<n;i++)

int main(){
    
    int k,t,a;
    int m=0;
    
    cin>>k>>t;
    loop(i,t){
        cin>>a;
        m=max(m,a);
    }
    k-=m;
    cout<<max(m-k-1,0)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(1e9)+7;
const int maxn=610;
int n,ans;
char s[maxn][maxn];
ll lie[maxn][maxn],hang[maxn][maxn];
ll cf[maxn];
int main() {
//	freopen("1.txt","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%s",s[i]);
		for (int j=n;j>=1;j--) s[i][j]=s[i][j-1];
		for (int j=1;j<=n;j++) {
			s[i+n][j]=s[i][j];
			s[i+n][j+n]=s[i][j];
			s[i][j+n]=s[i][j];
		}
	}
	cf[0]=1;
	for (int i=1;i<=2*n;i++)
		cf[i]=cf[i-1]*27%mod;
	for (int i=1;i<=2*n;i++)
		for (int j=1;j<=2*n;j++) {
			lie[i][j]=hang[i][j]=0;
			if (i+n-1<=2*n) {
				for (int k=i;k<=i+n-1;k++)
					lie[i][j]+=cf[k-i+1]*(s[k][j]-'a'+1)%mod,lie[i][j]%=mod;
			}
			if (j+n-1<=2*n) {
				for (int k=j;k<=j+n-1;k++)
					hang[i][j]+=cf[k-j+1]*(s[i][k]-'a'+1)%mod,hang[i][j]%=mod;
			}
			//printf("%d %d %lld %lld\n",i,j,lie[i][j],hang[i][j]);
		}
	ans=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++) {
			bool c=1;
			for (int k=0;k<n;k++)
				if (hang[i+k][j]!=lie[i][j+k]) {
					c=0; break;
				}
			if (c) ans++;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] A = new int[N];
		
		for (int i = 0; i < N; i++) {
			A[i] = 0;
		}
		
		for (int i = 0; i < N - 1; i++) {
			A[sc.nextInt() - 1] += 1;
		}
		
		sc.close();
		
		for (int i = 0; i < N; i++) {
			System.out.println(A[i]);
		}

	}

}


Measured memory_bytes: 60552
#include <iostream>
#define inf 1e9

using namespace std;

int h, w;
char a[105][105];
int sum[105][105];
int dp[2][105][105][105];
int sx, sy;

int get(int sx, int sy, int tx, int ty)
{
  if(sx > tx || sy > ty) return 0;
  return sum[tx][ty] - sum[sx-1][ty] - sum[tx][sy-1] + sum[sx-1][sy-1];
}

int main(void)
{
  cin >> h >> w;
  for(int y = 1; y <= h; y++){
    for(int x = 1; x <= w; x++){
      cin >> a[x][y];
      if(a[x][y] == 'E') sx = x, sy = y;
    }
  }

  for(int x = 1; x <= w; x++){
    for(int y = 1; y <= h; y++){
      sum[x][y] = sum[x-1][y] + sum[x][y-1] - sum[x-1][y-1];
      if(a[x][y] == 'o') sum[x][y]++;
    }
  }

  int ll = sx-1, rr = w-sx, dd = sy-1, uu = h-sy;
  for(int r = 0; r <= rr; r++){
    for(int d = 0; d <= dd; d++){
      for(int u = 0; u <= uu; u++){
        dp[0][r][d][u] = -inf;
      }
    }
  }
  dp[0][0][0][0] = 0;

  for(int i = 0; i < w+h-2; i++){
    for(int r = 0; r <= rr; r++){
      for(int d = 0; d <= dd; d++){
        for(int u = 0; u <= uu; u++){
          dp[(i+1)%2][r][d][u] = -inf;
        }
      }
    }
    for(int r = 0; r <= rr; r++){
      for(int d = 0; d <= dd; d++){
        for(int u = 0; u <= uu; u++){
          int l = i - (r+d+u);
          if(l < 0) continue;
          int L = r, R = w+1-l, D = u, U = h+1-d;
          //cout << l << " " << r << " " << d << " " << u << " " << dp[i%2][r][d][u] << endl;
          if(r+1 <= rr){
            int nr = sx+r+1;
            dp[(i+1)%2][r+1][d][u] = max(dp[(i+1)%2][r+1][d][u], dp[i%2][r][d][u] + ((nr < R)?get(nr, max(D+1,sy-d), nr, min(U-1,sy+u)):0));
          }
          if(l+1 <= ll){
            int nl = sx-l-1;
            dp[(i+1)%2][r][d][u] = max(dp[(i+1)%2][r][d][u], dp[i%2][r][d][u] + ((nl > L)?get(nl, max(D+1,sy-d), nl, min(U-1,sy+u)):0));
          }
          if(u+1 <= uu){
            int nu = sy+u+1;
            dp[(i+1)%2][r][d][u+1] = max(dp[(i+1)%2][r][d][u+1], dp[i%2][r][d][u] + ((nu < U)?get(max(L+1,sx-l), nu, min(R-1,sx+r), nu):0));
          }
          if(d+1 <= dd){
            int nd = sy-d-1;
            dp[(i+1)%2][r][d+1][u] = max(dp[(i+1)%2][r][d+1][u], dp[i%2][r][d][u] + ((nd > D)?get(max(L+1,sx-l), nd, min(R-1,sx+r), nd):0));
          }
        }
      }
    }
  }
  cout << dp[(w+h)%2][rr][dd][uu] << endl;
  return 0;
}


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

int field[2002][2002];
int cum[2002][2002];
int bcum[4002][4002];

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;

    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        for(int j=0;j<M;j++){
            field[i][j] = (s[j] == '1') ? 1 : 0;
            cum[i][j] = field[i][j];
        }
    }

    for(int i=0;i<N;i++){
        for(int j=1;j<M;j++){
            cum[i][j] += cum[i][j - 1];
        }
    }
    for(int j=0;j<M;j++){
        for(int i=1;i<N;i++){
            cum[i][j] += cum[i - 1][j];
        }
    }

    memset(bcum, 0, sizeof(bcum));
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            if(j + 1 < M && field[i][j] == 1 && field[i][j + 1] == 1){
                bcum[2 * i][2 * j + 1] = 1;
            }
            if(i + 1 < N && field[i][j] == 1 && field[i + 1][j] == 1){
                bcum[2 * i + 1][2 * j] = 1;
            }
        }
    }
    for(int i=0;i<2*N;i++){
        for(int j=1;j<2*M;j++){
            bcum[i][j] += bcum[i][j - 1];
        }
    }
    for(int j=0;j<2*M;j++){
        for(int i=1;i<2*N;i++){
            bcum[i][j] += bcum[i - 1][j];
        }
    }

    for(int i=0;i<Q;i++){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        x1--; y1--; x2--; y2--;
        int ret = 0;
        ret += cum[x2][y2];
        if(y1 > 0) ret -= cum[x2][y1 - 1];
        if(x1 > 0) ret -= cum[x1 - 1][y2];
        if(x1 > 0 && y1 > 0) ret += cum[x1 - 1][y1 - 1];
        ret -= bcum[2 * x2][2 * y2];
        if(y1 > 0) ret += bcum[2 * x2][2 * y1 - 1];
        if(x1 > 0) ret += bcum[2 * x1 - 1][2 * y2];
        if(x1 > 0 && y1 > 0) ret -= bcum[2 * x1 - 1][2 * y1 - 1];
        cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 95616
#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};


int main() {
	int W, B;
	cin >> W >> B;
	W--; B--;
	vector<string> x(45, string(99, '.'));
	vector<string> y(45, string(99, '#'));
	for (int i = 1; i < 45; i += 2) {
		for (int j = 1; j < 99; j += 2) {
			if (B > 0) {
				x[i][j] = '#'; B--;
			}
		}
	}
	for (int i = 1; i < 45; i += 2) {
		for (int j = 1; j < 99; j += 2) {
			if (W > 0) {
				y[i][j] = '.'; W--;
			}
		}
	}
	cout << 90 << " " << 99 << endl;
	for (auto it : x)cout << it << endl;
	for (auto it : y)cout << it << endl;

}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  set<pll> dame;
  if(n%2){
    reps(i,n/2){
      dame.insert({i,n-i});
    }
  }else{
    reps(i,n/2){
      dame.insert({i,n-i+1});
    }
  }
  
  set<pll> ans;
  reps(i,n){
    ireps(j,i+1,n){
      if(dame.count({i,j})) continue;
      ans.insert({i,j});
    }
  }
  
  cout<<ans.size()<<endl;
  for(auto e: ans){
    cout<<e.first <<" "<< e.second <<endl;
  }
  
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(std::string S){
  string a, b;
  int i = 0;
  int ret = 0;
  a.push_back(S[0]);
  i++;
  ret++;
  while(S.size() > i) {
    b.push_back(S[i]);
    i++;
    if (b != a) {
      ret++;
      a = b;
      b = "";
    }
  }
  std::cout << ret << std::endl;
}

int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 772
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <string.h>
#include <array>
#include <bitset>

using namespace std;

const int maxn=2e5+5;
typedef long long ll;
const ll inf=1e17;

int n;
int a[maxn];
ll dp[maxn][2][3];

ll rek(int x, bool p, int br){
	if(x==n && !br){
		return 0;
	}
	else if(x==n){
		return -inf;
	}
//	cout << x << " " << p << " " << br << '\n';
	if(dp[x][p][br]){
		return dp[x][p][br];
	}
	if(p){
		return dp[x][p][br]=rek(x+1, 0, br)+a[x];
	}
	else{
		if(br){
			return dp[x][p][br]=max(rek(x+1, 1, br), rek(x+1, 0, br-1));
		}
		else{
			return dp[x][p][br]=rek(x+1, 1, br);
		}
	}
}

void solve1(){
	cout << max(rek(0, 1, 2), rek(0, 0, 1)) << '\n';
}

void solve2(){
	cout << max(rek(0, 1, 1), rek(0, 0, 0)) << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	if(n%2){
		solve1();
	}
	else{
		solve2();
	}
	return 0;
}

Measured memory_bytes: 29436
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {
  ll N;
  cin >> N;
  cout << N * N * N << endl;
}

Measured memory_bytes: 256
import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int amount = 0;
		Integer Array[] = new Integer[N];
		for(int i = 0; i < N; i++){
			Array[i] = sc.nextInt();
		}
		for(int i = 1; i < N; i++){
			for(int j = 0; j < i; j ++){
				amount += Array[i]*Array[j];
			}
		}
		System.out.println(amount);
		sc.close();
	}
};

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>

using namespace std;
#define ll long long
#define MOD 1000000007
#define INF (int)1e9
#define EPS 1e-9
/*
    The probability is interesting to notice from a distance
    Drew Barrymore- SZA
    Make it up- Shura
*/

int main(){
    int n; cin>>n;
    double x;
    double dp[n+1];
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=0;i<n;i++){
        cin>>x;
        for(int j=i+1;j>=0;j--){
            dp[j]=(j==0? 0: dp[j-1]*x)+dp[j]*(1-x);
        }
    }
    double ans=0;
    for(int i=0;i<=n;i++){
        if(i>(n-i)){
            ans+=dp[i];
        }
    }
    cout<<setprecision(10)<<ans;
    return 0;
}



Measured memory_bytes: 256