akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

struct mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    bool operator <(const mint& r){return this->x<r.x;}
    bool operator ==(const mint& r){return this->x==r.x;}
    bool operator !=(const mint& r){return this->x!=r.x;}
    void operator++() {
        x++;
    }
    void operator--() {
        x--;
        if(x<0) x += mod;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

vector<mint> large;
ll parent[200005];
bool seen[200005];

void dfs(const graph &g,ll s){
  for(auto x:g[s]){
    if(seen[x]) continue;
    seen[x] = true;
    parent[x] = s;
    dfs(g,x);
    large[s] += large[x];
  }
}
int main() {
  ll N;
  cin>>N;
  graph g(N);
  large.assign(N,1);
  parent[0] = -1;
  rep(i,N-1){
    ll A,B;
    cin>>A>>B;
    A--;
    B--;
    g[A].push_back(B);
    g[B].push_back(A);
  }
  vector<mint> pow2(200005);
  pow2[0] = 1;
  rep(i,200004){
    pow2[i+1] = pow2[i] * (mint)2;
  }
  seen[0] = true;
  dfs(g,0);
  mint ans = 0;
  rep(i,N){
    mint ret = pow2[N-1];
    for(auto x:g[i]){
      if(x==parent[i]){
        ret -= pow2[N-large[i].x]-(mint)1;
      }
      else ret -= pow2[large[x].x]-(mint)1;
    }
    --ret;
    ans += ret;
  }
  ans *= pow2[N].inv();
  cout<<ans<<endl;
}

Measured memory_bytes: 30432
import Control.Applicative
import Control.Monad
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = do
  n <- f
  [a, d] <- g
  m <- f
  solve n a d <$> (reverse <$> (replicateM m g)) <*> f >>= print
  where
    f = readi B.readInt <$> B.getLine
    g = readil B.readInt <$> B.getLine

solve :: Int -> Int -> Int -> [[Int]] -> Int -> Int
solve n a d cs k = g $ foldl' f (k, []) cs
  where
    f (i, fs) [x, y, z]
      | x == 1 && y <= i && i <= z = (i, (+1) : fs)
      | x == 2 && y <= i && i <= z = (i, (flip div 2) : fs)
      | x == 0 && y <= i && i <= z = (y+z-i, fs)
      | otherwise = (i, fs)
    g (i, fs) = foldl' (\x f -> f x) (a + (i-1) * d) fs
                    
readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')



Measured memory_bytes: 66264
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
int N,M,Q;



int main() {
	cin >> N;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	cin >> Q;
	rep(i, Q) {
		int b, e;
		cin >> b >> e;
		reverse(A.begin() + b, A.begin() + e);
	}
	rep(i, N - 1) {
		cout << A[i] << " ";
	}
	cout << A[N - 1]<<endl;
	return 0;
}





Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(void) {
    int n, k; cin >> n >> k;
    vector<double> e(n+1);
    rep(i, n) {
        int p; cin >> p;
        double sum = p*(p+1)/2.0;
        e[i+1] = (double)sum/p;
    }
    rep(i, n-1) {
        e[i+2] += e[i+1];
    }
    e[0] = 0.0;
    double ma = 0.0;
    for(int i=0;i<=n;i++) {
        if(k+i>n) break;
        ma = max(e[k+i] - e[i], ma);
    }
    printf("%.10f\n",ma);
}



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

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

    string t;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] == 'C' && s[i - 1] == 'B') {
            t.push_back('D');
            i++;
        } else {
            t.push_back(s[i - 1]);
        }
    }

    long long res = 0, cnt = 0;
    for (int i = 0; i < t.size(); i++) {
        if (t[i] == 'B' || t[i] == 'C') {
            cnt = 0;
        } else if (t[i] == 'A') {
            cnt++;
        } else {
            res += cnt;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 776
# -*- coding: utf-8 -*-
A = int(raw_input())
B = int(raw_input())
C = int(raw_input())
X = int(raw_input())
count = 0
a = 0
while a <= A:
    b = 0
    c = 0
    A_price = 500 * (a)
    while b <= B:
        c = 0
        B_price = 100 * b
        while c <= C:
            C_price = 50 * c
            if A_price + B_price + C_price == X:
                count += 1
            c += 1
        b += 1
    a += 1
print count

Measured memory_bytes: 2568
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
//10,20//20,10//10,-20//20,-10//-10,20//-20,10//-10,-20//-20,-10
int n,m,ans;
int main(){
	scanf("%d%d",&n,&m);
	if(m==0){
		if(n>0)ans=n+1;
		else ans=-n;
	}
	else if(n>=0){
		if(m>=0){
			if(n>m)ans=n-m+2;
			else ans=m-n;
		}
		else if(m<0){
			ans=abs(n-abs(m))+1;
		}
	}
	else if(n<0){
		if(m>=0){
			ans=abs(n+m)+1;
		}
		else if(m<0){
			if(n>m)ans=abs(n-m)+2;
			else ans=abs(n-m);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = long.Parse(line[0]);
        var x = int.Parse(line[1]);
        var m = int.Parse(line[2]);
        getAns(n, x, m);
    }
    static void getAns(long n, int x, int m)
    {
        var a = new long[m];
        var b = new long[m + 1];
        a[0] = x;
        b[1] = x;
        var d = new Dictionary<long, int>();
        d[x] = 0;
        var p = 1;
        while (p < m)
        {
            var w = (a[p - 1] * a[p - 1]) % m;
            a[p] = w;
            b[p + 1] = b[p] + a[p];
            if (!d.ContainsKey(w)) d[w] = p;
            else
            {
                var dw = d[w];
                var loopc = p - dw;
                var loopv = b[p] - b[dw];
                var toloopv = b[dw];
                var time = (n - dw) / loopc;
                var toend = (n - dw) % loopc;
                var toendv = b[dw + toend] - b[dw];
                var ans = toloopv + time * loopv + toendv;
                Console.WriteLine(ans);
                return;
            }
            p++;
        }
        Console.WriteLine(b[m - 1]);
    }
}


Measured memory_bytes: 31904
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
//#define rep(i,a,b) for (int i=a;i<=b;i++)
//#define per(i,a,b) for (int i=a;i>=b;i--)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define f first
#define s second
#define mset(m,v) memset(m,v,sizeof(m))
#define mod 1000000007
const int N = 2e5 + 5;
#define PI acos(-1.0)
long double EPS = 1e-9;
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(ll a, ll b) { if (a < b)swap(a, b); return (((a%mod) - (b%mod) + mod) % mod); }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
void pre() {
}
int n;
vpii v;
int dp[2002][2002];
int go(int pos, int l, int r) {
	if (pos == sz(v))return 0;
	//trace(pos);
	int &ans = dp[pos][l];
	if (ans != -1)return ans;
	return ans = max(go(pos + 1, l + 1, r) + v[pos].first*abs(v[pos].second - l), go(pos+1, l, r - 1) + v[pos].f*abs(v[pos].s - r));
}
void solve() {
	cin >> n;
	rep(i, n) {
		int x;
		cin >> x;
		v.PB({x,i});
	}

	sort(rall(v));
	mset(dp, -1);
	cout << go(0, 0, n - 1) << endl;

}
signed main()
{
	fastio;
	cout << fixed << setprecision(3);
	//clock_t begin = clock();
	//pre();
	int tc;
	tc = 1;
	//cin >> tc;
	while (tc--) {
		solve();
	}
	//clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;
}


Measured memory_bytes: 35176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define rep2(i, a, b) for(int i=a; i<=(int)(b); ++i)
#define all(v) v.begin(),v.end()
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  ll x;
  cin >> x;
  rep2(a, -250, 250) rep2(b, -250, 250) {
    ll i = 1ll*a*a*a*a*a;
    ll j = 1ll*b*b*b*b*b;
    if (i-j == x) {
      printf("%d %d\n", a, b);
      return 0;
    }
  }
}

Measured memory_bytes: 3784
#include "bits/stdc++.h"
using namespace std;

int n;

#define MAX 4002

char buf[MAX];


bitset<MAX> x;

void read(bitset<MAX> &b) {
	b.reset();
	scanf("%s", buf);
	int sz = strlen(buf);
	for (int i = 0; i < sz; i++) {
		b.set(sz - i - 1, buf[i] - '0');
	}
}

bitset<MAX> gc;
bitset<MAX> tmp;

int idx(bitset<MAX> &a) {
	for (int i = MAX - 1; i >= 0; i--) {
		if (a.test(i)) {
			return i;
		}
	}
	return -1;
}
bitset<MAX> gcd(bitset<MAX> a, bitset<MAX> b) {
	while (1) {
		int A = idx(a);
		int B = idx(b);
		if (A == -1) {
			return b;
		}
		if (B == -1) {
			return a;
		}
		if (A >= B) {
			a ^= b << (A - B);
		}
		else {
			b ^= a << (B - A);
		}
	}
	return a;
}
#define MOD  998244353
bitset<MAX> xx;
long long int p2[MAX];
int main() {
	p2[0] = 1;
	for (int i = 1; i < MAX; i++) {
		p2[i] = p2[i - 1];
		p2[i] *= 2LL;
		p2[i] %= MOD;
	}
	cin >> n;
	read(x);
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			read(gc);
			continue;
		}
		read(tmp);
		gc = gcd(gc, tmp);
	}
	int d = idx(gc);
	long long int ans = 0;
	long long int way = 0;
	for (int i = MAX - 1; i >= d; i--) {
		if (x.test(i)) {
			way += p2[i - (d)];
			way %= MOD;
		}
	}
	xx = x;
	while (1) {
		int id1 = idx(xx);
		int id2 = idx(gc);
		if (id1 >= id2) {
			xx ^= gc << (id1 - id2);
		}
		else {
			break;
		}
	}
	xx ^= x;
	way++;
	for (int i = MAX - 1; i >= 0; i--) {
		int A = x.test(i);
		int B = xx.test(i);
		if (A == B)continue;
		if (A < B) {
			way += MOD-1;
			break;
		}
		break;
	}
	way %= MOD;
	printf("%lld\n", way);
	return 0;
}

Measured memory_bytes: 256
X,K,D=map(int,input().split())
L=min(X+D*K,X-D*K)
R=max(X+D*K,X-D*K)

if 0<=L:
    print(L)
elif R<=0:
    print(abs(R))
else:
    X=L
    start=0
    end=K
    while end-start>1:
        test=(end+start)//2
        if X+test*2*D<=0:
            start=test
        else:
            end=test
    ans1=abs(X+2*D*start)
    ans2=abs(X+2*D*end)
    print(min(ans1,ans2))


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

int main()
{
    int N, count=0;
    cin >> N;
    vector<int> data(N);

    for (int i = 0; i < N;i++){
        cin >> data.at(i) ;
    }

    sort(data.rbegin(), data.rend());

    for (int i = 0; i < N; i++){
        if(i%2==0){
            count += data.at(i);
        }else{
            count -= data.at(i);
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    const int mod = 2600000069;
    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    const int mod = 2600000069;
    const int p = 31;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for (int gap = 1; gap < n; gap++) {
        int cur = 0;
        for (int j = 0; j < n - gap; j++) {
            if (s[j] == s[j + gap]) cur++;
            else cur = 0;
            ans = max(ans, min(gap, cur));
        }
    }
    cout << ans;
}
/*

*/


Measured memory_bytes: 256
n, y = map(int, input().split())
y /= 1000
ans = (-1, -1, -1)
flag = False
for i in range(n+1):
    for j in range(n-i+1):
        if 10*i+5*j+(n-i-j) == y and n-i-j>=0:
            ans = (i, j, n-i-j)
            flag = True
            break
    if flag:
        break
print(*ans)

Measured memory_bytes: 3064
using System;
class p
{
  static void Main()
  {
    long H = long.Parse(Console.ReadLine());
    H = (H % 2 == 0) ? H : (H == 1) ? H : H - 1;
    long m = 1, sum = 0;
    
    while (1 <= H) {
      sum += m;
      H /= 2;
      m *= 2;
    }
    Console.WriteLine(sum);
  }
}

Measured memory_bytes: 13140
#include<iostream>
using namespace std;
int main() {
	long  a, b, n,ans;
	cin >> a >> b >> n;
	if (n < b)ans = (a * n / b ) - a * (n / b);
	else ans = (a * (b - 1) / b )- a * ((b - 1) / b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
    using namespace std;
    #define rep(i,n) for(int i=0; i<(n); i++)
    #define FOR(i,a,b) for(int i=(a); i<(b); i++)
    #define ALL(v) v.begin(), v.end()
    #define RALL(v) v.rbegin(), v.rend()
    typedef long long ll;
    const ll mod = 998244353;
    int main(){
        ll n; cin >> n;
        vector<ll> d(n),cnt(n);
        ll M = -1;
        ll ans = 1;
        rep(i,n) {
            cin >> d[i];
            cnt[d[i]]++;
            M = max(M, d[i]);
            if(d[i] == 0 && i != 0){
                puts("0");
                return 0;
            }
        }
        if(d[0] != 0){
            puts("0");
            return 0;
        }

        FOR(i,1,n){
            ans *= cnt[d[i]-1];
            ans %= mod;
        }
        cout << ans << endl;
    }

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int n;
  cin >> n;
  vector<int> w(n);
  int s1 = 0, s2 = 0;
  rep(i, n) {
    cin >> w[i];
    s2 += w[i];
  }

  int ans = 1e9;
  rep(i, n) {
    ans = min(ans, abs(s1 - s2));
    s1 += w[i];
    s2 -= w[i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+2;
const int M=1e3+2;
const int inf=1e9+7;
int cnt[M][M],cnt1[3][M][M],d;
int getsum(int idx,int l,int r,int l2,int r2){
	int ans=cnt1[idx][l2][r2];
	if(l){
		ans-=cnt1[idx][l-1][r2];
	}
	if(r){
		ans-=cnt1[idx][l2][r-1];
	}
	if(l&&r){
		ans+=cnt1[idx][l-1][r-1];
	}
	return ans;
}
int getrec(int idx,int l,int r,int a,int b){	
	if(l+a<d&&r+b<d){
		return getsum(idx,l,r,l+a,r+b);
	}
	else{
		if(l+a<d&&r+b>=d){
			return getsum(idx,l,r,l+a,d-1)+getsum(idx,l,0,l+a,r+b-d);
		}
		else{
			if(l+a>=d&&r+b<d){
				return getsum(idx,l,r,d-1,r+b)+getsum(idx,0,r,l+a-d,r+b);
			}
			else{
				return getsum(idx,l,r,d-1,d-1)+getsum(idx,l,0,d-1,r+b-d)+getsum(idx,0,r,l+a-d,d-1)+getsum(idx,0,0,l+a-d,r+b-d);
			}
		}
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,i,j,k,l,z,num=0,lef,rig,mid;
	cin>>n>>d;
	for(i=1;i<=n;i++){
		cin>>j>>k;
		cnt[j%d][k%d]++;
	}
	for(i=0;i<d;i++){
		for(j=0;j<d;j++){
			if(!cnt[i][j]){
				continue;
			}
			z=sqrt(cnt[i][j])-1;
			while((z+1)*(z+1)<cnt[i][j]){
				z++;
			}
			num=max(num,z);
		}
	}
//	cout<<num<<endl;
	lef=num*d,mid=rig=num*d+d-1;
	while(lef<rig){
		mid=(lef+rig)/2;
		for(i=0;i<3;i++){
			if(i==0){
				l=(num+1)*(num+1);
			}
			if(i==1){
				l=num*(num+1);
			}
			if(i==2){
				l=num*num;
			}
			for(j=0;j<d;j++){
				for(k=0;k<d;k++){
					cnt1[i][j][k]=(cnt[j][k]>l);
					if(j){
						cnt1[i][j][k]+=cnt1[i][j-1][k];
					}
					if(k){
						cnt1[i][j][k]+=cnt1[i][j][k-1];
					}
					if(j&&k){
						cnt1[i][j][k]-=cnt1[i][j-1][k-1];
					}
				}
			}
		}
		bool cac=false;
		l=mid%d;
		for(i=0;i<d;i++){
			for(j=0;j<d;j++){
				int cost1=getrec(0,i,j,l,l),cost2=0,cost3=0;
				if(l<d-1){
					cost2=max(getrec(1,(i+l+1)%d,j,d-1-l-1,l),getrec(1,i,(j+l+1)%d,l,d-1-l-1));
//					if(i==2&&j==2){
//						cout<<(i+l+1)%d<<' '<<j<<' '<<d-1-l-1<<' '<<l<<' '<<getrec(1,(i+l+1)%d,j,d-1-l-1,l)<<endl;
//						cout<<i<<' '<<(j+l+1)%d<<' '<<l<<' '<<d-1-l-1<<' '<<getrec(1,i,(j+l+1)%d,l,d-1-l-1)<<endl;
//					}
					cost3=getrec(2,(i+l+1)%d,(j+l+1)%d,d-l-1-1,d-l-1-1);
				}
//				if(i==2&&j==2){
//					cout<<cost1<<' '<<cost2<<' '<<cost3<<" CAC"<<endl;
//				}
				if(!cost1&&!cost2&&!cost3){
					cac=true;
					break;
				}
			}
			if(cac){
				break;
			}
		}
		if(cac){
			rig=mid;
		}
		else{
			lef=mid+1;
		}
	}
	cout<<rig;
}

Measured memory_bytes: 34852
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;

int main(){

string S;

while(cin>>S){
int Q=0,QQ=0;
for(int i=0;i<(S.size()-2);i++)
{
if(S[i]=='J'&&S[i+1]=='O'&&S[i+2]=='I')Q++;
else if(S[i]=='I'&&S[i+1]=='O'&&S[i+2]=='I')QQ++;
}
cout<<Q<<endl<<QQ<<endl;
}
return 0;

}

Measured memory_bytes: 1196
//////////////////////////// ⛎🎱💲♏☢🤘(NOOB 383)
//////////////////////////// 🇨🇸🇪 48
//////////////////////////// 🇯🇦🇭🇦🇳🇬🇮🇷🇳🇦🇬🇦🇷 🇺🇳🇮🇻🇪🇷🇸🇮🇹🇾((JU))

#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL vector<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
void Y()
{
    cout<<"Yes"<<endl;
}
void N()
{
    cout<<"No"<<endl;
}
V<LL>v;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
   cin>>n>>m;
   for(i=0,s=0;i<n;i++)
   {
       cin>>o;
       s+=o;
       v.PSB(o);
   }
   for(i=0,k=0;i<n;i++)
   {
       if(v[i]*4*m>=s)
       {
           k++;
       }
   }
   if(k>=m)
   {
       Y();
   }
   else
   {
       N();
   }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (b == 1) {
        cout << "0\n";
        return 0;
    }
    int c = a;
    int d = 1;
    while (true) {
        if (c >= b) {
            cout << d << "\n";
            return 0;
        }
        c += a - 1;
        d++;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            // write your code here
            int A = in.nextInt(), B = in.nextInt();
            out.println((A - 1) * (B - 1));
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}


Measured memory_bytes: 25044
#include <iostream> 

 

  #include <iomanip>

 

using namespace std; 

 

  

 

int 

 

main () 

 

{ 

 

  

 

  int a ; 

 

  

 

  int b ; 

 

  cin>>a>>b; 

 

  double f = a; 

 

  double g = b; 

 

  int c= a/b; 

 

  int d=a % b; 

 

  double e=f/g; 

 

   
 std::cout << std::fixed;
    std::cout << std::setprecision(5);
    
  cout<< c << " "<<d << " " << e <<endl; 

 

  return 0; 

 

 
} 


Measured memory_bytes: 3256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
constexpr ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ll n,m;
cin>>n>>m;
ll d=n*m;
if(n==1||m==1)cout<<1<<endl;
else cout<<(d+1)/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 610
int a[N][N],n,d1,d2,b;
int main()
{
	scanf("%d%d%d",&n,&d1,&d2);
	while (d1%4==0)
	{
		b++;
		d1/=4;
	}
	if (d1&1)
	{
		for (int i=0; i<2*n; i++)
			for (int j=0; j<2*n; j++)
				if (((i>>b)+(j>>b))&1)
					a[i][j]=1;
	}
	else
		for (int i=0; i<2*n; i++)
			for (int j=0; j<2*n; j++)
				if ((i>>b)&1) a[i][j]=1;
	b=0;
	while (d2%4==0)
	{
		b++;
		d2/=4;
	}
	if (d2&1)
		for (int i=0; i<2*n; i++)
		{
			for (int j=0; j<2*n; j++)
				if (((i>>b)+(j>>b))&1)
					a[i][j]=1;
		}
	else
		for (int i=0; i<2*n; i++)
			for (int j=0; j<2*n; j++)
				if ((i>>b)&1) a[i][j]=1;

	int tt=0;
	for (int i=0; i<2*n; i++)
		for (int j=0; j<2*n; j++)
			if (a[i][j]==0)
			{
				tt++;
				printf("%d %d\n",i,j);
				if (tt==n*n) return 0;
			}
	return 0;
}

Measured memory_bytes: 2304
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static final int MOD = (int)1e9 + 7;
	int N,M;
	char[] ch;
	int[] r,l,newR,sum;
	long[][] dp;

	public void solve() {
		N = nextInt();
		M = nextInt();
		ch = next().toCharArray();

		l = new int[M];
		r = new int[M];
		for(int i = 0;i < M;i++){
			l[i] = nextInt() - 1;
			r[i] = nextInt() - 1;
		}

		newR = new int[N];
		for(int i = 0;i < N;i++){
			newR[i] = i;
		}
		for(int i = 0;i < M;i++){
			newR[l[i]] = Math.max(newR[l[i]],r[i]);
		}

		for(int i = 1;i < N;i++){
			newR[i] = Math.max(newR[i], newR[i-1]);
		}

		sum = new int[N];
		for(int i = 0;i < N;i++){
			sum[i] = ch[i] - '0';
		}
		for(int i = 0;i < N - 1;i++){
			sum[i + 1] += sum[i];
		}

		dp = new long[N + 1][N + 1];
		dp[0][0] = 1L;

		//i = 今見ているSの位置
		for(int i = 0;i < N;i++){

			//j = これまで配置した1の数
			for(int j = 0;j <= i;j++){

				if(dp[i][j] == 0)continue;

				/*
				 * j <= sum[newR[i]] jがnewR[i]]の位置までに存在する1の数以下(これを超えていたら存在する1の数より多いのでありえない)
				 * sum[newR[i]] - j <= newR[i] - i 残りの配置しなければならない1の数 <= newR[i]の位置まで配置できる0or1の数(これも超えていたら1が余分に存在している)
				 *
				 * 以上の条件を満たした時、dp[i + 1][j]に遷移する(iの位置に0を配置して次の状態に移る)
				 */
				if(j <= sum[newR[i]] && sum[newR[i]] - j <= newR[i] - i){
					dp[i + 1][j] += dp[i][j]%MOD;
					dp[i + 1][j] %= MOD;
				}

				/*
				 * j <= sum[newR[i]] - 1 iの位置に1を配置する分をsum[newR[i]]から引いてもちゃんとj以上になる(これがj未満になると矛盾していることになる)
				 * sum[newR[i]] - j - 1 <= newR[i] - i 今iの位置に配置する分(-1)とこれまで配置した分(j)をsum[newR[i]]から引いた残りの数(これはnewR[i]の位置までに配置しなければならない1の数)が
				 * 残りの配置できる位置の数以下(これが上回っていると配置することが出来ない1が出てきてしまう)
				 */
				if(j  + 1<= sum[newR[i]] && sum[newR[i]] - j - 1 <= newR[i] - i){
					dp[i + 1][j + 1] += dp[i][j]%MOD;
					dp[i + 1][j + 1] %= MOD;
				}
			}
		}

		out.println(dp[N][sum[N-1]]);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

#define pb push_back
#define ppp pop_back
#define pii pair<int, int>
#define fi first
#define se second

const int N = 2e5 + 5;

ll dp[N], a[N];

struct CHT {
	int pointer=0;
	vector<ll> K;
	vector<ll> B;
	bool bad(int l1, int l2, int l3) {
		return (B[l3]-B[l1])*(K[l1]-K[l2])<(B[l2]-B[l1])*(K[l1]-K[l3]);
	}
	void add(ll k, ll b) {
		if (!K.empty() && K.back() == k) return;
		K.pb(k);
		B.pb(b);
		while (K.size() >= 3 && bad(K.size()-3, K.size()-2, K.size()-1)) {
			K.erase(K.end()-2);
			B.erase(B.end()-2);
		}
	}
	ll getmin(ll x) {
		while (pointer < K.size()-1 && K[pointer+1] * x + B[pointer+1] < K[pointer] * x + B[pointer]) pointer++;
		return K[pointer] * x + B[pointer];
	}
};

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int n;
	ll c;
	cin >> n >> c;
	for (int i=1; i<=n; i++) cin >> a[i];
	CHT cht;
	dp[1] = 0;
	cht.add(-2 * a[1], a[1] * a[1] + c);
	for (int i=2; i<=n; i++) {
		dp[i] = cht.getmin(a[i]) + a[i] * a[i];
		cht.add(-2 * a[i], a[i] * a[i] + c + dp[i]);
	}
	cout << dp[n] << "\n";
    return 0;
}


Measured memory_bytes: 6756
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sum = 0;

        for(int i=0; i<=n; i++){
            int temp = i;
            int digSum =0;
            while(temp > 0){
                digSum += temp % 10;
                temp /= 10;
            }
            if(a<=digSum && digSum <=b) sum += i;
        }
        System.out.println(sum);
    }
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll N;
vector<ll> a;

int main(int argc, char **argv)
{
	cin >> N;
	a.resize(N);
	REP(i, N) cin >> a[i];
	REP(i, N-1)
		a[i+1] += a[i];

	ll res{INF};
	ll pre;
	ll cnt;

	// patern 1
	pre = 0;
	cnt = 0;
	REP(i, N)
	{
		ll t = a[i] + pre;
		if (i & 1)
		{
			if (t <= 0)
			{
				cnt += -t + 1;
				pre += -t + 1;
			}
		}
		else
		{
			if (t >= 0)
			{
				cnt += t + 1;
				pre -= t + 1;
			}
		}
	}
	res = min(res, cnt);

	// patern 
	cnt = 0;
	pre = 0;
	REP(i, N)
	{
		ll t = a[i] + pre;
		if (~i & 1)
		{
			if (t <= 0)
			{
				cnt += -t + 1;
				pre += -t + 1;
			}
		}
		else
		{
			if (t >= 0)
			{
				cnt += t + 1;
				pre -= t + 1;
			}
		}
	}
	res = min(res, cnt);

	std::cout << res << std::endl;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
A = list(map(int, input().split()))
all_vote = sum(A)
count = 0


for i in range(N):
    if  A[i] >= all_vote / (4*M):
        count += 1

if count < M:
    print("No")
else:
    print("Yes")

    

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	if (n % 10 == 3)
		printf("bon");
	else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
		printf("pon");
	else if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9)
		printf("hon");
	return 0;
}


Measured memory_bytes: 1712
# aising2019C - Alternating Path
def dfs(sx: int, sy: int) -> None:
    color = [0] * 2
    s_col = S[sx][sy]
    color[s_col] += 1
    S[sx][sy] = 2  # make the grid visited
    stack = [(sx, sy, s_col)]
    while stack:
        x, y, col = stack.pop()
        for dx, dy in dxy:
            nx, ny = x + dx, y + dy
            if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == col ^ 1:
                n_col = S[nx][ny]
                stack.append((nx, ny, n_col))
                color[n_col] += 1
                S[nx][ny] = 2
    return color[0] * color[1]


def main():
    # separate S to connected components
    global H, W, S, dxy, blk, wht
    H, W, *S = open(0).read().split()
    H, W = int(H), int(W)
    S = [[1 if i == "#" else 0 for i in s] for s in S]
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] != 2:
                ans += dfs(i, j)
    print(ans)


if __name__ == "__main__":
    main()

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

namespace ABC125C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var numbers = Console.ReadLine().Split().Select(long.Parse).ToList();
            var count = 0;
            long sum = 0;
            long small = 0;
            var firstflag = true;
            long abs = 0;
            foreach (var number in numbers)
            {
                abs = Math.Abs(number);
                if (firstflag)
                {
                    small = abs;
                    firstflag = false;
                }
                else
                {
                    if (small > abs)
                    {
                        small = abs;
                    }
                }
                sum += abs;
                if (number < 0)
                {
                    count++;
                }
            }
            if (count % 2 == 0)
            {
                Console.WriteLine(sum);
            }
            else
            {
                Console.WriteLine(sum - small * 2);
            }
        }
    }
}

Measured memory_bytes: 28892
#include <bits/stdc++.h>
    
using namespace std;
     
int main(){  
    int n;
    cin >> n;
    vector<array<int,3>> h(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> h[i][j];
        }
    }
 
    vector<array<long long,3>> dp(n);
    for (int j = 0; j < 3; ++j) {
        dp[0][j] = h[0][j];
    }
    
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            dp[i][j] = 0;
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                dp[i][j] = max(dp[i][j], h[i][j] + dp[i - 1][k]);
            }
        }
    }
    return cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << '\n',0; 
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
main() {
    int a=readInt(),b=readInt();
    cout<<max((b+a-3), 0ll)/(a-1);
}


Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
# min_index = B.index(min(B))

A[0], A[1] = B[0], B[0]
for i in range(N - 1):
    if B[i] < A[i]: A[i] = B[i]
    A[i + 1] = B[i]
print(sum(A))


Measured memory_bytes: 3060
S=input()
dp=[[0 for _ in range(13)] for _ in range(len(S))]
MOD=10**9+7
if S[0]=='?':
  for i in range(10):
    dp[0][i]=1
else:
  dp[0][int(S[0])]+=1
for i in range(1, len(S)):
  cur_nums=[i for i in range(10)] if S[i]=='?' else [int(S[i])]
  for cur in cur_nums:
    for rem in range(13):
      dp[i][(10*rem+cur)%13]=(dp[i][(10*rem+cur)%13]+dp[i-1][rem])%MOD
print(dp[-1][5])

Measured memory_bytes: 66012
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    
    for(int i=0;i<n-2;i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
    }
    
    cout<<ans<<endl;
}

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

double a,b;

void luan(){
	cin>>a>>b;
	cout<<a/b<<"\n";
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	luan();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF (1e10+5)
#define F first
#define S second
#define pb push_back
#define MP make_pair
#define FRL(i,a,n) for(i=a;i<n;i++)
#define FR(i,n) FRL(i,0,n)
#define RFRL(i,n) for(i=n;i>=0;i--)
#define MOD 1000000007
#define fill(a) memset(dp,a,sizeof(dp));

using namespace std;

typedef long long int  ll;

typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector< pair<ll,ll> > vpi;
typedef set<ll> st;
typedef map<ll,ll> mp;
typedef unordered_map<ll,ll> ump;

template< class T>
T minn(T a,T b)
{
	return (a>b)?b:a;
}
template< class T>
T maxx(T a,T b)
{
	return (a>b)?a:b;
}


void FILE_OP()
{
	#ifndef ONLINE_JUDGE
        freopen("inputf.txt", "r", stdin);
        freopen("output2.txt", "w", stdout);
    #endif
}
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll n;
ll v[100005][4];
ll dp[100005][4];
/*ll frog(ll i,ll c)
{
	if(i>n)
		return 0;
	
	c=c+minn(frog(i+1,abs(v[i-1]-v[i])),frog(i+2,abs(v[i-2]-v[i])));
	return c;

}*/

ll findmax(ll d,ll la)
{
	if(d>n)
		return 0;
	if(dp[d][la]!=-1)
		return dp[d][la];
	ll b=-1e9;
	for(ll i=0;i<3;i++)
	{
		if(i!=la)
			b=maxx(b,v[d][i]+findmax(d+1,i));
	}
	return dp[d][la]=b;
}


void SOLVE()
{

	
	ll tt,m,i,j,k,a,b,c,d,l,r;
	//cin>>tt;
	tt=1;
	fill(-1)
	while(tt--)
	{
		cin>>n;
		
		for(i=1;i<=n;i++)
			for(j=0;j<3;j++)
				cin>>v[i][j];
		cout<<findmax(0,1);
		
		
	}


		
}

int main()
{
	FAST_IO
	//FILE_OP();
	SOLVE();
	
	return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100005
#define mp make_pair
#define pb push_back
#define f first
#define se second
vector<int>adj[N];
vector<bool>vis(N,false);
int cnt=0;
bool prime[1000004];
void dfs(int v)
{   
    vis[v]=true;
    for(auto it:adj[v])
        if(!vis[it])
            dfs(it);
}
bool isPerfectSquare(long double x) 
{   
  // Find floating point value of  
  // square root of x. 
  long double sr = sqrt(x); 
  
  // If square root is an integer 
  return ((sr - floor(sr)) == 0); 
} 
void prime_check() 
{  
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=1000000; p++) 
    { 
        if (prime[p] == true) 
        {  
            for (int i=p*p; i<=1000000; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int main()
{
  ll n,k,sum=0,i;
  cin>>n>>k;
  ll a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  for(i=0;i<(n-(min(k,n)));i++)
  {
      sum+=a[i];
  }
  cout<<sum;
}

Measured memory_bytes: 4224
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int h = sc.nextInt();
      int w = sc.nextInt();
      int[][] grid = new int[h][w];
      for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
          grid[i][j] = sc.nextInt();

      List<String> res = new ArrayList<>();
      for(int i = 0; i < h; i++) {
        for(int j = 0; j < w-1; j++) {
          if(grid[i][j] % 2 == 0) continue;
          grid[i][j+1]++;
          res.add((i+1) + " " + (j+1) + " " + (i+1) + " " + (j + 2));
        }
      }

      for(int i = 0; i < h - 1; i++) {
        if(grid[i][w-1] % 2 == 0) continue;
          grid[i+1][w-1]++;
          res.add((i+1) + " " + (w) + " " + (i + 2) + " " + (w));
      }

      System.out.println(res.size());
      for(String s : res)
      System.out.println(s);
  }
}

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

using namespace std;

int main(void){
  int n;
  int ac = 0,wa = 0,tle = 0,re = 0;
  cin >> n;
  
  for(int i = 0; i < n; i++){
    string tmp;
    cin >> tmp;
    
    if(tmp == "AC")ac++;
    else if(tmp == "WA")wa++;
    else if(tmp == "TLE")tle++;
    else if(tmp == "RE")re++;
    
  }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  
}

Measured memory_bytes: 3632
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#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>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main(){

  int a, b, k;
  cin >> a >> b >> k;

  vi res;
  for(int i=a; i<a+k; ++i){
    if( i>b ) break;
    res.push_back(i);
  }
  for(int i=b; i>b-k; --i){
    if( i<a ) break;
    res.push_back(i);
  }

  sort(res.begin(), res.end());
  res.erase(unique(res.begin(), res.end()), res.end());

  for(auto i : res) cout << i << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int[] a = sc.nextIntArray(n);
		
		int res = 0;
		
		for(int i : a) {
			res+=(2*i-1)%i;
		}
		
		out.println(res);
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static int lcm(int a, int b) {
		return (a * b) / gcd(a, b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 22484