akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);


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

    vector<int> cnts(n, 0);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        ++cnts[a];
        ++cnts[b];
    }

    for (int i = 0; i < n; ++i) {
        cout << cnts[i] << '\n';
    }


    return 0;
}

Measured memory_bytes: 3668
import math
from itertools import permutations
def inp():return map(int,input().split())
n=int(input())
cd=[[] for _  in range(n+1)]
s=0
for i in range(1,n+1):
    x,y=inp()
    cd[i].append(x)
    cd[i].append(y)

def add(A,n):
    length = 0
    for i in range(n - 1):
        length += math.sqrt((abs(cd[A[i]][0] - cd[A[i + 1]][0])) ** 2 + (abs(cd[A[i]][1] - cd[A[i + 1]][1]))**2)
    return (length)

def num(n):
    p=1
    for i in range(2,n+1):
        p=p*i
    return p


for x in permutations(range(1,n+1),n):
    s=s+add(x,n)
print(s/num(n))

Measured memory_bytes: 44396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
ll comb(ll n, ll r){
  if (r*2>n) r=n-r;
  ll x=1, y=1;
  reps(i,1,r+1){ x *= (n-i+1); y *= i; }
  return x / y;
}


int main(){
  int n; cin >> n;
  vector<int> a(n), v(100007,0);
  rep(i,n){ cin >> a[i]; v[a[i]]++; }

  int ans=0;
  rep(i,100007){
    chmax(ans, v[i]+v[i+1]+v[i+2]);
  }
  
  cout << ans;
  
return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    if(c > a && c < b){
        cout << "Yes";
    }
    if(c < a && c > b){
        cout << "Yes";
    }
    if(c < a && c < b){
        cout << "No";
    }
    if(c > a && c > b){
        cout << "No";
    }

}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();


    ll c= 0, mx= 0, n;

    cin>> n;

    ll h[n];

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

        if(h[i]> h[i-1])
        {
            mx= max (c, mx);
            c= 0;
        }
        else
            c++;
    }

    cout << max(mx, c);
    nl;


    return 0;
}




Measured memory_bytes: 4360
#include <iostream>

 using namespace std;

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   m = i % 3600 / 60;
   s = i % 3600 % 60;
   cout << h << ":" << m << ":" << s << endl;
}



Measured memory_bytes: 3084
#include <stdio.h>

int main(void)
{
    int a[3];
    for (int i = 0; i < 3; i++)
    {
        scanf("%1d", &a[i]);
        if (a[i] == 1)
        {
            a[i] = 9;
        }
        else if (a[i] == 9)
        {
            a[i] = 1;
        }
        
        printf("%1d", a[i]);
    }
    
    return 0;
}

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

#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (l); i > (r); --i)

const int N = (int)2e5 + 1;

int n;
int dp[N];//min cost 1 -> i
int h[N];

int main() {
    cin >> n;
    rep(i, 1, n + 1) {
        cin >> h[i];
    }
    dp[1] = 0;
    rep(i, 2, n + 1) {
        dp[i] = dp[i - 1] + abs(h[i - 1] - h[i]);
        if (i - 2 >= 1) dp[i] = min(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
    } 
    cout << dp[n];
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,sum=0;
	cin>>x;
	for(int i=1;i<1000000001;i++){
		sum+=i;
		if(sum>=x){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord

--import qualified Data.IntSet as S
import qualified Data.Sequence as S

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)

main :: IO ()
main = do
    n <- readLn
    bs <- r (n-1)
    let r = U.zipWith min (U.cons maxBound bs) (U.snoc bs maxBound)
    --print r
    print (U.sum $ r)



Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N],dp[N];
int main(){
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		dp[a[i]]=dp[a[i]-1]+1;
	}
	int max_=0;
	for(int i=1;i<=n;i++) max_=max(max_,dp[i]);
	printf("%d\n",n-max_);
	return 0;
} 

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    bool flag = false;
    for(int i=0; i<n; i++) {
        string s;
        cin >> s;
        if(s=="Y") flag = true;
    }
    cout << (flag ? "Four" : "Three") << endl;

}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
l=[[0]*w for _ in range(h)]
r=[[0]*w for _ in range(h)]
u=[[0]*w for _ in range(h)]
d=[[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            continue
        if j==0:
            l[i][j]=1
        else:
            l[i][j]=l[i][j-1]+1
        if j==w-1:
            r[i][j]=1
        else:
            r[i][j]=r[i][j+1]+1
        if i==0:
            u[i][j]=1
        else:
            u[i][j]=u[i-1][j]+1
for i in range(h-1,-1,-1):
    for j in range(w-1,-1,-1):
        if s[i][j]=="#":
            continue
        if j==w-1:
            r[i][j]=1
        else:
            r[i][j]=r[i][j+1]+1
        if i==h-1:
            d[i][j]=1
        else:
            d[i][j]=d[i+1][j]+1
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
print(ans)


Measured memory_bytes: 308360
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define maxn 200100

using namespace std;
tr1::unordered_map<int,int>st;
int dp[maxn],n,x;
char s[maxn];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	st[x=0]=0;
	for(int i=1;i<=n;++i){
		x^=(1<<(s[i]-'a'));
		dp[i]=dp[i-1]+1;
		if(st.find(x)!=st.end())dp[i]=min(dp[i],st[x]+1);
		for(int j=0;j<26;++j)if(st.find(x^(1<<j))!=st.end())
			dp[i]=min(dp[i],st[x^(1<<j)]+1);
		if(st.find(x)==st.end())st[x]=dp[i];
		else st[x]=min(st[x],dp[i]);
	}
	printf("%d",dp[n]);
}

Measured memory_bytes: 9416
#include<iostream>
#include<string>
using namespace std;
string s,la="R";
void co(int r,int l){
	for(int i=0;i<r-1;i++)cout<<"0 ";
	if(r%2==l%2)cout<<(r+l)/2<<' '<<(r+l)/2<<' ';
	else if(max(r,l)%2==1)cout<<(r+l)/2+(r>l?1:0)<<' '<<(r+l)/2+(r>l?0:1)<<' ';
	else cout<<(r+l)/2+(r>l?0:1)<<' '<<(r+l)/2+(r>l?1:0)<<' ';
	for(int i=0;i<l-1;i++)cout<<"0 ";
	return ;
}
int main(void){
	cin>>s;
	int r=0,l=0;
	for(int i=0;i<s.size();i++){
		if(s[i]==la[0]){
			if(la[0]=='R')r++;
			else{
				l++;
				if(i+1==s.size())co(r,l);
			} 
		}
		else{
			if(la[0]=='L'){
				la[0]='R';
				co(r,l);
				r=1;
				l=0;
			}
			else{
				la[0]='L';
				l++;
				if(i+1==s.size())co(r,l);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 640
import sys
from math import sqrt

def solve(N, D, X):
    def dist(ys, zs):
        sum = 0
        for d in range(D):
            sum += (ys[d] - zs[d])**2
        return sqrt(sum)
    count = 0
    for i in range(N):
        for j in range(i+1, N):
            d = dist(X[i], X[j])
            if d.is_integer():
                count += 1
    print(count)


def main():
    N, D = map(int, input().split())
    X = [ []]  * N
    for y in range(N):
        X[y] = list(map(int, input().split()))
    solve(N, D, X)

if __name__ == "__main__":
    main()

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

int main(){
  int N;  cin >> N;
  long long sum = 0;
  long long min = 1LL << 60;
  int minuscount = 0;
  for(int i=0;i<N;i++){
    long long A;  cin >> A;
    if(A < 0){
      A *= -1;
      minuscount ++;
    }
    if(min > A) min = A;
    sum += A;
  }
  if(minuscount % 2 == 0) cout << sum << endl;
  else  cout << sum - 2*min << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int sum(int i){
	int total=0;
	while(i>0){
		total += i%10;
		i /= 10;
	}
	return total;
}

int main(){
	int N,A,B;
	cin >> N >> A >> B;
	
	int ans=0;
	for(int i=1;i<=N;i++){
		if(sum(i)>=A && sum(i)<=B) ans+=i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
    string s,t;cin>>s>>t;
    int ans = 10000;
    for (int i = 0;i<s.size()-t.size()+1;i++) {
        int cnt = 0;
        rep(j,t.size()) {
            if(s[i+j]==t[j]) cnt++;
        }
        ans = min(ans,(int)t.size()-cnt);
    }
    cout<<ans<<endl;
}

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

int h, w;
char grid[1010][1010];
long long num[1010][1010];
const long long INF = 1e9+7;

int search(int x, int y){

}

int main() {
	cin >> h >> w;
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			cin >> grid[i][j];
		}
	}
	for(int i=0; i<=h; i++){
		for(int j=0; j<=w; j++){
			num[i][j] = 0;
		}
	}
	num[1][1] = 1;
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			if(grid[i][j] == '#') continue;
			if(grid[i-1][j] == '.') num[i][j] += num[i-1][j];
			if(grid[i][j-1] == '.') num[i][j] += num[i][j-1];
			num[i][j] %= INF;
		}
	}
	cout << num[h][w] << endl;
}



Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, 0, n) cin >> a[i];
    ll sum[n + 1] = {};
    rep(i, 0, n) {
        sum[i + 1] = sum[i] + a[i];
    }
    map<ll, ll> mp;
    rep(i, 1, n + 1) {
        mp[sum[i]]++;
    }
    ll ans = 0;
    for (auto i : mp) {
        if (i.first == 0) ans += i.second;
        ans += i.second * (i.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
#define ll long long

int n,m,k=0;
//int yhsj[35][35]={0};
ll fac[100050],inv_fac[100050];//阶乘，阶乘逆元 
const int mod=1e9+7;
ll ans=1;

/*void prepare(){
	for(int i=0;i<=32;i++)
		yhsj[i][0]=1;
	for(int i=1;i<=32;i++)
	for(int j=1;j<=i;j++)
		yhsj[i][j]=(yhsj[i-1][j-1]+yhsj[i-1][j])%mod;
}*/

ll qpow(ll x,int p){//快速幂
	ll res=1;
    while(p)  
    {
        if(p&1) res=(res*x)%mod;
        x=(x*x)%mod;
        p>>=1;
    }  
    return res;
}

void jcny(){//阶乘逆元 
	int maxn=100040;
	fac[0]=1;
	for(int i=1;i<=maxn;i++)
		fac[i]=(fac[i-1]*i)%mod;
	inv_fac[maxn]=qpow(fac[maxn],mod-2);
	for(int i=maxn-1;i>=0;i--)
		inv_fac[i]=(inv_fac[i+1]*(i+1))%mod;
}

int main(){
	scanf("%d%d",&n,&m);
	//prepare();
	jcny();
	for(int i=2;i<=sqrt(m);i++,k=0){
		if(!(m%i))
			while(!(m%i)){
				m/=i;
				k++;
			}
		//ans=ans*yhsj[k+n-1][n-1]%mod;
		ll now=((fac[k+n-1]*inv_fac[n-1])%mod)*inv_fac[k]%mod;
		ans=(ans*now)%mod;
	}
	if(m>1){
		k=1;
		ll now=((fac[k+n-1]*inv_fac[n-1])%mod)*inv_fac[k]%mod;
		ans=(ans*now)%mod;
	}
	printf("%lld",ans);
	
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();
		int[] array = new int[num];
		int count = 0;

		for (int i = 0; i < num; i++) {
			array[i] = scan.nextInt();
			if(isprime(array[i])) {
				count+=1;
			}
		}
		System.out.println(count);

		scan.close();
	}

	private static boolean isprime(int x) {
		if (x == 2) {
			return true;
		}

		if (x < 2 || x % 2 == 0) {
			return false;
		}
		int i = 3;
		while (i <= Math.sqrt(x)) {
			if (x % i == 0) {
				return false;
			}
			i += 2;
		}
		return true;
	}

}


Measured memory_bytes: 43224
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,d;
	cin >> n >> d;
	cout << (((n-1)/(d*2+1))+1) << endl;
	return 0;
}


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

struct union_find {
    vector<int> v;
    union_find(int n) : v(n, -1) {}
    int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return;
        if (-v[x] < -v[y]) swap(x, y);
        v[x] += v[y]; v[y] = x;
    }
    bool root(int x) { return v[x] < 0; }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -v[find(x)]; }
};

int main() {
    int N; cin >> N;
    vector<i_i> ai(N), bi(N);
    rep(i, N) {
        int x; cin >> x;
        ai[i] = i_i(x, i);
    }
    rep(i, N) {
        int x; cin >> x;
        bi[i] = i_i(x, i);
    }
    sort(all(ai));
    sort(all(bi));
    rep(k, N) {
        int x = get<0>(ai[k]);
        int y = get<0>(bi[k]);
        if (x > y) {
            cout << "No" << endl;
            return 0;
        }
    }
    rep(k, N - 1) {
        int x = get<0>(ai[k + 1]);
        int y = get<0>(bi[k]);
        if (x <= y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    union_find uf(N);
    rep(k, N) {
        int i = get<1>(ai[k]);
        int j = get<1>(bi[k]);
        uf.unite(i, j);
    }
    cout << (uf.size(0) < N ? "Yes" : "No") << endl;
}


Measured memory_bytes: 2176
#include <stdio.h>

int main(void){
	int t,s=0;
	
	while(scanf("%d",&t),t){
		int i,now=0,count=0;
		int train[12]={0},car[12]={0};
		
		
		for(;;){
			if(s!=0){
				scanf("%d",&t);
			}
			else {
				s=1;
			}
			if(t!=0){
				train[now]=t;
				now++;
			}
			else{
				now--;
				car[count]=train[now];
				train[now]=0;
				count++;
				if(now==0)break;
			}
		}
		
		i=0;
		while(car[i]!=0){
			printf("%d\n",car[i]);
			i++;
		}
		s=0;
	}
	return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    A = [0] + A
    B = [0 for _ in range(N + 1)]
    for i in reversed(range(1, N + 1)):
        j = i
        t = 0
        while j < N + 1:
            t += B[j]
            j += i
        if A[i] != t % 2:
            B[i] = 1
    ans = sum(B)
    print(ans)
    if ans > 0:
        print(*[i for i, b in enumerate(B) if b == 1], sep=' ')


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 20008
#include<cstdio>
#include<cstring>
#define N 100005
#define p 1000000007
inline int _a(int x){return x<3?x:x-3;}
inline int _b(int x){return x<p?x:x-p;}
char c[N];int a[N],b[N][3],f[N],i,j,n,o[3],x;
int main()
{
    scanf("%s",c+1),n=strlen(c+1),o[0]=o[1]=o[2]=b[n+1][0]=b[n+1][1]=b[n+1][2]=n+1,*f=1;
    for(i=1;i<=n;i++)a[i]=_a(a[i-1]+(c[i]==97?1:2));
    for(i=1;i<n&&c[i]!=c[i+1];i++);
    if(i==n)return 0&puts("1");
    for(i=j=n;i;b[i][_a(3-a[i-1])]=o[0],b[i][_a(4-a[i-1])]=o[1],b[i][_a(5-a[i-1])]=o[2],b[i][c[i]==97?1:2]=i,i--)if(c[i]==c[i+1])while(i<j)o[a[j]]=j,j--;
    for(i=0;i<=n;i++)f[b[i+1][1]]=_b(f[b[i+1][1]]+f[i]),f[b[i+1][2]]=_b(f[b[i+1][2]]+f[i]);
    for(i=1;i<=n;i++)if(a[i]==a[n])x=_b(x+f[i]);
    return 0*printf("%d\n",x);
}

Measured memory_bytes: 2176
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int Maxn = 2004;
const int Maxm = 100000;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x7FFFFFFF;

struct MinCostMaxFlow_Dinic {
	struct Edge {
		int to, cap;
		ll cos;
		Edge *nxt, *bak;
	};
	Edge pool[Maxm + 5];
	Edge *ecnt, *G[Maxn + 5];
	inline void addedge(int u, int v, int cap, ll c) {
		Edge *p = ++ecnt;
		p->to = v, p->cap = cap, p->cos = c;
		p->nxt = G[u], G[u] = p;
		p->bak = p + 1;
		p = ++ecnt;
		p->to = u, p->cap = 0, p->cos = -c;
		p->nxt = G[v], G[v] = p;
		p->bak = p - 1;
	}
	int node, s, t;
	ll d[Maxn + 5];
	Edge *cpy[Maxn + 5];
	ll cost;
	void init(int n) {
		ecnt = &pool[0];
		node = n;
		for(int i = 1; i <= n; i++)
			G[i] = NULL;
	}
	bool vis[Maxn + 5];
	int dfs(int u, int tot) {
		if(u == t) return tot;
		vis[u] = true;
		int sum = 0;
		for(;cpy[u] != NULL; cpy[u] = cpy[u]->nxt) {
			int v = cpy[u]->to, w = cpy[u]->cos;
			if(!vis[v] && d[v] == d[u] + w && cpy[u]->cap > 0) {
				int delta = dfs(v, min(tot - sum, cpy[u]->cap));
				cpy[u]->cap -= delta, cpy[u]->bak->cap += delta;
				cost += cpy[u]->cos * delta;
				sum += delta;
				if(sum == tot) break;
			}
		}
		vis[u] = false;
		return sum;
	}
	bool spfa(int _s, int _t) {
		static bool inq[Maxn + 5];
		memset(inq, false, sizeof inq);
		for(int i = 0 ; i <= node; i++)
			d[i] = -INFLL, cpy[i] = G[i];
		queue<int> q;
		q.push(_s), d[_s] = 0, inq[_s] = true;
		while(!q.empty()) {
			int u = q.front();
			q.pop(), inq[u] = false;
			for(Edge *p = G[u]; p != NULL; p = p->nxt) {
				int v = p->to;
				if(p->cap > 0 && d[v] < d[u] + p->cos) {
					d[v] = d[u] + p->cos;
					if(!inq[v]) {
						inq[v] = true;
						q.push(v);
					}
				}
			}
		}
		return d[_t] != -INFLL;
	}
	ll mcmf(int _s, int _t) {
		s = _s, t = _t, cost = 0;
		while(spfa(s, t)) {
			memset(vis, false, sizeof vis);
			dfs(s, INF);
		}
		return cost;
	}
};

int N;
MinCostMaxFlow_Dinic f;

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d", &N);
	int S = 1, T = 2 * N + 6;
	f.init(2 * N + 6);
	for(int i = 1; i <= N; i++) {
		int x, y, val;
		scanf("%d %d %d", &x, &y, &val);
		f.addedge(S, i + 1, val, 0);
		f.addedge(i + 1, N + 2, INF, x + y);
		f.addedge(i + 1, N + 3, INF, -x + y);
		f.addedge(i + 1, N + 4, INF, x - y);
		f.addedge(i + 1, N + 5, INF, -x - y);
	}
	for(int i = 1; i <= N; i++) {
		int x, y, val;
		scanf("%d %d %d", &x, &y, &val);
		f.addedge(i + N + 5, T, val, 0);
		f.addedge(N + 2, i + N + 5, INF, -x - y);
		f.addedge(N + 3, i + N + 5, INF, x - y);
		f.addedge(N + 4, i + N + 5, INF, -x + y);
		f.addedge(N + 5, i + N + 5, INF, x + y);
	}
	printf("%lld\n", f.mcmf(S, T));
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll V;
ll d_f[MAX_N];
ll d_s[MAX_N];
struct edge { ll to, cost; };
typedef pair<ll, ll> P;
vector<edge> G[MAX_N];
void dijkstra(ll *d, ll s) {
	fill(d + 1, d + V + 1, INF);
	d[s] = 0;

	priority_queue <P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first)continue;
		rep(i, 0, G[v].size()) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	cin >> V;
	rep(i, 1, V) {
		ll s, t, d; cin >> s >> t;
		G[s].push_back(*(new edge{ t,1 }));
		G[t].push_back(*(new edge{ s,1 }));
	}

	dijkstra(d_f, 1);
	dijkstra(d_s, V);

	ll a = 0;
	ll b = 0;
	repe(i, 1, V) ((d_f[i] <= d_s[i]) ? a++ : b++);

	cout << ((a > b) ? "Fennec" : "Snuke");

	return 0;
}

Measured memory_bytes: 15836
n,*L=map(int,open(0).read().split())
g=[[]for _ in range(n)]
for a,b in zip(*[iter(L)]*2):
	g[a-1].append(b-1)
	g[b-1].append(a-1)
tr=[-1]*n
q=[0]
tr[0]=0
while q:
	cu=q.pop()
	for nx in g[cu]:
		if tr[nx]<0:
			tr[nx]=1-tr[cu]
			q.append(nx)
lab=[-1]*n
z,o=map(tr.count,(0,1))
if z<=n//3 or o<=n//3:
	f=0 if z<=n//3 else 1
	onetwo=1
	thr=3
	for i,x in enumerate(tr):
		if x==f:
			lab[i]=thr
			thr+=3
	for i,x in enumerate(tr):
		if x==1-f:
			if thr<=n:
				lab[i]=thr
				thr+=3
			else:
				lab[i]=onetwo
				onetwo+=1 if onetwo%3==1 else 2
else:
	one=1
	for i,x in enumerate(tr):
		if x==0:
			lab[i]=one
			one+=3
			if one>n:
				break
	two=2
	for i,x in enumerate(tr):
		if x==1:
			lab[i]=two
			two+=3
			if two>n:
				break
	thr=3
	for i in range(n):
		if lab[i]<0:
			lab[i]=thr
			thr+=3
print(*lab)




Measured memory_bytes: 70368
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
vector<int>G[51];

int N,M;
int S;
LL A[101];
LL B[101];
LL C[101];
LL D[101];
LL E[101];
LL F[101];
bool used[51][3001];
LL dp[51][3001];
typedef pair<LL,LL>P;
typedef pair<LL,P>PP;
priority_queue<PP,vector<PP>,greater<PP> >que;

int main(){
	cin>>N>>M>>S;
	REP(i,M){
		cin>>A[i]>>B[i]>>C[i]>>D[i];
		A[i]--;
		B[i]--;
		G[A[i]].push_back(i);
		G[B[i]].push_back(i);
	}
	REP(i,N){
		cin>>E[i]>>F[i];
	}
	S=min(S,2500);
	REP(i,N){
		REP(j,3001){
			dp[i][j]=1e18;
			used[i][j]=false;
		}
	}
	dp[0][S]=0;
	que.push(PP(0,P(0,S)));
	while(que.empty()==false){
		PP pp=que.top();
		que.pop();
		P p=pp.second;
		LL pos=p.first;
		LL money=p.second;
		LL now=pp.first;
		/*if(now<15){
			cout<<now<<" "<<pos<<" "<<money<<" "<<endl;
		}*/
		if(used[pos][money]==true)continue;
		used[pos][money]=true;
		if(dp[pos][min(money+E[pos],(LL)2500)]>dp[pos][money]+F[pos]){
			dp[pos][min(money+E[pos],(LL)2500)]=dp[pos][money]+F[pos];
			que.push(PP(dp[pos][min(money+E[pos],(LL)2500)],P(pos,min(money+E[pos],(LL)2500))));
		}
		REP(i,G[pos].size()){
			int tmp=G[pos][i];
			if(money>=C[tmp]){
				int x=pos^A[tmp]^B[tmp];
				if(dp[x][money-C[tmp]]>dp[pos][money]+D[tmp]){
					dp[x][money-C[tmp]]=min(dp[x][money-C[tmp]],dp[pos][money]+D[tmp]);
					que.push(PP(dp[x][money-C[tmp]],P(x,money-C[tmp])));
				}
			}
		}
	}
	REP(i,N){
		LL ans=1e18;
		REP(j,2701){
			ans=min(ans,dp[i][j]);
		}
		if(i==0)continue;
		cout<<ans<<endl;
	}
	//cout<<1<<endl;
}

Measured memory_bytes: 7628
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int n;
string s;
char ses[M];
char fnd(int pos,char cur,char dan)
{
    if(cur=='S')
    {
        if(s[pos]=='o')return dan;
        else
        {
            if(dan=='S')return 'W';
            else return 'S';
        }
    }
    else if(cur=='W')
    {
        if(s[pos]=='x')return dan;
        else
        {
            if(dan=='S')return 'W';
            else return 'S';
        }
    }
}
void chk(char x,char y)
{

    ses[0]=x;
    ses[1]=y;
    ses[n-1]=fnd(0,x,y);
    for(int i=2;i<=n;i++)
    {
        char yo=fnd(i-1,ses[i-1],ses[i-2]);
        if(i==n-1)
        {
            if(yo!=ses[n-1])
            {
                return ;
            }
        }
        else if(i==n)
        {
            if(yo!=ses[0])return ;
            continue;
        }
        ses[i]=yo;
    }
    ses[n]='\0';
    cout<<ses<<endl;
    exit(0);
}
 main()

{
    fast
    cin>>n;
    cin>>s;
    chk('S','W');
    chk('S','S');
    chk('W','S');
    chk('W','W');
    cout<<"-1"<<endl;
    return 0;

}





































Measured memory_bytes: 720
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define fail return puts("Impossible"), 0
#define rep(i, x, y) for (int i = (x); i <= (y); i ++)
using namespace std;

const int N = 105;

int a[N];

int main() {
  int n, x;
  scanf("%d", &n);
  rep(i, 1, n) {
    scanf("%d", &x);
    a[x] ++;
  }
  int d = n - 1;
  while (!a[d]) d --;
  for (int i = 0; i <= d; i ++) {
    if (!a[max(i, d - i)]) fail;
    a[max(i, d - i)] --;
  }
  d = (d + 1) >> 1;
  rep(i, 1, d)
    if (a[i]) fail;
  puts("Possible");
  return 0;
}


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

int main(void){
    ll a,b; cin >> a >> b;
    bool head=false,back=false;
    ll ans;
    if(a%2==1){
        head = true;
        a++;
    }
    if((b-a+1)%2==1){
        back = true;
    }
    if(((b-a+1)/2)%2==1){
        ans = 1;
    }else{
        ans = 0;
    }

    if(head==true) ans = ans^(a-1);
    if(back==true) ans = ans^b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

double distance1(int x[], int y[], int n);
double distance2(int x[], int y[], int n);
double distance3(int x[], int y[], int n);
double distanceInf(int x[], int y[], int n);
int main(void) {
  int n, i;
  int x[1002], y[1002];
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &x[i]);
  for (i = 0; i < n; i++) scanf("%d", &y[i]);

  printf("%f\n", distance1(x, y, n));
  printf("%f\n", distance2(x, y, n));
  printf("%f\n", distance3(x, y, n));
  printf("%f\n", distanceInf(x, y, n));

  return 0;
}
double distance1(int x[], int y[], int n) {
  int i;
  double d = 0.0;
  for (i = 0; i < n; i++) {
    d += (double)abs(x[i] - y[i]);
  }
  return d;
}
double distance2(int x[], int y[], int n) {
  int i;
  double d = 0.0;
  for (i = 0; i < n; i++) {
    d += (double)(abs(x[i] - y[i]) * abs(x[i] - y[i]));
  }
  d = sqrt(d);
  return d;
}
double distance3(int x[], int y[], int n) {
  int i;
  double d = 0.0;
  for (i = 0; i < n; i++) {
    d += (double)(abs(x[i] - y[i]) * abs(x[i] - y[i]) * abs(x[i] - y[i]));
  }
  d = cbrt(d);
  return d;
}
double distanceInf(int x[], int y[], int n) {
  int i = 0;
  double d = (double)abs(x[i] - y[i]);
  if (n > 1) {
    for (i = 1; i < n; i++) {
      if (d < (double)abs(x[i] - y[i])) d = (double)abs(x[i] - y[i]);
    }
  }
  return d;
}


Measured memory_bytes: 2100
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	a := nextInt()
	b := nextInt()
	c := nextInt()
	d := nextInt()
	fmt.Println(max(max(max(a*c, a*d), b*c), b*d))
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    string s; cin >> s;

    if(s == "SUN") cout << 7 << endl;
    if(s == "MON") cout << 6 << endl;
    if(s == "TUE") cout << 5 << endl;
    if(s == "WED") cout << 4 << endl;
    if(s == "THU") cout << 3 << endl;
    if(s == "FRI") cout << 2 << endl;
    if(s == "SAT") cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 3568
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
prime_factors = []

i = 2
copy_n = n
while i ** 2 <= copy_n:
    ext = 0
    while copy_n % i == 0:
        ext += 1
        copy_n //= i
    if ext:
        prime_factors.append((i, ext))
    i += 1
if copy_n != 1:
    prime_factors.append((copy_n, 1))

for pf, _ in prime_factors:
    n *= (pf - 1)
    n //= pf
print(n)



Measured memory_bytes: 5604
#include <bits/stdc++.h>
//#define mod 1000000007
//#define mod998 998244353
#define mod003 1000003
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int Q;
ll f[1111111], inv[1111111], x, d, n;

ll pw(ll x, int y) {
	ll a = 1;
	while (y) {
		if (y & 1) {
			a = a*x%mod003;
		}
		x = x*x%mod003;
		y /= 2;
	}
	return a;
}

ll modinv(ll x) {
	return pw(x, mod003 - 2);
}

int main() {
	f[0] = inv[0] = 1;
	for (int i = 1; i < 1111111; ++i) {
		f[i] = f[i - 1] * i%mod003;
		inv[i] = modinv(f[i]);
	}
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		cin >> x >> d >> n;
		if (d == 0) {
			cout << pw(x, n) << endl;
		}
		else {
			if ((mod003 - x)*modinv(d) % mod003 < n)cout << 0 << endl;
			else {
				cout << x*pw(d, n - 1) % mod003*f[((d + x) % mod003*modinv(d) % mod003 + n - 2 + mod003) % mod003] % mod003*inv[((d + x) % mod003*modinv(d) % mod003 - 1 + mod003) % mod003] % mod003 << endl;
			}
		}
	}
}

Measured memory_bytes: 18176
na,nb,k = map(int, input().split())
ta = list(map(int, input().split()))
tb = list(map(int, input().split()))

a = [0]
for i in range(na):
  a.append( a[i] + ta[i] )
b = [0]
for i in range(nb):
  b.append( b[i] + tb[i] )

ans, j=0, nb
for i in range(na + 1):
  if a[i] > k:
    break
  while True:
    if a[i] + b[j] > k:
      j -= 1
    else:
      break
  ans = max(ans, i+j)
    
print(ans)

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

int main (){
  double n,k;
  cin>>n>>k;
  ll point;
  double ans=0;
  for (int i = 1;i<=n;i++){
    point=i;
    double sum=1;
    bool ok = true;
    while(ok){
      if (point < k){
        point*=2;
        sum/=2;
      }
      else{
        break;
      }
    }
    ans = ans + 1/n*sum;
  }
  cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
ans=[0]*(n+1)
for x in range(1,105):
  for y in range(1,105):
    for z in range(1,105):
      t=x*x+y*y+z*z+x*y+y*z+z*x
      if t<=n:
        ans[t]+=1
for i in range(1,n+1):
  print(ans[i])

Measured memory_bytes: 69124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long N = in.nextLong();
		long A = in.nextLong();
		long B = in.nextLong();
		long C = in.nextLong();
		long D = in.nextLong();
		long E = in.nextLong();
		long minMove = Math.min(A, Math.min(B, Math.min(C, Math.min(D, E))));
		long ans = ((N + minMove - 1) / minMove) + 4;
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int mod = 1e9+7;
int dp[100005][2];

int main(){
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i,n){
        {
            if (s[i] == '0'){
                dp[i+1][0] = dp[i][0];
                dp[i+1][1] = dp[i][1];
            }else{
                dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
            }
        }

        {
            if (s[i] == '0'){
                (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
            }else{
                (dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
                (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
            }
        }
    }
    int ans = (dp[n][0] + dp[n][1]) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4528
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    n,wn=MI()
    vw=[LI() for _ in range(n)]
    dp=[0]*(wn+1)
    for v,w in vw:
        for i in range(wn,w-1,-1):
            dp[i]=max(dp[i],dp[i-w]+v)
    print(dp[-1])

main()



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

int main(){
	string name;
	int t1,t2;
	for(int i=0;i<9;i++){
		cin >> name >> t1 >> t2;
		cout << name << " " << t1+t2 << " " << t1*200 + t2 * 300 << endl;
	}
	
} 

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long int

using namespace std;
int main(){
		ll n;
		cin>>n;
		if(n&1LL){
			cout<<0;
		}else{
			ll ans=0LL;
			n=n/2LL;
			while(n){
				ans+=n/5LL;
				n=n/5LL;
				// cout<<num<<endl;
			}
			cout<<ans;
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
const ll INF = 1e9;

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

    ll m = INF;
    int idx_m = -1;
    ll M = -INF;
    int idx_M = -1;
    for (int i = 0; i < n; i ++) {
        if (M < a[i]) {
            M = a[i];
            idx_M = i;
        }
        if (m > a[i]) {
            m = a[i];
            idx_m = i;
        }
    }

    vector<pint> ans;
    bool flag = false;

    if (m < 0 && M > 0) {
        if (abs(m) <= abs(M)) flag = true;
    }
    if (m >= 0) flag = true;


    if (flag) {
        for (int i = 0; i < n; i ++) {
            if (a[i] < 0) {
                a[i] += M;
                ans.push_back({idx_M + 1, i + 1});
            }
        }
        for (int i = 0; i < n - 1; i ++) {
            if (a[i] > a[i + 1]) {
                a[i + 1] += a[i];
                ans.push_back({i + 1, i + 2});
            }
        }
    }   

    else {
        for (int i = 0; i < n; i ++) {
            if (a[i] > 0) {
                a[i] += m;
                ans.push_back({idx_m + 1, i + 1});
            }
        }
        for (int i = n - 2; i >= 0; i --) {
            if (a[i] > a[i+1]) {
                a[i] += a[i+1];
                ans.push_back({i + 2, i + 1});
            }
        }
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i ++) {
        cout << ans[i].first << ' ' << ans[i].second << endl; 
    }
}

Measured memory_bytes: 256
/* ITP1_6_D:Matrix Vector Multiplication */
/* 20181122 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
	int A[100][100], B[100];
	int C[100] = {0};
	int n, m, i, j;

	scanf("%d%d", &n, &m);
	for(i = 0; i < n; i++) {
		for(j= 0; j < m; j++) {
			scanf("%d", &A[i][j]);
		}
	}

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

	for(i = 0; i < n; i++) {
		for(j = 0; j < m; j++) {
			C[i] += A[i][j] * B[j];
		}
		printf("%d\n", C[i]);
	}

	return 0;
}


Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int 
const int twx=100+100;
const int inf=0x7fffffff;
ll read()
{
    ll sum=0;
    ll flag=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            flag=-1;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        sum=((sum*10)+c-'0');
        c=getchar();
    }
    return sum*flag;
}
char s[twx];
void init()
{
	scanf("%s",s+1);
    int len=strlen(s+1);
    f1(1,len,i)
    {
        if(s[i]=='C')
        {
            f1(i+1,len,j)
            {
                if(s[j]=='F')
                {
                    puts("Yes");
                    exit(0);
                }
            }
        }
    }
    puts("No");
}
int main()
{
	init();
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=n-1
s1=0
s2=0
while i>0:
    if a[i]==a[i-1] and s1==0:
        s1=a[i]
        i-=2
        continue
    if a[i]==a[i-1]:
        s2=a[i]
        i-=1
        break
    i-=1

print(s1*s2)

Measured memory_bytes: 14668
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,x=0;cin>>N;
  vector<int>C(N);
  cin>>C.at(0);
  for(int i=1;i<N;i++){
    cin>>C.at(i);
    if(C.at(i)==C.at(i-1)){
      x++;C.at(i)=0;
    }
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos) n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos) a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos) b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7896
#include <bits/stdc++.h>
using namespace std;
#define max 200009
map<long,long>mp;

int main()
{
    long i,j,t,a,b,n,c,temp,m;
    t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n;
        if(n<2)cout<<1;
        else
        {
            temp=1;
            while(temp<=n)
            {
                temp*=2;
            }
            cout<<temp/2;
        }

    }
}

Measured memory_bytes: 256
object Main extends App {
  override def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val _ = sc.nextLine()
    val arr = sc.nextLine().split(" ").map(_.toInt)
    var arr1 = arr
    var sum = 0
    while (applicable(arr1)) {
      arr1 = arr1.map(x => x / 2)
      sum += 1
    }
    println(sum)

  }
  def applicable(num: Array[Int]): Boolean = {
    num.forall(x => x % 2 == 0)
  }

}

Measured memory_bytes: 27332
A,B,C,D,E,F = map(int,input().split())
waterset = set()
for i in range(F//(100*A)+1):
    for j in range(F//(100*B)+1):
        water = (A*i + B *j)*100
        if water < F:
            waterset.add(water)
waterset.remove(0)
sugarset = set()
for i in range(F//C + 1):
    for j in range(F//D + 1):
        sugar = C*i + D*j
        if sugar < F:
            sugarset.add(sugar)
best_conc = -1
best_a = -1
best_b = -1
for a in waterset:
    for b in sugarset:
        if a+b >F:
            continue
        if b/a > E/100:
            continue
        conc = 100*b/(a+b)
        if conc > best_conc:
            best_conc = conc
            best_a = a
            best_b = b
print(best_a+best_b,best_b)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int N = 205;
const int maxS = 40005;
long long f[2][2*maxS],n,m,a[N];
const int MOD =1e9+7;
void init()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    freopen("AVERAGE.inp","r",stdin);
    freopen("AVERAGE.out","w",stdout);
}
void nhap()
{
    cin >> n >> m;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
        a[i] -= m;
    }
}
void xuli()
{
    memset(f,0,sizeof(f));
    f[0][maxS] = 1;
    for (int i = 1; i<=n; i++) {
        for (int j = 0; j<2*maxS; j++) {
             f[1][j] += f[0][j];
             f[1][j+a[i]] += f[0][j];
        }
        for (int j = 0; j<2*maxS; j++) {
            f[0][j] = f[1][j];
            f[1][j] = 0;
        }
    }
    cout << f[0][maxS] - 1  << '\n';
}
int main()
{
        nhap();
        xuli();

}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
  	sort(a,a+n);
	int k = -1, in;
	for(int i = 0; i < n; i++) {
		int d = min(a[i], a[n - 1] - a[i]);
		if (d > k){ k = d;  in = i;}
	}
	cout << a[n-1] << " " << a[in] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    int x,t;

    cin >> x >> t;

    if(x>=t) cout << x-t << endl;
    else cout << 0 << endl;

    return 0;
}

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

int main() {
    int i, n, cnt1 = 0, cnt2 = 0;
    string str1, str2;

    cin >> n;
    for(i=0; i<n; ++i) {
        cin >> str1 >> str2;
        if(str1.compare(str2) > 0) cnt1 += 3;
        else if(str1.compare(str2) < 0) cnt2 += 3;
        else {
            ++cnt1;
            ++cnt2;
        }
    }
    cout << cnt1 << ' ' << cnt2 << endl;

    return 0;
}

Measured memory_bytes: 3168
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
int flag[N], prim[N], a[N], vist[N];
int cnt;
void get_prim()
{
	//int tot = 0;
	for(int i = 2; i <= 1e6; i++)
	{
		if(!flag[i])	prim[++cnt] = i;
		//if(!flag[i] && i <= 1000)	tot++;
		for(int j = 1; j <= cnt; j++)
		{
			if(prim[j] * i > 1e6)	break;
			flag[prim[j] * i] = 1;
			if(i % prim[j] == 0)	break;
		}
	}
	//printf("%d\n",tot);
	//printf("<%d>",cnt);
}
int main()
{
	get_prim();
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)	scanf("%d", &a[i]);
	/*sort(a + 1, a + n + 1);
	m = unique(a + 1, a + n + 1) - a - 1;
	if(n > cnt)
	{
		printf("not coprime\n");
		return 0;
	}*/
	for(int i = 1;i <= n; i++)
	{
		for(int j = 1; j <= cnt; j++)
		{
			if(a[i] == 1 || prim[j] > 1000 )	break;
			if(a[i] % prim[j] == 0)	vist[j] ++; 
			while(a[i] % prim[j] == 0)	a[i] /= prim[j];
		}
		if(a[i] != 1)
		{
			int x = lower_bound(prim + 1, prim + cnt + 1, a[i]) - prim;
			vist[x]++;
		}
	}
	for(int i = 1; i <= cnt; i++)
		if(vist[i] == n)
		{
			printf("not coprime\n");
			return 0;
		}
	for(int i = 1; i <= cnt; i++)
		if(vist[i] > 1)
		{
			printf("setwise coprime\n");
			return 0;
		}
	printf("pairwise coprime\n");
	return 0;
 } 

Measured memory_bytes: 11920