akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n,k;
    scanf("%d%d", &n, &k);

    if(k==1) {
        printf("0\n");
    }
    else {
        printf("%d\n", n-(k-1)-1);
    }



    return 0;
}


Measured memory_bytes: 128
n = int(input())
l = list(map(int, input().split(" ")))

for i in range(n // 2):
	l[i],l[-1-i] = l[-1-i],l[i]
        
for j in l:
	if j == l[0]:
		print(str(j), end="")
	else:
		print(" " + str(j), end="")
		
print("")


Measured memory_bytes: 5608
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

struct edge {
    int to, distance;
};

vector<edge> G[100100];
int N, M;
bool used[100100];
int x[100100];

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

void dfs(int i) {
  used[i] = true;
  rep(j, G[i].size()) {
    int g = G[i][j].to;
    bool flag = used[g];
    int distance = G[i][j].distance;
    if(!flag) {
      x[g] = x[i] + distance;
      dfs(g);
    } else {
      if(x[g] != x[i] + distance) No();
    }
  }
}

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

  cin >> N >> M;
  rep(i, M) {
    int L, R, D; cin >> L >> R >> D;
    L --; R--; edge es;
    es.to = R; es.distance = D;
    G[L].push_back(es);
    es.to = L; es.distance = -D;
    G[R].push_back(es);
  }
  rep(i, N) used[i] = false;
  rep(i, N) {
    if(!(used[i])) {
      x[i] = 0;
      dfs(i);
    }
  }
  Yes();
  return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	if(c-a-b>0&&4*a*b<(c*c+a*a+b*b+2*(-1*c*a+a*b-1*b*c))){
		cout << "Yes";
	}
	else{
		cout <<"No";
	}
	// your code goes here
	return 0;
}

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

const int Mx = 300;
const int mod = 998244353;
ll p2[Mx + 1];

typedef bitset<Mx> * It;

ll f(It first, It last, const int pos) {

	if (pos < 0 || first == last) {
		assert(all_of(first, last, [](const bitset<Mx> &x) {
			return x == 0;
		}));
		return p2[last - first];
	}

	partition(first, last, [&pos](const bitset<Mx> &x) {
		return x[pos] == 0;
	});

	It pLast = prev(last);
	if ((*pLast)[pos] == 0)
		return f(first, last, pos - 1);
	for (It it = first; it < pLast; ++it)
		if ((*it)[pos])
			*it ^= *pLast;
	return f(first, pLast, pos - 1);
}

bitset<Mx> a[300];

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

	p2[0] = 1;
	for (int i = 1; i <= Mx; ++i)
		p2[i] = (p2[i - 1] * 2) % mod;

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

	for (int i = 0; i < n; ++i) {
		a[i] = 0;
		for (int j = 0; j < m; ++j) {
			int x;
			cin >> x;
			a[i][j] = x;
		}
	}

	ll res = f(a, a + n, m - 1);
	res = (p2[n] - res) * p2[m - 1];
	cout << (res % mod + mod) % mod;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

XOR=[0]
for a in A:
    XOR.append(XOR[-1]^a)

ZEROS=[0]
for xor in XOR:
    if xor==0:
        ZEROS.append(ZEROS[-1]+1)
    else:
        ZEROS.append(ZEROS[-1])

if XOR[-1]!=0:
    SUBJ=XOR[-1]
    SUBJ_LIST=[]

    for j in range(N+1):
        if XOR[j]==SUBJ:
            SUBJ_LIST.append(j)

    #print(SUBJ_LIST)

    ZERO=1
    NOW=0

    for i in range(len(SUBJ_LIST)):
        ZERO+=NOW*(ZEROS[SUBJ_LIST[i]]-ZEROS[SUBJ_LIST[i-1]])
        NOW+=ZERO

        #print(NOW,ZERO)

    print(ZERO%mod)

else:
    SET=set(XOR)
    
    from collections import defaultdict
    SUBJ=defaultdict(list)
    for j in range(1,N+1):
        SUBJ[XOR[j]].append(j)

    ANS=1<<(ZEROS[-1]-2)

    for subj in SUBJ:
        if subj==0:
            continue
        ZERO=1
        NOW=0

        for i in range(len(SUBJ[subj])):
            
            ZERO=(ZERO+NOW*(ZEROS[SUBJ[subj][i]]-ZEROS[SUBJ[subj][i-1]]))%mod
            NOW=(NOW+ZERO)%mod

        #print(ZERO,SUBJ[subj],subj)
        ANS=(ANS+NOW)%mod

    print(ANS%mod)

Measured memory_bytes: 125568
while 1:
    cnt=0
    n,x=map(int,input().split())
    if(n==0 and x==0):
        break
    else:
        for i in range(1,n+1):
            for j in range(1,n+1):
                for k in range(1,n+1):
                    if i<j<k and i+j+k==x:
                        cnt+=1
        print(cnt)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll N = 1e6 + 5;
const ll maxn = 5005;
ll m, n, t, T, k, a[N], b[N], ans, tong;
string s, ss;
struct dang
{
    ll pos, val, mn, mx, vtri;
};
bool so(const dang& x, const dang& y)
{
    return (x.val < y.val) || (x.val == y.val && x.pos < y.pos);
}
void sol()
{
    cin >> n >> m;
    while(n -- > 0)
    {
        cin >> t >> k;
        tong = t * t + k * k;
        if(tong <= m * m)++ans;
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cin >> T; while(T -- > 0)
    sol();
}


Measured memory_bytes: 3656
#include <stdio.h>
#define MOD 1000000007
#define MAX (int)10e6+1

int main(){
  int n,t=0,
      i;
  long long res=1;
  char c[MAX];
  
  scanf("%d",&n);
  scanf("%s",&c);
  
  for(i=0;i<2*n;i++){
    if((i%2==0 && c[i]=='B') || (i%2==1 && c[i]=='W')){
      t++;
    }else{
      if(t==0){
        printf("0\n");
        return 0;
      }
      res *= t;
      res %= MOD;
      t--;
    }
  }
  if(t!=0)res = 0;
//  printf("%lld\n",res);
  
  for(i=1;i<=n;i++){
    res *= i;
    res %= MOD;
  }
  
  printf("%lld\n",res);
  return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <string.h>
void LCSLength(void);
char X[10000],Y[10000];
int c[10000][10000],m,n;
int main(){
int i,num;
scanf("%d",&num);
 for (i = 1; i<=num;i++)
   {
     scanf("%s%s",X,Y);
     LCSLength();
     
     printf("%d\n",c[m][n]);

   }
 return 0;
}
void LCSLength(void){
  int i,j;
  m = strlen(X);
  n = strlen(Y);
  for (i = 1; i<=m;i++)
    c[i][0] =0;
  for (j = 0; j<=n;j++)
    c[0][j] =0;

  for (i = 1; i<=m;i++)
    for (j = 1; j<=n;j++){
      if (X[i-1] == Y[j-1])
	c[i][j] = c[i-1][j-1] + 1;
      else if (c[i-1][j] >= c[i][j-1])
	c[i][j] = c[i-1][j];
      else
	c[i][j] = c[i][j-1];

    }
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 5e5+100;
const ll mod = 1e9 + 7;

ll fac[maxn], ifac[maxn];

ll modpow(ll, ll);
ll inv(ll);
ll nck(ll, ll);
void build();
void testlib();



int n;
int k;
//multiset coef: out of x item types, pick y of them
ll H(ll x, ll y) {
  return nck(x+y-1,x-1);
}
//y balls with x-1 dividers

//example
//suppose we pick 3 1's to go to rooms {1,2,1}, this is same as 3 1's going to rooms {1,1,2}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  build();
  testlib();

  cin>>n>>k;
  int m = min(n-1,k);//upper bound on 0s
  ll ans = 0;

  for (int i=0; i<=m; i++) {
    //1. pick where the i 0's will go
    //2. out of the n-i remaining slots>0, pick where the i ppl will go to
    ans += nck(n,i)*H(n-i,i)%mod;
    ans %= mod;
  }

  ans %= mod;
  ans += mod;
  ans %= mod;
  cout<<ans<<endl;
  return 0;
}

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


ll modpow(ll x, ll y) {
  x %= mod;
  ll res = 1;
  while (y > 0) {
    if (y%2 == 1) {
      res *= x;
      res %= mod;
    }
    x = x * x;
    x %= mod;
    y = y / 2;
  }
  return res;
}

ll inv(ll x) {
  assert(x != 0);
  return modpow(x, mod-2);
}

void build() {
  fac[0] = ifac[0] = 1;
  for (int i=1; i<maxn; i++) {
    fac[i] = fac[i-1] * i;
    fac[i] %= mod;
    ifac[i] = inv(fac[i]);
    ifac[i] %= mod;
  }
}

ll nck(ll n, ll k) {
  assert(n>=0 && k>=0);
  if (k > n) return 0;
  return (((fac[n] * ifac[k]) % mod) * ifac[n-k]) % mod;
}

void testlib() {
  assert(modpow(1,1) == 1);
  assert(modpow(4,2) == 16);
  assert(modpow(2,5) == 32);
  assert(fac[3] == 6);
  assert(nck(4,2) == 6);
  assert(nck(10,2) == 45);
}


Measured memory_bytes: 8064
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.C
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			decimal a = cin.NextLong();
			string s = cin.Next();
			decimal b = (s[0] - '0') * 100 + (s[2] - '0') * 10 + s[3] - '0';
			Console.WriteLine((long)Math.Floor((a * b) / 100));

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

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

int A[128], N;

int main() {

	while ( cin >> N && N ) {

		A[0] = 1;
	
		for ( int i = 1; i <= N; i++ ) {
	
			A[i] = A[i-1];
		
			if ( i >= 2 ) { A[i] += A[i-2]; }
			if ( i >= 3 ) { A[i] += A[i-3]; }
	
		}
		
		cout << ( ( A[N] + 9 ) / 10 + 364 ) / 365 << endl;

	}

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int INF=1e9;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  vector<ll>vec(3*n);
  priority_queue<ll,vector<ll>,greater<ll>>left;
  priority_queue<ll>right;
  vector<ll>suml(n+1,0),sumr(n+1,0);
  rep(i,3*n){
    cin >> vec[i];
    if(i<n){
      suml[0]+=vec[i];
      left.push(vec[i]);
    }
    if(2*n<=i){
      sumr[n]+=vec[i];
      right.push(vec[i]);
    }
  }
  rep(i,n){
    suml[i+1]=suml[i]+vec[n+i];
    left.push(vec[n+i]);
    suml[i+1]-=left.top();
    left.pop();
  }
  rep(i,n){
    sumr[n-i-1]=sumr[n-i]+vec[2*n-i-1];
    right.push(vec[2*n-i-1]);
    sumr[n-i-1]-=right.top();
    right.pop();
  }
  ll ans=suml[0]-sumr[0];
  rep(i,n){
    ans=max(ans,suml[i+1]-sumr[i+1]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6644
import java.util.*;
import java.io.*;
public class Main{
    public  static void main(String[] args)throws IOException{
	InputStreamReader isr = new InputStreamReader(System.in);
	BufferedReader br=new BufferedReader(isr);
	int[] tr=new int[10];
	String a = br.readLine();
	int i=0;
	while(a!=null){
	    int aa =Integer.parseInt(a);
	    if(aa==0){
		System.out.println(tr[i-1]);
		i--;
	    }
	    else{
		tr[i]=aa;
		i++;
	    }
	   a= br.readLine();
	}
    }
}

Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
struct pref{
    int num,p,y;
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll n,m;
    cin >> n >> m;
    vector<pref>A(m);
    vector<int> T(n+1,1);
    REP(i,m){
        A[i].num= i;
        cin >> A[i].p >> A[i].y;
    }
    sort(A.begin(), A.end(), [](const pref &a, const pref &b){ return a.y<b.y; });
    REP(i,m){
        A[i].y= T[A[i].p];
        T[A[i].p]++;
    }
    sort(A.begin(), A.end(), [](const pref &a, const pref &b){ return a.num<b.num; });
    REP(i,m){
        cout << setfill('0') << right << setw(6) << A[i].p;
        cout << setfill('0') << right << setw(6) << A[i].y << endl;
    }
}


Measured memory_bytes: 3072
N = int(input())
inList = list(map(int, input().split()))

inList.sort()

noFlag = 0

for indx in range(len(inList) - 1):
  if inList[indx] == inList[indx + 1]:
    print("NO")
    noFlag = 1
    break

if noFlag == 0:
  print("YES")

Measured memory_bytes: 26808
import bisect

A, B, Q = map(int, input().split())
S = [-float('inf')] + [int(input()) for _ in range(A)] + [float('inf')]
T = [-float('inf')] + [int(input()) for _ in range(B)] + [float('inf')]

for _ in range(Q):
    answer = float('inf')
    x = int(input())
    si = bisect.bisect_left(S, x)    
    ti = bisect.bisect_left(T, x)
    for s in [S[si-1], S[si]]:
        for t in [T[ti-1], T[ti]]:
            d = min(abs(s-x), abs(t-x)) + abs(t-s)            
            answer = min(answer, d)
    print(answer)

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    vector<int> x(100001);
    int minv, maxv;
    rep(i, n) {
        cin >> a.at(i);
        x.at(a.at(i))++;
        if (a.at(i)-1 >= 0)
            x.at(a.at(i)-1)++;
        //cout << min(99999, a.at(i)+1);
        if (a.at(i) + 1 <= 100000)
            x.at(a.at(i)+1)++;
    }
    int ans = 0;
    rep(i, 100001) {
        //cout << x.at(i);
        ans = max(ans, x.at(i));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(int)n; i++)
    
int main(){
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    printf("%f ", (double)w*h/2);
    if(2*x==w && 2*y == h) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

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

    sort(p.begin(),p.end(),greater<ll>());
    ll ans=0;
    rep(i,n){
        if(i==0) ans+=p[i]/2;
        else ans+=p[i];
    }

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

Measured memory_bytes: 3596
#include<stdio.h>

int main()
{
    int k;
    int a, b;
    scanf("%d",&k);
    scanf("%d%d",&a,&b);

    int sum=0;

    for(int i=a; i<=b; i++)
    {
        if(i%k==0)
        {
            sum++;
            printf("OK\n");
            break;
        }

    }
    if(sum==0)
        printf("NG\n");
        return 0;
}


Measured memory_bytes: 1644
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <utility>
using namespace std;
const int inf = 1e9;

int main(){
    while(1){
        int n,m,cap;
        cin >> n >> m >> cap;
        cap *= 10;
        if(n==0) break;

        string src, dest;
        cin >> src >> dest;
        vector<int> c1(n), c2(n), d(n);
        map<string, int> city;
        city[src] = 0;
        city[dest] = 1;
        int count = 2;
        for(int i=0; i<n; i++){
            string s1,s2;
            cin >> s1 >> s2 >> d[i];
            if(city.count(s1)==0){
                city[s1] = count;
                count++;
            }
            if(city.count(s2)==0){
                city[s2] = count;
                count++;
            }
            c1[i] = city[s1];
            c2[i] = city[s2];
        }

        vector<vector<pair<int, int> > > adj(count);
        for(int i=0; i<n; i++){
            adj[c1[i]].push_back(make_pair(c2[i], d[i]));
            adj[c2[i]].push_back(make_pair(c1[i], d[i]));
        }
        vector<bool> sta(count, false);
        for(int i=0; i<m; i++){
            string s;
            cin >> s;
            sta[city[s]] = true;
        }

        priority_queue<pair<int, pair<int, int> > > wait;
        wait.push(make_pair(0, make_pair(0, cap)));
        vector<vector<int> > mindist(count, vector<int>(cap+1, inf));
        mindist[0][cap] = 0;
        int ans = -1;
        while(!wait.empty()){
            int dist = -wait.top().first;
            int pos = wait.top().second.first;
            int gas = wait.top().second.second;
            wait.pop();
            if(dist > mindist[pos][gas]) continue;
            if(pos == 1){
                ans = dist;
                break;
            }
            for(int i=0; i<(int)adj[pos].size(); i++){
                int ndist = adj[pos][i].second;
                int npos = adj[pos][i].first;
                int ngas = (sta[npos])? cap: gas-ndist;
                if(gas >= ndist && dist+ndist < mindist[npos][ngas]){
                    wait.push(make_pair(-(dist+ndist), make_pair(npos, ngas)));
                    mindist[npos][ngas] = dist+ndist;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

int main() {
	ll l, r, d;
	cin >> l >> r >> d;
	ll ans = 0;
	for (ll i = l; i <= r; ++i) {
		if (i % d == 0)++ans;
	}
	cout << ans << endl;
}


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

int main() {
	int n, sum=0;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	for(int i=0; i<n; i++)
	{
		if(a[i]==i+1)
		{
			sum++;
			i++;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 640
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int i=0 ; i<b ; i++)scanf("%d",&a[i])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int n;
	scd(n);
	LL a[20000];
	LL sum=0;
	forin(i,0,n)
	{
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	
	LL max=a[0],min=a[0];
	forin(i,0,n)
	{
		if(max<a[i])
		max=a[i];
		
		if(min>a[i])
		min=a[i];
	}
	printf("%lld %lld %lld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 3292
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
//fixed<<setprecision(10)<<ans<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sx,sy,tx,ty;
    cin >> sx>>sy>>tx>>ty;
    int X=tx-sx;
    int Y=ty-sy;
    string ans = "";
    ans += string(X,'R') + string(Y,'U');
    ans += string(X,'L') + string(Y,'D');
    ans += 'D' + string(X+1,'R') + string(Y+1,'U') + 'L';
    ans += 'U' + string(X+1,'L') + string(Y+1,'D') + 'R';

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int masu[20][20];

int main(int argc, char *argv[])
{
	int h, w;
	int g, r;
	int i, j;
	int cnt;

	scanf("%d %d", &h, &w);
	scanf("%d %d", &g, &r);
	for (i = 0; i < h; i++){
		for (j = 0; j < w; j++) {
			masu[i][j] = 0;
		}
	}

	for (i = 0; i < g; i++){
		for (j = 0; j < w; j++) {
			masu[i][j] = 1;
		}
	}
	for (i = 0; i < h; i++) {
		for (j = 0; j < r; j++) {
			masu[i][j] = 1;
		}
	}
	cnt  = 0;
	for (i = 0; i < h; i++){
		for (j = 0; j < w; j++) {
			if (masu[i][j] == 0){
				cnt++;
			}
		}
	}
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979

typedef long long Int;
typedef unsigned long long UINT;
typedef vector <int> VI;
typedef pair <int, int> PII;

const int INF = 1000000000;
const int MAX = 200000;
const int UP = 2160;
const int UP2 = 100000;

int n;

Int check(Int x)
{
    Int Min = 1, Max = UP2;
    while (Min < Max)
    {
        Int Mid = (Min+Max)/2;
        if (Mid*Mid < x)
            Min = Mid+1;
        else
            Max = Mid;
    }

    if (Min*Min == x)
        return Min;
    return 0;
}

map<Int, int> C;
map<Int, Int> Q;

int main()
{
	//freopen("in.txt", "r", stdin);
	
	cin >> n;
	int res = 0;
	int res2 = 0;

	FOR (i,0,n)
	{
	    Int x;
	    scanf("%lld", &x);
	    
	    vector< pair<Int, int> > P;
	    FOR (j,2,UP)
	    {
	        if (j > 2 && (j & 1) == 0) continue;
	        int cnt = 0;
	        while (x > 1 && x % j == 0)
	        {
	            ++ cnt;
	            cnt %= 3;
	            x /= j;
	        }
	        if (cnt)
	        {
	            P.PB(MP(j, cnt));
	        }
	    }
	    
	    if (x != 1)
    	{
    	    Int d = check(x);
    	    if (d != 0)
    	    {
    	        P.PB(MP(d, 2));
    	    }
    	    else
            if (x > UP2)
            {
                ++ res;
                continue;
            }
            else
            {
                P.PB(MP(x, 1));
            }
    	}
    	
    	Int d = 1;
    	FOR (i,0,SZ(P))
    	    FOR (j,0,P[i].second)
    	        d *= P[i].first;
    	        
    	Int q = 1;
    	FOR (i,0,SZ(P))
    	    FOR (j,0,3-P[i].second)
    	        q *= P[i].first;
    	        
        C[d] ++;
        Q[d] = q;
        Q[q] = d;
	}
	
	for (map<Int, Int>::iterator it = Q.begin(); it != Q.end(); ++it)
	{
	    Int d = it->first;
	    int c = C[d];
	    Int q = it->second;
	    if (d == q)
	        res += min(c, 1);
	    else
	        res2 += max(c, C[q]);
	}
	
	res += res2 / 2;
	
	cout << res << endl;
	
	   
    return 0;
}

Measured memory_bytes: 20864
a = int(input())
b = int(input())
c = int(input())
x = int(input())
i1, i2, i3, p = 0, 0, 0, 0
while i1 <= a:
  while i2 <= b:
    while i3 <= c:
      m = 500 * i1 + 100 * i2 + 50 * i3
      if m > x:
        break
      elif m == x:
        p += 1
      i3 += 1
    i3 = 0
    i2 += 1
  i2 = 0
  i1 += 1
print(p)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
//setprecision(10);
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
        return b != 0 ? gcd(b, a % b) : a;
    }

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



vector<vector<pair<int,int>>> al(100000);
vector<int> dist(100000,inf * -1);
vector<bool> visited(100000,false);

bool bfs(int i,int d){

    if(visited[i] && d != dist[i]) return false;

    if(visited[i] && d == dist[i]) return true;

    visited[i] = true;
    dist[i] = d;
    for(int j=0; j<al[i].size(); j++){
        if( ! bfs(al[i][j].first, d + al[i][j].second) ) return false;
    }

    return true;
}



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //COMinit();
    int n,m;
    cin >> n >> m;

    for(int i=0; i<m; i++){
        int l,r,d;
        cin >> l >> r >> d;
        l--; r--;
        al[l].push_back(make_pair(r,d));
        al[r].push_back(make_pair(l,-1*d));
    }

    for(int i=0; i<n; i++){
        if(!visited[i]){
            if( ! bfs(i,0) ){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
        return 0;
    }





Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int Q;

int cdiv(int a, int b) { return (a+b-1)/b; }

int eval(int a, int b, int i, int L) {
    return i-i/(L+1)+(a+b-i)/(L+1);
}

bool ok(int a, int b, int i, int L) {
    if (i < 0 || i > a+b) return 0;
    if (eval(a,b,i,L) != a) return 0;
    if (i && a+b-i) if ((i % (L+1) == 0) ^ ((a+b-i) % (L+1) == 0)) return 0;
    return 1;
}

vi get(int a, int b) {
    int L = cdiv(max(a,b),min(a,b)+1);
    if (a > (ll)b*L) return {a,b,L,a+b};
    if (b > (ll)a*L) return {a,b,L,0};
    
    int lo = 0, hi = a+b;
    while (lo < hi) {
        int mid = (lo+hi)/2;
        if (eval(a,b,mid,L) < a) lo = mid+1;
        else hi = mid;
    }
    
    // cout << eval(a,b,lo,L) << " " << a << "\n";
    while (1) {
        if (ok(a,b,lo,L)) return {a,b,L,lo};
        lo --;
        if (ok(a,b,hi,L)) return {a,b,L,hi};
        hi ++;
    }
}

string get(int L, int x, int c, int d) {
    d = min(d,x-1);
    if (c > d) return "";
    string res;
    FOR(i,c,d+1) {
        if ((i+1) % (L+1) == 0) res += 'B';
        else res += 'A';
    }
    return res;
}

string extract(vi x, int c, int d) {
    string s1 = get(x[2],x[3],c,d);
    string s2 = get(x[2],x[0]+x[1]-x[3],x[0]+x[1]-1-d,x[0]+x[1]-1-c);
    reverse(all(s2));
    for (char& c: s2) c = char('A'+(1-(c-'A')));
    return s1+s2;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> Q;
    F0R(i,Q) {
        int a,b,c,d; cin >> a >> b >> c >> d;
        vi x = get(a,b);
        cout << extract(x,c-1,d-1) << "\n";
    }
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  string s;
  cin >> n >> s;
  vl a(n+1);
  rep(i,n){
    if(s[i]=='.'){
      a[0]++;
    }
  }
  FOR(i,1,n+1){
    if(s[i-1]=='#'){
      a[i]=a[i-1]+1;
    }
    else
      a[i]=a[i-1]-1;
  }
  ll ans=INF;
  rep(i,n+1){
    ans=min(ans,a[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2180
#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 RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    ll x; cin >> x;
    for(ll i = -1000; i <= 1000; i++){
        for(ll j = -1000; j <= 1000; j++){
            ll a5 = i * i * i * i * i;
            ll b5 = j * j * j * j * j;
            if(a5 - b5 == x){
                cout << i << " " << j << endl;
                //cout << a5 << endl;
                //cout << b5 << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3624
import Data.List (intercalate)

type Point = (Int, Int)

rotL :: Point -> Point
rotL (x, y) = (-y , x)

main = do
    [x1, y1, x2, y2] <- map read . words <$> getLine :: IO [Int]
    let v1 = (x2 - x1, y2 - y1)
    let v2 = rotL v1
    let v3 = rotL v2
    let (x3, y3) = (x2 + fst v2, y2 + snd v2)
    let (x4, y4) = (x3 + fst v3, y3 + snd v3)
    putStrLn $ (intercalate " " . map show) [x3, y3, x4, y4]

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

char map[14][14];
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

void solve(int i, int j){
  int k,ni,nj;

  map[i][j] = '0';
  for(k=0;k<4;k++){
    ni = i + dir[k][0];
    nj = j + dir[k][1];
    if(map[ni][nj] == '1'){
      solve(ni,nj);
    }
  }
}

int main(void){
  int i,j,rst;

  while(1){
    rst = 0;
    memset(map,'0',sizeof(map));
    for(i=1;i<=12;i++){
      if(scanf("%s",&map[i][1]) == EOF) return 0;
      map[i][13] = '0';
    }

    for(i=1;i<=12;i++){
      for(j=1;j<=12;j++){
	if(map[i][j] == '1'){
	  solve(i,j);
	  rst++;
	}
      }
    }
    printf("%d\n",rst);
  }
}

Measured memory_bytes: 0
#include<iostream>
#include <algorithm>
#include<iomanip>
#include<math.h>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int main() {
    int n,t;
    long long sum=0;
    cin >> n;
    for (int x = 1; x <=n; x++) {
        for (int y = 1; y <= n; y++) {
            for (int z = 1; z <= n; z++) {
                t=gcd(y,z);
                sum += gcd(t, x);
            }
        }
    }
    cout << sum;


    return 0;
}

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

int main() {
    string s;
    cin >> s;
    if(s[0] == 'A' && s[1] == 'A' && s[2] == 'A') {
        cout << "No" << endl;
    } else if (s[0] == 'B' && s[1] == 'B' && s[2] == 'B') {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second

typedef long long ll;

using namespace std;

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, cnt = 0;

    cin >> n;

    int arr[n];

    for (int i = 0; i < n; i++) {

        cin >> arr[i];
    }

    for (int i = 1; i < n-1; i++) {

        vector <int> v(3);

        v[0] = arr[i-1], v[1] = arr[i], v[2] = arr[i+1];

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

        if (arr[i] == v[1]) cnt++;
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector <vector <char>> s(h, vector <char> (w));
    vector <pair <int, int>> goals(n);
    pair <int, int> st;
    rep (i, h) rep (j, w) {
        cin >> s[i][j];
        if (s[i][j] == 'S') st = make_pair(i, j);
        if (isdigit(s[i][j])) goals[s[i][j] - '0' - 1] = make_pair(i, j);
    }

    int ans = 0;
    const int INF = 1000000000;
    for (auto & goal : goals) {
        queue <pair <int, int>> que;
        vector <vector <int>> dist(h, vector <int> (w, INF));
        que.push(st);
        dist[st.first][st.second] = 0;

        while(!que.empty()) {
            pair <int, int> now = que.front(); que.pop();
            int dx[] = {  0,  1,  0, -1},
                dy[] = { -1,  0,  1,  0};

            rep (i, 4) {
                int tox = now.first + dx[i], toy = now.second + dy[i];
                if (tox < 0 || h <= tox || toy < 0 || w <= toy) continue;
                if (s[tox][toy] == 'X') continue;
                if (dist[tox][toy] > dist[now.first][now.second] + 1) {
                    dist[tox][toy] = dist[now.first][now.second] + 1;
                    que.emplace(tox, toy);
                }
            }
        }

        st = goal;
        ans += dist[goal.first][goal.second];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7772
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long dp[1005][1005];
long long h,k;
char mat[1006][1007];
long long rec(int i, int j){
    if(dp[i][j]!=-1)return dp[i][j];
    if(i==h-1 and j==k-1)return 1;
    else if((mat[i+1][j]=='#' or mat[i+1][j]=='-') and(mat[i][j+1]=='#' or mat[i][j+1]=='-'))return 0;
    else if(mat[i][j+1]=='#' or mat[i][j+1]=='-')return dp[i][j]=rec(i+1,j);
    else if( mat[i+1][j]=='#' or mat[i+1][j]=='-')return dp[i][j]=rec(i,j+1);
    else if(j+1<k and i+1<h and mat[i][j+1]!='#' and mat[i+1][j]!='#')return dp[i][j]=(rec(i+1,j)+rec(i,j+1))%MOD;
}
int main(){
    cin>>h>>k;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<=h;i++){
        for(int j=0;j<=k;j++){
          if(i<h and j<k)cin>>mat[i][j];
          else mat[i][j]='-';
        }
    }

    cout<<rec(0,0)%MOD;
}


Measured memory_bytes: 9216
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace AtcoderExpress
{


    class Program2
    {
        static String S;
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var Max = -10000000L;
            var Maxi = 0L;
            var Min = 10000000L;
            var Mini = 0L;

            for (int i = 0; i < N; i++)
            {
                if(A[i] < Min)
                {
                    Min = A[i];
                    Mini = i;
                }

                if (A[i] > Max)
                {
                    Max = A[i];
                    Maxi = i;
                }
            }

            var ans = new List<String>();
            var count = 0;
            if((Max > 0 && Abs(Max) >= Abs(Min)) ||Min >= 0)
            {
                for (int i = 0; i < N; i++)
                {
                    if(i != Maxi)
                    {
                        A[i] += Max;
                        ans.Add((Maxi+1)+" "+(i+1));
                        count++;
                    }
                }

                for (int i = 1; i < N; i++)
                {
                    if(A[i] < A[i - 1])
                    {
                        A[i] += A[i - 1];
                        ans.Add(i+ " " + (i + 1));
                        count++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < N; i++)
                {
                    if (i != Mini)
                    {
                        A[i] += Min;
                        ans.Add((Mini + 1) + " " + (i + 1));
                        count++;
                    }
                }

                for (long i = N-1; i > 0; i--)
                {
                    if (A[i] < A[i - 1])
                    {
                        A[i-1] += A[i];
                        ans.Add(i+1 + " " + i);
                        count++;
                    }
                }
            }

            Console.WriteLine(count);
            foreach(var item in ans)
            {
                Console.WriteLine(item);
            }
        }


    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
using namespace std;
typedef long long int lli;
int main(void)
{
    int N;
    cin >> N;
    vector<int> b;
    int tmp;
    for (int i = 0; i < N - 1; i++)
    {
        cin >> tmp;
        b.push_back(tmp);
    }
    vector<int> a;
    if (b[0] <= b[1])
    {
        a.push_back(b[0]);
        a.push_back(b[0]);
    }
    else
    {
        a.push_back(b[0]);
        a.push_back(b[1]);
    }
    for (int i = 1; i < N - 2; i++)
    {
        if (b[i] > b[i + 1])
        {
            a.push_back(b[i + 1]);
        }
        else
        {
            a.push_back(b[i]);
        }
    }
    a.push_back(b[N - 2]);
    lli ans = 0;
    ans = accumulate(a.begin(), a.end(), 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
N,K = gets.split(' ').map(&:to_i)
h = gets.split(' ').map(&:to_i)
a = Array.new(N, Float::INFINITY)
a[0] = 0

if N < K
  (1...N).each do |i|
    (1..i).each do |j|
      x = a[i-j] + (h[i]-h[i-j]).abs
      a[i] = x if x < a[i]
    end
  end
else
  (1...K).each do |i|
    (1..i).each do |j|
      x = a[i-j] + (h[i]-h[i-j]).abs
      a[i] = x if x < a[i]
    end
  end

  (K...N).each do |i|
    (1..K).each do |j|
      x = a[i-j] + (h[i]-h[i-j]).abs
      a[i] = x if x < a[i]
    end
  end
end

print a[N-1]


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; string s; cin>>n>>s;
	int ans=0;
	for(int i=1;i<n;++i){
		vector<bool>usdl(26,false);
		for(int j=0;j<i;++j){
			usdl.at(s.at(j)-'a')=true;
		}
		vector<bool>usdr(26,false);
		for(int j=i;j<n;++j){
			usdr.at(s.at(j)-'a')=true;
		}
		int tans=0;
		for(int j=0;j<26;++j){
			if(usdl.at(j)&&usdr.at(j))++tans;
		}
		ans=max(ans,tans);
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3656
// B - Comparison

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> s;
  cin >> t;

  if (s > t && s.size() >= t.size())
  {
    cout << "GREATER"
         << "\n";
  }
  else if (s == t)
  {
    cout << "EQUAL"
         << "\n";
  }
  else
  {
    cout << "LESS"
         << "\n";
  }
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int w = sc.nextInt();
    String ans = "unsafe";
    if(s>w)
      ans = "safe";
    
    System.out.println(ans);
  }
}


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


#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;

int memo[128][128][128];

int main(void){
    vector<int> a(3);
    int ans = 0;

    rep(i,3) cin >> a[i];

    sort(a.begin(), a.end());
    int x;
    x = a[2] - a[0];
    x/=2;
    a[0] += x * 2;
    ans += x;

    x = a[2] - a[1];
    x/=2;
    a[1] += x * 2;
    ans += x;

    sort(a.begin(), a.end());
    if(a[0] + 1 == a[1] + 1 && a[1] + 1 == a[2]){
        ans += 1;
    }else if(a[0] + 1 == a[1] && a[1] == a[2]){
        ans += 2;
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B < C + D)
    cout << "Right" << endl;
   else if (A + B == C + D)
    cout << "Balanced" << endl;
  else
    cout << "Left" << endl;
}

Measured memory_bytes: 256