akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define int long long 


signed main(){
    string S;
    string T;
    cin >> S;
    bool ex[26]={};
    for(int i=S.size()-1;i>=0;i--){
        if(i==0)continue;
        if(S[i]>S[i-1]){
            T=S.substr(0,i);
            //cout << T << endl;
            REP(j,T.size()){
                ex[T[j]-'a']=1;
            }
            REP(j,26){
                if(ex[j]==0 && (char)('a'+j)>T[T.size()-1]){
                    T[T.size()-1]=(char)('a'+j);
                    break;
                }
            }
            break;
        }
    }
    REP(i,26){ex[i]=0;}
    REP(i,S.size()){
        ex[S[i]-'a']=1;
    }
    REP(i,26){
        if(ex[i]==0){
            cout << S << (char)('a'+i) << endl;
            return 0;
        }
    }
    if(!T.empty()){
        cout << T << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  ll N = s.size();
  ll K;
  cin >> K;

  bool allsame = true;
  for(int i = 0; i < N - 1; i++){
    if(s[i] != s[i + 1]) allsame = false;
  }

  if(allsame){
    ll ans = N * K / 2;
    cout << ans << endl;
    return 0;
  }

  string t = s + s;

  ll cnts = 0;
  for(int i = 0; i < N - 1; i++){
    if(s[i] == s[i + 1]){
      cnts++;
      s[i + 1] = '=';
    }
  }

  ll cntt = 0;
  for(int i = 0; i < 2 * N - 1; i++){
    if(t[i] == t[i + 1]){
      cntt++;
      t[i + 1] = '=';
    }
  }

  ll ans = cnts * K;
  ans -= (K - 1) * (cnts * 2 - cntt);

  //cout << cnts << " " << cntt << endl;

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_vector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_vector(int n, Ts ... ts){
        return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    void run(){
        ll N;
        is >> N;
        if(!is) return;
        vector<ll> L(N);
        for (auto &&l : L) { is >> l; } // end l
        sort(ALL(L));
        ll count = 0;
        for (int i = 0; i < N-1; ++i) {
            for (int j = i + 1; j < N; ++j) {
                auto t = L[i] + L[j];
                auto lb = lower_bound(ALL(L), t);
                if(lb == L.end()){
                    ll lj = N - j-1;
                    count += lj;
                }
                else{
                    ll lj = lb - L.begin() - j-1;
                    if(lj < 0) lj = 0;
                    count += lj;
                }
            } // end j
        } // end i
        os << count << endl;

    }
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_D.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, q = map(int, input().split())


ab_list = [[] for _ in range(n+1) ]
for _ in range(n-1):
  a, b = map(int, input().split())
  ab_list[a].append(b)
  ab_list[b].append(a)
  
px_list = [0]*(n+1)
for _ in range(q):
  p,x = map(int, input().split())
  px_list[p] += x
  
stack = [1]
par_list = [0] * (n+1)

while stack:
  x = stack.pop()
  for y in ab_list[x]:
    if y == par_list[x]:
      continue
    par_list[y] = x
    stack.append(y)
    px_list[y] += px_list[x]

print(' '.join(str(i) for i in px_list[1:]))

Measured memory_bytes: 123084
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<pair<ll, ll>> vec(n);
    rep(i, 0, n)
    {
        ll a, b;
        cin >> a >> b;
        vec[i].first = b;
        vec[i].second = a;
    }
    sort(all(vec));
    ll time = 0;
    cout << endl;
    rep(i, 0, n)
    {
        time += vec[i].second;
        if (time > vec[i].first)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;

int parents[100010];
int ranks[100010];

// trees[x] -> y, x?????????y
// ??\???????????¨?§?????????±
int trees[100010]; 

void initUnionFind() {
    for (int i=0; i<100010; ++i) {
        parents[i] = i;
        ranks[i] = 1;
    }
}
int findParent(int x) {
    if (x == parents[x]) return x;
    return parents[x] = findParent(parents[x]);
}

int main() {
    int N,Q;

    while (cin >> N >> Q) {
        if (N == 0 && Q == 0) break;

        initUnionFind();
        for (int i=0; i<100010; ++i) trees[i] = i;

        for (int i=0; i<N-1; ++i) {
            int p; cin >> p;
            parents[i + 2] = p;
            trees[i + 2] = p;
        }

        vector<pair<char, int> > queries;
        for (int i=0; i<Q; ++i) {
            char ope;
            int v;
            cin >> ope >> v;
            // ????????????????????????????????????
            if (ope == 'M' && parents[v] == v) continue;

            // ???????????????
            if (ope == 'M') {
                parents[v] = v;
            }
            queries.push_back( make_pair(ope, v) );
        }

        // ???????????????
        reverse( queries.begin(), queries.end() );
        long long ans = 0;
        for (int i=0; i<queries.size(); ++i) {
            if (queries[i].first == 'M') {
                // mark??????????????????node??¨??£???
                parents[queries[i].second] = trees[queries[i].second];
            } else {
                // ope = 'Q'
                ans += findParent(queries[i].second);
            }
        }

        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5784
def main():
    N,K=map(int,input().split())
    A=[0]+list(map(int,input().split()))
    for i in range(K+1,N+1):
        if A[i]>A[i-K]:
            print("Yes")
        else:
            print("No")
if __name__=='__main__':
    main()

Measured memory_bytes: 105764
#include <bits/stdc++.h>
using namespace std;
    
#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
    
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
    
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
    
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
    
int main(){
    LL N, M;
    string S;
    cin >> N >> M >> S;

    int valid_check = 0;
    REP(i, N+1) {
        if(S[i] == '1') {
            valid_check++;
            
            if(valid_check == M) {
                cout << -1 << endl;
                return 0;
            }
        } else {
            valid_check = 0;
        }
    }

    int prev[100002];
    int cnt[100002];
    prev[0] = -1;

    REP(i, M) {
        if(S[i+1] == '0') {
            prev[i+1] = 0;  
            cnt[i+1] = 1; 
        } else {
            cnt[i+1] = -1;
        }
    }

    VLL skip_index_vec;
    REP1(i, N+1) {
        if (S[i] == '0') {
            REP(j, skip_index_vec.size()) {
                int step = skip_index_vec[j] - i;
                prev[skip_index_vec[j]] = i;
                cnt[skip_index_vec[j]] = cnt[i] + 1;
            }
            skip_index_vec.clear();
            if(i+M < N+1 && S[i+M] == '0') {
                prev[i+M] = i;
                cnt[i+M] = cnt[i] + 1;
            }
        } else if (i+M < N+1  && S[i+M] == '0') {
            skip_index_vec.PB(i+M);
        }
    }

    stack<int> ans;
    int idx = N;
    while(prev[idx] != -1) {
        ans.push(idx - prev[idx]);
        idx = prev[idx];
    }

    while(!ans.empty()) {
        int out = ans.top(); ans.pop();
        cout << out << (ans.empty() ? "\n" : " ");
    }
}

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

int main() {
	int a, b;
	cin >> a >> b;
	string ans = "Impossible";
	if ((a%3 == 0) || (b%3 == 0) || ((a+b)%3 == 0)) ans = "Possible";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
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; }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    int a1,a2,a3;
    cin>>a1>>a2>>a3;
    if(a1+a2+a3>=22)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        #define endl "\n"
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    sort(ALL(a));
    int x = a.back();
    double mn = INF;
    int y = 0;
    REP(i, n) {
        if (chmin(mn, abs(x / 2.0 - a[i]))) {
            y = a[i];
        }
    }
    cout << x << " " << y << endl;
    return 0;
}



Measured memory_bytes: 1024
N = int(input())
A = [int(x) for x in input().split()]

cnt = {}
if N & 1:
    bit = 1
else:
    bit = 0

for a in A:
    if a & bit:
        ans = 0
        break
    if a in cnt:
        cnt[a] += 1
    else:
        cnt[a] = 1

for key in cnt.keys():
    if key == 0 and cnt[key] != 1:
        ans = 0
        break
    if key != 0 and cnt[key] != 2:
        ans = 0
        break
else:
    ans = 2**(N//2) %1000000007
print(ans)


Measured memory_bytes: 19848
N, M = map(int,input().split())

dp = [1]*(N+1)
for i in range(M):
    dp[int(input())]=0

for i in range(1,N+1):
    if dp[i]==1:
        if not i==1:
            dp[i]=dp[i-1]+dp[i-2]
        else:
            dp[i]=dp[i-1]
print(dp[N]%1000000007)

Measured memory_bytes: 470264
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

a = INT()

if a == 0:
    print(0)
    exit()

ans = ''
i = 0
while abs(a) > 0:
    # 小さいビットから見て行って、余るかどうかで値を特定していく
    if a % 2**(i+1) != 0:
        a -= (-2)**i
        ans += '1'
    else:
        ans += '0'
    i += 1
print(ans[::-1])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s.at(i);
  vector<vector<int>> ans(h, vector<int>(w, 0));
  rep(i, h)rep(j, w){
    int di[] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[] = {0, 1, 0, -1, 1, -1, 1, -1};
    if(s.at(i).at(j) == '#'){
      rep(k, 8){
        int ni = i + di[k], nj = j + dj[k];
        if(ni < 0 || h <= ni || nj < 0 || w <= nj) continue;
        if(s.at(ni).at(nj) == '#') continue;
        ans.at(ni).at(nj)++;
      }
    }
  }

  rep(i, h){
    rep(j, w){
      if(s.at(i).at(j) == '#') cout << '#';
      else cout << ans.at(i).at(j);
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
//お勉強中

//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 22;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint();
	int n = 1 << N;
	int dp1[1 << 18], dp2[1 << 18];
	rep(i, n) {
		dp1[i] = getint();
		dp2[i] = 0;
	}

	rep(k, N) {
		int m = 1 << k;
		int m2 = ~(1 << k);
		for (int j = n - 1 & m2; j >= 0; j = j - 1 & m2) {
			int i = j | m;
			int k = min(dp1[i], dp1[j]);
			dp1[i] = max(dp1[i], dp1[j]);
			dp2[i] = max(dp2[i], k);
			dp2[i] = max(dp2[i], dp2[j]);
		}
	}

	int saidai = 0;
	rep1(i, n - 1) {
		saidai = max(saidai, dp1[i] + dp2[i]);
		putint(saidai);
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
#include<cstring>
 
#define ll long long
using namespace std;
long long power(ll  x, ll n){
    if(n==0)return 1;
    ll temp=power(x,n/2);
    if(n%2==0)return temp*temp;
    else return x*temp*temp;
 
}
ll max(ll a,ll b){
    return a>b?a:b;
 
}
 
ll max(ll a,ll b,ll c){
    return max(max(a,b),c);
}
ll min(ll x,ll  y){
    return x+y-max(x,y);
}
ll min(ll x,ll y,ll z){
    return min(min(x,y),z);
 
}
 
 
 
void swap(int* a, int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}
 
bool f(ll x,ll y){
    return x>y;
 
}
 
 
int main(){
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0)sum+=i;
 
 
 
    }
 
cout<<sum;
 
 
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define loop(i,b,a) for(int i = b ; i < a; i ++)
#define rep(i,a) for(int i = 0 ; i < a; i ++)
int main(void){
  const int MAX = 600000;
  bool prime[MAX];
  rep(i,MAX) prime[i] = true;
  
  prime[0] = prime[1] = false;
  vector<int> box;
  loop(i,2,MAX){
    if(prime[i]){
      for(int j = i + i ;  j < MAX ; j += i){
	prime[j] = false;
      }
    }
  }
  
  int n;
  while(cin>>n,n){
  int cnt = 0;
    rep(i,n/2+1){
      if(prime[i] && prime[n-i]){
	cnt++;
	//cout<<i<<" "<<n-i<<endl;
      }
    }
    cout<<cnt<<endl;
  }
  
}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mkp make_pair
const int N=1e5+10;
map<pii ,int > g;
unsigned long long ans[20];
int main()
{
	int h,w,n;
	scanf("%d%d%d",&h,&w,&n);
	ans[0]=1LL*(h-2)*(w-2);
	for(int a,b,i=1;i<=n;i++){
		scanf("%d%d",&a,&b);
		for(int j=0;j<3;j++)
		for(int k=0;k<3;k++)
		if(a+j<=h&&a+j>=3&&k+b<=w&&k+b>=3)
		{	
			ans[ g[mkp(a+j,b+k)] ]--;
			ans[ ++g[mkp(a+j,b+k)] ]++;
		}
	}
	for(int i=0;i<10;i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 56448
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main(){
    map<long long,long long> p;
    long long n,x,t=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x;
        t+=p[i-x];
        p[i+x]++;
    }
    cout<<t;
}

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

int main(){
    int n;
    string d;
    char ch[12];
    map<string,bool> T;
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> d >> ch;
        if(d=="insert"){
            T[string(ch)] = true;
        }else if(d=="find"){
            if(T[string(ch)]) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 47420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

    int s,w;
    cin >> s >> w;
    if(s<=w)cout << "unsafe" << endl;
    else cout << "safe" << endl;
    
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>

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

struct Dice {
    int top, bottom, right, left, front, back;
    void reset() {
        top = 1, bottom = 6, right = 3, left = 4, front = 2, back = 5;
    }
    void operation(std::string s) {
        int tmp;
        if (s == "North") {
            tmp = top, top = front, front = bottom, bottom = back, back = tmp;
        } else if (s == "East") {
            tmp = top, top = left, left = bottom, bottom = right, right = tmp;
        } else if (s == "West") {
            tmp = top, top = right, right = bottom, bottom = left, left = tmp;
        } else if (s == "South") {
            tmp = top, top = back, back = bottom, bottom = front, front = tmp;
        } else if (s == "Right") {
            tmp = front, front = right, right = back, back = left, left = tmp;
        } else if (s == "Left") {
            tmp = front, front = left, left = back, back = right, right = tmp;
        }
    }
};

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

    int n;
    std::string s;
    Dice c;
    while (std::cin >> n && n) {
        c.reset();
        int total = 1;
        rep(i, n) {
            std::cin >> s;
            c.operation(s);
            total += c.top;
        }
        std::cout << total << std::endl;
    }
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	
	// ll t;
	// cin>>t;
	// while(t--)
	{
	  ll n,k;
	  cin>>n>>k;
	  vector<ll> v;
	  for(ll i=0;i<n;i++)
	  {
	  	ll x;
	  	cin>>x;
	  	v.push_back(x);
	  }
	  sort(v.begin(),v.end());
	  ll ans=0;
	  for(ll i=0;i<k;i++)
	   ans+=v[i];
	   
	   cout<<ans;
	
	
	}
	
	
	return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int k, n;
char s[1 << 20];

const int mxn = 1 << 22;
const int mod = 1e9 + 7;

int fac[mxn], ifac[mxn];

int qp(int x, int n) {
	int ans = 1;
	for (; n; n >>= 1, x = 1LL * x * x % mod)
		if (n & 1) ans = 1LL * ans * x % mod;
	return ans;
}

int inv(int x) { return qp(x, mod - 2); }

int comb(int n, int m) {
	if (m < 0 || m > n) return 0;
	return 1LL * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

int pw25[mxn], pw26[mxn];

int main() {
	scanf("%d", &k);
	scanf("%s", s); n = strlen(s);

	rep(i, mxn) fac[i] = i ? 1LL * fac[i - 1] * i % mod : 1;
	ifac[mxn - 1] = inv(fac[mxn - 1]);
	for (int i = mxn - 1; i; -- i) ifac[i - 1] = 1LL * ifac[i] * i % mod;
	rep(i, mxn) pw25[i] = i ? 25LL * pw25[i - 1] % mod : 1;
	rep(i, mxn) pw26[i] = i ? 26LL * pw26[i - 1] % mod : 1;

	int ans = 0;
	rep(l, k + 1)
		(ans += 1LL * comb(k - l + n - 1, n - 1) * pw25[k - l] % mod * pw26[l] % mod) %= mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 70348
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int A, B, C;

int main() {
	cin >> A >> B >> C;
	cout << max(0, C - (A - B)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char ar[100],br[100],cr[100];
    int i=0;
    
    scanf ("%s %s %s",ar,br,cr);
    int p,q,r;
    p=strlen(ar);
    q=strlen(br);
    r=strlen(cr);

    if (ar[p-1]==br[0] && br[q-1]==cr[0])
    {
        printf ("YES\n");
    }
    else if (ar[p-1]!=br[0] || br[q-1]!=cr[0])
    {
        printf ("NO\n");
    }
    return 0;
}

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

set<string> st;
int k;
int main()
{
    string s; cin>>s;
    cin>>k;
    for(int i=0; i<s.size(); i++)
    {
        string temp="";
        for(int j=0; j<k; j++)
        {
            if(i+j>=s.size()) break;
            temp+=s[i+j];
            st.insert(temp);  
        }
        
        while(st.size()>k) st.erase(prev(st.end()));
    }
    
    cout<<*prev(st.end())<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
//#pragma GCC target(avx)
using namespace std;
#define int long long
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector <string> asd(h);
    for(int i = 0; i < h; ++i)cin >> asd[i];
    queue <pair <int,int> > Q;
    
    vector < vector < int >  > sadf(h, vector <int> (w));
    vector < vector < int >  > dis(h, vector <int> (w, -1));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(asd[i][j] == '#'){
                Q.push({i,j});
                dis[i][j] = 0;
            }
        }
    }
    int ans = 0;
    while(!Q.empty()){
        auto u = Q.front();
        Q.pop();
        ans = max(dis[u.first][u.second], ans);
        if(u.first && dis[u.first-1][u.second] == -1){
            dis[u.first-1][u.second] = dis[u.first][u.second] + 1;
            Q.push({u.first-1, u.second});
        }
        if(u.second && dis[u.first][u.second-1] == -1){
            dis[u.first][u.second - 1] = dis[u.first][u.second] + 1;
            Q.push({u.first, u.second - 1});
        }
        if(u.first  + 1 < h && dis[u.first+1][u.second] == -1){
            dis[u.first + 1][u.second] = dis[u.first][u.second] + 1;
            Q.push({u.first + 1, u.second});
        }
        if(u.second + 1 < w && dis[u.first][u.second+1] == -1){
            dis[u.first][u.second + 1] = dis[u.first][u.second] + 1;
            Q.push({u.first, u.second + 1});
        }
    }
    cout << ans << '\n';
}

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


void solve(long long N, std::string S){
    ll ans = 1;
    for (int i = 1; i < N; i++) {
        if(S[i-1] != S[i])
            ans++;
    }
    cout << ans << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}

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

int main()
{
    int n;
    int out = 0;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (j <= i) continue;
            for (int k = 0; k < n; ++k)
            {
                if (k <= j) continue;
                if (l[i] == l[j] || l[i] == l[k] || l[j] == l[k]) continue;
                if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[i] + l[k] > l[j]) ++out;
            }
        }
    }

    cout << out << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string t, b;
	cin >> t >> b;

	int dp[1010][1010] = { 0 };

	REP(i, b.size()) {
		FOR(j,i, t.size()) {
			
			//cout << b[i] << " " << t[j] << " " <<i<<endl;
			if (i == 0) {
				if (b[i] == t[j] && j==0) {
					dp[i][j] = 1;
				}
				else if (b[i] == t[j]) {
					dp[i][j] = dp[i][j - 1] + 1;
					//cout << "W" << endl;
				}
				else {
					dp[i][j] = dp[i][j - 1];
				}
			}
			else {
				if (b[i] == t[j]) {
					dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
				}
				else {
					dp[i][j] = dp[i][j - 1];
				}
			}
			dp[i][j] %= mod;
			//cout << dp[i][j];
		}
		//cout << endl;
	}
	cout << dp[b.size() - 1][t.size() - 1] << endl;
	return 0;
}




Measured memory_bytes: 11204
#include<iostream>
using namespace std;
char r[510][510],b[510][510],a[510][510];
int main(){
    int n,m;
    cin>>n>>m;
    int i,j;
    for(i=1;i<=n;i+=2)
    for(j=1;j<=m;j++) r[i][j]='#';
    for(i=2;i<=n;i+=2)
    for(j=1;j<=m;j++) r[i][j]='.';
    for(i=2;i<=n;i+=2)
    for(j=1;j<=m;j++) b[i][j]='#';
    for(int i=1;i<=n;i+=2)
    for(j=1;j<=m;j++){
        b[i][j]='.';
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            char cur;
            cin>>cur;
            if(cur=='#'){
                r[i][j]='#';b[i][j]='#';
            }
        }
    }
    for(i=1;i<=n;i++) r[i][1]='#',b[i][1]='.';
    for(i=1;i<=n;i++) r[i][m]='.',b[i][m]='#';
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++) cout<<r[i][j];
        cout<<endl;
    }
    cout<<endl;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++)cout<<b[i][j];
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main{
  public static void main(String args []){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int ans = a % 10;
    switch(ans){
      case 2:
      case 4:
      case 5:
      case 7:
      case 9:        
        System.out.println("hon");
        break;
      case 0:
      case 1:
      case 6:
      case 8:        
        System.out.println("pon");
        break;
      case 3:
        System.out.println("bon");
        break;
    }
  }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int X = a * b;
  
  if (X % 2 == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int a[100010];
int ans[100010]={};
int main(){
	cin>>n;
	REP(i,n)
		cin>>a[i];
	int k=1;
	for(int i=0;i<n;i++){
		ans[0]+=a[i]*k;
		k*=(-1);
	}
	for(int i=1;i<n;i++){
		ans[i]=2*(a[i-1]-ans[i-1]/2);
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */
vector<int> G[MAX];
int inv[MAX];


int main(){
    int n, m; cin >> n >> m;
    rep(i, n+m-1){
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        inv[b]++;
    }

    int r; //root
    rep(i, n){
        if(inv[i] == 0){
            r = i; break;
        }
    }

    vector<int> par(n); par[r] = -1;
    queue<int> q; q.push(r);
    while(!q.empty()){
        int s = q.front(); q.pop();
        for(int t : G[s]){
            inv[t]--;
            if(inv[t] == 0){
                par[t] = s;
                q.push(t);
            }
        }
    }

    rep(i, n) out(par[i] + 1);
}

Measured memory_bytes: 7040
n = int(input())
omoris = list(map(int,input().split()))

mae, usiro = 0,0
mae_i,usiro_i = 0,-1

for _ in range(len(omoris)):
    if mae <= usiro:
        mae += omoris[mae_i]
        mae_i += 1
    else:
        usiro += omoris[usiro_i]
        usiro_i -= 1

print(abs(mae-usiro))

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    abc095b()
}

fun abc095b() {
    val (n, happyPowder) = readLine()!!.split(" ").map { it.toInt() }
    val donuts = (1..n).map { readLine()!!.toInt() }

    val remainPowder = happyPowder - donuts.sum()
    val answer = donuts.size + remainPowder / donuts.min()!!

    println(answer)
}


Measured memory_bytes: 37968
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<vector<int> >v(k);
	int x;
	for(int i=0;i<k;++i){
		cin>>x;
		v[i].resize(x);
		for(int j=0;j<x;++j){
			cin>>v[i][j];
			--v[i][j];
		}
	}
	vector<int>p(k);
	for(int i=0;i<k;++i)
		cin>>p[i];
	int ans=0;
	for(int i=0;i<(1<<n);++i){
		bool f=true;
		for(int j=0;j<k&&f;++j){
			int sum=0;
			for(int l=0;l<v[j].size();++l)
				sum+=((i>>v[j][l])&1);
			f=((sum&1)==p[j]);
		}
		ans+=f;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(void){
    
    int N, Abuf;
    vector<int> A;

    cin >> N;
    for(int i=0; i<N; i++){
        cin >> Abuf;
        A.push_back(Abuf);
    }

    int resbuf = 0;
    for(int i=0; i<N; i++){
        resbuf+=A[i]*(i%2==0?1:-1);
    }
    cout << resbuf;

    for(int i=0; i<N-1; i++){
        resbuf = A[i]*2 - resbuf;
        cout << " " << resbuf;        
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 1784
#line 1 "main.cpp"
#include <bits/stdc++.h>
#line 2 "/home/user/GitHub/competitive-programming-library/utils/macros.hpp"
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
#line 4 "/home/user/GitHub/competitive-programming-library/utils/binary_search.hpp"

/**
 * @brief a binary search / 二分探索
 * @param[in] p  a monotone predicate defined on $[l, r)$
 * @return $\min \lbrace x \in [l, r) \mid p(x) \rbrace$, or r if it doesn't exist
 */
template <typename UnaryPredicate>
int64_t binsearch(int64_t l, int64_t r, UnaryPredicate p) {
    assert (l <= r);
    -- l;
    while (r - l > 1) {
        int64_t m = l + (r - l) / 2;
        (p(m) ? r : l) = m;
    }
    return r;
}

/**
 * @return $\max \lbrace x \in (l, r] \mid p(x) \rbrace$, or l if it doesn't exist
 */
template <typename UnaryPredicate>
int64_t binsearch_max(int64_t l, int64_t r, UnaryPredicate p) {
    assert (l <= r);
    ++ r;
    while (r - l > 1) {
        int64_t m = l + (r - l) / 2;
        (p(m) ? l : r) = m;
    }
    return l;
}
#line 4 "main.cpp"
using namespace std;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }

int64_t solve(int n, const vector<int64_t> & a) {
    constexpr int64_t INF = 1e18;
    if (n % 2 == 0) {
        vector<array<int64_t, 2> > dp(n + 1, { -INF, -INF });
        dp[0][0] = 0;
        dp[1][0] = a[0];
        dp[2][1] = a[1];
        REP3 (i, 2, n) {
            chmax(dp[i + 1][0], dp[i - 1][0] + a[i]);
            chmax(dp[i + 1][1], dp[i - 1][1] + a[i]);
            chmax(dp[i + 1][1], dp[i - 2][0] + a[i]);
        }
        return max(dp[n - 1][0], dp[n][1]);
    } else {
        vector<array<int64_t, 3> > dp(n + 1, { -INF, -INF, -INF });
        dp[0][0] = 0;
        dp[1][0] = a[0];
        dp[2][1] = a[1];
        dp[3][0] = a[0] + a[2];
        dp[3][2] = a[2];
        REP3 (i, 3, n) {
            chmax(dp[i + 1][0], dp[i - 1][0] + a[i]);
            chmax(dp[i + 1][1], dp[i - 2][0] + a[i]);
            chmax(dp[i + 1][1], dp[i - 1][1] + a[i]);
            chmax(dp[i + 1][2], dp[i - 3][0] + a[i]);
            chmax(dp[i + 1][2], dp[i - 2][1] + a[i]);
            chmax(dp[i + 1][2], dp[i - 1][2] + a[i]);
        }
        return max({ dp[n - 2][0], dp[n - 1][1], dp[n][2] });
    }
}

// generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int N;
    cin >> N;
    vector<int64_t> A(N);
    REP (i, N) {
        cin >> A[i];
    }
    auto ans = solve(N, A);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9532
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

vector<P> factorizer(ll n) {
    vector<P> facts;
    for (ll p=2; p*p<=n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        facts.push_back(P(p, num));
    }
    if (n != 1) facts.push_back(P(n, 1));
    return facts;
}

int main() {
    ll n; cin >> n;
    if (n & 1) { puts("0"); return 0; }
    n /= 10;
    ll cnt = n;
    while (n) {
        n /= 5;
        cnt += n;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gsort(x) sort(x, x+n, greater<ll>()); 
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sync2 cout<<fixed<<setprecision(10)
const ll inf=1e9+7;
#define pi 3.14159265358979323846
#define REP(i,j,n) for (int i = (int)j; i <=(int)n; i++)
#define REPD(i,n,j) for (int i = (int)n; i>=(int)j; i--)
#define all(vv) vv.begin(),vv.end()
//priority_queue <int, vector<int>, greater<int>> mnheap;

int main()
{
    sync;
    int n;
    cin>>n;
    ll x,ans=0;
    REP(i,1,n)
    {
        cin>>x;
        ans^=x;
    }
    if(ans==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}
/*
1
4 2
15 28 10 20
*/

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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;i<(n);i++)
#define vecadd emplace_back

typedef pair<int,int> P;

int main(){
  long n;
  cin>>n;
  
  cout<<n*(n-1)/2;
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

using Point = complex<double>;

int main() {
  int n;
  cin >> n;
  vector<Point> holes;
  for (int i = 0; i < n; ++i) {
    double x, y;
    cin >> x >> y;
    holes.emplace_back(x, y);
  }

  for (const Point& hole : holes) {
    vector<double> args;
    for (const Point& h : holes) {
      if (h == hole)
        continue;
      args.push_back(arg(h - hole));
    }
    sort(args.begin(), args.end());
    args.push_back(args.front() + 2 * M_PI);
    for (int i = 0; i < args.size() - 1; ++i) {
      args[i] = args[i + 1] - args[i];
    }
    args.pop_back();
    double rad = max(0.0, *max_element(args.begin(), args.end()) - M_PI);
    printf("%.15f\n", rad / (2 * M_PI));
  }

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = (long)1e9+7;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		slove(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void slove(String[] args) throws Exception{
		int H = nextInt();
		int W = nextInt();
		char[][] s = new char[H+2][W+2];
		Arrays.fill(s[0],'#');
		Arrays.fill(s[s.length-1],'#');
		for(int i=1;i<=H;i++) {
			s[i]=("#"+nextString()+"#").toCharArray();
		}
		int[][] hv = new int[H+2][W+2];
		for(int w=1;w<W+2;w++) {
			for(int h=1;h<H+2;h++) {
				if(s[h][w]=='.') {
					hv[h][w]=hv[h-1][w]+1;
				}
			}
			for(int h=H-1;h>0;h--) {
				if(s[h][w]=='.'&&s[h+1][w]=='.') {
					hv[h][w]=hv[h+1][w];
				}
			}
		}
		int[][] wv = new int[H+2][W+2];
		for(int h=1;h<H+2;h++) {
			for(int w=1;w<W+2;w++) {
				if(s[h][w]=='.') {
					wv[h][w]=wv[h][w-1]+1;
				}
			}
			for(int w=W-1;w>0;w--) {
				if(s[h][w]=='.'&&s[h][w+1]=='.') {
					wv[h][w]=wv[h][w+1];
				}
			}
		}
		int ans = 0;
		for(int h=1;h<H+1;h++) {
			for(int w=1;w<W+1;w++) {
				ans=Math.max(ans,wv[h][w]+hv[h][w]-1);
			}
		}
		pw.println(ans);

	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 84892
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> PI;
typedef pair<int, int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////

int h, w;
int a[100][100], b[100][100];
bool dp[99][99][25600];

void solve()
{
	cin >> h >> w;
	REP(i, h) REP(j, w) cin >> a[i][j];
	REP(i, h) REP(j, w) cin >> b[i][j];
	
	dp[0][0][a[0][0] - b[0][0] + 12800] = true;
	REP(i, h) REP(j, w) REP(k, 25600){
		if (!dp[i][j][k]) continue;
		int diff;
		if (i + 1 < h) {
			diff = a[i + 1][j] - b[i + 1][j];
			dp[i + 1][j][k + diff] = true;
			dp[i + 1][j][k - diff] = true;
		}
		if (j + 1 < w) {
			diff = a[i][j + 1] - b[i][j + 1];
			dp[i][j + 1][k + diff] = true;
			dp[i][j + 1][k - diff] = true;
		}
	}
	
	int ans = INF;
	for (int i = 0; i < 25600;i++) {
		if (dp[h - 1][w - 1][i]) {
			ans = min(ans, abs(12800 - i));
		}
	}
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 107992