akhauriyash/Code-Regression huggingface dataset:
// 3_abc143_c
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;

    char ch = s[0];
    int ans = n;
    for(int i = 1; i < n; i++){
        if(s[i] == ch) ans--;
        else ch = s[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
// OURL: https://atcoder.jp/contests/abc136/tasks/abc136_e
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

bool check(vector<ll> &as, ll val, ll k) {
  auto rs = make_v<ll>(as.size());
  ll rsum = 0;
  REP(i,as.size()) {
    rs[i] = as[i] % val;
    rsum += rs[i];
  }
  sort(rs.begin(), rs.end(), greater<ll>());
  ll plus = 0;
  REP(i,rs.size()) {
    plus += val - rs[i];
    rsum -= rs[i];
    if (plus <= k && rsum <= k && (plus - rsum) % val == 0) {
      return plus <= k;
    }
  }
  return false;
}

template<typename T>
void divisor(T n, vector<T> &div) {
  for(ll i=1;i<=sqrt(n); i++) {
    if (n % i == 0) {
      div.push_back(i);
      if (i*i != n) div.push_back(n / i);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,k;
  cin >> n>> k;
  auto as = make_v<ll>(n);
  ll sum = 0;
  REP(i,n) {
    cin >> as[i];
    sum += as[i];
  }
  debug(as, sum);
  ll i = 1;
  vector<ll> divs;
  divisor(sum, divs);
  sort(divs.begin(), divs.end(), greater<ll>());
  debug(divs);

  for(auto &d : divs) {
    if (check(as, d, k)) {
      cout << d << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
strstoints :: [String] -> [Integer]
strstoints xs =  map read xs

ints input = (strstoints (words input))

ord :: [Integer] -> String
ord ints@(a:b:[]) | a > b  = "a" ++ " > " ++ "b"
                  | a == b = "a" ++ " == " ++ "b"
                  | a < b  = "a" ++ " < " ++ "b"

main = do
  str <- getLine
  putStrLn $ ord $ ints str

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

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

    double X;
    cin >> X;

    double x = 100;
    int ans = 0;

    for(double i = 0;; i++) {
        if(x >= X) {
            cout << ans << endl;
            return 0;
        }
        x *= 1.01;
        x = floor(x);
        ans++;
    }
}

Measured memory_bytes: 3740
f=lambda:map(int,input().split())
f()
s,*l=[0]*100002
for i in f(): s+=i; l[i]+=1
q,=f()
for _ in range(q): b,c=f(); s+=(c-b)*l[b]; l[c]+=l[b]; l[b]=0; print(s)

Measured memory_bytes: 18536
import itertools

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

a, b, c, d = [], [], [], []
for i in range(Q):
    _a, _b, _c, _d = map(int, input().split())
    a.append(_a)
    b.append(_b)
    c.append(_c)
    d.append(_d)

l = [v for v in range(1, M+1)]
ll = list(itertools.combinations_with_replacement(l, N))

ans = 0
for i in ll:
    anstmp = 0
    for j in range(Q):
        if i[b[j]-1] - i[a[j]-1] == c[j]:
            anstmp += d[j]
    if anstmp > ans:
        ans = anstmp

print(ans)


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

int main(){
  int N, f = 0;
  string S, T, s, t;
  cin >> N >> S >> T;
  
  for(int i = 0; i < N; i++){
    s = S.substr(i, N-i);
    t = T.substr(0, N-i);
    if (s == t){
      cout << N + i << endl;
      f = 1;
      break;
    }
  }
  if (f == 0){
    cout << N * 2 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const long int INF = 100000000000000;
long int min (long int a,long int b) {
  if (a < b) return a;
  else return b;
}
long int max (long int a,long int b) {
  return a + b - min(a, b);
}
long int min4 (long int a,long int b,long int c,long int d) {
  long int k, j;
  k = min(a, b);
  j = min(c, d);
  return min(k, j);
}
long int min6 (long int a,long int b,long int c,long int d,long int e,long int f) {
  long int k, j;
  k = min(a, b);
  j = min4(c, d, e, f);
  return min(k, j);
}
int search(long int a[], long int x, int N) {
  int mi = 0;
  int ma = N;
  while (mi < ma) {
    int mid = (mi + ma) / 2;
    if (a[mid] < x) mi = mid + 1;
    else ma = mid;
  }
  return mi;
}
int main () {
  int A, B, Q;
  cin >> A >> B >>Q;
  long int shr[100006];
  long int tem[100006];
  for (int i = 1; i <= A; i ++) cin >> shr[i];
  for (int i = 1; i <= B; i ++) cin >> tem[i];
  shr[A + 1] = tem[B + 1] = INF;
  shr[0] = tem[0] = -INF;
  for (int i = 0; i < Q; i ++) {
    long int x;
    cin >> x;
    int sm, tm, sp, tp;
    sm = tm = sp = tp = 0;
    sp = search(shr, x, A + 2);
    sm = sp - 1;
    tp = search(tem, x, B + 2);
    tm = tp - 1;
    //cout << sm << ' ' << tm << endl;
    long int a, b, c, d, e, f;
    a = max(shr[sp], tem[tp]) - x;
    b = x - min(shr[sm], tem[tm]);
    c = tem[tp] * 2 - (x + shr[sm]);
    d = shr[sp] * 2 - (x + tem[tm]);
    e = (x + shr[sp]) - tem[tm] * 2;
    f = (x + tem[tp]) - shr[sm] * 2;
    //cout << a << ' ' << b << ' ' << c << ' ';
    //cout << d << ' ' << e << ' ' <<  f << endl;
    cout << min6(a, b, c, d, e, f) << endl;
  }
}
 
  



Measured memory_bytes: 2816
n=int(input())
aaa=tuple(map(int, input().split()))

ans_e=0
ans_o=0
even=0
odd=0
#even->+
for i, a in enumerate(aaa):
    even+=a
    if i%2==0:
        if even>0:
            continue
        else:
            tmp=1-even
            even=1
            ans_e+=tmp
    else:
        if even<0:
            continue
        else:
            tmp=even+1
            even=-1
            ans_e+=tmp

for i, a in enumerate(aaa):
    odd+=a
    if i%2==0:
        if odd<0:
            continue
        else:
            tmp=odd+1
            odd=-1
            ans_o+=tmp
    else:
        if odd>0:
            continue
        else:
            tmp=1-odd
            odd=1
            ans_o+=tmp
print(min(ans_e, ans_o))

Measured memory_bytes: 14596
#include<stdio.h>

int main(void){
    int rooms[4][3][10];

    int i,n,j;
    for(i=0;i<4;i++)
        for(n=0;n<3;n++)
            for(j=0;j<10;j++)
                rooms[i][n][j]=0;
    
    int num;
    scanf("%d",&num);

    int a,b,c,d;
    for(i=0;i<num;i++){
        scanf("%d %d %d %d",&a,&b,&c,&d);
            rooms[a-1][b-1][c-1]+=d;
    }

    for(i=0;i<4;i++){
        for(n=0;n<3;n++){
            for(j=0;j<10;j++){
                printf(" %d",rooms[i][n][j]);
            }
                printf("\n");
        }
        if(i != 3)
            printf("####################\n");  
    }
        
     return 0;           
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

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

void solve() {
    int h, w, k;
    cin >> h >> w >> k;
    vs s(h);
    REP(i, h) cin >> s[i];
    vvi ans(h, vi(w));
    int p = 1;
    int x = 0;
    REP(i, h) {
        bool none = true;
        REP(j, w) {
            if (s[i][j] == '#') {
                if (none) {
                    none = false;
                } else {
                    p++;
                }
            }
            ans[i][j] = p;
        }
        if (none) {
            if (x >= 0) {
                x = i;
            } else {
                ans[i] = ans[i - 1];
            }
        } else if (x >= 0) {
            REP(j, x + 1) ans[j] = ans[i];
            x = -1;
            p++;
        } else {
            p++;
        }
    }
    printvv(ans);
}


Measured memory_bytes: 3864
#include<stdio.h>

int main(void){

    long long n,i,j,amari,syo;
    char a[26],c[16];
    a[0] = 'z';
    for(i = 1; i <= 25; i++){
        a[i] = 'a' + i - 1;
        
    }
    
    scanf("%lld",&n);
    i = 0;
    while(1){

        amari = n % 26;

        syo = n / 26;
        if(amari == 0){
            c[i] = a[amari];
            syo--;
            i++;
        }else {
            c[i] = a[amari];
            i++;
        }
            

        

        if(syo <= 0)
        break;
        n = syo;

    }  

    
    j = i;

    for(i = j; i > 0; i--){
        printf("%c",c[i - 1]);

    }

    return 0;

}

Measured memory_bytes: 1656
#include <stdio.h>

int main(){
  int a[3];
  int cnt_5=0, cnt_7=0;
  scanf("%d %d %d", &a[0], &a[1], &a[2]);
  for(int i=0; i<3; i++){
    if(a[i]==5){
      cnt_5 += 1;
    }
    if(a[i]==7){
      cnt_7 += 1;
    }
  }
  if(cnt_5==2 && cnt_7==1){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
//4008802802
//4008160009
//1175114440
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define pb push_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define forn(i, a) for(register int i=0; i<a; i++)
#define Forn(i, a) for(register int i=1; i<=a; i++)
#define memINF 127
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false)
#define mid ((l+r)>>1)
#define lid (id<<1|1)
#define rid (id<<1)+2
#define lson lid, l, mid
#define rson rid, mid, r

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;
typedef vector<vector<ll> > matrix;
typedef __int128 LL;

inline int in() 
{
    int x=0, c;
    while((uint)((c=getchar())-48)>=10) 
        if(c=='-') 
            return -in();
    do 
    { x=(x<<3)+(x<<1)+(c^48); }
    while((uint)((c=getchar())^48)<10);
    return x;
}
inline ll lcm(ll a, ll b){return a*b/__gcd(a, b);}

const int MAX=1e5+5;

ll N, M, tmp;
char s[MAX], t[MAX];

int main()
{
    N=in(), M=in();
    scanf("%s%s", s, t);
    tmp=lcm(N, M);
    if(s[0]!=t[0])
    {
        puts("-1");
        return 0;
    }
 
    ll s_i=tmp/N;
    ll t_i=tmp/M;
    for(ll i=0; i<min(N/t_i, M/s_i); i++)
        if(s[t_i*i]!=t[s_i*i])
        {
            puts("-1");
            return 0;
        }
    printf("%lld\n", tmp);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n, m;
llint u[1005], d[1005], x[1005];
llint l[1005], r[1005], y[1005];
llint h, w;
bool wall[6005][6005], used[6005][6005];
vector<llint> compX, compY;
llint dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

void comp(vector<llint> &vec)
{
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

llint get(vector<llint> &vec, llint x)
{
	return lower_bound(vec.begin(), vec.end(), x) - vec.begin(); 
}

void dfs(int x, int y)
{
	used[x][y] = true;
	queue<P> Q;
	Q.push(P(x, y));
	
	while(Q.size()){
		x = Q.front().first, y = Q.front().second;
		Q.pop();
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if(used[nx][ny] || wall[nx][ny]) continue;
			used[nx][ny] = true;
			Q.push(P(nx, ny));
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> u[i] >> d[i] >> x[i];
	for(int i = 1; i <= m; i++) cin >> y[i] >> l[i] >> r[i];
	
	compX.push_back(-2e9);
	compX.push_back(2e9);
	compY.push_back(-2e9);
	compY.push_back(2e9);
	
	for(int i = 1; i <= n; i++){
		compX.push_back(x[i]);
		compY.push_back(u[i]);
		compY.push_back(d[i]);
	}
	for(int i = 1; i <= m; i++){
		compY.push_back(y[i]);
		compX.push_back(l[i]);
		compX.push_back(r[i]);
	}
	comp(compX), comp(compY);
	w = compX.size()*2, h = compY.size()*2;
	
	for(int i = 1; i <= n; i++){
		llint U = get(compY, u[i])*2, D = get(compY, d[i])*2, X = get(compX, x[i])*2;
		for(int j = U; j <= D; j++) wall[X][j] = true;
	}
	
	for(int i = 1; i <= m; i++){
		llint L = get(compX, l[i])*2, R = get(compX, r[i])*2, Y = get(compY, y[i])*2;
		for(int j = L; j <= R; j++) wall[j][Y] = true;
	}
	
	/*for(int y = 0; y < h; y++){
		for(int x = 0; x < w; x++){
			cout << wall[x][y];
		}
		cout << endl;
	}*/
	
	llint sx = get(compX, 0)*2-1, sy = get(compY, 0)*2-1;
	
	dfs(sx, sy);
	
	llint ans = 0;
	for(int x = 0; x < w; x++){
		for(int y = 0; y < h; y++){
			if(!used[x][y]) continue;
			if(x == 0 || x >= w-2 || y == 0 || y >= h-2){
				cout << "INF"<< endl;
				return 0;
			}
			if(x % 2 == 0 || y % 2 == 0) continue;
			llint X = x/2, Y = y/2;
			if(X+1 >= compX.size() || Y+1 >= compY.size()){
				cout << "INF" << endl;
				return 0;
			}
			ans += (compX[X+1]-compX[X]) * (compY[Y+1]-compY[Y]);
		}
	}
	cout << ans << endl;
	 
	return 0;
}

Measured memory_bytes: 73172
#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;
 
 
void reader(int &a){scanf("%d",&a);}
void reader(double &a){scanf("%lf",&a);}
void reader(char a[]){scanf("%s",a);}
void reader(ll &a){scanf("%lld",&a);}
void reader(ull &a){scanf("%llu",&a);}
// void reader(string& a){cin >> a;};
template<class T,class U> void reader(T& t,U& u){reader(t); reader(u);}
template<class T,class U,class V> void reader(T& t,U& u,V& v){reader(t); reader(u); reader(v);}
 
void writer(int a,char c) {printf("%d",a); putchar(c);}
void writer(ll a,char c) {printf("%lld",a); putchar(c);}
void writer(double a,char c) {printf("%.20lf",a); putchar(c);}
void writer(char a[]) {printf("%s",a);};
void writer(char a[],char c) {printf("%s",a);putchar(c);};
void writer(char a,char c) {putchar(a); putchar(c);};
template<class T>void writerLn(T t){writer(t,'\n');}
template<class T,class U>void writerLn(T t,U u){writer(t,' ');writer(u,'\n');}
template<class T,class U,class V> void writerLn(T t,U u,V v){writer(t,' ');writer(u,' ');writer(v,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
template<class T> void writerVec(vector<T> x){int n=x.size();int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
 

 
// #define int ll
 
bool test = 1;

//............................
#define MAX 300000
signed main(){
  int i,j,k,l;
  while(1) {
	int n,p;
	cin >> n >> p;
	if(n == 0) break;
	vector<int> a1(n);
	int step = 0;
	int pabble_of_bowl = p;
	for(;;step++) {
	  if(pabble_of_bowl) {
		a1[step%n]++;
		pabble_of_bowl--;
		if(a1[step%n] == p) {
		  goto end;
		}
	  }
	  else {
		pabble_of_bowl += a1[step%n];
		a1[step%n] = 0;
	  }
	}
  end: 
	cout << step%n << endl;
  }
  return 0;
}

Measured memory_bytes: 3080
#2
a,b,c,k = input().split(' ')
out = 0
a = int(a)
b = a + int(b)
c = b + int(c)
k = int(k)

if k <= a:
    out = k
elif k <= b:
    out = a
elif k <= c:
    out = a - (k - b)

print(out)

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

int main(){
  int n; cin >> n;
  int ma=0, mb=0, mc=0;
  
  for(int i=0; i<n; ++i){
    int a, b, c;
    cin >> a >> b >> c;
    int ta=ma, tb=mb, tc=mc;
    ma = max(tb, tc) + a;
    mb = max(tc, ta) + b;
    mc = max(ta, tb) + c;
  }
  
  cout << max({ma, mb, mc}) << endl;
  
  return 0;
}

Measured memory_bytes: 3544
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	int nEven = 0.5*n*(n-1);
	int nOdd = 0.5*m*(m-1);
	cout << nEven + nOdd << endl;
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    int ab, bc, ca;
    cin >> ab >> bc >> ca;

    cout << (ab*bc) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; typedef pair<int, int> pi;
int dd[] = { 0, 1, 0, -1, 0 };


int main()
{
	string S;
	cin >> S;
	bool flag = true;
	for (int i = 0; i < S.size(); i++)
	{
		for (int j = i + 1; j < S.size(); j++)
		{
			if (S[i] == S[j])
			{
				flag = false;
				break;
			}
		}
	}
	cout << (flag ? "yes" : "no") << endl;
	return 0;
}


Measured memory_bytes: 256
import Data.Array.IArray

solve :: Int -> Array Int (Int,Int,Int) -> [Int]
solve n a = map (go 0) [1..n]
  where
    go :: Int -> Int -> Int
    go t i
      | i == n = t
      | t <= s = go (s+c) (i+1)
      | otherwise = let k = (t + f - 1) `div` f
                     in go (k * f + c) (i+1)
      where
        (c,s,f) = a!i

main :: IO ()
main = do
    n <- readLn :: IO Int
    a <- listArray (1,n-1) . map ((\[a,b,c] -> (a,b,c)) . (map read . words))
       . lines <$> getContents :: IO (Array Int (Int,Int,Int))
    mapM_ print $ solve n a

Measured memory_bytes: 1148
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
   int N;
   cin>>N;
   if(N%1000==0) cout<<0;
   else cout<<1000-N%1000;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;
vvl G = vv(200002, 0, 0, ll);
std::vector<ll> check(200002, 0);
ll ans = 0;
set<ll> x, y;
void dfs(ll from, ll now){
  if(check[now]!=0) return;
  check[now] = 1;
  if(now>=100001&&y.find(now)==y.end()) y.insert(now);
  if(now<100001&&x.find(now)==x.end()) x.insert(now);
  for(int i=0;i<G[now].size();i++){
    if(from==G[now][i]) continue;
    dfs(now, G[now][i]);
  }
}
int main(int argc, char const *argv[]) {
  ll N, a, b, ans = 0;
  std::cin >> N;
  for(int i=0;i<N;i++){
    std::cin >> a >> b;
    G[a].push_back(b+100001);
    G[b+100001].push_back(a);
  }
  for(int i=1;i<200002;i++){
    x.clear(), y.clear();
    dfs(-1, i);
    ans += x.size()*y.size();
  }
  std::cout << ans - N << '\n';
  return 0;
}


Measured memory_bytes: 17280
#include <stdio.h>
int main (void) {
	int n,b,f,r,v,i,j,k,l;
	int a[4][3][10]= {0};
	
	scanf("%d",&n);
	for(i=0 ;i<n ;i++) {
		scanf("%d %d %d %d",&b,&f,&r,&v);
		a[b-1][f-1][r-1] += v;
	}
	
	for(j=0; j<4; j++) {
		for(k=0; k<3; k++) {
			for(l=0; l<10; l++) {
				printf(" %d",a[j][k][l]);
			}
			printf("\n");
		}
		if(j<3) printf("####################\n");
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(int, n);
  Cin(string, a, b, c);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    map<char, int> mp;
    mp[a[i]]++;
    mp[b[i]]++;
    mp[c[i]]++;

    int ma = 0;
    for (auto e : mp) ma = max(ma, e.second);
    ans += 3 - ma;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll h,n;
    cin>>h>>n;
    ll a[n];
    ll ss=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        ss+=a[i];
    }
    if(ss>=h){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 1024
n = gets.chomp.to_i
ans = []
m = n
loop do
  r = m % (-2)
  p = m / (-2)
  if r == -1
    ans.push '1'
    p += 1
  else
    ans.push '0'
  end
  m = p
  if m == 1
    ans.push '1'
    break
  elsif m == 0
    break
  end
end
puts ans.reverse.join


Measured memory_bytes: 1788
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
 
using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
 
int main()
{
#if LOCAL_ENVIRONMENT == 1
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  ll N = input();
  ll M = input();
 
  string reslt = N<=M ? "Yes" : "No";
  output(reslt);
 
  return 0;
}

Measured memory_bytes: 256
/*input
*/
#include <bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define ff first
#define ss second
#define pb push_back
 
using ll = long long;
using pii = pair<int, int>;
using ld = long double;
 
template<typename T> using V = vector<T>;

int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int n, m; cin >> n >> m;
	vector<pii> jobs(n);
	priority_queue<int> Q;
	for (int i = 0; i < n; ++i) {
		cin >> jobs[i].ff >> jobs[i].ss;
	}
	sort(all(jobs));
	ll ans = 0;
	int cur = 0;
	for (int day = m - 1; day >= 0; --day) {
		while (cur < n and jobs[cur].ff == m - day) {
			Q.push(jobs[cur].ss);
			++cur;
		}
		if (!Q.empty()) {
			ans += (ll)Q.top();
			Q.pop();
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1660
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        long n = sc.nextLong();
        long s = sc.nextLong();

        if (n == s) {
            System.out.println(n + 1);
            return;
        }

        if ((n + 1) / 2 < s) {
            System.out.println(-1);
            return;
        }

        for (long b = 2; b * b <= n; b++) {
            if (f(n, b) == s) {
                System.out.println(b);
                return;
            }
        }

        long min = Long.MAX_VALUE;
        for (long p = 1; p * p <= n; p++) {
            long b = (n - s) / p + 1;
            if (f(n, b) == s) {
                min = Math.min(min, b);
            }
        }
        System.out.println(min);
    }

    private long f(long n, long b) {
        if (n < b) {
            return n;
        } else {
            return f(n / b, b) + n % b;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 21844
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define nax 100000
int minF(int a, int b){
	return a<b ? a:b;
}
int main(){
	int n;
	int h[nax];
	int dp[nax];
	scanf("%i",&n);

	for(int i=0;i<n;i++){
		scanf("%i",&h[i]);
	}
	dp[0]= 0;
	dp[1] = abs(h[0]-h[1]);
	for(int i=2;i<n;i++){
		dp[i] = minF(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
	}

		printf("%i",dp[n-1]);


}

Measured memory_bytes: 896
n,k = map(int,input().split())
ans = 0
if k == 0:
  print(n**2)
  exit()
for b in range(k+1,n+1):
  c,d = n//b,n%b
  ans += (b-k)*c
  ans += max(0,d-k+1)
print(ans)

Measured memory_bytes: 39280
import sys
input=sys.stdin.readline #文字列入力はするな！！
import heapq
n,m=map(int,input().split())
a=[]
for i in input().split():
    heapq.heappush(a,-int(i))
for i in range(m):
    p=-heapq.heappop(a)
    p=p//2
    heapq.heappush(a,-p)
print(-sum(a))



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

using namespace std;

int main()
{
  int N;
  string S;
  bool isSta = false;
                                                                                                                                              
  cin >> N;
  cin >> S;

  while(!isSta){
    isSta = true;
    for(int i=0;i<S.size()-1;i++){
      if(S[i] == S[i+1]){
        S.erase(S.begin() + i);
        isSta = false;
        break;
      }
    }
  }

  cout << S.size() << endl;

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	int s,t,i=0;
	for(;scanf("%d%d",&s,&t),s;i++)
	{
		if(i>0)puts("");
		for(;s<=t&&!(s%400==0||(s%100&&s%4==0));s++);
		if(s>t)
			puts("NA");
		else
			for(;s<=t;s+=4)
				if(!(s%400)||s%100)
					printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 612
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

H, W = mapint()
ch, cw = mapint()
dh, dw = mapint()
maze = [list(input()) for _ in range(H)]

dirc = set([(-1, 0), (1, 0), (0, -1), (0, 1)])
from collections import deque
from heapq import heappop, heappush
Q = [(0, (ch-1)*(10**4)+cw-1)]

dist = [[10**18]*W for _ in range(H)]
dist[ch-1][cw-1] = 0
ans = 10**18
while Q:
    d, yx = heappop(Q)
    y, x = divmod(yx, 10**4)
    if d>dist[y][x]:
        continue
    dist[y][x] = d
    if y==dh-1 and x==dw-1:
        ans = d
        break
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            ny, nx = y+dy, x+dx
            if ny<0 or ny>=H or nx<0 or nx>=W:
                continue
            if maze[ny][nx]=='#':
                continue
            if (dy, dx) in dirc:
                if dist[ny][nx]>d:
                    dist[ny][nx] = d
                    heappush(Q, (d, ny*(10**4)+nx))
            else:
                if dist[ny][nx]>d+1:
                    dist[ny][nx] = d+1
                    heappush(Q, (d+1, ny*(10**4)+nx))
if ans>=10**17:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 128472
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;


signed main() {
int A,B,C,D;
int frag =0;
string ans = "No";
cin >> A >> B >> C >> D;
while(A>0 && C>0){
if(ans[0]=='N'){
    C = C - B;
    ans = "Yes";
    continue;
}
else{
    A = A - D;
    ans = "No";
    continue;
}
}

answer(ans);
}

Measured memory_bytes: 3624
from math import floor, sqrt

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n // b) + n % b

def solve(n, s):
    if s > n:
        return -1
    elif s == n:
        return n + 1

    for b in range(2, floor(sqrt(n)) + 1):
        if f(b, n) == s:
            return b

    for p in reversed(range(1, floor(sqrt(n)) + 1)):
        if (n - s) % p == 0:
            b = (n - s) // p + 1
            if f(b, n) == s:
                return b

    return -1


n = int(input())
s = int(input())

print(solve(n, s))


Measured memory_bytes: 3064
use std::io::{self, BufRead};

fn gcd(x: u64, y: u64) -> u64 {
  let (mut a, mut b) = if x < y {
    (y, x)
  } else {
    (x, y)
  };
  while b != 0 {
    let r = a % b;
    a = b;
    b = r;
  }
  a
}

fn lcm_by_gcd(x: u64, y: u64, g: u64) -> u64 {
  x * y / g
}

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let xs: Vec<u64> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let (a, b, c, d) = (xs[0], xs[1], xs[2], xs[3]);
  let g = gcd(c, d);
  let l = lcm_by_gcd(c, d, g);
  let total = b - a + 1;
  let div_c = b / c - (a - 1) / c;
  let div_d = b / d - (a - 1) / d;
  let div_cd = b / l - (a - 1) / l;
  let ans = total - (div_c + div_d - div_cd);
  println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll n; cin>>n;
  vector<ll> a(n);
  rep(i, n) cin>>a[i];

  ll t = 0;
  rep(i, n) t ^= a[i];
  if (t == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3940
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;
using ll=long long;


int main() {
  char c; cin >> c;
  cout << char(c+1);
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b;
	cin >> a >> b;
	cout << a + b / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
while True:
    try:
        n,x = map(int,input().split(" "))
        if n == 0 and x == 0:
            break
        pattern = 0
        for i in range(1,n+1):
            for j in range(i+1,n+1):
                for h in range(j+1,n+1):
                    if i + j + h == x:
                        pattern += 1
        print(pattern)
    except (EOFError):
        break

Measured memory_bytes: 7684
#include <bits/stdc++.h>
using namespace std;
int n,c;
bool prime(int p){
	if(p==1)return false;
	if(p==57)return true;
	for(int i=2;i<=sqrt(p);i++){
		if(p%i==0)return false;
	}
	return true;
}
int main(){
	cin>>n;
	int c=0;
	for(int i=6;c<n;i+=5){
		if(prime(i)){
			cout<<i<<" ";
			c++;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      
      	int A = sc.nextInt();
      	int B = sc.nextInt();
      	int C = sc.nextInt();
      
      	int result = Math.min(C, B/A);
      	System.out.println(result);
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}
int main(){
    int q; cin >> q;
    deque<int> dq;
    for(int i = 0; i < q; i++){
        int a,b,c; cin >> a >> b;
        if (a == 0){
            cin >> c;
            if (b) dq.push_back(c);
            else dq.push_front(c);
        } else if (a == 1) cout << dq[b] << endl;
        else {
            if (b == 1) dq.pop_back();
            else dq.pop_front();
        }
    }
}
  




Measured memory_bytes: 4600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
#include<iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    while(n % 111 != 0){
        n++;
    }
    cout << n << endl;
    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int N, M, Q;
vector<lint> a, b, c, d;

lint ma = -1;
void bfs(int i, vector<lint>& A) {
    if (i == 0) {
        for (int x = 1; x <= M; x++) {
            A[i] = x;
            bfs(i + 1, A);
        }
    } else if (i == N) {
        // dump(A);

        lint score = 0;
        for (int i = 0; i < Q; i++) {
            if (A[b[i]] - A[a[i]] == c[i]) score += d[i];
        }
        ma = max(ma, score);
    } else {
        for (int x = A[i - 1]; x <= M; x++) {
            A[i] = x;
            bfs(i + 1, A);
        }
    }
    return;
}

int main() {
    cin >> N >> M >> Q;
    a = b = c = d = vector<lint>(Q);
    rep(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }

    vector<lint> A(N);

    bfs(0, A);

    cout << ma << endl;

    return 0;
}

Measured memory_bytes: 3616
S = list(input())
N = int(input())

Q = [list(input().split()) for _ in range(N)]

count = 0
c = 0

ans_append = []
ans_insert = []

for q in Q:
    if q[0] == "1":
        count += 1
        c = count % 2
    else:
        if (c == 0 and q[1] == "1") or (c == 1 and q[1] == "2"):
            ans_insert.append(q[2])
        elif (c == 0 and q[1] == "2") or (c == 1 and q[1] == "1"):
            ans_append.append(q[2])


if count % 2  == 1:
    ans = ans_append[::-1] + S[::-1] + ans_insert
    print("".join(ans))
else:
    ans = ans_insert[::-1] + S + ans_append
    print("".join(ans))

Measured memory_bytes: 119288
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

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

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

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

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	char w[101];
	size_t count['z' - 'a' + 1];

	for (size_t i = 0; i < (size_t)('z' - 'a' + 1); i++) {
		count[i] = 0;
	}

	scanf("%s", w);
	
	const size_t len = strlen(w);

	for (size_t i = 0; i < len; i++) {
		count[w[i] - 'a']++;
	}

	bool isBeautiful = true;

	for (size_t i = 0; i < (size_t)('z' - 'a' + 1); i++) {
		if (count[i] % 2 != 0) {
			isBeautiful = false;

			break;
		}
	}

	puts((isBeautiful ? "Yes" : "No"));

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int k,a,b;
    scanf("%d%d%d",&k,&a,&b);
    for(int i=a;i<=b;i++){
        if(i%k==0){
            printf("OK");
            return 0;
        }
    }
    printf("NG");
    return 0;
}

Measured memory_bytes: 1696
#include <stdio.h>

int main(void)
{
	int n;
	int a[100000];
	char d = 'n';
	int i;
	int ans = 1;
	
	/* input */
	scanf("%d", &n);
	for(i=0; i<n; i++)
		scanf("%d", &a[i]);
	
	/* to do */
	for(i=1; i<n; i++){
		if(a[i-1] < a[i]){		//増加
			if(d == 'n'){
				d = 'u';
				continue;
			}
			else if(d == 'd'){
				d = 'n';
				ans++;
				continue;
			}
			else if(d == 'u')
				continue;
		}
		else if(a[i-1] > a[i]){	//減少
			if(d == 'n'){
				d = 'd';
				continue;
			}
			else if(d == 'u'){
				d = 'n';
				ans++;
				continue;
			}
			else if(d == 'd')
				continue;
		}
	}
	
	/* output */
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
	int l,r,d=-1,i,j,x;
	cin >> l >> r; 
	if(2019+l/2019*2019<=r){
		cout << 0 << endl;
	}
	else{
		for(i=l;i<r;i++){
			for(j=i+1;j<=r;j++){
				x=(i%2019)*(j%2019)%2019;
				if(d==-1 || d>x){
					d=x;
				}
			}
		}
		cout << d << endl;
	} 
	return 0;
}


Measured memory_bytes: 256
def main():
    D = int(input())
    fuman = list(map(int, input().split()))
    manzoku = [[0]*26 for _ in range(D)]
    for i in range(D): manzoku[i] = list(map(int, input().split()))
    # できるだけ点数が下がらないように、満足度の高いものを選んでいく
    # d日目にテストiを受けた時、score += manzoku[d][i]-sigma[i以外25個](fuman[k]*それを受けてない日数)
    # >テストiをd日目に受ける
    # 1.fuman[i]*受けてない日数が一番でかいやつを受ける
    # 2.manzoku[d][i]が一番でかいやつを受ける
    timepass = [0]*26
    for i in range(D):
        #1
        x1 = 0
        t1 = 0
        for j in range(26):
            tmp = fuman[j]*timepass[j]
            if tmp>x1:
                x1 = tmp
                t1 = j
        #2
        x2 = 0
        t2 = 0
        for j in range(26):
            tmp = manzoku[i][j]
            if tmp>x2:
                x2 = tmp
                t2 = j
        #sel
        if x1>x2:
            for j in range(26):
                if not j==t1: timepass[j] += 1
                else: timepass[j] = 0
            print(t1+1)
        else:
            for j in range(26):
                if not j==t2: timepass[j] += 1
                else: timepass[j] = 0
            print(t2+1)




main()


Measured memory_bytes: 9512
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for (int i = 0; i < n; i++) {
            int r = sc.nextInt();
            ans = Math.max(ans, r - min);
            min = Math.min(min, r);
        }
        System.out.println(ans);
        sc.close();
    }
}


Measured memory_bytes: 99216