akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{
    public static void Main()
    {
        String[] input = Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int K = int.Parse(input[1]);
        input = Console.ReadLine().Split();
        int[] p = new int[N];
        for (int i=0; i < N; i++) { p[i] = int.Parse(input[i]); }
        Array.Sort(p);
        long ans = 0;
        for(int i = 0; i < K; i++)
        {
            ans += p[i];
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27720
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
#include <set>

typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
//四方向への移動ベクトル
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

//入力
int H, W;
vector<string> field;

//探索
bool seen[510][510];	// seen[h][w] := マス(h,w)が検知済みかどうか

void dfs(int h, int w)
{
	seen[h][w] = true;

	//四方向を検索
	for (int dir = 0; dir < 4; dir++)
	{
		int nh = h + dx[dir];
		int nw = w + dy[dir];

		//場外アウトしたり、移動先が壁の場合はスルー
		if (nh < 0 || nh >= H || nw < 0 || nw <= W)continue;
		if (field[nh][nw] == '#')continue;

		//移動先が探索済みの場合
		if (seen[nh][nw])continue;

		//再帰的に探索
		dfs(nh, nw);
	}
}

/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}




int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/
/*
vector<bool> seen;
void dfs(const Graph & G, int v)
{
	seen[v] = true;	//v を訪問済みにする

	// vから行ける各頂点 next_vについて
	for (auto next_v : G[v])
	{
		if (seen[next_v])continue;	//next_vが探索済みだったらスルー
		dfs(G, next_v);//再帰的に探索
	}
}
*/
/*
 * 最大公約数計算
 */
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


void init(int n)
{
	for (int i = 0; i < n; i++) par[i] = i;
	for (int i = 0; i < n; i++) r[i] = 0;
}

int find(int x)
{
	if (par[x] == x)return x;
	else return find(par[x]);
}

void unite(int x, int y)
{
	x = find(x);
	y = find(y);

	if (r[x] < r[y])
	{
		par[x] = y;
	}
	else
	{
		par[y] = x;
		if (r[x] == r[y])
		{
			r[x]++;
		}
	}
}

bool same(int x, int y)
{
	return find(x) == find(y);
}

};

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

	int N, K;
	cin >> N >> K;
	int ans = 1;
	for (int i = 0; i < N; i++)
	{
		if (ans  < K)
		{
			ans *= 2;
		}
		else
		{
			ans += K;
		}

	}
	
	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N=3e3+100;
ll dp[N][N];
int32_t main(){
    ll n,t;
    cin >> n >> t;
    vector <pii> a;
    for (int i=0;i<n;i++){
        ll x,y;
        cin >> x >> y;
        a.pb({x,y});
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for (int i=1;i<=n;i++){
        for (int j=0;j<t;j++){
            dp[i][j]=dp[i-1][j];
            if (j+a[i-1].F>=t){
                dp[i][j]=max(dp[i][j],a[i-1].S);
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i-1][j+a[i-1].F]+a[i-1].S);
            }
        }
    }
    ll ma=0;
    for (int i=0;i<t;i++){
        ma=max(ma,dp[n][i]);
    }
    cout << ma;
}


Measured memory_bytes: 74112
#include<iostream>
#include<vector>
#include<cmath>
#include<stdio.h>
#include<string>
using namespace std;

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

    long long int cnt = 0;

    vector<long long int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
        if (i != 0) {
            if (a.at(i) < a.at(i - 1)) {
                cnt += a.at(i - 1) - a.at(i);
                a.at(i) = a.at(i-1);
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>s;

	fill(ara,ara+n_size,0);
	//mem(ara);

	f(i,0,strlen(s)-1){
        ara[s[i]]++;
	}

	f(i,0,300)
	{
	    if(ara[i]>1) {
            cout<<"no"<<endl,exit(0);
	    }

	}

    cout<<"yes"<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[2][10005];
//10000*10000だとMLEする.
//荷物のインデックスについては現在と直前だけ気にしていれば良い.
const int inf=1e9;
int main(void)
{
    int C,N,M;
    cin >> C >> N >>M;
    dp[0][0]=0;
    int s[N+5];
    int p[N+5];
    ll ans=0;
    for(int i=1;i<=N;i++)
    {
        cin >> s[i] >> p[i];
    }
    for(int i=0;i<2;i++)for(int j=0;j<=10000;j++)dp[i][j]=-inf;
    dp[0][0]=0;
    int nowindex;
    //1セットの荷物の組み合わせだけを調べておく
    for(int i=1;i<=N;i++)
    {
        nowindex=i%2;
        for(int j=0;j<=C;j++)
        {
            //i番目の荷物を持つ(dp[(i+1)%2][j]が-infでなく,容量オーバーしなければ)
            if(dp[(nowindex+1)%2][j]!=-inf && j+s[i]<=C) dp[nowindex][j+s[i]]=max(dp[nowindex][j+s[i]],dp[(nowindex+1)%2][j]+p[i]);
            //i番目の荷物を持たない
            dp[nowindex][j]=max(dp[(nowindex+1)%2][j],dp[nowindex][j]);
        }
    }
    int lastindex=nowindex;
    for(ll k=1;k<=M;k++)
    {
        ans=0;
        for(int i=0;i<=C;i++) 
        {
            //1セットの荷物について容量と最大価値の組み合わせを知っていて,i*kがCを超えていなければ,
            //k*dp[N][i]をするだけで,kセットの荷物で考えた時の最大価値が算出できる.
            if(i*k<=C) ans=max(ans,k*dp[lastindex][i]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3336
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int sum=0,a,b,c,p;
    cin>>a>>b>>c;
    p=(a+b+c)/2;

    sum=sqrt(p*(p-a)*(p-b)*(p-c));
    cout<<sum<<endl;



   return 0;

      }




Measured memory_bytes: 256
#include <stdio.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)

int main(){
	int d,c[27],s[366][27]={0},t[366],last[27]={0},sat=0;
	scanf("%d",&d);
	rep(i,26)scanf("%d",c+i+1);
	rep(i,d)rep(j,26)scanf("%d",&s[i+1][j+1]);
	rep(i,d)scanf("%d",t+i+1);
	rep(i,d){
		sat+=s[i+1][t[i+1]];
		last[t[i+1]]=i+1;
		rep(j,26)sat-=c[j+1]*(i+1-last[j+1]);
		printf("%d\n",sat);
	}
	return 0;
}

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

int main(){
  int n,p=1,w=1,g=1,y=1;
  char q;
  cin >> n;
  for(int j = 0 ; j < n ; j++ ){
    cin >> q;
    switch(q){
        case 'P':
        	p=0;
        	break;
        case 'W' :
        	w=0;
        	break;
        case 'G' :
        	g=0;
        	break;
        case 'Y' :
        	y=0;
        	break;
        default :
        	break;
    }
   }
  if( 4-w-p-g-y == 3 )
    {
  cout << "Three" ;
    }else{
    cout << "Four" ;
	
    }
  return 0;
 }


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const ll mod = 998244353;
inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
#define F(i,a,b)      for(int i= a; i <= b; i++)
#define R(i,b,a)      for(int i= b; i >= a; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
const ll base = modInverse(9);
int n;
#define lson id<<1
#define rson id << 1|1
struct SGMENT_TREE
{
	static const int N = 2e5 + 5;
	ll sg[N << 2] = {0}, lazy[N << 2] = {0};

	void init() {
		memset(sg, 0, sizeof sg);
		memset(lazy, -1, sizeof lazy);
	}

	void build(int id = 1, int l = 1, int r = n) {
		if (l == r) {sg[id] = 1; return;}
		int mid = (l + r) >> 1;
		build(lson, l, mid);
		build(rson, mid + 1, r);
		sg[id] = modAdd(sg[lson] * modPow(10, r - mid), sg[rson]);
	}

	void Shift(int id, int l, int r) {
		int L = (r - l + 1);
		if (lazy[id] != -1) {
			sg[id] = (((lazy[id] * (modPow(10, L) - 1)) % mod) * base) % mod;

			if (l != r) {
				lazy[lson] = lazy[id];
				lazy[rson] = lazy[id];
			}
			lazy[id] = -1ll;
		}
	}
	void update(int i, int j, ll v, int id = 1, int l = 1, int r = n) {
		Shift(id, l, r);
		if (l > j || r < i)return;
		if (i <= l && r <= j) {
			lazy[id] = v;
			Shift(id, l, r);
			return;
		}

		int m = (l + r) >> 1;
		update(i, j, v, lson, l, m);
		update(i, j, v, rson, m + 1, r);
		sg[id] = (sg[lson] * modPow(10, r - m) + sg[rson]) % mod;
	}
	ll Query(int i, int j, int id = 1, int l = 1, int r = n) {
		Shift(id, l, r);
		if (l > j || r < i)return 0;
		if (i <= l && r <= j) {
			return sg[id];
		}

		int m = (l + r) >> 1;
		ll P = Query(i, j, lson, l, m);
		ll Q = Query(i, j, rson, m + 1, r);
		return (P * modPow(10, r - m) + Q) % mod;
	}
} Ank;
int main()
{
	FASTIO
	int q;
	cin >> n >> q;
	Ank.init();
	Ank.build();
	while (q--) {
		int l, r, d;
		cin >> l >> r >> d;
		Ank.update(l, r, d);
		cout << Ank.Query(1, n) << "\n";
	}
	return 0;
}


Measured memory_bytes: 16136
#include<stdio.h>
int main(void){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %.5f\n",d,r,f);
return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

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



// Main Code
int main()
{
  int a, b;
  cin>>a>>b;
  if(!(a&1) | !(b&1)) puts("Even");
  else puts("Odd");
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    auto x = io.read_vec<int>(5);
    int ans = 0;
    for(int i = 0; i < 5; i++){
        if(x[i] == 0) ans = i;
    }
    cout << ans + 1;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
    string o,e;
    char s[200],a;
    int i,j,n,oddn,evenn,tot,k=0,q=0;
    cin>>o;
    cin>>e;
    oddn=o.size();
    evenn=e.size();
    tot=oddn+evenn;
    for(i=0;i<tot;i++)
    {
        if(i%2==0)
            s[i]=o[k++];
        else
            s[i]=e[q++];
    }

    for(i=0;i<tot;i++)
    {
        cout<<s[i];
    }

}


Measured memory_bytes: 256
#include <cstdio>

int main(){
    int h,w;
    scanf("%d %d",&h,&w);
    char a[h][w];
    bool b[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            scanf("\n%c",&a[i][j]);
            b[i][j] = true;
        }
    }

    int count_a_r;
    int count_b_r;
    for(int j = 0; j < h; j++){
        count_a_r = 0;
        count_b_r = 0;
        for(int k = 0; k < w; k++){
            if(b[j][k] == true){
                count_b_r++;
                if(a[j][k] == '.'){
                    count_a_r++;
                    continue;
                }else if(a[j][k] == '#'){
                    break;
                }
            }
        }
        if(count_a_r == count_b_r){
            for(int l = 0; l < w; l++){
                b[j][l] = false;
            }
        }
    }

    int W = w;
    int count_a_c;
    int count_b_c;
    for(int j = 0; j < w; j++){
        count_a_c = 0;
        count_b_c = 0;
        for(int k = 0; k < h; k++){
            if(b[k][j] == true){
                count_b_c++;
                if(a[k][j] == '.'){
                    count_a_c++;
                    continue;
                }else if(a[k][j] == '#'){
                    break;
                }
            }
        }
        if(count_a_c == count_b_c){
            for(int l = 0; l < h; l++){
                b[l][j] = false;
            }
            W--;
        }
    }

    int count_w = 0;
    for(int i = 0; i < h; i++){
        count_w = 0;
        for(int j = 0; j < w; j++){
            if(b[i][j]){
                printf("%c",a[i][j]);
                count_w++;
            }
            if(count_w == W){
                printf("\n");
                break;
            }
        }
    }

    return 0;
}

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

int main(){
  int a, b, c, flag = 0;
  cin >> a >> b >> c;
  for(int i = a; i <= b*a; i+=a){
    if(i % b == c){
      flag = 1;
      break;
    }
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
  ll s,w;
  cin>>s>>w;
  if(w>=s)
    cout<<"unsafe";
  else
    cout<<"safe";
  return 0;
}

Measured memory_bytes: 3652
from collections import deque
import bisect
N = int(input())
A = deque()
for _ in range(N):
    x = int(input())
    i = bisect.bisect_left(A,x)
    if i == 0:
        A.appendleft(x)
    else:
        A[i-1] = x

print(len(A))

Measured memory_bytes: 7284
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
int main(void)
{
	int n, a[100001], i, ans;
	double sum = 0, mini = 10000;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	sum /= n;
	//printf("%f\n", sum);
	for (i = 0; i < n; i++) {
		if (mini > fabs(sum - (double)(a[i]))) {
			mini = fabs(sum - (double)(a[i]));
			ans = i;
		}
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 128
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
	for (const auto &e : mp) os << "[" << e << "] ";
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int H, W;
	cin >> H >> W;

	vector<vector<char>> grid(H, vector<char>(W)), visited(H, vector<char>(W));
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> grid[i][j];

	queue<pair<pair<int,int>, int>> que;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (grid[i][j] == '#') {
				que.emplace(make_pair(i, j), 0);
			}
		}
	}

	auto inGrid = [&](int row, int col) {
		return 0 <= row && row < H && 0 <= col && col < W;
	};


	int ans = 0;
	while (!que.empty()) {

		auto now = que.front(); que.pop();

		vector<int> dr{ -1,1,0,0 }, dc{ 0,0,-1,1 };
		for (int i = 0; i < 4; i++) {
			int r = now.first.first + dr[i];
			int c = now.first.second + dc[i];

			if (inGrid(r, c) && grid[r][c] == '.') {
				grid[r][c] = '#';
				que.emplace(make_pair(r, c), now.second + 1);
				ans = max(ans, now.second + 1);
			}
		}
	}

	cout << ans << "\n";

	return 0;
}

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

int main() {
	int a, b, c;
	int i = 0;

	cin >> a>>b>>c;

	a -= b;
	
	while (i==0) {
		if (a >= c) {
			a -= c;
		}
		else {
			i = 1;
		}
		
	}

	cout << a << endl;
	

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;
LL A[100000];
LL sum[100000];
int main() {
	int N;
	cin >> N;
	rep(i, N) cin >> A[i];
	sort(A, A + N);
	rep(i, N) {
		sum[i] = A[i];
		if (i > 0) sum[i] += sum[i - 1];
	}
	int l = -1, r = N - 1;
	while (r - l > 1) {
		int m = (l + r) / 2;
		bool OK = 1;
		for (int i = m + 1; i < N; i++) {
			if (2 * sum[i - 1] < A[i]) {
				OK = 0;
				break;
			}
		}
		if (OK) r = m; else l = m;
	}
	cout << N - r << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include <math.h>
int main(void){
	int a,b,x[101],y[101],i,j,k,n;
	double p1,p2,p3,pu;
	scanf("%d%*c",&n );

	for(i=0;i<n;i++){
		scanf("%d",&x[i] );
	}
	scanf("%*c" );
	for(i=0;i<n;i++){
		scanf("%d",&y[i] );
	}
	for(i=0,p1=0,p2=0,p3=0,pu=0;i<n;i++){
		p1+=(double)abs(x[i]-y[i]);
		p2+=pow(x[i]-y[i],2);
		p3+=pow(abs(x[i]-y[i]),3);
		pu=fmax(pu,abs(x[i]-y[i]));
	}
	printf("%f\n%f\n%f\n%f\n",p1,sqrt(p2),pow(p3,1.0/3.0),pu);



	return 0;
}

Measured memory_bytes: 700
long n,a[3][1<<18],b,c,x,y,N[1<<18],M[1<<18],i,j;main(){scanf("%d",&n);for(i=0;i<3;++i)for(j=0;j<n;++j){scanf("%d",&a[i][j]);--a[i][j];}for(i=0;i<n;++i){if(a[0][i]/3!=a[1][i]/3||a[1][i]/3!=a[2][i]/3||a[2][i]/3!=a[0][i]/3||a[1][i]%3!=1||(a[1][i]/3-i)%2){puts("No");return 0;}x=a[1][i]/3+1;while(x){if(i&1)c-=M[x];else b-=N[x];x-=x&-x;}if(i&1)c+=i/2;else b+=i/2;y=a[2][i]/3+1;while (y<1<<18){if(i&1)++M[y];else ++N[y];y+=y&-y;}if(a[0][i]%3){if(i&1)++b;else++c;}}puts((b&1)||(c&1)?"No":"Yes");}

Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
  int main(){
  int N;
    cin >> N;
  int A;
  double B;
  double sum;
  double ans;
  sum = 0;
 for (int i = 0; i < N; i++) {
   cin >> A;
 B = (double)1/A;
 sum = sum + B;
 }
  ans= 1/sum;
  cout << ans << endl;
  }

Measured memory_bytes: 256
a,b,c = map(int, input().split())

import math
# if round(math.sqrt(a) + math.sqrt(b), 10) < round(math.sqrt(c), 10):
# if abs(math.sqrt(a) + math.sqrt(b) - math.sqrt(c)) < 1e-10:
if c - a - b > 0 and 4 * a * b < (c-a-b)*(c-a-b):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;

const long long MOD = 1000000007;

// Ref.[1] https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396 //
// Ref.[2] https://atcoder.jp/contests/abc120/submissions/4444370 //
class UnionFind {
    vector<int> par,sz;
  public:

    // Initialize. All vertices are roots when initial state.
    UnionFind(int N) : par(N),sz(N) {
      REP(n,N){
        par[n] = n;
        sz[n] = 1;
      }
    }

    // Return the root of tree which consists of vertex(x)
    int root(int x) {
      if (par[x] == x) return x;     // If x is the root, return x
      return par[x] = root(par[x]);  // Recursively find the root of tree. 
    }

    // Unite two vertices into one tree. 
    void unite(int x, int y) {
      int rx = root(x);       // root of x
      int ry = root(y);       // root of y
      if (rx == ry) return;   // do nothing if root of x is the same as root of y
      if(sz[rx] > sz[ry]){
        par[ry] = rx;
        sz[rx] += sz[ry];
      }else{
        par[rx] = ry;
        sz[ry] += sz[rx];
      }
    }

    // Return true if two vertices has the same root, else return false.
    bool same(int x, int y) { return root(x) == root(y); }

    // Return the number of vertices which are component of a tree
    int size(int x){ return sz[root(x)]; }
};

int main() {
  int N, M;
  cin >> N >> M;


  vector<int> A(M);
  vector<int> B(M);

  REP(m,M){
    int a, b;
    cin >> a >> b;
    A[m] = a-1, B[m] = b-1;
  }

  UnionFind tree(N);

  long long inconv = N*(long long)(N-1)/2;
  vector<long long> res;
  
  RREP(m,M){
    res.push_back(inconv);
    if (tree.same(A[m],B[m])) continue;

    inconv -= tree.size(A[m])*tree.size(B[m]);
    tree.unite(A[m],B[m]);

  }
  reverse(res.begin(),res.end());
  REP(m,M) cout << res.at(m) << endl;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    string S;
    cin >> S;
    int tmp;
    ll ans = 0;
    ll num = stoll(S);
    REP(i,1<<(S.size()-1)){
        tmp = 0;
        REP(j,S.size()){
            if((i>>j) %2 == 1 || j == S.size()-1){
                ans += num % ll(pow(10.0,double(j+1))) / ll(pow(10,tmp));
                tmp = j+1;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n;
	cin >> n;
	vector<int> x(n);
	int sum = 0;
	for(int i = 0; i < n; ++i)
	{
		cin >> x[i];
		sum += x[i];
	}
	int ave_dec = floor((double)sum / (double)n + 0.5);

	sum = 0;
	for(int i = 0; i < n; ++i)
	{
		sum += pow((x[i] - ave_dec), 2.0);
	}

	cout << sum;

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
n , k , q = map(int,input().split())
p = [0 for i in range(n)]
for i in range(q):
    a = int(input())
    p[a-1] += 1

for i in range(n):
    if k - q + p[i] <= 0:
        print("No")
    else:
        print("Yes")

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

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

int main() {
	string s; cin >> s;
	Loop(i, s.length() - 1) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}

Measured memory_bytes: 764
import sys

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

if a == 0:
    print(0)
    sys.exit()

amari = n % (a + b)
ao_count = n // (a + b)

if (amari >= 0) and (amari <= a):
    print(a * ao_count + amari)
else:
    print(a * (ao_count + 1))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); i++)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); i++)
#define FORR(i, a, b) for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))
#define ALL(v) (v).begin(), (v).end()

#ifdef HOGE
#define DEBUG(x) cerr << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                                                                                                   \
  cerr << #v << ": ";                                                                                                  \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", ";                                                                     \
  cerr << endl
#else
#define DEBUG_VEC(v)
#define DEBUG(x)
#endif

#define PRINT(x) cout << (x) << endl;
#define PRINT_ARR(arr)                                                                                                 \
  for (_loop_int i = 0; i < arr.size() - 1; i++)                                                                       \
    cout << arr[i] << " ";                                                                                             \
  cout << arr[arr.size() - 1] << endl;
#define IN(n) cin >> n;
#define EXTEND(base_arr, arr) base_arr.insert(base_arr.begin(), arr.begin(), arr.end());
#define APPEND(arr, item) arr.push_back(item);
#define APPEND_N(arr, item, n) arr.insert(arr.end(), (n), (item));

const ll MOD = 1000000007ll;

int main() {
  std::forward_list<std::string> list = {"apple", "banana", "cinnamon"};
  for (const auto &e : list | boost::adaptors::indexed()) {
    // std::cout << e.index() << ":" << e.value() << std::endl;
  }
  string s;
  IN(s)

  auto rcount = 0;
  auto lcount = 0;
  auto l = 'R';
  auto result = vl(0);
  // for (const auto &e : s) {
  //   std::cout << e << std::endl;
  // }
  REP(i, s.size()) {
    auto c = s[i];
    if (l == 'L' && c == 'R') {
      auto rr = (rcount + 1) / 2 + (lcount / 2);
      auto ll = rcount + lcount - rr;
      DEBUG_VEC(result);
      result.insert(result.end(), rcount - 1, 0);
      result.push_back(rr);
      result.push_back(ll);
      result.insert(result.end(), lcount - 1, 0);
      rcount = 0;
      lcount = 0;
    }
    if (c == 'R') {
      rcount += 1;
    }
    if (c == 'L') {
      lcount += 1;
    }
    l = c;
  }
  auto rr = (rcount + 1) / 2 + (lcount / 2);
  auto ll = rcount + lcount - rr;
  APPEND_N(result, 0, rcount - 1)
  result.push_back(rr);
  result.push_back(ll);
  APPEND_N(result, 0, lcount - 1)

  PRINT_ARR(result);
}


Measured memory_bytes: 2048
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 1e6 + 111;
        
using namespace std;          

int a, b, n;

void solve(){                       
	int q;

	string s, ss = "", tt = "";

	cin >> s >> q;

	while (q--){
		int type;

		cin >> type;
		
		if (type == 1)
			b++;
		else{
			char x;
			cin >> a >> x;
			if (a == 1){
				if (b % 2 == 0)
					ss += x;
				else
					tt += x;
			}
			else{
				if (b % 2 == 0)
					tt += x;
				else
					ss += x;
			}
		}
	}

	if (b % 2 == 1){
		swap(ss, tt);
		rev(all(s));
	}
	rev(all(ss));

	cout << ss << s << tt;
}                              
      
main(){
    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

Measured memory_bytes: 1040
# -*- Coding: utf-8 -*-

n = int(input())
A = []
A = [list(map(int,input().split())) for i in range(n-1)]
C = list(map(int,input().split()))

C2 = []
for i in range(n):
    C2.append([C[i],i])

C2.sort()

ans = sum(C)-C2[-1][0]

T = [[] for i in range(n)]
for i in range(len(A)):
    T[A[i][0]-1].append(A[i][1]-1)
    T[A[i][1]-1].append(A[i][0]-1)
#print(T)


E = [[0,i] for i in range(n)]
E[0][0]=1
# co = 0
# while co < n-1:
#     #print(co)
#     t = 0
#     while t < n+1 :
#         if len(T[t]) == 1:
#             E.append(t)
#             if co == n-2 :
#                 E.append(T[t][0])
#             T[T[t][0]].remove(t)
#             T[t] = []
#             co += 1
#         t += 1

holist=[0]
hot = 0

def ho(u):
    p = E[u][0]
    for j in range(len(T[u])):
        if E[T[u][j]][0] == 0:
            E[T[u][j]][0] = p+1
            holist.append(T[u][j])

while hot < len(holist):
    ho(holist[hot])
    hot += 1
#print(E)
E.sort(reverse=1)


#print(E)

D = [0 for i in range(n)]
for i in range(n):
    D[E[i][1]] = C2[i][0]

print(ans)
s = ""
for i in range(n):
    s += str(D[i])
    s += " "

print(s)


Measured memory_bytes: 10460
from sys import stdin
import numpy as np
 
N = int(input())
S = [input() for _ in range(N)]

cnt_innerAB = 0
cnt_endA_firstB = 0
cnt_endA = 0
cnt_firstB = 0

for i in range(N):
  cnt_innerAB += S[i].count('AB')
  if S[i][-1] == 'A' and S[i][0] == 'B':
    cnt_endA_firstB += 1
  if S[i][-1] == 'A' and S[i][0] != 'B':
    cnt_endA += 1
  if S[i][-1] != 'A' and S[i][0] == 'B':
    cnt_firstB += 1

if cnt_endA_firstB > 0 and cnt_endA == 0 and cnt_firstB == 0:
  cnt_sideAB = cnt_endA_firstB - 1
else:
  cnt_sideAB = min(min(cnt_endA, cnt_firstB) + cnt_endA_firstB, N-1)
ans = int(cnt_innerAB + cnt_sideAB)

print(ans)



Measured memory_bytes: 21584
n = int(input())
w = []
res = 'Yes'
prev = ''
# input
for i in range(n):
    w.append(input())
# 複数回発言をチェック
for word in w:
    if w.count(word) > 1:
        res = 'No'
        break
# w[i]の末尾とw[i+1]の先頭が同じならNo
for i in range(n):
    if i == 0:
        prev = w[i]
    else:  # i > 0
        if prev[-1] != w[i][0]:
            res = 'No'
            break
        prev = w[i]
print(res)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
   

  int main(){      
        lint n,k;
        cin >>n>>k; vector<lint> a(n);
        rep(i,n)cin >> a[i];
        lint b[n+1];
        lint c[n+1];
        b[0]=0;
        c[0]=0;
        rep(i,n){
            b[i+1]=a[i]+b[i];
            b[i+1]%=k;
            lint x=b[i+1]-(i+1)%k;
            x+=k;
            x%=k;
            c[i+1]=x;
            
          //  cout<<x<<endl;
        }
        lint ans=0;
        map<lint,lint> mp;
        lint g=min(k,n+1);
        rep(i,g){
            mp[c[i]]++;
        }
        for(auto x:mp){
            ans+=x.second*(x.second-1)/2;
        }
        rep(i,n+1-g){
            mp[c[i]]--;
            mp[c[i+g]]++;
            ans+=mp[c[i+g]]-1;
        }
       cout<<ans<<endl;
  }
          
  

Measured memory_bytes: 17408
n = int(input())

l = [0 for i in range(n)]

for i in range(n):
  l[i] = int(input())

min = l[0]
max = l[1]-l[0]

for j in range(1,n):
  sa = l[j]-min
  if max < sa:
    max = sa
  if l[j] < min:
    min = l[j]


print(max)


Measured memory_bytes: 13608
function Main(input) {
	input = input.split("\n");
var N=parseInt(input[0].split(" ")[0],10);
var M=parseInt(input[0].split(" ")[1],10);
var X=parseInt(input[0].split(" ")[2],10);
var Y=parseInt(input[0].split(" ")[3],10);

var maxx; var miny;
for(var i=0;i<N;i++){
 if(i==0){
  maxx=parseInt(input[1].split(" ")[i],10);
 }else{
   if(parseInt(input[1].split(" ")[i],10) > maxx){ maxx = parseInt(input[1].split(" ")[i],10); }
 }
}

for(var i=0;i<M;i++){
 if(i==0){
  miny=parseInt(input[2].split(" ")[i],10);
 }else{
   if(parseInt(input[2].split(" ")[i],10) < miny){ miny = parseInt(input[2].split(" ")[i],10); }
 }
}

if(X<Y && maxx<miny && X<miny && maxx<Y){
 console.log('No War');
}else{
 console.log('War');
}

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
long long i,j,n,m,a,b,c[12],x,k,y[12][12],skill[12],mp=10000000000;
bool res[12],fin;
int main(){
  for(cin>>n>>m>>x;i<n;i++){
    cin>>c[i];
    for(j=0;j<m;j++)cin>>y[i][j];
  }
  
  for (int bit = 0; bit < (1<<n); ++bit) {
    for(i=0;i<n;i++)res[i]=false;
    for(i=0;i<m;i++)skill[i]=0;
    for(i=0;i<n;i++)if(bit&(1<<i))res[i]=true;
    fin=true;
    long long price=0;
    for(i=0;i<n;i++){
      if(res[i]){
        for(j=0;j<m;j++)skill[j]+=y[i][j];
        price+=c[i];
      }
    }
    for(i=0;i<m;i++){
      if(skill[i]<x){
        fin=false;
        break;
      }
    }
    if(fin){
      a++;
      mp=min(mp,price);
    }
  }
  cout<<(a==0?-1:mp);
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int main(){
    int n,max_num = -1000001,min_num = 1000001,tmp;
    long long int sum = 0;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d",&tmp);
        sum += tmp;
        max_num = max(max_num,tmp);
        min_num = min(min_num,tmp);
    }
    printf("%d %d %lld\n",min_num,max_num,sum);
}


Measured memory_bytes: 2748
import java.util.Arrays;
import java.util.Scanner;

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

	void run() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] graph = new int[n + 1][n + 1];
		for (int i = 0; i <= n; i++) {
			Arrays.fill(graph[i], M);
		}
		for (int i = 0; i < m; i++) {
			String[] input = sc.next().split(",");
			int s = Integer.valueOf(input[0]);
			int t = Integer.valueOf(input[1]);
			graph[s][t] = Integer.valueOf(input[2]);
			graph[t][s] = Integer.valueOf(input[3]);
		}
		String[] input = sc.next().split(",");
		int[] go = { Integer.valueOf(input[0]), Integer.valueOf(input[1]) };
		int get = Integer.valueOf(input[2]) - Integer.valueOf(input[3]);
		for (int I = 0; I < 2; I++) {
			int start = go[I];
			int goal = go[I ^ 1];
			int[] len = new int[n + 1];
			boolean[] v = new boolean[n + 1];
			for (int i = 0; i <= n; i++) {
				len[i] = M;
			}
			len[start] = 0;
			for (int i = 0; i <= n; i++) {
				int min = M;
				int p = 0;
				for (int j = 0; j <= n; j++) {
					if (!v[j] && len[j] < min) {
						p = j;
						min = len[j];
					}
				}
				v[p] = true;
				for (int j = 0; j <= n; j++) {
					if (len[p] + graph[p][j] < len[j]) {
						len[j] = len[p] + graph[p][j];
					}
				}
			}
			get -= len[goal];
		}
		System.out.println(get);
	}

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

Measured memory_bytes: 17200
s = gets.rstrip.chars.map(&:to_i)
k = gets.to_i
n = s.size

dp = Array.new(n + 1) { Array.new(2) { Array.new(4, 0)}}

dp[0][0][0] = 1

0.upto(n-1) do |i|
  2.times do |smaller|
    4.times do |count|
      (smaller == 1 ? 10 : s[i] + 1).times do |x|
        snext = (smaller == 1 || x < s[i] ? 1 : 0)
        cnext = x > 0 ? count + 1 : count
        if cnext < 4
          dp[i + 1][snext][cnext] += dp[i][smaller][count]
        end
      end
    end
  end
end

p dp[n][0][k] + dp[n][1][k]


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 100000000
#define MAX 100001
#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(int, n, a, b);
    if(abs(a - b) == 1 && a == 1){
        OUTL("Borys"); RET;
    }

    if(abs(a - b)%2) {
        OUTL("Borys");
    }else{
        OUTL("Alice");
    }
RET;}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n, a, i, min, max;
    long long int s = 0;
    min = 1000000;
    max = -1000000;
    scanf("%d",&n);
    for(i=0; i<n; i++){
    	scanf("%d",&a);
    	s += a;
       	if(a<min){
       		min=a;
       	}
       	if(a>max){
       		max=a;
       	}
   }
	printf("%d %d %lld\n",min, max, s);
	return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(ll n,ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// a^n mod を計算する
ll modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];
int n, m, q;
vector<int>a, b, c, d;
int ans = 0;

void dfs(vector<int>s) {
	if (s.size() == n+1) {
		int now = 0;
		rep(i, q) {
			if (s[b[i]] - s[a[i]] == c[i])now += d[i];
		}
		ans = max(ans, now);
		return;
	}
	s.push_back(s.back());
	while (s.back() <= m) {
		dfs(s);
		s.back()++;
	}
}

//long longしか使わない
//素数は1より大きい
int main() {
	cin >> n >> m >> q;
	a = b = c = d = vector<int>(q);
	rep(i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	dfs(vector<int>(1, 1));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	int i = N - 1;
	ll h = -1, w = -1;
	while (i > 0) {
		if (A[i] == A[i - 1]) {
			if (h == -1) h = A[i];
			else {
				w = A[i];
				break;
			}
			i -= 2;
		}
		else {
			i--;
		}
	}
	if (h == -1 || w == -1) {
		cout << 0 << endl;
	}
	else {
		cout << h * w << endl;
	}
 }

Measured memory_bytes: 1024
#include <iostream>
#include<math.h>
using namespace std;

int main()
{
   int x=0,y=0,a=0;
   for (a=1;;a++){
        cin >> x;
        cin >> y;
        if ((x == 0)&&(y==0))break;
        if (x<=y){
            cout << x << " " << y << endl;
        }
        else{
            cout << y << " " << x << endl;
        }
   }

}

Measured memory_bytes: 1160