akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>

using namespace std;

template <typename T, const T id>
class convex_hull_trick {
    struct line {
        T a, b;
        line(T a_ = 0, T b_ = 0) : a(a_), b(b_) {}
        T get(T x) { return a * x + b; }
    };
    struct node {
        line l;
        node *lch, *rch;
        node(line l_) : l(l_), lch(nullptr), rch(nullptr) {}
        ~node() {
            if (lch) delete lch;
            if (rch) delete rch;
        }
    };

private:
    const int n;
    const vector<T> pos;
    node *root;

public:
    convex_hull_trick(const vector<T>& pos_) : n(pos_.size()), pos(pos_), root(nullptr) {}
    ~convex_hull_trick() {
        if (root) delete root;
    }
    void insert(T a, T b) {
        line l(a, b);
        root = modify(root, 0, n - 1, l);
    }
    T get(T x) const {
        int t = lower_bound(pos.begin(), pos.end(), x) - pos.begin();
        assert(t < n && pos[t] == x);
        return sub(root, 0, n - 1, t);
    }

private:
    node* modify(node *p, int lb, int ub, line& l) {
        if (!p) return new node(l);
        if (p->l.get(pos[lb]) >= l.get(pos[lb]) && p->l.get(pos[ub]) >= l.get(pos[ub])) return p;
        if (p->l.get(pos[lb]) <= l.get(pos[lb]) && p->l.get(pos[ub]) <= l.get(pos[ub])) {
            p->l = l;
            return p;
        }
        int c = (lb + ub) / 2;
        if (p->l.get(pos[c]) < l.get(pos[c])) swap(p->l, l);
        if (p->l.get(pos[lb]) <= l.get(pos[lb]))
            p->lch = modify(p->lch, lb, c, l);
        else
            p->rch = modify(p->rch, c + 1, ub, l);
        return p;
    }
    T sub(node *p, int lb, int ub, int t) const {
        if (!p) return id;
        if (ub - lb == 0) return p->l.get(pos[t]);
        int c = (lb + ub) / 2;
        if (t <= c) return max(p->l.get(pos[t]), sub(p->lch, lb, c, t));
        return max(p->l.get(pos[t]), sub(p->rch, c + 1, ub, t));
    }
};

using ll = long long;

const ll inf = 1LL << 60;

int main() {
    int n;
    ll c;
    
    cin >> n >> c;
    
    vector<ll> h(n);
    
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    
    vector<ll> dp(n, inf);
    
    dp[0] = 0;
    
    convex_hull_trick<ll, -inf> cht(h); 
    
    for (int i = 0; i < n; i++) {
        if (i != 0) {
            dp[i] = -cht.get(h[i]) + h[i] * h[i] + c;
        }
        
        cht.insert(-(-2 * h[i]), -(dp[i] + h[i] * h[i]));
    }
    
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 14336
import sys
n = int(input())

if n % 2 == 0 or n % 5 == 0:
  print(-1)
  sys.exit()
  
tmp = 7

count = 1
while True:
  if tmp % n == 0:
    print(count)
    sys.exit()

  count += 1
  tmp = tmp * 10 + 7
  tmp %= n
  

Measured memory_bytes: 63032
n=int(input())
a=list(map(int,input().split()))
a1=sorted(a,reverse=True)
a2=sorted(a)
ans=1
if len(a)<90:
    for i in range(len(a)):
        ans*=a[i]

else:
    if a2[0]==0:
        ans=0
    elif a1[90]>1:
        ans=-1
    else:
        del a1[90:]
        for i in range(len(a1)):
           ans*=a1[i]
if ans>10**18:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 21632
from collections import deque
def bfs(gragh,n,start):
    visited = [0]*n
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited


n,m = map(int,input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(lambda n: int(n)-1,input().split())
    graph[a].append(b)
    graph[b].append(a)
visited = bfs(graph,n,0)[1:]
if all(visited):
    print("Yes")
    print(*visited,sep="\n")
else:
    print("No")


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

using namespace std;

int main()
{   
    
    ios_base::sync_with_stdio(false);
    
    /*Code from here*/
    char c;
    cin >> c;
    
    const string s = "aeiou";
    
    if (find(s.begin(), s.end(), c) != s.end())
        cout << "vowel\n";
    else
        cout << "consonant\n";
    
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int h, w, d; cin >> h >> w >> d;
    vector<pair<int, int>> coo(h*w+5);
    repr(i, 1, h+1) repr(j, 1, w+1){
        int a; cin >> a;
        coo[a].first = i;
        coo[a].second = j;
    }

    vector<int> cum(h*w+5, 0);
    repr(i, d+1, h*w+1){
        cum[i] = cum[i-d] + abs(coo[i].first - coo[i-d].first) + abs(coo[i].second - coo[i-d].second);
    }

    int q; cin >> q;
    rep(i, q){
        int l, r; cin >> l >> r;
        cout << cum[r] - cum[l] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2176
using System;

namespace _8_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            //Char?????????????????????
            char[] cs = s.ToCharArray();
            for (int i = 0; i < cs.Length; i++)
            {
                //??§??????????????????
                if (char.IsUpper(cs[i]))
                {
                    //?°????????????????
                    cs[i] = char.ToLower(cs[i]);
                }
                //?°???????????????????
                else if (char.IsLower(cs[i]))
                {
                    //??§???????????????
                    cs[i] = char.ToUpper(cs[i]);
                }
            }
            //String????????????
            string s2 = new string(cs);
            //???????????¨???
            Console.WriteLine(s2);
            //mICROsOFT???vISUAL bASIC
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9104
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 int a,b,c;
  cin>>a>>b>>c;
  if(c-(a-b)>=0){
    cout<<c-a+b<<endl;}
  else{
    cout<<0<<endl;}
 
}

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

typedef long long ll;
using namespace std;

vector<int> ans(100000, 0);

void add(int rStart, int lStart, int lEnd) {
    int rDist = lStart - rStart;
    int lDist = lEnd - lStart + 1;
    int l = 0, r = 0;
    if (rDist % 2 == 0) {
        l += rDist / 2;
        r += rDist / 2;
    } else {
        l += (rDist - 1) / 2;
        r += (rDist + 1) / 2;
    }

    if (lDist % 2 == 0) {
        l += lDist / 2;
        r += lDist / 2;
    } else {
        l += (lDist + 1) / 2;
        r += (lDist - 1) / 2;
    }

    ans[lStart] = l;
    ans[lStart - 1] = r;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int lStart = 0, rStart = 0;
    bool rDone = false;
    for (int i = 0; i < s.size(); i++) {
        char c = s[i];
        if (c == 'R') {
            if (rDone) {
                add(rStart, lStart, i - 1);
                rDone = false;
                rStart = i;
            }
        } else if (c == 'L') {
            if (!rDone) {
                rDone = true;
                lStart = i;
            }
            if (i == s.size() - 1) {
                add(rStart, lStart, i);
            }
        }
    }
    for (int i = 0; i < s.size(); i++) {
        if (i == 0) cout << ans[i];
        else cout << " " << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1104
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 998244353;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
struct mi {
	ll v; explicit operator ll() const { return v; }
	mi() { v = 0; }
	mi(ll _v) { 
		v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
		if (v < 0) v += MOD;
	}
	friend bool operator==(const mi& a, const mi& b) { 
		return a.v == b.v; }
	friend bool operator!=(const mi& a, const mi& b) { 
		return !(a == b); }
	friend bool operator<(const mi& a, const mi& b) { 
		return a.v < b.v; }
   
	mi& operator+=(const mi& m) { 
		if ((v += m.v) >= MOD) v -= MOD; 
		return *this; }
	mi& operator-=(const mi& m) { 
		if ((v -= m.v) < 0) v += MOD; 
		return *this; }
	mi& operator*=(const mi& m) { 
		v = v*m.v%MOD; return *this; }
	mi& operator/=(const mi& m) { return (*this) *= inv(m); }
	friend mi pow(mi a, ll p) {
		mi ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans;
	}
	friend mi inv(const mi& a) { assert(a.v != 0); 
		return pow(a,MOD-2); }
		
	mi operator-() const { return mi(-v); }
	mi& operator++() { return *this += 1; }
	mi& operator--() { return *this -= 1; }
	friend mi operator+(mi a, const mi& b) { return a += b; }
	friend mi operator-(mi a, const mi& b) { return a -= b; }
	friend mi operator*(mi a, const mi& b) { return a *= b; }
	friend mi operator/(mi a, const mi& b) { return a /= b; }
    friend ostream& operator<<(ostream& os, const mi& m) {
        os << m.v; return os;
    }
    friend istream& operator>>(istream& is, mi& m) {
        ll x; is >> x;
        m.v = x;
        return is;
    }
};


typedef vector<mi> vmi;
typedef pair<mi,mi> pmi;
typedef vector<pmi> vpmi;
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, S; cin >> N >> S;
    mi dp[N+1][S+1];
    F0R(i, N+1) F0R(j, S+1) dp[i][j] = 0;
    dp[0][0] = pow((mi) 2, N);
    int A[N]; F0R(i, N) cin >> A[i];
    mi inv2 = 2; inv2 = inv(inv2);
    F0R(i, N) {
        F0R(j, S+1) {
            dp[i+1][j] += dp[i][j];
            if (j + A[i] <= S) {
                dp[i+1][j+A[i]] += dp[i][j] * inv2;
            }
        }
    }

    cout << dp[N][S] << endl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 74020
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    int n, x;
    cin >> n >> x;

    vector<int> l(n);
    REP(i, n) cin >> l.at(i);

    int ans = 1;
    int cx = 0;
    REP(i, n)
    {
        cx = cx + l.at(i);
        if(cx > x) break;
        ans++;

    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n,t;cin >> n >> t;
    vi a(n);
    int ma = -1000000000;
    int mi = inf; 
    int count = 0;
    rep(i, n) {
        cin >> a[i];
        chmin(mi,a[i]);
        if(i>0){
            if(chmax(ma,a[i]-mi))count=0;
            if(ma==a[i]-mi)count++;
        }
    }
   
    /*rep(i, n-1) {
        if(a[i+1]-a[i]==ma) count++;
    }*/
    cout << count << endl;
    // cout << ma << endl;
    return 0;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,i,k;
cin>>n>>k;
long long h[n+1],dp[n+1]={0},j;
h[0]=0;
for(i=1;i<=n;i++)
     cin>>h[i];
 dp[0]=0;
 dp[1]=0;
 for(i=2;i<=n;i++)
 {
  if(i==2)
        dp[2]=abs(h[i]-h[i-1])+dp[i-1];
  else{
      long long ans=INT_MAX;
        for(j=1;j<=k;j++)
        {   if(i-j>0)
            ans=min(ans,abs(h[i]-h[i-j])+dp[i-j]);
        }
    dp[i]=ans;
  }

 }
cout<<dp[n]<<endl;

}


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


void solve(long long N, std::vector<long long> L){
    ll ans=0;
    sort(L.begin(),L.end());
    ll n=N;
    rep(b,n){rep(a,b){
            ll ab=L[a]+L[b];
            ll r=lower_bound(L.begin(),L.end(),ab)-L.begin();
            ll l=b+1;
            ans+=max(0LL,r-l);
        }
    }
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    struct Student {
        ll id, num;
    };
    vector<Student> students(N);
    for (ll i = 0; i < N; i++) {
        cin >> students[i].num;
        students[i].id = i + 1;
    }
    sort(students.begin(), students.end(), [](Student& lhs, Student& rhs){
        return lhs.num < rhs.num;
    });
    for (ll i = 0; i < N; i++) {
        cout << students[i].id << " \n"[i == N - 1];
    }
}

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

int main() {
    stack<int> st;
    string op;
    while (cin >> op) {
        if (op.size() == 1) {
            if (op == "+") {
                int a = st.top(); st.pop();
                int b = st.top(); st.pop();
                st.push(a + b);
                continue;
            }
            if (op == "-") {
                int a = st.top(); st.pop();
                int b = st.top(); st.pop();
                st.push(b - a);
                continue;
            }
            if (op == "*") {
                int a = st.top(); st.pop();
                int b = st.top(); st.pop();
                st.push(a * b);
                continue;
            }
        }
        st.push(stoi(op));
    }
    cout << st.top() << endl;
}


Measured memory_bytes: 3176
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}

const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n;
  scanf("%d",&n);
  vi l(n*2);
  rep(i,n*2) scanf("%d",&l[i]);
  sort(rng(l));
  int ans = 0;
  rep(i,n) ans += l[i*2];
  cout<<ans<<endl;
  return 0;
}







Measured memory_bytes: 764
A, B, K = map(int, input().split())

if A + K >= B or A >= B - K:
    ans = [i for i in range(A, B+1)]
else:
    ans = [i for i in range(A, A+K)]
    ans.extend([j for j in range(B - K + 1, B+1)])
    ans = sorted(list(set(ans)))
for i in ans:
    print(i)

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
int main(){
    double x,h,i,j;
    while(1){
        scanf("%lf %lf",&x,&h);
        if(x == 0 && h == 0){
            break;
        }
        i=x*x;
        j=x/2;
        j=j*j;
        j=h*h+j;
        j=sqrt(j);
        j=j*x/2;
        j=j*4;
        printf("%f\n",i+j);
    }
    return (0);
}

Measured memory_bytes: 644
# -*- coding: utf-8 -*-
import sys
from collections import deque

N=input()

al=[ [] for i in range(N+1) ]
Q=[]    #クエリー
for _ in range(N-1):
    a,b=map(int, sys.stdin.readline().split())
    al[a].append(b)
    al[b].append(a)
    Q.append((a,b))

K=0
start=None
for i,t in enumerate(al):
    K=max(K,len(t))
    if start is None and len(t)==1:
        start=i

edge={} #辺集合 (fro,to):色

#BFS
Visit=[ 0 for _ in range(N+1) ] #訪問した頂点
q=deque()
q.append(start)
Visit[start]=1
used=[ None for _ in range(N+1) ] #前の頂点との間で使用済みの色をセットする配列

while q:
    fro=q.popleft()
    for color in range(1,K+1):  #未使用の色番号で最小の番号をcolor変数にセットする
        if used[fro]!=color:
            break

    for to in al[fro]:
        if Visit[to]==0:
            Visit[to]=1	#ここで訪問済みVisitに1をセットする。popleftの直後でVisitをセットすると同じ頂点がqに入り、TLEする
            q.append(to)
            edge[(fro,to)]=color
            edge[(to,fro)]=color
            used[to]=color
            color+=1
            if used[fro]==color:    #次に使おうとした色が前の頂点との間で使用済みであれば、色番号を１ずらす
                color+=1

print K
for a,b in Q:
    print edge[(a,b)]


Measured memory_bytes: 90584
#include <cstdio>
#include <algorithm>
using namespace std;
int pos, ans;
int n, d;

int main() {
    scanf("%d %d", &n, &d);
    pos = 1 + d;
    ans++;
    while(pos < n) {
        if(pos + d >= n)
            break;
        pos = pos + 2 * d + 1;
        ans++;
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		for (;;){
			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			if(m==-1 && f==-1 && r==-1)break;
			int p = m + f;
			if(m==-1 || f==-1) p=0;
			if(p>=80){
				System.out.println("A");
			}else if(p>=65 && p<80){
				System.out.println("B");
			}else if(p>=50 && p<65){
				System.out.println("C");
			}else if(p>=30 && p<50){
				if(r>=50){
					System.out.println("C");
				}else{
					System.out.println("D");
				}
			}else if(p<30){
				System.out.println("F");
			}
		}
	}
}

Measured memory_bytes: 25988
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        List<Long> res = new ArrayList<>();
        List<Long> p = new ArrayList<>();
        List<Long> q = new ArrayList<>();
        List<Long> r = new ArrayList<>();
        for(int i=0;i<A;i++){
            p.add(sc.nextLong());
        }
        for(int i=0;i<B;i++){
            q.add(sc.nextLong());
        }
        for(int i=0;i<C;i++){
            r.add(sc.nextLong());
        }
        Collections.sort(p, Comparator.reverseOrder());
        Collections.sort(q, Comparator.reverseOrder());
        Collections.sort(r, Comparator.reverseOrder());
        res.addAll(p.subList(0,X));
        res.addAll(q.subList(0,Y));
        res.addAll(r);
        Collections.sort(res, Comparator.reverseOrder());
        long sum=0;
        for(int i=0;i<X+Y;i++){
            sum += res.get(i);
        }

        System.out.println(sum);

    }

    private static class Ringo{
        int rg;
        long value;
        Ringo(int rg, long value){
            this.rg = rg;
            this.value = value;
        }
    }
}


Measured memory_bytes: 102388
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int d;
	cin>>n>>d;
	d*=2;
	d+=1;
	int ans;
	if(n%d==0)ans=n/d;
	else ans=(n+d)/d;
	cout<<ans<<endl;
	return 0; 
 } 

Measured memory_bytes: 256
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n, k;
    cin >> n >> k;

    int cur = 1;
    REP(i, n) {
        if (cur < k) cur *= 2;
        else cur += k;
    }

    print(cur);

}

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

int main() {
    int n,m;cin>>n>>m;
    int a[n][n],b[m][m];
    string s;
    for(int i=0;i<n;++i){
        cin>>s;
        for(int j=0;j<n;++j){
            if(s[j]=='#')a[i][j]=1;
            else a[i][j]=0;
            
//            cout<<a[i][j];
        }
//            cout<<endl;
    }

    for(int i=0;i<m;++i){
        cin>>s;
        for(int j=0;j<m;++j){
            if(s[j]=='#')b[i][j]=1;
            else b[i][j]=0;

//            cout<<b[i][j];
        }
//            cout<<endl;
    }
    int ans=0;

    for(int i=0;i<n-m+1;++i){
        for(int j=0;j<n-m+1;++j){
        if(a[i][j]==b[0][0]){
            int tmp=0;
            for(int k=0;k<m;++k){
                for(int l=0;l<m;++l){
                    if(b[l][k]==a[i+l][j+k])tmp++;
            }
        }
        if(tmp==m*m){
            cout<<"Yes"<<endl;
            return 0;
        }
        }
        }
    }
    cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define Mod 1000000007
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
#define INF 999999999999999999
#define NN (ll)(1e6+5)
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {    
       ll n,x,i;
       cin>>x>>n;
       vector <ll> v(n),vis(105);
       for(auto &u:v)
       {
           cin>>u;
           vis[u]++;
       }     
       ll ans=0,mn=INF;  
       for(i=x;i>=0;i--)
       {
           if(!vis[i])
            break;
       }
       if(mn>x-i)
       {
        ans=i;
        mn=x-i;
       }
       for(i=x;i<=101;i++)
       {
           if(!vis[i])
            break;
       }
       if(mn>i-x)
        ans=i;
       cout<<ans<<"\n";
   }
}

Measured memory_bytes: 3660
import math

N,K = map(int,input().split())
A = list(map(int,input().split()))

if max(A) < K:
    print('IMPOSSIBLE')
else:
    check = A[0]
    for i in range(1,N):
        check = math.gcd(A[i],check)
    if K % check == 0:
        print("POSSIBLE")
    else:
        print('IMPOSSIBLE')

Measured memory_bytes: 20332
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define mp(a, b) make_pair((a),(b))
#define bs(n) ((ull)1<<(ull)n)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
constexpr double eps = 0.000000001;

int main() {
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=110,M=1e5+10;
const ll INF=1e18;
int w[N],v[N];
ll dp[M];
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch&15),ch=getchar();
	return x*f;
}
int main()
{
	int n=read(),W=read();
	for (register int i=1;i<=n;++i) w[i]=read(),v[i]=read();
	dp[0]=0;for (register int i=1;i<=W;++i) dp[i]=-INF;
	for (register int i=1;i<=n;++i)
	  for (register int j=W;j>=w[i];--j)
	    dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
	ll ans=0;for (register int i=0;i<=W;++i) ans=max(ans,dp[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
  double d;
  cin >> d;
  if(d < 1.0){
    printf("%.10f\n",d*sqrt(2.0));
    return 0;
  }
  printf("%.10f\n",max(floor(d)+1.0,sqrt(2)*d));
  return 0;
}

Measured memory_bytes: 3280
#include<iostream>

using namespace std;


int main()
{
	int h;
	int r;

	cin >> h >> r;

	if (h < 0 && h + r == 0)
	{
		cout << "0" << endl;
	}
	else if (h+r>0)
	{
		cout << "1"<<endl;
	}
	else
	{
		cout << "-1"<<endl;
	}

	return 0;
}


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

int main(){
  int N;
  cin>>N;
  string s,t;
  cin>>s>>t;
  string kk="";
  for(int i=0;i<N;i++){
    kk+=s[i];
    kk+=t[i];
  }
  cout<<kk<<endl;
}

Measured memory_bytes: 3644
N, K = map(int, input().split())
d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

hito = [i for i in range(1, N+1)]


for i in range(N):
    name = hito[i]
    for j in range(K):
        if name in A[j]:
            hito[i] = -1
            break

ans = set(hito)
print(len(ans)-1)


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll a;
    cin >> a;
    string s;
    cin >> s;
    if(a>=3200) cout << s << endl;
    else cout << "red" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[11];
ll n;
int sx(int ni)
{
	ll flag=0,i=0;
	for(i=0;i<n;i++)
	{
		if(arr[i]==ni)
		{flag=1;break;
		}
	}
	return flag;
}

int main()
{
	ll i,j,k,a=0,s=0,b;
	ll xx[3][3];
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++) cin>>xx[i][j];
	}
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	
	if(sx(xx[0][0])==1 && sx(xx[0][1])==1 && sx(xx[0][2])==1)
	{cout<<"Yes";
	}
	else if(sx(xx[1][0])==1 && sx(xx[1][1])==1 && sx(xx[1][2])==1)
	{cout<<"Yes";
	}
	
	else if(sx(xx[2][0])==1 && sx(xx[2][1])==1 && sx(xx[2][2])==1)
	{cout<<"Yes";
	}
	
	else if(sx(xx[0][0])==1 && sx(xx[1][0])==1 && sx(xx[2][0])==1)
	{cout<<"Yes";
	}
		else if(sx(xx[0][1])==1 && sx(xx[1][1])==1 && sx(xx[2][1])==1)
	{cout<<"Yes";
	}
		else if(sx(xx[0][2])==1 && sx(xx[1][2])==1 && sx(xx[2][2])==1)
	{cout<<"Yes";
	}
		else if(sx(xx[0][0])==1 && sx(xx[1][1])==1 && sx(xx[2][2])==1)
	{cout<<"Yes";
	}
		else if(sx(xx[2][0])==1 && sx(xx[1][1])==1 && sx(xx[0][2])==1)
	{cout<<"Yes";
	}
	else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long int N, a[100001] = {}, biggest = 0, smallest = 100000, num[100002] = {}, nBiggest = 0;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
		if (biggest < a[i])biggest = a[i];
		if (smallest > a[i])smallest = a[i];
		num[a[i]]++;
		num[a[i] + 1]++;
		num[a[i] + 2]++;
	}
	for (int i = smallest; i <= biggest + 2; i++) {
		if (nBiggest < num[i])nBiggest = num[i];
	}
	cout << nBiggest << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

struct asumikana {
	uint32_t a;
	uint64_t b;
};

int amamiyasora(const void* x, const void* y) {
	struct asumikana a = *(const struct asumikana*)x, b = *(const struct asumikana*)y;
	return a.a < b.a ? -1 : a.a > b.a;
}

uint32_t N;
uint64_t K;
struct asumikana horieyui[114514];

int main(void) {
	uint32_t i;
	if (scanf("%" SCNu32 "%" SCNu64, &N, &K) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNu32 "%" SCNu64, &horieyui[i].a, &horieyui[i].b) != 2) return 1;
	}
	qsort(horieyui, N, sizeof(*horieyui), amamiyasora);
	for (i = 1; i < N; i++) {
		horieyui[i].b += horieyui[i - 1].b;
	}
	if (horieyui[0].b >= K) {
		printf("%" PRIu32 "\n", horieyui[0].a);
	} else {
		uint32_t mada = 0, ok = N - 1;
		while (mada + 1 < ok) {
			uint32_t mid = mada + (ok - mada) / 2;
			if (horieyui[mid].b >= K) ok = mid; else mada = mid;
		}
		printf("%" PRIu32 "\n", horieyui[ok].a);
	}
	return 0;
}


Measured memory_bytes: 3324
/*In the name of Allah*/
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define MAX 100011
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if(b + c <= a)cout<<0;
	else cout<<c - a + b;
	return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string T = Console.ReadLine();
        int i;
        int g = 0, p = 0, ans = 0;
        for (i = 0; i < T.Length; i++)
        {
            if (T[i] == 'g')
            {
                if (g > 0)
                {
                    ans++;
                    g--;
                }
                else g++;
            }
            else
            {
                if (g > 0) g--;
                else
                {
                    g++;
                    ans--;
                }
            }
        }
        Console.WriteLine(ans);
    }
}


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

using Matrix = array<array<int, 26>, 26>;

struct Trie
{
    array<Trie*, 26> children;
    Matrix* counts;
    int prefixes, size;
    bool is_terminal;

    Trie* insert(string::const_iterator c)
    {
        size++;
        if (*c == 0)
        {
            is_terminal = true;
            return this;
        }
        else
        {
            auto& child = children[*c-'a'];
            if (child == nullptr) child = new Trie{};
            return child->insert(next(c));
        }
    }

    void preprocess(Matrix& current)
    {
        if (is_terminal) counts = new Matrix(current);

        for (auto i = 0; i < 26; i++) if (children[i] != nullptr)
        {
            children[i]->prefixes = prefixes + is_terminal;

            for (auto j = 0; j < 26; j++) if (j != i && children[j] != nullptr)
                current[j][i] += children[j]->size;

            children[i]->preprocess(current);

            for (auto j = 0; j < 26; j++) if (j != i && children[j] != nullptr)
                current[j][i] -= children[j]->size;
        }
    }
};

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

    auto trie = new Trie{};

    int N; cin >> N;
    auto nodes = vector<Trie*>(N);
    for (auto i = 0; i < N; i++)
    {
        string s; cin >> s;
        nodes[i] = trie->insert(s.cbegin());
    }

    auto counts = Matrix{};
    trie->preprocess(counts);

    int Q; cin >> Q;
    for (auto q = 0; q < Q; q++)
    {
        int k; string order; cin >> k >> order;
        k--;

        auto result = nodes[k]->prefixes;
        for (auto j1 = 0; j1 < 26; j1++) for (auto j2 = j1+1; j2 < 26; j2++)
            result += (*nodes[k]->counts)[order[j1]-'a'][order[j2]-'a'];
        cout << result+1 << "\n";
    }
}


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

const int MAX = 500000;
int n;

void maxHeapify(int *A,int i){
    int l = 2 * i, r = 2 * i + 1, largest;
    if(l <= n && A[l-1] > A[i-1]) largest = l;
    else largest = i;
    if(r <= n && A[r-1] > A[largest-1]) largest = r;
    if(largest != i){
        swap(A[i-1], A[largest-1]);
        maxHeapify(A, largest);
    }
}

void buildMaxHeap(int *A){
    for(int i=n/2;i>0;i--) maxHeapify(A, i);
}

int main(){
    while(cin >> n){
        int a[MAX];
        for(int i=0;i<n;i++) cin >> a[i];
        buildMaxHeap(a);
        for(int i=0;i<n;i++) cout << ' ' << a[i];
        cout << endl;
    }
}

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

int main(){
  ll n; cin >>n;
  string ans = "";
  while(n>0){
    n--;
    ans += (n%26)+'a';
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0; 
}

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

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

using namespace std;

int main(){
	int h,w,n,y0,x0;
	string s,t;
	cin>>h>>w>>n>>y0>>x0>>s>>t; y0--; x0--;

	bool ok=true;
	int p=y0;
	rep(i,n){
		if(s[i]=='U'){
			p--;
			if(p<0) ok=false;
		}
		if(t[i]=='D') p=min(p+1,h-1);
	}
	p=y0;
	rep(i,n){
		if(s[i]=='D'){
			p++;
			if(p>=h) ok=false;
		}
		if(t[i]=='U') p=max(p-1,0);
	}
	p=x0;
	rep(i,n){
		if(s[i]=='L'){
			p--;
			if(p<0) ok=false;
		}
		if(t[i]=='R') p=min(p+1,w-1);
	}
	p=x0;
	rep(i,n){
		if(s[i]=='R'){
			p++;
			if(p>=w) ok=false;
		}
		if(t[i]=='L') p=max(p-1,0);
	}
	puts(ok?"YES":"NO");

	return 0;
}


Measured memory_bytes: 776
def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(input())

    A.sort()

    d = {}
    x = A[0]
    cnt = 1
    # print(A)
    for ai in A[1:]:
        if ai == x:
            cnt += 1
        else:
            d[x] = cnt
            x = ai
            cnt = 1
    d[x] = cnt

    ans = 0
    for i in d.values():
        if i % 2 == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
	int n;
	cin >> n;
	int a[21], b[21], c[21];
	fori(n) cin >> a[i];
	fori(n) cin >> b[i];
	fori(n - 1) cin >> c[i];
	int s = 0;
	int l = n + 5;
	fori(n) {
		s += b[a[i] - 1];
		if (a[i] - 2 == l) {
			s += c[l];
		}
		l = a[i] - 1;
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  ll n,a,b;
  cin>>n>>a>>b;
  if(n%(a+b)<=a)
  cout<<(n/(a+b))*a+n%(a+b)<<endl;
  else
  cout<<(n/(a+b))*a+a<<endl;
  
    
  
 
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef FIO
const int S = 1 << 21;
char p0[S],*p1,*p2;
#ifndef ZXY
#define getchar() (p2 == p1 && (p2 = (p1 = p0) + fread(p0,1,S,stdin)) == p1 ? EOF : *p1++)
#endif
inline int read() {
	static int x,c;x = 0;
	do{c = getchar();}while(!isdigit(c));
	do{x = (x << 3) + (x << 1) + (c & 15);c = getchar();}while(isdigit(c));
	return x;
}
#endif
int a,b;
int main() {
	cin >> a >> b;
	if(2*a <= b && b <= 4*a && b % 2 == 0) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
typedef long long ll;

int main(){
  int n, m, h, w, b, f, r ,v;
  m = 4, h = 3, w = 10;
  int a[m][h][w] = {};
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> b >> f >> r >> v;
    a[b-1][f-1][r-1] += v;
  }
  for (int i = 0; i < m; i++){
    for (int j = 0; j < h; j++){
      for (int k = 0; k < w; k++){
        cout << " " << a[i][j][k];
        if (k == w-1) cout << endl;
      }
    }
    if (i != m-1) cout << "####################" << endl;
  }

  return 0;
}


Measured memory_bytes: 3124
#define DEBUG 0
/**
 * File    : D2.cpp
 * Author  : Kazune Takahashi
 * Created : 2019/9/8 0:14:32
 * Powered by Visual Studio Code
 */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using ll = long long;
class mint
{
public:
  static ll MOD;
  ll x;
  mint() : x(0) {}
  mint(ll x) : x(x % MOD) {}
  mint operator-() const { return x ? MOD - x : 0; }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  mint &operator-=(const mint &a) { return *this += -a; }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint &operator/=(const mint &a)
  {
    mint b{a};
    return *this *= b.power(MOD - 2);
  }
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
  const mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      mint half = power(N / 2);
      return half * half;
    }
  }
};
ll mint::MOD = 1e9 + 7;
istream &operator>>(istream &stream, mint &a) { return stream >> a.x; }
ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; }
class combination
{
public:
  vector<mint> inv, fact, factinv;
  static int MAX_SIZE;
  combination() : inv(MAX_SIZE), fact(MAX_SIZE), factinv(MAX_SIZE)
  {
    inv[1] = 1;
    for (auto i = 2; i < MAX_SIZE; i++)
    {
      inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for (auto i = 1; i < MAX_SIZE; i++)
    {
      fact[i] = mint(i) * fact[i - 1];
      factinv[i] = inv[i] * factinv[i - 1];
    }
  }
  mint operator()(int n, int k)
  {
    if (n >= 0 && k >= 0 && n - k >= 0)
    {
      return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
  }
};
int combination::MAX_SIZE = 3000010;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// constexpr double epsilon = 1e-10;
// constexpr ll infty = 1000000000000000LL;
// constexpr int dx[4] = {1, 0, -1, 0};
// constexpr int dy[4] = {0, 1, 0, -1};
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}

int main()
{
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  int score{0};
  for (auto i = 0; i < N - 1; i++)
  {
    if (S[i] == S[i + 1])
    {
      ++score;
    }
  }
  int ans{min(score + 2 * K, N - 1)};
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>

#include <sstream>
#include <fstream>
#include <cmath>
#include <vector>


using namespace std;


void check( string val ){
	
	cout << val << endl;
}

int main( int argc , char ** argv ){
	
	string X;
	cin >> X;

	// check(X);

	bool ST_check = false;
	int S_count = 0;
	int T_count = 0;
	int m_count = 0;


	int start = 0;
/*
	while(1){
		if(X[start] == 'S' )break;
		start ++;
	}
*/

	for(int i = start ; i < X.length() ; i++){

		if(X[i] == 'S'){
			
			if(!ST_check){

				int num = (S_count <= T_count) ? S_count : T_count;
				m_count += num*2;
				S_count -= num;
				T_count =0;
			}
			ST_check = true;
			S_count ++;
		}

		if(X[i] == 'T'){

			T_count ++;
			ST_check = false;
		}
	}

	if(!ST_check){

		int num = (S_count <= T_count) ? S_count : T_count;
		m_count += num*2;
	}

	cout << X.length() - m_count << endl;
	
}



Measured memory_bytes: 640
while 1:
    r, c = map(int, raw_input().split())
    if r == 0: break
    old = [raw_input().split() for i in range(r)]
    old = map(list, zip(*old))
    new = [int("".join(lst),2) for lst in old]
    ans = 0
    for i in range(1<<r):
        ret = 0
        for j in new:
            cnt = bin(i^j).count('1')
            ret += cnt if cnt > r/2 else r-cnt
        ans = max(ans, ret)
    print ans

Measured memory_bytes: 10664
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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 n2(int a) {
  int ret = 0;
  while (a%2 == 0) {
    a /= 2;
    ret++;
  }
  return ret;
}

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  
  ll ans = 0;
  rep(i,n) {
    ans += n2(a[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り　0:ON　1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if(system==0) param.add(sc.next());
				if(system==1) param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		boolean flag = false;
		String target = "";
		
		param = new ArrayList<String>(Arrays.asList(param.get(0).split("")));
		int size = param.size();

		for(int i = 0; i < size; i++){
			target = param.get(0);
			param.remove(0);
			if(param.contains(target)) flag = true;
		}
		
		if(!flag){
			System.out.println("yes");
		} else {
			System.out.println("no");
		}
	}
}

Measured memory_bytes: 21972