akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

typedef long long LL;
typedef vector<LL> VL;
typedef vector<vector<LL>> VVL;
typedef vector<string> VS;

#define REPD(i,a,b) for (LL i=(a);i<(b);i++)
#define REP(i,n) REPD(i,0,n)

LL llRead(){
  LL a;
  cin >> a;
  return a;
};

string stringRead(){
  string a;
  cin >> a;
  return a;
};

vector<LL> vlRead(LL a){
  vector<LL> rv;
  REP(i, a){
    LL input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}

vector<string> vsRead(LL a){
  vector<string> rv;
  REP(i, a){
    string input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}
vector<vector<LL>> vvlRead(LL a, LL b){
  vector<vector<LL>> rv;
  REP(i, a){
    rv.push_back(vector<LL>());
    REP(j, b) {
      LL input;
      cin >> input;
      rv.at(i).push_back(input);
    }
  }
  return rv;
}

#if 1
#define debug(d) debug1(__LINE__,#d, d)
void debug1(LL line, const char* name, VL& v) {
  cout << line << ":" << name << ":vector<LL>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, LL i) {
  cout << line << ":" << name << ":LL " << i << endl;;
}
void debug1(LL line, const char* name, VS& v) {
  cout << line << ":" << name << ":vector<string>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, VVL& v) {
  cout << line << ":" << name << ":vector<vector<LL>>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    REP(j, (LL)v.at(i).size()) {
      cout << v.at(i).at(j) << " ";
    }
    cout << ", ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, char* s) {
  cout << line << ":" << name << ":char* " << s << endl;;
}
void debug1(LL line, const char* name, vector<const char*>& v) {
  cout << line << ":" << name << ":vector<const char*>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, priority_queue<LL>& p) {
  cout << line << ":" << name << ":priority_queue<LL>(" << p.size() << ") ";
  priority_queue<LL> copy = p;
  while(!copy.empty()) {
    cout << copy.top() << " ";
    copy.pop();
  }
  cout << endl;
}
#else
#define debug(n)
#endif

int main(int argc, const char * argv[]) {
	cout.precision(16);
  // source code

  auto n = llRead();
  auto k = llRead();
  LL a = 0;
  REP(i, n) {
    auto c = llRead();
    if (c >= k) a++;
  }
  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first    
#define se second
#define mod 1000000007
void solve()
{
    ll n;
    cin>>n;
    ll ans=(n-1)*n;
    ans/=2;
    cout<<ans;
}
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif  
    clock_t tStart = clock();
    ll t;
    // cin>>t;
    // while(t--)
       solve();
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}       

Measured memory_bytes: 256
//
// Created by 绔ユ闃?on 2018/9/14.
// 棰樻剰锛氳f(b,n)涓簄鍦╞杩涘埗涓嬬殑鏁颁綅涔嬪拰锛岀粰瀹歯鍜宻锛屾眰婊¤冻f(b,n)=s鐨勬渶灏忕殑b銆?
// 1. 褰揵<=sqrt(n)鏃讹紝鐩存帴鏆村姏銆?
// 2. 褰揵>sqrt(n)鏃讹紝鏈塶 = b*p + q(p<b涓攓<b)锛屼簬鏄湁f(b,n) = f(b,p)+q = p+q = s銆?
//
#include <iostream>
using namespace std;
typedef long long ll;
ll n, s;
ll f(ll b, ll n) {
    if (n < b) {
        return n;
    } else {
        return f(b, n/b) + (n % b);
    }
}
int main() {
    cin >> n >> s;
    if (n < s) {
        cout << -1 << endl;
    } else if (n == s) {
        cout << n+1 << endl;
    } else {
        ll ans1 = 1e12;
        for (ll b = 2; b*b <= n; b++) {
            if (f(b, n) == s) {
                ans1 = b;
                break;
            }
        }
        ll ans2 = 1e12;
        for (ll p = 1; p*p <= n && p <= s; p++) {
            ll q = s - p;
            if ((n - q) % p == 0) {
                ll b = (n - q) / p;
                if (b > p && b > q) {
                    ans2 = min(ans2, b);
                }
            }
        }
        ll ans = min(ans1, ans2);
        if (ans >= 1e12) {
            ans = -1;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
fun main() {
    val n = readInt()
    val lengths = readInts()
    var ans = 0
    for (i in 0 until n) {
        for (j in (i + 1) until n) {
            for (k in (j + 1) until n) {
                val sides = listOf(lengths[i], lengths[j], lengths[k]).sorted()
                if (sides.toSet().size == 3 && sides[0] + sides[1] > sides[2]) ans++
            }
        }
    }

    println(ans)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 56576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N =1e4 + 5;

int main(){
    int n,m;
  	scanf("%d %d",&n,&m);
  	int len = min(n,m);
  	n=n==len?m:n;
  	for(int i = 0;i < n;i++)
      	printf("%d",len);
    return 0;
}


Measured memory_bytes: 256
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD

    def combination2(self, k, r):
        """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用"""
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.MOD
        return (res * self.inv_fact[r]) % self.MOD


n, a, b, c, d = map(int, input().split())
MOD = 10 ** 9 + 7
comb = Combination(10 ** 5, MOD)

dp = [[0] * (n + 1) for i in range(b - a + 2)]
dp[0][0] = 1

for i in range(b - a + 1):
    per_g = i + a
    for j in range(0, n + 1):
        dp[i + 1][j] = dp[i][j]
        for cnt_g in range(c, d + 1):
            if j - cnt_g * per_g < 0:
                break
            dp[i + 1][j] += dp[i][j - cnt_g * per_g] * comb.combination(j, cnt_g * per_g)\
                            * comb.factorial(cnt_g * per_g) * (pow(comb.inverse_factorial(per_g), cnt_g, MOD))\
                            * comb.inverse_factorial(cnt_g)
            dp[i + 1][j] %= MOD
print(dp[-1][-1])

Measured memory_bytes: 102732
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    set<int> s;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        s.insert(x);
    }
    if (sz(s) == n){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
long long m=1e9+7;

long long maxProductSubarrayOfSizeK(long long A[], long long n, long long k) 
{  
    sort(A, A + n); 
    long long product = 1; 
    if (A[n - 1] == 0 && (k & 1)) 
        return 0; 
    if (A[n - 1] < 0 && (k & 1)) 
    { 
        for (long long i = n - 1; i >= n - k; i--) 
            product =(product*A[i])%m; 
        return product; 
    } 
    long long i = 0; 
    long long j = n - 1; 
    if (k & 1) 
    { 
        product =(product*A[j])%m; 
        j--; k--; 
    } 
    k >>= 1; 
    for (long long itr = 0; itr < k; itr++) 
    { 
        long long left_product =(A[i] * A[i + 1]); 
        long long right_product =(A[j] * A[j - 1]); 
        if (left_product > right_product) 
        { 
            left_product%=m;
            product =(product*left_product)%m; 
            i += 2; 
        } 
        else 
        { 
            right_product%=m;
            product = (product*right_product)%m; 
            j -= 2; 
        } 
    } 
    return product; 
} 

int main()
{
    long long n,k;
    cin>>n>>k;
    long long a[n];
    for(long long i=0; i<n; i++)
        cin>>a[i];
    cout<<(maxProductSubarrayOfSizeK(a,n,k)+m)%m<<endl;
    return 0;
}

Measured memory_bytes: 5184
#include<bits/stdc++.h> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define REP(i,a,b) for(int i=int(a);i<=int(b);i++)
#define MOD 1000000007
#define INF 2000000000
#define DESPACITO 1000000000000000000
#define PI acos(-1);
#define E 998244353
#define pb push_back
#define mp make_pair
#define ll long long

using namespace std;


int main()
{
	IOS;
	int n,x;
	cin >> n >> x;
	int pos =0;
	int ct=0;
	REP(i,1,n)
	{
		if(pos<=x)
			ct++;
		int l;
		cin >> l;
		pos+=l;
	}
	if(pos<=x)
		ct++;
	cout << ct;
}


Measured memory_bytes: 256
from collections import Counter
def cmb(n,k):
    over = 1
    under = 1
    for i in range(n-k+1,n+1):
        over *= i
    for i in range(1,k+1):
        under *= i
    return over//under

N,A,B = map(int,input().split())
v = list(map(int,input().split()))
C = Counter(v)
li = sorted(list(C.keys()),reverse=True)
ans = 0
SUM = 0
ave = 0
remain = A
n = C[li[0]]
if n >= A:
    ave = li[0]
    for k in range(A,min(B,n)+1):
        ans += cmb(n,k)
else:
    for i in li:
        if C[i] < remain:
            SUM += i*C[i]
            remain -= C[i]
        else:
            SUM += i*remain
            ans = cmb(C[i],remain)
            ave = SUM/A
            break
print(ave)
print(ans)

Measured memory_bytes: 67584
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	string s; cin >> s;
	ll k; cin >> k;
	int len = s.length();
	for (int i = 0; i < len; i++) {
		int step = (26 - (s[i] - 'a')) % 26;
		if (k >= step) {
			k -= step;
			s[i] = 'a';
		}
	}
	if (k > 0) {
		s[len - 1] = (s[len - 1] -'a'+ k) % 26 +'a';
	}
	cout << s << endl;
}


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

int main(){
  string s,t;
  cin>>s;
  cin>>t;
  int n;
  n=s.size();
  for(int i=0;i<n;i++){
    if(s.at(i)!=t.at(i)){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    int tmp;
    rep(i, n)
    {
        if (h[i])
        {
            tmp = i;
            break;
        }
    }

    rep(cx, 100 + 1)
    {
        rep(cy, 100 + 1)
        {
            int H = h[tmp] + abs(x[tmp] - cx) + abs(y[tmp] - cy);
            bool ck = true;
            rep(i, n)
            {
                int hh = max(H - abs(x[i] - cx) - abs(y[i] - cy), 0);
                if (hh != h[i])
                    ck = false;
            }
            if (ck)
            {
                printf("%d %d %d\n", cx, cy, H);
            }
        }
    }
    // cout << ((a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) ? "Possible" : "Impossible") << "\n ";

    return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream> 
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;

#define assert_range(x,a,b) assert((a) <= (x) and (x) <= (b))
using ll = long long;
const int INF = 1e9;

const int K = 1e5;
bool winning[K+1][2];

int main() {
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int h = 0; h <= k; ++h) {
        for (int player = 0; player <= 1; ++player) {
            winning[h][player] = false;
            for (auto s : a) {
                if (s > h) break;
                if (!winning[h-s][1-player]) {
                    winning[h][player] = true;
                    break;
                }
            }
        }
    }
    cout << (winning[k][0] ? "First" : "Second") << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i < (int)(n); i++)
typedef long long ll;
#define NP next_permutation
#define MP make_pair

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int H, W;
  cin >> H >> W;
  int S = H*W;
  int h, w;
  cin >> h >> w;
  int ans = S - (h*W + w*H - h*w);
  cout << ans << endl;
}




Measured memory_bytes: 256
// i_m_arin

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef map<ll,ll> mpll;
typedef set<ll> stll;

#define f(i, a, n) 	for(ll i=a; i<(ll)n; i++)
#define f2(i, a, b) for(ll i=a; i<=(ll)b; i++)
#define pb 			push_back
#define ff 			first
#define ss 			second
#define pf			push_front
#define mp			make_pair
#define all(a)		(a).begin(),(a).end()
#define decimal(x)	fixed<<setprecision(x)
#define fsort(a)	sort(all(a))
#define rsort(a)	sort(all(a),greater<>())
#define fast_io		ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem0(a)		memset(a,0,sizeof(a))
#define mem1(a)		memset(a,-1,sizeof(a))
#define lcm(a,b)	(a*b)/__gcd(a,b)
#define ub(v,x)		upper_bound(all(v),x)-v.begin()
#define lb(v,x)		lower_bound(all(v),x)-v.begin()

const ld PI  = acos(-1);
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll SIZE= 100000;


void solve(){

ll a,b,c,d;
cin>>a>>b>>c>>d;
// if(b>=0 && d>=0) cout<<b*d<<endl;
// else if(b<0 && d<0) {
// 	cout<<b*d<<endl;
// }
// else{
// 	if(b<0){
// 		cout<<b*c<<endl;

// 	}
// 	else if(d<0){
// 		cout<<d*a<<endl;
// 	}
// }
ll ar[10];
ar[0]=a*c;
ar[1]=a*d;
ar[2]=b*c;
ar[3]=b*d;
sort(ar,ar+4);
cout<<ar[3]<<endl;

}


int main(){
	fast_io;
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
def part(A,p,r):
    x=A[r]
    i=p-1
    for j in range(p,r):
        if(A[j]<=x):
            i+=1
            A[i],A[j]=A[j],A[i]
    A[i+1],A[r]=A[r],A[i+1]
    return i+1

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

qi=part(a,0,len(a)-1)
list_qi=[a[qi]]
a[qi]=list_qi
print(*a)


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

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

// chmax, chmin
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;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long X) {
    if( X >= 30 ){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }
}

int main() {
  long long X;
  scanf("%lld", &X);
  solve(X);
  return 0;
}


Measured memory_bytes: 3748
signlist = ["101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010",
            "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000",
            "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000",
            "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011",
            "10010000"]

char = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"
charlist = list(char)
decode = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"
decodelist = list(decode)

while 1:
    try:
        sentence = input()
    except EOFError:
        break

    sentence = list(sentence)
    encode = ""
    for s in sentence:
        num = charlist.index(s)
        encode += signlist[num]

    tmp = len(encode) % 5
    if tmp != 0:
        encode += "0" * (5-tmp)

    encodelist = []
    for i in range(0, len(encode), 5):
        encodelist.append(encode[i:i+5])

    ans = ""
    for e in encodelist:
        dec_e = int(e, 2)
        ans += decodelist[dec_e]

    print(ans)



Measured memory_bytes: 5584
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

bool visited[20];
int bitmask[20];
int memo[1<<20];
int c[20];
int n,U;
int S, sum;
int solve() {
  if (memo[S]>=0) return memo[S];
//  cout <<bitset<4>(S) << " "  << sum << endl;
  if (sum >= U) return 0;
  int res = INF;
  REP(i,n) {
    if (!(S>>i&1)) {
      if ((S&bitmask[i]) == bitmask[i]) {
        if (sum+c[i]>=U) return memo[S]=1;
        else {
          S|=1<<i;
          if (memo[S]>=0)
            res = min(res, memo[S]+1);
          else {
            sum += c[i];
            res = min(res, solve()+1);
            sum -= c[i];
          }
          S^=1<<i;
        }
      }
    }
  }
  return memo[S] = res;
}

int main() {
  while(cin>>n>>U, n||U) {
    memset(bitmask,0,sizeof(bitmask));
    REP(i,n) {
      int k;
      cin >> c[i] >> k;
      REP(j,k) {
        int r;
        cin >> r;
        bitmask[i] |= 1<<r;
      }
    }
    if (U==0) {                 // ツつ「ツづゥツつゥツ不ツ鳴セ
      cout << 0 << endl;
      continue;      
    }

    memset(visited,0,sizeof(visited));
    memset(memo,-1,sizeof(memo));
    S = 0; sum = 0;
    cout << solve() << endl;
  }
}

Measured memory_bytes: 4964
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod=1e9+7;
//vector<vector<int>>v;

int main() {
    ll a,b,c,d, res[4];
    cin>>a>>b>>c>>d;
 res[0]=a*c;
 res[1]=a*d;
 res[2]=b*c;
 res[3]=b*d;
sort(res,res+4);
cout<<res[3]<<endl;
   
    
    
    
    
    
    
	// your code goes here
	return 0;
}


Measured memory_bytes: 3632
import math
ans = []
while True:
    n = int(input())
    if n == 0:
        break
    sn = list(map(float,input().split()))
    avg = sum(sn) / len(sn)
    var = 0
    for i in sn:
        var += (i - avg)**2
    var /= n
    ans.append(math.sqrt(var))

for i in ans:
    print(i)


Measured memory_bytes: 5776
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int gcm(int x, int y){int r;while((r=x%y)!=0)x=y,y=r;return y;}
int main(void){
    
    int n,x;
    scanf("%d%d",&n,&x);
    int t[100000];
    int ans=0;
    for(int i=0;i<n;i++){
        scanf("%d",&t[i]);
        if(i==0){
            ans=gcm(abs(t[0]-x),abs(t[0]-x));
        }else if(i>0){
            ans=gcm(ans,abs(t[i]-x));
        }
    }
    printf("%d\n",ans);
    
}


Measured memory_bytes: 2036
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    s = to_string(n);
    string r;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '1')
        {
            r.push_back('9');
        }else{
            r.push_back('1');
        }
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
import math

x = int(input())

prm_dict = {i: True for i in range(2, 100004)}
for n in range(2, 100004):
    if prm_dict[n]:
        if n >= x:
            break
        for nk in range(n * 2, 100004, n):
            prm_dict[nk] = False
print(n)


Measured memory_bytes: 19428
# 写経 全然わからん
d,g=map(int,input().split())
p,c=[0]*d,[0]*d

for i in range(d):
    p[i],c[i]=map(int,input().split())

ans=float('inf')

for i in range(2**d):
    s=0
    cnt=0
    rest_max=-1
    for j in range(d):
        if (i>>j)&1:
            s+=100*(j+1)*p[j]+c[j]
            cnt+=p[j]
        else:
            rest_max=j
    if s<g:
        s1=100*(rest_max+1)
        need=(g-s+s1-1)//s1 # 切上げ？
        if need>=p[rest_max]:continue
        cnt+=need
    ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = int(b) - 1; i >= (int)(a); --i)
using pii = pair<int, int>;
using vi = vector<int>;

pair<char, int>parse(string s) {
	int level = 0;
	while (s[level] == '.') {
		level++;
	}
	return make_pair(s[level], level);
}

int dfs(vector<string>& v, int& idx) {

	char c; int level;
	tie(c, level) = parse(v[idx]);
	//cerr << "c:" << c << "level:" << level << endl;
	if (isdigit(c)) {
		return (int)c - '0';
	}
	else {
		int ret;
		if (c == '+') {
			ret = 0;
			while (idx + 1 < v.size() and parse(v[idx + 1]).second == level + 1) {
				idx++;
				ret += dfs(v, idx);
			}
		}
		else {
			ret = 1;
			while (idx + 1 < v.size() and parse(v[idx + 1]).second == level + 1) {
				idx++;
				ret *= dfs(v, idx);
			}
		}
		//cerr << "c:" << c << ",level:" << level << ",ret:" << ret << ",idx:" << idx << endl;

		return ret;
	}
}

void solve(int n) {
	vector<string>v(n);
	rep(i, 0, n) {
		cin >> v[i];
	}
	int idx = 0;
	cout << dfs(v, idx) << endl;
}

signed main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) break;
		solve(n);
	}
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	string s;
	cin >> s;
	
	vector <char> v;
	
	for(int i = 0; i < s.size(); i ++){
		if(s[i] == 'B'){
			if(!v.empty()){
				v.pop_back();
			}
			continue;
		}
		
		v.push_back(s[i]);
	}
	
	for(int i = 0; i < v.size(); i ++){
		cout << v.at(i);
	}
	
	return 0;
}


Measured memory_bytes: 3616
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

if all(a==0 for a in A):
  answer="Yes"

elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    answer="Yes"
     
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    bin(AA[third]^AA[2*third])==bin(AA[0]) and \
    bin(AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)

Measured memory_bytes: 14460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}

class comb{
	vector<ll> f,fr;
	ll MOD_;
	public:
	//a^(p-1) = 1 (mod p)(p->Prime numbers)
	//a^(p-2) = a^(-1)
	ll calc(ll a,ll b,ll p){//a^(b) mod p   
		if(b==0)return 1;
		ll y = calc(a,b/2,p);y=(y*y)%p;
		if(b & 1) y = (y * a) % p;
		return y;
	}
	void init(ll n,ll mod){//input max_n
		MOD_ = mod;
		f.resize(n+1);
		fr.resize(n+1);
		f[0]=fr[0]=1;
		for(ll i=1;i<n+1;i++){
			f[i] = (f[i-1] * i) % mod;
		}
		fr[n] = calc(f[n],mod-2,mod);
		for(ll i=n-1;i>=0;i--){
			fr[i] = fr[i+1] * (i+1) % mod;
		}
	}
	ll nCr(ll n,ll r){
		if(n<0||r<0||n<r)return 0;
		return f[n] * fr[r] % MOD_ * fr[n-r] % MOD_;
	}//nHr = n+r-1Cr
};


int main(){


	ll N,ans=0;
	cin >> N;
	vector<ll> A(N),num(100008,0);
	FOR(i,0,N) cin >> A[i];
	FOR(i,0,N) num[A[i]]++;
	FOR(i,0,N) ans+=A[i];

	ll Q;
	cin >> Q;

	FOR(i,0,Q){
		ll b,c;
		cin >> b >> c;
		ll bf = num[b];
		ans += c*bf - b*bf;
		num[b] = 0;
		num[c] += bf;
		cout << ans << endl;
	}
}



Measured memory_bytes: 4840
s = input()
t = input()
        
dic = "abcdefghijklmnopqrstuvwxyz"
s_dic = {}
t_dic = {}
for i in dic:
    s_dic[i] = []
    t_dic[i] = []

for i in range(len(s)):
    s_dic[s[i:i+1]].append(i)
    t_dic[t[i:i+1]].append(i)

s_list = s_dic.values()
t_list = t_dic.values()

if sorted(s_list) == sorted(t_list):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14448
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	// それぞれの食べ物(数字)の出現回数をカウント
	count := make([]int, m)
	for i := 0; i < n; i++ {
		tmp := 0
		fmt.Scan(&tmp)
		for j := 0; j < tmp; j++ {
			tmp2 := 0
			fmt.Scan(&tmp2)
			count[tmp2-1]++
		}
	}

	// 出現回数==人数 な食べ物はみんな好き
	ans := 0
	for _, c := range count {
		if c == n {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<set>
#include<map>
#include<cmath>
#include<deque>
#include<stack>
#include<ctime>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
#define MAXN 600
queue<int> Q;
int siz[MAXN+5];
int G[MAXN+5][MAXN+5];
double f[MAXN+5],g[MAXN+5];
int main(){
	int n=read(),m=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read();
		G[u][v]=1,siz[u]++;
	}
	for(int i=n-1;i>=1;i--)
		for(int j=i+1;j<=n;j++)
			if(G[i][j])
				f[i]+=(f[j]+1)/siz[i];
	double ans=f[1];
	for(int t=n;t>=1;t--){
		if(siz[t]!=1){
			int pos=-1;
			for(int j=t+1;j<=n;j++)
				if(G[t][j]&&(pos==-1||f[j]>f[pos]))
					pos=j;
			g[t]=0;
			for(int j=t+1;j<=n;j++)
				if(G[t][j])
					if(pos!=j)
						g[t]+=(f[j]+1)/(siz[t]-1);
			for(int i=t-1;i>=1;i--){
				g[i]=0;
				for(int j=i+1;j<=n;j++)
					if(G[i][j])
						g[i]+=(g[j]+1)/siz[i];
			}
			ans=min(ans,g[1]);
		}
		g[t]=f[t];
	}
	printf("%.8lf\n",ans);
	return 0;
}

Measured memory_bytes: 1664
import math

while True:
    a = int(input())
    if a == 0:
        break
    b = list(map(float, input().split()))
    m = sum(b)/a
    s = 0
    for i in range(int(a)):
        s += (b[i]-m)**2
    s = s / (int(a))
    s = math.sqrt(s)
    print(s)

Measured memory_bytes: 7756
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define VV(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	int n; cin >> n;
	vi v(n); rep(i, 0, n) cin >> v[i];
	reverse(all(v));
	rep(i, 0, n - 1) {
		cout << v[i] << " ";
	}
	P(v[n - 1]);
	return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

vector<int> enum_divisor(int n) {
    vector<int> divisors;
    for (int i=1;i*i<=n;i++) {
        if (n % i == 0) {
            divisors.push_back(i);
            if (i*i != n) divisors.push_back(n/i);
        }
    }
    sort(divisors.begin(),divisors.end());
    return divisors;
}

int gcd(int a, int b) {
    if (a<b) gcd(b,a);
    int r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

int a,b,k;
signed main() {
    cin >> a >> b >> k;
    int q = gcd(a,b);
    vector<int> divisors = enum_divisor(q);
    reverse(divisors.begin(),divisors.end());
    cout << divisors[k-1] << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  deque<char> qa, qb, qc;
  for (int i = 0; i < sa.size(); i++) qa.push_back(sa[i]);
  for (int i = 0; i < sb.size(); i++) qb.push_back(sb[i]);
  for (int i = 0; i < sc.size(); i++) qc.push_back(sc[i]);
  char ans = 'a';
  while(true){
    if (ans == 'a') {
      if (qa.empty()) break;
      ans = qa.front();
      qa.pop_front();
    }
    if (ans == 'b') {
      if (qb.empty()) break;
      ans = qb.front();
      qb.pop_front();
    }
    if (ans == 'c') {
      if (qc.empty()) break;
      ans = qc.front();
      qc.pop_front();
    }
  }
  cout << (char)(ans + 'A' - 'a') << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;

int main()
{
	int N,K;
	cin >> N >> K;
	
	if (K == 1)
	{
		cout << 0 << endl;
	}
	else {
		cout << (N - K + 1) -1 << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[1005];
int main() {
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; ++i) cin >> a[i];
    sort(a,a+n);
    int ans = 0;
    for(int i = 0 ;  i < k; ++i) ans += a[i];
    cout << ans << endl;
return 0;
}

Measured memory_bytes: 3616
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String[] w = {"Sunny", "Cloudy", "Rainy"};
            String cur = in.next();
            for (int i = 0; i < 3; i++)
                if (w[i].compareTo(cur) == 0) {
                    out.println(w[(i + 1) % 3]);
                    return;
                }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}

Measured memory_bytes: 19412
#include <iostream>
#include<string>
#include<iomanip>
#define N 100
using namespace std;
int main(void) {
	int n;
	int k;
	int i;
	int a=0;

	cin >> n;
	cin >> k;

	for (i = 1; i <= n; i = i + 2) {
		a++;
	}

	if (k<=a)
		cout << "YES";
	else
		cout << "NO";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(){

	int i,n,m = 100000;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		m*=1.05;
		if(m%1000>0){
			m-=(m%1000);
			m+=1000;
		}
	}
	printf("%d\n",m);


	return 0;
}

Measured memory_bytes: 0
n=int(input())
a=list(map(int,input().split()))
p=[]
for j in range(30):
  p.append(pow(2,j))
t=0
for i in range(n):
  t=t^a[i]
for i in range(n):
  ans=0
  for j in range(30):
    ans=ans+p[j]*(((a[i]^t)//p[j])%2)
  print(ans,end=" ")


Measured memory_bytes: 31536
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
using namespace std;

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

int main() {
	long long x;
	cin >> x;

	long long count = 2 * ((x - x % 11) / 11);
	if (0 < x % 11 && x % 11 < 7) {
		count += 1;
	}
	else if(6 < x % 11){
		count += 2;
	}
	

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3536
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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 (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main() {
	int n;
	cin >> n;
	cout << n*n*n << endl;
}

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

using namespace std;

using ll = long long;

const int MN = 102;

int n,k;
ll v[MN];

ll memo[MN][MN][MN];
bool memod[MN][MN][MN];
ll f(int ki, int l, int r){
	if(l>r)return 0;
	if(ki>=k)return 0;
	if(memod[ki][l][r])return memo[ki][l][r];
	memod[ki][l][r]=1;
	ll a = f(ki+1,l+1,r)+v[l];
	if(ki+1<k)a=max(a,f(ki+2,l+1,r));
	ll b = f(ki+1,l,r-1)+v[r];
	if(ki+1<k)b=max(b,f(ki+2,l,r-1));
	return memo[ki][l][r]=max(0ll,max(a,b));
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>k;
	for(int i=0; i<n; ++i)cin>>v[i];
	cout<<f(0,0,n-1)<<endl;
	return 0;
}


Measured memory_bytes: 7808
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;
 
signed main(){
	int N,K;
	cin >> N >> K;
	vector<int>a(N);
	REP(i,N){
		cin >> a[i];
	}
	int LOG2 = log2(200010);
	REP(i,min(K,1000ll)){
		vector<int>b(N + 1);
		REP(j,N){
			int l = max(0ll,j - a[j]);
			int r = min(N - 1,j + a[j]);
			b[r + 1] += -1;
			b[l] += 1;
		}
		REP(j,N){
			b[j + 1] += b[j];
		}
		REP(j,N)a[j] = b[j];
	}
	REP(i,a.size())cout << a[i] << " \n"[i+1 == a.size()];
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380
struct ST {
    int val, mask;
    vector<int> c;
};

vector<ST> item;
int N, M;

int dp[2][1 << 12];
int main() {
    cout << fixed << setprecision(10);
    cin >> N >> M;
    item.resize(M);
    REP(i, M) {
        cin >> item[i].val;
        int b;
        cin >> b;
        REP(j, b) {
            int t;
            cin >> t;
            item[i].mask |= 1 << (t - 1);
        }
    }

    REP(mask, 1 << 12) {
        REP(key, 2) {
            dp[key][mask] = INF;
        }
    }

    dp[1][0] = 0;
    REP(key, M) {
        REP(mask, 1 << N) {
            if(dp[(key + 1) & 1][mask] != INF) {
                chmin(dp[key & 1][mask | item[key].mask], dp[(key + 1) & 1][mask] + item[key].val);
                chmin(dp[key & 1][mask], dp[(key + 1) & 1][mask]);
            }
        }
    }

    int ans = dp[(N + 1) & 1][(1 << N) - 1];
    if(10000000 <= ans) ans = -1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,m,x,ans=0,s=0;
map<ll,ll>viz;
map<ll,ll>wa;
char a,b;
int32_t main(){
CODE_START;
cin>>n>>m;
for(ll i=0;i<m;i++)
{
    cin>>x;
    cin>>a>>b;
    if(a=='A'&&viz[x]==0){
        viz[x]=1;
        ans++;
    }else if(viz[x]==0&&a=='W'){
   wa[x]++;
    }
}
for(ll i=1;i<=1e5;i++)
if(viz[i]==1){
    s=s+wa[i];
}
cout<<ans<<' '<<s<<endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int main(void){
    char c1[3], c2[3],c3[3];
    
    for(int i=0;i<3;i++) cin >> c1[i];
    for(int i=0;i<3;i++) cin >> c2[i];
    for(int i=0;i<3;i++) cin >> c3[i];
    
    cout << c1[0] << c2[1] << c3[2] << endl;
    
}


Measured memory_bytes: 256
/* 
 * File:   main.cpp
 * Author: masa
 *
 * Created on 2016/03/05, 9:02
 */

#include <cstdlib>
#include <string>
#include <iostream>


#define MAX 101

using namespace std;

/*
 * 
 */
int main(void) {
    string line;
    

    
    const char* decomposed;
    while(cin >> line) {
        decomposed = line.c_str();
        
        int i = 0;
        while(i < line.length()) {
            if(decomposed[i] == '@') {
                int size = (int)decomposed[i + 1] - 48;
                for(int j = 0; j < size; j++) {
                    cout << decomposed[i + 2];
                }
                i += 3;
            }
            else {
                cout << decomposed[i];
                i++;
            }
        }
        cout << endl;
    }
    return 0;
}

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

#define FLASH ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >  
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"

int32_t main()
{
 FLASH;
 int n,m,x;
 cin>>n>>m>>x;
 int arr[m];
 for(int i=0;i<m;i++)
 {
 	cin>>arr[i];
 }
 int cnt=0;
 for(int i=0;i<m;i++)
 {
 if(arr[i]<x){ cnt++;}
 else{ break;}
 }
 cout<<min(cnt,abs(m-cnt))<<endl;
}



Measured memory_bytes: 3652
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

char buf[200005];

char ret[200005];

int main() {
  scanf("%s", buf);
  int retLen = 0;
  int bufLen = strlen(buf);
  for(int i = 0; i < bufLen; i++) {
    if(buf[i] == 'T' && retLen && ret[retLen-1] == 'S') {
      retLen--;
    }
    else {
      ret[retLen++] = buf[i];
    }
  }
  printf("%d\n", retLen);
}


Measured memory_bytes: 640
/*author : Yashvardhan
Saturday, February 02, 2019
7:58 PM
*/

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

typedef long long ll;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define endl '\n'

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

vi vals;
int dp[3005][3005];

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int solve(int start, int end){
	if(dp[start][end] != -1) return dp[start][end];
	if(start == end) return dp[start][end] = vals[start];
	if(start + 1 == end){
		return dp[start][end] = abs(vals[start] - vals[end]);
	}
	int op1 = vals[start] - solve(start+1,end);
	int op2 = vals[end] - solve(start,end-1);
	return dp[start][end] = max(op1,op2);
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n;
	cin>>n;

	for(int i = 1; i <= n ; i++){
		int x;
		cin>>x;
		vals.pb(x);
	}

	memset(dp,-1,sizeof(dp));
	
	solve(0,n-1);
	int ans = dp[0][n-1];
	cout<<ans<<endl;

	t2 = clock();
	cerr<<endl<<t2-t1<<endl;
	
	return 0;
}



Measured memory_bytes: 71040
#include <stdio.h>

#define WIDTH 6
#define HEIGHT 12

enum { YET, ALREADY };

int del( void );
int search( int, int );
int search_body( int, int, char );
void fall( void );

typedef struct {
	char color;
	int state;
} FIELD;

FIELD field[ WIDTH + 2 ][ HEIGHT + 2 ] = {};
const int dx[ 4 ] = { -1, 0, 1, 0 }, dy[ 4 ] = { 0, -1, 0, 1 };

int stack[ WIDTH * HEIGHT ], sp;

int main( void ) {
	int n, x, y, chain;

	for ( scanf( "%d", &n ); n--; printf( "%d\n", chain ) ) {
		for ( y = 1; y <= HEIGHT; y++ )
			for ( x = 1; x <= WIDTH; x++ ) {
				scanf( " %c", &field[ x ][ y ].color );
				field[ x ][ y ].state = YET;
			}

		for ( chain = 0; del(); chain++ )
			fall();
	}

	return 0;
}

int del( void ) {
	int x, y, del = 0;

	for ( y = 1; y <= HEIGHT; y++ )
		for ( x = 1; x <= WIDTH; x++ )
			if ( field[ x ][ y ].color != '.' && field[ x ][ y ].color != 'O' && field[ x ][ y ].state == YET ) {
				sp = 0;
				if ( search( x, y ) >= 4 ) {
					while ( sp-- )
						field[ stack[ sp ] / ( HEIGHT + 2 ) ][ stack[ sp ] % ( HEIGHT + 2 ) ].color = '.';

					del++;
				}
			}

	return del;
}

int search( int x, int y ) {
	return search_body( x, y, field[ x ][ y ].color );
}

int search_body( int x, int y, char color ) {
	int i, sum;

	stack[ sp++ ] = x * ( HEIGHT + 2 ) + y;
	field[ x ][ y ].state = ALREADY;

	sum = 0;
	for ( i = 4; i--;  ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ].state == YET )
			if ( field[ nx ][ ny ].color == color )
				sum += search_body( nx, ny, color );
			else if ( field[ nx ][ ny ].color == 'O' )
				stack[ sp++ ] = nx * ( HEIGHT + 2 ) + ny;
	}

	return sum + 1;
}

void fall( void ) {
	int x, y;

	for ( x = 1; x <= WIDTH; x++ ) {
		int cnt = 0;

		for ( y = HEIGHT; y; y-- )
			if ( field[ x ][ y ].color == '.' )
				cnt++;
			else {
				field[ x ][ y + cnt ].color = field[ x ][ y ].color;
				field[ x ][ y + cnt ].state = YET;
			}

		for ( y = cnt; y; field[ x ][ y-- ].color = '.' ) ;
	}
}

Measured memory_bytes: 596