akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = 1LL << 60;//numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
set<LL>st;
map<Pll, LL>ma;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
string str, ss;
bool f[200000];
LL n, m, s, t, h, w, k, q, p, ans, sum[210000], cnt, a[210000], b[210000];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		sum[i + 1] = sum[i] + a[i];
	}
	//2個目 (,i],3個目(i,]
	ans = INF;
	for (int i = 2; i < n - 1; i++) {
		auto it1_ = lower_bound(sum + 1, sum + i + 1, sum[i] / 2) - sum,
			it2_ = lower_bound(sum + i + 1, sum + n, sum[i] + (sum[n] - sum[i]) / 2) - sum;
		if (it1_ == i)it1_--;
		if (it2_ == n)it2_--;
		for (int k = -1; k < 2; k++) {
			for (int l = -1; l < 2; l++) {
				auto it1 = it1_ - k, it2 = it2_ - l;
				if (it1 > 0 && it2 > 0 && it1 < n&&it2 < n) {
					LL p = sum[it1], q = sum[i] - sum[it1], r = sum[it2] - sum[i], s = sum[n] - sum[it2];
					if (p > 0 && q > 0 && r > 0 && s > 0) {
						LL mx = max({ p,q,r,s }), mn = min({ p,q,r,s });
						ans = min(ans, mx - mn);
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

Measured memory_bytes: 612
#include "bits/stdc++.h"
using namespace std;

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

void test() {}

int D, c[27];
int s[366][27];

int calc(vector<int> sc) {
	vector<int> last(27, 0);
	int val = 0;
	rep(d, 1, D + 1) {
		val += s[d][sc[d]];
		last[sc[d]] = d;
		rep(i, 1, 27)
			val -= c[i] * (d - last[i]);
		write(val);
	}
	return val;
}

void solve() {
	vector<int> ans(366);

}

int main(int argc, char *argv[]) {
	//cin.tie(0)->sync_with_stdio(0);
	//cin.exceptions(cin.failbit);

	if (argc >= 2 && string(argv[1]) == "test") {
		test();
		return 0;
	}

	read(D);
	rep(i, 1, 27) read(c[i]);
	rep(i, 1, D + 1) rep(j, 1, 27) read(s[i][j]);

	vector<int> t(366, 0);
	rep(i, 1, D + 1) read(t[i]);

	calc(t);
}


Measured memory_bytes: 3668
n, k = map(int, input().split())

a = list(map(int, input().split()))
a_pos = sorted([i for i in a if i >= 0])
a_neg = sorted([i for i in a if i < 0], reverse=True)

mod = 10 ** 9 + 7
ans = 1

if len(a_pos) == 0 and k % 2:
    for i in a_neg[:k]:
        ans = ans * i % mod
    print(ans)
    exit()

while k > 0:
    if k == 1 or len(a_neg) <= 1:
        if len(a_pos) == 0:
            ans *= a_neg.pop()
        elif len(a_pos) > 0:
            ans *= a_pos.pop()
        k -= 1
    elif len(a_pos) <= 1:
        ans *= a_neg.pop() * a_neg.pop()
        k -= 2
    
    elif a_pos[-1] * a_pos[-2] > a_neg[-1] * a_neg[-2]:
        ans *= a_pos.pop()
        k -= 1
    elif a_pos[0] * a_pos[1] <= a_neg[-1] * a_neg[-2]:
        ans *= a_neg.pop() * a_neg.pop()
        k -= 2
    ans %= mod

else:
    print(ans)

Measured memory_bytes: 31620
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	double r;
	cin >> r;
	cout << 2 * r * 3.14159265358979323846;
}


Measured memory_bytes: 3804
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<int>a(n),aa;
	vector<int>b(m),bb;
	ll asum(0);
	ll bsum(0);
	int limita(1),limitb(1);
	rep(i, n) {
		int buffer;
		cin >> buffer;
		a.push_back(buffer);
		if (limita == 1) {
			asum += buffer;
		}
		if (asum <= k) {
			aa.push_back(asum);
		}
		else {
			limita = -1;
		}
		
	}
	rep(i, m) {
		int buffer;
		cin >> buffer;
		b.push_back(buffer);
		if (limitb == 1) {
			bsum += buffer;
		}
		if (bsum <= k) {
			bb.push_back(bsum);
		}
		else {
			limitb = -1;
		}
	}
	int t = aa.size();
	int ans = 0;
	auto iter= upper_bound(bb.begin(), bb.end(),k);
	int it = iter - bb.begin();
	ans = it;
	rep(i, t) {
		int abuf = aa[i];
		int nokori = k - abuf;
		auto iter = upper_bound(bb.begin(),bb.end(), nokori);
		int it = iter - bb.begin();
		if (bb[0] <= nokori) {
			if (it == 0) {
				it = bb.size() - 1;
			}
		}
		int k = i +1+ it;

		ans = max(ans, k);
	}
	cout << ans;
	return 0;

}

Measured memory_bytes: 8816
#include<stdio.h>

int main(){
	int n, m, a, b, c, d, i, flag=0;
	scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
	char s[n+3];
	scanf("%s", s);
	m = c>d?c:d;
	for(i=a-1;i<m-2;i++){
		if(s[i]=='#'&&s[i+1]=='#'){
			printf("No"); return 0;
		}
	}
	if(c>d){
		for(i=b-1;i<d;i++){
			if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
				printf("Yes"); return 0;
			}
		}
		printf("No"); return 0;
	}else{
		printf("Yes"); return 0;
	}
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

const int INF = INT_MAX / 2;

vector<int> candles;

ll solve(const int N, const int K) {
    int ans = INF;

    for (int i = 0; i < N - K + 1; i++) {
        int l = candles[i];
        int r = candles[i + K - 1];
        chmin(ans, abs(l) + abs(r - l));
        chmin(ans, abs(r) + abs(r - l));
    }

    return ans;
}

int main(void) {
    int N, K;
    cin >> N >> K;

    candles.resize(N);

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

    cout << solve(N, K) << endl;

    return 0;
}


Measured memory_bytes: 640
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=5e5+5;
int a[N],n;ll res;
int main(){
	scanf("%d",&n);
	fp(i,1,n*3)scanf("%d",&a[i]);
	sort(a+1,a+1+n*3);
	for(R int i=n+1;i<=n*3;i+=2)res+=a[i];
	printf("%lld\n",res);
	return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

string dir[6] = {"North", "East", "West", "South", "Right", "Left"};

int roll[6][6] = {
	{5, 1, 3, 4, 6, 2},
	{3, 2, 6, 1, 5, 4},
	{4, 2, 1, 6, 5, 3},
	{2, 6, 3, 4, 1, 5},
	{1, 4, 2, 5, 3, 6},
	{1, 3, 5, 2, 4, 6},
};

vector< int > initDice() {
	vector< int > res;
	for_(i,1,7) res.push_back(i);
	return res;
}

vector< int > rollDice(vector< int > dice, int d) {
	vector< int > res(6);
	for_(i,0,6) res[roll[d][i] - 1] = dice[i];
	return res;
}

int main() {
	int N;
	
	while (cin >> N, N) {
		vector< int > dice = initDice();
		
		int ans = 1;
		for_(i,0,N) {
			string S;
			cin >> S;
			dice = rollDice(dice, find(dir, dir + 6, S) - dir);
			ans += dice[0];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const int MAX_X = 1000005;

ll power_mod(ll n, ll m)
{
    ll res = 1;
    ll base = n;
    while (m > 0)
    {
        if (m&1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        m >>= 1;
    }
    return res;
}

ll inv_mod(ll n)
{
    return power_mod(n, MOD-2);
}

ll factorial[MAX_X];
void init_fact()
{
    factorial[0] = 1;
    rep(i, 1, MAX_X)
    {
        factorial[i] = factorial[i-1]*i;
        factorial[i] %= MOD;
    }
}

ll comb(ll n, ll m)
{
    ll res = 1;
    res *= factorial[n];
    res %= MOD;
    res *= inv_mod(factorial[n-m]);
    res %= MOD;
    res *= inv_mod(factorial[m]);
    res %= MOD;
    return res;
}

int main()
{
    init_fact();

    ll x, y;
    cin >> x >> y;

    ll res = 0;
    rep(a, 0, x+1)
    {
        ll rx = x-a;
        ll b = y-2*a;

        // cout << a << ' ' << b << ' ' << rx << endl;

        if (b < 0) continue;
        if (b*2 != rx) continue;

        res += comb(a+b, a);
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8064
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    long n, p;
    readlnTo(n, p);
    auto a = readLongs();
    auto dp = new long[][](n+1, 2);
    dp[0][0] = 1;
    dp[0][1] = 0;
    foreach(i; iota(1, n+1)) {
        dp[i][0] = dp[i-1][0];
        dp[i][1] = dp[i-1][1];
        if(a[i-1] % 2 == 0) {
            dp[i][0] += dp[i-1][0];
            dp[i][1] += dp[i-1][1];
        } else {
            dp[i][0] += dp[i-1][1];
            dp[i][1] += dp[i-1][0];
        }
    }
    writeln(dp[n][p]);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  int i = 0, j = s.size() - 1;
  while(s[i] != 'A') i++;
  while(s[j] != 'Z') j--;
  cout << (j - i + 1) << endl;
  return 0;
}

Measured memory_bytes: 640
class SegTree:
    """ segment tree with point modification and range product. """
    # # https://yukicoder.me/submissions/452850
    def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)
      
N=int(input())
S=input()
seg = SegTree(N,set.union,set())
S = [set([ord(S[i])-97]) for i in range(N)]
seg.build(S)
Q=int(input())
for i in range(Q):
  *q, = input().split()
  if q[0] == '1':
    i, c = q[1:]
    seg.set_val(int(i)-1,set([ord(c)-97]))
  else:
    l,r = map(int,q[1:])
    print(len(seg.fold(l-1,r)))

Measured memory_bytes: 442892
#pragma GCC optimize("O2")
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<climits>
#include<random>
#include <iomanip>
#include <bitset>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
 
/////////////////////////////////////////////
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
///////////////////////////////
#define int long long

vector<vector<int>> generateSubsets(int n){

	vector<vector<int>> ans;

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

		vector<int> tmp;
		for(int j = 0 ; j < n ; ++j){

			if(i&(1<<j))
				tmp.pb(j);
		}
		ans.pb(tmp);
	}
	return ans;
}

void solve(){

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

	string s[n];

	for(int i = 0 ; i < n ; ++i)
		cin>>s[i];

	vector<vector<int>> rows = generateSubsets(n);
	vector<vector<int>> cols = generateSubsets(m);

	int ans = 0;
	for(auto &row : rows){

		for(auto &col : cols){

			string tmp[n];
			for(int i = 0 ; i < n ; ++i)
				tmp[i] = s[i];
			
			for(int x : row){

				for(int j = 0 ; j < m ; ++j)
					tmp[x][j] = '.';
			}
			for(int x : col){

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

					tmp[i][x] = '.';
				}
			}

			int cnt = 0;
			for(int i = 0 ; i < n ; ++i)
				for(int j = 0 ; j < m ; ++j)
					cnt += (tmp[i][j]=='#');

			if(cnt==k)
				ans++;

		}
	}
	cout<<ans<<endl;
}
 
signed main(){
 
	fast;
	int t = 1;
	//cin>>t;
	for(int i = 1 ; i <= t ; ++i)
		solve();
}


Measured memory_bytes: 3688
from itertools import permutations
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    P = tuple([int(i) for i in readline().split()])
    Q = tuple([int(i) for i in readline().split()])

    pattern = list(permutations(range(1,N+1)))

    print(abs(pattern.index(P) - pattern.index(Q)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 8052
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



string s, t;


int main() {
  while (cin >> s >> t) {
		sort(s.begin(), s.end());
		sort(t.begin(), t.end(), greater<char>());
		if (s < t) puts("Yes");
		else puts("No");
  }
}


















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

using namespace std;

#define ll long long
#define REP(i, N) for(int i = 0; i < N; i++)

int main() {
    int A, B, C, X;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;

    X /= 50;
    int ans = 0;
    REP(a, A+1) {
        REP(b, B+1) {
            int c = X - 10*a - 2*b;
            if (0 <= c && c <= C) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli, lli>>
#define pll pair<lli, lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...)                           \
	{                                            \
		string _s = #args;                       \
		replace(_s.begin(), _s.end(), ',', ' '); \
		stringstream _ss(_s);                    \
		istream_iterator<string> _it(_ss);       \
		err(_it, args);                          \
	}
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
void err(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cout << *it << " = " << a << "\n";
	err(++it, args...);
}
void take() {}
template <typename T, typename... Args>
void take(T &a, Args &... args)
{
	cin >> a;
	take(args...);
}
 
#define endl "\n"
 
lli power_mod(lli a, lli x)
{
	if (x == 0)
		return 1;
	lli y = power_mod(a, x / 2);
	lli ans = (y * y) % mod;
	if (x % 2)
		ans = (ans * a) % mod;
	return ans;
}
lli inv(lli a) { return power_mod(a, mod - 2); }
lli power(lli a, lli x)
{
	if (x == 0)
		return 1;
	lli y = power(a, x / 2);
	lli ans = (y * y);
	if (x % 2)
		ans *= a;
	return ans;
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, h, i, a[100005], dp[100005];
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for (i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int  N = 11;
typedef struct query{
        int a,b,c,d;
}query;
int n,m,q,a,b,c,d,f[N],mx=0;
query e[55];
void recur(int idx,int val){
        if(idx==n){
                //for(int i=0;i<n;i++) cout<<f[i]<<" "; cout<<endl;
                int res=0;
                for(int i=0;i<q;i++){ if((f[e[i].b]-f[e[i].a])==e[i].c) res+=e[i].d; }
                //cout<<res<<endl;
                mx=max(mx,res); return;
        }
        for(int i=val;i<=m;i++){
                f[idx]=i;
                recur(idx+1,f[idx]);
        }
}

void solve(){
recur(0,1);
cout<<mx<<endl;
}
int main(){
        cin>>n>>m>>q;
        for(int i=0;i<q;i++){
                cin>>a>>b>>c>>d;
                e[i]={--a,--b,c,d};
        }
        solve();
}


Measured memory_bytes: 3616
import java.io.*;
import java.util.*;

/**
 * @author:26019
 */
public class Main {

    public static void main(String[] args) throws Exception {
        solve();
    }

    private static long gcd(long x, long y) {
        if (y == 0) return x;
        return gcd(y, x % y);
    }

    private static int cal(int x) {
        int res = 1;
        while (x != 1) {
            if ((x & 1) == 1) {
                x = x * 3 + 1;
            } else {
                x >>= 1;
            }
            res++;
        }
        return res;
    }

    private static void solve() throws Exception {
        FastScanner cin = new FastScanner();
        int n = cin.nextInt();
        int[] arr = cin.readArray(n);
        int res = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                res += arr[i] * arr[j];
            }
        }
        System.out.println(res);
    }


    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        FastScanner() throws IOException {
        }

        public String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        private void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == 0) {
        v.clear();
        return 0;
    }
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

void solve(int N) {
    int d = (int)sqrt(N*2), e = d+1;
    if (d * e != N*2) {
        printf("No\n");
        return;
    }

    vvi pat(e); // , vi(d, 0));
    int ix = 0;
    repC2(i,j,e){
        ++ix;
        pat[i].pb(ix);
        pat[j].pb(ix);
    }

    printf("Yes\n");
    printf("%d\n", e);
    rep(i,e){
        printf("%d", (int)pat[i].size());
        sort(ALL(pat[i]));
        for (int si:pat[i]) printf(" %d", si);
        printf("\n");
    }
}

int main() {
    int N; cin >> N;
    solve(N);
    return 0;
}


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

int main(){
  int a;
  cin >> a;
  int i =0;
  int ans =0;
  while(ans<a){
    i++;
    ans = i*i;
    if(ans>a){
    ans = (i-1)*(i-1);
    break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;
//using namespace boost::multiprecision;

int main(){

    string s;
    cin >> s;

    //貪欲に前からパーが出せるときにはパーを出す

    int n = s.size();
    int ans = 0;
    int paperable = 1;

    if(s[0] == 'p'){
        ans--;
    }

    for(int i = 1; i < n; i++){
        if(paperable > 0){
            paperable--;
            if(s[i] == 'g'){
                ans++;
            }
        }else{
            paperable++;
            if(s[i] == 'p'){
                ans--;
            }
        }
    }

    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  for(int i = 0; i <= (N - 3); ++i)
  {
    if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C')
    {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(void){
    int A,B,C;
    cin >> A >> B >> C;
    int min = A+B;
    if(min > B+C){
        min = B+C;
    }

    if(min > A+C){
        min = A+C;
    }
    cout << min << endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll n, m, x;
  cin >> n >> m >> x;
  vll c(n);
  vvll a(n, vll(m));
  rep(i, 0, n){
    cin >> c.at(i);
    vin(a.at(i));
  }

  ll ans = inf;
  rep(i, 0, 1<<12){
    bitset<12> bit(i);
    vll power(m, 0);
    ll money = 0;
    rep(i, 0, n) if(bit.test(i)){
      rep(j, 0, m) power.at(j) += a.at(i).at(j);
      money += c.at(i);
    }
    ll check = true;
    rep(i, 0, m) if(power.at(i) < x) check = false;
    if(check) chmin(ans, money);
  }
  cout << (ans == inf ? -1 : ans) << endl;
}

Measured memory_bytes: 3632
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;

    for(int i=0; i<100; i++) {
        for(int j=0; j<100; j++) {
            int price = 4*i + 7*j;
            if(price == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>bool chmax(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int h,w;
    cin>>h>>w;
    auto vec=make_vec<char>(h,w);
    rep(i,h) rep(j,w) cin>>vec[i][j];
    
    auto dp=make_vec<ll>(h,w);
    dp[0][0]=1;
    rep(i,h) rep(j,w) {
        if(i>0 && vec[i-1][j]!='#') dp[i][j]+=dp[i-1][j];
        if(j>0 && vec[i][j-1]!='#') dp[i][j]+=dp[i][j-1];
        while(dp[i][j]>=MOD) dp[i][j]-=MOD;
    }
    cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main() {
	int n, t;
	cin >> n >> t;
	int lst = 0, ans = 0;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		ans += t - max(0LL, lst - a);
		lst = a + t;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int X;
int n, q;
const int N = 200000;
int ri[N];
struct P3
{
    LL a, b, c;
} L[N];
P3 change(P3 a, int d)
{
    if (d <= 0)
    {
        if (a.c + d >= 0) return (P3){a.a, a.b, a.c + d};
        else if (a.c + a.b + d >= 0) return (P3){a.a + (-d) - a.c, a.b + a.a - (a.a + (-d) - a.c), 0};
        else return (P3){X, 0, 0};
    }
    else
    {
        if (a.c + a.b + d <= X) return (P3){a.a, a.b, a.c + d};
        else if (a.c + d <= X) return (P3){a.a, X - d - a.c, a.c + d};
        else return (P3){X, 0, X};
    }
}
int main()
{
    cin >> X >> n;
    L[0] = (P3){0, X, 0};
    for (int i = 1; i <= n; ++ i)
    {
        cin >> ri[i];
        if (i & 1) L[i] = change(L[i - 1], -(ri[i] - ri[i - 1]));
        else L[i] = change(L[i - 1], ri[i] - ri[i - 1]);
    }
    cin >> q;
    while (q --)
    {
        int t, a;
        cin >> t >> a;
        P3 nw;
        int p = upper_bound(ri, ri + n + 1, t) - ri - 1;
        if ((p + 1) & 1) nw = change(L[p], -(t - ri[p]));
        else nw = change(L[p], t - ri[p]);
        if (a <= nw.a) cout << nw.c;
        else if (a <= nw.a + nw.b) cout << nw.c + (a - nw.a);
        else cout << nw.c + nw.b;
        cout << endl;
    }
}

Measured memory_bytes: 5632
#include <stdio.h>
#include <stdlib.h>

int main(){
	int i,cnt,n,m,tmp;
	int *flag;

	while(1){
		scanf("%d %d",&n,&m);
		if(n == 0 && m == 0){
			break;
		}
		flag = (int *)calloc(n,sizeof(int));

		i = 0;
		tmp = 0;
		while(tmp != n){
			cnt = 0;
			while(cnt != m){
				i++;
				if(i == n+1){
					i = 1;
				}
				if(!flag[i-1]){
					cnt++;
				}
			}
			flag[i-1] = 1;
			tmp++;
		}

		printf("%d\n",i);
	}

	return 0;
}

Measured memory_bytes: 620
#include <stdio.h>
int main(void){
  int data[100],result[100],i=0,j=0,count=0;
  while(1){
    scanf("%d",&data[i]);
    if(feof(stdin))break;
    if(data[i]!=0){
      i++;
      count++;
    }else{
      result[j]=data[i-1];
      i--;
      j++;
    }
  }
  for(i=0;i<count;i++){
    printf("%d\n",result[i]);
  }
  return(0);
}

Measured memory_bytes: 604
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define N 200010
#define int long long
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int a[N],sum[N];

bool cmp(int a,int b)
{
    return a>b;
}

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


Measured memory_bytes: 6948
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

constexpr int MAX_N = 200000;

int N;
int a[MAX_N], b[MAX_N], c[MAX_N];

int main()
{
  scanf( "%d", &N );
  rep( i, N )
    scanf( "%d", a+i );
  rep( i, N )
    scanf( "%d", b+i );

  int ans = 0;
  rep( t, 29 )
  {
    int T = 1<<t;
    int cnt = 0;

    rep( i, N )
      c[i] = b[i]%(2*T);

    std::sort( c, c+N );

    rep( i, N )
    {
      int m = a[i]%(2*T);

      cnt += (std::lower_bound( c, c+N, 2*T-m )-std::lower_bound( c, c+N, T-m ))%2;
      cnt += (std::lower_bound( c, c+N, 4*T-m )-std::lower_bound( c, c+N, 3*T-m ))%2;
      cnt %= 2;
    }

    ans += (cnt%2)*T;
  }

  printf( "%d\n", ans );

  return 0;
}

Measured memory_bytes: 2560
fun main(arr: Array<String>) {
    println(readLine()!!.split(" ").map { it.toLong() }.let { solve(it[0], it[1], it[2], it[3]) })
}

fun solve(taka:Long, naka:Long, hiku:Long, k:Long):Long {
    if(k % 2 == 0L) {
        return taka - naka
    } else {
        return naka - taka
    }
}

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

void printvec(vector<int> a, int n){
    for(int i=0; i<n; i++){
        cout << a[i];
        if(i!=n-1){
            cout << " ";
        }
    }
    cout << endl;
}

void selectionSort(vector<int> a, int n){
    int count = 0;
    for(int i=0; i<n; i++){
        int minj = i;
        for(int j=i; j<n; j++){
            if(a[j]<a[minj]){
                minj = j;
            }
        }
        if(i!=minj){
            int tmp = a[i];
            a[i] = a[minj];
            a[minj] = tmp;
            count++;
        }
    }
    printvec(a, n);
    cout << count << endl;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    selectionSort(a, n);
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	vector<int> h(n);
	rep(i,n) cin >> h.at(i);
	vector<int> dp(n,1000000000);
	dp.at(0)=0;
	rep(i,n){
		rep(j,k){
			if(i+j+1<n) dp[i+j+1]=min(dp[i+j+1],dp[i]+abs(h.at(i+j+1)-h.at(i)));
		}
	}
	cout << dp[n-1] << endl;
}

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

int main() {
  int L, R, d;
  cin >> L >> R >> d;

  int ans = 0;
  for (int i = L; i <= R; i++) {
    if(i%d==0){
      ans++;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define MAX 100001
#define MOD 1000000007
using namespace std;

 
int32_t main()
{
    int n;
    cin>>n;
    int a[n][n];
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j)
            cin>>a[i][j];

    int dp [(1<<n)] = {0};

    dp[0] = 1;



    // Base Case

    for (int i = 1; i < (1<<n); i++) 
    {
        int cnt = __builtin_popcount(i);
        for(int j=0;j<n;++j) 
        {
            if (i&(1<<j)) {

                dp[i] =  ( dp[i]  + ( dp[i^(1<<j)]*a[cnt-1][j]) ) %MOD;

            }
        }
    }

    cout << dp[(1<<n)-1];


    return 0;
}

Measured memory_bytes: 20016
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, h, a = 0, x;
	cin >> n >> h;
	int b[n + 1];
	FOR (i, 1, n)
	{
		cin >> x >> b[i];
		a = max(a, x);
	}
	
	sort(b + 1, b + n + 1, greater<int>());
	int cnt = 0, sum = 0;
	FOR (i, 1, n)
	{
		if (sum >= h) {cout << cnt; return 0;}
		if (b[i] < a) break;
		sum += b[i];
		cnt++;
	}
	
	if (sum >= h) {cout << cnt; return 0;}
	int c = (h - sum)/a;
	if ((h - sum) % a) c++;
	cout << cnt + c;
}

Measured memory_bytes: 1024
// Code by : h_mm 

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ull unsigned long long
#define ll long long
#define t ll t; cin>>t; while(t--)
ll mod=1000000007;
using namespace std;

int main(void){
    int n;
    cin>>n;
    ll a[n], b[n];
    ll sum = 0;
    for(int i=0 ;i<n; i++){
    	cin>>a[i];
    	sum += a[i];
    	sum %= mod;
    }
    ll ans = 0;
    for(int i=0; i<n; i++){
    	sum -= a[i];
    	if(sum<0) sum += mod;
    	ans += a[i]*(sum);
    	ans %= mod;
    }
    cout<<ans;
}

Measured memory_bytes: 5112
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M, K = map(int, readline().split())
MOD = 998244353

# Combination under a modulo: nCk % mod
# Modulo must be a prime number.
# Intermediate numerators and denominators are cached and reused.
def combmod(n, k, p=MOD, numden=[(1, 1)]):
    if k > n:
        return 0
    if k > n - k:
        k = n - k
    # Reuse precalculated numerators and denominators.
    if k < len(numden):
        num, den = numden[k]
    else:
        # Resume from len(numden).
        num, den = numden[-1]
        for i in range(len(numden) - 1, k):
            num = num * (n - i) % p
            den = den * (i + 1) % p
            numden.append((num, den))
    # a^(p-1) ≡ 1 mod p (by Fermat's little theorem)
    # i.e. a^(p-2) ≡ a^(-1) mod p
    inv_dev = pow(den, p - 2, p)
    return num * inv_dev % p


def solve():
    ans = 0
    for i in range(K + 1):
        ans += combmod(N - 1, i) * M * pow(M - 1, N - 1 - i, MOD) % MOD
        ans %= MOD
    return ans


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 22632
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second

typedef long long ll;

using namespace std;

int main()

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

    int x, t;

    cin >> x >> t;

    cout << max(0, x-t);

    return 0;
}



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

int main() {
  
  int N, tmp; string S; cin >> N >> S;
  
  string alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < 26; j++) {
      if (S.at(i) == alp.at(j)) {
        tmp = (j + N) % 26;
        break;
      }
    }
    cout << alp.at(tmp);
  }
  
  cout << endl;
  
}

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

public class Main {
	Scanner sc = new Scanner(System.in);

	int N, M;
	int[] indeg;
	ArrayList<Integer>[] G;
	ArrayList<Integer> res;
	boolean[] V;
	boolean multi;

	@SuppressWarnings("unchecked")
	void run() {
		N = sc.nextInt();
		M = sc.nextInt();
		indeg = new int[N];
		G = new ArrayList[N];
		res = new ArrayList<Integer>();
		V = new boolean[N];
		multi = false;
		for (int i = 0; i < N; i++) G[i] = new ArrayList<Integer>();
		for (int i = 0; i < M; i++) {
			int v = sc.nextInt() - 1;
			int u = sc.nextInt() - 1;
			G[u].add(v);
			indeg[v]++;
		}

		int cnt = 0;
		for (int i = 0; i < N; i++) if (indeg[i] == 0) cnt++;
		if (cnt > 1) multi = true;
	
		topologicalSort();

		StringBuilder o = new StringBuilder();
		for (int i = N - 1; i >= 0; i--) o.append(res.get(i) + "\n");
		System.out.print(o);
		System.out.println(multi ? 1 : 0);
	}

	void topologicalSort() {
		for (int u = 0; u < N; u++) {
			if (indeg[u] == 0 && !V[u]) {
				bfs(u);
			}
		}
	}

	void bfs(int s) {
		V[s] = true;
		LinkedList<Integer> que = new LinkedList<Integer>();
		que.add(s);
		while (!que.isEmpty()) {
			int u = que.poll();
			res.add(u + 1);
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u].get(i);
				indeg[v]--;
				if (indeg[v] == 0 && !V[v]) {
					que.add(v);
					V[v] = true;
				}
			}
			if (que.size() > 1) multi = true;
		}
	}

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

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

int main() {
	int n;
	int* h;
	cin >> n;
	h = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int ans = 1;
	int max = h[0];
	for (int i = 1; i < n; i++) {
		if (h[i] >= max) {
			max = h[i];
			ans++;
		}
	}
	cout << ans << endl;
	delete[] h;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

const int INF = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);

    rep(i, n)cin >> a[i];
    ll s = 0;
    rep(i, n) s ^= a[i];
    ll ans = s;
    rep(i, n) {
        a[i] &= ~s;
    }

    int r = 0;
    vector<int> top(n);
    for (int i = 60; i >= 0; i--) {
        int j = r;
        for (; j < n; j++) {
            if (a[j] >> i & 1) {
                swap(a[r], a[j]);
                break;
            }
        }
        if (j == n) continue;
        top[r] = i;
        rep(k, n) {
            if (r == k) continue;
            if (a[k] >> i & 1) {
                a[k] ^= a[r];
            }
        }
        r++;
    }
    ll x = 0;
    for (int i = 60; i >= 0; i--) {
        ll nx = x | (1ll << i);
        {
            ll b = nx;
            rep(j, r) {
                if (b >> top[j] & 1)b ^= a[j];
            }
            if ((b & nx) == 0) {
                x = nx;
            }
        }
    }
    ans += x * 2;
    cout << ans << endl;


}


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

typedef long long ll;

ll a[100005];
map<ll, ll> mp;

int main(void)
{
    ll n, q, sum = 0;

    scanf("%lld" ,&n);
    for(ll i=1; i<=n; i++)
    {
        scanf("%lld" ,&a[i]);
        sum+=a[i];
        mp[a[i]]++;
    }

    scanf("%lld" ,&q);
    while(q--)
    {
        ll b, c;
        scanf("%lld %lld" ,&b, &c);
        sum-=mp[b]*b - mp[b]*c;
        mp[c]+=mp[b];
        mp[b]=0;
        printf("%lld\n" ,sum);
    }
    return 0;
}

Measured memory_bytes: 10360