akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int n, m; cin>>n>>m;
    vector<vector<int>> g(n);
    int sa, sb;
    for(int i=0; i<m; i++){
        int a, b; cin>>a>>b;
        a--, b--;
        if(i==0) sa=a, sb=b;
        g[a].eb(b);
        g[b].eb(a);
    }

    list<int> lst;
    lst.push_front(sa), lst.push_back(sb);
    vector<bool> visited(n, false);
    visited[sa]=true, visited[sb]=true;
    queue<int> que;
    que.push(sa);
    while(que.size()){
        int cv=que.front(); que.pop();
        for(int i=0; i<g[cv].size(); i++){
            int nv=g[cv][i];
            if(!visited[nv]){
                visited[nv]=true;
                lst.push_front(nv);
                que.push(nv);
                break;
            }
        }
    }

    int tail=sb;
    que.push(sb);
    while(que.size()){
        int cv=que.front(); que.pop();
        for(int i=0; i<g[cv].size(); i++){
            int nv=g[cv][i];
            if(!visited[nv]){
                tail=nv;
                visited[nv]=true;
                lst.push_back(nv);
                que.push(nv);
                break;
            }
        }
    }

    cout << lst.size() << endl;
    for(auto itr=lst.begin(); itr!=lst.end(); itr++){
        if(*itr==tail) cout << *itr+1 << endl;
        else cout << *itr+1 << " ";
    }
}

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

int main(){
  string s; cin >> s;
  int n = s.size() - 1;
  ll ans = 0;
  for(int i = 0; i < (1 << n); i++){
    int cnt = 0;
    for(int j = 0; j < n; j++){
      if(i & (1 << j)){
        ans += stoll(s.substr(cnt, j+1-cnt));
        cnt = j+1;
      }
    }
    ans += stoll(s.substr(cnt, n+1));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{	
	int n;
	int i = 1;
	int x;

	cin >> n;

	while (i <= n)
	{
		x = i;

		if (x % 3 == 0)
			cout << " " << i;
		else
		{
			while (x % 10 != 3 && x>0)
			{
				x /= 10;
			}

			if (x % 10 == 3)
				cout << " " << i;
		}

		i++;
	}

	cout << endl;

	return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define int long long
using namespace std;
int h,n,a[200005],b[200005],dp[1005][10005];
int Rec(int i,int health){
    if(health <= 0)return 0;
    if(i == n){
        return 1e12;
    }
    if(dp[i][health] + 1)   return dp[i][health];
    int Ans = 1e12,Ans1 = 1e12;
    Ans = Rec(i,health - a[i]) + b[i];
    Ans1 = Rec(i+1, health);

    return dp[i][health] = min(Ans,Ans1);
}

main()
{

    memset(dp,-1,sizeof(dp));
    cin>>h>>n;
    for(int i = 0; i<n; i++){
        cin>>a[i]>>b[i];
    }
    cout<<Rec(0,h);



    return 0;
}


Measured memory_bytes: 80640
//#include "oj/atcoder.h"
//#include "std.h"
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <float.h>

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define SWAP(T,a,b) do { T _tmp=a; a=b; b=_tmp; } while (0)

//#include "oj/io.h"

void print_ai(int *a, int n) {
	for (int i=0; i<n; i++) {
		if (i) printf(" ");
		printf("%d", a[i]);
	}
	printf("\n");
}

void scan_ai(int *a, int n) {
	for (int i=0; i<n; i++)
		scanf("%d", &a[i]);
}

//#include "oj/debug.h"

void print_hr() {
	printf("---------------------------\n");
}



#define MAXN 200000

int main() {
	char s[MAXN+1];
	long ct[26];
	while (scanf("%s", s)==1) {
		memset(ct, 0, sizeof(ct));
		for (int i=0; s[i]; i++)
			ct[s[i]-'a']++;
		long r = 1;
		for (int i=0; i<26; i++)
			for (int j=i+1; j<26; j++)
				r += ct[i] * ct[j];
		printf("%ld\n", r);
	}
}



Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
        k: i32,
    }
    let mut ans = 0;
    let mut n = n;

    while n > 0 {
        n = n / k;
        ans += 1;
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string s;
    cin >> s;
    int res;
    int flagA = 0;
    int flagZ = 0;
    int cnt = 0;
    int Max = 0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A' && flagA==0){
            flagA = 1;
            cnt = i;
        }
        if(s[i] == 'Z' && flagA==1){
            res = i - cnt;
            Max = res;
        }
    }
    cout << Max+1 << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
    int n, i = 0;
    scanf("%d",&n);
    int h[n];
    int ans = 1;
    for(; i < n; i++)
        scanf("%d",&h[i]);
    for(i = 1; i < n; i++){
        int f = 1;
        for(int j = 0; j < i; j++){
            if(h[j] > h[i]){
                f = 0;
                break;
            }
        }
        if(f)
            ans ++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
 
const ll MOD = 1e9+7;
 
int main(){
    ll n; string s; cin >> n >> s;
    vector<vector<ll>> dp(n,vector<ll>(n,1));
    rep(i,n-1){
        // 累積和
        vector<ll> sum(n-i,0);
        rep(j,n-i) sum[j] = dp[i][j];
        rep(j,n-i-1) sum[j+1] += sum[j], sum[j+1] %= MOD;
        // DP遷移
        rep(j,n-i-1){
            if(s[i] == '<') dp[i+1][j] = sum[j] % MOD;
            else dp[i+1][j] = (sum[n-i-1] - sum[j] + MOD) % MOD;
        }
    }
    cout << dp[n-1][0] << endl;
}

Measured memory_bytes: 74032
from math import factorial as fact
n,m=map(int,input().split())
i,k=0,0
if n<2 and m<2:
  print(0)
else:
  if n==0:i=0
  elif n==2:
  	i=1
  elif n!=1:
    i=fact(n)/fact(2)/fact(n-2)
  if m==0:k=0
  elif m==2:
  	k=1
  elif m!=1:
    k=fact(m)/fact(2)/fact(m-2)
  print(int(i+k))

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// Nの入力
		int N = sc.nextInt();
		
		// Liの入力
		Integer[] L = new Integer[N];
		for (int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
		}
		
		// Liを降順にソートして、長い2辺の差より長い1辺を探す
		Arrays.sort(L, Collections.reverseOrder());
		int count = 0;
		for (int i = 0; i < N - 2; i++) {
			int a = L[i];
			for (int j = i + 1; j < N -1; j++) {
				int b = L[j];
				if (b < a - b) {
					break;
				}
				for (int k = j + 1; k < N; k++) {
					int c = L[k];
					if (c > a - b) {
						count++;
					}
					else {
						break;
					}
				}
			}
		}
		
		// 結果の出力
		System.out.println(count);
		
		sc.close();
	}
}


Measured memory_bytes: 25964
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
const int N=1e9+7;
#define int long long
#define double long double
int mod_expo_iterative(int x, int y,  int mod) {
  int an = 1;
  while(y>0) {
    if(y&1) {
      an = (an*x)%mod;
    }
    x = (x*x)%mod;
    y/=2;
  }
  return (int)an;
}
int32_t main()
{
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
 IOS;
int n;
cin>>n;
int ans=mod_expo_iterative(10ll,n,N)-(2*mod_expo_iterative(9ll,n,N))%N+mod_expo_iterative(8ll,n,N)+N;
ans%=N;
cout<<ans;
 	



  
 




  
return 0;
}


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

int main()
{
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    while(1){
        C-=B;
        if(C<=0){
            cout << "Yes" << endl;
            break;
        }
        A-=D;
        if(A<=0){
            cout << "No" << endl;
            break;
        }


    }
}

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=(ll)a-1;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<26;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll 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 (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j=0,N,K;
  string s,ans="";
  cin>>s;
  N=s.size();
  vec term(1,N),ch(26,0);
  brep(i,N){
    j|=1LL<<(s[i]-'a');
    if(j+1==inf){
      j=0;
      term.pb(i);
    }
  }
  K=term.size();
  rep(j,term[K-1])++ch[s[j]-'a'];
  N=0;
  while(ch[N])++N;
  ans+='a'+N;
  brep(i,K-1){
    ch=vec(26,0);
    while(s[j++]-'a'!=N);
    while(j<term[i])++ch[s[j++]-'a'];
    N=0;
    while(ch[N])++N;
    ans+='a'+N;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python

import sys

def main():
    n = int(raw_input())
    for i in range(3, n+1):
        if three(i):
            sys.stdout.write(' {}'.format(i))
    print

def three(i):
    if i%3 == 0:
        return True

    while i > 0:
        if i%10 == 3:
            return True
        i /= 10

    return False

if __name__ == '__main__':
    main()



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

int main(){
	int n;
	cin >> n;
	vector<int> mochi(n);
	rep(i, n) cin >> mochi.at(i);
	vector<int> num(110);
	
	int res = 0;
	rep(i, n) num.at(mochi.at(i))++;
	rep(i, 110){
		if(num.at(i))
			res++;
	}

	cout << res << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define vi vector<int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
using namespace std;

ll fun(ll h){
	if(!h){
		return 0;
	}
	return 2 * fun(h / 2) + 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	// int t;
	// cin>>t;
	// while(t--){
		
	// }
	ll h;
	cin>>h;
	cout<<fun(h)<<endl;
	return 0;
}

Measured memory_bytes: 256
var input=require("fs").readFileSync("/dev/stdin","utf8");

input=input.split(" ");
var W=parseInt(input[0]);
var H=parseInt(input[1]);
var x=parseInt(input[2]);
var y=parseInt(input[3]);
var r=parseInt(input[4]);

if(x-r<0||x+r>W){
    console.log("No");
}
else if(y-r<0||y+r>H){
    console.log("No");
}
else{
    console.log("Yes");
}


Measured memory_bytes: 15096
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin>>N;
  int cnt = 0;
  M = N;
  while(M>=1){
    cnt = cnt + M % 10;
    M /= 10;
  }
  //cout << cnt << endl;
  if(N % cnt == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3560
# include <iostream>
# include <stack>
# include <iomanip>

int main() {
	int H, W;
	while (true) {
		std::cin >> H >> W;
		if (H == 0 && W == 0)
			break;
		for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				if ((x + y) % 2 == 0)
					std::cout << "#";
				else
					std::cout << ".";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	return 0;
}

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

using namespace std;

#define REP(i,a,b) for(ll i = a; i < b; i++)
#define DB( x ) cout << #x << " = " << x << endl;
#define sz(s) ((int)((s).size()))
#define endl '\n'

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, pii> tri;
typedef vector <vector <ll>> matrix;
typedef pair<string, string> pss;

const ll mod = (ll)1e9 + 7;
const int MAX = 4000;

double dp[MAX][MAX];

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

	cout << setprecision(9) << fixed;

    int n; cin >> n;
    
    vector<double> v(n + 1, 0.0);
    
    for(int i = 1;i <= n;++i)
		cin >> v[i];
	
	dp[0][0] = 1;
	
	for(int i = 1;i <= n;++i){
		dp[0][i] = (1 - v[i])*dp[0][i - 1];
		for(int j = 1;j <= i;++j){
			dp[j][i] = dp[j][i - 1] * (1 - v[i]) + dp[j - 1][i - 1] * v[i];
		}
	}
	
	double solve = 0;
	
	for(int i = (n + 1)/ 2;i <= n;++i)
		solve += dp[i][n];
	cout << solve << endl;
}


Measured memory_bytes: 94208
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	w       = bufio.NewWriter(os.Stdout)
)

func readInt() (read int) {
	scanner.Scan()
	read, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner.Split(bufio.ScanWords)
	defer w.Flush()

	n := readInt()

	s := make(map[string]int, n)
	for i := 0; i < n; i++ {
		key := readString()
		s[key]++
	}

	fmt.Printf("AC x %d\n", s["AC"])
	fmt.Printf("WA x %d\n", s["WA"])
	fmt.Printf("TLE x %d\n", s["TLE"])
	fmt.Printf("RE x %d\n", s["RE"])

}

Measured memory_bytes: 2200
package main

import (
        "fmt"
)

func main() {
        var a, b, k int
        fmt.Scanf("%d %d %d\n", &a, &b, &k)

        if a+k-1 >= b-k+1 {
                for i := a; i <= b; i++ {
                        fmt.Println(i)
                }
                return
        }
        for i := a; i < a+k; i++ {
                fmt.Println(i)
        }
        for i := b - k + 1; i <= b; i++ {
                fmt.Println(i)
        }
}

Measured memory_bytes: 512
S=input()
s=int(len(S))
p=1
for i in range(int((((s-1)/2)+1)/2)):
    if S[i]==S[int((s-1)/2-(i+1))]==S[s-i-1]==S[int((s-1)/2+(i+1))]:
        p=p*1
    else:
        p=p*0
if int(p)==1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
ll n,m,c=0;
cin>>n;
ll i;
vector<ll>v,v1;
for(i=0;i<n;i++)
{
    cin>>m;
    v.pb(m);
}
v1=v;
sort(v.begin(),v.end());
for(i=0;i<n;i++)
{
    if(v[i]!=v1[i])
        c++;
}
if(c==0 || c==2)
    cout<<"YES"<<endl;
else
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
T_HP,T_Atk,A_HP,A_Atk = map(int,input().split())

Takahashi = [T_HP,T_Atk]
Asakura = [A_HP,A_Atk]

    
while True:    
    Asakura[0] -= Takahashi[1]
    if Asakura[0] < 1:
        print("Yes")
        exit()
    
    
    Takahashi[0] -= Asakura[1]
    if Takahashi[0] < 1:
        print("No")
        exit()


Measured memory_bytes: 9176
#include <stdio.h>

int main(void) {
	int i,n,t,j,w;
	t=0;
	scanf("%d",&n);
	int a[n],b[n],c[n-1];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&b[i]);
		t+=b[i];
	}
	for(i=0;i<n-1;i++){
		scanf("%d",&c[i]);
	}
	for(i=0;i<n-1;i++){
		j=i+1;
		if(a[i]+1==a[j]){
			w=a[i]-1;
			t+=c[w];
		}
	}
	printf("%d",t);
	
	
	
	// your code goes here
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
const ll INF = 1e16;

void solver(int N, vector<ll> const &a, bool &flg){

    int cnt_4bynum{}, cnt_odd{};
    for(auto iter = a.begin(); iter != a.end(); ++iter){
        if(*iter%4LL == 0) ++cnt_4bynum;
        else if(*iter%2 != 0) ++cnt_odd;
    }

    int thr = N/2;
    if(cnt_4bynum >= thr) flg = true;
    else{
        if(cnt_4bynum >= cnt_odd) flg = true;
        else flg = false;
    }

    return;
}

int main(){

    int N;
    cin >> N;
    vector<ll> a(N);
    for(auto iter = a.begin(); iter != a.end(); ++iter) cin >> *iter;

    bool flg = false;
    solver(N, a, flg);

    if(flg) cout << "Yes"s << endl;
    else cout << "No"s << endl;

    return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b)
{
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    vector<pair<ll, ll>> a(M);
    for (int i = 0; i < M; i++)
    {
        ll A, B;
        cin >> A >> B;
        a[i] = make_pair(B, A);
    }
    SORT(a);
    ll ans = 1;
    ll cut = a[0].first - 1;
    for (int i = 0; i < M; i++)
    {
        if (a[i].second <= cut && cut <= a[i].first)
        {
            continue;
        }
        else
        {
            ans++;
            cut = a[i].first - 1;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  long long N,A,B;
  cin >> N >> A >> B;
  long long s;
  if (A == 0) {
    s = 0;
  }
  else if (N%(A+B) < A) {
    s = N%(A+B);
  }
  else {
    s = A;
  }
  cout << A*(N/(A+B))+s << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//templete
int main() {
	string S,T;
	cin>>S>>T;
	int alpha[26]={};
	for(int i=0;i<S.length();i++)
		alpha[S[i]-'a']++;
	for(int i=0;i<T.length();i++){
		if(alpha[T[i]-'a']==0){
			cout<<-1<<endl;
			return 0;
		}
	}

	vll place[26];
	for(int i=0;i<S.length();i++){
		place[S[i]-'a'].pb(i);
	}
	ll now=-1,loop=0;
	for(int i=0;i<T.length();i++){
		//cout<<i<<" "<<now<<endl;
		char next=T[i];
		if(place[next-'a'].back()<=now){
			i--;
			loop++;
			now=-1;
			continue;
		}
		auto itr=upper_bound(place[next-'a'].begin(),place[next-'a'].end(),now);
		now=*itr;
	}
	cout<<loop*ll(S.length())+now+1<<endl;
	return 0;
}

Measured memory_bytes: 1724
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int aa[200001], bb[200001];
int main() {
	long long n, a, b; cin >> a >> b;
	if (abs(a - b) % 2 == 1) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << abs(a - b) / 2 + min(a, b) << endl;
	}
	cin >> n;
}

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

int main(){
    int N;
    long long ans = 0;
    std::cin>>N;
    std::vector<int> triangle(N);
    for(int i=0;i<N;i++)std::cin>>triangle[i];

    std::sort(triangle.begin(),triangle.end());
    for(int i=0;i<N;i++){
        for(int j=i+1; j<N; j++){
            int leni = triangle[i];
            int lenj = triangle[j];
            int min = std::upper_bound(triangle.begin(),triangle.end(),lenj-leni)-triangle.begin();
            int max = std::lower_bound(triangle.begin(),triangle.end(),lenj+leni)-triangle.begin();
            int length = max-min;
            if(min<=i&&max>i)length-=1;
            if(min<=j&&max>j)length-=1;
            ans += length;
        }
    }
    std::cout<<ans/3<<std::endl;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, k;
int main(){
	cin >> n >> k;
	cout << (k != 1 ? n - k : 0) << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
flag=0
A=a.sort()
num=[]

if n%2==0:
    for i in range(1,n,2):
        num.append(i)
        num.append(i)

if n%2==1:
    num=[0]
    for i in range(2,n,2):
        num.append(i)
        num.append(i)

if num==a:
    print(2**(n//2)%(10**9+7))

else:
    print("0")

Measured memory_bytes: 20624
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 500020
#define P 9191891
#define MO 1000000007
#define LL long long
LL hash[MAXN],Pow[MAXN];
char s[MAXN];
int n;
bool vis[MAXN];
bool check(int x)
{
	LL cmp;
	for(int i=2*x;i<=n;i+=x)
		if((hash[i-x]*Pow[x]+hash[x])%MO==hash[i])
			vis[i]=1;
		else
		{
			cmp=(hash[n]-hash[n-x]*Pow[x]%MO+MO)%MO;
			for(int j=n-x*2;j>0;j-=x)
				if((hash[j]*Pow[x]+cmp)%MO==hash[j+x])
					vis[j]=1;
				else break;
			return 0;
		}
	return n%x==0;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	Pow[0]=1;
	for(int i=1;i<=n;i++)
		Pow[i]=P*Pow[i-1]%MO;
	int mn=n+1;
	for(int i=1;i<=n;i++)
		hash[i]=(hash[i-1]*P+s[i]-'a')%MO;
	for(int i=1;i<=n/2;i++)
		if(check(i))
		{
			mn=i;
			break;
		}
	if(mn==n+1)
		printf("1\n1\n");
	else if(mn==1) printf("%d\n1\n",n);
	else
	{
		int ans;
		if(n/mn==2) ans=n-1;
		else ans=n-n/mn;
		for(int i=2;i<mn;i++) if(vis[i]) ans--;
		for(int i=n-1;i>n-mn;i--) if(vis[i]) ans--;
		printf("2\n%d\n",ans);
	}
}

Measured memory_bytes: 8960
n = gets.chomp.to_i
a = gets.split.map(&:to_i)
count = {}
ans = 0
a.each do |i|
  if count[i] == i
    count[i] = -1
    ans += 1
  elsif count[i] == -1
    ans += 1
  else
    if count[i]
      count[i] += 1
    else
      count[i] = 1
    end
  end
end
count.each do |k, v|
  ans += v if v > 0 && v != k
end
puts ans


Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
#define forn(i,n) for(int i=0; i < int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fst first
#define snd second

const ll N = 1e5+20;

ll n, xs[N];

ll count(ll median) {
    ll countgt0 = 0;
    ll ans = 0;
    ll offset = 0;
    unordered_map<ll, ll> M;
    forn(i, n) {
        if (xs[i] >= median) {
            --offset;
            ++M[offset+1];
            countgt0 += M[offset] + 1;
        }
        else {
            ++offset;
            countgt0 -= M[offset-1];
            ++M[offset-1];
        }
        ans += countgt0;
    }
    return ans;
}

/*
ll brute() {
    vll medians;
    for (int i = 0; i < n; ++i) for (int j = i; j < n; ++j) {
        vll tmp;
        for (int k = i; k <= j; ++k) tmp.pb(xs[k]);
        sort(all(tmp));
        int sz = tmp.size();
        medians.pb(tmp[sz/2]);
    }
    sort(all(medians));
    return medians[(medians.size())/2];
}
*/

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    forn(i, n) cin >> xs[i];
    ll nn = 1ll*n*(n-1)/2 + n;
    ll lo = *min_element(xs, xs+n);
    ll hi = *max_element(xs, xs+n);
    while (lo < hi) {
        ll mid = (lo + hi + 1) / 2;
        if (2*count(mid) >= nn)
            lo = mid;
        else
            hi = mid - 1;
    }
    forn(i, n) if (xs[i] == lo) goto ok;
    assert(false);
ok:
    cout << lo << '\n';
    //cout << brute() << '\n';
    //cout.flush();
    //assert(lo == brute());
}


Measured memory_bytes: 4516
#include<bits/stdc++.h>
using namespace std;int a[100000];int main(){int n,m;cin>>n>>m;for(int i=1;i<=n;i++)cin>>a[i];sort(a+1,a+n+1);int sum=0;for(int i=n;i>=n-m+1;i--)sum+=a[i];cout<<sum;return 0;}

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

int main(){
 int n,m,ab = 0;
 int a[100][100],b[100];

 cin >> n >> m;

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

 for(int i = 0; i < m; i++){
  cin >> b[i];
 }

 for(int i = 0; i < n; i++){
  ab = 0;
  for(int j = 0; j < m; j++){
   ab += a[i][j] * b[j];
  }
  cout << ab << endl;
 }

 return 0;
}

Measured memory_bytes: 1200
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int N;
	cin >> N;
	string S;
	cin >> S;

	ll kotae = 0;
	int R = 0, G = 0, B = 0;
	rep(i, N) {
		if (S[i] == 'R') R++;
		if (S[i] == 'G') G++;
		if (S[i] == 'B') B++;
	}
	kotae = ll(R) * G * B;

	rep1(d, N) {
		rep(i, N) {
			if (i + d + d >= N) break;
			int a = i;
			int b = i + d;
			int c = i + d + d;
			if (S[a] != S[b] && S[b] != S[c] && S[a] != S[c]) kotae--;
		}
	}
	co(kotae);


	Would you please return 0;
}

Measured memory_bytes: 3672
Scanf.scanf "%s" (fun s ->
    let n = String.length s in

    let rec loop i tame acc =
        if i = n then acc else
            if s.[i] = 'S' then loop (i + 1) (tame + 1) (acc + 1) else
                if tame > 0 then loop (i + 1) (tame - 1) (acc - 1) else
                    loop (i + 1) tame (acc + 1)
    in
    loop 0 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 4492
h,w=map(int,input().split())
g=[input() for _ in range(h)]
def search(y,x):
	q=[(y,x)]
	vis=[[-1]*w for _ in range(h)]
	vis[y][x]=0
	while q:
		cy,cx=q.pop(0)
		for dy,dx in ((1,0),(-1,0),(0,1),(0,-1)):
			ny,nx=cy+dy,cx+dx
			if 0<=ny<h and 0<=nx<w and g[ny][nx]=="." and vis[ny][nx]==-1:
				vis[ny][nx]=vis[cy][cx]+1
				q.append((ny,nx))
	return max(max(l) for l in vis)
ans=0
for i in range(h):
	for j in range(w):
		if g[i][j]==".":
			ans=max(search(i,j),ans)
print(ans)

Measured memory_bytes: 3064
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

a,b,c,d = map(int,readline().split())

print(max(a*c, a*d, b*c, b*d))



Measured memory_bytes: 9420
#include <stdio.h>

int main() 
{
    int x,y,z;
    int temp;
    scanf("%d%d%d",&x,&y,&z);
    temp=x;
    x=y;
    y=temp;
    temp=z;
    z=x;
    x=temp;
    printf("%d% d% d",x,y,z);
  
    return 0;
}


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

int main(){
  long L, R;
  if(scanf("%ld %ld", &L, &R) == EOF) exit(1);
  /*
    L = L % 2019;
    R = R % 2019;
  */
  long min = 2018;
    for(long i = L; i < R; i++){
      for(long j = i+1; j < R+1; j++){
        long a = (i*j) % 2019;
        if(a == 0){
          min = a;
          break;
        }
        if(a < min) min = a;
      }
      if(min == 0) break;
    }
  //if(answer == 2019) answer = 0;
  
  printf("%ld", min);
  return 0;
}



Measured memory_bytes: 128
#include <stdio.h>
 
int main(void) {
	int a,b,c,d;
	double x;
	scanf("%d %d",&a,&b);
	c=a/b;
	d=a%b;
	x=1.0*a/b;
	printf("%d %d %lf\n",c,d,x);
	return 0;
}


Measured memory_bytes: 2112
class struct:
  def __init__(self,i,a,b,c):
    self.i=i
    self.a=a
    self.b=b
    self.c=c
n,m=map(int,input().split())
l=[]
l2=[]#市番
for i in range(n):
  l2.append(1)
for i in range(m):
  a,b=map(int,input().split())
  l.append(struct(i,a,b,0))
l=sorted(l,key=lambda x:(x.a,x.b))
for i in range(m):
  a=l[i].a
  l[i].c=l2[a-1]
  l2[a-1]+=1
l=sorted(l,key=lambda x:x.i)
for i in l:
  print(str(i.a).zfill(6)+str(i.c).zfill(6))

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

#define ll long long
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)

//library----------------------------------------------


int main(){
  int a,b;cin>>a>>b;
  if(b%a==0){
    printf("%d\n",a+b);
  }else{
    printf("%d\n",b-a);
  }
  
  return 0;
}

Measured memory_bytes: 256
//सत्यान्न प्रमदितव्यम्  ||
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
// #define mp make_pair
#define nt _int128 
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define inf 0x3f3f3f3f
 
const ll mod = 998244353;
#define mx 100005
const ll mxi = 2e3 + 5;

    vector<ll> mp[mx];
int main()
{
    fast_as_levi;
    ll i,j,n,m;
    cin>>n>>m;
    // map<ll,vector<ll>> mp;
    while(m--)
    {
        ll x;
        string ch;
        cin>>x>>ch;
        if(ch=="AC")
        {
            x--;
            mp[x].pb(1);
        }
        else
        {
            x--;
            mp[x].pb(-1);
        }
    }
    ll ac=0,pen=0;
    for(i=0;i<n;i++)
    {
        ll fl=0;
        ll z=0;
        for(j=0;j<mp[i].size();j++)
        {
            if(mp[i][j]==-1)
            {
                z++;
                // pen++;
            }
            else
            {
                fl=1;
                ac++;
                break;
            }
        }
        if(fl)
        {
            pen+=z;
        }
    }
    cout<<ac<<" "<<pen;
}

Measured memory_bytes: 5760
// C - K-th Substring
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	string s; int k; cin>>s>>k;
	vector<string> c;
	rep(i, s.size())
		rep(j, k) c.push_back(s.substr(i, j+1));
	sort(c.begin(), c.end());
	string pre = "";
	for(auto x:c){
		if(pre == x) continue;
		if(--k == 0){ cout<< x <<"\n"; break; }
		pre = x;
	}
}


Measured memory_bytes: 1660
s=input()
a=1
p=[0 for i in s]
#for i in range(len(s)-1):
s=iter(s)
i=0
j=next(s,'')
while j!='':
    k=next(s,'')
    #print(j,k)
    if j==k:
        a+=1
    else:
        if j=='R':
            p[i]-=-a//2
            p[i+1]+=a//2
        else:
            p[i-a+1]-=-a//2
            p[i-a]+=a//2
        a=1
    j=k
    i+=1
print(*p)

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

long long sum(long long x) {
    return (x*x+x)/2;
}

int main(void) {
    long long n;
    scanf("%lld",&n);
    printf("%lld",sum(n)-3*sum(n/3)-5*sum(n/5)+15*sum(n/15));
}

Measured memory_bytes: 3824
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

int run(istream& in, ostream& out) {
    ll A, B;
    in >> A >> B;
    ll ans = 0;
    while(1+ans * (A-1) < B) {
        ++ans;
    }
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int x, i;

    i = 1;

    while(1){
             scanf("%d", &x);
             if(x == 0)
                break;
             
                printf("Case %d: %d\n", i, x);
       
                i++;
}


    return 0;
}


Measured memory_bytes: 1932
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}

void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}

#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const double PI = acos(-1);
typedef long long ll;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

void solve() {
    cini(n);
    cinai(a,n);

    vi dp(n);
    map<int,int> f;
    for(int i=0; i<n; i++) {
        dp[i]=a[i]-i;
        f[dp[i]]++;
    }

    int ans=0;
    for(int i=0; i<n; i++) {
        f[dp[i]]--;
        ans+=f[-a[i]-i];
    }
    cout<<ans<<endl;
    
}

signed main() {
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
}



Measured memory_bytes: 29036
// @{Problem} https://atcoder.jp/contests/code-festival-2016-qualb/tasks/codefestival_2016_qualB_b
use proconio::input;

fn main() {
    input! {
        _n: u32,
        a: u32,
        b: u32,
        s: String,
    }

    let mut rm_a = a as i32;
    let mut rm_b = b as i32;

    for char in s.chars() {
        if rm_a + rm_b <= 0 {
            println!("No");
            continue;
        }

        match char {
            'a' => {
                if rm_a > 0 {
                    rm_a = rm_a - 1;
                } else {
                    rm_b = rm_b - 1;
                }
                println!("Yes");
            },
            'b' => {
                if rm_b > 0 {
                    rm_b = rm_b - 1;
                    println!("Yes");
                } else {
                    println!("No");
                }
            },
            'c' => println!("No"),
            _ => (),
        }

    }
}


Measured memory_bytes: 2272
import sys
import numpy as np
import math
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))
n,k = Mi()
a = np.array(sys.stdin.readline().split(), np.int64)
mina = np.sum(a//(n+k))
maxa = np.max(a)
while maxa > mina+1:
  mid = (mina+maxa)//2
  div = np.sum(np.ceil(a/mid-1))
  if div > k:
    mina = mid
  else:
    maxa = mid
  
print(maxa)

Measured memory_bytes: 52744
#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

ll gcf(ll a, ll b){
    if(b == 0) return a;
    return gcf(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcf(a, b);
    return a/g*b;
}

int main(){
    ll N,X; cin >> N >> X;
    vector<ll> x(N); for(int i = 0; i < N; i++) cin >> x[i];
    sort(x.begin(),x.end());
    ll ans = gcf(abs(X-x[0]),0);
    for(int i = 0; i < N - 1; i++){
        ans = gcf(ans,x[i+1]-x[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio> 
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;

int n,k,cnt;
string s;

int main(){
	cin>>n>>k;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]==s[i+1]) cnt++; 
	}
	printf("%d",min(n-1,cnt+2*k));
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18


int main(){
   int N,M; cin >> N >> M;
   vector<long long> dp(N+10);
   vector<int> a(M);
   rep(i,M){
       cin >> a[i];
   }
   if(M != 0){
    dp[0] = 1;
    if(*lower_bound(a.begin(),a.end(),1) == 1) dp[1] = 0;
    else dp[1] = 1;
    rep(i,N){
        if(i+2 <= a[M-1]){
            if(*lower_bound(a.begin(),a.end(),i+2) == i+2) dp[i+2] = 0;
            else dp[i+2] = dp[i+1] + dp[i];
            dp[i+2] %= MOD;
        }
        else dp[i+2] = dp[i+1] + dp[i];
            dp[i+2] %= MOD;
    }
    rep(i,M-1){
        if(a[i+1] == a[i]+1){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << dp[N] << endl;
   }
   else{
       dp[0] = 1;
       dp[1] = 1;
       rep(i,N){
           dp[i+2] = (dp[i+1] + dp[i]) % MOD;
       }
       cout << dp[N] << endl;
   }
}
  


  


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

int main(){
  int N;
  cin >> N;
  string S;
  int x=0,maxi;
  cin >> S;
  maxi=0;
  for(int i=0;i<S.size();i++){
    if(S[i]=='I'){
      x++;
    }else if(S[i]=='D'){
      x--;
    }
    maxi = max(maxi,x);
  }
  cout << maxi << endl;
}

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

using namespace std;

#define INF 1/0.
#define fac(x) lgammal((x)+1.0)
#define C(x,y) (x<y?-INF:fac(x)-fac(y)-fac(x-y))

int n,a[300000],x,y;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	x=-1; y=0;
	for (int i=1;i<=n;++i){
		int k=lower_bound(a+1,a+n+1,a[i]/2)-a;
		if (k-1>0){
			if (C(a[i],a[k-1])>C(x,y)){
				x=a[i]; y=a[k-1];
			}
		}
		if (k<i){
			if (C(a[i],a[k])>C(x,y)){
				x=a[i]; y=a[k];
			}
		}
	}
	printf("%d %d\n",x,y);
	
	return 0;
}
			

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

int n, a[100];
int ta = 0;
int iwa = 0;

int main(){
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = n - 1; i >= 0; i--) {
		if ((n - i) % 2 == 0) {
			ta += a[i];
		}
		else {
			iwa += a[i];
		}
	}
	cout << iwa - ta << endl;
	return 0;
}

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

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

typedef long long ll;

ll INF = 100000000000000;
ll MOD = 1e9+7;

int main(){
  ll N,S;cin >> N >> S;
  vector<ll> W(N),V(N);
  for(int i = 0;i < N;i++){
      cin >> W[i] >> V[i];
  }
  vector<vector<ll>> dp(110,vector<ll>(100010));
  for(int i = 0;i < 110;i++){
      for(int j = 0;j < 100010;j++){
          dp[i][j] = 0;
      }
  }
  for(int i = 0;i < N;i++){
      for(int j = 0;j <= S;j++){
          if(W[i] <= j){
              dp[i+1][j] = max(dp[i][j],dp[i][j-W[i]] + V[i]);
          }else{
              dp[i+1][j] = dp[i][j];
          }
      }
  }
  cout << dp[N][S] << endl;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    ll ans = 0, i = 1;
    for (i=1; i<=n; ++i) {
        ll k = n / i;
        ans += k*(k+1)/2 * i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <utility>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	ll ans = LINF;
	for (ll i = -100; i <= 100; i++) {
		ll cnt = 0;
		for (int j = 0; j < n; j++) {
			cnt += (a[j] - i)*(a[j] - i);
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n; cin>>n;
  map<int,int> insu;
  vi a(n); rep(i,n) cin>>a[i];
  rep(i,n){
    int x=a[i];
    for(int j=2;j<=sqrt(x);j++){
      if(x%j==0) insu[j]++;
      while(x%j==0){
        x/=j;
      }
    }
    if(x>1) insu[x]++;
  }
  bool judge0=true,judge1=false;
  for(auto x:insu){
    if(x.second>1) judge0=false;
  }
  if(judge0){
    cout<<"pairwise coprime"<<endl;
    return 0;
  }
  for(auto x:insu){
    if(x.second==n) judge1=true;
  }
  if(judge1){
    cout<<"not coprime"<<endl;
    return 0;
  }
  cout<<"setwise coprime"<<endl;
}


Measured memory_bytes: 10932
#include<cstdio>
#include<vector>
int H,W,N,X[200010],Y[200010];
std::vector<int>ys[200010];
int main(){
	scanf("%d%d%d",&H,&W,&N);
	for(int i=0;i<N;i++)scanf("%d%d",X+i,Y+i),ys[X[i]].push_back(Y[i]);
	int d=1,l=1,r=1;
	while(d<H){
		bool fl=0;
		for(int i=0;i<ys[d+1].size();i++){
			if(ys[d+1][i]>=l&&ys[d+1][i]<=r){
				printf("%d\n",d);
				return 0;
			}
			if(ys[d+1][i]==r+1)fl=1;
		}
		if(!fl&&r<W)r++;
		d++;
	}
	printf("%d\n",d);
}

Measured memory_bytes: 12800