akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N=2e5+3;
int a[N];
int main()
{
    ft
    int t,i,j,n,m,l=0,r;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        if(a[i]==1)
        {
            l=1;
            break;
        }
    }
    if(l==0)
    {
        cout<<"-1\n";
    }
    else
    {
        l=1;
        for(i=0;i<n;i++)
        {
            if(a[i]==l)
            {
                l++;
            }
        }
        cout<<(n-l+1)<<"\n";
    }
    return 0;
}

Measured memory_bytes: 1024
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    h = A[0]
    for i in range(1, N):
        ans += max(0, h - A[i])
        h = max(h, A[i])
    print(ans)


if __name__ == '__main__':
    main()

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

#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()

#define rep(i,n) for(int i=0;i<n;++i)
#define Rep(i,a,n) for(int i=a;i<=n;++i)
#define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mset multiset
#define pqueue priority_queue
#define umap unordered_map
 
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

const double PI=acos(-1),eps=1e-9;
const int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
const int N=3e5+5,mod=2019,inf=1e9;

bool check(ll x,vector<ll>&a,ll n){
	vector<ll>b=a,ans(n);
	ans[0]=x;
	b[0]-=ans[0]/2;
	b[n-1]-=ans[0]/2;	
	for(ll i=1;i<n;i++){
		ans[i]=b[i-1]*2;
		b[i]-=ans[i]/2;
		b[i-1]-=ans[i]/2;
	}
	bool ok=1;
	for(ll i=0;i<n;i++){
		if(b[i]){
			ok=0;
			break;	
			}
	}
	return ok;
}

void printAns(ll x,vector<ll>&a,ll n){
	vector<ll>b=a,ans(n);
	ans[0]=x;
	b[0]-=ans[0]/2;
	b[n-1]-=ans[0]/2;	
	for(ll i=1;i<n;i++){
		ans[i]=b[i-1]*2;
		b[i]-=ans[i]/2;
		b[i-1]-=ans[i]/2;
	}
	for(ll i=0;i<n;++i){
		cout<<ans[i]<<' ';
	}
}


void solve(){
	ll n;
	cin>>n;
	vector<ll>a(n);
	ll x=0;
	for(ll i=0;i<n;++i){
		cin>>a[i];
		if(i%2)x-=a[i];
		else x+=a[i];
	}
	printAns(x,a,n);
	
}

int main(){
	Speed();
	int T=1;
	//cin>>T;
	while(T--)solve();
}



Measured memory_bytes: 5564
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node
{
    int key;
    struct node *next;
    struct node *prev;
};
typedef struct node *NodePointer;
NodePointer nil;
NodePointer listSearch(int key)
{
    NodePointer i;
    for (i = nil; i->next != nil; i = i->next)
    {
        if (i->next->key == key)
            return i->next;
    }
    return NULL;
}
void init()
{
    nil = malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
}
void printList()
{
    NodePointer cur = nil->next;
    int isf = 1;
    while (1)
    {
        if (cur == nil)
            break;
        if (isf == 0)
            printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
    printf("\n");
}
void deleteNode(NodePointer t)
{
    t->next->prev = t->prev;
    t->prev->next = t->next;
    free(t);
}
void deleteFirst()
{
    NodePointer t = nil->next;
    if (t == nil)
        return;
    deleteNode(t);
}
void deleteLast()
{
    NodePointer i;
    i = nil->prev;
    deleteNode(i);
}
void delete (int key)
{
    NodePointer i;
    i = listSearch(key);
    if (i != NULL)
        deleteNode(i);
}
void insert(int key)
{
    NodePointer x;
    x = malloc(sizeof(struct node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}
int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++)
    {
        scanf("%s%d", com, &key);
        if (com[0] == 'i')
        {
            insert(key);
            np++;
            size++;
        }
        else if (com[0] == 'd')
        {
            if (strlen(com) > 6)
            {
                if (com[6] == 'F')
                    deleteFirst();
                else if (com[6] == 'L')
                    deleteLast();
            }
            else
            {
                delete (key);
                nd++;
            }
            size--;
        }
    }
    printList();
    return 0;
}



Measured memory_bytes: 33024
#include <algorithm>
#include <cstdio>
#include <cstring>

const int MaxN = 3000, MaxLen = MaxN * 2;

int N;
char S[MaxLen + 5];
int A[MaxN + 5], B[MaxN + 5];
char F[MaxN + 5][MaxLen + 5], G[MaxN + 5][MaxLen + 5];
int CntA, CntB;

void init() {
  scanf("%d", &N);
  scanf("%s", S + 1);
  for (int i = 1; i <= N * 2; ++i)
    if (S[i] == 'a') A[++CntA] = i;
    else B[++CntB] = i;
}

void solve() {
  for (int i = N; i >= 1; --i) {
    if (A[i] < B[i]) {
      F[i][1] = 'a', F[i][2] = 'b';
      for (int j = i; j <= N; ++j) {
        if (j == N || A[j + 1] > B[i]) {
          strcpy(F[i] + 3, G[j + 1] + 1);
          break;
        }
      }
    } else {
      for (int j = i; j <= N; ++j) {
        if (j == N || B[j + 1] > A[i]) {
          int cnt = 0;
          for (int k = i; k <= j; ++k) F[i][++cnt] = 'b';
          F[i][++cnt] = 'a';
          if (i == j) strcpy(F[i] + cnt + 1, G[i + 1] + 1);
          else strcpy(F[i] + cnt + 1, F[i + 1] + j - i + 1);
          break;
        }
      }
    }
    if (strcmp(F[i] + 1, G[i + 1] + 1) < 0) strcpy(G[i] + 1, G[i + 1] + 1);
    else strcpy(G[i] + 1, F[i] + 1);
    // printf("F[%d] = %s, G = %s\n", i, F[i] + 1, G[i] + 1);
  }
  printf("%s\n", G[1] + 1);
}

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

Measured memory_bytes: 34548
#include<iostream>
#include<algorithm>
using namespace std;
int h[100000];
int main(){
	int n,k;
	cin >> n >> k;
	for(int i=0;i<n;i++) cin >> h[i];
	sort(h,h+n);
	int ans=1e9;
	for(int i=0;i<=n-k;i++) ans=min(ans,h[i+k-1]-h[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SyntheticKadomatsu solver = new SyntheticKadomatsu();
        solver.solve(1, in, out);
        out.close();
    }

    static class SyntheticKadomatsu {
        List<Integer> l;
        List<Integer> abc;
        int n;
        int a;
        int b;
        int c;
        int result = Integer.MAX_VALUE;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            n = in.nextInt();
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            l = new ArrayList<>();
            abc = new ArrayList<>();

            abc.add(a);
            abc.add(b);
            abc.add(c);

            for (int i = 0; i < n; i++) {
                l.add(in.nextInt());
            }

            for (int bit = 0; bit < (1 << (2 * n)); bit++) {
                List<List<Integer>> d = new ArrayList<>();
                // a,b,c,none
                for (int i = 0; i < 4; i++) {
                    d.add(new ArrayList<>());
                }
                for (int i = 0; i < n; i++) {
                    int index = (bit >> (2 * i)) & 3;
                    d.get(index).add(l.get(i));
                }

                boolean zero_exists = false;
                for (int i = 0; i < 3; i++) {
                    if (d.get(i).size() == 0) {
                        zero_exists = true;
                        break;
                    }
                }

                if (zero_exists) {
                    continue;
                }

                int score = 0;
                for (int i = 0; i < 3; i++) {
                    score += 10 * (d.get(i).size() - 1);
                    int total = 0;
                    for (Integer num : d.get(i)) {
                        total += num;
                    }
                    score += Math.abs(abc.get(i) - total);
                }
                result = Math.min(result, score);
            }

//        recursive(0, 0, 0, 0, 0);
            out.println(result);
        }

    }
}



Measured memory_bytes: 56336
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n, W;
ll w[111];
ll v[111];
ll dp[111][100001];

int main()
{
	cin >> n >> W;
	for (int i = 0;i < n;i++) {
		cin >> w[i] >> v[i];
	}

	dp[0][v[0]] = w[0];

	for (int i = 1;i < n;i++) {
		for (int j = 0;j < 100001;j++) {
			dp[i][j] = dp[i - 1][j];
			if (j - v[i] >= 0 && dp[i - 1][j - v[i]]) {
				if (dp[i][j] > 0) {
					dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
				}
				else {
					dp[i][j] = dp[i - 1][j - v[i]] + w[i];
				}
			}
			if (v[i] == j) {
				if (dp[i][j] > 0) dp[i][j] = min(dp[i][j], w[i]);
				else dp[i][j] = w[i];
			}
		}
	}

	int ans = 0;
	for (int i = 0;i < 100001;i++) {
		if (dp[n - 1][i] > 0 && dp[n - 1][i] <= W) {
			ans = max(ans, i);
		}
	}

	cout << ans << endl;

	return 0;
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if (a + b >= c){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

const int MAX = 10000;

int main() {
	int N;
	cin >> N;
	int a[MAX], b[MAX];
	ll numPlusBi=0, numMinusAi=0;

	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> b[i];
	}

	for (int i = 0; i < N; ++i) {
		if (a[i] - b[i] > 0) {
			numPlusBi += (a[i] - b[i]);
		}
		else if (b[i] - a[i] >1) {
			numMinusAi += (b[i] - a[i])/2;
		}
	}

	if (numMinusAi >= numPlusBi) cout << "Yes";
	else cout << "No";

	system("pause");
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

string str(P p){
    stringstream ss;
    ss << p.first << ", " << p.second;
    return ss.str();
}

P ab[10][10];
P hoge[10][70];
P add(P A, P B){
    return P(A.first + B.first + ab[A.second][B.second].first, ab[A.second][B.second].second);
}

void init(){
    rep(a, 10)rep(b, 10){
        if(a + b <= 9)ab[a][b] = P(1, a + b);
        else ab[a][b] = P(2, (a + b - 9));
    }
    rep(a, 10)hoge[a][0] = P(0, a);
    rep1(i, 68){
        rep(a, 10){
            hoge[a][i] = add(hoge[a][i - 1], hoge[a][i - 1]);
        }
    }
}

P calc(ll a, ll b){
    P tmp(0, 0);
    ll flg = 1;
    for(ll i = 0; b; i++){
        if((1LL << i) & b){
            if(flg){
                flg = 0;
                tmp = hoge[a][i];
            }
            else tmp = add(tmp, hoge[a][i]);
            b ^= (1LL << i);
        }
    }
    return tmp;
}

int main(){
    init();
    // rep(i, 10)cout << i << " : " << str(calc(9, i)) << endl;
    // cout << str(calc(9, 100)) << endl;
    // cout << str(calc(9, 10000)) << endl;
    // cout << str(calc(9, 1000000000LL)) << endl;
    // cout << str(calc(9, 10000000000LL)) << endl;
    // cout << str(calc(9, 100000000000LL)) << endl;
    // cout << str(calc(9, 1000000000000LL)) << endl;
    // cout << str(calc(9, 1000000000000000LL)) << endl;
    // return 0;
    ll M;
    cin >> M;
    P tmp(0, 0);
    rep(i, M){
        ll a, b;
        cin >> a >> b;
        if(i == 0)tmp = calc(a, b);
        else tmp = add(tmp, calc(a, b));
    }
    cout << tmp.first << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;
int n;
vector<pii>p[100100];

bool v[100100];
ll res[100100];
bool b = 0;
void dfs(int x){
    for(int i=0 ;i <p[x].size() ;i ++){
        if(v[p[x][i].fr] && res[p[x][i].fr] != res[x]+p[x][i].sc){
            b = 1;
        }
        if(v[p[x][i].fr])continue;
        res[p[x][i].fr] = res[x]+p[x][i].sc;
        v[p[x][i].fr] = 1;
        dfs(p[x][i].fr);
    }
}

int main()  {
    int m;
    cin>>n>>m;
    int x,y,d;
    for(int i=0 ;i <m ;i ++){
        scanf("%d%d%d",&x,&y,&d);
        p[x].push_back(mp(y,d));
        p[y].push_back(mp(x,-d));
    }
    for(int i=1; i<=n ;i ++){
        if(!v[i]){
            v[i] = 1;
            res[i] = 0;
            dfs(i);
        }

    }
    if(!b){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;
}


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

int main(){
  int a,b,i,j,ans[101]={};
  string red[101],blue[101];
  cin>>a;
  for(i=0;i<a;i++){
    cin>>red[i];
  }
  cin>>b;
  for(i=0;i<b;i++){
    cin>>blue[i];
  }
  for(i=0;i<a;i++){
    for(j=0;j<a;j++){
      ans[i]+=(red[i]==red[j]);
    }
    for(j=0;j<b;j++){
      ans[i]-=(red[i]==blue[j]);
    }
  }
  sort(ans,ans+a);
  if(ans[a-1]<=0){
    cout<<0<<endl;
  }else{
    cout<<ans[a-1]<<endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  if(n == 3){
    cout << "YES" << endl;
  }
  else if(n == 5) {
    cout << "YES" << endl;
  }
  else if(n == 7) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int n;
    cin >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    rep2(i, 1, n) {
        if (a[i] < a[i - 1] || b[i] < b[i - 1]) {
            int t = max((a[i - 1] + a[i] - 1) / a[i], (b[i - 1] + b[i] - 1) / b[i]);
            a[i] *= t;
            b[i] *= t;
        }
    }
    cout << a.back() + b.back() << endl;
}


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

using namespace std;

int main(){
int N,M; cin >> N >> M;
  vector<vector<bool>> E(N,vector<bool>(N,false));
  for(int i = 0; i < M; i++){
    int u,v; cin >> u >> v; u--; v--;
    E[u][v] = true; E[v][u] = true;}
  
  vector<int> p(N - 1);
  for(int i = 0; i < N - 1; i++){
    p[i] = i + 1;} 
  int cnt = 0;
  do{
    bool flag = true;
  // 0 →　p[0] → ___ → p[N-2] まで全て直接繋がっているかを調べる
  for(int i = 0; i < N - 1; i++){
    if( i == 0){ //この場合は 0 → p[0]を調べる必要がある
      if(E[0][p[0]] == false){ flag = false;}}
    else {
    if( E[p[i-1]][p[i]] == false){ flag = false;}}}
    
   if( flag){ cnt++;}
  } while( next_permutation(p.begin(),p.end()));
    
          cout << cnt << endl; return 0;}

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

int ans(string s) {
	if (s.length() == 1) return s[0] - '0';
	if (s[0] == '9' && s[1] != '9') return 9 * s.length() - 1;
	if (s[0] == '9' && s[1] == '9') return 9 + ans(s.substr(1, s.length() - 1));
	if (s[0] != '9' && s[1] == '9') return s[0] - '0' + ans(s.substr(1, s.length() - 1));
	if (s[0] != '9' && s[1] != '9') return s[0] - '0' - 1 + 9 * (s.length() - 1);
}

int main() {
	string N;
	cin >> N;
	cout << ans(N) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[100], b[100]; long long dp[100][101];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= n; j++) dp[i][j] = j - i - 1 ? (1LL << 60) : 0;
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 0; i + j <= n; j++) {
			for (int k = j; k < i + j; k++) dp[j][i + j] = min(dp[j][i + j], dp[j][k] + dp[k][i + j] + a[j] * b[k - 1] * a[k] * b[i + j - 1]);
		}
	}
	cout << dp[0][n] << endl;
	return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int gcd(int n, int m) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int r = n % m;
        n = m;
        m = r;
    }
    return n;
}

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

    ll r = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            int t = gcd(i, j);
            for (int k = 1; k <= n; k++) {
                r += gcd(t, k);
            }
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e,f,g,h;
    cin>>a>>b>>c>>d>>e>>f>>g>>h;
    if(a+b+c+d>e+f+g+h)
    cout<<a+b+c+d<<endl;
    else if(a+b+c+d<e+f+g+h)
    cout<<e+f+g+h<<endl;
    else 
    cout<<a+b+c+d<<endl;
}



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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vi a(n);
	int ind = 0, ab = 0;
	REP(i, n){
		cin >> a[i];
		if(abs(a[i]) > ab){
			ab = abs(a[i]);
			ind = i;
		}
	}
	cout << 2 * (n - 1) << "\n";
	REP(i, n){
		if(i == ind) continue;
		cout << ind + 1 << " " << i + 1 << "\n";
	}
	if(a[ind] < 0){
		RREP(i, n - 1){
			cout << i + 2 << " " << i + 1 << "\n";
		}
	}
	else{
		REP(i, n - 1){
			cout << i + 1 << " " << i + 2 << "\n";
		}
	}
	return 0;
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n,m;
  cin>>n>>m;
  while(n!=0){
    //dp初期化
    VEC2(dp,n+1,256);
    FOR(i,0,n+1) FOR(j,0,256) dp[i][j] = 1e12;
    dp[0][128] = 0;

    vector<ll> code(m);
    vector<ll> pls(n);
    cinv(code,0,m);
    cinv(pls,0,n);
    FOR(i,0,n){
      FOR(j,0,256){
        FOR(k,0,code.size()){
          ll pos = j + code[k];
          if(pos<0) pos=0;
          if(pos>255) pos=255;
          ll x = dp[i][j] + ( pls[i] - pos )*( pls[i] - pos );
          dp[i+1][pos] = min(dp[i+1][pos], x);

        }
      //cout<<"i = "<< i <<"j = "<<j-255 <<" " <<dp[i][j]<<endl;
      }
    }
    ll res = 1e15;
    FOR(i,0,256){
      res = min(dp[n][i], res);
    }
    cout<<res<<endl;
    cin>>n>>m;
  }

}



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

int main(){
    ll n;
    cin >> n;
    vector<ll> cnt(26);
    rep(i,n){
        string s;
        cin >> s;
        cnt[s[0]]++;
    }
    ll sum = 0;
    sum += cnt['M']*cnt['A']*cnt['R'];
    sum += cnt['M']*cnt['A']*cnt['C'];
    sum += cnt['M']*cnt['A']*cnt['H'];
    sum += cnt['M']*cnt['R']*cnt['C'];
    sum += cnt['M']*cnt['R']*cnt['H'];
    sum += cnt['M']*cnt['C']*cnt['H'];
    sum += cnt['A']*cnt['R']*cnt['C'];
    sum += cnt['A']*cnt['R']*cnt['H'];
    sum += cnt['A']*cnt['C']*cnt['H'];
    sum += cnt['R']*cnt['C']*cnt['H'];
    cout << sum << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll c[100005];
ll ans,n,w;
ll a[100005],b[1000005];
int main()
{
	ll i,j,k,x,y,t;
	cin>>n>>w;
	for(i=1;i<=n;i++)
	cin>>a[i]>>b[i];
	for(i=1;i<=n;i++)
		for(j=w;j>=a[i];j--)
		c[j]=max(c[j],c[j-a[i]]+b[i]);
	
	cout<<c[w];
	return 0;
}


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

typedef long long ll;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define clr(a, b) memset(a, b, sizeof(a))
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int n;
    cin >> n;
    set<int> st;
    forn(i, n) {
        int x;
        cin >> x;
        st.insert(x);
    }
    if((int)st.size() == n)
        cout<<"YES\n";
    else
        cout <<"NO\n";
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
const int N(505);
char s[N][N];
int c[N], r[N], inf(1e9);
int a;
int n;
int u[N], v[N], uu[N], vv[N];
void dfs(int stp) {
	if(stp >= a) {
		return;
	}
	int cnt(0);
	for(int i(0); i < n; i++)
		for(int j(0); j < n; j++)
			if(s[i][j] == '#')
				cnt++;
	if(cnt == n * n) {
		a = min(a, stp);
		memcpy(vv, v, sizeof(v));
		memcpy(uu, u, sizeof(u));
		
		return;
	}
	char bak[n][n];
	for(int i(0); i < n; i++) {
		for(int j(0); j < n; j++) {
			bak[i][j] = s[i][j];
		}
	}
	
	for(int i(0); i < n; i++) {
		for(int j(0); j < n; j++) {
			char cur[n];
			for(int k(0); k < n; k++)
				cur[k] = s[i][k];
			for(int k(0); k < n; k++)
				s[k][j] = cur[k];
			u[stp] = i;
			v[stp] = j;
			dfs(stp + 1);
			for(int k(0); k < n; k++)
				for(int l(0); l < n; l++)
					s[k][l] = bak[k][l];
		}
	}
	
}
int main() {
	scanf("%d", &n);
	for(int i(0); i < n; i++) {
		scanf("%s", s[i]);
	}
	int cntNotFullCol(0);
	int tot(0);
	for(int i(0); i < n; i++) {
		int cnt(0);
		for(int j(0); j < n; j++) {
			cnt += s[j][i] == '#';
		}
		c[i] = cnt;
		cntNotFullCol += c[i] != n;
		cnt = 0;
		for(int j(0); j < n; j++) {
			cnt += s[i][j] == '#';
		}
		r[i] = cnt;
		tot += cnt;
	}
	if(tot == 0) {
		cout << -1 << endl;
		return 0;
	}
	int ans(inf);
	for(int i(0); i < n; i++) {
		int ans1(0);
		if(r[i] != n) {
			bool flag(false);
			for(int j(0); j < n; j++) {
				if(s[j][i] == '#') {
					flag = true;
					break;
				}
			}
			if(!flag) {
				ans1 ++;
			}
			ans1 += n - r[i];
		}
		ans1 += cntNotFullCol;
		ans = min(ans, ans1);
	}
	cout << ans << endl;
	
	/*a = 6;
	dfs(0);
	if(a == 6)
		a = -1;
	cout << a << endl;
	for(int i(0); i < a; i++)
		cout << uu[i] << ' ' << vv[i] << endl;
	assert(a == ans);*/
}

Measured memory_bytes: 512
/* ----------------------- reclone_rk --------------------------------------------*/ 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mod=1e9+7;

#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define prq priority_queue<int>
#define prqp priority_queue<pair<int,int>>
#define vtr vector<int>
#define INF INT_MAX
#define NINF INT_MIN
#define endl "\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pvtr vector<pair<int,int>>
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)

int gcd(int a, int b){ if(a == 0) return b; return gcd(b%a, a);}
int MOD(int n){ return ((n%mod)+mod)%mod;}
int power(int a,int b){ if(b==0)return 1LL;int s=power(a,b/2LL);s*=s;s%=mod;if(b&1LL)return (s*a)%mod;return s;}
int inv(int a){return power(a,mod-2);}
int nCr(int n,int r){if(r>n)return 0LL;if(n-r<r)r=n-r;int ans=1;for(int i=0;i<r;i++){ans*=(n-i);ans=MOD(ans);ans*=inv(i+1);ans=MOD(ans);}return ans;}

int pi = 3.14159265358979323846;
signed main()
{   
    int n, l;
    cin>>n>>l;
    vector<string>str(n);
    for(int i=0; i<n; i++)
    {
        string s;
        cin>>s;
        str[i] = s;
        // cout<<s<<endl;
    }
    sort(str.begin(), str.end());
    for(int i=0; i<n; i++)
        cout<<str[i];
	return 0;
}
// 56425719433005567605

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

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

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

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

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

int main(){
    double r; cin >> r;
    cout << fixed << setprecision(15) << 2 * r * 3.141592 << endl;
}

Measured memory_bytes: 3784
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

max_cnt=sum(b)-sum(a)
if max_cnt<0:
    print("No")
    exit()
b_cnt=0
a_cnt=0
for i in range(n):
    if a[i]>b[i]:
        b_cnt+=a[i]-b[i]
    elif a[i]<b[i]:
        a_cnt+=(b[i]-a[i])//2
print("Yes" if b_cnt<=a_cnt else "No")



Measured memory_bytes: 10308
import collections
N=int(input())
siritori=collections.defaultdict(int)
prev=" "
for i in range(N):
  word = input()
  if word in siritori:
    print("No")
    exit(0)
  elif prev[-1]!=word[0] and i != 0:
    print("No")
    exit(0)
  siritori[word]+=1
  prev=word
print("Yes")


Measured memory_bytes: 3316
n = readline()
n = parse(Int, n);
if n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 ==7 || n % 10 == 9
    println("hon")
elseif n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8
    println("pon")
else
    println("bon")
end


Measured memory_bytes: 152140
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

void update_divs(unordered_set<int64_t>& dividents, int64_t tmp) {
  vector<int64_t> updates;
  for (auto div : dividents) {
    updates.emplace_back(div * tmp);
  }
  for (auto update : updates) {
    dividents.emplace(update);
  }
  return;
}

int64_t num_divs(int64_t n) {
  if (n == 1) return 0;

  vector<int64_t> num_primes;
  int64_t tmp = n;
  for (int64_t i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (tmp % i == 0) {
      cnt++;
      tmp /= i;
    }
    if (cnt != 0)
      num_primes.push_back(cnt);
    if (tmp == 1) break;
  }
  if (tmp != 1) {
    num_primes.push_back(1);
  }
  int64_t cnt = 1;
  for (auto np : num_primes) {
    cnt *= (np + 1);
  }
  cnt--;
  return cnt;
}

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

  int64_t N;
  cin >> N; 
  int64_t res = 0;

  unordered_set<int64_t> dividents;
  dividents.emplace(1);
  int64_t tmp = N;
  for (int64_t i = 2; i * i  <= N; i++) {
    while (tmp % i == 0) {
      update_divs(dividents, i);
      tmp /= i;
    }
    if (tmp == 1) break;
  }
  if (tmp != 1) {
    update_divs(dividents, tmp);
  }

  //cout << "dump_divs :";
  //for (auto div : dividents) {
  //  cout << div << ",";
  //}
  //cout << endl;


  for (auto divs : dividents) {
    if (divs  == 1) continue;
    int64_t tmp = N;
    while (tmp % divs == 0) {
      tmp /= divs;
    }
    if (tmp == 1) {
  //    cout << divs << "is K(p1)" << endl;
      res++;
    } else {
      if ((tmp - 1) % divs == 0) {
   //     cout << divs << "is K(p2)" << endl;
        res++;
      }
    }
  }

  res += num_divs(N - 1);
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
// #include <atcoder/all>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) vc(vc(T))
using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int n;
  cin >> n;
  int c = 0;
  bool ans = false;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    if (a != b) c = 0;
    else {
      c++;
      if (c >= 3) ans = true;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll dp[101][100001];
int main(){
    int n,W,v[100],w[100];
    cin>>n>>W;
    rep(i,n) cin>>w[i]>>v[i];
    fill(dp[0],dp[0]+W+1,0);
    rep(i,n)rep(j,W+1){
        if(j>=w[i]) dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
        else dp[i+1][j]=dp[i][j];
    }
    cout<<dp[n][W]<<"\n";
}

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

int main(int argc, char const *argv[])
{
	int n, q;
	cin >> n >> q;
	int memo=0, tmp1, tmp2;
	for (int i = 0; i < q; ++i)
	{
		cin >> tmp1 >> tmp2;
		if(tmp1==0)
		{
			if(memo==0) cout << tmp2 << endl;
			else if(memo+tmp2-1>n) cout << memo+tmp2-1-n << endl;
			else cout << memo+tmp2-1 << endl;
		}
		else
		{
			if(memo==0) memo=tmp2+1;
			else if(tmp2<=n-memo) memo+=tmp2; //cut left
			else memo=tmp2-n+memo; //cut right
		}
	}
	return 0;
}


Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nm = Input.ar;
        var adj = Enumerable.Repeat(0, nm[0]).Select(_ => new List<int>()).ToArray();
        for(var i=0;i<nm[1];i++)
        {
            var ab = Input.ar.Select(v => --v).ToArray();
            adj[ab[0]].Add(ab[1]);
            adj[ab[1]].Add(ab[0]);
        }
        var co = new int[nm[0]];
        if (IsBipartite(adj, 0, co, 1))
            WriteLine((long)co.Count(v => v == 1) * co.Count(v => v == 2) - nm[1]);
        else WriteLine((long)nm[0] * (nm[0] - 1) / 2 - nm[1]);
    }
    public static bool IsBipartite(IList<IEnumerable<int>> edge,int index,int[] color,int c)
    {
        if (color[index] != 0) return color[index] == c;
        color[index] = c;
        var t = true;
        foreach (var ad in edge[index])
            t &= IsBipartite(edge, ad, color, 2 - (c >> 1));
        return t;
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static string[] strs(int n)
        => Enumerable.Repeat(0, n).Select(_ => read).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
    string S;
    cin >> S;
    int v_0 = 0, v_1 = 0;

    for (int i = 0; i < S.length(); i++) {
        if (S.at(i) == '0') v_0++;
        else v_1++;
    }
    
    cout << min(v_0, v_1) * 2 << endl;
    return 0;
}

Measured memory_bytes: 3756
days_in_month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

while True:
    m, d = map(int, input().split())
    if m == 0 or d == 0:
        break
    days = 0
    for month in range(0, m-1):
        days += days_in_month[month]
    days += d + 2
    days %= 7
    print(day[days])

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

if N==1:
    print(0)
    exit()

MOD=10**9+7

ALL=pow(10,N,MOD)
No0=pow(9,N,MOD)
No9=pow(9,N,MOD)
No09=pow(8,N,MOD)

ans=ALL-No9-No0+No09+MOD
print(ans%MOD)


Measured memory_bytes: 61864
#include<cstdio>
int main() {
    int a, b;
    char op;
    while (true) {
        scanf("%d %c %d", &a, &op, &b);
        if (op == '?' )break;
        else if (op == '+')printf("%d\n", a + b);
        else if (op == '-')printf("%d\n", a - b);
        else if (op == '*')printf("%d\n", a * b);
        else if (op == '/')printf("%d\n", a / b);
        else {}
    }
    return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define ll long long
#define mod 1000000007LL
#define INF 123456789012345
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e4 + 10;

int main() {
	
	int n;cin>>n;
	if(n%2) n*=2;

	cout << n<< endl;


	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
template<class T> bool umin(T &x,T y) { if (x<y) return 0; x=y; return 1; }
template<class T> bool umax(T &x,T y) { if (x>y) return 0; x=y; return 1; }
using ll = long long;
using ld = long double;

int const INF=1e9;

struct dist_func {
	ll l1,r1,l2,r2,m1,m2;
	vector<ll> ts;
	
	dist_func(ll a,ll b,ll c,ll d,ll e,ll f): l1(a),r1(b),l2(c),r2(d),m1(e),m2(f) {
		ts.push_back(0);
		while (true) {
			ll nt=find_next(ts.back());
			if (nt==INF) break;
			ts.push_back(nt);
		}
	}
	
	ll eval(ll t) const {
		return max({r1+t,r2-t,m2})-min({l1+t,l2-t,m1});
	}
	
	ll operator()(ll t) const {
		return eval(t);
	}
	
	ll find_next(ll t) {
		ll s=eval(t+1)-eval(t);
		ll l=t,r=INF;
		while (l<r) {
			ll m=l+(r-l)/2;
			if (eval(m+1)-eval(m)==s) l=m+1; else r=m;
		}
		return l;
	}
};

ll check(const dist_func &dx, const dist_func &dy,ll t) {
	return dx(t)*dy(t);
}

ll cross(const dist_func &d1, const dist_func &d2,ll l,ll r) {
	while (l<r) {
		ll m=l+(r-l)/2;
		if (d1(m)<d2(m)) l=m+1; else r=m;
	}
	return l;
}

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

	ll r1,r2,l1,l2,x1,x2,d1,d2,u1,u2,y1,y2;
	r1=l1=x1=d1=u1=y1=INF;
	r2=l2=x2=d2=u2=y2=-INF;
	
	int N;
	cin>>N;
	rep(i,0,N) {
		ll x,y;
		string s;
		cin>>x>>y>>s;
		x*=2;
		y*=2;
		switch (s[0]) {
			case 'R':
				umin(r1,x),umax(r2,x),umin(y1,y),umax(y2,y);
				break;
			case 'L':
				umin(l1,x),umax(l2,x),umin(y1,y),umax(y2,y);
				break;
			case 'U':
				umin(u1,y),umax(u2,y),umin(x1,x),umax(x2,x);
				break;
			case 'D':
				umin(d1,y),umax(d2,y),umin(x1,x),umax(x2,x);
				break;
			default:
				throw;
		}
	}
	
	dist_func dx(r1,r2,l1,l2,x1,x2);
	dist_func dy(u1,u2,d1,d2,y1,y2);

	ll res=check(dx,dy,0);
	for (ll t:dx.ts) umin(res,check(dx,dy,t));
	for (ll t:dy.ts) umin(res,check(dx,dy,t));
	//~ for (ll t1:dx.ts) for (ll t2:dy.ts) {
		//~ umin(res,check(dx,dy,cross(dx,dy,t1,t2)));
		//~ umin(res,check(dx,dy,cross(dy,dx,t2,t1)));
	//~ }
	cout<<ld(res)/4<<"\n";	
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int A[100][100], b[100], c[100];
int main(){
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		c[i] = 0;
	}
	for (int a = 0; a < n; a++){
		for (int g = 0; g < m; g++){
			cin >> A[a][g];
		}
	}
	for (int d = 0; d < m; d++){
		cin >> b[d];
	}
	for (int e = 0; e < n; e++){
		for (int f = 0; f < m; f++){
			c[e] += A[e][f] * b[f];
		}
	}
	for (int h = 0; h < n; h++){
		cout << c[h] << endl;
	}
	return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
#define LL long long
int A[N], B[N][210], L[N], R[N], S[N];
LL sum[N][N];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i < n; i++) scanf("%d", &A[i]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			scanf("%d", &B[i][j]);
	for (int i = 1; i <= m; i++) {
		int top = 0;
		for (int j = 1; j <= n; j++) {
			while (top && B[j][i] > B[S[top]][i])
				R[S[top--]] = j;
			L[j] = S[top]; S[++top] = j; 
		}
		for (int j = 1; j <= top; j++) R[S[j]] = n + 1;
		/*for (int j = 1; j <= n; j++)
			printf("[%d,%d] ", L[j], R[j]);
		puts("");*/
		for (int j = 1; j <= n; j++) {
			sum[L[j] + 1][j] += B[j][i];
			sum[L[j] + 1][R[j]] -= B[j][i];
			sum[j + 1][j] -= B[j][i];
			sum[j + 1][R[j]] += B[j][i];
		}
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			sum[i][j] += sum[i][j - 1];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			sum[i][j] += sum[i - 1][j];	
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		LL tmp = 0;
		for (int j = i; j <= n; j++) {
			ans = max(ans, sum[i][j] - tmp);
			/*if (ans == 13) {
				printf("%d %d %d %d\n", i, j, sum[i][j], tmp);
				return 0;
			}*/
			tmp += A[j];
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 200448
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  ll N, K; cin >> N >> K;

  ll ans = pow(N / K, 3);

  if (K % 2 == 0){
    if (N % K >= K / 2) ans += pow(N / K + 1, 3);
    else ans += pow(N / K, 3);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	int n, t;
	
	unsigned long long ans=1;
	cin >> n >> t;
	vector<int> v(n);
	REP(i, n) {
		cin >> v[i];
	}
	sort(ALL(v));
	REP(i, n) {
		auto j = lower_bound(ALL(v), v[i] - t)-v.begin();
		ans *= i + 1 - j;
		ans%=MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define ll long long
#define pp pair<int,int> 
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10);
 
int main(){
  int n;
  cin >> n;
  vector<double> x(n);
  vector<string> u(n);
  rep(i,n) cin >> x[i] >> u[i];
  long double ans=0;
  rep(i,n){
    if(u[i]=="JPY") ans+=x[i];
    else ans+=x[i]*380000;
  }
  cout << fixed << setprecision(5);
  cout << ans << endl;
}    

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = a[0]
out = 0
for i in range(1,n):
    ans *= a[i]
    if (ans > 1000000000000000000):
        out = 1
        break
if out:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 21560
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,Sum[1024][1024],a[1024][1024],Cnt[1024];
int read()
{
  char c=0;
  int sum=0;
  while (c<'0'||c>'9')
    c=getchar();
  while ('0'<=c&&c<='9')
    {
      sum=sum*10+c-'0';
      c=getchar();
    }
  return sum;
}
int lowbit(int x)
{
  return x&(-x);
}
int main()
{
  n=read(),m=read();
  for (int i=1;i<=(1<<max(n,m))-1;++i)
    Cnt[i]=Cnt[i-lowbit(i)]^1;
  for (int i=1;i<=(1<<n)-1;++i)
    for (int j=1;j<=(1<<m)-1;++j)
      Sum[i][j]=Cnt[i&j];
  for (int i=1;i<=(1<<n)-1;++i)
    for (int j=1;j<=(1<<m)-1;++j)
      a[i][j]=Sum[i][j]^Sum[i-1][j]^Sum[i][j-1]^Sum[i-1][j-1];
  for (int i=1;i<=(1<<n)-1;++i)
    {
      for (int j=1;j<=(1<<m)-1;++j)
        printf("%d",a[i][j]);
       puts("");
    }
  return 0;
}

Measured memory_bytes: 11356
#include <iostream>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

int main(void) {
    char c;
    cin >> c;
    if (c == 'a') {
        cout << "vowel" << endl;
    } else if (c == 'i') {
        cout << "vowel" << endl;
    } else if (c == 'u') {
        cout << "vowel" << endl;
    } else if (c == 'e') {
        cout << "vowel" << endl;
    } else if (c == 'o') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <string.h>
 
#define rep(i,n)    for(ll i=0;i<n;i++)
#define repu(i,k,n) for(ll i=k;i<=n;i++)
#define repd(i,k,n) for(ll i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define INF (ll)ll_MAX
 
typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector< ll > vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, ll > > vpp;
 
const ll N = 3*1e5 +5 ;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long inf = 1e18;
 
using namespace std;



void solve()
{	

    ll a,b,c;
    cin>>a>>b>>c;
    ll k;
    cin>>k;

    ll ctr = 0;
    while(b<=a){
        b*=2;
        ctr++;
    }
    while(c<=b){
        c*=2;
        ctr++;
    }

    if(ctr<=k){
        cout<<"Yes";
    }
    else cout<<"No";

    
}

int main() {

    // #ifndef ONLINE_JUDGE
    //     // for getting input from input.txt
    //     freopen("input.txt", "r", stdin);
    //     // for writing output to output.txt
    //     freopen("output.txt", "w", stdout);
    // #endif


    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll t = 1;
    // cin>>t;
    ll ctr=0;
    while(t--)
    {   
        ctr++;
        // cout<<"Case #"<<ctr<<": ";
        solve();    
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
}

Measured memory_bytes: 3800