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

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    ll N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    bool flag = false;
    REP(p,0,N){
        if(p * C - (N-1-p)*D <= abs(B-A) && abs(B-A) <= p * D - (N-1-p)*C ){
            flag = true;
        }
    }

    if(flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M,C; cin >> N >> M >> C;
    int count = 0;
    vector<int> B(M);
    vector<vector <int>> A(N,vector<int>(M));

    // 配列に入力
    for(int i =0 ; i < M; i++){
        cin >> B.at(i);
    }
    for(int j = 0 ; j < N; j++){
        for(int k = 0; k < M; k++){
            cin >> A.at(j).at(k);
        }
    }
    //けいさん
      for(int p = 0 ; p < N; p++){

            int ans = 0;
        for(int q = 0; q < M; q++){

            ans +=  A.at(p).at(q) * B.at(q);
        }
            ans += C;
          if( ans > 0){

              count ++;
           }
      }

    //出力
    cout << count << endl;
 return 0;
}

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

using namespace std;

typedef long long ll;

ll n;
ll a[100005];
ll ans;

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }
    sort(a, a + n);
    for(ll i = 1; i < n - 1; i++)
    {
        ans += abs(a[i]);
    }
    ans += a[n - 1] - a[0];
    printf("%lld\n", ans);
    for(ll i = 1; i < n - 1; i++)
    {
        if(a[i] > 0) printf("%lld %lld\n", a[0], a[i]), a[0] -= a[i];
        else printf("%lld %lld\n", a[n - 1], a[i]), a[n - 1] -= a[i];
    }
    printf("%lld %lld\n", a[n - 1], a[0]);
    return 0;
}


Measured memory_bytes: 2688
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll res = 0;
    queue<int> q;
    q.push(a[n - 1]);
    for (int i = n - 2; i >= 0; i--) {
        res += q.front();
        q.pop();
        q.push(a[i]);
        q.push(a[i]);
    }
    cout << res <<endl;
    return 0;
}


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

ll solve() {
    ll X, Y;
    cin >> X >> Y;
    if ( (X+Y) % 3 != 0 ) return 0;
    ll k = (X+Y)/3;
    ll x = X-k, y = Y-k;
    if ( x < 0 ) return 0;
    if ( y < 0 ) return 0;
    const ll MOD = 1e9 + 7;
    auto Add = [&](ll& x, ll y) { x = ( x + y % MOD ) % MOD; };
    auto Mul = [&](ll& x, ll y) { x = ( x * y % MOD ) % MOD; };
    auto Pow = [&](ll x, ll n) -> ll {
        ll t = x % MOD, r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) Mul(r, t);
        Mul(t, t);
        n >>= 1;
        }
        return r;
    };
    auto Inv = [&](ll a) -> ll {
        return Pow(a, MOD - 2);
    };
    ll d1 = 1, d2 = 1;
    for ( ll i = 1; i <= x; i++ ) {
        Mul(d1, k-i+1);
        Mul(d2, i);
    }
    Mul(d1, Inv(d2));
    return d1;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#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 rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
int main(){
    int n;
    cin>>n;
    int a;
    vector<int> v;
    for(int i=0; i<n; i++){
        cin >> a;
		v.push_back(a);
    }
    int flag=0;
    sort(v.begin(), v.end());
    rep1(i,n){
    if (v[i-1]==v[i]){
        flag=1;
    }
}
    if (flag==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main()
{
    int i,a,b,tmp;
    int s;
    b= 0;
    scanf("%d",&s);
    tmp = s%10;
    b+=tmp;
    s/=10;
    tmp = s%10;
    b+=tmp*10;
    s/=10;
    if(s<=12 && s>=1){
        if(b<=12 && b>=1){
            printf("AMBIGUOUS");
        }else printf("MMYY");
    }else if(b<=12 && b>=1) printf("YYMM");
    else printf("NA");
}


Measured memory_bytes: 128
S = list(input())
if S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]:
  print('Yes')
elif S[0]==S[2] and S[1]==S[3] and S[0]!=S[3]:
  print('Yes')
elif S[0]==S[3] and S[1]==S[2] and S[0]!=S[1]:
  print('Yes')
else :
  print('No')


Measured memory_bytes: 3060
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node {int parent, left, right; };

Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u, int d){
	if(u==NIL) return;
	D[u]=d;
	setDepth(T[u].left, d+1);
	setDepth(T[u].right, d+1);
}

int setHeight(int u){
	int h1 = 0, h2 = 0;
	if(T[u].left != NIL)
		h1 = setHeight(T[u].left) + 1;
	if(T[u].right != NIL)
		h2 = setHeight(T[u].right) + 1;
	return H[u] = (h1>h2 ? h1:h2);
}


//節点uの兄弟を探す
int getSibling(int u){
	if(T[u].parent == NIL) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
	return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
	return T[T[u].parent].right;
	return NIL;
}

void print(int u){
	printf("node %d: ", u);
	printf("parent = %d, ", T[u].parent);
	printf("sibling = %d, ", getSibling(u));
	int deg = 0;
	if(T[u].left != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ", deg);
	printf("depth = %d, ", D[u]);
	printf("height = %d, ", H[u]);
	
	if(T[u].parent == NIL){
		printf("root\n");
	}else if (T[u].left == NIL && T[u].right == NIL){
		printf("leaf\n");
	}else{
		printf("internal node\n");
	}
}

int main(){
	int v, l, r, root = 0;
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++)T[i].parent = NIL;
	
	for(int i = 0; i < n; i++){
		scanf("%d %d %d", &v, &l, &r);
		T[v].left = l;
		T[v].right = r;
		if(l != NIL)T[l].parent = v;
		if(r != NIL)T[r].parent = v;
	}
	
	for(int i = 0; i < n; i++) if(T[i].parent == NIL)root = i;
	
	setDepth(root, 0);
	setHeight(root);
	
	for(int i = 0; i < n; i++) print(i);
	
	return 0;
}


	
	
	
		
		


Measured memory_bytes: 2764
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector <long long> a(n + 1);
  vector <long long> b(n);
  for (int i = 0; i < n + 1; i++) {
	  cin >> a[i];
	}
  for (int i = 0; i < n; i++) {
	  cin >> b[i];
	}
  long long ans = 0;
  for (int i = 0; i < n; i++) {
	  int t = min(a[i], b[i]);
	  ans      += t;
	  b[i]     -= t;
	  t         = min(a[i + 1], b[i]);
	  ans      += t;
	  a[i + 1] -= t;
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt" , "r" , stdin);
// 	freopen("output.txt" , "w" , stdout);
// #endif

	ll n, m, count = 0;
	cin >> n >> m;
	vector<ll>v[m];
	for (ll i = 0; i < m; i++)
	{
		ll k;
		cin >> k;
		for (ll j = 0; j < k; j++)
		{
			ll a;
			cin >> a;
			v[i].push_back(a);
		}
	}
	ll p[m];
	for (ll i = 0; i < m; i++)
		cin >> p[i];
	for (ll i = 0; i < pow(2, n); i++)
	{
		ll vis[n] = {0}, f = 0;
		for (ll j = 0; j < n; j++)
		{
			if (i & (1 << j))
				vis[j] = 1;
		}
		for (ll j = 0; j < m; j++)
		{
			ll c = 0;
			for (ll k = 0; k < v[j].size(); k++)
			{
				if (vis[v[j][k] - 1])
					c++;
			}
			if ( (c % 2) != p[j])
			{
				f = 1;
				break;
			}
		}
		if (!f)
			count++;
	}
	cout << count << endl;




}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int h,w,k;cin >> h >> w >> k;
    vector<string> f(h);
    rep(i,h)cin >> f[i];
    int ans = 0;
    rep(i,1<<h)rep(j,1<<w){
        
        int cnt = 0;
        rep(a,h)rep(b,w){
            int aka = ((i >> a &1) ||(j >> b &1) );
            if(!aka && f[a][b] == '#'){
                cnt++;
            }
        }
        //trace(i,j,cnt);
        ans += (cnt == k);



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

Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    int a[1000],b[1000],i,j,x,sum=0,sump=0;
    scanf("%d",&x);
    for(i=0;i<x;i++)
        scanf("%d",&a[i]);
    for(i=0;i<x;i++)
        scanf("%d",&b[i]);
    for(i=0;i<x;i++){
        sum=0;
        for(j=0;j<=i;j++)
            sum+=a[j];
        for(j=i;j<x;j++)
            sum+=b[j];
        if(sum>sump)
            sump=sum;
    }
    printf("%d",sump);
    return 0;
         }


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int S;
	cin >> S;
	int a,b,c;
	a = S/100;
	b = S/10-10*a;
	c = S%10;
	int d;
	d = 0;
	if(a == 1){
        d=d+1;}	
	if(b == 1){
        d=d+1;}
	if(c == 1){
        d=d+1;}	
	cout << d << endl;
return 0;
}



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

using namespace std;

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

  const int coins[] = {
      1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049,
  };
  int N;
  cin >> N;

  vector<int> dp(N + 1, 100000);
  for (int i = 1; i <= N; ++i) {
    for (auto c : coins) {
      if (i - c < 0) continue;
      if (c == i) {
        dp[i] = 1;
        continue;
      }
      dp[i] = min(dp[i], dp[i - c] + 1);
    }
  }
  cout << dp[N] << endl;

  return 0;
}


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

const long long mod = (long long)1e9 + 7;
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main()
{
	long long n;
    cin >> n;
    
    if(n == 1) cout << 0 << endl;
    else if(n == 2) cout << 2 << endl;
    else
    {
        cout << ((binpow(10, n, mod) - (2 * binpow(9, n, mod)) % mod + mod)%mod + binpow(8, n, mod)) % mod << endl;
        
    }
	return 0;
}

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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 2e9, mxp = 10, maxn = 1e5;



void solve(int ci)
{
    int am[maxn + 1] = {0};
    int n;
    cin >> n;
    sc(a, n)
    int s = 0;
    f(n) am[a[i]]++, s += a[i];
    ic(q)
    f(q)
    {
        ic(x)
        ic(y)
        s += am[x] * (y - x);
        am[y] += am[x];
        am[x] = 0;
        cout << s << '\n';
    }
}

signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    f(t) solve(i + 1);
}


Measured memory_bytes: 5220
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let ret: i64 = a.iter().sum::<i64>() - n as i64;
    println!("{}", ret);
}


Measured memory_bytes: 2124
def submit():
    n, c = map(int, input().split())
    table_max = 10 ** 5
    table = [0 for _ in range(table_max + 1)]

    programs = []
    for _ in range(n):
        s, t, c = map(int, input().split())
        programs.append((s, t, c))
    programs.sort(key=lambda x: (x[2], x[0]))

    program_merge = [programs[0]]
    last = programs[0]
    for p in programs[1:]:
        if last[2] == p[2] and last[1] == p[0]:
            program_merge.pop()
            program_merge.append((last[0], p[1], p[2]))
        else:
            program_merge.append(p)
        last = program_merge[-1]
            

    for s, t, _ in program_merge:
        table[s - 1] += 1
        table[t] -= 1

    curr_max = 0
    for i in range(1, table_max + 1):
        table[i] += table[i - 1]
        if table[i] > curr_max:
            curr_max = table[i]

    print(curr_max)


submit()

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

typedef vector<long long> vec;
typedef vector<vec> mat;

long long L, A, B, M;

mat mal( mat a, mat b )
{
	mat c( 3, vec( 3 ) );
	for( int i = 0; i < 3; i++ ) {
		for( int j = 0; j < 3; j++ ) {
			for( int k = 0; k < 3; k++ ) {
				c[i][j] += a[i][k] * b[k][j] % M;
				c[i][j] %= M;
			}
		}
	}
	return c;
}

mat powmat( mat m, long long n )
{
	mat res( 3, vec( 3 ) );
	for( int i = 0; i < 3; i++ ) res[i][i] = 1;
	while( n ) {
		if( n & 1 ) res = mal( res, m );
		m = mal( m, m );
		n >>= 1;
	}
	return res;
}

int main() {

	cin >> L >> A >> B >> M;

	long long ans = 0;
	for( long long pow10 = 10; pow10 <= 1e18; pow10 *= 10 ) {
		if( pow10 <= A ) continue;
		long long Cd = (pow10 - A + B - 1) / B;
		Cd = min( Cd, L );
		mat m( 3, vec( 3 ) );
		m[0][0] = pow10 % M;
		m[1][0] = 1;
		m[1][1] = 1;
		m[2][1] = B % M;
		m[2][2] = 1;
		m = powmat( m, Cd );
		mat r( 3, vec( 3 ) );
		r[0][0] = ans;
		r[0][1] = A % M;
		r[0][2] = 1;
		r = mal( r, m );
		ans = r[0][0];
		A += Cd * B;
		L -= Cd;
		if( L == 0 ) {
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    ll a, b;
    cin >> n >> a >> b;

    ll ma = a * b;
    ll mi = a + b - 1;

    bool mab = ma >= n;
    bool mib = mi <= n;

    if (!(mab && mib)) {
        cout << -1 << endl;
        ret();
    }

    vector<vector<int>> ans(a);

    queue<int> q;
    rep(i, n) q.push(i + 1);

    rep(i, a) {
        for (int j = 0; j < b && q.size() > (a - i - 1); j++) {
            ans[i].push_back(q.front());
            q.pop();
        }
    }

    rep(i, a) reverse(ans[i].begin(), ans[i].end());

    rep(i, a) {
        rep(j, ans[i].size()) cout << ans[i][j] << ' ';
    }
    cout << endl;

}


Measured memory_bytes: 17932
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int n = input<int>();
    vector<int> a(n);

    input_seq(ALL(a));

    vector<int> ans;

    while (not a.empty()) {
        int i;
        for (i = SZ(a); i > 0; --i) {
            if (a[i - 1] == i)
                break;
        }

        if (i == 0) {
            cout << -1 << "\n";
            return 0;
        }
        
        ans.push_back(i);
        a.erase(a.begin() + (i - 1));
    }

    std::reverse(ALL(ans));
    for (int elem: ans)
        cout << elem << "\n";
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int K = GetInt();
		int Q = GetInt();
		int[] A = Enumerable.Range(0, Q).Select(_ => GetInt() - 1).ToArray();

		int[] cnt = new int[N];
		for(int i = 0; i < Q; i++)
			cnt[A[i]]++;

		int[] score = Enumerable.Repeat(K, N).ToArray();
		for(int i = 0; i < N; i++)
			score[i] -= Q - cnt[i];

		string[] ans = new string[N];
		for(int i = 0; i < N; i++)
			ans[i] = (score[i] > 0) ? "Yes" : "No";

		Console.WriteLine(string.Join("\n", ans));
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 20688
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 55;
struct P{
    int v, a, b;
};
vector<P> G[N];
int c[N], d[N];
ll f[N][N * N];
int main() {
    int n, m, s;
    scanf("%d%d%d", &n, &m, &s), s = min(s, 2500);
    for(int i = 0, u, v, a, b; i < m; i++) {
        scanf("%d%d%d%d", &u, &v, &a, &b);
        G[u].push_back({v, a, b});
        G[v].push_back({u, a, b});
    }
    for(int i = 1; i <= n; i++) {
        scanf("%d%d", &c[i], &d[i]);
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N * N; j++) {
            f[i][j] = 1e18;
        }
    }
    f[1][s] = 0;
    typedef tuple<ll, int, int> T;
    priority_queue<T, vector<T>, greater<T>> qu;
    qu.push(T(0, 1, s));
    while(!qu.empty()) {
        ll t = get<0>(qu.top());
        int u = get<1>(qu.top()), w = get<2>(qu.top());
        qu.pop();
        if(f[u][w] > t) continue;
        for(int i = 0; i < G[u].size(); i++) {
            int v = G[u][i].v, a = G[u][i].a, b = G[u][i].b;
            if(w >= a && f[v][w - a] > t + b) {
                f[v][w - a] = t + b;
                qu.push(T(t + b, v, w - a));
            }
        }
        if(f[u][min(w + c[u], 2500)] > t + d[u]) {
            f[u][min(w + c[u], 2500)] = t + d[u];
            qu.push(T(t + d[u], u, min(w + c[u], 2500)));
        }
    }
    for(int i = 2; i <= n; i++) {
        ll ans = 1e18;
        for(int j = 0; j <= 2500; j++) {
            ans = min(ans, f[i][j]);
        }
        printf("%lld\n", ans);
    }
    return 0;
}



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

int main() {
	int n;
	cin >> n;
	int MAX = 1e5;
	int a[2][MAX], b[MAX];
	memset(a,0,sizeof(a));
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		a[i%2][b[i]]++;
	}
	vector<pair<int,int>> v1, v2;
	for(int i = 0; i < MAX; i++) {
		if (a[0][i] != 0)
			v1.push_back({a[0][i],i});
		if (a[1][i] != 0)
			v2.push_back({a[1][i],i});
	}
	v1.push_back({0,-1});
	v2.push_back({0,-1});
	sort(v1.begin(),v1.end(),greater<pair<int,int>>());
	sort(v2.begin(),v2.end(),greater<pair<int,int>>());
	// cout << v1.size() << v2.size() << "\n";
	 
	if (v1[0].second != v2[0].second)
		cout << abs(n/2 - v1[0].first) + abs(n/2 - v2[0].first);
	else {
		cout << min(abs(n/2 - v1[0].first) + abs(n/2 - v2[1].first), abs(n/2 - v1[1].first) + abs(n/2 - v2[0].first));	
	}
	return 0;
}

Measured memory_bytes: 2428
n,m = map(int,input().split())
l = [0] * m

for _ in range(n):
	a = list(map(int,input().split()))
	for i in range(1,len(a)):
		l[a[i] - 1]+=1

ans = 0
for i in l:
	if i == n:ans+=1

print(ans)

Measured memory_bytes: 3060
from fractions import gcd
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
    
    
a, b = map(int,input().split())
a_d = make_divisors(a)
b_d = make_divisors(b)

yakusu = []

for i in a_d:
    if i in b_d:
        yakusu.append(i)

ans = [yakusu.pop(0)]
for i in yakusu:
    flg=0
    tmp = 0
    for j,num in enumerate(ans):
        if gcd(num,i) != 1:
            ans[j] = min(i,num)
            flg = 1
            break
    if flg == 0:
        ans.append(i)

print(len(ans))



Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n - 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) {
      cin >> a.at(i).at(j);
      a.at(i).at(j)--;
    }
    reverse(a.at(i).begin(), a.at(i).end());
  }

  vector<P> q;
  auto check = [&](int i) {
    if (a.at(i).size() == 0) return;

    int j = a.at(i).back();

    if (a.at(j).size() == 0) return;
    if (a.at(j).back() == i) {
      P p(i, j);
      if (p.second < p.first)
        swap(p.first, p.second);  // あとでuniq取れるように揃えてる
      q.push_back(p);
    }
  };

  for (int i = 0; i < n; i++) {
    check(i);
  }

  int day = 0;
  while (q.size() > 0) {
    day++;

    // uniqをとっている
    sort(q.begin(), q.end());
    q.erase(unique(q.begin(), q.end()), q.end());

    vector<P> prevQ;
    swap(prevQ, q);

    for (P p : prevQ) {
      int i = p.first, j = p.second;
      a.at(i).pop_back();
      a.at(j).pop_back();
    }

    for (P p : prevQ) {
      int i = p.first, j = p.second;
      check(i);
      check(j);
    }
  }

  for (int i = 0; i < n; i++) {
    if (a.at(i).size() != 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << day << endl;

  return 0;
}

Measured memory_bytes: 4224
mod = 1000000000 + 7

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

n = int(input())
dat = [0] * 2000

res = 1
for i in range(1, n + 1):
    d = factorization(i)
    for j in range(len(d)):
        dat[d[j][0]] += d[j][1]

for i in range(2, n + 1):
    if dat[i] == 0:
        continue
    #print(dat[i])
    res *= (dat[i] + 1)
    res %= mod

print(res)

Measured memory_bytes: 42348
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long     //1844674407370955161
#define INT_INF 0x3f3f3f3f      //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf，sscanf, getchar, fgets之类的一起使用了。
const int dr[]={0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]={-1, 1, 0, 0, -1, 1, -1, 1};
int read()//输入外挂
{
    int ret=0, flag=0;
    char ch;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        ret = ch - '0';
    while((ch=getchar())>='0'&&ch<='9')
        ret=ret*10+(ch-'0');
    return flag ? -ret : ret;
}
int a[15];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    memset(a,0,sizeof(a));
    for(int i=0;i<k;++i)
    {
        int tem;
        scanf("%d",&tem);
        a[tem]=1;
        //cout<<tem<<endl;
    }
    for(int i=n;;++i)
    {
        //cout<<i<<endl;
        int tem=i;
        bool flag=true;
        while(tem)
        {
            int x=tem%10;
            if(a[x])
            {
                flag=false;
                break;
            }
            tem/=10;
        }
        if(flag)
        {
            printf("%d\n",i);
            break;
        }

    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

ll solve1(vector<ll> &a) {
  ll sum = 0ll;
  ll res = 0ll;
  for (int i = 0; i < a.size(); i++) {
    sum += a[i];
    if (i % 2 == 0) {
      if (sum <= 0) {
        res += 1 - sum;
        sum = 1;
      }
    } else {
      if (sum >= 0) {
        res += sum + 1;
        sum = -1;
      }
    }
  }
  return res;
}

ll solve2(vector<ll> &a) {
  ll sum = 0ll;
  ll res = 0ll;
  for (int i = 0; i < a.size(); i++) {
    sum += a[i];
    if (i % 2 == 1) {
      if (sum <= 0) {
        res += 1 - sum;
        sum = 1;
      }
    } else {
      if (sum >= 0) {
        res += sum + 1;
        sum = -1;
      }
    }
  }
  return res;
}

void solve() {
  ll n, m;
  cin >> n >> m;
  ll l = 0, r = 10000000000000ll;
  auto check = [&](ll k) {
    if (m < 2 * k) return false;
    ll a = n + (m - 2 * k) / 2;
    return a >= k;
  };
  while (r - l > 1ll) {
    ll mid = (l + r) / 2ll;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
array = Array.new

while val = gets do
    array.push(val.chomp.split.map!{|i| i.to_i})
end

A = Array.new
for i in 0..2 do
    A.push(array[i])
end 

N = array[3][0]

def number_check(number,bingo_card)
    for i in 0..2
        for n in 0..2
            if number - bingo_card[i][n] == 0
                bingo_card[i][n] = 0
            end
        end
    end
end

for i in 4..(N + 3) do
    number_check(array[i][0], A)
end

answer = "No"

for i in 0..2
    if A[0][i] == A[1][i] && A[1][i] == A[2][i]
        answer = "Yes"
    end 
end
for n in 0..2
    if A[n][0] == A[n][1] && A[n][1] == A[n][2]
        answer = "Yes"
    end 
end

if A[0][0] == A[1][1] && A[1][1] == A[2][2]
    answer = "Yes"
elsif A[0][2] == A[1][1] && A[1][1] == A[2][0]
    answer = "Yes"
end

puts(answer)


Measured memory_bytes: 1788
#include <stdio.h>
int main(){
    int a,b;
    bool f,first=true;
    while(1){
        scanf("%d%d",&a,&b);
        f=true;
        if(a==0&&b==0)return 0;
        if(!first)printf("\n");
        first=false;
        for(int i=a;i<=b;i++){
            if(i%4==0){
                if(i%100==0){
                    if(i%400==0){
                        printf("%d\n",i);
                        f=false;
                    }
                }
                else {printf("%d\n",i);
                    f=false;}
            }
        }
        if(f)printf("NA\n");
    }
}

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


int main() {
  int N;
  int l;
  int r;
  int s = 0;
  cin >> N;
  for(int i=0;i<N;i++)
  {
    cin >> l >> r;
    s += (r-l+1);
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n,c,i,j;(n=s.nextInt())>0;System.out.println(((n-=c)>0?"deficient":n<0?"abundant":"perfect")+" number"))for(c=n>1?1:0,i=2,j=n;i<j;i++)c+=n%i<1?i+(i!=(j=n/i)?j:0):0;}}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; ++i)
const int N = 1e5 + 7;

int n, a[N], f[N];

int main() {
	scanf("%d", &n); 
	
	rep(i, 1, n) {
		scanf("%d", &a[i]);
	}
	
	f[2] = abs(a[2] - a[1]);
	rep(i, 3, n) {
		f[i] += min(f[i - 2] + abs(a[i - 2] - a[i]), f[i - 1] + abs(a[i - 1] - a[i]));
	}
	
	printf("%d\n", f[n]);
	
	return 0;
}


Measured memory_bytes: 1024
h,w = map(int,input().split())
src = [input() for _ in range(h)]
li = []
for i,z in enumerate(src[0]):
    if z == '.':
        li.append(i)
eliminate_column_index = []
for l in li:
    tmp = True
    for s in src:
        if s[l] == '#':
            tmp = False
            break
    if tmp == True:
        eliminate_column_index.append(l)
eliminate_row_index = []
for si,sr in enumerate(src):
    if sr == '.'*w:
        eliminate_row_index.append(si)
for s_row,ss in enumerate(src):
    if s_row in eliminate_row_index:
        continue
    tmp = ''
    for i,s in enumerate(ss):
        if i not in eliminate_column_index:
            tmp += s
    if tmp != '':
        print(tmp)

Measured memory_bytes: 3064
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}
#define ll long long
ll gcd (ll a, ll b) {
    while (b > 0) {
        ll t = a % b;
        a = b, b = t;
    }
    return a;
}

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

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int a, b;
    cin >> a >> b;
    if ((a < 0 && b > 0) || a == 0 || b == 0) {
        cout << "Zero" << endl;
    } else if (a > 0 || (b - a + 1) % 2 == 0) {
        cout << "Positive" << endl;
    } else {
        cout << "Negative" << endl;
    }
    return 0;
}


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

int main(){

    ll x,y,z;

    cin >> x >> y >> z;

    x-=z;
    ll ans = x/(y+z);
    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define limit int(1e6)
int arr[ limit ];
int dist[ limit ];

int found_answer(int count, int k) {
	fill(arr, arr + limit, int(1e9));
	arr[ 0 ] = dist[ 0 ];

	for(int i = 1; i < count; i++) {
		//int first_answer = abs(dist[ i - 1 ] - dist[ i ]);
		//int second_answer = abs(dist[ i - 1 ] - dist[ i + 1 ]);

		//arr[ i ] = min(arr[ i ], arr[ i - 1 ] + first_answer);
		//arr[ i + 1 ] = min(arr[ i + 1 ], arr[ i - 1 ] + second_answer);
		for(int j = 0; j < k; j++) {
			int ans = abs(dist[ i - 1 ] - dist[ i + j ]);
			arr[ i + j ] = min(arr[ i + j ], arr[ i - 1 ] + ans);
			//printf("i - 1 = %i, j = %i ||| ans = %i\n", i - 1, j, ans);
		}
	}
	/*
	for(int i = 0; i < count; i++) {
		printf("%i ", arr[ i ]);
	} printf("\n");
	*/
	return arr[ count - 1 ] - arr[ 0 ];
}

int main() {
	int count, k;
	scanf("%i%i", &count, &k);

	for(int i = 0; i < count; i++) {
		scanf("%i", &dist[ i ]);
	}

	printf("%i", found_answer(count, k));
}

Measured memory_bytes: 6400
import java.util.*;

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

        int ans = 0;

        for(int i = n; i <= m / 2; i++){
            if( m % i == 0){
                ans = m / i;
                break;
            }
        }
        if(ans == 0){
            ans = 1;
        }
        System.out.println(ans);
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5+50;
const ll oo = 1e18;
const ll mod = 1e9+7;

int main(){
    string x;
    cin>>x;
    if(x[0]!='A'){
        puts("WA");
        return 0;
    }
    int ans=0;
    for(int i=2;i<x.size()-1;i++){
        if(x[i]=='C')
            ans++;
    }
    if(ans!=1){
        puts("WA");
        return 0;
    }
    for(int i=1;i<x.size();i++){
        if(x[i]=='C'&&i>=2&&i<x.size()-1)
            continue;
        if(x[i]!=tolower(x[i])){
            puts("WA");
            return 0;
        }
    }
    puts("AC");
    return 0;
}


Measured memory_bytes: 256
import sys, math
from collections import defaultdict
from itertools import product
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    A = list(mi())

    stock = 0
    money = 1000

    u = []
    d = []

    i = 0
    while i < N-1:
        if A[i] <= A[i+1]:
            tmp = i
            while i+1 < N and A[i] <= A[i+1]:
                i += 1
            u.append((tmp, i))
        else:
            i += 1

    for v in u:
        stock += money//A[v[0]]
        money -= A[v[0]] * (money//A[v[0]])

        money += A[v[1]] * stock
        stock = 0

    print(money)

if __name__ == '__main__':
    main()

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

struct node{
	int a,b,c,d;
}a[55];

int n,m,q;
int ans = 0;
vector<int> res;

void dfs(int now)
{
	if( res.size() == n+1 )
	{
		int temp = 0;
		for (int i = 1; i <= q; i++)
		{
			node t = a[i];
			if( res[t.b] - res[t.a] == t.c )
			{
				temp += t.d;
			}
		}
		ans = max(ans,temp);
		return;
	}
	for (int i = now; i <= m; i++)
	{
		res.push_back(i);
		dfs(i);
		res.pop_back(); 
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> q;
	for (int i = 1; i <= q; i++)
	{
		cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d;
	}
	res.push_back(0); 
	dfs(1);
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N, K;
    cin >> N >> K;

    vector<vector<ll>> dp(N + 1, vector<ll>(K + 1));
    for (int i = 0; i <= K; ++i)
        dp[0][i] = 1;

    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        for (int j = 0; j <= K; ++j) {
            if (j <= a)
                dp[i + 1][j] += dp[i][j];
            else
                dp[i + 1][j] += dp[i][j] - dp[i][j - a - 1];
            if (j > 0)
                dp[i + 1][j] += dp[i + 1][j - 1];
            dp[i + 1][j] %= MOD;
        }
    }

    ll ans = dp[N][K];
    if (K > 0)
        ans -= dp[N][K - 1];
    ans %= MOD;
    if (ans < 0)
        ans += MOD;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 83056
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n, d; cin >> n >> d;
    vector<vector<int>> v(n, vector<int> (10, 0));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < d; j++) {
            cin >> v[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < n - 1; i++) {
        for(int j = i + 1; j < n; j++) {
            int sq_dist = 0;
            for(int k = 0; k < d; k++) {
                sq_dist += pow((v[i][k] - v[j][k]), 2);
            }
            double dist = sqrt(sq_dist);
            if(ceil(dist) == floor(dist)) ans++;
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	char b;
	cin>>b;
	switch(b){
		case 'A':
			cout<<"T"<<endl;
			break;
		case 'C':
			cout<<"G"<<endl;
			break;
		case 'G':
			cout<<"C"<<endl;
			break;
		case 'T':
			cout<<"A"<<endl;
			break;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
from bisect import bisect_left

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(int(input()) for _ in range(n))

    LIS = deque()
    for i in range(n):
        if len(LIS) == 0:
            LIS.appendleft(A[i])
        else:
            idx = bisect_left(LIS, A[i])
            if idx == 0:
                LIS.appendleft(A[i])
            else:
                LIS[idx - 1] = A[i]
    print(len(LIS))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 13708
import java.util.Scanner;
import java.util.Vector;

public class Main {
	static int a[];
	static long dp[][];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		dp = new long [n][n];
		a = new int[n];
		for (int i=0;i<n;i++) 
			a[i]=sc.nextInt();
		
		f(0,n-1);
		System.out.println(dp[0][n-1]);
	}
	private static long f(int l, int r) {
		if (l==r) {
			dp[l][r] = 0;
			return 0;
		}
		if (dp[l][r]>0) return dp[l][r];
		long ans = Long.MAX_VALUE;
		long sum = a[r];
		for (int i=l;i<r;i++) {
			sum+=a[i];
			long kq = f(l,i) + f(i+1,r);
			if (ans > kq) ans = kq;
		}
		dp[l][r] = ans+sum;
		return dp[l][r];
	}
}


Measured memory_bytes: 24916
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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 main(void){
    string s,t;
    cin >> s >> t;

    VVI exist(26);
    REP(i,s.size()) exist[s[i]-'a'].push_back(i);

    if(exist[t[0]-'a'].size() == 0){cout << "-1" << endl; return 0;}
    ll idx = exist[t[0]-'a'][0];
    ll top = 0, next;
    FOR(i,1,t.size()){
        if(exist[t[i]-'a'].empty()){cout << "-1" << endl; return 0;}
        else if(exist[t[i]-'a'].size() == 1) next = exist[t[i]-'a'][0];
        else{
            if(exist[t[i]-'a'][0] > idx) next = exist[t[i]-'a'][0];
            else if(exist[t[i]-'a'][exist[t[i]-'a'].size()-1] <= idx) next = exist[t[i]-'a'][0];
            else{
                int l = 0, r = exist[t[i]-'a'].size()-1;
                int n = (l+r)/2;
                while(r-l > 1){
                    if(exist[t[i]-'a'][n] <= idx) l = n;
                    else r = n;
                    n = (l+r)/2;
                }
                next = exist[t[i]-'a'][r];
            }
        }
        if(idx >= next) top++;
        idx = next;
    }
    ll ans = top*s.size() + idx+1;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;

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

  int h, w, k;
  cin >> h >> w >> k;
  vector < string > s (h);
  for (int i = 0; i < h; i++) cin >> s[i];

  int ans = 0;
  for (int i = 0; i < (1 << h); i++) {
    for (int j = 0; j < (1 << w); j++) {
      int cnt = 0;
      for (int a = 0; a < h; a++) {
        for (int b = 0; b < w; b++) {
          if (((i >> a) & 1) || ((j >> b) & 1)) continue;
          if (s[a][b] == '#') cnt++;
        }
      }

      ans += (cnt == k);
    }
  }

  cout << ans << '\n';
}


Measured memory_bytes: 3652