akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    cout << n*800 - n/15*200 << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

vector<vector<int> > memo(MAX_N,vector<int>(18,INF));
int t[18];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    int hoge = 1;
    rep(i,18){
        t[i] = hoge;
        hoge *= 2;
    }
    int mx = 0;
    int bf = n;
    while(bf){
        bf /= 2;
        mx++;
    }
    mx--;
    int L;
    cin >> L;
    rep(i,n-1){
        int id = upper_bound(all(vec),vec[i]+L) - vec.begin();
        memo[i][0] = id-1;
    }
    memo[n-1][0] = INF;
    for(int i=1;i<mx;i++){
        rep(j,n){
            if(memo[j][i-1] < n){
                memo[j][i] = memo[memo[j][i-1]][i-1];
            }else{
                memo[j][i] = INF;
            }
        }
    }
    // rep(i,n){
    //     rep(j,mx){
    //         cout << memo[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    int Q;
    cin >> Q;
    rep(i,Q){
        int x,y;
        cin >> x >> y;
        x--,y--;
        int a,b;
        a = min(x,y),b = max(x,y);
        int cnt = 0;
        while(1){
            int id = upper_bound(all(memo[a]),b) - memo[a].begin();
            // if(cnt == 0){
            //     show(a),show(b),show(id);
            // }
            if(id == 0){
                cout << cnt+1 << endl;
                break;
            }
            cnt += t[id-1];
            if(memo[a][id-1] == b){
                cout << cnt << endl;
                break;
            }else{
                a = memo[a][id-1];
            }
        }
    }
    return 0;
}


Measured memory_bytes: 11392
import java.util.Scanner;
class Main{
    public static int[] Efunc(int[] dice){
        int[] newdice = new int[6];
        newdice[0] = dice[3];
        newdice[1] = dice[1];
        newdice[2] = dice[0];
        newdice[3] = dice[5];
        newdice[4] = dice[4];
        newdice[5] = dice[2];
        return newdice;
    }
    public static int[] Wfunc(int[] dice){
        int[] newdice = new int[6];
        newdice[0] = dice[2];
        newdice[1] = dice[1];
        newdice[2] = dice[5];
        newdice[3] = dice[0];
        newdice[4] = dice[4];
        newdice[5] = dice[3];
        return newdice;
    }
    public static int[] Nfunc(int[] dice){
        int[] newdice = new int[6];
        newdice[0] = dice[1];
        newdice[1] = dice[5];
        newdice[2] = dice[2];
        newdice[3] = dice[3];
        newdice[4] = dice[0];
        newdice[5] = dice[4];
        return newdice;
    }
    public static int[] Sfunc(int[] dice){
        int[] newdice = new int[6];
        newdice[0] = dice[4];
        newdice[1] = dice[0];
        newdice[2] = dice[2];
        newdice[3] = dice[3];
        newdice[4] = dice[5];
        newdice[5] = dice[1];
        return newdice;
    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int[] dice = new int[6];
        for(int i = 0; i < 6; i++)dice[i] = scanner.nextInt();
        String cmdline = scanner.next();
        char cmd;
        for(int i = 0; i < cmdline.length(); i++){
            cmd = cmdline.charAt(i);
            if(cmd == 'E')dice = Efunc(dice);
            else if(cmd == 'S')dice = Sfunc(dice);
            else if(cmd == 'W')dice = Wfunc(dice);
            else if(cmd == 'N')dice = Nfunc(dice);
        }
        System.out.println(dice[0]);
    }
}


Measured memory_bytes: 26244
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
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)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

ll a[100010];
ll dp[100010];
int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N,M;cin >> N >> M;
    REP(i,M) cin >> a[i];
    dp[0] = 1;
    if(a[0]!=1) dp[1] = 1;
    rep(i,2,N+1){
        if(!binary_search(a,a+M,i)){
            dp[i] = (dp[i] + dp[i-1] + dp[i-2])%MOD;
        }
    }
    cout << dp[N] << '\n';

    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;
string s;
int main() {
    cin >> s;
    bool ok = true;
    int n = s.length();
    for (int i = 1; i < n; ++i) {
        if (s[i] == s[i - 1]) {
            ok = false;
            break;
        }
    }
    if (ok)
        cout << "Good" << endl;
    else
        cout << "Bad" << endl;
    return 0;
}


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


int main()
{
	int a,p, pies;
	cin >> a >> p;
	p = a * 3 + p ;
	if(p % 2 == 0)
		pies = p/2;
	else
		pies = (p-1)/2;
	cout << pies;
	
	
}	


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll gcd(ll x, ll y) {
    if(y == 0) {
        return x;
    }
    return gcd(y, x%y);
}

ll GCD(vl &v) {  // vの全要素のgcd
    ll res = v[0];
    rep(i, v.size()) {
        res = gcd(res, v[i]);
    }
    return res;
}

int main() {
    ll n;
    cin >> n;
    vl x(n+1);
    cin >> x[0];

    exrep(i, 1, n) {
        cin >> x[i];
    }
    sort(all(x));

    vl v;
    rep(i, n) {
        v.pb(x[i+1] - x[i]);
    }

    out(GCD(v));
    re0;
}

Measured memory_bytes: 2168
#include<stdio.h>
int main()
{
    int a,i;
    double t=0,m;
    double e,f,g=0,a1;
    scanf("%d",&a);
    while(a!=0)
    {
        int x[a];
        for(i=0;i<a;i++)
        {
            scanf("%d",&x[i]);
        }
        for(i=0;i<a;i++)
        {
            t=t+x[i];
        }
        m=t/a;
        for(i=0;i<a;i++)
        {
            if(x[i]<m || x[i]==m)
            {
                e=(m-x[i])*(m-x[i]);
                g=g+e;
            }
            else if(x[i]>m)
            {
                e=(x[i]-m)*(x[i]-m);
                g=g+e;
            }
        }
        a1=a;
        f=sqrt(g/a1);
        printf("%.8lf\n",f);
        t=0;
        g=0;
        scanf("%d",&a);
    }
    return 0;
}



Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

vector<vector<pair<int, P>>> num(90000, vector<pair<int, P>>(0));

ll func(int i, int j){
  if(j == 0) return 0;
  ll y1 = num.at(i).at(j-1).second.first;
  ll x1 = num.at(i).at(j-1).second.second;
  ll y2 = num.at(i).at(j).second.first;
  ll x2 = num.at(i).at(j).second.second;
  return abs(y2 - y1) + abs(x2 - x1);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll H, W, D;
  cin >> H >> W >> D;
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W ; j++){
      ll A;
      cin >> A;
      A--;
      num.at(A%D).push_back(make_pair(A, P(i, j)));
    }
  }
  for(int i = 0; i < D; i++){
    sort(ALL(num.at(i)));
  }
  vvll sum(D, vll(1, 0));
  for(int i = 0; i < D; i++){
    for(int j = 0; j < num.at(i).size(); j++){
      sum.at(i).push_back(sum.at(i).at(j) + func(i, j));
    }
  }
  ll Q;
  cin >> Q;
  vll ans(0);
  for(int i = 0; i < Q; i++){
    ll L, R;
    cin >> L >> R;
    L--; R--;
    ans.push_back(sum.at(L%D).at(R/D+1) - sum.at(L%D).at(L/D+1));
  }
  for(auto x: ans) cout << x << endl;
}

Measured memory_bytes: 11256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;


int main(){
   int n,m;
   cin>>n>>m;
   vector<int> p(m),y(m);
   vector<tuple<int,int,int>> a(m);

   for(int i=0;i<m;i++){
      cin>>p[i]>>y[i];
      a[i]=make_tuple(p[i],y[i],i);
   }

   sort(a.begin(),a.end());
   vector<string> ans(m);
   fill(ans.begin(),ans.end(),"000000");
   int cnt=1;
   ans[get<2>(a[0])]=ans[get<2>(a[0])].substr(0,6-to_string(get<0>(a[0])).size())+to_string(get<0>(a[0]))+ans[get<2>(a[0])].substr(0,6-to_string(1).size())+to_string(1);
   for(int i=1;i<m;i++){
      if(get<0>(a[i])!=get<0>(a[i-1]))cnt=1;
      else cnt++;
      string s1=to_string(get<0>(a[i]));
      string s2=to_string(cnt);
      ans[get<2>(a[i])]=ans[get<2>(a[i])].substr(0,6-s1.size())+s1+ans[get<2>(a[i])].substr(0,6-s2.size())+s2;
   }
   for(int i=0;i<m;i++)cout<<ans[i]<<endl;

}

   


Measured memory_bytes: 5888
#include <iostream>

using namespace std;
int a, b, c, x;
int main()
{
    int cnt = 0;
    cin >> a >> b >> c >> x;
    for(int i = 0; i <= a; ++i)
        for(int j = 0; j <= b; ++j)
                for(int k = 0; k <= c; ++k)
                    if(i * 500 + j * 100 + k * 50 == x)cnt ++;
    cout << cnt;
    return 0;
}


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

int n;
int main() {
  cin >> n;
  long long h[n];
  string ans = "Yes";
  for(int i = 0; i < n; i++) cin >> h[i];
  for(int i = n-2; i > 0; i--){
    if(h[i]>h[i+1]) h[i]--;
     if(h[i]>h[i+1]){
      ans = "No";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4364
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  string str;
  cin>>str;
  if(str.size()==2){
    cout<<str<<endl;
  }
  else{
    cout<<str[2]<<str[1]<<str[0]<<endl;
  }
  return 0;

}


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

int main()
{
  int N, M;
  cin >> N >> M;
  
  const int NMMAX = 50;
  int A[NMMAX], B[NMMAX], road[NMMAX];
  
  for(int i = 0; i < M; ++i)
  {
    cin >> A[i] >> B[i];
  }

  for(int i = 0; i < N; ++i)
  {
    road[i] = 0;
  }
  
  for(int i = 0; i < M; ++i)
  {
    road[A[i] - 1]++;
    road[B[i] - 1]++; 
  }
  
  for(int i = 0; i < N; ++i)
  {
    cout << road[i] << endl;
  }
}


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;
const ll M = 1e15;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

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

  if(x==0) cout << 1 << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

int n;
vector<int> tree[1005];
int x[1005];
int tree_dp[1005];

bool memo_rec(int u){
    if(tree[u].size() == 0){
        tree_dp[u] = 0;
        return true;
    }

    bitset<5001> dp = 1;
    int sum = 0;
    for(int v : tree[u]){
        if(!memo_rec(v))    return false;
        dp = (dp << x[v]) | (dp << tree_dp[v]);
        sum += x[v] + tree_dp[v];
    }
    for(int i = x[u]; i >= 0; --i){
        if(dp[i]){
            tree_dp[u] = sum - i;
            return true;
        }
    }
    return false;
}

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

    cin >> n;
    for(int i = 1; i < n; ++i){
        int p;
        cin >> p;
        --p;
        tree[p].push_back(i);
    }
    for(int i = 0; i < n; ++i)  cin >> x[i];
    
    if(memo_rec(0)) cout << "POSSIBLE\n";
    else    cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 1664
#include<iostream>
#include<bitset>
using namespace std;
string a;
char b[3];

void solve() {
  for(int bit = 0; bit < (1<<3); bit++) {
    int result = a[0] - '0';
    
    for(int i = 0; i < 3; i++) {
      if(bit & (1<<i)) {
        result += a[i + 1] - '0';
        b[i] = '+';
      } else {
        result -= a[i + 1] - '0';
        b[i] = '-';
      }
    }

    if(result == 7) {
      for(int i = 0; i < 3; i++) {
        cout << a[i] << b[i];
      }
      cout << a[3] << '=' << 7 << endl;
      break;
    }
  }
}

int main() {
  cin >> a;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[N];

int main()
{
    fast;

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

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

    cout << (a ^ b ^ 1 ^ 2 ^ 3);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
for j in range(N):
    if X[j][2] != 0:
        k = j
        break
A = X[j]
for cx in range(101):
    for cy in range(101):
        H = A[2] + abs(A[0] - cx) + abs(A[1] - cy)
        Flag = True
        for i in range(N):
            if max(H - abs(X[i][0] - cx) - abs(X[i][1] - cy), 0) != X[i][2]:
                Flag = False
                break
        if Flag:
            print(cx, cy, H)
            break
    if Flag:
        break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N;
  cin >> N;
  vll d(N);
  rep(i, N) {
    cin >> d[i];
  }

  SORT(d);
  ll l = d[N / 2 - 1];
  ll r = d[N / 2];
  if (r - l < 0) {
    COUT(0);
  } else {
    COUT(r - l);
  }
  return 0;
}

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



int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll h,w,n;
	cin>>h>>w>>n;
	int mini=INT_MAX;

	for(int i=0;i<=h;i++)
	{
		for(int j=0;j<=w;j++)
		{
			if(w*i+h*j>=n+i*j)
			{
				mini=min(mini,i+j);
			}
		}
	}    
	cout<<mini<<endl;
    
    

    
	return 0;
	
	
}

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

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

    int n; cin >> n;
    vector<int> extracted(26, 50*50+1);

    for (int i = 0; i < n; ++i) {
        string S; cin >> S;
        vector<int> cnt(26);
        for (auto& s : S) cnt[s - 'a']++;
        for (int j = 0; j < 26; ++j) {
            extracted[j] = min(extracted[j], cnt[j]);
        }
    }

    for (int i = 0; i < 26; ++i) {
        for (int j = 0; j < extracted[i]; ++j) {
            cout << (char)(i + 'a');
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
 
int main(){
    int r,d;
    vector<int> x(20);
    cin >> r >> d >> x[0];
    rep(i,10){
        x[i+1] = r * x[i] - d;
        cout << x[i+1] << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process()throws IOException
    {
       int n = ni(), arr[] = new int[n+1], res = 0;
       for(int i = 1; i <= n; i++) arr[i] = ni();
       for(int i = 1; i <= n; i++)
            if((arr[i] % 2 == 1) && (i % 2== 1))
                res++;
        pn(res);
    }
 
    static final long mod = (long)1e9+7l;
    
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc = new FastReader();
 
        long s = System.currentTimeMillis();
        int t = 1;
        //t = ni();
        while(t-- > 0)
            process();
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }

    static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };
    static void pn(Object o){ out.println(o); }
    static void p(Object o){ out.print(o); }
    static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
    static long nl()throws IOException{ return Long.parseLong(sc.next()); }
    static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
    static String nln()throws IOException{ return sc.nextLine(); }
    static long gcd(long a, long b)throws IOException{ return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{ return (b==0)?a:gcd(b,a%b); }
    static int bit(long n)throws IOException{ return (n==0)?0:(1+bit(n&(n-1))); }
    
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 36700
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <utility>
#include <set>

using llint = long long int;
using namespace std;

namespace CsF {
#define MIN_INT -2147483648
#define MAX_INT 2147483647

#define nfor(I,J,K) for(int I = 0;I < J;I+=K)


	string ConvertBit(int N, int e) {
		string s = "";
		int r = 0;
		while (N != 0) {
			r = N % e;
			s = to_string(r) + s;
			N -= r;
			N /= e;
		}
		return s;
	}

	int GCD(int a, int b) {
		if (a < b)swap(a, b);
		int r = a % b;
		while (r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}

	int LCM(int a, int b) {
		int n = a * b;
		return (n / GCD(a, b));
	}

	int Count(string s, char c) {
		int cou = 0;
		nfor(i, s.length(), 1) {
			if (s[i] == c)cou++;
		}
		return cou;
	}

	vector<int> SieveOfEratosthenes(int N) {
		vector<bool> memo(N + 1);
		vector<int> ret;
		memo[0] = true;
		memo[1] = true;
		for (int i = 2; i < N; i++) {
			if (memo[i])continue;
			ret.push_back(i);
			for (int b = 2; true; b++) {
				if (i*b <= N) {
					memo[i*b] = true;
				}
				else break;
			}
		}
		return ret;
	}
}

using namespace CsF;


int main() {
	int a, b;
	cin >> a >> b;
	cout << (a % b == 0 ? 0 : 1) << endl;
	return 0;
}



Measured memory_bytes: 256
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST

solve ps qs n = abs $ a - b
  where
    perm = sort $ permutations [1..n]
    Just a = elemIndex ps perm
    Just b = elemIndex qs perm

main = do
  n <- readLn :: IO Int
  ps <- map read . words <$> getLine :: IO [Int]
  qs <- map read . words <$> getLine :: IO [Int]
  print $ solve ps qs n


Measured memory_bytes: 20988
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<time.h>
#include<climits>
#include<string>
//#define IONAME "cttf"
//#define E_DEBUG
//#define TIMECOMP

int n,k,a[111000],dp[111000];

void marota(){
    std::cin>>n>>k;
    for (int i=1;i<=n;i++){
        std::cin>>a[i];
    }   
    a[0]=a[1];
    for (int i=2;i<=n;i++){
        dp[i]=1e9+123;
        int mx=std::max(0,i-k);
        for (int j=mx;j<i;j++){
            dp[i]=std::min(dp[i],dp[j]+std::abs(a[i]-a[j]));
        }
    }
    std::cout<<dp[n];
}

int main(){
    #ifdef TIMECOMP
    clock_t tStart = clock();
    #endif
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    #if defined(IONAME)
    freopen(IONAME".INP","r",stdin);
    freopen(IONAME".OUT","w",stdout);
    #endif
    marota();
    #ifdef TIMECOMP
    printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    #endif
    return 0;
}

Measured memory_bytes: 4396
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    String N = sc.next();
    int sum = 0;
 
    for(int i = 0; i < N.length(); i++){
      int a =Integer.parseInt(N.substring(i, i+1)); 
      sum += a;
    }
    
    int total = Integer.parseInt(N);
    String output = null;
    
    output = (total % sum == 0) ? "Yes":"No";
    System.out.println(output);
  }
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int f[N];
struct P{int id,fa;ll c[2];}a[N];
inline bool operator <(P x,P y){return x.c[1]*y.c[0]>y.c[1]*x.c[0];}
priority_queue<P> q;
int findf(int x){return f[x]==x?x:f[x]=findf(f[x]);}
int main()
{	int n,col; ll ans=0; cin>>n;
	for(rint i=2;i<=n;i++) scanf("%d",&a[i].fa);
	for(rint i=1;i<=n;i++) scanf("%d",&col),a[i].c[col]=1,f[i]=a[i].id=i;
	for(rint i=2;i<=n;i++) q.push(a[i]);
	while(!q.empty())
	{	P x=q.top(); q.pop();
		if(a[x.id].c[0]!=x.c[0]||a[x.id].c[1]!=x.c[1]) continue;
		int y=f[x.id]=findf(x.fa); ans+=a[y].c[1]*x.c[0];
		a[y].c[0]+=x.c[0]; a[y].c[1]+=x.c[1]; if(y>1) q.push(a[y]);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 16624
# 19
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')

n = I()
s = SR(n)
set_c = set(list(s[0]))
for elem in s:
    set_c = set_c & set(list(elem))
# print(set_c)
s = sorted(s, key=lambda x: len(x))[::-1]
d = {k: 51 for k in set_c}
for elem in s:
    c = Counter(list(elem))
    for k in d.keys():
        if k in c.keys():
            d[k] = min(d[k], c[k])
# print(d)
d = sorted(d.items(), key=lambda x: x[0])
# print(d)
ans = ''
for k, v in d:
    ans += k * v
print(ans)


Measured memory_bytes: 9496
import sys
n = int(input())
a = [int(input()) for a in range(n)]
cnt = 1
a.insert(0,0)
if a[1] ==2:
	print(1)
	sys.exit()
sel = a[1]
for i in range(n+1):
	if a[sel] == 2:
		cnt += 1
		print(cnt)
		sys.exit()
	else:
		cnt += 1
		sel = a[sel]
print(-1)

Measured memory_bytes: 13004
#include <stdio.h>
#include <string.h>
int main(void)
{
	int i,previous,next;
	char input[256],sum[256];
	char* p;
	while(fgets(input, sizeof(input),stdin))
	{
		sscanf(input,"%d %d\n",&previous,&next);
		sprintf(sum, "%d", previous + next);
		printf("%d\n",strlen(sum));
	}
	return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n;
	vector<int> p(n);
	int ra[n+1];
	for(int i=0;i<n;i++){
		cin >> p[i];
		ra[p[i]]=i;
	}
	ll ans=0;
	set<int> S;
	S.insert(-1); S.insert(n);
	for(ll d=1;d<=n;d++){
		int i=ra[d];
		auto it=S.lower_bound(i);
		int r=*it;
		it--;
		int l=*it;
		ans+=d*(i-l)*(r-i);
		S.insert(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
// AGC 032B
// DeP
#include <cstdio>

const int MAXN = 105 * 105 / 2;

int n, m;
int u[MAXN], v[MAXN];

int main() {
    scanf("%d", &n);
    if (n & 1) {
        for (int i = 1; i <= n; ++i)
            for (int j = i + 1; j <= n; ++j)
                if (j != n - i) u[++m] = i, v[m] = j;
    } else {
        for (int i = 1; i <= n; ++i)
            for (int j = i + 1; j <= n; ++j)
                if (j != n - i + 1) u[++m] = i, v[m] = j;
    }
    printf("%d\n", m);
    for (int i = 1; i <= m; ++i) printf("%d %d\n", u[i], v[i]);
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  i64 N, A, B;
  cin >> N >> A >> B;
  vi64 X(N); cin >> X;
  i64 ans = 0;
  rep(i, N - 1) {
    ans += min((X[i + 1] - X[i]) * A, B);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 1024
// AOJ 1552: Mountain Climbing
// 2019.2.21 bal4u

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

#define gc() getchar()
int in()
{
	int n = 0, c = gc();
	if (c == '-') {
		c = gc();
		do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int cnt[5];

int main()
{
	int N, aa, a, f, zero;

	N = in();
	f = zero = 0;
	aa = in();
	while (--N) {
		a = in();
		if (a < aa) {
			if (f == 1) {
				if (zero) cnt[0]++;
				else cnt[3]++;
			}
			else if (f == -1) {
				if (zero) cnt[2]++;
			}
			f = -1, zero = 0;
		}
		else if (a > aa) {
			if (f == 1) {
				if (zero) cnt[2]++;
			}
			else if (f == -1) {
				if (zero) cnt[1]++;
				else cnt[4]++;
			}
			f = 1, zero = 0;
		}
		else zero = 1;
		aa  = a;
	}
	printf("%d %d %d %d %d\n", cnt[0], cnt[1], cnt[2], cnt[3], cnt[4]);
	return 0;
}


Measured memory_bytes: 2064
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[]v = new int[n];
		for(int i = 0; i < n; i++) {
			v[i] = scan.nextInt();
		}
		scan.close();
		Map<Integer, Integer> map1 = new HashMap<Integer, Integer>();
		Map<Integer, Integer> map2 = new HashMap<Integer, Integer>();
		for(int i = 0; i < n/2; i++) {
			map1.merge(v[2 * i], 1, (val1, val2) -> (val1 + val2));
			map2.merge(v[2 * i + 1], 1, (val1, val2) -> (val1 + val2));
		}
		if(map1.size() == 1 && map2.size() == 1) {
			if(v[0] != v[1]) {
				System.out.println(0);
			}else {
				System.out.println(n/2);
			}
			System.exit(0);
		}
		if(map1.size() == 1) {
			int kMax = -1;
			int max = 0;
			for(int k : map2.keySet()) {
				if(max < map2.get(k)) {
					kMax = k;
					max = map2.get(k);
				}
			}
			if(v[0] != kMax) {
				int ans = n/2 -  map2.get(kMax);
				System.out.println(ans);
			}else {
				int t = kMax;
				kMax = -1;
				max = 0;
				for(int k : map2.keySet()) {
					if(max < map2.get(k) && k != t) {
						kMax = k;
						max = map2.get(k);
					}
				}
				int ans = n/2 - map2.get(kMax);
				System.out.println(ans);
			}
			System.exit(0);
		}
		if(map2.size() == 1) {
			int kMax = -1;
			int max = 0;
			for(int k : map1.keySet()) {
				if(max < map1.get(k)) {
					kMax = k;
					max = map1.get(k);
				}
			}
			if(v[1] != kMax) {
				int ans = n/2 - map1.get(kMax);
				System.out.println(ans);
			}else {
				int t = kMax;
				kMax = -1;
				max = 0;
				for(int k : map1.keySet()) {
					if(max < map1.get(k) && k != t) {
						kMax = k;
						max = map1.get(k);
					}
				}
				int ans = n/2 - map1.get(kMax);
				System.out.println(ans);
			}
			System.exit(0);
		}
		int t0 = 0;
		int t1 = 0;
		int k0 = 0;
		int k1 = 0;
		int kMax = -1;
		int max = 0;
		for(int k : map1.keySet()) {
			if(max < map1.get(k)) {
				kMax = k;
				max = map1.get(k);
			}
		}
		t0 = kMax;
		kMax = -1;
		max = 0;
		for(int k : map1.keySet()) {
			if(max < map1.get(k) && k != t0) {
				kMax = k;
				max = map1.get(k);
			}
		}
		t1 = kMax;
		kMax = -1;
		max = 0;
		for(int k : map2.keySet()) {
			if(max < map2.get(k)) {
				kMax = k;
				max =  map2.get(k);
			}
		}
		k0 = kMax;
		kMax = -1;
		max = 0;
		for(int k : map2.keySet()) {
			if(max < map2.get(k) && k != k0) {
				kMax = k;
				max = map2.get(k);
			}
		}
		k1 = kMax;
		if(k0 != t0) {
			int ans = n - map1.get(t0) - map2.get(k0);
			System.out.println(ans);
			System.exit(0);
		}else {
			int m1 = n - map1.get(t0) - map2.get(k1);
			int m2 = n - map1.get(t1) - map2.get(k0);
			int ans = Math.min(m1, m2);
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 59936
import itertools
import numpy as np

N, D = list(map(int, input().split()))
X_LIST = []
for _ in range(N):
    X_LIST.append(list(map(int, input().split())))

ans = 0
for x1, x2 in itertools.combinations(X_LIST, 2):
    distance = np.linalg.norm(np.array(x1) - np.array(x2))
    if distance.is_integer():
        ans += 1
print(ans)

Measured memory_bytes: 12508
import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=1
c=0
l=0
r=-1
c1=0
while True:
    if k-c>=2:
        if a[r]*a[r-1]>a[l]*a[l+1]:
            s*=a[r]*a[r-1]
            r-=2
            c+=2
        else:
            s*=a[l]*a[l+1]
            l+=2
            c+=2
    else:
        if a[r]<0:
            s=1
            a=np.absolute(a)
            a=list(a)
            a.sort()
            while True:
                s*=a[c1]
                c1+=1
                s%=10**9+7
                if c1==k:
                    s=-s
                    print(s%10**9+7)
                    exit()
        else:s*=a[r]
        c+=1
    s%=10**9+7
    if k==c:break
print(s)

Measured memory_bytes: 49788
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define int ll
vector<ll> node[100005];
ll group[100005]={0},group_num[100005]={0},col[100005]={0};
ll nibu[100005]={0};
bool used[100005]={0};
bool dfs(ll pos,ll k,ll cl){
  used[pos]=true;
  group[pos]=k;
  col[pos]=cl;
  ll nc=cl%2;
  nc++;
  bool res=true;
  for(int i=0;i<node[pos].size();i++){
    ll to=node[pos][i];
    if(!used[to]){
      used[to]=true;
      dfs(to,k,nc);
    }
    if(col[to]!=nc){
      res=false;
    }
  }
  return res;
}
signed main(){
  ll n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    ll s,t;
    cin>>s>>t;
    node[s].push_back(t);
    node[t].push_back(s);
  }
  for(int i=1;i<=n;i++) used[i]=false;
  ll cnct_num=0,a=0,b=0,c=0;
  for(int i=1;i<=n;i++){
    if(!used[i]){
      used[i]=true;
      group[i]=cnct_num;
      if(node[i].size()==0) {
        c++;
        continue;
      }
      bool f=dfs(i,cnct_num,1);
      b++;
      cnct_num++;
    }
  }
 for(int i=1;i<=n;i++){
    for(int j=0;j<node[i].size();j++){
      ll to=node[i][j];
      if(col[i]==col[to]){
        nibu[group[i]]=1;
      }
    }
  }
  for(int i=0;i<cnct_num;i++){
    if(nibu[i]==1){
      b--;
      a++;
    }
  }
  cout<<a*a+2*a*b+2*b*b+c*(n*2-c)<<endl;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s;
    cin >> s;

    int64_t m = s.size();

    vector a(1, 0L);
    int64_t t = 0;
    for (auto c : s) {
        if (c == '0') {
            a.push_back(t);
        } else {
            ++t;
        }
    }
    a.push_back(t);

    int64_t k;
    cin >> k;
    k = min(k, a.back());

    int64_t n = a.size();

    constexpr auto M = 998244353L;

    vector dp(vector(k + 1, vector(a.back() + 1, 0L)));
    int64_t mk = 0;
    dp[0][0] = 1;
    for (auto i : irange(0L, n - 1)) {
        for (auto j : irange(mk, -1L, -1L)) {
            auto r = min(k - j, a[i + 1] - a[i]);
            for (auto c : irange(0L, a.back() - a[i + 1] + 1)) {
                for (auto b : irange(c + 1, c + r + 1)) {
                    auto w = j + b - c;
                    dp[w][c] += dp[j][b];
                    if (dp[w][c] >= M) {
                        dp[w][c] -= M;
                    }
                }
            }
            mk = max(mk, j + r);

            for (auto c : irange(1L, a.back() - a[i + 1] + 1)) {
                dp[j][c] += dp[j][c - 1];
                if (dp[j][c] >= M) {
                    dp[j][c] -= M;
                }
            }
        }
        // mk = min(k, mk + a[i + 1] - a[i]);
    }

    int64_t ans = 0;
    for (auto i : irange(0L, mk + 1)) {
        ans += dp[i][0];
        if (ans >= M) {
            ans -= M;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
//#define int long long int
#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define pb push_back
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define DEBUG false
#pragma GCC optimize "trapv"

void solve(int arr[][3],int n)
{
    int dp[n][3];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<3;i++)
    dp[0][i]=arr[0][i];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+arr[i][2];
    }
    int ans=0;
    for(int i=0;i<3;i++)
    ans=max(ans,dp[n-1][i]);
    cout<<ans<<'\n';
   /* for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
}
int main()
{
    nitro;
    int n,k;
    cin>>n;
    int arr[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        cin>>arr[i][j];
    }
    solve(arr,n);
return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<numeric>

int main(){
    int H, N;
    std::cin >> H;
    std::cin >> N;
    int A;
    std::vector<int> Ai;
    for(int i=0; i<N; i++){
        std::cin >> A;
        Ai.push_back(A);
    }

    int A_sum = std::accumulate(Ai.begin(), Ai.end(),0);
    if (A_sum >= H){
        std::cout<< "Yes";
    }else{
        std::cout << "No";
    }
    
    return 0;
}


Measured memory_bytes: 892
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

const int N = 111, K = 4;
ll dp[N][K][2];

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

    int n = s.size();
    dp[0][0][0] = 1;
    rep(i, n) rep(j, k + 1) rep(x, 2) {
        int v = s[i] - '0';

        int r = v;
        if (x == 1) r = 9;
        rep(y, r + 1) {
            int nj = j;
            if (y > 0) ++nj;
            if (nj > k) continue;

            int nx = x;
            if (y < r) nx = 1;
            dp[i + 1][nj][nx] += dp[i][j][x];
        }
    }

    ll ans = 0;
    rep(i, 2) ans += dp[n][k][i];
    cout << ans << "\n";
    return 0;
}


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

int main() {
  vector<long> a(4);
  for(int i=0;i<6;i++){
    int x;
    cin>>x;
    a[x-1]++;
  }
  sort(a.begin(),a.end());
  int b[4]={1,1,2,2};
  bool flg=false;
  for(int i=0;i<4;i++){
    if(a[i]!=b[i]) continue;
    if(i==3) flg=true;
  }
  if(flg) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


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

signed main(){
	int n,ma=0;
	cin>>n;
	vector<int>a(n),b(n),c(n);
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(i){
			a[i]=x+a[i-1];
		}
		else{
			a[0]=x;
		}
	}
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	for(int i=n-1;i>=0;i--){
		if(i==n-1)b[i]=c[i];
		else{
			b[i]=b[i+1]+c[i];
		}
	}
	for(int i=0;i<n;i++){
		ma=max(ma,a[i]+b[i]);
	}
	cout<<ma<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())

    ans = defaultdict(int)
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                n = x * x + y * y + z * z + x * y + y * z + z * x
                ans[n] += 1

    for i in range(1, N + 1):
        print(ans[i])


main()


Measured memory_bytes: 72144
#include<cstdio>
#include<algorithm>

using namespace std;
const int maxn=1e5+5;
int dp[maxn],a[maxn];

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


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

int main(){
	int n;
	while(cin>>n){
		int ans=0;
		for(int i=1;i*n<600;i++){
			ans+=(i*n)*(i*n)*n;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back
#define eps 1e-10


int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    map<pii, int> mp;
    vector<pii> v;
    rep(i, n) {int x, y; cin >> x >> y; v.eb(x, y); mp[{x, y}] = 1;}
    int ans = 0;
    rep(i, n) {
        rep(j, n) {
            if (i == j) continue;
            int p = v[i].first - v[j].first;
            int q = v[i].second - v[j].second;
            int c = 0;
            rep(k, n) {
                if (mp[{v[k].first + p, v[k].second + q}]) {
                    c++;
                }
            }
            chmax(ans, c);
        }
    }
    cout << n - ans << endl;
}


Measured memory_bytes: 4096