akhauriyash/Code-Regression huggingface dataset:
/*author : Yashvardhan
Sunday, April 19, 2020
5:29 PM
*/

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

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	double r;
	cin >> r;

	cout << setprecision(10) << fixed;

	cout << 2 * 3.1415926535 * r << endl;

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 3808
import java.util.*;
 
import java.io.*;
 
public class Main{
    
	public static void main(String[] $){
		Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int M = s.nextInt();
        int[] p = new int[M];
        String[] S = new String[M];
        for(int i = 0; i < M; i++){
            p[i] = s.nextInt();
            S[i] = s.next();
        }

        int correct = 0;
        int wrong = 0;
        boolean[] AC = new boolean[N];
        int[] WA = new int[N];
        for(int i = 0; i < M; i++){
            if(AC[p[i]-1] == false){
                if(S[i].equals("AC")){
                    AC[p[i]-1] = true;
                    correct++;
                }else{
                    WA[p[i]-1]++;
                }
            }else{
                continue;
            }
        }

        for(int i = 0; i < N; i++){
            if(AC[i] == false){

            }else{
                wrong += WA[i];
            }
        }
        
        System.out.println(correct + " " + wrong);
 
	}
} 

Measured memory_bytes: 71380
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7
INF = int(1e09)

nCr = {}

sys.setrecursionlimit(100000)


def comb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = comb(n-1, r) + comb(n-1, r-1)
    return nCr[(n, r)]


def main():
    # sys.stdin = open("sample.txt")
    N, A, B = Scanner.map_int()
    V = Scanner.map_int()
    V.sort(reverse=True)
    ans = 0
    for i in range(A):
        ans += V[i]
    ans /= A
    print(ans)

    vmin = V[A-1]
    if V[0] != V[A-1]:
        cnt = V.count(vmin)
        c = V[:A].count(vmin)
        print(comb(cnt, c))
        return

    c = V.count(vmin)
    cnt = 0
    for i in range(A, B+1):
        if V[i-1] != vmin:
            break
        cnt += comb(c, i)
    print(cnt)


if __name__ == "__main__":
    main()


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

int main()
{
    int n,m,tmp,cnt=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>tmp;
        if(tmp >= m)
            cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,q,s[100002],t;
int ans=0;
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>t;
    int left=0,right=n,mid;
    while(left<right){
      mid=(left+right)/2;
      if(s[mid]==t){
	ans++;
	break;
      }
      if(t<s[mid])right=mid;
      else left=mid+1;
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main() {
int K;
cin >> K;
int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2,
1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << a[K-1] << endl;

}

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

int main() {
  int n, q;
  cin >> n >> q;
  string sss;
  cin >> sss;
  int sum = 0;
  vector<int> vec(n);
  for(int i = 1; i < sss.size(); i++) {
    if(sss.at(i - 1) == 'A' && sss.at(i) == 'C') {
      sum++;
    }
    vec.at(i) = sum;
  }
  int e, f;
  for(int i = 0; i < q; i++) {
    cin >> e >> f;
    cout << vec.at(f - 1) -vec.at(e - 1) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1408
/*input
3 1
10 20 10
*/
#include <bits/stdc++.h>
using namespace std;

int n, k; 
long long h[100005], dp[100005];

long long solve(int ind){
	if(ind >= n) return 0LL;
	if(dp[ind] != -1){
		return dp[ind];
	}
	long long ans = 1000000000000000000;
	int lim = (ind + k <= n) ?k :n - ind;
	for(int i = 1; i <= lim; i++){
		ans = min(ans, solve(ind + i) + abs(h[ind + i] - h[ind]));
	}
	return dp[ind] = ans;
}

int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%lld", h + i);
	}
	memset(dp, -1, sizeof(dp));
	printf("%lld\n", solve(1));
	
	return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>
#include <stdlib.h>
#define N 255 //ヒープの個数
 
int Parent(int i){ //親のアドレス番号ッスね
  return i/2;
}
 
int Left(int i){ //左側の子のアドレス番号ッス
  return 2*i;
}
 
int Right(int i){ //右側の子のアドレス番号ッス
  return 2*i+1;
}
 
int check(int n,int i){//プリントするパターンをここで分岐させるッス
  if(n>=Right(i)) return 1;//左側と右側の子供がいる
  else if(n>=Left(i) && n<Right(i)) return 2;//左の子供は居るけど、右側の子供がいない
  else if(n<Left(i)) return 3;//左側すらないのか…（困惑）
}
 
main(){
  int n,i;
  int A[N];
 
  scanf("%d",&n);//スキャンする個数ッス
 
  for(i=1;i<=n;i++){//for文回して頭も回すで！
	 scanf("%d",&A[i]);
 }

  for(i=1;i<=n;i++){//for文回してプリントするやでー
    if(i==1){//最初は親無いから場合分けするやでー
      if(check(n,i)==1) printf("node %d: key = %d, left key = %d, right key = %d, \n",i,A[i],A[Left(i)],A[Right(i)]);
      else if(check(n,i)==2) printf("node %d: key = %d, left key = %d, \n",i,A[i],A[Left(i)]);
      else if(check(n,i)==3) printf("node %d: key = %d, \n",i,A[i]);
    }
    else{//一番最初以外はこの３つのパターンでプリントするやでー
      if(check(n,i)==1) printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n",i,A[i],A[Parent(i)],A[Left(i)],A[Right(i)]);
      else if(check(n,i)==2) printf("node %d: key = %d, parent key = %d, left key = %d, \n",i,A[i],A[Parent(i)],A[Left(i)]);
      else if(check(n,i)==3)printf("node %d: key = %d, parent key = %d, \n",i,A[i],A[Parent(i)]);
    }
  }
 
  return 0;
}

Measured memory_bytes: 596
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int main()
{
	int x;
	std::cin >> x;
	std::cout << ((x < 1200) ? "ABC" : "ARC") << std::endl;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real()*a.real() + a.imag()*a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
pair<int,int> calc(string a, int b) {
	int ans = 0;
	while (b < a.length() && a[b] >= '0'&&a[b] <= '9') {
		ans *= 10;
		ans += a[b] - '0';
		b++;
	}
	return make_pair(ans, b);
}
int compare(string a, string b) {
	int itr = 0;
	for (int i = 0; i < min(a.length(),b.length()); ++i) {
		if ((a[i] >= 'a'&&a[i] <= 'z') || (a[i] >= 'A'&&a[i] <= 'Z')) {
			if ((b[i] >= 'a'&&b[i] <= 'z') || (b[i] >= 'A'&&b[i] <= 'Z')) {
				if (a[i] > b[i]) {
					return 1;
				}
				else if (a[i] < b[i]) {
					return 0;
				}
			}
			else {
				return 1;
			}
		}
		else{
			if ((b[i] >= 'a'&&b[i] <= 'z') || (b[i] >= 'A'&&b[i] <= 'Z')) {
				return 0;
			}
			else {
				pair<int, int> as = calc(a, i),bs = calc(b,i);
				if (as.first < bs.first) return 0;
				else if (as.first > bs.first) return 1;
				i = as.second-1;
			}
		}
	}
	if (a.length() <= b.length()) return 0;
	return 1;
}
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	for (int i = 0; i < n; ++i) {
		string b;
		cin >> b;
		if (compare(s, b) == 0) {
			cout << "+" << endl;
		}
		else {
			cout << "-" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int n; cin >> n;
    vi A(n);
    rep(i, 0, n) cin >> A[i];
    sort(all(A));
    int alice = 0, bob = 0;
    rep(i, 0, n) {
        if (i % 2 == 0) {
            alice += *max_element(all(A));
            A.pop_back();
        }
        else {
            bob += *max_element(all(A));
            A.pop_back();
        }
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
void solve() {
    int N,K;
    R(N,K);
    VI a(N);
    REP(i,N)R(a[i]);
    REPP(i,K,N){
        W(a[i]>a[i-K]?"Yes":"No");
    }
}
int main(){
#define MULTITEST 0
#if MULTITEST    
    CASET{
        solve();
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 4068
# 答案
N,Q = map(int,input().split())
S = input()
l,r = 0,0
csum = [0]*(N+1)

# 累積和
for ctr in range(N):
    if ctr == (N-1):
        csum[ctr+1] = csum[ctr]
    elif S[ctr]=='A' and S[ctr+1]=='C':
        csum[ctr+1] = csum[ctr] + 1
    else:
        csum[ctr+1] = csum[ctr]

# 出力
for ctr in range(Q):
    l,r=map(int,input().split())
    print(csum[r-1] - csum[l-1])

Measured memory_bytes: 6164
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j <= i + k; ++j) {
            if(j < n) {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }
    cout << dp[n-1];
}



Measured memory_bytes: 1024
fun main() {
    val (H, W, m) = readLine()!!.split(' ').map { it.toInt() }

    val hs = Array(H + 1) { mutableSetOf<Int>() }
    val ws = Array(W + 1) { mutableSetOf<Int>() }

    for (i in 0 until m) {
        val (h, w) = readLine()!!.split(' ').map { it.toInt() }
        hs[h].add(w)
        ws[w].add(h)
    }

    val mh = hs.map { it.size }.max()!!
    val mhs = hs.filter { it.size == mh }

    val mw = ws.map { it.size }.max()!!
    val mws = ws.withIndex()
            .filter { (i, v) -> v.size == mw }
            .map { (i, v) -> i }

    var ans = mh + mw - 1
    for (i in mhs.indices) {
        for (j in mws.indices) {
            if (!mhs[i].contains(mws[j])) {
                ans = mh + mw
                break
            }
        }
        if (ans == mh + mw) break
    }
    println(ans)
}


Measured memory_bytes: 242008
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>

int main() {
  std::string S;
  std::cin >> S;
  if (S[2] == S[3] && S[4] == S[5]) std::cout << "Yes";
  else std::cout << "No";
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    X, Y = map(int, input().split())

    if abs(X - Y) <= 1:
        print("Brown")
    else:
        print("Alice")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

//long longしか使わない
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	map<ll, ll>mp;
	ll ans = 0;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		ll plus = a[i] + i;
		ll minus = i - a[i];
		ans += mp[i - a[i]];
		mp[a[i] + i]++;
	}
	cout << ans << endl;
	return 0;
}


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

const int MAXN = 3002;
const int P = 998244353;

int a[MAXN];
int64_t f[MAXN][MAXN];

int64_t solve(int n, int sum) {
  memset(f, 0, sizeof(f));
  int64_t ans = 0;
  for (int i = n; i > 0; --i) {
    if (sum > a[i]) ans += i * f[i + 1][sum - a[i]];
    else if (sum == a[i]) ans += i * (n + 1 - i);
    if (ans >= P) ans %= P;

    for (int j = 1; j <= sum; ++j) {
      f[i][j] = f[i + 1][j];
      if (j >= a[i]) f[i][j] += f[i + 1][j - a[i]];
      if (f[i][j] >= P) f[i][j] %= P;
    }
    f[i][a[i]] += n + 1 - i;
  }
  return ans;
}

int main() {
  int n, sum;
  std::cin >> n >> sum;
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  std::cout << solve(n, sum) << std::endl;
  return 0;
}


Measured memory_bytes: 70656
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      long N = sc.nextLong();
      long min = N;
      long a = 0;
      long b = 0;

      for(long i = 1;i<=Math.sqrt(N);i++){
          if(N%i==0){
             a = i-1;
             b = N/i-1;
        }
          min = Math.min(a+b,min);
      }
      System.out.println(min);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	int N,M,X;
	cin >> N >> M >> X;
	vector<int> A(M);
	int ans1 = 0;
	int ans = 0;
	rep(i,0,M) cin >> A[i];
	sort(all(A));
	rel(i,M,0){
		if(A[i]>X) ans1++;
		else break;
	}
	rep(i,0,M){
		if(A[i]<X) ans++;
		else break;
	}
	cout << min(ans,ans1) << endl;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define fs first
#define sc second
#define pb push_back
#define sz size() 
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;

const static int INF = 1e8;
const static D EPS = 1e-8;

int main(){
  int n,k;
  cin >> n >> k;
  vi cnt(26,0);
  rep(i,n){
    string s; cin >> s;
    cnt[s[0]-'A']++;
  }

  priority_queue<int> q;
  rep(i,26){
    if(cnt[i]>0) q.push(cnt[i]);
  }

  int ans = 0;
  while((int)q.size() >= k){
    vi tmp;
    rep(i,k){
      tmp.pb(q.top()); q.pop();
    }

    rep(i,k){
      tmp[i]--;
      if(tmp[i]>0) q.push(tmp[i]);
    }
    ans++;
  }

  cout << ans << endl;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<int32> a(n);
  REP(i,n)cin >> a[i];
  sort(ALL(a));
  a.erase(unique(ALL(a)),a.end());
  // REP(i,a.size())cout << a[i] << " ";
  // cout << endl;
  if(a.size() % 2 == 0){
    ANS(a.size()-1);
  }else{
    ANS(a.size());
  }
  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#define N 500010
#define O 48
#define MAX(a,b) (a>(b)?a:(b))
int n,f[N];
char s[N];
signed main()
{
	scanf("%d%s",&n,s+1);int now(0),cnt(0),mn(0);
	for(register int i(1);i<=n;i++)
		f[i]=f[i-1],s[i]-O?(s[i-1]==O?f[i]=MAX(f[i],cnt+mn),cnt=mn=0:8,now>0&&s[now]-O?f[i]=MAX(f[i],f[now-1]+cnt+1):8,mn=MAX(mn,f[i-1]-cnt),++cnt):(s[i-1]==O?cnt=mn=0:8,now=i-1);
	return printf("%d\n",f[n]),0;
}

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

int main() {
	// your code goes here
	int A,B,C;
	cin>>A>>B>>C;
	bool can = false;
	int sum = A;
	for(int i=0;i<=B;i++){
		if(sum%B == C){
			printf("YES\n");
			can = true;
			return 0;
		}
		sum+=A;
	}
	if(!can) printf("NO\n");
	return 0;
}

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

int main() {
    int n, q;
    cin >> n >> q;
    queue< pair<string, int> > que;
    for(int i = 0; i < n; i++) {
        string s;
        int t;
        cin >> s >> t;
        que.push(pair<string, int>(s, t));
    }

    int cnt = 0;
    while(que.size()) {
        pair<string, int> p = que.front();
        que.pop();
        if(p.second <= q) {
            cnt += p.second;
            cout << p.first << " " << cnt << endl;
        } else {
            p.second -= q;
            cnt += q;
            que.push(p);
        }
    }
    return 0;
}

Measured memory_bytes: 6332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    int n;
    cin>>n;
    int l[2*n];
    rep(i,2*n)cin>>l[i];
    sort(l,l+2*n,greater<int>());
    int ans=0;
    rep(i,2*n){
        if(i%2)ans+=l[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> lint gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> lint lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector <lint> vec(n);
  rep(i, n) cin >> vec[i];
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  lint sum = 0;
  for (int i = k; i < n; ++i) {
    sum += vec[i];
  }
  cout << sum << '\n';
}


Measured memory_bytes: 1792
let n, d = stdin.ReadLine().Split() |> fun x -> int x.[0], float x.[1]
[for _ in 1..n -> stdin.ReadLine().Split() |> fun x -> float x.[0], float x.[1]] |> List.map ((fun (x, y) -> x ** 2. + y ** 2.) >> sqrt)
|> List.filter ((>=) d) |> List.length |> printfn "%d"

Measured memory_bytes: 59656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int h,w,n;cin>>h>>w>>n;
    vin a(n);rep(i,n)cin>>a[i];
    vvin ans(h,vin(w));
    int r=0;int c=0;
    rep(i,n){
        while(a[i]){
            ans[r][c]=i+1;
            if(r%2==0){
                if(c<w-1)c++;
                else r++;
            }
            else{
                if(0<c)c--;
                else r++;
            }
            a[i]--;
        }
    }
    rep(i,h){
        rep(j,w-1)cout<<ans[i][j]<<" ";
        cout<<ans[i][w-1]<<endl;
    }
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String s = sc.next();
        int N = s.length();

        //check 1
        for(int i = 1; i<N; i++){
            if(s.charAt(i) == s.charAt(i-1)){
                System.out.println(i + " " + (i+1));
                System.exit(0);
            }
        }

        //check 2
        for(int i = 2; i<N; i++){
            if(s.charAt(i) == s.charAt(i-2)){
                System.out.println((i-1) + " " + (i+1));
                System.exit(0);
            }
        }

        //no match
        System.out.println("-1 -1");
    }
}


Measured memory_bytes: 13128
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int n, T, A; scanf("%d %d %d", &n, &T, &A);
	T *= 1000; A *= 1000;
	int res, ret = 1 << 29;
	for(int i = 0; i < n; i++){
		int h; scanf("%d", &h);
		if(abs(T - 6 * h - A) < ret){ ret = abs(T - 6 * h - A); res = i + 1; }
	}
	printf("%d\n", res);
	return 0;
}

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

class Maze {
public:
	map<char, char> next;
	map<char, char> prev;
	map<char, pair<int,int>> xy;

	Maze(vector<string> maze) : maze(maze), rest(-1) {
		next = { {'N','E'}, {'E','S'}, {'S','W'}, {'W','N'} };
		prev = { {'E','N'}, {'S','E'}, {'W','S'}, {'N','W'} };
		xy = { {'N', {0, -1}}, {'E', {1, 0}}, {'S', {0, 1}}, {'W', {-1, 0}} };
		H = maze.size();
		W = maze[0].size();
		rest = countPeople();
	}

	void move() {
		changeDirection();
		goAhead();
	}

	int countPeople() {
		if (0 <= rest) return rest;
		int count = 0;
		for (string str : maze) {
			for (char c : str) {
				count += isPerson(c);
			}
		}
		return count;
	}

private:
	vector<string> maze;
	int H, W;
	int rest;

	bool isPerson(char c) {
		return (isalpha(c) && c != 'X');
	}

	bool isPassable(char c) {
		return (c == '.' || c == 'X');
	}

	void changeDirection() {
		for (int i=0; i<H; ++i) {
			for (int j=0; j<W; ++j) {
				if ( ! isPerson(maze[i][j])) continue;
				char dir = next[maze[i][j]];
				for (int k=0; k<4; ++k) {
					int x = j + xy[dir].first;
					int y = i + xy[dir].second;
					if (maze[y][x] == '.' || maze[y][x] == 'X') {
						maze[i][j] = dir;
						break;
					}
					dir = prev[dir];
				}
			}
		}
	}

	void goAhead () {
		for (int i=0; i<H; ++i) {
			for (int j=0; j<W; ++j) {
				if ( ! isPassable(maze[i][j])) continue;
				char dir = 'E';
				for (int k=0; k<4; ++k) {
					int x = j + xy[dir].first;
					int y = i + xy[dir].second;
					if (0 <= x && x < W && 0 <= y && y < H && maze[y][x] == next[next[dir]]) {
						maze[y][x] = '*';
						if (maze[i][j] == '.') {
							maze[i][j] = tolower(next[next[dir]]);
						} else {
							rest --;
						}
						break;
					}
					dir = prev[dir];
				}
			}
		}
		for (int i=0; i<(int)maze.size(); ++i) {
			for (int j=0; j<(int)maze[i].size(); ++j) {
				if (maze[i][j] == '*') {
					maze[i][j] = '.';
				} else {
					maze[i][j] = toupper(maze[i][j]);
				}
			}
		}
	}
};

int main() {
	ios::sync_with_stdio(false);

	int W, H;
	while (cin >> W >> H && (W || H)) {
		vector<string> input(H);
		for (int i=0; i<H; ++i) cin >> input[i];

		Maze maze(input);

		if (maze.countPeople() == 0) {
			cout << 0 << endl;
			continue;
		}

		int second = 0;
		while (0 < maze.countPeople() && second <= 180) {
			maze.move();
			second ++;
		}
		if (second <= 180) cout << second << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
    ll N,K;
    cin >> N >> K;
    vl A(N);
    FOR(i,0,N)cin >> A[i];
    map<int,int> m;
    set<int> s;
    FOR(i,0,N){
        m[A[i]] += 1;
        s.insert(A[i]);
    }
    vl v;
    for(auto x:s)v.push_back(m[x]);
    sort(ALL(v));
    ll ans = 0;
    FOR(i,0,(int)s.size()-K){
        ans += v[i];
    }
    cout << ans << endl;
}

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

int main(void){

	int H;
	int W;
	int mod = 1e+9 + 7;

	cin >> H;
	cin >> W;

	vector<vector<char> > grid(H,vector<char>(W,'.'));

	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> grid[i][j];
		}
	}

	// for(int i=0;i<H;i++){
	// 	for(int j=0;j<W;j++){
	// 		cout << grid[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	vector<vector<int> > arr(H+1,vector<int>(W+1,0));
	arr[1][1] = 1;

	for(int i=1;i<H+1;i++){
		for(int j=1;j<W+1;j++){
			if(grid[i-1][j-1]=='#' or (i==1 and j==1)) continue;
			else{
				arr[i][j] = (arr[i-1][j]%(mod) + arr[i][j-1]%(mod))%(mod);
			}
		}
	}

	// for(int i=1;i<H+1;i++){
	// 	for(int j=1;j<W+1;j++){
	// 		cout << arr[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	cout << arr[H][W];
}

Measured memory_bytes: 5248
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<vector>

using namespace std;
const int INF =1001001001;
#define rep(i,n) for(int i=0;i<n;i++)
int N,M;
int L[5002];//負けた回数
vector< int > WT[5002];
//[i]=iのチームに負けたチーム(＝iのチームが勝てたチーム)




int main(){
	scanf("%d",&N);
	scanf("%d",&M);
	rep(i,M){
		int win,lose;
		scanf("%d %d",&win,&lose);
		L[lose-1]++;
		WT[win-1].push_back(lose-1);
	}
	bool types=false;
	rep(i,N){
		bool canmake=false;
		int sentaku=-1;
		rep(j,N){
			if(L[j]<=0&&!canmake){canmake=true;sentaku=j;}
			else if(L[j]<=0){types=true;break;}
		}
		rep(j,WT[sentaku].size()){
			L[WT[sentaku][j]]--;
		}
		L[sentaku]=INF;
		printf("%d\n",sentaku+1);
	}
	printf("%d",(int)(types==true));
	return 0;
}

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

#define MAX_N 100
#define MAX_M 100

const int INF =  100000000;
typedef pair<int,int> P;
//2つの型の異なる、あるいは同じ型の値をまとめて管理するクラステンプレート

int N,M;
char maze[MAX_N][MAX_M + 1];//迷路
int sx,sy;//スタート
int gx,gy;//ゴール
int d[MAX_N][MAX_M];//最短距離
int dx[4] = {1,0,-1,0};//x方向
int dy[4] = {0,1,0,-1};//y方向
int ans = 0;
int black = 0;


//たどり着けないところはINF
void bfs(){

    queue<P> que;//pair のキューの定義
    for(int i = 0 ; i < N;i++){
        for(int j = 0 ;j < M ;j++){
            d[i][j] = INF;//全ての点をINFで初期化
        }
    }
    //スタートの位置をキューに入れ、その点に0を代入する
    que.push(P(sx,sy));
    d[sx][sy] = 0;

    //キューが空になるまでループ
    while(que.size()){
        //取り出した状態がゴールなら探索終了
        P p = que.front(); que.pop();
        if(p.first == gx && p.second == gy){
            break;
        }
        //移動方向をループして探索
        for(int i = 0;i < 4;i++){
            int nx = p.first + dx[i], ny = p.second + dy[i];
            //移動可能か、また、すでに訪れているかの判定
            if(0<=nx && nx < N && 0<=ny && ny < M && maze[nx][ny] != '#' && d[nx][ny] == INF){
                que.push(P(nx,ny));
                //移動できるならその点をpからの距離+1する
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }         
    }
    return;
}

void solve(){
    bfs();
    //cout << res << endl;
}


int main(){

    cin >> N >> M;
    for(int i = 0;i < N;i++){
        for(int j = 0;j < M;j++){
            cin >> maze[i][j];
            /*if(maze[i][j] == 'S'){
                sx = i; sy = j;
            }
            if(maze[i][j] == 'G'){
                gx = i; gy = j;
            }*/
        }
    }
    sx = 0;sy=0;
    gx=N-1;gy=M-1;
    
    for(int i = 0;i < N;i++){
        for(int j = 0;j < M;j++){
            if(maze[i][j] == '#'){
                black++;
            }
        }
    }

    solve();

    if(d[N-1][M-1]== INF){
        cout << "-1" << endl;
    }else{
        cout << N*M -black - d[N-1][M-1]-1 << endl;
    }
    return 0;
}

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

#define INF 0x3f3f3f3f

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

int n;
map<int, int> mp;
int ma;
int ans;

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

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

	for (auto a : mp) {
		if (a.second > ma) {
			ma = a.second;
		}
	}

	cout << ma << endl;

	return 0;
}


Measured memory_bytes: 4736
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try (Scanner sc = new Scanner(System.in)) {
			final int N = sc.nextInt();
			
			long[] array = new long[N];
			for(int i = 0; i < N; i++){
				array[i] = sc.nextLong();
			}
			
			long min = Long.MAX_VALUE;
			long max = Long.MIN_VALUE;
			int min_pos = -1, max_pos = -1;
			for(int i = 0; i < N; i++){
				if(array[i] < min){ min = array[i]; min_pos = i; }
				if(array[i] > max){ max = array[i]; max_pos = i; }
			}
			
			LinkedList<String> answer = new LinkedList<String>();
			if(Math.abs(max) >= Math.abs(min)){
				for(int i = 0; i < N; i++){
					if(array[i] >= 0){ continue; }
					
					array[i] += array[max_pos];
					answer.add((max_pos + 1) + " " + (i + 1));
				}
				
				for(int i = 1; i < N; i++){
					array[i] += array[i - 1];
					answer.add((i) + " " + (i + 1));
				}
			}else{
				for(int i = 0; i < N; i++){
					if(array[i] <= 0){ continue; }
					
					array[i] += array[min_pos];
					answer.add((min_pos + 1) + " " + (i + 1));
				}
				
				for(int i = N - 2; i >= 0; i--){
					array[i] += array[i + 1];
					answer.add((i + 2) + " " + (i + 1));
				}
			}
			//System.out.println(Arrays.toString(array));
			
			System.out.println(answer.size());
			for(final String str : answer){ System.out.println(str); }
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 23380
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String s = sc.next();
      if(s.equals("Sunny"))System.out.println("Cloudy");
      else if(s.equals("Cloudy"))System.out.println("Rainy");
      else System.out.println("Sunny");
    }
}


Measured memory_bytes: 21204
#include <iostream>
using namespace std;
    int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if(A*B >= C*D){
        cout << A*B << endl;
    }
    if(A*B < C*D){
        cout << C*D << endl;
    }
    return 0;
    }

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

int main() {
  string S;
  cin >> S;
  int N = S.length();
  vector<string> T;
  vector<int> r;
  int k = 0;
  int cnt = 0;
  int cntR = 0;
  S += 'R';
  for (int i = 0; i < N ; i++)
  {
    cnt++;
    if (S[i] == 'L' && S[i + 1] == 'R')
    {
      string t = "";
      t = S.substr(k, cnt);
      T.push_back(t);
      r.push_back(cntR);
      k = i + 1;
      cnt = 0;
      cntR = 0;
      continue;
    }
    if (S[i] == 'R' && S[i + 1] == 'L')
    {
      cntR = cnt;
    }
      
  }
  
  vector<int> ans(N, 0);
  int j = -1;
  for (int i = 0; i < T.size(); i++)
  {
    int l = T[i].length() - r[i];

    if (r[i] >= l)
    {
      ans[j + r[i]] = (T[i].length() + 1) / 2;
    } else
    {
      ans[j + r[i]] = T[i].length() / 2;
    }
    ans[j + r[i] + 1] = T[i].length() - ans[j + r[i]];

    if ((max(r[i], l) - 1) % 2 != 0) {
      swap(ans[j + r[i]], ans[j + r[i] + 1]);
    }
    j += T[i].length();
  }
  
  for (int i = 0; i < N; i++)
  {
    cout << ans[i];
    if (i == N - 1)
    {
      cout << endl;
    } else
    {
      cout << " ";
    }  
  }
  return 0;
}


Measured memory_bytes: 5716
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b,c; cin>>a>>b>>c;
    cout<<((a+b==c||b+c==a||c+a==b)?"Yes":"No")<<endl;return 0;
}

Measured memory_bytes: 768
#include <cstdio>

int main(void){
	int n;
	long a, max=-1000000, min=1000000, sum=0;

	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		scanf(" %ld", &a);
		if(a>max) max = a;
		if(a<min) min = a;
		sum+=a;
	}

	printf("%ld %ld %ld\n", min, max, sum);

	return 0;
}



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

int N, Q;
int arr[101010];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> Q;
  fill(arr, arr+101010, 0);

  int pos = 0;

  for (int j = 0; j < Q; ++j) {    
    int a, b;
    cin >> a >> b;
    --a; --b;

    // use magic before exchange
    if (pos > 0) { arr[pos-1] = 1; }
    if (pos < N-1) { arr[pos+1] = 1; }

    swap(arr[a], arr[b]);

    if (pos == a) { pos = b; }
    else if (pos == b) { pos = a; }
  }
  if (pos > 0) { arr[pos-1] = 1; }
  if (pos < N-1) { arr[pos+1] = 1; }
  arr[pos] = 1;
  int val = 0;
  for (int j = 0; j < N; ++j) { val += arr[j]; }
  cout << val << endl;
  return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;
#define DUMPR(v) REP(_i,v.size()){std::cerr<< #v << "[" << _i << "] = " << (v[_i]) << std::endl;}
#define CIN_VEC(v,N) {v.clear(); v.reserve(N); REP(i,N){typename decltype(v)::value_type x; cin>>x; v.emplace_back(x);}};

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

int main() {
  int a[100001];
  int N;
  cin>>N;
  REP(i,N) cin>>a[i];

  int ans = accumulate(a, a+N, 0) - N;
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    long long int a;
    long long int sum = 0;
    for(int i = 0; i < n; i++){
        scanf("%lld", &a);
        while(a % 2 == 0){
            a /= 2;
            sum++;
        }
    }
    printf("%lld\n", sum);
    return 0;
}

/*
int main(){
    int n, d;
    long long int base = 1;
    scanf("%d%d", &d, &n);
    for(int i = 0; i < d; i++){
        base *= 100;
    }
    printf("%ld", base * n);
    return 0;
}
*/


Measured memory_bytes: 128
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define int long long
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,m,v,p,a[100005],b[100005],c[100005],d[100005];
bool cmp(int x,int y){
    return x>y;
}
signed main(){
    in(n);in(m);in(v);in(p);
    for(int i=1;i<=n;i++)in(a[i]);
    sort(a+1,a+1+n,cmp);
    d[0]=1;
    for(int i=1;i<=n;i++){
        d[i]=d[i-1];
        if(a[i]!=a[d[i]])d[i]=i;
        c[d[i]]++;
    }
    int ans=d[p]-1+c[d[p]];
    int sum=0,tot=c[d[p]];
    for(int i=d[p]+c[d[p]];i<=n;i++){
        if(a[i]+m<a[p])break;
        if(v<=n-tot)ans++;
        else{
            int x=m*(v-n+tot)-sum;
            x=(x+tot-1)/tot;
            if(a[i]+m>=a[p]+x)ans++;
        }
        sum+=min(m,a[p]-a[i]);
        tot++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560