akhauriyash/Code-Regression huggingface dataset:
use proconio::input;

fn main() {
    input! {
        n: usize,
        t: usize,
        ct: [(usize, usize); n],
    };
    let inf = 1_000_000;
    let mut ans = inf;
    for &(c_i, t_i) in ct.iter() {
        if t_i <= t {
            ans = std::cmp::min(ans, c_i);
        }
    }
    if ans == inf {
        println!("TLE");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 2160
#include <cstdio>

#define M 100000
int A[M], n;

int partition(int p, int r) {
	int j, t, x = A[r], i = p-1;
	for(j=p; j<r; ++j) {
		if(A[j] <= x) {
			++i;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i+1]; A[i+1] = A[r]; A[r] = t;
	return i+1;
}

int main() 
{
	int i, q;
	scanf("%d", &n);
	for(i=0; i<n; ++i) scanf("%d", &A[i]);

	q = partition(0, n-1);
	for(i=0; i<n; ++i) {
		if(i) printf(" ");
		if(i == q) printf("[");
		printf("%d", A[i]);
		if(i == q) printf("]");
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 2956
#include<bits/stdc++.h>
 
using namespace std;
typedef unsigned long long int ll;
const ll hell = 100005; 
bool comp(vector<ll> a, vector<ll> b)
{
    return a[0]<b[0];
}
ll binpow(ll a,ll b) 
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    for(ll i=0; i<s.length()-1; i++)
    {
        if(s[i]!=s[i+1]){
            cout<<"Yes";
            exit(0);
        }
    }
    cout<<"No";
    return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

int a[6];

int main() {
    for (int i = 1; i <= 5; i++) scanf("%d", &a[i]);
    int res = inf;
    do {
        int tmp = 0;
        for (int i = 1; i < 5; i++) {
            tmp += (a[i] / 10 * 10 + (a[i] % 10 == 0 ? 0 : 10));
        }
        tmp += a[5];
        res = min(res, tmp);
    } while (next_permutation(a + 1, a + 6));
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}


int N;
ll A[200010];
ll fsum[200010];
ll bsum[200010];
ll dp[3][200010];
bool flag[3][200010];

ll ans = 0;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
        dp[0][i] = -linf;
        dp[1][i] = -linf;
        dp[2][i] = -linf;
    }
    for(int i = 1; i <= N; i++){
        fsum[i] += A[i];
        fsum[i + 2] = fsum[i];
    }
    for(int i = N; i >= 1; i--){
        bsum[i] = bsum[i + 2];
        bsum[i] += A[i];
    }
    ans = max(fsum[N - 1], bsum[2]);
    
    for(int i = 0; i < N; i++){
        ll res = fsum[i] + bsum[i + 2];
        int cnt = (i + 1) / 2;
        cnt += (N - i) / 2;
        if(cnt == N / 2) chmax(ans, res);
    }
    for(int i = 0; i < N; i++){
        ll res = fsum[i] + bsum[i + 3];
        int cnt = (i + 1) / 2;
        cnt += (N - i - 1) / 2;
        if(cnt == N / 2) chmax(ans, res);
    }
    for(int i = 0; i < N; i++){
        ll res = fsum[i] + bsum[i + 4];
        int cnt = (i + 1) / 2;
        cnt += (N - i - 2) / 2;
        if(cnt == N / 2) chmax(ans, res);
    }

    flag[0][1] = true;
    flag[1][2] = true;
    flag[2][3] = true;
    dp[0][1] = 0;
    dp[1][2] = 0;
    dp[2][3] = 0;
    for(int i = 1; i <= N; i++){
        if(flag[0][i]){
            dp[0][i] += A[i];
            chmax(dp[0][i + 2], dp[0][i]);
            chmax(dp[1][i + 3], dp[0][i]);
            chmax(dp[2][i + 4], dp[0][i]);
            flag[0][i + 2] = true;
            flag[1][i + 3] = true;
            flag[2][i + 4] = true;
        }
        if(flag[1][i]){
            dp[1][i] += A[i];
            chmax(dp[1][i + 2], dp[1][i]);
            chmax(dp[2][i + 3], dp[1][i]);
            flag[1][i + 2] = true;
            flag[2][i + 3] = true;

        }
        if(flag[2][i]){
            dp[2][i] += A[i];
            chmax(dp[2][i + 2], dp[2][i]);
            flag[2][i + 2] = true;
        }
    }

    if(N % 2 == 1){
        chmax(ans, dp[2][N]);
        chmax(ans, dp[1][N - 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13620
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N =iRaw()
    As = isRaw()
    ans = [1 if i%2==0 and k%2==1 else 0 for i,k in enumerate(As)]
    print(sum(ans))

main()


Measured memory_bytes: 67600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
inline int popcount(const int x) { return __builtin_popcount(x);}
inline ll popcount(const ll x) { return __builtin_popcountll(x);}
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

map<ll, int> mp;

int dfs(ll y) {
  if (y == 0) return 0;
  if (y == 0) return 1;
  if (mp.count(y)) return mp[y];
  ll next = y % popcount(y);
  mp[y] = dfs(next) + 1;
  return mp[y];
}

int main() {
  int n;
  string X;
  cin >> n >> X;
  int cnt = 0;
  rep(i, n) {
    if (X[i] == '1') cnt++;
  }
  ll modpop1 = 0, modpop2 = 0;
  ll two1 = 1;
  for (int i = n-1; i >= 0; --i) {
    if (cnt-1 == 0) break;
    if (X[i] == '1') {
      modpop1 += two1;
      modpop1 %= (cnt-1);
    }
    two1 *= 2LL; two1 %= (cnt-1);
  }
  ll two2 = 1;
  for (int i = n-1; i >= 0; --i) {
    if (X[i] == '1') {
      modpop2 += two2;
      modpop2 %= (cnt+1);
    }
    two2 *= 2LL; two2 %= (cnt+1);
  }

  // debug(modpop1, modpop2);
  two1 = 1LL, two2 = 1LL;
  vector<int> ans(n);
  for (int i = n-1; i >= 0; --i) {
    ll y = 0;
    if (X[i] == '1') {
      if (cnt-1 == 0) {
        ans[i] = 0; continue;
      }
      y = modpop1 - two1;
      y %= (cnt-1);
      if (y < 0) y += ll(cnt-1);
    }
    else {
      y = modpop2 + two2;
      y %= (cnt+1);
    }
    if (cnt-1 != 0) {
      two1 *= 2LL; two1 %= (cnt-1);
    }
    two2 *= 2LL; two2 %= (cnt+1);
    ans[i] = dfs(y) + 1;
    // debug(y, ans[i]);
  }
  rep(i,n) cout << ans[i] << "\n";
  return 0;
}

Measured memory_bytes: 5656
N = 6
a = [int(input()) for i in range(N)]
p = [a[0],0,0,0,0,0]
count = 0
b = min(a)
if a[0] <= b:
    ans = 5
else:
    ans = -1*(-1*a[0] // b) + 4
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n, inf = 1000000000, N = 200001;
    cin >> n;
    int ans = inf;
    vector<set<int> > U(N), D(N), R(N), L(N);
    vector<vector<set<int> > > u(2, vector<set<int> > (N*2));
    vector<vector<set<int> > > d(2, vector<set<int> > (N*2));
    vector<vector<set<int> > > r(2, vector<set<int> > (N*2));
    vector<vector<set<int> > > l(2, vector<set<int> > (N*2));
    int a, b;
    char c;
    for(int i=0;i<n;i++){
    	cin >> a >> b >> c;
    	if(c == 'U'){
    		U[a].insert(b);
    		u[0][b - a + N].insert(a);
    		u[1][a + b].insert(a);
    	}
    	if(c == 'D'){
    		D[a].insert(b);
    		d[0][b - a + N].insert(a);
    		d[1][a + b].insert(a);
    	}
    	if(c == 'R'){
    		R[b].insert(a);
    		r[0][b - a + N].insert(a);
    		r[1][a + b].insert(a);
    	}
    	if(c == 'L'){
    		L[b].insert(a);
    		l[0][b - a + N].insert(a);
    		l[1][a + b].insert(a);
    	}
    }
    for(int i=0;i<N;i++){
    	for(auto& j: U[i]){
    		if(D[i].lower_bound(j) == D[i].end()) continue;
    		ans = min(ans, (*(D[i].lower_bound(j)) - j) * 5);
    	}
    	for(auto& j: R[i]){
    		if(L[i].lower_bound(j) == L[i].end()) continue;
    		ans = min(ans, (*(L[i].lower_bound(j)) - j)* 5);
    	}
    }
    for(int i=0;i<N*2;i++){    	
    	for(auto& j : d[0][i]){
    		auto itr = r[0][i].lower_bound(j);
    		if(itr != r[0][i].begin()){
    			itr--;
    			ans = min(ans, (j - *itr) * 10);
    		}
    	}
    	for(auto& j : d[1][i]){
    		auto itr = l[1][i].lower_bound(j);
    		if(itr != l[1][i].end()){
    			ans = min(ans, (*itr - j) * 10);
    		}
    	}
    	for(auto& j : u[0][i]){
    		auto itr = l[0][i].lower_bound(j);
    		if(itr != l[0][i].end()){
    			ans = min(ans, (*itr - j) * 10);
    		}
    	}
    	for(auto& j : u[1][i]){
    		auto itr = r[1][i].lower_bound(j);
    		if(itr != r[1][i].begin()){
    			itr--;
    			ans = min(ans, (j - *itr) * 10);
    		}
    	}
    }
    if(ans == inf) cout << "SAFE" << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 218820
a={0}
_,*s=range(10)
while s:
  v=s.pop()
  a|={v}
  for w in range(max(0,v%10-1),min(10,v%10+2)):
    w+=v*10
    if w<4e9:s+=w,
print(sorted(a)[int(input())])

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

int main(){
  string s; cin>>s;

  for(int i=0; i<s.size()-2; i++){
    if(s[i] == s[i+1] || s[i+2] == s[i+1] || s[i] == s[i+2]){
      
      cout<<i+1<<" "<<i+3<<endl;
      return 0;
      
    }
  }

  if(s.size() == 2 && s[0] == s[1]){
    
    cout<<1<<" "<<2<<endl;
    return 0;
    
  }

  cout<<-1<<" "<<-1<<endl;

  return 0;
  
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N;
  cin >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> dp(N, INF);
  dp[0] = 0;

  REP(i, N-1){
    chmin(dp[i+1], dp[i]+abs(A[i+1]-A[i]));
    if(i+2 < N) chmin(dp[i+2], dp[i]+abs(A[i+2]-A[i]));
  }

  cout << dp[N-1] << "\n";

  return 0;
}

Measured memory_bytes: 1792
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"2017/12/01"# => "2018/12/01",
// r#"5"# => "43",
// r#"21"# => "27",
// r#"24"# => "No",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
        mut d: [usize; n],
    }
    d.sort();
    d.dedup();
    d.len().to_string()
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,A,B,C,i;
    string S;
    cin >> N >> A >> B >> C;
    char ans[N];
    bool flag=1;
    for(i=0;i<N;i++){
        if(flag)cin >> S;
        flag=1;
        if(S=="AB"){
            if(A==B){
                if(A==0){
                    cout << "No";
                    return 0;
                }else {
                    flag=0;
                    if(i==N-1){
                        ans[i]='A';B--;A++;    
                    }else{
                        cin >> S;
                        if(S=="AC"){
                            ans[i]='A';B--;A++;
                        }else{
                            ans[i]='B';A--;B++;
                        }
                    }
                }
            }else if(A>B){
                ans[i]='B';A--;B++;
            }else {
                ans[i]='A';B--;A++;
            }
        }else if(S=="BC"){
            if(B==C){
                if(B==0){
                    cout << "No";
                    return 0;
                }else{
                    flag=0;
                    if(i==N-1){
                        ans[i]='C';B--;C++;    
                    }else{
                        cin >> S;
                        if(S=="AC"){
                            ans[i]='C';B--;C++;
                        }else{
                            ans[i]='B';C--;B++;
                        }
                    }
                }
            }else if(B>C){
                ans[i]='C';B--;C++;
            }else{
                ans[i]='B';C--;B++;
            }
        }else if(S=="AC"){
            if(A==C){
                if(A==0){
                    cout << "No";
                    return 0;
                }else {
                    flag=0;
                    if(i==N-1){
                        ans[i]='A';C--;A++;    
                    }else{
                        cin >> S;
                        if(S=="AB"){
                            ans[i]='A';C--;A++;
                        }else{
                            ans[i]='C';A--;C++;
                        }
                    }
                }
            }else if(A>C){
                ans[i]='C';A--;C++;
            }else {
                ans[i]='A';C--;A++;
            }
        }
    }
    cout << "Yes"<<endl;
    for(i=0;i<N;i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define VI vector<int>
#define pb push_back
#define LL long long
#define mp make_pair
#define pii pair<int,int>
using namespace std;
string days[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main(){
	string x;
	cin>>x;
	int d = 0;
	for(int i = 0; i < 8; i++){
		if(days[i] == x){
			d = i;
			break;
		}
	}
	d = (d + 1)%7;
	int dif = 1;
	for(; days[d%7] != "SUN"; d++, dif++);
	printf("%d\n", dif);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()

int main() {
		int X;
		cin >> X;
		int pos = 0;
		for (int t = 1; t < 2*X; t++) {
				pos += t;
				if (pos >= X) {
						cout << t << endl;
						return 0;
				}
		}
		return 0;
}


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

int main()
{
    int     n;  
    string  s;  
    map<string, int> mp; 
    cin>>n;
    int max_c = 0;
    
    for (int i = 0; i < n; i++)
    {   
        cin>>s;
        mp[s]++;
        max_c = max(max_c, mp[s]);
    }   

    for (auto p : mp) 
    {   
        if (p.second == max_c)
        {   
            cout<<p.first<<endl;
        }   
    }   
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

const ll mod = 1e9 + 7;


struct ModComb {
    vector<long long> fact, rfact;
    long long max, mod;
    ModComb(long long ma, long long mod) :fact(ma, 0), rfact(ma, 0), max(ma), mod(mod) {
        fact[0] = 1;
        for (long long i=1; i<max; ++i) {
            fact[i] = fact[i-1]*i;
            fact[i] %= mod;
        }
        rfact[max-1] = mod_inverse(fact[max-1], mod);
        for (long long i=max-2; i>=0; --i) {
            rfact[i] = rfact[i+1]*(i+1);
            rfact[i] %= mod;
        }
    }
    long long mod_pow(long long x, long long n, long long mod) {
        long long a = 1LL;
        while (n) {
            if (n%2) a = ((a%mod)*(x%mod))%mod;
            x = ((x%mod)*(x%mod))%mod;
            n /= 2LL;
        }
        return a;
    }

    long long mod_inverse(long long a, long long m) {
        return mod_pow(a, m-2, m);
    }

    long long operator()(long long n, long long r) {
        if (n < r) return 0;
        return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
    }
};

ll dp[2020][2020];

int main() {
    ll N, K;
    cin >> N >> K;

    ModComb mb(2001, mod);

    ll ans = 1;
    rep(i, K) {
        cout << mb(N-K+1, i+1) * mb(K-1, i) % mod << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int N, M, C, a, b;
  cin >> N >> M >> C;
  int ans = 0;
  vector<int> arrB(M);
  vector<vector<int>> arrA(N, vector<int>(M));

  for (int i = 0; i < M; i++){
    cin >> b;
    arrB.at(i) = b;
  }

  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++) {
      cin >> a;
      arrA.at(i).at(j) = a;
    }
  }

  for (int i = 0; i < N; i++){
    int num = 0;
    for (int j = 0; j < M; j++) {
      num += arrB.at(j) * arrA.at(i).at(j);
    }
    num += C;
    if(num > 0) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

typedef long long ll;

int main(){
	ll x, y; cin >> x >> y;
	vector<ll> v;
	while (x <= y) {
		v.push_back(x);
		x *= 2;
	}
	cout << v.size();
	return 0;
}

Measured memory_bytes: 256
n,*a=map(int,open(0).readlines())
a.sort()
if n%2:
  b=a[:n//2]
  c=a[n//2:]
  for i in range(n//2):
    b[i]*=2
  for i in range(2,n//2+1):
    c[i]*=2
  m=sum(c)-sum(b)
  b=a[:n//2+1]
  c=a[n//2+1:]
  for i in range(n//2-1):
    b[i]*=2
  for i in range(n//2):
    c[i]*=2
  m=max(m,sum(c)-sum(b))
else:
  b=a[:n//2]
  c=a[n//2:]
  for i in range(n//2-1):
    b[i]*=2
  for i in range(1,n//2):
    c[i]*=2
  m=sum(c)-sum(b)
print(m)

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    vll accs(s.size()+1, 0), acct(t.size()+1);
    REP(i, s.size()) {
        if (s[i] == 'A') accs[i+1] = accs[i] + 1;
        else accs[i+1] = accs[i] + 2; 
    }
    REP(i, t.size()) {
        if (t[i] == 'A') acct[i+1] = acct[i] + 1;
        else acct[i+1] = acct[i] + 2; 
    }
    ll q; cin >> q;
    ll a, b, c, d;
    REP(_, q) {
        cin >> a >> b >> c >> d;
        if ((accs[b]-accs[a-1])%3 == (acct[d]-acct[c-1])%3) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}


Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
int solve(vector<int> &arr, int n) {
	int pre1 = abs(arr[1]-arr[0]), pre2 = 0, ans = pre1;
	for(int i = 2; i < n; i++) {
		ans = min(abs(arr[i]-arr[i-1])+pre1, abs(arr[i]-arr[i-2])+pre2);
		pre2 = pre1;
		pre1 = ans;
	}
	return ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin >> n;
	vector<int> arr(n);
	for(int i = 0; i < n; i++) cin >> arr[i];
	cout << solve(arr, n) << endl;
}

Measured memory_bytes: 3700
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stack>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[1111111];
int main()
{
	ios::sync_with_stdio(false);
	ll n;	cin>>n;
	ll xx=0;
	ll yy=0;
	ll zz=0;
	ll sum=0;
	string ss[111111];
	
	for(ll i=0;i<n;i++)
	{
		string s;	cin>>s;
		if(s[0]=='B'&&s[s.size()-1]=='A')
		{
//			ss[zz][0]='B';
//			ss[zz][1]='A';
			zz++;
		}
		if(s[0]=='B'&&s[s.size()-1]!='A')
			xx++;	
		if(s[0]!='B'&&s[s.size()-1]=='A')
			yy++;
		for(ll j=0;j<s.size()-1;j++)
		{
			if(s[j]=='A'&&s[j+1]=='B')
				sum++;
		}
		
	}
	//cout<<sum;
	int xx1=0;
	int yy1=0;
	if(zz)
	{
		sum=sum+zz-1;
		if(xx)
			yy1=1;
		if(yy)
			xx1=1;	
	}
	xx=xx+xx1;
	yy=yy+yy1;
	sum=sum+min(xx,yy);
	cout<<sum<<endl;
	return 0;
}



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

using namespace std;

int r;

int main(void)
{
	cin >> r;
	if(r < 1200) cout << "ABC" << endl;
	else if(r < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return (ll)1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
 ios::sync_with_stdio(false);
 string s;
 cin>>s;

 cout<<s[0]<<s[1]<<s[2]<<endl;



return 0;
}




Measured memory_bytes: 3644
n = int(input())
s = input().split()
for i, x in enumerate(s):
    s[i] = int(x)
q = int(input())
t = input().split()
for i, x in enumerate(t):
    t[i] = int(x)

c = 0
for x_t in t:
    for x_s in s:
        if x_t == x_s:
            c += 1
            break

print(c)


Measured memory_bytes: 6060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
  int n;
  cin >> n;
  int ab=0, bxa=0, bxx=0, xxa=0;
  rep(i,n) {
    string s;
    cin >> s;
    for(int j=0; j<s.size()-1; j++) {
      if(s[j]=='A'&&s[j+1]=='B') ab++;
    }
    if(s[0]=='B'&&s[s.size()-1]=='A') bxa++;
    else if(s[0]=='B') bxx++;
    else if(s[s.size()-1]=='A') xxa++;
  }
  if(bxa+xxa+bxx==0) {
    cout << ab << endl;
  }
  else if(xxa+bxx==0) {
    cout << ab+bxa-1 << endl;
  }
  else {
    cout << ab+bxa+min(xxa,bxx) << endl;
  }
  return 0;
}

Measured memory_bytes: 3604
N=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            T=[L[i],L[j],L[k]]
            T.sort()
            if T[2]<T[0]+T[1] and T[0]<T[1] and T[1]<T[2]:
                #print(i,j,k)
                ans+=1
print(ans)

Measured memory_bytes: 68332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
ll n;
int main()
{
    ll mid=0;
    cin>>n;
    ans=(n+1)*n/2;
   // cout<<ans<<endl;
    for(int i=1;i<=n;i++){
        if(i%3==0||i%5==0) mid+=i;
    }
   // cout<<mid<<endl;
    ans=ans-mid;
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v = 0 ; v < n ; v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int u;
  for(u = 0 ; u < n ; u++) color[u] = WHITE;
  tt = 0;

  for(u = 0 ; u < n ; u++){
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(u = 0 ; u < n ; u++){
    printf("%d %d %d\n",u + 1, d[u], f[u]);
  }
}

int main(){
  int u, v, k, i, j;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++) M[i][j] = 0;
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int x,y,z; cin >> x >> y >> z;
	swap(x,y);
	swap(x,z);
	cout << x << " " << y << " " << z << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B,C;
  cin>>A>>B>>C;
  int sum=A+B+C;
  int X[3]={A,B,C};
  sort(X,X+3);
  if(3*X[2]%2==sum%2)
  {
    cout<<(3*X[2]-sum)/2<<endl;
  }else{
    cout<<(3*X[2]+3-sum)/2<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const double PI = 3.14159265359;

int main(){
    double A,B,H,M;

    cin >> A >> B >> H >> M;

    double ha = ((H + M / 60)/ 12) * 2 * PI;
    double ma = (M / 60) * 2 * PI;
    double ax = cos(ha) * A;
    double ay = sin(ha) * A;
    double bx = cos(ma) * B;
    double by = sin(ma) * B;

    cout << fixed << setprecision(12) << sqrt(pow(ax - bx,2) + pow(ay - by,2)) << endl;

    return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;
int cnt = 0;
ll n;
/*vector<string> p;

void dfs(ll a) {
    if(a <= n) {
        cnt++;
        p.pb(to_string(a));


    if(a * 10 + 3 <= n) dfs(a * 10 + 3);
    if(a * 10 + 5 <= n) dfs(a * 10 + 5);
    if(a * 10 + 7 <= n) dfs(a * 10 + 7);
    }   
}


int main(){
    cin >> n;
    int ans = 0;
    dfs(0);
    for(int i = 0;i < cnt;i++){
        int si = p[i].size();
        string s = p[i];
        bool ok3 = false, ok5 = false, ok7 = false;
        for(int j = 0;j < si;j++){
            if(s[j] == '3') ok3 = true;
            if(s[j] == '5') ok5 = true;
            if(s[j] == '7') ok7 = true;
        }
        if(ok3 && ok5 && ok7) ans++;
    }
    cout << ans << endl;
}
*/

void dfs(ll a, bool ok3, bool ok5, bool ok7){
    if(a <= n && ok3 && ok5 && ok7) cnt++;

    if(a * 10 + 3 <= n) dfs(a * 10 + 3, true, ok5, ok7);
    if(a * 10 + 5 <= n) dfs(a * 10 + 5, ok3, true, ok7);
    if(a * 10 + 7 <= n) dfs(a * 10 + 7, ok3, ok5, true);
}

int main(){
    cin >> n;
    dfs(0, false, false, false);
    cout << cnt << endl; 
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;
/*
vector<ll> G[500005];
vector<P> tree[500010];

//big priority queue
priority_queue <ll> pql;
priority_queue <P> pqp;

//small priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
*/
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj,n,m;
ll a,b,c,d,e,g,h,r,l,w,num,ans;
ll x[500005],y[500005],z[500005];
bool dame;
char s[5005][5005];
ll dp[3005][3005];

int main(){
    
    cin >> h >> w;
	for(i=0;i<h;i++){
		cin >> s[i];
	}
	dp[0][0] = 1;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(i + j == 0)continue;
			a = 0;
			if(i >= 1)a += dp[i-1][j];
			if(j >= 1)a += dp[i][j-1];
			a %= mod;
			dp[i][j] = a;
			if(s[i][j] == '#')dp[i][j] = 0;
			//pe(dp[i][j]);
		}
		//el;
	}
	p(dp[h-1][w-1]);
    return 0;
}

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


void input(); template<typename First,typename... Rest> void input(First&,Rest&...);
void inputVector(); template<typename First,typename... Rest>  void inputVector(std::vector<First>&,Rest&...);
#define loop(n) for(int i = 0;i < (int)(n);++i)


void calculate(){
    int N;
    std::string a,b;
    input(N,a,b);
    for(int i = 0;i < N;++i){
        std::cout << a[i] << b[i];
    }
    std::cout << '\n';
}

int main(int,char**){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    calculate();
}



void input(){return;}
template<typename First,typename... Rest>
void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}

void inputVector(){return;}
template<typename First,typename... Rest> 
void inputVector(std::vector<First> &first,Rest&... rest){
    int N = first.size();
    for(int i = 0;i < N;i++){
        std::cin >> first[i];
    }
    inputVector(rest...);
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		Scanner scan = new Scanner(System.in);
		String word = "";		//???????????????string
		int[] shuffleBegin = new int[100]; //?????£?????????????§????
		String targetText = "";
		String temp = "";
		String kansei = "";
		while(true){
			temp = scan.next();
			if(temp.equals("-")){
				break;
			}
			char[] targetChar = temp.toCharArray();
			int targetLength = temp.length();
			int shuffleTimes = scan.nextInt();
			
			for(int i=0; i<shuffleTimes; i++){
				shuffleBegin[i] = scan.nextInt();
				
			}
			for(int i =0;i<shuffleTimes; i++){
				for(int ii=0; ii<(targetLength - shuffleBegin[i]) ; ii++){
					word = word + targetChar[ii + shuffleBegin[i]];
//					System.out.println(word);
				}
				for(int ii=0; ii<shuffleBegin[i]; ii++){
					word = word + targetChar[ii];
//					System.out.println(word);
				}
			targetChar = word.toCharArray();
			kansei = word;
			word = "";
			}
			System.out.println(kansei);		
			
		}
	}
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc=new Scanner(System.in);
        int[] in=new int[6];
        for(int i=0;i<6;i++)in[i]=Integer.parseInt(sc.next());
        String s=sc.next();
        Dice d=new Dice(in);
        for(int i=0;i<s.length();i++)d.move(s.charAt(i));
        out.println(d.Get(0));
        out.flush();
    }
}
class Dice{
    private int[] memo=new int[6];
    private static final String equalmove="NNNNWNNNWNNNENNNENNNWNNN";
    public Dice(int[] in){
        Set(in[0],in[1],in[2],in[3],in[4],in[5]);
    }
    private void Set(int a,int b,int c,int d,int e,int f){
        memo[0]=a;memo[1]=b;memo[2]=c;memo[3]=d;memo[4]=e;memo[5]=f;
    }
    public void move(char c){
        switch(c){
            case 'W':
                Set(memo[2],memo[1],memo[5],memo[0],memo[4],memo[3]);
                break;
            case 'N':
                Set(memo[1],memo[5],memo[2],memo[3],memo[0],memo[4]);
                break;
            case 'S':
                Set(memo[4],memo[0],memo[2],memo[3],memo[5],memo[1]);
                break;
            case 'E':
                Set(memo[3],memo[1],memo[0],memo[5],memo[4],memo[2]);
                break;
            default:
                System.out.println("error");
        }
    }
    public int Get(int i){
        return memo[i];
    }
    public boolean isequal(Dice D2){
        if(D2==this)return true;
        for(int i=0;i<equalmove.length();i++){
            this.move(equalmove.charAt(i));
            boolean flag=true;
            for(int j=0;j<6;j++){
                if(this.Get(j)!=D2.Get(j)){
                    flag=false;
                    break;
                }
            }
            if(flag)return true;
        }
        return false;
    }
}




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


int main()
{
    ll i,j,k,l,m,n;

    cin >> n;

    ll ar[n+10];
    ll fir[n+10];

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

    ll ekn = 0,sum = 0,baki;

    fir[n] = ar[n];

    for(i = n-1 ; i >= 0 ; i--)fir[i] = ar[i] + fir[i+1];

    for(i=0; i<=n; i++)
    {

       if(!i)ekn = 1;
       else
       {
           ekn = ekn*2;
       }
       ekn = min(ekn,fir[i]);
       sum += ekn;

       ekn -= ar[i];

       if(ekn < 0)return cout << -1 << endl,0;

    }

    cout << sum << endl;


}


Measured memory_bytes: 5188
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<string>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

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

	bool c_flag = false;
	bool s_flag = false;

	for(auto& s:S){
		if(s == 'C'){
			c_flag = true;
		}
		if((s == 'F') && c_flag){
			s_flag = true;
		}
	}


	if(s_flag && c_flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}


	return 0;
}


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

typedef double          D;
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define MOD             1000000007
#define PI              2.0*acos(0.0)
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define Rep(i,a,b)      Rep(int i = 0; i <n; i++)
#define rep(i,a,b)      rep(int i = n; i >= 0; i--)
#define boost		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;

int main(void){

   // boost
    char s;
    cin>>s;

        if(s>='A'&&s<='Z')
           cout<<'A'<<nl;
        else
           cout<<'a'<<nl;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;

	string t = "keyence";
	int sn = S.size();
	int tn = t.size();
	int l = 0;
	int r = 0;

	for( int i = 0; i < tn && S[i] == t[i]; ++i ) {
		l = i+1;
	}

	for( int i = 0; i < tn && S[sn-1 - i] == t[tn-1 - i]; ++i ) {
		r = i+1;
	}

	cout << (l+r >= tn ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    char first = s.charAt(0);
    char last = s.charAt(s.length() - 1);
    String ans = "Second";
    if((first == last) ^ (s.length() % 2 == 1)) ans = "First";
    System.out.println(ans);
  }
}

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



using namespace std;



using ll = long long;



int main(){

  int n;

  vector <ll> b;

  ll tmp;

  cin >> n;

  cin.ignore();

  for(int i = 0; i < n - 1; i++){

    cin >> tmp;

    b.push_back(tmp);

  }



  ll sum_a = b[0];



  ll tmp_a;

  for (int i = 1; i <= n - 2; i++){

    if(b[i-1] < b[i]){

      sum_a += b[i-1];

    } else {

      sum_a += b[i];

    }



  }

  sum_a += b[n-2];

  cout << sum_a << endl;

  return 0;

}



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

int main() {
    string s;
    cin >> s;

    bool flg = false;
    rep(i, s.size()) {
        if(i % 2 == 0) {
            if(s.at(i) == 'R' || s.at(i) == 'U' || s.at(i) == 'D')
                flg = true;
            else {
              flg = false;
              break;
            }
        }
    }
    
    if(!flg) {
        cout << "No" << endl;
        return 0;
    } 

    rep(i, s.size()) {
        if(i % 2 == 1) {
            if(s.at(i) == 'L' || s.at(i) == 'U' || s.at(i) == 'D')
                flg = true;
            else {
                flg = false;
                break;
            }
        }
    }

    if(flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in);) {
      String input = sc.next();

      String answer ="";
      if("A".equals(input)) {
        answer = "T";
      }else if("T".equals(input)) {
        answer = "A";
      }else if("C".equals(input)) {
        answer = "G";
      }else {
        answer = "C";
      }

      System.out.println(answer);
    }
  }
}

Measured memory_bytes: 21716
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Algorithms.Intro as VA
main=V.mapM_ print.solve.V.tail.V.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve xs=V.map f xs where
  f x=if x<=a then b else a
  [a,b]=V.toList.V.slice(V.length xs`div`2-1)2.V.modify VA.sort$xs

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

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	int ave = 0;
	rep(i, N) {
		cin >> a.at(i);
		ave += a.at(i);
	}
	ave = round((double)ave / N);
	int ans = 0;
	rep(i, N) ans += pow(a.at(i) - ave, 2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cctype>
using namespace std;
int main()
{
    string s;
    int i,a,c,num;
    while(cin >> s)
    {
    	int len=s.length();
    	num=0;
		for(i=0;i<len;i++)
		{
			if(s[i]=='A')
			a=i;
			if(s[i]=='C')
			c=i;
			if(isupper(s[i]))
			num++;
		}
		if(a!=0||(c<2||c>len-2)||num!=2)
		printf("WA\n");
		else
		printf("AC\n");
	}
	return 0;
}


Measured memory_bytes: 256
//PDF解説を参考にした
#include<bits/stdc++.h>
using namespace std;

int main(){
  int64_t a,b;
  int c,d;
  cin>> a >> b >> c >> d;
  
  //cとdの最大公約数をユークリッドの互除法で求める
  int x=max(c,d),y=min(c,d),z=x%y;
  while (z!=0){
    x=y;
    y=z;
    z=x%y;
  }
  //cとdの最小公倍数を求める
  int64_t lcm=(int64_t)c*d/y;
  
  int64_t ans=(b-b/c-b/d+b/lcm)-((a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm);
  //1~bのc,dで割り切れない個数 - 1~(a-1)のc,dで割り切れない個数
  cout<< ans <<endl;
}

Measured memory_bytes: 256