akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

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

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

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

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if (z->left == NIL || x->right == NIL) {
    y = z;
  } else {	
    y = treeSuccessor(z);
  }
  
  if (y->left != NIL) {
    x = y->right;
  } else {
    x = y->right;
  }
  
  if (x != NIL) {
    x->parent = y->parent;
  }
  
  if (y->parent == NIL) {
    root = x;
  } else if (y == y->parent->left) {
    y->parent->left = x;
  } else {
    y->parent->right = x;
  }
  
}

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

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

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

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

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

}


void inorder(Node u){
  
  if(u->left != NIL){
    inorder(u->left);
  }
  
  printf(" %d",u->key);
  
  if(u->right != NIL){
    inorder(u->right);
  }
  
}

void preorder(Node u){

  printf(" %d",u->key);
	
  if(u->left != NIL){
    preorder(u->left);
  }
  
  if(u->right != NIL){
    preorder(u->right);
  }
  
}


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

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

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

Measured memory_bytes: 9844
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;

int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    if(a%2==b%2){
        cout << (b-a)/2 << endl;
    } else {
        cout << min(a-1,n-b) + 1 + (b-a-1)/2 << endl;
    }
}

Measured memory_bytes: 3580
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1000000007;

int main() {
  ll n, q;
  cin >> n >> q;

  set<P> s;
  vT evs;
  vll ans(q, -1);
  rep(i, n) {
    ll a, b, c;
    cin >> a >> b >> c;
    evs.push_back(T(c, a - c, b - c));
  }
  Sort(evs);

  rep(i, q) {
    ll t;
    cin >> t;
    s.insert(P(t, i));
  }

  for (ll i = 0; i < n; i++) {
    ll x, l, r;
    tie(x, l, r) = evs[i];
    auto it = s.lower_bound(P(l, -1));
    while (it != s.end()) {
      if (it->first >= r) break;
      ans[it->second] = x;
      s.erase(it++);
    }
  }

  rep(i, q) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 21356
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int A,B,C,X,Y;
    cin>>A>>B>>C>>X>>Y;
    int p1=A+B;
    int p2=C*2;
    int cnt=0;
    if(X>=Y){
        if(p1<=p2){
            cnt=p1*Y+min(A,p2)*(X-Y);
        }
        else{
            cnt=p2*Y+min(A,p2)*(X-Y);
        }
    }
    else{
        if(p1<=p2){
            cnt=p1*X+min(B,p2)*(Y-X);
        }
        else{
            cnt=p2*X+min(B,p2)*(Y-X);
        }

    }
    cout<<cnt<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int Q, p, x, a[309], v[7] = { 2,3,5,7,11,13,17 }, w[7] = { 8,5,3,2,2,2,2 }, maxn;
vector<int>primes;
 
void dfs(vector<int>vec) {
	if (vec.size() == 7) {
		long long s = 1;
		for (int i = 0; i < vec.size(); i++) { for (int j = 0; j < vec[i]; j++) s *= 1LL * v[i]; }
		for (int i = 7; i < primes.size(); i++) {
			int score = a[primes[i]];
			for (int j = 2; j*primes[i] <= 300; j++) {
				if (s%j == 0) score += a[j*primes[i]];
			}
			if (score > 0) { vec.push_back(1); }
			else { vec.push_back(0); }
		}
		int sum = 0;
		for (int i = 2; i <= 300; i++) {
			int cx = i; bool OK = true;
			for (int j = 0; j < primes.size(); j++) {
				int t = 0;
				while (cx%primes[j] == 0) { cx /= primes[j]; t++; }
				if (vec[j] < t) OK = false;
				if (cx == 1) break;
			}
			if (OK == true) sum += a[i];
		}
		maxn = max(maxn, sum);
		return;
	}
	for (int i = 0; i <= w[vec.size()]; i++) {
		vector<int>vec2 = vec; vec2.push_back(i);
		dfs(vec2);
	}
}
 
int main() {
	cin >> Q;
	for (int i = 2; i <= 300; i++) {
		bool OK = false;
		for (int j = 2; j*j <= i; j++) { if (i%j == 0)OK = true; }
		if (OK == false) primes.push_back(i);
	}
	for (int i = 1; i <= Q; i++) {
		cin >> p >> x;
		a[p] = x;
	}
	dfs(vector<int>{});
	cout << maxn << endl;
	return 0;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 A,B,C,K;
    cin >> A >> B >> C >> K;

    if(K%2==0) cout << A-B << endl;
    else cout << -A+B << endl;
}

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


Measured memory_bytes: 256
def main():
    S=input()
    T=input()
    X=[]
    Y=[]
    flag=True
    for i in range(len(S)):
        al=False
        if T[i] in Y:
            al=True
            if X[Y.index(T[i])]!=S[i]:
                flag=False
                break
        if S[i] in X:
            al=True
            if Y[X.index(S[i])]!=T[i]:
                flag=False
                break
        if al==False:
            X.append(S[i])
            Y.append(T[i])
    if flag:
        print("Yes")
    else:
        print("No")

if __name__=="__main__":
    main()

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            char c = br.readLine().charAt(0);
            if(Character.isUpperCase(c)) { 
                pw.println('A');
            }
            else {
                pw.println('a');
            }

        }
        finally {
            pw.flush();
            pw.close();
        }
    }
}


Measured memory_bytes: 32668
x, y = gets.split.map(&:to_i)
if x % y == 0
  puts -1
else
  z = 2
  limit = 10 ** 18
  ans = -1
  while x * z <= limit
    if x * z % y != 0
      ans = x * z
      break
    end
    z += 1
  end
  puts ans
end


Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <limits.h>
#include <cmath>
#include <cstring>
#include <queue>
#include <stdlib.h>

using namespace std;

#define mod (1000000007)
typedef long long  ll;
typedef vector<int> vi;


ll exp(ll a, ll n) {
  if (n==0) return 1;
  if (n == 1) return a;
  if (n%2) {
    ll s = exp(a,n-1);
    return s * a;
  } else {
    ll s = exp(a,n/2);
    return s*s;
  }
}

long max(long a, long b) {
  if (a < b) return b;
  return a;
}

int min(int a, int b, int c) {
  return min(min(a,b), min(b,c));
}


void solve() {
  long n, w;
  cin >> n >> w;
  
  vector<pair<long, long> > arr(n);
  
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first >> arr[i].second;
  }
  
  vector<long> weight (w+1, -1);
  //memset(weight, 0, w+1);
  weight[0] = 0;
  
  
  for (int i = 0; i < n; i++) {
    for (int j = w; j >= 0; j--) {
      if (weight[j] >= 0) {
        if (j + arr[i].first <= w) {
          weight[j+arr[i].first] = max(weight[j+arr[i].first], weight[j] + arr[i].second);
        }
      }
    }
  }
  long ans = 0;
  
  for (int i = 0; i <= w; i++) ans = max(ans, weight[i]);
  
  cout << ans << "\n";
 
}

int main() {
  solve();
  return 0;
}



Measured memory_bytes: 4044
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

res = 1e+9
c = 0
for i in range(N):
    t = T - H[i] * 0.006
    tmp = abs(t - A)
    if res > tmp:
        res = tmp
        c = i
print(c+1)

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


void solve(std::string S){
    if(S[1] == 'R'){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ARC"<<endl;
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  int n; cin >> n;
  ll ans = 0;
  vector<ll> a(n,0);
  rep(i,n){
    ll x; cin >> x;
    if(x>n){
      ans++;
    }else{
      a.at(x-1)++;
    }
  }

  rep(i,n){
    if(a.at(i)<i+1) ans+=a.at(i);
    else if(a.at(i)>i+1) ans+=a.at(i)-i-1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4048
n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    s=input().split()
    A,B=int(s[0]),int(s[1])
    a.append(A)
    b.append(B)
    c.append(A+B)
c.sort(reverse=True)
s1=0
s2=0
for i in range(n):
    s1+=a[i]
    if i%2:
        s2+=c[i]
print(s1-s2)

Measured memory_bytes: 15396
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())


k = int(input())

def diff(x, y, z = k):
  if abs(x - y) > z:
    return 1
  else:
    return 0
  
num = 0

num += diff(a, e)
num += diff(a, d)
num += diff(a, c)
num += diff(a, b) 
num += diff(b, e)
num += diff(b, d)
num += diff(b, c)
num += diff(c, e)
num += diff(c, d)
num += diff(d, e)

if num == 0:
  print("Yay!")
else:
  print(":(")


Measured memory_bytes: 3064
# じょえチャンネルおもしろいよ～～～
# https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ

Hitachi="Hitachi"
hitachi="hitachi"

s=input()
if "hi"*(len(s)//2)==s:print("Yes")
else:print("No")


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
const long long mod = 1e9 + 7;

int main(){
     int n,d;
     cin >> n >> d;
     if(n%(2*d+1)==0)cout << n/(2*d+1) << endl;
     else cout << n/(2*d+1) + 1 << endl;
     return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
int N, X;
int L[Max];
int D[Max];

int main(int argc, const char * argv[]) {
    cin >> N >> X;
    inputArray(L, N);

    D[0] = 0;
    rep(i, N+1) {
        D[i+1] = D[i] + L[i];
    }

    int count = 0;

    rep(i, N+1) {
        if (D[i] <= X) count++;
    }

    output(count);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String s = sc.next();
		String t = sc.next();

		String[] sa = s.split("");
		String[] ta = t.split("");

		String ans = "";
		for (int i = 0; i < n; i++) {
			ans += sa[i];
			ans += ta[i];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long sum =0;

		for(long i=1; i<=n; i++){
			if(i % 3 == 0  || i %5 ==0 ){

			}else{
				sum += i;
			}
		}

		System.out.println(sum);
	}
}

Measured memory_bytes: 35728
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")


ll gcd(ll a, ll b) {
	if (a < b) gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

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


signed main() {

	int N, K;
	cin >> N >> K;

	if ((N - 1) * (N - 2) / 2 < K) {
		cout << -1 << endl;
		return 0;
	}
	int A = (N - 1) * (N - 2) / 2 - K;
	cerr << "A " << A << endl;
	cout << N - 1 + A << endl;
	rep(i, N - 1) {
		cout << "1 " << (i + 2) << endl;
	}

	if (A == 0) return 0;
	for (int i = 2; i <= N - 1; i++) {
		for (int j = i + 1; j <= N; j++) {
			cout << i << " " << j << endl;
			A--;
			if (A == 0) return 0;

		}
	}
	
	return 0;
}


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

int main(){
  int N;cin>>N;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  for(int i=0;i<N;i++){
    if(S[i]=="AC") ac++;
    else if(S[i]=="WA") wa++;
    else if(S[i]=="TLE") tle++;
    else re++;
  }
  cout<<"AC"<<" "<<"x"<<" "<<ac<<endl;
  cout<<"WA"<<" "<<"x"<<" "<<wa<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<tle<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<re<<endl;
}
  

Measured memory_bytes: 6424
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli n, k, cnt = 0, basho=0, ans;
	cin >> n >> k;
	vector<lli> a(n+1);
	map<lli, int> memo;
	loop(i, 1, n+1) cin >> a[i];

	int flag = 0;
	memo[1]++;
	lli old = 1;
	vector<lli> q(1,1);//初期設定

	rep(i,n+1){
		memo[a[old]]++;
		if(memo[a[old]] > 1){
			flag = 1;
			for(const auto& x : q){
				if(x == a[old]) break;
				basho++;
			}
		}
		if(flag == 1) break;
		q.push_back(a[old]);
		old = a[old];
	}//ループし始める要素の先頭になったら
	//その要素の過去に出た場所を特定する

	if(k < basho) ans = q[k];
	else{
		k -= (basho);
		k %= q.size()-basho;
		ans = q[basho+k];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 18556
def main():
    def cmb(n, r, mod):#コンビネーションの高速計算　
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    mod = 10**9+7 #出力の制限
    N = 10**6
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    X,Y=map(int,input().split())
    if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
        print(0)
    else:
        s=(2*Y-X)//3
        t=(2*X-Y)//3
        if s<0 or t<0:
            print(0)
        else:
            print(cmb(s+t,t,mod))

if __name__ == '__main__':
    main()

Measured memory_bytes: 127568
#A〜Bの範囲のK番目以内の数字をリストに入れた後、
#重複をなくし、ソートして順に出力する。

#入力値読み込み
A,B,K = map(int, input().split())

#AからAよりK分大きい数までをLisに入れる。
    #B以下の数字のみlisに追加
lis = []
for i in range(A, A+K):
    if i <= B:
        lis.append(i)

#BよりK分小さい数からBまでをlisに入れる
    #A以上の数字のみlisに追加
for j in range(B-K+1, B+1):
    if j >= A:
        lis.append(j)

#集合にして重複をなくす
ans_set = set(lis)

#リストにする
ans_list = list(ans_set)

#昇順にsortでソートする
ans_list.sort()

#順に出力する
for n in ans_list:
        print(n)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#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 ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

const LL Z=1e18;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    VI a(n*3);
    REP(i,3*n) cin >> a[i];
    vector<LL> L(3*n+1), R(3*n+1);
    {
        MinHeap<int> q;
        for ( int i=0; i<3*n; i++ ) {
            q.push(a[i]);
            L[i+1]=L[i]+a[i];
            if ( q.size()>n ) {
                L[i+1]-=q.top();
                q.pop();
            }
        }
    }
    {
        MaxHeap<int> q;
        for ( int i=3*n-1; i>=0; i-- ) {
            q.push(a[i]);
            R[i]=R[i+1]+a[i];
            if ( q.size()>n ) {
                R[i]-=q.top();
                q.pop();
            }
        }
    }
    // for ( int i=0; i<3*n; i++ ) {
    //     cout << L[i+1] << ' ';
    // } cout << endl;
    // for ( int i=0; i<3*n; i++ ) {
    //     cout << R[i] << ' ';
    // } cout << endl;

    LL ans=-Z;
    for ( int i=n; i<=2*n; i++ ) {
        chmax(ans, L[i]-R[i]);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 7028
N = int(input())
A = list(map(int, input().split())) # length: N
B = list(map(int, input().split())) # length: N
C = list(map(int, input().split())) # length: N - 1

M = 0
M += sum(B)
for i in range(N - 1):
    if A[i + 1] - A[i] == 1:
        M += C[A[i] - 1]

print(M)

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N, K;
int x, y;
char c;

int d[2010][2010];

/*==================================================*/
/*function*/
int cal(int y1, int x1, int y2, int x2){
    int ret = 0;

    if(x1 >= 2*K || y1 >= 2*K || x2 < 0 || y2 < 0) return ret;  //全くの範囲外

    if(x1 < 0) x1 = 0;  //はみ出しをカット
    if(y1 < 0) y1 = 0;
    if(x2 >= 2*K) x2 = 2*K-1;
    if(y2 >= 2*K) y2 = 2*K-1;

    ret = d[y2][x2];    //累積和で計算
    if(y1-1 >= 0) ret -= d[y1-1][x2];
    if(x1-1 >= 0) ret -= d[y2][x1-1];
    if(y1-1 >= 0 && x1-1 >= 0) ret += d[y1-1][x1-1];

    return ret;
}

/*==================================================*/

int main() {
    cin>>N>>K;
    REP(i,0,N){
        cin>>x>>y>>c;
        x %= (2*K);
        y %= (2*K);
        if(c == 'W'){
            y = (y + K) % (2*K);
        }
        d[y][x]++;
    }

    //２次元累積和の準備
    REP(i,0,2*K+1){
        REP(j,0,2*K+1){
            d[i][j+1] += d[i][j];
        }
    }
    REP(j,0,2*K){
        REP(i,0,2*K){
            d[i+1][j] += d[i][j];
        }
    }

    int ans = 0;

    REP(i,0,2*K){
        REP(j,0,2*K){
//            int t = cal(i-K+1,j-K+1,i,j) +
//                    cal(i+K+1,j-K+1,i+2*K,j) +
//                    cal(i-K+1,j+K+1,i,j+2*K) +
//                    cal(i+1,j+1,i+K,j+K) +
//                    cal(i+K+1,j+K+1,i+2*K,j+2*K) +
//                    cal(i-3*K+1,j-K+1,i-2*K,j) +
//                    cal(i-K+1,j-3*K+1,i,j-2*K) +
//                    cal(i-2*K+1,j-2*K+1,i-K,j-K) +
//                    cal(i-3*K+1,j-3*K+1,i-2*K,j-2*K) +
//                    cal(i+1,j-2*K+1,i+K,j-K);

            int t = cal(i-K+1,j-K+1,i,j) +
                    cal(i-2*K+1,j-2*K+1,i-K,j-K) +
                    cal(i-2*K+1,j+1,i-K,j+K) +
                    cal(i-K+1,j+K+1,i,j+2*K) +
                    cal(i+1,j-2*K+1,i+K,j-K) +
                    cal(i+1,j+1,i+K,j+K) +
                    cal(i+K+1,j-K+1,i+2*K,j) +
                    cal(i+K+1,j+K+1,i+2*K,j+2*K)
                    ;
            ans = max(ans, t);
            //cout<<endl;
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

const int MAX = 510000;
const int MOD = 1000000007;

void	ComInit(vector<long> &fac, vector<long> &finv, vector<long> &inv) {
	fac.at(0) = 1;
	fac.at(1) = 1;
	finv.at(0) = 1;
	finv.at(1) = 1;
	inv.at(1) = 1;
	for (int i=2; i<MAX; i++) {
		fac.at(i) = (fac.at(i-1)*i) %MOD;
		inv.at(i) = MOD - (inv.at(MOD%i)*(MOD/i)) %MOD;
		finv.at(i) = (finv.at(i-1)*inv.at(i)) %MOD; 
	}
}

long	COM(int N, int K, vector<long> &fac, vector<long> &finv) {
	if (N<K)
		return 0;
	if ((N<0)||(K<0))
		return 0;
	return (fac.at(N) * ((finv.at(K)*finv.at(N-K)) %MOD)) %MOD;
}

int	main() {
	// Array
	vector<long> fac(MAX);
	vector<long> finv(MAX);
	vector<long> inv(MAX);
	// Initialize
	ComInit(fac, finv, inv);

	long H, W, A, B;
	cin >>H >>W >>A >>B;

	long S=0;
	int h=H-A;
	int w=B+1;
	while ((h>0)&&(w<=W)) {
		long SS=COM(h+w-2, h-1, fac, finv)*COM(H+W-h-w, H-h, fac, finv);
		SS %=MOD;
		S += SS;
		S %=MOD;
		h--;
		w++;
	}
	cout <<S <<endl;
	return 0;
};


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// ??????10??????
		 int debt = 100000;

		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);

		// n??±??????
		int n = Integer.parseInt(br.readLine());

		// n??±????????????????????§??°?????????
		for (int i = 0; i < n; i++ ){
			// ??????5
			debt *= 1.05;

			// 1000?????????????????????
			int a = debt % 1000;
			if (a > 0) {
				debt = debt - a + 1000;
			}
		}

		System.out.println(debt);
	}
}

Measured memory_bytes: 24072
#include <iostream>
#include <vector>
#include <map>

using namespace std;

struct Disc {
	int x, y, r, c;
	int depend;
};

map<int, int> memo;

int recur(vector<Disc> &discs, int picked){
	if(memo.find(picked) != memo.end()){ return memo[picked]; }
	vector<int> pickable[4];
	for(int i = 0; i < discs.size(); ++i){
		if(picked & (1 << i)){ continue; }
		if(discs[i].depend & ~picked){ continue; }
		pickable[discs[i].c - 1].push_back(i);
	}
	int result = __builtin_popcount(picked);
	for(int i = 0; i < 4; ++i){
		for(int j = 0; j < pickable[i].size(); ++j){
			for(int k = 0; k < j; ++k){
				int pick = (1 << pickable[i][j]) | (1 << pickable[i][k]);
				result = max(result, recur(discs, picked | pick));
			}
		}
	}
	memo[picked] = result;
	return result;
}

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<Disc> discs(n);
		for(int i = 0; i < n; ++i){
			cin >> discs[i].x >> discs[i].y >> discs[i].r >> discs[i].c;
		}
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < i; ++j){
				int x = discs[i].x - discs[j].x;
				int y = discs[i].y - discs[j].y;
				int r = discs[i].r + discs[j].r;
				if(x * x + y * y < r * r){
					discs[i].depend |= (1 << j) | discs[j].depend;
				}
			}
		}
		memo.clear();
		cout << recur(discs, 0) << endl;
	}
	return 0;
}

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

unordered_map<ll, bool> M;
bool l[5][5];
ll s[10];
int h, w, n;

inline bool getv(ll x, ll y)
{
    ll v = (x << 32) | y;
    return M.find(v) != M.end();
}

inline void setv(ll x, ll y)
{
    ll v = (x << 32) | y;
    M[v] = true;
}

inline bool good(int x, int y)
{
    return x >= 0 && y >= 0 && x < h && y < w;
}

int main()
{
    cin >> h >> w >> n;
    s[0] = (ll) (h - 2) * (w - 2);
    for (int k = 0; k < n; ++k)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        setv(a, b);
        memset(l, 0, sizeof l);
        for (int i = a - 2; i <= a + 2; ++i)
            for (int j = b - 2; j <= b + 2; ++j)
                if (good(i, j))
                    l[i - (a - 2)][j - (b - 2)] = getv(i, j);

        for (int i = 0; i < 3; ++i)
        {
            for (int j = 0; j < 3; ++j)
            {
                if (!good(a - 2 + i, b - 2 + j) ||
                    !good(a + i, b + j))
                    continue;

                int cnt = 0;
                for (int p = i; p < i + 3; ++p)
                    for (int q = j; q < j + 3; ++q)
                        cnt += (int)l[p][q];

                s[cnt - 1]--;
                s[cnt]++;
            }
        }
    }
    for (int k = 0; k < 10; ++k)
        cout << s[k] << '\n';
}


Measured memory_bytes: 4388
#include <stdio.h>
#include <string.h>
char s[100010];
int a[100010];
int main()
{
	int n, k;
	int d = 0;
	scanf("%d", &n);
	scanf("%d\n", &k);
	gets(s);
	int i,  c;
	int b;
	int l;
	memset(a, 0, sizeof(a));
	b = 0;
	c = 0;
	i = 0;
	while (i < n-1)
	{
		if (s[i] != s[i + 1])
		{
			a[b] = i + 1;
			if ((b>0)&&((b%2)!=0))
			{
				d = a[b-1];
				while (d < a[b])
				{
					s[d] = s[d - 1];
					d++;
				}
				c++;
				if (c >= k)
					break;
			}
			b++;
		}
		i++;
	}
	if (c < k)
	{
		d = a[b - 1];
		while (d < n)
		{
			s[d] = s[d - 1];
			d++;
		}

	}
	d = 0;
	l = 0;
	while (d < n - 1)
	{
		if (s[d] == s[d + 1])
			l++;
		d++;
	}
	printf("%d\n", l);
	return 0;
}

Measured memory_bytes: 2228
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

ll pow_n(ll l, ll n, ll p)
{
    if (l > 1000000 && n >= 2)
        return -1;

    ll ret{1};

    for (ll i = 0; i < n; ++i)
    {
        ret *= l;
        if (ret > p || ret < 0)
        {
            ret = -1;
            break;
        }
    }

    return ret;
}

int main()
{
    using namespace std;

    ll n, p;

    cin >> n >> p;

    if (n == 1)
    {
        cout << p << endl;
        return 0;
    }

    ll ans{1};
    for (ll i = 2; pow_n(i, n, p) > 0; ++i)
    {
        auto po = pow_n(i, n, p);
        if (p % po == 0)
            ans = i;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*input
1 30
3 5 10 30
*/

#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, m, ans = 0;
	scanf("%d%d", &n, &m);
	vector<int> cnt(m + 1);
	for (int i = 0; i < n; i++) {
		int k;
		scanf("%d", &k);
		for (int j = 0; j < k; j++) {
			int num;
			scanf("%d", &num);
			cnt[num]++;
			ans += (cnt[num] == n);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int B = X / 500;
        int S = (X - B * 500) / 5;
        System.out.print((B * 1000)  +  (S * 5)); 
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
ll cnt = 0;
vi G;
inline void insertionSort(vi& a, int n, int g) {
	rep(i, g, n) {
		int v = a[i];
		int j = i - g;
		while(j >= 0 && a[j] > v) {
			a[j + g] = a[j];
			j -= g;
			++cnt;
		}
		a[j + g] = v;
	}
}
inline void shellSort(vi& a, int n) {
	for (int h = 1; h <= n; h = h * 3 + 1) {
		G.eb(h);
	}
	rrep(i, len(G) - 1, -1) {
		insertionSort(a, n, G[i]);
	}
}
int main() {
	int n; cin >> n;
	vi v(n); rep(i, 0, n) cin >> v[i];
	shellSort(v, n);
	P(len(G));
	rrep(i, len(G) - 1, -1) cout << G[i] << (i == 0 ? "\n" : " ");
	P(cnt);
	rep(i, 0, len(v)) P(v[i]);
	return 0;
}

Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  int n,w;
  cin >>n>>w;
  vector<int> wei(n+1);
  vector<int> val(n+1);
  rep1(i,n) cin >>wei[i]>>val[i];
  vector<vector<ll>> dp(n+1, vector<ll>(w+1));
  rep1(i,n){
    rep1(j,w){
      ll tmp;
      if(j < wei[i]) tmp = 0;
      else tmp = dp[i-1][j-wei[i]]+val[i];
      dp[i][j] = max(tmp,dp[i-1][j]);
    }
  }
  cout << dp[n][w] << endl;
}

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

int main()
{
    int n;
    int s1, s2, s3, s4;

    cin >> n;
    s1 = s2 = s3 = s4 = 0;
    rep(i, n) {
        string s;
        cin >> s;
        if (s == "AC")
            ++s1;
        else if (s == "WA")
            ++s2;
        else if (s == "TLE")
            ++s3;
        else if (s == "RE")
            ++s4;
    }

    cout << "AC x " << s1 << endl;
    cout << "WA x " << s2 << endl;
    cout << "TLE x " << s3 << endl;
    cout << "RE x " << s4 << endl;

    return 0;
}


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

string map[20];
int count,W,H;
int walk(int ,int);

int main(){
	int i,j;
	while(cin >> W >> H,(W || H)){
		count=0;
		for(i=0;i<H;i++) cin >> map[i];
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if(map[i][j]=='@') goto LOOP;
			}
		}
	LOOP:
		walk(i,j);
	cout << count << endl;
	}

}

int walk(int a,int b){
	map[a][b] = '#';
	count++;
	if(a+1<H && map[a+1][b]  == '.') walk(a+1,b);
	if(b+1<W && map[a][b+1]  == '.') walk(a,b+1);
	if(a-1>=0 && map[a-1][b]  == '.') walk(a-1,b);
	if(b-1>=0 && map[a][b-1]  == '.') walk(a,b-1);
	return 0;
}

Measured memory_bytes: 1232
c = []

for i in range(3):
  tmp = list(map(int,input().split()))
  c.append(tmp)

diff = c[0][1] - c[0][0]
if c[1][1] - c[1][0] == diff and c[2][1] - c[2][0] == diff:
  #next
  diff = c[0][2] - c[0][1]
  if c[1][2] - c[1][1] == diff and c[2][2] - c[2][1] == diff:
    #next
    diff = c[0][0] - c[0][2]
    if c[1][0] - c[1][2] == diff and c[2][0] - c[2][2] == diff:
      print("Yes")
    else:
      print("No")

  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 3064
def main():
    N = int(input())
    B = [int(x) for x in input().split()]
    B.append(2**31)
    ans = B[0]
    for i in range(N-1):
        ans += min(B[i], B[i+1])
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
a,b,c=map(int,input().split())
k=int(input())

def dfs(a,b,c,k):
    if k==0:
        if a<b<c:
            print("Yes")
            exit()
    else:
        dfs(a,2*b,c,k-1)
        dfs(a,b,2*c,k-1)
dfs(a,b,c,k)
print("No")

Measured memory_bytes: 61872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main() {
    ll X, x = 100; cin >> X;
    ll i = 0;
    while (x < X) {
        x = ll(x * 1.01);
        i++;
    }
    cout << i << endl;
}

Measured memory_bytes: 3632
from heapq import heappop, heappush
INF = 10 ** 18

def dijkstra(s):
    used = [1] * n
    dp = [INF] * n
    dp[s] = 0
    hq = []
    used[s] = 0
    for i in cost[s]:
        heappush(hq, i)

    while hq:
        minv = heappop(hq)
        if used[minv[1]] == 0:
            continue
        v = minv[1]
        dp[v] = minv[0]
        used[v] = 0
        for i in cost[v]:
            if used[i[1]]:
                heappush(hq, [i[0] + dp[v], i[1]])
    return dp

n, u, v = map(int, input().split())
cost = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    cost[a].append([1, b])
    cost[b].append([1, a])

dp1 = dijkstra(v - 1)
dp2 = dijkstra(u - 1)
ans = 0
for i in range(n):
    if dp1[i] >= dp2[i]:
        ans = max(ans, dp1[i])

print(ans - 1)


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

bool comp(int a, int b)
{
    return a > b;
}

int main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    int p[a], q[b], r[c];
    for (int i = 0; i < a; i++) cin >> p[i];
    for (int i = 0; i < b; i++) cin >> q[i];
    for (int i = 0; i < c; i++) cin >> r[i];
    sort(p, p + a, comp);
    sort(q, q + b, comp);
    sort(r, r + c, comp);
    queue<int> app1, app2, app3;
    for (int i = 0; i < x; i++) app1.push(p[i]);
    for (int i = 0; i < y; i++) app2.push(q[i]);
    for (int i = 0; i < c; i++) app3.push(r[i]);

    long long sum = 0;
    int cnt = x + y;
    int mx = 0;
    for (int i = 0; i < cnt; i++) {
        if (!app1.empty() && app1.front() > mx) mx = app1.front();
        if (!app2.empty() && app2.front() > mx) mx = app2.front();
        if (!app3.empty() && app3.front() > mx) mx = app3.front();
        if (!app1.empty() && mx == app1.front()) app1.pop();
        else if (!app2.empty() && mx == app2.front()) app2.pop();
        else if (!app3.empty()) app3.pop();
        sum += mx;
        mx = 0;
    }
    cout << sum << "\n";
}


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

int main(){
  ll n;
  cin >> n;
  deque<ll> A;
  deque<ll> B;
  bool judge;
  rep(i, n){
    ll a;
    cin >> a;
    if (i % 2 == 0) A.push_front(a);
    else A.push_back(a);
  }
  
  if (n % 2 == 0) reverse(A.begin(), A.end());
  
  for (auto p : A) cout << p << " ";
  cout << endl;
}

Measured memory_bytes: 3840
N = gets.to_i
f_list = N.times.map do
  gets.split.map(&:to_i)
end
p_list = N.times.map do
  gets.split.map(&:to_i)
end

max = -(2 << 60)
(1..(2 ** 10 - 1)).each do |n|
  sum = 0
  N.times.map do |s|
    count = 10.times.count do |i|
      n[i] == 1 && f_list[s][i] == 1
    end
    sum += p_list[s][count]
  end
  max = [max, sum].max
end
puts max


Measured memory_bytes: 1916
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    set<string> st;
    REP(i,n){
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 19160
s = input()
s_base = int(s.replace('?', '0'))
digit = reversed(list(s))
sumd = 0
s10 = 4 # Before 1
hatena = []
for i, x in enumerate(digit):
    s10 = (10 * s10) % 13
    if x == '?':
        hatena.append(s10)
    else:
        sumd += int(x) * s10
        sumd %= 13

# sum( hatena[i] * x ) を満たすxの組み合わせを求める
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(len(hatena) + 2)]
# dp[i][x] hatena[:i]の和を13で割った余りがxである整数の数
dp[0][0] = 1

for i in range(len(hatena)):
    for x in range(13):
        for num in range(10):
            j = (x + num*hatena[i]) % 13
            dp[i+1][j] += dp[i][x]
            dp[i+1][j] %= mod

print(dp[len(hatena)][(5-sumd)%13])
"""
print(hatena)
print(sumd)
print(dp)
"""


Measured memory_bytes: 67592
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

pair<int, int> check2(string line) {
	for(int i = 0; i < line.length() - 1; i++) {
		if(line[i] == line[i+1]) {
			return make_pair(i + 1, i + 2);
		}
	}
	return make_pair(-1, -1);
}

pair<int, int> check3(string line) {
	for(int i = 0; i < line.length() - 2; i++) {
		if(line[i] == line[i+2]) {
			return make_pair(i + 1, i + 3);
		}
	}
	return make_pair(-1, -1);
}

int main() 
{
	string line;
	getline(cin, line);

	// "xx" or "xox"のパターンが属しているしかありえない
	// xx
	pair<int,int> pos_check2 = check2(line);
	pair<int, int> pos_check3 = check3(line);
	if(pos_check2.first >= 0) {
		cout << pos_check2.first << " " << pos_check2.second << endl;
	} else if(pos_check3.first >= 0) {
		cout << pos_check3.first << " " << pos_check3.second << endl;
	} else {
		cout << -1 << " " << -1 << endl;
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>

std::vector<int> vec;

int rem(int a, int b)
{
    int r;
    for (int i = 0; i < 3; ++i)
    {
        if (i != a && i != b)
            r = i;
    }

    return r;
}

int main()
{

    int n;

    std::cin >> n;

    long long int r = 0, g = 0, b = 0;

    for (int i = 0; i < n; ++i)
    {
        char ch;
        std::cin >> ch;
        if (ch == 'R')
        {
            vec.push_back(0);
            ++r;
        }
        else if (ch == 'G')
        {
            vec.push_back(1);
            ++g;
        }
        else
        {
            vec.push_back(2);
            ++b;
        }
    }

    long long int sum = r * g * b;

    for (int i = 0; i < n; ++i)
    {
        for (int j = i; j * 2 - i < n; ++j)
        {
            int k = j * 2 - i;

            if (vec[i] != vec[j] && rem(vec[i], vec[j]) == vec[k])
                --sum;
        }
    }

    std::cout << sum << std::endl;

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
int main()
{
    Imposter
    
    ll n;
    cin>>n;
    string str;
    cin>>str;int k,j;
    for( k=n-1;k>=0;k--)
    {
        if(str[k]=='W')
        continue;
        else
        break;
    }
    for(j=0;j<n;j++)
    {
        if(str[j]=='R')
        continue;
        else
        break;
    }
    ll ans=0;
    for(int i=j;i<=k;i++)
    {
        if(str[i]=='W')
        {
            int flag=0;
            for(int l=k;l>=i;l--)
            {
                k--;
                if(str[l]=='R')
                {
                    str[i]='R';
                    str[l]='W';
                    //cout<<i<<" "<<l<<endl;
                    ans++;
                    flag=1;
                    break;
                }
            }
            if(!flag)
            break;
        }
    }
    cout<<ans<<endl;
    
    
    return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"
const int N = 1e6 + 10;


signed main()
{
    FAST;
    int t;
    t=1;
    
    while(t--)
    {
        int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
        int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
        int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
        int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
        int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
        
        cin>>n;
        int a[n];
        map<int,int> mp,mp1;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            mp[a[i]]++;
        }
        
        ans=0;
        
        for(auto it : mp)
        {
            int num = it.first;
            count = it.second;
            if(num==1)
            {
                if(count==1)
                {
                    cout<<1<<endl;
                }
                
                else
                {
                    cout<<0<<endl;
                }
                return 0;
            }
            if(count==1 && mp1.count(num)==0)
            {
                ans++;
            }
            
            if(mp1.count(num)==0)
            {
                for(i=2;i*num<N;i++)
                {
                    mp1[i*num]++;
                }
            }
            
        }
        
        cout<<ans<<endl;
        
        
    }
        
    
    
    
    
}

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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long n, k;
        cin >> n >> k;

        long ans = n % k;
        ans = min(ans, k - ans);
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 3728
num = int(input())
numList = list(map(int, input().split()))
max = 1000000000000000000
flg = True
result = 1

if 0 in numList:
    print(0)
else:
    for i in range(num):
        result *= numList[i]
        if result > max:
            flg = False
            break
    if flg:
        print(result)
    else:
        print(-1)


Measured memory_bytes: 21632
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    cin >> a;
    int ans = a + a*a + a*a*a;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656