akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) { //にぶたんgreater
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

vector<ll> Divisor(ll x) { // 約数列挙
	vector<ll> result;
	ll i=1LL;
	for( ; i*i<x; i++) {
		if(x%i) continue;
		result.push_back(i);
		result.push_back(x/i);
	}
	if(i*i==x&&x%i==0)
		result.push_back(i);
	
	sort(result.begin(),result.end());
	return result;
}

vector<llpair> PrimeFact(ll x) { // 素因数分解 {素因数,指数}
	vector<llpair> result;
	ll ex=0LL;
	if(x%2==0) {
		while(x%2==0) {
			x/=2;
			ex++;
		}
		result.push_back({2,ex});
	}

	for(ll i=3LL; i*i<=x; i+=2) {
		if(x%i) continue;

		ex=0LL;
		while(x%i==0) {
			x/=i;
			ex++;
		}
		result.push_back({i,ex});
	}

	if(x!=1) result.push_back({x,1});

	return result;
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}

int main() {
	int N; cin>>N;
	ll A[N]; for(int i=0; i<N; i++) cin>>A[i];
	ll X[N];
	X[0]=accumulate(A,A+N,0LL);
	for(int i=1; i<N; i+=2) {
		X[0]-=2*A[i];
	}
	cout<<X[0]<<" ";
	for(int i=0; i<N-1; i++) {
		X[i+1]=2*A[i]-X[i];
		cout<<X[i+1]<<" ";
	}
	cout<<endl;
}


Measured memory_bytes: 2816
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const x = nextInt()
    let t = 0
    while(true){
        if(t*(t+1)/2 >= x){
            console.log(t)
            return
        }
        t++
    }
}
Main()


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

string s[100000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    vector<int> a(3);
    cin >> n >> a[0] >> a[1] >> a[2];
    for (int i=0; i<n; i++)
        cin >> s[i];

    vector<char> ret;
    for (int i=0; i<n; i++) {
        int &x = a[s[i][0]-'A'], &y = a[s[i][1]-'A'];
        if (x == 0) {
            if (y == 0) {
                cout << "No\n";
                return 0;
            } else {
                x++;
                y--;
                ret.push_back(s[i][0]);
            }
        } else if (y == 0) {
            x--;
            y++;
            ret.push_back(s[i][1]);
        } else if (x == 1 && y == 1) {
            if (i < n - 1 && (s[i+1][0] == s[i][0] || s[i+1][1] == s[i][0])) {
                x++;
                y--;
                ret.push_back(s[i][0]);
            } else {
                x--;
                y++;
                ret.push_back(s[i][1]);
            }
        } else if (x < y) {
            x++;
            y--;
            ret.push_back(s[i][0]);
        } else {
            x--;
            y++;
            ret.push_back(s[i][1]);
        }
    }

    cout << "Yes\n";
    for (char c : ret)
        cout << c << "\n";

    return 0;
}


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

using namespace std;

double p[3005],dp[3005][3005];
int main()
{
	int n,odd;
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	scanf("%lf",p+i);
	odd = n/2 + 1;
	for(int i=n;i>=0;--i)
	{	
		for(int j=0;j<=n;++j)
		{
			if(odd <= i && j == 0)
			dp[i][j] = 1;
			else if(odd > i && j == 0)
			dp[i][j] = 0;
			else
			dp[i][j] = p[j-1]*dp[i+1][j-1] + (1-p[j-1])*dp[i][j-1];
		}
	}
	printf("%0.10lf\n",dp[0][n]);
	return 0;
}


Measured memory_bytes: 70656
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main(){
	int a=0,b=0,c;
	cin>>c;
	while(1){
		if(c>=3600){
			a++;
			c-=3600;
		}else{
			break;
		}
	}
	while(1){
		if(c>=60){
			b++;
			c-=60;
		}else{
			break;
		}
	}

	cout<<a<<":"<<b<<":"<<c<<endl;
}


Measured memory_bytes: 3100
import java.util.Scanner;

/**
 * Registration.
 */
public class Main {
    public static void main(String[] args) {
        var scanner = new Scanner(System.in);
        var s = scanner.next();
        var t = scanner.next();
        if (t.startsWith(s) && t.length() == s.length() + 1) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

count = [0]*100
for i in range(1, n+1):
    s = str(i)
    x = int(s[0] + s[len(s)-1])
    count[x] += 1

ans = 0
for i in range(1, n+1):
    s = str(i)
    x = int(s[len(s)-1] + s[0])
    ans += count[x]

print(ans)


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

#define rep(i, n) for(int i = 0; i < int(n) ;++i)
#define SZ(a) ((int)(a.size()))
int n;

string in[10000];

void solve(){
  rep(i, n) cin >> in[i];
  rep(i, n){
    int idx = -1;
    rep(j, SZ(in[i])){
      if(in[i][j] != '.'){
        if(j){
          in[i][j - 1] = '+';
          idx = j - 1;
        }
        break;
      }
    }
    if(idx >= 0)for(int k = i - 1; k; --k){
      if(isalpha(in[k][idx]) || in[k][idx] == '+') break;
      in[k][idx] = '|';
    }
  }
  rep(i, n) for(auto& c : in[i]) if(c == '.') c = ' ';
  rep(i, n) cout << in[i] << endl;
}

int main(int argc, char *argv[])
{

  while(cin >> n && n) solve();
  return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    
    vector<pair<int, int>> g(m);
    
    rep(i,m)
    {
        cin >> g[i].first >> g[i].second;
    }
    
    int minv = 0, maxv = 10000000;
    rep(i,m)
    {
        minv = max(minv,g[i].first);
        maxv = min(maxv,g[i].second);
    }
    
    cout << max(0,maxv-minv+1) << endl;
}


Measured memory_bytes: 1024
// ProblemURL : https://atcoder.jp/contests/abc114/tasks/abc114_c
// ---------------------------------------------
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ct := 0
	var dfs func(int)
	dfs = func(x int) {
		if x > n {
			return
		}
		if func(n int) bool {
			a, b, c := false, false, false
			for n > 0 {
				switch n % 10 {
				case 3:
					a = true
				case 5:
					b = true
				case 7:
					c = true
				}
				n /= 10
			}
			return a && b && c
		}(x) {
			ct++
		}
		dfs(x*10 + 3)
		dfs(x*10 + 5)
		dfs(x*10 + 7)
	}
	dfs(0)
	fmt.Println(ct)
}


Measured memory_bytes: 512
// 上級者の解答を勉強する.
// maroonrk氏.
// https://atcoder.jp/contests/agc036/submissions/6433451
#include <iostream>
using namespace std;

int main(){
    long long s;
    scanf("%lld", &s);
    
    const int v=1000000000;
    int x=(v-s%v)%v;
    int y=(s+x)/v;
    
    printf("%lld %lld %lld %lld %lld %lld\n", 0, 0, 1000000000, 1, x, y);

}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define popcnt(x) __builtin_popcount(x)
#define popcntll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CCountOrder {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N, p = -1, q = -1;
        in>>N;
        vc<int> P(N), Q(N), C(N);
        REP(i, N) C[i] = i + 1;
        REP(i, N) in>>P[i];
        REP(i, N) in>>Q[i];
        int now = 0;
        do{
            if(C==P) p = now;
            if(C==Q) q = now;
            ++now;
        }while(next_permutation(ALL(C)));
        out<<abs(p-q)<<'\n';
    }
};


int main() {
	CCountOrder solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3660
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    ll ans = n;
    for(int i=1;i<=sqrt(n);i++){
        if(n%i==0){
            ll m = i - 1 + n/i -1;
            ans = min(ans,m); 
        }
    }
    cout << ans;

    return 0;
}

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

typedef vector< int >      vi;
typedef vector< vi >       vvi;
typedef pair<int, int>     pi;
typedef vector< pi >       vpi;

typedef long long          ll;
typedef vector<ll>         vl;
typedef vector< vl >      vvl;

const int LARGE_INT = 1000000007;
const ll LARGE_LONG = 1L << 62;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = (int)(a); i < (int)(b); i++)

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll  a, b, ans;
    cin >> a >> b;
    ans = a * b / __gcd(a,b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php 
$count = 0;
$str = trim(fgets(STDIN));
for ($length = $current = strlen($str); $length / 2 < $current; $current --) {
  if (substr($str, $current - 1, 1) !== substr($str, $length - $current, 1)) {
    $count ++;
  }
}
echo $count;

Measured memory_bytes: 4604
/// {{{ Author: Wang, Yen-Jen
// include
#include <bits/stdc++.h>

// using
using namespace std;

// types
typedef long long ll;
typedef pair<int,int> pii;

// macro
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin() , (x).end()
#define REP(i , n) for(int i = 0; i < int(n); i++)
#define REP1(i , a , b) for(int i = a; i <= int(b); i++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LC o<<1 , l , m
#define RC o<<1|1 , m + 1 , r
#define MS(x , v) memset(x , (v) , sizeof(x))

// input
inline bool SR(int &x) {
  return scanf("%d",&x) == 1;
}

inline bool SR(ll &x) {
  return scanf("%lld",&x) == 1;
}

inline bool SR(double &x) {
  return scanf("%lf",&x) == 1;
}

inline bool SR(char *s) {
  return scanf("%s",s) == 1;
}

inline bool RI() {
  return true;
}

template<typename I , typename... T> inline bool RI(I &x , T&... tail) {
  return SR(x) && RI(tail...);
}

// output
inline void SP(const int x) {
  printf("%d",x);
}

inline void SP(const ll x) {
  printf("%lld",x);
}

inline void SP(const double x) {
  printf("%.16lf",x);
}

inline void SP(const char *s) {
  printf("%s",s);
}

inline void PL() {
  puts("");
}

template<typename I , typename... T> inline void PL(const I x , const T... tail) {
  SP(x);
  if(sizeof...(tail)) putchar(' ');
  PL(tail...);
}

// debug
#define WangYenJen

#ifdef WangYenJen
template<typename I> void _DOING(const char *s , I&& x) {
  cerr << s << " = " << x << endl;
}

template<typename I , typename... T> void _DOING(const char *s , I&& x , T&&... tail) {
  int c = 0;
  while(*s != ',' || c != 0) {
    if(*s == '(' || *s == '[' || *s == '{') c++;
    if(*s == ')' || *s == ']' || *s == '}') c--;
    cerr << *s++;
  }
  cerr << " = " << x << " , ";
  _DOING(s + 1 , tail...);
}

#define DEBUG(...) \
do {\
  fprintf(stderr , "%s: Line %d - ",__PRETTY_FUNCTION__,__LINE__);\
  _DOING(#__VA_ARGS__ , __VA_ARGS__);\
} while(0);

#else
#define DEBUG(...)

#endif

// constant number
const int INF = 0x3f3f3f3f;
const ll INF64 = 0x3f3f3f3f3f3f3f3fll;

// random function
inline int RAND() {
  static int x = 880301;
  return (x = x * 0xdefaced + 1) % 0x7fffffff;
}
/// }}}

const int MAX_N = 2000 + 7;
const ll MOD = 1000000000 + 7;

ll K;
ll dp[MAX_N][MAX_N];
ll fact[MAX_N * MAX_N];

ll power(ll a, ll n) {
  ll x = 1;
  while (n) {
    if (n & 1) x = x * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return x;
}

ll inv(ll x) {
  return power(x, MOD - 2);
}

ll C(ll n, ll m) {
  if (n < m) return 0;
  else return fact[n] * inv(fact[n - m] * fact[m] % MOD) % MOD;
}

ll dfs(int x, int y) {
  ll &res = dp[x][y];
  if (res != -1) return res;
  if (x == 0 && y == 0) return 1;
  res = 0;
  if (x > 0) {
    res += dfs(x - 1, y);
    if (res >= MOD) res -= MOD;
  }
  if (y > x) {
    res += C(x + y * (K - 1) - 1, K - 2) * dfs(x, y - 1) % MOD;
    if (res >= MOD) res -= MOD;
  }
  return res;
}

int main() {
  fact[0] = 1;
  REP1(i, 1, MAX_N * MAX_N - 1) fact[i] = fact[i - 1] * i % MOD;
  int N;
  RI(N, K);
  if (K == 1) PL(1);
  else {
    MS(dp, -1);
    PL(dfs(N, N) * fact[N] % MOD);
  }
  return 0;
}



Measured memory_bytes: 63360
# coding:utf-8

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

def gen_id(n):
    id = ""
    hokan = 6 - len(str(n))
    for _ in range(hokan):
        id += "0"
    id += str(n)
    return id

DIC = dict()
CITY = []

for pi in range(1, N+1):
    DIC[pi] = []

for i in range(M):
    pi, yi = map(int, input().split())
    DIC[pi].append({ "i":i, "p":pi, "y":yi})

# まずは県ごとにソートする
for pi in range(1, N+1):
    DIC[pi] = sorted(DIC[pi], key=lambda x: x["y"])

# 認識番号を生成
for pi in range(1, N+1):
    for index, city in enumerate(DIC[pi]):
        id = gen_id(city["p"]) + gen_id(index+1)
        city["id"] = id
        CITY.append(city)

# 市番号でソート
x =sorted(CITY, key=lambda x: x["i"])

for i in x:
    print(i["id"])



Measured memory_bytes: 73356
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

char str[200];
void search(int rest, int last, int strpos) {
    if(rest == 0) {
        printf("%s\n", str+1);
    }
    for(int i = min(rest, last); i > 0; i--) {
        search(rest-i, i, strpos+sprintf(str+strpos, " %d", i));
    }
}

int main() {
    while(true) {
        int n; scanf("%d", &n);
        if(n==0) break;
        search(n, n, 0);
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[100],b[100],n,i,j=0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=n-1;i>=0;i--){
		b[j]=a[i];
		j++;
	}
	for(i=0;i<n;i++){
		cout << b[i];
		if(i!=n-1){
			cout << ' ';
		}
			
	}
	cout << endl;
}


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

int N, A, B;
int findSum(int n) {
  int tmp = 0;
  while (n > 0) {
    tmp += n % 10;
    n /= 10;
  }
  return tmp;
}

int main() {
    cin >> N >> A >> B; 
    int total = 0;
    for (int i = 1; i <= N; i++) {
      int sum = findSum(i);
      if (sum >= A && sum <= B) total += i;
    }
  cout << total << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <random>
using namespace std;
using ll = long long;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> z(n);
    for (int i = 0; i < n; i++) {
        cin >> z[i];
    }
    ll ans = 0;
    for (int i = 60; i > -1; --i) {
        ll o = 0;
        ll l = 0;
        for (int j = 0; j < n; j++) {
            if (z[j] & (1ll << i)) {
                l++;
            }
            else o++;
        }
        if (l >= o) {
            ans += l * (1ll << i);
            if (k & (1ll << i)) {
                for (int j = 0; j < 60; j++) {
                    k |= (1ll << j);
                }
            }
        }
        else {
            if(k&(1ll<<i))ans += o * (1ll << i);
            else ans += l * (1ll << i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4036
n,c=map(int,input().split())

xv=[]
xv_rev=[]

for _ in range(n):
    x,v=map(int,input().split())
    xv.append((x,v))
    xv_rev.append((c-x,v))

xv_rev=xv_rev[::-1]

#(最大価値,その時の距離,累積価値合計,累積距離)

ittekoi=[0]*n
itte=[0]*n

sumv=0
#時計回り
for i,(x,v) in enumerate(xv):
    if i==0:
        sumv=v
        itte[i]=max(0,sumv-x)
        ittekoi[i]=max(0,sumv-2*x)
    else:
        sumv+=v
        itte[i]=max(itte[i-1],sumv-x)
        ittekoi[i]=max(ittekoi[i-1],sumv-2*x)    

sumv=0
ittekoi2=[0]*n
itte2=[0]*n

#班時計周り
for i,(x,v) in enumerate(xv_rev):
    if i==0:
        sumv=v
        itte2[i]=max(0,sumv-x)
        ittekoi2[i]=max(0,sumv-2*x)
    else:
        sumv+=v
        itte2[i]=max(itte2[i-1],sumv-x)
        ittekoi2[i]=max(ittekoi2[i],sumv-2*x)    

#print(itte,ittekoi)
#print(itte2,ittekoi2)

ans=0
for i in range(n):
    if i==n-1:
        ans=max(ans,itte[i])
        ans=max(ans,itte2[i])
    else:
        ans=max(ans,itte[i]+ittekoi2[n-i-2])
        ans=max(ans,itte2[i]+ittekoi[n-i-2])

print(ans)


        




Measured memory_bytes: 94380
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;
 
//const long long INF = 1LL << 55;
 
#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false)

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int matrix[210][210];
vector<int> G[210];
int group[210];
int bfs(int start){
    fill(group,group + 210,0);
   queue<int> q;
   q.push(start);group[start] = 1;
   int ans = 0;
   while(!q.empty()){
      int y = q.front();q.pop();
      for(auto i : G[y]){
         //cout << i << " " << group[i] << endl;
         if(!group[i]){
            group[i] = group[y] + 1;
            maxs(ans,group[i]);
            q.push(i);
         }else{
            if(abs(group[i] - group[y]) != 1){
               return -1;
            }
         }
      }
   }
   return ans;
}
int main(void){
   ioboost;
   int n;cin >> n;
   rep(i,n){
       string s;cin >> s;
       rep(j,n)matrix[i][j] = (s[j] == '1');
   }
   
   rep(i,n){
      rep(j,n)if(matrix[i][j])G[i].pb(j);
   }
   int res = -1;
   rep(i,n){
      maxs(res,bfs(i));
   }
 //  rep(i,n)cout << group[i] << endl;
   cout << res << endl;
   return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fastAF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mapll map<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define deb(x) cout<<x
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
int main()
{
    fastAF
    string s; cin>>s; ll c=0; ll ans=0;
    if(s[0]=='R') c++;
    ans=max(ans,c);
    if(s[1]=='R') c++;
    else c=0;
    ans=max(ans,c);
    if(s[2]=='R') c++;
    else c=0;
    ans=max(ans,c);
    cout<<ans<<endl;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
 
int main() {
	int n,m;
	int a,b;
	cin>>n>>m;
	vector<pair<int,int> > AB(n);
	for(int i=0;i<n;i++){
		cin>>a>>b;
		AB[i]=make_pair(a,b);
	}
	sort(AB.begin(),AB.end());
	long long value=0;
	for(int i=0;m>0;i++){
		if(m>AB[i].second){
			value+=(long long)AB[i].first*AB[i].second;
			m-=AB[i].second;
		}else{
			value+=(long long)AB[i].first*m;
			m=0;
		}
	}
	cout<<value<<endl;
	return 0;
	
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    int slen = s.length();
    string result = "AC";
    if(s[0] != 'A'){
        result = "WA";
    }
    int count = 0;
    for(int i = 1; i < slen; i++){
        if(isupper(s[i])){
            if(i == 1 || i == slen - 1 || s[i] != 'C'){
                result = "WA";
            }
            count++;
        }
    }
    if(count != 1){
        result = "WA";
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define in(n) ll a[n];  for (i=0;i<n;i++)   cin>>a[i]
#define inb(n) ll b[n]; for (i=0;i<n;i++)   cin>>b[i]
#define op(n) for(i=0;i<n;i++)  cout<<a[i]<<" ";  cout<<endl;

#define ini ll n,i,j,k,l,m,o,p,s=0,su=0,s1=0,s2=0,d,x,y,z,r,q
#define te ll t;cin>>t;while(t--)

#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define min4(a,b,c,d) min(min3(a,b,c),d)
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define maxa(a,n) (*max_element(a,a+n))
#define maxv(v) (*max_element(v.begin(),v.end())
#define mina(a,n) (*min_element(a,a+n))
#define minv(v) (*min_element(v.begin(),v.end())
#define sot(v) sort(v.begin(),v.end())

#define ct(v,k) count(v.begin(),v.end(),k)
#define pb(a) push_back(a)




#define fo(j,n) for(i=j;i<n;i++)

#define itr(v) for(auto it=v.begin();it!=v.end();it++) 


#define fi it->first
#define sc it->second

using namespace std;

typedef long long int ll;
typedef long double db;

const ll  mod=(ll )1e9+7;

   ll gcd(ll a,ll b) { if(a%b==0) return b; return gcd(b,a%b); }
   ll ab(ll a){if(a<0) return -1*a;return a;}   
   ll cei(ll a,ll b){ if(a==0) return 0;return ((a-1)/b)+1;}  // postive values only
   ll flo(ll a,ll b){return a/b;}
   ll lc(ll a,ll b){return ((a*b)/gcd(a,b));}


ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}



ll modInverse(ll a, ll m) { return power(a, m-2, m); }


void fastscan(ll &number)
{ 
    bool negative = false; 
     register ll c; number = 0; c = getchar(); 
    if (c=='-') 
    { 
        negative = true; 
        c = getchar(); 
    }
    
    for (; (c>47 && c<58); 
    c=getchar()) number = number *10 + c - 48; 
    if (negative)  number *= -1;   
}

inline vector<string> tokenize(string To_change,string delimiter)
{
    size_t pos = 0;
    string token;
    vector<string> changed;
    while ((pos = To_change.find(delimiter)) != string::npos) 
    {
        token = To_change.substr(0, pos);
        //cout << token << endl;
        changed.push_back(token);
        To_change.erase(0, pos + delimiter.length());
    }
    //cout << To_change << endl;
    changed.push_back(To_change);
    
    for(int i=0;i<(int)changed.size();i++)cout<<changed[i]<<endl;
    return changed;
}



/*
bool prime[1000001]; 
void Sieve(ll n){memset(prime, true, sizeof(prime));for (ll p=2; p*p<=n; p++) if (prime[p] == true) { for (ll i=p*p; i<=n; i += p)prime[i] = false;} prime[0]=false; prime[1]=false;}



ll fac[100001]; 
void ncrmodp(ll n, ll r, ll p){fac[0] = 1; for (ll i=1 ; i<=n; i++) fac[i] = fac[i-1]*i%p;} 
ll getncrmod(ll n,ll r,ll p){if (r==0) return 1;return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p; }
*/ 

// function to print the divisors
  


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ini;
    cin>>n>>m;
    cout<<cei(n,(2*m)+1);
        
        
    return 0;
}

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

void insertionSort(int A[],int N)
{
    int v;

    for(int i=1;i<N;i++)
    {

        v=A[i];
       int j=i-1;


        for(int n=0;n<N;n++)
        {
            if(n>0)
                cout<<" ";

         cout<<A[n];

        }
          cout<<endl;
        while(j>=0&&A[j]>v)
        {
            A[j+1]=A[j];
            j--;
            A[j+1]=v;

        }

    }
    for(int i=0;i<N;i++)
    {
        if(i>0)
        cout<<" ";
        cout<<A[i];
    }
    cout<<endl;

}

int main()
{
    int N,a[105];
    cin>>N;
    for(int i=0;i<N;i++)
        cin>>a[i];
    insertionSort(a,N);
    return 0;

}

Measured memory_bytes: 3048
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        initFac(n);
        long a = sc.nextLong(); long b = sc.nextLong(); long k = sc.nextLong();
        long res = 0;
        for (int i = 0; i <= n; i++) {
            if ((k - a * i) < 0) continue;
            if ((k - a * i) % b != 0) continue;
            int j = (int) ((k - a * i) / b);
            res = (res + (nck(n, i) * nck(n, j)) % mod) % mod;
        }
        out.println(res);
        out.close();
    }

    static long[] fac;
    static long mod = (long) 998244353;

    static void initFac(long n) {
        fac = new long[(int) n + 1];
        fac[0] = 1;
        for (int i = 1; i <= n; i++) {
            fac[i] = (fac[i - 1]  * i) % mod;
        }
    }



    static long nck(int n, int k) {
        if (n < k)
            return 0;
        long den = inv((int) (fac[k] * fac[n - k] % mod));
        return fac[n] * den % mod;
    }

    static long pow(long b, long e) {
        long ans = 1;
        while (e > 0) {
            if (e % 2 == 1)
                ans = ans * b % mod;
            e >>= 1;
            b = b * b % mod;
        }
        return ans;
    }

    static long inv(long x) {
        return pow(x, mod - 2);
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 35940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
int n,m;
int par[N],rk[N];
unordered_map<int,int> h;
void init(int n){
    for(int i = 1;i<=n;i++){
        par[i] = i;
        rk[i] = 0;
    }
}

int find(int x){
    if(par[x] == x)  return x;
    else{
        return par[x] = find(par[x]);
    }
}

bool same(int x,int y){
    return find(x) == find(y);
}

void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rk[x] < rk[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(rk[x] == rk[y]) rk[x]++;
    }
}


int main(){
    cin >> n >> m;
    init(n);
    int ans = 0;
    for(int i = 0;i<m;i++){
        int a,b;
        cin >> a >> b;
        if(!same(a,b)) {
            unite(a,b);
        }
    }
    for(int i =1;i<=n;i++) find(i);
    for(int i = 1;i<=n;i++){
        h[par[i]]++;
        ans = max(ans,h[par[i]]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12852
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>; 

int main() {
    ll N;
    cin >> N;
    vector<string> s(N);
    rep(i, N){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());
    ll ans = 0;
    ll cnt = 1;
    rep(i, N-1){
        if(s[i] != s[i+1]){
            ans += cnt * (cnt-1) / 2;
            cnt = 1;
        }else{
            cnt++;
        }
        if(i+1 == N-1){
            ans += cnt * (cnt-1) / 2;
        }
    }
    cout << ans;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll x, y;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> x >> y;
    if (x % y == 0) cout << -1 << endl;
    else cout << (y + 1) * x << endl;
    return 0;
}

Measured memory_bytes: 256
h,w= map(int,input().split())
rg = [list(map(int,input().split())) for _ in range(10)]
for k in range(10):
    for i in range(10):
        for j in range(10):rg[i][j]=min(rg[i][j],rg[i][k]+rg[k][j])
atable = [list(map(int,input().split())) for _ in range(h)]
g=0
for i in range(h):
    for j in range(w):
        if atable[i][j]!=-1:g+=rg[atable[i][j]][1]
print(g)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
#define inf             1e18
#define mod             1000000007
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}void _p() {cout << "]\n";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=========================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r;








void sol()
{   
    cin>>n>>m;
    in(a,n);
    int sm=0;
    fo(i,n)sm+=a[i];
    sm=ceil(sm/(4.0*m));
    c=0;
    fo(i,n)if(a[i]>=sm)c++;

    cout<<((c>=m)?"Yes":"No")  <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 3720
def main():
    N = int(input())
    A = list(map(int, input().split()))

    sort_A = sorted(A, reverse=True)
    alice = 0
    bob = 0
    for i, a in enumerate(sort_A):
        if i % 2 == 0:
            alice += a
        else:
            bob += a

    print(alice - bob)


main()

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

using namespace std;

int main(){
  int N,M; cin >> N >> M;
  pair<long,int> p[N];
  REP(i,N){
    long A,B; cin >> A >> B;
    p[i] = make_pair(A,B);
  }
  sort(p,p+N);
  
  long count = 0 , money = 0;
  int j = 0;
  while(count < M){
    long A = p[j].first , B = p[j].second;
    money += A;
    count++;
    p[j].second--;
    if(p[j].second == 0) j++;
  }
  cout << money << endl;
}



Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys


def solve(n: int, p: "List[int]"):
    count = 0
    for i in range(1, n -1):
        if sorted([p[i-1], p[i], p[i+1]])[1] == p[i]:
            count += 1
    print(count)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    if a % 3 == 0 or b % 3 == 0 or (a + b) % 3 == 0:
        print("Possible")
    else:
        print("Impossible")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <stdio.h>

int A, B, C;

int main(void)
{
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);

	int remain = C;
	int renzokuCnt = 0;
	int loginCnt = 0;
	while (remain > 0) {
		renzokuCnt++;
		loginCnt++;
		remain -= A;
		if (renzokuCnt >= 7) {
			remain -= B;
			renzokuCnt = 0;
		}
	}
	printf("%d\n", loginCnt);

	return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>

int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a > b)
        printf("a > b\n");
    else if (b > a)
        printf("a < b\n");
    else
        printf("a == b\n");
    return 0;
}


Measured memory_bytes: 2100
//#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
//#pragma GCC target ("avx")
//#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

#define N 30000
#define M (2*3*5)

int main(){
	int n;
	cin>>n;
	if(n==3){
		cout<<"2 5 63"<<endl;
		return 0;
	}
	vector<int> res;
	int sum = 0;
	for(int i = M*3+2; i <= N; i++){
		if(__gcd(i, M)==1) continue;
		if(res.size()==n-2){
			sum %= M;
			for(int j = 0; j < M; j++){
				if(__gcd(j, M)==1) continue;
				int k = (M-sum-j+M)%M;
				if(__gcd(k, M)==1) continue;
				res.pb(j+M);
				res.pb(k+2*M);
				i = j = k = INF;
				break;
			}
		} else {
			res.pb(i);
			sum += i;
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 512
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

// conversion
inline int
toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//change
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//math
template <class T>
inline T sqr(T x) { return x * x; }

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

template <class T>
inline T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

//repetition
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (c - (a - b) < 0)
    {
        cout << 0 << endl;
        return 0;
    }
    cout << c - (a - b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int a[4],b[4];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]){
	int hit=0,blow=0;
	for(int i=0;i<4;i++)cin>>b[i];
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
		if(i==j)continue;
		if(a[i]==b[j])blow++;
		}
	}
	for(int i=0;i<4;i++)if(a[i]==b[i])hit++;
	cout<<hit<<" "<<blow<<endl;
	}
	return 0;
}

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

int ppl[55]={0};
int n,p,now,num;

int main(){
  int i,j,k;
  while(1){
    cin >> n >> p;
    if(n+p==0)break;
    now = p;
    num = 0;
    while(1){
      if(now>0){
	ppl[num]++;
	now--;
      }
      else if(ppl[num]==p)break;
      else{
	now = ppl[num];
	ppl[num]=0;
      }
      num++;
      num%=n;
    }
    printf("%d\n",num);
    for(i=0;i<n;i++)ppl[i]=0;
  }
  return 0;
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
 
template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc
 
const int N=1e5+5;
vector<int>lk[N];
bool vis[N];
 
int dfs(int x,int fr)
{
	//if(vis[x]) return 0;
	if(lk[x].size()>2)return x;
	vis[x]=1;
	if(!vis[lk[x][lk[x][0]==fr]]) return dfs(lk[x][lk[x][0]==fr],x);
	else return 0;
}
 
int main()
{
	int n,m,M;
	cin>>n>>m;
	M=m;
	while(M--)
	{
		int x=read(),y=read();
		lk[x].push_back(y);
		lk[y].push_back(x);
	}
	rep(i,1,n)
	if(lk[i].size()%2){puts("No");exit(0);}
	rep(i,1,n)
	if(lk[i].size()>4){puts("Yes");exit(0);}
	if(m>n+2){puts("Yes");exit(0);}
	if(m<n+2){puts("No");exit(0);}
	//cout<<"y"<<endl;
	int cnt=0;
	rep(i,1,n)
	if(lk[i].size()==4)
	{
		for(auto j:lk[i])
		{
			if(dfs(j,i)!=i)++cnt;
		}
		break;
	}
	if(cnt>=4)puts("No");
	else puts("Yes");	
}
/*
7 9
1 2
2 3
1 3
3 4
3 5
4 5
5 6
5 7
6 7
*/

Measured memory_bytes: 5760
from collections import deque
def solve():
    n = int(input())
    A = list(map(int,input().split()))

    q = deque()
    for i in range(n):
        if i % 2 == 0:
            q.append(A[i])
        else:
            q.appendleft(A[i])
    
    ans = list(q)
    if n % 2 != 0:
        ans.reverse()
    
    print(*ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 106764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int ctoi(char c){
    switch (c){
        case '0': return 0;
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
        case '4': return 4;
        case '5': return 5;
        case '6': return 6;
        case '7': return 7;
        case '8': return 8;
        case '9': return 9;
        default: return 0;
    }
}

int main(){
    string S;
    cin >> S;
    ll len = S.size();
    vector<ll> dp(2019, 0);
    ll prev = 0;
    ll num = 1;
    dp[0]++;
    for (ll i = len - 1; i >= 0; i--){
        dp[(prev + num * ctoi(S[i])) % 2019]++;
        prev = (prev + num * ctoi(S[i])) % 2019;
        num = (num * 10) % 2019;
    }
    ll ans = 0;
    rep(i,2019){
        ans += (dp[i]) * (dp[i] - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,k;
    cin >> n >> k;
    int pi[n];
    for(int i=0;i<n;i++){
        cin >> pi[i];
    }
    sort(pi,pi+n);
    int total=0;
    for(int i=0;i<k;i++){
        total+=pi[i];
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 3628