akhauriyash/Code-Regression huggingface dataset:
coffeeinput = input()
if len(coffeeinput) == 6:
  con1 = coffeeinput[2] == coffeeinput[3]
  con2 = coffeeinput[4] == coffeeinput[5]
  if con1 == True and con2 == True:
    print("Yes")
  else:
    print("No")
else:
  print()


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(void){
    long long a,b,k;
  	cin>>a>>b>>k;
	if(a+b<k){
      a=b=0;
    }else if(a>k){
      a-=k;
    }else{
      b-=k-a;
      a=0;
    }
  	cout<<a<<" "<<b<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<int,int> a, const pair<int,int> b) {

    return a.second < b.second;
}

int Dx[6] = { 0, 0, 1, 1,-1,-1};
int Dy[6] = { 1,-1, 1, 0, 0,-1};

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;
int main(){

  int N;
  vector<pair<int, int> >tList;
  string s = "Yes";

  cin >>N;

  for(int i = 0;i<N;i++){
      int A,B;
      cin >>A>>B;
      tList.push_back(make_pair(A,B));
  }

  sort(tList.begin(),tList.end(),comp);

  long long int sum = 0;

  for(int i = 0;i<N;i++){
      if(sum+tList[i].first> tList[i].second){
          s = "No";
          break;
      }
      sum += tList[i].first;
  }

  cout <<s<<endl;
  return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

*/

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

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

  double avg = total / static_cast<double>(n);

  double mind = INF;
  int ans = -1;
  for (int i = 0; i < n; i++) {
    double dist = abs(avg - a[i]);
    if (dist < mind) {
      ans = i;
      mind = dist;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 1000000007
int main()
{
	int d,m;
	long long s=1;
	scanf("%d%d",&d,&m);
	if(d == m)
	{
		for(long long t=1;t<=d;t++)
		{
			s *= (t*t)%N;
			s %= N;
		}
		printf("%lld\n",(s*2)%N);
	}
	else if(d-m==1 || m-d==1)
	{
		int i;
		i = (d<m)?d:m;
		for(long long t=1;t<=i;t++)
		{
			s *= (t*t)%N;
			s %= N;
		}
		s *= i+1;	
		printf("%lld\n",s%N);
	}
	else
	{
		printf("0\n");
	}
	return 0;
}

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

int GCD(int value1,int value2){
    int large,small;
    
    if(value1>=value2){
        large=value1;
        small=value2;
    }else{
        large=value2;
        small=value1;
    }
    
    if((large%small)==0){
        return small;
    }else{
        return GCD(small,large%small);
    }
}

int main(){
    int a,b,gcd,lcm;
    while(cin>>a>>b){
        gcd=GCD(a,b);
        lcm=a/gcd*b;
        cout << gcd << " " << lcm << endl;
    }
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,k;
	cin >> n >> k;
	int mx = (n - 1)*(n - 2) / 2;
	if(mx < k){
		cout << -1 << endl;
		return 0;
	}
	vector<P> ans;
	for(int i = 1; i < n; i++){
		ans.push_back(P(i, n));
	}
	vector<P> edge;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j < i; j++){
			edge.push_back(P(i,j));
		}
	}
	int add = mx - k;
	REP(i,add) ans.push_back(edge[i]);
	cout << ans.size() << endl;
	REP(i,ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
}

Measured memory_bytes: 384
n, m = map(int, input().split())


lst_sw = []
for _ in range(m):
    lst_sw.append(list(map(int, input().split())))
lst_p = list(map(int, input().split()))


ans = 0
for bits in range(2 ** n):
    judge = True
    for i in range(m):
        cnt_sw_on = 0
        for j in range(1, len(lst_sw[i])):
            sw = lst_sw[i][j]
            if (bits >> (sw - 1)) & 1:
                cnt_sw_on += 1
        if cnt_sw_on % 2 != lst_p[i]:
            judge = False
            break
    if judge:
        ans += 1


print(ans)


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

int main() {
    int n; scanf("%d", &n);
    if (n % 2 == 0) {
        printf("%d\n", n - 2 + (n - 2) * (n - 2) / 2);
        for (int i = 2; i < n; ++i)
            printf("1 %d\n", i);

        for (int i = 2; i < n; ++i) {
            for (int j = 1; j <= n; ++j) {
                if (j == i || j == n - i + 1) continue;
                if (j > i)
                    printf("%d %d\n", i, j);
            }
        }
    } else {
        printf("%d\n", (n - 1) * (n - 1) / 2);
        for (int i = 1; i < n; ++i) {
            for (int j = 1; j <= n; ++j) {
                if (j == i || j + i == n) continue;
                if (i < j)
                    printf("%d %d\n", i, j);
            }
        }
    }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
manzoku = sum(b)
for i in range(n-1):
	if a[i] + 1 == a[i+1]:
		manzoku += c[a[i]-1]
print(manzoku)


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < N - 1; i++) {
        cin >> C[i];
    }
    int res = 0;
    for (int i = 0; i < N; i++) {
        res += B[A[i]];
        if (i > 0 && A[i] == A[i - 1] + 1) res += C[A[i - 1]];
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回

int main() {
    int x, n;
    cin >> x >> n;
    vector<int> d(102);
    rep(i, n) {
        int p;
        cin >> p;
        d[p] = 1;
    }
    P ans(999999, -1);
    for (int i = 0; i <= 101; i++) {
        if (d[i] == 1) continue;
        int dif = abs(x - i);
        ans = min(ans, P(dif, i));
    }
    cout << ans.second << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,a[1000],b[1000],c=0,i;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>a[i]>>b[i];
    }
    ll chk=0;
    for(i=1; i<=n; i++)
    {
        if(a[i]!=b[i])
        {
            c=0;
        }
        else
            c++;
        if(c>=3)
        {
            chk=1;
            break;
        }
    }
    if(chk==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define FILE "file"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const ull ULLINF = numeric_limits<ull>::max();
const double PI = acos(-1.0);

bool dp[100010];

int main()
{
//    freopen(FILE".in", "r", stdin);
//    freopen(FILE".out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    dp[0] = 1;
    int n = s.size();
    for(int i = 5; i <= n; i++)
    {
        for(int j = 5; i - j >= 0 && j <= 7; j++)
        {
            string sub = s.substr(i - j, j);
            if(sub == "dream" || sub == "dreamer" || sub == "erase" || sub == "eraser")
                dp[i] |= dp[i - j];
        }
    }
    cout << (dp[n] ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 592
import math
import copy
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0

a = []
n = iin()
for i in range(n):
    a.append(iin())
    if neko < a[i]:
        neko = a[i]
b = copy.copy(a)
a.remove(neko)
nya = max(a)
for i in range(n):
    if b[i] == neko:
        print(nya)
    else:
        print(neko)

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;


int main() {
    int n;cin>>n;
    vector<ll>a(n+1);
    a[n]=mod;

    rep(i,n){
        cin>>a[i];
    }
    sort(a.begin(),a.end());

    int cnt=0,ans=0;

    rep(i,n){
        cnt++;
        if(a[i]!=a[i+1]){
            if(cnt%2!=0){
            ans++;
            }
            cnt=0;
        }
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  a+=b;
  c+=d;
  if(a>c) pr("Left");
  else if(a<c) pr("Right");
  else pr("Balanced");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
setrecursionlimit(1000000)

# INF = float('inf')
INF = int(1e10)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))    
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    ans = 0
    v = p[:X] + q[:Y]
    v.sort()
    w = 0
    for i in range(min(X + Y, C)):
        if v[i] < r[w]:
            v[i] = r[w]
            w += 1
    print(sum(v))


if __name__ == '__main__':
    main()

Measured memory_bytes: 94120
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int n=in(),y=in(),i,j,t;
	rep(i,n+1){
		rep(j,n-i+1){
			t=n-i-j;
			if(10000*i+5000*j+1000*t==y){
				printf("%d %d %d\n",i,j,t);
				return 0;
			}
		}
	}
	puts("-1 -1 -1");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n;
map<string,int> q;
struct p
{
	int num;
	string name;
};
p ps[200001];
bool cmp(p a,p b)
{
	if(a.num==b.num)
	{
		return a.name<b.name;
	}
	return a.num>b.num;
}
int main()
{
	cin>>n;
	while(n--)
	{
		string tmp;
		cin>>tmp;
		q[tmp]++;
	}
	int j=0;
	for(map<string,int>::iterator i=q.begin();i!=q.end();i++,j++)
	{
		ps[j].name=i->first;
		ps[j].num=i->second;
	}
	sort(ps,ps+q.size(),cmp);
	cout<<ps[0].name<<endl;
	for(int i=1;i<q.size();i++)
	{
		if(ps[i].num==ps[i-1].num)
		{
			cout<<ps[i].name<<endl;
		}
		else
		{
			break;
		}
	}
}

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

void dp_solve(vector<vector<long long>> &dp, int l, int r, vector<pair<int, int>> &vp)
{
    if (dp[l][r] != -1)
    {
        return;
    }
    if (l == r)
    {
        dp[l][r] = 0;
        return;
    }
    for (int i = 0; i < r - l; i++)
    {
        dp_solve(dp, l, l + i, vp);
        dp_solve(dp, l + i + 1, r, vp);
    }
    dp[l][r] = 10000000000;
    for (int i = 0; i < r - l; i++)
    {
        dp[l][r] = min(dp[l][r], dp[l][l + i] + dp[l + i + 1][r] + vp[l].first * vp[l + i].second * vp[r].second);
    }
}

int main()
{
    int n;
    cin >> n;
    vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, -1));
    vector<pair<int, int>> vp(n + 1);
    for (int i = 1; i <= n; i++)
    {
        int r, c;
        cin >> r >> c;
        vp[i] = make_pair(r, c);
    }
    dp_solve(dp, 1, n, vp);
    cout << dp[1][n] << endl;
}



Measured memory_bytes: 3196
# integrotS
N, K = map(int, input().split())
S = format(K, "0%ib" % 30)

d = []
use = []
for i in range(N):
    x, y = map(int, input().split())
    d.append((x, y))
for i in range(30):
    if S[i] == "1":
        que = S[:i] + "0" + "1"*(29-i)
        use.append(int(que, 2))

use.append(int(S, 2))
use = set(use)
ans = 0

for some in use:
    s=0
    for num, value in d:
        if num|some == some:
            s += value
    ans = max(s, ans)
print(ans)

Measured memory_bytes: 53464
#include <stdio.h>
int main(void){
   int i, x, y;
for(i = 0; i < 3000; i++) {
 scanf("%d %d", &x,&y);
 if(x == 0 && y == 0) {
   break;
 }
 else if(x<y) { printf("%d %d\n", x,y);
 }
 else { printf("%d %d\n", y,x);
 }
}
 return 0;
   
}


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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll x, ll y) {
    if (x % y == 0LL) {
        return y;
    }

    else {
        return gcd(y, x % y);
    }
}

int main() {
  ll A, B, C,D;
  cin >> B >>A>>C>>D;
  ll E = gcd(C,D);
  ll F = (C/E)*D;
  ll a = (A/C)-((B-1)/C);
  ll b = (A/D)-((B-1)/D);
  ll c = (A/F)-((B-1)/F);
  cout<<A+1LL-B-a-b+c<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool Used[1000100];
int X[200200];
int main()
{
  int N;
  cin>>N;
  for(int i=0;i<N;i++)
    cin>>X[i];
  sort(X,X+N);
  int Ans=0;
  for(int i=0;i<N;i++)
    if(!Used[X[i]])
    {
      Ans++;
      if(X[i]==X[i+1])
        Ans--;
      for(int j=X[i];j<=1000000;j+=X[i])
        Used[j]=true;
    }
  cout<<Ans<<endl;
  return 0;
}


Measured memory_bytes: 5336
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
#define fs first
#define sc second
using namespace std;

typedef pair<ll,ll> P;



ll gcd(ll a,ll b){
  if(!b) return a;
  else return gcd(b,a%b);
}

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


int main(){

  string s;
  cin >> s;

  
  rep(i,0,3){
    if(s[i] == '7'){
      
      cout << "Yes" << endl;
      return 0;
    } 
  }
  
  cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int a,b;
  cin >> a >> b;
  if(a%2 == 0 || b%2 == 0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define for(a,n) for(int i = int(a); i<int(n); i++)
#define ll long long

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    string a1,b1;
    cin>>a>>b;
    for(0,a)
        b1+=to_string(b);
    for(0,b)
        a1+=to_string(a);

    if(a1==b1)
        cout<<a1;
    else if(a>b)
        cout<<b1;
    else
        cout<<a1;





    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int visit[100],end[100],a[100][100];
int t,N,u,k,p;
 
void list(int N){
    for(int i=0;i<N;i++){
        cin>>u>>k;
        for (int j=0;j<k;j++){
            cin>>p;
            a[u-1][p-1]=1;
        }
    }
}
 
void sor(int cur,int N){
    t+=1;
    visit[cur]=t;
    for(int kyo=0;kyo<N;++kyo){
        if(a[cur][kyo]==1&&visit[kyo]==0){
            sor(kyo,N);
        }
    }
    t+=1;
    end[cur]=t;
}
 
int main(){
    cin >> N;
    list(N);
    for(int i=0;i<N;i++){
        if(visit[i] == 0) sor(i,N);
    }
    for(int i=0;i<N;i++){
        cout<<i+1<<' '<<visit[i]<<' '<<end[i]<<endl;
    }
}


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

int amt(int h[],int dp[],int i,int n,int k){
	
	if(i>=n){
		return 0;
	}
	
	if(dp[i]!=-1){
		return dp[i];
	}
	else{
		int ans, minimum=INT_MAX;
		
		for(int j=1;j<=k;j++){
			if(i+j<=n){
				int ans = abs(h[i+j] - h[i])  + amt(h,dp,i+j,n,k)  ;
				minimum = min(minimum,ans);
			}
			
		}
		
		return dp[i] = minimum;
		
	}
}


int main(){
  
	int n,x,k;
	cin>>n>>k;
	int h[n+1];
	
	for(int i=1;i<=n;i++){
		cin>>h[i];
		
	}
	
	int dp[n+1];
	for(int i=0;i<n+1;i++){
		dp[i] = -1;
	}
	
	cout<<amt(h,dp,1,n,k);

}

Measured memory_bytes: 15248
num = int(input())

ans = 0
next_ans = 0
count = 0
index = 0

for i in range(num):
  s = int(input())
  if s > ans:
    next_ans = ans
    ans = s
    index = i
    count = 1
  elif s == ans:
    count += 1
  elif s > next_ans:
    next_ans = s
    
if count > 1:
  for i in range(num):
    print(ans)
else:
  for i in range(num):
    if i == index:
      print(next_ans)
    else:
      print(ans)
    

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

#define ll long long int

ll dp[102][100002], w[1000], v[1000];
ll n, weight;

void init() {
    for (int i = 0; i < n + 2; i++) {
        for (int j = 0; j < weight + 2; j++) {
            dp[i][j] = -1;
        }
    }
}

ll solve_temp(int pos, int weight) {
    if (weight < 0) return 0;
    if (pos >= n) return 0;
    /*if (pos == n - 1) {
        if (weight < w[n - 1]) return 0;
        else return v[n - 1];
    }*/
    ll temp = 0;
    if (weight - w[pos] >= 0) {
        //temp = v[pos] + test(pos + 1, weight - w[pos]);
    }
    //return max(temp, test(pos + 1, weight));
    return 0;
}

ll test(int pos, int weight) {
    if (weight < 0) return 0;
    if (pos >= n) return 0;
    if (dp[pos][weight] != -1) return dp[pos][weight];
    /*if (pos == n - 1) {
        if (weight < w[n - 1]) return 0;
        else return v[n - 1];
    }*/
    ll temp = 0;
    if (weight - w[pos] >= 0) {
        temp = v[pos] + test(pos + 1, weight - w[pos]);
    }
    dp[pos][weight] = max(temp, test(pos + 1, weight));
    return dp[pos][weight];
}

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

    //for (int i = 0; i < n; i++) for (int j = 0; j < weight; j++) cout << dp[i][j] << " "; cout << endl;
    for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
    

    cout << test(0, weight) << endl;

    return 0;
}

Measured memory_bytes: 80000
'use strict'

const main = arg => {
 const input = arg.trim().split("\n");
 const result = input.filter(num => num !== "0 0").map(num => { 
     const separate = num.split(" ").sort((a, b) => a - b);
     return `${separate[0]} ${separate[1]}`;
 });

 console.log(result.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 17308
#include<cstdio>
#include<cstring>
#include<iostream> 
#include<cmath>
#include<algorithm>
#include<stdlib.h>
using namespace std;

int main()
{
	int a;
	cin>>a;
	int ans=a%10;
	if(ans==3)
	{
		cout<<"bon"<<endl;
	}
	else if(ans==0||ans==1||ans==6||ans==8)
	{
		cout<<"pon"<<endl;
	}
	else
	{
		cout<<"hon"<<endl;
	}

return 0;
}

Measured memory_bytes: 3616
from collections import Counter

H, W, N = map(int, input().split())

# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]

# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = {}

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        # 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            if (a + dy, b + dx) not in dict:
                dict[(a + dy, b + dx)] = 1
            else:
                dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]

# ans[1], ans[2], ..., ans[9]を確定させる（ans[0]は後述）
for k, v in c.items():
    if v > 0:
        ans[k] = v

# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])

for i in range(10):
    print(ans[i])


Measured memory_bytes: 249472
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>

using namespace std;

int main(){
	int a[12];
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"
				,&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&a[10],&a[11]) != EOF){

		int ans = 0;	
		double t = 0, d = 0;
		int sum = 0;
		for(int i = 0;i < 10;i++){
			sum += a[i];
		}
		t = (double)sum / (a[10]+a[11]);
		d = (double)a[10] * t;
		sum = 0;
		for(int i = 0;i < 10;i++){
			sum += a[i];
			if(sum >= d){
				ans = i + 1;
				break;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000000
#define N 10000005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
       if(n % i == 0 && i<10)
       {
           if(n/i < 10)
           {
               cout<<"Yes"<<endl;
               return 0;
           }
       }
   }
   cout<<"No"<<endl;


}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
int main(){
    int N,A; cin >> N >> A;
    vector<int> x(N);
    for (int i = 0; i < N; i++){
        cin >> x[i];
    }
    ll dp[55][2555]; memset(dp,0LL,sizeof(dp));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++){  
        for (int j = 50; j >= 0; j--){
            for (int num = 2550; num >= 0; num--){
                if (dp[j][num-x[i]] && num >= x[i]){
                    dp[j+1][num] += dp[j][num-x[i]];
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 1; i <= N; i++){
        for (int num = 0; num < 2550; num++){
            if (dp[i][num] && num % i == 0 && num/i == A){
                //cout << "i : " << i << ", num : " << num << ", size : " << dp[i][num] << endl;
                ans += dp[i][num];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
s = input()
n = len(s)
def check(x):
    for i in range(len(x)):
        if x[i] != x[-1-i]:
            return False
    return True

if check(s) and check(s[:(n-1)//2]) and check(s[(n+1)//2:]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAX =1e5+6;
const long long inf=1e18;
const int mod=1e9+7;
vector<int>adj[MAX];

int main(){
    int a, b;
    cin>>a>>b;
    if(a>9||b>9)
        cout<<-1;
    else
        cout<<a*b;
}

Measured memory_bytes: 2560
n,a,b = gets.strip.split.map(&:to_i)

def digit_sum n
    sum = 0
    while n > 0 do
        sum += n%10
        n /= 10
    end
    sum
end

ans = (1..n)
        .map {|i| [i,digit_sum(i)]}
        .select {|d| a <= d[1] && d[1] <= b}
        .inject(0) {|sum,d| sum + d[0]}

puts ans

Measured memory_bytes: 14592
#include <bits/stdc++.h>
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
 
const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;
 
int main()
{
	int n, k, s;
	scanf("%d%d%d", &n, &k, &s);
	if(s != inf){
		for(int i = 0; i < k; i++)
			printf("%d ", s);
		for(int i = k; i < n; i++)
			printf("%d ", s + 1);
	}else{
		for(int i = 0; i < k; i++)
			printf("%d ", s);
		for(int i = k; i < n; i++)
			printf("%d ", s - 1);
	}
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int l,r,d;cin >> l >> r >> d;
    cout << r/d-(l-1)/d << endl;
}

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

int main(){

  int a,b;

  cin>>a>>b;

  int ans=0;
  ans+=max(a,b);

  if(a==max(a,b)){
	a-=1;
  }else{
	b-=1;
  }

  cout<<ans+max(a,b)<<endl;
  
  
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
Int p,q,a,n;
Int cnt;

void dfs(Int s,Int m,Int x,Int y){  
  if(s*q>=m*p){
    if(s*q==m*p) cnt++;
    return;
  }
  if(y==n) return;
  for(Int i=x;m*i<=a;i++){
    Int ns=s*i+m;
    Int nm=m*i;
    dfs(ns,nm,i,y+1);
  }  
}

signed main(){
  while(cin>>p>>q>>a>>n,n){
    cnt=0;
    dfs(0,1,1,0);
    cout<<cnt<<endl;
  }  
  return 0;
}



Measured memory_bytes: 3004
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9+7
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] && s[0] == s[2] && s[1] == s[2]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    
    int main(){
        ll n , k ;
        cin >> n >> k;
        ll ans;
        ans = (n - 1) / (k - 1);
        if( (n - 1) % (k - 1) != 0){
            ans += 1;
        }
        cout << ans << endl;
        
        return 0;
        
    }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <numeric>
using namespace std;

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    char pre = S[0];
    int ans = 1;
    for (int i = 1; i < N; ++i)
    {
        if(pre != S[i] ){
            pre = S[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int board[255][255],dx[] = {1,-1,0,1},dy[] = {0,1,1,1};
int main(){
	int n,tx,ty,cnt,max;
	string str;
	while(cin >> n,n){
		max = 0;
		for(int i = 0;i < n;++i){
			cin >> str;
			for(int j = 0;j < str.size();++j){
				board[i][j] = (int)(str[j] - '0');
			}
		}
		for(int i = 0;i < n;++i){
			for(int j = 0;j < n;++j){
				if(board[i][j] == 1){
					for(int k = 0;k < 4;++k){
						cnt = 1;
						tx = j + dx[k];
						ty = i + dy[k];
						while(0 <= tx && 0 <= ty && tx < n && ty < n && board[ty][tx] == 1){
							++cnt;
							tx += dx[k];
							ty += dy[k];
						}
						if(cnt > max) max = cnt;
					}
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

Measured memory_bytes: 1456
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
using namespace std;
typedef pair<int, int> P;

struct UnionFind {
	vector<int> par;
	vector<int> d;
	int cnt;
	UnionFind(int size_) : par(size_, -1), d(size_), cnt(size_) {}
	void unite(int x, int y, int w) {
		P px = find(x), py = find(y);
		if(px.first != py.first) {
			if(par[py.first] < par[px.first]) swap(px, py), w *= -1;
			par[px.first] += par[py.first];
			par[py.first] = px.first;
			d[py.first] = px.second - py.second - w;
			cnt--;
		}
	}
	bool same(int x, int y) {
		return find(x).first == find(y).first;
	}
	P find(int x) {
		if(par[x] < 0) return P(x, 0);
		P res = find(par[x]);
		par[x] = res.first;
		d[x] += res.second;
		return P(par[x], d[x]);
	}
	int size() { return cnt; }
};

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

	int N, M;
	while(cin >> N >> M, N | M) {
		UnionFind uf(N);
		while(M--) {
			char c; int a, b, diff;
			cin >> c >> a >> b;
			a--, b--;
			if(c == '!') {
				cin >> diff;
				if(uf.same(a, b)) continue;
				uf.unite(a, b, diff);
			}
			else {
				if(uf.same(a, b)) {
					int w1 = uf.find(a).second, w2 = uf.find(b).second;
					cout << w1 - w2 << endl;
				}
				else {
					cout << "UNKNOWN" << endl;
				}
			}
		}
	}
}

Measured memory_bytes: 3592
"use strict";

const Main = args => {
  const input = args.trim().split("\n");
  const N = parseInt(input[0]);
  const T_arg = input[1].split(" ").map(e => parseInt(e));
  const M = parseInt(input[2]);
  const drink_arg = input.slice(3).map(e => e.split(' ').map(e => parseInt(e)));
  const result = drink_arg.map(e => {
    const P = e[0];
    const X = e[1];
    return T_arg.reduce((prev, curr, i) => {
      if (i === P - 1) {
        return prev + X;
      } else {
        return prev + curr;
      }
    }, 0);
  })
  console.log(result.join('\n'));
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7848
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[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" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{n:usize,m:usize,p:[(i64,i64);n], q:[(i64,i64);m]};
    for i in 0..n {
        let mut mn = INF_I64;
        let mut idx = 0;
        for j in 0..m {
            let d = (p[i].0 - q[j].0).abs() + (p[i].1 - q[j].1).abs();
            if mn > d {
                mn = d;
                idx = j;
            }
        }
        println!("{}", idx+1);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline void goodbye(const T& val) { cout << val << endl; exit(0); }

vector<ll> a;
int n;
vector<pii> answ;

void add(int i, int j) {
	a[j] += a[i];

	answ.emplace_back(i, j);
}

void solve() {
	int n;
	cin >> n;

	for(int i = 0; i < n; ++i) {
		a.push_back(fetch<ll>());
	}

	int max_abs = 0;

	for(int i = 1; i < n; ++i) {
		if(abs(a[i]) > abs(a[max_abs])) {
			max_abs = i;
		}
	}

	for(int i = 0; i < n; ++i) {
		if(i != max_abs) {
			add(max_abs, i);
		}
	}

	if(a[max_abs] >= 0) {
		for(int i = 1; i < n; ++i) {
			add(i - 1, i);
		}
	} else {
		for(int i = n - 2; i >= 0; --i) {
			add(i + 1, i);
		}
	}

	DBG(a);

	cout << len(answ) << '\n';

	for(auto& pr: answ) {
		cout << pr.first + 1 << ' ' << pr.second + 1 << '\n';
	}
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
  int n = 0;
  int inputnum1 = 0;
  int inputnum2 = 0;
  int sum = 0;
  
  std::cin >> n;
  
  for(int i=0; i<n; i++){
    std::cin >> inputnum1;
    std::cin >> inputnum2;
    sum += (inputnum2 - inputnum1 + 1);
  }
  
  std::cout << sum;
  
  return 0;
}


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

int main()
{
	string s;
	cin >> s;
	int now = s.size()-1;
	bool ng = false;
	while(now >= 0) {
		if(s[now] == 'r' && now >= 5) {
			if(s[now-5] =='e' && s[now-4] =='r' && s[now-3] == 'a' && s[now-2] == 's' && s[now-1] == 'e') {
				now-=6;
			} else if(now>=6 && s[now-6] =='d' && s[now-5] =='r' && 
				s[now-4] =='e' && s[now-3] =='a' && s[now-2] == 'm' && s[now-1] == 'e' ) {
				now-=7;
			} else {
				ng = true;
			}
		} else if(s[now] == 'm' && now >= 4) {
			if(s[now-4] =='d' && s[now-3] == 'r' && s[now-2] == 'e' && s[now-1] == 'a') {
				now-=5;			
			} else {
				ng = true;
			}
		} else if(s[now] == 'e' && now >= 4) {
			if(s[now-4] =='e' && s[now-3] == 'r' && s[now-2] == 'a' && s[now-1] == 's') {
				now-=5;
			} else {
				ng = true;
			}
		} else {
			ng = true;
		}
		if(ng) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <string>

using namespace std;
using ll = long long int;

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

int main(){
    string S;
    cin >> S;
    ll N = S.length();

    vector<ll> nums;

    ll num = 0;
    char last = 'R';
    rep(i, N){
        if(last == S[i]){
            num++;
        }else{
            nums.push_back(num);
            last = S[i];
            num = 1;
        }
    }
    nums.push_back(num);

    vector<ll> ret(N, 0);
    ll crr = 0;
    for(ll i = 0; i < nums.size(); i += 2){
        ll base = crr + nums[i] - 1;
        ret[base] += (nums[i] + 1) / 2;
        ret[base+1] += nums[i] / 2;
        ret[base+1] += (nums[i+1] + 1) / 2;
        ret[base] += nums[i+1] / 2;
        crr += nums[i] + nums[i+1];
    }
    
    rep(i, N){
        if(i) cout << " ";
        cout << ret[i];
    }
    cout << endl;
}



Measured memory_bytes: 2292
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int M, C;
int A[22];
int B[22];

bool AC() {
    int val = C;
    rep(i, M) {
        val += A[i] * B[i];
    }
    return val > 0;
}

signed main() {
    int N;
    cin >> N >> M >> C;
    rep(i, M) {
        cin >> B[i];
    }
    int ans = 0;
    rep(i, N) {
        rep(j, M) {
            cin >> A[j];
        }
        ans += AC();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include <vector>
#include<algorithm>
using namespace std;
int main(void){
	char a[100010];
	int n;
	int z;
	scanf("%s", a);
	n = strlen(a);
	if (a[0] == a[1]){
		printf("1 2\n");
		return 0;
	}
	if (a[n - 2] == a[n - 1]){
		printf("%d %d\n", n - 1, n);
		return 0;
	}
	z = 0;
	for (int i = 0; i < n - 2; i++){
		if (a[i] == a[i + 1])z++;
		if (a[i] == a[i + 2])z++;
		if (a[i + 1] == a[i + 2])z++;
		if (z > 0){
			printf("%d %d\n", i + 1, i + 3);
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int B[] = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			B[0] += A[i];
			if(i % 2 == 1) {
				B[0] -= A[i] * 2;
			}
		}
		
		for(int i = 1; i < N; i++) {
			B[i] = (A[i - 1] - B[i - 1] / 2) * 2;
		}
		for(int i = 0; i < N - 1; i ++) {
			System.out.print(B[i] + " ");
		}
		System.out.println(B[N - 1]);
	}
}


Measured memory_bytes: 65600
while True:
  n = int(input())
  if n == 0:
    break
  y = int(input())
  max_x = 0
  max_n = -1
  for _ in range(n):
    b, r, t = map(int, input().split())
    if t == 1:
      x = (1 + y * r / 100)
    else:
      x = (1 + r / 100) ** y
    if x > max_x:
      max_x = x
      max_n = b
  print(max_n)


Measured memory_bytes: 5684
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
	int N;
	cin>>N;
	vector<pair<int,int>> BA(N);
	for(int i=0;i<N;i++){
		cin >> BA[i].second>>BA[i].first;
	}
	sort(BA.begin(),BA.end());
	int sum=0;
	bool pro=true;
	for(int i=0;i<N;i++){
		sum+=BA[i].second;
		if(sum>BA[i].first){
			pro=false;
			break;
		}
	}
	if(pro)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

	

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

typedef enum{A=0, C=1, G=2, T=3} ACGT;

int memo[100][4][4][4];

bool good(ACGT last4[])
{
  ACGT c0 = last4[0];
  ACGT c1 = last4[1];
  ACGT c2 = last4[2];
  ACGT c3 = last4[3];

  // AGC
  if ((c0 == A && c1 == G && c2 == C) ||
      (c1 == A && c2 == G && c3 == C)){ return false; }

  // GAC
  if ((c0 == G && c1 == A && c2 == C) ||
      (c1 == G && c2 == A && c3 == C)){ return false; }

  // ACG
  if ((c0 == A && c1 == C && c2 == G) ||
      (c1 == A && c2 == C && c3 == G)){ return false; }

  // A?GC || AG?C
  if ((c0 == A && c2 == G && c3 == C) ||
      (c0 == A && c1 == G && c3 == C)){ return false; }

  return true;
}

long search(int n, const ACGT last3[])
{
  const long M = 1000000007ULL;
  ACGT a[4] = {A, C, G, T};

  long ret = memo[n][last3[0]][last3[1]][last3[2]];
  if (ret > 0){ return ret; }
  
  if (n == 0){ return 1; }

  ret = 0;
  if (ret > 0){ return ret; }

  for (int i = 0; i < 4; i++){
    ACGT c = a[i];
    ACGT last4[4] = {last3[0], last3[1], last3[2], c};
    if (good(last4)){
      ACGT new_last3[3] = {last3[1], last3[2], c};
      ret = (ret + search(n-1, new_last3)) % M;
    }
  }

  memo[n][last3[0]][last3[1]][last3[2]] = ret;
  return ret;
}

      

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

  ACGT ttt[3] = {T, T, T};
  cout << search(n, ttt) << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    int fast,last;
    cin>>a>>b>>c>>d;
    if(a>c)
    {
        fast=a;
    }
    else
    {
        fast=c;
    }
    if(b<d)
    {
        last=b;
    }
    else
    {
        last=d;
    }
    if(fast>last)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<last-fast<<endl;
    }
    
    return 0;
}

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

V kai;
V ikai;
ll mod=1e9+7;

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a,ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ikai[a-b]*ikai[b] % mod;
    return tmp * kai[a] % mod;
}

int main() {
    ll n;
    cin>>n;
    V a(n+1);
    vector<bool> used(n+1,false);
    ll num;
    rep(i,n+1){
        cin>>a[i];
        if(used[a[i]-1])num=a[i];
        used[a[i]-1]=true;
    }
    V pos;
    rep(i,n+1)if(a[i]==num)pos.push_back(i);
    kai.assign(1e6+1,0);
    ikai.assign(1e6+1, 0);
    kai[0]=1;
    ikai[0]=1;
    rep(i,1e6){
        kai[i+1]=kai[i]*(i+1);
        kai[i+1]%=mod;
        ikai[i+1]=ikai[i]*mpow(i+1, mod-2);
        ikai[i+1]%=mod;
    }
    for(ll k=1;k<=n+1;k++){
        ll res=comb(n+1,k);
        res-=comb(pos[0]+n-pos[1],k-1);
        res=(res+mod)%mod;
        cout<<res<<endl;
    }
}


Measured memory_bytes: 17664