akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = int64_t;
#define MAX_N 1010
#define MAX_M 100010
const long long mod = pow(10, 9) + 7;
#define vect vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vect) for(int aqw=0;aqw<vect.size();aqw++){cout<<vect[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
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 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 10010
#define PI 3.141592653589793
#define vecP vector<P>
//cout << setprecision(15) << std::fixed;


int main() {
	int h, w ,cut;
	cin >> h >> w;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			char c;
			cin >> c;
			if (c == '#') {
				cut++;
			}
		}
	}
	if (cut - 1 > h + w - 2) {
		print("Impossible");
	}
	else {
		print("Possible");
	}
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	static int[][] lengthGrid;
	static int[][] grid;
	static int h;
	static int w;

	static List<Entry<Integer,Integer>> pairList = new ArrayList<>();

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] s = sc.nextLine().split(" ");
		h = Integer.parseInt(s[0]);
		w = Integer.parseInt(s[1]);
		int max = Integer.MAX_VALUE;
		grid = new int[h][w];
		lengthGrid = new int[h][w];
		for(int i = 0;i < h;i++){
			char[] array = sc.nextLine().toCharArray();
			for(int j =0;j<w;j++){
				grid[i][j] = array[j] == '.' ? 1 : 0;
				lengthGrid[i][j] = -1;
			}
		}
		search(0,0,0);
		/*
		for(int[] array : grid){
			for(int i : array){
				System.out.print(i+ " ");
			}
			System.out.println();
		}
		for(int[] array : lengthGrid){
			for(int i : array){
				System.out.print(i+ " ");
			}
			System.out.println();
		}
		*/
		if(lengthGrid[h-1][w-1] == -1){
			System.out.println(-1);
			return;
		}
		back(h-1,w-1, lengthGrid[h-1][w-1]);
		int score = 0;
		for(int i = 0;i < h;i++){
			for(int j = 0; j < w;j++){
				score += grid[i][j];
			}
		}
		System.out.println(score-1);
	}

	public static void back(int i, int j, int length){
		if(i == 0 && j == 0) return;
		grid[i][j] = 0;
		length--;
		if(i != h-1 && lengthGrid[i+1][j] == length) back(i+1,j,length);
		else if(j != w-1 && lengthGrid[i][j+1] == length) back(i,j+1,length);
		else{
			if(i > 0 && lengthGrid[i-1][j] == length) back(i-1,j,length);
			else if(j > 0)back(i,j-1,length);
		}
	}

	public static void search(int i, int j, int length){
		if(i == h || j == w) return;
		if(lengthGrid[i][j] != -1 && lengthGrid[i][j] <= length) return;
		if(grid[i][j] == 0) return;
		lengthGrid[i][j] = length;
		if(i == h-1 && j == w-1) return;
		length++;
		if(i != 0) search(i-1,j,length);
		if(j != 0) search(i,j-1,length);
		search(i+1,j,length);
		search(i,j+1,length);
	}
}

Measured memory_bytes: 24828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = INF;
    for(ll i=-100; i<101; i++){
        ll cnt = 0;
        rep(j, n){
            // cnt += pow(a[i]-i, 2);
            cnt += (a[j]-i) * (a[j]-i);
        }
        // if(chmin(ans, cnt)){
        //     cout << i << endl;
        // }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}


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

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

string next(string s) {
	string ret=s.substr(1);
	ret+=s[0];
	return ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s,t; cin>>s>>t;
	set<string> used;
	while(used.find(s)==used.end()) {
		if(s==t) { cout << "Yes" << endl; return 0; }
		used.insert(s);
		s=next(s);
	}
	cout << "No" << endl;
	return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
/*
int f(int i, int j) {
    int maxi = (j / i);
    vector<int> now;
    now.push_back(10000);
    for(int k = 1; k <= maxi; k++){
        now.push_back(Grundy[i][j - k]);
    }
    sort(now.begin(), now.end());
    now.erase(unique(now.begin(), now.end()), now.end());
    for(int k = 0; k < now.size(); k++) {
        if(now[k] != k) {
            return k;
        }
    }
}
*/

ll g(ll K, ll N) {
    //cout << j << endl;
    if((N % K) == 0) {
        return N / K;
    }
    if(N < K) return 0;
    if(N >= K * K) return g(K, N - 1 - N / K);
    ll delta = N / K + 1;
    ll time = (N - K * (delta - 1) + (delta - 1)) / delta;
    return g(K, N - delta * time);
}
int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    ll grundy = 0;
    for(int i = 1; i <= n; i++){
        ll a, k;
        cin >> a >> k;
        grundy = grundy ^ g(k, a);
    }
    if(grundy == 0) {
        cout << "Aoki" << endl;
    } else {
        cout << "Takahashi" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int i, j, k, n, v, a[1000];
	scanf("%d", &n);
	for (i = 0; i < n; i++)scanf("%d", &a[i]);
	for (i = 0; i < n; i++) {
		v = a[i];
		j = i - 1;
		while ((j >= 0) && (a[j] > v)) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		for (k = 0; k < n; k++) {
			printf("%d", a[k]);
			if (k != n - 1)printf(" ");
		}
		printf("\n");
	}
	return 0;
}

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 1100;
char s[maxn];
i64 k, dp[maxn][4][2]; //0: ==  1: <
// i j k -> 前i位有j个非0的数

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif

	cin >> (s + 1);
	int len = strlen(s + 1);
	cin >> k;
	ms(dp, 0);
	dp[0][0][0] = 1;
	for (int i = 1; i <= len; ++i) {
        dp[i][0][1] = 1;
	}
    for (int i = 1; i <= len; ++i) {
        for (int j = 1; j <= 3; ++j) {
            if (s[i] == '0') {
                dp[i][j][1] = dp[i - 1][j - 1][1] * 9 + dp[i - 1][j][1];
                dp[i][j][0] = dp[i - 1][j][0];
            } else {
                int num = s[i] - '0';
                dp[i][j][1] = dp[i - 1][j - 1][1] * 9 + dp[i - 1][j - 1][0] * (num - 1) + dp[i - 1][j][0] + dp[i - 1][j][1];
                dp[i][j][0] = dp[i - 1][j - 1][0];
            }
        }
    }
//    cerr << dp[1][1][1] << " " << dp[1][1][0] << '\n';
    cout << (dp[len][k][0] + dp[len][k][1]) << endl;

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  int N, a, b;
  long long K;
  cin >> N >> K;
  vector<pair<int, int>> vp;
  for(int i = 0; i < N; i++){
    cin >> a >> b;
    pair<int, int> p(a, b);
    vp.push_back(p);
  }
  sort(vp.begin(), vp.end());
  
  int ans;
  long long count = 0;
  for(auto p : vp){
    count += p.second;
    if(count >= K){
      ans = p.first;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>

int main(){
	
	int a, b;
	char op;
	
	scanf("%d %c %d", &a, &op, &b);
	
	if(op == '-'){
		printf("%d\n", a-b);
	}
	else{
		printf("%d\n", a+b);
	}
	
	
	
	return 0;
}

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

A = []
B = []
for i in range(M):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
AB = A + B

# 各都市間の道路の本数は、ABに含まれる各都市の個数（番号）に等しい
roadsCntArray = []
# 入力に含まれる都市の個数を数える
for i in range(N):
    roadsCntArray.append(AB.count(i+1))

for i in range(N):
    print(roadsCntArray[i])

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

int main() {
    string s;
    int q , i;
    deque<char> ans;
    bool reverse = false;
    cin >> s >> q;
    for(i = 0; i < s.length(); i++){
        ans.push_back(s.at(i));
    }
    for(i = 0; i < q; i++){
        int query, f;
        char c;
        cin >> query;
        if(query == 1) reverse = !reverse;
        else{
            cin >> f >> c;
            if(((!reverse)&&(f==1)) ||((reverse)&&(f==2))){
                ans.push_front(c);
            }else{
                ans.push_back(c);
            }
        }
    }
    if(reverse){
        while(!ans.empty()){
            cout << ans.back();
            ans.pop_back();
        }
    }else{
        while(!ans.empty()){
            cout << ans.front();
            ans.pop_front();
        }
    }
}


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

using namespace std;

int N = 11, x[1000009], v[1000009];
char sir[1000009];

int brute(int v[], int N)
{
    int aux[100][100];
    for (int i=1; i<=N; i++)
        aux[1][i] = v[i];
    for (int i=2; i<=N; i++)
        for (int j=1; j<=N - i + 1; j++)
            aux[i][j] = abs(aux[i - 1][j] - aux[i - 1][j + 1]);
    return aux[N][1];
}

int getSol(int x[])
{
    if (N == 2)
        return abs(x[1] - x[2]);
    bool all02 = 1, cnt2 = 0;
    for (int i=1; i<=N; i++)
        all02 &= (x[i] != 1),
        cnt2 ^= (x[i] == 2);
    int par = 0, par2 = 0;
    for (int i=0; i<N; i++)
        if (((N - 1) & i) == i)
            par ^= (x[i + 1] & 1),
            par2 ^= (x[i + 1] == 2);
    if (par) return 1;
    if (!all02) return 0;
    if (par2)
        return 2;
    return 0;
}

void back (int pos)
{
    if (pos == N + 1)
    {
        int curr = brute (v, N);
        if (curr != getSol(v))
        {
            for (int i=1; i<=N; i++)
                printf ("%d", v[i]);
            printf (" -> %d instead of %d\n", curr, getSol(v));
        }
        return ;
    }
    for (int i=0; i<3; i++)
        v[pos] = i, back (pos + 1);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d\n", &N);
scanf ("%s", sir + 1);
for (int i=1; i<=N; i++)
    x[i] = sir[i] - '1';
printf ("%d\n", getSol(x));
/*for (int a=0; a<3; a++)
    for(int b=0; b<3; b++)
    for (int c=0; c<3;c++)
{bool ok = 1;
int f[] = {a, b, c};
if (a==b||b==c||c==a) continue;
for (int i=0; i<3; i++)
    for (int j=0; j<3; j++)
    {
/*        if (abs(i - j) != (a * i + b * j + c) % 3)
        {
            ok = 0;
            i = j = 5;
            break;
        }
        if (f[abs(i - j)] != (f[i] + f[j]) % 3)
        {
            ok = 0;
            i = j = 5;
            break;
        }
    }
if (ok)
{
    printf ("%d %d %d\n", a, b, c);
    return 0;
}
}*/
//back (1);
return 0;
}


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

#友達候補：　ブロック関係にない　友達ではない　間接的に友達
#友達候補＝友達の輪　ー　友達
#ブロックリストが友達の輪とsamegroupだったら−１

class UnionFind():
  # 作りたい要素数nで初期化
  # 使用するインスタンス変数の初期化
  def __init__(self, n):
    self.n = n
    # root[x]<0ならそのノードが根かつその値が木の要素数
    # rootノードでその木の要素数を記録する
    self.root = [-1]*(n+1)
    # 木をくっつける時にアンバランスにならないように調整する
    self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
    # ここで代入しておくことで、後の繰り返しを避ける
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

    # 木の併合、入力は併合したい各ノード
  def Unite(self, x, y):
    # 入力ノードのrootノードを見つける
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    # すでに同じ木に属していた場合
    if (x == y):
      return 
      # 違う木に属していた場合rnkを見てくっつける方を決める
      #rnkが大きい方に結合
    elif (self.rnk[x] > self.rnk[y]):
      self.root[x] += self.root[y]
      self.root[y] = x

    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      # rnkが同じ（深さに差がない場合）は1増やす
      if(self.rnk[x] == self.rnk[y]):
        self.rnk[y] += 1

  # xとyが同じグループに属するか判断
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  # ノードxが属する木のサイズを返す
  def Count(self, x):
    return -self.root[self.Find_Root(x)]
  
uni=UnionFind(N)
fri=[[] for _ in range(N)]
blo=[[] for _ in range(N)]
for i in range(M):
  a,b=map(int, input().split())
  uni.Unite(a-1,b-1)
  fri[a-1].append(b-1)
  fri[b-1].append(a-1)
for i in range(K):
  c,d=map(int, input().split())
  blo[c-1].append(d-1)
  blo[d-1].append(c-1)
  
for i in range(N):
  ans=uni.Count(i)-len(fri[i])-1
  for a in blo[i]:
    if uni.isSameGroup(i,a):
      ans-=1
  print(ans, end=" ")

Measured memory_bytes: 42176
#include <iostream>

using namespace std;

int main() {
  string s;
  
  cin >> s;
  
  int is_no = 0;
  for(int i = 0; i < s.length(); i++) {
    if ((i % 2 == 0 && s[i] == 'L') ||
        (i % 2 != 0 && s[i] == 'R')) {
    	is_no = 1;
    }
  }
  
  if(is_no == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;


void solve(){

    string s,t;
    cin >> s >> t;
    ll ans = INF;
    for(ll i=0; i<=s.size()-t.size(); i++){
        ll tmp = 0;
        for(ll j=0; j<t.size(); j++){
            if(s[i+j]!=t[j]) tmp++;
        }
        ans=min(ans,tmp);
    }
    cout << ans << endl;

}

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


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

int main() {
    vector<int>mountain(10);
    for(int i = 0; i < 10; i++){
      cin >> mountain.at(i);
    }
    sort(mountain.begin(), mountain.end());
    reverse(mountain.begin(), mountain.end());

    for(int i = 0; i < 3; i++){
      cout << mountain.at(i) <<endl;
    }
}



Measured memory_bytes: 3108
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

int n, p1, p2;
int Not, V;
bool used[605];
vector<pair<int, int> > vec;
vector<vector<int> > comp, comp2;
int dp[605][305];

int parent[1205];
void init(){
	for(int i = 1; i <= V; i++) parent[i] = i;
}
int root(int i){
	if(parent[i] == i) return i;
	return parent[i] = root(parent[i]);
}
void unite(int i, int j){
	int root_i = root(i), root_j = root(j);
	if(root_i == root_j) return;
	parent[root_i] = root_j;
}

int main(void)
{
	while(1){
		cin >> n >> p1 >> p2;
		if(n == 0 && p1 == 0 && p2 == 0) break;
		Not = p1 + p2;
		V = 2 * Not;
		
		init();
		int x, y; string s;
		for(int i = 0; i < n; i++){
			cin >> x >> y >> s;
			if(s == "yes"){
				unite(x, y);
				unite(x+Not, y+Not);
			}
			else{
				unite(x, y+Not);
				unite(x+Not, y);
			}
		}
		
		vec.clear();
		comp.clear(), comp2.clear();
		for(int i = 1; i <= Not; i++) used[i] = false;
		for(int i = 1; i <= Not; i++){
			if(used[i]) continue;
			int root_i = root(i);
			int cnt1 = 0, cnt2 = 0;
			vector<int> tmp1, tmp2;
			for(int j = 1; j <= V; j++){
				if(root(j) == root_i){
					if(j <= Not){
						cnt1++;
						used[j] = true;
						tmp1.push_back(j);
					}
					else{
						cnt2++;
						used[j-Not] = true;
						tmp2.push_back(j-Not);
					}
				}
			}
			vec.push_back(make_pair(cnt1, cnt2));
			comp.push_back(tmp1);
			comp2.push_back(tmp2);
		}
		
		int N = vec.size();
		for(int i = 0; i <= N; i++){
			for(int j = 0; j <= p1; j++){
				dp[i][j] = 0;
			}
		}
		dp[0][0] = 1;
		
		for(int i = 0; i < N; i++){
			for(int j = 0; j <= p1; j++){
				dp[i][j] = min(dp[i][j], 2);
				if(j+vec[i].first <= p1) dp[i+1][j+vec[i].first] += dp[i][j];
				if(j+vec[i].second <= p1) dp[i+1][j+vec[i].second] += dp[i][j];
			}
		}
		
		if(dp[N][p1] >= 2){
			cout << "no" << endl;
			continue;
		}
		
		int p = p1;
		vector<int> ans;
		for(int i = N-1; i >= 0; i--){
			if(p - vec[i].first >= 0 && dp[i][p - vec[i].first]){
				p -= vec[i].first;
				for(int j = 0; j < comp[i].size(); j++) ans.push_back(comp[i][j]);
			}
			else if(p - vec[i].second >= 0 && dp[i][p - vec[i].second]){
				p -= vec[i].second;
				for(int j = 0; j < comp2[i].size(); j++) ans.push_back(comp2[i][j]);
			}
		}
		
		sort(ans.begin(), ans.end());
		for(int i = 0; i < ans.size(); i++){
			cout << ans[i] << endl;
		}
		cout << "end" << endl;
	}
	return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = LLONG_MAX;
 
using vc = vector<char>;
using vi = vector<int>;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N; cin >> N;
    string S; cin >> S;
    int t = 0;
    F0R(i, N) {
        if (S.substr(i, 3) == "ABC") ++t;
    }
    cout << t << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int[][] A= {
				{1,2,3,4,5,6,7,8,9,10,11,12},{1,3,1,2,1,2,1,1,2,1,2,1}
		}
		;

		int aa=sc.nextInt();
		int bb=sc.nextInt();

		if(A[1][aa-1]==A[1][bb-1]) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
H a[200];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].x >> a[i].y;
	}
	int ans = n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			int p = a[i].x - a[j].x;
			int q = a[i].y - a[j].y;
			if (p == 0 && q == 0) continue;
			int res = n;
			for (int z = 0; z < n; z++) {
				for (int k = 0; k < n; k++) {
					if (z == k) continue;
					if (a[z].x - a[k].x == p && a[z].y - a[k].y == q) {
						res--;
					}
				}
			}
			chmin(ans, res);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 1000005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;
ll t , n, ans = 0, k, a[MAXX], b[MAXX];
double f = 0.5;

int main()
{
	cin >> n;
	for(ll i = 1; i <= n; i++){
		cin >> a[i];
		b[a[i]] = i; 
	}
	for(ll i = 1; i <= n; i++){
		cout << b[i] << " ";
	}
	return 0;
    
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }
#define sz(x) (int)x.size()
#define pii pair < int, int >
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const ll MAXN = 1e18;
const ll SIZE = 1e5+2; //are u sure?
const ll mod = 1e9+7;
ll line[3][SIZE];

void solve(){
	int n; cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}
	int cnt = 0;
	int cur = 0;
	for(int i = 0; i < n; i++){
		if(v[i] - cur == 1){
			cur = v[i];
			cnt++;
		}
	}
	if(cur == 0) cout << -1 << endl;
	else 
	cout << n - cnt << endl;
}


int main(){
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli A[50] = {};

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

	lli total = 0;

	for (int i = 0; i < N; i++) {
		cin >> A[i];

		if (A[i] != i + 1)
			total++;

	}

	if (total <= 2 && total % 2 == 0) {
		COUT("YES");
	}
	else {
		COUT("NO");
	}

	return 0;
}

Measured memory_bytes: 256
N, M = map(int, raw_input().split())
m = (10**9)+7
if abs(N-M)>1:
  print 0
else:
  s = 1
  for i in range(2, N+1):
    s = (s*i) % m
  for j in range(2, M+1):
    s = (s*j) % m
  if N==M:
    s = (s*2) % m
  print s

Measured memory_bytes: 5764
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n = NextInt()
ans = [0]*4
da = ['AC', 'WA', 'TLE', 'RE']
for i in range(n):
    s = input()
    for j in range(4):
        if da[j] == s:
            ans[j] += 1
for i in range(4):
    print(da[i], 'x', ans[i])

Measured memory_bytes: 9396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define len(v) (int)(v).size()

using namespace std;

int main()
{
    int n;
    cin >> n;
    rep(t,n){
        string s[2];
        cin >> s[0] >> s[1];
        int a[2] = {};
        rep(i,2){
            rep(j,len(s[i])){
                int ad = 1;
                if(isdigit(s[i][j])){
                    ad = (int)(s[i][j] - '0');
                    j++;
                }
                if(s[i][j] == 'm'){
                    a[i] += ad*1000;
                }else if(s[i][j] == 'c'){
                    a[i] += ad*100;
                }else if(s[i][j] == 'x'){
                    a[i] += ad*10;
                }else{
                    a[i] += ad;
                }
            }
        }
        int res = a[0]+a[1];
        if(res / 1000){
            int val = res / 1000;
            res -= val*1000;
            if(val > 1){
                cout << (char)('0'+val);
            }
            cout << 'm';
        }
        if(res / 100){
            int val = res / 100;
            res -= val*100;
            if(val > 1){
                cout << (char)('0'+val);
            }
            cout << 'c';
        }
        if(res / 10){
            int val = res / 10;
            res -= val*10;
            if(val > 1){
                cout << (char)('0'+val);
            }
            cout << 'x';
        }
        if(res > 0){
            if(res > 1){
                cout << (char)('0'+res);
            }
            cout << 'i';
        }
        cout << "\n";
    }
}



Measured memory_bytes: 3080
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  ll H;
  while (cin >> N >> H) {
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++) {
      cin >> a[i] >> b[i];
    }
    sort(b.rbegin(), b.rend());
    ll amax = *max_element(a.begin(), a.end());
    ll res = (H + amax - 1) / amax;
    ll bsum = 0;
    for (int i = 0; i < N; i++) {
      bsum += b[i];
      res = min(res, (i + 1) + (max(0ll, H - bsum) + amax - 1) / amax);
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	int N, d[110], min = 110, count = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &d[i]);
	}
	sort(d, d + N,greater<int>());
	for (int i = 0; i < N; i++) {
		if (d[i] < min) {
			count++;
			min = d[i];
		}
	}
	printf("%d", count);;
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long A[100005];
pair<long long, long long> R[100005];
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n + 1; ++i) scanf("%lld", A + i);

    for (int i = n; i >= 0; --i) {
        if (i == n) R[i] = {A[i], A[i]};
        else R[i] = {A[i] + (R[i + 1].first + 1) / 2, A[i] + R[i + 1].second};
    }

    long long m = 1;
    bool ok = true;
    long long ans = 0;

    for (int i = 0; i < n + 1; ++i) {
        if (i == 0) m = 1;
        else if(m > 10e15) ;
        else {
            m -= A[i - 1];
            m *= 2;
        }
        if (m < R[i].first) {
            ok = false;
            break;
        }
        if (m > R[i].second) ans += R[i].second;

        else ans += m;
    }

    if (!ok) printf("-1\n");
    else printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 6096
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int n;
    cin >> n;
    vector<pair<int,int>> p(n);
    for(int i = 0; i < n; i++){
        pair<int,int> tmp;
        cin >> tmp.first;
        tmp.second = i;
        p[i] = tmp;
    }

    sort(p.begin(), p.end());
    int ma = 1;
    int tmp = 1;
    for(int i = 0; i < n - 1; i++){
        if(p[i].second < p[i + 1].second){
            //cout << p[i].second << p[i + 1].second << endl;
            tmp++;
        } else {
            ma = max(ma, tmp);
            tmp = 1;
        }
    }

    ma = max(ma, tmp);

    cout << n - ma << endl;

    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll a,b;
	cin>>a>>b;
	if(a>=13){
		cout <<b;
	}
	else if(a>=6){
		cout << b/2;
	}
	else{
		cout <<0;
	}
	// your code goes here
	return 0;
}

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

using namespace std;
long long x,p[10001][100][2];
vector <long long> d;
string a;
long long cal(long long i,long long s,bool t)
{
    if (i==d.size())
        return !s;
    if (p[i][s][t]>-1)
        return p[i][s][t];
    long long tp=0,lim=(t)?d[i]:9;
    for (long long dg=0; dg<=lim; dg++)
    {
        bool nt=(dg<lim)?0:t;
        tp=(tp+cal(i+1,(s+dg)%x,nt))%1000000007;
    }
    return p[i][s][t]=tp;
}
long long ans(string num)
{
    memset(p,-1,sizeof(p));
    d.clear();
    for (int i=0;i<num.size();i++)
        d.push_back(num[i]-'0');
    return cal(0,0,1);
}

main()
{
    cin>>a>>x;
    cout<<(ans(a)+1000000006)%1000000007;
}


Measured memory_bytes: 16896
from collections import Counter
from math import sqrt

#f_listとf_r_listの要素数は状況に応じて変えよう

MOD = (10 ** 9) + 7

list_size = 3 * (10 ** 5)

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int((n * n) % MOD), int(x / 2))
	else:
		return int((n * power(n, x - 1)) % MOD)

f_r_list[-1] = power(f_list[-1], MOD - 2)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

def is_prime(i):
	if i == 1:
		return False
	for j in range(2, int(sqrt(i)) + 1):
		if i % j == 0:
			return False
	return True

n, m = map(int, input().split())
prime_factor = Counter()

for i in range(2, int(sqrt(m)) + 1):
	if m % i == 0:
		prime_factor[i] += 1
		m = m // i
		while m % i == 0:
			prime_factor[i] += 1
			m = m // i
	if is_prime(m):
		prime_factor[m] += 1
		break

ans = 1
for i in prime_factor.values():
	ans *= comb(n + i - 1, i)
	ans %= MOD
print(ans)



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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i < (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p,)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#define STOP_DEBUG
#ifndef STOP_DEBUG
#define debug(...)\
    do{ cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << setprecision(20);
    }
} iosetup;

// library
template<const long long mod = 1000000007>
struct Modint{ //modint
    long long x;
    Modint(long long x = 0): x((x %= mod) < 0 ? x + mod : x) {}
    friend istream& operator >> (istream &s, Modint& m){ return s >> m.x; }
    friend ostream& operator << (ostream &s, Modint m){ return s << m.x; }
    inline Modint& operator += (Modint a){ if((x += a.x) >= mod)x -= mod; return *this; }
    inline Modint& operator -= (Modint a){ if((x += mod - a.x) >= mod)x -= mod; return *this; }
    inline Modint& operator *= (Modint a){ (x *= a.x) %= mod; return *this; }
    inline Modint& operator /= (Modint a){ return (*this) *= a.inv(); }
    inline Modint operator + (Modint a){ Modint res(*this); return res += a; }
    inline Modint operator - (Modint a){ Modint res(*this); return res -= a; }
    inline Modint operator * (Modint a){ Modint res(*this); return res *= a; }
    inline Modint operator / (Modint a){ Modint res(*this); return res /= a; }
    inline void takemod(){ x = ((x % mod) + mod) % mod; }
    inline Modint inv(){
        long long a = x, b = mod, u = 1, v = 0, t;
        while(b){
            t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return Modint(u);
    }
    inline Modint pow(long long p){
        Modint res(1), tmp(x);
        for(; p; p >>= 1){ if(p & 1)res *= tmp; tmp *= tmp; }
        return res;
    }
};
using mint = Modint<>;

// Let's get AC!
int main(){

    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N)cin >> a[i];

    int now = 0, pos = 0;
    mint ans(1);
    while(now < N){
        while(pos < N && a[pos] >= (pos - now) * 2 + 1)pos++;
        if(pos >= N)pos--;
        debug(pos, a[pos]);
        ans *= mint(pos + 1 - now);
        now++;
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 640
object Main extends App {

  import scala.io.StdIn._

  val Array(l, n) = readLine.trim.split(' ').map(_.toInt)
  val circles = Array.tabulate(n){_ ⇒
    val Array(p, d, t) = readLine.trim.split(' ').map(_.toLong)
    (p, d, t)
  }.sortBy(_._1)
  val position= circles.map(_._1) :+ l.toLong
  val minTime = position.map{i ⇒ i}
  for (i ← circles.indices){
    val (p, d, t) = circles(i)
    if (minTime(i + 1) > minTime(i) + position(i + 1) - position(i)) minTime(i + 1) = minTime(i) + position(i + 1) - position(i)
    lowerBound(position, p + d) match {
      case pos if minTime(pos) > minTime(i) + t + position(pos) - p - d ⇒
        minTime(pos) = minTime(i) + t + position(pos) - p - d
      case _ ⇒
    }
  }
  println(minTime.last)
  def lowerBound[T](array: Array[T], target: T)(implicit ord: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while(left < right){
      val mid = (left + right) / 2
      if (ord.compare(array(mid), target) < 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  implicit class Extend[T](value: T){
    def also(func: T ⇒ Unit): T = {func(value); value}
    def let[A](func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 48632
n,x=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
for i in range(n-1):
	if a[i+1]+a[i]>x:
		cnt+=a[i+1]+a[i]-x
		a[i+1]=max(0,x-a[i])
print(cnt)


Measured memory_bytes: 14540
n, k = map(int, input().split())
s = input()

c = [0]
import itertools
for _, g in itertools.groupby(s):
  c.append(c[-1] + len(list(g)))
  
c = c[1:]
if s[0] == "1":
  c = [0] + c
else:
  c = [0,0] + c
if s[-1] == "0":
  c = c + [c[-1]]

ans = 0
for i in range(0,len(c), 2):
  end = min(i+2*k+1, len(c)-1)
  ans = max(ans, c[end]-c[i])

print(ans)

Measured memory_bytes: 7940
N, K = map(int, input().split())
mod = 10**9 + 7

  
fact_count = [0 for _ in range(K+1)]
for k in range(1, K+1):
  fact_count[k] = K//k

ans = 0
count = [0 for _ in range(K+1)]
for k in range(K, 0, -1):
  c = pow(fact_count[k], N, mod)
  j = 2*k
  l = 2
  while(j<=K):
    c -= count[j]
    l += 1
    j = k*l
  count[k] = c
  c = c*k%mod
  ans += c
  ans %= mod
print(ans)



Measured memory_bytes: 12092
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr
A.insert(0, 0)
cnt = [0] * (N + 1)
ans = 0
for i in range(1, N + 1):
    if i - A[i] >= 0:
        ans += cnt[i - A[i]]
    if i + A[i] <= N:
        cnt[i + A[i]] += 1
print(ans)

Measured memory_bytes: 32068
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
#include<numeric>
//AtCoderC++.cpp

using namespace std;

long long comb_max = 100;
vector<long long> comb = vector<long long>(comb_max * comb_max, -1);

long long combination(long long n, long long r) {
	if (n == 1 || n == 0)return 1;
	if (n == r)	return 1;
	else if (r == 0)return 1;
	else if (r == 1)return n;
	else if (comb[comb_max * (n - 1) + (r - 1)] != -1) return comb[comb_max * (n - 1) + (r - 1)];
	else {
		auto res = combination(n - 1, r - 1) + combination(n - 1, r);
		comb[comb_max * (n - 1) + (r - 1)] = res;
		return res;
	}
}


inline int ceileing(int a, int b) {return a % b == 0 ? a / b : a / b + 1;}


void D() {
	int N, M; cin >> N >> M;
	using work = pair<int, int>;
	auto works = vector<work>(N);
	for (size_t i = 0; i < N; i++) cin >> works[i].first >> works[i].second;
	sort(works.begin(), works.end(), [](work a, work b) {if (a.first == b.first)return a.second > b.second; else return a.first > b.first; });
	long long answer = 0;
	for (size_t i = 0; i < N; i++) {
		if (M >= works[i].first) {
			answer += works[i].second;
			--M;
		}
	}
	cout << answer << endl;
}

void C() {
	int N; cin >> N;
	auto ss = vector<string>(N);
	for (size_t i = 0; i < N; i++) {
		cin >> ss[i];
		sort(ss[i].begin(), ss[i].end());
	}
	sort(ss.begin(), ss.end());
	long long answer = 0;
	int i = 1;
	string prev = ss[0];
	auto count = 1;
	while (i < N) {
		if (prev == ss[i]) {
			++count;
		} else {
			if (count > 1) {
				answer += combination(count, 2);
			}
			count = 1;
			prev = ss[i];
		}
		++i;
	}
	if (count > 1) 		answer += combination(count, 2);
	cout << answer << endl;
}


int main() {
	int A, B; cin >> A >> B;
	cout << max(A - B, max(A + B, A*B)) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,sum=0,i,j,k;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    
    sort(a,a+n);
    for(i=0;i<n;i++){
       for(j=i+2;j<n;j++){
           for(k=i+1;k<j;k++){
               if((a[k]+a[j])>a[i]&&(a[i]+a[k])>a[j]&&(a[i]+a[j])>a[k])
               sum++;
           }
       }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <stack>

using namespace std;

typedef long long LL;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 105;

int main()
{
	bool vis[MaxN];
	int a, b ,c, ans = 0;
	memset(vis, 0 , sizeof(vis));
	cin >> a >> b >> c;
	vis[a] = true;
	vis[b] = true;
	vis[c] = true;
	for(int i = 1 ; i <= 100 ; i++)
		if(vis[i])ans++;
		cout << ans << endl;
	return 0;
	}

Measured memory_bytes: 256
N = int(input())
src = list(map(int,input().split()))
x4 = odd = 0
for a in src:
    if a%4 == 0:
        x4 += 1
    elif a%2:
        odd += 1

if odd <= x4:
    print('Yes')
elif odd == x4+1:
    print('Yes' if x4+odd == N else 'No')
else:
    print('No')

Measured memory_bytes: 14252
#include <iostream>
using namespace std;
int main()
{
	int N;
	cin >> N;
	int l, r;
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> l >> r;
		ans += (r - l + 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
//  RAKSHIT KADAM
//ALWAYS USE &IT FOR ITERATING USING AUTO ...
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!

    #define INF 2000000000000000005
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
 
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
//#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){ return power(a, m-2, m);}
ll dp[1043][4][2];
string n;ll k;
ll rec(ll f,ll ind,ll count)
{
    if(count>k)
    {
        return 0;
    }
    if(ind==n.length())
    {
        if(count==k)return 1;
        return 0;
        
    }
    if(dp[ind][count][f]!=-1)
    {
        return dp[ind][count][f];
    }
        
    ll lim;
    if(!f)lim=9;
    else
    {
        lim = n[ind]-'0';
    }
    ll ret = 0;
    for(ll i=0;i<=lim;i++)
    {
        ll newf=f;
        if(newf && i<(n[ind]-'0'))
        {
            newf&=0;
        }
        ret+= rec(newf,ind+1,((i==0)?(count):(count+1)));
        
    }
        return dp[ind][count][f]=ret;
}
void solve()
{
   cin>>n>>k;
    memset(dp,-1,sizeof dp);
    rec(1,0,0);
    cout<<dp[0][0][1]<<endl;
    
}
signed main()
{
 
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

  //  time;
 solve();
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  ll a[n+1]={};
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  sort(a,a+n);
  ll sum=0,ans=0;
  for(int i=0;i<n;i++){
    if(sum+a[i]<x&&i!=n-1){
      ans++;
      sum+=a[i];
    }else if(sum+a[i]==x){
      ans++;
      break;
    }
  }

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


Measured memory_bytes: 764
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+4;
struct Edge {
	int v,nxt;
}e[N<<1];
int head[N],etot;
int ans[N];
int n,m;
inline int read() {
	int x=0;char c=getchar();
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x;
}
inline void adde(int u,int v) {
	e[++etot].nxt=head[u],e[etot].v=v,head[u]=etot;
}
void dfs(int p,int fa) {
	for (int i=head[p];~i;i=e[i].nxt) {
		int v=e[i].v;
		if (v^fa) {
			ans[v]+=ans[p];
			dfs(v,p);
		}
	}
}
int main() {
	memset(head,-1,sizeof(head));
	n=read(),m=read();
	for (register int i=1;i<n;++i) {
		int u=read(),v=read();
		adde(u,v);
		adde(v,u);
	}
	for (register int i=0;i<m;++i) {
		int p=read(),x=read();
		ans[p]+=x;
	}
	dfs(1,0);
	for (register int i=1;i<=n;++i)
		printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 16384