akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; string s; int q; cin >> n >> s >> q;
    vector<set<int>> alpha(26);
    // set<int> alpha[26];
    rep(i, s.size()) {
        alpha[s[i]-'a'].insert(i);
    }
    rep(i, q) {
        int type; cin >> type;
        if (type == 1) {
            int k; char d; cin >> k >> d;
            k--;
            alpha[s[k]-'a'].erase(k);
            alpha[d-'a'].insert(k);
            s[k] = d;
        }
        if (type == 2) {
            int l, r; cin >> l >> r;
            l--; r--;
            int cnt = 0;
            rep(j, 26) {
                auto tmp = alpha[j].lower_bound(l);
                if (tmp != alpha[j].end() && *tmp <= r) {
                    cnt++;
                }
            }
            cout << cnt << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 26268
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;
constexpr ll INF = MOD * MOD;
inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int n;
    cin >> n;
    vector<long long> A(n + 1);
    for(auto& x : A) cin >> x;
    if(n == 0) {
        if(A[0] == 1) {
            cout << 1 << '\n';
        }
        else cout << -1 << '\n';
        return 0;
    }
    if(A[0] != 0) {
        cout << -1 << '\n';
        return 0;
    }
    
    vector< pll > large(n + 1);
    large[n] = make_pair(A[n], A[n]);
    for(int i = n; i > 0; --i)
    {
        large[i - 1] = make_pair(A[i - 1], A[i - 1]);
        // agora quero saber quanto tem que ter na estimativa mais conservadora
        long long low = large[i].first / 2 + (large[i].first % 2);
        long long hi  = large[i].second;
        large[i - 1].first += low;
        large[i - 1].second += hi;
    }

    if(large[0].first > 1 || large[0].second < 1) {
        cout << "-1\n";
        return 0;
    }
    
    // agora vamos fazer as contas
    vector< long long > actual(n + 1, 0ll);
    long long res = 0ll; 
    actual[0] = 1ll;
    for(int i = 1; i <= n; ++i)
    {
        // desses podem vir 1 ou 2 filhos
        long long max_down = (actual[i - 1] - A[i - 1]);
        
        long long kid_hi = 2 * max_down;
        long long kid_lo = max_down;
        
        if(kid_lo > large[i].second) {
            cout << -1 << '\n';
            return 0;
        }
        if(kid_hi < large[i].first) {
            cout << -1 << '\n';
            return 0;
        }
        actual[i] = min(large[i].second, kid_hi);
    }
    for(int i = 0; i <= n; ++i) res += actual[i];
    cout << res << '\n';
    return 0;
}



Measured memory_bytes: 6316
# readtest
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	str = readlines()
	#println(str)
	a = Array{Int}(2,n)
	for i in 1:n
		a[:,i] = str[i] |> split |> parseMap
	end
	a = sortcols(a, by=z->z[2])
	t = 0
	flg = 0
	for i in 1:n
		t += a[1,i]
		if t > a[2,i]
			flg = 1
			break
		end
	end
	println(flg==0?"Yes":"No")
end

main()


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

ll solve() {
    auto check = [](ll x) {
        cout << "? " << x << std::endl;
        char a;
        cin >> a;
        return a == 'Y';
    };

    ll l = 1e10, r = 1e11;
    while ( r - l > 1 ) {
        ll m = (l+r)/2;
        if ( check(m) ) r = m;
        else l = m;
    }
    ll x = r / 10, t = x;
    while ( t % 10 == 0 ) t /= 10;
    if ( t != 1 ) {
        while ( !check(x-1) ) x /= 10;
    } else {
        while ( x > 1 && check(x-1) ) x /= 10;
    }
    cout << "! " << x << std::endl;
    return 0;
}

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

Measured memory_bytes: 720
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define lo long
const long long lmax=1999999999;
const long long lmx=1999999999999999999;
vector<long long>dp(100003,0);
long long n,W;
vector<long long>dpp(100003,0);
long long w[100003];
long long v[100003];
int main(){std::ios::sync_with_stdio(false);
cin>>n>>W;
for(long long i=1;i<=n;i++){
	cin>>w[i]>>v[i];
}
for(long long i=1;i<=n;i++){
	dpp=dp;
	for(long long j=0;j<=W;j++){
//		cout<<j<<" "<<w[i]<<endl;
		if(j-w[i]>=0){
			dpp[j]=max(dp[j],dp[j-w[i]]+v[i]);
//			cout<<dpp[j]<<" "<<j<<endl;
		}
	}
	dp=dpp;
}
for(long long i=W;i>=0;i--){
	if(dp[i]>0){
		cout<<dp[i]<<endl;
		return 0;
	}
}
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int a, b, c;
    cin>>a>>b>>c;
    int x = 0;
    for(int i=a; i<=a*b; i+=a){
        if(i%b==c){
            cout<<"YES"<<endl;
            return 0;
        }
        x++;
    }
    cout<<"NO"<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N, K; cin >> N >> K;
  ll A[N]; rep(i,N) { cin >> A[i]; A[i]--; }

  ll to[N]; rep(i,N) to[i] = A[i];
  ll result[N]; rep(i,N) result[i] = i;
  ll p2 = 1;
  while (K>=p2) {
    if (K&p2) rep(i,N) result[i] = to[result[i]];
    ll tmp[N]; rep(i,N) tmp[i] = to[to[i]];
    rep(i,N) to[i] = tmp[i];
    p2 *= 2;
  }
  // debug(result,result+N);

  cout << result[0]+1 << endl;
  return 0;
}

Measured memory_bytes: 9876
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))

ans = []
while 1:
	n = INT()
	if n == 0:
		break

	a = LIST()
	ave = sum(a)/n
	count = 0
	for i in a:
		if i <= ave:
			count += 1
	ans.append(count)
for i in ans:
	print(i)



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

int main(void) {
	int n;
	cin >> n;
	int left, right;
	right = 0;
	cin >> left;
	for (int i = 1; i < n; i++)
	{
		cin >> right;
		if (left - right > 0)
		{
			cout << "No";
			return 0;
		}
		if (abs(right - left) >= 1)
		{
			right--;
		}
		left = right;
	}

	cout << "Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int CNT = 0;
bool man(int x){
    CNT++;
    if(CNT > 20) assert(false);
    printf("%d\n", x);
    fflush(stdout);
    char s[10];
    scanf("%s", s);
    if(s[0] == 'V') exit(0);
    else if(s[0] == 'M') return true;
    else return false;
}
int main(){
    int n;
    scanf("%d", &n);
    bool p = man(0);
    int lo = 1;
    int hi = n - 1;
    while(lo <= hi){
        int md = (lo + hi) / 2;
        bool same = (md % 2 == 0);
        bool q = man(md);
        if(same == (p == q)) lo = md + 1;
        else hi = md - 1;
    }
    return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

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

int main() {
    cout << fixed << setprecision(10);
    
    int N, M; cin >> N >> M;
    vector<int> a(N);
    rep(i, N) cin >> a[i];

    rep(i, N) {
        a[i] /= 2;
    }
    int div = 1;
    int a0 = a[0];
    while (a0 % 2 == 0) {
        div *= 2;
        a0 /= 2;
    }

    // int gdiv = pow(2, div_count):
    rep(i, N) {
        // 2^yでわっていく
        // 素因数に2が多い場合と2が少ない場合がある
        if (a[i] % div != 0) {
            // 2^yで割って、あまりがある
            // 素因数少ない
            cout << 0 << endl;
            return 0;
        }
        a[i] /= div;
        if (a[i] % 2 == 0) {
            // 素因数多い
            cout << 0 << endl;
            return 0;
        }
    }
    // Mも
    M /= div;

    ll glcm = 1;
    rep(i, N) {
        glcm = lcm(glcm, a[i]);
    }

    int ans = (M/glcm+1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    set<int> s;
    s.insert(A), s.insert(B), s.insert(C);
    if(s.size() == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
def solve():
    from itertools import combinations
    from collections import Counter
    n = int(input())
    s = list(map(int, input().split()))
    co = Counter(s)
    uni = set(s)
    cnt = 0
    for a, b, c in combinations(uni, 3):
        # print(a, b, c)
        if not(a + b <= c or b + c <= a or c + a <= b):
            cnt += co[a] * co[b] * co[c]
    print(cnt)

solve()


Measured memory_bytes: 9456
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){
    int N;
	cin >> N;
    if(N == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    vector<long long> x(N);
    vector<long long> y(N);

    REP(i,N)
    {
        cin >> x[i] >> y[i];
    }

	int res = N;

    for(int i = 0; i < N; ++i)
    {
        for(int j = 0; j < N; ++j)
        {

            if(i == j)continue;
            //各2点間の距離を全て試して最小値を導く
            ll dx = x[j] - x[i];
            ll dy = y[j] - y[i];

            int sub = 0;
            for(int i2 = 0; i2 < N; ++i2)
            {
                for(int j2 = 0; j2 < N; ++j2)
                {
                    if(i2 == j2)continue;
                    if(dx == x[j2]-x[i2] && dy == y[j2]- y[i2])
                    {
                        ++sub;
                    }

                    res = min(res, N - sub);
                }
            }
        }
    }

	cout << res << endl;


    return 0;    
}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

#define rep(i,m,n) for(ll i=m;i<n;i++)

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

 ll n;
  cin >> n;
  vector<long> a(n);
  rep(i,0,n) cin >> a[i];

 ll res=0; 
 ll r=0,sum=0;
  
  rep(l,0,n){
   while(r<n&&(sum&a[r])==0) sum^=a[r++];
   res+=r-l;  
    if(r==l) r++;
    else sum^=a[l]; 
  }
  
  cout << res <<endl;
  
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
//*/
/*
#include <iostream>
#include <vector>
#include <string.h>
//*/
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
#define int long long
#ifdef int
    const long long INF = LLONG_MAX / 10;
#else
    const int INF = 1010101010;
#endif
 
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
 
//遅延評価セグメント木（区間加算区間和）
struct LazySegmentTree
{
private:
    int n;
    vector<ll> node, lazy;
 
public:
    //初期化
    LazySegmentTree(vector<ll> v)
    {
        int sz = (int)v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2 * n - 1);
        lazy.resize(2 * n - 1, 0);
 
        for (int i=0; i<sz; i++) node[i+(n-1)] = v[i];
        for (int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }
 
    //k番目のノードについて遅延評価を行う
    void eval(int k, int l, int r)
    {
        //遅延配列が空でない場合、自ノード及び子ノードへの
        //値の伝播が起こる
        if (lazy[k] != 0) {
            node[k] += lazy[k];
 
            //最下段かどうかのチェックをする
            //子ノードは親ノードの1/2の範囲であるため、
            //伝播させるときは半分にする
            if (r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
 
            //伝播が終わったので、自ノードの遅延配列を空にする
            lazy[k] = 0;
        }
    }
 
    //区間加算
    void add(int a, int b, ll x, int k=0, int l=0, int r=-1)
    {
        if (r < 0) r = n;
 
        //k番目のノードに対して遅延評価を行う
        eval(k, l, r);
 
        //範囲外なら何もしない
        if (b <= l || r <= a) return;
 
        //完全に被覆しているならば、遅延配列に値を入れた後に評価
        if (a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
 
        //そうでないならば、子ノードの値を再帰的に計算して、
        //計算済みの値をもらってくる
        else {
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }
 
    //区間和の取得
    ll getsum(int a, int b, int k=0, int l=0, int r=-1)
    {
        if (r < 0) r = n;
 
        //関数が呼び出されたらまず評価
        eval(k, l, r);
 
        if (b <= l || r <= a) return 0;
        if (a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};
 
signed main()
{
    int n, q;
 
    cin >> n >> q;
    vector<ll> a(n, 0);
    LazySegmentTree lst(a);
 
    REP(i,q) {
        int type;
        cin >> type;
        if (type == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            lst.add(s - 1, t, x);
        } else {
            int s, t;
            cin >> s >> t;
            cout << lst.getsum(s - 1, t) << endl;
        }
    }
}


Measured memory_bytes: 8420
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
    static void solve(){//Here is the main function
      ArrayList<Integer> one = nextIntArray();
      int A = one.get(0);
      int B = one.get(1);
      int output = A + B;
      if(A + B >= 24){
        output -= 24;
      }
      myout(output);
	}
	//Method addition frame start


  
	//Method addition frame end
}


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

using namespace std;

int R, C, x[10005], n, a = 1, banyak, y[105][105];
int main(){
    cin >> R >> C;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> x[i];
    }
    for(int r=1; r<=R; r++){
        if(r%2 == 1){
            for(int c=1; c<=C; c++){
                if(banyak == x[a]){
                    a++;
                    y[r][c] = a;
                    banyak = 1;
                }
                else{
                    y[r][c] = a;
                    banyak++;
                }
            }
        }
        else{
            for(int c=C; c>=1; c--){
                if(banyak == x[a]){
                    a++;
                    y[r][c] = a;
                    banyak = 1;
                }
                else{
                    y[r][c] = a;
                    banyak++;
                }
            }
        }
    }
    for(int r=1; r<=R; r++){
        for(int c=1; c<=C; c++){
            if(banyak == x[a]){
                a++;
                cout << y[r][c];
                banyak = 1;
            }
            else{
                cout << y[r][c];
                banyak++;
            }
            cout << " ";
        }
        cout << endl;
    }
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i,n)cin >> v[i];
  vector<ll> pre(200200,0);
  vector<ll> dp(n+1,0);
  dp[0] =  1;
  v.erase(unique(ALL(v)),v.end());
  rep(i,v.size()){
    (dp[i+1] += pre[v[i]])%= MOD;
    (pre[v[i]] += dp[i])%= MOD;
    (dp[i+1] += dp[i])%= MOD;
  }
  cout << dp[v.size()] << endl;





  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int X; cin >> X;
    if(X/100*105>=X) cout << 1 << endl;
    else cout << 0 << endl;    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int w[200005];
int v[200005];
int W;
LL dp[101][200005];
int n;
LL f(int i,int W){
    if(i==n || W==0) return 0;
    if(dp[i][W]!=-1) return dp[i][W];
    if(W-w[i]>=0) return dp[i][W] = max(v[i]+f(i+1,W-w[i]),f(i+1,W));
    else return dp[i][W] = f(i+1,W);
}
void solve(){
   cin>>n>>W;
   for(int i=0;i<n;i++){
       cin>>w[i]>>v[i];
       for(int j=0;j<=W;j++){
           dp[i][j] = -1;
       }
   }
   cout<<f(0,W)<<endl;

}
int main(){
    int t;
    t = 1;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 155136
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <vector>
#include<valarray>
#include<map>
#include <bits/stdc++.h>
#include <utility>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int K, N;
    cin >> N >> K;
    int p[1001];
    for (int i = 0; i < N; i++)
    {
        cin >> p[i];
    }
    int minm = p[0], index = 0, sum = 0;
    for (int i = 0; i < K; i++)
    {
        
        for (int j = 0; j < N; j++)
        {
            if (minm > p[j] && p[j] !='\0')
            {
                minm = p[j];
                index = j;
            }
        }
        sum += minm;
        p [index] = '\0';
        for (int j = 0; j < N; j++)
        {
            if (p[j] != '\0')
            {
                minm = p[j];
                index = j;
                break;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define mx 1000000000000000000
#define ll long long int
int main()
{
   ll a,len,i,j,n;
   string s;
   cin>> n >> s;
   if(s.size()>n)
   {
       s= s.substr(0,n)+"...";
   }
   cout << s << endl;
    return 0;
}


Measured memory_bytes: 3584
N = int(input())
l = sorted(list(map(int, input().split())))
 
from bisect import bisect_left

cnt = 0
for i in range(N):
    a = l[i]
    for j in range(i+1, N):
        b = l[j]
        cnt += bisect_left(l[j+1:], a+b)
print(cnt)

Measured memory_bytes: 51948
#include <iostream>
#include <string>
#include <utility>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
#define loop(i,n) for(int i=0;i<n;i++)

int main(){

  int n;
  cin>>n;
  long long tt=1,aa=1;
  
  loop(i,n){
    int t,a;
    cin>>t>>a;
    long long s;
    if(tt*a==aa*t)continue;
    if(tt/t>aa/a){
      s=tt/t;
      if(tt%t)s++;
    }else{
      s=aa/a;
      if(aa%a)s++;
    }
    tt=t*s;
    aa=a*s;
  }
  cout<<(tt+aa);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a),end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int inpX, inpY, total;

    while( cin >> inpX >> inpY >> total, inpX||inpY||total ){
        int max = 0;
        int x = inpX + 100, y = inpY + 100;
        for(int i = 1; i < 1000; i++){
            if(i > total) break;
            for(int j = 1; j < 1000; j++){
                if(i + j > total) break;
                if(i * x / 100 + j * x / 100 == total && i * y / 100 + j * y / 100 > max){
                    max = i * y / 100 + j * y / 100;
                }
            }
        }
        cout << max << endl;
    }
}

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

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

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

  int a, b;
  cin >> a >> b;
  int ans;

  if (b % a == 0) {
    ans = a + b;
  } else {
    ans = b - a;
  }

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


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

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    string s;
    cin>>s;
    int sz=s.size();
    string last="#";
    int ses=0;
    f(i,0,sz-1)
    {
        string ch="";
        ch+=s[i];
        if(ch!=last)
        {
            ses++;
            last=ch;
        }
        else if(i<sz-1)
        {
           ch=ch+s[i+1];
           last=ch;
           ses++;
           i++;
        }
    }
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 3784
#include <stdio.h>
int main(void){
    int x,y,t;
    while(1){
        scanf("%d %d",&x,&y);
        if (x==0 && y==0) break;
        if (x>y)
        t=x,x=y,y=t;
        printf("%d %d\n",x,y);
    }
    
    return 0;
}


Measured memory_bytes: 1984
#include <iostream>
using namespace std;
struct CARD{char st;int value;};

void output(CARD C[], int N,string stableResult){
    
    for (int i=0; i<N; i++){
        if (i==N-1)
        {
            cout << C[i].st << C[i].value << endl;
            cout << stableResult << endl;
        }
        else
        {
            cout << C[i].st << C[i].value << flush;
            cout << " " << flush;
        }
    }
}

void BubbleSort(CARD A[],int N){
    
    for (int j=0; j!=N-1; j++){
        for (int i=N-1; i>j; i--){
            if (A[i-1].value > A[i].value){
                swap(A[i], A[i-1]);
            }
        }
    }
}

void SelectionSort(CARD B[],int N){
    
    int minj;
    
    for (int i=0; i<N; i++){
        minj=i;
        for (int j=i; j<N; j++){
            if (B[minj].value > B[j].value){
                minj=j;
            }
        }
        swap(B[minj], B[i]);
    }
}

int main() {
    
    int N;
    string stableResult;
    bool stableFlg;

    CARD A[36],B[36];
    
    cin >> N;
    
    for (int i=0; i<N; i++){
        cin >> A[i].st >> A[i].value;
    }
    
    for (int i=0; i<N; i++){
        B[i]=A[i];
    }

    BubbleSort(A,N);
    stableResult = "Stable";
    output(A, N,stableResult);

    SelectionSort(B,N);
    stableFlg=1;
    for (int i=0; i<N; i++){
        if (B[i].st!=A[i].st){
            stableFlg=0;
        }
    }
    if (stableFlg){
        stableResult = "Stable";
    }
    else{
        stableResult = "Not stable";
    }
    output(B, N,stableResult);

    return 0;
}


Measured memory_bytes: 3196
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int h, w;
    cin >> h >> w;

    vector<string> a(h);
    rep(i, h) cin >> a[i];

    if(a[0][0] != '#'){
        cout << "Impossible" << endl;
        return 0;
    }

    vector<vector<bool>> mark(h, vector<bool>(w, false));
    int x = 0;
    int y = 0;
    mark[x][y] = true;
    while(x < h && y < w){
        if(x + 1 < h && a[x+1][y] == '#'){
            mark[x+1][y] = true;
            x++;
            continue;
        }
        if(y + 1 < w && a[x][y+1] == '#'){
            mark[x][y+1] = true;
            y++;
            continue;
        }
        if(x != h-1 && y != w-1){
            cout << "Impossible" << endl;
            return 0;
        }
        break;
    }

    rep(i, h){
        rep(j, w){
            if(not mark[i][j] && a[i][j] == '#'){
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }
    cout << "Possible" << endl;

    return 0;
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<int> a(n+1),b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];

    ll ans = 0;
    for(int i = n-1; i >= 0; i--){
        int l = min(a[i+1], b[i]);
        ans += (ll)l;
        a[i+1] -= l;
        b[i] -= l;
        int r = min(a[i],b[i]);
        a[i] -= r;
        b[i] -= r;
        ans += (ll)r;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, z, w;
  cin >> n >> z >> w;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll ans;
  if(n == 1)
    ans = abs(a[0] - w);
  else {
    ans = max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def solve(s):
    n = len(s)
    t = "".join(filter(lambda _: _!= "x", s))
    if t != t[::-1]:
        return -1
    l = 0
    r = n-1
    res = 0
    while l < r:
        nl = 0
        while (l < r) and (s[l] == "x"):
            nl += 1
            l += 1
        nr = 0
        while (l < r) and (s[r] == "x"):
            nr += 1
            r -= 1
        if (s[l] == s[r]) and (s[l] != "x"):
            res += abs(nl - nr)
        l += 1
        r -= 1
    return res

assert solve("xabxa") == 2
assert solve("ab") == -1
assert solve("a") == 0
assert solve("oxxx") == 3
assert solve("axxxa") == 0

s = input()
print(solve(s))

Measured memory_bytes: 4084
n,m =map(int,input().split())

foods =set([ i+1 for i in range(m)])


for _ in range(n):
    k = list(map(int,input().split()))
    fav = set(k[1:])

    foods = foods&fav

if len(foods)!=0:
    print(len(foods))
else:
    print(0)

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

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

	int a, b;
	string	s;
	cin >> a >> b >> s;
	if (s.size() != a + b + 1)
	{
		cout << "No" << endl;
		return (0);
	}
	int i;
	i = 0;
	while (i < a)
	{
		if (!(isdigit(s.at(i))))
		{
			cout << "No" << endl;
			return (0);
		}
		i++;
	}
	if (s.at(i) != '-')
	{
		cout << "No" << endl;
		return (0);
	}
	i++;
	rep(j, b)
	{
		if (!(isdigit(s.at(i))))
		{
			cout << "No" << endl;
			return (0);
		}
		i++;
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
/*
    Author: isaf27 (Ivan Safonov)
*/

//#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fast_read cin.sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-10;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 2 * 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    ll ans = 1;
    while (k)
    {
        if (k & 1) ans = (ans * a) % MOD;
        ans = (ans * ans) % MOD;
        k >>= 1;
    }
    return ans;
}

//random
mt19937 rnd(239);

//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 19);
const int B = trunc(sqrt(M)) + 1;
const int X = 10;

// Code starts here

int n, k, q, a[N];

int main()
{   //*
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif /**/
    fast_read;
    cin >> n >> k >> q;
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = BIG;
    for (int i = 0; i < n; i++)
    {
        vector<int> al;
        vector<int> v;
        for (int x = 0; x < n; x++)
        {
            if (a[x] < a[i])
            {
                sort(v.begin(), v.end());
                for (int t = 0; t < (int)v.size() - k + 1; t++) al.push_back(v[t]);
                v.clear();
            }
            else
                v.push_back(a[x]);
        }
        sort(v.begin(), v.end());
        for (int t = 0; t < (int)v.size() - k + 1; t++) al.push_back(v[t]);
        if (al.size() < q) continue;
        sort(al.begin(), al.end());
        ans = min(ans, al[q - 1] - a[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 384
//wawando's template

#include <iostream>
#include <string>
#include <fstream>
#include <functional>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <set>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>  //clock_t , clock() , CLOCKS_PER_SEC
#include <cstring>
#include <cctype>
#include <climits> // LLONG_MAX , LLONG_MIN , INT_MAX , INT_MIN

//MACROS
#define pb              push_back
#define mp              make_pair
#define INF             1000000000     //1 billion safer for floyd warshall, avoid overflow

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	//ios::sync_with_stdio(false);
  int N, K;
  int adjMat[110][110];
  scanf("%d %d", &N, &K);
  int maxK = ((N-2)*(N-1))/2;
  if(K > maxK)
    printf("-1\n");
  else {
    int M = (N*(N-1))/2;
    for(int i = 1; i <= N; i++) {
      for(int j = 1; j <= N; j++) {
        if(i == j) adjMat[i][j] = 0;
        else adjMat[i][j] = 1;
      }
    }
    int p = 1;
    int q = p + 1;
    while(K--) {
      adjMat[p][q] = 0;
      adjMat[q][p] = 0;
      M--;
      q++;
      if(q == N) {
        p++;
        q = p + 1;
      }
    }
    printf("%d\n", M);
    for(int i = 1; i <= N; i++) {
      for(int j = 1; j <= N; j++) {
        if(adjMat[i][j] == 1) {
          printf("%d %d\n", i, j);
          adjMat[i][j] = 0;
          adjMat[j][i] = 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include<math.h>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define    ll   long long int
#define    py   printf("Yes\n")
#define    pn   printf("No\n")
using namespace std;

ll hako[200000];
int main()
{
    string s;
    int tmp=100000;
    cin>>s;
    rep(i,s.size()-2)
    {
      string balue=s.substr(i,3);
      int n = stoi(balue);
      tmp = min(tmp,abs(n-753));
    }
    cout<<tmp<<endl;
    return 0;
}


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

using ll = long long;
int n;
int P;

int dp[2][5050][5050];

inline void update(int& x, int y) {
  x += y;
  if (x >= P) x -= P;
}
int main() {
  cin >> n >> P;
  n--;
  int k = n / 2;
  if (n % 2 == 1)
    dp[0][0][0] = 1;
  else {
    for (int d = 0; d < n + 2; d++)
      if (d * k < n + 2) {
        dp[0][d][d] = 1;
      }
    k--;
  }
  int p = 0;
  for (int i = 0; i < k; i++) {
    for (int j = n + 2 - 1; j >= 0; j--) {
      int cum = 0;
      int s = 0;
      for (int d = 0; d < n + 2; d++) {
        if (d * (k - i) + j < n + 2) {
          update(s, dp[p][d][j]);
          update(cum, s);
          update(dp[p ^ 1][d][d + j], cum);
          dp[p][d][j] = 0;
        } else
          break;
      }
    }
    p ^= 1;
  }
  for (int d = 0; d < n + 2; d++)
    for (int j = 1; j < n + 2; j++) {
      update(dp[p][d][j], dp[p][d][j - 1]);
    }
  ll ans = 0;
  for (int min = 1; min <= n + 1; min++) {
    int md = n + 1 - min;
    for (int d = 0; d <= md; d++) {
      ans += (md - d + 1LL) * dp[p][d][min - 1] % P;
      ans %= P;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 198912
while line=gets
(m,f,r)=line.split().map(&:to_i)
  break if m==-1&&f==-1&&r==-1
  m=f=0 if m==-1||f==-1
  case m+f
  when 80..100; puts "A"
  when 65...80; puts "B"
  when 50...65; puts "C"
  when 30...50; puts r >= 50 ? "C" : "D"
  else ; puts "F"
  end
end

Measured memory_bytes: 6104
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int X;
    cin >> X;
    bool dp[110000];
    rep(i,110000) dp[i]=false;
    dp[0]=true;
    rep(i,100000){
        if(dp[i]) rep(j,6) dp[i+100+j]=true;
    }
    if(dp[X]) cout << 1 << endl;
    else cout << 0 << endl;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

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

const lli MOD = 1000000007LL;

lli modpow(lli a, lli n){
    lli res = 1;

    for(lli ai = a; n; n>>=1){
        if(1&n) res = (res*ai)%MOD;
        ai=(ai*ai)%MOD;
    }
    return res;
}

lli inv(lli n){
    return modpow(n, MOD-2);
}

lli modperm(lli n, lli k){
    lli res = 1;
    rep(i, k){
        res = (res*(n-i))%MOD;
    }
    return res;
}

lli modcomb(lli n, lli k){
    return (modperm(n, k)*inv(modperm(k, k)))%MOD;
}

lli posmod(lli n){
    lli res = n;
    res %= MOD;
    if(res < 0) res += MOD;
    return res;
}
string s, t;

int main(void){
    cin >> s >> t;
    if(s.size()+1 == t.size()){
        if(s == t.substr(0, t.size()-1)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <stack>
#include <string>

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

int main() {
  std::string str;
  std::stack<int> s;

  while (std::cin >> str) {
    if (str[0] == '+') {
      int a = s.top();
      s.pop();
      int b = s.top();
      s.pop();
      s.push(a + b);
    } else if (str[0] == '-') {
      int a = s.top();
      s.pop();
      int b = s.top();
      s.pop();
      s.push(b - a);
    } else if (str[0] == '*') {
      int a = s.top();
      s.pop();
      int b = s.top();
      s.pop();
      s.push(a * b);
    } else {
      s.push(std::stoi(str));
    }
  }

  std::cout << s.top() << '\n';
  return 0;
}


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

#define int ll
#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e15);
constexpr ll MOD = (1e9+7);

ll b[2003][2003];

signed main() {
  int n, x; cin >> n >> x;
  vector<ll> a(n); REP(i,n) cin >> a[i];
  REP(i,n) b[i][0] = a[i];
  REP(i,n) FOR(j,1,n) {
    b[i][j] = min(b[i][j-1], a[(i-j+n)%n]);
  }
  REP(j,n) FOR(i,1,n) {
    b[i][j] += b[i-1][j];
  }
  ll ans = INF;
  REP(i,n) {
    chmin(ans, i*x+b[n-1][i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 31616
#include <stdio.h>

int main(void){
  int h,w,i,j;

  scanf("%d%d",&h,&w);
  while(h!=0 || w!=0){
    for(i=1;i<=h;i++){
      if(i%2==1){
        for(j=1;j<=w;j++){
          if(j%2==1)  printf("#");
          else printf(".");
        }
      } else {
        for(j=1;j<=w;j++){
          if(j%2==1)  printf(".");
          else printf("#");
        }
      }
      printf("\n");
    }
    printf("\n");
    scanf("%d%d",&h,&w);
  }

  return 0;
}

Measured memory_bytes: 572
#include<stdio.h>
#include<string.h>
int main(){
  int n,i,l,j;
  char s[100001];
  scanf("%d",&n);
  scanf("%s",s);
  l=strlen(s);
  for(i=0; i<n; i++){
    j=i+1;
    if(s[i]==s[j]){
      l=l-1;
    }
  }
  printf("%d\n",l);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= int(m); -- (i))
using ll = long long;
using namespace std;
 
ll f(ll b, ll n) {
    if (b < 2) return -1;
    ll acc = 0;
    for (; n; n /= b) acc += n % b;
    return acc;
}
 
ll solve(ll n, ll s) {
    // search lower half
    int sqrt_n = min<ll>(n, sqrt(n) + 3);
    REP3 (b, 2, sqrt_n) if (f(b, n) == s) return b;
    // search upper half
    if (s == n) return n + 1;
    REP3R (a, 1, sqrt_n) {
        ll b = (n - s) / a + 1;
        if (f(b, n) == s) return b;
    }
    return -1;
}
 
int main() {
    ll n, s; scanf("%lld%lld", &n, &s);
    ll result = solve(n, s);
    printf("%lld\n", result);
    return 0;
}
 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import heapq

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

fh_sum = 0
fh = []
sh_sum = 0
sh = []
for i in range(n):
    heapq.heappush(fh, a[i])
    fh_sum += a[i]
    heapq.heappush(sh, -a[-(i+1)])
    sh_sum += a[-(i+1)]

fh_sums = [fh_sum]
sh_sums = [sh_sum]
for k in range(n, 2 * n):
    fh_sum += a[k]
    heapq.heappush(fh, a[k])
    fh_sum -= heapq.heappop(fh)
    fh_sums.append(fh_sum)
    sh_sum += a[-(k+1)]
    heapq.heappush(sh, -a[-(k+1)])
    sh_sum += heapq.heappop(sh)
    sh_sums.append(sh_sum)

sh_sums = sh_sums[::-1]

ans = -float("inf")
for fh_sum, sh_sum in zip(fh_sums, sh_sums):
    score = fh_sum - sh_sum
    ans = max(ans, score)

print(ans)


Measured memory_bytes: 38420
#include<bits/stdc++.h>
#define ll long long
#define f   first
#define s   second
#define pb          push_back
#define mod         1000000007
#define hell        998244353
#define inf         1000000000000000000LL
using namespace std;
ll n,k,m;
//ll dp[15][1005];
void solve()
{   
    cin>>n;
    vector<ll> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    ll dp[n];
    dp[0]=0;
    dp[1]=dp[0]+abs(v[1]-v[0]);
    for(int i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    cout<<dp[n-1];
}

int main()
{
    ll t=1;
    //cin>>t;
    while(t--)
        solve();

}

Measured memory_bytes: 1792