akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll H, W;
    cin >> H >> W;

    ll minS = LINF;
    for (int h = 1; h < H - 1; h++) {
        ll Sa = h * W;
        ll w = W / 2;
        ll Sb1 = (H - h) * (W - w), Sc1 = (H - h) * w;
        ll h2 = (H - h) / 2;
        ll Sb2 = h2 * W, Sc2 = (H - h - h2) * W;
        ll ma1 = max({Sa, Sb1, Sc1}), ma2 = max({Sa, Sb2, Sc2});
        ll mi1 = min({Sa, Sb1, Sc1}), mi2 = min({Sa, Sb2, Sc2});
        minS = min({minS, ma1 - mi1, ma2 - mi2});
    }
    ll h = H - 1;
    ll Sa = h * W;
    ll w = W / 2;
    ll Sb1 = (H - h) * (W - w), Sc1 = (H - h) * w;
    ll ma1 = max({Sa, Sb1, Sc1});
    ll mi1 = min({Sa, Sb1, Sc1});
    minS = min({minS, ma1 - mi1});
    for (int w = 1; w < W - 1; w++) {
        ll Sa = w * H;
        ll h = H / 2;
        ll Sb1 = (H - h) * (W - w), Sc1 = h * (W - w);
        ll w2 = (W - w) / 2;
        ll Sb2 = w2 * H, Sc2 = (W - w - w2) * H;
        ll ma1 = max({Sa, Sb1, Sc1}), ma2 = max({Sa, Sb2, Sc2});
        ll mi1 = min({Sa, Sb1, Sc1}), mi2 = min({Sa, Sb2, Sc2});
        minS = min({minS, ma1 - mi1, ma2 - mi2});
    }
    w = W - 1;
    Sa = w * H;
    h = H / 2;
    Sb1 = (H - h) * (W - w), Sc1 = h * (W - w);
    ma1 = max({Sa, Sb1, Sc1});
    mi1 = min({Sa, Sb1, Sc1});
    minS = min({minS, ma1 - mi1});
    cout << minS << '\n';
}


Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(r <= x && x <= w-r && r <= y && y <= h-r) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int main(){
    int N, Y;
    cin >> N >> Y;

    int yu = 0, it = 0, ng = 0;
    for(yu = 0; yu <= N; yu++){
        for(int it = 0; it <= N; it++){
            if(10000*yu + 5000*it + 1000*(N-yu-it) == Y && N-yu-it >= 0){
                cout << yu << " " << it << " " << N-yu-it << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

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

using namespace std;

int main() {
  vector<int> V(3);
  for (int i = 0; i < 3; i++) cin >> V[i];
  sort(V.begin(), V.end());
  if (V[0] + V[1] == V[2]) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}


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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			D();
		}

		public static void D()
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int k = cin.Int();
			long[] v = new long[n];
			for (int i = 0; i < n; i++) {
				v[i] = cin.Int();
			}

			int max = Math.Min(n, k);
			long ans = 0;
			for (int l = 0; l <= max; l++) {
				for (int r = 0; l + r <= max; r++) {
					int remain = k - l - r;
					List<long> vv = new List<long>();

					for (int i = 0; i < l; ++i) {
						vv.Add(v[i]);
					}

					for (int i = 0; i < r; i++) {
						vv.Add(v[n - 1 - i]);
					}

					vv.Sort();
					for (int i = 0; i < remain; i++) {
						if (vv.Count > 0 && vv[0] < 0) {
							vv.RemoveAt(0);
						}
					}

					ans = Math.Max(ans, vv.Sum());
				}
			}

			Console.WriteLine(ans);
		}


	}

	public 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 Int()
		{
			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] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			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] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			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] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 13396
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	long N = sc.nextLong();
    	long A = sc.nextLong();
    	long B = sc.nextLong();
    	if ((B-A)%2 == 0) {
    		System.out.println((B-A)/2);
    	} else {
    		if (N-A < B-1) {
    			System.out.println((B-A-1)/2+(N-B+1));
    		} else {
    			System.out.println((B-A-1)/2+A);
    		}
    	}
    }
}

Measured memory_bytes: 22612
n = int(input())

def dot(a,b):
    return a[0] * b[0] + a[1] * b[1]

from math import sqrt
def s(a):
    return a[0]**2 + a[1]**2
for i in range(n):
    points = [int(j) for j in input().split()]
    p0 = points[:2]
    p1 = points[2:4]
    a = [p0[0]-p1[0],p0[1]-p1[1]]
    p2 = points[4:6]
    p3 = points[6:8]
    b = [p2[0]-p3[0],p2[1]-p3[1]]
    c = dot(a,b)**2/(s(a) * s(b))
    if c == 0:
        print(1)
    elif c == 1:
        print(2)
    else:
        print(0)

Measured memory_bytes: 7900
// AOJ 2937 Tile
// 2018.3.12 bal4u@uu

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

int main()
{
	int h, w, a, b;

	scanf("%d%d%d%d", &h, &w, &a, &b);
	printf("%d\n", (h%a)*w+h*(w%b)-(h%a)*(w%b));
	return 0;
}


Measured memory_bytes: 2112
#include <cstdio>
#include <algorithm>
#define Min(A, B) A < B ? A : B
const int MaxN = 1e6 + 10;
int N, L[MaxN];
int main() {
	scanf("%d", &N);
	for(int i = 1; i <= 2 * N; i++) scanf("%d", &L[i]);		
	std::sort(L + 1, L + 1 + N * 2);
	int Cnt = 0;
	for(int i = 2; i <= 2 * N; i += 2) Cnt += Min(L[i], L[i - 1]);
	printf("%d", Cnt);
} 

Measured memory_bytes: 128
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return x0

def modinv(a, m):
    x = xgcd(a, m)
    return x % m


max_num = 10 ** 9 + 7
res = 0
n, m, k = map(int, input().strip().split())

for d in range(1, n):
    res += (n - d) * d * m * m
    res %= max_num
for d in range(1, m):
    res += (m - d) * d * n * n
    res %= max_num

r = min(n*m-2, k-2)
for i in range(1, r+1):
    res *= n * m - 1 - i
    res %= max_num
for i in range(1, r+1):
    res *= modinv(i, max_num)
    res %= max_num

print(res)


Measured memory_bytes: 9160
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }
template<class T>
inline T upper(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	int all = 0;
	rep(i, m) {
		int v;
		cin >> v;

		all += v;
	}

	if (n >= all) cout << n - all << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

char cm[30][30];

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

int mm[30][30];

void init(){
	for( int i = 0; i < 25; ++i ){
		for( int j = 0; j < 25; ++j ){
			mm[i][j] = 0;
		}
	}
}

int main(){
	int h, w; cin >> h >> w; 
	for( int i = 0; i < 25; ++i ){
		for( int j = 0; j < 25; ++j ){
			cm[i][j] = '#';
		}
	}
	for( int i = 0; i < h; ++i ){
		for( int j = 0; j < w; ++j ){
			char c; cin >> c;
			cm[i+1][j+1] = c;
		}
	}
	int ans = 0;
	for( int si = 1; si < h+1; ++si ){
		for( int sj = 1; sj < w+1; ++sj ){
			init();
			if( cm[si][sj] == '#' ) continue;
			queue<int> q;
			q.push((si)*100+(sj));
			int cnt = 0;
			while( !q.empty() ){
				int a = q.front(); q.pop();
				int y = a%100, x = a/100;
				for( int i = 0; i < 4; ++i ){
					if( cm[x+dx[i]][y+dy[i]] == '#' || mm[x+dx[i]][y+dy[i]] > 0 || ( x+dx[i] == si && y+dy[i] == sj ) ) continue;
					ans = max(ans, mm[x+dx[i]][y+dy[i]] = mm[x][y]+1); 
					q.push(100*(x+dx[i])+y+dy[i]);
				}
			}
			/* for( int i = 0; i < h+2; ++i ){
				for( int j = 0; j < w+2; ++j ){
					cout << mm[i][j] << ' ';
				} cout << endl;
			} cout << endl; */
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vll;
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define srt(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define mod 1000000007
#define pi 3.1415926535
lld a,b,c,d,e,f,g,h,i,j,k=0,l=0,m=1,n=1,o,q=0,r=0,u,v,w,x,y,z,s,t,p=0;
lld temp=0,ans=0;
double f1,f2,f3,f4,f5,f6;
char c2,c3,c4,c5,c6;
vll v11;
pair<lld,lld>p1,p2,p3;
map<lld,lld>mv;bool a12[200005],a13[200005];
bool b11[500006],c11[500006];lld a11[500006];
lld gcd(lld a, lld b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
}
void dfs(lld i,vector<lld>vg[])
{
    if(b11[i]==true)    return;
    p++;
    b11[i]=true;
    for(auto x11:vg[i])
    {
        if(b11[x11]==false)
        {
            dfs(x11,vg);
        }
    }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  t=1;
  //cin>>t;
  while(t--)
  {
    string s3,s1,s2;
    cin>>n>>m;
    //lld p1,q1,a1,b1,c1,d1;
    lld a1[n+1]={0},b1[n],c1[n+1];vector<lld>vg[n+1];
    map<lld,lld>m1,m2;queue<lld>q2;vll v1,v2;p=q=0;
    rep(i,1,n+1)    b11[i]=false;
    
    while(m--)
    {
        cin>>x>>y;
        vg[x].pb(y);vg[y].pb(x);
    }
    for(i=1;i<n+1;i++)
    {
        if(b11[i]==false)
        {
            p=0;dfs(i,vg);q=max(q,p);
        }
    }
    cout<<q;
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 25688
#include<cstdio>
#include<algorithm>
using namespace std;
int n,ans,sum[2000010];
char c;
int main() {
	scanf("%d",&n); ans=n;
	for (int i=1;i<=n;i++) {
		c=getchar();
		while (c!='.'&&c!='#') c=getchar();
		sum[i]=sum[i-1]+(c=='#');
	}
	for (int i=0;i<=n;i++) ans=min(ans,sum[i]+n-i-(sum[n]-sum[i]));
	printf("%d\n",ans);
	return 0;
}

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

const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using P = pair<int, int>;



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

    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) cout << "Yes" << "\n";
    else cout << "No"  << "\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	int k; cin >> k;
	int x, y; cin >> x >> y;

	int res = 0;
	for (int i = 1; i <= n; i++) {
		if (i <= k) {
			res += x;
		}
		else {
			res += y;
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222

pll dp[55];

void merge(ll lv) {
  if (dp[lv].first <= m && dp[lv].first) {
    m -= dp[lv].first;
    ans += dp[lv].second;
    return;
  }
  pll p = pll(m, ans);
  if (!m) return;
  if (m) m--;
  merge(lv - 1);
  if (m) {
    m--; ans++;
  }
  merge(lv - 1);
  if (m) m--;
  dp[lv].first = p.first - m;
  dp[lv].second = ans - p.second;
}


int main(void) {


  cin >> n >> m;
  dp[0].first = 1;
  dp[0].second = 1;
  merge(n);
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gsort(arr) sort(arr, arr+n, greater<ll>()); 
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sync2 cout<<fixed<<setprecision(10)
const ll inf=1e9+7;
const ll inf2=inf*inf;
#define pi 3.14159265358979323846
#define for0(i,n) for (int i = 0; i <(int)n; i++)
#define for1(i,n) for (int i = 1; i<=(int)n; i++)
#define all(vv) vv.begin(),vv.end()
priority_queue <ll, vector<ll>, greater<ll>> mnheap;
priority_queue <ll> mxheap;
#define vc(vv) vector<ll> vv;
ll gcd(ll x,ll y){if (x == 0)return y;return gcd(y%x, x);}
int is_prime(ll x) {if(x<2)return 0;for(ll i=2;i*i<=x;i++){if(x%i==0)return 0;}return 1;}
inline ll modpw(ll x, ll y, ll z) {ll res=1;x=x%z;while(y){if(y&1) res=(res*x)%z;x=(x*x)%z;y/=2;}return res;}
inline ll modinv(ll x,ll z){return modpw(x,z-2,z);}
ll lcm(ll x,ll y){return (x*y)/gcd(x,y);}
#define pYES cout<<"YES"<<endl
#define pNO cout<<"NO"<<endl

int dp[100005];
vector<int>adj[100005];
int vis[100005];
void dfs(int x)
{
     vis[x]=1;
     for(auto xx:adj[x])
     {
          if(vis[xx])
               continue;
          dfs(xx);
     }
     for(auto xx:adj[x])
     {
          dp[x]=max(dp[x],dp[xx]+1);
     }
}
int main()
{
     sync;
     int t;
     //cin>>t;
     t=1;
     while(t--)
     {
          int n,m;
          cin>>n>>m;
          int x,y;
          for0(i,m)
          {
               cin>>x>>y;
               adj[x].pb(y);
          }
          for(int i=1;i<=n;i++)
          {
               if(vis[i])
                    continue;
               dfs(i);
          }
          int mx=0;
          for(int i=1;i<=n;i++)
               mx=max(mx,dp[i]);
          cout<<mx<<endl;
     }
}

Measured memory_bytes: 11872
N = int(input())
a = list(map(int, input().split()))
c_odd = 0
c_even = 0
c_4 = 0

for i in range(N):
    if a[i] % 2 != 0:
        c_odd += 1
    else:
        if a[i] % 4 == 0:
            c_4 += 1
        else:
            c_even += 1

if c_even == 0:
    if c_odd <= c_4 + 1:
        print('Yes')
    else:
        print('No')
else:
    if c_odd == c_4:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 14252
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    string s;
    cin >> s;
    rep(i, 3) {
        if(s[i] == s[i+1]) {
            cout << "Bad" << '\n';
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long int
using namespace std;

int main(void) {
  int n;
  int ans;
  cin >> n;
  
  ans = n/2 + n%2;
  
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
N, K = map(int, input().split())
log = [0]*N
pre = []
ls = []
for i in range(N):
  t, d = map(int, input().split())
  t = t-1
  heappush(ls,(-d,t))
v = 0
n = 0
for i in range(K):
  d, t = heappop(ls)
  d = -d
  log[t] += 1
  v += d
  if log[t]>1:
    heappush(pre,(d,t))
  else:
    n += 1
v += n*n
ans = v
while ls and pre:
  d, t = heappop(ls)
  if log[t]>0:
    continue
  log[t] += 1
  d = -d
  pv = v
  x, y = heappop(pre)
  v -= x
  v += d
  v += 2*n+1
  n += 1
  if ans<v:
    ans = v
print(ans)

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

int a,n;
int out;

int main()
{
	cin>>a>>n;
	for(int i = 1;i <= n;i++)
	{
		int in;
		cin>>in;
		out += in;
	}
	
	if(out >= a) cout<<"Yes";
	else cout<<"No";
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(); int b = sc.nextInt();
        if ((a < 0 && b > 0) || a == 0 || b == 0) {
            System.out.println("Zero");
        } else if (a > 0) {
            System.out.println("Positive");
        } else {
            System.out.println( (b - a + 1) % 2 == 0 ? "Positive" : "Negative");
        }
    }


}

Measured memory_bytes: 35680
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
 
int main(void){
    ll n; 
    cin >> n;
    ll array[n + 1];
    for(int i = 0; i < n; i++){
        cin >> array[i];
    }
    
    array[n] = 0;
    
    ll counter = 0;
    
    int index = 0;
    
    bool isFinished = false;
    
    while(index < n){
        if(array[index + 1] == 0){
            counter++;
            break;
        }
        if(array[index] < array[index + 1]){
            for(int i = index; i < n; i++){
               if(array[i + 1] == 0){
                   counter++;
                    isFinished = true;
                    break;
                }
                if(array[i] > array[i + 1]){
                    counter++;
                    index = i + 1; 
                    break;
                }
            }
            if(isFinished)break;
        } else if(array[index] > array[index + 1]){
            for(int i = index; i < n; i++){
                if(array[i + 1] == 0){
                   counter++;
                    isFinished = true;
                    break;
                }
                if(array[i] < array[i + 1]){
                    counter++;
                    index = i + 1;
                    break;
                }
            }
            if(isFinished)break;
        } else {
            index++;
        }
    }
    
    cout << counter << endl;
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll A(N);
        rep(i, 0, N) cin >> A[i];
        sort(all(A));
        cout << abs(A.front() - A.back()) << endl;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = sc.next().split("");
        String[] t = sc.next().split("");

        List<String> result = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            result.add(s[i]);
            result.add(t[i]);
        }
        result.forEach(System.out::print);
    }
}

Measured memory_bytes: 27092
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>

#define INF 1 << 16;

using namespace std;

int pos;
string expr;

bool keisan();
string number();

string wa(string str1, string str2) {
	int sz = max(str1.size(), str2.size()) + 1;

	reverse( str1.begin(), str1.end() );
	reverse( str2.begin(), str2.end() );

	vector<int> v(sz, 0);
	for (int i = 0; i < str1.size(); ++i) v[i] += str1[i]-'0';
	for (int i = 0; i < str2.size(); ++i) v[i] += str2[i]-'0';

	for (int i = 0; i < sz-1; ++i) {
		v[i+1] += v[i] / 10;
		v[i] %= 10;
	}
	reverse( v.begin(), v.end() );

	bool f = false; string ret = "";
	for (int i = 0; i < sz; ++i) {
		if (v[i]) f = true;
		if (f) ret += v[i] + '0';
	}

	if (ret == "") ret = "0";

	return ret;
}

bool check() {
	string kou1 = number(); ++pos;
	string kou2 = number(); ++pos;
	string right = number();

	if (kou1.size() > 1 && kou1[0] == '0') return false;
	if (kou2.size() > 1 && kou2[0] == '0') return false;
	if (right.size() > 1 && right[0] == '0') return false;

	string left = wa(kou1, kou2);

	return right == left;
}
string number() {
	string str = "";
	while (expr[pos] >= '0' && expr[pos] <= '9')
		str += expr[pos++];

	return str;
}

string replace(string str, char c1, char c2) {
	for (int i = 0; i < str.size(); ++i)
		if (str[i] == c1) str[i] = c2;

	return str;
}

int main() {
	char s[1000];
	while (scanf("%s", s) != EOF) {
		string str = "";

		for (int i = 0; s[i]; ++i) str += s[i];
		str += '=';

		int ans = -1;
		for (int i = 0; i < 10; ++i) {
			pos = 0;
			expr = replace(str, 'X', i+'0');
			if ( check() ) ans = i;
		}

		if (ans < 0) cout << "NA" << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 1216
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
#define MAX(a, b) ((ll)(a) > (ll)(b)) ? (a) : (b)
#define MIN(a, b) ((ll)(a) > (ll)(b)) ? (b) : (a)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}};


const int MAX_N = 100000;
const int MAX_Q = 100000;
const long long UB = 1000000000;

long long A[MAX_N];
int N;

long long eSum[MAX_N], oSum[MAX_N];
long long sum[MAX_N];

bool lt(int x, int a, int b) {
	//if (b < 0 || b >= N) return true;
	//if (a < 0 || a >= N) return false;
	long long d1 = abs(x - A[a]);
	long long d2 = abs(x - A[b]);
	if (d1 < d2) return true;
	if (d1 == d2) return a < b;
	return false;
}

long long calc(int r, int d) {
	if (r < 0) return 0;
	if (d == 0) return eSum[r];
	else if (d == 1) return oSum[r];
	else return sum[r];
}

long long calc(int l, int r, int d) {
	if (l > r) return 0;
	return calc(r, d) - calc(l - 1, d);
}

long long query(int x) {
	int lb = 1, ub = N+1;
	while (ub - lb > 1) {
		int mid = (lb + ub) / 2;
		int a = mid / 2;
		
		if (2 * a < mid) a++;
		int l = N - mid;
		int r = N - a;
		// take [l, r]
		if (lt(x, r, l)) ub = mid;
		else lb = mid;
	}
	// lb cards: no conflict
	int a = (lb + 1) / 2;
	int d = N % 2;
	long long ans = calc(0, N - lb - 1, d) + calc(N - lb, N - a - 1, -1);
	return sum[N - 1] - ans;
}

int main() {
	int Q;
	cin >> N >> Q;
	for (int i = 0; i < N; ++i) cin >> A[i];
	sum[0] = A[0];
	for (int i = 1; i < N; ++i) sum[i] = sum[i - 1] + A[i];
	eSum[0] = A[0];
	for (int i = 1; i < N; ++i) eSum[i] = eSum[i - 1] + (i % 2 == 0 ? A[i] : 0);
	oSum[0] = 0;
	for (int i = 1; i < N; ++i) oSum[i] = oSum[i - 1] + (i % 2 == 1 ? A[i] : 0);
	for (int i = 0; i < Q; ++i) {
		long long x;
		cin >> x;
		long long ans = query(x);
		printf("%lld\n", ans);
	}
	return 0;
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int n, k;
  cin >> n >> k;

  if (k == 1)
    cout << 0 << endl;
  else
    cout << n - k << endl;

  return 0;
}


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

int main(void){
	char str[128];
	int c,f,i,l,flg;
	scanf("%s%*c",str);
	c=f=-1;
	flg=0;
	l=strlen(str);
	for(i=0;i<l;i++){
		if(str[i]=='C') c=i;
		if(str[i]=='F') f=i;
		
		if(c>=0 && f>=0 && c<f){
			flg=1;
			break;
		}
	}
	
	puts((flg)?"Yes":"No");
	return 0;
}

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

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

  int64_t sum = 0;
  int n = 0;
  int64_t A;
  int last_max;
  cin >> last_max;

  for (n = 1; n < N; n++){
    cin >> A;
    if (A < last_max){
      sum += last_max - A;
    }else{
      last_max = A;
    }
  }

  cout << sum << endl;
    
  return 0;
}


Measured memory_bytes: 3636
#include <cstdint>
#include <algorithm>
#include <iostream>
#include <list>

void mondai_b()
{
    size_t n;
    std::cin >> n;
    std::string s, t;
    std::cin >> s;
    std::cin >> t;
    std::string v;
    for ( size_t i = 0; i < n ; i++ ) {
        v += s[i];
        v += t[i];
    }
    std::cout << v;
    return;
}



int main()
{
    // mondai_a();
    mondai_b();

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
	unsigned long long n;
	vector<long long> list;

	cin >> n;
	for (unsigned long iN = 1; iN <= n; iN++)
	{
		long long num;
		cin >> num;
		list.push_back(num);
	}

	std::sort(list.begin(), list.end(), std::greater<int>());

	long long level = 0;
	long long prev = 0;
	for (int i = 0; i < n; i++)
	{
		if (list[i] != prev)
		{
			prev = list[i];
			level++;
		}
	}

	cout << level << endl;
}

//int main()
//{
//	unsigned long long n;
//	vector<long long> list;
//
//	cin >> n;
//	for (unsigned long iN = 1; iN <= n; iN++)
//	{
//		long long num;
//		cin >> num;
//		list.push_back(num);
//	}
//
//	std::sort(list.begin(), list.end(), std::greater<int>());
//
//	long long result = 0;
//	for (int i = 0; i < n; i++)
//	{
//		if (i % 2 == 0)
//		{
//			result += list[i];
//		}
//		else
//		{
//			result -= list[i];
//		}
//	}
//
//	cout << result << endl;
//}

//int main()
//{
//	unsigned long n, a, b;
//
//	cin >> n >> a >> b;
//
//	unsigned long sum = 0;
//	for (unsigned long iN = 1; iN <= n; iN++)
//	{
//		unsigned long last = iN;
//
//		unsigned long rank10000 = last / 10000;
//		last -= rank10000 * 10000;
//
//		unsigned long rank1000 = last / 1000;
//		last -= rank1000 * 1000;
//
//		unsigned long rank100 = last / 100;
//		last -= rank100 * 100;
//
//		unsigned long rank10 = last / 10;
//		last -= rank10 * 10;
//
//		unsigned long rank1 = last;
//
//		unsigned long temp_sum = rank10000 + rank1000 + rank100 + rank10 + rank1;
//		if (temp_sum >= a && temp_sum <= b)
//		{
//			sum += iN;
//		}
//	}
//
//	cout << sum << endl;
//}

//int main()
//{
//	int coin500, coin100, coin50;
//	int x;
//
//	cin >> coin500 >> coin100 >> coin50 >> x;
//
//	int count_pattern = 0;
//	for (int i500 = 0; i500 <= coin500; i500++)
//	{
//		for (int i100 = 0; i100 <= coin100; i100++)
//		{
//			for (int i50 = 0; i50 <= coin50; i50++)
//			{
//				if (i500 * 500 + i100 * 100 + i50 * 50 == x)
//				{
//					count_pattern++;
//				}
//			}
//		}
//	}
//
//	cout << count_pattern << endl;
//}

//int main()
//{
//	int n;
//	vector<int> list;
//
//	cin >> n;
//
//	for (int i = 0; i < n; i++)
//	{
//		int num;
//		cin >> num;
//		list.push_back(num);
//	}
//
//	int proc_count = 0;
//	while (true)
//	{
//		bool valid = true;
//		for (int i = 0; i < n; i++)
//		{
//			if (list[i] % 2 > 0)
//			{
//				valid = false;
//				break;
//			}
//			else
//			{
//				list[i] /= 2;
//			}
//		}
//
//		if (valid == true)
//		{
//			proc_count++;
//		}
//		else
//		{
//			break;
//		}
//	}
//
//	cout << proc_count << endl;
//}

//int main()
//{
//	string str;
//
//	cin >> str;
//
//	int count_one = 0;
//
//	if (str[0] == '1')
//	{
//		count_one++;
//	}
//	
//	if (str[1] == '1')
//	{
//		count_one++;
//	}
//
//	if (str[2] == '1')
//	{
//		count_one++;
//	}
//
//	cout << count_one << endl;
//}


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

Measured memory_bytes: 256
/* vim: set st=2 sts=2 : */
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;

typedef pair<char,int> P;

int N,Q;
int mark[100001];
int tree[100001];
P query[100001];

int get(int i){
  if(mark[i])return i;
  return tree[i]=get(tree[i]);
}

int main() {
  while(scanf("%d%d",&N,&Q),N|Q){
    memset(mark,0,sizeof(mark));
    mark[0]=1;
    for(int i=1;i<N;i++){
      scanf("%d",tree+i);
      tree[i]--;
    }
    for(int i=0;i<Q;i++){
      scanf(" %c%d",&query[i].first,&query[i].second);
      query[i].second--;
    }
    for(int i=0;i<Q;i++){
      if(query[i].first=='M'){
        mark[query[i].second]+=1;
      }
    }

    long long c=0;
    for(int i=Q-1;i>=0;i--){
      if(query[i].first=='M'){
        mark[query[i].second]-=1;
      }else{
        c+=get(query[i].second)+1;
      }
    }
    printf("%lld\n",c);
  }
}

Measured memory_bytes: 2480
#include <iostream>
using namespace std;
int main(void){
    long long int N,M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        long long int a;
        cin>>a;
        N=N-a;
    }
    if(N<0){
        cout<<-1<<endl;
    }
    else{
        cout<<N<<endl;
    }
}


Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
	int n,a1,a2,a3,a4,b1,b2,b3,b4;
	while(scanf("%d",&n),n)
	{
		while(n--)
		{
			scanf("%d%d%d%d%d%d%d%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4);
			printf("%d %d %d %d\n",
				a1*b1-a2*b2-a3*b3-a4*b4,
				a1*b2+a2*b1+a3*b4-a4*b3,
				a1*b3-a2*b4+a3*b1+a4*b2,
				a1*b4+a2*b3-a3*b2+a4*b1);
		}
	}
	return 0;
}

Measured memory_bytes: 1028
use std::io;

fn next_int() -> i64 {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn main() {
    let n = next_int();

    let mut i: i64 = 1;
    while (i+1) * (i+1) <= n {
        i += 1;
    }
    println!("{:?}", i*i);
}


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

int main(){

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

  sort(a, a+N, greater<int>());

  for(int i=0; i<N; i++){
    ans += i%2 ? -a[i] : a[i] ;
  }

  cout << ans << endl;

  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n);
    rep(i,n) cin>>a[i];
    bool ng = false;
    rep(i,n){
        if (a[i]%2==0 && !(a[i]%3==0||a[i]%5==0)){
            ng = true;
            break;
        }
    }
    if (ng){
        cout<<"DENIED\n";
    }else{
        cout<<"APPROVED\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cstdlib>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define Set(i, v) memset(i, v, sizeof i)
#define pb push_back

using namespace std;

const int N = 100010;

vector<int> G[N];

int n, m;
int col[N];
int cnt[5];

void DFS(int o){
	cnt[col[o]]++;
	for(int v : G[o]){
		if(!col[v]){
			col[v] = 3 - col[o];
			DFS(v);
		}
		else if(col[v] + col[o] != 3){
			printf("%lld\n", 1ll * n * (n - 1) / 2 - m);
			exit(0);
		}
	}
}

int main(){
	scanf("%d%d", &n, &m);
	For(i, 1, m){
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].pb(v), G[v].pb(u);
	}
	col[1] = 1;
	DFS(1);
	printf("%lld\n", 1ll * cnt[1] * cnt[2] - m);
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
 	bool ac[100010]={};
	ll wa[100010]={};
int main() {
	ll n,k;
	cin>>n>>k;

	for(ll i=0;i<k;i++){
		ll x;string s;
		cin>>x>>s;x--;
		if(s=="AC"){
			ac[x]=true;
		}
		else{
			if(ac[x]!=true){
				wa[x]++;
			}
		}
	}
		ll cnt1=0;
		ll cnt2=0;
		for(ll i=0;i<n;i++){
			if(ac[i]){
				cnt1++;
				cnt2+=wa[i];
			}
		}
		cout << cnt1<<" "<<cnt2;	
	// your code goes here
	return 0;
}

Measured memory_bytes: 4388
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int n, mm; cin >> n >> mm;
	vector<vector<mp>> v;
	map<mp, int> m;
	rep(i, n){
		m[mp(i, 0)] = v.size();
		v.push_back(vector<mp>{});
	}
	rep(i, mm){
		int p, q, c; cin >> p >> q >> c; p--; q--;
		if(m.find(mp(p, c)) ==  m.end()){
			m[mp(p, c)] = v.size();
			v.push_back(vector<mp>{});
		}
		if(m.find(mp(q, c)) ==  m.end()){
			m[mp(q, c)] = v.size();
			v.push_back(vector<mp>{});
		}
		v[m[mp(p, c)]].push_back(mp(m[mp(p, 0)], 1));
		v[m[mp(q, c)]].push_back(mp(m[mp(q, 0)], 1));
		v[m[mp(p, 0)]].push_back(mp(m[mp(p, c)], 0));
		v[m[mp(q, 0)]].push_back(mp(m[mp(q, c)], 0));
		v[m[mp(p, c)]].push_back(mp(m[mp(q, c)], 0));
		v[m[mp(q, c)]].push_back(mp(m[mp(p, c)], 0));
	}
	vector<int> d(v.size(), IINF);
	
	pque(mp) q; q.push(mp(0, m[mp(0, 0)])); d[m[mp(0, 0)]] = 0;
	while(!q.empty()){
		mp p = q.top(); q.pop();
		if(p.fir > d[p.sec]) continue;
		rep(i, v[p.sec].size()) if(d[v[p.sec][i].fir] > p.fir + v[p.sec][i].sec){
			d[v[p.sec][i].fir] = p.fir + v[p.sec][i].sec;
			q.push(mp(d[v[p.sec][i].fir], v[p.sec][i].fir));
		}
	}
	
	int ans = d[m[mp(n-1, 0)]];
	
	cout << (ans==IINF?-1:ans) << endl;
	
	return 0;
}

Measured memory_bytes: 65192
#include <iostream>
#include <vector>
#include <cmath>

#define INF 100000

using namespace std;

void chmin(int &a, int b) { if(a>b) a=b; }
void chmax(int &a, int b) { if(a<b) a=b; }

int N;
vector<int> A;

vector<int> L, R;

int rec(int a, int b){
	if(a==0) return b;
	if(b==0) return a;
	return rec(b, a%b);
}

int main() {
    cin >> N;
	A.resize(N+2);
	A[0] = 0; A[N+1] = 0;
    for(int i=1; i<=N; i++) cin>>A[i];
	
	L.resize(N+2);
	R.resize(N+2);

	L[0] = 0;
	for(int i = 1; i < N+2; i++){
		L[i] = rec(L[i-1], A[i]);
	}
	R[N+1] = 0;
	for(int i = N; i > 0; i--){
		R[i] = rec(R[i+1], A[i]);
	}

	int ans = 0;
	for(int i = 1; i <= N; i++){
		chmax(ans, rec(L[i-1], R[i+1]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
x = int(input())
#n, m = list(map(int, input().split()))
#a, b = list(map(int, input().split()))
# sy, sx = map(int, input().split())
# gy, gx = map(int, input().split())
money = 100
year = 0
while money < x:
    money *= 1.01
    money = money//1
    year += 1

print(year)


Measured memory_bytes: 9220
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
using namespace std;
int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){return x+y-min(x,y);}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<9&&b<9)cout<<"Yay!"<<endl;
    else cout<<":("<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define re register ll
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline ll
#define C(x,y) memset(x,y,sizeof(x))
#define STS system("pause")
I read(ll &res){
	res=0;re g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
} 
ll n,a,b,ans;
IN min(ll x,ll y){
	return x<y?x:y;
}
int main(){
	read(n);read(a);read(b);if(a>b)swap(a,b);
	if(!((b-a)&1ll))ans=(b-a)/2ll;
	else ans=min(a-1+((b-a+1)/2ll),n-b+((b-a+1)/2ll));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<limits>
using namespace std;

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

typedef long long ll;

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: 256
N, W = map(int, input().split())
w, v = [0]*(N+1), [0]*(N+1)
for i in range(N):
  w[i+1], v[i+1] = map(int, input().split())
  
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1,N+1):
  for j in range(W+1):
    if j < w[i]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j])
print(dp[N][W])

Measured memory_bytes: 119916
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <map>
#include <memory.h>
#include <vector>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
const double EPS = 1e-12;
const int INF = 1 << 29;

struct edge{
  int to;
  int cap;
  int rev;
  int id;
  edge(){};
  edge(int to, int cap, int rev, int id){
    this->to = to;
    this->cap = cap;
    this->rev = rev;
    this->id = id;
  }
};

vector<edge> G[400];
bool used[400];

void add_edge(int from, int to, int cap, int id){
  G[from].push_back(edge(to, cap, G[to].size(), id));
  G[to].push_back(edge(from, 0, G[from].size() - 1, -1));
}

int dfs(int v, int t, int f){
  if(v == t) return f;
  used[v] = true;
  for(int i = 0; i < (int)G[v].size(); i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap +=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t){
  int res = 0;
  for(;;){
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0) return res;
    res += f;
  }
}

int N, M, x, y;

int main(){
  int S, T;
  cin >> N >> M;
  rep(i, M){
    cin >> x >> y;
    add_edge(x, y, 1, i + 1);
    add_edge(y, x, 1, i + 1 + M);
  }
  cin >> S >> T;
  int cost = max_flow(S, T);
  vector<int> R;
  cout << cost << endl;
  for(int i = 1; i <= N; i++){
    for(int j = 0; j < (int)G[i].size(); j++){
      if(G[i][j].id > M && G[i][j].cap == 0) R.push_back(G[i][j].id - M);
    }
  }
  sort(R.begin(), R.end());
  cout << R.size() << endl;
  rep(i, (int)R.size()){
    cout << R[i] << endl;
  }
  return 0;
}

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

int r, b, g, n;

int main(){
  cin >> r >> b >> g >> n;
  int sum = 0;
  for(int i = 0; i <= n; i += r){
    for(int j = 0; j <= n; j += b){
      int num = n - i - j;
      if(num >= 0 && num % g == 0){
        sum++;
      }
      //cerr << i <<" "<< j <<" "<< n - i - j << endl;
    }
  }
  cout << sum << endl;
  return 0;
}


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

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

  int *d;
  d = new int[n];
  for(int i=0; i<n; i++){
    cin >> d[i];
  }
  
  int e = 0;
  for(int i=0; i<n; i++){
	for(int j=i+1; j<n; j++){
	  e += d[i]*d[j];
    }  
  }
  
  cout << e << endl;
  return 0;
}

Measured memory_bytes: 384
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    A = sorted(A)
    full = gcd(A[0], A[1])
    removed = set([A[0], A[1]])
    for i in range(2, N):
        temp = set()
        temp.add(full)
        for v in removed:
            temp.add(gcd(v, A[i]))
        full = gcd(full, A[i])
        removed = temp

    return max(removed)

def gcd(a, b):
    if a == 0: return b
    else: return gcd(b%a, a)

if __name__ == '__main__':
    print(main())

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

using ll=long long;



void solve(){
    int x,a,b;
    cin>>x>>a>>b;
    if(b<=a)cout<<"delicious"<<endl;
    else if(b-a<=x)cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;
}

signed main(){
    //while(1)
    solve();
}

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

using namespace std;
const int N = 1110;

int n, a[N];

int main() {
	cin >> n; int cnt = 0;
	for(int i = 1;i <= n; ++i)
		cin >> a[i];
	sort(a + 1, a + 1 + n);
	for(int i = 1;i <= n; ++i) 
		for(int j = i + 1;j <= n; ++j)
			for(int k = j + 1;k <= n; ++k)
				if(a[i] != a[k] && a[j] != a[k] && a[i] != a[j] && (a[i] + a[j] > a[k]))
					cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll h, w, K;
    cin >> h >> w >> K;
    K--;

    vvl dp(h+1, vl(w));  // dp[i+1][j] : i行j列を通過する場合の数の総数
    dp[0][0] = 1;
    rep(i, h) {  // i-1行を通過したとする
        rep(j, w) {  // j列にいるとする
            rep(b, 1<<(w-1)) {  // bのkビット目が1のときk列とk+1列を横線で繋ぐ
                vl v(w);  // v[k] : bのkビット目(v[k] = 1のときk列とk+1列を横線で繋ぐ)
                rep(k, w-1) {
                    if(b & 1<<k) {
                        v[k] = 1;
                    }
                }
                ll ok = true;  // 横線のつなぎ方がokならtrue
                rep(k, w-2) {
                    if(v[k] && v[k+1]) {  // 横線が端点を共有するときダメ
                        ok = false;
                    }
                }
                if(ok == false) {
                    continue;
                }
                // 以下横線のつなぎ方はルール的にok
                if(j >= 1 && v[j-1]) {  // j-1列目とj列目が横線でつながれているとき
                    dp[i+1][j-1] += dp[i][j];
                    dp[i+1][j-1] %= mod;
                }
                else if(j <= w-2 && v[j]) {  // j列目とj+1列目が横線でつながれているとき
                    dp[i+1][j+1] += dp[i][j];
                    dp[i+1][j+1] %= mod;
                }
                else {  // いずれも横線で繋がれていないとき
                    dp[i+1][j] += dp[i][j];
                    dp[i+1][j] %= mod;
                }
            }
        }
    }

    out(dp[h][K]);
    re0;
}

Measured memory_bytes: 256