akhauriyash/Code-Regression huggingface dataset:
def inpl(): return list(map(int, input().split()))

n,k = inpl()
A = inpl()

L = [0]*40

for i in range(n):
    for j in range(40):
        L[j] += (A[i] >> j)&1

default = [(n - L[i]) * (2**i) if (k>>i)&1 == 1 else L[i] * (2**i) for i in range(40)]
free = [max(L[i] * (2**i), (n-L[i]) * (2**i)) for i in range(40)]

ans = sum([k^A[i] for i in range(n)])
for i in range(40):
    if ( k >> i)&1 == 1:
        ans = max(ans, sum(free[:i]) + L[i]*(2**i) + sum(default[i+1:]))

print(ans)


Measured memory_bytes: 14984
/*
    ____       ____                 _
   |  _ \ _ __|  _ \  ___ _ __   __| |_ __ ___
   | | | | '__| | | |/ _ \ '_ \ / _` | '__/ _ \ 
   | |_| | |_ | |_| |  __/ | | | (_| | | | (_) |
   |____/|_(_)|____/ \___|_| |_|\__,_|_|  \___/
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define db1(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << '\n'
#define rep(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(x) scanf("%s", x)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(x) printf("%s\n", x)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define F first
#define S second
#define pb push_back
#define ll long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

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

int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N, OO = 1e9 + 7;
const ll LLOO = 1e18 + 7;
//=======================

vi g[N];
int a[N];

void solve()
{
    int n,x,t;
    si(n);
    si(x);
    si(t);
    n = ceil((double)n/x);
    n*=t;
    pi(n);
}

int main()
{
    // uncomment if file :
    // freopen("in","r",stdin);
    // freopen("out","w",stdout);
    int t = 1;
    // si(t); // uncomment if testcases
    while (t--)
        solve();
    return 0;
}

int mpow(int base, int exp)
{
    base %= mod;
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m)
{
    int u, v;
    while (m--)
    {
        scanf("%d %d", &u, &v);
        g[u - 1].pb(v - 1);
        g[v - 1].pb(u - 1);
    }
}

void dfs(int u, int par)
{
    for (int v : g[u])
    {
        if (v == par)
            continue;
        dfs(v, u);
    }
}


Measured memory_bytes: 10864
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=100005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int n,k;
int dp[N],ar[101];
int fun(int cu)
{
    if(dp[cu]!=0)
    return dp[cu];
    int ans=1;
    for(int i=0;i<n;i++)
    {
        if(cu<ar[i])
        break;
        ans=min(ans, fun(cu-ar[i]));
        if(ans==-1)
        break;
    }
    return dp[cu]=-1*ans;
}
int32_t main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
    cin>>ar[i];
    sort(ar, ar+n);
    int ans=fun(k);
    //rep(i,0,k+1)
    //cout<<dp[i]<<" ";
    if(ans==-1)
    cout<<"Second";
    else
    cout<<"First";
    return 0;
}

Measured memory_bytes: 4096
A, B, M = [int(x) for x in input().split()]
Aprices = [int(x) for x in input().split()]
Bprices = [int(x) for x in input().split()]
mins = min(Aprices) + min(Bprices)
for i in range(M):
    a, b, c = [int(x) for x in input().split()]
    current = Aprices[a -1] + Bprices[b - 1] - c
    mins = min(mins, current)

print(mins)

Measured memory_bytes: 18488
#include <stdio.h>
typedef unsigned long long ull;
int main(void)
{
  ull h,n;
  scanf("%lld %lld",&h,&n);
  if(h%n==0)
    printf("%lld\n",h/n);
  else
    printf("%lld\n",(h/n)+1);
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int n, w[110], P[110], res;
int main() {
	int i;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
	}
	for (i = 1; i < n; i++)if (w[i] == w[i + 1])P[i] = 1;
	for (i = 1; i < n; i++) {
		if (P[i]) {
			P[i] = P[i + 1] = 0;
			res++;
		}
	}
	printf("%d\n", res);
}

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

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

  for(int i=0; i<N; i++){
    vector<int> l(3);
    cin >> l[0] >> l[1] >> l[2];
    sort(l.begin(), l.end());

    if(l[2]*l[2] == (l[1]*l[1] + l[0]*l[0])){
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}


Measured memory_bytes: 3064
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x)&(-x)
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define maxd 1000000007
typedef long long ll;
const int N=100000;
const double pi=acos(-1.0);
int n,cnt1=0,cnt2=0;
char s[10010];

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int main()
{
	n=read();
	scanf("%s",s);
	rep(i,0,n-1)
	{
		if (s[i]=='R') cnt1++;else cnt2++;
	}
	if (cnt1>cnt2) cout << "Yes"; else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
	ll n;
	cin >> n;
	ll ans = (n-1)*(n)/2;
	cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


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

int main()
{
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  rep(i, N - 2)
  {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

auto divisor = [](i64 x){
 int sq = sqrt(x) + 1;
 vector<i64> ret;
 for(i64 i = 1; i < sq; ++i)
  if(!(x % i)){
      if(i != 1)
       ret.emplace_back(i);
   if(__int128_t(i) * i != x && x / i != 1)
    ret.emplace_back(x / i);
  }
 sort(ret.begin(), ret.end());
 return ret;
};


void solve(long long n){

    i64 ans = 0;

    auto n_div = divisor(n);
    auto m_div = divisor(n - 1);

    ans += m_div.size();

    for(auto& k : n_div){
        for(__int128 kp = k; kp <= n && n % kp == 0; kp *= k){
            if((n / kp) % k == 1){
                ++ans;
                break;
            }
        }
    }

    cout << ans << endl;
}


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


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

ll gcd(ll x, ll y){
  if(y == 0)return x;
  return gcd(y, x % y);
}


ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int n; cin >> n;
  ll ans = 1;
  for(int i = 0; i < n; ++i){
    ll x; cin >> x;
    ans = lcm(ans,x);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3608
c = [int(input()) for i in range(5)]
a = []
for i in range(5):
    a.append(c[i]%10)
ans = 0
for i in range(5):
    ans += (c[i]//10)*10
    if a[i] != 0:
        ans += 10
a = [i for i in a if i != 0]
if len(a)!=0:
    ans -= 10 
    ans += min(a)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define lol long long
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol n,p;
  cin >>n>>p;
  map<lol,lol> sum;
  lol ans=1;
  lol limit=p;
  for(lol i=2;i*i+5<=limit;i++){
    while(p%i==0){
      sum[i]++;
      p/=i;
    }
  }
  if(p!=1) sum[p]++;
  for(auto e:sum){
    ans*=pow(e.first,e.second/n);
  }
  cout <<ans<<'\n';
  return (0);
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong n,a[200100],count[200100]={},sum[200100]={},all=0;
    cin >> n;
    rep(i,n){
        cin >> a[i];
        count[a[i]]++;
    }
    
    for(llong i=2;i<200010;i++) sum[i] += sum[i-1] + i-1;
    
    for(llong i=1;i<=n;i++){
        all += sum[count[i]];
    }
    
    for(llong i=0;i<n;i++){
        llong ans;
        ans = all - count[a[i]]+1;
        cout << ans << endl;
    }
}

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

using namespace std;

#define ops cout<<"ops"<<endl;
#define freopens freopen("cowpatibility.in", "r", stdin);freopen("cowpatibility.out", "w", stdout);
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define DIM 100007
#define DIMM 50007
#define INF 10000000000000000007.0
#define X 31
#define eps 0.0000001
#define PI 3.14159265358979323846
#define MAX 25
#define MODULO (long long)1000000007

const long double gr=(1+sqrt(5))/2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;
typedef pair<ld,ld> pldld;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

ll n;
ll a,b,c;
ll da[DIM],db[DIM],dc[DIM];

int main()
{
    //ops;
    //freopens;
    fast;
    //ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4;

    cin>>n;
    for(int i=1;i<=n;i++){
     cin>>a>>b>>c;
     if(i==1){
      da[i]=a;
      db[i]=b;
      dc[i]=c;
     }
     else{
      da[i]=max(db[i-1],dc[i-1])+a;
      db[i]=max(da[i-1],dc[i-1])+b;
      dc[i]=max(da[i-1],db[i-1])+c;
     }
    }
    cout<<max({da[n],db[n],dc[n]})<<endl;
    return 0;
}


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

using namespace std;



int main(int argc, char* argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;

  int res = 0;
  for (int i = 1; i <= N; i += 2)
  {
    int divs = 0;
    for (int j = 1; j <= i; ++j) divs += (i%j == 0);
    if (divs == 8) ++res;
  }
  cout << res << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 100000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, i;
    ll no, cash;
    bool flag;
    cin >> n;
    int a[n + 5];
    for (i = 0; i < n; ++i) {
        cin >> a[i];
    }
    cash = 1000, no = 0;
    flag = false;
    for (i = 0; i < n - 1; ++i) {
        if (flag) {
            if (a[i] > a[i + 1]) {
                cash += no * a[i];
                no = 0;
                flag ^= 1;
            }
        } else {
            if (a[i] < a[i + 1]) {
                no = cash / a[i];
                cash -= no * a[i];
                flag ^= 1;
            }
        }
    }
    if (flag) {
        cash += no * a[i];
    }
    cout << cash;

    return 0;
}


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

#define MAX 100

int n;
int p[MAX + 1];
int m[MAX + 1][MAX + 1];

int main() {
	cin >> n;
	cin >> p[0];
	for (int i = 1; i < n; i++)
		cin >> p[i] >> p[i];
	cin >> p[n];
	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] = INT_MAX;
			for (int k = i; k < j; 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: 3140
# https://atcoder.jp/contests/abc112/tasks/abc112_b
n, t = [int(x) for x in input().split()]
r = []
s = []
for _ in range(n):
    r.append([int(x) for x in input().split()])
for i in r:
    if i[1] <= t:
        s.append(i[0])
print(min(s)) if len(s) > 0 else print("TLE")


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int time = scan.nextInt();
		int h = time / (60 * 60);
		time %= 60 * 60;
		int m = time / 60;
		int s = time % 60;
		System.out.println(h + ":" + m + ":" + s);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 26232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main (){
  Bint X,K,D;
  cin>>X>>K>>D;
  if((abs(X)-K*D)>D){
    cout<<abs(X)-K*D;
    return 0;
  }
  else{
    Bint kai,kaii,kaiii;
    kai=abs(X)/D;
    kaii=abs(X)-kai*D;
    kaiii=kaii-D;
    K=K-kai;
    if(K%2==0){
      cout<<abs(kaii);
    }
    else{
      cout<<abs(kaiii);
    }
  }
}

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

int main()
{
	long long N, A, B;
	cin >> N >> A >> B;

	long long d = abs( A - B );
	long long ans = d / 2;
	if( d % 2 ) {
		long long mi = min( A, B );
		long long ma = max( A, B );
		ans = min( ma - 1, N - mi );
		long long ans1 = min( mi - 1, N - ma ) + (d + 1) / 2;
		ans = min( ans, ans1 );
	}

	cout << ans << endl;
}


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

#define N 100

int main() {
  int i, j, n, u, k, v;
  int A[N+1][N+1];  

  cin >> n;
    
  
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      A[i][j] =  0;
    }
  }    

  
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    for (j = 0; j < k; j++) {
      cin >> v;
      A[u][v] = 1;
    }
  }

  
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (j > 1) cout << " ";
      cout << A[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define f(i,a,b) for(ll i=a;i<=b;++i)
#define mod 1000000007

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    ll x=n%10;
    for(ll y:{2,4,5,7,9})
    {
        if(y==x) {cout<<"hon"; return 0;}
    }
    for(ll y:{0,1,6,8})
    {
        if(y==x) {cout<<"pon"; return 0;}
    }
    cout<<"bon";
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin>>N;
    
    vector<int> a(100001,0),b(100001,0);
    for(int i=0;i<N;i++){
        int j;
        cin>>j;
        a[j]++;
    }
  
    int maxv=0;
    
    for(int i=1;i<100000;i++){
        b[i]=a[i-1]+a[i]+a[i+1];
        maxv=max(maxv,b[i]);
    }
    
    cout<<maxv<<endl;
}

Measured memory_bytes: 1024
from collections import namedtuple
from heapq import heappop, heappush
import sys

input = sys.stdin.readline


def solve():
    inf = 10 ** 14 + 10

    Edge = namedtuple('Edge', ('cost', 'to'))

    def dijkstra(s):
        used = [False] * n
        used[s] = True

        dist = [inf] * n
        dist[s] = 0

        h = []
        for e_ in e[s]:
            heappush(h, e_)

        while h:
            c, v = heappop(h)
            if used[v]:
                continue
            used[v] = True
            dist[v] = c
            for e_ in map(lambda x: (x.cost + dist[v], x.to), e[v]):
                heappush(h, e_)
        return dist

    n = int(input())
    e = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        e[a].append(Edge(cost=c, to=b))
        e[b].append(Edge(cost=c, to=a))

    q, v = map(int, input().split())
    v -= 1

    g = dijkstra(v)

    for _ in range(q):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        print(g[x] + g[y])


if __name__ == '__main__':
    solve()

# warshall_floyd
# n大で無理

# inf = 10 ** 14 + 10
#
# n = int(input())
# g = [[inf] * n for _ in range(n)]
# for i in range(n):
#     g[i][i] = 0
# for _ in range(n - 1):
#     a, b, c = map(int, input().split())
#     a -= 1
#     b -= 1
#     g[a][b] = c
#     g[b][a] = c
#
# for k in range(n):
#     for i in range(n):
#         for j in range(n):
#             g[i][j] = min(g[i][j], g[i][k] + g[k][j])
#
# q, v = map(int, input().split())
# v -= 1
# for _ in range(q):
#     x, y = map(int, input().split())
#     x -= 1
#     y -= 1
#     print(g[x][v] + g[v][y])
#


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


int main(){
    int N,d[100]={};
    cin >> N;
    for(int i=0; i < N; ++i) cin >> d[i];
    sort(d,d+N);
    int mochi = 0,result = 0;
    for(int i=0; i < N; ++i){
        if(mochi<d[i]){
            ++result;
            mochi = d[i];
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int a, b, q;
vector<int> s, t;

signed main() {

    cin >> a >> b >> q;
    s.resize(a+1), t.resize(b+1);
    for(int i = 0; i < a; i++) {
        cin >> s[i+1];
    }
    for(int i = 0; i < b; i++) {
        cin >> t[i+1];
    }
    s[0] = -LINF;
    t[0] = -LINF;
    s.bash(LINF);
    t.bash(LINF);

    int x;
    for(int i = 0; i < q; i++) {
        cin >> x;
        auto n = lower_bound(ALL(s), x)-1;
        auto m = lower_bound(ALL(t), x)-1;
        int ans = abs(min(*n, *m)-x);
        chmin(ans, abs((m[1] - x)*2 + x - *n));
        chmin(ans, abs((m[1] - x) + 2*(x - *n)));
        chmin(ans, abs((m[0] - x)*2 + (x - n[1])));
        chmin(ans, abs((m[0] - x) + 2*(x - n[1])));
        chmin(ans, abs(max(n[1], m[1]) - x));

        cout << ans << endl;
    }

  
    return 0;
}



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

int main() {
  int N,A,B;
  cin >> N >> A >> B;
  vector<int>P(N);
  for(int i=0;i<N;i++){
    cin >> P.at(i);
  }
 vector<int>count(3);
  for(int i=0;i<N;i++){
    if(P.at(i)<=A){
      count.at(0)++;
    }else if(P.at(i)<=B){
      count.at(1)++;
    }else{
      count.at(2)++;
    }
  }
  sort(count.begin(),count.end());
  cout << count.at(0) << endl;
  
}

Measured memory_bytes: 256
N = int(input())
 
H = list(map(int,input().split()))
 
flg = True
for i in range(1,N):
    if H[i] > H[i-1]:
        H[i] = H[i]-1
    if H[i-1] - H[i] > 0:
        flg = False
        break
 
if flg:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include <stdio.h>
#define N 100

int main()
{
  int n,p[N+1],m[N+1][N+1],i,j,k,l;
  scanf("%d",&n);
  for(i = 1;i < n+1;i++)
    scanf("%d %d",&p[i-1],&p[i]);

  for(i = 1;i < n+1;i++)
    m[i][i] = 0;
  for(l = 2;l < n+1;l++){
    for(i = 1;i < n-l+2;i++){
      j = i+l-1;
      m[i][j] = 100000;
      for(k = i;k < j;k++){
	if(m[i][j] >= m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
	  m[i][j] = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      }
    }
  }
  printf("%d\n",m[1][n]);
	
  return 0;
}



Measured memory_bytes: 2088
#include<bits/stdc++.h>
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    fr(i,0,n)
    cin>>a[i];
    sort(a,a+n);
    bool f=1;
    fr(i,0,n-1)
    if(a[i]==a[i+1])
    f=0;
    if(f)
    cout<<"YES";
    else
    cout<<"NO";
}


Measured memory_bytes: 1152
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int N;
	cin >> N;

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	auto it = lower_bound(A.begin(), A.end(), 2);
	A.erase(unique(it, A.end()), A.end());

	bool no = false;
	if (A.size() != N) no = true;

	vector<int> p(1000100);
	for (int i = 0; i < A.size(); i++) {
		p[A[i]] = 1;
	}
	for (int i = 2; i < 1000100; i++) {
		if (no) break;
		int cnt = 0;
		for (int j = 1; i * j < 1000100; j++) {
			if (p[i * j]) {
				DMP(i, i * j);
				if (cnt) no = true;
				cnt++;
			}
		}
	}

	int g = 0;
	for (int i = 0; i < A.size(); i++) {
		g = gcd(g, A[i]);
	}

	if (!no) {
		cout << "pairwise coprime" << "\n";
	}
	else if (g == 1) {
		cout << "setwise coprime" << "\n";
	}
	else {
		cout << "not coprime" << "\n";
	}

	return 0;
}


Measured memory_bytes: 11056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
const int maxn = 1e5 + 5;
string a;
ll cal (string a)
{
    ll all = 0 , now = 0;
    for (auto g : a){
        if (g == '+') {
            all += now;
            now = 0;
        }
        else {
            now = now * 10 + (g - '0');
        }
    }
    return all + now;
}
ll ans = 0;
void dfs (string now , int step)
{
    if (step < 0) {
   //     cout << now << endl;
        ans += cal (now);
        return ;
    }
    now = a[step] +  now;
    if (step != 0)
        dfs("+" + now , step - 1);
    dfs(now , step - 1);
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> a;
    dfs("" , a.size() - 1);
    cout << ans << endl;
    return 0;
}


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

int compare(const void *a, const void *b){
	int *A = (int *)a;
	int *B = (int *)b;
	if (*A > *B) return 1;
	if (*A < *B) return -1;
	return 0;
}

int main(){
	int N,i;
	scanf("%d",&N);
	int X[N],S[N];
	for(i=0;i<N;i++){
		scanf("%d",&X[i]);
		S[i]=X[i];
	}
	qsort(S,N,sizeof(int),compare);
	for(i=0;i<N;i++){
		int b;
		if(X[i]<=S[(N/2)-1])b=S[N/2];
		else b=S[(N/2)-1];
		printf("%d\n",b);
	}
	return 0;
}

Measured memory_bytes: 3692
// IN THE NAME OF ALLAH
// MOST GRACIOUS, MOST MERCIFUL
// We mere live in a simulation, a game
// and it's programmer is one and only Allah!

#include <bits/stdc++.h>
#define N 123456789
#define INF INFINITY
#define ll long long 
using namespace std;
 
vector<int>prme;
void SieveOfEratosthenes(int n){
	bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++){  
        if (prime[p] == true){ 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          prme.push_back(p);
} 

void solve()
{
	string s;
	cin>>s;
	if(s[s.length()-1]=='s'){
		s+="es";
	}else{
		s+="s";
	}
	cout<<s;
}
	

int main()
{
	//to make I/O faster
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	/*int t;cin>>t;
	while(t--)solve();*/
	solve();
}


Measured memory_bytes: 3608
N = int(input())
l = list(map(int, input().split()))

count = 0
Flag = True
while Flag:
    for i in range(N):
        #if each elem can divide with 2
        if l[i] % 2 == 0:
            l[i] = int(l[i] / 2)
        else:
            Flag = False

        # add count
        if i == N-1 and Flag == True:
            count+=1
        
print(count)

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main() {
	int loan = 100000;
	int n;

	cin >> n;
	while (n-- > 0) {
		// 一週間ごとにすること
		loan += loan / 20;					// 5%増（5% → 0.05 → 1/20）
		loan = (loan + 999) / 1000 * 1000;	// 1000円未満切り上げ（末尾３ケタが0円の時は切り上げない）
	}
	cout << loan << endl;

	return 0;
}

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

int main() {
    int D, G;
    cin >> D >> G;
    int p[D], c[D];
    for (int i = 0; i < D; ++i) cin >> p[i] >> c[i];

    int ans = 1000000000;
    for (int i = 0; i < (1 << D); ++i) {
        int cnt = 0, sum = 0, rest_max = -1;
        for (int j = 0; j < D; ++j) {
            if (i &(1 << j)) {
                sum += p[j] * (j + 1) * 100 + c[j];
                cnt += p[j];
            }
            else {
                rest_max = j;
            }
        }
        if (sum < G) {
            if (sum + p[rest_max] * (rest_max + 1) * 100 < G) continue;
            while (sum < G) {
                sum += (rest_max + 1) * 100;
                ++cnt;
            }
        }
        ans = min(ans, cnt);
    }

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

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		if(s.equals("Sunny")) {
			System.out.println("Cloudy");
		}
		
		if(s.equals("Cloudy")) {
			System.out.println("Rainy");
		}
		

		if(s.equals("Rainy")) {
			System.out.println("Sunny");
		}


		sc.close();
	}
}



Measured memory_bytes: 21844
#include<stdio.h>

int main(void)
{
	int H, W, i, j;

	while (1)
	{
		scanf("%d %d", &H, &W);
		if ((H == 0) && (W == 0)) break;
		for (i = 0; i < H; i++)
		{
			for (j = 0; j < W; j++)
			{
				if (i==0 || i==H-1 || j == 0 || j==W-1)
				{
					printf("#");
				}
				else
				{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2016
#include<stdio.h>
int main(void)
{
  int x,a,b,n,m;

  scanf("%d %d %d",&x,&a,&b);

  n=x-a;
  m=x-b;

  if(x-a<0){
    n=a-x;
  }
  if(x-b<0){
    m=b-x;
  }

  if(n<m){
    printf("A\n");
  } else {
    printf("B\n");
  }
  
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 11007;

ll n, k, p[N], c[N], sum[N];

int vis[N];

vector<ll>g[N];

ll tree[8 * N];

#define m (l + r) / 2
#define lson 2 * node
#define rson 2 * node + 1

void update(ll v, int pos, int l, int r, int node) {
    if (l == r) {
        tree[node] = v;
        return;
    }
    if (pos <= m) update(v, pos, l, m, lson);
    else update(v, pos, m + 1, r, rson);
    tree[node] = min(tree[lson], tree[rson]);

}


ll query(int ql, int qr, int l, int r, int node) {
    if (ql <= l && qr >= r) {
        return tree[node];
    }
    ll ans = LLONG_MAX;
    if (ql <= m) ans = min(ans, query(ql, qr, l, m, lson));
    if (qr > m) ans = min(ans, query(ql, qr, m + 1, r, rson));
    return ans;
}

ll work(int x, int cnt) {
    for (int i = 1; i <= x; i++) {
        update(sum[i], i, 1, x, 1);
    }
    ll mx1 = LLONG_MIN;
    for (int i = 1; i <= x; i++) {
        int l =max(1, i - cnt + 1);
        if (i - 1 >= l) {
             ll res = query(l, i - 1, 1, x, 1);
            mx1 = max(mx1, sum[i] - res);
        } 
        mx1 = max(mx1, sum[i] - sum[max(0, i - cnt)]);
        
    }
    return mx1;
}

void dfs(int id, int u) {
    vis[u] = 1;
    g[id].push_back(u);
    if (vis[p[u]] == 0) {
        dfs(id, p[u]);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    int top = 1;
    for (int i = 1; i <= n; i++) {
        if (vis[i] == 0) {
            dfs(top, i);
            top++;
        }
    }
    ll maxn = LLONG_MIN;
    for (int i = 1; i < top; i++) {
        ll cnt = 0;
        for (int j = 0; j < g[i].size(); j++) {
            cnt += c[g[i][j]];
            sum[j + 1] = c[g[i][j]];
        }
    
        int cn = (int)g[i].size();
        for (int j = 1; j <= cn; j++) {
            sum[j + cn] = sum[j];
        }
        for (int j = 1; j <= 2 * cn; j++) {
            sum[j] = sum[j - 1] + sum[j];
        }
        if (cnt > 0) {
            ll res = k / cn;
            ll cat = res * cnt;
            res = k % cn;
            ll ca = cat;
            if (res) {
                cat += work(2 * cn, res);
                maxn = max(maxn, cat);
            } 
            cat = ca;
            cat -= cnt;
            cat += work(2 * cn, cn);
            maxn= max(maxn, cat);
            
            
        } 
        if (k >= cn) {
            maxn = max(maxn, work(2 * cn, cn));
        } else {
            maxn = max(maxn, work(2 * cn, k));
        }

    }
    cout << maxn << endl;
}


/*9 7876
4 2 5 1 6 8 3 7 9 
-6557 -2648 -2420 25613 4314 25455 -6418 -2334 -763 */
/*

3 1670
1 3 2 
-10082 20147 -12332 
*/

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


using namespace std;

long long n, a[2001], x;

long long spells[2001]={0};

long long ans = (1LL << 60);
long long maxspells=0, totalspells = 0;



long long mmm[2001][2001];



// int min(int x, int y){
// 	if(x < y) return x;
// 	return y;
// }



long long compute(int y){
	long long ans = y*x;
	for(int i=1;i<=n;i++){
		if(i+y > n){
			ans += min(mmm[i][n], mmm[1][y-n+i]);
		} else {
			ans += mmm[i][i+y];
		}
	}
	return ans;
}





int main(){
	ios_base::sync_with_stdio(false);
  	cin >> n >> x;
  	for(int i=1 ;i <= n; i++) cin >> a[i];

  	for(int i=1;i<=n;i++){
  		mmm[i][i-1] = a[i];
  		for(int j=i;j<=n;j++){
  			mmm[i][j] = min(mmm[i][j-1], a[j]);
  		}
  	}


  	for(int i=0;i<n;i++){
  		ans = min(ans, compute(i));
  	}
  	cout << ans << endl;

	
	return 0;
}

Measured memory_bytes: 31104
def main():
    abc = [int(x) for x in input().split()]
    cnt = 0
    while True:
        abc.sort()
        if abc[0] == abc[1] == abc[2]:
            break
        if abc[1] == abc[2]:
            abc[0] += 2
        else:
            abc[0] += 1
            abc[1] += 1
        cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

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




namespace ConsoleApplication1 {

    class sqrr {
        public int id;
        public int x , y;
        public sqrr(int id, int x, int y) {
            this.id = id; this.x = x; this.y = y;
        }
        public sqrr createSq(int nexid, int dir) {
            int[] diffx = new int[4]{-1,0,1,0};
            int[] diffy = new int[4]{0,-1,0,1};
            int nexx = x + diffx[dir];
            int nexy = y + diffy[dir];
            return new sqrr(nexid, nexx, nexy);            
        }
    }

    class ClassMain {

      



        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = ints[0];
                int n = int.Parse(line);                
                if (n == 0) { break; }
                List<sqrr> sqlis  = new List<sqrr>();
                sqlis.Add(new sqrr(0,0,0));
                int maxX  = 0, maxY = 0, minX = 0, minY = 0;
                for (int i = 0; i < n-1; i++) {
                    int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    int id = ints[0]; int dir = ints[1];
                    sqrr nexsq = null;
                    foreach (sqrr ele in sqlis) {
                        if (ele.id == id) {
                            nexsq = ele.createSq(sqlis.Count, dir);
                            break;
                        }
                    }
                    //Console.WriteLine(nexsq.x+"-"+nexsq.y);
                    minX = Math.Min(minX, nexsq.x);
                    maxX = Math.Max(maxX, nexsq.x);
                    minY = Math.Min(minY, nexsq.y);
                    maxY = Math.Max(maxY, nexsq.y);
                    sqlis.Add(nexsq);
                }

                Console.WriteLine((maxX - minX + 1) +" "+(maxY - minY + 1));

                
                    
              //Console.WriteLine();
                    
                



            }
        }
    }
}

Measured memory_bytes: 20508
#!/usr/bin/env python3
#ABC123 D

X,Y,Z,K = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
A.reverse()
B = list(map(int,input().split()))
B.sort()
B.reverse()
C = list(map(int,input().split()))
C.sort()
C.reverse()
S = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1) <= K:
                S.append(A[i]+B[j]+C[k])
            else:
                break
S.sort()
S.reverse()
for i in range(K):
    print(S[i])

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

int px[90001], py[90001];
int dp[90001];
int main(){
  int h, w, d; cin >> h >> w >> d;
  for(int i=0;i<h;i++) for(int j=0;j<w;j++){
    int t; cin >> t; px[t] = i; py[t] = j;
  }

  for(int i=d+1;i<=h*w;i++){
     dp[i] = dp[i-d] + abs(px[i]-px[i-d]) + abs(py[i]-py[i-d]);
  }

  int q; cin >> q;
  for(int i=0; i<q; i++){
    int l, r; cin >> l >> r;
    cout << dp[r] - dp[l] << endl;
  }
  return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){


	int A, B, C; cin >> A >> B >> C;
	int K; cin >> K;

	int ans = 0;
	while(A >= B){
		B *= 2;
		ans++;
	}
	while(B >= C){
		C *= 2;
		ans++;
	}

	if(ans <= K) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;

}


Measured memory_bytes: 3632
void main() {
    long n = readln.chomp.to!long;
    long[] a = new long[5];
    foreach (i; 0 .. 5) {
        a[i] = readln.chomp.to!long;
    }
    long m = a.reduce!min;
    writeln((n + m - 1) / m + 4);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[400005];
int main()
{
	ll n,k;
	scanf("%lld%lld",&k,&n);
	for(ll i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		a[i+n]=a[i]+k;
	}
	ll mi=1000000000;
	for(ll i=0;i<n;i++)
	{
		ll c=min(a[i+n-1]-a[i],a[i+n]-a[i+1]);
		mi=min(mi,c);
	}
	printf("%lld",mi);
}

Measured memory_bytes: 3328
// Ver19.02
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int x, a, b;
  scanf("%d%d%d", &x, &a, &b);

  printf("%d\n", (x - a) % b);
  return 0;
}

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

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int c[n], a[n][m];
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++)  cin >> a[i][j];
    }
    int ret = 1<<30;
    for(int s = 1; s < 1<<n; s++){
        vector<int> tmp(m, 0);
        int score = 0;
        for(int i = 0; i < n; i++){
            if((s>>i&1) == 0) continue;
            score += c[i];
            for(int j = 0; j < m; j++)  tmp[j] += a[i][j];
        }
        bool ok = true;
        for(int j = 0; j < m; j++)  ok &= tmp[j] >= x;
        if(ok)  ret = min(ret, score);
    }
    cout << (ret==1<<30 ? -1 : ret) << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T> inline T sqr(T t) {return t*t;}
#define pb push_back
#define mp make_pair
#define endl "\n"

inline void files(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef _WIN32
        return;
    #endif // _WIN32
    //freopen("lca.in", "r", stdin);//freopen("output.out", "w", stdout);
}

int a, b, c, d;

int main(){
    files();
    cin >> a >> b >> c >> d;
    int nach = max(a, c);
    int fin = min(b, d);
    cout << max(0, fin-nach);
}


Measured memory_bytes: 256
//To include everything you need
#include <bits/stdc++.h>
using namespace std;
typedef std::vector<int>  vi;
typedef std::vector<std::pair<int,int> > vpi;
typedef std::vector<string>  vs;
typedef std::vector<char>  vc;


int main(){

    int n;
    cin>>n;
    int slimeCount = 0;
    char lastSlime = ' ';
    char currSlime = ' ';
    for(int i=0;i<n;i++){
        cin>>currSlime;
        if(currSlime != lastSlime){
            slimeCount++;
            lastSlime = currSlime;
        }
    }
    cout<<slimeCount;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = input()

a_cnt = 0
b_cnt = 0

for i in range(N):
    if S[i] == "a":
        if a_cnt + b_cnt < A + B:
            print("Yes")
            a_cnt += 1
        else:
            print("No")
    elif S[i] == "b":
        if a_cnt + b_cnt < A + B and b_cnt < B:
            print("Yes")
            b_cnt += 1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 76132
#include <iostream>
#include <iomanip>
#include <fstream>
#include <utility>
#include <queue>
#include <vector>
#include <array>
#include <stack>
#include <list>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define bs(n) (1ull<<(n))

constexpr ll inf = INT64_MAX / 4;

int main() {
	ll n, m, a[2000], b[2000], c[2000], d[1001], t;
	cin >> n >> m;
	rep(i, m)cin >> a[i] >> b[i] >> c[i];
	for (int i = 0; i < 1001; i++)d[i] = -inf;
	d[1] = 0;
	for (int i = 0; i <= 2*n; i++) {
		for (int j = 0; j < m; j++) {
			if (d[a[j]] != -inf && d[b[j]] < d[a[j]] + c[j]) {
				d[b[j]] = d[a[j]] + c[j];
			}
		}
		if (i == n - 1) t = d[n];
	}
	if (d[n] != t) cout << "inf";
	else cout << d[n];
	cout << endl;
}

Measured memory_bytes: 256
N = int(input())
List = [[] for _ in range(N)]
ans = [-1]*N
for i in range(N-1):
    a, b, c = map(int, input().split())
    List[a-1].append((b-1, c))
    List[b-1].append((a-1, c))
Q, K = map(int, input().split())
queue = [K-1]
ans[K-1] = 0
while queue:
    edge = queue.pop()
    for node in List[edge]:
        index, cost = node
        if ans[index]>0:
            continue
        ans[index] = ans[edge]+cost
        queue.append(index)
for i in range(Q):
    x, y = map(int, input().split())
    print(ans[x-1]+ans[y-1])

Measured memory_bytes: 80160
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c;
    
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if(b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if(b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if(c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    else
        cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int x;
    cin >> x;
    if(x>=30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,W;
  cin >> n >> W;
  ll w[n], v[n];
  ll dp[n+1][W+1];
  for(int i=0 ; i<n ; i++){
    cin >> w[i] >> v[i];
  }
  for(int i=0 ; i<=n ; i++){
    for(int j=0 ; j<=W ; j++){
      dp[i][j] = 0;
    }
  }
  for(int i=0 ; i<n ; i++){
    for(int j=0 ; j<=W ; j++){
      if(j >= w[i]){
        dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j]);
      }else{
        dp[i+1][j] = dp[i][j];
      }
    }
  }
  cout << dp[n][W] << endl;
  return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()

using namespace std;

void execute()
{
	char input;
	cin >> input;
	set<char> boin = {'a', 'i', 'u', 'e', 'o'};
	if (boin.count(input))
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,add=0,k,a,b;
    cin>>k>>a>>b;
    for(i=a;i<=b;i++)
    {
        if(i%k==0)
            add++;
    }

    if(add==0)
        cout<<"NG"<<endl;
    else
    cout<<"OK"<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<#x<<": "<<x<<endl;ll
#define Nmax 400005
#define OFF 100001
#define MOD 1000000007
using namespace std;

ll n, x;
vector<int> v[Nmax];

int dfs(int nod){
    int ans = 0, nr = 0;
    vector<int> L;
    for (auto it : v[nod]){
        L.push_back(dfs(it));
    }
    sort(L.begin(),L.end());
    while (!L.empty()){
        nr++;
        ans = max(ans, nr + L.back());
        L.pop_back();
    }
    return ans;
}

int main()
{
    cin >> n;
    for (int i=2;i<=n;i++){
        cin >> x;
        v[x].push_back(i);
    }

    cout << dfs(1) << '\n';

    return 0;
}


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

using namespace std;

int main()
{
	vector<pair<int, int> > v;
	int x, y;
	while(true)
	{
		scanf("%d %d", &x, &y);
		
		if(x == 0 && y == 0)
			break;
		if(x > y)
  			v.push_back(make_pair(y, x));
  		else
  			v.push_back(make_pair(x, y));
	}
	
	for(int i = 0; i < v.size(); i++)
		printf("%d %d\n", v[i].first, v[i].second);
	
	return 0;
}


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

const int MOD = 1e9+7;

int main(){

  int N, M; cin >> N >> M;
  vector<bool> step(N+1);
  for(int i=0; i<M; i++){
    int a; cin >> a;
    step.at(a) = true;
  }
  
  vector<long long int> dp(N+1);
  dp.at(0) = 1;
  
  for(int i=0; i<N; i++){
  
    for(int j=i+1; j<=i+2 && j<N+1; j++){
      
      if( !step.at(j) ){
        dp.at(j) += dp.at(i);
        dp.at(j) %= MOD;
      }
    
    }
  
  }
  
  cout << dp.at(N) << endl;
  
}

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

int main() {
    // 入力の受け取り
    int n;
    cin >> n;

    vector<int> values(n);
    for (int i=0; i<n; i++) {
        cin >> values.at(i);
    }
    sort(values.begin(), values.end());

    // 価値の小さな具材から順に鍋に入れていく
    // i番目に投入した具材の価値は 1/2^{n-k} 倍になる
    double final_value = values.at(0) / pow(2, n-1);
    for (int i=1; i<n; i++) {
        final_value += values.at(i) / pow(2, n-i);
    }

    cout << final_value << endl;

}

Measured memory_bytes: 384