akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;


#define rep(i,n) for(ll i=0;i<n;i++)

double minko(ll p, vint &x, vint &y){
  double rtn = 0;

  rep(i, x.size()){
    rtn += pow(abs(x[i]-y[i]), p);
  }

  rtn = pow(rtn, 1.0/p);

  return rtn;
}

ll minko_inf(vint &x, vint &y){
  ll rtn = 0;


  rep(i,x.size()) if(abs(x[i]-y[i]) > rtn) rtn = abs(x[i] - y[i]);

  return rtn;
}

int main() {



  cout<<fixed<<setprecision(10);

  ll n;cin>>n;
  vint x(n),y(n);
  rep(i,n)cin>>x[i];
  rep(i,n)cin>>y[i];

  cout<<minko(1, x,y)<<endl;
  cout<<minko(2,x,y)<<endl;
  cout<<minko(3,x,y)<<endl;
  cout<<minko_inf(x,y)<<endl;

}






//









Measured memory_bytes: 3468
n,m = map(int,input().split())
a = [int(input()) for i in range(m)]
dp =[0,1] + [0] * n
m = 10**9+7
for i in a:
    dp[i+1] = -1
for i in range(2,n+2):
    if dp[i] == 0:
        dp[i] = max(0,dp[i-1]) + max(0,dp[i-2])
        dp[i] %= m
    if dp[i-1] == 0 and dp[i-2] == 0:
        print(0)
        exit()
print(dp[-1])

Measured memory_bytes: 8592
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

w,h,x,y = readInts()

if x==w/2 and y==h/2:
	d = 1
else:
	d = 0

print(w*h/2,d)

Measured memory_bytes: 9412
local n = io.read("*n")
local edge = {}
local len = {}
for i = 1, n do
  edge[i] = {}
  len[i] = -1
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  edge[a][b], edge[b][a] = true, true
end
local tasks = {1}
len[1] = 0
for i = 1, n do
  local src = tasks[i]
  for dst, _u in pairs(edge[src]) do
    if len[dst] < 0 then
      len[dst] = len[src] + 1
      table.insert(tasks, dst)
    end
  end
end
local startpos = 1
for i = 2, n do
  if len[startpos] < len[i] then
    startpos = i
  end
end
tasks = {startpos}
for i = 1, n do
  len[i] = -1
end
len[startpos] = 0
for i = 1, n do
  local src = tasks[i]
  for dst, _u in pairs(edge[src]) do
    if len[dst] < 0 then
      len[dst] = len[src] + 1
      table.insert(tasks, dst)
    end
  end
end
local maxlen = 0
for i = 1, n do
  if maxlen < len[i] then maxlen = len[i] end
end
print(maxlen % 3 == 1 and "Second" or "First")


Measured memory_bytes: 46584
#include<bits/stdc++.h>
#define ll long long
#define fin(x) scanf("%lld",&x)
#define fout(x) printf("%lld\n",x)
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define cases int t;  scanf("%d",&t);   while(t--)
#define MOD 1000000007
#define MAXN 1234567
#define read() freopen("lele.txt","r",stdin)
#define write() freopen("dede.txt","w",stdout)

using namespace std;

ll prime[MAXN];

inline void init()
{
    prime[1] = 1;
    for(ll i = 2; i < MAXN; i++)
    {
        if(!prime[i])
        {
            for(ll j = 2 * i; j < MAXN; j += i)
                prime[j] = true;
        }
    }
}

int main()
{   
    init();
    ll x;
    fin(x);
    for(ll i = x;;i++)
    {
        if(!prime[i])
        {
            fout(i);
            exit(0);
        }
    }
    return 0;
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
//#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define F first
#define S second
#define mod 1000000007
signed main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	/************************************/
	
	int n, m;
	cin>>n>>m;
	int a[n][m];
	for(int i=0; i<n; i++)
	{
		string s; cin>>s;
		for(int j=0; j<m; j++)
		{
			a[i][j] = s[j] == '.';
		}
	}
	
	int r[n][m], c[n][m];
	
	for(int i=0; i<n; i++)
	{
		r[i][0] = a[i][0];
		for(int j=1; j<m; j++)
		{
			if(a[i][j] == 0)
				r[i][j] = 0;
			else if(a[i][j-1] == 0)
				r[i][j] = a[i][j];
			else r[i][j] = a[i][j] + r[i][j-1];
		}
	}
	for(int j=0; j<m; j++)
	{
		c[0][j] = a[0][j];
		for(int i=1; i<n; i++)
		{
			if(a[i][j] == 0)
				c[i][j] = 0;
			else if(a[i-1][j] == 0)
				c[i][j] = a[i][j];
			else c[i][j] = a[i][j] + c[i-1][j];
		}
	}
	
	int rs[n][m], cs[n][m];
	
	for(int i=n-1; i>=0; i--)
	{
		rs[i][m-1] = a[i][m-1];
		for(int j = m-2; j>=0; j--)
		{
			if(a[i][j] == 0)
				rs[i][j] = 0;
			else if(a[i][j+1] == 0)
				rs[i][j] = a[i][j];
			else rs[i][j] = a[i][j] + rs[i][j+1];
		}
	}
	
	for(int j = m-1; j>=0; j--)
	{
		cs[n-1][j] = a[n-1][j];
		for(int i=n-2; i>=0; i--)
		{
			if(a[i][j] == 0)
				cs[i][j] = 0;
			else if(a[i+1][j] == 0)
				cs[i][j] = a[i][j];
			else cs[i][j] = a[i][j] + cs[i+1][j];
		}
	}
	
	int ans = 0;
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<m; j++)
		{
			ans = max(ans, r[i][j] + c[i][j] + rs[i][j] + cs[i][j] - 3);
		}
	}
	cout<<ans;
	
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int maxn=100010;
int n,m;
priority_queue<pii,vector<pii >,greater<pii > > op[maxn];
int y[maxn],p[maxn],id[maxn],cnt;
int main(){
    scanf("%d%d",&n,&m);
    for(register int i=1;i<=m;i++){
        scanf("%d%d",&p[i],&y[i]);
        op[p[i]].push(make_pair(y[i],i));
    }
    pii tem;
    for(register int i=1;i<=n;i++){
        cnt=1;
        while(!op[i].empty()){
            tem=op[i].top();op[i].pop();
            id[tem.second]=cnt;
            cnt++;
        }
    }
    for(register int i=1;i<=m;i++) printf("%06d%06d\n",p[i],id[i]);
    return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef double ld;
#define X first
#define Y second
#define mk make_pair
#define pb push_back
#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(x) (x).begin(), (x).end()
const int MOD = (int) 1e9 + 7;
const ll base =  31;
void MAIN();
int main(){
    //freopen("input.txt", "r", stdin);
    ios:: sync_with_stdio(false); cin.tie(0);
    MAIN();
    return 0;
}
////////////////////////////////////////////////////////////////////////

const int N = 3004;

int n, t, s, f[N];
int a, b;

void MAIN(){
    cin >> n >> t >> s;
    int ans = 0;
    for(int i = 1; i <= n; i ++){
        cin >> a >> b;
        for(int j = t; j >= 0; j --){
            if(!(j > s && j - b < s)) if(j >= b) f[j] = max(f[j], f[j-b] + a);
            ans = max(ans, f[j]);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1212
N, A, B = map(int, input().split(" "))
ans = 0
for i in range(1,N + 1):
	num = str(i)
	sum = 0
	for j in num:
		sum += int(j) 		      
	if sum >= A and sum <= B:
		# print(i)          
		ans += i
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int ws(int n){
	int l=0;
	while(n) n/=10,l++;
	return l;
}
int f(long long n){
	for(int i=(int)sqrt(n);;i--)
		if(n%i==0)
			return n/i;
}
int main(){
	long long n;
	scanf("%lld",&n);
	printf("%d\n",ws(f(n)));
	return 0;
}

Measured memory_bytes: 256
def include3?(x)
	return (x % 10 == 3)
end


n = gets.to_i
cout = ""
for i in 1..n
	x = i
	if(x%3 == 0)
		print(cout + " " + i.to_s)
		next
	end

	while x != 0
	  if(include3?(x))
		  print(cout + " " + i.to_s)
		  x = 0
	  else
	  	x /= 10
	  end
	end
end
puts cout

Measured memory_bytes: 6100
N = int(input())

A = [list(map(int, input().split())) for _ in range(N)]
flg_list = [[True] * N for _ in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            if A[i][j] == A[i][k] + A[k][j] and i != k and k != j:
                flg_list[i][j] = flg_list[j][i] = False
ans = 0
for i in range(N):
    for j in range(N):
        if flg_list[i][j]:
            ans += A[i][j]
print(ans//2)

Measured memory_bytes: 45788
n, m = (int(i) for i in input().split())
#print(n,m)
data = [[int(i) for i in input().split()] for i in range(m)]
#print(data)
#n,m=2,3
#data=[[1, 32], [2, 63], [1, 12]]#[ken_city,year]
#print(len(data))
id=[]
for i in range(m):
    id.append(i+1)

#print(id)
    
dataid=list(zip(data,id))
#print(dataid)
dataid.sort()
#print(dataid)

listz=[]
ken=0

for i in range(m):
    if dataid[i][0][0]==ken:
        kazu+=1        
        y=[dataid[i][1],dataid[i][0][0],kazu]
        listz.append(y)
    else:
        kazu=1
        ken=dataid[i][0][0]
        y=[dataid[i][1],dataid[i][0][0],kazu]
        listz.append(y)
        
#print(z)

listz.sort()
#print(listz)

for i in range(m):
    print(str(listz[i][1]).zfill(6)+str(listz[i][2]).zfill(6))



Measured memory_bytes: 47384
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

void flip(int x,int y,int stage[10][10]){
	const int t[][2] = {{0,0},{-1,0},{1,0},{0,1},{0,-1}};
	for(int i=0;i<5;i++){
		int dx = x+t[i][0];
		int dy = y+t[i][1];

		if(dx < 0 || dx >= 10 || dy < 0 || dy >= 10) continue;

		stage[dy][dx]*=-1;
	}
}

bool checkStage(int store[10][10],int x,int y){
	return store[y][x] == -1 ? true : false;
}

bool isClear(int store[10][10]){
	for(int y=0;y<10;y++){
		for(int x=0;x<10;x++){
			if(store[y][x]==1) return false;
		}
	}

	return true;
}

void writeResult(int result[10][10]){
	for(int y=0;y<10;y++){
		for(int x=0;x<10;x++){
			printf("%d%s",result[y][x],x==9 ? "\n" : " ");
		}
	}
}

int main(){

	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			int stage[10][10];
			
			for(int y=0;y<10;y++){
				for(int x=0;x<10;x++){
					int num;
					scanf("%d",&num);
					stage[y][x] = (num == 0 ? -1 : 1);
				}
			}
			
			for(int S=0;S<=(1 << 10)-1;S++){
				int store[10][10];
				int result[10][10];
				memset(result,0,sizeof(result));
				//memset(store,0,sizeof(store));
				memcpy(store,stage,sizeof(stage));

				for(int j=0;j<10;j++){
					if((S>>j) & 1){
						flip(j,0,store);
						result[0][j]=1;
					}
				}

				for(int y=1;y<10;y++){
					for(int x=0;x<10;x++){
						flip(x,y,store);
						if(!checkStage(store,x,y-1)){
							flip(x,y,store);
						}
						else{
							result[y][x] = 1;
						}
					}
				}

				if(isClear(store)){
					writeResult(result);
					break;
				}
			}

		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int n,K,ans,x[100005];
int main()
{
	//freopen("candle.in","r",stdin);
	//freopen("candle.out","w",stdout);
	scanf("%d%d",&n,&K);
	for(RI i=1;i<=n;++i) scanf("%d",&x[i]);
	ans=1e9;
	for(RI i=1;i+K-1<=n;++i) {
		int kl;
		if(x[i]<=0&&x[i+K-1]<=0) kl=abs(x[i]);
		else if(x[i]>=0&&x[i+K-1]>=0) kl=x[i+K-1];
		else kl=min(abs(x[i]),x[i+K-1])*2+max(abs(x[i]),x[i+K-1]);
		ans=min(ans,kl);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  string s, t;
  cin >> s >> t;
  int size = s.size();
  s += t.at(size);

  if (s == t)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


Measured memory_bytes: 3632
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    bool isNoChange = false;
    for (int i = 0; i <= n/4; ++i)
    {
        for (int j = 0; j <= n/7; ++j)
        {
            if (i * 4 + j * 7 == n)
            {
                isNoChange = true;
                break;
            }
        }
    }
    
    cout << (isNoChange ? "Yes" : "No") << endl;
    
    return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#  define _GLIBCXX_DEBUG
#else
#  define cerr __get_ce
#endif
#include <bits/stdc++.h>
#define ff first
#define ss second
#define szof(x) ((int)x.size())

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
mt19937 tw(9450189);
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }


void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	int tmp = min(c, a);
	ans = tmp;
	c -= tmp;
	int tmp2 = min(c, b);
	c -= tmp2;
	int tmp3 = min(c, 1);
	cout << b + tmp + tmp2 + tmp3 << "\n";
}


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	// cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}
	
#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}


Measured memory_bytes: 256
def cumprod(start, stop=None, mod=None):
    res = 1
    for i in range(start, stop):
        if mod:
            res *= i % mod
            res %= mod
        else:
            res *= i
    return res


n, a, b = map(int, input().split())

mod = 10**9+7
res = pow(2, n, mod) - 1
comb_a = cumprod(n-a+1, n+1, mod) * pow(cumprod(1, a+1, mod), mod-2, mod) % mod
comb_b = cumprod(n-b+1, n+1, mod) * pow(cumprod(1, b+1, mod), mod-2, mod) % mod
res -= comb_a + comb_b
while res < 0:
    res += mod

print(res)


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int N;
  int L[10]={};
  scanf("%d",&N);
  int max = -1;
  int j;
  int sum = 0;
  for(int i=0;i<N;i++){
    scanf("%d",&L[i]);
    sum += L[i];
    if(L[i] > max){
      max = L[i];
      j = i;
    }
  }
  sum - L[j] > L[j] ? printf("Yes\n"):printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a=0,b=0;

    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='0'){a++;}
        else{b++;}
    }
    a=min(a,b);
a=a*2;
cout<<a<<endl;

}


Measured memory_bytes: 512
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val a = nextInt()
    val b = nextInt()
    val c = nextInt()
    val d = nextInt()
    val train = if(a < b) a else b
    val bus = if(c < d) c else d
    println(train + bus)
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
            .filter { value % it == 0L }
            .map { listOf(it, value / it) }
            .flatten()
            .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 31392
input_line = list(input())
half = (len(input_line) - 1) // 2
before = "".join(input_line[0: half])
after = "".join(input_line[half + 1: len(input_line)])
input_line = "".join(input_line)
input_line_reverse = "".join(list(reversed(input_line)))
before_reverse = "".join(list(reversed(before)))
after_reverse = "".join(list(reversed(after)))

if input_line == input_line_reverse and before == before_reverse and after == after_reverse:
    print("Yes")
else:
    print("No")


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

using ll=long long;

const int MAX = 2200000;
const long long MOD = 1000000007;
long long INF = 90000000001000;


int main() {

ll n;cin >> n;
ll sum = 0;
for (int i = 1; i <= n; ++i)
{
    if(i%3==0||i%5==0) continue;
    else sum += i;
}
cout << sum << endl;
return 0;
}




Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	int[] F;
	boolean[] flag;
	void run() {
		Scanner sc = new Scanner(System.in);
		F = new int[50];
		flag = new boolean[50];
		int ans = fib(sc.nextInt());
		System.out.println(ans);
		sc.close();
	}
	
	int fib(int n) {
		if(n == 0 || n == 1) return 1;
		if(flag[n]) return F[n];
		F[n] = fib(n-1) + fib(n-2);
		flag[n] = true;
		return F[n];
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 26352
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
int main()
{
    int n, k;
	cin>>n>>k;
	int ans=0;
	while(n){
		n/=k;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  bool isAliceTurn = true;
  vector<int> aliceVec(N / 2 + N % 2);
  vector<int> bobVec(N / 2);
  vector<int> vec(N);
  for (int i = 0; i < N;i++) {
    int value;
    cin >> value;
    vec.push_back(value);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i = 0;i < N;i++) {
    if (isAliceTurn) {
      aliceVec.push_back(vec.at(i));
    } else {
      bobVec.push_back(vec.at(i));
    }
    isAliceTurn = !isAliceTurn;
  }
  
  int aliceTotal = 0;
  int bobTotal = 0;
  for (int x = 0; x < aliceVec.size(); x++) {
    aliceTotal += aliceVec.at(x);
  }
  
  for (int x = 0; x < bobVec.size(); x++) {
    bobTotal += bobVec.at(x);
  }
  
  cout << aliceTotal - bobTotal << endl;
}

Measured memory_bytes: 256
def binary_search(array, tgt_no): #  arrayは昇順にソートされているものとする

    def compare_midpoint(tgt, array, start, end):
        midpoint = (end + start)//2
        if tgt == array[midpoint]:
            return True, None, None
        elif tgt < array[midpoint]:
            return False, start, midpoint
        elif tgt > array[midpoint]:
            return False, midpoint + 1, end

    start = 0
    end = len(array)
    while True:
        ret, start, end = compare_midpoint(tgt_no, array, start, end)
        if ret:
            return True
        if end <= start:
            return False


def main():
    _ = input()
    array_A = list(map(int, input().split()))
    _ = input()
    array_B = list(map(int, input().split()))

    cnt = 0
    for integer_B in array_B:
        if binary_search(array_A, integer_B):
            #print(integer_B)
            cnt += 1

    print(cnt)
    return


main()


Measured memory_bytes: 16712
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	int k;
	cin >> k;
	string s;
	cin >> s;
	if (s.size() <= k) {
		cout << s << endl;
	}
	else {
		rep(i, k) {
			cout << s[i];
		}
		cout <<"..."<< endl;
	}
}




Measured memory_bytes: 3748
import numpy as np

M, D = map(int, input().split())

if D < 22:
    print(0)
    
else:
    d = np.arange(22, D+1)
    m = np.arange(1, M+1)
    ans = 0
    
    for i in d:
        if i % 10 != 1:
            i1 = i % 10
            i10 = i // 10
            if np.any(m==i1*i10):
                ans += 1
                
    print(ans)

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

#define mx 500008

#define pii pair<int,int>
#define pi acos(-1.0)
#define pb push_back
#define ss second
#define ff first
typedef long long int ll;
///adjacent move
int fx[4]={0,+1,0,-1};
int fy[4]={+1,0,-1,0};
///knight
ll prime[mx];

vector<pii>v[mx];
double d(int x1,int x2,int y1,int y2)
{
    double x=(x1-x2);
    x=x*2;
    double y=(y1-y2);
    y*=2;
    return sqrt(x+y);
}
int main()
{
    int t=1;

    while(t--){
        ll n,k;
        cin>>n;
        string s="7";
        int ans=0;
        ll cur=0;
        while(1){
            cur=cur*10+7;
            ans++;
            if(cur%n==0){
                break;
            }
            if(ans>1e8) {
                cout<<-1<<endl;
                return 0;
            }
            cur=cur%n;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 15308
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

const int N = 2e5 + 5;
int pref[N];

int bits(int n) {
    return __builtin_popcountll(n);
}

int power(int x, int n, int m) {

    int res = 1;
    while(n) {
        if(n & 1) {
            res = (res * x) % m;
        }
        x = (x * x) % m;
        n /= 2;
    }
    return res;

}

int sub(int x, int y, int mod) {
    return (x - y + mod) % mod;
}

int add(int x, int y, int mod) {
    return (x + y) % mod;
}

int32_t main() {

    int n;
    cin >> n;

    string x;
    cin >> x;

    for(int i = 1; i < N; i++) {
        pref[i] = pref[i % bits(i)] + 1;
    }

    int o = 0;
    for(int i = 0; i < n; i++)
        if(x[i] == '1')o++;

    int mod1 = o + 1;
    int mod2 = o - 1;
    if(mod2 <= 0)mod2 = 1e5;

    int value1, value2;
    value2=value1=0;
    for(int i = 0; i < n; i++) {
        int base = n - i - 1;
        if(x[i] == '1') {
            value1 += power(2, base, mod1);
            value1 %= mod1;
            value2 += power(2, base, mod2);
            value2 %= mod2;
        }
    }
    //cout<<value1<<" "<<value2<<endl;
    int ones;
    for(int i = 0; i < n; i++) {
        ones = o;
        if(x[i] == '1') {
            ones--;
            if(ones == 0) {
                cout << 0 << endl;
                continue;
            }
            int value = sub(value2, power(2, n - i - 1, mod2), mod2);
            cout << pref[value] + 1 << endl;
        } else {

            int value = add(value1, power(2, n - i - 1, mod1), mod1);
            cout << pref[value] + 1 << endl;
        }

    }



    return 0;
}



Measured memory_bytes: 5264
#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl
ll a[200009],b[1000000];
map<ll,ll>mp;

///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b[1000],aa[1000],bb[10000],n,m,r,t;
    // ll bb[10][10];
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    s1="CODEFORCES";

    while(cin>>n)
    {
       // mem(a);
        cin>>k;
        c=0;
        for(i=0; i<n; i++)
        {
            cin>>m;
            a[m]++;
        }
        sort(a,a+200001);

        for(i=200000,j=0; j<k; i--,j++)
        {
            c+=a[i];
        }
        cout<<n-c<<endl;
    }
}






Measured memory_bytes: 3584
#include <stdio.h>
int main(void)
{
    int N,T,A;
    double res;
    int H[1100];
    scanf("%d%d%d", &N, &T, &A);
    for(int i=0;i<N;i++) scanf("%d", &H[i]);
    double min=1000000000;
    int ans=0;
    for(int i=0;i<N;i++){
        res=((T-H[i]*0.006)-A)*((T-H[i]*0.006)-A);
        if(min>res){
            min=res;
            ans=i+1;
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))

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


int main(){
int N; cin>>N;
vector<bool> vec(N);
REP(i,N){
    int d1,d2;
    cin>>d1>>d2;
    if(d1==d2){
        vec.at(i)=true;}else{
            vec.at(i)=false;
        }
}
bool ans=false;
REP(i,N-2){
    if(vec.at(i)&&vec.at(i+1)&&vec.at(i+2)){
        ans=true;
    }

}
if(ans){
   cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}
}
  

  


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}
int last_digit(int n)
{
    int ans = 0;
    while (n != 0)
    {
        ans = n % 10;
        n /= 10;
    }
    return ans;
}
int main()
{
    ll n, d;
    cin >> n >> d;
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        if (sqrt(pow(x, 2) + pow(y, 2) * 1.0) <= d)
        {
            count++;
        }
    }
    cout << count;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> xs(3*n);
    for (int i = 0; i < 3*n; ++i) {
        if (s[i] == 'R') {
            xs[i] = 0;
        } else if (s[i] == 'G') {
            xs[i] = 1;
        } else {
            xs[i] = 2;
        }
    }
    vector<vector<int>> colors(3);
    for (int i = 0; i < 3*n; ++i) {
        colors[xs[i]].push_back(i);
    }
    vector<int> ms(n), Ms(n);
    vector<int> types(3*n, 0);
    for (int i = 0; i < n; ++i) {
        ms[i] = min(min(colors[0][i], colors[1][i]), colors[2][i]);
        Ms[i] = max(max(colors[0][i], colors[1][i]), colors[2][i]);
        types[ms[i]] = -1;
        types[Ms[i]] = 1;
    }
    long long prime = 998244353;
    long long first_count = 0;
    long long second_count = 0;
    long long third_count = 0;
    long long answer = 1;
    for (int i = 0; i < 3*n; ++i) {
        if (types[i] == -1) {
            answer = (answer * (n - first_count)) % prime;
            ++first_count;
        } else if (types[i] == 0) {
            answer = (answer * (first_count - second_count)) % prime;
            ++second_count;
        } else {
            answer = (answer * (second_count - third_count)) % prime;
            ++third_count;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 5008
while True:
    height, width = [int(x) for x in input().split(" ")]
    if height == width == 0:
        break
    col1 = "#." * 150
    col2 = ".#" * 150
    col_set = col1[:width] + "\n" + col2[:width] + "\n"
    print(col_set * (height // 2) + (col1[:width] + "\n") * (height % 2))

Measured memory_bytes: 7684
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <tuple>
using namespace std;
long int N, A, B, Z, count, D, sum,Q;
int main() {
    
    cin >> N >> A >> B;
    ::sum = A + B;
    
    D = N / ::sum;
    ::count += D * A;
    Z += D * ::sum;
    Q = N - Z;
    if (Q <= A) {
        ::count += Q;
    }
    else { ::count += A; }
    
    cout << ::count << endl;
    
    
}

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    map<ll, ll> mp1;
    REP(i, 0, n){ll a; cin >> a; mp1[a]++;}
    int m; cin >> m;
    REP(i, 0, m){
        ll b; cin >> b;
        if(mp1[b] == 0){
            cout << "NO" << endl;
            return 0;
        }else{
            mp1[b]--;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 12800
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int n, int s) {
    int ans = 0;
    foreach (e; combinations!int(iota(10).array, n)) {
        if (e.sum == s)
            ans++;
    }
    return ans;
}

void main() {
    while (true) {
        auto xs = readints;
        int n = xs[0], s = xs[1];

        if (n == 0 && s == 0) break;
        writeln(calc(n, s));
    }
}

struct combinations(T) {
    private T[] _source;
    private int _n;
    private T[][] _q;
    private int _state;

    this(T[] source, int n) {
        _source = source.dup;
        _n = n;
        _state = 0;

        pushNext();
    }

    @property T[] front() {
        return _q[0];
    }

    void popFront() {
        _q = _q[1..$];
        pushNext();
    }

    bool empty() {
        return _q.length == 0;
    }

    private void pushNext() {
        int len = cast(int)_source.length;
        while (_state < (1 << len)) {
            int[] buf;
            for (int j = 0; j < len; j++) {
                if (_state & (1 << j)) {
                    buf ~= _source[j];
                    if (buf.length > _n) break;
                }
            }

            _state++;
            if (buf.length == _n) {
                _q ~= buf;
                return;
            }
        }
    }
}



Measured memory_bytes: 3136
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:

    Int func(Int X, Int Y) {
        if (X == 0 || Y == 0) {
            return 0ll;
        }
        if (X == Y) {
            return X;
        } else if (X > Y) {
            return func(Y, X);
        } else {
//            Int ret = 2ll * X * (Y / X);
//            ret += func(X, Y % X);
            Int div = Y / X;
            if (Y % X == 0)div--;
            Int ret = 2ll * X * div;
            Int rec = func(X, Y - div * X);
            ret += rec;
            return ret;
        }
    }

    void solve() {
        Int N, X;
        cin >> N >> X;

        Int ans = N + func(X, N - X);

        cout << ans << endl;
    }

};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

int w[100000],n,k;
int cntp(int p)
{
	int cnt=1,wgh=0;
	for(int i=0;i<n;)
	{
		if(wgh+w[i]<=p)
		{
			wgh+=w[i++];
		}
		else
		{
			if(wgh>0)cnt++;
			else return k+1; 
			wgh=0;
		}
	}
	return cnt;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;scanf("%d",w+i++));
	int l=0,r=1000000000,m;
	while(l<r)
	{
		m=(l+r)/2;
		if(cntp(m)>k)l=m+1;
		else r=m;
	}
	for(m-=9;;m++)
	{
		if(cntp(m)<=k)break;
	}
	printf("%d\n",m);
	return 0;
}

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

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> ans(n - 1, 0);

    for(int i = 1; i <= n - 1; i++){
        for(int j = i + 1; j <= n; j++){
            int tmp = min(j - i, abs(x - i) + 1 + abs(j -y));
            ans[tmp - 1]++;
        }
    }

    for(auto x:ans){
        cout << x << endl;
    }
    return 0;
}

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

using namespace std;

template <unsigned long long mod> class modint {
public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod - this->v); }
	modint& operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod) v -= mod;
		return *this;
	}
	modint& operator-=(const modint rhs) {
		if (v < rhs.v) v += mod;
		v -= rhs.v;
		return *this;
	}
	modint& operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) {
				ret *= a;
			}
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint& operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
	friend ostream& operator<<(ostream& os, modint& u) {
		os << u.v;
		return (os);
	}
	friend istream& operator>>(istream& is, modint& u) {
		is >> u.v;
		return (is);
	}
};

const int MOD = 1000000007;
using mint = modint<MOD>;

class Solution {
public:
	void solve() {
		long long _n, _k;
		cin >> _n >> _k;
		mint n = _n, k = _k, ans = 0;
		for (long long r = _k; r <= _n + 1; r++) {
			ans += n * r - mint((r * (r - 1))) + 1;
		}
		cout << ans << "\n";

		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll dist(P a, P b){
  return abs(a.first-b.first) + abs(a.second - b.second);
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll H, W, D;
  cin >> H >> W >> D;
  vector<llvec> dS(D);
  vector<P> A(H*W+1);
  rep(i, H){
    rep(j, W){
      ll a;
      cin >> a;
      A[a] = {i, j};
    }
  }
  rep(i, D){
    ll j=i;
    dS[i].push_back(0);
    while(j+D<=H*W){
      dS[i].push_back(dist(A[j],A[j+D]));
      j+=D;
    }
    rep(k, dS[i].size()-1){
      dS[i][k+1] += dS[i][k];
    }
  }
  ll Q;
  cin >> Q;
  llvec L(Q), R(Q);
  rep(i, Q){
    cin >> L[i] >> R[i];
  }


  rep(i, Q){
    cout << dS[R[i]%D][R[i]/D]-dS[L[i]%D][L[i]/D] << endl;
  }
  return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){fastio
    ll n;cin>>n;
    ll a[n+1];rep(i,1,n)cin>>a[i];
    ll maxi=-inf,flag=-1;
    vector<l_l> ans;
    rep(i,1,n){
        if(maxi<abs(a[i])){
            maxi=abs(a[i]);
            flag=i;
        }
    }
    if(maxi==0){
        cout<<0<<endl;
        return 0;
    }
    if(a[flag]<0){
        rep(i,1,n){
            if(i!=flag){
                ans.pb(l_l(flag,i));
            }
        }
        for(ll i=n;i>=2;i--){
            ans.pb(l_l(i,i-1));
        }
        cout<<ans.size()<<endl;
        rep(i,0,(ll)ans.size()-1){
            cout<<ans[i].first<<' '<<ans[i].second<<endl;
        }
    }else{
        rep(i,1,n){
            if(i!=flag){
                ans.pb(l_l(flag,i));
            }
        }
        for(ll i=1;i<=n-1;i++){
            ans.pb(l_l(i,i+1));
        }
        cout<<ans.size()<<endl;
        rep(i,0,(ll)ans.size()-1){
            cout<<ans[i].first<<' '<<ans[i].second<<endl;
        }
    }
    
    
    return 0;
}





Measured memory_bytes: 3632
import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i,2019)
  mod.append((now + mod[i]) % 2019)


c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
for i in hindo:
  if i != 1:
    cnt += i*(i-1)//2


print(cnt)

Measured memory_bytes: 16636
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
 
#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

using namespace std;

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


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9+7;

const int N = 2e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p=clock();



int32_t main(){
  fast;

  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);

  char c;
  cin >> c;
  cout << (char)(c + 1);

  time_p=clock()-time_p;
  cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

  return 0;
}

Measured memory_bytes: 256
S=input()
n=len(S)
i=0
count=0
maxcount=0
while(n>0):
    if(S[i]=='A'or S[i]=='T' or S[i]=='G' or S[i]=='C'):
        count=count+1
        if(maxcount<count):
            maxcount=count
    else:
        if(maxcount<count):
            maxcount=count
        count=0
    n=n-1
    i=i+1
print(maxcount)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))

#if 1
//No.4
int main()
{
	INT N;
	LLONG K;
	cin >> N >> K;

	INT* A = new INT[N+1];
	for (int i = 0; i < N; ++i) {
		cin >> A[i+1];
	}

	INT* ariveCnt = new INT[N+1];
	memset(ariveCnt, 0, sizeof(INT) * (N+1));

	INT loopStartCnt, loopLength, loopPos;
	{
		INT pos = 1;
		INT count = 0;
		while (1) {
			INT next = A[pos];
			if (next == 1 || ariveCnt[next] > 0) {
				loopPos = next;
				loopStartCnt = ariveCnt[next];
				loopLength = (count + 1) - ariveCnt[next];
				//cout << loopPos << ", "<< loopStartCnt << ", " << loopLength << endl;
				break;
			}
			else {
				count += 1;
				pos = next;
				ariveCnt[next] = count;
			}
		}
	}


	if (K >= loopStartCnt + loopLength) {
		LLONG K_tmp = K - loopStartCnt;
		K_tmp %= loopLength;

		INT pos = loopPos;
		for (int i = 0; i < K_tmp; ++i) {
			pos = A[pos];
		}

		cout << pos;
	}
	else {
		INT pos = 1;
		for (int i = 0; i < K; ++i) {
			pos = A[pos];
		}

		cout << pos;
	}

	delete[] ariveCnt;
	delete[] A;
	return 0;
}
#endif


Measured memory_bytes: 4816
#include <stdio.h>
#define N 8
#define FREE -1
#define NOTFREE 1

int gyou[N],retsu[N],leftback[2*N-1],rightback[2*N-1];
int X[N][N];

void initialize() {
  for(int i=0;i<N;i++){
    gyou[i]=FREE;
    retsu[i]=FREE;
  }
  for(int i=0;i<2*N-1;i++){
    leftback[i]=FREE;
    rightback[i]=FREE;
  }
}
void printchess() {
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(X[i][j]){
	if(gyou[i]!=j)return;
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(gyou[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
void recursive(int i){
  if(i==N){
    printchess();
    return;
  }
  for(int j=0;j<N;j++){
    if(NOTFREE==retsu[j] || NOTFREE==leftback[i+j] || NOTFREE==rightback[i-j+N-1])continue;
    gyou[i]=j;
    retsu[j]=leftback[i+j]=rightback[i-j+N-1]=NOTFREE;
    recursive(i+1);
    gyou[i]=retsu[j]=leftback[i+j]=rightback[i-j+N-1]=FREE;
  }
}

int main() {
  initialize();
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      X[i][j]=0;
    }
  }
  int k;
  scanf("%d",&k);
  for(int i=0;i<k;i++){
    int r,c;
    scanf("%d%d",&r,&c);
    X[r][c]=1;
  }
  recursive(0);
  
  return 0;
}



Measured memory_bytes: 2112