akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Get some numbers from stdio and convert it
	sc.Scan()
	numString := strings.Split(sc.Text(), " ")

	nums := make([]int, len(numString))
	var err error

	for i := 0; i < len(nums); i++ {
		nums[i], err = strconv.Atoi(numString[i])
		if err != nil {
			panic(err)
		}
	}

	train := nums[0] * nums[1]
	taxi := nums[2]
	if train > taxi {
		fmt.Println(taxi)
	} else {
		fmt.Println(train)
	}
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
double n,m,a[10005],cnt,sum;
int main()
{
    cin>>n>>m;
    sum=0;
    cnt=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    } 
    double x=sum/(4.00*m);
    for(int i=1;i<=n;i++)
    {
        
        //cout<<x<<endl;
        if(a[i]>=x)
        cnt+=1;
    }
    if(cnt>=m)
    {
        cout<<"Yes"<<endl;
    }
    else
    cout<<"No"<<endl;
    return 0;
} 

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : (x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair((x), (y))

typedef long long ll;

typedef double T;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<T> vt;
typedef vector<vt> vvt;
typedef vector<pii> vpi;
typedef vector<vpi> graph;
typedef complex<T> Pt;
typedef pair<Pt, Pt> Line;

const ll MOD = 1e9+7; // 998244353;
const T EPS = 1e-7;
const int INF = 1e9 + 1;

template <typename A, typename B>
istream& operator>>(istream &in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template <typename A, typename B>
ostream& operator<<(ostream &out, pair<A, B> &p) {
    out << "(" << p.first << " " << p.second << ")";
    return out;
}

template <typename I>
istream& operator>>(istream &in, vector<I> &a) {
    trav(i, a) in >> i;
    return in;
}

template <typename I>
ostream& operator<<(ostream &out, vector<I> &a) {
    rep(i, 0, sz(a)) {
        if (i) out << " ";
        out << a[i];
    }
    return out;
}

void fast_io() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin.exceptions(cin.failbit);
}

const int N = 2e5;
ll fact[N];
ll inv[N];

ll harm[N];

void solve_test() {
    int n; 
    cin >> n; 
    vi a(n); 
    cin >> a;
    harm[0] = fact[n];
    rep(i, 1, N-1) {
        harm[i] = (harm[i-1] + fact[n]*inv[i+1])%MOD;
    }

    ll tot = 0;
    rep(i, 0, n) {
        tot = (tot + a[i]*((harm[i] + harm[n-i-1] - fact[n])%MOD + MOD))%MOD;
    }
    cout << tot << "\n";
}

void setup() {
    fact[0] = 1;
    rep(i, 1, N) fact[i] = (fact[i-1]*i)%MOD;
    inv[1] = 1;
    rep(i, 2, N) inv[i] = MOD - (MOD / i)*inv[MOD%i]%MOD;
}

int main() {
    setup();
    srand(time(0));
    fast_io();
    int t = 1;
    // cin >> t;
    while (t--) {
        solve_test();
    }
}

Measured memory_bytes: 5376
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    while(a&&c)
    {
        c-=b;
        if(c<=0)
        {
            printf("Yes");
            break;
        }
        a-=d;
        if(a<=0)
        {
            printf("No");
            break;
        }
    }
}

Measured memory_bytes: 1724
h, w = map(int, input().split())
sss = [input() for _ in range(h)]

ok = 1
for i, ss in enumerate(sss) :
    for j, s in enumerate(ss) :
        if s == "#" :
            okness = 0
            try : 
                if ss[j-1] == "#" :
                    okness = 1
            except : pass
            try : 
                if ss[j+1] == "#" :
                    okness = 1
            except : pass
            try : 
                if sss[i-1][j] == "#" :
                    okness = 1
            except : pass
            try : 
                if sss[i+1][j] == "#" :
                    okness = 1
            except : pass
            ok *= okness
print(" YNeos"[ok::2])

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



int main(){
    string s;
    cin >> s;
    string ans;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0'||s[i]=='1'){
            ans.pb(s[i]);
        }else{
            if(ans.size()>0){
                ans.erase(ans.size()-1);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define vvll(z,a,b) vector<vector<ll>>z(a,vector<ll>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
using namespace std;


int main(){
   int n,m,l;
   cin>>n>>m>>l;
   vv(A,n,m);
   vv(B,m,l);
   vvll(C,n,l);
   rep(i,n){
       rep(j,m){
           cin>>A.at(i).at(j);
       }
   }
 rep(i,m){
       rep(j,l){
           cin>>B.at(i).at(j);
       }
   }
rep(i,n){
       rep(j,l){
           rep(k,m){
               C.at(i).at(j)+=A.at(i).at(k)*B.at(k).at(j);

           }
           cout<<C.at(i).at(j);
           if(j!=l-1)cout<<" ";
       }
       cout<<endl;
   }



}


Measured memory_bytes: 3268
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N)cin >> a[i];
    bool incrFlag = false;
    if(N == 1){
        cout << 1 << endl;
        return 0;
    }
    int ans = 0;
    bool center = false;
    rep(i, N - 1){
        if(center == true){
            if(incrFlag == true && a[i] - a[i + 1] > 0){
                ans++;
                incrFlag = false;
                center = false;
            }else if(incrFlag == false && a[i] - a[i + 1] < 0){
                ans++;
                incrFlag = true;
                center = false;
            }
        }else{//増加なのか減少なのか
            if(a[i] - a[i + 1] > 0){
                incrFlag = false;
                center = true;
            }else if(a[i] - a[i + 1] < 0){
                incrFlag = true;
                center = true;
            }
        }
    }
    cout << ans + 1 << endl;
}

Measured memory_bytes: 640
#include "iostream"
#include "algorithm"
#include "string"
#include "set"
#include "vector"

using namespace std;

long long int N, M, K, L, R, H, W;

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

	cin >> N >> M >> K;
	vector<int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 1; j <= M; j += v[i]) {
			K++;
		}
	}
	cout << K << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define MAX 5000000000000000000LL
#define MIN -5000000000000000000LL

ll ss = 998244353;
ll n, k;
pair<ll, ll> lr[20];
ll d[200010];
ll nu[200010];

int main(void)
{
	scanf("%lld %lld", &n, &k);
	
	for(ll i = 0 ; i < k ; i++)
		scanf("%lld %lld", &lr[i].first, &lr[i].second);
	
	d[1] = 1;
	nu[1] = 1;
	
	for(ll i = 2 ; i <= n ; i++)
	{
		for(ll j = 0 ; j < k ; j++)
		{
			ll l = max(1LL, i - lr[j].second);
			ll r = max(0LL, i - lr[j].first);
			
			d[i] = (d[i] + nu[r] - nu[l - 1]) % ss;
		}
		
		nu[i] = (nu[i - 1] + d[i]) % ss;
	}
	
	printf("%lld", d[n] % ss < 0 ? d[n] % ss + ss : d[n] % ss);
	return 0;
}

Measured memory_bytes: 6948
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> d(n);
    REP(i, n) cin >> d[i];
    sort(ALL_OF(d));

    cout << d[n/2] - d[n/2-1] << endl;
    
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;


namespace AtCoder
{
    class AtCoderrr
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            long[] a = ReadLine().Split(' ').Select(long.Parse).ToArray();
            long ans = 0;
            for (int i = 0; i < n; i++)
            {
                while (a[i] % 2 == 0)
                {
                    a[i] /= 2;
                    ans++;
                }
            }
            WriteLine(ans);
        }
        
    }
}


Measured memory_bytes: 12256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll A, B, N, M;
vector<pair<ll, ll>> V; 
ll price;
ll temp;
ll cnt;

int main() {
	scanf("%lld %lld", &N, &M);
	for(int i = 0; i < N; i++) {
		scanf("%lld %lld", &A, &B);
		V.push_back(make_pair(A, B));
	}
	sort(V.begin(), V.end());
	for(int i = 0; i < V.size(); i++) {
		temp = min(V[i].second, M);
		cnt += temp;
		price += temp * V[i].first;
		M -= temp;
	}
	printf("%lld\n", price);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

int main()
{
	int n,m;
	double sum=0;
	cin>>n>>m;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a,a+n);
	double min=sum/(4*m);
	int count=0;
	for(int i=n-1;i>=0;i--)
	{
		if(a[i]<min || count==m)
			break;
		else
			count++;
	}
	if(count==m)
		cout<<"Yes";
	else
		cout<<"No";
}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
const int mod = 1000000007;

vector<ll> divisor(ll n) {
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            res.push_back(i);
            if(i * i != n) {
                res.push_back(n / i);
            }
        }
    }
    sort(begin(res), end(res));
    return res;
}

int main() {
    ll n, min_ = LLONG_MAX;
    cin >> n;
    vector<ll> v = divisor(n);
    ll len = max(v.size() / 2, v.size() + 1 / 2);
    for(ll i = 0; i < len; i++) {
        min_ = min(min_, v[i] + v[len - i - 1] - 2);
    }

    cout << min_ << endl;

    return 0;
}

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

namespace ABC149A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            string str1 = str[1] + str[0];
            Console.WriteLine(str1);
        }
    }
}


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

a.sort(reverse=True)
score_of_alice, score_of_bob = 0, 0
for i in range(n):
    score = a.pop(0)
    if i % 2 == 0:
        score_of_alice += score
    else:
        score_of_bob += score

print(score_of_alice - score_of_bob)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int flag=0,ans=0;
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='R')
      flag++;
    if(s[i]=='S')
      flag=0;
    ans=max(ans,flag);
  }
  if(flag!=0)
    ans=max(ans,flag);
  cout<<ans<<endl;
}


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

int main(){
  string S;
  cin >> S;
  
  char ch_1, ch_2;
  ch_1 = S[0];
  ch_2 = S[1];
  
  if (ch_1 == ch_2) {
    if (ch_1 != S[2]) {
      if (S[2] == S[3]) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    else {
      cout << "No" << endl;
    }
  }
  
  else {
    if (ch_1 == S[2]) {
      if (ch_2 == S[3]) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    else if (ch_1 == S[3]) {
      if (ch_2 == S[2]) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    else {
      cout << "No" << endl;
    }
  }
  
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  int ans=100;
  for(int i=0; i<N; i++){
    cin >> A.at(i);
    int B=A.at(i);
    int cnt=0;
    while(B%2==0){
      B=B/2;
      cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound

using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(C % B == 0){
    if(A % D == 0){
  if((C / B) + 1 > (A / D) + 1){
    cout << "No" << endl;
  }
  if((C / B) + 1 <= (A / D) + 1){
    cout << "Yes" << endl;
  }
    }}
  
  if(C % B != 0){
    if(A % D != 0){
  if((C / B) + 1 > (A / D) + 1){
    cout << "No" << endl;
  }
  if((C / B) + 1 <= (A / D) + 1){
    cout << "Yes" << endl;
  }
    }}
  if(C % B != 0){
    if(A % D == 0){
  if((C / B) + 1 > (A / D)){
    cout << "No" << endl;
  }
  if((C / B) + 1 <= (A / D)){
    cout << "Yes" << endl;
  }
    }}
  if(C % B == 0){
    if(A % D != 0){
  if((C / B) > (A / D) + 1){
    cout << "No" << endl;
  }
  if((C / B) <= (A / D) + 1){
    cout << "Yes" << endl;
  }
    }}
  
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std ;
const int N = 1e7 + 4;
void FastInputOutput()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline ll LLD()
{
    ll ret;
    scanf("%lld", &ret);
    return ret;
}
inline int D()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
void bin( int x )
{
    if(!x)
        return;
    bin( x / 2 );
    cout << x % 2 ;
}
bool checkPrimeNumber(int n)
{
    bool flag = true;
    for(int j = 2 ; j <= n ; ++j)
    {
        if (n % j == 0)
        {
            flag = false;
            break;
        }
    }
    return flag;
}
bool cmp(string last, string first)
{
    if(last.size() < first.size())
        return 1;
    return 0;
}
int calculateDigit(int n)
{
    double temp = (double)(n);
    double a = 0.39908-(0.434294 * n);
    double b = log10( n ) ;
    double c = ( n + 0.5 ) * b ;
    double ans = c - abs( a ) ;
    return ceil(ans) ;
}
int findDigits(int n)
{
    double E = 2.71828182845904523536;
    double PI = 3.141592654;

    if (n < 0)
        return 0;
    if (n <= 1)
        return 1;

    double x = ((n * log10(n / E) +
                 log10(2.0 * PI * n) /
                 2.0));

    return floor(x) + 1;
}
ll fact(ll n)
{
    ll ans = 1 ;
    for(ll i = 1 ; i <= n ; ++i)
        ans *= i ;
    return ans ;
}
unsigned long long Factorial(int n)
{
    const unsigned int M = 1000000007;
    unsigned long long f = 1;
    for (int i = 1; i <= n; i++)
        f = (f*i) % M;

    return f;
}
bool checkNumber(int start, int ed, string s)
{
    int flag = 1;
    for(int i = start ; i <= ed ; ++i)
    {
        if(s[ i ] - '0' >= 0 && s[ i ] - '0' <= 9) {}

        else
        {
            flag = 0 ;
            break ;
        }
    }
    return flag ? true : false ;
}
int main()
{
    FastInputOutput() ;
    int a, b, cnta = 0, cntb = 0;
    cin >> a >> b ;
    string s ;
    cin >> s ;
    int flag = 0 ;
    int sz = a + b + 1 ;
    for(int i = 0 ; i < sz ; ++i)
    {
        if(s[ i ] == '-' )
            flag = 1 ;
        if(flag == 0)
        {
            if(s[i] >= '0' && s[i] <= '9')
                ++cnta ;
        }
        else
        {
            if(s[i] >= '0' && s[i] <= '9')
                ++cntb ;
        }
    }

    if(cnta == a && cntb == b)
        cout << "Yes" << endl ;
    else
        cout << "No" << endl ;

}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint n,m,i;cin>>n>>m;
	deque<llint>b(n+n);
	for(i=0;i<n+n;i++){cin>>b[i];}
	SO(b);
	llint bmin=-1,bmax=n+n-1;
	while(bmax-bmin>1){
		llint bgen=(bmin+bmax)/2;
		auto a=b;
		for(i=0;i<bgen;i++){a.pub(a[0]+m);a.pof();}
		bool ok=1;
		for(i=0;i<n;i++){if(a[i]+a[n+n-1-i]<m){ok=0;break;}}
		if(ok==0){bmin=bgen;}
		else{bmax=bgen;}
	}
	cerr<<bmax<<endl;
	auto a=b;
	llint ans=0;
	for(i=0;i<bmax;i++){a.pub(a[0]+m);a.pof();}
	for(i=0;i<n;i++){maxeq(ans,a[i]+a[n+n-1-i]-m);}
	cout<<ans<<endl;
	return 0;
}
/*
3 4 ->34 67
*/

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

int INF;
int n;
int es[100][100];

// sから各頂点への最短経路を求める
void dijkstra () {
  
  int minv;
  int d[100];

  // 0:未調査 1:調査中 2:調査完了
  int status[100];

  for (int i = 0; i < n; i++) {
    d[i] = INF;
    status[i] = 0;
  }

  d[0] = 0;
  status[0] = 1;

  while (1) {
    minv = INF;
    int u = -1;
    for (int i = 0; i < n; i++) {
      if (d[i] < minv && status[i] != 2) {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1) {
      break;
    }
    status[u] = 2;
    for (int v = 0; v < n; v++) {
      if (status[v] != 2 && es[u][v] != INF) {
        if (d[u] + es[u][v] < d[v]) {
          d[v] = d[u] + es[u][v];
          status[v] = 1;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (d[i] == INF) {
      cout << i << " -1" << endl;
    } else {
      cout << i << " " << d[i] << endl;
    } 
  }
}

int main() {
  
  cin >> n;

  INF = 2000000;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      es[i][j] = INF;
    }
  }

  // 入力を受け取る
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v, c;
      cin >> v >> c;
      es[u][v] = c;
    }
  }

  // ダイクストラ法開始
  dijkstra();

  return 0;
}


Measured memory_bytes: 3148
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>
//<editor-fold desc="definitions">
#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n"
using namespace std;
using ll=long long;
using ld=long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using vlll = vector<vector<vector<ll>>>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) {
            for (auto vvv : vv) cout << vvv << " ";
            cout << endl;
        }
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

dbg::Debug debug;
//</editor-fold>

class BEasyLinearProgramming {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll a, b, c, k;
	    in >> a >> b >> c >> k;

	    ll res = 0;
	    res += min(a, k) * 1;
	    k -= min(a, k);

	    if(k > 0){
	        k -= min(b, k);
	    }

	    if(k > 0){
	        res += min(c, k) * (-1);
	        k -= min(c, k);
	    }

	    out << res << enl;
	}
};


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	BEasyLinearProgramming solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3660
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			int N = scn.nextInt();
			int M = scn.nextInt();
			int X = scn.nextInt();

			int[][] algorism = new int[12][13];
			int[] bitflg = new int[12];
			List<Integer> list = new ArrayList<Integer>();

			//initialize
			for(int i = 0; i < N; i++) {
				for(int j = 0; j < M+1; j++) {
					algorism[i][j] = scn.nextInt();
				}
			}

			int result = 99999999;
			int cost = 0;
			int roop = (int) Math.pow(2, N);
			//2^N回（最大4096回)繰り返す
			for(int i = 0; i < roop; i++) {
				int[] realize = new int[M];
				for(int j = 0; j < N; j++) {
					if(bitflg[j] == 1) {
						cost += algorism[j][0];
						for(int k = 0; k < M; k++) {
							realize[k] += algorism[j][k+1];
						}
					}
				}
				boolean flg = true;
				for(int k = 0; k < M; k++) {
					if(realize[k] < X) flg = false;
				}
				if(flg) {
					result = (int) Math.min(cost, result);
				}
				cost = 0;
				bitCalc(bitflg, 0, N);
			}
			if(result == 99999999) {
				System.out.println(-1);
			} else {
				System.out.println(result);
			}
		}
	}

	//ビット計算
	public static void bitCalc(int[] bitflg, int idx, int idxMax) {
		if(idx == idxMax) return;
		if(bitflg[idx] == 0) {
			bitflg[idx] = 1;
		} else {
			bitflg[idx] = 0;
			bitCalc(bitflg, idx+1, idxMax);
		}
	}
}

Measured memory_bytes: 28816
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep(a,b,c) for (int a=b;a<=c;a++)
using namespace std;
const int N=205,M=40005;
int ft[N],cu[N],q[N],h,t,tot=1,ans,S,T,d[N];
struct edge{int t,f,n;}E[M];  
void add(int x,int y,int f){  
	E[++tot]=(edge){y,f,ft[x]},ft[x]=tot;  
	E[++tot]=(edge){x,0,ft[y]},ft[y]=tot; 
}  
#define FOR for (int o=cu[u],v;v=E[o].t;o=E[o].n)  
void bfs(int u=S){  
	memset(d,0,sizeof(d));  
	memcpy(cu,ft,sizeof(cu));  
	for (d[q[h=t=1]=u]=1;h<=t;u=q[++h])  
		FOR if (E[o].f&&!d[v]) d[q[++t]=v]=d[u]+1;  
}  
int dfs(int u,int f){  
	if (u==T||!f) return f;  
	int g=0,t;  
	FOR if (cu[u]=o,d[v]==d[u]+1&&(t=dfs(v,min(f,E[o].f))))  
		g+=t,f-=t,E[o].f-=t,E[o^1].f+=t;  
	return g;  
}
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n) rep(j,1,m){
		char c;
		cin>>c;
		if (c=='.') continue;
		int f=1;
		if (c=='S') S=i,f=1000;
		if (c=='T') T=i,f=1000;
		add(i,j+n,f);
		add(j+n,i,f);
	}
	while (bfs(),d[T]&&ans<1e7) ans+=dfs(S,1e8);
	printf("%d\n",ans>n+m?-1:ans);
	return 0;
}

Measured memory_bytes: 768
use std::io::Read;
use std::collections::VecDeque;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let mut sa: VecDeque<char> = iterator.next().unwrap().chars().collect();
    let mut sb: VecDeque<char> = iterator.next().unwrap().chars().collect();
    let mut sc: VecDeque<char> = iterator.next().unwrap().chars().collect();

    let mut next: char = sa.pop_front().unwrap();
    loop {
        if next == 'a' {
            if sa.is_empty() {
                return "A".to_string();
            } else {
                next = sa.pop_front().unwrap();
            }
        } else if next == 'b' {
            if sb.is_empty() {
                return "B".to_string();
            } else {
                next = sb.pop_front().unwrap();
            }
        } else {
            if sc.is_empty() {
                return "C".to_string();
            } else {
                next = sc.pop_front().unwrap();
            }
        }
    }
}


Measured memory_bytes: 4352
# 2019/08/05

n,m=map(int,input().split())
edge=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    edge[a].append(b)
    edge[b].append(a)


for e in edge[-1]:
    if 0 in edge[e]:
        print('POSSIBLE')
        exit()

print('IMPOSSIBLE')

Measured memory_bytes: 38296
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int LINF=1e18;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
/*
どこまでを-にするかを考えてあげて前からやるだけ
[0,l)が負、[l,N)が正だとして、考えるのは
l+2*(f(l)+g(l))
ただしf(l)は[0,l)を4倍だけで降順にするのにかかるコスト、g(l)は[l,N)を4倍だけで昇順にするのにかかるコスト
これが出せればansはlを0~Nで走らせるだけ

*/
int dpf[223456][20],dpg[223456][20];
//dpf[i][j]:i番目にj回4をかけてる時の[i,N)を昇順に並べる時の4をかける総合回数

signed main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  vector<int> w(n,0);//w[i]:v[i]とv[i+1]がギリギリ昇順になるためにv[i]に何回4をかけるか
  for(int i=0;i<n-1;i++){
    if(v[i]<v[i+1]){
      int tmp=v[i];
      while(tmp<=v[i+1])tmp*=4,w[i]++;
      w[i]--;
    }
    else{
      int tmp=v[i+1];
      while(v[i]>tmp)tmp*=4,w[i]--;
    }
  }
  for(int j=0;j<20;j++)dpf[n-1][j]=j;
  for(int i=n-2;i>=0;i--){
    for(int j=0;j<20;j++){
      int a=j-w[i];
      if(a<0)a=0;
      int r=a-19;if(r<0)r=0;
      dpf[i][j]=j+dpf[i+1][min(a,19LL)]+r*(n-i-1);
    }
  }
  reverse(v.begin(),v.end());
  vector<int> w2(n,0);//w[i]:v[i]とv[i+1]がギリギリ昇順になるためにv[i]に何回4をかけるか
  for(int i=0;i<n-1;i++){
    if(v[i]<v[i+1]){
      int tmp=v[i];
      while(tmp<=v[i+1])tmp*=4,w2[i]++;
      w2[i]--;
    }
    else{
      int tmp=v[i+1];
      while(v[i]>tmp)tmp*=4,w2[i]--;
    }
  }
  for(int j=0;j<20;j++)dpg[n-1][j]=j;
  for(int i=n-2;i>=0;i--){
    for(int j=0;j<20;j++){
      int a=j-w2[i];
      if(a<0)a=0;
      int r=a-19;if(r<0)r=0;
      dpg[i][j]=j+dpg[i+1][min(a,19LL)]+r*(n-i-1);
    }
  }
  int ans=LINF;
  for(int i=0;i<=n;i++){
    int a=dpf[i][0]*2;
    int b=dpg[n-i][0]*2;b+=i;
    //cout<<a<<" "<<b<<endl;
    chmin(ans,a+b);
  }
  cout<<ans<<endl;
}

/*
解説AC
+と-の境界線に注目するのもdpしたくなるのもわかっていただけに勿体無い
dpで追わないといけない上限が存在してそれより上は単純な計算でいいってのは覚えておく
*/


Measured memory_bytes: 70400
N = int(input())
SP = []
a = 1
for i in range(N):
    SP.append(input().split())
for i in SP:
    i.append(a)
    a += 1
for i in range(N):
    SP[i][1] = int(SP[i][1])
SP.sort(reverse=True)
SP.sort(key=lambda x: x[0])
for i in range(N):
    print(SP[i][2])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int a, b; cin >> a >> b;
    string s; cin >> s;

    for(int i=0; i<s.size(); i++){
        if(i == a){
            if(s[i] != '-'){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if(!('0' <= s[i] && s[i] <= '9')){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	std::string s;
	std::cin >> s;

	if(s=="Sunny") print("Cloudy");
	if(s=="Cloudy") print("Rainy");
	if(s=="Rainy") print("Sunny");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
signed main() {
  int N, D; string X;
  cin >> N >> X >> D;
  string Y = X;
  REP(i,N) {
    if(D > 0 && X[i] == '0') {
      Y[i] = '1';
      D--;
    }
  }
  REP(i,N) {
    int j = N - i - 1;
    if(D > 0 && X[j] == '1') {
      Y[j] = '0';
      D--;
    }
  }
  cout << Y << endl;
}

Measured memory_bytes: 3200
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    N,X = LMIIS()
    p = [1]*(N+1)
    a = [1]*(N+1)
    for i in range(1,N+1):
        p[i] = p[i-1] * 2 + 1
        a[i] = a[i-1] * 2 + 3
    


    def f(i,y):
        if i == 0:
            return 1
        if y == 1:
            return 0
        if 1 < y <= 1 + a[i-1]:
            return f(i-1,y-1)
        if y == 2 + a[i-1]:
            return p[i-1] + 1
        if 2 + a[i-1] < y <= 2 + a[i-1]*2:
            return p[i-1] + 1 + f(i-1,y-(2+a[i-1]))
        else:
            return p[i-1] * 2 + 1

    print(f(N,X))

    



if __name__ == '__main__':
    main()

Measured memory_bytes: 62040
// https://atcoder.jp/contests/agc025/tasks/agc025_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

const int MOD = 998244353;
const int SZ = 3e5;

template <int N, int M> struct Fact {
    int mod[N + 1];
    int inv_mod[N + 1];
    constexpr Fact() : mod(), inv_mod() {
        mod[0] = 1;
        for (int i = 0; i < N; ++i) {
            mod[i + 1] = (mod[i] * (i + 1)) % M;
        }
        inv_mod[N] = power(mod[N], M - 2);
        for (int i = N - 1; i >= 0; --i) {
            inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
        }
    }

    // aのb乗
    constexpr int power(int a, int b) {
        int r = 1;
        while (b > 0) {
            if ((b & 1) != 0)
                r = (r * a) % M;
            a = (a * a) % M;
            b >>= 1;
        }
        return r;
    }

    // 組み合わせ n C r
    constexpr int comb(int n, int r) {
        return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
    }

    // 重複組み合わせ n H r
    constexpr int homo(int n, int r) { return comb(n + r - 1, n - 1); }
};
Fact<SZ, MOD> facmod;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b, k, ans = 0;
    cin >> n >> a >> b >> k;
    for (int i = 0, j = n; i <= n && i * a <= k; i++) {
        while (i * a + j * b > k)
            j--;
        if (i * a + j * b == k)
            ans = (ans + facmod.comb(n, i) * facmod.comb(n, j)) % MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8280
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>


using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================

	string S;
	cin >> S;

	vstring akihabares = {
		"AKIHABARA",

		"KIHABARA",
		"AKIHBARA",
		"AKIHABRA",
		"AKIHABAR",

		"KIHBARA",
		"KIHABRA",
		"KIHABAR",
		"AKIHBRA",
		"AKIHBAR",
		"AKIHABR",

		"AKIHBR",
		"KIHABR",
		"KIHBAR",
		"KIHBRA",

		"KIHBR",
	};


	for (int i = 0; i < akihabares.size(); i++)
	{
		if (S == akihabares[i])
		{
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;



}





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

int main(){
  int n;cin>>n;
  int a,sum=0;
  for(int i=0;i<n;i++){
    cin>>a;
    while(a%2==0){
      sum++;
      a/=2;
    }
  }
  cout<<sum;
}

Measured memory_bytes: 256
#include <iostream>

const int INF = 1 << 29;

using namespace std;

int main(void){
	int n,m;
	
	while(cin >> n >> m){
		if((n|m) == 0) break;
		int dist[m][m];
		int time[m][m];
		
		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				if(i == j){
					dist[i][j] = 0;
					time[i][j] = 0;
				}else{
					dist[i][j] = INF;
					time[i][j] = INF;
				}
			}
		}
		
		int s, e, cd, ct;
		for(int i=0;i<n;i++){
			cin >> s >> e >> cd >> ct;
			dist[s-1][e-1] = cd;
			dist[e-1][s-1] = cd;
			time[s-1][e-1] = ct;
			time[e-1][s-1] = ct;
		}
		
		//WF
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
					time[i][j] = min(time[i][j], time[i][k] + time[k][j]);
				}
			}
		}
		
		int cases,type;
		cin >> cases;
		for(int i=0;i<cases;i++){
			cin >> s >> e >> type;
			if(type == 0){
				cout << dist[s-1][e-1] << endl;
			}else{
				cout << time[s-1][e-1] << endl;
			}
		}
	}
}

Measured memory_bytes: 940
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> cost(m), mask(m);
  for (int i = 0; i < m; ++i) {
    int len;
    scanf("%d%d", &cost[i], &len);
    while (len--) {
      int x;
      scanf("%d", &x);
      --x;
      mask[i] |= 1 << x;
    }
  }
  vector<int> d(1 << n, INF), e(1 << n);
  d[0] = 0;
  for (int i = 0; i < m; ++i) {
    copy(d.begin(), d.end(), e.begin());
    for (int k = 0; k < (1 << n); ++k) {
      int nxt_k = k | mask[i];
      e[nxt_k] = min(d[k] + cost[i], e[nxt_k]);
    }
    swap(d, e);
  }
  int ret = d[(1 << n) - 1];
  if (ret == INF) ret = -1;
  printf("%d\n", ret);
  return 0;
}


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

int main() {
  int N, ans = 0, max;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
    if (i == 0) {
      ans++;
      max = H.at(i);
    }
    else if(max <= H.at(i)) {
      ans++;
      max = H.at(i);
    }   
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 int n;
 cin >> n;
 vector<ll> a(n);
 ll sum=0;
 rep(i,n){
    cin >> a[i] ;
    sum+=a.at(i);
 }
 ll ans=100000000000000;
 ll suma=0;
 rep(i,n-1){
    suma+=a.at(i);
    ll dif=abs(sum-suma*2);
    ans=min(dif,ans);
 }
 cout << ans << endl;
}



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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N);
  vector<pair<int, int>> p(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i) >> B.at(i);
    p.at(i).first = A.at(i);
    p.at(i).second = B.at(i);
  }
  sort(p.begin(), p.end());
  long long kane = 0;
  int total = 0;
  
  for(int i = 0; i < N; i++){
    total += p.at(i).second;
    if(total >= M){
      kane += p.at(i).first * (long long)(p.at(i).second - (total - M));
      break;
    }
    else kane += p.at(i).first * (long long)p.at(i).second;
  }
  cout << kane << endl;
}

Measured memory_bytes: 4852
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))

l = 0
r = 1
tmp = A[0]
ans = 0
while l<N:
    if r==N:
        ans += r-l
        l += 1
    elif tmp+A[r] == tmp^A[r]:
        tmp = tmp+A[r]
        r += 1
    else:
        ans += r-l
        tmp = tmp-A[l]
        l += 1
print(ans)

Measured memory_bytes: 25216
def gen_primes(N):
    from itertools import compress
    sieve = list(range(N))
    sieve[1] = 0
    for i in range(2, int(N**.5) + 1):
        sieve[i * 2::i] = [0] * len(sieve[i * 2::i])
    return list(compress(range(N), sieve))

N = int(input())
print(*[p for p in gen_primes(55555) if p % 5 == 1][:N])

Measured memory_bytes: 5656
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC165D
//ABC165C

int main(void) {
  long long n, k, i, cou=0, tmp, a, b;
  scanf(" %lld %lld %lld", &a, &b, &n);

  if(b>n){
    printf("%lld", a*n/b);
  }else{
    printf("%lld", a*(b-1)/b);
  }
  return 0;
}

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

int main() {
  int x[3];
  rep(i, 3) cin >> x[i];
  sort(x, x+3);
  if (x[0]%2 == x[1]%2) cout << (x[2]-x[1] + (x[1]-x[0])/2) << endl;
  else if (x[1]%2 == x[2]%2) cout << ((++x[2])-(++x[1]) + (x[1]-x[0])/2) + 1 << endl;
  else cout << ((++x[2])-(x[1]) + (x[1]-(++x[0]))/2) + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;


int main(){
	/*input*/
	int a[3][3];
	int n;
	for(int i = 0; i < 3; i++){
		for(int j =0; j<3; j++ ){
			cin >> a[i][j];
		}
	}
	bool a11=false,a12=false,a13=false,a21=false,a22=false,a23=false,
			a31=false,a32=false,a33=false;

	cin >> n;
	int b[100];
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}
	/*calc*/
	if(n < 4){
		cout<< "No" <<endl;
		return 0;
	}
	for(int i = 0; i< n; i++){
		if(b[i] == a[0][0]){
			a11 = true;
		}
	}
	for(int i = 0; i< n; i++){
		if(b[i] == a[0][1]){
			a12 = true;
		}
	}
	for(int i = 0; i< n; i++){
		if(b[i] == a[0][2]){
			a13 = true;
		}
	}
	for(int i = 0; i< n; i++){
		if(b[i] == a[1][0]){
			a21 = true;
		}
	}
	for(int i = 0; i< n; i++){
		if(b[i] == a[1][1]){
			a22 = true;
		}
	}
	for(int i = 0; i< n; i++){
		if(b[i] == a[1][2]){
			a23 = true;
		}
	}
	for(int i = 0; i< n; i++){
		if(b[i] == a[2][0]){
			a31 = true;
		}
	}
	for(int i = 0; i< n; i++){
		if(b[i] == a[2][1]){
			a32 = true;
		}
	}
	for(int i = 0; i< n; i++){
		if(b[i] == a[2][2]){
			a33 = true;
		}
	}
    /*output*/
	if((a11 && a12 && a13) ||(a21 && a22 && a23) ||(a31 && a32 && a33)
	|| (a11 && a21 && a31) ||(a12 && a22 && a32) ||(a13 && a23 && a33)
	|| (a11 && a22 && a33) ||(a13 && a22 && a31) ){
		cout<< "Yes" <<endl;
	}else{
		cout<< "No" <<endl;
	}
    return 0;
}

Measured memory_bytes: 256
num_list = [] #空リスト作成
for _ in range(5): #5回繰り返す
    num_list.append(int(input())) #標準入力をしてそのままリストに格納
num1 = num_list[0] * num_list[4] #X社の料金計算
if num_list[2] < num_list[4]: #Y社の制限を超えるか
    num2 = num_list[4] - num_list[2] #何L超えるか
    num2 = num2 * num_list[3] + num_list[1] #超えた時のY社の料金計算
else:num2 = num_list[1] #超えなかった時のY社の料金計算
print(min(num1,num2)) #2社の料金が安い方を出力


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int e1,e2,e3,e4,e5,x,y=0;
  
for (int i = A; i <= B; i++){
	x=i;
      
    e1=x%10;
  	x/=10;  
    e2=x%10;
    x/=10;
    e3=x%10;
    x/=10;
	e4=x%10;
    x/=10;
    e5=x%10;
  	x/=10;

  if(e1==e5 && e2==e4) y++;
        
  
                 
	}  
  
  cout << y <<endl;
  
 }
  

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<usize>();
    let h = input[0];
    let w = input[1];

    let mut map: Vec<Vec<char>> = vec![];

    for _ in 0..h {
        let line = read::<String>();
        map.push(line.chars().collect::<Vec<char>>());
    }

    let mut dp = vec![vec![std::usize::MAX; w]; h];
    dp[0][0] = if map[0][0] == '#' {
        1
    } else {
        0
    };
    
    for i in 0..h {
        for j in 0..w {
            if i > 0 && dp[i][j] > dp[i-1][j] {
                dp[i][j] = dp[i-1][j];

                if map[i-1][j] == '.' && map[i][j] == '#' {
                    dp[i][j] = dp[i-1][j] + 1;
                }
            }
            if j > 0 && dp[i][j] > dp[i][j-1] {
                dp[i][j] = dp[i][j-1];

                if map[i][j-1] == '.' && map[i][j] == '#' {
                    dp[i][j] += 1;
                }
            }
        }
    }
    println!("{}", dp[h-1][w-1]);
}


Measured memory_bytes: 2236