akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll MOD=1000000007;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




int main(){
    int n,m;cin >> n >> m;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if(s[i][j] == 'o') cnt++;
        }
    }
    mcf_graph<int, ll> graph(n * m + cnt + 2);
    int t = 1;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if(s[i][j] == 'o'){
                vector<vector<int>> dp(n, vector<int> (m, -INF));
                dp[i][j] = 0;
                int tmp = 0;
                for (int l = i; l < n; l++) {
                    for (int r = j; r < m; r++) {
                        if(l+1<n and s[l+1][r] != '#'){
                            chmax(dp[l+1][r],dp[l][r] + 1);
                            chmax(tmp, dp[l+1][r]);
                        }
                        if(r+1<m and s[l][r+1] != '#'){
                            chmax(dp[l][r+1],dp[l][r] + 1);
                            chmax(tmp, dp[l][r+1]);
                        }
                    }
                }
                ans += tmp;
                for (int l = 0; l < n; l++) {
                    for (int r = 0; r < m; r++) {
                        if(dp[l][r] >= 0){
                            graph.add_edge(t, cnt + l * m + r + 1, 1, tmp - dp[l][r]);
                        }
                    }
                }
                t++;
            }
        }
    }
    for (int i = 0; i < cnt; i++) {
        graph.add_edge(0, i + 1, 1, 0);
    }
    for (int i = 0; i < n * m; i++) {
        graph.add_edge(cnt + 1 + i, cnt + n * m + 1, 1, 0);
    }
    cout << ans - graph.flow(0, cnt + n * m + 1).sc << endl;
    return 0;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  int X=1;
  for(int i=0;i<N;i++){
    if(X+K>=X*2){
      X*=2;
    }
    else if(X+K<X*2){
      X+=K;
    }
  }
  cout<<X<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int const ns[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    int ss[11][46] = {};
    for( int i=0; i<1024; ++i ) {
        int sum = 0, n = 0;
        for( int j=0; j<10; ++j ) {
            if ( i & 1 << j ) {
                sum += ns[j];
                ++n;
            }
        }
        ++ss[n][sum];
    }

    int n, s;
    while( cin >> n >> s, n||s ) {
        cout << ( ( n >= 0 && n <= 10 && s >= 0 && s <= 45 ) ? ss[n][s] : 0 ) << endl;
    }
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    int n;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            if (set.contains(num)) {
                set.remove(num);
            } else {
                set.add(num);
            }
        }
        System.out.println(set.size());
    }

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

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

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

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 44244
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int cnt[100010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) cin >> A[i];
    int Q; cin >> Q;
    rep(i, N) cnt[A[i]]++;
    int sum = 0;
    rep(i, N) sum += A[i];
    while(Q--) {
        int tmp = sum;
        int A, B; cin >> A >> B;
        tmp -= cnt[A] * A;
        tmp += cnt[A] * B;
        cnt[B] += cnt[A];
        cnt[A] = 0;
        sum = tmp;
        cout << tmp << endl;
    }

    return 0;
}


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

using namespace std;

const int64_t INF = 1LL << 60;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  const int skip = 1 + (N % 2);
  vector<vector<int64_t>> dp(N + 2, vector<int64_t>(skip + 1, -INF));
  dp[0][0] = 0;
  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < skip + 1; j++) {
      if (j < skip) chmax(dp[i + 1][j + 1], dp[i][j]);
      if (i < N) chmax(dp[i + 2][j], dp[i][j] + A[i]);
    }
  }
  cout << dp[N + 1][skip] << '\n';
  return 0;
}


Measured memory_bytes: 15572
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(c<=a+b) cout<<b+c<<endl;
    else cout<<b*2+a+1<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys


fin = sys.stdin.readline
H, W = [int(elem) for elem in fin().split()]
N = int(fin())
a_list = tuple(int(elem) for elem in fin().split())
grid = [[-1] * W for _ in range(H)]
cur_row, cur_col = 0, 0
is_moving_forward = True
for color, a in enumerate(a_list, start=1):
    for _ in range(a):
        grid[cur_row][cur_col] = color
        if cur_col == W - 1 and is_moving_forward:
            cur_row += 1
            is_moving_forward = False
        elif cur_col == 0 and not is_moving_forward:
            cur_row += 1
            is_moving_forward = True
        else:
            cur_col += 1 if is_moving_forward else -1

for row in grid:
    print(*row)


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

void solve()
{
	ll n;
	cin>>n;
	ll ans  = 0;
	for (ll i = 1; i < n; ++i)
	{
		ans += (n-1)/i;
	}
	cout<<ans<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3636
//Look at my code, my code is clean :3
//Khánh đẹp trai
#include <bits/stdc++.h>
#define FORUP(i, start, end) for (int i = start; i <= end; i++)
#define FORDOWN(i, end, start) for (int i = end; i >= start; i--)
#define mem(a, v) memset(a, v, sizeof a)
#define ll long long
#define ld long double
#define pir pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const ll MAX = 20, MOD = 1000000007, BASE = 311, inf  = 1e9;

int du[] = {1, 0}, dv[] = {0, 1};
struct node {
    ll v; ll d; ll e;
};

using namespace std;

int n, cnt;
bool check = false;

int main()
{
    fast_io;
    cin >> n;
    FORUP(i, 1, n) {
        int u, v;
        cin >> u >> v;
        if(u == v) cnt++;
        else cnt = 0;
        if(cnt == 3) check = true;
    }

    if(check) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
using namespace std;
 
int n,k;
 
double expo( double a, int b ){
	if ( b == 0 ) return 1;
  	if ( b == 1 ) return a;
  double half = expo(a,b/2);
  half = ( half * half );
  if ( b & 1 ) half = half * a;
  return half;
}
 
int main(){
  scanf("%d%d",&n,&k);
  double ans = 0;
  for ( int i = 1; i <= n; i++ ){
    int dice = i;
    int cnt = 0;
    while ( dice < k ) {
    	dice *= 2;
      cnt++;
    }
  	ans += (1.0/(1.0*n)) * expo(0.5,cnt);
  }
  printf("%.10lf\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll N,K;
    cin >> N >> K;
    while(N>=K){
        N -= ((N-K)/K+1)*K;
    }
    cout << min(N,abs(N-K)) << endl;
    return 0;
}


Measured memory_bytes: 384
n, k = gets.split(" ").map(&:to_i)
scores = gets.split(" ").map(&:to_i)

inf = 10 ** 9 + 7

(n-k).times do |i|
#   p "#{scores[i..i+k-1]} #{scores[i+1..i+k]}"
  previous_score = scores[i]
  current_score = scores[i+k]
#   k.times do |j|
#     # p "#{scores[j+i]} #{scores[j+i+1]}"
#     previous_score *= scores[j+i]
#     current_score *= scores[j+i+1]
#   end
#   p "#{previous_score} #{current_score}"
  if previous_score >= current_score
    puts "No"
  else
    puts "Yes"
  end
end

Measured memory_bytes: 33904
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fir first
#define sec second
using namespace std;
const int MAXN = 2e5 + 7;
const int INF = 1e9;
int head[MAXN];
struct node{int v, next, val;}e[MAXN << 1];
int tot = 1, col[MAXN];
void add(int u, int v)
{
    e[++tot] = {v, head[u], INF};
    head[u] = tot;
}
pii a[MAXN];
int d[MAXN];
int main()
{
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) 
    {
        scanf("%d", &d[i]);
        a[i].fir = d[i], a[i].sec = i;
        col[i] = -1;
    }
    sort(a + 1, a + 1 + n);
    for (int i = 1, u, v; i <= m; i++)
    {
        scanf("%d%d", &u, &v);
        add(u, v); add(v, u);
    }
    for (int o = 1; o <= n; o++)
    {
        int u = a[o].sec;
        if (col[u] != -1) continue;
        int eid = 0;
        for (int i = head[u]; i; i = e[i].next)
        {
            int v = e[i].v;
            if (d[v] <= d[u]) eid = i;
        }
        if (!eid) 
        {
            puts("-1");
            return 0;
        }
        int v = e[eid].v;
        e[eid].val = e[eid ^ 1].val = d[u];
        if (col[v] == -1) {col[v] = 0; col[u] = 1;}
        else col[u] = col[v] ^ 1;
    }
    for (int i = 1; i <= n; i++) putchar(col[i] ? 'B' : 'W');
    putchar('\n');
    for (int i = 2; i <= tot; i += 2) printf("%d\n", e[i].val);
    return 0;
}

Measured memory_bytes: 9728
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A, B, X = map(int, input().split())
print("YES" if A <= X <= A + B else "NO")

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int X,A,B;cin>>X>>A>>B;
    cout<<X-A-((X-A)/B)*B<<endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    if (n*a < b) cout << n*a << endl;
    else cout << b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
// std::ios::sync_with_stdio(false);
typedef long long LL;
const LL N = 100007;
const LL M = 2000005;
const LL INF = 0x3f3f3f3f;
const double Pi = acos(-1);
LL n,m;
LL s[4][N];
int main()
{
    while (~scanf("%lld",&n))
    {
        for (LL j=0;j<3;j++)
        {
            for (LL i=0;i<n;i++)
                scanf("%lld",&s[j][i]);
            sort(s[j],s[j]+n);
        }
        LL ans = 0;
        for (LL i=0;i<n;i++)
        {
            LL l = lower_bound(s[0],s[0]+n,s[1][i])-s[0];
            LL r = n - (upper_bound(s[2],s[2]+n,s[1][i])-s[2]);
            if (l<0)
                l=0;
            if (r<0)
                r=0;
            // cout<<"bug "<<i<<" "<<l<<" "<<r<<endl;
            ans += l*r;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

/*

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

*/

Measured memory_bytes: 2560
#include<iostream>
#include<cstring>

int dp[17][17];

bool can[17][17];

int main(){
	int a,b,n;//縦　横　個数
	while(std::cin>>a>>b,a*b){
		std::cin>>n;
		for(int i=1;i<=a;i++)for(int j=1;j<=b;j++)dp[i][j]=0,can[i][j]=true;
		for(int i=0;i<n;i++){
			int c,d;
			std::cin>>c>>d;
			can[c][d]=false;
		}
		for(int i=1;i<=a;i++){
			if(!can[i][1]){
				break;
			}
			dp[i][1]=1;
		}
		for(int i=1;i<=b;i++){
			if(!can[1][i]){
				break;
			}
			dp[1][i]=1;
		}
		for(int i=2;i<=a;i++){
			for(int j=2;j<=b;j++){
				if(can[i][j]){
					int sum=0;
					if(can[i-1][j])sum+=dp[i-1][j];
					if(can[i][j-1])sum+=dp[i][j-1];
					dp[i][j]=sum;
				}
			}
		}
		std::cout<<dp[a][b]<<std::endl;
		a=0,b=0,n=0;
	}
	return 0;
}

Measured memory_bytes: 1160
n =int(input())
s = list(map(int, input().split()))

q =int(input())
t = list(map(int, input().split()))

ans = 0
for i in range(q):
    key = t[i]
    left = 0
    right = n
    mid = (left + right) // 2
    while left <= right:
        if s[mid] == key:
            ans += 1
            break
        elif s[mid] < key:
            left = mid + 1
        else:
            right = mid - 1
        mid = (left + right) // 2
print(ans)


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


int main(){
    int n,k,r,s,p,count=0;
    string t;
    cin >> n >> k >> r >> s >> p >> t;

    for(int i=0; i<t.size()-k; i++){
        if(t.at(i)==t.at(i+k)){
            t.at(i+k)='n';
        }
    }
    
    for(int i=0; i<t.size(); i++){
        if(t.at(i)=='r') count+=p;
        if(t.at(i)=='s') count+=r;
        if(t.at(i)=='p') count+=s;
    }
    
    cout << count << endl;
}

Measured memory_bytes: 512
m=f=r=0
p=print
while 1:
    m,f,r=map(int,input().split())
    x=m+f
    if m==f==r==-1:break
    elif m==-1 or f==-1 or x<30:p('F')
    elif x>=80:p('A')
    elif 65<=x<80:p('B')
    elif 50<=x<65 or r>=50:p('C')
    else:p('D')

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

string s;

int solve(vector<int> x){
  int ret = 0;
  if (x.empty()) ret = s.size();
  else{
    for(int i=0;i+1<x.size();i++){
      ret = max(ret, x[i+1] - x[i] - 1);
    }
    ret = max(ret, x[0]);
    ret = max(ret, (int)(s.size()) - x[x.size()-1] - 1);
  }
  return ret;  
}
int main(void){
  cin >> s;
  int ans = INT_MAX;
  for(int i=0;i<26;i++){
    vector<int> idx;
    for(int j=0;j<s.size();j++){
      if (s[j]=='a'+i) idx.push_back(j);
    }
    ans = min(ans, solve(idx));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int N;
  cin >> N;
  int kekka = 1000;
  while(kekka < N){
    kekka += 1000;
  }
  cout << kekka - N << endl;
}


Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int a[50];
    a[0] = 1;
    a[1] = 1;
    for(int i = 2;i < 50;i++)
        a[i] = a[i-1]+a[i-2];
    cout << a[n] << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;

int main()
{
    ll N,K,res;
    ll tmp;

    cin >> N >> K;

    vector <ll> cnt(200001,0);

    if(N == K)
    {
        cout << "0" << endl;
        return 0;
    }


    REP(i,N)
    {
        cin >> tmp;
        cnt[tmp]++; 
    }

    //cntが立ってるやつはいくつなのって話
    sort(cnt.begin(),cnt.end());

    ll kind;
    ll keshi = 0;
    for(ll i = 1; i <= 200000; i++)
    {
        if(cnt[i] == 0)
        {
            continue;
        }
        else
        {
            kind = 200000 - i + 1;

        }
        if(kind <= K)
        {
            break;
        }
        keshi += cnt[i];


    }

    cout << keshi << endl;

}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 3e5+100;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+9;
const ll p = 29;

int arr[N];

int main(){
    FASTIO;
    PRECISION; 

    ll n,k;
    cin>>k;

    if(k<=12){
        cout<<k<<"\n";
        return 0;
    }

    int len = 2,pos=1;

    arr[0] = 1;
    arr[1] = 0;
    // k-=10;
    int z = 10;

    while(z<k){
        // for(int i=0;i<len;i++){
        //     cout<<arr[i];
        // }
        // cout<<"\n";
        // for(int i=0;i+1<len;i++){
        //     if(abs(arr[i]-arr[i+1])>1){
        //         cout<<z<<"\n";
        //         return 0;
        //     }
        // }

        if(arr[pos]==arr[pos-1]+1){
            // arr[pos-1]++;
            // arr[pos]=arr[pos-1]-1;
            int x = pos;

            while(x>=1&&arr[x]==arr[x-1]+1) x--;
            arr[x]++;
            for(int i=x+1;i<len;i++){
                arr[i] = max(0,arr[i-1]-1);
            }

        }else if(arr[pos]==arr[pos-1]){
            if(arr[pos]==9){
                int x=pos;
                while(x>=0 && arr[x]==9) x--;
                if(x==-1){
                    len++;
                    for(int i=0;i<len;i++){
                        arr[i]=0;
                    }
                    arr[0] = 1;
                    pos = len-1;
                }else{
                    while(x>=1&&arr[x]==arr[x-1]+1) x--;
                    arr[x]++;
                    for(int i=x+1;i<len;i++){
                        arr[i] = max(0,arr[i-1]-1);
                    }
                    // if(arr[x]==8){

                    // }
                    // arr[x]++;
                    // for(int i=x+1;i<len;i++){
                    //     arr[i] = max(0,arr[i-1]-1);
                    // }
                    // pos = len-1;
                }
            }else{
                arr[pos]++;
            }
        }else if(arr[pos]==arr[pos-1]-1){
            arr[pos]++;
        }
        z++;
    }

    for(int i=0;i<len;i++){
        cout<<arr[i];
    }

    cout<<"\n";
    

    
 
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
L = [0] * 10 ** 5
for i in range(N):
    L[a[i]] += 1
s = L[0] + L[1] + L[2]
A = s
for i in range(10 ** 5-3):
    s += L[i+3] - L[i]
    A = max(A,s)
print(A)


Measured memory_bytes: 13964
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
 
ll K, N;
 
int main(void) {
  cin >> K >> N;
 
  vector<ll> ans(N);
  if(K % 2 == 0) {
    ans[0] = K / 2;
    REP(i, 1, N) ans[i] = K;
  } else {
    REP(i, 0, N) ans[i] = (K + 1) / 2;
    int p = 0;
    REP(i, 0, N / 2) {
      if(ans[N - 1 - p] == 0) p++;
      ans[N - 1 - p]--;
      if(p > 0 && ans[N - 1 - p] > 0) for(; p > 0; p--) ans[N - p] = K;
    }
    ans.erase(find(ans.begin(), ans.end(), 0), ans.end());
  }
  REP(i, 0, ans.size()) cout << ans[i] << (i + 1 != ans.size() ? " " : "\n");
}

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

int main() {
  
  int N, L;
  cin >> N >> L;
  int sou = 0;
  vector<int> A(N);
  int X = L;
  bool hantei = false; 
  
  for ( int i = 0; i < N; i++) {
    A.at(i) = X;
    X++;
    sou += A.at(i);
    if ( A.at(i) == 0 ) hantei = true;
  }
   
  if ( hantei ) cout << sou << endl;
  else if ( sou >= 0 ) cout << sou - A.at(0) << endl;
  else if ( sou <= 0 ) cout << sou - A.at(N - 1) << endl;
  else cout << sou << endl;
  
}

Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 2019
L, R = lr()
if (R-L) > 2019 * 2:
    R = L + (R-L)%MOD + 2019

answer = 2019
for i in range(L, R):
    for j in range(i+1, R+1):
        temp = i * j % MOD
        if temp < answer:
            answer = temp

print(answer)

Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;
use std::cmp::min;

fn main() {
    let n: i64 = read();
    let mut d = 1;
    let mut minv = std::i64::MAX;
    while d * d <= n {
        if n % d == 0 {
            let a = d;
            let b = n / d;
            minv = min(minv, max(a.to_string().len(), b.to_string().len()) as i64);
        }
        d += 1;
    }
    println!("{}", minv);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, minn=INT_MAX, neg=0;
    cin >> n;
    int arr[n]    ;
    ll sum = 0;
    for(int i=0; i<n; ++i){
        cin >> arr[i];
        if(arr[i] < 0 ) ++neg;
        sum += abs(arr[i]);
        minn = min(minn, abs(arr[i]));
    }
    if(neg & 1){

        cout << sum - 2*minn << "\n";
    }
    else{
        cout << sum << "\n";
    }
}


Measured memory_bytes: 640
#include <stdio.h>

 int main(void){
    int n;
    scanf("%d", &n);

    switch(n%10){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
           puts("hon");
        break;
         case 0:
         case 1:
         case 6:
         case 8:
           puts("pon");
           break;
         case 3:
            puts("bon");
            break;
    }
    return 0;
 }

Measured memory_bytes: 1612
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
	string a,b;
	cin >> a>>b;
	int x,y;
	cin >> x >> y;
	string u;
	cin >> u;
	if(u==a) {
		cout << x-1 << " "<<y <<endl;
	}
	else if(u==b){
		cout << x<< " "<<y-1 <<endl;
	}
}

signed main() {
	boost;
	solve();
}

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

int main()
{
  long nAnum, nBnum, nXpos;
  cin >> nAnum >> nBnum >> nXpos;

  long nDivHigh = nBnum / nXpos;
  long nDivLow;

  if (nAnum - 1 < 0)
  {
    nDivHigh++;
    nDivLow = 0;
  }
  else
    nDivLow = (nAnum - 1) / nXpos;

  cout << (nDivHigh - nDivLow) << endl;
  return 0;
}

Measured memory_bytes: 764
/* Arunava Chakraborty [ @iArunava ] */

/* Already 2018 - AtCoder */

#include <bits/stdc++.h>

using namespace std;

int main() {
    string s = "";
    cin >> s;
    cout << "2018" + s.substr(4, s.size()) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)


int main() {
	int n;
	string s;
	set<string> se;
	vector<string> va;
	cin >> s >> n;
	int N = s.size();
	REP(i, min(n,N)) {
		REP(j, s.size() - i) {
			if (se.find(s.substr(j, i + 1)) == se.end()) {
				se.insert(s.substr(j, i + 1));
				va.push_back(s.substr(j, i + 1));

			}
		}
	}
	sort(ALL(va));
	cout << va[n - 1] << endl;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const int inf = 1e9;

int main(){
	int n;
	string s;
	cin >> n >> s;
	vector<int> rev(n, 0);
	for(int i=1; i<n; i++){
		rev[i] += rev[i-1];
		if(s[i-1] == 'W') rev[i]++;
	}
	vector<int> rev2(n, 0);
	for(int i=n-2; i>=0; i--){
		rev2[i] += rev2[i+1];
		if(s[i+1] == 'E') rev2[i]++;
	}
	
	int ans = inf;
	for(int i=0; i<n; i++){
		ans = min(ans, rev[i]+rev2[i]);
	}
	cout << ans << endl;
	return 0;
}

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

#ifdef LOCAL_DEBUG
#include "bits/mytest.h"
#endif

using namespace std;


#pragma region user_defined
#define CLR(arr,val) fill(arr.begin(),arr.end(),val);
#define CLR0(arr)  CLR(arr,0)

#define d2clear(arr,data) for(int i =0;i<arr.size();i++){for(int j =0;j<arr[i].size();j++){arr[i][j]=data;}}
#define d2print(arr) for(int i =0;i<arr.size();i++){for(int j =0;j<arr[i].size();j++){cout<<arr[i][j];} cout<<endl;}
#define d2array(name,type,rows,cols,data) vector< vector<type>  > name(rows,vector<type>(cols,data))

#define forit(arr,it) for(auto it=arr.begin();it!=arr.end();it++)
#define rforit(arr,it) for(auto it=arr.rbegin();it!=arr.rend();it++)

#define LL long long
#define A(n) n.begin(),n.end()
#define maxn(a,b) ((a)=((a)>(b)?(a):(b)))
#define minn(a,b) ((a)=((a)<(b)?(a):(b)))

#define min(a,b)  ( (a)<(b)?(a):(b)   )
#define max(a,b)  ( (a)>(b)?(a):(b)  )
#define last(a)   a[a.size()-1]
#define first(a)  a[0]
#define println(a) cout<<a<<endl;
#define mp(a,b)  make_pair(a,b)
#pragma endregion

//#define MULTI_CASE
struct Solution{
	
	
	void solve(istream & cin = std::cin, ostream & cout = std::cout){
		int a, b, c; cin >> a >> b >> c;
		vector<int> arr(101, 0);
		arr[a] = 1;
		arr[b] = 1;
		arr[c] = 1;
		int cnt = 0;
		for (int i = 0; i <=100; i++)
		{
			cnt += arr[i];
		}
		cout << cnt << endl;
	}

};


int main() {
#ifdef LOCAL_DEBUG 
 
	MyTest::Judge::JudgeNormal judge;
	MyTest::Config config;
	config.judge = &judge;
	MyTest::Test test(config);

	const string ITEM_NAME("A.cpp");
	const string FILE_NAME(__FILE__);
	auto it=FILE_NAME.find_last_of('\\');
	auto inputfile = FILE_NAME.substr(0, it + 1) + ITEM_NAME.substr(0, ITEM_NAME.find_last_of('.')) + "_input.txt";
	auto outputfile = FILE_NAME.substr(0, it + 1) + ITEM_NAME.substr(0, ITEM_NAME.find_last_of('.')) + "_output.txt";
	freopen(inputfile.c_str(), "r", stdin);
	//freopen(outputfile.c_str(), "w", stdout);
	
	while (test.ReadCaseInOneFile()) {
		test.Begin();
		Solution s;
		s.solve(test.Input(),test.Output());
		test.End();
	}
	test.DisplayInfo();
#else   //online judge
 
	Solution s;
	s.solve();
 
#endif
	

 
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc161/tasks/abc161_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve() {
  ll K;
  cin >> K;

  queue<ll> q;
  rep1(num, 9) q.push(num);

  rep(i, K - 1) {
    ll n = q.front();
    q.pop();

    if (n % 10 >= 1) q.push(10 * n + (n % 10 - 1));
    q.push(10 * n + (n % 10));
    if (n % 10 <= 8) q.push(10 * n + (n % 10 + 1));
  }

  ll res = q.front();

  cout << res << "\n";
}

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

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

    long long n, k;
    cin >> n >> k;

    // 余り(0 ~ k-1)をそれぞれカウント
    vector<long long> cnt(k, 0);
    for(int i = 1; i <= n; i++){
        cnt[i % k]++;
    }

    long long ans = 0;
    for(int i = 0; i < k; i++){
        if(i * 2 % k != 0) continue;
        /*
            余りに2掛けたもののkで割ったうち，0のもの
            つまり，(a, b), (b, c), (c, a)それぞれ足し合わせた時，
            kで割って0になる（割り切れる）ことを意味する．

            ansに足すのは二値足したものをkで割り切れるものの個数を三つ掛け合わせたもの
            たとえば，cnt[2] = 4とする
            これはたとえば，k = 4, n = 14のとき，
            a(13-16行目のfor文でいうi) = 2, 6, 10, 14が考えられる．
            このうち二倍してkで割り切れるものを探す
            2 * 2 = 4
            6 * 2 = 12
            10 * 2 = 20
            14 * 2 = 28
            　上にあげたものは因数に必ず2が1つ含まれており，それに2を掛けたら，
            4で割り切れるのは自明である
            　2, 6, 10, 12このうち任意の二つを選ぶ場合4で割り切れるので（判定で），
            この四つからトリオをつくる
            2 2 2
            2 2 6…
            気合でどうにかなるものでもない（そうでもないが）ので計算しよう
            2 2 2
            2 2 6
            2 2 10
            2 2 12
            (cnt[2] * cnt[2] * cnt[2])でいける．
            4(==cnt[2]) * 4 * 4なのである．

            k=4の場合はイメージがつきやすいがkが奇数の場合はどうだろう
            k=3の場合を考える．k=3, n=15とする  
            いやそんなことは考えなくて良い．
            そもそもトリオの中の任意の二つを足し合わせたものがkの倍数であればよい
            つまり(kの倍数/2, kの倍数/2, kの倍数/2)でありk/2は整数でなくてはいけない
            それを上のfor文で探しているんだ．

        */
        ans += cnt[i] * cnt[i] * cnt[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}

const int mod = 1000000007;
const int max_n = 200005;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
    int n;cin >> n;
    vector<vector<mint>> dp(n+1,vector<mint>(4));
    dp[0][0]=1;
    rep(i,n){
        dp[i+1][0]=dp[i][0]*8;
        dp[i+1][1]=dp[i][1]*9+dp[i][0];
        dp[i+1][2]=dp[i][2]*9+dp[i][0];
        dp[i+1][3]=dp[i][1]+dp[i][2]+dp[i][3]*10;
    }
    cout << dp[n][3] <<endl;
}  

Measured memory_bytes: 73492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;

int main(void){
  
  IN(N);
  vl h(N);
  REP(i, N) {
    IN(h[i]);
  }
  vl dp(N, 0);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  FOR(i, 2, N) {
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
  }
  PRINT(dp[N-1]);

}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <math.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define INF 1001001
using namespace std;
 
 
int main(){
  int n;
  long long h=0, a, result=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    if(h>a){
      result += h-a;
    }else{
      h = a;
    }
  }
  cout << result << endl;
  
 
  
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main(){

  long long k;
  int n,a,b,i;

  cin>>n>>k;
  vector <pair<int,int> > pairs(n);
  for(i=0;i<n;i++){
    cin>>a>>b;
    pairs[i]=make_pair(a,b);
  }
  sort(pairs.begin(),pairs.end());
  for(i=0;k>0&&i<n;i++) k-=pairs[i].second;
  if(i==0) i++;
  cout<<pairs[i-1].first<<endl;
  return 0;
}



Measured memory_bytes: 1024
# include <bits/stdc++.h>
using namespace std;
# define FOR(i, a, b) for (int i = a; i <= b; ++i)
# define FDR(i, a, b) for (int i = a; i >= b; --i)
# define push_back pb
# define make_pair mp
# define lch p<<1, l, mid
# define rch p<<1|1, mid + 1, r
# define mem(a, b) memset(a, b, sizeof(a))
# define first fi
# define second se
# define MOD 1000000007
# define INF 1000000000
typedef long long i64;
typedef vector<int> VI;
typedef pair<int, int> PII;
const int N = 300005;

char s[N];
int sum[N];

int main ()
{
    int n;
    scanf("%d %s", &n, s + 1);
    FOR(i, 1, n) sum[i] = sum[i - 1] + (s[i] == 'E');
    int ans = INF;
    FOR(i, 1, n) {
        ans = min(ans, i - 1 - sum[i - 1] + sum[n] - sum[i]);
    }
    printf("%d\n", ans);
    return 0;
}


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

int main() {
  int a, b;

  scanf("%d", &a);
  scanf("%d", &b);

  int num = 0;

  if (b >= 0 && b < 10) {
    num = a * 10 + b;
  } else if (b < 100) {
    num = a * 100 + b;
  } else {
    num = a * 1000 + b;
  }

  int i = 1;

  while (i * i < num) {
    i++;
  }

  if (i * i == num) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

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

s=[0]*(N+1)
xs=[0]*(N+1)
for i in range(N):
  s[i+1]=s[i]+A[i]
  xs[i+1]=xs[i] ^ A[i]
ans=0
l=0
for r in range(N+1):
    #print(l,r)
    
    if r == N:
      ans+=((r-l)*(r+1-l))//2
      continue   
    while(r != l):
      if s[r+1]-s[l] == xs[r+1]^xs[l]:
        break
      else:         
        ans+=r-l
        l+=1
print(ans)



Measured memory_bytes: 28360
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define FOR(a, b) for (ll i = a; i < b + 1; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
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;}


signed main(){
    ll a,b,k;
    cin >> a >> b >> k;
    if(a+b<k){
        cout << 0 << " " << 0 << endl;
    }
    else if(a<k){
        cout << 0 << " " <<  a+b-k << endl;
    }
    else{
        cout << a-k << " " << b << endl;
    }
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
llst = [0] * N
rlst = [0] * N

for i in range(N - 1):
    llst[i] = (i + 1) + a[i]
    rlst[-i - 1] = (N - i) - a[-i - 1]

d = defaultdict(int)
for i in range(1, N):
    d[rlst[i]] += 1

cnt = 0
for i in range(N - 1):
    cnt += d[llst[i]]

print(cnt)

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

int main() {
  int S;

  cin >> S;
  int h = S / 3600;
  int m = (S - h * 3600) / 60;
  int s = S - h * 3600 - m * 60;

  cout << h << ":" << m << ":" << s << endl;

  return 0;
}



Measured memory_bytes: 3088
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;

bool operator<(pll l, pll r) {
	return l.fi * r.se < r.fi * l.se;
}

ll sm(ll x) {
	if (x < 10) return x;
	return sm(x/10) + x%10;
}

ll f(ll x) {
	pll opt = mp(x, sm(x));
	ll cur = 1;
	for (int i = 0; cur <= x; i++) {
		x -= ((x / cur) % 10) * cur;
		x += cur * 9;
		if (mp(x, sm(x)) < opt)
			opt = mp(x, sm(x));
		cur *= 10;
	}
	return opt.fi;
}

int main() {
	int k; ni(k);
	if (k < 10) {
		for (int i = 1; i <= k; i++)
			pri(i);
		return 0;
	}
	for (int i = 1; i <= 9; i++)
		pri(i);
	ll cur = 9; k -= 9;
	while (k) {
		cur = f(cur+1);
		prl(cur);
		k--;
	}
	return 0;
}


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

using namespace std;

const int L = 18; 
int a[2][L];
int dp[L][1<<L];

void solve() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[0][i];
    }
    for (int i = 0; i < n; i++) {
        cin >> a[1][i];
    }
    const int INF = 0x3f3f3f3f;
    memset(dp, 0x3f, sizeof dp);
    const int MSK = 1<<n; 
    for (int i = 0; i < n; i++) {
        dp[i][1<<i] = 0;
    }
    for (int msk = 1; msk < MSK; msk++) {
        int cbit = 0;
        int p = __builtin_popcount(msk)&1;
        for (int i = n-1; i >= 0; i--) {
            if (msk>>i&1) cbit++;
            else {
                int x = a[p^(i&1)][i];
                for (int j = 0; j < n; j++) {
                    if (msk>>j&1) {
                        if (dp[j][msk] >= INF) continue;
                        int y = a[p^(j&1)^1][j];
                        if (y <= x) {
                            dp[i][msk|1<<i] = min(dp[i][msk|1<<i], dp[j][msk] + cbit);
                        }
                    }
                }
            }
        }
    }
    int res = INF;
    for (int i = 0; i < n; i++) {
        res = min(res, dp[i][MSK-1]);
    }
    if (res >= INF) res = -1;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


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

#define                                 pai                                         acos(-1)
#define                                 ll                                          long long
#define                                 pb                                          push_back
#define                                 mp                                          make_pair
#define                                 pll                                         pair<ll,ll>
#define                                 sz(a)                                       (ll)a.size()
#define                                 endl                                        "\n"
#define                                 gcd(a, b)                                   __gcd(a, b)
#define                                 lcm(a, b)                                   (((a)*(b))/gcd(a,b))
#define                                 all(vec)                                    vec.begin(),vec.end()
#define                                 ms(a, b)                                    memset(a,b,sizeof(a))
#define                                 TEST_CASE(t)                                for(int www=1;www<=t;www++)
#define                                 PRINT_CASE                                  printf("Case %d: ",z)
#define                                 fii                                         freopen("input.txt","r",stdin);
#define                                 foo                                         freopen("output.txt","w",stdout);
#define                                 fast                                        ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll mod  = 1e9 +07;
const ll mxn  = 1e6 +10;

int  main()
{
    ll i,j,k,a,b,c,d=0,n,m,t,h,u,v,x,y,z;
    string s1,s2;
    cin>>s1>>s2;
    m=sz(s2);
    n=sz(s1);
    ll mx=0;
    for(i=0;i<=n-m;i++)
    {
        string tem = s1.substr(i,m);
        ll cnt=0;
        for(j=0;j<m;j++)
        {
            if(tem[j]==s2[j])
            {
                cnt++;
            }
        }
        mx=max(mx,cnt);
    }
    ll ans=m-mx;
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 3600
w = gets.to_i
n = gets.to_i
arr = []
n.times{|i|
    a, b = gets.chomp.split(",").map(&:to_i)
    arr << [a, b, i]
    arr << [b, a, i]
}

result = []
1.upto(w){|x|
    b = x
    index = -1
    arr.each{|s, g, i|
        if s == b && i > index
            b = g
            index = i
        end
    }
    result[b - 1] = x
 }
puts result


Measured memory_bytes: 6876
#include <stdio.h>
#include <stdlib.h>

int solve(int, int);

int *array, n;

int main(){
  int i, m, M;
  scanf("%d",&n);
  array = malloc(n * sizeof(int));
  for(i = 0; i < n; i++){
    scanf("%d",&array[i]);
  }
  scanf("%d",&m);
  for(i = 0; i < m; i++){
    scanf("%d",&M);
    if(solve(0, M)){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
  }
  
  return 0;
}

int solve(int i, int M){
  if(M == 0){
    return 1;
  }
  if(i >= n){
    return 0;
  }
  return solve(i + 1, M) || solve(i + 1, M - array[i]);
}


Measured memory_bytes: 2104
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  int a, b;
  cin >> a >> b;

  int a_sum = 0, b_sum = 0;

  if(a < b) {
    for (int i=0; i<b; i++){
      a_sum += a * pow(10, i);
    }
    cout << a_sum << endl;
  } else {
    for (int i=0; i<a; i++){
      b_sum += b * pow(10, i);
    }
    cout << b_sum << endl;
  }
  
}


Measured memory_bytes: 256
#define x(a)for(i=0;i<n;i++)scanf("%d",a+i);qsort(a,n,4,y)
a[40000],b[40000];int y(int *a,int *b){return *b-*a;}
main(n,i){for(;scanf("%d",&n),n;){x(a);x(b);for(i=0;i<n/2;i++)if(a[i*2]>b[i]){printf("%d\n",i*2+1);break;}if(i==n/2)puts("NA");}exit(0);}

Measured memory_bytes: 1116