akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  int M,D;
  cin >> M >> D;
  int cnt = 0;
  for(int i=1; i<=M; i++){
    for(int j=11; j<=D; j++){
      string S = to_string(j);
      if(S[0] <= '1' or S[1] <= '1') continue;
      if((S[0]-'0')*(S[1]-'0') == i) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A, B; cin >> A >> B;
    int ans = 0, preans = 1;
    while(preans < B) {
        ans++;
        preans += (A-1);
    }
    cout << ans;
    return 0;
}

/*
 * 4 10
 * 4*1 = 4
 * 4*2 - 1 = 7
 * 4*3 - 2 = 10
 *
 * 8 9
 * 8*1 - 0 = 8
 * 8*2 - 1 = 15
 * */

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

int int_sort( const void * a , const void * b ) {
  /* 引数はvoid*型と規定されているのでint型にcastする */
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}

int main(void) {
  int n, i;
  int* a;
  scanf("%d", &n);
  a = (int*)malloc(sizeof(int)*n);
  for(i=0; i<n; i++) {
    scanf("%d", &a[i]);
  }
  qsort((void*)a, n, sizeof(int), int_sort);
  for(i=1; i<n; i++) {
    if(a[i] == a[i-1]) {
      printf("NO\n");
      goto fin;
    }
  }
  printf("YES\n");
fin:
  free(a);  
  return 0;
}


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

typedef long long ll;

int main() {
    int H, W, N, a;
    cin >> H >> W;
    cin >> N;
    int cnt = 0;
    vector<int>c;

    for (int i = 0; i < N; i++) {
        cin >> a;
        for (int j = 0; j < a; j++) {
            c.push_back(i+1);
        }
    }

    while (cnt < H*W) {
        if ((cnt / W) % 2 == 0) {
            for (int i = 0; i < W; i++) {
                cout << c[cnt+i] << " ";
            }
        } else {
            for (int i = 1; i <= W; i++) {
                cout << c[cnt+W-i] << " ";
            }
        }
        cout << endl;
        cnt += W;
    }
    return 0;
}


Measured memory_bytes: 384
x,k,d = map(int,input().split())
if k * d < abs(x):
    print(abs(x) - k * d)
    exit()

amari = x % d
syou = x // d
a = k - syou
if a % 2 == 0:
    print(amari)
else:
    print(abs(d-amari))


Measured memory_bytes: 9168
/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl;
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl;
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl;
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl;
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl;
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 200010;

ll n, k, ar[maxn];

void MAIN() {

    cin >> n >> k;
    fori (i, n) cin >> ar[i];
    sort(ar, ar + n);
    ll s = 0;
    fori (i, n - k) {
        s += ar[i];
    }
    cout << s << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(

    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
signed main() {
  int N;
  while (cin>>N, N!=0) {
    if (N < 3) {
      cout << 1 << endl;
      continue;
    }
    int dp[N];
    dp[0] = 1;
    dp[1] = dp[0]+1;
    dp[2] = dp[1]+dp[0]+1; 
    for (int i = 3; i < N; i++) {
      dp[i] = dp[i-3] + dp[i-2] + dp[i-1];
    }
    cout << ceil((dp[N-1]/10.0)/365.0) << endl;
  }  
}



Measured memory_bytes: 3172
#include <algorithm>
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cctype>

using namespace std;

int main(void) {

    string word;
    int n;
    cin >> word >> n;

    for (int _ = 0; _ < n; ++_) {
        string op;
        int b, e;
        cin >> op >> b >> e;
        if (op == "replace") {
            string sub;
            cin >> sub;
            word.replace(b, sub.size(), sub);
        }
        else if (op == "reverse") {
            reverse(word.begin() + b, word.begin() + e + 1);
        }
        else if (op == "print") {
            cout << word.substr(b, e - b + 1) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()

const ll Mod = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n ,k ; cin >> n >> k;
	int cnt = 0 , x;
	for(int i = 0;i < n ; i++){
		cin >> x;
		if(x >= k)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long

string s[3];
int n[3];
int dp[3][3][2005];

int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  for(int i = 0; i < 3; i++) {
    cin >> s[i];
    n[i] = s[i].size();
  }
  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
      if(i == j) continue;
      for(int k = 0; k <= n[i]; k++) {
        int l = 0;
        for(; k + l < n[i] && l < n[j]; l++) {
          if(s[i][k + l] != s[j][l]) {
            if(s[i][k + l] == '?' || s[j][l] == '?') {
              continue;
            }
            break;
          }
        }
        if(k + l == n[i] || l == n[j]) dp[i][j][k] = 1;
      }
    }
  }
  int ans = n[0] + n[1] + n[2];
  vector<int> p = {0, 1 ,2};
  do {
    for(int i = 0; i <= n[p[0]]; i++) {
      for(int j = 0; j <= n[p[1]]; j++) {
        int d = max(n[p[0]], max(n[p[1]] + i, n[p[2]] + i + j));
        bool flag = false;
        if(dp[p[0]][p[1]][i] && dp[p[1]][p[2]][j]) {
          if(i + j < n[p[0]]) {
            if(dp[p[0]][p[2]][i + j]) {
              flag = true;
            }
          } 
          else {
            flag = true;
          }
        }
        if(flag) {
          ans = min(ans, d);
        }
      }
      for(int j = n[p[1]] + 1; j <= n[p[0]]; j++) {
        int d = max(n[p[0]], max(n[p[1]] + i, n[p[2]] + i + j));
        if(dp[p[0]][p[1]][i] && dp[p[0]][p[2]][i + j]) {
          ans = min(ans, d);
        }
      }
    }
  }while(next_permutation(p.begin(), p.end()));
  cout << ans << endl;
  return 0;
}


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

int main() {
	
	ll n, k; cin >> n >> k;

	ll ans = 1;
	ll cnt = n;
	ans *= k;
	cnt--;
	if (cnt != 0) {
		while (cnt--) {
			ans *= k - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main()
{
  int A, B, C; cin >> A >> B >> C;
  for (int i = 0; A*i < 100*B; ++i) {
    if (A*i % B == C) {
      cout << "YES";
      return 0;
    }
  }

  cout << "NO";
}

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

int dp[100005][2];

int func(int stones,int turn,vector<int> &v)
{
    if(stones<0)
    {
        if(turn==0)//turn 0 
        {
            return 0;
        }
        else if(turn==1)
        {
            return 1;
        }
    }
    
    if(dp[stones][turn]!=-1)
    {
        return dp[stones][turn];
    }
    
    if(stones==0)
    {
        if(turn==0)
        {
            return 1;
        }
        else if(turn==1)
        {
            return 0;
        }
    }
    
    for(int i=0;i<v.size();i++)
    {
        if(turn==1)
        {
            if(func(stones-v[i],(turn+1)%2,v)==1)
            {
                dp[stones][turn]=1;
                return 1;
            }
        }
        else if(turn==0)
        {
            if(func(stones-v[i],(turn+1)%2,v)==0)
            {
                dp[stones][turn]=0;
                return 0;
            }
        }
    }
    
    if(turn==1)
    {
        dp[stones][turn]=0;
        return 0;
    }
    else
    {
        dp[stones][turn]==1;
        return 1;
    }
    
    
}



int main()
{
    int n,k;
    cin>>n>>k;
    
    vector<int> v(n);
    
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }

    //turn//T 1
    //J 0

    int turn=1;
    memset(dp,-1,sizeof(dp));
    int a=func(k,turn,v);
    
    if(a==0)
    {
        cout<<"Second";
    }
    else if(a==1)
    {
        cout<<"First";
    }
    
    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1e18
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b,ll m){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a) % m;  a = (a * a) % m;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 2e5 + 7;
ll x,y;
bool X, Y;
string a;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a;
    x = (a[0] - '0') * 10 + (a[1] - '0');
    y = (a[2] - '0') * 10 + (a[3] - '0');
    if(x >= 1 && x <= 12) X = 1;
    if(y >= 1 && y <= 12) Y = 1;
    if(X){
        if(Y) cout<<"AMBIGUOUS";
        else
            cout<<"MMYY";
    }
    else{
        if(Y) cout<<"YYMM";
        else
            cout<<"NA";
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX_V 100001
#define MOD 1000000007
typedef vector<vector<int> > Graph;

int main(){
    ll a,b,n;cin>>a>>b>>n;
    if(b>n){
        cout<<a*n/b<<endl;
    }
    else{
        cout<<a*(b-1)/b<<endl;
    }
}

Measured memory_bytes: 3628
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N = INT()
A = LIST()
 
max_length = len("{:b}".format(max(A)))
 
cnt = [defaultdict(int) for _ in range(max_length)]
 
for i in range(N):
    num = "{:b}".format(A[i]).zfill(max_length)
    for j in range(len(num)):
        # [i桁目][numのj番目の数，(0 or 1)]
        # 0, 1 の数を数える
        cnt[max_length-1-j][num[j]] += 1
 
ans = 0
 
for i in range(max_length):
    # 1を左にiシフト(2 ** i 倍)
    # 桁内で0の個数 * 桁内で1の個数 が，XOR = 1になる数 (0 xor 1 = 1)
    ans = ans + (1 << i) * cnt[i]["0"] * cnt[i]["1"]
ans = ans % mod
print(ans)
 

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

namespace ProblemA
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = read[0];
            var K = read[1];
            var ret = N - K + 1;
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 11348
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  string S;
  cin >> S;
  if (S.size() == 3)
    reverse(S.begin(), S.end());
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string text1, text2, str;
    getline(cin, text1);
    getline(cin, text2);
	int m=text1.size()+1;
    int n=text2.size()+1;
        
    text1='*'+text1;
    text2='*'+text2;

    int lcs[m][n];
    for(int i=0;i<n;i++)
        lcs[0][i]=0;
    for(int i=0;i<m;i++)
        lcs[i][0]=0;
    for(int i=1;i<m;i++){
        for(int j=1;j<n;j++) {
            if(text1[i] == text2[j]) 
                lcs[i][j]=1+lcs[i-1][j-1];
                
             
            else
                lcs[i][j]=max(lcs[i-1][j], lcs[i][j-1]);
        }
    }
    int i=m-1;
    int j=n-1;
	
    	while(j-1>=0 && i-1>= 0) {
    		if(lcs[i][j] == 1 + lcs[i-1][j-1] && text1[i] == text2[j]) {
    			str=text1[i]+str;
    			i=i-1;
    			j=j-1;
    		}
    		else if(lcs[i][j] == lcs[i-1][j])
    			i=i-1;
    		else if(lcs[i][j] == lcs[i][j-1])
    			j=j-1;
    		
    		
    	}
    cout<<str<<"\n";
}
        

Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    string s;
    cin >> s;
    int n = (int) s.size();

    int score = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0 && s[i] == 'p') --score;
        else if (i % 2 != 0 && s[i] == 'g') ++score;
    }

    cout << score << endl;
}

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

using namespace std;

const int maxn = 100005;
int a[maxn], dp[maxn];

int findMin(int m)
{
	dp[1] = 0;
	dp[2] = abs(a[2] - a[1]);
	for(int n = 3; n <= m;n++)
	{
		dp[n] = min(dp[n-2]+abs(a[n-2]-a[n]), dp[n-1]+abs(a[n-1]-a[n])); 
	}
	return dp[m];
}


int main()
{
	int n;
	cin >> n;
	for(int i=1; i <= n; i++)
	{
    	cin >> a[i];
	}
	cout << findMin(n) <<endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, a, b;
  cin >> n >> a >> b;
  long long k = n / (a + b);
  long long ans = a * k;
  ans = ans + min((n - k * (a + b)), a);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	ll X, Y;
	
	cin >> X >> Y;

	ll ratio = Y / X;

	int i = 0;
	while( (1LL<<i) <= ratio )
	{
		i++;
	}

	cout << i << endl;

	
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;

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

    for(int i = x - (k-1); i <= x + (k-1); i++) {
        cout << i << " ";
    }

    return 0;
}

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

const int MAX_N = 200000;
long long int n;
long long int a[MAX_N];
long long int ans[MAX_N];
map<long long int, long long int> c;

void solve() {
    long long int all = 0;
    for (pair<long long int, long long int> p : c) {
        all += p.second * (p.second - 1) / 2;
    }

    for (int k = 0; k < n; k++) {
        ans[k] = all - (c[a[k]] - 1);
        cout << ans[k] << endl;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        c[a[i]]++;
    }
    solve();
}

Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
 
typedef long long LL;
typedef pair<int, int> PII;

const int MAX = 1 << 9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int n;
int d[MAX][MAX];
bool is[MAX][MAX];

bool ok(int x)
{
	return x >= 0 && x < n;
}

void dfs(int r, int c)
{
	FOR(i, 0, 4)
		if(ok(r + dx[i]) && ok(c + dy[i]) && d[r][c] + is[r][c] < d[r + dx[i]][c + dy[i]])
		{
			d[r + dx[i]][c + dy[i]] = d[r][c] + is[r][c];
			dfs(r + dx[i], c + dy[i]);
		}
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	FOR(i, 0, n)
		FOR(j, 0, n)
		{
			d[i][j] = min(i, j);
			d[i][j] = min(d[i][j], min(n - 1 - i, n - 1 - j));
			is[i][j] = true;
		}
	int ans = 0;
	FOR(i, 0, n * n)
	{
		int p;
		cin >> p;
		p--;
		int r = p / n, c = p % n;
		ans += d[r][c];
		is[r][c] = false;
		dfs(r, c);
	}
	cout << ans << "\n";
	return 0;
}


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

#define int long long
#define ll long long
#define vll vector<int>
#define mset(a) memset(a,0,sizeof(a))
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<(int)n; ++i)
#define for1(i,n) for(ll i=1; i<(int)n; ++i)
#define endl '\n'
#define MOD 1000000007
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
using namespace std;

vector<bool> sieve(ll n){
    vector<bool>prime(n+1,true);
    prime[0]=prime[1]=false;
    for(ll i=2; i<=n; ++i){
        if(prime[i]&&(i*i)<=n)
        for(ll j=i*i; j<=n; j+=i)prime[j]=false;
    }
    return prime;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//////////////////////////////////////////////////////////////

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    

    int r,c;
    cin>>r>>c;
    char grid[r][c];
    forn(i,r) forn(j,c) cin>>grid[i][j];

    int dp[r][c];
    mset(dp);

    for(int i=0; i<c; ++i) {
        if(grid[0][i] == '#')
        break;

        dp[0][i]=1;
    }

    for(int i=0; i<r; ++i) {
        if(grid[i][0] == '#')
        break;

        dp[i][0]=1;
    }

    for(int i=1; i<r; ++i) {
        for(int j=1; j<c; ++j) {
            
            int val1 = 0;
            int val2 = 0;

            if(grid[i][j] == '#') continue;
            if(i-1>=0) val1 = dp[i-1][j];
            if(j-1>=0) val2 = dp[i][j-1];

            dp[i][j] = val1+val2;
            dp[i][j]%=MOD;
        }
    }

    // forn(i,r) {
    //     forn(j,c) {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    cout<<dp[r-1][c-1];

    return 0;
}


Measured memory_bytes: 9088
#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>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll h[1000000];
ll v[1000000];
ll a[1000000];
ll b[1000000];
ll c[1000000];
ll DP[50][500][500];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll cup[101010];
bool red[101010];
int main() {
	cin>>N>>M;
	rep(i,0,N){
		cup[i]=1;
		red[i]=false;
	}
	red[0]=true;
	rep(i,0,M){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		cup[y]++;
		red[y]=max(red[y],red[x]);
		cup[x]--;
		if(cup[x]==0){
			red[x]=false;
		}
	}
	ans=0;
	rep(i,0,N){
		if(red[i])ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int ans = 0;
    for(int i=0;i<5;++i){
        int val;
        cin>>val;
        if(!val){
            ans = i+1;
        }
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3656
from bisect import bisect
import operator
import sys
from collections import defaultdict
readline = sys.stdin.readline
write = sys.stdout.write

N, Q = map(int, readline().split())
R = [int(readline()) for i in range(N)]
S = list(set(R))
S.sort()
mp = {e: i for i, e in enumerate(S)}
D = defaultdict(int)

T = R[:]
T.sort()
mpm = {}
for i, e in enumerate(T):
    mpm[e] = i

INF = 10**9+1
ps = []
for i in range(Q):
    t, x = readline().split(); x = int(x)
    if t == 'ADD':
        y = R[x-1]
        if D[y] == 0:
            z = mp[y]
            idx = bisect(ps, z-1)
            ps = ps[:idx] + [z] + ps[idx:]
        D[y] += 1
    elif t == 'REMOVE':
        y = R[x-1]
        D[y] -= 1
        if D[y] == 0:
            z = mp[y]
            idx = bisect(ps, z-1)
            ps.pop(idx)
    else:
        left = -1; right = INF
        while left+1 < right:
            mid = (left + right) >> 1
            prv = -1
            cnt = 0
            for e in ps:
                s = S[e]; v = mpm[s]
                idx = max(bisect(T, s-mid-1)-1, prv)
                cnt += v - idx
                prv = v
            if N - cnt <= x:
                right = mid
            else:
                left = mid
        if right == INF:
            write("NA\n")
        else:
            write("%d\n" % right)



Measured memory_bytes: 248104
def resolve():
    N, M = map(int, input().split())
    H = tuple(map(int, input().split()))
    C = [[] for i in range(N)]
    count = 0
    for i in range(M):
        A, B = map(int, input().split())
        C[A-1].append(B-1)
        C[B-1].append(A-1)
    for i in range(N):
        idx = 0
        if len(C[i]) == 0:
            count += 1
        for j in C[i]:
            idx += 1
            if H[i] <= H[j]:
                break
            if idx == len(C[i]):
                count += 1
    print(count)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 29352
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long int a[3][100005]={0},n,dp[100005][4];
long long int calc(long long int i,long long int type)
{
	if(dp[i][type]!=-1)
		return dp[i][type];
	else
	{
		long long int x,y,z;
		x=a[0][i]+calc(i-1,0);
		y=a[1][i]+calc(i-1,1);
		z=a[2][i]+calc(i-1,2);
		if(type==3)
		{
			dp[i][type]=x>y?x:y;
			dp[i][type]=dp[i][type]>z?dp[i][type]:z;
		}
		else if(type==2)
			dp[i][type]=x>y?x:y;
		else if(type==1)
			dp[i][type]=x>z?x:z;
		else
			dp[i][type]=y>z?y:z;
		return dp[i][type];
	}
}
int main()
{
	long long int i,j,ans;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[0][i]>>a[1][i]>>a[2][i];
	for(i=1;i<=n;i++)
		for(j=0;j<4;j++)
			dp[i][j]=-1;
	dp[1][3]=a[0][1]>a[1][1]?a[0][1]:a[1][1];
	dp[1][3]=dp[1][3]>a[2][1]?dp[1][3]:a[2][1];
	dp[1][2]=a[0][1]>a[1][1]?a[0][1]:a[1][1];
	dp[1][1]=a[0][1]>a[2][1]?a[0][1]:a[2][1];
	dp[1][0]=a[1][1]>a[2][1]?a[1][1]:a[2][1];
	ans=calc(n,3);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11904
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, x) = get!(usize, usize);
    let mut a = get!(String).split_whitespace().map(|t| t.parse::<usize>().unwrap()).collect::<Vec<_>>();

    let mut r = 0;
    if a[0] + a[1] > x {
        let d = (a[0] + a[1]) - x;
        r += d;
        if d > a[1] {
            a[1] = 0;
        } else {
            a[1] -= d;
        }
    }
    if a[0] + a[1] > x {
        a[0] = x;
    }
    for i in 1..n {
        if a[i-1] + a[i] > x {
            let d = (a[i-1] + a[i]) - x;
            a[i] -= d;
            r += d;
        }
    }
    println!("{}", r);
}

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

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

    if(a%3==0 || b%3==0|| (a+b)%3==0){
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
import re
import math
import random
import itertools

def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):

        if serial >= sqrt:
            return input_list

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False


if __name__ == '__main__':

    n = int(input())
    
    input_list = sieve_of_erastosthenes(55555)
    prime_list = [i for i, b in enumerate(input_list) if b == True]

    ans = list()
    for p in prime_list:
        if p % 5 == 1:
            ans.append(p)

    ans = ans[:n]

    for i in range(len(ans)-1):
        print("{} ".format(ans[i]), end='')
    print(ans[-1])



Measured memory_bytes: 4320
// 1_5_C
#include<stdio.h>

int main(void)
{
	int height, width, H, W;
	scanf("%d %d", &H, &W);
	if(H == 0 && W == 0){
		return 0;
	}

	for(height = 0; height < H; height++){
		for(width = 0; width <W; width++){
			if((height + width)%2){
				printf(".");
			}else{
				printf("#");
			}
		}
		printf("\n");
	}
	printf("\n");

	main();
}

Measured memory_bytes: 572
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

	public class Main {
	    public static void main(String[] args) throws Exception {
	        // Here your code !
	        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	        String line = br.readLine();
	        String line2 = br.readLine();
	        String[] ary = line2.split(" ");
	        long sum = 0;
	        List<Integer> list = new ArrayList<Integer>();
	        for(int i=0;i < ary.length;i++) {
	            list.add(new Integer(ary[i]));
	        }
	        Collections.sort(list);
	        for(Integer item : list) {
	            sum += item;
	        }
	        System.out.println(list.get(0) + " " + list.get(list.size() - 1) + " " + sum);
	    }
	}

Measured memory_bytes: 30304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (n == 2)
    {
        if(s[0]==s[1])
        {
            cout<<"1 2";
        }
        else
        {
            cout<<"-1 -1";
        }
        return 0;
    }
    rep(i, n - 2)
    {
        set<char> tmp;
        tmp.insert(s[i]);
        tmp.insert(s[i + 1]);
        tmp.insert(s[i + 2]);
        if (tmp.size() < 3)
        {
            cout << i + 1 << " " << i + 3;
            return 0;
        }
    }
    cout << "-1 -1";
    return 0;
}

Measured memory_bytes: 512
module Main where
--import Debug.Trace
import Data.List
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: [[Int]] -> [String]
solve [] = []
solve ([m,f,r]:ds) = case [m,f,r] of
    [-1,_,_]    -> "F": solve ds
    [_,-1,_]    -> "F": solve ds
    _   | ts >= 80  -> "A": solve ds
        | ts >= 65  -> "B": solve ds
        | ts >= 50  -> "C": solve ds
        | ts >= 30 && r >= 50 -> "C": solve ds
        | ts >= 30  -> "D": solve ds
        | otherwise -> "F": solve ds where ts = m + f

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

readUntil :: ([Int] -> Bool) -> IO [[Int]]
readUntil eof = iter where
    iter = readLine >>=
            (\a -> if eof a then return [] else fmap (a:) iter)
            
eof :: [Int] -> Bool
eof (m:f:r:xs) = all (<0) [m, f, r] 

main :: IO() 
main = do
    l   <- readUntil eof
    mapM_ putStrLn (solve l)



Measured memory_bytes: 4108
#include<deque>
#include<functional>
#include<utility>
#include<cstddef>
#include<cassert>

template<typename T, class Compare = std::less<T>>
class SlidingMinimum{
public:
	using value_compare = Compare;
	using value_type = T;
	using size_type = std::size_t;
	using container_type = std::deque<std::pair<const value_type, size_type>>;
protected:
	container_type c;
	value_compare comp;
public:
	SlidingMinimum(const value_compare &x = value_compare()) :comp(x){}
	const value_type &top()const{
		return c.front().first;
	}
	const size_type top_index()const{
		return c.front().second - 1;
	}
	void push(const value_type &x){
		size_type s = 1;
		while (!c.empty() && comp(x, c.back().first)){
			s += c.back().second;
			c.pop_back();
		}
		c.push_back(std::pair<const value_type, size_type>(x, s));
	}
	void push(value_type &&x){
		size_type s = 1;
		while (!c.empty() && comp(x, c.back().first)){
			s += c.back().second;
			c.pop_back();
		}
		c.push_back(std::pair<const value_type, size_type>(std::move(x), s));
	}
	void pop(){
		assert(!c.empty());
		if (!(--c.front().second))
			c.pop_front();
	}
};


#include<cstdio>
#include<utility>

int main(){
	int n, l;
	scanf("%d%d", &n, &l);
	SlidingMinimum<int> S;
	int a;
	n -= l;
	while (l--){
		scanf("%d", &a);
		S.push(std::move(a));
	}
	printf("%d", S.top());
	while (n--){
		S.pop();
		scanf("%d", &a);
		S.push(std::move(a));
		printf(" %d", S.top());
	}
	printf("\n");
	return 0;
}







Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

///////////////////////////



	
int main() {
	ll N;
	cin >> N;
	ll a[MAX], b[MAX];
	repn(i, N) cin >> a[i];
	repn(i, N) cin >> b[i];

	ll ans = 0;
	
	rep(i, 29) {
		vector<ll> x, y;
		ll M = pow(2, i);

		repn(i, N) {
			x.push_back(a[i] % (2*M));
			y.push_back(b[i] % (2*M));
		}
		sort(x.begin(), x.end());
		sort(y.begin(), y.end());

		ll v = 0;

		rep(i, N) {
			auto itr1 = lower_bound(y.begin(), y.end(), M - x[i]);
			auto itr2 = lower_bound(y.begin(), y.end(), 2*M - x[i]);
			auto itr3 = lower_bound(y.begin(), y.end(), 3*M - x[i]);
			auto itr4 = lower_bound(y.begin(), y.end(), 4 * M - x[i]);
			v += distance(itr1, itr2) + distance(itr3, itr4);
		}

		ans += M * (v % 2);

	}

	cout << ans;

	system("PAUSE");
}

Measured memory_bytes: 12532
#include <iostream>
using namespace std;
int main(void){
  int n;
  int a;
  int maxa=0;
  int mina=1000;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a;
    if(maxa<a){maxa=a;}
    if(mina>a){mina=a;}
  }
  cout << maxa-mina << endl;
  return 0;
}


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

int main(){
  int a[] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int x , y;
  cin >> x >> y;
  int A = 0;
  int B = 0;
  int C = 0;
  if(a[x] == a[y]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include  <unordered_set>
#include <unordered_map>
#define ll long long int
#define INF 1e9
#define INFL 1e15
#define MAXN 1e6
int getInt(char ch) {
    return (int) (ch - '0');
}
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int X, A, B;
    cin >> X >> A >> B;
    
    X -= A;
    
    X %= B;
    
    cout << X << endl;
    
}



























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int count = 0;
  for(int i = min(a, b); i >= 1; i--){
    if(a%i == 0 && b%i == 0){
      count += 1;
    }
    if(count == c){
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

vector<pair<i64, int>> factorize(i64 x)
{
    vector<pair<i64, int>> res;
    for (i64 f = 2; f * f <= x; f++)
    {
        if (x % f)
        {
            continue;
        }
        int cnt = 0;
        while (x % f == 0)
        {
            cnt++;
            x /= f;
        }
        res.push_back(make_pair(f, cnt));
    }
    if (x > 1)
    {
        res.push_back(make_pair(x, 1));
    }
    return res;
}

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    i64 ans = 0;
    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        ans += mp[i - a];
        mp[a + i]++;
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 20636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

int main(){
    std::string s;
    std::vector<int> n  = {0};

    std::cin >> s;

    for(int a = 0; a < s.size(); a++){
        if(s[a] == 'A' || s[a] == 'C' || s[a] == 'G' || s[a] == 'T'){
            int sum = 0;
            while(s[a] == 'A' || s[a] == 'C' || s[a]  =='G' || s[a] == 'T'){
                sum++;
                a++;
            }
            n.push_back(sum);
        }
    }

    std::vector<int>::iterator v = std::max_element(n.begin() ,n.end());
    size_t index = std::distance(n.begin() ,v);

    std::cout << n[index] << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
int cnt,n,prime[10000007];
using namespace std;

void getprime()
{
	/*int tt=0,flag;
	prime[tt++]=2;
	for(int i=3;i<=1000000;i++) 
	{
		flag=1;
		for(int j=0;prime[j]*prime[j]<=i;j++)
		{
			if(i%prime[j]==0)
			{	
			    flag=0;
		     	break;
			}
		}
		if(flag==1) prime[tt++]=i;
	}*/
	memset(prime,0,sizeof(prime));  
    for(int i = 2; i<=10000007; i++)  
    {  
        if (!prime[i]) prime[++prime[0]] = i;  
        for(int j = 1;j<=prime[0] &&prime[j] < 10000007/i;j++ )  
        {  
            prime[prime[j]*i] = 1;  
            if(i%prime[j]==0) break;  
        }  
    } 
}

int main()
{	getprime();
	while(cin >> n)
	{
       for(int i=1;;i++)
	   {
       	if(prime[i]>n)
		   {
       		printf("%d\n",i-1);
       		break; 
		   }
	   }
    }
}


Measured memory_bytes: 42160
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC075_B_Minesweeper
{
    class Program
    {
        static int H;
        static int W;
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            H = input[0];
            W = input[1];
            var list = new List<string>();
            var result = new int[H, W];

            for(var i = 0; i < H; i++)
            {
                list.Add(Console.ReadLine());
            }

            for (var i = 0; i < H; i++)
            {
                for(var j = 0; j < W; j++)
                {
                    if(list[i][j] != '#')
                    {
                        continue;
                    }

                    result[i, j] = -1;
                    AddBomCount(result, i, j);
                }
            }
            
            for (var i = 0; i < H; i++)
            {
                for(var j = 0; j < W; j++)
                {
                    Console.Write(result[i, j] == -1 ? "#" : result[i, j].ToString());
                }
                Console.WriteLine();
            }
        }

        static void AddBomCount(int[,] result,
                                int h,
                                int w)
        {
            for (var i = 0; i < 3; i++)
            {
                for(var j = 0; j < 3; j++)
                {
                    var a = h + i - 1;
                    var b = w + j - 1;
                    if(a < 0 || H <= a)
                        continue;
                    
                    if(b < 0 || W <= b)
                        continue;

                    if(result[a, b] == -1)
                        continue;

                    result[a, b]++;
                }
            }
        }
    }
}


Measured memory_bytes: 13396
import time

MOD = 10 ** 9 + 7

K = int(input())
S = input()
l = len(S)

fac = [1] * (K + l + 1)
invfac = [1] * (K + l + 1)
for i in range(1, K + l + 1):
	fac[i] = (fac[i - 1] * i) % MOD
	invfac[i] = pow(fac[i], MOD - 2, MOD)

p25 = [1] * (K + 1)
p26 = [1] * (K + 1)
for i in range(1, K + 1):
	p25[i] = (p25[i - 1] * 25) % MOD
	p26[i] = (p26[i - 1] * 26) % MOD

ans = 0
for en in range(l - 1, l + K):
	t = (fac[en] * invfac[en - l + 1]) % MOD
	t = (t * invfac[l - 1]) % MOD
	t = (t * p25[en - l + 1]) % MOD
	t = (t * p26[l + K - 1 - en]) % MOD
	ans = (ans + t) % MOD
print(ans)

Measured memory_bytes: 136564
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define Rep(i,v) rep(i,0,(int)v.size()-1)
#define mp make_pair
#define fir first
#define sec second
#define pb push_back
#define gc getchar()
#define lint long long
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
#define wrong return !printf("-1\n")
#define N 100010
using namespace std;
typedef pair<int,int> pii;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
struct P{
	lint d;int id;
	inline bool operator<(const P &p)const{return d>p.d;}
}p[N];int n;
vector<int> g[N];
int us[N],vs[N],sz[N];
lint d[N];map<lint,int> sv;
int getdrt(int x,int l,int rt)
{
	d[rt]+=l;
	Rep(i,g[x]) getdrt(g[x][i],l+1,rt);
	return 0;
}
int getd(int x)
{
	Rep(i,g[x]) d[g[x][i]]=d[x]+n-2*sz[g[x][i]],getd(g[x][i]);
	return 0;
}
int main()
{
	n=inn();
	for(int i=1;i<=n;i++) scanf("%lld",&p[i].d),p[i].id=i,sv[p[i].d]=i;
	for(int i=1;i<=n;i++) sz[i]=1;
	sort(p+1,p+n+1);//from big to small
	for(int i=1;i<n;i++)
	{
		int x=p[i].id;
		lint dlt=n-2*sz[x];
		if(dlt<=0) wrong;
		if(!sv.count(p[i].d-dlt)) wrong;
		int fa=sv[p[i].d-dlt];
		us[i]=x,vs[i]=fa,sz[fa]+=sz[x];
	}
	for(int i=1;i<n;i++) g[vs[i]].pb(us[i]);
	int rt=p[n].id;getdrt(rt,0,rt),getd(rt);
	for(int i=1;i<=n;i++)
		if(d[p[i].id]!=p[i].d) wrong;
	for(int i=1;i<n;i++) printf("%d %d\n",us[i],vs[i]);
}

Measured memory_bytes: 19712
using System;
using System.Linq;
using System.Collections.Generic;


public class CoinChanging
{
    public static void Main()
    {
        var inputs = Console.ReadLine().Split(' ').Select(int.Parse);
        var n = inputs.First();
        
        var coins = Console.ReadLine().Split(' ').Select(int.Parse);
        
        var totals = coins.ToList();
        var count = 1;
        
        var max = coins.Max();
        
        while (totals.All(x => x != n))
        {
            count++;
            
            totals = totals.SelectMany(x => 
            {
                return n - x > max * 10
                    ? new int[] { x + max }
                    : coins.Select(y => x + y);
//                return coins.Select(y => x + y);
            }).ToList();
            totals.RemoveAll(x => x > n);
            totals = totals.Distinct().ToList();
        }
    
        Console.WriteLine(count);
    
    }
}

// Define other methods and classes here

Measured memory_bytes: 23188