akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto ab = readln.split.to!(int[]);
    auto A = ab[0];
    auto B = ab[1];
    int t = 1, r;
    while (t < B) {
        ++r;
        t = t - 1 + A;
    }
    writeln(r);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
bool sortDescByFirst(const pair<int,int>&a, const pair<int,int>&b){
    return a.first>=b.first;
}
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b;
    while(cin>>a>>b){
        a*b %2?cout<<"Odd"<<endl:cout<<"Even"<<endl;
    }
    return 0;
}


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

struct color {
    int id;
    int num;
    bool operator<(const color& right) const { return num < right.num; }
};

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    vector<color> a(N);
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        a[i].id = i + 1;
        a[i].num = tmp;
    }

    vector<vector<int>> grid(H, vector<int>(W, 0));

    sort(a.begin(), a.end());
    int point = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < a[i].num; j++) {
            int h = point / W;
            int w = point % W;
            if (h % 2 == 1) {
                w = W - w - 1;
            }
            grid[h][w] = a[i].id;
            point++;
        }
    }

    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            printf("%d ", grid[h][w]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 1e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int arr[5];
	for(int i = 0; i < 5; i++){
		cin >> arr[i];
	}
	sort(arr, arr + 5);
	int ans = 1e17;
	do{
		int sum = 0;
		for(int i = 0; i < 4; i++){
			sum += ((arr[i] + 9) / 10) * 10;
		}
		sum += arr[4];
		ans = min(ans, sum);
	}while(next_permutation(arr, arr + 5));
	cout << ans;
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    string s; cin >> s;
    const int n = s.length();

    int ans = 0;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - 1 - i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(non_upper_case_globals)]
#![macro_use]
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::ops::*;
use std::rc::*;
use std::str::*;
use std::string::*;
use std::*;

const MOD: usize = 1000000007;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    // ========================================= //

    let X : isize = sc.read();
    for i in -1000..1000 {
        for j in -1000..1000 {
            if i*i*i*i*i - j*j*j*j*j == X {
                println!("{} {}",i,j);
                return;
            }
        }
    }

}


pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);
impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int c_a[100005],c_b[100005];
int main(){
    int n;
    cin >> n;
    int a[n/2],b[n/2];
    for(int i=0;i<n;i++){
        if(i%2==0){
            cin >> a[i/2];
            c_a[a[i/2]]++;
        }
        else{
            cin >> b[(i-1)/2];
            c_b[b[(i-1)/2]]++;
        }
    }
    int max_a=0;
    int sec_a=0;
    int max_b=0;
    int sec_b=0;
    for(int i=0;i<n/2;i++){
        if(c_a[max_a]<=c_a[a[i]] && max_a!=a[i]){
            sec_a=max_a;
            max_a=a[i];
        }
        else if(c_a[sec_a]<=c_a[a[i]] && sec_a!=a[i] && max_a!=a[i]){
            sec_a=a[i];
        }
        if(c_b[max_b]<=c_b[b[i]] && max_b!=b[i]){
            sec_b=max_b;
            max_b=b[i];
        }
        else if(c_b[sec_b]<=c_b[b[i]] && sec_b!=b[i] && max_b!=b[i]){
            sec_b=b[i];
        }      
    }
    if(max_a!=max_b)cout << n-c_a[max_a]-c_b[max_b] << endl;
    else if(c_a[sec_a]>c_b[sec_b])cout << n-c_a[sec_a]-c_b[max_b] << endl;
    else cout << n-c_a[max_a]-c_b[sec_b] << endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <iomanip>
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std ;

inline LL read() {
	LL x = 0 , f = 1 ;
	char ch = getchar() ;
	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
	return x * f ;
}

const int N = 1e5+11;
int n,x,y,S;
int a,b,c,d;


int main() {
	n=read();
	For(i, 1, n) {
		x=read();
		if(x%4==0) a++;
		else if(x%2==0) b++;
		else c++;
	}
	
	if(a>=c || a+1==c&&b==0) puts("Yes");
	else puts("No");
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

bool chk(int a) {
    if (a == 1) return false;
    if (a == 2 || a == 3) return true;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0) return false;
    }
    return true;
}

signed main() {
    int q;
    cin >> q;
    int a[100100];
    a[0] = 0;
    rep(i, 1, 100100) {
        if (chk(i) && chk((i + 1) / 2)) {
            a[i] = a[i - 1] + 1;
        } else {
            a[i] = a[i - 1];
        }
    }
    rep(i, 0, q) {
        int l, r;
        cin >> l >> r;
        cout << a[r] - a[--l] << "\n";
    }
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

#include <bits/extc++.h>
using namespace __gnu_pbds;

typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int MX = 100005;
int n, a[MX], b[MX];
vi c;

bool esPos (int m) {
	ll res = 0;

	for (int i = 1; i <= n; i++)
		b[i] = a[i] <= c[m] ? 1 : -1;

	ordered_set st;
	st.insert(ii(0, 0));

	for (int i = 1; i <= n; i++) {
		b[i] += b[i - 1];
		res += st.order_of_key(ii(b[i], -1));
		st.insert(ii(b[i], i));
	}

	return res >= (1ll * n * (n + 1) / 2) / 2 + 1;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		c.pb(a[i]);
	}

	sort(all(c));

	int i = 0, j = (int)c.size() - 1, rep = 20;

	while (rep--) {
		int m = (i + j) / 2;
		if (esPos(m)) j = m;
		else i = m;
	}

	cout << c[j] << endl;

	return 0;
}


Measured memory_bytes: 10100
//Author : Siriuslight
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0),cout<<setprecision(10)<<fixed;
#define int long long
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const ll inf = 1e9+100, N = 2e5+5;
const ll INF = 1e18+100, MOD = 1e9+7;

ll powmod(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll power(ll a,ll b){ll r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);}
ll inv(ll a, ll m = MOD){return powmod(a,m-2,m);}
ll lcm(ll a,ll b){return(a*b)/gcd(a,b);}

//ordered_set X;
//X.insert(3);
//X.order_of_key(3) no of elements less than 3
//*X.find_by_order(n) nth greatest element(0-indexed)

int n, a[4][N], dp[N][5];

int solve(int id, int t){
    if(id == 1){
        return a[t][id];
    }
    int &res = dp[id][t];
    if(res != -1) return res;
    if(t == 1)
        res = a[t][id] + max(solve(id - 1, 2), solve(id - 1, 3));
    else if(t == 2)
        res = a[t][id] + max(solve(id - 1, 1), solve(id - 1, 3));
    else
        res = a[t][id] + max(solve(id - 1, 1), solve(id - 1, 2));
    return res;
}

int32_t main(){
    FIO;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[1][i] >> a[2][i] >> a[3][i];
    }
    memset(dp, -1, sizeof(dp));
    cout << max(solve(n, 1), max(solve(n, 2), solve(n, 3)));
}


Measured memory_bytes: 18048
INF = float("inf")

N, *S = map(int, open(0).read().split())
M = len(S)

S.sort(reverse=True)

Q = [S[0]]
S[0] = INF
for _ in range(N):
    Q.sort()
    T = Q[:]

    cur = 1
    while Q:
        p = Q.pop()
        while S[cur] >= p:
            cur += 1
            if cur == M:
                print("No")
                exit()
        T.append(S[cur])
        S[cur] = INF

    Q = T

print("Yes")

Measured memory_bytes: 32044
class SegmentTree
  MIN = -Float::INFINITY
  def initialize(data)
    @offset = 1 << data.length.bit_length
    @data = Array.new(@offset * 2, MIN)
    data.each_with_index do |v, i|
      @data[@offset + i] = v
    end
    i = @offset - 1
    while i > 0
      @data[i] = merge(@data[2 * i], @data[2 * i + 1])
      i -= 1
    end
  end
  def merge(l, r); l > r ? l : r; end
  def max(a, b, k = 1, l = 0, r = @offset)
    mid = (l + r) / 2
    return MIN if b <= l || r <= a
    return @data[k] if a <= l && r <= b
    return merge(max(a,b,2 * k, l, mid), max(a,b,2 * k + 1, mid, r))
  end
end

def max(a,b); a > b ? a : b; end
def min(a,b); a < b ? a : b; end

def extract_cycle(s, used)
  cycle = []
  u = s
  until used[u]
    used[u] = true
    cycle << u  
    u = P[u]
  end
  return cycle
end

N, K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i).tap{|array| array.unshift(0) }
C = gets.split.map(&:to_i).tap{|array| array.unshift(0) }

used = Array.new(N + 1)
ans = (1 .. N).inject(-1e20) do |max_score, s|
  next max_score if used[s]
  # sを始点とする閉路を抽出
  cycle = extract_cycle(s, used)
  z = cycle.size
  
  # 閉路の各頂点から最大1周分のスコアを計算できるように事前準備
  score = Array.new(3 * z + 1, 0)
  (1 .. z * 3).each do |i|
    v = cycle[i % z]
    score[i] = score[i - 1] + C[v]
  end

  # 閉路上の任意の点 s を始点としたときの最大スコアを 
  # セグ木を使って O(N log N) で計算
  
  sz = max(0, score[z])
  k = min(K, z + K % z)
  r = (K - k) / z

  st = SegmentTree.new(score)
  cycle_score = (0 ... z).map{|s| r * sz + st.max(s + 1, s + k + 1) - score[s]}.max

  max(max_score, cycle_score)
end

puts ans


Measured memory_bytes: 15416
h,w,k = map(int,input().split())
mod = 10**9+7
dp = [0]*(w+2)
dp[1] = 1

#左右の余白を埋めるパターン数
ref = [1,2,3,5,8,13,21]
pat = lambda l,r:ref[max(l,0)] * ref[max(r,0)]

for i in range(h):
	_dp = [0]*(w + 2)
	for j in range(1,w+1):
		_dp[j] = dp[j-1]*pat(j-3,w-j-1) + dp[j]*pat(j-2,w-j-1) + dp[j+1]*pat(j-2,w-j-2)
		_dp[j] %= mod
	dp = _dp
print(dp[k])

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

int main(){
    string s1,s2;
    cin >> s1 >> s2;
    int a1 = s1.size();
    int a2 = s2.size();
    for(int i = 0 ; i < a2; i++){
        cout << s1[i] << s2[i];
    }
    if(a1-a2 == 1){
        cout << s1[a1-1];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	string s; cin >> s;
	int ans = 100;
	int cnt=0;
	for(int i = 0;i < 26 ; i++)	
	{
		int hoge = -1;
		int foo= -1;
		rep(j,s.size())
		{
			if(s[j]=='a'+i)
			{
				foo=0;
			}
		}
		if(foo==-1)continue;
		hoge = 0;
		rep(j,s.size())
		{
			if((s[j]=='a'+i&&j!=0)||j+1==s.size())
			{
				if(j+1==s.size())foo++;
				//cout<<' '<<foo<<endl;
				hoge = max(hoge,foo);
				foo=0;
			}
			else foo++;
		}
		//cout<<(char)('a'+i)<<':'<<hoge<<endl;
		ans = min(ans , hoge);
		cnt++;
	}
	if(cnt==1)ans=0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from scipy.sparse import csr_matrix #pypyだとエラーになるので、pythonを使うこと
from scipy.sparse.csgraph import shortest_path, floyd_warshall
import numpy as np

import sys
def input():
	return sys.stdin.readline().strip()

N, M, L = list(map(int, input().split()))

A = [0]*M
B = [0]*M
C = [0]*M
for i in range(M):
	Ai, Bi, Ci = list(map(int, input().split()))
	A[i] = Ai - 1
	B[i] = Bi - 1
	C[i] = Ci

graph = csr_matrix((C, (A, B)), shape=(N, N))
#print(graph)
dist = floyd_warshall(graph, directed=False)

graph2 = np.full((N, N), np.inf)
graph2[dist <= L] = 1
graph2 = csr_matrix(graph2)
num = floyd_warshall(graph2, directed=False)


num = num.tolist()

Q = int(input())
for q in range(Q):
	s, t = list(map(int, input().split()))
	if num[s - 1][t - 1] < 10000000:
		print(int(num[s - 1][t - 1] - 1))
	else:
		print(-1)

Measured memory_bytes: 22932
n=int(input())
mod=10**9+7
#A=0,C=1,G=2,T=3
table=[1]*(64)
data=[[] for i in range(64)]
for i in range(64):
    z=i
    num=""
    for j in range(3):
        if i//(4**(2-j))==1:
            num+="1"
            i%=(4**(2-j))
        elif i//(4**(2-j))==2:
            num+="2"
            i%=(4**(2-j))*2
        elif i//(4**(2-j))==3:
            num+="3"
            i%=(4**(2-j))*3
        else:
            num+="0"
    for j in range(4):
        a=num+str(j)
        b=a[1]+a[0]+a[2]+a[3]
        c=a[0]+a[2]+a[1]+a[3]
        d=a[0]+a[1]+a[3]+a[2]
        if "021" in a or "021" in b or "021" in c or "021" in d:
            continue
        else:
            data[z].append(16*int(a[1])+4*int(a[2])+int(a[3]))
table[6]=0
table[9]=0
table[33]=0
for i in range(n-3):
    h=[0]*64
    for j in range(64):
        for u in data[j]:
            h[u]=(h[u]+table[j])%mod
    table=h
ans=0
for i in range(64):
    ans=(ans+table[i])%mod
print(ans)

Measured memory_bytes: 39024
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<57;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

int n;
vl a;

int main(){
	cin>>n;
	a=vl(3*n);
	for(int i=0;i<3*n;i++) cin>>a[i];
	sort(a.rbegin(),a.rend());
	ll sum=0;
	for(int i=0;i<n;i++) sum+=a[2*i+1];
	cout<<sum<<endl;
}

Measured memory_bytes: 2560
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
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;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (auto &x : a) {
        cin >> x;
    }

    if (n == 2) {
        cout << max(a[0], a[1]) << "\n";
        return 0;
    }

    vector<vector<ll>> dp(n, vector<ll>(2));
    dp[n-1][0] = a[n-1];
    dp[n-1][1] = a[n-1];
    dp[n-2][0] = a[n-2];
    dp[n-2][1] = a[n-2];
    dp[n-3][0] = a[n-3];
    dp[n-3][1] = a[n-3] + a[n-1];

    for (ll i = n-4; i >= 0; i--) {
        if ((n-i)%2 == 0) {
            dp[i][0] = max(dp[i+2][0], dp[i+3][1]);
            dp[i][0] += a[i];
            dp[i][1] = dp[i][0];
        } else {
            dp[i][0] = max(dp[i+2][0], max(dp[i+3][0], dp[i+4][1]));
            dp[i][0] += a[i];
            dp[i][1] = a[i] + dp[i+2][1];
        }
    }

    if (n%2 == 0) {
        cout << max(dp[0][0], dp[1][1]) << "\n";
    } else {
        cout << max(dp[0][0], max(dp[1][0], dp[2][1])) << "\n";
    }
}



Measured memory_bytes: 15664
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	string S, T;
	cin >> S >> T;

	string ans = "UNRESTORABLE";
	IREP(i, S.length() - T.length())
	{
		bool conform = true;
		FOR(j, i + T.length(), i)
		{
			if (S[j] == '?' || S[j] == T[j - i])continue;
			conform = false;
			break;
		}
		if (conform)
		{
			FOR(j, i + T.length(), i)
			{
				S[j] = T[j - i];
			}
			REP(j, S.length())
			{
				if (S[j] == '?')S[j] = 'a';
			}
			ans = S;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define int long long

main()
{
	int n,k;
	cin>>n>>k;
	int ans;
	if(k%2){
		ans=(n/k)*(n/k)*(n/k);
	}
	else {
		int gay=(n+k/2)/k;
		ans=(n/k)*(n/k)*(n/k)+gay*gay*gay;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N;
    cin >> N ;
    vector<int> A(N);
    for (int i = 0; i < N ; i++) {
        std::cin >> A.at(i);
    }
    vector<int> O(N);
    for (int j = 0; j < N; j++)
    {
        O[A[j]-1] = j+1;
    }
    for (int i = 0; i < N; i++)
    {
        cout << O[i] << " ";
    }
}

Measured memory_bytes: 1536
#include<stdio.h>

#define NIL NULL

struct node
{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

Node root;

Node treeMinimum(Node x)
{
  while(x->left != NIL)
    {
      x = x->left;
    }
  
  return x;
}

Node treeMaximum(Node x)
{
  while(x->right != NIL)
    {
      x = x->right;
    }
  
  return x;
}

Node treeSearch(Node u, int k)
{
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x)
{
  Node y;
  
  if(x->right != NIL)
    {
      return treeMinimum(x->right);
    }
  y = x->parent;

  while(y != NIL && x == y->right)
    {
      x = y;
      y = y->parent;
    }
  
  return y;
}

void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL)
    {
      y = x;

      if(z->key < x->key)
	{
	  x = x->left;
	}
      else
	{
	  x = x->right;
	}
    }
  z->parent = y;

  if(y == NIL)
    {
      root = z;
    }
  else if(z->key < y->key)
    {
      y->left = z;
    }
  else
    {
      y->right = z;
    }

  return;
}

void inorder(Node u)
{
  if(u == NIL) return;

  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

  return;
}
void preorder(Node u)
{
  if(u == NIL) return;

  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);

  return;
}


int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ )
    {
      scanf("%s", com);
      if ( com[0] == 'f' )
	{
	  scanf("%d", &x);
	  Node t = treeSearch(root, x);
	  if ( t != NIL ) printf("yes\n");
	  else printf("no\n");
	}
      else if ( com[0] == 'i' )
	{
	  scanf("%d", &x);
	  insert(x);
	}
      else if ( com[0] == 'p' )
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
    }

  return 0;
}



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

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		
		String s = buf.readLine();
    	String[] strlAry =s.split(" ");
    	for(int i=0;i<strlAry.length;i++){
   	    }
   	    double a = Integer.parseInt(strlAry[0]);
   	    double b = Integer.parseInt(strlAry[1]);

   	    double d = a/b;
   	    double r = a%b;
   	    double f = a/b;
   	    String f2 = String.format("%.5f", f);
   	    System.out.println((int)d+" "+(int)r+" "+f2);
 	}
}

Measured memory_bytes: 17112
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

int main() {
  int a, b;
  cin >> a >> b;
  int tmp = min(a, b);
  int iter = max(a, b);
 rep(i, iter){
   cout << tmp;
 }
 cout << endl;
 return 0;
   }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    string s;
    cin >> s;
    int n = s.size();
    rep(i,n){
        if(s[i] == '?') s[i] = 'D';
    }
    cout << s << endl;
    return 0;
}




Measured memory_bytes: 3748
<?php

fscanf(STDIN, "%d", $n);
$H = array_map('intval', explode(' ', trim(fgets(STDIN))));

$ans = 0;
while (max($H) !== 0) {
    $l = 0;
    while ($H[$l] == 0) ++$l;

    $r = $l;
    while ($r < $n && $H[$r] != 0) {
        --$H[$r];
        ++$r;
    }
    ++$ans;
}

echo $ans, PHP_EOL;


Measured memory_bytes: 4856
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	int K, X;
	cin >> K >> X;

	for (int i = X - K + 1; i < X + K; ++i) {
		cout << i << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    struct engine {
        double x, y;
        bool operator<(const engine &rhs) const { return atan2(x, y) < atan2(rhs.x, rhs.y); };
    };
    vector<engine> engines(n);
    for (int i = 0; i < n; ++i) {
        double x, y;
        cin >> x >> y;
        engines[i] = {x, y};
    }
    sort(engines.begin(), engines.end());
    double ret = 0;
    for (int i = 0; i < n; ++i) {
        double xx = 0, yy = 0;
        for (int j = 0; j < n; ++j) {
            xx += engines[(i + j) % n].x;
            yy += engines[(i + j) % n].y;
            chmax(ret, xx * xx + yy * yy);
        }
    }
    cout << fixed << setprecision(15) << sqrt(ret) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#define N 5000
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL dp[N+2][N+2];
LL solve()
{
	int K; cin >> K;
	
	string s; cin >> s; 
	int n = s.length();
	
	memset(dp,0,sizeof dp);
	dp[0][0] = 1;
	for(int k = 1; k <= K; k++)
		for(int x = 0; x <= k; x++)
			if(x==0)
				dp[x][k] = (dp[x][k-1]+2*dp[x+1][k-1])%MOD;
			else
				dp[x][k] = (dp[x-1][k-1]+2*dp[x+1][k-1])%MOD;
			
	return dp[n][K];
}
int main()
{
	cout<<solve()<<endl;
	return 0;
}


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


int main(void){
        
    int a[16];
    string s;
    cin >> s;
    int n = s.size();
    int64_t bin = ((int64_t)1) << (n-1);
    int64_t sum = 0;
    int64_t temp = 0;
    
    for(int i = 0 ; i < s.size() ; i++ )
        a[i] = ((int)s[i]) - ((int)'0');
        
    for(int16_t i = 0 ; i < bin ; i++ ){
        temp = a[0];
        for(int j = 1 ; j < n  ; j++ ){
            int64_t and_val = ((int64_t)1)<<(j-1);
            
            if( (i & and_val) == 0 ){
                sum += temp;
                temp = a[j];
            }else{
                temp = temp * 10 + a[j];
            }
        }
        
        sum += temp;
    }
    
    printf("%lld\n",sum);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int n, h, w;
	cin >> n >> h >> w;

	int ans = 0;
	rep(i, n){
		int a, b;
		cin >> a >> b;
		if(a >= h && b >= w) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> P;
vector<int> v;
string s[8];
string cp[8];
int res[8][8];
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
void bancp()
{
	for(int i=0;i<8;i++)
	{
		cp[i]=s[i];
	}
	return;
}

int check2(int x,int y)
{
	int ret=0;
	char jiban=s[x][y];
	char taban;
	if(jiban=='x')
		taban='o';
	else
		taban='x';
	//上下左右斜め順番に調べる
	for(int i=0;i<8;i++)
	{
		int nx=x;
		int ny=y;
		int cnt=0;
		while(1)
		{
			nx+=dx[i];
			ny+=dy[i];
			if(nx>=0 && nx<8 && ny>=0 && ny<8)
			{
				if(s[nx][ny]!=taban)
					break;
				cnt++;
			}else{
				break;
			}
		}
		if(nx>=0 && nx<8 && ny>=0 && ny<8)
		{
			if(s[nx][ny]==jiban)
			{
				nx=x;ny=y;
				for(int j=0;j<cnt+2;j++)
				{
					s[nx][ny]=jiban;
					nx+=dx[i];
					ny+=dy[i];
				}
				ret+=cnt;
			}
		}
	}
	return ret;
}
int check(int x,int y)
{
	int ret=0;
	char jiban=cp[x][y];
	char taban;
	if(jiban=='x')
		taban='o';
	else
		taban='x';
	//上下左右斜め順番に調べる
	for(int i=0;i<8;i++)
	{
		int nx=x;
		int ny=y;
		int cnt=0;
		while(1)
		{
			nx+=dx[i];
			ny+=dy[i];
			if(nx>=0 && nx<8 && ny>=0 && ny<8)
			{
				if(cp[nx][ny]!=taban)
					break;
				cnt++;
			}else{
				break;
			}
		}
		if(nx>=0 && nx<8 && ny>=0 && ny<8)
		{
			if(cp[nx][ny]==jiban)
			{
				nx=x;ny=y;
				for(int j=0;j<cnt+2;j++)
				{
					cp[nx][ny]=jiban;
					nx+=dx[i];
					ny+=dy[i];
				}
				ret+=cnt;
			}
		}
	}
	return ret;
}

P senteAI()
{
	v.clear();
	fill(res[0],res[8],-1);
	//すべての場所に置く
	for(int i=0;i<8;i++)
	{
		for(int j=0;j<8;j++)
		{
			if(s[i][j]!='.')
				continue;
			bancp();
			cp[i][j]='o';
			//置いた場所から消せるマスを調べて消す
			int cnt=check(i,j);
			//cerr<<cnt<<endl;
			if(cnt>0)
			{
				v.push_back(cnt);
				res[i][j]=cnt;
			}
		}
	}
	//cerr<<v.size()<<endl;
	if(v.size()==0)
		return P(-1,-1);
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for(int i=0;i<8;i++)
	{
		for(int j=0;j<8;j++)
		{
			if(res[i][j]==v[0])
				return P(i,j);
		}
	}
	return P(-10,-10);
}

P goteAI()
{
	v.clear();
	fill(res[0],res[8],-1);
	//すべての場所に置く
	for(int i=0;i<8;i++)
	{
		for(int j=0;j<8;j++)
		{
			if(s[i][j]!='.')
				continue;
			bancp();
			cp[i][j]='x';
			//置いた場所から消せるマスを調べて消す
			int cnt=check(i,j);
			if(cnt>0)
			{
				v.push_back(cnt);
				res[i][j]=cnt;
			}
		}
	}
	if(v.size()==0)
		return P(-1,-1);
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for(int i=7;i>=0;i--)
	{
		for(int j=7;j>=0;j--)
		{
			if(res[i][j]==v[0])
				return P(i,j);
		}
	}
	return P(-10,-10);
}

int main()
{
	for(int i=0;i<8;i++)
		cin>>s[i];
	P p;
	bool f[2]={true,true};
	while(1)
	{
		//cerr<<"sente"<<endl;
		//先手番
		f[0]=false;
		p=senteAI();
		//cerr<<p.first<<" "<<p.second<<endl;
		if(p>P(-1,-1))
		{
			f[0]=true;
			s[p.first][p.second]='o';
			check2(p.first,p.second);
		}
		if(!(f[0] || f[1]))
			break;
		f[1]=false;
		//cerr<<"gote"<<endl;
		p=goteAI();
		if(p>P(-1,-1))
		{
			f[1]=true;
			s[p.first][p.second]='x';
			check2(p.first,p.second);
		}
		if(!(f[0] || f[1]))
			break;
	}
	for(int i=0;i<8;i++)
		cout<<s[i]<<endl;
	return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
constexpr int MOD = 1'000'000'007;

// https://github.com/ei1333/library/blob/master/math/combinatorics/arbitrary-mod-int.cpp
template <int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            std::swap(a -= t * b, b);
            std::swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend std::ostream &operator<<(std::ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend std::istream &operator>>(std::istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

int main() {
    using std::cin;
    using std::cout;
    using std::endl;
    using modint = ModInt<MOD>;

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

    modint ans = 0, N = n, t = 2, o = 1;
    modint sumn2 = (N + o) * (N + t) / t;
    for (int i = k; i <= n + 1; ++i) {
        modint ki     = i;
        modint sumnnk = (N - ki + o) * (N - ki + t) / t;
        modint sumk   = ki * (ki + o) / t;
        ans += sumn2 - sumnnk - sumk + o;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ld t[3005];
int main(){
	ll n, l; cin >> n >> l;
	for (ll i = 0; i < n; i++) cin >> t[i];
	ld x = 0, y = 0;
	for (ll i = 0; i < n; i++){
		for (ll j = i + 1; j < n; j++){
			ll arc = j - i - 1;
			ld ang = PI * (t[i] + t[j]) / l;
			x += cos(ang) * (n - 2 * arc - 2);
			y += sin(ang) * (n - 2 * arc - 2);
		}
	} 
	x /= n * (n - 1) * (n - 2) / 6;
	y /= n * (n - 1) * (n - 2) / 6;
	cout << fixed << setprecision(12);
	cout << x << " " << y << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<char> s(n);
  bool a = false;
  for(int i=0; i<n; i++) {
    cin >> s.at(i);
    if(s.at(i) == 'Y') {
      a = true;
      break;
    }
  }
  
  if(a) cout << "Four" << endl;
  else  cout << "Three" << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
    int n,m;
    int i,j,k;
    LL a,b,c;
    LL s=0,s2=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a;
        s+=a,s2+=a*a%MAX;
    }
    s%=MAX,s2%=MAX;
    s=s*s-s2;
    if(s<0)s+=MAX;
    if(s%2==1)s+=MAX;
    s/=2;
    cout<<s%MAX<<endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N, M;
    int S;
    cin >> N >> M >> S;
    S = min(2500, S);
    vector<vector<tuple<int, int, ll>>> edge(N);
    REP(i, M) {
        int u, v, a;
        ll b;
        cin >> u >> v >> a >> b;
        --u;
        --v;
        edge[u].emplace_back(v, a, b);
        edge[v].emplace_back(u, a, b);
    }
    vector<ll> C(N), D(N);
    REP(i, N) { cin >> C[i] >> D[i]; }

    using T = tuple<ll, int, int>;
    priority_queue<T, vector<T>, greater<T>> pq;
    pq.emplace(0, 0, S);
    vector<vector<ll>> t(N, vector<ll>(2501, (ll)1e18));
    t[0][S] = 0;
    vector<int> checked(N);
    int ch = 0;
    while (!pq.empty()) {
        ll x;
        int i, s;
        tie(x, i, s) = pq.top();
        pq.pop();
        if (!checked[i]) {
            checked[i] = true;
            ++ch;
        }
        if (ch == N) break;
        for (auto &tup : edge[i]) {
            int j, a;
            ll b;
            tie(j, a, b) = tup;
            if (s >= a && x + b < t[j][s - a]) {
                t[j][s - a] = x + b;
                pq.emplace(x + b, j, s - a);
            }
        }
        while (s < 2500) {
            s = (s + C[i] < 2500) ? s + C[i] : 2500;
            x += D[i];
            if (x < t[i][s]) {
                t[i][s] = x;
                pq.emplace(x, i, s);
            } else {
                break;
            }
        }
    }
    FOR(i, 1, N) {
        ll res = (ll)1e18;
        REP(j, 2501) { res = min(res, t[i][j]); }
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 11696
n, m, x = gets.split.map(&:to_i)
pri = []
ary = []
n.times do
  t = gets.split.map(&:to_i)
  pri << t[0]
  ary << t[1..m]
end
lis = []
[1,0].repeated_permutation(n) do |i|
  num = 0
  ans = Array.new(m,0)
  i.each_with_index do |k, l|
    if k == 1
      num+=pri[l]
      ans = [ans, ary[l]].transpose.map{|a| a.inject(:+) }
    end
  end
  lis << num if ans.all? { |a| a >= x }
end
puts lis.empty? ? "-1" : lis.min


Measured memory_bytes: 14260
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long int
#define P pair<ll, ll>
#define vii vector<P>
#define vvi vector<vector<ll>>
#define P_B push_back

#define MOD 1000000007
#define pi 3.141592653589793238


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

	// ll T; cin>>T; while(T--) 
	{
		
		ll n, w;
		cin>>n>>w;

		vector<ll> wt(n), value(n);
		for (int i = 0; i < n; i++) {
			cin>>wt[i] >> value[i];
		}

		ll total_value = 0;

		for (int i = 0; i < n; i++) {
			total_value += value[i];
		}

		vector<ll> DP(total_value + 1, INT_MAX);
		ll answer = 0;

		DP[0] = 0;

		for (ll i = 0; i < n; i++) {
			for (ll cur_val = total_value; cur_val >= 0; cur_val--) {

				if(value[i] > cur_val) continue;

				DP[cur_val] = min(DP[cur_val], DP[cur_val - value[i]] + wt[i]); 

				if(DP[cur_val] <= w) answer = max(answer, cur_val);
			}
		}

		cout<<answer;
		
	}	
	return 0;
}   

Measured memory_bytes: 3976
#include <stdio.h>
#include <math.h>

double length(double px1, double py1, double px2, double py2)
{
	return sqrt(pow(px1 - px2, 2) + pow(py1 - py2, 2));
}

double helon(double a, double b, double c)
{
	double s = (a + b + c) / 2;

	return sqrt(s * (s - a) * (s - b) * (s - c));
}

int main()
{
	double x1, y1, x2, y2, x3, y3, px, py;
	double a, b, c;
	double a1, b1, c1;

	while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &px, &py) != EOF) {
		a = length(x1, y1, x2, y2);
		b = length(x2, y2, x3, y3);
		c = length(x3, y3, x1, y1);

		a1 = length(x1, y1, px, py);
		b1 = length(x2, y2, px, py);
		c1 = length(x3, y3, px, py);
//		printf("%.3f %.3f\n", helon(a1, b1, a) + helon(a1, c1, c) + helon(b1, c1, b) , helon(a, b, c));
		if (fabs(helon(a1, b1, a) + helon(a1, c1, c) + helon(b1, c1, b) - helon(a, b, c)) < 0.0001) {
			puts("YES");
		} else {
			puts("NO");
		}
	}
	return 0;
}

Measured memory_bytes: 0
N=int(input())
A=list(map(int,input().split()))
B=[0] * N
ans = []
for i in reversed(range(1, N+1)):
    a = 0
    for j in range(1, N+1):
        tmp = i * j
        if tmp > N:
            break
        a = (B[tmp-1] + a) % 2
    if (A[i-1] + a) % 2 == 1:
        ans.append(i)
    B[i-1] = (A[i-1] + a) % 2
print(len(ans))
for a in ans: print(a)

Measured memory_bytes: 12088
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------




int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    int ans = min(abs(A[0]-0),abs(A[K-1]-0)) + abs(A[K-1]-A[0]);
    for(int i=K; i<N; i++){
        chmin(ans,min(abs(A[i]-0),abs(A[i-K+1]-0))+A[i]-A[i-K+1]);
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;
#define ll long long
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int inf = 5000000 + 7;
const ll linf  = 1ll * inf * inf;
const int N = 100000 + 7;
const int M = 10000 + 7;
const int multipleTest = 0;
const double pi = acos(-1);

int n;
int a[N];
int b[N];
vector<int> uniq;

class FenWickTree{
public:
	static const int MAXN = 200000 + 7;
	static const int MID = MAXN / 2;
	int L[MAXN];
	
	void update(int x, int val) {
		x += MID;
		for (int t = x; t < MAXN; t += t & -t) L[t] += val;
	}
	
	int get(int x) {
		x += MID;
		int res = 0;
		for (int t = x; t > 0; t -= t & -t) {
			res += L[t];
		}
		return res;
	}
} fenwickTree;


ll check(int x) {
	for (int i = 0; i < n; ++i) b[i] = (a[i] >= x) ? 1 : -1;
	for (int i = 1; i < n; ++i) b[i] += b[i - 1];
	
	fenwickTree.update(0, 1);
	ll cnt = 0;
	for (int i = 0; i < n; ++i) {
		cnt += fenwickTree.get(-b[i] - 1);
		fenwickTree.update(-b[i], 1);
	}
	
	fenwickTree.update(0, -1);
	for (int i = 0; i < n; ++i) fenwickTree.update(-b[i], -1);
	
	return cnt;
}

void solve() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		scanf("%d", a + i);
	}
	set<int> s(a, a + n);
	uniq.assign(s.begin(), s.end());
	
	int lo = 0, hi = uniq.size() - 1, res = uniq[0];
	const ll M = 1ll * n * (n + 1) / 2;
	const ll cnt = M / 2 + 1;
	
	while (lo <= hi) {
		int mid = (lo + hi) >> 1;
		if (check(uniq[mid]) < cnt) {
			res = uniq[mid];
			lo = mid + 1;
		} else hi = mid - 1;
	}
	
	cout << res << '\n';
}

int main() {
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin);
	//	freopen("out.txt", "w", stdout);
#endif
	int Test = 1;
	if (multipleTest) {
		cin >> Test;
	}
	
	for(int i = 0; i < Test; ++i) {
		//		printf("Case #%d: ", i + 1);
		solve();
	}
#ifdef _LOCAL_
	cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repi(i, a, b) for(int i=(a); i>(b); i--)
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define iceil(n, x) ((n + x - 1) / x)
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue
#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld", &a)
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
#define MOD 1000000007
#define N 100005
#define M 105
using namespace std;

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;

//All indexing is 0-based
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
			 tree_order_statistics_node_update> ordered_set;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar.

int a[105];

main()
{	
	#ifdef CP
		freopen("/home/tarun/Desktop/input.txt", "r", stdin);
		//freopen("/home/tarun/Desktop/output.txt", "w", stdout);
	#endif
	sync;
	clock_t clk = clock();
	cerr << "I will return...\n";
	
	vi m4, m7;
	int i = 0;
	while(i * 4 <= 100) {
		m4.pb(i * 4);
		i++;
	}

	i = 0;
	while(i * 7 <= 100) {
		m7.pb(i * 7);
		i++;
	}

	set<int> s;
	for(int i : m4) s.insert(i);
	for(int i : m7) s.insert(i);

	rep(i, 0, m4.sz) {
		rep(j, 0, m7.sz) {
			if(m4[i] + m7[j] <= 100) {
				s.insert(m4[i] + m7[j]);
			}
		}
	}
	s.erase(0);
	int n; cin >> n;
	cout << (s.find(n) == s.end() ? "No": "Yes");

	cerr << "...don't you ever hang your head.\n";
	cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << '\n';
}

//Compile using:
//g++ -o filename.exe --std=c++11 filename.cpp
//Use -D CP for defining a macro CP in the local environment






Measured memory_bytes: 256
//
//  supercon.cpp
//
//
//  Created by Fourier Shuzaei on 2018/06/02.
//

#include "bits/stdc++.h"
using namespace std;
#define ri(a,b,c) for(int a=(b);a<(c);++a)
#define ll long long
#define rll(a,b,c) for(ll a=(b);a<(c);++a)

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

    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
    cin>>a;
  i=0;
  b=1;
  while(a/b){
    i+=(a/b)%10;
    b*=10;
  }















    cout<<((a%i)?"No":"Yes")<<"\n";
}



Measured memory_bytes: 256