akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<51)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define all(c) (c).begin(),(c).end()
#define N 3000

ld dp[N][N];
bool vis[N][N];
ld p[N];
int n;
ld ans = 0;
ld rec(int i,int heads)
{
    if(i == n)
    {
        if(heads > n - heads)
            return 1;
        else 
            return 0;
    }
    if(vis[i][heads] == 0)
    {
        ld ans = 0.0;
        ans = ans + p[i] * rec(i+1,heads + 1);
        ans = ans + (1.0 - p[i]) * rec(i+1,heads);
        dp[i][heads] = ans;
        vis[i][heads] = 1;
        return ans;
    }
    else
        return dp[i][heads];
}
int32_t main()
{                
    IOS;
    
    
    memset(vis,0,sizeof(vis));
    memset(dp,0,sizeof(dp));
    cin>>n;
    for(int i = 0; i < n;i++ )
        cin>>p[i];
    cout<<fixed<<setprecision(10);
    cout<<rec(0,0);
    return 0;

}

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

using namespace std;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef long long ll;
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define NEXTP(c) next_permutation(ALL(c))
#define SUM(c) accumulate(ALL(c),0)
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define ANS(x) cout << (x) << endl;
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define INF 1000000000 // 10^9
const double EPS = 1e-10;

int main(){
    string str;
    cin >> str;
    int c = -1 ,f = -1;
    REP(i, str.length()){
        if (str[i] == 'C' && c==-1) c = i;
        if (str[i] == 'F') f = i;
    }

    if (c!=-1 && f!=-1 && c<f)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {  
    int n; cin >> n;
    vector<ll> A(n), B(n);
    rep(i, n) cin >> A[i] >> B[i];

    sort(all(A)), sort(all(B));
    ll res;
    if(n%2==1){
        res = B[n/2] - A[n/2] + 1;
    }else{
        res = (B[(n/2)-1] + B[n/2]) - (A[(n/2)-1] + A[n/2]) + 1;
    }
    cout << res << ln;
}




Measured memory_bytes: 6436
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
  int n; cin >> n;
  int t[101];
  int t_2 = 0;
  for(int i = 1; i <= n; i++){
    cin >> t[i];
    t_2 += t[i];
  }
  int t_3 = t_2;
  
  int m; cin >> m;
  int p[101], x[101];
  for(int i = 1; i <= m; i++){
    cin >> p[i] >> x[i];
    t_2 -= t[p[i]];
    t_2 += x[i];
    cout << t_2 << endl;
    t_2 = t_3;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int K,X;
  cin>>K>>X;
  string ans= K*500>=X?"Yes":"No";
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    s = input()
    cnt = 0
    s = s.replace('A', '1').replace('BC', '0')
    arr = re.split('[A-C]', s)
    arr = [list(x) for x in arr]

    for a in arr:
        tmp = 0
        for i in a:
            i = int(i)
            tmp += i
            if i is 0:
                cnt += tmp

    return cnt


if __name__ == '__main__':
    print(main())


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

int ri() {
    int n;
    cin >> n;
    return n;
}


int main()
{



    int a,b,c,d;
    a = ri();
    b = ri();
    c = ri();
    d = ri();


    for (;;) {
        c = c - b;
        if (c <= 0) {
            cout << "Yes";
            break;
        }
        a = a - d;
        if (a <= 0) {
            cout << "No";
            break;
        }

    }





    return 0;
}

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

using namespace std;

const int NUM = 50;

int g[NUM][NUM];

void dfs(int n, vector<bool>& seen)
{
    seen[n] = true;
    for (int i = 0; i < NUM; ++i) {
        if (g[n][i] == 1 && !seen[i]) dfs(i, seen);
    }
}

int main()
{
    for (int i = 0; i < NUM; ++i)
        for (int j = 0; j < NUM; ++j)
            g[i][j] = 0;

    int n, m; cin >> n >> m;
    int ans = 0;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        --a[i]; --b[i];
        g[a[i]][b[i]] = 1;
        g[b[i]][a[i]] = 1;
    }

    for (int i = 0; i < m; ++i) {
        g[a[i]][b[i]] = 0;
        g[b[i]][a[i]] = 0;
        vector<bool> seen(n, false);
        dfs(0, seen);
        if (find(seen.begin(), seen.end(), false) != seen.end()) ++ans;
        g[a[i]][b[i]] = 1;
        g[b[i]][a[i]] = 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*---Author:HenryHuang---*/
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e3+5;
typedef long long ll;
int n,p;
ll ksm(ll a,ll b,ll p){
	ll ans=1;
	while(b){
		if(b&1) ans=ans*a%p;
		b>>=1,a=a*a%p;
	}
	return ans;
}
ll C[maxn][maxn],S[maxn][maxn];
void init(){
	C[0][0]=S[0][0]=1;
	for(int i=1;i<=n+1;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j){
			S[i][j]=(S[i-1][j-1]+j*S[i-1][j])%p;
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%p;
		}
	}
}
ll a[32769],b[32769];
ll c[32769],d[32769];
ll p1(ll x){
	return a[x&0x00007fff]*b[x>>15]%p;
}
ll p2(ll x){
	return c[x&0x00007fff]*d[x>>15]%(p-1);
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>p;init();
	a[0]=1;
	for(int i=1;i<=32768;++i){
		a[i]=a[i-1]*2%p;
	}
	b[0]=1,b[1]=a[32768];
	for(int i=2;i<=32768;++i){
		b[i]=b[i-1]*b[1]%p;
	}
	c[0]=1;
	for(int i=1;i<=32768;++i){
		c[i]=c[i-1]*2%(p-1);
	}
	d[0]=1,d[1]=c[32768];
	for(int i=2;i<=32768;++i){
		d[i]=d[i-1]*d[1]%(p-1);
	}
	ll ans=0;
	for(int i=0;i<=n;++i){
		ll tmp=p1(p2(n-i))*C[n][i]%p,owo=0;
		if(i&1) tmp=p-tmp;
		for(int j=0;j<=i;++j){
			owo=(owo+S[i+1][j+1]*p1(1ll*(n-i)*j%(p-1))%p)%p;
		}
		(ans+=tmp*owo%p)%=p;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 97020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  int n,x;
  cin >> n >> x;
  vector<int> L(n);
  rep(i,n){
    cin >> L[i];
  }
  
  int h=0;
  rep(i,n){
    h+=L[i];
    if(h>x){cout << i+1 << endl;
           return 0;}
  }
  cout << n+1 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n, m, c;
    cin >> n >> m >> c;
    vector<ll> a(m), b(m);
    rep1(i, m) cin >> b[i];
    ll ans = 0, cnt;
    rep1(i, n){
        cnt = c;
        rep1(j, m) {
            cin >> a[j];
            cnt += a[j]*b[j];
        }
        if (cnt>0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    N,M = map(int,input().split())
    A_list = list(map(int,input().split()))

    for i in A_list:
        N -= i
    print(N if N>=0 else -1)

main()


Measured memory_bytes: 10040
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1e9+7;
using namespace std;

int main(){
    int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
                   59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
                   127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
                   191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
                   257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
                   331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,
                   401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
                   467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
                   563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619,
                   631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
                   709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787,
                   797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
                   877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953,
                   967, 971, 977, 983, 991, 997};
                   
    int prnum = sizeof(prime)/sizeof(prime[0]);
    int n; cin >> n;
    ll ans = 1;
    for(int i = 0; i < prnum && prime[i] <= n ; i++){
        ll eachfac = 0;
        for(int j = prime[i]; j <= n; j *= prime[i])
            eachfac = (eachfac + (n/j)) % MOD;
            
        ans = ans * (eachfac+1) % MOD;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#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 long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


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


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


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

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };


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



int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int r,b,w,g;
	cin >> r>>b>> w >> g;



	cout << r+b+w+g << endl;

	return 0;
}




Measured memory_bytes: 3184
import sys
import os
import collections

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = sys.stdin.buffer.readline().decode().rstrip()
    p = S[:(len(S)-1)//2]
    u = S[(len(S)+2)//2:]
    print('Yes' if S == S[::-1] and p == p[::-1] and u == u[::-1] else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int N;
  ci(N);
  rep(i, N){
    char c;
    ci(c);
    if(c == 'Y'){
      co("Four");
      rt;
    }
  }
  co("Three");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,q,a) for(long long i=q; i<a; i++)
#define ll long long
#define pb push_back
#define mod 1000000007
using namespace std;
char g[1002][1002];
ll visited[1002][1002]={};
bool exists(ll x, ll y)
{
    if(x<0||x>1001)return 0;
    if(y<0||y>1001)return 0;
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll n, m;
    cin>>n>>m;
    ll a, b, x, y;
    cin>>a>>b>>x>>y;

    f(i,0,1002)
    f(k,0,1002)g[i][k]='#';

    f(i,0,1002)
    f(k,0,1002)visited[i][k]=mod;

    f(i,1,n+1)
    f(k,1,m+1)cin>>g[i][k];

    //BFS

    ll moves=-1;

    deque<array<ll,3>>q;
    q.pb({a,b,0});
    visited[a][b]=0;

    while(!q.empty())
    {
    ll u=q.front()[0], v=q.front()[1], z=q.front()[2];
    q.pop_front();
    if(u==x&&v==y)
    {
        if(moves==-1)moves=visited[u][v];
        else moves=min(visited[u][v],moves);
    }
    if((visited[u][v+1]>z)&&g[u][v+1]!='#')visited[u][v+1]=z, q.push_front({{u,v+1,z}});
    if((visited[u][v-1]>z)&&g[u][v-1]!='#')visited[u][v-1]=z, q.push_front({{u,v-1,z}});
    if((visited[u+1][v]>z)&&g[u+1][v]!='#')visited[u+1][v]=z, q.push_front({{u+1,v,z}});
    if((visited[u-1][v]>z)&&g[u-1][v]!='#')visited[u-1][v]=z, q.push_front({{u-1,v,z}});

    ll d[5]={-2,-1,0,1,2};

    f(i,0,5)
    f(k,0,5)
    {
        if(exists(u+d[i],v+d[k]))
        {
            if(visited[u+d[i]][v+d[k]]==mod&&g[u+d[i]][v+d[k]]!='#')visited[u+d[i]][v+d[k]]=z+1, q.pb({{u+d[i],v+d[k],z+1}});
        }
    }
    }
    cout<<moves<<endl;
    return 0;
}


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

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

int main()
{
  int N, Y;
  cin >> N >> Y;
  bool b = false;

  rep(i, N+1)
  {
    if(b)
    {
      break;
    }
    rep(j, N+1)
    {
      if(b)
      {
        break;
      }
      if((i + j) > N)
      {
        break;
      }
      rep(k, N+1)
      {
        if(b)
        {
          break;
        }
        if((i + j + k) > N)
        {
          break;
        }
        else if((i + j + k) < N)
        {
          continue;
        }

        if(Y == (i * 10000 + j * 5000 + k * 1000))
        {
          cout << i << ' ' << j << ' ' << k << endl;
          i = N;
          j = N;
          k = N;
          b = true;
          break;
        }
      }
    }
  }
  if(!b)
  {
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int N,K,C[100],i,j,m,n,t;

int f()
{
	int i,j,r=-1;
	for(i=j=0,t=1;i<=N-K;i++)
		{
			for(;j-i<K;j++)
				t*=C[j];
			r=r>t?r:t;
			t/=C[i];
		}
	return r;
}

int main()
{
	for(;scanf("%d%d",&N,&K),N;)
	{
		m=n=-1;
		for(i=0;i<N;i++)scanf("%d",&C[i]);
		m=f();
		for(i=0;i<N-1;i++)
			for(j=i+1;j<N;j++)
			{
				C[i]^=C[j]^=C[i]^=C[j];
				t=f();
				n=n>t?n:t;
				C[i]^=C[j]^=C[i]^=C[j];
			}
		if(n-m<0)puts("NO GAME");
		else printf("%d\n",n-m);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int a, b, x;
  cin >> a >> b >> x;

  cout << setprecision(12);

  double h = (double)x / (a * a);

  double l = 2 * h - b;

  double c = 2 * a * h / b;

  if (l >= 0) {
    cout << atan((b - l) / a) * 180 / M_PI << endl;
  } else {
    cout << atan(b / c) * 180 / M_PI << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

typedef pair<int, int> pii;
const int N = int(4e5) + 7;

ll n, s, b;

ll F(ll b, ll n) {
    if(n < b) return n;
    return F(b, n / b) + n % b;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> s;
    for(int i = 2; i <= N; ++i)
        if(F(i, n) == s) return cout << i, 0;
    ll res = (ll)1e18;
    if(s == n) res = n + 1; n -= s;
    for(int i = 1; i <= int(1e6); ++i) {
        if(i > s) break;
        b = n / i + 1;
        if(b > N && n == (b - 1) * i && s - i < b) res = min(res, b);
    }
    if(res == (ll)1e18) cout << -1;
    else cout << res;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    string x;
    int c=0;
    cin>>x;
    int arr['d']={0};
    for (int i=0;i<3;i++)
    {
        int a=x[i];
        arr[a]++;
    }

        if (arr['a']==1&&arr['b']==1&&arr['c']==1)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;

int main(){
    int n,temp;
    cin>>n;
    vector<int> dp(3);
    // dp[i] - total cost such that we did activity i on the last day
    for(int day = 0; day < n; day++){
            vector<int> new_dp(3, 0);
            vector<int> c(3);
    for(int i = 0; i < 3; i++){
        cin>>c[i];
    }
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                if(j != i){
                    new_dp[j] = max(new_dp[j], dp[i] + c[j]);
                }
            }
        }
    dp = new_dp;
    }
    cout<<max({dp[0], dp[1], dp[2]});

    return 0;
}



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

int main()
{
    int n,k; cin >> n >> k;

    vector<int> p(n);
    rep(i, n) cin >> p.at(i);

    sort(p.begin(), p.end());

    int sum = 0;

    rep(i,k) {
        sum += p.at(i);
    }

    cout << sum << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    ll a, b, c, d; cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <array>
#include <string>
#include <map>
using namespace std;

#define DB(x)

/*
int getIntSp(){
    string str;
    getline(cin,str,' ');
    return stoi(str);
}

int getIntLF(){
    string str;
    getline(cin,str);
    return stoi(str);
}
 */


int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    string S;
    cin >> S;

    string out;

    for( int i = 0; i < S.size(); ++i )
    {
        char c = S.c_str()[i];
        c -= 'A';
        c += N;
        c %= 26;
        c += 'A';
        out += c;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
A=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
    point=[int(j) for j in input().split()]
    if point[1]>0:
        for k in point[2:]:
            if k:A[i][k-1]=1
                
for i in A:
    print(*i)


Measured memory_bytes: 6388
# 138A

# 整数a:標準入力 → n = int(input())
# 文字列s：標準入力
a = int(input())
s = input()

# a >= 3200 なら 's'と出力
# a < 3200なら'red'と出力

if a >= 3200:
    print(s)

elif a < 3200:
    print('red')

Measured memory_bytes: 9080
#include<cstdio>
#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
using ll = long long;
 
 
 
int main(void){
	int a, b;
	cin >> a >> b;
	if ((a*b) % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
 
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> mochi_size(N);
  for (int i=0; i < N; i++){
    cin >> mochi_size.at(i);
  }
  sort(mochi_size.begin(),mochi_size.end());
  int f = 1;
  for (int i=1; i < N; i++){
    if (mochi_size.at(i) > mochi_size.at(i-1)){
      f++;
    }
  }
  cout << f << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N;
      string S;
      cin >> N;
      for(int i=0;i<N;i++){
        cin >> S;
        if(S == "Y"){
          cout << "Four" << endl;
          break;
        }
      }
      if(S != "Y"){
        cout << "Three" << endl;
      }
    }

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

using namespace std;

int dig(int x){
    int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;
    if(n % dig(n) == 0){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 + (y1 - y2)
y3 = y2 - (x1 - x2)

x4 = x1 + (y1 - y2)
y4 = y1 - (x1 - x2)

print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include <iostream>
 using namespace std;
 	int main(){
 		int W , H , x , y , r ;
 		cin >> W >> H >> x >> y >> r ;
 	if ( x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0 )
 	cout << "Yes" << endl;
 	else 
 	cout << "No" << endl;	
 	}

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

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

ll n,w,meow;
ll weight[105],value[105];
ll dp[105][100005];

ll find(ll n,ll v){
	if (v<0)return inf;
	if (v==0)return 0;
	if (n==0)return inf;
	if (dp[n][v]!=-1)return dp[n][v];
	dp[n][v]=min(weight[n-1]+find(n-1,v-value[n-1]),find(n-1,v));
	return dp[n][v];
}

void solve() {
    cin>>n>>w;
    rep(i,0,n){
    	cin>>weight[i]>>value[i];
    	meow+=value[i];
    }
    memset(dp,-1,sizeof dp);
    repr(i,meow+1,0){
    	if (find(n,i)<=w){
    		cout<<i<<endl;
    		return;
    	}
    }
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}


Measured memory_bytes: 82304
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  i++)
#define REP(i, n)    for(int i=0;   i<(n);  i++)
#define REP1(i, n)   for(int i=1;   i<=(n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul    = unsigned long;
using ll    = long long;
using ld    = long double;
using vint  = vector<int>;
using vll   = vector<ll>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;

int n;

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

  scan(n);
  int a = n%100;
  int b = n/100;
  // n = ba

  bool YYMM =0;
  bool MMYY =0;
  if(b>=1 && b<=12) MMYY=1;
  else              MMYY=0;

  if(a>=1 && a<=12) YYMM=1;
  else              YYMM=0;

  if(YYMM && MMYY) cout << "AMBIGUOUS" << endl;
  else if(YYMM)    cout << "YYMM" << endl;
  else if(MMYY)    cout << "MMYY" << endl;
  else             cout << "NA" << endl;
//  vint s(n);
//  REP(i, n) scan(s[i]);

//  cout <<  << endl;

  return 0;
}


Measured memory_bytes: 256
package main
                                                          
import "fmt"               
import "strconv"                                          
                                                          
var s string                                              
var nums []string        
var total int  

func find(a []int, x int) int {
        for i, n := range a {
                if x == n {
                        return i
                }
        }
        return len(a)
}

func main() {
        fmt.Scanf("%s", &s)

        for i := 0; i < len(s); i++ {
                nums = append(nums, s[i:i+1])
        }

        n := len(nums) - 1

        for bit := 0; bit < (1 << n); bit++ {
                var r []int
                for i := 0; i < n; i++ {
                        if bit&(1<<i) >= 1 {
                                r = append(r, i)
                        }
                }

                var nn []int

                for i := range nums {
                        f := find(r, i-1)
                        if f < len(r) && r[f] == (i-1) { // ある場合はそのままpush
                                ni, _ := strconv.Atoi(nums[i])
                                nn = append(nn, ni)
                        } else if len(nn) >= 1 { // 1つ前が存在する場合は結合する
                                sn := strconv.Itoa(nn[len(nn)-1])
                                ni, _ := strconv.Atoi(sn + nums[i])
                                nn[len(nn)-1] = ni
                        } else {
                                ni, _ := strconv.Atoi(nums[i])
                                nn = append(nn, ni)
                        }
                }

                t := 0
                for _, v := range nn {
                        t += v
                }
                total += t
        }
        fmt.Print(total)
}


Measured memory_bytes: 1940
n = int(input().split()[0])
p_list = list(map(int, input().split()))

r_count = 0
target_index_dict = {}
for i, number in enumerate(p_list):
    if i+1 != number:
        r_count += 1
        target_index_dict[i] = number

if not target_index_dict:
    ans = 'YES'
else:
    if len(target_index_dict) >= 3:
        ans = 'NO'
    else:
        a_key = list(target_index_dict.keys())[0]
        a_value = target_index_dict[a_key]
        b_key = list(target_index_dict.keys())[1]
        b_value = target_index_dict[b_key]
        if (a_key+1 == b_value) and (b_key+1 == a_value):
            ans = 'YES'

print(ans)

Measured memory_bytes: 3064
N,M = map(int,input().split())

L = []
R = []

for i in range(M) :
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

left = max(L)
right = min(R)

ans = max(0, right-left+1)

print(ans)

Measured memory_bytes: 11016
N = int(input())
cur = [('a', 0)]
for _ in range(N-1):
    new = []
    for s, c in cur:
        for i in range(c + 2):
            new.append((s + chr(ord('a') + i), max(i, c)))
    cur = new
for s, c in cur:
    print(s)

Measured memory_bytes: 21592
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        HashMap<Integer,Integer>[] map = new HashMap[N+1];
        for(int i=0;i<=N;i++) map[i]=new HashMap<>();
        for(int i=1;i<=N-1;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            map[a].put(b,c);
            map[b].put(a,c);
        }
        int Q = sc.nextInt();
        int K = sc.nextInt();
        long[] dist = new long[N+1];
        Arrays.fill(dist,-1);
        dist[K]=0;
        LinkedList<Integer> current = new LinkedList<>();
        LinkedList<Integer> next = new LinkedList<>();
        current.add(K);
        while(current.size()>0){
            int now = current.poll();
            for(Integer w:map[now].keySet()){
                if(dist[w]==-1){
                    dist[w]=dist[now]+map[now].get(w);
                    next.add(w);
                }
                if(current.size()==0){
                    current=next;
                    next = new LinkedList<>();
                }
            }
        }
        for(int i=1;i<=Q;i++){
            int x=sc.nextInt();
            int y=sc.nextInt();
            System.out.println(dist[x]+dist[y]);
        }
    }
}


Measured memory_bytes: 195940
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 5005

ll N,M;
ll table[SIZE],rest_min[SIZE];
ll dp[2][SIZE];

int main(){

	scanf("%lld %lld",&N,&M);

	for(int i = 0; i < N; i++){

		scanf("%lld",&table[i]);
	}

	rest_min[N] = BIG_NUM;
	for(int i = N-1; i >= 0; i--){

		rest_min[i] = min(table[i],rest_min[i+1]);
	}

	int CURRENT = 0,NEXT = 1;
	int maximum = -1;

	dp[CURRENT][0] = 1;

	for(int i = 0; i <= N-1; i++){

		for(int k = 0; k <= i+1; k++){

			dp[NEXT][k] = 0;
		}

		if(table[i] > maximum){

			for(int k = 1; k <= i+1; k++){

				dp[NEXT][k] = dp[CURRENT][k-1];
			}

			if(maximum < rest_min[i+1]){
				for(int k = 0; k <= i+1; k++){

					dp[NEXT][k] += dp[CURRENT][i+1-k];
					dp[NEXT][k] %= MOD;
				}
			}

			maximum = table[i];

		}else if(table[i] == rest_min[i]){

			for(int k = 0; k <= i+1; k++){

				dp[NEXT][k] = dp[CURRENT][k];
			}

		}else{

			printf("0\n");
			return 0;
		}
		swap(CURRENT,NEXT);
	}

	ll ans = 0;

	for(int i = N-M; i <= M; i++){

		ans += dp[CURRENT][i];
		ans %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}



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

#define lld long long int
#define llu unsigned long long

int main()
{
    //freopen("input.txt", "w", stdin);

    int x,t,res;

    while(cin>>x>>t)
    {
        if( t >= x)
            res = 0;
        else
            res = x-t;

        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int T;
	scanf("%d", &T);
	for(int ii = 0; ii < T; ++ ii) {
		int N; int D;
		scanf("%d%d", &N, &D);
		int ans = (N / 2 * 254) + (N % 2 == 0 ? -D : +D);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

double n,a,x;
double ans;

int main(){

	scanf("%lf%lf%lf",&n,&a,&x);
	for(int i=n;i>=1;i--){
		double m=2*i;
		double v=(a+(a+(m-1)*x))/m*i;
		ans+=v;
		a=((m+2)*a+5*x)/m;
		x=(m+4)*x/m;
	}
	printf("%.15lf\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	if (n == 3) {
		cout << "2 5 63" << endl;
	}
	else {
		set<int> st;
		st.insert(2);
		st.insert(5);
		st.insert(20);
		st.insert(63);
		n -= 4;
		if (n & 1) {
			st.insert(30);
			n--;
		}
		for (int i = 2; i < 30000 && n > 0; i += 2) {
			if (st.count(i) || st.count(30000-i) || i == 30000-i) continue;
			st.insert(i);
			st.insert(30000-i);
			n -= 2;
		}
		for (int i = 3; i < 30000 && n > 0; i += 3) {
			if (st.count(i) || st.count(30000-i) || i == 30000-i) continue;
			st.insert(i);
			st.insert(30000-i);
			n -= 2;
		}
		for (int i = 5; i < 30000 && n > 0; i += 5) {
			if (st.count(i) || st.count(30000-i) || i == 30000-i) continue;
			st.insert(i);
			st.insert(30000-i);
			n -= 2;
		}
		FORR(x, st) cout << x << " ";
		cout << endl;
	}
	return 0;
}

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

int main()
{
  int n,k;
  cin>>n>>k;
  set<int>ar;
  while(k--)
  {
    int t;
    cin>>t;
    while(t--)
    {
      int a;
      cin>>a;
      ar.insert(a);
    }
  }
  cout<<n-ar.size()<<endl;
}

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

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
1 bubbleSort(A, N) // N 個の要素を含む 0-オリジンの配列 A
2   flag = 1 // 逆の隣接要素が存在する
3   while flag
4     flag = 0
5     for j が N-1 から 1 まで
6       if A[j] < A[j-1]
7         A[j] と A[j-1] を交換
8         flag = 1
             */
            Console.ReadLine();
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var IsContinue = true;
            while(IsContinue)
            {
                IsContinue = false;
                for(var i = arr.Length - 1; i >= 1; --i)
                {
                    if(arr[i] < arr[i - 1])
                    {
                        Swap(ref arr[i], ref arr[i - 1]);
                        IsContinue = true;
                    }
                }
            }
            Console.WriteLine(string.Join(" ", arr));
            Console.WriteLine(SwapCount);
        }

        private static int SwapCount { set; get; } = 0;

        private static void Swap<T>(ref T a, ref T b)
        {
            var t = a;
            a = b;
            b = t;
            SwapCount++;
        }
    }
}


Measured memory_bytes: 18460
#include <iostream>
#include <string>

using namespace std;

bool pal(std::string const& s) {
  return s == std::string(s.rbegin(), s.rend());
}

int main(void) {
    string s;
    cin >> s;
    int n = s.size();
    s = "0" + s;

    if(!pal(s) || s[1] == '0') {
        cout << -1 << endl;
    } else {
        int r = 1;
        for(int i=2; i<=n; i++) {
            cout << r << ' ' << i << endl;
            if(s[i-1] == '1') {
                r = i;
            }
        }
    }
    return 0;
}


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

void fnInput(int &rnLod, int &rnTrk, vector<int> &rvnLod)
{
  cin >> rnLod >> rnTrk;

  rvnLod.resize(rnLod);
  for (int i = 0; i < rnLod; i++)
    cin >> rvnLod[i];
}

int fnSimuAlloc(const vector<int> &cnrvnLod, int nTrk, int nLod)
{
  int nCurLod;
  int nCntTrk = 0;

  for (int i = 0; i < cnrvnLod.size();    )
  {
    if (cnrvnLod[i] > nLod)  return 0;

    nCntTrk++;
    nCurLod = 0;
    while (i < cnrvnLod.size())
    {
      nCurLod += cnrvnLod[i];
      if (nCurLod > nLod)  break;

      i++;
    }
  }
  return (nCntTrk <= nTrk);
}

void fnAlloc(const vector<int> &cnrvnLod, int nTrk, int &rnMinLod)
{
  const int cnnMinLod = 0;
  const int cnnMaxLod = 1000000000;

  int nLow  = cnnMinLod;
  int nHigh = cnnMaxLod;
  rnMinLod = cnnMaxLod;

  while (nLow < nHigh)
  {
    int nLod = (nLow + nHigh) / 2;
    if (fnSimuAlloc(cnrvnLod, nTrk, nLod))
    {
      rnMinLod = min(rnMinLod, nLod);
      nHigh = nLod;
    }
    else
      nLow = nLod + 1;
  }
}

void fnReSult(int nMinLod)
{
  cout << nMinLod << endl;
}

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

  int nLod, nTrk;
  vector<int> vnLod;
  int nMinLod = 0;

  fnInput(nLod, nTrk, vnLod);
  fnAlloc(vnLod, nTrk, nMinLod);
  fnReSult(nMinLod);

  return 0;
}

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

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpl;
typedef vector<vector<long long>> mll;
typedef vector<bool> vbl;

class Graph {
   public:
    enum NodeColor { VISITED, VISITING, UNVISITED };
    struct Node {
        int index;
        vpl adjacent;
        NodeColor color = UNVISITED;
    };
    vector<Node> list;
    int n;
    Graph(int n) {
        list.resize(n);
        for (int i = 0; i < n; i++)
            list[i].index = i;
        this->n = n;
    }
    void add_edge(int u, int v, long long w = 1, bool bidirectional = true) {
        list[u].adjacent.emplace_back(v, w);
        if (bidirectional)
            list[v].adjacent.emplace_back(u, w);
    }

    pair<vll, vll> dijkstra(vll from) {
        vll dist(n, INT64_MAX), parent(n, INT32_MAX);
        priority_queue<pll, vpl, greater<>> q;
        for (auto index : from) {
            dist[index] = 0;
            q.emplace(0, index);
        }
        while (!q.empty()) {
            pll top = q.top();
            q.pop();
            if (top.first > dist[top.second])
                continue;
            for (auto edge : list[top.second].adjacent) {
                if (top.first + edge.second < dist[edge.first]) {
                    dist[edge.first] = top.first + edge.second;
                    parent[edge.first] = top.second - 1;
                    q.emplace(top.first + edge.second, edge.first);
                }
            }
        }
        return {dist, parent};
    }
};

int main() {
    // Prepare the Graph
    int n, m, s;
    cin >> n >> m >> s;
    Graph g(n);
    for (int i = 0; i < m; i++) {
        ll u, v, w;
        cin >> u >> v >> w;
        g.add_edge(u, v, w, false);
    }
    // Get the result from a call to Dijkstra
    pair<vll, vll> res = g.dijkstra({s});
    // Print the outputs
    for (int i = 0; i < n; i++) {
        if (res.first[i] == INT64_MAX)
            cout << "INF" << endl;
        else
            cout << res.first[i] << endl;
    }
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)



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

  ll n;
  cin >> n;
  vll p(n),q(n),c(n);
 rep(i,0,n) c[i]=i+1;
 rep(i,0,n) cin >> p[i];
 rep(i,0,n) cin >> q[i]; 
 
  ll a,b,num=0;
  do{
   num++;
   if(p==c) a=num;
   if(q==c) b=num;
  }while(next_permutation(c.begin(), c.end()));
  
  cout << abs(a-b) << endl;
}

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

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX_N 100

int n,time,head,tail;
int *queue;
int *dist;
int *color;
int* matrix[MAX_N];

void enqueue(int);
int dequeue(void);
void bfs(void);

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);

  queue = malloc(MAX_N * sizeof(int));
  color = malloc(n * sizeof(int));
  dist = malloc(n * sizeof(int));

  for(i = 0 ; i < n ; i++){
    matrix[i] = malloc(n * sizeof(int));
  }
 for(i = 0 ; i < n ; i++){
   dist[i] = -1;
 }
 for(i = 0 ; i < n ; i++){
   for(j = 0 ; j < n ; j++){
     matrix[i][j] = 0;
   }
 }

 for(i = 0 ; i < n ; i++){
    scanf("%d",&u); u--;
    scanf("%d",&k);
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v); v--;
      matrix[u][v] = 1;
    }
  }

  bfs();
  for(i = 0 ; i < n ; i++){
    printf("%d %d\n",i+1,dist[i]);
  }

  for(i = 0 ; i < n ; i++){
    free(matrix[i]);
  }
  free(queue);
  free(dist);
  free(color);
  return 0;
}

void bfs(){
  int u,i;

  head = tail = 0;
  color[0] = GRAY;
  dist[0] = 0;
  enqueue(0);

  while(head != tail){
    u = dequeue();
    for(i = 0 ; i < n ; i++){
      if(matrix[u][i] == 1 && color[i] == WHITE){
        color[i] = GRAY;
        dist[i] = dist[u] + 1;
        enqueue(i);
      }
    }
    color[u] = BLACK;
  }
}

void enqueue(int q){
  queue[tail] = q;
  if(++tail == n+1) tail = 0;
}

int dequeue(){
  int v = queue[head];
  if(++head == n+1) head = 0;
  return v;
}

Measured memory_bytes: 636
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int L[11];
    rep(i, N) cin >> L[i];
    sort(L, L + N);
    int sum = 0;
    rep(i, N - 1) sum += L[i];
    if (sum > L[N - 1]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256