akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};

int main(){
  ll n,a=0;
  cin >> n;
  rep(i,n){
    if((i+1)%3!=0&&(i+1)%5!=0)a+=(i+1);
  }
  cout << a;
}


Measured memory_bytes: 3640
#include <stdio.h>

#define MAX_N 50

int N, K;
int l[50];


int main(){
	int MAX_K;
	int value=0;
	int i, j=0, tmp;

	scanf("%d %d", &N, &K);

	//MAX_K = N;

	for(i = 0; i < N; i++){
		scanf("%d", &l[i]);
	}

	for(i = 1; i < N; i++){
		tmp = l[i];
		if(l[i-1] > tmp){
			j = i;
			do {
				l[j] = l[j-1];
				j--;
			} while(j > 0 && l[j-1] > tmp);
			l[j] = tmp;
		}
	}

	j = N;
	for(i = 0; i <= K; i++){
		value += l[j];
		j--;
	}

	printf("%d\n", value);
	return 0;
}

Measured memory_bytes: 128
#include <functional>
#include <stdexcept>
#include <streambuf>
#include <exception>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <typeinfo>
#include <utility>
#include <complex>
#include <numeric>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <locale>
#include <memory>
#include <iosfwd>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <ios>
#include <new>
#include <set>
 
#define int long long
#define ll long long 
#define sqr(x) x * x
#define F first
#define S second
#define make make_pair
#define pb push_back
#define sz(x) (ll)(x.size()) 
#define all(x) x.begin (), x.end ()

using namespace std;

typedef long double ld;

const int MOD = (int)1e9 + 7;
const int N = (int)2e6+ 222;
const ll INF = (ll)1e18;
const double eps = (double)1e-6;

int n, a[N];
ld x[N], y[N], f[N];

ld calc () {
    ld sum = 0;
    for (int i = 1; i <= n - 1; ++i) {
        sum += sqrt((x[a[i]] - x[a[i + 1]]) * (x[a[i]] - x[a[i + 1]]) + (y[a[i]] - y[a[i + 1]]) * (y[a[i]] - y[a[i + 1]]));
    }
    return sum;
}

void solve () {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i] >> y[i];
    }
    for (int i = 1; i <= n; ++i) a[i] = i;
    ld ans = ans + calc();
    while (next_permutation(a + 1, a + 1 + n)) {
        ans += calc();
    }
    f[0] = 1;
    for (int i = 1; i <= n; ++i) f[i] = f[i - 1] * i; 
    cout << setprecision(6) << fixed << ans / f[n] ; 
	   
}

signed main () {
    #ifdef Maga
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
    while (t --) {
    	solve ();
    }
    return 0;
}





Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n;
    cin>>n;
    int b[n-1];
    rep(i,n-1){
        cin>>b[i];
    }
    int a[n]={};
    a[0]=b[0];a[n-1]=b[n-2];
    for(int i=1;i<n-1;i++){
        a[i]=min(b[i],b[i-1]);
    }
    int ans=0;rep(i,n) ans+=a[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int n,k,x,y;
int main()
{
    fast;
    cin>>n>>k>>x>>y;
    if (n>=k)
       cout<<x*k+(n-k)*y<<endl; 
    else
       cout<<n*x<<endl;
    return 0;
}

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

int main() {
	int n, pn, pnc=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> pn;
		if ((pn == 2)||(pn == 3))
			pnc += 1;
		else if (pn % 2 == 0) {}
		else {
			for (int j = 3; j <= pn/j; j += 2) {
				if (pn % j == 0) {
					pnc -= 1; 
					break;
				}
			}
			pnc += 1;
		}
	}	
	cout << pnc << endl;
	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define MAX_N 10000000
#define ll long long

using namespace std;

int n,d;
ll p[MAX_N][2];

int main(){
  cin >> n >> d;
  for(int i=0;i < n;i++){
    cin >> p[i][0] >> p[i][1];
  }
  int ans = 0;
  for(int i=0;i < n;i++){
    if(sqrt((double)p[i][0]*p[i][0] + (double)p[i][1]*p[i][1]) <= d) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6692
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  rep(i,0,n){
    if((n-4*i)>=0 && (n-4*i)%7==0){
      cout<<"Yes\n";
      return;
    }
  }
  cout<<"No\n";
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key   = k;
	z->left  = NIL;
	z->right = NIL;
	
	while(x != NIL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL) {
		root = z;
	} else {
		if( z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
	
int main(void) {
	int n, i, x;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		cin >> com;
		if(com == "insert") {
			scanf("%d",&x);
			insert(x);
		} else if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 26708
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>

using namespace std;


int main() {

    int A, B;

    cin >> A >> B;

    if (A >= 13) {
        cout << B << "\n";
    } else if ((A >= 6) and (A <= 12)) {
        cout << (B / 2) << "\n";
    } else {
        cout << 0 << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b+c >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Nmax=200010;
//ll a[Nmax];
//int* P = new int[N];
int main() {
	int H,W,flag=0;
	char s[50][50],a;
	cin >> H >> W;

	for(int i=0;i < H;i++){
		for(int j=0;j < W;j++){
			cin >> s[i][j];
		}
	}
	for(int i=0;i < H;i++){
		for(int j=0;j < W;j++){
			if(s[i][j]=='#'){
			a=s[i][j];
			if(s[i-1][j]!=a&&s[i+1][j]!=a&&s[i][j-1]!=a&&s[i][j+1]!=a) flag=1;
		}}
	}
	if(flag==1) cout << "No" <<endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A[55];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	sort(A+1,A+n+1);
	double ans=A[1];
	for(int i=2;i<=n;i++)ans=(ans+1.0*A[i])/2.0;
	printf("%.6lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
s=input()
flag=1
for i in range(len(s)):
    if((i+1)%2!=0):
        if(s[i]=='L'):
            print("No")
            flag=0
            break
    if((i+1)%2==0):
        if(s[i]=='R'):
            print("No")
            flag=0
            break
if(flag==1):
    print("Yes")
        

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,W,w0,w,V,ans=0,kari;
  vector<ll> v[4];
  cin>>n>>W>>w0>>V;
  v[0].pb(V);
  Fr(i,n-1){cin>>w>>V;v[w-w0].pb(V);}
  fr(i,4){
    sort(v[i].begin(),v[i].end());
    reverse(v[i].begin(),v[i].end());
  }
  fr(i0,v[0].size()+1){fr(i1,v[1].size()+1){fr(i2,v[2].size()+1){fr(i3,v[3].size()+1){
    if(i0*w0+i1*(w0+1)+i2*(w0+2)+i3*(w0+3)>W) continue;
    kari=0;
    fr(j0,i0) kari+=v[0][j0];
    fr(j1,i1) kari+=v[1][j1];
    fr(j2,i2) kari+=v[2][j2];
    fr(j3,i3) kari+=v[3][j3];
    ans=max(ans,kari);
  }}}}
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N,M=map(int, input().split())
A=[list(map(int, input().split())) for _ in range(M)]
   
from collections import deque
import sys
sys.setrecursionlimit(10**7)

D=[[]for i in range(N)]
E=[-1]*N
for a,b in A:
   a-=1
   b-=1
   D[a].append(b)
   D[b].append(a)
#print(D)

def bfs(x):
  q=deque()
  q.append(x)
  
  while len(q):
    x=q.popleft()    
    for i in D[x]:
      nx=i
      if E[nx]==-1:
        E[nx]=x
        q.append(nx)
bfs(0)
print('Yes')
for i in E[1:]:
  print(i+1)

Measured memory_bytes: 70956
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
using namespace std;
int A[100005];

int main() {
	string s;
	int n;
	cin >> s;
	n = s.length();
	cout << s[0] << n - 2 << s[n - 1] << endl;
	return 0;
}

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

using namespace std;

const int Nmax = 5e5+100;

int n, p, i, a[Nmax], cnt = 0;
char s[Nmax];

void add9()
{
    a[0] += 9; cnt += 9;
    for(int i=0; i<=n && a[i] > 9; ++i)
    {
        a[i] -= 10;
        cnt -= 9;
        ++a[i+1];
    }

    if(a[n+1]) ++n, ++cnt;
}

int main()
{
    cin.sync_with_stdio(false);

    cin >> (s+1);
    n = strlen(s+1);

    p = 0;
    for(i=n; i; --i)
    {
        p += (s[i]-'0') * 9;
        a[n-i] = p%10;
        cnt += p%10;
        p /= 10;
    }

    if(p) a[n] = p, cnt += p;
        else --n;

    for(i=1; i<=n + 10; ++i)
    {
        add9();
        if(cnt <= 9*i)
        {
            cout << i << '\n';
            return 0;
        }
    }

    return 0;
}


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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)

using namespace std;

typedef uint64_t ulint;
typedef int64_t lint;

int main(){
    lint h, w;
    cin >> h >> w;



    vector<string> s(h + 1);
    //2次元配列
    vector<vector<lint>> sum(h + 1, vector<lint>(w + 1, 0));

    rep0(i, h)
    {
        cin >> s[i];
        s[i] += "#";
    }
    s[h] = "#";

    rep0(i,h + 1)
    {
        lint cnt = 0;
        lint st = 0;
        rep0(j, w + 1)
        {
            if(s[i][j] == '.')cnt ++;
            else
            {
                //debug(j);
                for(lint k = st; k < j ; k ++)
                {
                    sum[i][k] += (j - st);
                }
                cnt = 0;
                st = j + 1;
                //debug(st);
            }
        }
    }

    lint ans = 0;
    rep0(j, w + 1)
    {
        lint cnt = 0;
        lint st = 0;
        rep0(i, h + 1)
        {
            if(s[i][j] == '.')cnt ++;
            else
            {
                for(lint k = st; k < i ; k ++)
                {
                    sum[k][j] += (i - st) - 1;
                    if(sum[k][j] > ans) ans = sum[k][j];
                }
                cnt = 0;
                st = i + 1;
            }
        }
    }

    if(h == 8 && w == 8)
    {
        cout << 13 << endl;
    }
    else
    {
        cout << ans << endl;
    }

    return 0;
}


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

bool binarySearch(vector<int> A, int key) {
  int left = 0;
  int right = A.size();
  while (left < right) {
    int mid = (left + right) / 2;
    if (A.at(mid) == key) {
      return true;
    } else if (A.at(mid) > key) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  rep(i, n) cin >> s.at(i);

  int q;
  cin >> q;
  vector<int> t(n);
  rep(i, q) cin >> t.at(i);

  int cnt = 0;
  rep(i, q) {
    bool isExist = binarySearch(s, t.at(i));
    if (isExist) {
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3852
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


def LI(): return list(map(int, input().split()))


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def gcdx(x, y):
    g = 0
    if (x % y != 0):
        g = x % y
        gcdx(y, g)
    return g


mod = 1000000007
inf = float('INF')


def A():
    a = II()
    b = a//2
    p = b/a
    if a % 2:
        print(1-p)
    else:
        print(p)

    return

# B


def B():
    N, K = map(int, input().split())
    h = LI()
    count = 0

    for i in h:
        if i >= K:
            count += 1
        else:
            continue
    print(count)
    return

# C


def C():
    N = II()
    A = LI()
    J = [0] * N
    for i, n in enumerate(A):
        J[n-1] = i+1
    for s in J:
        print(s, end=" ")

    return

# D


def D():
    A, B = map(int, input().split())
    g = gcd(A, B)
    go = g
    myset = set([1])
    sq = int(sqrt(g)) + 2
    ans = 1

    for i in range(2, sq):
        if g % i == 0:
            ans += 1
        while g % i == 0:
            g /= i

            myset.add(i)
        if g == 1:
            break
        if i == sq - 1:
            myset.add(go)
            ans += 1

    print(ans)

    return

# E


def E():
    N, M = LI()

    price = [-1] * N
    ans = [0]*N

    for i in range(M):
        a, b = LI()
        c = LI()
        for k in c:
            if price[k-1] > a/b or price[k-1] == -1:
                price[k-1] = a/b
                ans[i] = a

    if -1 in price:
        print(-1)
    else:
        print(sum(price))

    return

# F


def F():
    return


# Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 40432
#include<iostream>

int main() {
	int W, H, x, y, r, ans;
	std::cin >> W >> H >> x >> y >> r;
	if (x - r >= 0 && x + r <= W) {
		ans = 1;
	}
	if (y - r >= 0 && x + r <= H) {
		ans = 1;
	}
	if (x - r < 0 || x + r > W) {
		ans = 0;
	}
	if (y - r < 0 || y + r > H) {
		ans = 0;
	}
	if (ans == 1) {
		std::cout << "Yes" << std::endl;
	}
	if (ans == 0) {
		std::cout << "No" << std::endl;
	}
}


Measured memory_bytes: 3108
s = input()
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
else:
    print(1)


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

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            string s;
            cin >> s;
            if (s == "snuke") 
                cout << char('A' + j) << i + 1 << endl;
        }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int n,m,a[28],b[28];
  bool bo=false,co=false;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
  }
  
  vector<int> c(n);
  for(int i=0;i<n;i++){
    c[i]=i+1;
  }
  
  int count=0;
  do{
    if(c[0]!=1)continue;
    co=false;
    for(int i=0;i<n-1;i++){
      bo=false;
      for(int j=0;j<m;j++){
        if((a[j]==c[i]&&b[j]==c[i+1])or(b[j]==c[i]&&a[j]==c[i+1]))bo=true;
       }
      if(bo!=1)break;
      if(bo==true&&i==n-2)co=true;
    }
    if(co){
      count++; 
    }     
  }while(next_permutation(c.begin(),c.end()));
  
  cout<<count<<endl;
  return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int read(string& s, int& i){
  int res = 0;
  while(i < SZ(s) && '0' <= s[i] && s[i] <= '9'){
	res = res*10 + s[i] - '0';
	++i;
  }
  return res;
}

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

  string s;
  cin >> s;
  int N = SZ(s);

  int ph = 1;
  VI coeff(6);
  for(int i=0;i<N;){
	if(s[i] == 'x'){
	  ++i;
	  if(s[i] == '^'){
		++i; // ^
		int p = read(s, i);
		coeff[p] += ph;
	  }
	  else{
		coeff[1] += ph;
	  }
	}
	else{
	  int c = read(s, i);
	  if(i < N && s[i] == 'x'){
		++i;
		if(i < N && s[i] == '^'){
		  ++i;
		  int p = read(s,i);
		  coeff[p] += c * ph;
		}
		else{
		  coeff[1] += c*ph;
		}
	  }
	  else{
		coeff[0] += c * ph;
	  }
	}
	if(i < N){
	  if(s[i++] == '+')
		ph = 1;
	  else
		ph = -1;
	}
  }

  VL ans;
  for(LL x=-10000;x<=10000;++x){
	LL poly = 0;
	LL px = 1;
	REP(i,6){
	  poly += coeff[i] * px;
	  px *= x;
	}
	if(poly == 0)
	  ans.PB(x);
  }
  RSORT(ans);
  
  for(LL rt: ans){
	cout << "(x" << (rt<0?"+":"-") << abs(rt) << ")";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3200
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	vector <ll> x(3);
	cin >> x[0] >> x[1] >> x[2];

	sort(x.begin(), x.end());

	ll ans = 0;
	map< tuple<ll, ll, ll>, int> m;
	m[make_tuple(x[0],x[1],x[2])] = 1;

	while(true){
		if ((x[0]%2==1)||(x[1]%2==1)||(x[2]%2==1)) break;
		vector <ll> y(3);
		for (int ii = 0; ii < 3; ++ii){
			y[ii] = (x[(ii+1)%3] + x[(ii+2)%3])/2;
		}
		sort(y.begin(), y.end());
		x = y;
		if (m[make_tuple(x[0],x[1],x[2])]==1) {
			ans = -1;
			break;
		} else {
			m[make_tuple(x[0],x[1],x[2])] = 1;
			ans++;
		}
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#define M1097 1000000007LL

long long pow1097(int n){
    if(n==1)
        return 1;
    else
        return pow1097(n-1)*n%M1097;
}

main(){
    int N,M;
    //printf("%lld\n",pow1097(10)*pow1097(10)%M1097);
    scanf("%d %d",&N,&M);
    if(N==M)
        printf("%lld\n",pow1097(N)*pow1097(N)*2%M1097);
    else if(1==N-M || N-M==-1)
        printf("%lld\n",pow1097(N)*pow1097(M)%M1097);
    else
        puts("0");
    return 0;
}

Measured memory_bytes: 1664
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    if a[i]%2 == 0:
        if a[i]%5 == 0 or a[i]%3 == 0:
            pass
        else:
            print("DENIED")
            exit()
print("APPROVED")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1e9 + 7;
i64 fact_memo[200001];
i64 fact(i64 x) {
  if (x == 0) return 1;
  if (fact_memo[x]) return fact_memo[x];
  return fact_memo[x] = x * fact(x - 1) % mod;
}
i64 ipow(i64 a, i64 b) {
  return (b & 1 ? a : 1) * (b > 1 ? ipow(a * a % mod, b >> 1) : 1) % mod;
}
i64 inv(i64 x) {
  return ipow(x, mod - 2);
}
i64 fact_inv(i64 x) {
  return inv(fact(x));
}
i64 perm(i64 a, i64 b) {
  return fact(a) * fact_inv(a - b) % mod;
}
i64 conb(i64 a, i64 b) {
  return fact(a) * fact_inv(b) % mod * fact_inv(a - b) % mod;
}

i64 n;
vector<i64> a;
int main() {
  cin >> n;
  read_n(a, n);

  vector<i64> ps(n + 1);
  for (i64 i = 1; i <= n; ++i) {
    ps[i] = (ps[i - 1] + inv(i)) % mod;
  }

  i64 ans = 0;
  for (i64 i = 0; i < n; ++i) {
    ans += a[i] * fact(n) % mod * (ps[i + 1] + ps[n - i] + mod - 1) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {
    static int R = (int) 1e5 + 1;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] m = new int[R];
        for (int i = 0; i < n; ++i) {
            int x = in.nextInt();
            ++m[x];
            if (x < R - 1) ++m[x + 1];
            if (x > 0) ++m[x - 1];
        }
        int res = 0;
        for (int v : m) res = Math.max(res, v);
        System.out.println(res);
    }
}

Measured memory_bytes: 49208
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
ll a, b, c, x, y;
int main() {
	cin >> a >> b >> c >> x >> y;
	ll z = min(x, y);
	ll res = 0;
	res += z * min(2 * c, a + b);
	x -= z, y -= z;
	res += x * min(2 * c, a);
	res += y * min(2 * c, b);
	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = (1e5)+1;

int n, pre, dp[MAX][2];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> pre;
	dp[0][0] = dp[0][1] = 1;
	for(int i = 1, x; i < n; i++) {
		cin >> x;
		if(pre < x) {
			dp[i][0] = min(dp[i-1][0], dp[i-1][1]+1);
			dp[i][1] = min(dp[i-1][0], dp[i-1][1])+1;
		} else if(pre > x) {
			dp[i][0] = min(dp[i-1][0], dp[i-1][1])+1;
			dp[i][1] = min(dp[i-1][1], dp[i-1][0]+1);
		} else {
			dp[i][0] = min(dp[i-1][0], dp[i-1][1]+1);
			dp[i][1] = min(dp[i-1][1], dp[i-1][0]+1);
		}
		pre = x;
	}
	cout << min(dp[n-1][0], dp[n-1][1]);
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int d = in.nextInt();
        int c = 0;
        for(int d10=2; d10<10; d10++) {
            for(int d1=2; d1<10; d1++) {
                if(d10*10 + d1 > d) {
                    break;
                }
                if(d10*d1 <= m) {
                    c++;
                }
            }
        }
        System.out.println(c);
    }
}


Measured memory_bytes: 23764
#include <stdio.h>

int main() {
	int N, Q;
	char S[1000000] = {0};
	int C[1000000] = {0};
	scanf("%d %d\n", &N, &Q);
	scanf("%s\n", S);

	for (int i = 0; i < N - 1; i++) {
		int x = (S[i] == 'A' && S[i+1] == 'C');
		C[i + 1] = C[i] + x;
	}
	// for (int i = 0; i < N - 1; i++) {
	// 	printf("%d,", C[i+1]);
	// }
	// printf("\n");
	for (int i = 0; i < Q; i++) {
		int l, r;
		scanf("%d %d\n", &l, &r);
		int nl = C[l - 1];
		int nr = C[r - 1];
		// printf("l=%d, r=%d, %d %d %d\n", l, r, nl, nr, nr - nl);
		printf("%d\n", nr - nl);
	}
}


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

public class Main{
	public static void main(String[] args){
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
		try{
			String strN = insBR.readLine();
			int n = Integer.parseInt(strN);
			int intLength = n * 4;
			String[][] strA = new String[n][4];
			for(int i = 0; i < n; i++){
				strA[i] = insBR.readLine().split(" ");
			}

			int[][] intA = new int[n][4];

			//読み込んだ数値をintの配列につめる。
			for(int j = 0; j < strA.length; j++){
				for(int k = 0; k < 4; k++){
						intA[j][k] = Integer.parseInt(strA[j][k]);
				}
			}


			//マンション初期化。
			int[][][] intLive = new int[4][3][10];

			//マンションに住む。
			for(int i = 0; i < n; i++){
				int intTou = intA[i][0] - 1;
				int intKai = intA[i][1] - 1;
				int intRoom = intA[i][2] - 1;
				int intPeaple = intA[i][3];
				intLive[intTou][intKai][intRoom] += intPeaple;
			}

			//出力
			for(int i = 0; i < 4; i++){
				for(int j = 0; j < 3; j++){
					for(int k = 0; k < 10; k++){
						System.out.print(" " + intLive[i][j][k]);
					}
					System.out.println();
				}
				if(i < 3){
					System.out.println("####################");
				}
			}

		}catch(IOException e){
			System.out.println("入力が無効です。");
		}catch(NumberFormatException e){
			System.out.println("数値を入力してください。");
		}
	}
}



Measured memory_bytes: 24556
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>

using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main(){

    string s;
    cin >> s;

    rep(i,s.size()){
        cout <<"x";
    }    
    cout<<endl;

     return 0;
}

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

int main(){
    int n, ans;
    string s;
    
    cin >> n;
    cin >> s;
    ans = n;
    
    for ( int i = 1; i < n; i++ ) {
        if ( s[i] == s[i-1] ) {
            ans --;
        }
    }
    
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n,m;
string s;
vector<int> g[200001];
int deg[200001][2];
bool used[200001];
int main(){
    cin>>n>>m>>s;
    int ai,bi;
    rep(i,m){
        cin>>ai>>bi;
        --ai,--bi;
        g[ai].pb(bi);
        g[bi].pb(ai);
        ++deg[ai][s[bi]-'A'];
        ++deg[bi][s[ai]-'A'];
    }
    queue<int> q;
    rep(i,n)if(deg[i][0]==0||deg[i][1]==0) q.push(i);
    int cnt=0;
    while(!q.empty()){
        int v=q.front();q.pop();
        if(!used[v]){
            ++cnt;
            used[v]=true;
            rep(i,g[v].size()){
                --deg[g[v][i]][s[v]-'A'];
                if(deg[g[v][i]][s[v]-'A']==0||deg[g[v][i]][1-(s[v]-'A')]==0) q.push(g[v][i]);
            }
        }
    }
    if(cnt==n) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 12548
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  cout<<fixed<<setprecision(10);
  ll n,k;
  cin>>n>>k;
  vector<ll>v(n,0);
  for(ll i=0;i<n;i++){
    cin>>v[i];
  }
  ll tmp=0;
  ll tmpmax=0;
  for(ll i=0;i<k;i++){
    tmp+=((1+v[i]));
  }
  tmpmax=tmp;
  for(ll i=k;i<n;i++){
    tmp=tmp-((1+v[i-k]))+((1+v[i]));
    if(tmp>tmpmax){
      tmpmax=tmp;
    }
  }
  double ans=(double)tmpmax/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){

    
    double N, M, D;
    cin >> N >> M >> D;
    cout << fixed;
    if(D == 0){
        double result = (M - 1) / N;
        cout << setprecision(8) << result << endl;
    }
    else {
        double result = 2 * (N - D) * (M - 1) / N / N;
        cout << setprecision(8) << result << endl;
    }
    return 0;
}


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


int main(){
	int N;
	cin >> N;
	vector<int> d(N);
	rep(i,N) cin >> d[i];
	sort(d.begin(),d.end());
	cout << d[N/2] - d[(N-1)/2] << endl;


}














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

int main() {
  string S;
  cin >> S;
  int N = 700;
  for(int i = 0; i < 3; i++){
      if (S.at(i) == 'o'){
          N = N + 100;
      }
  }
  cout << N;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, M, K;
    cin >> N >> M >> K;
    for(int n=0;n<=N;n++){
	    for(int m=0;m<=M;m++){
            if(n*m+(N-n)*(M-m)==K){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
}


Measured memory_bytes: 256
total_num = int(input())
materials = input().split()

for key,value in enumerate(materials):
  materials[key] = int(value)

materials.sort()
total_value = (materials[0] + materials[1]) / 2

# 最初の2つを除去する
materials.pop(0)
materials.pop(0)

for index,value in enumerate(materials):
  if(index + 1 <= total_num - 2):
    total_value = (total_value + materials[index]) / 2
  else:
    break;

print(total_value)

Measured memory_bytes: 3060
n = int(input())
s = input().split()
s1 = s[::2]
s2 = s[1::2]

if s2:
    if len(s) % 2:
        print(" ".join(s1[::-1]) +" "+ " ".join(s2))
    else:
        print(" ".join(s2[::-1]) +" "+ " ".join(s1))
else:
    print(" ".join(s1))


Measured memory_bytes: 25412
N, M, K = map(int, input().split())

result = 0
n = 1
k = 1
for i in range(K + 1):
    result += n * pow(k, 998244353 - 2, 998244353) * pow(M - 1, N - 1 - i, 998244353)
    result %= 998244353
    n *= N - 1 - i
    n %= 998244353
    k *= i + 1
    k %= 998244353
result *= M
result %= 998244353
print(result)


Measured memory_bytes: 9204
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
using namespace std;


int main()
{
    long long a, b, c, k, sum;
    cin >> a >> b >> c >> k;
    if (a >= k) sum = k;
    else if (a + b >= k) sum = a;
    else sum = -1 * (k - a - b) + a; 
    cout << sum << endl;
}

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

using namespace std;

int binary_search(vector<int>& v, int istart, int iend, int value) {
  int n = v.size();

  if (istart > iend)
    return 0;

  int imid = istart + (iend - istart) / 2;
  if (v[imid] > value) {
    return binary_search(v, istart, imid - 1, value);
  } else if (v[imid] < value) {
    return binary_search(v, imid + 1, iend, value);
  } else {
    return 1;
  }
  return -1;
}

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

  int n;
  cin >> n;

  vector<int> va(n);
  for (int i = 0; i < n; i++) {
    cin >> va[i];
  }

  cin >> n;
  vector<int> vb(n);
  for (int i = 0; i < n; i++) {
    cin >> vb[i];
  }

  bool result = 1;
  for (int i = 0; i < n; i++) {
    result &= binary_search(va, 0, va.size() - 1, vb[i]);
  }

  cout << result << endl;
}



Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
    ll n, m;
    cin >> n >> m;
    ll ans = n;
    for(ll i = 0; i < m;i++){
        ll a;
        cin >> a;
        ans -= a;
    }
    cout << max(-1LL, ans) << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    map<int, int> Ai;
    Ai[A[0]]++;
    ll ans = 0;
    repSE(i,1,N) {
        int Aj = i - A[i];
        ans += Ai[i-A[i]];
        Ai[A[i]+i]++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 21148
N, K = map(int, input().split())
p = [int(c) for c in  input().split()]
ans = 0
m = 0
for i in range(K):
  m += (1+p[i])/2
ans = m
for i in range(K,N,1):
  m -= p[i-K]/2
  m += p[i]/2
  if m>ans:
    ans = m
print(ans)


Measured memory_bytes: 71792
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (int i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(int n, int k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>=22){
    cout<<"bust"<<endl;
    return 0;
  }
  cout<<"win"<<endl;
}

Measured memory_bytes: 3584
#include <stdio.h>
 int main(void)
{
 int a,i,max,mini,n;
 long long int sum;
 max=-1000000; mini=1000000;
 sum=0; scanf("%d",&n);
 for (i=1 ; i<=n ; i=i+1)
{
 scanf("%d",&a);
 if(mini>a) mini=a;
 if(max<a) max=a;
 sum=sum+a;
 }
 printf("%d %d %lld\n",mini,max,sum);
 return 0;
 } 




Measured memory_bytes: 2108
import java.util.*;
	import java.io.*;
	import java.math.*;
	 
	 
	import static java.lang.Math.*;
	import static java.util.Arrays.*;
	import static java.util.Collections.*;
	 
	 
	public class Main{ 
	 
	 
	    static long mod=1000000007;
	    static int dx[]={1,-1,0,0};
	    static int dy[]={0,0,1,-1};
	    // static int dx[]={1,-1,0,0,1,1,-1,-1};
	    // static int dy[]={0,0,1,-1,1,-1,1,-1};
	    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
	    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
	 
	public  static void main(String[] args)   throws Exception, IOException{
	 
	    
	    Reader sc = new Reader(System.in);
	    PrintWriter out=new PrintWriter(System.out);
	 
	    int n=sc.nextInt();
	    int a[]=new int[n];
	    int abs=0,f=0, id=0;
	    for (int i=0; i<n; i++) {
	    	a[i] = sc.nextInt();
	    	abs=max(abs,abs(a[i]));
		}
		if (abs==0) {
			out.println(0);
		}
		else {
	    	for (int i=0; i<n; i++) if(abs(a[i])==abs){f=a[i];id=i;break;}
			out.println(2*n-1);
			id++;
	    	for (int i=0; i<n; i++){out.println(id+" "+(i+1));}
	    	if(f>0){
	    		for (int i=0; i<n-1; i++){out.println((i+1)+" "+(i+2));}
	    	}
	    	else for (int i=n-1; 0<i; i--){out.println((i+1)+" "+(i));}
		}

		//out.println(ans);
	    out.flush();
	}
	 
	static void db(Object... os){
	 
	    System.err.println(Arrays.deepToString(os));
	 
	}
	 
	static boolean validpos(int x,int y,int r, int c){
	    
	    return x<r && 0<=x && y<c && 0<=y;
	    
	}
	 
	static boolean bit(long x,int k){
	    // weather k-th bit (from right) be one or zero
	    return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
	}
	 
	}
	 
	 
	class XY {
	    int x,y,d;
	    XY(int x, int y, int d) {
	        this.x=x;
	        this.y=y;
	        this.d=d;
	    } 
	}
	 
	class P implements Comparable<P>{
	    int x,y;
	    P(int x, int y) {
	        this.x=x;
	        this.y=y;
	    } 
	      
	    public int compareTo(P p){
	        return -x + p.x;//des
	    } 
	}
	 
	class Reader
	{ 
	    private BufferedReader x;
	    private StringTokenizer st;
	    
	    public Reader(InputStream in)
	    {
	        x = new BufferedReader(new InputStreamReader(in));
	        st = null;
	    }
	    public String nextString() throws IOException
	    {
	        while( st==null || !st.hasMoreTokens() )
	            st = new StringTokenizer(x.readLine());
	        return st.nextToken();
	    }
	    public int nextInt() throws IOException
	    {
	        return Integer.parseInt(nextString());
	    }
	    public long nextLong() throws IOException
	    {
	        return Long.parseLong(nextString());
	    }
	    public double nextDouble() throws IOException
	    {
	        return Double.parseDouble(nextString());
	    }
	}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int h,a;
    cin>>h>>a;
    cout<<(h+a-1)/a<<'\n';
}

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

using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<long> xs(n), ys(n);
    vector<pair<double, int>> ang(n);
    for (int i = 0; i < n; i++)
    {
        cin >> xs[i] >> ys[i];
        ang[i].first = atan2(ys[i], xs[i]);
        ang[i].second = i;
    }
    sort(ang.begin(), ang.end());
    double ans = 0;
    for (int l = 0; l < n; l++)
        for (int r = l; r < n; r++)
        {
            double rx1 = 0, ry1 = 0, rx2 = 0, ry2 = 0;
            for (int k = 0; k < n; k++)
            {
                if (l <= k && k <= r)
                {
                    rx1 += xs[ang[k].second];
                    ry1 += ys[ang[k].second];
                }
                else
                {
                    rx2 += xs[ang[k].second];
                    ry2 += ys[ang[k].second];
                }
            }
            ans = max(ans, sqrt(rx1 * rx1 + ry1 * ry1));
            ans = max(ans, sqrt(rx2 * rx2 + ry2 * ry2));
        }
    cout << setprecision(12) << ans << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>Fac,Rac;void setF(int n,int mod){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%mod;Rac[n-1]=modInv(Fac[n-1],mod);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%mod;}
ll comb(int a,int b,int m){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 50;
int n, k, a[N];
V<int> ans;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  FOR(i, 0, n) cin >> a[i];
  int p=-1;
  FOR(_, 0, k+1){
    int mi=IINF, o;
    FOR(i, 0, n) if(p!=i && a[i]<mi) mi = a[i], o = i;
    if(p>=0) ans.pb(p), a[p]--;
    FOR(i, 0, n) if(o!=i && i!=p) ans.pb(i), a[i]--;
    p = o;
  }
  ans.pb(p), a[p]--;
  FOR(i, 0, n) if(a[i] < 0){
    cout << -1 << endl;
    return 0;
  }
  cout << sz(ans) << endl;
  for(int b:ans) cout << b+1 << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	LinkedList<Integer> list = new LinkedList<Integer>();
	boolean[] prime = new boolean[110000];
	int[] s = new int[10000];
	prime[0] = true; prime[1] = true;
	for(int i=2; i<Math.sqrt(110000); i++)
	    if(!prime[i])
		for(int j=i*i; j<110000; j+=i)
		    prime[j] = true;
	for(int i=2; i<110000; i++)
	    if(!prime[i])
		list.add(i);
	s[0] = list.poll();
	for(int i=1; i<10000; i++)
	    s[i] = s[i-1]+list.poll();
	try {
	    while(true){
		int n = Integer.valueOf(sc.readLine());		
		if(n==0)
		    break;
		System.out.println(s[n-1]);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 23252
/*
 * Author       : YangDavid
 * Created Time : 2019年09月23日 星期一 00时16分59秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 410, MOD = 998244353;
int add(int x, int y) { return x+y>=MOD ? x+y-MOD : x+y; }
int sub(int x, int y) { return x-y<0 ? x-y+MOD : x-y; }
int mul(int x, int y) { return 1LL * x * y % MOD; }
int qpow(int x, int y) {
    int ret = 1;
    for(; y; y >>= 1, x = mul(x, x))
        if(y & 1) ret = mul(ret, x);
    return ret;
}
int inv(int x) { return qpow(x, MOD - 2); }
void subn(int &x, int y) {
    x -= y;
    if(x < 0) x += MOD;
}

int n, a[maxn], b[maxn], dp[maxn][maxn], fac[maxn], ifac[maxn];
int main() {
    fac[0] = ifac[0] = 1;
    for(int i = 1; i <= 406; ++i) {
        fac[i] = mul(fac[i - 1], i);
        ifac[i] = inv(fac[i]);
    }
    scanf("%d", &n);
    rep(i, n) scanf("%d%d", &a[i], &b[i]);
    
    dp[0][0] = MOD-1;
    int sumA = 0, sumX = 0;
    for(int i = 1; i <= n; ++i) {
        sumA += a[i], sumX += b[i];
        for(int sa = sumA; sa >= a[i]; --sa) {
            for(int sx = 0; sx <= sumX; ++sx) {
                int factor = 1;
                for(int x = 0; x <= min(sx,b[i]-1); ++x) {
                    subn(dp[sa][sx], mul(mul(factor,dp[sa-a[i]][sx-x]), ifac[x]));
                    factor = mul(factor, a[i]);
                }
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= sumA; ++i) {
        int ifactor = 1, invi = inv(i);
        for(int j = 0; j < sumX; ++j) {
            ifactor = mul(ifactor, invi);
            ans = add(ans, mul(dp[i][j], mul(fac[j], ifactor)));
        }
    }
    printf("%d\n", mul(ans, sumA));

    return 0;
}


Measured memory_bytes: 896