akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const INF: usize = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let A: Vec<usize> = sc.vec(N);
    let mut dp = vec![0; N+1];
    dp[0] = 1000;
    for k in 1..=N {
        dp[k] = 0;
        for i in 0..k-1 {
            let mut m = INF;
            for j in i+1..k {
                m = min(m, A[j-1]);
            }
            dp[k] = max(dp[k], dp[i]/m*A[k-1] + dp[i]%m);
        }
    }
    let mut ans = 0;
    for i in 0..=N {
        ans = max(ans, dp[i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    char now = s[0];
    int ans = 0;
    for(int i = 1; i < s.size(); i++) {
        if(now != s[i]) {
            now = s[i];
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pii pair<ll, ll> 
#define pb push_back
#define debug(x) cerr<< #x << " is " <<x<<endl;
#define debug2(x) cerr<<#x<< " is\n"; for (auto &i:x) {cout<<i<<' '; } cout<<endl;
#define f first
#define s second
using namespace std;
const int maxn = 100005;
const ll inf=1ll<<60;
const ll mod = 1e9+7;

ll dp[maxn][2];
bool seen[maxn];
vector<vector<int> > graph (maxn);

void dfs(int at){
	seen[at]=1;
	dp[at][0]=dp[at][1]=1;
	for (int v:graph[at]){
		if (!seen[v]){
			dfs(v);
			dp[at][1]*=(dp[v][0]+dp[v][1]);
			dp[at][1]%=mod;
			dp[at][0]*=dp[v][1];
			dp[at][0]%=mod;
		}
	}
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin>>n;
    for (int i=0; i<n-1; i++){
    	int a, b; cin>>a>>b;
    	graph[a-1].pb(b-1);
    	graph[b-1].pb(a-1);
    }
    dfs(0);
    cout<<(dp[0][0]+dp[0][1])%mod<<endl;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456;
vector<int> e[maxn];
int solve(int u){
	vector<int> sons;
	for(int v : e[u]) sons.push_back(solve(v));
	sort(sons.begin(), sons.end());
	for(int i = 0; i < e[u].size(); i++) sons[i] += e[u].size() - i;
	int mx = 0;
	for(int v : sons) mx = max(mx, v);
	return mx;
}
int main(){
	int n; cin >> n;
	for(int i = 2; i <= n; i++){
		int x; cin >> x;
		e[x].push_back(i);
	}
	cout << solve(1) << endl;
	return 0;
}


Measured memory_bytes: 15616
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>

template <typename C>
void print_container(const C &c, const std::string &name)
{
  std::cout << name << ": ";
  std::for_each(c.cbegin(), c.cend(),
                [](auto &x) { std::cout << x << ", "; });
  std::cout << std::endl;
}

std::vector<int> n_ary(uint64_t decimal, uint64_t base)
{
  uint64_t s = decimal;
  std::vector<int> ret;
  while(s >= base) {
    int r = s % base;
    s /= base;
    ret.push_back(r);
  }
  ret.push_back(s);

  std::reverse(ret.begin(), ret.end());
  return ret;
}

char i2c(int i)
{
  return char('a' + i);
}


int main()
{
  uint64_t N;
  std::cin >> N;

  const uint64_t n = 26;
  uint64_t i=1; // i-place number(i=3, aaa-zzz)
  while(N - std::pow(n, i) > 0) {
    N -= std::pow(n, i);
    i++;
  }

  // let N 0 origin
  N--;

  auto ary26 = n_ary(N, n);
  // print_container(ary26, "ary26");

  std::string s;
  for(int j=0; j<i; j++) {
    s = "a" + s;
  }

  // i=3, ary26 = {1, 2} => s = abc
  std::reverse(ary26.begin(), ary26.end());
  size_t j = s.size() - 1;
  for(auto k: ary26) {
    s[j] = i2c(k);
    j--;
  }
  std::cout << s << std::endl;

  return 0;
}


Measured memory_bytes: 4064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int d,t,s;
  cin >> d >> t >> s;
  bool ans = d<=t*s;
  cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
long long dp[1001][100001],a[10001],b[10001],i,j,n,w;
long long cal(long long i, long long j)
{
    if (i>n)  return 0;
    if (dp[i][j]!=-1) return dp[i][j];
    else dp[i][j]=0;
    if (j+a[i]<=w) dp[i][j]=max(cal(i+1,j),cal(i+1,j+a[i])+b[i]);
    else dp[i][j]=cal(i+1,j);
    return dp[i][j];
}
int main()
{
    cin>>n>>w;
    for (i=1;i<=n;i++) cin>>a[i]>>b[i];
    for (i=1;i<=n;i++)
        for (j=0;j<=100000;j++)
        dp[i][j]=-1;
    cout<<cal(1,0);
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
int h, w, n, a[10020], c, x;
int main() {
	scanf("%d%d%d", &h, &w, &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &x);
		while (x--) {
			a[c++] = i;
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			printf("%d%c", a[i * w + (i & 1 ? w - j - 1: j)], j == w - 1 ? '\n' : ' ');
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
typedef long long ll;

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

    int ans = 0, max = h[0];

    rep(i,n){
        if(h[i] >= max){
            ++ans;
            max = h[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

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

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}

const ll MAX = 1000000;
const ll MOD = 1000000007;

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

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vector<ll> ans(n);
    rep(i,n){
        string x,y;
        cin>>x>>y;
    
        ll dp[1010][1010]={0};
        rep(i,y.size()) dp[0][i]=0;
        
        rep(i,x.size()){
            for(ll j=0;j<y.size();j++){
                if(x.at(i)==y.at(j)) dp[i+1][j+1]=max(dp[i+1][j+1],1+dp[i][j]);
                else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
        ans[i]=dp[x.size()][y.size()];
    }
    rep(i,n) cout<<ans[i]<<endl;
    return 0;
}



Measured memory_bytes: 11220
import java.math.*

fun main(args: Array<String>) {
    val (A, B, K) = readInputLine().split(" ").map{it.toInt()}
    
    var cnt = 0
    
    for (i in Math.min(A, B) downTo 1) {
        if (A % i == 0 && B % i == 0) {
            if (++cnt == K) {
                println(i)
                return
            }
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37860
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"


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

// ab >= a + b -> a,b枚数分
// ab < a + b ab < 2 * min(a,b)
// ab < a + b ab >= 2 * min(a,b)

int main(void) {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int minAB = min(a, b);
	if (a + b <= 2 * c) {
		cout << a * x + b * y << endl;
	}
	else {
		if (c * 2 < minAB) {
			cout << c * 2 * max(x, y) << endl;
		}
		else {
			int cost = c * 2 * min(x, y);
			int left = max(x, y) - min(x, y);
			if (x > y) {
				if (a > c * 2) {
					cout << cost + c * left * 2 << endl;
				}
				else {
					cout << cost + a * left << endl;
				}
			}
			else {
				if (b > c * 2) {
					cout << cost + c * left * 2 << endl;
				}
				else {
					cout << cost + b * left << endl;
				}
			}
		}
	}
}

Measured memory_bytes: 256
def calc(vlist):
    sum = vlist[0]
    for i in range(len(vlist) - 1):
        sum = ((sum + vlist[i+1]) / 2)

    return sum
   
try:
    n = int(input())

    v = [int(x) for x in input().split(' ')]
    v.sort()
    
    print(calc(v))
    
except ValueError:
    print("数値を入力してください")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N;
long long a[100002];
long long x;
int main(){
	cin>>N>>x;
	a[0]=0;
	REP(i,N){
	    cin>>a[i+1];
	}
	long long ans=0;
	REP(i,N){
	    if(a[i]+a[i+1]>x){
	       ans+=a[i]+a[i+1]-x;
	       a[i+1]-=(a[i]+a[i+1]-x);
	       if(a[i+1]<0){
	          assert(1);
	       }
	    }
	}
        cout<<ans<<endl;
	return(0);
}

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

typedef long long ll;

string s;

string solve() {
    string str = s.substr(0, 4);
    if( str == "YAKI" ) {
        return "Yes";
    }
    return "No";
}

int main()
{
    #ifdef _OFFLINE_
        freopen("in.txt", "r", stdin);
    #endif /// _OFFLINE_

    while(cin >> s) {
        cout << solve() << "\n";
    }

    return 0;
}


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

int fa[100010];
int in[100010];
int vis[100010];
int out[100010];
vector <int> from[100010];

void dfs(int x){
	vis[x] = 1, out[x] = 0;
	for (int i = 0; i < from[x].size(); i++){
		int v = from[x][i];
		if (vis[v]) continue;
		dfs(v), out[x]++;
	}
}

int find(int x){
	return fa[x] == x ? x : fa[x] = find(fa[x]);
}

int main(){
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++){
		int u, v; scanf("%d%d", &u, &v);
		from[u].push_back(v);
		from[v].push_back(u);
		in[u]++, in[v]++;
	}
	int maxj = 0;
	for (int i = 1; i <= n; i++){
		if (in[i] % 2 == 1){
			printf("No\n");
			return 0;
		}
		maxj = max(maxj, in[i]);
	}
	if (maxj >= 6){
		printf("Yes\n");
		return 0;
	}
	int cnt = 0, pos;
	for (int i = 1; i <= n; i++){
		if (in[i] == 4) cnt++, pos = i;
	}
	if (cnt >= 3){
		printf("Yes\n");
		return 0;
	}
	if (cnt <= 1){
		printf("No\n");
		return 0;
	}
	dfs(pos);
	printf(out[pos] == 1 ? "No\n" : "Yes\n");
	return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(){
  int64_t a,b;
  cin >> a >> b;
  cout << a*b/euclidean_gcd(a,b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
 
  for(int i=a;i>0;i--){
    if(b-i>-1000001){
      cout<<b-i+1;
    }
    cout<<" ";
  }
  for(int i=1;i<a;i++){
    if(b+i<1000001){
      cout<<b+i;
    }
    if(i!=a-1){
      cout<<" ";
    }
  }
  cout<<"\n";
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    string s;
    cin >> s;
    ll N = s.size();
    vector<ll> cnt(26);
    for (int i = 0; i < N; i++) {
        cnt[s[i] - 'a']++;
    }
    ll sum = 0;
    for (int i = 0; i < 26; i++) {
        sum += cnt[i] * ((ll)cnt[i] - 1) / 2;
    }
    cout << N * (N - 1) / 2 - sum + 1 << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 720
// -*- coding:utf-8-unix -*-

use proconio::{input, fastout};

use num_traits::{pow, One};
use std::ops::{Add, Div, Mul, Sub};

const MODULUS: usize = 1000000007;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

#[fastout]
fn main() {
    input! {
        l :String
    }
    let l_bytes = l.as_bytes();

    println!("{}", count(l_bytes).0);
}

fn count(l_bytes :&[u8]) -> ModP {
    if l_bytes.len() == 0 {
        return ModP(1);
    }
    if l_bytes[0] == b'1' {
        // Pattern 1: with the top bit 0 in both a and b
        let pat1 = pow(ModP(3), l_bytes.len()-1);
        // Pattern 2: others
        // a xor b -> 2
        let mut pat2 = ModP(2);
        // (a-topbit) and b, or the other way round
        // must satisfy the condition for (l-topbit)
        pat2 = pat2 * count(&l_bytes[1..]);
        return pat1 + pat2;
    } else {
        // Now the top bit is 0 in both a and b
        return count(&l_bytes[1..]);
    }
}

#[derive(Clone, Copy, PartialEq, Debug)]
struct ModP(usize);

impl One for ModP {
    fn one() -> Self {
        return ModP(1);
    }
}
impl Add for ModP {
    type Output = Self;
    fn add(self, rhs: Self) -> Self {
        return ModP((self.0 + rhs.0) % MODULUS);
    }
}
impl Sub for ModP {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self {
        return ModP((self.0 + MODULUS - rhs.0) % MODULUS);
    }
}
impl Mul for ModP {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self {
        return ModP((self.0 * rhs.0) % MODULUS);
    }
}
impl Div for ModP {
    type Output = Self;
    fn div(self, rhs: Self) -> Self {
        if rhs.0 == 0 {
            panic!("Tried to divide by ModP(0)!");
        }
        let rhs_inv = pow(rhs, MODULUS - 2);
        return self * rhs_inv;
    }
}


Measured memory_bytes: 3848
def LI():return list(map(int,input().split()))
def yes():return print("Yes")
def no():return print("No")
from collections import deque, defaultdict, Counter
from heapq import heappop, heappush
# import math
# pi=math.pi
# print(pi)
# yes()
# no()
n=int(input())

# s=input()
a=LI()
a.sort()
if a[0]==0:
    print(0)
    exit()

ans=1
for q in a:
    ans*=q
    if ans>10**18:
        print(-1)
        exit()
print(ans)



Measured memory_bytes: 84216
#!python
# -*- coding: utf-8 -*-


S = input()
K = int(input())

substrings = []


for n in range(1, K + 1):
    for i in range(0, len(S) + 1 - n):
        substrings.append(S[i:i + n])
substrings.sort()

_ = ""
n = 0
for s in substrings:
    if s == _:
        continue
    n += 1
    if n == K:
        print(s)
        break
    else:
        _ = s


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll n;cin >> n;
    vl a(n);
    rep(i,n)cin>>a[i];
    vpii p;
    rep(i,n)p.emplace_back(a[i],i);
    sort(rall(p)); //降順そーと
    vvl dp(n+1,vl(n+1,-L_INF));
    dp[0][0] = 0;
    rep(i,n) {
        int pi = p[i].second;
        rep(l,i+1) {
            int r = i-l;
            chmax(dp[i+1][l+1], dp[i][l]+ll(pi-l)*a[pi]);
            chmax(dp[i+1][l], dp[i][l]+ll((n-r-1)-pi)*a[pi]);
        }
    }
    ll ans = 0;
    rep(i,n+1) chmax(ans, dp[n][i]);
    out(ans);
}



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

int main()
{
    int n = 0;
    int div = 0; 
    int sum = 0;
    cin >> n;

    if (n % 1000 == 0)
    {
        sum = 0;
    }
    else
    {
        div = n % 1000;
        sum = 1000 - div; 
    }
    cout << sum << endl;
    
}

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

const ll MOD=1e9+7;

int main(){
    int h,w,k;
    cin>>h>>w>>k;
    if(w==1){
        cout<<1<<endl;
        return 0;
    }
    ll cnt[10]={0};
    int sum=0;
    for(int bit=0;bit<1<<(w-1);bit++){
        bool flag=true;
        int tmp=bit,a=tmp%2,b;
        for(int i=0;i<w-2;i++){
            tmp/=2;
            b=tmp%2;
            if(a==1&&b==1){
                flag=false;
                break;
            }
            a=b;
        }
        if(!flag)continue;
        sum++;
        tmp=bit;
        for(int i=0;i<w-1;i++){
            if(tmp%2==1)cnt[w-2-i]++;
            tmp/=2;
        }
    }
    ll dp[110][10]={0};
    dp[0][0]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<w-1;j++){
            (dp[i][j]+=dp[i-1][j]*(sum-cnt[j-1]-cnt[j]))%=MOD;
            (dp[i][j]+=dp[i-1][j-1]*cnt[j-1]+dp[i-1][j+1]*cnt[j])%=MOD;
        }
        (dp[i][0]+=dp[i-1][0]*(sum-cnt[0]))%=MOD;
        (dp[i][0]+=dp[i-1][1]*cnt[0])%=MOD;
        (dp[i][w-1]+=dp[i-1][w-1]*(sum-cnt[w-2]))%=MOD;
        (dp[i][w-1]+=dp[i-1][w-2]*cnt[w-2])%=MOD;
    }
    cout<<dp[h][k-1]<<endl;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
s = gets.chomp.split(" ").map{ |x| x.to_i }

$count = 0

def merge(a, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = (0..n1).to_a
  r = (0..n2).to_a
  (0...n1).each { |i| l[i] = a[left + i] }
  (0...n2).each { |i| r[i] = a[mid + i] }

  l[n1] = r[n2] = 10**9
  i = j = 0

  (left...right).each do |k|
    $count += 1
    if l[i] <= r[j]
      a[k] = l[i]
      i = i + 1
    else
      a[k] = r[j]
      j = j + 1
    end
  end
end

def mergeSort(a, left, right)
  
  if left + 1 < right
    mid = (left + right) / 2
    mergeSort(a, left, mid)
    mergeSort(a, mid, right)
    merge(a, left, mid, right)
  end
  return $count, a
end

result = mergeSort(s, 0, n)
puts result[1].join(" ")
puts result[0]



Measured memory_bytes: 62076
#include <stdio.h>
int A[100001];
int partition(int p,int r){
  int x,i,j,tmp;

  x = A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;
  return i+1;
}

int main(){
  int i,n,q;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  q=partition(1,n);
  for(i=1;i<n;i++){
    if(q==i) printf("[%d] ",A[i]);
    else printf("%d ",A[i]);
  }
  printf("%d\n",A[n]);
  return 0;
}



Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
void solve(){
	int n;
	cin>>n;
int ans = 0;
	for(int i=1;i*i<=n;i++){
		ans = i;
	}
	cout<<ans*ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cout<<fixed<<setprecision(12);
	int t=1;
//	cin>>t;
	while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())

n_1000 = N // 1000
n_100 = (N - n_1000*1000) // 100
n_10 = (N - n_1000*1000 - n_100*100) // 10
n_1 = (N - n_1000*1000 - n_100*100 - n_10*10)

cnt = 0
if n_1000 == 2:
    cnt += 1
if n_100 == 2:
    cnt += 1
if n_10 == 2:
    cnt += 1
if n_1 == 2:
    cnt += 1

print(cnt)

Measured memory_bytes: 3060
n, k = map(int, raw_input().split())
plist = map(int, raw_input().split())

exp_list = [(p + 1) / 2.0 for p in plist]
ans = s = sum(exp_list[:k])
for i in xrange(n - k):
    s = s - exp_list[i] + exp_list[i + k]
    ans = max(ans, s)

print ans


Measured memory_bytes: 19988
#include <bits/stdc++.h>
#define maxn 10000005
#define mod 998244353
using namespace std;

long long fact[maxn], inv[maxn], p2[maxn];
int n;

long long get_power(int x, int p) {
	if (!p) {
		return 1;
	}
	long long q = get_power(x, p/2);
	q = (q * q) % mod;
	if (p & 1) {
		q = (q * x) % mod;
	}
	return q;
}

long long binom(int x, int y) {
	if (x < y) {
		return 0;
	}
	long long up = fact[x], down = (inv[y] * inv[x - y]) % mod;
	return up * down % mod;
}

int main() {
	scanf("%d", &n);
	long long ways = get_power(3, n);
	long long exc = 0;

	fact[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = (fact[i - 1] * i) % mod;
	}
	inv[n] = get_power(fact[n], mod - 2);
	for (int i = n - 1; i >= 0; i--) {
		inv[i] = (inv[i + 1] * (i + 1)) % mod;
	}

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

	for (int i = n/2 + 1; i <= n; i++) {
		exc = (exc + binom(n, i) * p2[n - i]) % mod;
	}
	exc = (exc * 2) % mod;

	cout << (ways + mod - exc) % mod << endl;
}

Measured memory_bytes: 234624
import heapq

T = int(input())

for _ in range(T):
  N = int(input())
  rlt = 0
  dicl = {}
  dicr = {}
  Ls = []
  Rs = []
  mkl = 0
  mkr = 0
  for i in range(1,N+1):
    k, l, r = map(int, input().split())
    rlt += min(l, r)
    if l > r:
      if k not in dicl:
        dicl[k] = [l-r]
      else:
        dicl[k].append(l-r)
      mkl = max(mkl, k)
    else:
      if N-k not in dicr:
        dicr[N-k] = [r-l]
      else:
        dicr[N-k].append(r-l)
      mkr = max(mkr, N-k)

  for i in range(1,mkl+1):
    if i in dicl:
      for j in dicl[i]:
        heapq.heappush(Ls, j)
        rlt += j
    while len(Ls) > i:
      t = heapq.heappop(Ls)
      rlt -= t
  for i in range(1,mkr+1):
    if i in dicr:
      for j in dicr[i]:
        heapq.heappush(Rs, j)
        rlt += j
    while len(Rs) > i:
      t = heapq.heappop(Rs)
      rlt -= t
      
  print(rlt)

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

odd_prime = [3,5,7,11,13]
ans = 0
#2*2*2=8
for i in range(3):
    for j in range(i+1,4):
        for h in range (j+1,5):
            if odd_prime[i] * odd_prime[j] * odd_prime[h] <= n:
                ans += 1
#4*2=8
for i in range(1,5):
    if 3**3 * odd_prime[i] <= n:
        ans += 1
        
print(ans)



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


int main(){
	string S;
	cin >> S;
	int count = 0;
	int subc = 0;
	for(int i = 0; i < S.length(); i++){
		if(S[i]=='A' || S[i]=='T' || S[i]=='C' || S[i]=='G'){
			if(subc > 0){
				subc++;
				if(subc > count){
					count = subc;//recode
				}
			}else{
				subc++;
				if(subc > count){
					count = subc;//recode
				}
			}
		}else{
			subc = 0;//reset
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#159_B
def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True

s = input()
n = len(s)

ans = False
if is_kaibun(s):
    s = s[:n//2]
    if is_kaibun(s):
        ans = True
        
if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8932
using System;
using System.IO;

class Program
{
	static void Main(string[] args)
	{
		int ans = 0;
		string S = Console.ReadLine();
		string T = Console.ReadLine();

		for (int i = 0; i < 3; i++) {
			if(S[i] == T[i]) {
                if(S[i] == 'C' || S[i] == 'S' || S[i] == 'R'){
                    ans++;
                }
            }
		}

		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main ()
{
    int r;
    int d;
    int x;
    cin >>r;
    cin >>d;
    cin >>x;
    for (int n=0;n<10;n++){
        int w=0;
        w=r*x-d;
        cout <<w<<endl;
        x=w;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   
   string str;
   cin>>str;
   
   if(str=="ARC")
   cout<<"ABC"<<endl;
   else
   cout<<"ARC"<<endl;
   

   return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

vector<string> get_keys(){
  string key;
  string tmp;  
  vector<string> keys;
  
  getline(cin, key);
  REP(i, key.size()) if(key[i] == '.') key[i] = ' ';
  istringstream in(key);
  while(in >> tmp) keys.push_back(tmp);
  return keys;
  
}

vector<string> get_yaml(){
  string tmp;
  vector<string> yaml;
  while(getline(cin, tmp)){
    yaml.push_back(tmp);
  }
  return yaml;
}


bool prefix(string s, string t){
  return s.size() <= t.size() && t.substr(0, s.size()) == s;
}

int main(){
  vector<string> keys = get_keys();
  vector<string> yaml = get_yaml();

  REP(i, keys.size()){
    bool ok = false;
    REP(j, yaml.size())if(!ok && prefix(keys[i] + ":", yaml[j])){
      string val = yaml[j].substr(min(yaml[j].size(), keys[i].size() + 2));
      if(i + 1 == (int)keys.size()){
        if(val == ""){
          cout << "object" << endl;
        }else{
          cout << "string \"" + val << "\"" << endl;
        }
        return 0;
      }
      if(j + 1 == (int)yaml.size()) goto no_such_property;
      int wcount = 0;
      vector<string> next;
      
      while(yaml[j+1][wcount] == ' ') wcount++;
      while(++j < (int)yaml.size() && prefix(string(wcount, ' '), yaml[j])){
        next.push_back(yaml[j].substr(wcount));
      }
      
      yaml = next;
      ok = true;
    }
    
    if(!ok) goto no_such_property;
  }
 no_such_property:
  cout << "no such property" << endl;
  return 0;
}

Measured memory_bytes: 1364
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int R = in.nextInt();
            int G = in.nextInt();
            int B = in.nextInt();
            int N = in.nextInt();

            long count = 0;

            int rd = N / R;
            for (int i = 0; i <= rd; i++) {
                int n2 = N - R * i;
                int rg = n2 / G;
                for (int j = 0; j <= rg; j++) {
                    int n3 = n2 - G * j;
                    if (n3 == 0 || n3 % B == 0) {
                        count += 1;
                    }
                }
            }
            out.println(count);
        }

    }
}



Measured memory_bytes: 23508
#include <iostream>

using namespace std;
using ULL = unsigned long long;

ULL gcd(ULL a, ULL b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ULL lcm(ULL a, ULL b) {
    return a * (b / gcd(a, b));
}

int main() {

    int N;
    ULL ans = 1;

    cin >> N;

    for (int i = 0; i < N; i++) {
        ULL T;
        cin >> T;
        ans = lcm(ans, T);
    }

    cout << ans << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 3e5 + 1;

int a[maxn];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, p; cin >> n >> p;
    int cnt[2] = {0, 0};
    for (int i = 0; i < n; i++) {
        cin >> a[i];  ++cnt[a[i] % 2];
    }
    if (p % 2)
        cout << (1ll << cnt[0]) * (1ll << (cnt[1] - 1));
    else
        cout << (1ll << cnt[0]) * (1ll << max(0ll, cnt[1] - 1));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>
#include <functional>

#define REP(i,a) for(int (i)=0;(i)<(a);i++)
#define RREP(i,a,b) for(int (i)=(a);(i)<(b);i++)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define vi vector<int> 
typedef long long ll;
using namespace std;


int main(void){
    int n;
    cin>>n;
    vector<ll> a(n);
    REP(i,n)cin>>a[i];

    ll ans1=0,ans2=0;
    vector<ll> ruiseki1(n,0);
    vector<ll> ruiseki2(n,0);
    //偶数番目が正
    REP(i,n){
        if(i==0)ruiseki1[0]+=a[0];
        else ruiseki1[i] = ruiseki1[i-1] +a[i];
        if(i%2==0){
            if(ruiseki1[i]<=0){
                ans1 += 1 - ruiseki1[i];
                ruiseki1[i] = 1;
            }
        }else{
            if(ruiseki1[i]>=0){
                ans1+= ruiseki1[i] + 1;
                ruiseki1[i] = -1;
            }
        }
    }
    //偶数番目が負
    REP(i,n){
        if(i==0)ruiseki2[0]+=a[0];
        else ruiseki2[i] = ruiseki2[i-1] + a[i];
        if(i%2==0){
            if(ruiseki2[i]>=0){
                ans2 += ruiseki2[i] + 1;
                ruiseki2[i] = -1;
            }
        }else{
            if(ruiseki2[i]<=0){
                ans2 += 1 - ruiseki2[i];
                ruiseki2[i] = 1;
            }
        }
    }
    ll ans = min (ans1,ans2);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if (a == b) {
      if (a != c) {
        System.out.println(2);
      } else {
        System.out.println(1);
      }
    } else {
      if (a == c) {
        System.out.println(2);
      } else {
        if (b == c) {
          System.out.println(2);
        } else {
          System.out.println(3);
        }
      }
    }
  }
}

Measured memory_bytes: 22100
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int z,g,m,b;
  for(;;){
    cin>>z>>g;
    if(z+g==0)
      break;
    m=z+g;
    b=0;
    for(i=1;i<5;i++){
      cin>>z>>g;
      if(z+g>m){
	m=z+g;
	b=i;
      }
    }
    cout<<(char)('A'+b)<<" "<<m<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import scala.io.StdIn


object Main extends App {
  val Array(w, h, x, y)  = StdIn.readLine.split(" ").map(_.toInt)

  def solve(w: Int, h: Int, x: Int, y: Int) : String  = {
    var ret1 : Double = 0d
    var ret2 : Int = if (w == x * 2 && h == y * 2)  1 else 0
    
    ret1 = w.toDouble * h.toDouble / 2.0

    ret1 + " " + ret2
  }
  println(solve(w, h, x, y))

}
  



Measured memory_bytes: 27196
import itertools
H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]
is_searched = [[False for _ in range(W)] for _ in range(H)]


def dfs(p, q):
    if is_searched[p][q] == 1:
        return 0
    count = {'#': 0, '.': 0}
    que = [[p, q]]
    while que:
        x, y = que.pop(0)
        if is_searched[x][y] != 1:
            is_searched[x][y] = 1
            count[S[x][y]] += 1
            dxy = [[-1, 0], [1, 0], [0, -1], [0, 1]]
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and S[x][y] != S[nx][ny]:
                    que += [[nx, ny]]
    return count['#'] * count['.']


print(sum([dfs(i, j) for i, j in itertools.product(range(H), range(W))]))


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




int main() {
    int N, M;
    std::cin >> N >> M;

    std::vector<int> F(N, -1);

    auto get_parent = [&F] (int idx) {
        int parent = idx;
        while (F[parent] != -1) {
            parent = F[parent];
        }
        int i = idx;
        while (F[i] != -1) {
            F[i] = parent;
            i = F[i];
        }
        return parent;
    };

    std::vector<int> count(N, 1);
    for (int i = 0; i < M; i++) {
        int a, b;
        std::cin >> a >> b;
        a--; b--;
        int pa = get_parent(a);
        int pb = get_parent(b);
        if (pa != pb) {
            F[pb] = pa;
            F[b] = pa;
            count[pa] += count[pb];
            count[pb] = 0;
        }
    }

    int max = count[0];
    for (int i = 0; i < N; i++) {
        max = std::max(max, count[i]);
    }
    std::cout << max << std::endl;
}


Measured memory_bytes: 4776
#include<iostream>
#include<cmath>

using namespace std;

int main(){

int middle_ex=0,last_ex=0,re_ex=0;
int total=0;

while(1){
  cin >> middle_ex >> last_ex >> re_ex;

  total = middle_ex + last_ex;


  if(middle_ex==-1 && last_ex==-1 && re_ex==-1)  break;

  if(total>= 80){
        cout << 'A' << endl;
  }
  else if(middle_ex==-1 || last_ex==-1){
      cout << 'F' << endl;
  }

  else if(65 <= total && total < 80){
        cout << 'B' << endl;
  }
  else if(50 <= total && total < 65){
      cout << 'C' << endl;
  }
  else if(30 <= total && total < 50 && re_ex >= 50){

      cout << 'C' << endl;
  }
  else if(30 <= total && total < 50){

      cout << 'D' << endl;
  }

  else if(total <30){
      cout << 'F' << endl;
  }
re_ex=0;
}

return 0;

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

map<ll, ll> prime_factor(ll N)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= N; i++) {
        while(N % i == 0) {
            ++res[i];
            N /= i;
        }
    }
    if (N != 1) res[N] = 1;
    return res;
}

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

    map<ll, ll> p = prime_factor(N);

    ll ans = 0;
    for (auto itr : p) {
        ll sum = 0;
        ll it = 1;
        while (1) {
            sum += it;
            if (sum > itr.second) break;
            ans++;
            it++;
        }
    }

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

Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long

LL n, m;
int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  cin >> n >> m;
  if(n == 1 || m == 1) {
    cout << 1 << endl;
  }
  else {
    LL ans = (n / 2) * m;
    if(n % 2 == 1) {
      ans += (m + 1) / 2;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

#define NMAX 100000
#define MOD 1000000007
#define INF 2000000000

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)

using namespace std;

int n;
int monsters[NMAX + 1];
int heroes[NMAX];

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

	long long totalMonstersKilled = 0;
	for (int i = 0; i < n; i++)
	{
		int monstersKilledInCurr = MIN(monsters[i], heroes[i]);
		monsters[i] -= monstersKilledInCurr;
		heroes[i] -= monstersKilledInCurr;
		if (heroes[i])
		{
			int monstersKilledInNext = MIN(monsters[i + 1], heroes[i]);
			heroes[i] -= monstersKilledInNext;
			monsters[i + 1] -= monstersKilledInNext;
			totalMonstersKilled += monstersKilledInNext;
		}
		totalMonstersKilled += monstersKilledInCurr;
	}
	cout << totalMonstersKilled << '\n';
	return 0;
}

Measured memory_bytes: 1024
n = gets.to_i
v = gets.chomp.split(" ").map(&:to_i)
odd = Hash.new(0)
even = Hash.new(0)
n.times do |i|
  if (i+1).odd?
    odd[v[i]] += 1
  else
    even[v[i]] += 1
  end
end
odd_max = 0
odd_max_n = 0
odd.each do |k,v|
  if v > odd_max
    odd_max = v
    odd_max_n = k
  end
end
even_max = 0
even_max_n = 0
even.each do |k,v|
  if v > even_max
    even_max = v
    even_max_n = k
  end
end
if odd_max_n != even_max_n
  puts n - odd_max - even_max
else
  odd_max2 = 0
  odd_max2_n = 0
  odd.each do |k,v|
    if v > odd_max2 && odd_max_n != k
      odd_max2 = v
      odd_max2_n = k
    end
  end
  even_max2 = 0
  even_max2_n = 0
  even.each do |k,v|
    if v > even_max2 && even_max_n != k
      even_max2 = v
      even_max2_n = k
    end
  end
  if odd_max2 < even_max2
    puts n - odd_max - even_max2
  else
    puts n - odd_max2 - even_max
  end
end

Measured memory_bytes: 24512
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int f[1000005][2],n,num;
char s[1000005];
bool check(int num){
	if (num>=0&&num<=9) return 1;
	return 0;
}
int main(){
	scanf ("%s",s+1);
	n=strlen(s+1);
	memset (f,0x3f3f3f3f,sizeof (f));
	f[0][0]=0;f[0][1]=1;
	for (register int i=1;i<=n;++i){
		num=s[i]-'0';
		for (register int j=0;j<=9;++j){
			if (check(j-num)) f[i][0]=min(f[i][0],f[i-1][0]+j+j-num);
			if (check(j-num+10)) f[i][0]=min(f[i][0],f[i-1][1]+j+j-num+10);
			if (check(j-1-num)) f[i][1]=min(f[i][1],f[i-1][0]+j+j-1-num);
			if (check(j-1-num+10)) f[i][1]=min(f[i][1],f[i-1][1]+j+j-1-num+10);
		}
	}
	printf ("%d\n",f[n][0]);
	return 0;
}

Measured memory_bytes: 9088
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>str;
    map<char,ll> ma;
    rep(i,4) ma[str[i]]++;
    rep(i,4) if(ma[str[i]]!=2) f=1;
    if(f) No;
    else Yes;
    return 0;
}


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

int d[11][11];
int H, W;

void warshall_floyd() {
  rep(k, 10)  rep(i, 10)  rep(j, 10) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  rep(i, 10) rep(j, 10) cin >> d[i][j];
  warshall_floyd();
  int ans = 0;
  rep(i, H) {
      rep(j, W) {
          int A; cin >> A;
          if(A == -1) continue;
          ans += d[A][1];
      }
  }
  cout << ans << "\n";
  return 0;
}

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

void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int a[3] = {0}, b[3] = {0}, c[3][3] = {0};

bool solve();

int main() {
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j) cin >> c[i][j];

  prians(solve());
  return 0;
}

bool solve() {
  for(int i = 0; i <= 100; ++i)
    for(int j = 0; j <= 100; ++j)
      for(int k = 0; k <= 100; ++k) {
        bool ch = 1;
        a[0] = i;
        a[1] = j;
        a[2] = k;
        b[0] = c[0][0] - a[0];
        b[1] = c[0][1] - a[0];
        b[2] = c[0][2] - a[0];
        for(int l = 1; l < 3; ++l)
          for(int m = 0; m < 3; ++m)
            if(c[l][m] != a[l] + b[m]) ch = 0;
        if(ch) return 1;
      }
  return 0;
}

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

int main()
{
  char s[20];int i,j,n;
  scanf("%s", s);
  n=strlen(s);
  if(s[0]!='A')
  {
        printf("WA");
        printf("\n");
        return 0;
  }
  else
  {
    s[0]+=32;
    j=0;
    for(i=2;i<n-1;i++)
    {
      if(s[i]=='C')
      {
        j++;
        s[i]+=32;
      }
    }
    if(j!=1)
    {
        printf("WA");
        printf("\n");
        return 0;
    }
    for(i=1;i<n;i++)
    {
      if(s[i]<'a')
      {
        printf("WA");
        printf("\n");
        return 0;
      }
    }
  }

  printf("AC");
  printf("\n");
  return 0;

}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using ll = long long;
const ll INF_LL = 1000000000000;
#define fir first
#define sec second

struct chack{
    int l;
    int r;
    bool odd;
};

class Union_Find{
private:
    std::vector<long long> data; //data[i] : 頂点iの親
public:
    Union_Find(int n){
        data.resize(n,-1);
    }
    //頂点iの親を返す
    int root(int i){
        if(data[i] < 0)return i;
        else return data[i] = root(data[i]);
    }
    //連結
    void unit(int i,int j){
        i = root(i);j = root(j);
        if(i != j){
            data[i] += data[j];
            data[j] = i;
        }
    }

    //頂点iの属する集合の頂点数
    int size(int i){
        i = root(i);
        return data[i];
    }
};


int main()
{
    int n,m;
    std::cin >> n >> m;
    std::vector<chack> a(m);
    Union_Find uni(n);
    for(int i = 0; i < m; i++){
        int t;
        std::cin >> a[i].l >> a[i].r >> t;
        t %= 2;
        a[i].l--;
        a[i].r--;
        a[i].odd = t;
        uni.unit(a[i].l, a[i].r);

    }
    //a[i].l + a[i].r の奇偶がわかった
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(i == uni.root(i))cnt++;
    }
    std::cout << cnt << std::endl;
    
}


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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

#define endl "\n"

int main()
{
	faster;
	
	int x;
	cin >> x;

	if(x >= 30){
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int out;
  out = b / a >= c ? c : (int)(b/a);  
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256