akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MX = 500005;
const ll MOD = 998244353;

int n, m;
ll fac[MX], faci[MX], inv[MX], pwn[MX], pwm[MX];

void init()
{
	int x = max(n, m);
	fac[0] = faci[0] = inv[0] = inv[1] = pwn[0] = pwm[0] = 1;
	for(int i=1; i<=x; i++)
	{
		fac[i] = fac[i-1] * i % MOD;
		if(i > 1) inv[i] = (MOD*MOD-(MOD/i)*inv[MOD%i]) % MOD;
		faci[i] = faci[i-1] * inv[i] % MOD;
		pwn[i] = pwn[i-1] * (n+1) % MOD;
		pwm[i] = pwm[i-1] * (m+1) % MOD;
	}
}

void work()
{
	ll ans = 0;
	auto C = [=](int x, int y){return fac[x]*faci[y]%MOD*faci[x-y]%MOD;};
	for(int i=0; i<=min(n, m); i++)
	{
		ll coe = (i&1) ? (MOD-1) : (+1);
		ans = (ans + coe*C(n, i)%MOD*C(m, i)%MOD*pwn[m-i]%MOD*pwm[n-i]%MOD*fac[i]) % MOD;
	}
	printf("%lld\n", ans);
}

int main()
{
	scanf("%d%d", &n, &m);
	init();
	work();
	return 0;
}

Measured memory_bytes: 19712
#include <cstdio>
#include <algorithm>
using namespace std;
int vis[110];
int main(){
	int x,n,i,a,l,r;
	scanf("%d%d",&x,&n);
	if(n==0){printf("%d\n",x);return 0;}
	for(i=1;i<=n;i++)scanf("%d",&a),vis[a]=1;
	if(!vis[x]){printf("%d\n",x);return 0;}
	l=r=x;
	while(1){
		l--,r++;
		if(!vis[l]){printf("%d\n",l);break;}
		if(!vis[r]){printf("%d\n",r);break;}
	}
	return 0;
}

Measured memory_bytes: 1736
N, A = map(int, input().split())
X = list(map(int, input().split()))
dp = []
for i in range(0, N+1):
	lst1 = []
	for j in range(0, N+1):
		lst2 = []
		for k in range(0, N*50+1):
			lst2.append(0)
		lst1.append(lst2)
	dp.append(lst1)
dp[0][0][0] = 1
for i in range(0, N):
	for j in range(0, N):
		for k in range(0, N*50):
			dp[i+1][j][k] += dp[i][j][k]
			if k+X[i] <= N*50:
				dp[i+1][j+1][k+X[i]] += dp[i][j][k]
ans = 0
for i in range(1, N+1):
	ans += dp[N][i][A*i]
print(ans)

Measured memory_bytes: 95452
// Problem : A - Air Conditioner
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define tos(x) string(1,x)
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testc   \
    int tcc;    \
    cin >> tcc; \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//#define int ll

signed main() {
	fast_io;
	int x; cin>>x;
	cout<<(x>=30?"Yes":"No");
}
// code!=think
// least efficient code to get ac


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

using namespace std;


int main(){
    int N,K;
    cin >> N >> K;
    string s;
    cin >> s;

    vector<int> Nums;
    int now = 1; //今見ている数
    int cnt = 0; //nowがいくつ並んでいるか
    for(int i = 0; i < N; i++){
        if(s[i] == (char)('0' + now)) cnt++;
        else{
            Nums.push_back(cnt);
            now = 1 - now; //0と1を切り替える時の計算
            cnt = 1;
        }
    }
    if(cnt != 0) Nums.push_back(cnt);

    //1-0-1-0-1-0って感じの配列が欲しい
    //1-0-1-0みたいに0で終わってたら、適当に１つ足す
    if(Nums.size() % 2 == 0) Nums.push_back(0);


    int Add = 2 * K + 1;

    int ans = 0;

    int left = 0;
    int right = 0; 
    int tmp = 0; //[left , ritht)のsum

    //1-0-1の1から始めるので、偶数番目だけ見る
    for(int i = 0; i < Nums.size(); i += 2){

        int Nextleft = i;
        int Nextright = min(i + Add, (int)Nums.size());
        //左端を移動する。
        while(Nextleft > left){
            tmp -= Nums[left];
            left++;
        }
        //右端を移動する
        while(Nextright > right){
            tmp += Nums[right];
            right++;
        }

        ans = max(tmp,ans);
    }



    cout << ans << endl;
}



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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n),b(n);
	rep(i,n) scanf("%d%d",&a[i],&b[i]);

	if(a==b){ puts("0"); return 0; }

	int pos=-1;
	rep(i,n) if(a[i]>b[i]) {
		if(pos==-1 || b[i]<b[pos]) pos=i;
	}

	lint ans=0;
	rep(i,n) ans+=a[i];
	ans-=b[pos];
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 384
// ConsoleApplication.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdio.h"
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

template<typename T>
void bubbleSort(vector<T>& ary, int& swapCount)
{
	swapCount = 0;
	bool existsInverseOrderElements = true;
	const int numberOfElements = ary.size();
	while (existsInverseOrderElements) {
		existsInverseOrderElements = false;
		for (int i = numberOfElements - 1; i != 0; --i) {
			T& front = ary.at(i - 1);
			T& back = ary.at(i);
			if (front > back) {
				swap(front, back);
				++swapCount;
				existsInverseOrderElements = true;
			}
		}
	}
}

template<typename T>
void selectionSort(vector<T>& ary, int& swapCount)
{
	swapCount = 0;
	const int numberOfElements = ary.size();
	for (int i = 0; i != numberOfElements - 1; ++i) {
		int minIndexJ = i;
		for (int j = i; j != numberOfElements; ++j) {
			if (ary.at(j) < ary.at(minIndexJ)) {
				minIndexJ = j;
			}
		}
		if (minIndexJ != i) {
			swap(ary.at(i), ary.at(minIndexJ));
			++swapCount;
		}
	}
}

struct Card
{
	//Card(const string& sign, const int number ):sign_(sign), number_(number){}
	bool operator<(const Card& rhs)const { return number_ < rhs.number_; }
	bool operator>(const Card& rhs)const { return number_ > rhs.number_; }
	bool operator==(const Card& rhs)const { return sign_ == rhs.sign_ && number_ == rhs.number_; }
	bool operator!=(const Card& rhs)const { return !(*this == rhs);}
	string getName()const { return sign_ + to_string(number_); }
	string sign_;
	int number_;
};

void outputCards(const vector<Card>& ary)
{
	const string values = accumulate(ary.begin() + 1, ary.end(), ary.front().getName()
		, [](const string& init, const Card& card) {return init + " " + card.getName(); });
	cout << values << endl;
}

auto& operator>>(istream& inputStream , Card& card)
{
	string input;
	inputStream >> input;
	card.sign_ = input.front();
	card.number_ = stoi(input.substr(1));
	return card;
}

int main()
{
	int n;
	cin >> n;
	vector<Card> aryBuble(n);
	
	for (auto& card : aryBuble) {
		cin >> card;
	}
	vector<Card> arySelection(aryBuble);

	int swapCount;
	bubbleSort(aryBuble, swapCount);
	selectionSort(arySelection, swapCount);

	const bool isSelectionStable = aryBuble == arySelection;//bubbleSortは安定なソートなので、これと比較してselectionSortが安定かどうか判断する

	outputCards(aryBuble);
	cout << "Stable" << endl;//bubbleSortは安定なソート
	outputCards(arySelection);
	cout << (isSelectionStable ? "Stable" : "Not stable") << endl;


	return 0;
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
long long dp[200005];
long long a[200005];
long long sum[200005];
int main()
{
	int n;
	scanf("%d", &n);
	scanf("%lld", &a[1]);
	sum[1] = a[1];
	for(int i = 2; i <= n; i++)
	{
		scanf("%lld", &a[i]);
		if(i & 1)
			sum[i] = sum[i - 2] + a[i];
	}
	dp[1] = 0;
	for(int i = 2; i <= n; i++)
	{
		if(i & 1)
			dp[i] = max(dp[i - 2] + a[i], dp[i - 1]);
		else
			dp[i] = max(sum[i - 1], dp[i - 2] + a[i]);
	}
	printf("%lld", dp[n]);
	return 0;
}

Measured memory_bytes: 8508
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
int e,y;
char g[4]={'M','T','S','H'};
int h[4]={1868,1912,1926,1989};
int main(){
cin>>e>>y;
int num=-1;
for(int i=0;i<3;i++){
	if(y-h[i+1]<0){
		num=i;
		break;
	}
}
if(num==-1)num=3;

if(e==0){
	cout<<g[num]<<y-h[num]+1<<endl;
}

else{
	cout<<h[e-1]+y-1<<endl;
}
	return 0;
}



Measured memory_bytes: 3108
k=int(input())
l=["1","2","3","4","5","6","7","8","9"]
for i in range(k):
    x=l[i]
    y=int(x[-1])
    if y==0:
        l.append(x+str(y))
        l.append(x+str(y+1))
    elif y==9:
        l.append(x+str(y-1))
        l.append(x+str(y))
    else:
        l.append(x+str(y-1))
        l.append(x+str(y))
        l.append(x+str(y+1))
print(l[k-1])

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



static const int N = 100;

int main()
{
	int n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> p[i - 1] >> p[i];
	}

	for (int i = 1; i <= n; i++) m[i][i] = 0;

	for (int l = 2; l <= n; l++)
	{
		for (int i = 1; i <= n - l + 1; i++)
		{
			int j = i + l - 1;
			m[i][j] = (1 << 21);
			for (int k = i; k <= j - 1; k++)
			{
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}

	cout << m[1][n] << endl;

    return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n,m) for(int i=(n);i<(m);i++)
#define REP_EQ(i,n,m) for(int i=(n);i<=(m);i++)
#define CNT(i,n) for(int i=(n);i>0;i--)
#define REP_two(i,n,m) for(int i=(n);i<(m);i+=2)
#define ll long long
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int MAX=1e9;
int MOD=1e9+7;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans,num0=0,num1=0;
  for(int i=0;i<n;i++){
    if(s[i]=='0')num0++;
    else if(s[i]=='1')num1++;
  }
  ans=min(num0,num1)*2;
  cout<<ans<<endl;
}


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

int main(){
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if((x-r)<0 || (x+r)>w || (y-r)<0 || (y+r)>h){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3112
import numpy as np
N = int(input())
A = list(map(int, input().split()))
a = np.array(A)
# l = int(((N*N)+1)/2)
b = []
for i in range(N):
    if i%2==0:
        b.append(1)
    else:
        b.append(-1)
c = np.dot(np.array(b),a)
x = [c]
for j in range(1,N):
    x_j = 2*a[j-1] - x[j-1]
    x.append(x_j)
ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Measured memory_bytes: 32572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

double CalcDis(pair<int,int> a,pair<int,int> b){
    double dist=sqrt(pow(a.first-b.first,2)+pow(a.second-b.second,2));
    return dist;
}

int main(){
    int N; cin>>N;
    vector<pair<int,int>> pos(N);
    rep(n,0,N){
        int x,y;
        cin>>x>>y;
        pos.at(n)=make_pair(x,y);
    }

    vector<int> town(N);
    int numComb=1;
    rep(n,0,N){
        town.at(n)=n;
        numComb*=n+1;
    }

    double ans=0;
    do{
        double dis=0;
        rep(n,0,N-1) dis+=CalcDis(pos.at(town.at(n)),pos.at(town.at(n+1)));
        ans+=dis;
    }while(next_permutation(ToEnd(town)));

    cout<<fixed<<setprecision(10)<<ans/numComb<<endl;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N, D;
int Grundy(vector<int> a) {
    int ans;
    rep(i, N) {
        a[i]--, a[i] = a[i] % (D + 1);
        if (i == 0)
            ans = a[i];
        else
            ans = ans ^ a[i];
    }
    return ans;
}

int main() {
    cin >> N >> D;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    if (Grundy(a) != 0)
        cout << "First" << endl;
    else
        cout << "Second" << endl;
    return 0;
}


Measured memory_bytes: 4932
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.141592653

int main() 
{
    FAST;
    long double r,c;
    cin>>r;
    c=PI*2.0*r;
    cout.precision(12);
    cout<<c;
    return 0;
}


Measured memory_bytes: 3780
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        var a = new int[101];
        string s;
        while ((s = Console.ReadLine()) != null)
        {
            a[int.Parse(s)]++;
        }
        var ans = a.Select((x, i) => (x == a.Max()) ? i : -1).Where(x => x != -1);
        foreach (var item in ans)
        {
            Console.WriteLine(item);
        }
    }
}


Measured memory_bytes: 16296
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

ll paupau(ll n){
	ll res = 1;
	for (ll i = 0; i < n; i++){
		res *= 2;
		res %= MOD;
	}
	return res;
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, a[100000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a+n);
	int b[100000] = {0};
	for (int i = 0; i < n; i++) {
		b[a[i]]++;
	}
	if(n % 2 != 0){
		bool yes = 1;
		for (int i = 0; i < n; i++) {
			if(i == 0 && b[i] != 1) yes = 0;
			if(i % 2 == 0 && i != 0 && b[i] != 2) yes = 0;
			if(i % 2 != 0 && b[i] > 0) yes = 0;
		}
		if(yes) cout << paupau((ll)(n/2)) << endl;
		else cout << 0 << endl;
	} else {
		bool yes = 1;
		for (int i = 0; i < n; i++) {
			if(i % 2 == 0 && b[i] > 0) yes = 0;
			if(i % 2 != 0 && b[i] != 2) yes = 0;
		}
		if(yes) cout << paupau((ll)(n/2)) << endl;
		else cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  string N;
  int cnt = 0;
  cin >> N;
  for (int i = 0; i < 4; ++i) {
    if (N[i] == '2') ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

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

    if(a == 0) cout << b/x + 1 << endl;
    else cout << b/x - (a-1) / x << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N=sc.nextInt();
    double M=sc.nextDouble();
    double As[]=new double[N];
    double sum=0;
    for(int i=0;i<N;i++){
      As[i]=sc.nextDouble();
      sum+=As[i];
    }

    boolean judge=false;
    for (int i = 0; i < As.length - 1; i++) {
        for (int j = As.length - 1; j > i; j--) {
            if (As[j - 1] < As[j]) {
                // 入れ替え
                double tmp = As[j - 1];
                As[j - 1] = As[j];
                As[j] = tmp;
            }
         }
    }
    int Msub=(int)M;
    double abc=sum/(4*M);
        if (As[Msub-1]>=abc) {
          judge=true;
        }


      if (judge) {
        System.out.println("Yes");
      }else{
       System.out.println("No");
      }
        }
      }


Measured memory_bytes: 25172
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 1e6 + 5;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,x,t;
    cin>>n>>x>>t;
    cout<<ll(1ll*((n+x-1)/x)*t)<<'\n';
    return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    for(int i = 0; i < n; i++)cin >> a[i].second >> a[i].first;
    sort(a.begin(), a.end());

    int cur = 0;
    for(int i = 0; i < n; i++) {
        cur += a[i].second;
        if(cur > a[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 4848
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int n;
V<int> a;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    set<int> seta;
    for (int state = 0; state < (1 << n); state++) {
        int tmp = 0;
        for (int i = 0; i < n; i++) {
            if ((state >> i) & 1) tmp += a[i];
        }
        seta.insert(tmp);
    }

    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        int m; cin >> m;
        if (seta.find(m) == seta.end()) cout << "no\n";
        else cout << "yes\n";
    }
    return 0;
}



Measured memory_bytes: 3168
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  double N, D;
  cin >> N >> D;

  int a = ceil(N / (2.0 * D + 1));

  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String N = in.next();
		if(N.length()==2) {
			System.out.println(N);
		}else {
			for(int i=0;i<3;i++) {
				System.out.print(N.charAt(2-i));
			}
		}

	}
}


Measured memory_bytes: 21204
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
    static final int MOD = (int)1e9 + 7;
    int N,M;
    public void solve() {
        N = nextInt();
        M = nextInt();


        if(Math.abs(N-M) >= 2){
            out.println(0);
            return;
        }

        long ans = 1;
        for(int i = N;i >= 1;i--){
            ans *= i;
            ans %=MOD;
        }

        for(int i = M;i >= 1;i--){
            ans *= i;
            ans %= MOD;
        }

        if(N % 2 == M % 2){
            ans *= 2;
            ans %= MOD;
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <algorithm>
#include <map>
#include <numeric>
#include <iomanip>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 100;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */

/* main */
int main() {

    list<int> L;
    int q; cin >> q;
    list<int>::iterator itr = L.end();
    while (q--) {

        int op; cin >> op;
        if (op == 2) {
            itr = L.erase(itr);
        }
        else {
            int x; cin >> x;
            if (op == 0) {
                itr = L.insert(itr, x);
                }
            else {
                if (x > 0)
                    while (x--) {
                        itr++;
                    }
                else 
                    while (x++) {
                        itr--;
                    }
            }
        }
    }
    for (auto l = L.begin(); l != L.end(); l++) 
        cout << *l << '\n';

}



Measured memory_bytes: 18628
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,k,sz[N],h[N],ans;
const int M=1000000007;
struct E{
	int l,to;
}e[N<<1];
void se(int x,int f){
	int s=(x==1)? k-1:k-2;
	for(int i=h[x];i;i=e[i].l){
		if(e[i].to==f)continue;
		ans=1ll*ans*s%M;
		se(e[i].to,x);
		s--;
	}
}
int main(){
	int x,y;
	scanf("%d %d",&n,&k);
	for(int i=1;i<n;++i){
		scanf("%d %d",&x,&y);
		e[i<<1].to=x;e[i<<1].l=h[y];h[y]=i<<1;
		e[i<<1|1].to=y;e[i<<1|1].l=h[x];h[x]=i<<1|1;
		sz[x]++;sz[y]++;
		sz[i+1]--;
	}
	ans=k;
	se(1,0);
	printf("%d",ans);
}

Measured memory_bytes: 6144
<?php

$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));

$sa = [];
for($i=0; $i<$n; $i++){
  $sa[$i] = $s[$i];
}

$ans = 0;
for($i=0; $i<=$n; $i++){
  $r = array_slice($sa,0,$i);
  $l = array_slice($sa,$i);
  $c = count(array_unique(array_intersect($r,$l)));
  if ($c > $ans) {
    $ans = $c;
  }
}
echo $ans;

?>

Measured memory_bytes: 4732
// AOJ GRL_3_C Connected Components - Strongly Connected Components
// 2018.4.26 bal4u

#include <stdio.h>
#include <malloc.h>
#include <string.h>

#define MAX_V 10002
int  V;    // 頂点数
int  *to[MAX_V], hi[MAX_V];
int  *r_to[MAX_V], r_hi[MAX_V];
int  vs[MAX_V], vsz;
char used[MAX_V];
int  cmp[MAX_V];    // 属する強連結成分のトポロジカル順序

void add_edge(int _from, int _to)
{
	to[_from][hi[_from]++] = _to;
	r_to[_to][r_hi[_to]++] = _from;
}

void dfs(int v)
{
	int i;
	used[v] = 1;
	for (i = 0; i < hi[v]; i++) {
		if (!used[to[v][i]]) dfs(to[v][i]);
	}
	vs[vsz++] = v;
}

void rdfs(int v, int k)
{
	int i;
	used[v] = 1;
	cmp[v] = k;
	for (i = 0; i < r_hi[v]; i++) {
		if (!used[r_to[v][i]]) rdfs(r_to[v][i], k);
	}
}

#if 0
void init(int n)
{
	V = n;
	memset(  lim, 0, V<<2), memset(  hi, 0, V<<2);
	memset(r_lim, 0, V<<2), memset(r_hi, 0, V<<2);
}
#endif

// 強連結成分への分解
int scc()
{
	int v, i, k;
	memset(used, 0, V);
	vsz = 0;
	for (v = 0; v < V; v++) if (!used[v]) dfs(v);
	memset(used, 0, V);
	k = 0;
	for (i = vsz-1; i >= 0; i--) {
		if (!used[vs[i]]) rdfs(vs[i], k++);
	}
	return k;		// 得られた強連結成分の数
}

// バッファを経ずstdinから数値を得る
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int main()
{
	int E, Q, s, t, i, j;
	int *memo;

	V = in(), E = in();
	memo = malloc(E<<3);
	j = 0; for (i = 0; i < E; i++) {
		memo[j++] = s = in(), memo[j++] = t = in();
		hi[s]++, r_hi[t]++;

	}
	for (i = 0; i < V; i++) {
		if (  hi[i])   to[i] = malloc(  hi[i]<<2);
		if (r_hi[i]) r_to[i] = malloc(r_hi[i]<<2);
	}
	memset(hi, 0, V<<2), memset(r_hi, 0, V<<2);

	j = 0; while (E--) {
		s = memo[j++], t = memo[j++];
		add_edge(s, t);
	}

	scc();

	Q = in();
	while (Q--) {
		s = in(), t = in();
		putchar('0'+ (cmp[s] == cmp[t]));
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
            sum += a[i];
        }
        int minVote = (int)Math.ceil(sum / 4.0 / m);
        int c = 0;
        for(int i=0; i<n; i++) {
            if(a[i]>=minVote) {
                c++;
            }
        }
        System.out.println(c>=m ? "Yes" : "No");
    }
}


Measured memory_bytes: 22868
#include<iostream>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  
  if (A <= 5) {
    cout << 0 << endl;
  }
  
  else if (A >= 6 && A <= 12) {
    cout << B/2 << endl;
  }
  
  else {
    cout << B <<endl;
  }

 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	ll a,b;
	cin>>a>>b;
	ll ans=(a*b)/__gcd(a,b);
	cout<<ans;
	re 0;
}

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

int main() {
    string X;
    cin >> X;
    int ans = X.length(), s_count = 0;
    for (int i = 0; i < X.length(); i++) {
        if (X[i] == 'S') s_count++;
        else if (X[i] == 'T' && s_count > 0) {
            ans -= 2;
            s_count--;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll dp[3030][6060];

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

    REP(i, 3030)REP(j, 6060) dp[i][j] = -1;
    dp[0][0] = 0;

    ll N, T;
    cin >> N >> T;
    vector<pll> C(N);
    vector<ll> A(N), B(N);
    REP(i, N) cin >> C[i].first >> C[i].second;
    sort(C.begin(), C.end());
    REP(i, N){
    	A[i] = C[i].first;
    	B[i] = C[i].second;
    }

    REP(i, N){
    	REP(j, T){
    		dp[i+1][j] = max(dp[i][j], dp[i+1][j]);
    		if(dp[i][j] != -1) dp[i+1][j+A[i]] = max(dp[i+1][j+A[i]], dp[i][j] + B[i]);
    	}
    }

    ll ma = 0;
    REP(i, 3030)REP(j, 6060) ma = max(ma, dp[i][j]);
    cout << ma << endl;

    /*
    REP(i, N){
    	REP(j, 2*T+1){
    		cout << dp[i][j] << " ";
    	}
    	cout << endl;
    }
    */
    return 0;
}

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

#define ll long long
#define db double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 303;
string s;
int n, k, dp[N][N][N];

int rec(int l, int r, int x) {
	if (x < 0) {
		return -N;
	}
	if (l > r) {
		return 0;
	}
	if (l == r) {
		return 1;
	}
	int & res = dp[l][r][x];
	if (res != -1) {
		return res;
	}
	res = 0;
	if (s[l] == s[r]) {
		res = rec(l + 1, r - 1, x) + 2;
	}
	res = max(res, rec(l + 1, r - 1, x - 1) + 2);
	res = max(res, rec(l + 1, r, x));
	res = max(res, rec(l, r - 1, x));
	return res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif

	cin >> s >> k;
	n = s.size();
	memset(& dp, -1, sizeof(dp));
	cout << rec(0, n - 1, k);
}


Measured memory_bytes: 108928
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt(), c = scanner.nextInt();
			int b[] = IntStream.range(0, m).map(i -> scanner.nextInt()).toArray();
			System.out.println(IntStream.range(0, n).filter(i -> {
				int sum = IntStream.range(0, m).map(j -> scanner.nextInt() * b[j]).sum();
				return (sum + c) > 0;
			}).count());
		}
	}
}


Measured memory_bytes: 37212
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String S = sc.next();

		sc.close();

		int ans = 0;

		for (int i = 0; i < S.length() / 2; i++) {
			if (S.charAt(i) != S.charAt(S.length() - i - 1)) {
				ans++;
			}
		}
		out.println(ans);

	}

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


Measured memory_bytes: 23764
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int K = sc.nextInt();
            int ans = 0;
            for(int i = 0; i < N; i++){
              int j = sc.nextInt();
              if(j >= K){
                ans++;
              }
            }
            System.out.println(ans);
          }
}

Measured memory_bytes: 45224
import math
import sys

A, B = map(int, input().split())

minx = max(10*B, math.floor(12.5*A))
maxx = min(10*(B+1)-1, math.floor(12.5*(A+1)-1))
for i in range(minx, maxx+1):
    if (A <= i*0.08 < A+1) and (B <= i*0.1 < B+1):
        print(i)
        sys.exit()

print(-1)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**7)

def solve(s):
    global ans
    h=0
    for i in ch[s]:
        h=max(h,solve(i)+1)
    if h==k-1 and a[s]!=0:
        ans+=1
        a[s]=0
        return -1
    return h

n,k=map(int,raw_input().split())
a=map(lambda x:int(x)-1,raw_input().split())
ans=0
ch=[[] for _ in xrange(n)]

if a[0]!=0:
    a[0]=0
    ans+=1

for i in xrange(1,n):
    ch[a[i]].append(i)

solve(0)
print(ans)

Measured memory_bytes: 153268
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n, p;
    cin >> n >> p;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(2, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] % 2 == 1) {
            dp[i + 1][0] = dp[i][0] + dp[i][1];
            dp[i + 1][1] = dp[i][1] + dp[i][0];
        } else {
            dp[i + 1][0] = dp[i][0] + dp[i][0];
            dp[i + 1][1] = dp[i][1] + dp[i][1];
        }
    }
    cout << dp[n][p] << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <stdio.h>
#include <queue>
#include <map>
#include <iostream>
using namespace std;

int main(){
    int N, a, b, node, next_node, K=0, i, cur;
    scanf("%d", &N);
    vector<vector <int> > G(N);
    vector<pair <int, int>> edge;
    queue<int> que;
    for(int i=1;i<N;i++){
        scanf("%d %d", &a, &b);
        a --; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        edge.emplace_back(a,b);
    }

    vector<int> used(N,0);
    vector<int> node_c(N,0);
    map<pair<int,int>, int> Ans;

    que.emplace(edge[0].first);
    used[edge[0].first] = 1;
    while(! que.empty()){
        node = que.front(); que.pop();
        if(K<(int)G[node].size()) K = G[node].size();
        cur = 1;
        // cout << "---------------" << node << "---------------" << endl;
        for(int next_node:G[node]){
            // next_node = G[node][i];
            // cout << "cur:" << cur << endl;
            if(used[next_node]) continue;
            if(cur == node_c[node]) cur++;
            // cout << "ok"<< endl;

            node_c[next_node] = Ans[make_pair(next_node, node)] = Ans[make_pair(node, next_node)] = cur++;
            used[next_node] = 1;
            que.emplace(next_node);
        }
    }

    printf("%d\n", K);
    for(auto nodes:edge){
        printf("%d\n", Ans[nodes]);
    }

    return 0;

}

Measured memory_bytes: 17012
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second > b.second; }

int main(){
        ll N, K;
        cin >> N >> K;
        vl A(N),F(N);
        rep(i, N) cin >> A[i];
        rep(i, N) cin >> F[i];
        sort(A.begin(), A.end());//消化コスト
        sort(F.rbegin(), F.rend());//食べにくさ
        //二部マッチング、食べにくい物を胃の強い奴に食わす
        ll left = -1, right = 1145141919810;
        while (right - left > 1)
        {
            ll mid = (left + right) / 2, res = 0;
            rep(i, N)if (A[i] * F[i] > mid) res += A[i] - mid / F[i]; //それぞれに必要な修行回数

            if (res <= K) right = mid;
            else left = mid;
        }
        cout << right << endl;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
#define double long double
using namespace std; const int N=400010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
struct Edge{ int x,y; }e[N];
signed main()
{
    int n=read(); int D=read();
    for(ri int i=1;i<=n;i++) e[i].x=read(), e[i].y=read();
    int res=0;
    for(ri int i=1;i<=n;i++)
    {
        int qwq=e[i].x*e[i].x+e[i].y*e[i].y;
        if(qwq<=D*D) res++;
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 6872
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string s, t[52];
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> s; t[i] = s[0];
			for (int j = 1; j < s.size(); j++) if (string("aeiou").find(s[j - 1]) != -1) t[i] += s[j];
			t[i] += string(50 - t[i].size(), '_');
		}
		int ret = -1;
		for (int i = 1; i <= 50; i++) {
			string g[50];
			for (int j = 0; j < n; j++) g[j] = t[j].substr(0, i);
			sort(g, g + n);
			bool flag = true;
			for (int j = 1; j < n; j++) if (g[j - 1] == g[j]) { flag = false; break; }
			if (flag) { ret = i; break; }
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 3252
N, M = map(int, input().split())
drink = [[int(i) for i in input().split()] for j in range(N)]
drink = sorted(drink)

ans = 0
for i in range(N):
    if drink[i][1] < M:
        ans += drink[i][0] * drink[i][1]
        M -= drink[i][1]
    else:
        ans += drink[i][0] * M
        print(ans)
        break

Measured memory_bytes: 22376
import sys
f = sys.stdin

while True:
    n = int(f.readline())
    if n == 0:
        break
    a_score,b_score = 0, 0
    for _ in range(n):
        a, b = map(int, f.readline().split())
        if a > b:
            a_score += a + b
        elif a < b:
            b_score += a + b
        else:
            a_score += a
            b_score += b
    print(a_score,b_score)

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

int main() {
	int N, K, a[1000];
	cin >> N >> K;
	for(int i = 0; i < N; i++)
	cin >> a[i];
	int n = N * sizeof(a[0]) / sizeof(a[0]); 
	sort(a, a + n);
	int sum = 0;
	for(int i = 0; i < K; i++)
	sum += a[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3572
//Doubly Linked List

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 20

typedef struct Node
{
  int key;
  struct Node *n,*p;
  
}Node;

Node *nil;

void initialize()
{
  nil = (Node *)malloc(sizeof(Node));
  nil -> n = nil;
  nil -> p = nil;
}

Node* search(int key)
{
  Node *now = nil->n;

  while(now != nil && now->key != key)
    {
      now = now->n;
    }
  return now;
}

void delete(Node *x)
{
  if(x == nil) return;
  x->p->n = x->n;
  x->n->p = x->p;
  free(x);
}

void deleteF()
{
  delete(nil -> n);
}

void deleteL()
{
  delete(nil -> p);
}

void deleteK(int key)
{
  delete(search(key));
}

void insert(int key)
{
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->n = nil-> n;
  nil->n->p = x;
  nil->n = x;
  x->p = nil;
}

void print()
{
  int imp = 0;
  Node *now = nil -> n;

  while(1)
    {
      if(now == nil) break;
      if(imp ++ > 0) printf(" ");
      printf("%d",now->key);
      now = now->n;
    }
  printf("\n");
}

int main()
{
  int i,n,key;
  int size = 0,a = 0, b = 0;
  char arr[N];

  //input & initialize data
  scanf("%d",&n);
  initialize();
  for(i = 0; i < n; i++)
    {
      scanf("%s%d",arr,&key);

      //work
      if(arr[0] == 'i')
	{
	  insert(key);
	  a++;
	  size++;
	}
      else if(arr[0] == 'd')
	{
	  if(strlen(arr) > 6)
	    {
	      if(arr[6] == 'F') deleteF();
	      else if(arr[6] == 'L') deleteL();
	    }else{
	    deleteK(key);
	    b++;
	  }
	  size--;
	}
    }

  //output data
  print();

  return 0;
  
}



Measured memory_bytes: 32984
S=input()
S_=S+"A"
K=int(input())
i=0
cnt=0
lst=[]
while i<len(S_)-1:
    if not S_[i] == S_[i+1]:
        cnt+=1
        lst.append(cnt)
        cnt=0
        i+=1
    else:
        i+=1
        cnt+=1
if len(lst)==1:#一種類の時
    print((lst[0]*K)//2)
elif S[0]!=S[-1]:
    ans=0
    for j in lst:
        ans+=j//2
    print(ans*K)
else:
    ans_1=0
    ans_2=0
    for k in range(len(lst)):
        ans_1+=lst[k]//2
    for k in range(len(lst)):
        if k==0:
            ans_2+=lst[k]//2
        elif k==len(lst)-1:
            ans_2+=lst[k]//2
            ans_2+=(lst[k]+lst[0])//2
        else:
            ans_2+=(lst[k]//2)*2
    print(ans_1+(ans_2-ans_1)*(K-1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

inline int xor128() {
    static int x = 123456789;
    static int y = 362436069;
    static int z = 521288629;
    static int w = 88675123;
    int t;
    t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}


const int D = 365;
const int M = 26;
vec<int> C(M);
vvec<int> S(D,vec<int>(M));

using arr = array<int,M>;

struct state{
    vec<int> res;
    int day;
    arr last;
    int score;
    state(){
        last = {};
        score = 0;
        day = 0;
    }
    void add(int type){
        day++;
        score += S[(int) res.size()][type];
        res.push_back(type);
        last[type] = day;
        for(int i=0;i<M;i++) if(i!=type) score -= C[i]*(day-last[i]);
    }

    bool operator<(const state& R)const{
        return score>R.score;
    }
};

const int width = 400;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d;
    cin >> d;
    for(auto& x:C) cin >> x;
    for(auto& v:S) for(auto& x:v) cin >> x;
    state init;
    vec<state> S;
    S.push_back(init);
    for(int d=0;d<D;d++){
        vec<state> neS;
        for(auto& now:S){
            for(int i=0;i<M;i++){
                state ne = now;
                ne.add(i);
                neS.push_back(ne);
            }
        }
        sort(neS.begin(),neS.end());
        if(neS.size()>width) neS.resize(width);
        S.swap(neS);
    }
    auto ans = S[0].res;
//    cerr << S[0].score << "\n";
    for(int i=0;i<D;i++) cout << ans[i]+1 << "\n";
}

Measured memory_bytes: 26524
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
gc032 B
"""


n = int(input())
es = []

if n % 2 == 1:
    for i in range(1, n):
        for j in range(i+1, n+1):
            if not (i+j == n):
                es.append((i, j))
else:
    for j in range(2,n):
        es.append((1,j))
    for i in range(2, n):
        for j in range(i+1, n+1):
            if not (i+j == n+1):
                es.append((i, j))

print(len(es))
for i, j in es:
    print(i, j)


Measured memory_bytes: 3956
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int X, Y, A, B, C;
	getint(X, Y);
	getint(A, B, C);

	std::vector<LLONG> pi(A);
	for (int i = 0; i < A; i++) {
		getint(pi[i]);
	}
	std::vector<LLONG> qi(B);
	for (int i = 0; i < B; i++) {
		getint(qi[i]);
	}
	std::vector<LLONG> ri(C);
	for (int i = 0; i < C; i++) {
		getint(ri[i]);
	}

	std::sort(pi.begin(), pi.end(), std::greater<LLONG>());
	std::sort(qi.begin(), qi.end(), std::greater<LLONG>());

	for (int i = 0; i < X; i++) {
		ri.push_back(pi[i]);
	}
	for (int i = 0; i < Y; i++) {
		ri.push_back(qi[i]);
	}
	std::sort(ri.begin(), ri.end(), std::greater<LLONG>());
	
	LLONG sum = 0;
	for (int i = 0; i < (X + Y); i++) {
		sum += ri[i];
	}
	printf("%lld\n", sum);
}


Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n,k;
  cin >> n >> k;
  vector<long> x(n);
  rep(i,n){
    cin >> x.at(i);
    if(x.at(i) == 0){
      i--;
      k--;
      n--;
    }
  }
  if(k==0){
    cout << "0" << endl;
    return 0;
  }
  long first;
  long last;
  long tmp;
  long mini = 1e9;
  for(int i=0;i<=n-k;i++){
    first = x.at(i);
    last = x.at(i+k-1);
    if(first > 0){
      tmp = last;
      mini = min(mini,tmp);
    }else if(last < 0){
      tmp = first * (-1);
      mini = min(mini,tmp);
    }else if(first < 0 && last > 0){
      tmp = 2*min(first*(-1),last) + max(first*(-1),last);
      mini = min(mini,tmp);
    }
  }
  cout << mini << endl;
}

Measured memory_bytes: 1024