akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main() {

    ll A, B;
    cin >> A >> B;

    ll X = gcd(A, B), cnt = 1, tmp = 2, flag = false, div = sqrt(X);


    while(tmp <= div) {
        while (X % tmp == 0) {
            X /= tmp;
            flag = true;
        }
        if (flag) cnt++;
        flag = false;
        tmp++;
    }

    if (X != 1) cnt++;

    cout << cnt;

    return 0;
}



ll gcd(ll a, ll b) {
    if (a % b == 0)return(b);
    else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a
#define pr2(a,b)    cout<<a<<" "<<b
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll minize(ll& a,ll b){return a=(a>b?b:a);}
inline ll maxize(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];
pll P[30];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t,p;
	// PROCESS IN HERE
	sc(n);
	fu(i,1,n)sc(A[i]);
	fu(i,1,n){
		p=0;
		fu(j,0,20){
			if((1LL<<j)&A[i]){
				P[j].fi=P[j].se;
				P[j].se=i;
			}
			maxize(p,P[j].fi);
		}
		ans+=i-p;
	}
	pr(ans);


	re 0;
	// Hack it if you can :)
}

int main(){
//	INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	ll test;
//	sc(test);
//	fu(T,1,test)
	Solves();
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 1792
import java.util.Scanner;
import java.lang.Math;

public class Main {
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] grid = new int[2][n];
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < n; j++) {
				grid[i][j] = sc.nextInt();
			}
		}

		int[][] ans = new int[2][n];
		ans[0][0] = grid[0][0];
		ans[1][0] = grid[1][0] + ans[0][0];

		for(int j = 1; j < n; j++) {
			ans[0][j] = grid[0][j] + ans[0][j - 1];
		}
		for(int j = 1; j < n; j++) {
			ans[1][j] = grid[1][j] + Math.max(ans[1][j - 1], ans[0][j]);
		}

		System.out.println(ans[1][n-1]);
	}

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

Measured memory_bytes: 21972
(defun main2 ()
  (let ((a (read))
        (b (read))
        (k (read)))
    (loop for i from a below (min (1+ b) (+ a k))
          do (format t "~A~%" i))
    (loop for i from (max (+ a k) (1+ (- b k))) upto b
          do (format t "~A~%" i))))

(main2)


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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cout << #x << " is " << x << endl;
#define endl                           '\n'

using namespace std;
ll n,w,dp[102][100001];
pll v;

ll f(ll i,ll rem)
{
	if(rem==0) return 0;
	if(i==n) return 0;
	if(rem<0) return -hell;
	if(dp[i][rem]!=-1) return dp[i][rem];
	ll val=0;
	if(v[i].F<=rem) val=max(val,f(i+1,rem-v[i].F)+v[i].S);
	val=max(val,f(i+1,rem));
	return dp[i][rem]=val;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,m,k,cnt=0,ans=0,t=1;
	cin>>n>>w;
	rep(i,0,n)
	{
		cin>>j>>k;
		v.pb(mp(j,k));
	}
	rep(i,0,n+1)
	{
		rep(j,0,w+1)
			dp[i][j]=-1;
	}
	ret(f(0,w))
	return 0;
}

Measured memory_bytes: 79232
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

class Combination{
    private:
    vector<ll>fact, inv;
    ll mod;
    
    public:
    ll modpow(ll x, ll n){
        ll res = 1;
        while(n > 0){
            if(n & 1)res = res * x % mod;
            x = x * x % mod;
            n >>= 1;
        }
        return res;
    }
    ll modinv(ll x){
        ll y = mod, u = 1, v = 0;
        while(y){
            ll t = x / y;
            x -= t * y; swap(x, y);
            u -= t * v; swap(u, v);
        }
        u %= mod;
        if(u < 0)u += mod;
        return u;
    }
    Combination(ll num, ll _mod = 1000000007){
        fact = vector<ll>(2 * num + 10);
        inv = vector<ll>(2 * num + 10);
        mod = _mod;
        fact[0] = 1;
        inv[0] = modinv(fact[0]);
        for(ll i = 1; i < fact.size(); i++){
            fact[i] = fact[i - 1] * i % mod;
            inv[i] = modinv(fact[i]);
        }
    }
    ll factrial(ll n){
        return fact[n];
    }
    ll nPk(ll n, ll k){
        return fact[n] * inv[n - k] % mod;
    }
    ll nCk(ll n, ll k){
        return nPk(n, k) * inv[k] % mod;
    }
    ll nHk(ll n, ll k){
        return nCk(n+k-1, k);
    }
};

int main(){

    ll N, M, K;
    cin >> N >> M >> K;
    Combination cmb(N * M);
    ll ans = 0;
    for(ll x = 1; x < M; x++){
        ll tmp = x * (M - x) % MOD;
        tmp = tmp * N % MOD;
        tmp = tmp * N % MOD;
        tmp = tmp * cmb.nCk(N * M - 2, K - 2) % MOD;
        ans = (ans + tmp) % MOD;
    }
    for(ll y = 1; y < N; y++){
        ll tmp = y * (N - y) % MOD;
        tmp = tmp * M % MOD;
        tmp = tmp * M % MOD;
        tmp = tmp * cmb.nCk(N * M - 2, K - 2) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

 main()
 {  int i,a,b;



cin>>a>>b;

i=a-(b+b);

if(i>=0)
    cout<<i<<endl;

else
    cout<<"0"<<endl;








return 0;

}


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

int main(){
    int N,M;cin>>N>>M;
    priority_queue<long> q;
    for(int i=0;i<N;i++){
        long a;cin>>a;
      q.push(a);
    }
    for(int i=0;i<M;i++){
      long a=q.top()/2;
      q.pop();
      q.push(a);
    }
    long res=0;
    for(int i=0;i<N;i++){
        res+=q.top();
        q.pop();
    }
  cout<<res<<endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
const int MOD = 1e9+7;

void solve() {
    int n;
    cin >> n;
    bool ok = true;
    int a;
    while(n--) {
        cin >> a;
        if(!ok)
            continue;
        if(a%2!=0) {
            continue;
        }
        if(a%3==0 || a%5==0) {
            continue;
        }
        else {
            ok=false;
        }
    } 
    if(ok) {
        cout << "APPROVED\n";
    }
    else {
        cout << "DENIED\n";
    }
}

int32_t main()
{
    hyperspeed
    int test=1;
    // cin >> test;
    while(test--) {
        solve();
    }
    return 0;
}

//--n1m5


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if (a == b && b != c){
    cout << "Yes" << endl;
    return 0;
  }
  if (c == b && a != c){
    cout << "Yes" << endl;
    return 0;
  }
  if (a == c && b != c){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}



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

using namespace std;
typedef long long ll;

bool checkPalindrome(string value, int start, int end) {
	int dist = (end - start+1)/2;

	for (int i = 0; i < dist; ++i) {
		if (value[start + i] != value[end - i]) {
			return false;
		}
	}
	return true;
}

int main() {
	string value;
	cin >> value;
	if (checkPalindrome(value, 0, value.size() - 1) && checkPalindrome(value, 0, (value.size() - 1) / 2 - 1) 
		&& checkPalindrome(value, (value.size() + 3) / 2 - 1, value.size() - 1)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

}


Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	// sc.Scan()
	// fmt.Println(n, sc.Text())
	h := make([]int, n)
	for i := 0; i < n; i++ {
		// fmt.Scan(&h[i])
		sc.Scan()
		h[i], _ = strconv.Atoi(sc.Text())
	}
	var cnt int
	var ans int
	for i := 0; i < n-1; i++ {
		if h[i] >= h[i+1] {
			cnt++
			ans = max(cnt, ans)
		} else {
			cnt = 0
		}
	}
	fmt.Println(ans)
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}


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

using ll = long long;

int main()
{
    int N;
    cin >> N;
    vector<int> A = vector<int>(N+1);
    for(int i = 0; i<N; i++){
        cin >> A.at(i+1);
    }
    int count = 0;
    int now = 1;
    for(int i = 1; i<N+1; i++){
        if(A.at(i) == now){
            now +=1;
        }else{
            count += 1;
        }
    }
    
    if(count == N){
        cout << -1 << endl;
    }else{
        cout << count << endl;
    }
}

Measured memory_bytes: 1024
#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>;


int main(){
	string S;
	cin >> S;
	int N = S.size();
	rep(i,N) cout << 'x';
	cout << endl;
}













Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  cin >> N;
  vector <int> A(N);
  /*
  rep(i,N) cin >> A[i];

  ll ans = 0;
  int mod = 1000000007;


  //累積和
  vector <ll> S(N);
  S.at(0) = A.at(0);
  for (int i = 1; i < N; i++){
    S.at(i) = (S.at(i - 1) + A.at(i)) % mod;
  }

  for (int i = 0; i < N - 1; i++){
    ans += (A.at(i) * (S.at(N - 1) - S.at(i)) % mod) % mod;
    ans %= mod;
  }

  cout << ans << endl;
*/

  vector <ll> B(N + 1, 0);  //累積和テーブル
  int mod = 1000000007;

  for (int i = 0; i < N; i++){
    cin >> A[i];
    B[i + 1] = B[i] + A[i];
  }

  ll ans = 0;

  //iについて全探索
  for (int i = 0; i < N; i++){
    //A[i+1] + ... + A[N]を求める
    ll sum = (B[N] - B[i + 1]) % mod;
    ans += A[i] * sum;
    ans %= mod;
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "yes" << endl;}
void no(){ cout << "no" << endl;}

//-----------------------------------------
ll n, k;
ll v[100000 + 10];

bool ok(ll p){
  int cnt = 1;
  int tmp = 0;
  for(ll i=0;i<n;i++){
    if(v[i] > p) return false;
    else{
      if(tmp+v[i]<=p){
        tmp += v[i];
      }
      else{
        tmp = v[i];
        cnt++;
      }
    }
  }
  return cnt <= k;
}

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

  cin >> n >> k;
  REP(i,n) cin >> v[i];

  ll lef = 0;
  ll rig = 1e9;
  while(rig - lef > 1){
    ll mid = (lef + rig) /2;
    if(ok(mid)) rig = mid;
    else lef = mid;
  }
  cout << rig <<endl;


    
  return 0;
}




Measured memory_bytes: 3968
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#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++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
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 long long

void solve() {
	string s; cin >> s;
    if(s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if(s == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int p,n;
	int sum_p,sum_n,sum_d;
	sum_p = 0;
	sum_n = 0;
	sum_d = 0;
	double ans;
	int a;
	while(scanf("%d,%d",&p,&n) != EOF){
		sum_d++;
		sum_n += n;
		sum_p += p * n;
	}
	ans = (double)sum_n / (double)sum_d;
	a = (ans+0.5);
	printf("%d\n%d\n",sum_p,a);
	return 0;
}

Measured memory_bytes: 1020
a, b, c, k = map(int, input().split())
if a > k:
    a_num = k
else:
    a_num = a
b_num = k - a_num
if b_num > b:
    b_num = b
else:
    b_num = b_num
c_num = k - (a+b)
if c_num > c:
    c_num = c
else:
    c_num = c_num

if k < a:
    ans = a_num * 1
elif k < (a+b):
    ans = a_num * 1 + b_num * 0
else:
    ans = a_num * 1 - c_num * 1
print(ans)

Measured memory_bytes: 9204
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

h, n = map(int, input().split())
a = list(map(int, input().split()))

if sum(a) >= h:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 13964
// inputに入力データ全体が入る
function Main(input) {
    var a = input[0].split(" ")[0]-0;
    var b = input[0].split(" ")[1]-0;
    var ans = 0;
    for(var i=0;i<1000;i++){
        ans += calc(a,b,i);
    }
    console.log(Math.round(ans));
}

function calc(a,b, i){
  var pp = Math.pow(2,b);
  return (1900*b + 100*(a-b)) * Math.pow((pp-1)/pp,i);
}



Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));



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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;


int main(){
    string s;
    cin >> s;
    int ans = 0;
    int nagasa = s.length();

    REP(i, s.length()/2) {
        if(s[i] != s[s.length()-1-i]) ans++;
    }

    cout << ans << endl;
    
    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException{
		InputStreamReader in = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(in);
		StringBuilder preSb = new StringBuilder();
		StringBuilder sb = new StringBuilder(br.readLine());
		int q = Integer.parseInt(br.readLine());
		
		boolean reverseFlg = false;
		String line = null;
		for(int i=0;i<q;i++) {
			line = br.readLine();
			char[] arr = line.toCharArray();
			if(arr[0]=='1') {
				reverseFlg = !reverseFlg;
			}else {
				if((arr[2]=='1' && !reverseFlg) || (arr[2]=='2' && reverseFlg)) {
//					sb.insert(0, arr[4]);
					preSb.append(arr[4]);
				} 
				else {
					sb.append(arr[4]);
				}
				
			}
		}
		br.close();
		preSb.reverse();
		preSb.append(sb);
		if(reverseFlg) {
			preSb.reverse();
		}
		System.out.println(preSb.toString());
		
	}
}


Measured memory_bytes: 40796
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> x(n);
	int sum = 0;
	for (int i = 0;i < n;i++) {
		cin >> x[i];
		sum += x[i];
	}
	sum = (double)sum / n + 0.5;

	long long ans = 0;

	for (int i = 0;i < n;i++) {
		ans += pow(x[i] - sum, 2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3552
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  string str; cin >> str;
  vector<char> ans;

  rep(i,str.size()){
    if(str[i] == '0')
      ans.pb('0');
    else if(str[i] == '1')
      ans.pb('1');
    else if((str[i] == 'B') && (ans.size() !=0))
      ans.pop_back();
  }

  rep(i,ans.size()){
    cout << ans[i] ;
  }

  cout << endl;
 
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
ans = 0
for i in range(K):
  if T[i] == 'r':
    ans += P
    
  elif T[i] == 's':
    ans += R
   
  elif T[i] == 'p':
    ans += S
    

for i in range(K, N):
  if T[i] == 'r':
    if T[i-K] != 'r':
      ans += P
    else:
      T[i] = 'q'
    
  elif T[i] == 's':
    if T[i-K] != 's':
      ans += R
    else:
      T[i] = 'q'
    
  elif T[i] == 'p':
    if T[i-K] != 'p':
      ans += S
    else:
      T[i] = 'q'
      
print(ans)
    

Measured memory_bytes: 4084
import sys
input = sys.stdin.readline

# というわけで一旦全パターンを計算してから評価する事にする

n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
result = []
depth = -1
sum = 0


def main():
    calc(depth, sum)
    for i in m:
        if i in result:
            print('yes')
        else:
            print('no')


def calc(depth, sum):
    if depth >= n - 1:
        result.append(sum)
        return

    calc(depth + 1, sum + A[depth])
    calc(depth + 1, sum)


if __name__ == '__main__':
    main()



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

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

const int N = 2e5;
bool uzyty[N + 7];
int ta[N + 7];
int tb[N + 7];

int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector <pair <int, int>> t;
  long long wa = 0;
  long long wb = 0;
  for (int i = 0; i < n; ++i) {
    cin >> ta[i] >> tb[i];
    wa += ta[i];
    wb += tb[i];
    t.push_back({ta[i], 2 * i});
    t.push_back({tb[i], 2 * i + 1});
  }
  
  sort(t.begin(), t.end());
  long long wynik = min(wa, wb);
  
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += t[i].first;
    uzyty[t[i].second] = 1;
  }
   
  for (int i = 0; i < n; ++i) {
    int ile = 0;
    long long wyn = sum;
    if (uzyty[2 * i]) {
      ile++;
      wyn -= ta[i];
    }
    if (uzyty[2 * i + 1]) {
      ile++;
      wyn -= tb[i];
    }
    for (int j = 0; j < ile; ++j) {
      if (t[n + j].second / 2 == i) ile++;
      else wyn += t[n + j].first;
    }
      
    wynik = min(wynik, wyn); 
  }
  cout << wynik << endl;
  return 0;
}

Measured memory_bytes: 2932
<?php

fscanf(STDIN, "%d", $n);

$ans = "";
while ($n != 0) {
    $r = $n % -2;
    if ($r < 0) $r += 2;

    $n = intdiv($n - $r, -2);

    $ans = $r . $ans;
}

if ($ans == "") $ans = "0";

echo $ans;


Measured memory_bytes: 4604
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	//数値の入力
		int a = sc.nextInt();
        int b = sc.nextInt();
        int m = sc.nextInt();
      	//配列
        int aNum[] = new int[a];
        for(int i = 0; i < a; i++){
        	aNum[i] = sc.nextInt();
        }
      	int bNum[] = new int[b];
        for(int i = 0; i < b; i++){
        	bNum[i] = sc.nextInt();
        }
      	int mNum[] = new int[m*3];
        for(int i = 0; i < m*3; i++){
        	mNum[i] = sc.nextInt();
        }
     	//クーポン未使用最安値
      	int ans =0;
      	//冷蔵庫
      	int aMin =aNum[0]+1;
      	for(int i = 0 ; i < a; i++){
        if(aMin > aNum[i]){
            aMin = aNum[i];
    		}
        }
         //レンジ
         int bMin =bNum[0]+1;
      	 for(int i = 0 ; i < b; i++){
         if(bMin > bNum[i]){
            bMin = bNum[i];
    		}
         }    
      	ans = aMin+bMin;
      	//クーポン使用最安値
      	int Coup =0;
      	for(int i = 0; i < m*3; i+=3){
          Coup = aNum[mNum[i]-1]+bNum[mNum[i+1]-1]-mNum[i+2];
            if(ans > Coup){
            ans = Coup;
    		}
        }
      System.out.println(ans);
    }
}

Measured memory_bytes: 62224
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int X, Y;
	cin >> X >> Y;
	
	bool ans = false;
	
	REP(i, 101) REP(j, 101) {
		int c = i * 2 + 4 * j;
		if (i + j == X && c == Y) ans = true;
	}
	
	puts([&] {
		return ans;
	}() ? "Yes": "No");
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
 
using namespace std;
 
#define MAX 1000001
#define INF (1<<29)
 
int main(){
    int pos[MAX];
    int x,y;
 
    while(true){
	cin >> x >> y;
	if(x == 0 && y == 0) break;
	fill(pos,pos+MAX,INF);
	int a,b;
	for(int i = 0 ; ; i++){
	    x %= y;
	    if(x == 0){
		a = i;
		b = 0;
		break;
	    }
	    if(pos[x] != INF){
		a = pos[x];
		b = i - pos[x];
		break;
	    }
	    pos[x] = i;
	    x *= 10;
	}
	cout << a << " " << b << endl;
    }
    return 0;
}

Measured memory_bytes: 6960
#include<iostream>
using namespace std;
int main()
{
	int n,c=0,x=0;
	string ch;
	cin>>n;
	for(int i=0;i<n;i++)
    {
	cin>>ch[i];
    }
	for(int i=0;i<n;i++)
    { 
    	if(ch[i]=='I')
    	{		
		x++;          
    	c=max(c,x);    
        }
		else
    	x--;        	
	}
	cout<<c;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#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))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int K, X; cin >> K >> X;
    FOR(i, -K + 1, K) cout << X + i << " ";
    cout << endl;


    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n, r;
    cin >> n >> r;
    if (n >=10) {
        cout << r <<endl;
    }else{
        cout << r + 100 * (10 - n) << endl;
    }
    
    
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7
MAX = 10 ** 5

def com_init
  @fac = []
  @inv = []
  @finv = []
  @fac[0] = @fac[1] = 1
  @finv[0] = @finv[1] = 1
  @inv[1] = 1

  2.upto(MAX) do |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
  end
end

def comb(n, k)
  return @fac[n] * ( @finv[k] * @finv[n - k] % MOD) % MOD
end

def main
  n, k = gets.chomp.split().map(&:to_i)
  array = gets.chomp.split.map(&:to_i).sort

  com_init()
  ans = 0
  
  (n - k + 1).times do |i|
    com = comb(n - i - 1, k - 1)
    ans += array[n - i - 1] * com % MOD
    ans -= array[i] * com % MOD
  end

  return ans % MOD
end

puts main

Measured memory_bytes: 15988
a, b, c = gets.split(" ").map(&:to_i)
$count = 0
while (1)
    if a % 2 != 0 || b % 2 != 0 || c % 2 != 0 then
        puts $count
        break
    end
    if $count > 1000000
        puts "-1"
        break
    end
    
    $count +=  1
    before_a = a
    before_b = b
    before_c = c
    a = (before_b / 2) + (before_c / 2)
    b = (before_a / 2) + (before_c / 2)
    c = (before_a / 2) + (before_b / 2)
end


Measured memory_bytes: 1788
// Author: Mohamamd Faisal
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
    cin >> a >> b >> c;
  	
  	int res = b/a;
  
  	if(res > c)
      cout<<c<<endl;
  	else 
      cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


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

	int N, M, K;

	cin >> N;
	int H[20];
	rep(i, 0, N) {
		cin >> H[i];
	}
	int ans = 0;
	int Max = 0;
	rep(i, 0, N) {
		if (Max <= H[i]) {
			ans++;
			Max = H[i];
		}
			
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long

using namespace std;

int main(){
    string N;
    cin >> N;
    int m_cnt=0,x_cnt=0;
    for(int i=0;i<N.size();i++){
        if(N[i]=='o'){
            m_cnt++;
        }
        else if(N[i]=='x'){
            x_cnt++;
        }
    }
    if(15-x_cnt>=8){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;

namespace abc126
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            var s01 = s.Substring(0, 2);
            var s23 = s.Substring(2, 2);
            var result = "NA";

            if (IsYy(s01) && CanMm(s23))
            {
                result = "YYMM";
            }
            else if (IsYy(s23) && CanMm(s01))
            {
                result = "MMYY";
            }
            else if (CanMm(s23) && CanMm(s01))
            {
                result = "AMBIGUOUS";
            }

            Console.WriteLine(result);
        }

        private static bool IsYy(string s)
        {
            var num = int.Parse(s);
            if (num == 0)
            {
                return true;
            }

            if (num > 12)
            {
                return true;
            }

            return false;
        }

        private static bool CanMm(string s)
        {
            var num = int.Parse(s);
            return 1 <= num && num <= 12;
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<cctype>
#include<vector>
#include <ctype.h>
#include<algorithm>
#include<queue>
#include<string>
#include <math.h>
#include <iomanip>
using namespace std;
int a=0,b,ans=0;
char c;
int main() {
	cin >> b;
	for (size_t i = 0; i < b; i++)
	{
		cin >> c;
		if (c == 'I')a++; else a--;
		ans = max(ans, a);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
string s;
int q;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >>s>>q;
    int count=0;
    string fronts="",backs="";
    rep(i,q){
        int flag,flag1;
        cin>>flag;
        if(flag==1){
            count++;
        }
        else{
            char c;
            cin>>flag1>>c;
            if(flag1==1){
                if(count%2==0){
                    fronts+=c;
                }
                else{
                    backs+=c;
                }
            }
            else{
                if(count%2==1){
                    fronts+=c;
                }
                else{
                    backs+=c;
                }
            }
        }
    }
    if(count%2==1){
        reverse(ALL(s));
        reverse(ALL(backs));
        //reverse(ALL(fronts));
        cout<<backs+s+fronts<<"\n";
    }
    else{
    reverse(ALL(fronts));
    cout<<fronts+s+backs<<"\n";
    }
}


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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  map<char, int> mp;
  for(int i=0; i<s.length(); i++) mp[s[i]]++;
  for(int i=0; i<26; i++){
    if(mp['a' + i] == 0){
      cout << (char)('a' + i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
	long long int h,w,ans;
	cin >> h >> w;
	ans=(w/2)*h;
	if (w%2==1) ans+=(h+1)/2;
	if (w==1 || h==1) ans=1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
signed main(signed argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int m,n;
    cin>>m>>n;
    int before=-1,ans=0;
    if(m==2){
        int ans2=0;
        rep(i,n){
            int in;
            cin>>in;
            if(in==i%2 + 1)ans++;
            else ans2++;
        }
        cout<<min(ans,ans2)<<endl;
        return 0;
    }
    rep(i,n){
        int in;
        cin>>in;
        if(in==before){
            ans++;
            before=-1;
        }
        else before=in;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define ull unsigned long long
using namespace std;
const int maxx = 2007;
const ll mod1 = 1e7;
const ll mod = 1e9 + 7;
const ll base = 311;
const ll base1 = 113;
const ll maxn = 1e6 + 7;
bool check;
ll t, T, n, a[maxn], b[maxn], m1, m, tong, r, ans, mx, k, ma[maxx][maxx], pw[maxx][maxx];
//ll , c[maxx], st1[maxx];
//ll  , pw[maxx];
//string s[maxx], ss[maxx], str, f[maxx][10];
struct dang
{
    ll mn, gcd, val, pos, dd, n1, n2, n3;
};
ll f[maxx][maxx];
string s;
struct les
{
    bool operator()(ll x, ll y)
    {
        return x > y;
    }
};
dang c[maxn];
bool lt(const dang&x, const dang& y)
{
    return x.val > y.val;
}
deque<ll> st;
priority_queue<ll, vector<ll>, les >st1;
map<ll, ll> mp;
vector<ll> adj;
void sol()
{

    cin >> n;
    ans = 0;
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
    for(int i = 1; i <= n; i ++)
        cin >> b[i];
    for(int i = 1; i <= n; i ++)
    {
        while(!st.empty() && b[st.back()] < b[i])st.pop_back();
        while(!st.empty() && b[st.front()] > a[i])st.pop_front();
        if(a[i] != b[i] && (st.empty() || b[st.back()] != b[i]))
        {
            ++ans;
            st.push_back(i);
        }
    }
    cout << ans;
}

void ntu()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> c[i].val;
        c[i].pos = i;
    }
    sort(c+1, c+1+n, lt);
    for(int i = 1; i <= n; i ++)
    {
        for(int lf = 0; lf <= i; lf ++)
        {
            int rt = i - lf;
            if(rt > 0) f[lf][rt] = max(f[lf][rt], f[lf][rt-1] + c[i].val * abs(n - rt + 1 - c[i].pos));
            if(lf > 0) f[lf][rt] = max(f[lf][rt], f[lf-1][rt] + c[i].val * abs(c[i].pos - lf));
            if(i == n)ans = max(f[lf][rt], ans);
        }
    }
    cout << ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    //freopen("Test.INP", "r", stdin);
    ntu();
}
/*
3 4
0 3 -1 2
3 3 3 3
3 1 3 0
*/


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    int K;
    cin >> N >> K;
    vector<int> h(N);
    vector<int> dp(N,INT_MAX);
    for(auto& x : h){
        cin >> x;
    }
    dp[0] = 0;
    for(int i = 0; i < N;i++){
        for(int j = i + 1; j <= i + K;j++){
            if( j < N) dp[j] = min(dp[j],dp[i] + abs(h[i] - h[j]));
        }
    }
    printf("%d\n",dp[N-1]);
    return 0;
}


Measured memory_bytes: 1024
import sys
import math
import bisect

def main():
    n, m = map(int, input().split())
    A = []
    for i in range(n):
        a, b = map(int, input().split())
        if b <= m:
            A.append(a)
    if len(A) == 0:
        print('TLE')
    else:
        print(min(A))

if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (100000)
#define NUM_MOD (1000000007)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, ts[MAX_N], as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &ts[i]);
  }
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // solve
  int hs[MAX_N], possible = 1;
  for (int i = 0; i < N; i++) {
    hs[i] = -1;
  }
  int prev;
  // check if it is possible
  prev = 0;
  for (int i = 0; i < N; i++) {
    const int h = ts[i];
    if (prev != h && as[i] < h) {
      possible = 0;
      break;
    }
    prev = h;
  }
  prev = 0;
  for (int i = N - 1; i >= 0; i--) {
    const int h = as[i];
    if (prev != h && ts[i] < h) {
      possible = 0;
      break;
    }
    prev = h;
  }
  // count
  prev = 0;
  for (int i = 0; i < N; i++) {
    const int h = ts[i];
    if (prev != h) {
      hs[i] = h;
    }
    prev = h;
  }
  prev = 0;
  for (int i = N - 1; i >= 0; i--) {
    const int h = as[i];
    if (prev != h) {
      hs[i] = h;
    }
    prev = h;
  }
  if (possible) {
    long ans = 1;
    for (int i = 0; i < N; i++) {
      if (hs[i] == -1) {
        ans = (ans * min(ts[i], as[i])) % NUM_MOD;
      }
    }
    printf("%ld\n", ans);
  } else {
    printf("0\n");
  }

  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> p(n);
    int be=0;
    rep(i,n){cin>>p[i];if(be<p[i])be=p[i];}
    int sum[be+1];
    sum[0]=0;
    rep(i,be){
        sum[i+1]=sum[i]+i+1;
    }
    vector<double> e(n,0);
    rep(i,n){
        e[i]=sum[p[i]]/(double)p[i];
    }
    vector<double> tosum(n+1,0);
    rep(i,n){
        tosum[i+1]=tosum[i]+e[i];
    }
    double tmp=0;
    rep(i,n-k+1){
        double t=tosum[i+k]-tosum[i];
        if(tmp<t)tmp=t;
    }
    printf("%.10lf",tmp);
}

Measured memory_bytes: 4096
/*	ex4_2
	suzuto	*/

#include <stdio.h>
#include <math.h>

double cos_theorem_func(double len_1, double len_2, double angle); /*プロトタイプ宣言*/

int main(void) {
  double len_hour, len_mimute, hour, minute, ans, angle; /*変数の宣言*/

  scanf("%lf %lf %lf %lf", &len_hour, &len_mimute, &hour, &minute); /*各針の長さ、及び時刻の入力*/
  angle = hour * 30 + minute * 0.5 - minute * 6; /*時針、分針の1分あたりの角速度がそれぞれ0.5度、6度より針間の角度を正負を問わず算出*/
  ans = cos_theorem_func(len_hour, len_mimute, angle); /*余弦定理で針の端点間の距離を出しansに代入*/
  printf("%10.10f\n", ans); /*距離を出力*/
  return 0;
}

/*余弦定理を用いて対角の辺を算出する関数*/
double cos_theorem_func(double len_1, double len_2, double angle){
  double angle_modified, res_pow2, res; /*変数の宣言*/
  angle_modified = M_PI * angle / 180;
  res_pow2 = pow(len_1, 2) + pow(len_2, 2) - 2 * len_1 * len_2 * cos(angle_modified); /*x^2 + y^2 - 2xycos(t)*/
  res = sqrt(res_pow2);
  return res;
}


Measured memory_bytes: 2488
using System;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Collections.Specialized;
using System.IO.Pipes;

namespace ConsoleC____
{
    class Program
    {
        static void Main()
        {
            int[] a = new int[100010];
            for (int i = 0; i < 100010; i++) a[i] = 0;
            int N = int.Parse(ReadLine());
            int[] A = new int[N];
            long ans = 0;
            string[] s = ReadLine().Split(' ');
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(s[i]);
                ans += A[i];
                //a[i]はiがA中に何個あるか記憶してる
                a[A[i]]++;
            }
            int Q = int.Parse(ReadLine());
            int[] B = new int[Q], C = new int[Q];
            for (int i = 0; i < 2 * Q; i += 2) {
                string[] s2 = ReadLine().Split(' ');
                B[i / 2] = int.Parse(s2[0]);
                C[i / 2] = int.Parse(s2[1]);
            }
            for (int i = 0; i < Q; i++)
            {
                //A中のB[i]の数を減らしてすべてC[i]として記録する
                int bNum = a[B[i]];
                //総和を書き換え
                //WriteLine("C[{0}]: {1}, B[{0}]: {2}, bNum: {3}", i, C[i], B[i], bNum);
                //for (int j = 0; j < N; j++) Write("{0} ", a[j + 1]);
                ans += (C[i] - B[i]) * bNum;
                WriteLine(ans);
                //a[i]の中身を書き換え
                a[B[i]] = 0;
                a[C[i]] += bNum;
            }
        }
    }
}

Measured memory_bytes: 30712
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}
int N,M,S;
inline void solve(){
  IN(N);
  M=N;
  while(M){
    S+=M%10;
    M/=10;
  }
  OUT(N%S==0?"Yes":"No");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

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

	int n, q;
	cin >> n >> q;

	string ans = "kogakubu10gokan";
	while(n--) {
		int year;
		string name;
		cin >> year >> name;

		if(year > q)
			break;

		ans = name;
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;



int main(){
  int a,b,c;
  std::cin >> a>>b>>c;
  if(a+b>c&&a<=c){
    std::cout << "YES" << '\n';
  }else{
    std::cout << "NO" << '\n';
  }

}


Measured memory_bytes: 256