akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>
#include <unordered_map>
using namespace std;

typedef long long ll;

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  unordered_map<int, int> rest_count;
  REP(i, N) {
    scanf("%d", &A[i]);
    rest_count[A[i]]++;
  }
  sort(A.begin(), A.end(), greater<int>());

  int res = 0;
  REP(i, N) {
    if (rest_count[A[i]] == 0) {
      continue;
    }

    for (int t = 30; t >= 0; t--) {
      int target = (1 << t) - A[i];
      if (target <= 0) break;
      
      if ((target != A[i] && rest_count[target] > 0 ) || rest_count[target] > 1) {
        res++;
        rest_count[target]--;
        rest_count[A[i]]--;
        break;
      }
    }
  }
  cout << res << endl;
}



Measured memory_bytes: 29556
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	string s ;
	cin >> s ;
	bool ok = 0 ;;	
	
	trav(i,s)if(i-'0' == 7) ok = 1;
	if(ok) cout << "Yes\n";
	else cout << "No\n";
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;

#define MAX_N 10000
int a[MAX_N];

int main() {

  // -----------------------------
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  // input
  int K, X;
  cin >> K >> X;

  // -----------------------------

  if ( 500 * K >= X) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
  
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
   int i,n,b[1001],high,low;
   scanf("%d",&n);
   int pos[n];

   for(i=0;i<n;i++)
      scanf("%d",&pos[i]);

   for(i=0;i<=1000;i++)
      b[i]=0;

   for(i=0;i<n;i++)
      b[pos[i]]=1;

   for(i=0;i<=1000;i++)
      if(b[i]==1) {low=i;break;}
   for(i=1000;i>=0;i--)
      if(b[i]==1) {high=i;break;}


   printf("%d\n",high-low);
   return 0;
}

Measured memory_bytes: 128
import  numpy   as      np

i_N             =       int(input())
s_d               =       input().split()
i_d             =       np.array(s_d).astype(type(i_N))
i_Counter       =       0
i_d             =       sorted(i_d)

if(i_d[int(len(i_d)/2)-1] < i_d[int(len(i_d)/2)]):
        i_Counter       =       i_d[int(len(i_d)/2)] - i_d[int(len(i_d)/2)-1]
print(i_Counter)



Measured memory_bytes: 25760
#include<stdio.h>

int bit(int a)
{
	int i=0;
	while(a%2==0){
		a=a/2;
		i++;
	}
	return i;
}


int main(void)
{
	int i,n,a,sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		sum+=bit(a);
	}
	printf("%d",sum);
	return 0;
}

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

int main() {
  string T,S;
  
  cin >> S >> T;
  
  if (S.find(T)!=std::string::npos) {
    cout << 0 << endl;
  } else {
    int match_count = 0;
    int match_count_now = 0;
    int found_change = 0;
  	for (int i=0;i<=(S.size()-T.size());i++) {
      match_count_now = 0;
      for (int j=0;j<T.size();j++) {
        if (S[i+j]==T[j]) {
          match_count_now++;
        }
      }
      match_count=max(match_count,match_count_now);
    }
    cout << T.size()-match_count << endl;
  }
}

Measured memory_bytes: 3628
s=input()
n=len(s)-1

res=0
if n==0:
    res=int(s)
    
for i in range(2**n):
    B=format(i,'b').zfill(n)+'1'
    left=0
    for j in range(n+1):
        if B[j]=='1':
            res+=int(s[left:j+1])
            left=j+1
        
print(res)



Measured memory_bytes: 9212
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    int bf;

    if (a > b) {
      bf = a;
      a = b;
      b = bf;
    }
    if (b > c) {
      bf = b;
      b = c;
      c = bf;
    }
    if (a > b) {
      bf = a;
      a = b;
      b = bf;
    }
    System.out.println(a + " " + b + " " + c);
  }
}


Measured memory_bytes: 26160
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

struct hoge {
    int p;
    int y;
    int id;
};

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    vector<hoge> ds(m);
    vector<hoge*> ps(m);
    for(int i=0; i<m; i++) {
        scanf("%d %d", &ds[i].p, &ds[i].y);
        ps[i] = &ds[i];
    }
    sort(ps.begin(), ps.end(), [](hoge *a, hoge *b){return a->p<b->p || (a->p==b->p && a->y<b->y);});
    int id = 0;
    for(int i=0; i<m; i++) {
        if(i==0 || ps[i]->p!=ps[i-1]->p) id = 0;
        ps[i]->id = ++id;
    }
    for(int i=0; i<m; i++) {
        printf("%06d%06d\n", ds[i].p, ds[i].id);
    }
    
    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
int main()
{
  int a,b,c,x,y;
  y=0;
  scanf("%d%d%d",&a,&b,&c);
  for(x=a;x<=b;x++){
    if(c%x==0){y=y+1;}
    else{y=y;}
  }
  printf("%d\n",y);
  return 0;
}



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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    bool p = false;
    for(;N;) {
        p = p || N%10 == 7;
        N /= 10;
    }
    if(p) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int red=0,blue =0,ans;
  string S;
  cin >> S;
  int N = S.size();
  for(int i = 0 ;i < N ;i++ ){
    if(S.at(i) == '0'){
      red++;
    }
    if(S.at(i) == '1'){
      blue++;
    }
  }
  if(red > blue){
    ans = N - red + blue;
  }
  else{
    ans = N - blue + red;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
   int A,B,C,x,y;
   int count;
   count=0;
   scanf("%d%d%d",&A,&B,&C);
   if(A>=C&&C>=B){
   x=A-C;
   y=A-B;
   }else{
     if(A>=B&&B>=C){
     x=A-B;
     y=A-C;
     }else{
       if(C>=A&&A>=B){
       x=C-A;
       y=C-B;
       }else{
         if(B>=A&&A>=C){
         x=B-A;
         y=B-C;
         }else{
           if(B>=C&&C>=A){
           x=B-C;
           y=B-A;
           }else{
             if(C>=B&&B>=A)
             x=C-B;
             y=C-A;
           }
         }
       } 
     }     
   }
  count=x+y;
  if(count%2==1){
  count=(count+3)/2;
  }else{
  count=count/2;
  }
  printf("%d\n",count);
  
}


Measured memory_bytes: 128
import sys

class Rect():
    def __init__(self,w,h):
        self.w = w
        self.h = h

    def draw(self):
        for i in range(self.w):
            for j in range(self.h):
                if (i == 0 or i == self.w - 1) or (j == 0 or j == self.h - 1):
                    sys.stdout.write("#")
                else:
                    sys.stdout.write(".")
            sys.stdout.write("\n")
        sys.stdout.write("\n")

def main():
    data = []
    while 1:
        n = input().split()
        w = int(n[0])
        h = int(n[1])

        if w == 0 and h == 0:
            break

        data.append(Rect(w,h))

    for num in data:
        num.draw()

if __name__ == "__main__":
    main()

Measured memory_bytes: 6308
#include <iostream>
#include <string>

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

int main(){
    string s;
    cin >> s;
    if(s.size() % 2 == 0){
        if(s.front() == s.back()){
            cout << "First" << endl;
        }else{
            cout << "Second" << endl;
        }
    }else{
        if(s.front() == s.back()){
            cout << "Second" << endl;
        }else{
            cout << "First" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    const int MMAX = 12;
    #else // ONLINE_JUDGE
    const int MMAX = 100005;
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<int> a(m), b(m);
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    vector<bitset<MMAX>> masks(n);
    vector<bool> bad(n, false);
    for (int i = 0; i < n; ++i) {
        vector<bool> forced(n, false);
        forced[i] = true;
        for (int j = m - 1; j >= 0; --j) {
            if (forced[a[j]] && forced[b[j]]) {
                bad[i] = true;
                break;
            } else if (forced[a[j]]) {
                forced[b[j]] = true;
                masks[i].set(j);
            } else if (forced[b[j]]) {
                forced[a[j]] = true;
                masks[i].set(j);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (bad[i]) {
            continue;
        }
        for (int j = i + 1; j < n; ++j) {
            if (!bad[j] && (masks[i] & masks[j]).count() == 0) {
                ans++;
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 5888
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int main(void) {
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    for(int i = 1; i <= n; ++i) {
        if(a[i] == i) {
            swap(a[i], a[i+1]);
            cnt++;
        }
    }
    printf("%d", cnt);
    return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
 
int main(){
	int n, k;
	cin >> n >> k;
	ll v[n];
	for(int i=0; i<n; i++) cin >> v[i];

	ll ans=-(ll)(1e10);
	for(int i=0; i<=n; i++){
		for(int j=0; j<=n; j++){
			if(i+j>min(n,k)) continue;

			vector<ll> t;
			int negative=0;
			for(int l=0; l<i; l++){
				t.push_back(v[l]);
				if(v[l]<0) negative++;
			}
			for(int l=0; l<j; l++){
				t.push_back(v[n-1-l]);
				if(v[n-1-l]<0) negative++;
			}
			sort(t.begin(), t.end());

			ll sum=0;
			for(int l=min(negative, k-(i+j)); l<t.size(); l++){
				sum+=t[l];
			}
			ans=max(ans, sum);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    int n, m;
    cin>>n>>m;

    if(m==n) cout<<"Yes";
    else cout<<"No";
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int H,W,N;
    cin >> H >> W >> N;
    int X = 1;
    int Y = 1;
    vector<vector<int>>ans(H,vector<int>(W));
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        for(int j = 0; j < a; j++) {
            if(X%2 == 1) {
                ans[X-1][Y-1] = i+1;
                if(Y+1 <= W) {
                    Y++;
                }
                else {
                    X++;
                }
            }
            else {
                ans[X-1][Y-1] = i+1;
                if(Y-1 >= 1) {
                    Y--;
                }
                else {
                    X++;
                }
            }
        }
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cout << ans[i][j];
            if(j+1 != W) {
                cout << " ";
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 3692
#include<stdio.h>
#include<string.h>

#define MAX 1000

int main() {

	char W[11],T[MAX];
	int count = 0,i;

	scanf("%s", W);

	while (1) {
		scanf("%s", T);
			if (strcmp(T, "END_OF_TEXT") == 0) break;

		for (i = 0; i < strlen(T); i++) {
			if (T[i] >= 65 && T[i] <= 90) T[i] += 32;
		}

		if (strcmp(W, T) == 0) count++;

	}

	printf("%d\n", count);
	

	return 0;

}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
//define
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define pb() push_back()
#define mod 100000007
#define elif else if
#define str string
//main
signed main(){
  int N,M,O,P,Q,count=0,count2=0,count3=0;
  double D=0;
  int c='A'-'a';
  //char C;
  str S,T;
  cin>>S;
  rep(0,S.size()){
    if((i+1)%2==1&&S[i]=='L')count++;
    if((i+1)%2==0&&S[i]=='R')count++;
  }
  count>0?cout<<"No"<<endl:cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};


//////////////////////////////////////////////////



int main() {
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i] /= 2;
    }
    
    
    ll lm = 1;
    for (int i = 0; i < n; i++)
    {
        lm = lm*a[i] / __gcd(lm, a[i]);
        if (lm > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (lm/a[i] % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    
    
    cout << (m-lm)/(lm*2) + 1 << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    queue<pair<string,char> > que;
    priority_queue<string>answer;
    vector<string>reversed_answer;


    que.push(make_pair("a",'a'));
    if(n == 1){
        cout << "a" << endl;
        return 0;
    }

    while(!que.empty()){
        pair<string,char> temp = que.front();
        que.pop();
        for(int i = 0;i < temp.second-'a'+2;i++){
            string new_string;
            char new_char=temp.second;

            new_string = temp.first+(char)('a'+i);
            if('a'+i > temp.second)new_char = 'a'+i;
            if(new_string.length() == n){
                answer.push(new_string);
                continue;
            }
            que.push(make_pair(new_string,new_char));
        }
    }
    while(!answer.empty()){
        reversed_answer.push_back(answer.top());
        answer.pop();
    }
    reverse(ALL(reversed_answer));

    REP(i,reversed_answer.size()){
        cout << reversed_answer[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 8952
#include <stdio.h>

int tail[1000];
int cnt;
int pre[501010];
int val[501010];

int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++)tail[i]=i,pre[i]=-1;
	cnt=n;
	while(q--){
		int t;
		scanf("%d",&t);
		if(t==0){
			int k,x;
			scanf("%d%d",&k,&x);
			val[cnt]=x;
			pre[cnt]=tail[k];
			tail[k]=cnt;
			cnt++;
		}else if(t==1){
			int k;
			scanf("%d",&k);
			if(pre[tail[k]]!=-1)printf("%d\n",val[tail[k]]);
		}else{
			int k;
			scanf("%d",&k);
			if(pre[tail[k]]!=-1)tail[k]=pre[tail[k]];
		}
	}
}


Measured memory_bytes: 3352
#include<stdio.h>

int main (void){
  int n , a, b ,s ,i;
  scanf("%d %d %d",&n,&a,&b);
  
  int count = 0,temp,wa=0;
  
  for(i = 1;i <=n;i++){
    s = i;
    while(s > 0){
      wa += s%10;
      temp = s;
      s = temp/10;  
    }
    if(a<=wa&&wa<=b){
      count +=i;
    }
    wa = 0;
   }
    printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
# import math

def solve(A: int, B: int):
    # math.gcd()は3.5から
    # g = math.gcd(A, B)
    g = gcd(A, B)
    f = factorize(g)
    print(1 + len(f))


def gcd(x: int, y: int):
    return gcd(y, x % y) if y else x


def factorize(n: int):
    res = []
    for i in range(2, int(n ** 0.5//1 + 2)):
        if n % i:
            continue
        s = 0
        while n % i == 0:
            n /= i
            s += 1
        res.append([i, s])
    if n != 1:
        res.append([n, 1])
    return res


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

enum {
    INITIAL,
    FOUND_A,
    FOUND_AB
};

int main(int argc, char *argv[]) {
    int N;
    char *S;

    scanf("%d", &N);
    S = malloc(N + 1);
    scanf("%s", S);

    int count = 0;
    int state = INITIAL;
    for (int i = 0; i <= N; i++) {
        char c = S[i];
        switch (state) {
            case INITIAL:
                if (c == 'A') {
                    state = FOUND_A;
                }
                break;
            case FOUND_A:
                if (c == 'A') {
                    state = FOUND_A;
                } else if (c == 'B') {
                    state = FOUND_AB;
                } else {
                    state = INITIAL;
                }
                break;
            case FOUND_AB:
                if (c == 'A') {
                    state = FOUND_A;
                } else if (c == 'C') {
                    count++;
                    state = INITIAL;
                } else {
                    state = INITIAL;
                }
                break;
        }
    }
    free(S);
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,m;
	char flg[51][51];
	int i,j,k;
	int wcnt[51];
	int rcnt[51];
	int bcnt[51];
	int cnt=0;
	cin>>n>>m;
	for(i=0;i<n;i++){
		wcnt[i]=0;
		rcnt[i]=0;
		bcnt[i]=0;
		for(j=0;j<m;j++){
			cin>>flg[i][j];
			if(flg[i][j]=='W'){
				wcnt[i]++;
			}
			if(flg[i][j]=='B'){
				bcnt[i]++;
			}
			if(flg[i][j]=='R'){
				rcnt[i]++;
			}
		}
	}
	
	int cnt1=0,cnt2=0,cnt3=0;	
	int MIN=INT_MAX;
	for(i=0;i<n-2;i++){
		cnt1+=rcnt[i]+bcnt[i];
		//cout<<"I="<<i<<endl;
		cnt2=0;
		for(j=i+1;j<n-1;j++){
			cnt2+=wcnt[j]+rcnt[j];
			//cout<<"J="<<j<<endl;
			cnt3=0;
			for(k=j+1;k<n;k++){
				cnt3+=wcnt[k]+bcnt[k];
				//cout<<"K="<<k<<endl;
			}
			cnt+=cnt1+cnt2+cnt3;
			//cout<<cnt<<endl;
			//cout<<cnt<<endl;
			MIN=min(MIN,cnt);
			cnt=0;
		}
	}
	cout<<MIN<<endl;
	return 0;
}
			


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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

int n;

PII a[100010];

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i].fi), a[i].se = i;
	sort(a + 1, a + n + 1);
	int ans = 0;
	for (int i = 1; i <= n; ++i) if ((a[i].se & 1) != (i & 1)) ++ans;
	printf("%d\n", ans >> 1);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main(int argc, char const* argv[])
{
    int a, b;
    std::cin >> a >> b;

    if((a*b) % 2 == 0)
    {
        std::cout << "Even" << std::endl;
    }
    else
    {
        std::cout << "Odd" << std::endl;
    }
    return 0;
}

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

using namespace std;

#define ll long long int
const int mod = 1e9 + 7;
#define INF INT_MAX

int main() {
    //code
    int n,k;
    cin>>n>>k;
    vector<int> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    vector<int> dp(n,INF);
    dp[0] = 0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            if((i-j)>=0){
                dp[i] = min(dp[i],(abs(arr[i]-arr[i-j])+dp[i-j]));
            }
        }
    }
    cout<<dp[n-1];
    return 0;
}

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

int main(){       
 	 int A,B;
        cin>>A>>B;
        int answer=0;
        
        if(A>B){
        answer=answer+A;
        A=A-1;
        }else{
        answer=answer+B;
        B=B-1;
        }
         if(A>B){
        answer=answer+A;
        A=A-1;
        }else{
        answer=answer+B;
        B=B-1;
        }
        
        cout<<answer<<endl;
        return 0;
}       


Measured memory_bytes: 256
N, X = map(int, input().split())
a, p = [1], [1]
for i in range(N):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)
def f(N, X):
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])
print(f(N, X))


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

int main()
{
  int A,B,C,K,SUM;
  SUM=0;

  cin >> A >> B >> C >> K;

  if(K<=A){
    SUM+=K;
  }else{
    SUM+=A;
    if(0<=K-A-B){
      if(K-A-B<=C){
	SUM-=K-A-B;
      }else{
	SUM-=C;
      }
    }else{
      SUM+=0;
    }
  }

  cout << SUM;

  return 0;
}

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

using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;
using str = string;
using bl = bool;
using ch = char;

template<class T> using v = vector<T>;
template<class T> using uset = unordered_set<T>;
template<class T1, class T2> using umap = unordered_map<T1, T2>;

template<class T> void pd(T x)
{
    cout << x << " ";
}
template<class T> void pl(T x)
{
    cout << x << endl;
}

#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define sz(x) ((int)(x).size())
#define ph push_back
#define pp pop_back
#define mp make_pair
#define rep(i, a) for(int i = 0; i < (int)a; ++i)
#define repd(i, a) for(int i = (int)a; i >= 0; --i)
#define REP(i, a, b) for(int i = a; i < (int)b; ++i)
#define REPD(i, a, b) for(int i = (int)a; i >= b; --i)
#define fore(i, a) for(auto& i : a)
#define FORE(i, a) for(auto i : a)
#define PI 3.14159265358979323846264338327950L

// -----



int main()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, sz(s))
    {
        if(s[i] != t[i]) ++ans;
    }
    pl(ans);
}


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

using namespace std;

void doc() {
    freopen("OB.inp", "r", stdin);
    freopen("OB.out", "w", stdout);
}

const   int MaxN = 1e5 + 100;
int n, W;
int c[MaxN], v[MaxN];
long long f[105][MaxN];

void Trace(int i, int j){
    if (i <= 0 || j <= 0) return;
    if (f[i][j] == f[i - 1][j]){
        Trace(i - 1, j);
        return;
    }
    Trace(i - 1, j - v[i]);
    cout << i << '\n';
}

void solve(){
    cin >> n >> W;
    for(int i = 1; i <= n ; i++)
        cin >> c[i] >> v[i];
    long long sum = 0;
    for(int i = 1; i <= n; i++)
        sum += v[i];
    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= sum; j++)
            f[i][j] = 1e12;
    f[0][0] = 0;
    for(int i = 1; i <= n; i++)
        for(int j = 0; j <= sum; j++){
            f[i][j] = f[i - 1][j];
            if (j - v[i] >= 0)
                f[i][j] = min(f[i][j], f[i - 1][j - v[i]] + c[i]);
        }
    long long res = 0;
    for(int i = 0; i <= sum; i++)
        if (f[n][i] <= W) res = i;
    cout << res << '\n';
   // Trace(n, res);
}

int main()
{
//    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
//    doc();
    solve();
}



Measured memory_bytes: 80128
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		v[i] = t;
	}
	int maxv = v[1] - v[0], minv = v[0];

	for (int i = 1; i < n - 0; i++)
	{
		maxv = max(maxv, v[i] - minv);
		minv = min(minv, v[i]);
	}

	cout << maxv << endl;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  vector<string> results;
  vector<string> next_results;
  int n;cin>>n;

  results.push_back("a");

  rep(i, n-1){
    for(auto s: results){
      map<char, int>m;
      rep(i, s.size()) m[s[i]]++;
      rep(i, m.size()+1){
        char c = (char)('a'+i);
        string t(s);
        t.push_back(c);
        next_results.push_back(t);
      }
    }
    swap(results, next_results);
    next_results.clear();
  }

  rep(i, results.size())cout<<results[i]<<endl;

  return 0;
}

Measured memory_bytes: 11124
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	uft []int
	ch  []int
	ans []int64
)

func find(x int) int {
	if uft[x] == x {
		return x
	}

	uft[x] = find(uft[x])
	return uft[x]
}

func union(a, b, i int) {
	ans[i-1] = ans[i]
	ar, br := find(a), find(b)
	if ar == br {
		return
	}

	ans[i-1] -= int64(ch[ar] * ch[br])
	uft[ar] = uft[br]
	ch[br] += ch[ar]
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, m)
	bs := make([]int, m)
	for i := 0; i < m; i++ {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		bs[i], _ = strconv.Atoi(sc.Text())
	}

	uft = make([]int, n+1)
	ch = make([]int, n+1)
	for i := range uft {
		uft[i] = i
		ch[i]++
	}

	ans = make([]int64, m)
	ans[m-1] = int64(n * (n - 1) / 2)
	for i := m - 1; i >= 1; i-- {
		union(as[i], bs[i], i)
	}

	for _, v := range ans {
		fmt.Println(v)
	}
}


Measured memory_bytes: 7552
import java.util.Scanner;


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

	void run() {
		Scanner sc = new Scanner(System.in);

		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			String[] operations = new String[n];
			for (int i = 0; i < n; i++) {
				operations[i] = sc.next();
			}
			System.out.println(solve(n, operations));
		}

	}

	int solve(int n, String[] operations) {

		State currentState = State.MovingUp_LeftDownRightDown;

		int res = 0;
		for (String str : operations) {
			Command c = Command.valueOf(str);
			StateAndOutput next = getNext(currentState,c);

			res += next.i;
			currentState = next.s;
		}
		return res;
	}

	enum State {
		MovingUp_LeftDownRightDown, MovingUp_LeftDownRightUp, MovingUp_LeftUpRightDown, MovingDown_LeftUpRightUp, MovingDown_LeftUpRightDown, MovingDown_LeftDownRightUp,
	}

	enum Command {
		lu, ru, ld, rd
	}

	static class StateAndOutput {
		State s;
		int i;

		StateAndOutput(State s, int i) {
			this.s = s;
			this.i = i;
		}
	}

	static StateAndOutput getNext(State currentState, Command command) {
		switch (currentState) {
		case MovingUp_LeftDownRightDown:
			switch (command) {
			case lu:
				return new StateAndOutput(State.MovingUp_LeftUpRightDown, 0);
			case ru:
				return new StateAndOutput(State.MovingUp_LeftDownRightUp, 0);
			}
		case MovingUp_LeftDownRightUp:
			switch (command) {
			case lu:
				return new StateAndOutput(State.MovingDown_LeftUpRightUp, 1);
			case rd:
				return new StateAndOutput(State.MovingUp_LeftDownRightDown,0);
			}
		case MovingUp_LeftUpRightDown:
			switch (command) {
			case ru:
				return new StateAndOutput(State.MovingDown_LeftUpRightUp, 1);
			case ld:
				return new StateAndOutput(State.MovingUp_LeftDownRightDown,0);
			}
		case MovingDown_LeftUpRightUp:
			switch (command) {
			case ld:
				return new StateAndOutput(State.MovingDown_LeftDownRightUp, 0);
			case rd:
				return new StateAndOutput(State.MovingDown_LeftUpRightDown, 0);
			}
		case MovingDown_LeftUpRightDown:
			switch (command) {
			case ru:
				return new StateAndOutput(State.MovingDown_LeftUpRightUp, 0);
			case ld:
				return new StateAndOutput(State.MovingUp_LeftDownRightDown,1);
			}
		case MovingDown_LeftDownRightUp:
			switch (command) {
			case lu:
				return new StateAndOutput(State.MovingDown_LeftUpRightUp, 0);
			case rd:
				return new StateAndOutput(State.MovingUp_LeftDownRightDown,1);
			}
		}
		throw new RuntimeException("??¶?´???????????°??????????");
	}
}

Measured memory_bytes: 38472
/* A0J 0001 List of Top 3 Hills */

#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
    int h[10];
    int idx1, idx2, idx3 = -1;
    int temp_h = 0;
    int i;

    for (i = 0; i < 10; i++)
        scanf("%d", h + i);

    /* 1 番目に高い山を探す */
    for (i = 0; i < 10; i++) {
        if (h[i] > temp_h) {
            temp_h = h[i];
            idx1 = i;
        }
    }

    /* 2 番目に高い山を探す */
    temp_h = 0;
    for (i = 0; i < 10; i++) {
        if (i == idx1) continue;

        if (h[i] > temp_h) {
            temp_h = h[i];
            idx2 = i;
        }
    }

    /* 3 番目に高い山を探す */
    temp_h = 0;
    for (i = 0; i < 10; i++) {
        if (i == idx1 || i == idx2) continue;

        if (h[i] > temp_h) {
            temp_h = h[i];
            idx3 = i;
        }
    }

    printf("%d\n%d\n%d\n", h[idx1], h[idx2], h[idx3]);

    return 0;
}

Measured memory_bytes: 600
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import math
import itertools
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float("inf")

N = int(input())
A = list(map(int, input().split()))

min_diff = 1
max_diff = N - 1

dl = defaultdict(list)
dr = defaultdict(list)
for i in range(1, N + 1):
    key = i + A[i-1]
    dl[key].append(i)
    key = i - A[i-1]
    if key > 0:
        dr[key].append(i)
# pprint(dict(dl))
# pprint(dict(dr))

count = 0
for diff in range(min_diff, max_diff + 1):
    count += len(dl[diff]) * len(dr[diff])
print(count)


Measured memory_bytes: 168916
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double

using namespace std;

int main()
{
    fastio;

    ll n, l;
    cin >> n >> l;

    vector<string> a;

    for(ll i=0;i<n;i++){
        string s;
        cin >> s;
        a.push_back(s);
    }

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

    for(ll i=0;i<n;i++){
        cout << a[i];
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
  string s; cin>>s;
  for(int i=0;i<5;i++){
    cout<<s[i];
  }
  cout<<" ";
  for(int i=6;i<13;i++){
    cout<<s[i];
  }
  cout<<" ";
  for(int i=14;i<19;i++){
    cout<<s[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        double d = scn.nextDouble();
        int n = scn.nextInt();
        d = Math.pow(100,d);
        if(n==100) n++;
        if(d==0){
            System.out.println((int)n);
        }else{
            System.out.println((int) d*n);
        }
    }
}

Measured memory_bytes: 23252
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(61)]
for i in range(n):
    ai = a[i]
    for j in reversed(range(61)):
        arr[j] += ai % 2
        ai //= 2
ans = 0
for i in range(61):
    ans *= 2
    arri = arr[i]
    ans += arri * (n - arri if arri != 0 else 0)
    ans %= mod
print(ans)


Measured memory_bytes: 124568
s = gets.chomp

def result(s)
  check_hash = { 'a' => false, 'b' => false, 'c' => false }
  s.each_char do |c|
    return 'No' unless check_hash.has_key?(c)
    return 'No' if check_hash[c]
    check_hash[c] = true
  end
  return 'Yes'
end

puts result(s)


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

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n;
string s;
bool f[301][301];
int main()
{
    cin>>s;
    n=s.length();
    s='.'+s;
    for(int len=1;len<=n;len++)
    {
        for(int i=1;i<=n-len+1;i++)
        {
            int j = i+len-1;
            if(len == 1)
            {
                f[i][j]=true;
                continue;
            }
            if(len==2)
            {
                f[i][j] = s[i]==s[j];
                continue;
            }
            f[i][j] = s[i]==s[j]&&f[i+1][j-1];
        }
    }
    f[1][n]&&f[1][(n-1)/2]&&f[(n+3)/2][n] ? cout<<"Yes" : cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#import sys
#input = sys.stdin.readline
#from numpy import matrix, eye, dot
def productMatrix(N, A, B):
    Ret = [[0]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            for k in range(N):
                Ret[i][j] += A[i][k]*B[k][j]
    return Ret
def modMatrix(N, A, Q): #N×N行列のmod
    for i in range(N):
        for j in range(N):
            A[i][j] %= Q
    return

def powOfMatrix(N, X, n, Q): #N×N行列のn乗
    Ret = [[1,0,0],[0,1,0],[0,0,1]]
    power = '{:060b}'.format(n)[::-1] #log2(pow(10,18)) < 60
    for p in power:
        if p == "1":
            Ret = productMatrix(N,Ret, X)
            modMatrix(N, Ret, Q)
        X = productMatrix(N,X,X)
        modMatrix(N, X, Q)
    return Ret

def main():
    L, A, B, M = map( int, input().split())
    s = A
    ANS = [[1,0,0],[0,1,0],[0,0,1]]
    for i in range(1, 37):
        if s >= pow(10,i):
            continue
        P = [[pow(10, i, M), 0, 0], [1,1,0], [0,B,1]]
        step = (pow(10,i)-s+B-1)//B
        if L <= step:
            ANS = productMatrix(3,ANS,powOfMatrix(3,P,L,M))
            modMatrix(3,ANS,M)
            break
        ANS = productMatrix(3,ANS, powOfMatrix(3,P, step,M))
        modMatrix(3,ANS, M)
        L -= step
        s += step*B
    print( (ANS[1][0]*A + ANS[2][0])%M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 43756
grid = [list(map(int, input().split())) for _ in range(3)]


def solve():
    for i in range(max(grid[0]) + 1):
        b1 = grid[0][0] - i
        b2 = grid[0][1] - i
        b3 = grid[0][2] - i
        if not b1 < 0 and not b2 < 0 and not b3 < 0:
            if grid[1][0] - b1 == grid[1][1] - b2 == grid[1][2] - b3:
                if grid[2][0] - b1 == grid[2][1] - b2 == grid[2][2] - b3:
                    print("Yes")
                    return 0
    print("No")
    return 0


if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
S = input()
num = [int(S[i]) for i in range(4)]

for i in range(2 ** 3):
    ans = ''
    total = 0
    k = 3
    for j in range(3):
        if (i >> j) & 1:
            total += num[k]
            ans = ('+' + str(num[k])) + ans
        else:
            total -= num[k]
            ans = ('-' + str(num[k])) + ans
        k -= 1
    
    if total + num[0] == 7:
        print(str(num[0]) + ans + '=7')
        break

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

int n, cntZero, cntOne;
int a[100010];
char ch;

int main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    while (isdigit(ch = getchar()))
    	a[++n] = ch ^ 48, cntZero += a[n] == 0, cntOne += a[n];
	std::cout << std::min(cntOne, cntZero) * 2 << "\n";
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>
#include <bitset>

using namespace std;
typedef long long ll;
ll MOD = 1000000007;

template <class Abel>
struct UnionFind
{
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0)
    {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0)
    {
        par.resize(n);
        rank.resize(n);
        diff_weight.resize(n);
        for (int i = 0; i < n; ++i)
            par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x)
    {
        if (par[x] == x)
        {
            return x;
        }
        else
        {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x)
    {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w)
    {
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (rank[x] < rank[y])
            swap(x, y), w = -w;
        if (rank[x] == rank[y])
            ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y)
    {
        return weight(y) - weight(x);
    }
};

int main()
{
    ll n, q;
    cin >> n >> q;
    UnionFind<ll> uf(n);

    for (int i = 0; i < q; i++)
    {
        ll x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        if (uf.issame(x, y))
        {
            if (uf.diff(x, y) != z)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            uf.merge(x, y, z);
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n) cin >>a[i];

    int idx = 0;
    int d = 0;
    rep(i,n){
        if(abs(a[i]) > d){
            d = abs(a[i]);
            idx = i;
        }
    }

    vector<pi> ans;
    rep(i,n)if(i!=idx) ans.pb({idx,i});

    if(a[idx]>0) rep(i,n-1) ans.pb({i,i+1});
    else for(int i=n-1; i>0; --i) ans.pb({i,i-1});

    cout << ans.size() << endl;
    for(const auto &p:ans) cout << p.fi+1 << " " << p.se+1 << endl;

    // for(const auto &p:ans) a[p.se] += a[p.fi];
    // dbg(a);
    return 0;
}


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

long long Power5(long long a) {
  return a * a * a * a * a;
}

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

  int x;
  cin >> x;

  vector<pair<long long, long long>> cands = {{0, 0}};
  for (long long a = 1; Power5(a) - Power5(a - 1) <= x; ++a) {
    long long value = Power5(a);
    cands.emplace_back(value, a);
    cands.emplace_back(-value, -a);
  }

  for (auto a: cands)
    for (auto b: cands)
      if (a.first - b.first == x) {
        cout << a.second << ' ' << b.second << '\n';
        return 0;
      }
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int h;
void maxHeapify(int* A, int i){
  int l = 2*i;
  int r = 2*i+1;
  int largest;
  if ( l<= h && A[l] > A[i] )
    largest = l;
  else
    largest = i;

  if ( r<= h && A[r] > A[largest])
    largest = r;

  if (largest != i){
    swap(A[i], A[largest]);
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int* A){
  for (int i=h/2 ; i>=1 ;--i)
    maxHeapify(A, i);
}

int main(void){
  int a[500000];
  cin >> h;
  for (int i=1;i<=h;++i){
    cin >> a[i];
  }
  buildMaxHeap(a);

  for (int i=1;i<=h;++i){
    cout << " " << a[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 4948
# -*- coding:utf-8 -*-


n = int(input())
n = n%10

if n==2 or n==4 or n==5 or n==7 or n==9:
    print("hon")
elif n==0 or n==1 or n==6 or n==8:
    print("pon")
else:
    print("bon")


Measured memory_bytes: 9172
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cassert>
typedef long long lint;
const int N=131080;
int n;
class pair{
	public:
		lint x,y;
		friend bool operator < (const pair &a,const pair &b);
};

bool operator < (const pair &a,const pair &b){
	return a.x==b.x?a.y<b.y:a.x<b.x;
}

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

inline int x_bound(std::vector <pair> &vt,const lint _lim){
	int l=0,r=vt.size()-1,mid;
	while(l!=r){
		mid=(l+r+1)>>1;
		if(vt[mid].x>_lim) r=mid-1;
		else l=mid;
	}
	return l;
}

inline int y_bound(std::vector <pair> &vt,const lint _lim){
	int l=0,r=vt.size()-1,mid;
	while(l!=r){
		mid=(l+r)>>1;
		if(vt[mid].y>_lim) l=mid+1;
		else r=mid;
	}
	return l;
}

inline void sanitize_seq(std::vector <pair> &vt){
	const int sz=vt.size();
	int p1=1,p2=1;
	for(; p1<sz; ++p1){
		if(vt[p1].x!=vt[p1-1].x) vt[p2++]=vt[p1];
	}
	while((int)vt.size()>p2) vt.pop_back();
}

namespace G{
	int cnt,nxt[N][2],wt[N][2];
	lint lim_w;
	std::vector <pair> vt[N];

	inline void add(const int a,const int b,const int v){
		bool f=nxt[a][0]>0;
		nxt[a][f]=b,wt[a][f]=v;
	}

	void dfs(const int x){
		if(!nxt[x][0]){
			vt[x].push_back((pair){0,0});
			return;
		}
		dfs(nxt[x][0]);
		dfs(nxt[x][1]);
		if(vt[nxt[x][0]].size()>vt[nxt[x][1]].size()){
			std::swap(nxt[x][0],nxt[x][1]);
			std::swap(wt[x][0],wt[x][1]);
		}

		const int c0=nxt[x][0],c1=nxt[x][1];
		const lint v0=wt[x][0],v1=wt[x][1];
		const int lim_l=vt[c0].size();
		const int lim_r=vt[c1].size();

		for(int i=0,j,lst_j=-1; i<lim_l; ++i){
			const lint _lim=lim_w-vt[c0][i].y-v0-v1;
			j=x_bound(vt[c1],_lim);
			assert(j<lim_r);
			if(vt[c1][j].x>_lim) continue;
			if(j!=lst_j){
				lst_j=j;
				vt[x].push_back((pair){vt[c0][i].x+v0,vt[c1][j].y+v1});
			}
			//vt[x].push_back((pair){vt[c0][i].x+v0,vt[c1][j].y+v1});
		}
		for(int i=lim_l-1,j,lst_j=-1; i>=0; --i){
			const lint _lim=lim_w-vt[c0][i].x-v0-v1;
			j=y_bound(vt[c1],_lim);
			assert(j<lim_r);
			if(vt[c1][j].y>_lim) continue;
			if(j!=lst_j){
				lst_j=j;
				vt[x].push_back((pair){vt[c1][j].x+v1,vt[c0][i].y+v0});
			}
			//vt[x].push_back((pair){vt[c1][j].x+v1,vt[c0][i].y+v0});
		}
		std::sort(vt[x].begin(),vt[x].end());
		sanitize_seq(vt[x]);
	}

	bool jdg(const lint tgt){
		lim_w=tgt;
		for(int i=1; i<=n; ++i){
			vt[i].clear();
		}
		dfs(1);
		return !vt[1].empty();
	}
}

inline lint solve(){
	lint l=0,r=1e12,mid;
	while(l!=r){
		mid=(l+r)>>1;
		if(G::jdg(mid)) r=mid;
		else l=mid+1;
	}
	return l;
}

int main(){
	n=nxi();
	for(int i=2; i<=n; ++i){
		int fr=nxi();
		G::add(fr,i,nxi());
	}
	printf("%lld\n",solve());
	//printf("%d\n",G::jdg(25));
	return 0;
}

Measured memory_bytes: 27316
while True:
    try:
        cnt = 0
        for i in range(8):
            inp = input()
            if cnt == 1:
                if inp.count("1") == 1:
                    print("B")
                elif inp.index("1") == ind:
                    print("F")
                else:
                    print("D")
                cnt = -1
            elif cnt == 2:
                if inp.index("1") == ind:
                    print("A")
                elif inp.index("1") == ind + 1:
                    print("E")
                else:
                    print("G")
                cnt = -1
            elif "1" in inp and cnt == 0:
                ind = inp.index("1")
                cnt = inp.count("1")
                if cnt == 4:
                    print("C")
                    cnt = -1
        inp = input()
    except:
        break



Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    string t;
    cin >> t;
    int n = t.size();
    rep(i, n) {
        if (t[i]!='?') continue;
        t[i] = 'D';

    }
    
    
    cout << t << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define dbg(S) { int f=1; for(auto x:S) cerr<<(f?"[":", ")<<x, f=0; cerr<<"]\n"; }

using namespace std;
using lint=long long;

int main(){
	string s; cin>>s;
	s=">"+s+"<";
	int n=s.length();

	vector<int> pos;
	rep(i,n-1) if(s[i]=='>' && s[i+1]=='<') pos.emplace_back(i+1);

	vector<int> a(n+1);
	for(int p:pos){
		for(int i=p-1;i>=0;i--){
			if(s[i]=='<') break;
			a[i]=max(a[i],a[i+1]+1);
		}
		for(int i=p;i<n;i++){
			if(s[i]=='>') break;
			a[i+1]=max(a[i+1],a[i]+1);
		}
	}

	lint ans=0;
	for(int i=1;i<n;i++) ans+=a[i];
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3736