akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("input.in", "r", stdin);
    ll n, m, s;
    scanf("%lld%lld", &n, &m);
    vector<ll> d(n, 0);
    for(int i=0;i<n;i++){
        scanf("%lld", &d[i]);
    }
    scanf("%lld", &s);
    vector<ll> q(s, 0);
    for(int i=0;i<s;i++){
        scanf("%lld", &q[i]);
    }

    vector<ll> dis(n+1, 0);
    vector<ll> dp(n+1, 0);
    dis[0]=m;
    for(int i=0;i<n;i++){
        dis[i+1]=min(dis[i], abs(dis[i]-d[i]));
    }

    dp[n]=1;
    for(int i=n-1;i>=0;i--){
        if(dp[i+1]<=d[i]/2){
            dp[i]=dp[i+1];
        }
        else {
            dp[i]=dp[i+1]+d[i];
        }
    }
    for(int i=0;i<s;i++){
        if(dp[q[i]]<=dis[q[i]-1]){
            printf("YES\n");
        }
        else printf("NO\n");
    }
    return 0;
}


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

int main(){
    string S;cin>>S;
    int a;int count=0;
    for(int i=0;i<4;i++){
        a=S.at(i)-'0';
        if(a==2){
            count++;
        }
    }cout<<count<<endl;
}

Measured memory_bytes: 256
fn main() {
 let z: Vec<i32> = r();
 let v: Vec<i32> = r();
 println!("{}", v.iter().map(std::string::ToString::to_string).collect::<Vec<_>>().join(" "));
}
fn r<T:std::str::FromStr>()->Vec<T>{
 let mut b=String::new();
 let s=std::io::stdin();
 s.read_line(&mut b).unwrap();
 b.split_whitespace().rev().flat_map(str::parse).collect()
}


Measured memory_bytes: 5036
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N, K;
  cin >> N >> K;

  i64 ans = K;
  ans *= pow(K-1, N-1);
  cout << ans << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a >= b && a >= c){
		cout << a*10 +b+c << endl;
	}else if(b >=a && b >=c){
		cout << b*10 +a+c << endl;
	}else{
		cout << c*10 +a+b << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  
    int i,n,a,b,c;
    scanf("%d",&n);
    for(i=0;i<n;i++){
    scanf("%d %d %d",&a,&b,&c);
    if((a*a==b*b+c*c)||(b*b==a*a+c*c)||(c*c==a*a+b*b))
    printf("YES\n");
    else
    printf("NO\n");
    }
    return 0;
}  



Measured memory_bytes: 1976
n, a, b, c = [ int(v) for v in input().split() ]
num_list = [ int(input()) for i in range(n) ]
n_2 = 2 * n
def magic(inlist,barlength):
    return abs( barlength - sum(inlist) ) + ( 10 * ( len(inlist) - 1 ) )

ans = 10**9
for i in range(1,4**n):
    distribute_list = [ [] for i in range(3) ]
    s = bin(i)[2:].zfill(n_2)

    for j in range(0,n_2,2):
        p = int(s[j:j+2],2)
        if p != 0:
            distribute_list[p-1].append(num_list[j//2])
    if all(map(lambda x: x != [],distribute_list)):
        bar_sum = magic(distribute_list[0],a) + magic(distribute_list[1],b) + magic(distribute_list[2],c)
        ans = min(bar_sum,ans)
print(ans)

Measured memory_bytes: 58332
def main():
    k=int(input())
    n=3
    A=[0]*(k+1)
    A[k]=1
    for i in range(1,k)[::-1]:
        l=k//i
        A[i]=pow(l,n)
        for j in range(2,l+1):
            #print(i,i*j)
            A[i]-=A[i*j]
    #print(A)
    ans=0
    for i in range(1,k+1):
        ans+=A[i]*i
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 62064
using System;
using System.Linq;

namespace AGC007
{
    class A
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = input[0];
            int W = input[1];
            char[,] A = new char[W, H];
            for (int h = 0; h < H; h++)
            {
                string s = Console.ReadLine();
                for (int w = 0; w < W; w++)
                {
                    A[w, h] = s[w];
                }
            }

            for (int h = 0; h < H; h++)
            {
                for (int w = 0; w < W; w++)
                {
                    if (0 < w && 0 < h && A[w, h] == '#' && (A[w - 1, h] == '#' && A[w, h - 1] == '#'))
                    {
                        Console.WriteLine("Impossible");
                        return;
                    }

                    if (w < W - 1 && h < H - 1 && A[w, h] == '#' && (A[w + 1, h] == '#' && A[w, h + 1] == '#'))
                    {
                        Console.WriteLine("Impossible");
                        return;
                    }
                }
            }
            Console.WriteLine("Possible");
        }
    }
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

long double EPS = 1e-9;

const int MOD = 1e9+7;

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

	int n; cin >> n;
	vi v(n); FOR(i, n) cin >> v[i];

	vi dp(v);
	for(int i = n-2; i >= 0; i--)
		dp[i] = (dp[i] + dp[i+1]) % MOD;

	ll ans = 0;
	FOR(i, n-1){
		int add = 1LL * v[i] * dp[i+1] % MOD;
		ans = (ans + add) % MOD;
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 4764
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

struct Node{

	Node(int arg_to,int arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	bool operator<(const struct Node &arg) const{
			return cost > arg.cost;
	};

	int to,cost;
};

int main(){

	int N;
	scanf("%d",&N);

	vector<Node> V[N];

	int node,num,to,cost,D[N];;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&node);
		scanf("%d",&num);
		for(int i = 0; i < num; i++){
			scanf("%d %d",&to,&cost);
			V[node].push_back(Node(to,cost));
		}
		D[loop] = BIG_NUM;
	}

	D[0] = 0;

	bool visited[N];
	for(int i = 1; i < N; i++)visited[i] = false;
	visited[0] = true;

	priority_queue<Node> Q;

	for(int i = 0; i < V[0].size(); i++){
		D[V[0][i].to] = V[0][i].cost;
		Q.push(Node(V[0][i].to,V[0][i].cost));
	}

	int min_index;

	while(!Q.empty()){
		if(Q.top().cost == D[Q.top().to]){
			min_index = Q.top().to;
			Q.pop();
		}else{
			Q.pop();
			continue;
		}

		for(int k = 0; k < V[min_index].size(); k++){ //min_index?????????????????´?????§????????¨??´??°??§??????????????§???min_index?????????????????¨?????????????????¢???
			if(D[V[min_index][k].to] > D[min_index] + V[min_index][k].cost){
				D[V[min_index][k].to] = D[min_index] + V[min_index][k].cost;
				Q.push(Node(V[min_index][k].to,D[V[min_index][k].to]));
			}
		}
	}

	for(int i = 0; i < N; i++)printf("%d %d\n",i,D[i]);

    return 0;
}

Measured memory_bytes: 7448
#include <iostream>
#include <cstring>
using namespace std;
char s[17]="CODEFESTIVAL2016";
char t[17];
int main(void){
    cin>>t;
    int ans=0;
    for(int i=0;i<16;i++)if(s[i]!=t[i])ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    cin >> A;
    map<ll, ll> cnt;
    for (int i = 0; i < N; i++) {
        cnt[i + A[i]]++;
    }
    ll ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        cnt[i + A[i]]--;
        ll explore = i - A[i];
        ans += cnt[explore];
    }
    cout << ans << endl;
}

Measured memory_bytes: 27452
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
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 MX = 1000005;

int main(){
    int N;
    ll a[1000010][3];
    ll dp[100010][3];

    cin>>N;
    rep(i,N) rep(j,3) cin>>a[i][j];

    rep(i,N){
        rep(j,3){
            rep(k,3){
                if (j==k) continue;
                else chmax(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }
    ll res = 0;
    rep(j,3) chmax(res, dp[N][j]);
    cout<<res<<endl;
}

Measured memory_bytes: 8312
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;
#define N 501

int main(){
    int n;
    double p[N],q[N];
    double pSum[N][N],qSum[N][N];
    double d[N][N];
    double t;
    
    cin >> n;
    
    for(int i = 0;i < n;++i){
        cin >> p[i];
    }
    
    for(int i = 0;i < n + 1;++i){
        cin >> q[i];
        d[i][i] = q[i];
    }
    
     // p
    for(int i = 0;i < n;++i){
        pSum[i][i] = p[i];
        for(int j = i + 1;j < n;++j){
            pSum[i][j] = pSum[i][j - 1] + p[j];
        }
    }
    
    // q
    for(int i = 0;i < n + 1;++i){
        qSum[i][i] = q[i];
        for(int j = i + 1;j < n + 1;++j){
            qSum[i][j] = qSum[i][j - 1] + q[j];
        }
    }
    
    for(int i = 1;i < n + 1;++i){
        for(int j = 0;j < (n + 1) - i;++j){
            d[j][j + i] = __DBL_MAX__;
            for(int k = 0;k < i;++k){
                t = d[j][j + k] + d[j + k + 1][j + i] + pSum[j][j + i - 1] + qSum[j][j + i];
                d[j][j + i] = min(d[j][j + i], t);
            }
        }
    }
    
    printf("%.8lf\n",d[0][n]);
    
    return 0;
}



Measured memory_bytes: 9104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;
int INF = 100 * 40 + 5;

int a[45], b[45], c[45];
int dp[45][405][405];

int main()
{
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	int suma = 0, sumb = 0;
	REP(i, N)
	{
		cin >> a[i] >> b[i] >> c[i];
		suma += a[i]; sumb += b[i];
	}

	REP(i, N + 1)
	{
		REP(j, 10 * N + 1)
		{
			REP(k, 10 * N + 1)
			{
				dp[i][j][k] = INF;
			}
		}
	}
	dp[0][0][0] = 0;
	REP(i, N)
	{
		REP(j, suma + 1)
		{
			REP(k, sumb + 1)
			{
				if (j - a[i] < 0 || k - b[i] < 0)
				{
					dp[i + 1][j][k] = dp[i][j][k];
				}
				else
				{
					dp[i + 1][j][k] = std::min(dp[i][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
				}
			}
		}
	}

	int min = INF;
	FOR(i, suma + 1, 1)
	{
		FOR(j, sumb + 1, 1)
		{
			if (i*Mb == j*Ma)
			{
				min = std::min(min, dp[N][i][j]);
			}
		}
	}
	if (min == INF)
	{
		min = -1;
	}
	cout << min << endl;

	return 0;
}

Measured memory_bytes: 26880
n = int(input())
ans = 0
m = n
x = 1

while m >= 10: #nの桁数を求める
  m = m / 10
  x = x + 1

for i in range(1,x+1):
  if i == x and i%2 == 1: #最後の奇数桁だったら
    ans = ans + n - 10**(i-1) + 1
  elif i%2 == 0: #偶数桁だったら
      continue
  else: #最後の桁意外の奇数だったら
    ans = ans + 9 * 10**(i-1)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	string s;
	cin >> s;
	int n = (int)s.size();
	if (s[n - 1] == '1' || s[0] == '0') {
		put(-1);
		return 0;
	}
	REP(i, n-1) {
		if (s[i] != s[n - 2 - i]) {
			put(-1);
			return 0;
		}
	}
	vector<int> p(n, -1);
	p[n - 1] = n - 1;
	RREP(i, n-1) {
		if (s[i] == '1') {
			p[i] = i;
		} else {
			p[i] = p[i + 1];
		}
	}
	int last = -1;
	REP(i, n) {
		if (s[i] == '1') {
			if (last < 0) {
				last = i;
			} else {
				put(last+1, i+1);
				last = i;
			}
		}
	}
	put(last + 1, n);
	REP(i, n) {
		if (i != p[i]) {
			put(i+1, p[i]+1);
		}
	}
	return 0;
}


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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef unsigned long long ull;

template<typename T> inline void read(T &x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}

template<typename T> inline bool checkMax(T &a, const T &b) {
	return a < b ? a = b, true : false;
}

template<typename T> inline bool checkMin(T &a, const T &b) {
	return a > b ? a = b, true : false;
}

const int N = 1e4 + 10, mod = 998244353, G = 3;

inline void add(int& a, int b) {
    a += b;
    if (a >= mod) {
        a -= mod;
    } if (a < 0) {
        a += mod;
    }
}

inline void mul(int& a, int b) {
    a = 1ll * a * b - 1ll * a * b / mod * mod;
}

int fac[N], invfac[N];

inline int qpow(int v, int p) {
	int res = 1;
	for (; p; p >>= 1, mul(v, v)) {
		if (p & 1) {
			mul(res, v);
		}
	}
	return res;
}

void init() {
	fac[0] = invfac[0] = 1;
	int ub = 1e4 + 1;
	for (register int i = 1; i <= ub; ++i) {
		mul(fac[i] = fac[i - 1], i);
	}
	invfac[ub] = qpow(fac[ub], mod - 2);
	for (register int i = ub - 1; i; --i) {
		mul(invfac[i] = invfac[i + 1], i + 1);
	}
}

int n, x[N << 2], y[N << 2], r[N << 2], l, S;

void prepare(int n) {
	x[0] = 1;
	for (register int i = 0; i <= n; ++i) {
		y[i] = invfac[i + 1];
	}
	for (l = 0, S = 1; S <= n << 1; S <<= 1, ++l);
	--l;
	for (register int i = 0; i < S; ++i) {
		r[i] = (r[i >> 1] >> 1) | ((i & 1) << l);
	}
}

inline void ntt(int* c, int type) {
	for (register int i = 0; i < S; ++i) {
		if (i < r[i]) {
			swap(c[i], c[r[i]]);
		}
	}
	for (register int i = 1; i < S; i <<= 1) {
		int x = qpow(G, type == 1 ? (mod - 1) / (i << 1) : mod - 1 - (mod - 1) / (i << 1));
		for (register int j = 0; j < S; j += i << 1) {
			int y = 1;
			for (register int k = 0; k < i; ++k, mul(y, x)) {
				int p = c[j + k], q = c[i + j + k];
				mul(q, y);
				add(c[j + k] = p, q);
				add(c[i + j + k] = p, -q);
			}
		}
	}
	if (type == -1) {
		int inv = qpow(S, mod - 2);
		for (register int i = 0; i < S; ++i) {
			mul(c[i], inv);
		}
	}
}

inline void mul(int* c, int* t) {
	for (register int i = 0; i < S; ++i) {
		mul(c[i], t[i]);
	}
}

char a[N], b[N];

int main() {
	scanf("%s%s", a, b);
	int n = strlen(a), c1 = 0, c2 = 0;
	for (register int i = 0; i < n; ++i) {
		if (a[i] == '1' && b[i] == '1') {
			c1++;
		} else if (a[i] == '1' && b[i] == '0') {
			c2++;
		}
	}
	init();
	prepare(c1);
	for (register int p = c2; p; p >>= 1) {
		ntt(y, 1);
		if (p & 1) {
			ntt(x, 1), mul(x, y), ntt(x, -1);
			fill(x + c1 + 1, x + S, 0);
		}
		mul(y, y), ntt(y, -1);
		fill(y + c1 + 1, y + S, 0);
	}
	int res = 0;
	for (register int i = 0; i <= c1; ++i) {
		add(res, x[i]);
	}
	mul(res, fac[c1]), mul(res, fac[c2]), mul(res, fac[c1 + c2]);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define REP(i,n)for(int i=0;i<n;i++)
#define FORD(i,a,b) for(int i=a;i>=(b);i--)
#define MP make_pair
#define F first
#define S second
typedef long long ll;
using namespace std;
int main(){
    ll n,k,s,t;cin >> n >> k >> s >> t;
    vector<ll> a(n);REP(i,n)cin >> a[i];
    vector<map<pair<ll,ll>,ll>> dp(k);
    REP(i,n){
        FORD(j,k-2,0){
            for(auto l=dp[j].begin();l!=dp[j].end();l++){
                dp[j+1][MP((l->F.F)&a[i],(l->F.S)|a[i])]+=(l->S);
            }
        }
        dp[0][MP(a[i],a[i])]=1;
    }
    ll ans=0;
    REP(i,k)ans+=(dp[i][MP(s,t)]);
    cout << ans << endl;
}

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

int main()
{
	int n,d,i,j,k,a[20][20],sum=0,count=0;
	cin >> n >> d;
		
	for(i=0;i<n;i++)
	{
		for(j=0;j<d;j++)
		{
			cin >> a[i][j];
		}
	}
	
	for(i=0;i<n;i++)
	{
		for(k=i;k<n;k++)
		{
			for(j=0;j<d;j++)
			{
				sum+=pow(abs(a[i][j]-a[k][j]),2);
			}
			int inte = abs(sqrt(sum));
			if (sqrt(sum)==inte && sqrt(sum) != 0) count++ ;
		//	cout << sqrt(sum) << endl;
			sum=0;
		}
	}
	
	cout << count ;
}

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

int main(){
  int a,b;
  cin >>a;
  b=a;
  int m=a%2;
  int ans=b/2;
  if(m==1){
    ans=ans+1;
    cout << ans << endl;
  }
  if(m==0){
    cout << ans << endl;
  }
}

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

int main(){
    int A, B, C, N, M ,K;
    int sum = 0;
    int t = 0;
    string s, s1;
    cin >> A;

if(A == 25) cout << "Christmas" << endl;
else if(A == 24) cout << "Christmas Eve"<< endl;
else if(A == 23) cout << "Christmas Eve Eve"<< endl;
else if(A == 22) cout << "Christmas Eve Eve Eve"<< endl;
//    vector<int> X();

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

//    cout <<  << endl;
}

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


void maxof(int* x,int* y){
    int t;
    if(*x > *y){
        t = *x;
        *x = *y;
        *y = t;
    }
}
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    maxof(&a,&b);
    maxof(&b,&c);
    maxof(&a,&b);
    cout<<a<<' '<<b<<' '<<c<<'\n';
    return 0;  
}


Measured memory_bytes: 3104
#include<stdio.h>

void trace(int A[], int N) {
    int i;
    for (i = 0; i < N; i++) {
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

void insertionSort(int A[], int N) {
    int j, i, v;
    for (i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A, N);
    }
}

int main() {
    int N, i, j;
    int A[100];

    scanf("%d", &N);
    for (i = 0; i < N; i++) scanf("%d", &A[i]);

    trace(A, N);
    insertionSort(A, N);

    return 0;
}


Measured memory_bytes: 2060
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	[n, k] <- readIntToList <$> BS.getLine
	ps <- readIntToList <$> BS.getLine
	print $ sum $ take k $ List.sort ps

Measured memory_bytes: 4408
N, L = gets.split.map(&:to_i)

tastes = N.times.map { |i| L + i }

min_abs = 999
min = nil
tastes.each do |taste|
  if min_abs > taste.abs
    min_abs = taste.abs
    min = taste
  end
end

puts tastes.inject(:+) - min


Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll INF = 1000000000;

int main(){
    int N, K;
    ll S;
    cin >> N >> K >> S;

    if(S != INF){
        for(int i = 0; i < K; i++){
            cout << S << " ";
        }
        for(int i = K; i < N; i++){
            cout << INF << " ";
        }
    }
    else {
        for(int i = 0; i < K; i++){
            cout << S << " ";
        }
        for(int i = K; i < N; i++){
            cout << INF - 1 << " ";
        }
    }

    cout << endl;
    return 0;

}


Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <string>
#include <climits>
#include <utility>

#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl
#define ROUNDED(N) fixed << setprecision(N)
#define SPACE " "

typedef long long ll;
using namespace std;

int nextInt() { int n; cin >> n; return n; }
double nextDouble() { double d; cin >> d; return d; }
string nextString() { string str; cin >> str; return str; }

int main() {
	cin.tie(0); //対話型には使えない
	ios::sync_with_stdio(false); //printfと共には使えない
	while (true) {
		int n = nextInt();
		if (!n) break;
		int a_sum = 0, b_sum = 0;
		for (int i = 0; i < n; i++) {
			int a = nextInt(), b = nextInt();
			if (a > b) a_sum += a + b;
			else if (a == b) a_sum += a, b_sum += b;
			else b_sum += a + b;
		}
		cout << a_sum << SPACE << b_sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
from itertools import accumulate

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

def do(A):
  B = [0] * (N+2)
  for i, a in enumerate(A, 1):
    l = max(i - a, 0)
    r = min(i + a + 1, N+1)
    B[l] += 1
    B[r] -= 1
  B = list(accumulate(B))
  return B[1:-1]

def check(A):
  for a in A:
    if a < N:
      return False
  return True

for i in range(K):
  A = do(A)
  if check(A):
    print(*A)
    quit()

print(*A)

Measured memory_bytes: 178160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;


int main() {

    string S;
    cin >> S;

    int n = S.size();

    int cnt = 0;
    for (int i = 0; i < (n / 2); ++i) {
        if (S[i] != S[n - 1 - i]) {
            cnt += 1;
        }
    }

    cout << cnt << endl;

    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int m, int n) {
    while(n != 0) {
        int r = m % n;
        m = n;
        n = r;
    }
    return m;
}


int main(int argc, char const *argv[]) {
  int n1,n2;
  scanf("%d %d",&n1,&n2);
  printf("%d\n",gcd(n1,n2));
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
    int a,b,c,d;
    
    cin >> a >> b >> c >> d;
    
    
    while(a > 0 && c > 0)
    {
    	
        c-=b;
        
        if(c <= 0)
        {
            cout <<"Yes";
            return;
        }
        
        a-=d;
        
        if(a <= 0)
        {
            cout <<"No";
            return;
        }
        
        
    }
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
#define rep(i, s, n) for(i64 i=(s); i < (n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;

signed main()
{
  int N, C, K;
  cin >> N >> C >> K;

  priority_queue<int, vector<int>, greater<int>> pq;

  rep(i, 0, N) {
    int t; cin >> t;
    pq.emplace(t);
  }

  int ans = 0;
  while(!pq.empty()) {
    const int t = pq.top(); pq.pop();
    const int lim = t + K;

    for (int i = 1; i < C && !pq.empty() && pq.top() <= lim; ++i) {
      pq.pop();
    }
    ++ans;
  }

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



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

int main() {
    string S;
    cin >> S;
    
    if ( S[0] - 'a' < 0 ) {
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main() {
  ll n;
  cin >> n;
  ll ans = 1;
  ll num1 = 1, num2 = 1, num3 = 1;
  if(n < 2) {
    cout << 0 << endl;
    return 0;
  }
  for(int i = 0; i < n; i++) {
    ans *= 10;
    ans %= MOD;
    num1 *= 9;
    num1 %= MOD;
    num2 *= 8;
    num2 %= MOD;
  }
  ans -= num1;
  if(ans < 0) {
    ans += MOD;
  }
  ans -= num1;
  if(ans < 0) {
    ans += MOD;
  }
  ans += num2;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a >= 13) cout << b;
    else if(a >= 6) cout << b/2;
    else cout << 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
string x, y;
int dp[1010][1010];
int f(int i,int j) {
	if (i < 0 || j < 0)return 0;
	if (dp[i][j] >= 0)return dp[i][j];
	if (x[i] == y[j])return dp[i][j] = f(i - 1, j - 1) + 1;
	else return dp[i][j] = max(f(i - 1, j), f(i, j - 1));
}
signed main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> x >> y;
		for (int i = 0; i <= x.size(); i++)for (int j = 0; j <= y.size(); j++)dp[i][j] = -1;
		cout << f(x.size() - 1, y.size() - 1) << endl;
	}
}


Measured memory_bytes: 11136
s=input()
t=s.replace("BC","D")
"""print(t)"""
u=""
cnt=0
dcnt=0
for i in range(1,len(t)+1):
  num=(-1)*i
  """print("t",t[num])"""
  if t[num]=="B" or t[num]=="C":
    dcnt=0
  if t[num]=="D":
    dcnt+=1
  if t[num]=="A":
    cnt+=dcnt
  
print(cnt)

Measured memory_bytes: 3500
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) #hate取得
like=[]
hate.sort()
like.sort()
for i in range(10): #like取得
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break
		if pointer==1:
			break


if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #5桁の場合
	for man in like:
		for sen in like:
			for hyaku in like:
				for ju in like:
					for ichi in like:
						if man*10000+sen*1000+hyaku*100+ju*10+ichi>=n:
							kane=man*10000+sen*1000+hyaku*100+ju*10+ichi
							pointer=1
							break
					if pointer==1:
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break				

if pointer==1:
	print(kane)
else:
	print("Error!!")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const ll INF = 1e18 + 10;

int N, K;

int main() {
    cin >> N >> K;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];
    ll sum = 0;
    rep(i,N) sum += a[i];
    set<ll> candidates;
    for(int i= 1; i*i<=sum; ++i) {
        if(sum%i == 0) {
            candidates.insert(i);
            candidates.insert(sum/i);
        }
    }
    ll ans = 1;
    for (ll x : candidates) {
        ll need;
        vector<ll> r(N);
        rep(i,N) r[i] = a[i]%x;
        sort(ALL(r));
        ll B =0;
        rep(i,N) B += x-r[i];
        ll A = 0;
        need = INF;
        rep(i,N) {
            A += r[i];
            B -= x-r[i];
            need = min(need, max(A,B));
        }
        if (need <= K) ans = max(ans,x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <utility>
#include <boost/foreach.hpp>
#include <cmath>

long long int X, N, min, ans;
long long int p[100 + 1];

int main() {
  min = -1;

  std::cin >> X >> N;
  for (int i = 1; i <= N; i++) {
    std::cin >> p[i];
  }

  for (int i = 1; i <= N; i++) {
    if (p[i] == X) {
      goto start;
    }
  }
  std::cout << X << std::endl;
  return 0;
start:
  for (long long l = 1; ; l++) {
    long long int tmp;

    tmp = X - l;
    for (int i = 1; i <= N; i++) {
      if (p[i] == tmp) {
        goto error;
      }
    }
    std::cout << tmp << std::endl;
    return 0;
error:
    tmp = X + l;
    for (int i = 1; i <= N; i++) {
      if (p[i] == tmp) {
        tmp = X;
        break;
      }
    }
    if (tmp == X) {
      continue;
    }
    std::cout << tmp << std::endl;
    return 0;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n;
	
	string str;
	
	while(cin>>n)
	{
		
		cin>>str;
		
		set<int>r;
		
		set<int>w;
		
		for(int i=0;i<n;i++)
		{
			if(str[i]=='R')
			{
				r.insert(i);
			}
			else if(str[i]=='W')
			{
				w.insert(i);
			}
		}
		
		int ans=0;
		
		while(!r.empty() && !w.empty())
		{
			
			int leftt=*w.begin();
			int rightt=*(--r.end());
			
//			cout<<"hehe"<<endl;
//			cout<<leftt<<" "<<rightt<<endl;
//			getchar();
			
			if(leftt > rightt)
			{
				break;
			}
			
			w.erase(leftt);
			w.insert(rightt);
			
			r.erase(rightt);
			r.insert(leftt);
			
			ans++;
			
		}
		
		cout<<ans<<endl;
		
	}
	
	return 0;
}


Measured memory_bytes: 13020
// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
 
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <list>
#include <stack>
#include <bitset>
#include <ctime>
using namespace std;
 
typedef long double ld;
typedef long long int lli;
#define pb(x) push_back(x)
#define fr first
#define sc second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
const lli N = 1e6, N2 = 5e3, delta = 46639, mod = 1e9 + 7, oo = 1e16;
const ld PI = 3.141592653589793;

lli a[N];

int main(){
	lli n, ans = 0;
	cin >> n;
	for (lli i = 0; i < n; i++)
		cin >> a[i];
	for (lli i = 0; i < n; i++)
		for (lli j = i + 1; j < n; j++)
			ans += (a[i] * a[j]);
	cout << ans;
}


Measured memory_bytes: 256
S = input()
counts = []
count = 0
for i in range(len(S)):
  if S[i] == 'A' or S[i] == 'G' or S[i] == 'C' or S[i] == 'T':
    count += 1
  else:
    counts.append(count)
    count = 0
counts.append(count)
if len(S) ==1:
  print(counts[0])
else:
  print(max(counts))

Measured memory_bytes: 9108
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX 1e9+7
#define lim 1e5
using namespace std;


int main()
{
	int n,k;
	cin>>n>>k;

	std::vector<int> v(n+1);
	std::vector<int> dp(n+1);

	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
	}

	int temp;

	for(int i=2;i<=n;i++)
	{
		temp=MAX;
		for(int j=1;j<=k;j++)
		{
			if(i-j>0)
				temp = min(temp,dp[i-j]+abs(v[i]-v[i-j]));

			dp[i] = temp;
		}

	}

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
struct query{
  int type;//0=empty, 1=set
  ll value;
  query(int a=0,ll b=0):type(a),value(b) {}
};
 
query s[(1<<18)];
ll t[(1<<18)];
 
void compute(int k,int l,int r){
  query q=s[k];
  s[k].type=0;
  if(q.type==0||r-l==1)return;
  s[k*2+1]=s[k*2+2]=q;  
  t[k*2+1]=t[k*2+2]=q.value;
}
 
void Set(int a,int b,ll x,int k=0,int l=0,int r=(1<<17)){
  if(b<=l || r<=a)return;
  compute(k,l,r);
  if(a<=l && r<=b){
    s[k]=query(1,x);
    t[k]=x;
  }else{
    int m=(l+r)/2;
    Set(a,b,x,k*2+1,l,m);
    Set(a,b,x,k*2+2,m,r);
    t[k]=min(t[k*2+1],t[k*2+2]);
  }
}
 
ll Get(int a,int b,int k=0,int l=0,int r=(1<<17)){
  if(b<=l || r<=a)return (1LL<<60);
  compute(k,l,r);
  if(a<=l && r<=b){
    return t[k];
  }else{
    int m=(l+r)/2;
    ll lv=Get(a,b,k*2+1,l,m);
    ll rv=Get(a,b,k*2+2,m,r);
    return min(lv,rv);
  }
}
 
 
 
int main(){
  int n,q,type,a,b,x;
  Set(0,(1<<17),2147483647);
  scanf("%d %d",&n,&q);
  while(q--){
    scanf("%d",&type);
    if(type==0){
      scanf("%d %d %d",&a,&b,&x);
      b++;
      Set(a,b,x);
    }else{
      scanf("%d %d",&a,&b);
      b++;
      printf("%lld\n",Get(a,b));
    }
  }
  return 0;
}

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

int main(){
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif

	int n, uniq=0;
	cin >> n;
	bool dupe;
	string vars[n];
	for(int i=0;i<n;i++){
		cin >> vars[i];
	}
	unordered_set<string> s(vars, vars + n);
	cout << s.size();
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define pb push_back
#define mp make_pair

int n, m;
int mas[100000] = {};
int cnt[100001] = {};
int p[100000] = {};

int main()
{
        std::cin.sync_with_stdio(0);
        cin >> n >> m;
        for(int i = 0; i < n; i++){
                int t;
                cin >> t;
                cnt[t]++;
                if(cnt[t] % 2 == 0) p[t % m]++;
                t %= m;
                mas[t]++;
        }

        int ans = 0;
        for(int i = 0; i <= m / 2; i++){
                int cur = i;
                int cur2;
                if(i == 0) cur2 = 0;
                else cur2 = m - i;

                if(cur == cur2){
                        int mx = mas[cur] / 2;
                        ans += mx;
                }
                else{
                        int mx = min(mas[cur], mas[cur2]);
                        mas[cur] -= mx;
                        mas[cur2] -= mx;

                        int probPairs = mas[cur] / 2;
                        p[cur] = min(p[cur], probPairs);

                        probPairs = mas[cur2] / 2;
                        p[cur2] = min(p[cur2], probPairs);

                        ans += mx + p[cur] + p[cur2];
                }
        }
        cout << ans;

        return 0;
}


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

int main () {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U ;
  if(S == U){
    cout << A -1<< " " <<B << endl ;
  } else {
    cout << A << " " << B -1<< endl ;
  }
}

Measured memory_bytes: 256
/* binary_indexed_tree_RAQ.cpp
    BIT を用いた Range Add Query (RAQ)。区間への更新を行える

    verified: AOJ DSL_2_E
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E&lang=ja
*/

#include <bits/stdc++.h>
using namespace std;

/* BIT: 区間和の更新や計算を行う構造体
    初期値は a_1 = a_2 = ... = a_n = 0
    ・add(l,r,x): [l,r) に x を加算する
    ・sum(i): a_1 + a_2 + ... + a_i を計算する
    ・query(l,r): [l,r) の区間の和を求める
    計算量は全て O(logn)
*/
template <typename T>
struct BIT {
    int n;             // 要素数
    vector<T> bit[2];  // データの格納先
    BIT(int n_) { init(n_); }
    void init(int n_) {
        n = n_ + 1;
        for (int p = 0; p < 2; p++) bit[p].assign(n, 0);
    }

    void add_sub(int p, int i, int x) {
        for (int idx = i; idx < n; idx += (idx & -idx)) {
            bit[p][idx] += x;
        }
    }
    void add(int l, int r, T x) {  // [l,r) に加算
        add_sub(0, l, -x * (l - 1));
        add_sub(0, r, x * (r - 1));
        add_sub(1, l, x);
        add_sub(1, r, -x);
    }

    T sum_sub(int p, int i) {
        T s(0);
        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[p][idx];
        }
        return s;
    }
    T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; }

    // [l,r) の区間和を取得
    T query(int l, int r) { return sum(r - 1) - sum(l - 1); }
};

int main() {
    int n, q;
    cin >> n >> q;
    BIT<int> raq(n);

    vector<int> ans;
    for (int i = 0; i < q; i++) {
        int c;
        cin >> c;
        if (c == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            raq.add(s, t + 1, x);
        } else if (c == 1) {
            int i;
            cin >> i;
            ans.push_back(raq.query(i, i + 1));
        }
    }
    for (auto i : ans) {
        cout << i << endl;
    }

    return 0;
}



Measured memory_bytes: 4324
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0

for i in range(n):
    if B[i] - A[i] >= 0:
        ans += A[i]
        B[i] = B[i] - A[i]
        if B[i] - A[i+1] >= 0:
            ans += A[i+1]
            A[i+1] = 0
        else:
            ans += B[i]
            A[i+1] = A[i+1] - B[i]
    else:
        ans += B[i]

print(ans)


Measured memory_bytes: 97884
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
string grid[10];
int wc_count[10];
int cur_wc_count[10];
int main(){
  int H;
  int W;
  int K;
  cin >> H >> W >> K;
  for(int i = 0; i < H; i++){
    cin >> grid[i];
  }

  int  ans = INT_MAX;
  for(int bit_set = 0; bit_set < (1 << (H - 1)); bit_set++){
    int tmp_ans = 0;
    for(int i = 0; i < H - 1; i++){
      if(((bit_set >> i) & 1) == 1){
        tmp_ans ++;
      }
    }

    vector <int> row_range_begin;
    vector <int> row_range_end;
    bool in_range = false;
    for(int i = 0; i < H - 1; i++){
      if(!in_range){
        row_range_begin.push_back(i);
        in_range = true;
      }
      if(in_range && (((bit_set >> i) & 1) == 1)){
        row_range_end.push_back(i);
        in_range = false;
      }
    }
    if(in_range){
      row_range_end.push_back(H - 1);
    } else {
      row_range_begin.push_back(H - 1);
      row_range_end.push_back(H - 1);
    }


    for(int i = 0; i < row_range_begin.size(); i++){
      wc_count[i] = 0;
      cur_wc_count[i] = 0;
    }

    bool valid = true;
    for(int i = 0; i < W; i++){
      for(int j = 0; j < row_range_begin.size(); j++){
        for(int k = row_range_begin[j]; k <= row_range_end[j]; k++){
          if(grid[k][i] == '1'){
            cur_wc_count[j] ++;
          }
          if(cur_wc_count[j] > K){
            valid = false;
            break;
          }
          if(wc_count[j] + cur_wc_count[j] > K){
            tmp_ans ++;
            for(int l = 0; l < row_range_begin.size(); l++){
              wc_count[l] = 0;
            }
          }
        }
        if(!valid){
          break;
        }
      }
      for(int j = 0; j < row_range_begin.size(); j++){
        wc_count[j] += cur_wc_count[j];
        cur_wc_count[j] = 0;
      }
      if(!valid){
        break;
      }
    }
    if(valid){
      ans = min(ans, tmp_ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256