akhauriyash/Code-Regression huggingface dataset:
while 1:
    n=input()
    if n==0:break
    t=[map(int,raw_input().split()) for i in [1]*n]
    t=sorted(sorted(sorted(t),key=lambda x:x[3])[::-1],key=lambda x:x[2])[::-1]
    u=[0]*1001
    s=0
    for i in t:
        if (s<10 and u[i[1]]<3) or (s<20 and u[i[1]]<2) or (s<26 and u[i[1]]<1):
            print i[0]
            u[i[1]]+=1
            s+=1

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

const int N = (int)1e6;

char s[N+5];
int carry[N+5];

int main() {
    for (int i=0; i<N+3; i++) carry[i] = 0;

    scanf("%s", s+1); s[0] = '0';
    int n = strlen(s+1);

    int res = 0;
    for (int i=n; i>=0; i--) {
        assert('0' <= s[i] && s[i] <= '9' + 1);
        assert(0 <= carry[i] && carry[i] <= 1);

        if (s[i] >= '5' && carry[i]) {
            res += '9' - s[i];
            s[i] = '0';
            if (s[i-1] >= '5') {
                carry[i-1] += 1;
            } else {
                s[i-1] += 1;
            }
        } else {
            if (s[i] > '5') {
                res += ('9' + 1) - s[i];
                s[i] = '0';
                s[i-1] += 1;
            } else if (s[i] == '5' && s[i-1] >= '5') {
                res += ('9' + 1) - s[i];
                s[i] = '0';
                carry[i-1] += 1;
            } else if (s[i] <= '5') {
                res += s[i] - '0';
            }
        }
    }

    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1ll << 60;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

#ifdef WIN32
#define dump(x) cout << #x << " = " << (x) << "\n"
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n"
#else
#define dump(x)
#define debug(x)
#endif

int n;
LL dp[ 101 ][ 21 ];
VI a;

void solve() {
	CLR( dp );
	dp[ 1 ][ a[ 0 ] ] = 1;
	for ( int i = 1; i < n - 1; i++ ) {
		for ( int j = 0; j <= 20; j++ ) {
			if ( j - a[ i ] >= 0 ) {
				dp[ i + 1 ][ j ] += dp[ i ][ j - a[ i ] ];
			}
			if ( j + a[ i ] <= 20 ) {
				dp[ i + 1 ][ j ] += dp[ i ][ j + a[ i ] ];
			}
		}
	}
	LL ans = dp[ n - 1 ][ a[ n - 1 ] ];
	cout << ans << "\n";
}

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 );
#ifdef WIN32
	srand( ( uint ) time( NULL ) );
	cout << "Debug Mode\n";
	while ( true ) {
		n = rand() % 101;
		if ( n ) {
			n = max( n, 3 );
		}
		cout << "n = " << n << "\n";
		if ( n == 0 ) {
			break;
		}
		a.resize( n );
		for ( int i = 0; i < n; i++ ) {
			a[ i ] = rand() % 10;
			cout << a[ i ] << " ";
		}
		cout << "\n";
		solve();
	}
	return 0;
#endif
	cin >> n;
	a.resize( n );
	for ( int i = 0; i < n; i++ ) {
		cin >> a[ i ];
	}
	solve();
	return 0;
}

Measured memory_bytes: 1220
/*
 * @Author: Kaizyn
 * @Date: 2020-03-28 21:07:03
 * @LastEditTime: 2020-03-28 21:10:45
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int MOD = 998244353;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> pii;

int n;

inline void solve()
{
    cin >> n;
    long long res = 0;
    res += n/500*1000;
    n %= 500;
    res += n/5*5;
    cout << res << endl;
}
    

signed main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcase = 1;
    // cin >> testcase;
    for (int i = 1; i <= testcase; ++i) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int N[4], i;
	int check[4] = {0};
	scanf("%d %d %d %d", &N[0], &N[1], &N[2], &N[3]);	
	for (i = 0; i < 4; i++) {
		if(N[i] == 1) { check[0] += 1; }
		if(N[i] == 4) { check[1] += 1; }
		if(N[i] == 7) { check[2] += 1; }
		if(N[i] == 9) { check[3] += 1; }
	}
	for (i = 0; i < 4; i++) {
		if (check[i] != 1) {
			printf("NO\n");
			return 0;			
		}
	}
	printf("YES\n");
	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL n, m;
    cin >> n >> m;
    LL res = (min(n, m / 2));
    m -= n * 2;
    if(m > 0) {
        res += m / 4;

    }
    cout << res << endl;

    return 0;
}



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

int main() {
  vector<char> n(4);
  for(int i = 0; i < 4; i++) {
    cin >> n.at(i);
    if(i != 0) {
      if(n.at(i) == n.at(i-1)) {
        cout << "Bad" << endl;
        break;
      }
    }
    
    if(i == 3) {
      cout << "Good" << endl;
    }
  }
}

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

int main(){
  double n;
  double goukei = 0;
  cin >> n;
  vector<double> a(n);
  for(int i = 0;i < n;i++){
    cin >> a.at(i);
    goukei += a.at(i);
  }
  double av = goukei/n;
  int kekka = 0;
  double d = abs(a.at(0) - av);
  for(int i = 1;i < n;i++){
    double cur = abs(a.at(i) - av);
    if(cur < d){
      kekka = i;
      d = cur;
    }
  }
  cout << kekka << endl;
}
             
    

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int[] counts = {0,0,0};
    for(int i = 0; i < N; i++){
      int tmp = sc.nextInt();
      if(tmp <= A){
        counts[0]++;
      }else if(tmp <= B){
        counts[1]++;
      }else{
        counts[2]++;
      }
    }
    System.out.println(Math.min(counts[0], Math.min(counts[1], counts[2])));
  }
}

Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=500 +117;
const int MM=400 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
int col[2*NN]={};
int main(){
	//open();
	int k=read();
	if(k==1){
		printf("1\n1\n");
		return 0;
	}
	n=(k+3)/4*2;
	for(int i=0;i<2*n;++i){
		col[i]=i+1;
	}
	for(int i=2*n-1;i>=0;--i){
		if(col[i]>k)col[i]-=n;
	}
	printf("%d\n",n);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(i&1){
				printf("%d ",col[(i+j)%n]);
			}
			else printf("%d ",col[(i+j)%n+n]);
		}
		putchar('\n');
	}
	close();
	return 0;
}

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

int main(){
    ll Q;
    cin >> Q;

    map<string, ll> mp;

    while(Q--){
        ll a;
        string key;
        cin >> a >> key;

        if(a==0){
            // insert
            ll x; cin >> x;
            mp[key] = x;
        }
        else if(a==1){
            // get
            p(mp[key]);
        }
        else{
            // delete
            mp.erase(key);
        }
    }

    return 0;
}


Measured memory_bytes: 27848
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

string s;
ll q;
vi v;
string fr,ed;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>s;
    cin>>q;
    ll t,f;
    string c,ss;
    ll former = 0;
    rep(i,q){
        cin>>t;
        if(t==1){
            former = (former+1)%2;
        }else{
            cin>>f>>c;
            if(former==0){
                if(f==2)ed += c;
                else{
                    c += fr;
                    fr = c;
                }
            }else{
                if(f==1)ed += c;
                else{
                    c += fr;
                    fr = c;
                }
            }
        }
    }
    s+=ed;
    fr += s;
    if(former == 1)reverse(all(fr));
    print(fr);
    return 0;
}

Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main() {
	long long x,k,d; scanf("%lld%lld%lld",&x,&k,&d);
	long long steps=abs(x)/d;
	if(k<=steps){
		printf("%lld\n",abs(x)-(k*d));
		return 0;
	}
	else{
		int rem=k-steps;
		if(rem%2==0){
			printf("%lld\n",abs(x)-(steps*d));
		}
		else{
			printf("%lld\n",abs(abs(x)-((steps+1)*d)));
		}
	}
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  int a, b; cin >> a >> b;
  auto ans = a < 10 && b < 10;

  cout << (ans ? a * b : -1) << CRLF;
  return;
}

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

  solve();

  return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define sz(a) (int)(a).size()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

int main() {

    //ifstream cin("defend.in");
    //freopen("defend.out", "w", stdout);
    //ifstream cin("input.txt");

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

    string s;
    cin >> s;

    if (sz(s) >= 4 && s.substr(0, 4) == "YAKI") {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

}


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

int main(){
	int N , K , x , sum = 0;
  	cin >> N >> K;
  	for (int i = 0 ; i < N ; i++){
    	cin >> x;
        if (x < K - x)
        	sum += x ;
        else
          	sum += K - x;
    }
  	cout << sum * 2 << endl;
}

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

static const int N = 1000;

int max(int s,int t){
if (s>=t) return s;
return t;
}

int lcs(char X[], char Y[], int m ,int n) {
  int c[N + 1][N +1];
  int maxl = 0,i,j;

  strcmp(&X[0], " ");
  strcmp(&Y[0], " ");
  //X[0] = ' ';
  //Y[0] = ' ';
  for(i=0;i<=m;i++) c[i][0]=0;
  for(j=0;j<=n;j++) c[0][j]=0;

  for(i = 1;i <=m; i++) {
    for(j = 1;j <=n; j++) {
    if(X[i] == Y[j]) {
      c[i][j] = c[i-1][j-1] + 1;
    } else {
      c[i][j] = max(c[i-1][j] , c[i][j-1]);
    }
    maxl = max(maxl,c[i][j]);
  }
}

return maxl;
}


int main() {
  char s1[1001],s2[1001];
  int i,n;

  scanf("%d\n", &n);
  for (i=0;i<n;i++) {
    scanf("%s", &s1[1]);
    scanf("%s", &s2[1]);
    printf("%d\n", lcs(s1,s2,(int)strlen(&s1[1]),(int)strlen(&s2[1])));
  }
  return 0;
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 2005, INF = 1e9 + 5;
int a[N], b[N], c[N];
bool used[N];

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

    int n, k, q;
    cin >> n >> k >> q;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }


    int ans = INF;

    for (int h = 0; h < n; h++) {

        for (int i = 0; i < n; i++) {
            c[i] = (a[i] < a[h]);
        }

        // if (k == 0) {
        //     for (int i = 0; i < n; i++)
        //         cout << c[i];
        //     cout << "\n";
        // } 

        int l = 0, r = INF;
        while (r - l > 1) {
            int p = (l + r) >> 1;

            for (int i = 0; i < n; i++) {
                b[i] = (a[i] <= p);
            }

            // if (p == 5 && h == 3) {
            //     for (int i = 0; i < n; i++) {
            //         cout << b[i];
            //     }
            //     cout << "\n";
            //     for (int i = 0; i < n; i++) {
            //         cout << c[i];
            //     }
            //     cout << "\n";
            // }

            fill(used, used + n, 0);

            int z = 0, cq = 0, y = 0, ct = k;
            for (int i = 0, j = k - 1; j < n; j++, ct++) {

                // if (p == 623690081 && a[h] == 211047202) {
                //     cout << i << " " << j << " " << ct << "\n";
                // }


                while (ct > k) {
                    ct -= !used[i];
                    i++;
                }

                if (ct < k)
                    break;

                y = max(i, y);
                z = max(i, z);

                while (y < n && c[y] == 0)
                    y++;

                if (y <= j)
                    continue;

                while (true) {
                    while (z < n && b[z] == 0)
                        z++;
                    if (z > j)
                        break;
                    used[z] = true;
                    j++;
                    cq++;
                    z++;
                    if (j >= n || y <= j)
                        break;
                }
            }

            if (cq >= q) {
                r = p;
            }
            else {
                l = p;
            }
        }

        
        if (r != INF) {
            // cout << r << " " << a[h] << " " << r - a[h] << "\n";
            ans = min(ans, r - a[h]);
        }
    }

    cout << ans;

    return 0;   
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

#include <complex>
using C = complex<double>;
int n;
vector<C> z;

int main() {
    cin >> n;
    z.resize(n);
    for (int i = 0; i < n; ++i) {
        double x, y;
        cin >> x >> y;
        z[i] = {x, y};
    }

    vector<C> ps;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            ps.push_back((z[i] + z[j]) / 2.0);
            for (int k = j + 1; k < n; ++k) {
                double a = norm(z[j] - z[k]), b = norm(z[k] - z[i]), c = norm(z[i] - z[j]),
                       s = a * (b + c - a), t = b * (c + a - b), u = c * (a + b - c);
                if (s + t + u == 0.0) continue;
                C w = (s * z[i] + t * z[j] + u * z[k]) / (s + t + u);
                ps.push_back(w);
            }
        }
    }

    double ans = 1e18;
    for (auto p : ps) {
        double res = 0;
        for (auto q : z) {
            res = max(res, abs(p - q));
        }
        // cerr << p << ' ' << res << endl;
        ans = min(ans, res);
    }

    printf("%.15f\n", ans);
}

Measured memory_bytes: 892
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		long a = scn.nextLong();
		long b = scn.nextLong();
      	long c = scn.nextLong();
      	long x = 2*(a*b + b*c + c*a);
      	long y = a*a + b*b + c*c;
      	long z = c - a - b;
      	String ans = "No";
      	if(z>0 && x<y) ans = "Yes";
      	System.out.println(ans);
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

struct BIT{
  int n;
  vector<ll> bit;
  BIT(int size):n(size),bit(size+1,0){}

  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }

  void add(int i,ll v){
    if(i==0)return ;
    while(i<=n){
      bit[i]+=v;
      i+=i&-i;
    }
  }

  ll lower_bound(ll w){
    if(w<=0)return 0;
    ll x=0,r=1;
    while(r<n)r<<=1;
    for(ll k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
        w-=bit[x+k];
        x+=k;
      }
    }
    return x+1;
  }
};

void ansquery(string name,bool iswork){
  if(iswork){
    cout<<name<<" is working hard now."<<endl;
  }else{
    cout<<name<<" is not working now."<<endl;    
  }
}

struct member{
  string name;
  int mtv,t;
};
bool operator<(const member& a,const member& b){
  if(a.mtv==b.mtv) return a.t < b.t;
  else return a.mtv < b.mtv;
}

int N,Q,T,M;
set<member> s1,s2;
map<string,member> mems;

int main(){
  cin>>N;
  BIT bit(100010);
  rep(i,N){
    member m;
    cin>>m.name>>m.mtv;
    m.mtv++;
    bit.add(m.mtv,1);
    m.t=T++;
    s1.insert(m);
    mems[m.name]=m;
  }
  M=N/5;
  while(s1.size()>M){
    member m=*s1.begin();
    s1.erase(m); s2.insert(m);
  }
  cin>>Q;
  while(Q--){
    char typ;
    cin>>typ;
    if(typ=='+'){
      N++;
      M=N/5;
      member m;
      cin>>m.name>>m.mtv;
      m.mtv++;
      m.t=T++;
      mems[m.name]=m;
      int hnum=bit.sum(100010)-bit.sum(m.mtv);
      if(hnum<M){
        s1.insert(m);
        ansquery(m.name,true);
      }else{
        s2.insert(m);
        ansquery(m.name,false);
      }
      bit.add(m.mtv,1);
    }else{
      N--;
      M=N/5;
      member m;
      cin>>m.name;
      m=mems[m.name];
      bit.add(m.mtv,-1);
      if(s1.count(m)) s1.erase(m);
      else s2.erase(m);
    }
    if(s1.size()<M){
      member m2=*s2.rbegin();
      s2.erase(m2); s1.insert(m2);
      ansquery(m2.name,true);
    }
    if(s1.size()>M){
      member m2=*s1.begin();
      s1.erase(m2); s2.insert(m2);
      ansquery(m2.name,false);
    }
  }
  return 0;
}



Measured memory_bytes: 13164
N,A,B = gets.split.map(&:to_i)

sum = 0
(1..N).each do |n|
  _sum = 0
  n.to_s.chars do |c|
    _sum += c.to_i
  end
  if _sum >= A && _sum <= B
    sum += n
  end
end

puts sum

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

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            // 標準入力:A,B,C,K
            string[] sline = Console.ReadLine().Split(" ");
            int a = int.Parse(sline[0]);
            int b = int.Parse(sline[1]);
            int c = int.Parse(sline[2]);
            int k = int.Parse(sline[3]);

            if (a > k)
            {
                Console.WriteLine(k);
            }
            else if (a + b >= k)
            {
                Console.WriteLine(a);
            }
            else
            {
                if (c < k - (a + b))
                {
                    // 残りの使える枚数より、cのが多い
                    int ans = a - c;
                    if (ans < 0)
                        ans = 0;
                    Console.WriteLine(ans);
                }
                else
                {
                    // 残りの使える枚数の方が、cより多い
                    int ans = a - (k - (a + b));
                    Console.WriteLine(ans);
                }
            }
        }
    }
}


Measured memory_bytes: 27508
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int N;cin>>N;
  int ans=0;
  for(int i=1;i*i<=N;i++){
    ans=max(ans,i*i);
  }
  cout<<ans<<endl;
}







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

int main() {
  
  char let;
  cin >> let;
  
  if(let=='a'||let=='i'||let=='u'||let=='e'||let=='o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
  
}

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

int main() {
int h,w;
cin >> h >> w;
int count = 0;
string s;
string arr[h];
while(cin >> s) {
arr[count] = s;
++count;
}

for(int i = 0; i < count; ++i) {
cout << arr[i] << "\n" << arr[i] << "\n";
}
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b,c; cin >> a >> b >> c; 
    if(a+b+c >= 22) OUT("bust");
    else OUT("win");

    return 0;
}

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

#define int long long int

void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif
//!

int32_t main()
{
	GO
	//fioe();
	string s;
	cin>>s;bool flag = false;
	for(int i=0;i<s.length();i++){
		if(s[i] == '7')
			flag = true;
	}	
	if(flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;	
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int main(void){
    int n; cin >> n;
    cout << 800*n - (200 * (n/15)) << endl;
    return 0;
}


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

using namespace std;

long find(const vector<int>& a, int x)
{
    long steps = 0;
	long sum = a[0] + a[1];
	for (int i = 1; i < a.size() - 1; ++i) {
        int tmp = a[i];
        if (sum > x) {
            int diff = sum - x;
            tmp -= diff;
            if (tmp < 0) tmp = 0;
            steps += diff;
        }
        sum = tmp + a[i + 1];
	}
    return steps;
}

int main()
{
	int N, x;
	cin >> N >> x;
	vector<int> a(N + 1, 0);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	cout << find(a, x) << endl;
	return 0;
}

Measured memory_bytes: 768
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 64 * 1024
	maxBufSize     = 10000000
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

func main() {
	scanner.Split(bufio.ScanWords)
	n := scanInt()
	count := make(map[string]int, n)
	for i := 0; i < n; i++ {
		count[scanText()]++
	}

	var ans []string
	most := 0

	for k, v := range count {
		if v >= most {
			if v > most {
				ans = make([]string, 0, n)
			}
			ans = append(ans, k)
			most = v
		}
	}
	sort.Strings(ans)
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

func min(n []int) (min, idx int) {
	min = math.MaxInt64
	for i := 0; i < len(n); i++ {
		if n[i] < min {
			min = n[i]
			idx = i
		}
	}
	return
}

func max(n []int) (max, idx int) {
	max = math.MinInt64
	for i := 0; i < len(n); i++ {
		if n[i] > max {
			max = n[i]
			idx = i
		}
	}
	return
}


Measured memory_bytes: 18944
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define rep_r(i,n) for(i=n-1;i>=0;i--)
#define debug_i(x) printf("x:%d\n",x)
#define debug_f(x) printf("x:%f\n",x)
#define debug_s(str) printf("str:%s\n",str)
#define debug_c(c) printf("c:%c\n",c)
#define s_i1(x) scanf("%d",&x)
#define s_i2(x,y) scanf("%d %d",&x,&y)
#define s_i3(x,y,z) scanf("%d %d %d",&x,&y,&z)
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
///////////////////////
static int num[100000]={};

int primecount(int N)
{
	int i,j;
	int count=0;
	int box[100000]={};

	rep_to(2,i,N)box[i]=1;
	rep_to(2,i,sqrt(N))
	{
		for(j=i;j*i<N;j++)box[i*j]=0;
	}

	j=0;
	rep_to(2,i,N)
	{
		if(box[i]==1)
		{
			num[j]=i;
			j++;
		}
	}
	return j;
}
int tansaku(int max,int search)
{
	int min=0;
	int flag=0;
	int mark=0;
	while(min<=max)
	{
		mark=(min+max)/2;
		if(search>num[mark])min=mark+1;
		else if(search<num[mark])max=mark-1;
		else 
		{
			flag=1;
			break;
		}
	}
	return flag;
}

int main()
{
	int N,i,j,max,count=0,search=0;
	max=primecount(50000);
	while(s_i1(N)!=EOF)
	{
		if(N==0)break;
		count=0;
		search=0;
		rep(i,max)
		{
			search=N-num[i];
			if(num[i]>N/2)break;
			if(tansaku(max,search)==1)count++;
		}
		printf("%d\n", count);
	}
	return 0;
}

Measured memory_bytes: 1444
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    int n;
    string s, t;
    int same = 0;

    cin >> n >> s >> t;

    for (int i = 1; i <= n; i++) {
        if (t.find(s.substr(0, i))+s.substr(0, i).size() == t.size()
            && same < s.substr(0, i).size()) {
            same = s.substr(0, i).size();
        }
    }

    for (int i = 1; i <= n; i++) {
        if (s.find(t.substr(0, i))+t.substr(0, i).size() == s.size()
            && same < t.substr(0, i).size()) {
            same = t.substr(0, i).size();
        }
    }

    cout << n*2-same << endl;

}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
while True:
    H, W = map(int, input().rstrip().split())
    if H == W == 0:
        break
    for i in range(H):
        for j in range(W):
            if j == W - 1:
                print("#")
            else:
                print("#", end="")
    print()
    


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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

long long n;
set <long long> ansv;

bool go(long long div) {
    long long cur = n;
    while (cur >= div) {
        if (cur % div == 0) {
            cur /= div;
        } else {
            cur %= div;
        }
    }
    return cur == 1;
}

int main() {

    cin >> n;
    ansv.insert(n);

    long long m = n - 1;
    for (long long i = 1; i * i <= m; i++) {
        if (m % i == 0) {
            if (i != 1) ansv.insert(i);
            if (m / i != i) ansv.insert(m / i);
        }
    }

    vector <long long> divs;
    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            divs.push_back(i);
            if (n / i != i) divs.push_back(n / i);
        }
    }
    sort(all(divs));

    for (long long div : divs) {
        if (go(div)) {
            ansv.insert(div);
        }
    }

    cout << sz(ansv) << endl;

    return 0;
}


Measured memory_bytes: 384
n = gets.to_i
a = n.times.map{gets.chomp}

p a.map!{|s| s.split("").sort.join}.group_by(&:itself).map{ |key, value| [key, value.count] }.to_h.values.select{|x| x>1}.inject(0){|i, j| i+=(j>1 ? j*(j-1)/2 : 0)}


Measured memory_bytes: 51860
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 10000000001
#define DIM 200001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define gg exit(0)
#define T true
#define F false
#define endl "\n"
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sl;
typedef queue < long long > que;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;
ll t,n,z,x,c;
st s;
int main()
{
    cin>>n;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')x++;
    }
    cout<<x<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20190324_03 {
    class Program {
        static void Main(string[] args) {
            var line0 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var n = line0[0];
            var q = line0[1];
            var s = Console.ReadLine();            
            var dict = new Dictionary<int, int>();
            var count = 0;
            bool isA = false;
            for (int i = 0; i < n; i++) {
                if (s[i] == 'C' && isA) {
                    count++;
                }
                if (s[i] == 'A') {
                    isA = true;
                } else {
                    isA = false;
                }
                dict[i + 1] = count;
            }
            var ans = new List<int>();
            for (int i = 0; i < q; i++) {
                var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                var l = line[0];
                var r = line[1];
                ans.Add(dict[r] - dict[l]);
            }
            foreach (var item in ans) {
                Console.WriteLine(item);
            }
        }
    }
}


Measured memory_bytes: 24504
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int INF=1001001001;

int main(){
    int N,X,Y; cin >> N >> X >> Y;
    --X; --Y;
    vector <int> ans(N);
    rep(i,N){
        vector <int> dist(N,INF);
        queue <int> q;
        auto push=[&](int v, int d){
            if(dist[v] != INF) return;
            dist[v]=d;
            q.push(v);
        };
        
        push(i,0);
        while(!q.empty()){
            int v=q.front(); q.pop();  //セットで
            int d=dist[v];
            if(v-1>=0) push(v-1,d+1);
            if(v+1<N) push(v+1,d+1);
            if(v==X) push(Y,d+1);
            if(v==Y) push(X,d+1);
        }
        rep(i,N) ans[dist[i]]++;
    }
    rep(i,N) ans[i]/=2;
    for (int i=1; i<=N-1; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
    while(true){
        string cards;
        cin >> cards;
        if(cards == "-") break;
        int m;
        cin >> m;
        for(int i = 0; i != m; ++i){
            int h;
            cin >> h;
            cards = cards.substr(h) + cards.substr(0, h);
        }
        cout << cards << endl;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#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, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;
    string a = S.substr(0, N / 2);
    string b = S.substr(N / 2, N/2);
    if (N % 2 != 0) {
        cout << "No" << endl;
    } else if (a == b) {
        cout << "Yes" << endl;
    } else
    {
        cout << "No" << endl;
    }
    // cout << a << " " << b << endl;
    return 0;
}

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


int main() {
	int a, b;
  	cin >> a >> b;
  	if (a >= 1 && a <= 9 && b >= 1 && b <= 9) cout << a * b << endl;
  	else cout << -1 << endl;
	return 0;

}

Measured memory_bytes: 256
from fractions import gcd
n, m = map(int, input().split())
aa = list(map(int, input().split()))


lcm = 1
def p2(m):
    cnt = 0
    n = m
    while 1:
        if n%2 == 0:
            cnt += 1
            n = n//2
        else:
            break
    return cnt
pp = p2(aa[0])
for a in aa:
    lcm = a * lcm // gcd(a, lcm)
    if pp != p2(a):
        lcm = 10 **18
        break
tmp = lcm // 2
print((m // tmp + 1) // 2)

Measured memory_bytes: 16320
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<50);

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

struct edge{
    int to, cost;
    edge(){}
    edge(int a, int b){
        to = a;
        cost = b;
    }
};
typedef vector<edge> ve;
ll dfs(vector<ve> &G, mat &dp, int s, int v){
    if(dp[s][v] != -1) {
        return dp[s][v];
    }else if(s == (1<<N) - 1){
        return INF;
    }
    dp[s][v] = INF;
    for(edge e : G[v]){
        if(!((s>>e.to)&1)){
            chmin(dp[s][v], dfs(G, dp, s | (1<<e.to), e.to) + e.cost);
        }
    }
    return dp[s][v];
}

int main() {
    cin>>N>>M;
    vector<ve> G(N, ve(0));
    rep(i,M){
        int s, t, d;
        cin>>s>>t>>d;
        G[s].emplace_back(t, d);
    }
    mat dp((1<<N), vec(N, -1));
    dp[(1<<N) - 1][0] = 0;
    cout<<(dfs(G, dp, 0, 0) == INF ? -1 : dp[0][0])<<endl;
}


Measured memory_bytes: 7632
#include<bits/stdc++.h>
using namespace std;
#define int long long int

signed main()
{
 int a[6];
    for(int i=1;i<=5;i++)
        cin>>a[i];
     for(int i=1;i<=5;i++)
        {
            if(a[i]==0)
                cout<<i<<endl;

        }
}




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

inline int read()
{
	int s = 0,f = 1; char ch;
	while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
	while(isdigit(ch)) s =s * 10 + ch - '0',ch =  getchar();
	return s * f;
}

typedef long long i64;
typedef std::multiset<i64> Set;

const int N = 2e5 + 3;
int x,z,y,n;
i64 sum = 0,pre[N],suf[N];
struct Tuple
{
	i64 a,b,c;
	inline bool operator<(const Tuple& rhs) const
	{
		return b - c > rhs.b - rhs.c;
	}
};
Tuple tuple[N];
Set queue;

inline void chkMax(i64& x,i64 y)
{
	if(x < y) x = y;
}

inline void preparePre()
{
#define VAL (tuple[i].b - tuple[i].a)
	for(int i = 1;i <= y;i++)
		pre[y] += VAL,queue.insert(VAL);
	for(int i = y + 1;i <= n - z;i++) /*FIXME*/ {
		queue.insert(VAL);
		if(*queue.begin() == VAL) pre[i] = pre[i - 1];
		else pre[i] = pre[i - 1] - *queue.begin() + VAL;
		queue.erase(queue.begin());
	}
#undef VAL
}

inline void prepareSuf()
{
#define VAL (tuple[i].c - tuple[i].a)
	queue.clear();
	for(int i = n;i >= n - z + 1;i--)
		suf[n - z + 1] += VAL,queue.insert(VAL);
	for(int i = n - z;i >= y + 1;i--) {
		queue.insert(VAL);
		if(*queue.begin() == VAL) suf[i] = suf[i + 1];
		else suf[i] = suf[i + 1] - *queue.begin() + VAL;
		queue.erase(queue.begin());
		/*FIXME*/
	}
#undef VAL
}

int main()
{
	x = read(),y = read(),z = read(),n = x + y + z;
	for(int i = 1;i <= n;i++) {
		tuple[i].a = read(),tuple[i].b = read(),tuple[i].c = read();
		sum += tuple[i].a;
	}

	std::sort(tuple + 1,tuple + 1 + n);

	preparePre();
	prepareSuf();
	i64 ans = LLONG_MIN;
	for(int i = y;i <= n - z;i++)
		chkMax(ans,pre[i] + suf[i + 1]);
	printf("%lld\n",ans + sum);
	exit(0);
}


Measured memory_bytes: 10752
#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>

using namespace std;
#define N 4
#define N2 16

static const int  dx[4]  = {0, -1, 0, 1};
static const int  dy[4]  = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle {
	int f[N2], space, MD;
	int cost;

	bool operator < (const Puzzle &p) const {
		for(int i = 0; i < N2; i++){
			if(f[i] == p.f[i]) continue;
			return f[i] < p.f[i];
		}
		return false;
	}
};

struct State {
	Puzzle puzzle;
	int estimated;
	bool operator < (const State &s) const {
		return estimated > s.estimated;
	}
};

int getAllMD(Puzzle pz){
	int sum = 0;
	for(int i = 0; i < N2; i++){
		if(pz.f[i] == N2) continue;
		sum += MDT[i][pz.f[i] - 1];
	}
	return sum;
}

int astar(Puzzle s){
	priority_queue<State> PQ;
	s.MD = getAllMD(s);
	s.cost = 0;
	map<Puzzle, bool> V;
	Puzzle u, v;
	State initial;
	initial.puzzle = s;
	initial.estimated = getAllMD(s);
	PQ.push(initial);

	while(!PQ.empty()){
		State st = PQ.top();
		PQ.pop();
		u = st.puzzle;

		if(u.MD == 0) return u.cost;
		V[u] = true;

		int sx = u.space / N;
		int sy = u.space % N;

		for(int r = 0; r < 4; r++){
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
			v = u;

			v.MD -= MDT[tx * N + ty][v.f[tx * N + ty] - 1];
			v.MD += MDT[sx * N + sy][v.f[tx * N + ty] - 1];
			swap(v.f[sx * N + sy], v.f[tx * N + ty]);
			v.space = tx * N + ty;
			if(!V[v]){
				v.cost++;
				State news;
				news.puzzle = v;
				news.estimated = v.cost + v.MD;	//f(n) = g(n) + h(n)
				PQ.push(news);
			}
		}
	}

	return -1;
}

int main(){
	for(int i = 0;i < N2; i++){
		for(int j = 0; j < N2; j++){
			MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
		}
	}

	Puzzle in;

	for(int i = 0; i < N2; i++){
		cin >> in.f[i];
		if(in.f[i] == 0){
			in.f[i] = N2;
			in.space = i;
		}
	}
	cout << astar(in) << endl;

	return 0;
}


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

int main(){
    int n;
    cin>> n;
    string s;
    cin >> s;
    rep(i,s.size()){
        s[i]=(s[i]-'A'+n)%26 + 'A';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3600