akhauriyash/Code-Regression huggingface dataset:
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = LLONG_MAX, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
    cin >> N >> K;
    rep(i, N){
        cin >> A;
    }
    if(N == K) cout << 1;
    else cout << ((N-K-1)/(K-1)+1)+1;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int ans=0;
	for(int i=0; i<s.length(); i++){
		if(i%2==0 && s[i]=='p') ans--;
		if(i%2==1 && s[i]=='g') ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
// https://atcoder.jp/contests/abc126/tasks/abc126_c

#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

int main()
{
  int N, K, mm = 0;
  vector<int> a(18, 0);
  ll win = 0;

  cin >> N >> K;

  FOR(i, 1, N + 1)
  {
    int index = K <= i ? 0 : ceil(log2((double)K / i));
    mm = max(mm, index);
    a[index]++;
  }

  REP(i, mm + 1)
  {
    win *= 2;
    if (0 < a[i])
      win += a[i];
  }

  printf("%.12f\n",win * pow(2, -1 * mm) / N);

  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		new Main().run();
	}

	private void run() throws NumberFormatException, IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++) {
			nodes[i] = new Node();
		}
		for (int i = 0; i < n; i++) {
			int v = scanner.nextInt();
			int l = scanner.nextInt();
			int r = scanner.nextInt();
			nodes[v].l = l;
			nodes[v].r = r;
			if (l != -1)
				nodes[l].p = v;
			if (r != -1)
				nodes[r].p = v;
		}

		int root = 0;
		for (int i = 0; i < n; i++) {
			if (nodes[i].p == -1) {
				root = i;
			}
		}
		System.out.println("Preorder");
		preParse(root, nodes);
		System.out.println();
		System.out.println("Inorder");
		inParse(root, nodes);
		System.out.println();
		System.out.println("Postorder");
		postParse(root, nodes);
		System.out.println();
	}

	private void postParse(int u, Node[] nodes) {
		if (u == -1)
			return;
		postParse(nodes[u].l, nodes);
		postParse(nodes[u].r, nodes);
		System.out.print(" " + u);
	}

	private void inParse(int u, Node[] nodes) {
		Deque<Integer> deque = new ArrayDeque<Integer>();
		deque.push(u);
		boolean[] b = new boolean[nodes.length];
		while (!deque.isEmpty()) {
			u = deque.peek();
			int l = nodes[u].l;
			if (l != -1 && !b[l]) {
				deque.push(l);
				continue;
			}
			deque.poll();
			b[u] = true;
			System.out.print(" " + u);
			int r = nodes[u].r;
			if (r != -1 && !b[r]) {
				deque.push(r);
			}

		}
	}

	private void preParse(int u, Node[] nodes) {
		Deque<Integer> deque = new ArrayDeque<Integer>();
		deque.push(u);
		while (!deque.isEmpty()) {
			u = deque.poll();
			System.out.print(" " + u);
			if (nodes[u].r != -1)
				deque.push(nodes[u].r);
			if (nodes[u].l != -1)
				deque.push(nodes[u].l);
		}

	}

	class Node {
		int p = -1, l, r;
	}
}

Measured memory_bytes: 18244
//“ In order to be irreplaceable, one must always be different”
#include <bits/stdc++.h>
using namespace std;
# define ll long long
#define endl "\n"
# define pi 3.14159265359
#define MOD 1000000007
# define str string
# define vll vector<ll>
# define vstr vector<str>
# define vchar vector<char>
# define pb push_back
# define mll map<ll,ll>
#define mchar map<char, ll>
# define mstr map<str,ll>
# define vp vector< pair<ll,ll> >
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
# define r(x,y) for(int x=y;x>=0;x--)
# define loop(x,y,z) for(int x=y;x<z;x++)
ll power(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll gcd(ll a, ll b){
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a/gcd(a, b))*b;
}
void print(vll a){
    for(int i=0;i<a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll a[5];
    f(i,5){
        cin>>a[i];
    }
    f(i,5){
        if(a[i]==0){
            cout<<i+1;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    VI masu(n,0);
    VI ans(n,0);
    rep(i,n) cin >> masu[i];
    rep(i,n - 1){
        if(masu[i] >= masu[i+1]){
            ans[i]++;
        }
    }
    int an = 0;
    int ma = 0;
    rep(i,n-1){
        if(ans[i] == 1){
            an += ans[i];
            ma = max(ma,an);
        }else{
            ma = max(ma,an);
            an = 0;
        }
    }
    cout << ma <<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int max_A = 0; // Aの最大値
  int sec_A = 0; // Aの2番目に大きい値
  int i_max = -1; // Aを最大にするi
  
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (max_A <= A[i]) {
      sec_A = max_A;
      max_A = A[i];
      i_max = i;
    } else if (sec_A <= A[i]) {
      sec_A = A[i];
    }
  }
  
  for (int i = 0; i < N; i++) {
    if (i != i_max) cout << max_A << endl;
    else cout << sec_A << endl;
  }
}

Measured memory_bytes: 2432
#! python3

moji_S=input()
moji_T=input()

flag=0
for i in range(len(moji_S)):
	if moji_S==moji_T:
		flag =1
		break
	moji_S=moji_S[-1]+moji_S[0:-1]
if flag:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var N, ans int
	fmt.Scan(&N)
	for i := 1; i <= N; i++ {
		if len(strconv.Itoa(i))%2 == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextSlice() []string {
	sc.Scan()
	return strings.Split(sc.Text(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func scanSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func scanFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

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

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func larger(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func largest(a, b, c int) (lgst int) {
	if a > b {
		lgst = a
	} else {
		lgst = b
	}
	if c > lgst {
		lgst = c
	}
	return
}

func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func smallest(a, b, c int) (slst int) {
	if a < b {
		slst = a
	} else {
		slst = b
	}
	if c < slst {
		slst = c
	}
	return
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

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

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    int p[n+1];
    for(int i=1;i<=n;i++){
        int a; cin >> a;
        p[a] = i;
    }
    set<int> st;
    st.insert(0);
    st.insert(n + 1);
    ll res = 0;
    for(int a=1;a<=n;a++){
        ll idx = p[a];
        st.insert(idx);
        auto iter = st.find(idx);
        iter--;
        ll left = *(iter) + 1;
        iter++; iter++;
        ll right = *(iter) - 1;
        res += (idx - left + 1) * (right - idx + 1) * a;
    }
    cout << res << endl;
}

Measured memory_bytes: 10368
# coding: utf-8

str = input()
table = list(str)
count = 0
for i in range(len(table)):
    if i % 2 == 0:
      if table[i] == 'R' or table[i] == 'U' or table[i] == 'D':
         count += 1
    elif i % 2 == 1:
      if table[i] == 'L' or table[i] == 'U' or table[i] == 'D':
         count += 1

if count == len(str):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9092
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {
	
	int M;
	scanf("%d", &M);
	printf("%d", 48 - M);



}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int maxnum = max({a, b, c});
    int ans = maxnum*10 + a + b + c - maxnum;
    cout << ans << endl;
    return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }


int main() {
  int n;
  while (cin >> n) {
    cout << 3 * n * n << endl;
  }
}


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

int main(){
	int n,a[100000];
	bool used[100000] = {};
	cin >> n;
	for(int i = 0;i < n;i++) {
		cin >> a[i];
		a[i]--;
	}
	int pos = 0;
	for(int i = 0;!used[pos];i++){
		if(pos == 1){
			cout << i << endl;
			return 0;
		}
		used[pos] = true;
		pos = a[pos];
	}
	cout << -1 << endl;
}

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

int main(){
    using namespace std;
    unsigned long K;
    cin >> K;
    cout << vector<unsigned long>{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}[K - 1] << endl;
    return 0;
}

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

using namespace std;
int main(){
	while(1){
	bool flag = false;
	int n, m ,count, max=0;
	int a[10000]; 
	cin >>n>> m;
	if(n==0 && m==0){
		break;
	}
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			count = a[i] + a[j];
			if(count<=m){
				if(max<count){
				max = count;	
				}
				break;
			}
			
		}
	}
	if(max == 0){
		cout << "NONE" << endl;
	}
	else{
		cout << max << endl;
	}
	
	}
}



Measured memory_bytes: 3108
#include <stdio.h>

int main() {
	int a, b, c, max;

	scanf("%d%d%d", &a, &b, &c);
	max = a;
	if (max < b)
		max = b;
	if (max < c)
		max = c;
	printf(a + b + c - max == max ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    V<string> s(n);
    vll p(n);
    REP(i, n) cin >> s[i] >> p[i];
    vll ord(n); iota(ALL(ord), 0LL);
    sort(ALL(ord), [&](ll x, ll y) {
        if (s[x] == s[y]) return p[x] > p[y];
        else return s[x] < s[y];
    });
    REP(i, n) cout << ord[i]+1 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  std::string S;
  std::cin >> S;

  std::string judge = "No";
  if (S.find("A") != std::string::npos && S.find("B") != std::string::npos) {
    judge = "Yes";
  }

  print(judge);
  return 0;
}


Measured memory_bytes: 256
def examA():
    N = I()
    ans = N*800-(N//15)*200
    print(ans)



import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()


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

int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  vector<int> Q(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  for (int i = 0; i < N; i++) cin >> Q.at(i);
  vector<int> A(N);
  for (int i = 0; i < N; i++) A.at(i) = i + 1;
  int cnt = 1, Pn, Qn;
  do{
    if (A == P) Pn = cnt;
    if (A == Q) Qn = cnt;
    cnt++;
   }while(next_permutation(A.begin(), A.end()));
  cout << abs(Pn - Qn) << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>

int main()
{
  int h,w,i,j,hw,ij,mini1,minj1;

  while(1){
    scanf("%d%d",&h,&w);
    if(h==0 &&w==0)break;

    hw=h*h+w*w;
    mini1=150;
    minj1=150;
    for(i=1;i<150;i++){
      for(j=i+1;j<150;j++){
	ij=i*i+j*j;
        if((hw<ij||((ij==hw) &&h<i)) && mini1*mini1+minj1*minj1>ij){
          mini1=i;
          minj1=j;
	  // printf("%d %d\n",mini1,minj1);
	}
      }
    }
    printf("%d %d\n",mini1,minj1);
  }
  return 0;
}


Measured memory_bytes: 2104
N,M,S=map(int,input().split())
UVAB=[list(map(int,input().split())) for i in range(M)]
C,D=zip(*[list(map(int,input().split())) for i in range(N)])
c=[[] for i in range(N)]
A=[[] for i in range(N)]
B=[[] for i in range(N)]
for u,v,a,b in UVAB:
    c[u-1].append(v-1)
    c[v-1].append(u-1)
    A[u-1].append(a)
    A[v-1].append(a)
    B[u-1].append(b)
    B[v-1].append(b)
inf=10**20
from heapq import heappop,heappush
X=50*(N-1)
def dij(p,s):
    d=[[inf]*(X+1) for i in range(N)]
    d[p][s]=0
    q=[]
    heappush(q,(0,(p,s)))
    while q:
        t,(p,s)=heappop(q)
        for i in range(1,(X+1-s)//C[p]):
            if X<s+i*C[p] or d[p][s+i*C[p]]<=d[p][s]+i*D[p]:break
            d[p][s+i*C[p]]=d[p][s]+i*D[p]
            heappush(q,(d[p][s]+i*D[p],(p,s+i*C[p])))
        for j,n in enumerate(c[p]):
            if 0<=s-A[p][j] and d[n][s-A[p][j]]>d[p][s]+B[p][j]:
                d[n][s-A[p][j]]=d[p][s]+B[p][j]
                heappush(q,(d[n][s-A[p][j]],(n,s-A[p][j])))
    return d
d=dij(0,min(S,X))
print(*[min(x) for x in d[1:]],sep='\n')

Measured memory_bytes: 117064
from collections import deque

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

b = deque()
for i in range(n):
    if (n % 2 == 0 and (i+1) % 2 == 0) or (n % 2 != 0 and (i+1) % 2 != 0):
        b.appendleft(l[i])
    else:
        b.append(l[i])

print(' '.join(map(str, b)))

Measured memory_bytes: 29240
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;

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

	int n,m;
	cin>>n>>m;
	string a="",b="";
	for(int i=0;i<n;i++)
	{
		a+=m+'0';
	}	
	for(int i=0;i<m;i++)
	{
		b+=n+'0';
	}	
	cout<<min(a,b);
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")


int main()
{int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vecl(AA); vecl(BB); vecl(CC);

	fx(A) {
		vecpl(AA)
	}
	fx(B) {
		vecpl(BB)
	}
	fx(C) {
		vecpl(CC)
	}
	sorts(AA); sorts(BB); sorts(CC);
	reverses(AA); reverses(BB);
	ll ans = 0;
	fx(X) {
		ans += AA[x];
	}
	fx(Y) {
		ans += BB[x];
	}
	reverses(CC);

	int x = X-1, y = Y-1;
	fz(C) {
		if (x<0) {
			if (y >=0 && CC[z] >= BB[y]) {
				ans += CC[z] - BB[y];
				y--;
			}
		}
		else if (y<0) {
			if (x >= 0&& CC[z] >= AA[x] ) {
				ans += CC[z] - AA[x] ;
				x--;
			}
		}
		else {
			if (BB[y] > AA[x] ) {
				if (x >=0 && CC[z] >= AA[x] ) {
					ans += CC[z] - AA[x];
					x--;
				}
			}
			else {
				if (y >=0 && CC[z] >= BB[y] ) {
					ans += CC[z] - BB[y] ;
					y--;
				}
			}
		}
	}
	ce(ans)

    return 0;
}



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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

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

int n,a[100001];

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

	cin>>n;
	FOR(i,1,n+1) {
		cin>>a[i];
	}
	int cnt=0;
	FOR(i,1,n+1) {
		if(a[a[i]]==i) cnt++;
	}
	cout<<cnt/2<<endl;

	return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    char c;
    while (cin >> c) {
        if (c == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N), D(N);
  for (auto &e : A) cin >> e;
  for (auto &e : B) cin >> e;
  ll del = 0;
  bool b = true;
  for (ll i = 0; i < N; i++) {
    D[i] = B[i]-A[i];
     if (D[i] != 0) b = false;
    del += D[i];
  }
  if (b) cout << "Yes" << endl;
  else if (del < 0) cout << "No" << endl;
  else {
    sort(D.begin(),D.end(),greater<ll>());
    ll L = 0, R = N-1;
    while (L < R) {
      if (D[L] == 1) {
        del -= 1;
        D[L] = 0;
        L++;
      }
      else if ((D[L]+1)/2 > D[R]*(-1)) {
        del += D[R];
        D[L] += 2*D[R];
        D[R] = 0;
        R--;
      }
      else {
        del -= D[L]/2;
        D[R] += D[L]/2;
        D[L] = D[L]%2;
        if (D[R] == 0) R--;
        if (D[L] == 0) L++;
      }
      if (del < 0) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n % 1000 == 0) cout << 0 << endl;
    else cout << n / 1000 * 1000 + 1000 - n << endl;
    return 0;
}


Measured memory_bytes: 3636
dxdy = ((0,1),(0,-1),(1,0),(-1,0))

H, W = map(int,input().split())
S = []

S.append('.'*(W+2))
for h in range(H):
    s = input()
    S.append('.'+s+'.')
S.append('.'*(W+2))

#print (S)

for h in range(1,H+1):
    for w in range(1,W+1):
        if S[h][w] == '.':
            continue
        ok = False
        for dx,dy in dxdy:
            if S[h+dx][w+dy] == '#':
                ok = True
                break
        if ok == False:
            print ('No')
            exit()
print ('Yes')



Measured memory_bytes: 9196
#include<stdio.h>
#include<stdlib.h>

#define N 100000

/*?????????????????????*/
typedef struct {
  int  parent;
  int  left;
  int  right;
}NODE;
  
NODE T[N];


int calc_depth(int);
int degree(int); //?¬???°
 
main(){
  int i,j,child,n,id,k,l;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      T[i].parent = -1;
      T[i].left = -1;
      T[i].right = -1;
    } //??????
  
  for(i = 0; i < n; i++)
    {
      scanf("%d%d",&id, &k);
      
      for(j = 0; j < k; j++){
	scanf("%d", &child);
	T[child].parent = id;
	if(j == 0){
	  T[id].left = child;
	}
	else{
	  T[l].right = child;
	}
	l = child;
       
      }
    }
  
  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, calc_depth(i));
    
    if(T[i].parent == -1){
      printf("root, [");
    }
    
    else if(T[i].left == -1){
      printf("leaf, [");
    }
    
    else{
      printf("internal node, [");
    }
    
    degree(T[i].left);
    printf("]\n");
  }
  
  return 0;
}



int calc_depth(int i){
  int c = 0;
  if(T[i].parent == -1)
    {
      return 0;
    }
  else {
    c = calc_depth(T[i].parent) + 1;
    return c;
  }
}
  
int degree(int a){
  if(a == -1){
    return 0;
  }
  else {
    if(T[a].right == -1){
      printf("%d",a); 
    }
    else{
      printf("%d, ",a);
      degree(T[a].right);
    }
  }
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
const int p2=1<<17;
ll gcd(ll x,ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x/gcd(x,y)*y;
}
ll mod=1e9+7;
ll g[p2*2],s[p2*2];
int p[100000],ord[100000];
ll sum(int a,int b,int l,int r,int k,ll T){
	if(b<=l||r<=a) return 0;
	if(a<=l&&r<=b) return s[k]*(T/g[k]%mod)%mod;
	return ( sum(a,b,l,(l+r)/2,k*2,T)+sum(a,b,(l+r)/2,r,k*2+1,T) )%mod;
}
ll getg(int a,int b,int l,int r,int k){
	if(b<=l||r<=a) return 1;
	if(a<=l&&r<=b) return g[k];
	return lcm(getg(a,b,l,(l+r)/2,k*2),getg(a,b,(l+r)/2,r,k*2+1));
}
int main(){
	int N,Q;
	cin>>N>>Q;
	rep(i,N) cin>>p[i],p[i]--;
	rep(i,N){
		if(ord[i]==0){
			int x=i,o=0;
			ll sum=0;
			while(true){
				x=p[x],o++;
				sum+=x+1;
				if(x==i) break;
			}
			sum%=mod;
			while(true){
				x=p[x];
				ord[x]=o;
				s[p2+x]=sum;
				if(x==i) break;
			}
		}
		g[p2+i]=ord[i];
	}
	for(int i=N;i<p2;i++) g[p2+i]=1;
	for(int i=p2-1;i>=1;i--){
		g[i]=lcm(g[i*2],g[i*2+1]);
		s[i]=(g[i]/g[i*2])%mod*s[i*2]+(g[i]/g[i*2+1])%mod*s[i*2+1];
		s[i]%=mod;
	}
	rep(tt,Q){
		int l,r;
		cin>>l>>r;
		l--;
		ll T=getg(l,r,0,p2,1);
		cout<<sum(l,r,0,p2,1,T)<<endl;
	}
}

Measured memory_bytes: 6036
import math

a,b,h,m = map(int,input().split())

hangle = float((h/12)*360)
hangle += float((m/60)*30)
mangle = float((m/60)*360)

if hangle > 180 and mangle > 180:
    angle = abs(hangle-mangle)
elif hangle > 180:
    hangle = 360 - hangle
    angle = abs(hangle+mangle)
elif mangle > 180:
    mangle = 360 - mangle
    angle = abs(hangle+mangle)
else:
    angle = abs(hangle-mangle)

rad = math.radians(angle)

ans = float(math.sqrt(a*a + b*b - float(2*a*b*math.cos(rad))))
print('{:.10f}'.format(ans))


Measured memory_bytes: 9476
from collections import deque

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

d = deque()

for i in range(n):
    if i % 2 == 0:
        d.append(a_s[i])
    else:
        d.appendleft(a_s[i])

if n%2==1:
    d.reverse()

print(' '.join(map(str, d)))


Measured memory_bytes: 36292
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
int n, k;
int a[200001], cur;

bool valid(int g){
	int cnt = 0;
	for(int i = 1; i<=n; i++){
		cnt += a[i]/g;
		//cout << cnt << endl;
		if(a[i]%g == 0)cnt--;
	}
	return cnt<=k;
}

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

	cin >> n >> k;
	for(int i = 1; i<=n; i++)
		cin >> a[i];

	int l = 1, r = 1e9, mid;
	while(l < r){
		mid = (l + r)/2;
		if(valid(mid)) r = mid;
		else l = mid+1;
	}

	//cout << valid(4) << endl;

	cout << l << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 4408
s = input()
t = input()
ls = len(s)
lt = len(t)

ans = 0
for i in range(ls-lt+1):
  same = 0
  for j in range(lt):
    ind = i+j
    if s[ind]==t[j]:
      same += 1
  ans = max(ans,same)
print(lt-ans)


Measured memory_bytes: 8976
import sys
from collections import deque
import copy
import math
import numpy as np

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def divisor_sub(p, q):
    a = []
    for i in xrange(0, q + 1):
        a.append(p ** i)
    return a

def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n /= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff

def divisor(n):
    xs = factorization(n)
    ys = divisor_sub(xs[0][0], xs[0][1])
    for p, q in xs[1:]:
        ys = [x * y for x in divisor_sub(p, q) for y in ys]
    return sorted(ys)

def is_prime(x):
    if x < 2: return False
    if x == 2 or x == 3 or x == 5: return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    if N == 1:
        print M
        exit()
    if is_prime(M):
        print 1
        exit()
##    div_list = divisor(M)
##    div_list.sort(reverse = True)
##
##    for num in div_list:
##        if M % num == 0 and M/num >= N:
##            print num
##            exit()

    max_p = 0
    for p in range(int(math.sqrt(M) + 0.5) , 0, -1):

        if(M % p == 0):
            q = M/p
            if q >= N:
                max_p = max(p, max_p)
            if p >= N:
                max_p = max(q, max_p)
    print max_p

if __name__ == '__main__':
    main()

Measured memory_bytes: 17584
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define inf 1e18+9
using namespace std;
int32_t main(){
	if(fopen("input.txt", "r"))
	freopen("input.txt", "r", stdin),
	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	string st;
	cin >> st;
	if(st=="AAA" or st=="BBB")
		cout << "No";
	else
		cout << "Yes";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL =LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    ll a,b,c;cin>>a>>b>>c;
    if(a%2==0 || b%2==0 || c%2==0){cout<<0<<endl;return 0;}
    cout<< min(min(a*b,a*c),c*b)<<endl;
    return 0;
}








Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string s;
  	cin >> s;
  	if(s.length() % 2 != 0)
    {
    	cout << "No" << endl;
    }
  	else
    {
    	bool ok = true;
      	for(int i = 0; i < s.length(); i++)
        {
        	if(i % 2 == 0 && s[i] != 'h' || i % 2 != 0 && s[i] != 'i')
            {
            	ok = false;
              	break;
            }
        }
      	if(ok)
          	cout << "Yes" << endl;
      	else
          	cout << "No" << endl;
    }
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, k ] <- readInts
	a <- readInts
	let
		g = foldl1 gcd a
	putStrLn $ which "POSSIBLE" "IMPOSSIBLE" $ k <= maximum a && k `mod` g == 0


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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
int INF = numeric_limits<int>::max();
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

/* if in function
template <class T>
bool contain(vector<T> &vec, T find_it) {
  auto it = find(vec.begin(), vec.end(), find_it);
  return it != vec.end();
}

bool contain(string &str, char c) {
  return str.find(c) != string::npos;
}
*/

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int cost_0 = 0;
  int cost_n = 0;
  rep(i, m) {
    int a;
    cin >> a;
    if (a < x) ++cost_0;
    else ++cost_n;
  }
  cout << min(cost_0, cost_n) << endl;
}


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

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramB a = new ProgramB();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {

            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);
            int d = int.Parse(s[3]);
            int e = int.Parse(s[4]);

            Console.WriteLine(d + c * 60 - b - a * 60 - e);

        }
    }

    class ProgramB
    {
        public void main()
        {

            string s = Console.ReadLine();

            for(int i = 0;i < s.Length;i++)
            {
                if(s[i] == '?')
                {
                    Console.Write('D');
                }
                else
                {
                    Console.Write(s[i]);
                }
            }
            

        }
    }

    class ProgramC
    {
        public void main()
        {
            


        }
    }

    class Dis
    {
        public int a;
        public long b;
        public Dis(int a, long b)
        {
            this.a = a;
            this.b = b;
        }
    }
}






Measured memory_bytes: 26588
#include <bits/stdc++.h>
#include <fstream>
#include <iostream>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define maxim INT_MAX
#define fi first
#define se second

/* 1. If you can't keep solution in mind, then visualize it on a paper.
 * 2. Try to identify the type of problem - DP, Greedy, Graph, Constructive,
 * 	  Prefix/Suffix, Difference Array, BIT/Segment Tree, etc.
 * 3. Look at the problems from different perspectives - reverse the problem,
 * 	  add instead of delete (maybe?)
 * 4. Divide difficult solutions into cases and/or sequences.
 * 5. Use math rules to solve Nested Summation.
 * 6. Optimisation problems are generally solved with DP, greedy, binary search or brute-force.
 * 7. Try fixing a solution then proving we can't do better or worse than that.
 * ------------------------------------------------------------------
 */
 ll n;
 ll ar[100005];
 ll br[100005];
 ll cr[100005];
 ll dp[100005][3];
 ll ans=0;
 ll holiday(ll k,ll i)
 {
     if(i==n)
        return 0;
     if(dp[i][k]!=-1)
        return dp[i][k];
     if(k==0)
     {
         ll x=br[i]+holiday(1,i+1);
         ll y=cr[i]+holiday(2,i+1);
         ans=max(x,y);
     }
     if(k==1)
     {
         ll x=ar[i]+holiday(0,i+1);
         ll y=cr[i]+holiday(2,i+1);
         ans=max(x,y);
     }
     if(k==2)
     {
         ll x=br[i]+holiday(1,i+1);
         ll y=ar[i]+holiday(0,i+1);
         ans=max(x,y);
     }
     return dp[i][k]=ans;
 }
int main()
{
    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>ar[i]>>br[i]>>cr[i];
    ll x=ar[0];
    ll y=br[0];
    ll z=cr[0];
    memset(dp,-1,sizeof(dp));
    x+=holiday(0,1);
    y+=holiday(1,1);
    z+=holiday(2,1);
    ll ans=max(x,max(y,z));
    cout<<ans<<endl;

}


Measured memory_bytes: 12944
#include<iostream>
#include <vector>
#include<algorithm>
#include<math.h>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)

using namespace std;
int main() {
	lli A, B, Q;
	cin >> A >> B >> Q;
	vector<lli> s(A+2, 0), t(B+2, 0), x(Q+2, 0);

	s[0]=-1e11;
	t[0]=-1e11;

	rep0(i, A) cin >> s[i+1];
	rep0(i, B) cin >> t[i+1];
	rep0(i, Q) cin >> x[i];
	s[A + 1] = 1e11;
	t[B + 1] = 1e11;

	sort(all(s));
	sort(all(t));

	rep0(i, Q) {
		decltype(s)::iterator it_s = upper_bound(all(s), x[i]);
		decltype(t)::iterator it_t = upper_bound(all(t), x[i]);

		cout <<
			min(min(min(abs(x[i] - *it_s), abs(x[i] - *it_t)) + abs(*it_s - *it_t),
					min(abs(x[i] - *it_s), abs(x[i] - *(it_t - 1))) + abs(*it_s - *(it_t - 1))), 
				min(min(abs(x[i] - *(it_s - 1)), abs(x[i] - *it_t)) + abs(*(it_s - 1) - *it_t),
					min(abs(x[i] - *(it_s - 1)), abs(x[i] - *(it_t - 1))) + abs(*(it_t - 1) - *(it_s - 1))))
			<< endl;
	}
}

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

vector<char> ans;

inline void rec(ll n) {
    if (n / 26 == 0) {
        char c = 'a' + (n % 26);
        ans.push_back(c);
        return ;
    }
    rec(n % 26);
    rec(n / 26 - 1);
}

int main() {
    cin.tie(0)->sync_with_stdio(false);

    ll n;
    cin >> n;
    n--;

    rec(n);
    reverse(ans.begin(), ans.end());
    for (auto x : ans)
        cout << x;
    cout << '\n';
    return 0;
}


Measured memory_bytes: 3696
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<ll> x(n), y(n), z(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i] >> z[i];
    }

    ll ans = 0;

    for (int bit = 0; bit < (1<<3); bit++) {
        ll sum = 0;
        vector<ll> a(n);
        for (int i = 0; i < n; i++)
        {
            ll tmp = 0;
            if (bit & (1<<0)) {
                tmp += x[i];
            } else {
                tmp -= x[i];
            }

            if (bit & (1<<1)) {
                tmp += y[i];
            } else {
                tmp -= y[i];
            }

            if (bit & (1<<2)) {
                tmp += z[i];
            } else { 
                tmp -= z[i];
            }

            a[i] = tmp;
        }
        sort(a.begin(), a.end());
        reverse(a.begin(), a.end());
        for (int i = 0; i < m; i++)
        {
            sum += a[i];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const int MX = 3003;

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

int n, m;
ll f[MX][2], g[MX][2];

int main()
{
	read(n), read(m);
	for(int i=1; i<=n; i++) f[i][0] = 1;
	f[0][1] = 1;
	for(int t=1; t<=m; t++)
	{
		for(int i=2; i<n; i++)
		{
			g[i][0] = (f[i-1][0] + f[i+1][0] + f[i][0]*2) % MOD;
			g[i][1] = (f[i-1][1] + f[i+1][1] + f[i][1]*2) % MOD;
		}
		g[0][1] = (f[0][1] + f[1][0] + f[1][1]) % MOD;
		if(n > 1)
		{
			g[n][0] = (f[n][0] + f[n-1][0]) % MOD;
			g[n][1] = (f[n][1] + f[n-1][1]) % MOD;
			g[1][0] = (f[2][0] + f[1][0]) % MOD;
			g[1][1] = (f[0][1] + f[2][1] + f[1][0] + f[1][1]*2) % MOD;
		}
		else g[1][1] = (f[0][1] + f[2][1] + f[1][0] + f[1][1]) % MOD;
		memmove(f, g, sizeof(f));
	}
	ll ans = 0;
	for(int i=0; i<=n; i++) ans = (ans + f[i][1]) % MOD;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000
using namespace std;
typedef pair<int, int> P;
int main()
{
    int n;
    while (cin >> n, n)
    {
        vector<vector<P>> v(n);
        vector<vector<P>> w(8);
        int m;
        cin >> m;
        rep(i, m)
        {
            int x, y;
            cin >> x >> y;
            w[0].push_back(make_pair(x, y));
            w[1].push_back(make_pair(y, -x));
            w[2].push_back(make_pair(-x, -y));
            w[3].push_back(make_pair(-y, x));
        }
        rep(i, 4)
        {
            w[i + 4] = vector<P>(m);
            reverse_copy(begin(w[i]), end(w[i]), begin(w[i + 4]));
        }
        rep(i, 8)
        {
            int m = w[i].size();
            rep(j, m)
            {
                if (j == 0)
                    continue;
                w[i][j].first -= w[i][0].first;
                w[i][j].second -= w[i][0].second;
            }
            w[i][0] = P(0, 0);
        }
        rep(i, n)
        {
            int m;
            cin >> m;
            rep(j, m)
            {
                int x, y;
                cin >> x >> y;
                v[i].push_back(make_pair(x, y));
            }
            rep(j, m)
            {
                if (j == 0)
                    continue;
                v[i][j].first -= v[i][0].first;
                v[i][j].second -= v[i][0].second;
            }
            v[i][0] = P(0, 0);
            bool ok = false;
            rep(j, 8)
            {
                if (v[i] == w[j])
                    ok = true;
            }
            if (ok)
                cout << i + 1 << endl;
        }
        cout << "+++++" << endl;
    }
    return 0;
}




Measured memory_bytes: 3080
module Memo = Map.Make(struct
  type t = string * string
  let compare = compare
end)
let str_of_list xs = List.fold_left (fun s c -> s ^ String.make 1 c) "" xs
let pow_str s f =
  let len = String.length s in
  let rec loop idx a b =
    if idx >= len then [(str_of_list (f a), str_of_list (f b))]
    else loop (idx+1) (s.[idx]::a) b @ loop (idx+1) a (s.[idx]::b)
  in loop 0 [] []
let () =
  Scanf.scanf "%d %s" @@ fun n s ->
  let s0, s1 = String.(sub s 0 n, sub s n n) in
  let memo = pow_str s0 (fun x -> x) |> List.fold_left (fun m p ->
    try let v = Memo.find p m in Memo.add p (v+1) m
    with Not_found -> Memo.add p 1 m) Memo.empty
  in
  pow_str s1 List.rev |> List.fold_left (fun s p ->
    try let v = Memo.find p memo in s + v
    with Not_found -> s) 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 75000
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string a;
	int n,p=0,g=0,sum=0;
    cin>>a;
    n=a.size();
	for(int x=0;x<=n-1;x++)
	{
		if(a[x]=='p')
		{
			if(p<g)
			{
				p++;
			}
			else
			{
				g++;
				sum--;
			}
		}
		if(a[x]=='g')
		{
		    if(p<g)
		    {
		    	p++;
		    	sum++;
			}
			else
			    g++;
		}
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

void mainsolve(){


	ll n,m;
	cin >> n >> m;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(), a.end());
	vector<ll> ss(n+1);
	rep(i,n) ss[i+1] = ss[i] + a[i];

	// x以上の幸福度を得られる握手がm通り以上あればtrue
	function<bool(ll)> isOK = [&](ll x){
		ll cnt = 0;
		rep(i,n){
			// 左手は固定
			ll left = a[i];
			ll j = lower_bound(a.begin(), a.end(), x-left) - a.begin();
			cnt += n-j;
		}
		return cnt >= m;
	};

	function<ll()> binsearch = [&](){
		ll ok = 2*a[0]-1;
		ll ng = 2*a[n-1]+1;
		ll mid = (ng+ok)/2;
		while(abs(ng-ok)>1){
			if(isOK(mid)) ok = mid;
			else ng = mid;
			mid = (ng+ok)/2;
		}
		return ok;
	};

	ll c = binsearch();
	ll res = 0;

	// c+1まではまとめて数える
	rep(i,n){
			// 左手は固定
			ll left = a[i];
			ll j = lower_bound(a.begin(), a.end(), c+1-left) - a.begin();
			if(j <= n-1){
				res += (n-j)*left;
				res += ss[n]-ss[j];
				m -= n-j;
			}
			
	}
	
	// 残りは全部c
	res += m*c;
	cout << res << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 1792