akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

long double A[100010];

int main(){
   ll N;
   cin >> N;
   bool p = 0;
   rep(i,N){
      cin >> A[i];
      if(A[i] == 0) p = 1;
   }
   if(p){
      cout << 0 << endl;
      return 0;
   }
   long double ans = 1;
   rep(i,N){
      ans *= A[i];
      if(ans > 1e18){
         cout << -1 << endl;
         return 0;
      }
   }
   cout << (ll)ans << endl;
}


Measured memory_bytes: 5280
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    ll n; cin >> n;
    string s = "";
    while(n != 0) {
        ll k = n % 26;
        if(k == 0) { 
            s += 'z';
            n /= 26; 
            n--; 
        } 
        else {
            s += k + 'a' - 1;
            n /= 26;
        }
        
    }   
    for(int i = 0; i < s.size() / 2; i++) {
        swap(s[i], s[s.size() - i - 1]);
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979323846  

int main() {
	int m, n;
	cin >> n >> m;
	if (n == m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define M 100005
using namespace std;
int n;
LL A[M];
LL ans[M];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&A[i]),A[i]*=2;
	ans[1]=0;
	for(int i=1;i<n;i++)ans[i+1]=A[i]-ans[i];
	LL d=A[n]-(ans[1]+ans[n]);
	for(int i=1;i<=n;i++){
		if(i&1)ans[i]+=d/2;
		else ans[i]-=d/2;
		printf("%lld ",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N, K;
    io.read(N, K);
    auto p = io.read_vec<int>(N);

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

    cout << accumulate(p.begin(), p.begin() + K, 0);
    
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.StringJoiner;

class Main {

	static int n;

	static int[] inOrd;
	static int[] preOrd;
	static int[] postOrd;

	static int cIdx = 0;
	static int rIdx = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();

		inOrd = new int[n];
		for (int i = 0; i < n; i++) inOrd[i] = sc.nextInt();

		preOrd = new int[n];
		for (int i = 0; i < n; i++) preOrd[i] = sc.nextInt();

		sc.close();

		postOrd = new int[n];
		postOrder(0, n);

		StringJoiner sj = new StringJoiner(" ");
		for (int i = 0; i < n; i++) {
			sj.add(String.valueOf(postOrd[i]));
		}
		System.out.println(sj);

	}

	private static void postOrder(int l, int r) {

		if(l >= r) return;

		int next = inOrd[cIdx];
		cIdx++;

		int m = -1;
		for (int i = 0; i < r; i++) {
			if (preOrd[i] == next) {
				m = i;
				break;
			}
		}

		postOrder(l, m);
		postOrder(m+1, r);

		postOrd[rIdx] = next;
		rIdx++;
	}
}

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

int main() 
{
    ios::sync_with_stdio(0); 
    string a , b ;
    cin >> a >> b ; 
    if ( a > b ) cout << ">\n";
    else if ( a < b ) cout << "<\n" ; 
    else cout << "=\n";
    return 0 ; 
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

iscanl :: (Int -> a -> b -> a) -> a -> V.Vector b -> V.Vector a
iscanl !k !a !v = V.scanl' (\(!x) (!i, !v) -> k i x v) a (V.indexed v)

iscanlU
  :: (VU.Unbox a, VU.Unbox b)
  => (Int -> a -> b -> a)
  -> a
  -> VU.Vector b
  -> VU.Vector a
iscanlU !k !a !v = VU.scanl' (\(!x) (!i, !v) -> k i x v) a (VU.indexed v)

ipostscanlU
  :: (VU.Unbox a, VU.Unbox b)
  => (Int -> a -> b -> a)
  -> a
  -> VU.Vector b
  -> VU.Vector a
ipostscanlU !k !a !v = iscanlU (\(!i) (!a) (!b) -> k (i + 1) a b)
                               (k 0 a (VU.unsafeHead v))
                               (VU.unsafeTail v)

solve :: Int -> VU.Vector Int8 -> Double
solve !n !pn = VU.sum $ VU.drop ((n + 1) `div` 2) $ V.last dp
 where
  dp :: V.Vector (VU.Vector Double)
  dp =
    iscanl
        ( \(!i) (!prev) (!pint) -> VU.generate
          (i + 2)
          ( \(!j) ->
            let pi = fromIntegral pint / 100
                qi = 1 - pi
            in  (if j == 0 then 0 else prev VU.! (j - 1) * pi)
                  + (if i + 1 == j then 0 else prev VU.! j * qi)
          )
        )
        (VU.singleton 1)
      $ V.convert pn

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt
  let readDouble :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readDouble b = readInt $ B.drop 2 b

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  pn <- VU.unfoldrN n readDouble <$> B.getLine
  print $ solve n pn


Measured memory_bytes: 3452
<?php
fscanf(STDIN, '%d', $n);
$numbers = fgets(STDIN);
$exploded_numbers = explode(' ', trim($numbers));

$counted_numbers = array_count_values($exploded_numbers);

for ($i=1; $i<=$n; $i++) {
  $result[] = 0 + $counted_numbers[$i];
}

$str = implode("\n", $result);
echo $str;

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
typedef vector<long long> vll, vLL;

bool check(const string& s,const string& t){
	int n = s.size();
	int m = t.size();
	for(int i=0;i<=n-m;i++){
		bool ok = true;
		REP(j,m){
			if(s[i+j]!='?' && s[i+j]!=t[j])ok=false;
		}
		if(ok)return true;
	}
	return false;
}
/*int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,t[1001],a[1001];
	ll dp[1001];
	scanf("%d",&n);
	REP(i,n){
		scanf("%d %d",&t[i+1],&a[i+1]);
	}

	dp[1] = 1;
	for(int i=2;i<=n;i++){
		cout << "t率" << (double)t[i-1]/t[i] << endl;
		cout << "a率" << (double)a[i-1]/a[i] << endl;
		cout << "max" << (ll)(max((double)t[i-1]/t[i],(double)a[i-1]/a[i]) + 0.5) << endl;
		dp[i] = ((ll)(max((double)t[i-1]/t[i],(double)a[i-1]/a[i]) + 0.5))*dp[i-1];
	}
	cout << dp[n]*(ll)(a[n]+t[n]) << endl;

	return 0;
}*/
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	ll dp[1001],t[1001],a[1001];
	scanf("%d",&n);
	REP(i,n){
		scanf("%lld %lld",&t[i+1],&a[i+1]);
	}

	dp[1] = 1;
	for(int i=2;i<=n;i++){
		dp[i] = max((a[i-1]*dp[i-1] + a[i]-1) / a[i], (t[i-1]*dp[i-1] + t[i]-1) / t[i]);
		//dp[i] = ((ll)(max(t[i-1]/t[i]+(t[i-1]%t[i]!=0),a[i-1]/a[i]+(a[i-1]%a[i]!=0))))*dp[i-1];
	}
	cout << dp[n]*(ll)(a[n]+t[n]) << endl;

	return 0;
}


Measured memory_bytes: 256
import scala.collection._

object Main{
	def main(A:Array[String]){
		val s = new java.util.Scanner(System.in)
		val n,k = s.nextInt
		val a = Array.fill(n)(-s.nextInt)
		val r = new mutable.Queue[Int]
		var prev = -1
		for(_ <- 0 to k) {
			(0 until n).filter(prev !=).sortBy(a).foreach(i=>{
				a(i) += 1
				r += i + 1
				prev = i
			})
		}
		if(a forall (0 >=)) {
			println((n - 1) * (k + 1) + 1)
			println(r mkString " ")
		} else
			println(-1)
	}
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

    bool n, w, s, e;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string S;
    cin >> S;
    rep(i, S.size()) {
        if (S[i] == 'N') n = true;
        if (S[i] == 'W') w = true;
        if (S[i] == 'S') s = true;
        if (S[i] == 'E') e = true;
    }

    if (n == s && w == e) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused)]

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Self {
        Self { reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get_str(&mut self) -> &str {
        if let Some(t) = self.iter.next() {
            return t;
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get_str()
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        self.get_str().parse().ok().expect("Parse error")
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let s: String = sc.get();

    if s == "ABC" {
        println!("ARC");
    } else {
        println!("ABC");
    }
}


Measured memory_bytes: 2108
from itertools import accumulate


def get_primes_til(n):
    primes = [True] * (n + 1)
    primes[0] = False
    primes[1] = False
    for i in range(2, int(n ** .5) + 1):
        for j in range(2 * i, n + 1, i):
            primes[j] = False
    return primes


N_MAX = 10 ** 5
primes = get_primes_til(N_MAX)
is_2017_like = list(accumulate([int(primes[i] and primes[(i + 1) // 2]) for i in range(N_MAX + 1)]))
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(is_2017_like[r] - is_2017_like[l - 1])


Measured memory_bytes: 7856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dl;
const int iNF = 1e9 + 100;
const ll INF = 1e18 + 100;
typedef pair<int, int> pii;

int main(){
   
   int n;
   ll k;
   cin >> n >> k;
   vector<int> a;
   int u;
   for(int i = 0; i < n; i++){
      cin >> u;
      a.push_back(u);
   }
   int cnt = 0;
   vector<bool> vis(n, 0);
   vector<int> seq;
   seq.push_back(cnt);
   vis[cnt] = 1;
   int cycle = 0;
   while(true){
      cnt = a[cnt] - 1;
      if(vis[cnt]){
         cycle = cnt;
         break;
      }
      vis[cnt] = 1;
      seq.push_back(cnt);
   }
   vector<int> seq1;
   int ans = 0;
   bool ok1 = 0;
   for(int i = 0; i < seq.size() and k > 0; i++){
      if(seq[i] == cycle){ ok1 = 1; }
      if(ok1){
         seq1.push_back(seq[i]);
         continue;
      }
      k --;
      ans = seq[i + 1] + 1;
   }
   if(k == 0) {
      cout << ans << endl;
      return 0;
   }
   ll sz = seq1.size();
   ll cnt1 = k / sz;
   ll cnt2 = k - (sz * cnt1);
   cout << seq1[cnt2] + 1 << endl;
   return 0;
}

Measured memory_bytes: 5936
NM = input().split()
n = int(NM[0])
m = int(NM[1])

A = []
B = []
for i in range(n):
    A.append([])
    a = input().split()
    for j in range(m):
        A[i].append(int(a[j]))

for i in range(m):
    b = int(input())
    B.append(b)

out = []
for i in range(n):
    sum = 0
    for j in range(m):
        sum = sum + A[i][j]*B[j]
    out.append(sum)

for i in range(n):
    print(out[i])

Measured memory_bytes: 7936
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
int dx[8]={0,0,1,1,1,-1,-1,-1};
int dy[8]={1,-1,1,-1,0,1,-1,0};
int main(){
    int n;cin>>n;
    if(n%2){
        cout<<n*2<<endl;
    }else{
        cout<<n<<endl;
    }
}


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

#define MAX 2000000
#define INFTY INT_MAX

void swap(int*, int*);
void maxHeapify(int);
int extract();
void increaseKey(int,int);
void insert(int);

int H, A[MAX+1];

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s",com);
    if(com[0] == 'e' && com[1] == 'n')
      break;
    if(com[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }
    else
      printf("%d\n",extract());
  }

  return 0;
}

void swap(int *a, int *b){
  int temp;

  temp = *a;
  *a = *b;
  *b = temp;

}

void maxHeapify(int i){
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;
  if(l <= H && A[l] > A[i])
    largest = l;
  else
    largest = i;
  if(r <= H && A[r] > A[largest])
    largest = r;

  if(largest != i){
    swap(&A[i], &A[largest]);
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if(H < 1)
    return -INFTY;
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  if(key < A[i])
    return;
  A[i] = key;
  while(i > 1 && A[i/2] < A[i]){
    swap(&A[i],&A[i/2]);
    i = i / 2;
  }
}

void insert(int key){
  H++;
  A[H] = -INFTY;
  increaseKey(H, key);
}


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

using namespace std;

typedef long long int LL;
typedef unsigned long long int ULL;
typedef pair<int, int> PII;
typedef map<int, int> MII;

const int SZ = 112345;
const int MOD = 1e9 + 7;

LL h;

LL ans(LL n) {
  if (n == 1) {
    return 1;
  }
  return 1 + 2 * ans(n/2);
}

int main() {
  cin >> h;
  cout << ans(h) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		String str = sc.nextLine();
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String ope = sc.next();
			int start = sc.nextInt();
			int end = sc.nextInt();
			if (ope.equals("replace")) {
				String tmp = sc.next();
				String A = str.substring(0, start);
				String B = str.substring(end+1);
				str = A + tmp + B;
			} else if (ope.equals("reverse")) {
				String A = str.substring(0, start);
				String B = str.substring(end+1);
				String C = str.substring(start, end+1);
				str = A;
				for (int j = 0; j < C.length(); j++) {
					str += "" + C.charAt(C.length()-j-1);
				}
				str += B;
			} else {
				System.out.println(str.substring(start, end+1));
			}
		}
	}
}



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

class Edge {
    public:
    int s, t, w;
    Edge(int s, int t, int w):s(s),t(t),w(w){}
    bool operator < (const Edge &e) const {
        return w < e.w;
    }
};
class DisjointSet {
    public:
        vector<int> rank, p;
        DisjointSet() {}
        DisjointSet(int size) {
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i=0; i<size; i++) makeSet(i);
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }
        bool same(int x, int y) {
            return findSet(x) == findSet(y);
        }
        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }  
        void link(int x, int y) {
            if (rank[x] > rank[y]){
                p[y] = x;
            } else
            {
                p[x] = y;
                if (rank[x] == rank[y])
                {
                    rank[y]++;
                }
            }
        }    
        int findSet(int x){                         //経路圧縮して、親の値を返す
            if (x != p[x]) {
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

vector<Edge> A;
int v;
int MST(){
    DisjointSet d(v);
    int ans = 0;
    for (int i = 0; i < A.size(); i++)
    {
        if (d.same(A[i].s, A[i].t)) continue;
        ans += A[i].w;
        d.unite(A[i].s, A[i].t);
    }
    return ans;
}

int main(){
    int e, s, t, w; cin >> v >> e;
    for (int i = 0; i < e; i++)
    {
        cin >> s >> t >> w;
        A.push_back(Edge(s, t, w));
    }
    sort(A.begin(), A.end());
    cout << MST() << endl;
}


Measured memory_bytes: 4540
#include <math.h>
#include <bits/stdc++.h>//一括で読み込み
typedef long long ll;
using namespace std;

map<pair<string, string>,int> g;
int n;
string s;
ll answer;
int main()
{
	cin >> n >> s;
  
	for(int i = 0; i < (1<<n); i++)//文字数の半分をbit
  {
		string a,b;
		for(int j = 0; j < n; j++)
    {
			if((i>>j) & 1) a += s[j];
			else b += s[j];
		}
		g[{a, b}]++;
	}
  
	for(int i = 0; i < (1<<n); i++)//文字数の半分をbit
  {
		string a,b;
		for(int j = 0; j < n; j++)
    {
			if((i>>j) & 1) a += s[2*n-1-j];//逆から数えてj文字目
			else b += s[2*n-1-j];
		}
		answer += g[{a,b}];
	}
  
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 91904
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<Edge>> AdjList;
AdjList graph;
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 100000000;



int GCD(int a, int b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return GCD(b, a%b);
}

vector<pair<ll, ll>> vp;
int main() {
    //cout << fixed << setprecision(15);

    int n; cin >> n;
    REP(i, n){
        LL a ,b; cin >> a >> b;

        vp.push_back({b, a});
    }
    sort(all(vp));
    ll dp[1010][1010];
    REP(i, 1010) REP(j, 1010) dp[i][j]= INF;

    dp[0][0]=0;

    for(int i=0; i<n; ++i){
        for(int j=0; j<=n; ++j){
            if(dp[i][j]!=-1){
            chmin(dp[i+1][j],dp[i][j]);
            if(dp[i][j] + vp[i].second <= vp[i].first)chmin(dp[i+1][j+1],dp[i][j]+vp[i].second);
            }
        }
    }
    int ans = 0;
    for(int i=0; i<=n; ++i){
        if(dp[n][i]!=INF) ans = i;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
int main(){
    ll n,k;
    ll INF=1001001001;
    cin>>n>>k;
    vector<ll> h(n+1), dp(n+1,INF);
    rep(i,n) cin>>h.at(i+1);
    dp.at(1)=0;
    dp.at(2)=abs(h.at(1)-h.at(2));
    for(int i=3;i<=n;i++){
        ll x=1;
        for(int j=1;i-j>=max(x,i-k);j++){
            dp.at(i)=min(dp.at(i),dp.at(i-j)+abs(h.at(i)-h.at(i-j)));
        }
    }
    cout<<dp.at(n)<<endl;
}

Measured memory_bytes: 1792
import copy
A = [[0]*3 for i in range(3)]
for i in range(3):
    A[i] = list(map(int, input().split()))
N = int(input())
b = [int(input()) for i in range(N)]
A_copy = copy.copy(A)
for i in range(3):
    for j in range(3):
        for k in range(N):
            if A[i][j] == b[k]:
                A_copy[i][j] = -1

for i in range(3):
    if A_copy[i][0] == -1 and A_copy[i][1] == -1 and A_copy[i][2] == -1:
        print("Yes")
        exit()
    if A_copy[0][i] == -1 and A_copy[1][i] == -1 and A_copy[2][i] == -1:
        print("Yes")
        exit()
if A_copy[0][0] == -1 and A_copy[1][1] == -1 and A_copy[2][2] == -1:
    print("Yes")
    exit()
if A_copy[0][2] == -1 and A_copy[1][1] == -1 and A_copy[2][0] == -1:
    print("Yes")
    exit()
print("No")


Measured memory_bytes: 3444
import collections

n = int(input())
l = []
for i in range(n):
  l.append( input() )
  
c = collections.Counter(l).most_common()
mn = c[0][1]

res = []
for cc in c:
  if cc[1]==mn:
    res.append(cc[0])
  else:
    break

for rr in sorted(res):
  print(rr)

Measured memory_bytes: 45032
#include<bits/stdc++.h>
#define int long long int
#define endl "\n"
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define mem(a,b) memset(a,b,sizeof(a))
#define loop(i,n) for(int i=0;i<(n);i++)
#define fors(a,b,i) for(int i=(a);i<=(b);i++)
#define ford(a,b,i) for(int i=(a);i>=(b);i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fastm_fast ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL)
using namespace std;
const int  mod = 1e9 + 7;
#define pb push_back
#define mp make_pair
#define S second
#define F first
const int MAX = 1e5;
void solve()
    {
        string s,t;
        cin >> s >> t;
        int slen = s.size();
        int tlen = t.size();
        int cnt = 0;
        int tmp = 0;
        for(int i = 0; i <= slen - tlen ; i++)
            {
                for(int j = 0; j < tlen; j++)
                    {
                        if(s[i+j]==t[j])
                        {
                            tmp++;
                        }
                    }
                if(tmp > cnt)
                {
                    cnt = tmp;
                }
                tmp = 0;
            }
        cout<<tlen - cnt ; 
        
  }
int32_t main()
 {
 fastm_fast;
 int tt;
//tt
tt =1;
 while(tt--)
  {
    solve();
 }
 return 0;
 }

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(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 ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    P a[m];
    rep(i, m){
        cin >> a[i].second >> a[i].first;
    }
    sort(a, a + m);
    int now = 0;
    int ans = 0;
    rep(i, m){
        if(now < a[i].second){
            now = a[i].first - 1;
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
//  zukonit14 - Kunal Raut

#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define int         long long
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define fi          first
#define se          second
#define mod         1000000007
#define mod9        1000000009
#define pi          3.1415926535
#define MAXN        2000005
#define N           1000001
#define MAX2N       1*1000 + 10
#define all(v)      v.begin(), v.end()
#define allr(v)     v.rbegin(), v.rend()
#define ms(s, n)    memset(s, n, sizeof(s))
#define prec(n)     fixed<<setprecision(n)
#define forci(p,n)  for(ll i=p;i<(ll)n;i++)
#define forcj(p,n)  for(ll j=p;j<(ll)n;j++)
#define bolt        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define bits(a)     __builtin_popcount(a)
#define test        ll t;cin>>t;for(ll testi=1;testi<=t;testi++)
#define djokovic    freopen("input00.txt", "r", stdin);freopen("output00.txt", "w", stdout);

ll gcd(ll a, ll b)  {    if (b == 0) return a;    return gcd(b, a % b);}
ll lcm(ll a, ll b)  {    return (a / gcd(a, b) * b);}
ll expo(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) {
        if (y & 1)res = (1ll * res * x) % mod;
        y = y >> 1; x = (1ll * x * x) % mod;
    } return res;
}
ll ncr(ll n, ll r)  { ll res = 1; if (r > n - r)r = n - r; for (ll i = 0; i < r; i++) {  res *= n - i;  res /= i + 1; } return res;}
ll max(ll a, ll b)  {return (a > b) ? a : b;}
bool prime(ll n)    {ll i; for (i = 2; i <= sqrt(n); i++) {if (n % i == 0)return false;} return true;}
bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b)
{
    if (a.second - a.first == b.second - b.first)
    {
        return (a.first < b.first);
    }
    return (a.second - a.first > b.second - b.first);
}
//https://www.youtube.com/watch?v=WTJSt4wP2ME

ll rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
ll cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll INF = 2e18;
ll n, k, m, q, x, ans, b[MAXN], pref[MAXN], min1 = 2e18, max1 = 0;
ld polyapothem(ld n, ld a = 1)
{
    if (a < 0 && n < 0)
        return -1;
    return a / (2 * tan((180 / n) * pi / 180));
}
ld findRadiusOfcircumcircle(ld n, ld a = 1)
{

    if (n < 0 || a < 0)
        return -1;
    //return a / sqrt(2 - (2 * cos((360 / n) * pi / 180)));
    //return a / (2 * sin((180 / n) * pi / 180));
    return polyapothem(n) / (cos((180 / n) * 3.14159 / 180));
}
void solve()
{
    cin >> n;
    string s; cin >> s;
    if (s.size() > n)
    {
        forci(0, n)
        cout << s[i];
        cout << "...";
    }
    else
        cout << s;
}
signed main()
{
    bolt;
#ifndef ONLINE_JUDGE
    djokovic;
#endif
    solve();
}

Measured memory_bytes: 3676
import fractions

n = int(input())
a = list(map(int, input().split()))

l = [0 for i in range(n+1)]
r = [0 for i in range(n+1)]
l[1] = a[0]
r[n-1] = a[n-1]
for i in range(2, n+1):
  l[i] = fractions.gcd(l[i-1], a[i-1])
  r[n-i] = fractions.gcd(r[n-i+1], a[n-i])
  
max_gcd = 1
for i in range(n):
  if l[i] == 0 or r[i+1] == 0:
    gcd_ = l[i] + r[i+1]
  else:
    gcd_ = fractions.gcd(l[i], r[i+1])
  max_gcd = max(max_gcd, gcd_)
print(max_gcd)

Measured memory_bytes: 16156
package main

import "fmt"

func main() {
	// Code for B - Polygon
	var N int
	fmt.Scanf("%d", &N)

	L := make([]int, N)
	var max int = 0
	var maxNumber int
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &L[i])
		if max < L[i] {
			max = L[i]
			maxNumber = i
		}
	}

	var sum int
	for i := 0; i < N; i++ {
		if i != maxNumber {
			sum += L[i]
		}
	}

	if max < sum {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1832
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())
x = np.zeros(N)
y = np.zeros(N)
for i in range(N):
  x[i], y[i] = map(int, input().split())

sum = 0
for i in range(N):
  for j in range(i+1, N):
    sum += np.sqrt(np.square(x[i] - x[j]) + np.square(y[i] - y[j]))

print(sum*2/N)


Measured memory_bytes: 12396
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
char input[20];
scanf("%s",&input);

if(!strcmp(input,"Sunny")){
    printf("Cloudy");
}

else if(!strcmp(input,"Cloudy")){
    printf("Rainy");
}
else{
    printf("Sunny");
}
    return 0;
}


Measured memory_bytes: 128
n, k = map(int, input().split())
num_list = []
for i in range(n):
  num_list.append(int(input()))
num_list.sort()
diff = 10**9 -1
for i in range(n-k+1):
  temp = abs(num_list[i]-num_list[i+k-1])
  if diff > temp:
    diff = temp
print(diff)

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

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


int main(){
    int A,B,C,K;
    cin >> A >> B >> C >> K;


    while(A >= B){
        B = 2*B;
        K--;
        if(B>A&&K>=0){
            break;
        }else if(K<0){
            break;
        }
    }

    while(B >= C){
        C = 2*C;
        K--;
        if(C>B&&K>=0){
            
            break;
        }else if(K<0){
            
            break;
        }
    }

    if(A<B&&B<C && K>=0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}



Measured memory_bytes: 3640
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  char s;
  int h,w,i,j,a[2010][2010],x[2010][2010],y[2010][2010];
  scanf("%d %d\n",&h,&w);
  for(i=0;i<=h+1;i++){
    for(j=0;j<=w+1;j++){
      a[i][j]=0,x[i][j]=0,y[i][j]=0;
    }
  }
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      scanf("%c",&s);
      if(s=='.'){
        a[i][j]=1;
      }
    }
    scanf("\n");
  }
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      if(a[i][j]==1){
        x[i][j]=x[i][j-1]+1;
      }
      else{
        x[i][j]=0;
      }
    }
  }
  for(i=1;i<=h;i++){
    for(j=w-1;j>=1;j--){
      if(x[i][j]!=0){
        if(x[i][j+1]==0){
          continue;
        }
        x[i][j]=x[i][j+1];
      }
    }
  }
  for(i=1;i<=w;i++){
    for(j=1;j<=h;j++){
      if(a[j][i]==1){
        y[j][i]=y[j-1][i]+1;
      }
      else{
        y[j][i]=0;
      }
    }
  }
  for(i=1;i<=w;i++){
    for(j=h-1;j>=1;j--){
      if(y[j][i]!=0){
        if(y[j+1][i]==0){
          continue;
        }
        y[j][i]=y[j+1][i];
      }
    }
  }
  int ans=0;
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      ans=max(ans,x[i][j]+y[i][j]);
    }
  }
  printf("%d\n",ans-1);
  return 0;
}

Measured memory_bytes: 47616
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

ll n, a, b;
int main() {
	scanf("%lld %lld %lld", &n, &a, &b);
	ll c = n / (a + b) * a;
	c += min(n % (a + b), a);
	printf("%lld\n", c);
}

Measured memory_bytes: 128
function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var dogs = parseInt(line[0]);
    var monks = parseInt(line[1]);
    var ans = 0;
    var dogsCount = 1;
    var monksCount = 1;
    var limit = 1E9+7;
    if(Math.abs(dogs-monks)>1){
        console.log(ans);
    } else {
        for(var i = 0; i<dogs; i++){
            dogsCount *= i+1;
            if(dogsCount>=limit){
                dogsCount %= limit;
            }
        }
        
//        console.log(dogsCount);
        ans = dogsCount;

        for(var i = 0; i<monks; i++){
            ans *= i+1;
            if(ans>=limit){
                ans %= limit;
            }
 //           console.log(i+" "+ans);
        }
        
        if(dogs===monks){
            ans*=2;
        }
        
        if(ans>=limit){
            ans %= limit;
        }
        
        console.log(ans);
//        console.log(dogsCount*dogsCount*2%limit);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <stdio.h>

int main(){

int a,b,c,x;

scanf("%d %d %d\n",&a,&b,&c);

if(a>b){
 x=a;
 a=b;
 b=x;
}

if(b>c){
 x=b;
 b=c;
 c=x;
}

if(a>b){
 x=a;
 a=b;
 b=x;
}

printf("%d %d %d\n",a,b,c);
return 0;
}

 



Measured memory_bytes: 2140
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] inputs = new int[n];
		
		long sum = 0;
		for(int i=0; i<n; i++) {
			inputs[i] = sc.nextInt();
			sum += inputs[i];
		}
		sc.close();
		
		Arrays.sort(inputs);
		
		System.out.printf("%d %d %d", inputs[0], inputs[n-1], sum);
		System.out.println();
	}

}

Measured memory_bytes: 42336
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
struct nod{
	string s;
	int p;
}e[105];
int n,r[105];
inline bool cmp(int a,int b){
	if (e[a].s<e[b].s) return 1;
	if (e[a].s>e[b].s) return 0;
	return e[a].p>e[b].p;
}
int main(){
	cin>>n;
	fo(i,1,n) cin>>e[i].s>>e[i].p;
	fo(i,1,n) r[i]=i;
	sort(r+1,r+n+1,cmp);
	fo(i,1,n) printf("%d\n",r[i]);
	return 0;
}

Measured memory_bytes: 256
plusEven :: Integer -> Integer -> Integer

plusEven 1 1 = 0
plusEven n m = (((n-1)*n) `div` 2) + (((m-1)*m) `div` 2) 

toInt x = read x :: Integer

main = do
    nm <- getLine
    let n = head $ map toInt $ words nm
        m = last $ map toInt $ words nm
    print $ plusEven n m

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

int main(){
    int n;
    cin>>n;
    int dp[3][n];
    for(int i=0;i<n;i++) cin>>dp[0][i]>>dp[1][i]>>dp[2][i];
    
    for(int i=n-2;i>=0;i--)
    {  
       dp[0][i]+=max(dp[1][i+1],dp[2][i+1]); 
       dp[1][i]+=max(dp[0][i+1],dp[2][i+1]);
       dp[2][i]+=max(dp[1][i+1],dp[0][i+1]); 
    }
    cout<<max(dp[0][0],max(dp[1][0],dp[2][0]))<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INT = 1e9;
const ll LINF = 1e18;

struct UF{
    vector<int> d;
    UF(int size):d(size,-1){}
    bool u(int x,int y){
        x = r(x); y = r(y);
        if(x != y){
            if(d[y] < d[x]) swap(x,y);
            d[x] += d[y]; d[y] = x;
        }
        return x!=y;
    }
    bool f(int x,int y){
        return r(x) == r(y);
    }
    int r(int x){
        return d[x] < 0 ? x:d[x] = r(d[x]);
    }
    int s(int x){
        return -d[r(x)];
    }
};

//const ll MAX_PRIME = 200000;
//vector<int> primes;
//vector<int> is_prime(MAX_PRIME + 1,true);
//void init_primes(){
//    is_prime[0] = is_prime[1] = false;
//    for(int i = 2; i <= MAX_PRIME;i++){
//        if(is_prime[i]){
//            primes.push_back(i);
//            for(int j = i*2;j<=MAX_PRIME;j+=i) is_prime[j] = false;
//        }
//    }
//}
//void solveF(){
//    init_primes();
//    ll N,P;
//    vector<ll> sum;
//    while(cin >> N >> P){
//        if(N == -1 && P == -1) break;
//        sum.clear();
//        auto idx = upper_bound(primes.begin(),primes.end(),N) - primes.begin();
//        for(int i = 0; i <= P;i++){
//            for(int j = i; j <= P;j++){
//                ll S = primes[idx+i] + primes[idx+j];
//                sum.push_back(S);
//            }
//        }
//        sort(sum.begin(),sum.end());
//        cout << sum[P-1] << endl;
//    }
//}


double func(ll P,ll A,ll B,ll C,ll D,ll E,ll F,ll S,ll M){
    double ret = 0;
    ll sum = M*F*S;
    ll kouritu = sum - P;
    ll T = A + B + C + D + E + (D + E)*(M-1);
    ret = kouritu/(double)T;
    return ret;
}
void solveG(){
    int N;
    while(cin >> N,N){
        vector<pair<double,string>> ans(N);
        for(int i = 0; i < N;i++){
            string L; cin >> L;
            ll P,A,B,C,D,E,F,S,M; cin >> P >> A >> B >> C >> D >> E >> F >> S >> M;
            ans[i] = {pair<double,string>{-func(P,A,B,C,D,E,F,S,M),L}};
        }
        sort(ans.begin(),ans.end());
        for(int i = 0; i < N;i++){
            cout << ans[i].second << endl;
        }
        cout << "#" << endl;
    }
}
int main(void){
    cin.tie(0); ios_base::sync_with_stdio(false);
    //solveF();
    solveG();
    return 0;
}



Measured memory_bytes: 3028
import java.util.Scanner;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n;

        n = in.nextInt();
        while(n != 0){
            int[] a = new int[n];
            for(int i = 0; i < n; i++){
                a[i] = in.nextInt();
            }
            Pair p = solve(a);
            System.out.println(p.count);
            for(int i = 0; i < p.a.length; i++){
                if(i != 0){
                    System.out.print(" ");
                }
                System.out.print(p.a[i]);
            }
            System.out.println();
            n = in.nextInt();
        }
    }

    static Pair solve(int[] a){
        int[] b = new int[a.length];
        int count = -1;
        while(!Arrays.equals(a, b)){
            b = a.clone();
            for(int i = 0; i < a.length; i++){
                int t = 0;
                for(int j = 0; j < a.length; j++){
                    if(a[i] == b[j]) t++;
                }
                a[i] = t;
            }
            count++;
        }
        return new Pair(count, b);
    }
}

class Pair{
    int count;
    int[] a;
    public Pair(int count, int[] a){
        this.count = count;
        this.a = a;
    }
}

Measured memory_bytes: 30852
log = console.log;

var stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
var lines = stdin.split("\n")
var line = lines[0].split(" ").map(Number)
var N = line[0]
var L = line[1]

var Start = L
var Last = L + N - 1
var Sum = (Start + Last) * N / 2

if(Start >= 0 && Last >= 0){
  log(Sum - Start)
}else if (Start < 0 && Last >= 0){
  log(Sum)
} else if(Start<0 && Last < 0){
  log(Sum - Last)
}

Measured memory_bytes: 11468
from sys import stdin
from scipy.misc import comb
import numpy as np
N,P = [int(x) for x in stdin.readline().rstrip().split()]
data = [int(x) for x in stdin.readline().rstrip().split()]
even = 0
odd  = 0
for i in data:
    if i % 2 == 0:
        even += 1
    else:
        odd  += 1
ans = 0
if P == 0:
    for j in range(0,odd+1,2):
        ans += (comb(odd,j,exact=True) * 2 ** even)
else:
    for j in range(1,odd+1,2):
        ans += (comb(odd,j,exact=True) * 2 ** even)

print(ans)

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

int main(){
  int a,b;
  cin >> a >> b;
  int ans = (a+b+1)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] a1 = new int[n];
        int[] a2 = new int[n];
        a1[0] = Integer.parseInt(sc.next());
        for(int i = 1; i < n; i++){
            a1[i] = a1[i-1] + Integer.parseInt(sc.next());
        }
        for(int i = 0; i < n; i++){
            a2[i] = Integer.parseInt(sc.next());
        }
        for(int i = n-2; i >= 0; i--){
            a2[i] += a2[i+1];
        }
        
        int max = 0;
        for(int i = 0; i < n; i++){
            if(a1[i] + a2[i] > max){
                max = a1[i] + a2[i];
            }
        }
        
        System.out.println(max);
    }
}

Measured memory_bytes: 23636
/*
 KUNAL RAUT (ZUKONIT14)  :- "DO WHAT YOU LIKE!"
 -PICT,PUNE! :)
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define inv (mod+1)/3
#define mod9 1000000009
#define pi 3.1415926535
#define MAXN 1000001
#define MAX2N 1*1000 + 10
#define all(v) v.begin(), v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define forci(p,n) for(ll i=p;i<(ll)n;i++)
#define forcj(p,n) for(ll j=p;j<(ll)n;j++)
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define bits(a) __builtin_popcount(a)
#define test ll t;cin>>t;while(t--)
ll zero=0;
ll one=1;
ll gcd(ll a,ll b){    if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) {    return (a/gcd(a,b)*b);}
ll expo(ll x, ll y) {ll res=1;x=x%mod;while(y>0){if(y&1)res=(1ll*res*x)%mod;
    y=y>>1;x=(1ll*x*x)%mod;} return res;}
ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime(ll n){ll i;for(i=2;i<=sqrt(n);i++){if(n%i==0)return false;}return true;}
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return(a.second<=b.second);}

//https://www.youtube.com/watch?v=k4V3Mo61fJM

ll rr[]={0,1,1,1,0,-1,-1,-1,};
ll cc[]={1,1,0,-1,-1,-1,0,1};

signed main()
{
    bolt;
    ll n, t, a, ans = -1;
    cin >> n >> t >> a;
    float best_temp_diff = 100000;
    for (ll i = 0; i < n; i++)
    {
        ll h;
        float temp_diff;
        cin >> h;
        temp_diff = abs(t - h * 0.006 - a);
        if (temp_diff < best_temp_diff) {
            best_temp_diff = temp_diff;
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

final class Main {

    private Main() {
    }

    public static void main(final String[] argv) throws IOException {
        final BufferedReader inputReader =
                new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String input = inputReader.readLine();
            if (input == null) {
                break;
            }
            int[] values = new int[input.length()];
            int index = 0;
            for (char c : input.toCharArray()) {
                if (c == 'I') {
                    values[index] = 1;
                } else if (c == 'V') {
                    values[index] = 5;
                } else if (c == 'X') {
                    values[index] = 10;
                } else if (c == 'L') {
                    values[index] = 50;
                } else if (c == 'C') {
                    values[index] = 100;
                } else if (c == 'D') {
                    values[index] = 500;
                } else if (c == 'M') {
                    values[index] = 1000;
                }
                index++;
            }
            int sum = 0;
            int back = 0;
            for (int i = values.length - 1; i >= 0; i--) {
                if (back <= values[i]) {
                    sum += values[i];
                    back = values[i];
                } else {
                    for (int j = i; j >= 0 && back >= values[j]; j--) {
                        sum -= values[j];
                        back = values[j];
                        i = j;
                    }
                }
            }
            System.out.println(sum);
        }
    }
}

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

a_sorted = sorted(set(a))+[10**18]
left, right = 0, len(a_sorted)-1

while right-left > 1:
    mid = (left+right)//2
    x = a_sorted[mid]

    count = [0]*(2*n+1)
    count[n+1] = 1
    i, accum, res = n+1, 1, 0

    for aa in a:
        if aa >= x:
            i += 1
            accum += count[i]
        else:
            accum -= count[i]
            i -= 1

        res += accum
        count[i] += 1
        accum += 1

    if res >= n*(n+1)//4:
        left = mid
    else:
        right = mid

print(a_sorted[left])


Measured memory_bytes: 14852
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

int main() {
    int s,res = 0;
    for (int i = 0; i < 10; ++i) { cin >> s; res += s; }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1160