akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int main() {
	long long int ans = 0, s, c;
	cin >> s >> c;
	if (s <= c/2) { ans += s; c -= 2 * s;
	ans += c / 4;
	}
	else {
		ans += c / 2;
	}
	cout << ans << "\n";
	cin >> s;
	return 0;
}

Measured memory_bytes: 764
#include<stdio.h>

#define NUMBER 100


void print_array(int array[],int num)
{
	int i;
	
	for(i = 0; i < num - 1; i++){
		
		printf("%d ", array[i]);
	}
	printf("%d\n", array[i]);
	
}
	
void insertSort(int array[],int num)
{
	int i, v, j;
	for(i = 1; i <= num - 1; i++){
		print_array(array, num);
		v = array[i];
		j = i - 1;
		while(j >= 0 && array[j] > v){
			array[j + 1] = array[j];
			j--;
			
		}
		array[j + 1] = v;
	
    }
}

int main(void)
{
	int i, num;
	int array[NUMBER];

	scanf("%d", &num);
	
	for(i = 0; i < num; i++)
	{
		scanf("%d", &array[i]);
	}
	
	insertSort(array , num);
	
	print_array(array , num);
	
	
	return 0;
}


Measured memory_bytes: 2056
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  for j in range(len(A)-1,-1,-1):
    if A[j]==j+1:
      B.append(A.pop(j))
      break
  else:
    print(-1)
    exit()

for i in B[::-1]:
  print(i)

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

void solve(){
	
	int n ;
	cin>>n ;

	priority_queue<int,vector<int>,greater<int>> pq1 ;
	priority_queue<int,vector<int>,greater<int>> pq2 ;

	int sum=0 ;

	rep(i,n){

		int x ;
		cin>>x ;

		if(x%10==0)
			pq1.push(x) ;
		else
			pq2.push(x) ;

		sum+=x ;

	}
 
	if(pq2.empty()){
		cout<<0 ;
		return ;
	}
	else{

		if(sum%10==0)
		{
			sum-=pq2.top() ;
			pq2.pop() ;
		
			cout<<sum ;
			return ;
		}
		else{

			cout<<sum ;
			return ;

		}

	}

}

int main(){

	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

//typedef uint64_t hash_t;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int HASH_COUNT = 2;
//const hash_t HASH_P = (uint32_t)-13337;
//uniform_int_distribution<hash_t> MULT_DIST(0.25 * HASH_P, 0.75 * HASH_P);
//const hash_t HASH_MULT[HASH_COUNT] = {MULT_DIST(rng), MULT_DIST(rng)};

int n, k;

int inp[N + N];
int inc[N + N];

int f(){
  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(inp[i] > inp[i - 1]){
      inc[i] = inc[i - 1] + 1;
    } else {
      inc[i] = 1;
    }
  }
  if(inc[k] < k){
    ans++;
  }
  set < int > mySet;
  for(int i = 1; i <= k; i++){
    mySet.insert(inp[i]);
  }
  for(int i = k + 1; i <= n; i++){
    int prev = inp[i - k];
    mySet.erase(prev);
    auto it = mySet.begin();
    int mn = *it;
    it = mySet.end();
    it--;
    int mx = *it;
    if(inc[i] < k){
      if(inp[i] < mx){
        ans++;
      } else {
        if(prev > mn){
          ans++;
        }
      }
    }
    mySet.insert(inp[i]);
  }
  for(int i = 1; i <= n; i++){
    if(inc[i] >= k){
      ans++;
      break;
    }
  }
  return ans;
}

int main(){
  fastScan(n);
  fastScan(k);
  inp[0] = -1;
  for(int i = 1; i <= n; i++){
    fastScan(inp[i]);
  }
  printf("%d\n", f());
}


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

namespace _02_ABC081A
{
    class Program
    {
        static void Main(string[] args)
        {

            string s = Console.ReadLine(); ;

            int counter = 0;

            for (int i = 0; i<= 2; i++) {
                if (s[i] == '1') { counter++; }
               }
        
            Console.WriteLine(counter);

            Console.Read();
                

        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
string s;
cin >> s;
sort(s.begin(),s.end());
int a=0,b=0;
for(int i=0;i<s.size();i++){
    if(s.at(i)=='A')a++;
    else b++;
}
if(a==2&&b==1){
cout << "Yes"<<endl;
}
else if(b==2&&a==1)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}




Measured memory_bytes: 256
def is_even(i):
    if i % 2 == 0:
        return True
    else:
        return False

def is_all_true(values):
    for x in values:
        if x == False:
            return False

    return True

def div(values):
    ret = []
    for x in values:
        ret += [int(x / 2)]

    return ret



_num_count = int(input())
values = list(map(int, input().split()))

count = 0
while True:
    x = list(map(is_even, values))
    if not is_all_true(x):
        print(count)
        break

    values = div(values)
    count = count + 1


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, N; cin >> H >> W >> N;
  int ans = 201;
  int tmp;
  REP(i, H+1){
    REP(j, W+1){
      tmp = i * W + j * H - i * j;
      if(tmp >= N){        
        ans = min(ans, i + j);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int r= n%10;
    if(r==2 || r==4 || r==5 || r==7 || r==9)printf("hon\n");
    else if(r==0 || r==1 || r==6 || r==8)printf("pon\n");
    else printf("bon\n");
    return 0;
}


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

int main() {
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if (2 * n > m) ans = m / 2;
    else {
        ans += n;
        m -= 2 * n;
        ans += m / 4;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

int main() {

    int N, K;
    string S;

    cin >> N;
    cin >> S;
    cin >> K;

    char tgt = S.at(K-1);
    for (auto & ch : S) {
        if (ch != tgt) ch = '*';
    }

    cout << S;

    return 0;
}



Measured memory_bytes: 256
N, K = [int(i) for i in input().split()]
R, S, P = [int(i) for i in input().split()]
T = input()

hands = {'r': 'p', 's': 'r', 'p': 's'}
score = {'r': R, 's': S, 'p': P}
max_score = 0
memo = [None for _ in range(N)]

for i, t in enumerate(T):
    if i < K:
        memo[i] = hands[t]
        max_score += score[hands[t]]
    else:
        if memo[i-K] == hands[t]:
            memo[i] = [k for k in hands.keys() if k not in (t, hands[t])]
        else:
            memo[i] = hands[t]
            max_score += score[hands[t]]
            
print(max_score)


Measured memory_bytes: 47776
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

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

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int N;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N;
    if (N%2==0) cout << (double).5 << endl;
    else cout << (double)(N-N/2)/(double)N << endl;
  
    return 0;
}



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

using namespace std;


void solve() {
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(n,k-q);
    for (int _ = 0; _ < q; _++) {
        int x; cin >> x;
        a[x-1]++;
    }
    for (int x: a){
        cout << (x>0?"Yes":"No") << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;
int mod = 1e9+7;
int inf = 1e18;
const int N = 5e5+999;
int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
int n,d;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
      string s;
      cin>>s;
      int n = sz(s);
      vi v(n+1);
      for(int i=0;i<n;++i)
      {
          if(s[i]=='<')
            v[i+1] = v[i]+1;
      }
      for(int i=n-1;i>=0;--i)
        if(s[i]=='>')
        v[i] = max(v[i],v[i+1]+1);
     int ans = 0;
      rep(i,0,n+1)
      ans+= v[i];
      cout<<ans<<el;
    }
   return 0;
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXL=100050;
bool dp[MAXL];
const string add[4]={"dream", "dreamer", "erase", "eraser"};

int main() {
	string S;
	cin >> S;
	dp[SZ(S)] = true;
	for(int i = SZ(S) - 1; i >= 0; i--)
		for(int j = 0; j < 4 && !dp[i]; j++)
			if(i + SZ(add[j]) <= SZ(S) && dp[i + SZ(add[j])] && S.substr(i, SZ(add[j])) == add[j])
				dp[i] = true;
	puts(dp[0] ? "YES" : "NO");
	return 0;
}


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

int main(){
    long long int A,B,K,A_last,B_last,cnt=0;
    cin >> A >> B >> K;

    if(K>A+B){
        cout << "0 0" << endl;
    }
    else if(K<=A){
        cout << A-K <<" " << B << endl; 
    }
    else
        cout << "0 " << A+B-K << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

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


inline void solve(){

    string str;
    int ans[100005]={};
    cin >> str;
    int n = str.size();
    int x = 1,id = 0;
    for(int i  = 1; i < n; i++){
        if(str[i-1] != str[i]){
            if(str[i-1] == 'R'){
                
                ans[i] += x/2;
                ans[i-1] += x-x/2;
                x = 0;
            }
            else x = 1;
        }
        else if(str[i]=='L') continue;
        else
            x++;
    }
    ans[n-1] += x;
    x = 1;
    for(int i = n-2; i >= 0; i--){
        if(str[i+1] != str[i]){
            if(str[i+1] == 'L'){
                ans[i] += x/2;
                ans[i+1] += x-x/2;
                x = 0;
            }
            else x = 1;
            
        }
        else if(str[i]=='R') continue;
        else x++;
    }
    
    ans[0] += x;

    for(int i = 0; i < n; i++){
        cout << ans[i];
        cout << (n-i-1?' ':'\n') ;
    }
    
                                 
                    
    

  

}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 1104
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long X;
  cin >> X;
  long ans = 1;
  for (long b = 2; b <= X; b++) {
    long current = b * b;
    while (current <= X) {
      ans = max(current, ans);
      current *= b;
    }
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;
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; }

const int MOD = 1000000007;
const lint INF = 1LL << 60;

int R, S, P;

int score(int p, char c) {
    if (p == 0) {
        if (c == 's') {
            return R;
        }
    }
    else if (p == 1) {
        if (c == 'p') {
            return S;
        }
    }
    else if (p == 2) {
        if (c == 'r') {
            return P;
        }
    }
    return 0;
}

int main() {
    int N, K;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    lint res = 0;
    int z[100010];

    for (int i = 0; i < N; i++) {
        char cpu = T[i];
        if (i >= K) {
            if (cpu == 'r') {
                if (z[i-K] == 2) {
                    z[i] = 3;
                    continue;
                }
                z[i] = 2;
                res += P;
            }
            else if (cpu == 's') {
                if (z[i-K] == 0) {
                    z[i] = 3;
                    continue;
                }
                z[i] = 0;
                res += R;
            }
            else if (cpu == 'p') {
                if (z[i-K] == 1) {
                    z[i] = 3;
                    continue;
                }
                z[i] = 1;
                res += S;
            }
        }
        else {
            if (cpu == 'r') {
                z[i] = 2;
                res += P;
            }
            else if (cpu == 's') {
                z[i] = 0;
                res += R;
            }
            else if (cpu == 'p') {
                z[i] = 1;
                res += S;
            }
        }
    }

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


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(void){
    int b1,b2,b3;
    cin>>b1>>b2>>b3;
    if((b3==1)||(b1==1 &&b2==1)){
        cout<<"Open"<<endl;
    }
    
    else{
        cout<<"Close"<<endl;
    }
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

struct Link {
    int64_t id;
    int64_t src;
    int64_t dst;
    int64_t company;
};

main() {
    int64_t n, m;
    cin >> n >> m;

    vector<Link> links;
    vector<unordered_map<int64_t, vector<int64_t>>> out_links(n);
    vector<unordered_map<int64_t, int64_t>> costs(n);
    for (auto i : irange(0L, m)) {
        int64_t p, q, c;
        cin >> p >> q >> c;
        --p;
        --q;
        links.push_back(Link{2 * i, p, q, c});
        links.push_back(Link{2 * i + 1, q, p, c});
        out_links[p][c].push_back(2 * i);
        out_links[q][c].push_back(2 * i + 1);
        costs[p][c] = numeric_limits<int64_t>::max();
        costs[q][c] = numeric_limits<int64_t>::max();
    }

    for (auto i : irange(0L, n)) {
        costs[i][-1] = numeric_limits<int64_t>::max();
    }

    priority_queue<pair<int64_t, pair<int64_t, int64_t>>> q;
    costs[0][-1] = 0;
    for (const auto& kv : out_links[0]) {
        for (auto link_id : kv.second) {
            const auto& link = links[link_id];
            costs[link.dst][link.company] = 1;
            q.emplace(-1, make_pair(link.dst, link.company));
        }
    }

    while (!q.empty()) {
        auto cost = -q.top().first;
        auto node = q.top().second.first;
        auto company = q.top().second.second;
        q.pop();

        if (cost > costs[node][company]) {
            continue;
        }

        if (company >= 0) {
            for (auto next_link_id : out_links[node][company]) {
                const auto& next_link = links[next_link_id];
                auto next_cost = cost;

                if (next_cost < costs[next_link.dst][next_link.company]) {
                    costs[next_link.dst][next_link.company] = next_cost;
                    q.emplace(-next_cost,
                              make_pair(next_link.dst, next_link.company));
                }
            }

            auto next_cost = cost;
            if (next_cost < costs[node][-1]) {
                costs[node][-1] = next_cost;
                q.emplace(-next_cost, make_pair(node, -1));
            }

            continue;
        }

        if (node == n - 1) {
            cout << cost << endl;
            return 0;
        }

        for (const auto& kv : out_links[node]) {
            for (auto next_link_id : kv.second) {
                const auto& next_link = links[next_link_id];
                auto next_cost = cost + 1;

                if (next_cost < costs[next_link.dst][next_link.company]) {
                    costs[next_link.dst][next_link.company] = next_cost;
                    q.emplace(-next_cost,
                              make_pair(next_link.dst, next_link.company));
                }
            }
        }
    }

    cout << -1 << endl;
}


Measured memory_bytes: 91876
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NMAX = 1e3 + 2, HMAX = 1e4 + 1;
const ll AUCUN = -1;

int n, h, a[NMAX], b[NMAX];
ll dp_min[HMAX];
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	for(int hp = 0; hp < HMAX; hp++)
	{
		dp_min[hp] = AUCUN;
	}
	
	cin >> h >> n;
	
	dp_min[h] = 0;
	
	//dont forget below 0 hp
	
	for(int index = 0; index < n; index++){
		cin >> a[index] >> b[index];
	}
	
	for(int hp = h; hp >= 0; hp--){
		if(dp_min[hp] != AUCUN){
			
			for(int spell_index = 0; spell_index < n; spell_index++){
				int remaining = max(0, hp - a[spell_index]);
				ll cost = dp_min[hp] + b[spell_index];
				if(dp_min[remaining] == AUCUN){
					dp_min[remaining] = cost;
				}
				else{
					dp_min[remaining] = min(dp_min[remaining], cost);
				}
			}
		}
	}
	
	cout << dp_min[0] << '\n';
}


Measured memory_bytes: 384
#include<iostream>
#include<cctype>
#include<string>
#include<cstdio>
using namespace std;

int main(){
    string word;
    string sentence;
    int sum = 0;
    cin >> word;
    
    while(1){
        cin >> sentence;
        if(sentence == "END_OF_TEXT") break;
        for(int i = 0; i < sentence.size(); i++){
        if(isalpha(sentence[i])){
            sentence[i] = tolower(sentence[i]);
        }
    }
        if(word == sentence) sum++;
    }
    cout << sum << endl;
    return 0;
}


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

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0) return false;
    if(n % 3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された

    if(n % 6 != 1 && n % 6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // 6n-1
        if(n % (i+2) == 0) return false; // 6n+1
    }

    return true;
}

int main(void){
    int x;
    cin>>x;
    int a=x;
    while(1){
        if(is_prime(a)) {
            cout<<a<<endl;
            break;
        }
        else{
            a++;
        }


    }
}

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

using namespace std;


const int MOD = 1e9+7;

void solve() {
    string S; cin >> S;

    vector<vector<int>> dp(S.length(), vector<int>(13));

    if (S[0] == '?') {
        for (int i = 0; i <= 9; i++) {
            dp[0][i] = 1;
        }
    }
    else dp[0][S[0] - '0'] = 1;

    for (int i = 1; i < S.length(); i++) {
        if (S[i] == '?') {
            for (int j = 0; j < 13; j++) {
                for (int k = 0; k <= 9; k++) {
                    dp[i][(j*10 + k)%13] += dp[i-1][j];
                    dp[i][(j*10 + k)%13] %= MOD;
                }
            }
        }
        else {
            for (int j = 0; j < 13; j++) {
                dp[i][(j*10 + S[i]-'0')%13] += dp[i-1][j];
                dp[i][(j*10 + S[i]-'0')%13] %= MOD;
            }
        }
    }

    cout << dp[S.length()-1][5] << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 11952
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
const int MAXN = 1e6 + 8;

int t[MAXN], x[MAXN], y[MAXN];

int main()
{
    #ifdef LOCAL
    freopen("a.txt", "r", stdin);
    //freopen("a.out", "w", stdout);
    int T = 4;
    while(T--){
    #endif // LOCAL
    ios::sync_with_stdio(false); cin.tie(0);

    LL n, i, xy;
    bool ans = true;
    t[0] = x[0] = y[0] = 0;
    cin >> n;
    for(i = 1; i <= n; i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    for(i = 1; i <= n; i++){
        xy = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
        if(t[i] - t[i-1] < xy){
            ans = false;
            break;
        }
        else{
            if((t[i] - t[i-1] - xy)&1){
                ans = false;
                break;
            }
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;




    #ifdef LOCAL
    cout << endl;
    }
    #endif // LOCAL
    return 0;
}



Measured memory_bytes: 8832
using System;
using System.Collections;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        int A, B, T;
        var t = Console.ReadLine().Split(' ');
        A = int.Parse(t[0]);
        B = int.Parse(t[1]);
        T = int.Parse(t[2]);
        Console.WriteLine((T / A) * B);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define INT long long int
using namespace std;
deque<INT> q;
INT n, d[100010], N, ans;
int main() {
  cin>>n;
  memset(d, 0x3f, sizeof(d));
  d[1]=1, q.push_back(1);
  while( !q.empty() )
  {
      INT now = q.front(); q.pop_front();
      if( d[(now+1)%n] > d[now]+1 ) q.push_back((now+1)%n), d[(now+1)%n] = d[now]+1;
      if( d[(now*10)%n] > d[now] ) q.push_front((now*10)%n), d[(now*10)%n] = d[now];
  }
  cout<<d[0]<<endl;
}



Measured memory_bytes: 1408
#include <stdio.h>

signed main(){
  
  int y,m,d;
  int h=1;
  scanf("%d/%d/%d",&y,&m,&d);
  if(y>2019) h=0;
  else if(y=2019 && m>4) h=0;
  if(h) printf("Heisei\n");
  else printf("TBD\n");
  
  return 0;
}






Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))

a.sort()

# lに個数を格納
l = []
i = 0
num = 1
while True:
    while i+1 < n and a[i] == a[i+1]:
        i += 1
        num += 1
    l.append(num)
    num = 1
    i += 1
    if i == n:
        break

ans = len(l)
num = 0
for i in l:
    if i % 2 == 0:
        num += 1
if num % 2 == 1:
    ans -= 1
print(ans)

Measured memory_bytes: 89708
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/****@author: Sayed Sohan, CSE 13th batch(2016), MBSTU*****/
/**********************************************************/

#include <bits/stdc++.h>
using namespace std;
//              Typedefs
typedef long long               ll;
typedef unsigned long long      ull;

//              Templates
template<class T>               using min_heap = \
                                priority_queue<T, \
                                std::vector<T>, std::greater<T>>;

//              Basic-Defs
#define PB                      push_back
#define MP                      make_pair
#define SP                      " "
#define NL                      "\n"
#define all(v)                  v.begin(), v.end()

//              DEBUG--SECTION
#define DE                      cout<<"HERE\n";
#define DE1(x)                  cout<<x<<"###\n";
#define DE2(x,y)                cout<<x<<"--->"<<y<<"\n";
#define Pause                   system("pause");

//              Functions
#define clr(arr,value)          memset(arr,value,sizeof(arr))
#define __FAST_IO               ios_base::sync_with_stdio(0);\
                                cin.tie(0);cout.tie(0);
#define NUM1(x)                 __builtin_popcount(x)
#define LCM(x,y)                (x*y)/__gcd(x,y)

//              Sizes--Math     0123456789
#define MOD                     1000000007   //1e9+7 
#define MAX                     100050      
#define INF                     1e18
#define PI                      acos(-1)
#define eps                     1e-6

//** your code goes from here
char mat[100][100];
ll n,m;
ll check(ll r,ll c){
    ll cnt = 0;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            if (r & (1 << i)){
                continue;
            }
            if (c & (1 << j)) continue;
            if(mat[i][j]=='#') cnt++;
        }
    }
    // cout<<cnt<<NL;
    return cnt;
}                                


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    
    ll i,j,k,T; //basic variables

    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n,greater<ll> ());
    
    ll ans = 0;
    if(n==1){
        cout<<ans<<NL;
    }
    else if(n==2){
        cout<<ans+arr[0]<<NL;
    }
    else{
        ans+=arr[0];
        ll pos = 0;
        // cout<<ans<<NL;
        for(i=2;i<n;i++){
            if(i%2==0) pos++;
            ans+=arr[pos];
        }
        cout<<ans<<NL;
    }

    /// Don't forget to set array size....
    return 0;
}




Measured memory_bytes: 5204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,x,y,ans=0,curr,last;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
    int can = 1;
    while(can)
    {
        int mini = 150;
        can = 0;
        int awal=-1,akhir=-1;
        for(i=0;i<n;i++)
        {
            if(arr[i] != 0 && awal == -1)
                awal = i;
            if(arr[i] == 0 && awal != -1)
            {
                akhir = i-1;
                break;
            }
        }
        if(akhir == -1)
            akhir = n-1;
        if(awal == -1)
            break;
        for(i=awal;i<=akhir;i++)
            mini = min(arr[i], mini);
        ans += mini;
        for(i=awal;i<=akhir;i++)
            arr[i] -= mini;

        for(i=0;i<n;i++)
        {
            if(arr[i] > 0)
                can = 1;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
const M: usize = 998244353;

fn main() {
    proconio::input! {
        n: usize,
        k: usize,
        lr: [(usize, usize); k],
    }

    let mut dp = vec![0; n];
    dp[0] = 1;
    dp[1] = M - 1;
    for i in 0..(n - 1) {
        for &(l, r) in &lr {
            let (l, r) = (i + l, i + r + 1);
            if l < n { dp[l] = (dp[l] + dp[i]) % M }
            if r < n { dp[r] = (M + dp[r] - dp[i]) % M }
        }
        dp[i + 1] = (dp[i + 1] + dp[i]) % M;
    }
    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,y;
  cin >>n>>y;
  for(ll i=0;i<=n;i++){
    for(ll j=0;j<=(n-i);j++){
      if(n-i-j>=0){
      if(10000*i+5000*j+1000*(n-i-j)==y){
        cout <<i<<" "<<j<<" "<<n-i-j<<endl;
        return 0;
      }
     }
    }
  }
  cout <<-1<<" "<<-1<<" "<<-1<<endl;
  return 0;
}


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

int main(){
  int n;
  string s,t;
  cin>>n>>s>>t;
  for(int i=0;i<n;i++){
    int f=1;
    for(int j=0;j<n-i;j++){
      if(s[i+j]==t[j])continue;
      f=0;
    }
    if(f){
      cout<<n+i<<endl;
      return 0;
    }
  }
  cout<<n*2<<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 all(a) (a).begin(),(a).end()
typedef long long ll;

template<typename T>
class BIT {
    public:
    int n;
    vector<T> dat; // i: [1,n]

    BIT(int size): n(size+1), dat(vector<T>(n+1)) {}

    void add(int i, T x) {
        while (i <= n) {
            dat[i] += x;
            i += i & -i;
        }
    }

    T sum(int i) {
        T ret = 0;
        while (i > 0) {
            ret += dat[i];
            i -= i & -i;
        }
        return ret;
    }

    T range(int l, int r) {
        return sum(r) - sum(l-1);
    }
};

// i < j, (v[i] op v[j]) を満たす(i,j)の組を数える
template<typename T>
ll inversion(vector<T> v, string op) {
    assert(op == "<=" || op == ">=" || op == ">" || op == "<");
    if (op == ">=" || op == "<") {
        reverse(all(v));
    }

    ll size = v.size();
    vector<pair<T, int>> vp(size);
    rep(i,size) {
        vp[i] = {v[i],i};
    }
    sort(all(vp));

    // 小さい順に 1..size の連番を振る
    vector<int> order(size);
    rep(i,size) {
        order[vp[i].second] = i+1;
    }

    // i < j, order[i] <= order[j] の個数を数える
    ll result = 0;
    BIT<int> bt(size);
    rep(i,size){
        result += bt.sum(order[i]);
        bt.add(order[i], 1);
    }

    if (op == ">" || op == "<") {
        return size*(size-1)/2 - result;
    } else {
        return result;
    }
}

ll n;
vector<int> a;

bool check(int x) {
    vector<int> b(n);
    rep(i,n){
        b[i] = (a[i] >= x ? +1 : -1);
    }
    vector<ll> s(n+1);
    rep(i,n){
        s[i+1] = s[i] + b[i];
    }
    return (n*(n+1)/2 + 1)/2 <= inversion(s, "<=");
}

int main(void) {
    cin >> n;
    a.resize(n);
    vector<int> meds(n);

    rep(i,n){
        cin >> a[i];
        meds[i] = a[i];
    }
    sort(all(meds));
    int l = 0, r = n;
    while (l + 1 < r) {
        int mid = (l+r)/2;
        if (check(meds[mid])) {
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << meds[l] << endl;
    return 0;
}


Measured memory_bytes: 5380
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        for(int i=0;i<n;++i) {
            BigInteger a = scan.nextBigInteger();
            BigInteger b = scan.nextBigInteger();
            a=a.add(b);
            if(a.toString().length()>80){
                System.out.println("overflow");
            }else {
                System.out.println(a);
            }
        }
    }
}

Measured memory_bytes: 26540
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;


bool soin(set<int64_t> &prime, int64_t x){
  int64_t N=x;
  if(prime.count(N)){
    prime.erase(N);
    return true;
  }
  for (int64_t i=2;i*i<=N;i++){
    if(x%i==0){
      if(prime.count(i)){
      prime.erase(i);
      }
      else{
        return false;
      }
      while(x%i==0)x/=i;
    }
  }
  if(prime.count(x)){
    prime.erase(x);
    return true;
  }
  else if(x==1){
    return true;
  }
  else{
    return false;
  }
}

int main() {
  //準備
  int64_t MAX=1000001;
  vector<bool> Prime(MAX,true);
  for(int64_t i=2;i*i<=MAX;i++){
    if(Prime[i]){
      int64_t k=2;
      while(i*k<=MAX){
        Prime[i*k]=false;
        k++;
      }
    }
  }
  
  set<int64_t> prime;
  for(int64_t i=2;i<MAX;i++){
    if(Prime.at(i)){
      prime.insert(i);
    }
  }
     
  //処理
  bool coprime=true;
  int64_t N,total; cin>>N;
  rep(i,N){
    int64_t K; cin>>K;
    if(coprime){
      bool temp=soin(prime,K);
      if(!temp){
        coprime=false;
      }
    }
    if(i==0) total=K;
    else total=gcd(total,K);
  }
  
  //出力
  if(coprime) cout<<"pairwise coprime";
  else if(total==1) cout<<"setwise coprime";
  else cout<<"not coprime";
}


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

int main(void){
	int N,M;
	cin >> N >> M;
	vector<vector<ll>> g(N,vector<ll>(N,1e9+7));
	vector<ll> a(M),b(M),c(M);
	for(int i=0;i<M;i++){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;b[i]--;
		g[a[i]][b[i]] = min(g[a[i]][b[i]],c[i]);
		g[b[i]][a[i]] = min(g[b[i]][a[i]],c[i]);
	}
	rep(k,N)rep(i,N)rep(j,N)g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
	ll ans = 0;
	for(int i=0;i<M;i++){
		if(c[i] != g[a[i]][b[i]])ans++;
	}
	cout << ans << endl;
}

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

using namespace std;
using LL = long long;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

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

    int n, k;
    cin >> n >> k;
    vector<int> t(n), d(n);
    REP(i, n) cin >> t[i] >> d[i];
    vector<pair<int, int>> p;
    REP(i, n) p.pb(make_pair(d[i], t[i]));
    sort(all(p), [](pair<int, int> a, pair<int, int> b){ return a.first > b.first; });

    vector<LL> sushi1, sushi2(1, 0);
    map<int, bool> close;
    REP(i, n){
        if(close[p[i].second]){
            sushi2.pb(p[i].first);
        }else{
            sushi1.pb(p[i].first);
            close[p[i].second] = true;
        }
    }
    REP(i, sushi1.size() - 1){
        sushi1[i+1] += sushi1[i];
    }
    REP(i, sushi2.size() - 1){
        sushi2[i+1] += sushi2[i];
    }

    LL ans = 0;
    REP(i, min(k, (int)sushi1.size())){
        if(sushi2.size() > k - i - 1){
            ans = max(ans, 1LL * (i+1) * (i+1) + sushi1[i] + sushi2[k - i - 1]);
            //cout << i+1 << " " << 1LL * (i+1) * (i+1) + sushi1[i] + sushi2[k - i - 1] << " " << sushi1[i] << " " << sushi2[k - i - 1] << endl;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 10480
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b := intScanner(), intScanner()
	if b%a == 0 {
		fmt.Println(a + b)
	} else {
		fmt.Println(b - a)
	}
}


Measured memory_bytes: 1772
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<string.h>
#include<bitset>
#include<set>
using namespace std;

struct S {
	int cost, x, y, o, xh;
	S(int c, int in_x, int in_y, int in_o, int in_xh) : cost(c), x(in_x), y(in_y), o(in_o), xh(in_xh){}
	bool operator<(const S &s) const { 
		if (cost != s.cost)
			return cost < s.cost;
		else
			return o < s.o;
	}
};

const int INF = -1000000000, INF2=10000000;
int w, h, f, m, o, ans;
int stratum[110][110];
int c[11][11][51];
priority_queue<S> pq;

void dijkstra(){
	int move[3] = { 1, -1, 1 };//?´y,?´x,?´x
	while (!pq.empty()){
		S a = pq.top();
		pq.pop();
		if (a.o == 0) continue;
		if (a.y == h){
			if (-a.cost <= f)
				ans = -a.cost;
			break;
		}
		if (a.o == 1) continue;
		for (int i = 0; i < 3; i++){
			int x = a.x;
			int y = a.y;
			if (i)
				x += move[i];
			else
				 y += move[i];
			int xx = 1<<(w-x);
			xx = xx&a.xh;
			if (!xx || !i){
				if (x <= w && 0 < x&&y <= h){
					if (stratum[y][x] < 0){
						if (a.cost + stratum[y][x] >= -f&&a.cost + stratum[y][x] > c[y][x][a.o - 1]){
							c[y][x][a.o - 1] = a.cost + stratum[y][x];
							if (i)
								pq.push({ c[y][x][a.o - 1], x, y, a.o - 1, a.xh | 1 << (w-x) });
							else
								pq.push({ c[y][x][a.o - 1], x, y, a.o - 1, 1 << (w-x) });
						}
					}
					else if (stratum[y][x] >0){
						int hokyuuu;
						hokyuuu = stratum[y][x] + a.o - 1;
						if (hokyuuu + a.o - 1 >= m)
							hokyuuu = m;
						c[y][x][hokyuuu] = a.cost;
						if (i)
							pq.push({ c[y][x][hokyuuu], x, y, hokyuuu, a.xh | 1 << (w-x) });
						else
							pq.push({ c[y][x][hokyuuu], x, y, hokyuuu, 1 << (w-x) });
					}
					else{
						pq.push({ 0, x, y, o, a.xh | 1 << (w-x) });
					}
				}
			}
			/*else{
				if (a.cost > c[y][x][a.o - 1] && a.o - 1){
					c[y][x][a.o - 1] = a.cost;
					pq.push({ c[y][x][a.o - 1], x, y, a.o - 1, a.xh });
				}
			}*/
		}
	}
}


int main(){
	while (cin >> w >> h&&w&&h){
		cin >> f >> m >> o;
		memset(stratum, sizeof(stratum), 0);
		ans=INF2;
		for (int i = 1; i <= 10; i++)
			for (int j = 1; j <= 10; j++)
				fill(c[i][j], c[i][j] + 51, INF);
		while (!pq.empty())
			pq.pop();
		for (int i = 1; i <= h; i++)
			for (int j = 1; j <= w; j++)
				cin >> stratum[i][j];
		pq.push({ 0, 1, 0, o, 1<<(w-1) });
		dijkstra();
		if (ans!=INF2)
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		sc.close();
		int a = 0, b = 0, c = 0, ans = 0;
		for(int i = 1; i <= K; i++) {
			a = i;
			for(int j = 1; j <= K ; j++) {
				b = j;
				for(int n = 1; n <= K ; n++) {
					c = n;
					int g = gcd(a, b);
					ans += gcd(g, c);
				}
			}
		}
		System.out.println(ans);
	}
    /**
     * 整数値x,yの最大公約数を求めて返却
     * @param x
     * @param y
     * @return 最大公約数
     */
    public static int gcd(int x, int y) {
        // System.out.println("x = " + x + " y = " + y);
		return y == 0 ? x : gcd(y, x % y);
    }
}

Measured memory_bytes: 27136
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<functional>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<unordered_map>
#include<math.h>
#include<stack>
#include<deque>
using namespace std;

signed main() {
	int ans = 0, n; cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		ans += b - a + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: usize, m: usize,
        h: [i32; n],
    }
    let mut obs = vec![1; n];
    for _ in 0..m {
        proconio::input! {
            a: usize, b: usize,
        }
        if h[a - 1] >= h[b - 1] {
            obs[b - 1] = 0;
        }
        if h[b - 1] >= h[a - 1] {
            obs[a - 1] = 0;
        }
    }
    let total: i32 = obs.iter().sum();
    println!("{}", total);
}


Measured memory_bytes: 4836
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    l=len(s)
    ct=0
    for i in range(l//2):
        if s[i]!=s[-1-i]:
            ct+=1
    print(ct)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#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;

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}

int main(){
  int n;
  cin >> n;
  ll v[n];
  rep(i,n){
    cin >> v[i];
  }
  sort(v,v+n);
  rep(i,n-1){
    if(v[i] == v[i+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		//C
		int N = sc.nextInt();
		int K = sc.nextInt();
		long ans = N / K;
		long counter = 0;
		ans = ans*ans*ans;

		if(K % 2 == 0){
			for(int i = 1 ; i <= N ; i++){
				if(i%K == (K/2)){
					counter++;
				}
			}
			ans += counter * counter * counter;
		}

		System.out.println(ans);
	}
}


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

int main() {

	int a, b; cin >> a >> b;
	string sa = "";
	for (int i = 0; i < b; i++) {
		sa += to_string(a);
	}
	string sb = "";
	for (int i = 0; i < a; i++) {
		sb += to_string(b);
	}
	string ans;
	if (a < b) ans = sa;
	else ans = sb;
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, K;
		N = sc.nextInt();
		K = sc.nextInt();
		sc.close();
		
		double ans = 0;
		for (int i = 1; i <= N; i++) {
			double tmp = 1.0/N;
			int now = i;
			while (now < K) {
				now *= 2;
				tmp /= 2;
			}
			ans += tmp;
		}
		System.out.println(ans);
		
	}
}

Measured memory_bytes: 22736
import itertools
def main():
    N, M, Q = (int(_) for _ in input().split())
    query = [[int(_) for _ in input().split()] for __ in range(Q)]
    ret = 0
    for ll in itertools.combinations_with_replacement(range(1, M+1), N):
        cc = 0
        for a, b, c, d in query:
            a, b = a-1, b-1
            if ll[b] - ll[a] == c: cc += d
        ret = max(ret, cc)
    print(ret)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	double a;
	while (cin>>a) 
	{
		double ans=a;
		for(int i = 2; i < 11; ++i)
		{
			if(i%2==0) a=a*2;
			else a=a/3;
			ans+=a;
		}
		printf("%.9lf\n",ans);
	}
  return 0;
}

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

int main(void)
{
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    int a[N];
    rep(i , N) cin >> a[i];
    int s = 0;
    int ans[H][W] = {0};
    int i = 0, j = 0;

    while (a[N-1] > 0){
        while(a[s] > 0){
            ans[i][j] = s + 1;
            a[s]--;
            j++;
        }
        s++;
    }
    for (int i = 0; i < H; i++){
        if ( i % 2 == 0){
            for (int j = 0; j < W; j++){
                cout << ans[i][j] << " ";
            }
        } else {
            for (int j = W -1; j >= 0; j--){
                cout << ans[i][j] << " ";
            }
        }

        cout << endl;
    }

    return 0;
}


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

int main() {
	int n;
	cin >> n;
	bool flag = false;
	for(int i = 0; i<n; i++){
		string s;
		cin >> s;
		if (s=="Y"){
			flag = true;
		}else{
			;//nothing to do
		}
	}
	cout << ( flag ? "Four" : "Three" ) << endl;
}


Measured memory_bytes: 256