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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)


int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n,k;
        cin>>n>>k;
        ll r,s,p;
        cin>>r>>s>>p;
        string a,b="";
        cin>>a;
        loop(i,0,n-1)
        {
            if(a[i]=='s') b+='r';
            else if(a[i]=='p') b+='s';
            else b+='p';
        }
        ll ans=0;
        loop(i,0,k-1)
        {
            if(b[i]=='s') ans+=s;
            else if(b[i]=='r') ans+=r;
            else ans+=p;
        }
        loop(i,k,n-1)
        {
            if( b[i]!=b[i-k])
            {
                if(b[i]=='s') ans+=s;
                else if(b[i]=='r') ans+=r;
                else ans+=p;
            }
            else b[i]='a';
        }
        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 3784
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n, k = LI()
    h = LI()
    h.sort(reverse=True)
    print(sum(h[k:]))
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 80716
N=int(input())
xyh=[list(map(int,input().split())) for _ in range(N)]

for Cx in range(101):        # x
    for Cy in range(101):    # y
        flg=True
        k=0
        while xyh[k][2]+abs(xyh[k][0]-Cx)+abs(xyh[k][1]-Cy) <1 or xyh[k][2]<1:
            k+=1
        H=xyh[k][2]+abs(xyh[k][0]-Cx)+abs(xyh[k][1]-Cy)
        for i in range(len(xyh)):
            if max(H-abs(xyh[i][0]-Cx)-abs(xyh[i][1]-Cy),0)!=xyh[i][2]:
                flg=False
        if flg:
            print(Cx,Cy,H)
            exit()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

ll le[100001];
ll lex[100001];
ll ri[100001];
ll rix[100001];

int main(){
	ll n;
	cin >> n;
	vector<ll> p(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	for (int i = 0; i <= 100000; i++){
		le[i] = -1;
		lex[i] = -1;
		ri[i] = -1;
		rix[i] = -1;
	}

	priority_queue<pai, vector<pai>, greater<pai> > pq1, pq2;
	priority_queue<pai, vector<pai>, greater<pai> > pq3, pq4;

	for (int i = 0; i < n; i++){
		pq1.push(make_pair(p[i], i));
		int temp = p[i];
		while (!pq3.empty() && pq3.top().first < temp){
			auto p = pq3.top();
			pq3.pop();
			rix[p.second] = i-1;
 		}
		while (pq1.top().first < temp){
			auto p = pq1.top();
			pq1.pop();
			ri[p.second] = i;
			pq3.push(p);
		}
	}
	while(!pq3.empty()){
		auto p = pq3.top();
		pq3.pop();
		rix[p.second] = n-1;
	}
	for (int i = n-1; i >= 0; i--){
		pq2.push(make_pair(p[i], i));
		int temp = p[i];
		while (!pq4.empty() && pq4.top().first < temp){
			auto p = pq4.top();
			pq4.pop();
			lex[p.second] = i+1;
		}
		while (pq2.top().first < temp){
			auto p = pq2.top();
			pq2.pop();
			le[p.second] = i;
			pq4.push(p);
		}
	}
	while(!pq4.empty()){
		auto p = pq4.top();
		pq4.pop();
		lex[p.second] = 0;
	}

	ll ans = 0;

	for (ll i = 0; i < n; i++){
		if (ri[i] != -1 && le[i] != -1){
			ans += p[i]*(rix[i]-ri[i]+1)*(i-le[i]);
			ans += p[i]*(le[i]-lex[i]+1)*(ri[i]-i);
		}else if (ri[i] != -1){
			ans += p[i]*(rix[i]-ri[i]+1)*(i+1);
		}else if (le[i] != -1){
			ans += p[i]*(le[i]-lex[i]+1)*(n-i);
		}
	}
	cout << ans << endl;
	return 0;
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int INF = -1e9-100;

signed main(){
  int N, K; cin >> N >> K;
  vector<int> A(N);
  int ans = INF;
  for(int i = 0; i < N; i++) cin >> A[i];
  for(int a = 0; a <= K; a++){
    for(int b = 0; b <= K; b++){
      if(a + b > min(N, K)) continue;
      vector<int> data;
      int ans1 = 0;
      for(int i = 0; i < a; i++) ans1 += A[i], data.push_back(A[i]);
      for(int i = N - 1; i > N - 1 - b; i--) ans1 += A[i], data.push_back(A[i]);
      sort(data.begin(), data.end());
      for(int i = 0; i < min(K - a - b, int(data.size())); i++) if(data[i] < 0) ans1 -= data[i];
      ans = max(ans, ans1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

string s;
string t;

void input() {
  cin >> s >> t;
}

void solve() {
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());

  string ans = "No";

  if (s < t)
    ans = "Yes";

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 5;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

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

const int MOD = 1e9+7;
const int INF = 1e9+7;

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

	int n; cin >> n;
	vector<vector<double>> dp(n+1, vector<double> (n+1, 0.0));
	vector<double> v(n);
	for(auto& p: v) cin >> p;

	dp[0][1] = 1-v[0]; dp[1][1] = v[0];

	for(int i = 2; i <= n; i++)
		dp[0][i] = (1-v[i-1])*dp[0][i-1];

	for(int i = 1; i <= n; i++){
		for(int j = i; j <= n; j++){
			if(i == 1 && j == 1) continue;
			dp[i][j] = dp[i-1][j-1]*(v[j-1]) + dp[i][j-1]*(1-v[j-1]);
		}
	}

	double ans = 0.0;
	for(int i = n/2+1; i <= n; i++){
		ans+=dp[i][n];
	}

	cout << setprecision(10) << fixed << ans << '\n';

	return 0;
}

Measured memory_bytes: 70656
#include<iostream>                                                 
#include<vector>                                                   
using namespace std;                                               
                                                                   
int main(void) {                                                   
  while (true) {                                                   
    int m, n_min, n_max;                                           
    cin >> m >> n_min >> n_max;                                    
    if (m==0) {                                                    
      break;                                                       
    }                                                              
    vector<int> P;                                                 
    for (int i=0; i<m; i++) {                                      
      int x;                                                       
      cin >> x;                                                    
      P.push_back(x);                                              
    }                                                              
    int gap=0;                                                     
    int gapi=0;                                                    
    for (int i=n_min-1; i<n_max; i++) {                            
      if (P[i]-P[i+1]>=gap) {                                      
        gap = P[i]-P[i+1];                                         
        gapi = i+1;                                                
      }                                                            
    }                                                              
    cout << gapi << endl;                                          
  }                                                                
  return 0;                                                        
}                             

Measured memory_bytes: 3096
num = [[[0 for i in range(10)] for i in range(3)] for i in range(4)]

n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    num[b-1][f-1][r-1] += v

for b in range(4):
    for f in range(3):
        print(" " + " ".join(map(str, num[b][f])))
    if b < 3:
        print("#"*20)


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

int main() {
	int n;
	while(cin >> n && n){
		string s;
		int prev = 0; /* 0: 地面に両足, 1: 踏み台の上に両足 */
		int ans = 0, nl = 0, nr = 0;
		for(int i = 0; i < n; ++i){
			cin >> s;
			if(s == "lu"){
				nl = 1;
			}
			if(s == "ru"){
				nr = 1;
			}
			if(s == "ld"){
				nl = 0;
			}
			if(s == "rd"){
				nr = 0;
			}
			if(!prev && nl && nr){
				prev = 1;
				ans++;
			}
			else if(prev && !nl && !nr){
				prev = 0;
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

  int main() {
    int A,B,C,K;
    int ans=0;
    cin >> A >> B >> C >> K;
    if((A-K)>=0){
      ans=K;
    }
    if((A-K)<=0){
      if((A+B-K)>=0){
        ans=A;
      }
      else{
        ans=2*A-K+B;
      }
    }
    cout << ans ;
  }




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

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll h, w;
    cin >> h >> w;
    vector<string> s;
    for (ll i = 0; i < h; i++)
    {
        string t;
        cin >> t;
        s.push_back(t);
    }

    for (ll i = 0; i < s.size(); i++)
    {
        if (s[i].find('#') == -1) {
            s.erase(s.begin() + i);
            i--;
        }
    }

    for (ll i = 0; i < w; i++)
    {
        bool tt = false;
        for (ll t = 0; t < s.size(); t++)
        {
            if(s[t][i] == '#'){
                tt = true;
                break;
            }
        }

        if (!tt)
        {
            for (ll k = 0; k < s.size(); k++)
            {
                s[k].erase(i, 1);
            }
            i--;
            w--;
        }
    }

    for (ll i = 0; i < s.size(); i++)
    {
        cout << s[i] << endl;
    }
}

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

typedef long long ll;

using namespace std;

int main()
{ll N; cin >> N;
vector<ll> A(N); vector<ll>B(N); vector<ll>C(N);
 
for(ll i = 0; i < N;i++){ cin >> A[i];}
 for(ll j = 0; j < N; j++){ cin >> B[j];}
  for(ll k = 0; k < N; k++){ cin >> C[k];}
 
 sort(A.begin(),A.end());
 sort(B.begin(),B.end());
 sort(C.begin(),C.end());
 
 ll total = 0;
 
 for(ll j = 0; j < N; j++){
   ll key = B[j];
   auto position1 = lower_bound(A.begin(),A.end(),key);
   auto position2 = upper_bound(C.begin(),C.end(),key);
   
   ll cntA = distance(A.begin(), position1);
   ll cntB = distance(position2,C.end());
   
   
    total += cntA * cntB;
 }
 
 cout << total << endl;
 
 return 0;
}


Measured memory_bytes: 2688
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        int n = sc.nextInt();
        int m = sc.nextInt();

        String[] arr = new String[n];
        for (int i=0; i<n; i++) arr[i] = sc.next();

        Arrays.sort(arr);

        StringBuilder sb = new StringBuilder();
        for (int i=0; i<n; i++) sb.append(arr[i]);

        System.out.println(sb.toString());

    }

}



Measured memory_bytes: 21588
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s,x;
	int n,a=0;
	cin>>s;
	cin>>n;
	for (int i=0;i<s.size();i++)
	{
		if (i%n==0)
		{
		    cout<<s[i];
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;

typedef long long int ll;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;


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());

	int ans = 0;

	for (int i = 0; i < n-1; i++)
	{
		ans += a[i + 1] - a[i];
	}

	cout << ans << endl;

	return 0;


}





Measured memory_bytes: 256
import fractions

N=int(raw_input())
A = map(int, raw_input().split())

def lcm(x,y):
    return x * y / fractions.gcd(x,y)


l = reduce(lcm, A)

res = 0
for i in range(N):
    res += l/A[i]

print res % (10**9+7)


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

int main(){
  int N;
  cin >> N;
  set<string> s;
  string pre;
  cin >> pre;
  s.insert(pre);
  for(int i=1;i<N;i++){
    string W;
    cin >> W;
    if(s.count(W)){
      cout << "No" << endl;
      return 0;
    }
    if(pre.back()!=W.front()){
      cout << "No" << endl;
      return 0;
    }
    s.insert(W);
    pre=W;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

size_t solve(const size_t x, const size_t y,
             map<pair<size_t, size_t>, size_t> & soln)
{
  if(x < 2 && y < 2) return 0;
  vector<bool> tag(20, false);

  for(size_t i = 1; 2 * i < x + 1; ++i)
    tag[soln[{x + y - i, x - 2 * i}]] = true;


  for(size_t i = 1; 2 * i < y + 1; ++i)
    tag[soln[{x + y - i, y - 2 * i}]] = true;

  for(size_t i = 0; i < tag.size(); ++i)
    if(!tag[i]) return i;

  return -1;
}

void calc()
{
  map<pair<size_t, size_t>, size_t> soln;
  for(size_t s = 0; s < 15; ++s)
    for(size_t i = 0; i < s + 1; ++i)
      soln[{s, i}] = solve(i, s - i, soln);

  size_t s = 0;
  for(const auto & pr: soln)
  {
    if(s != pr.first.first) cout << '\n';
    s = pr.first.first;

    cout << pr.first.first - pr.first.second << ", "
      << pr.first.second << ": " << pr.second << '\n';
  }
}

int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int64_t x, y;
  cin >> x >> y;
  if(x < 2 && y < 2)
    cout << "Brown";

  else if(abs(x - y) < 2)
    cout << "Brown";

  else
    cout << "Alice";

  return EXIT_SUCCESS;
}



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

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

#define INF  (int)1e9
#define LINF (long long)1e18

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

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

    string S;
    std::cin >> S;
    SORT(S);

    if(S[0] != S[1] || S[2] != S[3]) {
        std::cout << "No" << std::endl;
    }
    else {
        if(S[1] == S[2]) {
            std::cout << "No" << std::endl;
        }
        else {
            std::cout << "Yes" << std::endl;
        }
    }

    return 0;
}


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

using namespace std;

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

int N;
int A[20];
int X[20][20], Y[20][20];

int n_honests(int bits) {
  auto is_honest = [&](int i) { return bits & (1 << i); };

  int ret = 0;
  for (int i = 0; i < N; i++) {
    if (!is_honest(i)) {
      continue;
    }
    ret++;
    for (int j = 0; j < A[i]; j++) {
      if (Y[i][j] == 1 && !is_honest(X[i][j])) {
        return -1;
      }
      if (Y[i][j] == 0 && is_honest(X[i][j])) {
        return -1;
      }
    }
  }
  return ret;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    for (int j = 0; j < A[i]; j++) {
      cin >> X[i][j] >> Y[i][j];
      X[i][j]--;
    }
  }

  int ans = 0;
  for (int bits = 0; bits < (1 << N); bits++) {
    chmax(ans, n_honests(bits));
  }
  cout << ans << endl;

  return 0;
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

int main()
{
    int h1,m1,h2,m2,k;
    cin >> h1>>m1>>h2>>m2>>k;

    int ans=m2+60*h2-(m1+60*h1)-k;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(),a.end()
#define stoink stack<ll>
#define vec vector <ll>
#define vg vector<vector<ll> >
#define vgw vector<vector<pair<ll,ll> >
#define pa pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 1000000000000
#define mod 998244353
vec arr;
ll n;
vector<int> dp;
bool func(ll val) {
	if(val <= 0)
		return 0;
	if(dp[val] != -1)
		return dp[val];
	bool res = 0;
	for(int i = 0 ; i < n ; i++) {
		if(arr[i] <= val) {
			int temp = func(val - arr[i]);
			if(temp == 0)
				res = 1;
		}
	}
	return dp[val] = res;

}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll k,i;
	cin >> n >> k;
	arr.resize(n);
	dp.resize(k+1,-1);
	for(i = 0 ; i < n ; i++)
		cin >> arr[i];
	if(func(k))
		cout << "First";
	else
		cout << "Second";
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <cstdint>
#include <vector>
#include <numeric>

int main() {
  std::int_fast64_t n;
  std::cin >> n;
  std::vector<std::int_fast64_t> t(n);
  for (std::int_fast64_t& t_i : t) {
    std::cin >> t_i;
  }
  std::int_fast64_t sum = std::accumulate(t.begin(), t.end(), 0, [](const std::int_fast64_t& s, const std::int_fast64_t& t_i) { return s + t_i; });
  std::int_fast64_t m;
  std::cin >> m;
  for (std::int_fast64_t i = 0; i < m; ++i) {
    std::int_fast64_t p, x;
    std::cin >> p >> x;
    std::cout << sum - t[p - 1] + x << std::endl;
  }
  return 0;
}

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

int main(){
    int n, qt;//プロセスの数, クオンタイム
    cin >> n >> qt;
    
    char name[n][10];
    int time[n];
    for(int i=0; i<n; i++){
        cin >> name[i];
        cin >> time[i];
    }

    int head = 0;
    int tail = 0;
    int total = 0;//total time

    while(1){
        if(time[head] <= qt){
            total += time[head];
            cout << name[head] << " " << total << endl;
            head++;
            if(head == n) head = 0;
            if(head == tail) break;
        } else {
            total += qt;
            time[head] -= qt;
            for(int j=0; j<10; j++){
                name[tail][j] = name[head][j];
            }
            time[tail] = time[head];
            tail++;
            if(tail == n) tail = 0;
            head++;
            if(head == n) head = 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3776
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
edge = [0, 0]
index = 0
tmp = 0
for i in range(0, N):
	if 2 <= index: break
	if tmp == A[i]:
		edge[index] = A[i]
		tmp = 0
		index += 1
	else:
		tmp = A[i]
print(edge[0]*edge[1])

Measured memory_bytes: 62704
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  int cnt=0;
  REP(i,n) {
    int a;
    cin>>a;
    if (i%2==0 && a%2 == 1) ++cnt;
  }
  cout<<cnt<<endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    int l[n];
    int count = 0;

    for (int i = 0; i < n; i++) cin >> l[i];

    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
                    if (l[i] + l[j] > l[k] && l[i] + l[k] > l[j] &&
                        l[j] + l[k] > l[i]) {
                        count++;
                    }
                }
            }
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3628
str = gets
n = gets.to_i
n.times do
  c = gets.split(" ")
  case c[0]
  when "print"
    puts str[c[1].to_i..c[2].to_i]
  when "reverse"
    str[c[1].to_i..c[2].to_i] = str[c[1].to_i..c[2].to_i].reverse!
  when "replace"
    str[c[1].to_i..c[2].to_i] = c[3]
  end
end

Measured memory_bytes: 8700
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

char ans[10000];
char s[1000];

int main()
{
  int a,b,x,y,n1,n2,i,n,tmp;
  scanf("%d%d",&a,&b);
  n=a+b;
  if (a>b)
  {
    x=1;y=0;
    n1=0;n2=0;
    while (1)
    {
      if (x>=n) break;
      printf("? %d %d\n",x,y);
      fflush(stdout);
      scanf("%s",s);
      if (s[0]=='Y') n1++;
      else n2++;
      if (n2>=n1+1)
      {
        tmp=x+1;
        y=tmp;
        x=tmp+1;
        n1=0;n2=0;
      }
      else
      {
        x++;
      }
    }
    for (i=0;i<n;i++)
    {
      printf("? %d %d\n",y,i);
      fflush(stdout);
      scanf("%s",s);
      if (s[0]=='Y') ans[i]='1';
      else ans[i]='0';
    }
    ans[n]='\0';
    printf("! %s\n",ans);
  }
  else
  {
    printf("Impossible\n");
  }
  return 0;
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
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());
  long long sum=0;
  for(int i=0;i<n/2;i++){
    sum-=a[i]*2;
  }
  for(int i=0;i<n/2;i++){
    sum+=a[n-1-i]*2;
  }
  long long sum2=sum;
  if(n%2==1){
    sum-=a[n-1-n/2+1];
    sum+=a[n/2];
    sum2+=a[n/2-1];
    sum2-=a[n/2];
  }
  else{
    sum-=a[n/2];
    sum+=a[n/2-1];
    sum2=0;
  }
  cout << max(sum,sum2) << endl;
}

Measured memory_bytes: 640
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}

#define INF 1e9

inline void bfs(int s, vvi const& grafo, vi & dist) {
    dist[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        rep(i, 0, grafo[u].size()) {
            int v = grafo[u][i];
            if (dist[v] == INF){
                dist[v] = 1 + dist[u];
                q.push(v);
            }
        }
    }
}

int main(){

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

    int n, x, y;
    cin >> n >> x >> y;
    --x; --y;
    vvi grafo(n);
    rep(i, 0, n-1) {
        grafo[i].pb(i+1);
        grafo[i+1].pb(i);
    }
    grafo[x].pb(y);
    grafo[y].pb(x);
    //vvi dist(n, vi(n, INF));
    vi dist(n);
    vi cnt(n + 2, 0);
    rep(i, 0, n) {
        dist.assign(n, INF);
        bfs(i, grafo, dist);
        for (auto it : dist)
            ++cnt[it];
        //sort(all(dist[i]));
    }
    cout << n << '\n';
    rep(k, 2, n) {
        cout << (cnt[k] >> 1) << '\n';
    }
    
    return 0;
}

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;

string s;
int N, Q;

bool ok(int m, vector<char> t, vector<char> d, char dir) {
    int p = m;
    char cur = s[p];
    for (int i = 0; i < Q; i++) {
        if (t[i] == cur) {
            if ((p == ((dir == 'L') ? 1 : N)) and d[i] == dir) {
                return true;
            }
            p += (d[i] == 'L') ? -1 : 1;
            cur = s[p];
        }
    }
    return false;
}

int main() {
    cin >> N >> Q;
    cin >> s;
    s = ' ' + s;

    vector<char> t(Q), d(Q);
    for (int i = 0; i < Q; i++) {
        cin >> t[i] >> d[i];
    }

    int ans = N;
    int left = 0, right = N + 1;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        if (ok(mid, t, d, 'L'))left = mid;
        else right = mid;
    }

    ans -= left;

    left = 0, right = N + 1;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        if (ok(mid, t, d, 'R'))right = mid;
        else left = mid;
    }
    ans -= N - left;
    cout << max(0, ans) << endl;

    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000
struct unionfind{
	vector<int> data;
	vector<int> size;
	unionfind(int n){
		for(int i=0;i<n;i++){
			data.push_back(i);
			size.push_back(1);
		}
	}
	
	int find(int x){
		if(data[x]==x)return x;
		return data[x]=find(data[x]);
	}
	
	bool unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		data[x]=y;
		size[y]+=size[x];
		return true;
	}
	
	bool check(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_size(int x){
		int X = find(x);
		return size[X];
	}
};


int main(){
	
	int N,H,W;
	cin>>N>>H>>W;
	
	vector<pair<long long,pair<int,int>>> V(N);
	
	map<int,int> mp1,mp2;
	
	for(int i=0;i<N;i++){
		cin>>V[i].second.first>>V[i].second.second>>V[i].first;
		mp1[V[i].second.first]=-1;
		mp2[V[i].second.second]=-1;
		
	}
	int now = 0;
	for(auto &a:mp1){
		a.second=now;
		now++;
	}
	now=0;
	for(auto &a:mp2){
		a.second = now;
		now++;
	}
	
	for(int i=0;i<N;i++){
		V[i].second.first = mp1[V[i].second.first];
		V[i].second.second = mp2[V[i].second.second];
	}
	
	unionfind uf(2*N);
	
	sort(V.begin(),V.end());
	
	long long ans = 0;
	set<int> NG;
	for(int i=N-1;i>=0;i--){
		int a = V[i].second.first;
		int b = V[i].second.second+N;
		if(NG.count(uf.find(a))&&NG.count(uf.find(b)))continue;
		ans += (long long)V[i].first;
		bool f = (NG.count(uf.find(a))||NG.count(uf.find(b)));
		if(!uf.unite(a,b)||f){
			NG.insert(uf.find(a));
		}
		
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 12916
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
unsigned long long int m=1e9+7;
int main()
{
	ll n,arr[200001];
	cin>>n;
	unsigned long long int sum=0;
	for(ll i=1;i<=n;i++)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		sum-=arr[i];
		ans=(ans+((sum)%m*arr[i])%m)%m;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define int long long
typedef vector<int> vi;
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define OO 1e9
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
#define in_range(x, y, r, c) ((x >= 0 && x < r && y >= 0 && y < c))

const double eps=1e-9;
const  int MOD=1e10;
const int N=1e5+9;
const int inf = 1<<30;


template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <typename T> T exp(T b, T p){T x = 1;while(p){if(p&1)x=(x*b);b=(b*b);p=p>>1;}return x;}
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

map<pair<string,int>,int > mp;
bool cmp(const pair<string,int> &a,const pair<string,int> &b){
    if(a.first<=b.first){
        if(a.first<b.first)return true;
        return a.second>=b.second;
    }
    return false;
}
int32_t main() {
    IOS;
int n;
cin>>n;
vector<pair<string,int> > arr;
    for (int i = 0; i < n; ++i) {
        string a;
        int b;
        cin>>a>>b;
      mp[{a,b}]=i+1;
      arr.emplace_back(a,b);
    }
    sort(all(arr),cmp);
    for (int i = 0; i < arr.size(); ++i) {
        cout<<mp[arr[i]]<<endl;
    }
}

Measured memory_bytes: 256
def main():
    n, k, s = map(int, input().split(" "))
    array = []
    dummy = s + 1
    if s == 10 ** 9:
        dummy = s - 1
    if k <= n:
        array = [s for _ in range(k)]
        array += [dummy for _ in range(k, n)]
    print(" ".join(map(str, array)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 12056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  string s;cin>>s;
  int n=s.size();
  int l=1e9,r=0;
  rep(i,n){
    if(s[i]=='A')l=min(l,i);
    if(s[i]=='Z')r=max(r,i);
  }
  cout<<r-l+1<<endl;
}

Measured memory_bytes: 3732
#include<cstdio>
using namespace std;
const int maxn=100005,maxe=200005;
int n,m,p,ans[maxe][2];
int e=1,lnk[maxn],nxt[maxe],son[maxe];
bool vis[maxn],flg[maxe],F[maxn];
inline int read(){
	int ret=0;bool f=0;char ch=getchar();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=getchar();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
	return f?-ret:ret;
}
void add_e(int x,int y){son[++e]=y;nxt[e]=lnk[x];lnk[x]=e;}
void DFS1(int x){
	vis[x]=1;
	for (int i=lnk[x];i;i=nxt[i]){
		if(vis[son[i]]) continue;
		flg[i]=1;DFS1(son[i]);
	}
}
void DFS2(int x){
	for (int i=lnk[x];i;i=nxt[i])
	if(flg[i]){
		DFS2(son[i]);
		if(F[son[i]]) ans[++p][0]=son[i],ans[p][1]=x;
		else F[x]^=1,ans[++p][0]=x,ans[p][1]=son[i];
	}
}
int main(){
	n=read(),m=read();
	if(m&1){puts("-1");return 0;}
	for (int i=1;i<=m;i++){
		int x=read(),y=read();
		add_e(x,y),add_e(y,x);
	}
	DFS1(1);
	for (int i=1;i<=n;i++)
	for (int j=lnk[i];j;j=nxt[j])
	if((j&1)&&!flg[j]&&!flg[j^1])
	ans[++p][0]=i,ans[p][1]=son[j],F[i]^=1;
	DFS2(1);
	for (int i=1;i<=m;i++)
	printf("%d %d\n",ans[i][0],ans[i][1]);
	return 0;
}

Measured memory_bytes: 7552
#include <cstdio>
int main() {
    int a, b;
    scanf("%d %d", &a, &b);

    if (a == 1)
        a = 14;
    if (b == 1)
        b = 14;

    if (a < b)
        printf("Bob");
    else if (a == b)
        printf("Draw");
    else
        printf("Alice");

    return 0;
}


Measured memory_bytes: 128
n = int(input())
t, a = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dist = 1000000
ans = 0
def zettaiti(i):
  if(i<0):
    return i * -1
  else:
    return i

for i in range(n):
  te = a - ( t - (0.006 * h[i]))
  tem = zettaiti(te)
  if(dist>tem):
    dist = tem
    ans = i + 1
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = [int(v) for v in input().split()]

vmax = 10000
b = [-1] * len(a)
c = [0] * (vmax + 1)
for v in a:
    c[v] += 1

for i in range(1, vmax + 1):
    c[i] = c[i] + c[i-1]

for j in range(n-1, -1, -1):
    b[c[a[j]] - 1] = a[j]
    c[a[j]] -= 1

print(' '.join([str(v) for v in b]))


Measured memory_bytes: 241736
n=int(input())
h=list(map(int,input().split()))
res=0
cnt=0
for i in range(1,n):
  #print(cnt,res,h[i-1],h[i])
  if h[i-1] >= h[i]:
    cnt+=1
  else:
    res=max(res,cnt)
    cnt=0
res=max(res,cnt)
print(res)

Measured memory_bytes: 14224
import itertools

n = int(input())

route = [list(map(int, input().split())) for _ in range(n)]
results = []
for v in itertools.permutations(route, r=n):
    distance = 0
    for i in range(n - 1):
        start, goal = v[i], v[i + 1]
        distance += ((goal[0] - start[0]) ** 2 + (goal[1] - start[1]) ** 2) ** 0.5
    results.append(distance)
print(sum(results) / len(results))


Measured memory_bytes: 4504
#include<iostream>
using namespace std;
int main()
{
     int a,b,c;
     cin>>a>>b>>c;
     if(a<c&&c<b){
        cout<<"Yes"<<endl;
     }else if(a==b&&b==c){

          cout<<"Yes"<<endl;

     }
     else{

       cout<<"No"<<endl;


     }
     return 0;


}


Measured memory_bytes: 256
import std;

void main(){ 
	int n, k;
	int[] as;
	scanf("%d %d\n", &n, &k);
	auto mem = new bool[n];
	foreach(_i; 0..k) {
		int d;
		scanf("%d", &d);
		foreach (_j; 0..d) {
			int a;
			scanf("%d", &a);
			mem[a-1] |= true;
		}
	}
	mem.count!"!a".writeln;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cctype>
#define f(a,b,c) for((a)=(b);(a)<(c);(a)++)
#define fa(a,b,c) for((a)=(b);(a)>(c);(a)--)
#define s(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define x(a) scanf("%lld",&(a))
#define q(a) scanf("%s",(a))
#define d(a) printf("%lld\n",(a))
#define p(a,b) printf("%lld %lld\n",(a),(b))
#define ll long long
using namespace std;
const int mod=1000000007;
inline void read1(int &x){
	char ch=getchar(); x=0;
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch&15),ch=getchar();
}
inline ll read2(){
	ll summ=0,fl=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') fl=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		summ=((summ*10)+ch-'0')%mod;
		ch=getchar();
	}
	return summ*fl%mod;
}
inline void write(ll a){
    if(a==0){putchar('0');return;}
    if(a<0)putchar('-'),a=-a;
    char c1[120];
    int h=0;
    while(a)c1[++h]=a%10+'0',a/=10;
    for(int i=h;i>=1;i--)putchar(c1[i]);
    return;
}
inline void write_(ll a){write(a);putchar(' ');}
inline void writeln(ll a){write(a);putchar('\n');}
ll i,x,y,j,m,d,n,ans[100],sum;
char a;
int main(){
	while((a=getchar())!='\n'){
		n++;
		if(a=='C')x=1;
		if(a=='F'){
			if(x)return puts("Yes")&0;
		}
	}
	puts("No");
    return 0;
}

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

int main (void){  
    int x, y;
    cin >> x >> y;
    if (x % y == 0) {
        cout << -1 << endl;
    } else {
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
for i in range(110):
    x,y = map(int,input().split()) #xは生徒,yは科目
    if x == y == 0:
        break
    else:
        a = [0]*x
        for j in range(y):
            ls = list(map(int,input().split()))
            for _ in range(x):
                a[_] += ls[_]
        print(max(a))


Measured memory_bytes: 5716
import Control.Monad
main = do
  [n,_,c] <- map read . words <$> getLine
  b <- map read . words <$> getLine
  as <- replicateM n $ map read . words <$> getLine
  print $ length $ filter ( > 0) (map (f c b) as)
f x y z = sum (zipWith (*) y z) + x


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int a,b,x;
int main()
{
	cin>>a>>b;
	for(x=0;x<11111;++x)
	{
		int c=x/10;
		int d=x*8/100;
		if(c==b and d==a){cout<<x<<endl;return 0;}
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
import sys
import math

X = int(input())

x = int(math.sqrt(X) + 1)

# ａ⁵－ｂ⁵＝(ａ－ｂ)(ａ⁴＋ａ³ｂ＋ａ²ｂ²＋ａｂ³＋ｂ⁴)
# a - b >= 1
# a != b


a5 = []
for i in range(1000):
    a5.append(i ** 5)

b5 = []
for j in range(1000):
    b5.append(j ** 5)

ans_a = 0
ans_b = 0

for a in a5:
    for b in b5:
        if a - b == X:
            print("%d %d" % (a5.index(a), b5.index(b)))
            sys.exit()
        elif a + b == X:
            print("%d %d" % (a5.index(a), -1 * b5.index(b)))
            sys.exit()


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

int main(){
  int N;
  cin >> N;
  
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  sort(A,A+N);
  int check=0;
  
  for(int i=0;i<N-1;i++){
    if(A[i]==A[i+1]){
      cout << "NO" << endl;
      check=1;
      break;
    }
  }
  if(check==0){
    cout << "YES" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner s=new Scanner(System.in);
	int a=s.nextInt();
	int x=s.nextInt();
	long c[]=new long[a];
	long count=0;
	int ans=0;
	long sum=0;
	for(int i=0;i!=a;i++) {
		int b=s.nextInt();
		c[i]=b;
		sum+=c[i];
	}
	Arrays.sort(c);
	for(int i=0;i<a;i++) {
		count+=c[i];
		if(count>x) {
			break;
		}
		ans++;
	}
	System.out.println(sum<x?ans-1:ans);
	}
}

Measured memory_bytes: 21716
N = int(input())
A = list(map(int, input().split()))

if N == 0:
    print(A[0] if A[0] <= 1 else -1)
    exit()

if A[0] and N >= 1:
    print(-1)
    exit()

# 根の数
node = 1
root = 0

s = sum(A)

for i in range(len(A) - 1):
    node = min(s, node * 2) - A[i + 1]
    
    if node < 0:
        print(-1)
        exit()
    
    s -= A[i + 1]
    root += node

print(root + sum(A) + 1 if not node else -1)

Measured memory_bytes: 20136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define i64 unsigned long long
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll mod = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}


int pow(ll x, ll y, ll mod){
    ll ret=1;
    for(;y;y>>=1,x=1ll*x*x%mod){
        if(y&1) ret=1ll*ret*x%mod;
    }
    return ret;
}
void kill()
{
    cout << -1 << endl;
    exit(0);
}

int main() {
    sonic();
    int next, prev, total, i, t, n;
    ll ans=0;
    R n;
    priority_queue<pii> q;
    vi A(n), B(n);
    rep(i, n)R A[i];
    rep(i, n){
        R B[i];
        q.push(make_pair(B[i], i));
    }
    while(!q.empty()) {
        i = q.top().second;
        q.pop();
        if(B[i]==A[i])continue;
        next = (i + 1 + n) % n;
        prev = (n + i - 1) % n;
        total = B[next] + B[prev];
        t = (B[i] - A[i]) / total;
        if(t==0)kill();
        ans += t;
        B[i] -= t * total;
        q.push(make_pair(B[i], i));
    }
    co(ans);
}


Measured memory_bytes: 6940
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void rd(string &x){
  char *buf = (char *)wmem;
  rd(buf);
  x = buf;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
string S;
int main(){
  wmem = memarr;
  rd(N);
  rd(S);
  if(N%2==0 && S.substr(0,N/2)==S.substr(N/2)){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int N; string S;
// {
//   rd(N,S);
//   wt( if[N%2==0 && S.substr(0,N/2)==S.substr(N/2), "Yes", "No"] );
// }


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int n, m, q, l, r, a, b;
vector<int>v[510];

int main() {
	cin >> n >> m >> q;
	for (int i = 0;i < m;i++) {
		cin >> l >> r;
		v[l].eb(r);
	}
	for (int i = 1;i <= n;i++) {
		sort(ALL(v[i]));
	}
	for (int i = 0;i < q;i++) {
		cin >> a >> b;
		int ans = 0;
		for (int j = a;j <= b;j++) {
			ans += upper_bound(ALL(v[j]), b) - v[j].begin();
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main()
{
	int a,b;
	int i,n;
	int sa,sb;
	while(1){
		scanf("%d", &n);
		if(n==0){
			break;
		}
		sa=0;
		sb=0;
		for(i=0; i<n; i++){
			scanf("%d %d", &a, &b);
			if(a>b){
				sa+=a+b;
			}
			else if(b>a){
				sb+=a+b;
			}
			else{
				sa+=a;
				sb+=b;
			}
		}
		printf("%d %d\n", sa, sb);
	}
	return 0;
}

Measured memory_bytes: 600
n = int(input())
num = list(map(int, input().split()))

m = int(input())
checks = list(map(int, input().split()))

# bit全探索
pattern = set()
for i in range(2 ** n):
    ans = 0
    for j in range(n):
        if (i >> j) & 1:
            ans += num[j]
    pattern.add(ans)

for check in checks:
    if check in pattern:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 5644