akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<double,double> P;
typedef pair<double,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct edge{int to;double cost;};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	P st,en;
	cin>>st.fi>>st.se>>en.fi>>en.se;
	int n;
	cin>>n;
	vector<double> x(n+2),y(n+2),r(n+2);
	x[0]=st.fi,y[0]=st.se,r[0]=0;
	x[n+1]=en.fi,y[n+1]=en.se,r[0]=0;
	FOR(i,1,n+1){
		cin>>x[i]>>y[i]>>r[i];
	}
	vector<vector<edge>> g(n+2);
	rep(i,n+2){
		rep(j,n+2){
			if(i==j) continue;
			double d=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
			double cost=0;
			if(d>=r[i]+r[j]) cost=d-r[i]-r[j];
			g[i].push_back({int(j),cost});
		}
	}
	vector<double> dist(n+2,inf);
	dist[0]=0;
	priority_queue<Pi,vector<Pi>,greater<Pi>> que;
	que.push(Pi(0,0));
	while(!que.empty()){
		auto hoge=que.top();
		que.pop();
		double d=hoge.fi;
		int v=hoge.se;
		if(dist[v]<d) continue;
		for(auto to:g[v]){
			if(chmin(dist[to.to],dist[v]+to.cost)){
				que.push(Pi(dist[to.to],to.to));
			}
		}
	}
	cout<<setprecision(15)<<dist[n+1]<<endl;
}

Measured memory_bytes: 22000
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

vector< vector<int> > ans;

void dfs(int n, int mini, vector<int> &v){
    if(n == 0){
        ans.emplace_back(v);
        return;
    }

    rreps(i, min(n, mini)){
        v.emplace_back(i);
        dfs(n - i, min(mini, i), v);
        v.pop_back();
    }

    return;
}

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

    int n;
    while(cin >> n, n){
        ans.clear();
        vector<int> v;
        dfs(n, n, v);

        rep(i, ans.size()){
            rep(j, ans[i].size()){
                if(j) cout << ' ';
                cout << ans[i][j];
            }
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3380
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    int x;
    cin >> x;
    if (x < 1200) {
        cout << "ABC";
    } else {
        cout << "ARC";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	n=n%10;
	if(n==1||n==6||n==8||n==0){
		cout<<"pon";
	}
	if(n==2||n==4||n==5||n==7||n==9){
		cout<<"hon";
	}
	if(n==3){
		cout<<"bon";
	}
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	double ans = 0;
	for(int i = 0; i < N; i++){
		double a;
		cin >> a;
		ans += 1 / a;
	}
	ans = 1 / ans;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	
	int S;
	int hour;
	int min;
	int seco;
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
		S =sc.nextInt();
		
		hour = S / 3600;
		min = (S - hour*3600) / 60;
		seco= (S - hour*3600) - (min*60);
		
		System.out.println(hour+":"+min+":"+seco);
		
	}
	
	public static void main(String[]args){
		Main obj = new Main();
		obj.solve();
	}
}

Measured memory_bytes: 17168
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;

int main(void){
	int H,W;cin>>H>>W;
	vector<vector<char>> VVI(H,vector<char>(W,0));
	rep(aa,H)rep(bb,W)cin>>VVI[aa][bb];

	int cnt = 0;
	for(int i = 0; i < H; i++){
		for(int t = 0; t < W; t++){
			cnt = 0;
			if(VVI[i][t] == '.'){
				cnt = 0;
				for(int x = -1; x <= 1; x++){
					for(int y = -1; y <= 1; y++){
						if(i + y >= 0 && t + x >= 0 && i + y < H && t + x < W){
							if(VVI[i + y][t + x] == '#')	cnt++;
						}
					}
				}
				VVI[i][t] = cnt + '0';
			}
		}
	}
	//出力
	rep(j , H){
		rep(q , W){
			cout<<VVI[j][q];
		}
		cout<<endl;
	}

}


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

for i, a in enumerate(A):
    j = i - 1
    while j >= 0 and a < A[j]:
        A[j + 1] = A[j]
        j -= 1
    else:
        A[j + 1] = a
        print(*A)
    
    


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

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = -1;
    repl(i, 1, 100 * a) {
        if(i * 8 / 100 == a && i * 10 / 100 == b) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[10];
	int soe;
	int i;
	int tmp;
	
	for (soe = 0; soe != 10; soe++){
		scanf("%d", &a[soe]);
	}
	
	for (i = 0; i != 10; i++){
		for (soe = 1; soe != 10; soe++){
			if (a[soe - 1] < a[soe]){
				tmp = a[soe - 1];
				a[soe - 1] = a[soe];
				a[soe] = tmp;
			}
		}
	}
	
	for (soe = 0; soe != 3; soe++){
		printf("%d\n", a[soe]);
	}
	
	return (0);
}
		

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

using namespace std;

int main(){
    int e;
    while(cin>>e,e){
        int ans=1e9;
        for(int i=0;i*i*i<=e;++i){
            int e1=e-i*i*i;
            for(int j=0;j*j<=e1;++j){
                int k=e1-j*j;
                ans=min(ans,i+j+k);
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3072
#include <iostream>
using namespace std;
int main (){
  int k,s,x,y,z;
  int ans = 0;
  cin >> k >> s;
  for(x = 0; x <= k; x++){
    for(y = x; y <= k; y++){
      for(z = y; z <= k; z++){
        if((x + y + z) == s){
          if(x == y && y == z && z == x){
            ans += 1;
          }else if(x == y || y == z || z == x){
            ans += 3;
          }else{
            ans += 6;
          }
        }
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
const int MAXN=200+11;
bool isprime[MAXN];
vector<int> cnt(MAXN);
void pre(){
	for(int i=2;i<MAXN;i++){
	  for(int j=i;j<MAXN;j+=i){
		    cnt[j]++;
		  }	
	}
}
void solve(){
  	pre();
  	int n,val=0;
  	cin>>n;
  	for(int i=0;i<=n;i++)val+=(cnt[i]==7 and (i&1));
  	cout<<val<<endl;
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}

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

using namespace std;
typedef long long LL;
const int N = 200005;

int a[N];

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    LL ans = 0, tot = 0;
    for (int i = 1, j = 1; i <= n; i++)
    {
        for (; (a[j] ^ tot) == (a[j] + tot) && (j <= n); j++)
            tot ^= a[j];
        ans += j - i;
        tot ^= a[i];
    }
    printf("%lld\n", ans);
    return 0;
}

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  int L[2000];

  cin >> N;
  REP(i, N) { cin >> L[i]; }

  sort(L, L + N);

  int result = 0;
  int boundary;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      boundary = lower_bound(L, L + N, L[i] + L[j]) - L;
      result += max(boundary - (j + 1), 0);
    }
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))
    val = 0
    for i in range(N):
        if V[i]-C[i] >= 0:
            val += V[i]-C[i]
    print(val)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <array>
#include <cstddef>
#include <iostream>
#include <vector>

int N, W;
const int NMAX = 105;
const int WMAX = 10005;

struct Item
{
    int value, weight;
};

Item items[NMAX];
// Max value for total weight i when item 1,...,i used.
int dp[NMAX][WMAX];

int main()
{
    std::cin >> N >> W;

    for (size_t i = 1; i <= N; ++i)
    {
        std::cin >> items[i].value >> items[i].weight;
    }

    for (size_t w = 0; w <= W; ++w)
    {
        dp[0][w] = 0;
    }

    for (size_t i = 1; i <= N; ++i)
    {
        for (size_t w = 0; w <= W; ++w)
        {
            if (items[i].weight <= w)
            {
                auto new_value = dp[i - 1][w - items[i].weight] + items[i].value;
                if (new_value > dp[i - 1][w])
                {
                    dp[i][w] = new_value;
                }
                else
                {
                    dp[i][w] = dp[i - 1][w];
                }
            }
            else{
              dp[i][w] = dp[i-1][w];
            }
        }
    }

    std::cout << dp[N][W] << std::endl;
}



Measured memory_bytes: 7016
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int num, i, ans = 0, b;
	cin >> num;
	vector<int> a(num), c(num - 1);
	for (i = 0; i < num; i++) {
		cin >> a[i];
		a[i]--;
	}
	for (i = 0; i < num; i++) {
		cin >> b;
		ans += b;
	}
	for (i = 0; i < num - 1; i++)
		cin >> c[i];
	for (i = 0; i < num - 1; i++) {
		if (a[i] + 1 == a[i + 1])
			ans += c[a[i]];
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <bits/stdc++.h>
#include<string>
#include<string.h>
#define ll long long
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pshb(a) cin >> x;a.push_back(x)
#define fr(i,n) for(ll i=0;i<n;i++)
#define alph "abcdefghijklmnopqrstuvwxyz"
#define alph1 "abcdefghijklmnopqrstuvwxyz"
#include <vector>#include <bits/stdc++.h>
#include<string>
#include<string.h>
#define ll long long
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pb(x) cin>>x; a.push_back(x)
#define srt() sort(a.begin(),a.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define alph "abcdefghijklmnopqrstuvwxyz"
#define alph1 "abcdefghijklmnopqrstuvwxyz"
#include <vector>
#include<math.h>
#define WUBBAxxLUBAxxDUBxxDUB int main
#define salamo3lekooooom ios::sync_with_stdio(false)
using namespace std;
bool sortbysec(const pair<int,int> &a,
               const pair<int,int> &b)
{
    return (a.second < b.second);
}
#define LIMIT 1000000
long long i, j;
long long prime_flag[LIMIT];
void calculate_prime_flag()
{
    prime_flag[0] = prime_flag[1] = 1;
    for(i=2; i<LIMIT; i++)
    {
        if (prime_flag[i]==0)
        {
            for(j=i*i; j<LIMIT; j+=i)
            {
                prime_flag[j] = 1;
            }
        }
    }
}

#include <iostream>
#include <math.h>
using namespace std;
// Get SHWIFTY
vector<string>v;
int LPS(char *str)
{
    int n=strlen(str);
    int i,j,cl;
    int l[n][n];
    for(i=0; i<n; i++)
        l[i][i]=1;
    for(cl=2; cl<=n; cl++)
    {
        for(i=0; i<n-cl+1; i++)
        {
            j=i+cl-1;
            if(str[i]==str[j]&&cl==2)
                l[i][j]=2;
            else if (str[i]==str[j])
                l[i][j]=l[i+1][j-1]+2;
            else
                l[i][j]=max(l[i][j-1],l[i+1][j]);


        }
    }
    return l[0][n-1];


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

// Function to find gcd of array of
// numbers
int findGCD(int arr[], int n)
{
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
/////3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa


vector <int> adj[10];
    bool visited[10];

    void dfs(int s) {
        visited[s] = true;
        for(int i = 0;i < adj[s].size();++i)    {
         if(visited[adj[s][i]] == false)
             dfs(adj[s][i]);
        }
    }

    void initialize() {
        for(int i = 0;i < 10;++i)
         visited[i] = false;
    }

WUBBAxxLUBAxxDUBxxDUB()
{
    salamo3lekooooom;
    ll a,b;
    cin>>a>>b;
    if(a-2*b>0)
        cout<<a-2*b<<endl;
    else
        cout<<0<<endl;

}


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

int A, B, C, D;

int main() {
    cin >> A >> B >> C >> D;

    int ans = min(B, D) - max(A, C);
    if (ans < 0) cout << 0 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    D, T, S = LI()
    if T*S >= D:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 10016
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    string foo;
    for (int i = 0; s[i]; ++ i) {
        if (s[i] == 'B') {
            if (!foo.empty()) foo.pop_back();
        }
        else {
            foo.push_back(s[i]);
        }
    }
    cout << foo;
    
}

Measured memory_bytes: 256
function main(input) {
  const tmp = input.trim().split(' ').map((n) => parseInt(n, 10))
  const n = tmp[0]
  const l = tmp[1]


  if (l >= 0) {
    console.log((2 * l + n) * (n - 1) / 2)
  } else if (l + n - 1 <= 0) {
    console.log((2 * l + n - 2) * (n - 1) / 2)
  } else {
    console.log((2 * l + n - 1) * n / 2)
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 29624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int[] top3 = new int[3];
		while ((line = r.readLine()) != null) {
			int val = Integer.parseInt(line);
			if (top3[0] <= val) {
				top3[2] = top3[1];
				top3[1] = top3[0];
				top3[0] = val;
			} else if (top3[1] <= val) {
				top3[2] = top3[1];
				top3[1] = val;
			} else if (top3[2] <= val) {
				top3[2] = val;
			}
		}

		for (int t : top3) {
			System.out.println(t);
		}

	}
}

Measured memory_bytes: 17004
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(){
     int t,i,j,m,k=0,s[16]={0},n[20],a[20][20],b[20][20];
     scanf("%d",&t);
     for(i=0;i<t;i++){
        scanf("%d",&n[i]);
        for(j=0;j<n[i];j++)
            scanf("%d%d",&a[i][j],&b[i][j]);
     }
     m=0;
     while(s[t]!=1){
        s[0]++;
        for(i=0;i<t;i++){
            if(s[i]==2){
                s[i]=0;
                s[i+1]++;
            }
            else break;
        }
        k=0;
        for(i=0;i<t;i++){
            if(s[i]==1) k++;
        }
        for(i=0;i<t;i++){
            if(s[i]==1){
                for(j=0;j<n[i];j++){
                    if(b[i][j]!=s[a[i][j]-1]){
                        k=0;
                        break;
                    }
                }
                if(k==0) break;
            }
        }
        if(k>m) m=k;
     }
     printf("%d",m);
     return 0;
}


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

int main()
{
    int n, r;
    cin >> n >> r;
    int ans;
    if (n >= 10)
    {
        ans = r;
        cout << ans << endl;
        return 0;
    }
    else
    {
        ans = r + 100 * (10 - n);
        cout << ans << endl;
    }
}

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

cnt = 0
for a in A:
  H -= a
  cnt += 1
  if H > 0 and cnt == N:
    print("No")
    break
  elif H <= 0:
    print("Yes")
    break

Measured memory_bytes: 13964
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;


int main(){

    int N; cin >> N;
    vector<int> a(N);
    int max_abs = -1;
    int max_abs_index = -1;
    bool isMinus = false;
    rep(i,N) {
        cin >> a[i];
        if (max_abs < abs(a[i])){
            max_abs = abs(a[i]);
            max_abs_index = i;
            if (a[i] < 0) {
                isMinus = true;
            }
            else{
                isMinus = false;
            }
        }
    }
    

    cout << (N-1)*2 << endl;

    rep(i,N){
        if (i == max_abs_index) continue;
        cout << max_abs_index+1 << " " << i+1 << endl; 
    }

    if (!isMinus){
        for(int i = 0; i < N-1; i++){
            cout << i+1 << " " << i+2 << endl;
        }
    }
    else{
        for(int i = N-1; i > 0; i--){
            cout << i+1 << " " << i << endl;
        }
    }



}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
ll k,n,a[maxn],r[maxn],b[maxn];
ll be,len,p=1,cnt;
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i];
while(1)
{
	if(b[a[p]]!=0)
	{
		be=b[a[p]];
		len=cnt-be+1;
		break;
	}
	r[++cnt]=a[p];
	b[a[p]]=cnt;
	p=a[p];
}
if(k<=be)
cout<<r[k];
else
{
	int s=(k-be)%len;
	cout<<r[be+s];
}
return 0;

}

Measured memory_bytes: 8208
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

long long calc(long long n,long long m,long long a,long long b){
    long long ans = 0;
    long long r = (-a*n+b)/m;
    ans += r * n;
    b -= r * m;
    long long d = a / m;
    ans += n*(n-1)/2 * d;
    a -= d*m;
    b -= d*m*n;
    if(a==0) return ans;
    else return ans + calc(b/m,a,m,b);
}

long long floor_sum(long long n,long long m,long long a,long long b){
    return calc(n,m,a,a*n+b);
}

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,m,a,b;
        scanf("%d%d%d%d",&n,&m,&a,&b);
        printf("%lld\n",floor_sum(n,m,a,b));
    }
}

Measured memory_bytes: 3788
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P) :
 P = sorted(P)
 phU = []
 phU.append(P[0])
 phU.append(P[1])
 for p in P[2:] :
  phU.append(p)
  if isCLKWISE(phU) : continue
  while(True):
   del phU[-2]
   try:
    if isCLKWISE(phU) : break
   except IndexError : break
 phL = []
 phL.append(P[-1])
 phL.append(P[-2])
 for p in P[-3::-1] :
  phL.append(p)
  if isCLKWISE(phL) : continue
  while(True) :
   del phL[-2]
   try:
    if isCLKWISE(phL) : break
   except IndexError : break
 ph = phU + phL[1:-1]
 return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
P = P[idx:] + P[:idx]
for p in P : print(p[0],p[1])

Measured memory_bytes: 33108
import math

def plot(x,y):
    print(f'{x:8f} {y:8f}')

def koch(n,x1,y1,x2,y2):
    if n==0:
        plot(x1,y1)
        return
    sx=(2*x1+x2)/3
    sy=(2*y1+y2)/3
    tx=(x1+2*x2)/3
    ty=(y1+2*y2)/3
    ux=(tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy=(tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    koch(n-1,x1,y1,sx,sy)
    koch(n-1,sx,sy,ux,uy)
    koch(n-1,ux,uy,tx,ty)
    koch(n-1,tx,ty,x2,y2)
 
n=int(input())   
koch(n,0,0 ,100,0)
plot(100,0)


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;


int main() {

    int d;
    cin >> d;

    if (d == 25) {
        cout << "Christmas" << endl;
    } else if (d == 24) {
        cout << "Christmas Eve" << endl;
    } else if (d == 23) {
        cout << "Christmas Eve Eve" << endl;
    } else if (d == 22) {
        cout << "Christmas Eve Eve Eve" << endl;
    }

}

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

int main() {
    int n;
    cin >> n;
    bool flag = true;
    set<int> s;
    int now = 1;
    while (flag) {
        if(s.count(n)) {
            cout << now << endl;
            flag = false;
        } else {
            s.insert(n);
            now++;
            if(n%2 == 0) n /= 2;
            else n = 3*n+1;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
template<typename T>
inline void read(T &x)
{
    x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return;
}
template<typename T>
inline void write(T x)
{
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}
const int MAXN=1000010,MAXM=1000010,LOGN=20;
int n,m;
int a[MAXN];
int pre[MAXN];
int tmp[MAXN];
int tot=0;
struct node{
    int l,r;
    int val;
}f[MAXN*4+MAXN*LOGN*4];
int rt[MAXN];
inline void pushup(register int p)
{
    f[p].val=f[f[p].l].val+f[f[p].r].val;
}
int build(int l,int r)
{
    int p=++tot;
    if(l==r) return p;
    int mid=(l+r)>>1;
    f[p].l=build(l,mid),f[p].r=build(mid+1,r);
    return p;
}
int insert(int now,int l,int r,int x)
{
    int p=++tot;
    f[p]=f[now];
    if(l==r)
    {
        f[p].val++;
        return p;
    }
    int mid=(l+r)>>1;
    if(x<=mid) f[p].l=insert(f[now].l,l,mid,x);
    else f[p].r=insert(f[now].r,mid+1,r,x);
    pushup(p);
    return p;
}
int query(int p,int q,int l,int r,int lp,int rp)
{
    if(l>=lp&&r<=rp) return f[q].val-f[p].val;
    int ret=0;
    int mid=(l+r)>>1;
    if(lp<=mid) ret+=query(f[p].l,f[q].l,l,mid,lp,rp);
    if(rp>mid) ret+=query(f[p].r,f[q].r,mid+1,r,lp,rp);
    return ret;
}
int main()
{
    read(n),read(m);
    for(int i=1;i<=n;i++) read(a[i]);
    for(int i=1;i<=n;i++) pre[i]=tmp[a[i]],tmp[a[i]]=i;
    rt[0]=build(1,n+1);
    for(int i=1;i<=n;i++) rt[i]=insert(rt[i-1],1,n+1,pre[i]+1);
    for(int i=1;i<=m;i++)
    {
        int l,r;
        read(l),read(r);
        write(query(rt[l-1],rt[r],1,n+1,1,l)),putchar('\n');
    }
}


Measured memory_bytes: 140796
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

a = arr_data[0][0]
b = arr_data[0][1]
c = arr_data[0][2]


print("YES" if a[-1]==b[0] and b[-1]==c[0] else "NO")
    
    


Measured memory_bytes: 3064
// 解説の通りに実装
// 黒マスを頂点、黒マス同士が隣り合う辺をエッジとすると、森となる
// それぞれの部分矩形にて、頂点の数からエッジの数を引いたものが、求める連結成分の数となる
// 頂点の数、エッジの数は、事前に２次元累積和で計算しておく

#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

vector<int> table;

int integral(vector<vector<int>>& Vs, int h1, int w1, int h2, int w2) {
	//cout << "debug:" << endl;
	//cout <<   Vs[h2][w2] << endl;
	//cout <<   Vs[h1 - 1][w2] << endl;
	//cout <<   Vs[h2][w1 - 1] << endl;
	//cout <<   Vs[h1 - 1][w1 - 1] << endl;
	return Vs[h2][w2] - Vs[h1 - 1][w2] - Vs[h2][w1 - 1] + Vs[h1 - 1][w1 - 1];
}
void debug_print(vector<vector<int>>& a) {
	int H = SIZE(a);
	int W = SIZE(a[0]);
	REP(h, H) {
		REP(w, W) cout << a[h][w] << " ";
		cout << endl;
	}
	cout << endl;
}

int main(void)
{
	cin.sync_with_stdio(false);
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<string> cells(N);
	REP(n, N) cin >> cells[n];

	// 黒マスの数、上下に連結する黒マスの数、左右に連結する黒マスの数を2次元累積和で

	// 黒マスの数を2次元累積和で求めておく
	vector<vector<int>> Vs(N + 1, vector<int>(M + 1));
	vector<vector<int>> ver(N + 1, vector<int>(M + 1));
	vector<vector<int>> hor(N + 1, vector<int>(M + 1));
	REP(n, N) {
		REP(m, M) {
			Vs[n + 1][m + 1] = (cells[n][m] == '1');
			if (m > 0) {
				hor[n + 1][m] = (cells[n][m] == '1' && cells[n][m - 1] == '1');
			}
			if (n > 0) {
				ver[n][m + 1] = (cells[n][m] == '1' && cells[n - 1][m] == '1');
			}
		}
	}

	REP(n, N) {
		REP(m, M) {
			Vs[n + 1][m + 1] += Vs[n + 1][m];
			hor[n + 1][m + 1] += hor[n + 1][m];
			ver[n + 1][m + 1] += ver[n + 1][m];
		}
	}
	REP(m, M) {
		REP(n, N) {
			Vs[n + 1][m + 1] += Vs[n][m + 1];
			hor[n + 1][m + 1] += hor[n][m + 1];
			ver[n + 1][m + 1] += ver[n][m + 1];
		}
	}

	//cout << "Vs" << endl;
	//debug_print(Vs);
	//cout << "hors" << endl;
	//debug_print(hor);
	//cout << "vers" << endl;
	//debug_print(ver);

	REP(q, Q) {
		int h1, w1, h2, w2;
		cin >> h1 >> w1 >> h2 >> w2;

		auto v_num = integral(Vs, h1, w1, h2, w2);
		auto edge1_num = integral(hor, h1, w1, h2, w2 - 1);
		auto edge2_num = integral(ver, h1, w1, h2 - 1, w2);
		cout << (v_num - edge1_num - edge2_num) << endl;
	}

	return 0;
}


Measured memory_bytes: 53760
#include <cstdio>
#include <vector>
using namespace std;

int a, b;
vector<int> c, d;
int ans;

int f(int x){
	int y = 0;
	for(int i=0; i<a; i++){
		if(d[x] == c[i]){
			x++;
			y++;
		}
	}
	return y;
}

int main(){
	scanf("%d %d", &a, &b);
	for(int i=0; i<a; i++){
		int t;
		scanf("%d", &t);
		c.push_back(t);
	}
	for(int i=0; i<b; i++){
		int t;
		scanf("%d", &t);
		d.push_back(t);
	}
	
	for(int i=0; i<b; i++){
		ans = max(ans, f(i));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2864
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int mod=1e9+7,N=1e7+5;
int fac[N],inv[N],ins[N];
int ksm(int b,int n){
	int res=1;
	while(n){
		if(n&1) res=res*b%mod;
		b=b*b%mod; n>>=1;
	}
	return res;
} 
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i)
		fac[i]=fac[i-1]*i%mod;
	inv[n]=ksm(fac[n],mod-2);
	for(int i=n-1;i>=0;--i)
		inv[i]=inv[i+1]*(i+1)%mod;
	ins[1]=1;
	for(int i=2;i<=n;++i)
		ins[i]=(mod-(mod/i))*ins[mod%i]%mod;
}
int C(int n,int m){
	if(n<m) return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main(){
	int n,A,sum=0,res;
	cin>>n>>A;
	init(n);
	for(int t=2;t<=A+1;++t){
		int x=t-1,y=max(A-t,0ll),z=n-A;
		for(int i=0;i<=x;++i){
			res=C(x,i)*(x-i)%mod*ins[x+z-i]%mod*fac[x+y+z-i]%mod;
			if(i&1) sum+=(mod-res)%mod;
			else sum+=res;
			sum%=mod;
		}
	}
	cout<<sum;
	return 0; 
}

Measured memory_bytes: 237984
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define ll long long
typedef vector<vector<ll> > matrix;
#define pb push_back
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;

int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

ll f[2000001];



ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}

bool prime[100005];
void seive()
{  memset(prime,true,sizeof(prime));
    for(int i=2;i*i<=100005;i++)
    {
         if(prime[i]==true) {
        for(int j=2*i;j<=(100005);j+=i)
           { prime[j]=false;}
           }

    }
}
bool in(float x1,float y1,float x,float y,float r )
{
    if(abs(x1-x)*abs(x1-x)+abs(y1-y)*abs(y1-y)<=r*r) return true;
    return false;
}
bool cmp(pair<int,int> &a,pair<int,int> &b)
{

        return (a.second<b.second);
}
//
//vector<vector<int> >matrix;
matrix mul(matrix A,matrix B)
{
    matrix C(3, vector<ll>(3));
    for(int i=1;i<=2;i++)
    for(int j=1;j<=2;j++)
     for(int k=1;k<=2;k++)
         C[i][j] = (C[i][j] + A[i][k] * B[k][j]);
    return C;

}
matrix pow(matrix A, int p)
{
    if (p == 1)
        return A;
    if (p % 2)
        return mul(A, pow(A, p-1));
    matrix X = pow(A, p/2);
    return mul(X, X);
}
ll fib(int N,int a,int b)
{
    vector<ll> F1(3);
    F1[1] = a;
    F1[2] = b;
    matrix T(3, vector<ll>(3));
    T[1][1] = 0, T[1][2] = 1;
    T[2][1] = -1, T[2][2] = 1;
    if (N == 1)
        return a;
    if(N==2) return b;
    T = pow(T, N-1);
    ll res = 0;
    for(int i=1;i<=2;i++)
        res = (res + T[1][i] * F1[i]+ MOD)%MOD ;
    return res;
}

//1 2 3 4 5
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 int t =1;
 while(t--)
  {
      int n;
      cin>>n;
      int arr[n];
      ll c2=0,c1=0,c0=0;
      for(int i=0;i<n;i++) { cin>>arr[i]; if(arr[i]%4==0) c0++; else if(arr[i]%4==2) c2++; else c1++;}
      if(c2&1) c2=1; else c2=0;
      c1+=c2;
      if(c0>=c1-1) cout<<"Yes";
      else cout<<"No";
     // 3 0 3 0 3

  }
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int a, b;
	int n;
	int i;
	char str[100];
	
	while (fgets(str, 100, stdin) > 0){
		sscanf(str, "%d%d", &a, &b);
		n = 1;
		i = 0;
		while ((a + b) / n != 0) n *= 10, i++;
		printf("%d\n", i);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
// #include "atcoder/all"
// #define popcount __builtin_popcount
using namespace std;
// using namespace atcoder;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))




//3111111111111111111111111111111

	void solve(){
		

		ini(x);
		ini(x1);
		ini(y);
		ini(y1);
		int tmp = 0;
		int tmp1 = 0;
		tmp = max(x*y,x*y1);
		tmp1 = max(x1*y,x1*y1);
		out(max(tmp,tmp1));
		
		
			
			
			


				
		


		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 3652
// AOJ 2431
#include<cstdio>
#include<algorithm>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef long long ll;

int n;
ll bit[100001];

void add( int k, ll x )
{
	for( int i = k+1; i <= n; i += i&-i )
		bit[i] = std::max( bit[i], x );

	return;
}

ll sum( int k )
{
	ll ret = 0;

	for( int i = k; i > 0; i -= i&-i )
		ret = std::max( ret, bit[i] );

	return ret;
}

int main()
{
	scanf( "%d", &n );
	rep( i, n )
	{
		int x;
		scanf( "%d", &x );
		add( x-1, sum( x-1 )+x );
	}

	printf( "%lld\n", (ll(n)*(n+1)>>1)-sum(n) );

	return 0;
}

Measured memory_bytes: 1808
#include<bits/stdc++.h>
// iteration and input/output stream
#define rep(i,a,b) for(int i = int(a);i<=int(b);i++)
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define printarr(x) rep(i,0,x.size()-1) cout<<x[i]<<" "; cout<<endl;
#define all(v) v.begin(),v.end()
 
#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl printf("\n")
#define tr(cont,it) \
for(decltype(cont.begin()) it = cont.begin(); it!= cont.end() ; it++)
 
#define endl "\n"
#define tc() int t; cin >> t ; while (t--)
//STL shortcuts
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define MP make_pair
 
// Error detection
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
using namespace std;
 
typedef long long int ll; // 64 bit integer
typedef unsigned long long int  ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
 
inline void smax(int &x , int y) { x = max(x , y) ; }
inline void smin(int &x , int y) { x = min(x , y) ; }
 
#define MOD 1000000007
#define inf 4000000000000000000LL
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("err.txt","w",stderr);
    #endif
    SYNC
    int n;
    cin>>n;
    vector<pii> v1;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin>>x;
        v1.pb({x,i});
    }
    // cout<<v1.size();
    sort(all(v1));

    // trace2(v1.size(),v1[0]);
    // trace2(v1[0].F,v1[0].S);
    // printarr(v1);
    unordered_map<int,int> m1;
    for (int i = 0; i < n; i++)
    {
        auto cur = v1[i];
        int y = -1*cur.F + cur.S;
        m1[y]++;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        auto cur = v1[i];
        int x = cur.F + cur.S;
        if(m1.count(x))
        {
            trace1("in");
            ans+=(m1[x]);
        }
    }
    cout<<ans;

    return 0;
}

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

int main(){
    int A, B, C, X;
    int count = 0;
    cin >> A >> B >> C >> X;
    for (int i=0; i <= A; i++){
        for (int j=0; j <= B; j++){
            for (int k=0; k <= C; k++){
                if (500*i + 100*j + 50*k == X) count++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: August 14
 * 
 */

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define ef else if
#define wh while
#define el else
#define ivv(x) int x; cin>>x
#define lv(x) bint x; cin>>x
#define sv(x) string x; cin>>x
#define cv(x) char x; cin>>x
#define fv(x) float x; cin>>x
#define dv(x) double x; cin>>x
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {
    // your solution goes here 
    ivv(n);
    vi v(n);
    iv(v);
    vi temp = v;
    sort(all(temp));
    bint counter(0);
    rep(n){
        counter+=(temp.at(i)!=v.at(i));
    }
    puts((counter<=2)?"YES":"NO");
    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
vector <ll> a;
vector<ll> f;
ll n,k;
ll check(ll maxallowed)
{
   ll need = 0;
   for(ll i = 0; i<n ; i++)
   {
      if(a[i]*f[i]<=maxallowed)
         continue;
      else
      {
         need += a[i]-(maxallowed)/f[i];
      }
   }
   if(need <=k)
      return 1;
   else
      return 0;
 
}
 
int  main()
{
   // ios_base::sync_with_stdio(false); 
   // cin.tie(NULL);
   cin>>n>>k;
   ll x;
   for(ll i=0; i<n ; i++)
         {
            cin>>x;
            a.pb(x);
         }
      //cout<<"hey";
   for(ll i =0; i<n ; i++)
         {
            cin>>x;
            f.pb(x);
         }
      //cout<<"hu";
   sort(a.begin(),a.end(),greater<ll>());
   sort(f.begin(),f.end());   
   ll r = 1e12, l  = 0;
   for(ll i = 0; i<n ; i++)
      if(a[i]*f[i]>r)
            r = a[i]*f[i];
   
      while(l<r)
      {
         ll mid = (l+r)/2;
         if(check(mid))
            r = mid;
         else
            l = mid+1;
      }
 
   cout<<r<<endl;    
 
 
   return 0;
}

Measured memory_bytes: 4976
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
res = -10**10
for i in range(1, 1<<10):
    count = [0 for _ in range(n)]
    for j in range(10):
        for k in range(n):
            if (i>>j)&1 == 1 and f[k][10-j-1] == 1:
                count[k] += 1
    total = 0
    for k in range(n):
        total += p[k][count[k]]
    res = max(res, total)
print(res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;

int N, Q;
string S;
vector<set<int>*> st(26);
int main(int argc, char const *argv[])
{
  cin >> N >> S >> Q;
  REP(i, 26) st[i] = new set<int>();
  REP(i, N) st[S[i] - 'a']->insert(i);
  REP(i, Q) {
    int ty; cin >> ty;
    if (ty == 1) {
      int j; cin >> j; j--;
      char c; cin >> c;

      st[S[j] - 'a']->erase(j);
      st[c - 'a']->insert(j);
      S[j] = c;
    } else {
      int l, r; cin >> l >> r; l--;
      int cnt = 0;
      for (auto s : st) {
        auto lower = s->lower_bound(l);
        cnt += lower != s->end() && *lower < r;
      }
      cout << cnt << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 26244
#include <iostream>
#include <sstream>
#include <utility>
#include <algorithm>
#define FL(i,j,k) for(int i=j;i<k;++i)
using namespace std;
typedef long long int ll;
//typedef pair<int, int> ii;
ll A[200000];ll n,k,frontcount=0;

int main(){
    ll I,O,T,J,L,S,Z;cin>>I>>O>>T>>J>>L>>S>>Z;
    ll A=(I/2)*2+O+(J/2)*2+(L/2)*2;
    ll m=min(I, min(J,L));
    ll B=3*m+((I-m)/2)*2+O+((J-m)/2)*2+((L-m)/2)*2;
    ll C=m>1?3*(m-1)+((I-m+1)/2)*2+O+((J-m+1)/2)*2+((L-m+1)/2)*2:0;
    cout<<max(A, max(B, C));
}

Measured memory_bytes: 256
N, M = map(int, input().split())
L = 100000
dp = [[1000000001 for _ in range(L+1)] for _ in range(N+1)]
W, V = [], []
for _ in range(N):
    w, v = map(int, input().split())
    W.append(w)
    V.append(v)
dp[0][0] = 0
for i in range(N):
    for j in range(L+1):
        if j - V[i] >= 0:
            dp[i+1][j] = min(dp[i][j], dp[i][j-V[i]] + W[i])
        else:
            dp[i+1][j] = dp[i][j]
for i, d in enumerate(dp[N]):
    if d <= M:
        maxv = i
print(maxv)


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

int main(){
    int n, m;
    cin >> n >> m;

    vector<string> a(n), b(m);
    for (auto i = 0; i < n; i++) cin >> a[i];
    for (auto i = 0; i < m; i++) cin >> b[i];

    for (auto i = 0; i <= (n - m); i++) {
        for (auto j = 0; j <= (n - m); j++) {
            bool flg = true;
            for (auto k = 0; k < m; k++) {
                if(a[i + k].substr(j, m) != b[k]) {
                    flg = false; break;
                }
            }
            if(flg) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char b[1];
  scanf("%s",b);
  if(b[0]=='A')printf("T");
  if(b[0]=='T')printf("A");
  if(b[0]=='G')printf("C");
  if(b[0]=='C')printf("G");
  return 0;
}

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

int main()
{
    int n; cin>>n;
    map<int, int> a;
    for(int t; cin>>t; a[t]^=1);
    int res=0;
    for(auto& e: a) res+=e.second;
    cout<<res<<endl;
}

Measured memory_bytes: 4992