akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> P;

int main(){
    while (1){
        int n, w, d;
        cin >> n >> w >> d;
        if (w == 0) break;
        vector<P> ans;
        ans.push_back({w, d});
        for (int i = 0; i < n; i++){
            int p, s;
            cin >> p >> s; p--;
            w = ans[p].first;
            d = ans[p].second;
            for (int j = p; j < ans.size(); j++) ans[j] = ans[j+1];
            s = s % (w + w + d + d);
            if (s < w){
                int aw = s;
                int bw = w - aw;
                if (aw <= bw){
                    ans.back() = {aw, d};
                    ans.push_back({bw, d});
                }
                else {
                    ans.back() = {bw, d};
                    ans.push_back({aw, d});
                }
            }
            else if (s < w + d){
                int ad = s - w;
                int bd = d - ad;
                if (ad <= bd){
                    ans.back() = {w, ad};
                    ans.push_back({w, bd});
                }
                else {
                    ans.back() = {w, bd};
                    ans.push_back({w, ad});
                }
            }
            else if (s < w + d + w){
                int aw = s - w - d;
                int bw = w - aw;
                if (aw <= bw){
                    ans.back() = {aw, d};
                    ans.push_back({bw, d});
                }
                else {
                    ans.back() = {bw, d};
                    ans.push_back({aw, d});
                }
            }
            else {
                int ad = s - w - d - w;
                int bd = d - ad;
                if (ad <= bd){
                    ans.back() = {w, ad};
                    ans.push_back({w, bd});
                }
                else {
                    ans.back() = {w, bd};
                    ans.push_back({w, ad});
                }
            }
        }
        int k = (int)ans.size();
        vector<int> pq(k);
        for (int i = 0; i < k; i++) pq[i] = ans[i].first * ans[i].second;
        sort(pq.begin(), pq.end());
        for (int i = 0; i < k; i++){
            if (i != 0) cout << " ";
            cout << pq[i];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3044
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(1, N+1):
        a = A[i-1]
        if i % 2 == 1 and a % 2 == 1:
            ans = ans + 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9152
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,h,a[100000],b[100000],c=0;
    cin>>n>>h;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    sort(a,a+n,greater<int>());
    sort(b,b+n,greater<int>());
    for(int i=0;i<n;i++){
        h-=b[i];
        c++;
        if(h<=0){
            i=n;
        }else if(i==n-1){
            c+=(h-1)/a[0]+1;
        }else if(b[i+1]<=a[0]){
            c+=(h-1)/a[0]+1;
            i=n;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 1024
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var Q = parseInt(input[0][0], 10);
    var arr_lr = [];
    var min = 1e+5;
    var max = 1;
    var line;
    for (var i = 0; i < Q; i++){
        line = input[i + 1].map(e => parseInt(e, 10));
        min = Math.min(min, line[0], line[1]);
        max = Math.max(max, line[0], line[1]);
        arr_lr.push(line);
    }
    var bin = Array.from({length: max}, () => 1);
    bin[0] = 0;
    for (var i = 2; i <= Math.sqrt(max); i++){
        for (var j = 2; j <= max / i; j++){
            bin[i * j - 1] = 0;
        }
    }
    var bin2 = Array.from({length: max}, () => 0);
    for (var i = 0; i < Math.floor((max + 1)/2); i++){
        if (bin[i] >= 1) bin2[i * 2] = 1;
    }
    var ruisekiwa = Array.from({length: max}, () => 0);
    for (var i = 1; i < ruisekiwa.length; i++){
        ruisekiwa[i] = ruisekiwa[i - 1] + bin[i] * bin2[i];
    }

    var v_ans = [];
    for (var x of arr_lr){
        if (x[0] === 1) v_ans.push(ruisekiwa[x[1] - 1]);
        else v_ans.push(ruisekiwa[x[1] - 1] - ruisekiwa[x[0] - 2]);
    }
    console.log(v_ans.join("\n"));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (200006)
ll n, t, dp[MAXN][31], mi[31];
vector<pi> A;
vector<ll> B;
int main(){
	FAST
	// sort in decreasing order of a / (b+1);
	cin>>n>>t;
	A.resize(n);
	FOR(i,0,n-1) cin>>A[i].f>>A[i].s;
	sort(all(A), [](pi x,pi y){return x.f * (y.s + 1) > y.f * (x.s + 1); });
	while(A.size() && A.back().f == 0) {
		B.eb(A.back().s), A.pop_back();
	}
	sort(all(B));
	FOR(i,1,siz(B)-1) B[i] += B[i-1] + 1;
	FOR(i,1,30) mi[i]=LLINF;
	FOR(i,0,siz(A)-1) {
		DEC(j,30,1) {
			if(mi[j-1] <= t) dp[i][j] = mi[j-1] + 1 + A[i].f * (mi[j-1] + 1) + A[i].s;
			else dp[i][j]=LLINF;
			mi[j]=min(mi[j], dp[i][j]); 
		}
	}
	ll ans = 0;
	FOR(i,0,30) if(mi[i] <= t) {
		ans = max(ans, i + ubd(B, t-mi[i]-1));
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 51840
#include <iostream>
using namespace std;
int main() {

	int n;
	char s[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	if (n % 2 == 1) {
		cout << "No" << endl;
		goto end;
	}

	for (int i = 0; i < n / 2; i++) {
		if (s[i] != s[i + n / 2]) {
			cout << "No" << endl;
			goto end;
		}
	}
	
	cout << "Yes" << endl;

	end:

	return 0;
}

Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

const MOD: u64 = 1_000_000_000 + 7;

fn main() {
  let n: usize = read();
  let mut grid = Vec::new();
  for _ in 0..2 {
    let s: Vec<char> = read::<String>().chars().collect();
    grid.push(s);
  }

  let mut ans: u64 = 0;
  let mut pre = 0;
  let mut indx = 0;

  // 前処理
  if n == 1 {
    ans = 3;
    indx = 1;
  }
  else if n > 1 {
    if grid[0][0] == grid[0][1] {
      ans = 6;
      indx = 2;
      pre = 0;
    }
    else {
      ans = 3;
      indx = 1;
      pre = 1;
    }
  }

  //
  while indx < n {
    if grid[0][indx] == grid[1][indx] {
      if pre == 1 {
        ans *= 2;
        pre = 1;
      }
      else {
        ans *= 1;
        pre = 1;
      }

      indx += 1;
    }
    else {
      if pre == 1 {
        ans *= 2;
        pre = 0;
      }
      else {
        ans *= 3;
        pre = 0;
      }

      indx += 2;
    }
    ans %= MOD;
  }
  println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	int a[n];
	int one;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cout << (n - 1 + k - 2) / (k - 1) << endl;
	return 0;
}


Measured memory_bytes: 640
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N = ri()
    S = [""] * N
    for i in range(N): S[i] = rs()

    bw = [-1] * N
    q = collections.deque()
    bw[0] = 0
    q.append(0)
    while(len(q) > 0):
        now = q.popleft()
        for nxt in range(N):
            if S[now][nxt] == '0': continue
            if bw[nxt] == -1:
                bw[nxt] = bw[now] ^ 1
                q.append(nxt)
            elif bw[nxt] == bw[now]:
                print(-1)
                sys.exit(0)
    
    ma = 0
    e = [[] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            if(S[i][j] == '1'): e[i].append(j) 
    for i in range(N):
        dep = [-1] * N
        q = collections.deque()
        dep[i] = 0
        q.append(i)
        while(len(q) > 0):
            now = q.popleft()
            for nxt in e[now]:
                if dep[nxt] == -1:
                    dep[nxt] = dep[now] + 1
                    q.append(nxt)
        for j in range(N):
            ma = max(ma, dep[j])
    
    print(ma + 1)
        

if __name__ == "__main__":
    main()


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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;

using namespace std;

using ll = long long;

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;

ll powmod(ll a, ll b) { ll res = 1; a %= MOD; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % MOD; a = a * a % MOD; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


int n;
int a[101];

int main()
{
	FAST_IO;
	string s;
	cin >> s;
	for (auto x : s) {
		if (x == '7') {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}


Measured memory_bytes: 3656
//  SMOKE SHISHA PLAY FIFA  // 
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll t=1;
	//cin >> t;
	while(t--)
	{
		ll n,k=2;
		cin>>n;
		ll a[n+1];
		ll cost[n+1];
		lp(i,1,n){
			cin>>a[i];
			cost[i]=mod;
		}
		cost[1]=0;
		lp(i,2,n){
			for(ll j=i-1; j>= max((ll)1,i-k) ;j--){
				cost[i]=min(cost[i],cost[j]+abs(a[i]-a[j]));
			}
		}
		cout<<cost[n]<<endl;
	}
	return 0;	
}


Measured memory_bytes: 1792
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)
	writer := bufio.NewWriter(os.Stdout)

	var n int
	fmt.Sscan(getNextLine(scanner), &n)
	aa := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Sscan(getNextLine(scanner), &aa[i])
	}

	cnt, gg := shellSort(aa, n)

	fmt.Fprintln(writer, len(gg))
	fmt.Fprintln(writer, strings.Trim(fmt.Sprintf("%v", gg), "[]"))
	fmt.Fprintln(writer, cnt)
	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, aa[i])
	}
	writer.Flush()
}

func insertionSort(aa []int, n, g int) int {
	cnt := 0
	for i := g; i < n; i++ {
		v := aa[i]
		j := i - g
		for j >= 0 && aa[j] > v {
			aa[j+g] = aa[j]
			j -= g
			cnt++
		}
		aa[j+g] = v
	}

	return cnt
}

func shellSort(aa []int, n int) (int, []int) {
	cnt := 0
	gg := make([]int, 0)
	for g := 1; g <= n; g = 3*g + 1 {
		gg = append(gg, g)
	}
	l := len(gg)
	for i := 0; i*2 < l; i++ {
		gg[i], gg[l-1-i] = gg[l-1-i], gg[i]
	}
	for i := 0; i < l; i++ {
		cnt += insertionSort(aa, n, gg[i])
	}

	return cnt, gg
}



Measured memory_bytes: 18788
#include <stdio.h>

int main(void){
    int i,n,m,min,max;
    long long sum;
    sum = 0;
    scanf("%d", &n);
    for (i = 0;i<n;i++){
        scanf("%d", &m);
        if(i == 0){
            min = m;
            max = m;
        }
        if (min > m){
            min = m;
        }
        if (max < m){
            max = m;
        }
        sum += m;
    }
    printf("%d %d %lld\n",min,max,sum);
    return(0);
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
    using namespace std;
    int main() {
        long long n,m;
        cin>>n>>m;
        long long x, ara1[100001];
        long long a, b;
        a=b=0;
        int ia;
        for(int i=1; i<=n; i++) {
            cin>>x>>ara1[i];
            if(a<x ) {
                a=x;
                ia=i;
            }
        }
        sort(ara1+1,ara1+n+1);
        int ninjamoves=0;
        for(int i=n; i>=1; i--) {
            if(ara1[i]>=a) {
                ninjamoves++;
                m-=ara1[i];
                if(m<=0) {
                    cout<<ninjamoves<<endl;
                    return 0;
                }
            }
        }
        ninjamoves+=(m/a);
        if(m%a){
            ninjamoves++;
        }
        cout<<ninjamoves<<endl;
    }

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

int main(){
    string s;
    cin >> s;
    if(s=="Sunny"){
        cout << "Cloudy" << endl;
    }
    else if(s=="Cloudy"){
        cout << "Rainy" << endl;
    }
    else{
        cout << "Sunny" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
///////////////////////////////////////////// Template /////////////////////////////////////////////
#![allow(non_snake_case, unused)]
use std::collections::*;

macro_rules! debug {
	($($v: expr),*) => { {
		use ::std::io::Write;
		$(let _ = write!(::std::io::stderr(), "{} = {:?} ", stringify!($v), $v);)*
		let _ = writeln!(::std::io::stderr(), "@ {}:{}", file!(), line!());
	} }
}
macro_rules! mat {
	($e:expr) => { $e };
	($e:expr; $d:expr $(; $ds:expr)*) => { vec![mat![$e $(; $ds)*]; $d] };
}
macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}
mod template {
	type I<'a> = ::std::iter::Peekable<::std::str::SplitWhitespace<'a>>;
	pub trait FromLn<'a> {
		fn fromln(&mut I<'a>) -> Self;
	}
	pub fn readln<T: for<'a> FromLn<'a>>() -> T {
		let mut buf = String::new();
		let _ = ::std::io::stdin().read_line(&mut buf).unwrap_or_else(|e| panic!("{}", e));
		let mut it = buf.split_whitespace().peekable();
		let t = T::fromln(&mut it);
		if it.peek().is_some() { panic!("input mismatch") }
		t
	}
	pub fn readlns<T: for<'a> FromLn<'a>>(n: usize) -> Vec<T> {
		(0..n).map(|_| readln()).collect()
	}
	macro_rules! read_primitives {
		($($t:ty),*) => { $(
			impl<'a> FromLn<'a> for $t {
				fn fromln(it: &mut I<'a>) -> $t {
					it.next().unwrap_or_else(|| panic!("input mismatch")).parse().unwrap_or_else(|e| panic!("{}", e))
				}
			}
		)* }
	}
	read_primitives!(String, bool, f64, i32, i64, usize, u32, u64);
	impl<'a, T> FromLn<'a> for Vec<T> where T: for<'b> FromLn<'b> {
		fn fromln(it: &mut I) -> Vec<T> {
			let mut vs = vec![];
			while it.peek().is_some() {
				vs.push(T::fromln(it));
			}
			vs
		}
	}
	impl<'a> FromLn<'a> for Vec<char> {
		fn fromln(it: &mut I) -> Vec<char> {
			String::fromln(it).chars().collect()
		}
	}
	impl<'a> FromLn<'a> for Vec<u8> {
		fn fromln(it: &mut I) -> Vec<u8> {
			String::fromln(it).into()
		}
	}
	macro_rules! read_tuple {
		($($t:ident),*) => {
			impl<'a, $($t),*> FromLn<'a> for ($($t),*) where $($t: for<'b> FromLn<'b>),* {
				fn fromln(it: &mut I) -> ($($t),*) {
					($($t::fromln(it)),*)
				}
			}
		}
	}
	read_tuple!(A, B);
	read_tuple!(A, B, C);
	read_tuple!(A, B, C, D);
	pub trait SetMin {
		fn setmin(&mut self, v: Self) -> bool;
	}
	impl<T> SetMin for T where T: PartialOrd {
		fn setmin(&mut self, v: T) -> bool {
			*self > v && { *self = v; true }
		}
	}
	pub trait SetMax {
		fn setmax(&mut self, v: Self) -> bool;
	}
	impl<T> SetMax for T where T: PartialOrd {
		fn setmax(&mut self, v: T) -> bool {
			*self < v && { *self = v; true }
		}
	}
}
use self::template::*;

fn main() {
	let (n, m) = readln();
	let mut to = vec![false; n];
	let mut from = vec![false; n];
	for (a, b) in readlns::<(usize, usize)>(m) {
		if a == 1 {
			to[b - 1] = true;
		}
		if b == n {
			from[a - 1] = true;
		}
	}
	if from.into_iter().zip(to.into_iter()).any(|(a, b)| a && b) {
		println!("POSSIBLE");
	} else {
		println!("IMPOSSIBLE");
	}
}


Measured memory_bytes: 8444
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

struct graph{
  ll V;
  vector<vector<ll> > d;
  graph(ll n){
    init(n);
  }
  void init(ll n){
    V = n;
    d.resize(V);
    REP(i,V){
      d[i].resize(V);
    }
    REP(i,V)REP(j,V) d[i][j] = (i==j)?0:INF;
  }
  void add_edge(ll from, ll to, ll cost){
    d[from][to]=cost;
  }
  void warshall_floyd(){
    REP(k,V)REP(i,V)REP(j,V){
      d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    }
  }
};

int main(){
  ll N,M,R;
  cin >> N >> M >> R;
  ll r[R];
  REP(i,R){
    cin >> r[i];
    r[i]--;
  }
  graph g(N);
  REP(i,M){
    ll a,b,c;
    cin >> a >> b >> c;
    g.add_edge(a-1,b-1,c);
    g.add_edge(b-1,a-1,c);
  }
  g.warshall_floyd();
  ll perm[R];
  REP(i,R){
    perm[i] = i;
  }
  ll ans = INF;
  do{
    ll dist = 0;
    REP(i,R-1) dist += g.d[r[perm[i]]][r[perm[i+1]]];
    ans = min(ans,dist);
  }while(next_permutation(perm,perm+R));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#include <iostream>
using namespace std;
#define ll = long long;
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main()
{
	string x;
	int n;
	cin >>n >> x;
	int ans = 0;
	rep(i,n-1) {
		if (x[i] == x[i+1]) {
			ans++;
		}
	}
	cout << n - ans << endl;
}
/*


  　　　 _」_
　 　×´　　　  _,,..-──-､,_ｧo､__　　  ｀メ.
　　/　    ,  '"´　 　　　   （-､__oヽ　　　_|__
　 　　　／　　　　　　　　 　 ｀ヽ.ヽﾊ）　 　ﾉ
　　　 ／　　　　　　　　　　　  　 Y⌒ヽ.
　　  /　　 /　　　　　　     ヽ.　 |　　',
　　 ,'　　!　　,　 /!　,| ＿   !.　|　　 !　　
　　　|　  |.__/|_ ,'| / ! __｀./! /|　　 |
　　　|　　|´/ |_/  ﾚ' ｧ'´￣` |／､ﾄ、 　|　　奇跡を起こして計算量をO(N)にします!
　　  '､　 |/ｧ'´￣`  　　　,,　|　|ｿ   　ﾊ　　
　　 　 ＼,ハ ,,　　 '　   　（ ＼|　 / .|
　　　 　 | ﾊ、　i7´￣｀i  ,/ ＼_）,'　 |
　　　　 ,'/｀＞ ､,｀   ,.イ/＼＿_! !　  !　　|
　　 　　/　 /｀     T7´／/ヽ､_＿ﾉ_| 　 |__,メ
　　 　　|  .|r/´`ｰ'-､／　,'./  /::/｀ヽ /
　　　　 八　i/      rﾉ,!￣ヽ､| /:/ 　  i_
　　  　,' X`;くﾄ  ､ノ､　/ﾍ｀ヽ．Y    ／::>
　　　　!　// |::|/.|::|＼/ﾉ 八__ノr:':::／/
　　　　|／　 |::|./|::|/　 ）'ﾉ:/--‐'','
　  　  /　　 八:' _ﾉ::ﾉ　 _,.ｲ／　　　　|
　　 　,'　　　 ＼_ ／,|　 　／　　　 　 !
　　　 |　　　　　　  /|　 ／ 　　　/ 　 |
*/


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 100;
const long double EPS = 1e-10;

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

  vector<int> c(26, INF);
  rep(i, n) {
    int m = s[i].size();
    vector<int> cnt(26, 0);
    rep(j, m) {
      cnt[s[i][j] - 'a']++;
    }
    rep(j, 26) {
      c[j] = min(c[j], cnt[j]);
    }
  }

  rep(i, 26) {
    char ch = 'a' + i;
    rep(j, c[i]) {
      cout << ch;
    }
  }
  cout << endl;


  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    vector<int> vec(N);
    int max=0;
    REP(i,N){
        cin>>vec[i];
        chmax(max,vec[i]);
    }
    int s=0;
    REP(i,N){
        s+=vec[i];
    }
    isYes(s-max>max);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[])
{
        int n, i;
        int a;
        int a_min = 1000000, a_max = -1000000;
        long a_sum = 0;

        scanf("%d", &n);

        for (i = 0; i < n; i++) {
                scanf("%d", &a);
                if (a < a_min) a_min = a;
                if (a > a_max) a_max = a;
                a_sum += a;
        }

        printf("%d %d %ld\n", a_min, a_max, a_sum);

        return 0;
}

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

int main(){
	int x;
	while( cin >> x, x ){
		x = 1000 - x;
		int ans = 0;
		while( x > 0 ){
			ans++;
			if( x >= 500 ){
				x -= 500;
			}else if( x >= 100 ){
				x -= 100;
			}else if( x >= 50 ){
				x -= 50;
			}else if( x >= 10 ){
				x -= 10;
			}else if( x >= 5 ){
				x -= 5;
			}else{
				x--;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
// C++ program to count the Minimum number of 
// increasing subsequences 
#include <bits/stdc++.h> 
using namespace std; 
  
int MinimumNumIncreasingSubsequences(int arr[], int n) 
{ 
    multiset<int> last; 
  
    // last element in each  increasing subsequence  
    // found so far 
    for (int i = 0; i < n; i++) { 
  
        // here our current element is arr[i] 
        multiset<int>::iterator it = last.lower_bound(arr[i]); 
  
        // iterator to the first element larger  
        // than or equal to arr[i] 
        if (it == last.begin()) 
  
            // if all the elements in last larger 
            // than or to arr[i] then insert it into last 
            last.insert(arr[i]); 
  
        else { 
            it--; 
  
            // the largest element smaller than arr[i] is the number 
            // before *it which is it-- 
            last.erase(it); // erase the largest element smaller than arr[i] 
            last.insert(arr[i]); // and replace it with arr[i] 
        } 
    } 
    return last.size(); // our answer is the size of last 
} 
  
// Driver program 
int main() 
{   
    int n;
    cin >> n;
    int arr[n];
    for(int i=0; i<n; ++i) cin >> arr[i];
    cout << MinimumNumIncreasingSubsequences(arr, n) << endl; 
    return 0; 
} 

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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)


int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        int V,E;
        cin >> V >> E;
        vector<int> adj[V];
        int h[V];
        loop(i,0,V-1) cin>>h[i];
        for(int i = 0; i < E; i++)
        {
            int x, y;
            cin >> x >> y;
            x--;
            y--;
            adj[x].push_back(y);
            adj[y].push_back(x);
        }
        int ans=0;
        for(int i=0;i<V;i++)
        {
            int q=1;
            if(adj[i].size()==0)
            {
                ans++;
                continue;
            }
            for(int j=0;j<adj[i].size();j++)
            {
                if(h[i]<=h[adj[i][j]])
                {
                    q=0;
                    break;
                }
            }
            if(q) ans++;
        }
        cout<<ans;

    }
    return 0;
}


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

int main() {
    int64_t N;
    cin >> N;
    map<string, int64_t> mp;
    for (int64_t i = 0; i < N; i++) {
        string S;
        cin >> S;
        mp[S]++;
    }

    int64_t max_num = -1;
    for (const auto& p : mp) {
        max_num = max(max_num, p.second);
    }

    set<string> st;
    for (const auto& p : mp) {
        if (p.second == max_num) {
            st.insert(p.first);
        }
    }

    for (const string& s : st) {
        cout << s << endl;
    }
}

Measured memory_bytes: 35328
import bisect
import collections
N = int(input())
A = [int(input()) for i in range(N)]
q = collections.deque([-1])
for x in A:
    id = bisect.bisect_left(q, x)
    # print(id, x, q)
    if id == 0:
        q.appendleft(x)
    else:
        q[id-1] = x
print(len(q))


Measured memory_bytes: 8060
#define CIN_ONLY 1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
const int MOD = 1000000007;
const ld PI = acos(ld(-1));
int fix(ll n) { return (n % MOD + MOD) % MOD; }
int fix(ll n, int MOD) { return (n % MOD + MOD) % MOD; }

int main()
{
  if (CIN_ONLY) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  string s;
  cin >> s;
  ll nw = 0, ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'W') {
      ans += i - nw;
      ++nw;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 720
using System;
using System.Collections.Generic;

namespace binarySearch
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var S = new HashSet<int>();
            foreach (var s in Console.ReadLine().Split(' '))
            {
                S.Add(int.Parse(s));
            }
            Console.ReadLine();
            var T = new HashSet<int>();
            foreach (var t in Console.ReadLine().Split(' '))
            {
                T.Add(int.Parse(t));
            }

            S.IntersectWith(T);
            Console.WriteLine(new int[S.Count].Length);
        }
    }
}

Measured memory_bytes: 22124
#include<stdio.h>

int main(void)
{
	int N;
	int a;
	int b;
	int c;
	int i;
	
	scanf("%d", &N);
	
	for(i = 0;i < N;i++){
		scanf("%d %d %d", &a, &b, &c);
		
		if((a * a) + (b * b) == (c * c) || (c * c) + (b * b) == (a * a) || (a * a) + (c * c) == (b * b)){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 580
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 998244353

#C
def C():
    n = I()
    s = S()
    ans = float("inf")
    b = [0 for i in range(n)]
    for i in range(n):
        if s[i] == "#":
            b[i] = 1
    w = [0 for i in range(n)]
    for i in range(n):
        if s[i] == ".":
            w[i] = 1
    b.insert(0,0)
    w.insert(0,0)
    for i in range(n):
        b[i+1] += b[i]
        w[i+1] += w[i]
    for i in range(n+1):
        m = b[i]+w[n]-w[i]
        ans = min(ans,m)
    print(ans)
    return

#D
def D():
    n = I()
    a = IR(n)

    return

#E
def E():
    n = I()

    return

#F
def F():
    return


#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 65472
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>

using namespace std;
int main(){
  int n;
  vector<int> P, Q;

  cin >> n;
  for(int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    P.push_back(tmp);
  }
  for(int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    Q.push_back(tmp);
  }

  bool change = false;
  for(int i = 0; i < n; i++){
    if(P[i] == Q[i]) {
      continue;
    } else if(P[i] > Q[i]) {
      change = true;
      break;
    } else {
      break;
    }
  }

  if(change) {
    int tmp;
    for(int i = 0; i < n; i++) {
      tmp = P[i];
      P[i] = Q[i];
      Q[i] = tmp;
    }
  }

  int cnt = 0;
  do {
    if(P == Q) {
      cout << cnt << endl;
      break;
    } else {
      cnt++;
    }
  } while(next_permutation(P.begin(), P.end()));

  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const ll inf=1ll<<60;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	char a,b;
	cin>>a>>b;
	if(a=='H'&&b=='H'||a=='D'&&b=='D')cout<<"H"<<endl;
	else cout<<"D"<<endl;
}



















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 = sc.nextInt();
        char[]list = sc.next().toCharArray();
        
        int count=0;
        for(int i=0; i<N-2; i++){
            if(list[i]=='A' && list[i+1]=='B' && list[i+2]=='C'){
                count++;
            }
        }
        System.out.println(count);
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
int main() {
  string S,T; cin >> S >> T;
  int lg = S.size();
  int ans=0;
  rep(i,lg){
    if (S[i] != T[i]) ans++; 
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3896
// J4180449 三宅亮輔
// 問題名
// - Graph
// 問題URL
// - https://onlinejudge.u-aizu.ac.jp/#/problems/ALDS1_11_A
// 所要時間
// - 20分
// 学んだこと
// 隣接行列の方が扱いやすいが
// 計算量やメモリを考えると隣接リスト表現の方が優れていると感じた
// インデックスを最初1からはじめるか0から始めるかバラバラになっていてバグを取るのに手間取った

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n;

int ans[100][100];

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++) {
            int x;
            cin >> x;
            x--;
            ans[u][x] = 1;
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cout << ans[i][j];
            cout << (j == n - 1 ? "\n" : " ");
        }
    }
}


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

int main(){
  int a, b;
  cin >> a >> b;

  int x = 0, y = 0;
  for(int i = 1; i <= 998; i++){
    x += i;
    y = x + i + 1;
    if((x - a) == (y - b)) break;
  }
  
  int ans = x - a;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import heapq

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

heapq.heapify(a)
b = list(map(lambda x: x * (-1), a))
heapq.heapify(b)
ans -= heapq.heappop(b)

for i in range(n//2-1):
    ans -= 2 * heapq.heappop(b)
if n % 2 == 1:
    ans -= heapq.heappop(b)
print(ans)


Measured memory_bytes: 31680
#include <stdio.h>
#include <string.h>
int main(void){
  long long int a,b,c,d;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&d);

long long int ans;

if(a>=0&&b>=0&&c>=0&&d>=0)  ans=b*d;

if(a<=0&&b<=0&&c<=0&&d<=0)  ans=a*c;

if(a<=0&&b>=0&&c>=0&&d>=0)  ans=b*d;

if(a>=0&&b>=0&&c<=0&&d>=0)  ans=b*d;

if(a<=0&&b>=0&&c<=0&&d>=0){
  if(a*c>b*d){
    ans=a*c;
  }else{
    ans=b*d;
  } 
}
if(a<=0&&b<=0&&c>=0&&d>=0)  ans=b*c;

if(a>=0&&b>=0&&c<=0&&d<=0)  ans=a*d;

if(a<=0&&b<=0&&c<=0&&d>=0)  ans=a*c;

if(a<=0&&b>=0&&c<=0&&d<=0)  ans=a*c;


printf("%lld",ans);

return 0;


}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
//#define int long long

bool digit[10];

bool notValid(int n) {
	while(n > 0) {
		if(digit[n%10]) return true;
		n = n/10;
	}
	return false;
}

void solve() {
	int n,l,num;
	cin >> n >> l;
	
	while(l--) {
		cin >> num;
		digit[num] = true;
	}
	
	while(notValid(n)) {
		n++;
	}
	
	cout << n++ << endl;
 		
}
		
			
		

int32_t main() {
	IOS;
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll dp [1<<17];
ll binpow(ll a,ll b)
{
    a%=mod;
    ll res = 1;
    while(b>0)
    {
        if(b&1) res = res * a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return res;
}
int main()
{
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(int i=k;i>=1;i--)
    {
        dp[i] = binpow(k/i,n);
        for(int j = i+i ; j<=k;j+=i)
            dp[i]-=dp[j];
        ans+=i*dp[i]%mod;
    }
    cout<<ans%mod<<endl;
}


Measured memory_bytes: 4344
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S,T;
	scan(S>>T);
	T+=S;
	prin(T);
	return 0;
}


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

using namespace std;

vector<int> g[200000 + 1];
int a[200000 + 1];

int f(int u, int p, int sum){
    a[u] += sum;

    for(int i = 0; i < g[u].size(); i++){
        int v = g[u][i];
        if(v == p){
            continue;
        }
        f(v, u, a[u]);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n - 1; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    while(q--){
        int x, y;
        cin >> x >> y;
        a[x - 1] += y;
    }

    f(0, -1, 0);
    for(int i = 0; i < n; i++){
        cout << a[i] << " ";
    }

    return 0;
}

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

int main(){
	string s;
	while(cin>>s){
		int JOI=0;
		int IOI=0;
		for(int i=0;i<s.size()-2;i++){
			string alt="";
			for(int j=i;j<i+3;j++)alt+=s[j];
			if(alt=="JOI")JOI++;
			if(alt=="IOI")IOI++;
		}
		cout<<JOI<<endl;
		cout<<IOI<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
n = list(str(input()))

if n[-1] == '2' or n[-1] == '4' or n[-1] == '5' or n[-1] == '7' or n[-1] == '9':
  print('hon')
elif n[-1] == '0' or n[-1] == '1' or n[-1] == '6' or n[-1] == '8':
  print('pon')
else:
  print('bon')

Measured memory_bytes: 9056
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
use rustc_hash::*;

type Map = FxHashMap<(usize, usize), i64>;
fn main() {
    input! {
        n: usize,
        mut ai: [i64; n],
    }
    let m = n/2;

    let mut memo = Map::default();
    let ans = dfs(&ai,  0,  m, &mut memo);
    println!("{}", ans);
}

fn dfs(ai: &[i64], idx: usize, count: usize, memo: &mut Map) -> i64 {
    let key = (idx, count);
    if let Some(v) = memo.get(&key) {
        return *v;
    }

    if count == 0 {
        memo.insert(key, 0);
        return 0;
    }

    if count > (ai.len() - idx + 1)/2 {
        memo.insert(key, std::i64::MIN);
        return std::i64::MIN;
    }

    let res = max(
        dfs(ai, idx+1, count, memo),
        dfs(ai, idx+2, count-1, memo) + ai[idx]
    );
    memo.insert(key, res);
    res
}

Measured memory_bytes: 31232
#include<stdio.h>

int main()
{
  int n,i,j,v,vv,m;
  int map[101][101];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    if(i<n)break;
  }
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      map[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&m);
    for(j=0;j<m;j++){
      scanf("%d",&vv);
      map[v-1][vv-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      printf("%d ",map[i][j]);
    }
    printf("%d\n",map[i][j]);
  }
  return 0;
}



Measured memory_bytes: 2088
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 入力値を文字列で返却する
def gets_s()
  gets.chomp
end

n = gets_i

count_hash = {}
max = 0
n.times do
  s = gets_s
  count = count_hash[s].to_i + 1
  count_hash[s] = count
  max = [max, count].max
end

ans = []
count_hash.each do |k, v|
  if v == max
    ans.push k
  end
end

ans.sort.each do |a|
  puts a
end

Measured memory_bytes: 43560
#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 n, m;
vector<vector<int>> g;
vector<int> dp(200000, -1);

int dfs(int v) {
    if(dp[v] != -1) {
        return dp[v];
    }
    int res = 0;
    for(auto u : g[v]) {
        chmax(res, dfs(u) + 1);
    }
    return dp[v] = res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    g.resize(n);
    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].emplace_back(y);
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        chmax(ans, dfs(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> C(N),S(N),F(N);
	rep(i,N-1){
		cin >> C[i] >> S[i] >> F[i];
	}
	vector<int> ans;
	for(int i = 0;i<N;i++){
		//i地点からスタートしてN-1に行く場合を考える
		int time = 0;
		int now = i;
		while(now!=N-1){
			if(time<=S[now]){
				time = S[now];
				time += C[now];
				now++;
				continue;
			}
			if(time>S[now]){
				//次に出発するのは
				int t = time - S[now];
				//t秒後
				t %= F[now];
				time += C[now];
				if(t)time += F[now] - t;
				now++;
				//cout << time << endl;
				continue;
			}
		}
		ans.push_back(time);
	}
	for(auto x:ans)cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> P;
#define Mod 1000000007


int main(){
    ll i,j;
    ll n,k;
    cin>>n>>k;
    

    ll w[n];
    ll v[n];

    for(i=0;i<n;i++) cin>>w[i]>>v[i];


    ll dp[n][101010];

    for(j=0;j<101010;j++) dp[0][j]=1e15;
    dp[0][v[0]]=w[0];
    dp[0][0]=0;

    for(i=1;i<n;i++){
        for(j=0;j<101010;j++){
            dp[i][j]=dp[i-1][j];
        }
        for(j=0;j<101010;j++){
            if(j-v[i]>=0) dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
        }
    }

    ll ans=-1;
    for(i=0;i<101010;i++){
        if(dp[n-1][i]<=k) ans=i;
    }
    cout<<ans<<endl;




    return 0;
}

Measured memory_bytes: 79104
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;

using namespace std;

int main(){
  string S;
  cin >> S;
  if(S[0]==S[1] || S[1]==S[2] || S[2]==S[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 311;
const ll INF = 5e16;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x), putchar(' '); }

	inline void wln ( ll x ) { write(x), putchar('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	/*
		一个 a[i] 被删到 0 需要选他 a[i] 次 
		f[i][j][k] 表示从 (a1, a2, a3) 删到 (i, j, k)
		的期望操作次数。 
	*/
	
	ll a1, a2, a3;
	ll n, S = 0, a[N];
	double Ans, f[N][N][N];
	
	inline double dfs ( ll x, ll y, ll z ) {
		if (f[x][y][z]) return f[x][y][z];
		if (x == 0 && y == 0 && z == 0) return 0;
		
		double res = 1;
		if (x) res += dfs(x - 1, y, z) * x / (x + y + z);
		if (y) res += dfs(x + 1, y - 1, z) * y / (x + y + z);
		if (z) res += dfs(x, y + 1, z - 1) * z / (x + y + z);
		res += 1.0 * (n - x - y - z) / (x + y + z);
		return f[x][y][z] = res;
	}
	
//	inline double dfs ( ll x, ll y, ll z ) {
//		if (f[x][y][z]) return f[x][y][z];
//		if (x == a1 && y == a2 && z == a3) return 0;
//		
//		double res = 1.0 / (n - x - y - z);
//		if (x < a1) res += dfs(x + 1, y, z) * (a1 - x) / (n - x - y - z);
//		if (x && y < a2) res += dfs(x - 1, y + 1, z) * (a2 - y) / (n - x - y - z);
//		if (y && z < a3) res += dfs(x, y - 1, z + 1) * (a3 - z) / (n - x - y - z);
//		if (n > 1) res += 1.0 * (x + y + z) / (n - 1);
//		
//		return f[x][y][z] = res;
//	}
	
	int main() {
		n = read();
		For ( i, 1, n ) a[i] = read();
		For ( i, 1, n ) 
			a1 += a[i] == 1, 
			a2 += a[i] == 2, a3 += a[i] == 3;
		dfs(a1, a2, a3);
//		if (n > 1) f[a1][a2][a3] += 1.0 * n / (n - 1);
		return printf("%.8lf\n", f[a1][a2][a3]), 0;
	}
	
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	return Cesare :: main();
}

/*

*/






Measured memory_bytes: 227584