akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end() 
ll mod_pow(ll x,ll n,ll mod) {
ll res=1;
  while(n>0) {
     if(n&1) {
       res=res*x%mod;
     }
     x=x*x%mod;
     n>>=1;
   }
   return res;
}
int main() {
  ll mod=1000000007;
  ll n,a,b;
  cin>>n>>a>>b;
  ll A=1;
  ll B=1;
  for(ll i=0;i<a;i++) {
    A*=(n-i);
    A%=mod;
  }
  for(ll i=0;i<b;i++) {
    B*=(n-i);
    B%=mod;
  }
  for(ll i=2;i<=a;i++) {
    A*=mod_pow(i,mod-2,mod);
    A%=mod;
  }
  for(ll i=2;i<=b;i++) {
    B*=mod_pow(i,mod-2,mod);
    B%=mod;
  }
  ll ans=mod_pow(2,n,mod);
  ans--;
  ans-=(A+B);
  if(ans<0) {
    while(ans<0) {
      ans+=mod;
    }
  } 
  cout<<ans<<endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }



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

  ll x, n;
  cin >> x >> n;

  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];

  ll left = x, right = x;
  while(1){
    if(count(all(a), left) == 0){
      cout << left << endl;
      return 0;
    }else if(count(all(a), right) == 0){
      cout << right << endl;
      return 0;
    }
    left--, right++;
  }
  return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n,m;
    cin >> n >> m;
    int L = 1,R = n;
    rep(i,m){
        int l,r;
        cin >> l >> r;
        if(R < l || r < L){
            cout << 0 << endl;
            return 0;
        }
        if(L <= l && r <= R){
            L = l;
            R = r;
        }
        if(L <= l && R <= r){
            L = l;
        }
        if(l <= L && r <= R){
            R = r;
        }
    }
    cout << R - L + 1 << endl;

    

    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc127.contest.atcoder.jp/tasks/abc127_a

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * https://abc048.contest.atcoder.jp/tasks/abc048_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		sc.close();
		
		System.out.println(""+s1.charAt(0)+s2.charAt(0)+s3.charAt(0));

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int N;
      	cin>>N;
      	int count = 0;
      	int ans = 0;
      	int prev;
      	cin>>prev;
      	for(int i = 0; i < N-1; i++){
        	int temp;
          	cin>>temp;
          	if(temp <= prev){
            	count +=1;
              	if(count > ans)ans = count;
              	prev = temp;
            }
          	else{
            	count = 0;
              	prev = temp;
            }
        }
        cout<<ans<<"\n";
    	return 0;
    }

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 
#define PI 3.14159265359

void solve(){
    cout << fixed;
    cout << setprecision(10);
    double r;
    cin >> r;
    double circum = 2 * PI * r ;
    double area = PI * (r * r);
    cout << area << " " << circum << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3288
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

def out(N, table):
    r = 0
    for i in table:
        a = i
        b = N / i
        if r > (a-1)+(b-1) or r == 0:
            r = (a-1)+(b-1)
    return int(r)


N = int(input())
table = divisor(N)
r = out(N, table)
print(r)

Measured memory_bytes: 3924
#include <iostream>
#include <string>
#define FOR(i,k,n) for (int (i)=(k);(i)<(n);(i)++)
using namespace std;

// 各アルファベット a-z の出現回数
int alph[26];

void update_alph()
{
  int alph2[26] = {};
  string S;
  int x;
  cin >> S;

  FOR(i, 0, S.size()) {
    // TODO: 予期しない文字の場合、配列からはみ出る
    x = S[i] - 'a';
    alph2[x] += 1;
  }

  // alph を更新
  FOR(i,0,26) {
    if (alph2[i] < alph[i]) alph[i] = alph2[i];
  }
}

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

  // 初期値を大きめに
  FOR(i,0,26) alph[i] = 100;

  // i 番目の文字列 S_i
  FOR(i,0,n) update_alph();

  // 文字列をつくる
  string newS = "";
  char c;
  FOR(i,0,26) {
    c = 'a' + i;
    newS += string(alph[i], c);
  }

  cout << newS << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Describe
"""

import numpy as np

STR_TLE = 'TLE'

def get_min_cost(costs_, times_, max_time):
    """Get the minimum cost for required maximum time allowed.
    """

    costs = np.array(costs_)
    times = np.array(times_)
    filt = np.less_equal(times, max_time)
    costs = costs[filt]
    if len(costs) == 0:
        return STR_TLE
    else:
        return str(min(costs))

def main():
    n, t = map(int, input().split())
    costs, times = [], []
    for i in range(n):
        c_, t_ = map(int, input().split())
        costs.append(c_)
        times.append(t_)
    print(get_min_cost(costs, times, t))
        

main()


Measured memory_bytes: 13124
#!/usr/bin/env python3
import sys, os
range = xrange

def main():
    inp = [int(x) for x in os.read(0, os.fstat(0).st_size).split()]
    n, m = inp[0],inp[1]
 
    wi, vi = inp[2], inp[3]
 
 
    dp = [0] * (m + 1)
    for j in range(wi, m + 1):
        dp[j] = vi
 
    for i in range(n - 1):
        wi = inp[2*i + 4]
        vi = inp[2*i + 5]
        for j in range(m, wi-1, -1):
            x = vi + dp[j - wi]
            if dp[j] < x:
                dp[j] = x
 
    print(dp[-1])
main()


Measured memory_bytes: 5764
N = int(input())
A = list(map(int,input().split()))
B =  [[0, int(x)] for x in input().split()]

import copy
cnt=0
BB = copy.deepcopy(B) + ([[0,0],[0,0]])
for i, ai in enumerate(A):
    if sum(BB[i]) > ai:
        cnt += ai
        if BB[i][0] > ai:
            BB[i+1][0] += BB[i][1]
        else:
            BB[i+1][0] += sum(BB[i]) - ai
    else:       
        cnt += sum(BB[i])

print(cnt)

Measured memory_bytes: 45452
#include<cstdio>
#include<complex>
#include<cmath>
#include<utility>
#include<algorithm>

using namespace std;

typedef double Real;

const Real eps=1e-9;
const Real PI=acos(-1.0);

typedef pair<Real,Real> P;
typedef complex<Real> Point;
typedef complex<Real> Vector;
typedef pair<Point,Point> Segment;

template<class T> bool eq(T a,T b){
	return abs(a-b)<eps;
}

template<class T> int sgn(T a){
	if(eq(a,0.0)) return 0;
	if(a>0) return 1;
	return -1;
}

Real doP(Vector a,Vector b){
	return (conj(a)*b).real();
}

Real arg(Vector v){
	return atan2(v.imag(),v.real());
}

Real getAng(Segment s1,Segment s2){
	//directed segments, res<=PI
	Vector v1=s1.second-s1.first;
	Vector v2=s2.second-s2.first;
	Vector v=v2/v1;
	Real ang=arg(v);
	ang=abs(ang);
	if(ang>PI) ang=PI*2-ang;
//	printf("ang=%f\n",ang);
	return ang;
}

P getCircle(Segment s1,Segment s2){
	Real theta=getAng(s1,s2);
	Real d=abs(s1.second-s2.first);
	Real radius=1.0/sin(theta/2)*d/2;
//	printf("d=%f,radius=%f\n",d,radius);
	Point p=s1.first,q=s1.second,r=s2.first;
	Real x=doP(p-q,r-q);
	if(sgn(x)>0){
		theta=PI*2-theta;
	}
	return P(radius,theta);
}

Segment segs[40400];

Real ls[40400],Mv[40400];
Real rs[40400],angs[40400];
int N;

Real Ma;

void input(){
	scanf("%d%lf",&N,&Ma);
	for(int i=0;i<N;i++){
		double x1,y1,x2,y2;
		scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
		Point p1=Point(x1,y1);
		Point p2=Point(x2,y2);
		segs[i]=Segment(p1,p2);
	}
}

P solveLine(Real v0,Real x,Real Mlast){
//	printf("solve %f %f %f\n",v0,x,Mlast);
	Real lb=0,ub=x;
	P res;
	bool ok=false;
	for(int stage=0;stage<100;stage++){
		Real mid=(ub+lb)/2;
		Real m=sqrt(v0*v0+2.0*Ma*mid);
		Real t=(m-v0)/Ma;
		Real u2=m*m-2.0*Ma*(x-mid);
		if(u2<-eps){
			lb=mid;
			continue;
		}
		u2=max(u2,0.0);
		Real u=sqrt(u2);
		Real t2=(m-u)/Ma;
		if(sgn(Mlast-u)>=0){
			res=P(u,t+t2);
			lb=mid;
			ok=true;
		}else{
			ub=mid;
		}
	}
	if(ok==false){
		Real t=(v0-Mlast)/Ma;
		return P(Mlast,t);
	}
	return res;
}

Real solve(){
	for(int i=0;i<N-1;i++){
		P p=getCircle(segs[i],segs[i+1]);
		rs[i]=p.first;
		angs[i]=p.second;
		Mv[i]=sqrt(Ma*rs[i]);
//		printf("r=%f,ang=%f,mv=%f\n",rs[i],angs[i],Mv[i]);
	}
	for(int i=0;i<N;i++){
		ls[i]=abs(segs[i].second-segs[i].first);
	}
	Mv[N-1]=0;
	for(int i=N-1;i>=1;i--){
		Real val=2.0*Ma*ls[i];
		Real v0=Mv[i]*Mv[i]+val;
		v0=sqrt(v0);
		Mv[i-1]=min(Mv[i-1],v0);
	}
	Real t=0;
	Real prevv=0;
	for(int i=0;i<N;i++){
		P p=solveLine(prevv,ls[i],Mv[i]);
		t+=p.second;
		prevv=p.first;
		if(isinf(t)){
			printf("%f %f %f\n",prevv,ls[i],Mv[i]);
		}
//		printf("t+=%f\n",p.second);
		if(i!=N-1){
			Real len=angs[i]*rs[i];
//			printf("ang=%f,r=%f,v=%f\n",angs[i],rs[i],prevv);
			Real t2=len/prevv;
			t+=t2;
			if(isinf(t)){
				printf("ang=%f,r=%f,v=%f Mv=%f\n",angs[i],rs[i],prevv,Mv[i]);
				return 0;
			}
		}
	}
	return t;
}

int main(){
	input();
	Real ans=solve();
	printf("%.9f\n",ans);
	return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
 
 
int main() {
	
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	
	int sum = a*x + b*y;
	for(int i=0; i<=2*max(x,y); i+=2){
		sum = min( i*c + max(0, a*(x-i/2)) + max(0, b*(y-i/2)) , sum);
	}
	cout << sum <<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

total = 0
for i in range(N):
	ni0 = min(A[i],B[i])
	ni1 = min(A[i+1],B[i]-ni0)
	A[i] -= ni0
	A[i+1] -= ni1
	total += ni0+ni1

print(total)


Measured memory_bytes: 82020
#include<stdio.h>
#define NIL -1
int parent[100001],cleft[100001],right[100001];
int depth(int i){
    int d=0;
    while(parent[i]!=NIL){
        d++;
        i=parent[i];
    }
    return d;
}
void printchildren(int i){
    int c=cleft[i];
    while(c!=NIL && right[c]!=NIL){
        printf("%d, ",c);
        c=right[c];
    }
    if(cleft[i]!=NIL)printf("%d",c);
}
 
int main(){
    int n;scanf("%d",&n);
    int i;
    for(i=0;i<=n-1;i++)parent[i]=cleft[i]=right[i]=NIL;
    for(i=0;i<=n-1;i++){
        int id,k;
        scanf("%d %d",&id,&k);
        int c[k+1],j;
        for(j=1;j<=k;j++)scanf("%d",&c[j]);
        if(k>=1){
            parent[c[1]]=id;
            cleft[id]=c[1];
        }
        for(j=2;j<=k;j++){
            parent[c[j]]=id;
            right[c[j-1]]=c[j];
        }
    }
     
     
    for(i=0;i<=n-1;i++){
        printf("node %d: parent = %d, depth = %d, ",i,parent[i],depth(i));
        if(parent[i]==NIL) printf("root, [");
        else if(cleft[i]==NIL) printf("leaf, [");
        else printf("internal node, [");
        printchildren(i);
        printf("]\n");
         
    }
     
    return 0;
}


Measured memory_bytes: 3348
// Selection Sort
#include <stdio.h>

int SelectionSort(int*, int);

int main(){
int i, n, A[100], count;
  scanf("%d", &n);
  for(i=0; i < n; i++){
    scanf("%d", &A[i]);
  }
  count = SelectionSort(A, n); // 選択ソートを実行
  // 配列の内容とカウント回数を表示 //
  for(i=0; i < n; i++){
    if(i != 0)printf(" ");
    printf("%d", A[i]);
  }
  printf("\n%d\n",count);
  return 0;
}

int SelectionSort(int *A, int n){
  int i, j, minj, count=0, str;
  for(i=0; i < n; i++){
    minj = i;
    for(j=i; j < n; j++){
      if(A[j] < A[minj])minj = j;
    }
    str = A[i];
    A[i] =A[minj];
    A[minj] = str;
    if(i != minj)count++;
  }
  return count;
}



Measured memory_bytes: 2064
//*** cfmasterr ***//
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
	long long a, b;
	cin >> a >> b;
	long long lcm = a * b / __gcd(a, b);
	cout << lcm << '\n';
  return 0;
}




Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    D = int(readline())
    C = [int(i) for i in readline().split()]
    S = [[int(i) for i in readline().split()] for _ in range(D)]
    ans = []

    last = [0] * 26
    score = 0
    for i in range(D):
        kouho = []
        for t in range(26):
            tmp = score
            tmp += S[i][t]
            last_t = last[t]
            last[t] = i+1
            for j, c in enumerate(C):
                tmp -= c * (i+1 - last[j])
            kouho.append((tmp, t))
            last[t] = last_t

        score, ind = max(kouho)
        ans.append(ind + 1)
        last[ind] = i + 1
    
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9516
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#define rep(i,n) for (int i=0; i< (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n-1);
  rep(i,n-1){cin >> b[i];}
  
  a[0] = b[0];
  a[n-1] = b[n-2];
  rep(i,n-2){
    a[i+1] = min(b[i],b[i+1]);
  }
  int ans = accumulate(a.begin(), a.end(), 0);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=1e5+5;
int n,K,fa[maxn],dep[maxn],k,hd[maxn],mx[maxn];
ll ans=0;
struct edd{
	int nt,v;
}e[maxn*2];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline void add(int a,int b){
	e[k].v=b; e[k].nt=hd[a]; hd[a]=k++;
}

void dfs(int x,int f){
	dep[x]=dep[f]+1; mx[x]=dep[x];
	for(rg int i=hd[x];i!=-1;i=e[i].nt){
		int v=e[i].v;
		dfs(v,x);
		mx[x]=max(mx[x],mx[v]);
	}
	if(fa[x] != 1 && mx[x]-dep[x] == K-1) mx[x]=0,ans++;
}

int main(){
	memset(hd,-1,sizeof(hd)); k=0;
	n=rd(); K=rd();
	go(i,n+1,1)	fa[i]=rd();
	if(fa[1] != 1) ans++,fa[1]=1;
	go(i,n+1,2)	add(fa[i],i);
	dep[0]=-1; dfs(1,0);
	printf("%lld",ans);
	return 0;
}//Faze


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    ll n,m;cin>>n;
    cout << n*(n-1)/2 << endl;
    return 0;
}


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

int cmp(const void *a,const void *b)
{
  return *(int*)a-*(int*)b;
}

int main()
{
  int n,x;
  
  scanf("%d%d",&n,&x);
  
  int m[n];
  int i;
  int sum=0;
  int count=n;
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&m[i]);
    sum+=m[i];
  }
  
  x-=sum;
  
  qsort(m,n,sizeof(int),cmp);
  
  count+=x/m[0];
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>

char s[55],t[55],ans[55],tmp[55],tt[55];

int main()
{
	scanf("%s",s);
	scanf("%s",t);

	for (int i = 0; i<strlen(s); i++)
	{
		tt[i] = s[i];
		if (tt[i]=='?')
			tt[i] = 'a';
	}
	tt[strlen(s)] = '\0';

	for (int i = 0; i<strlen(s); i++)
	{
		ans[i] = s[i];
		if (ans[i]=='?')
			ans[i] = 'z';
	}
	ans[strlen(s)] = '\0';

	bool flag = false;
	for (int i = 0; i<strlen(s)-strlen(t)+1; i++)
	{
		bool b = true;
		for (int j = 0; j<strlen(t); j++)
			if (s[i+j]!=t[j] && s[i+j]!='?')
				b = false;
		if (b)
		{
			flag = true;

			for (int i = 0; i<strlen(tt); i++)
				tmp[i] = tt[i];
			for (int j = 0; j<strlen(t); j++)
				tmp[i+j] = t[j];

			//printf("!%s %s\n",tmp,ans);

			if (strcmp(tmp,ans)<0)
				for (int i = 0; i<strlen(ans); i++)
					ans[i] = tmp[i];
		}
	}	

	if (flag)
		printf("%s\n",ans);
	else printf("UNRESTORABLE\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
	int n;

	cin >> n;

	vector<int> rabbits(n);

	rep(i, n) {
		cin >> rabbits[i];
		rabbits[i]--;
	}

	int ans = 0;

	rep(i, n) {
		if (rabbits[rabbits[i]] == i) {
			ans++;
		}
	}

	cout << ans / 2 << endl;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;
int num[200005];
int main()
{
	int n,m,a,b,flag;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(num,0,sizeof(num));
		flag=0;
		for(int i=0;i<m;i++)
		{
			scanf("%d%d",&a,&b);
			if(a==1)
			{
				num[b]++;
				if(num[b]==2)
				flag=1;
			}
			if(b==n)
			{
				num[a]++;
				if(num[a]==2)
				flag=1;
			}
			
		}
		if(flag)cout<<"POSSIBLE"<<endl;
		else cout<<"IMPOSSIBLE"<<endl; 
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}
 
typedef pair<ll,ll> Pair;
const ll inf =1000000007;

int main(){
    ll x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: usize, m: usize,
        xy: [(usize1, usize1); m]
    }

    let mut g = vec![vec![];n];
    for i in 0..m {
        let (x, y) = xy[i];
        g[x].push(y);
    }
    let mut dp = vec![None;n];
    let mut ret = 0u64;
    for i in 0..n {
        ret = std::cmp::max(ret, rec(&mut dp, &g, None, i));
    }
    println!("{}", ret);
}

fn rec(dp: &mut [Option<u64>], g: &[Vec<usize>], p: Option<usize>, c: usize) -> u64 {
    if let Some(src) = dp[c] {
        return src;
    }

    let mut ret = 0u64;
    for &v in &g[c] {
        if p.map(|src| src == v).unwrap_or(false) {
            continue;
        }

        ret = std::cmp::max(ret, rec(dp,g,Some(c),v) + 1);
    }
    dp[c] = Some(ret);
    ret
}

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

int main() {
    int a,b;
    scanf("%d %d",&a,&b);
    string s;
    if ((a * b) % 2 == 0) {
        s = "Even";
    } else {
        s = "Odd";
    }
    cout << s << "\n";
}

Measured memory_bytes: 256
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

N,x=mint()
A=lint()
ans=max(0,A[0]+A[1]-x)
A[1]-=min(A[1],ans)
for i in range(2,N):
    tmp=max(0,A[i-1]+A[i]-x)
    A[i]-=min(A[i],tmp)
    ans+=tmp
print(ans)

Measured memory_bytes: 89912
#include<iostream>
#include<cmath>
#include<stdio.h>

double getHypotenuse( double a , double b )
{
	return sqrt( pow( (double)a , 2 ) + pow( (double)b , 2 ) );
}

int main(void)
{
	int x, h;

	while(1){
		std::cin >> x >> h;
		if( x == 0 && h == 0 ){
			break;
		}
		printf( "%5.9f\n",(double)x * (double)x + 2.0 * x * getHypotenuse( (double)x/2.0 , (double)h ) );
	}

	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = 998244353;


signed main() {
    int n;
    cin >> n;
    vector<int> d(n, 0);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        d[x]++;
        if ((i == 0 && x != 0) || (i != 0 && x == 0)) {
                cout << 0 << "\n";
                return 0;
        }
    }
    int ans = 1;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < d[i]; j++) {
            ans = ans * d[i - 1] % MOD;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int a[3010];
int b[3010];
int n;
int max = n;
int sum = 0;
int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		sum += a[i];
	}
	cout << sum - n;
}

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

using namespace std;

long long z[0x3f3f3f];
long long n,k,m,s=0;
int main(){
cin>>n>>k;
for(int i=0;i<n;i++){cin>>m;z[i]=m;}
sort(z,z+n);
reverse(z,z+n);
for(int i=0;i<k;i++){z[i]=0;
}
for(int i=0;i<n;i++){s+=z[i];
}
cout<<s;
return 0;
} 

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

int main(){
	int n, card1, card2, p1, p2;
	while(cin >> n, n != 0){
		p1 = 0;
		p2 = 0;
		for(int i = 0; i < n; i++){
			cin >> card1 >> card2;
			if(card1 < card2){
				p2 += card1+card2;
			}
			else if(card1 > card2){
				p1 += card1+card2;
			}
			else if(card1 == card2){
				p1 += card1;
				p2 += card2;
			}
		}
		
		cout << p1 << ' ' << p2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(){
    int len = 3;
    char str[20];
    char res[20];
    scanf("%s", str);

    for (int i = 0; (str[i] != '\0') && i < 3; i++) {
        res[i] = str[i];
        res[i + 1] = '\0';
    }
    printf("%s", res);
}



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


int main(){
  string date;
  cin >> date;
  string y, m, d;
  for (int i = 0; i < 4; i++) y = date.substr(0, 4);
  for (int i = 0; i < 2; i++) m = date.substr(5, 2);
  for (int i = 0; i < 2; i++) d = date.substr(8, 2);

  int y_ = atoi(y.c_str());
  int m_ = atoi(m.c_str());
  int d_ = atoi(d.c_str());

  if (y_ <= 2019 && m_ <= 4 && d_ <= 30) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int h, w, n;
int c[100][100], cx, cy;

int main() {
    cin >> h >> w >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        while (a--) {
            c[cx][cy] = i + 1;
            cy += cx % 2 == 0 ? 1 : -1;
            if (cy == w || cy == -1) {
                cx++;
                cy = cx % 2 == 0 ? 0 : w - 1;
            }
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) cout << c[i][j] << " ";
        cout << "\n";
    }
}


Measured memory_bytes: 384
a = []
n = int(input())
for i in range(n):
    a.append(input().split())
s = 0.0
for i in range(n):
    if (a[i][1])=="BTC":
        s += float(a[i][0]) * 380000.0
    else:
        s += float(a[i][0])
print(s)

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

using namespace std;

int n;
string s[50];

int t[50][26];
int ans[26];

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> s[i];

	for(int i = 0; i < n; ++i){
		for(int j = 0; j < s[i].size(); ++j){
			t[i][s[i][j]-'a']++;
		}
	}
	
	for(int j = 0; j < 26; ++j){
		int res = 100000000;
		for(int i = 0; i < n; ++i){
			res = min(res, t[i][j]);
		}
		ans[j] = res;
	}
	
	for(int i = 0; i < 26; ++i){
		for(int j = 0; j < ans[i]; ++j) cout << (char)('a'+i);
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n, m; cin >> n >> m;
    rep(i, m) {
        int c; cin >> c;
        n -= c;
    }
    if(n < 0) {
        print(-1);
    } else{
        print(n);
    }

    return 0;
}



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

using namespace std;
//typedef long long ll;
typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;


int main() {
    char c;
    cin >> c;
    c++;
    cout << c << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

//組み合わせの数nCrを計算
ll calc_num_of_combination(ll n, ll r){
  ll num = 1;
  for(ll i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

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

  int n, p;
  cin >> n >> p;
  ll n_odd = 0;
  ll n_even = 0;
  rep(i, n) {
    ll tmp;
    cin >> tmp;
    if (tmp % 2 == 0) n_even++;
    else n_odd++;
  }

  ll ans = 0;
  ll e = 1LL << n_even;
  if (p == 0) {
    for (ll i = 0; i <= n_odd; i += 2) {
      ans += e * calc_num_of_combination(n_odd, i);
    }
  } else {
    for (ll i = 1; i <= n_odd; i+= 2) {
      ans += e * calc_num_of_combination(n_odd, i);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,fix[200005],fix1[200005],ans;
long long A[200005];
long long B[200005],maxx;
string s;
int main() {
           cin>>n;
           for(long long i=1;i<=n;i++) {
                      cin>>A[i];
                      fix[A[i]]++;
           }
           for(long long i=1;i<=n;i++) {
                      if(fix1[A[i]]==0) {
                                 ans+=(fix[A[i]]*(fix[A[i]]-1))/2;
                                 fix1[A[i]]=1;
                      }
           }
           for(long long i=1;i<=n;i++) {
                      ans-=(fix[A[i]]*(fix[A[i]]-1))/2;
                      fix[A[i]]--;
                      ans+=(fix[A[i]]*(fix[A[i]]-1))/2;
                      cout<<ans<<endl;
                      ans-=(fix[A[i]]*(fix[A[i]]-1))/2;
                      fix[A[i]]++;
                      ans+=(fix[A[i]]*(fix[A[i]]-1))/2;
           }
}

Measured memory_bytes: 7296
def solve():
    from collections import deque
    from sys import stdin
    f_i = stdin
    
    n, q = map(int, f_i.readline().split())
    
    L = [deque() for i in range(n)]
    ans = []
    for op in (line.split() for line in f_i):
        op_type = op[0]
        if op_type == '0':
            L[int(op[1])].append(op[2])
        elif op_type == '1':
            ans.append(' '.join(L[int(op[1])]))
        else:
            s = int(op[1])
            ls = L[s]
            t = int(op[2])
            lt = L[t]
            if lt:
                if len(ls) == 1:
                    lt.append(ls[0])
                elif len(lt) == 1:
                    ls.appendleft(lt[0])
                    L[t] = ls
                elif ls:
                    lt.extend(ls)
            else:
                L[t] = ls
            L[s] = deque()
    print('\n'.join(ans))

solve()


Measured memory_bytes: 63732
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
  int n = s.size();
  int ans1 = 0;
  int ans2 = 0;
  // 取り除けないとき abab...aba(偶数長) or abababa...bab(奇数長)
  // のようになる(a,bは任意の文字)
  // 最初と最後は取り除けないのがポイント
  // 最初と最後が異なる文字なら abab のように偶数長
  // 最初と最後が同じ文字なら aba のように奇数長
  if(s[0]==s[n-1]) ans1 = 1;
  if(n%2) ans2 = 1;
  if(ans1^ans2) cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}


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

// ----------- define --------------
#define int long long
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void MAIN() {
  int x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  int t = min(x / d, k);
  k -= t;
  x -= t * d;
  int ans = x;
  if (k % 2) ans = abs(x - d);
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3620
n,k = map(int,input().split())

ans = 0

for i in range(1,n+1):
    count = 0
    a = i
    while 1:
        if a >= k:
            break
        a = a*2
        count += 1
  #  print(count)
    ans += (1/n) * (1/2)**count
print(ans)

Measured memory_bytes: 39408
#include<bits/stdc++.h>
using namespace std;
int n,x,a[10001],ans;
int main()
{
	cin>>n>>x;
	for (int i=1;i<=n;++i) cin>>a[i];
	sort(a+1,a+n+1);
	for (int i=1;i<=n;++i) if(x>=a[i]){if(i==n){if(x==a[i])ans++;break;}x-=a[i],ans++;}cout<<ans<<endl;
}

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

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long


LL mini=10000000,maxi=-10000000;
int minind,maxind,init,term;

LL a[50];
int x[100];
int y[100];

int main(){
  int n;
  cin>>n;
  REP(i,n)
    cin>>a[i];
  
  REP(i,n){
    if(mini>a[i]){
      mini=a[i];
      minind=i;
    }
    if(maxi<a[i]){
      maxi=a[i];
      maxind=i;
    }
  }

  int m=0;
  if(abs(maxi)>=abs(mini)){
    REP(i,n){
      x[m]=maxind+1;
      y[m]=i+1;
      m++;
    }
    REP(i,n-1){
      x[m]=i+1;
      y[m]=i+2;
      m++;
    }
    
    cout<<m<<endl;
    REP(i,m)
      cout<<x[i]<<" "<<y[i]<<endl;
    return 0;
    
  }

  if(abs(maxi)<abs(mini)){
    REP(i,n){
      x[m]=minind+1;
      y[m]=i+1;
      m++;
    }
    REP(i,n-1){
      x[m]=n-i;
      y[m]=n-1-i;
      m++;
    }
  }

  cout<<m<<endl;
  REP(i,m)
    cout<<x[i]<<" "<<y[i]<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner readMan = new Scanner(System.in);
        
        int nodesCount = readMan.nextInt();;
        int edgeCount = 0;
        
        int[][] edgeArray = new int[nodesCount][nodesCount];
        
        for(int i = 0; i < nodesCount; i++){ //each node will have its own row
            int vertix = readMan.nextInt();
            edgeCount = readMan.nextInt();
            for(int j = 0; j < edgeCount; j++){
                edgeArray[i][readMan.nextInt() - 1] = 1;
            }
        }
        
        for(int i = 0; i < nodesCount; i++){
            for(int j = 0; j < nodesCount -1; j++){
                System.out.print(edgeArray[i][j] + " ");
            }
            System.out.println(edgeArray[i][nodesCount - 1]);
        }
        
        
        readMan.close();
    }
}



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

using namespace std;


int main() {
    vector<int> a(5);
    for(int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < 5; i++) {
        if(a[i] == 0) {
            cout << i + 1 << "\n";
        }
    }
    return 0;
}

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

using namespace std;

int main () {
  int A, B, ans;

  cin >> A >> B;

  int arr[3] = {A + B, A - B, A * B};
 
  if (arr[0] >= arr[1] && arr[0] >= arr[2]) {
    ans = arr[0];
  } else if (arr[1] >= arr[0] && arr[1] >= arr[2]) {
    ans = arr[1];
  } else {
    ans = arr[2];
  }

  cout << ans << endl;

  return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int main(){
	int N;
	cin >> N;
	bool ans =false;
	reps(i,9){
		if(N%i==0&& N/i<10) {ans=true;break;}
	}
	cout << (ans?"Yes":"No");
}

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

int main() {
    string s;
    cin >> s;
    int freq[2];
    freq[0] = 0;
    freq[1] = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '1') {
            freq[1]++;
        } else {
            freq[0]++;
        }
    }
    cout << s.size() - abs(freq[1] - freq[0]) << endl;

    return 0;
}

Measured memory_bytes: 512
import java.math.BigInteger;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		scan.close();
		String[] substr = str.split(" ", 0);

		BigInteger n = new BigInteger(substr[0]);
		BigInteger a = new BigInteger(substr[1]);
		BigInteger b = new BigInteger(substr[2]);

		BigInteger c = a.add(b);
		BigInteger m = n.mod(c);
		BigInteger s = n.divide(c);
		BigInteger buf = BigInteger.ZERO;
		if (a != BigInteger.ZERO) {
			if (m.compareTo(a)>= 0) buf = a;
			if (m.compareTo(a)<0) buf = m;
		}
		System.out.println(a.multiply(s).add(buf));
	}
}


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


int main(void) {
  int n,k;
  cin >> n >> k;
  ll ans = k;
  int cnt = 1;
  while (cnt<n){
    ans *= (k-1);
    cnt ++;
  }
  cout << ans << endl;
    
               
   
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int l,i,a=0;
	char s[105];
	scanf("%s",s);
	l=strlen(s);
	for(i=0;i<(l+1)/2;i++)
	{
		if(s[i]!=s[l-1-i])a++;
	}
	printf("%d\n",a);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

int main(){
	int a,b;scanf("%d%d",&a,&b);
	int ret=mod;
	for(int i=0;i<(1<<a);i++){
		int cur=1;
		for(int j=0;j<a;j++){
			if(i&(1<<j))cur*=2;
			else cur+=b;
		}
		ret=min(ret,cur);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int sum=0;
  sum+=(s[1]==t[1])+(s[0]==t[2])+(s[2]==t[0]);
  cout<<(sum==3?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.rbegin(), a.rend());
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (1ll * a[i] * 4 * m >= sum) {
			++cnt;
		}
	}
	cout << (cnt >= m ? "Yes\n" : "No\n");
	
 	return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/

/******* define variable end *******/
int solve() {
	ll count = 0;
	vector<int> seen(4);
	REP(i, 6){
		ll a;
		cin >> a;
		if(seen[a-1] == 1) count++;
		seen[a-1]++;
	}
	if(count == 2) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
int main() {

  std::string S;
  std::cin >> S;

  int count = 0;
  std::vector<int> v;
  for (auto ch : S) {
    if (ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T') {
      count += 1;
      continue;
    }
    v.push_back(count);
    count = 0;
  }
  if (count > 0) {
    v.push_back(count);
  }

  if (v.size() == 0) {
    std::cout << count << std::endl;
    return 0;
  }
  auto iter = std::max_element(v.begin(), v.end());
  auto index = std::distance(v.begin(), iter);
  std::cout << v[index] << std::endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0]+list(map(int,input().split()))+[0]
plan = 0
for i in range(N+1):
    plan += abs(A[i+1]-A[i])
for i in range(N):
    difference = abs(A[i+2]-A[i+1])+abs(A[i+1]-A[i])-abs(A[i+2]-A[i])
    print(plan-difference)


Measured memory_bytes: 14048
r,c = map(int,input().split())
line = []
array = [[0 for i in range(c+1)]for j in range(r+1)]
for i in range(0,r):
    line = input().split()
    for j in range(c):
        array[i][j]=int(line[j])
sum = 0
for i in range(r):
    for j in range(c):
        sum = sum + array[i][j]
    array[i][c]=sum
    sum = 0
for i in range(c):
    for j in range(r):
        sum = sum + array[j][i]
    array[r][i]=sum
    sum = 0
sum = 0
for j in range(r):
    sum = sum + array[j][c]
array[r][c] = sum    
for i in range(r+1):
    for j in range(c+1):
        if j == c:
            print("{}".format(array[i][j])) 
        else:    
            print("{}".format(array[i][j]),end=" ")
       

Measured memory_bytes: 6184