akhauriyash/Code-Regression huggingface dataset:
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_D
// Sort II - Minimum Cost Sort

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int MAX_N = 1000;

ui64 n;
int w[MAX_N];
int w_copy[MAX_N];
bool moved[MAX_N];

ui64 solve() {
    for (int i = 0; i < n; ++i) moved[i] = false;
    copy(w, w + n, w_copy);
    sort(w_copy, w_copy + n);

    auto min_all_cost = w_copy[0];

    ui64 min_total_cost = 0;

    const ui64 not_found = n + 1;
    while (true) {
        // find cycle start index
        ui64 cycle_index = not_found;
        for (ui64 i = 0; i < n; ++i) {
            if (!moved[i]) {
                cycle_index = i;
                break;
            }
        }

        // all elements are moved
        if (cycle_index == not_found) break;

        // find cycle
        vector<ui64> cycle_indices;
        while (true) {
            if (find(cycle_indices.begin(), cycle_indices.end(), cycle_index) != cycle_indices.end()) break;
            cycle_indices.push_back(cycle_index);
            cycle_index = find(w_copy, w_copy + n, w[cycle_index]) - w_copy;
        }

        // compute minimum cost in the cycle
        vector<int> cycle_costs;
        for (const auto& i : cycle_indices) cycle_costs.push_back(w[i]);

        auto min_cycle_cost = *min_element(cycle_costs.begin(), cycle_costs.end());
        auto sum_cycle_cost = accumulate(cycle_costs.begin(), cycle_costs.end(), 0);
        min_total_cost += min(
                (cycle_costs.size() - 2) * min_cycle_cost + sum_cycle_cost, // in cycle
                min_cycle_cost + sum_cycle_cost + (cycle_costs.size() + 1) * min_all_cost // borrow min element in w
        );

        // memorize moved elements
        for (const auto& i : cycle_indices) moved[i] = true;
    }

    return min_total_cost;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> w[i];
    auto min_total_cost = solve();
    cout << min_total_cost << endl;
    return 0;
}


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

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

	vector<pair<int, string>> submits(m);
	for (int i = 0; i < m; i++) {
		cin >> submits[i].first >> submits[i].second;
	}

	stable_sort(submits.begin(), submits.end(), [](auto lhs, auto rhs) { return lhs.first < rhs.first; });

	vector<bool> flagsAC(n, false);
	ll countWA = 0;
	vector<ll> cnt(n, 0);
	for (int i = 0; i < m; i++) {
		if (flagsAC[submits[i].first - 1]) continue;

		if (submits[i].second == "AC") {
			flagsAC[submits[i].first - 1] = true;
			countWA += cnt[submits[i].first - 1];
		}
		else {
			cnt[submits[i].first - 1]++;
		}
	}

	ll numOfAC = count(flagsAC.cbegin(), flagsAC.cend(), true);

	cout << numOfAC << " " << countWA << endl;
}


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

int main() {
  long long A, B, K;
  cin >> A >> B >> K;
  if (A > K) {
    A -= K;
    K = 0;
  } else {
    K -= A;
    A = 0;
  }
  if (B > K) {
    B -= K;
    K = 0;
  } else {
    K -= B;
    B = 0;
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll>a(n),b(n);
    vector<pair<ll,ll> >job(n);
    std::priority_queue<pair<ll,ll> >p;


    REP(i,n){
        cin >> a[i] >> b[i];
        job[i]=make_pair(a[i],b[i]);
    }
    SORT(job);
    ll answer=0;
    ll index=0;
    FOR(i,1,m+1){
        while(index < n && job[index].first<=i){
            p.push(make_pair(job[index].second,job[index].first));
            index++;
        }
        //cout << i << " " << p.size() << endl;
        if(p.empty())continue;
        if(p.top().second <= i)
            answer+=p.top().first;
        //cout << answer << endl;
        p.pop();
    }
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 5492
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToLong();
		long wa = 0;
		for(long i = 1; i <= n; i++)
		{
			if(!(i%3 == 0 || i % 5 == 0))
				wa += i;
		}
		Console.WriteLine(wa);
	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;

  bool same = true;

  ll mn = INF;
  vll a(n), b(n);
  rep(i, n) {
    cin >> a[i] >> b[i];

    if (a[i] != b[i]) {
      same = false;
    }

    if (a[i] > b[i]) {
      chmin(mn, b[i]);
    }
  }

  ll sum = accumulate(all(a), 0ll);

  if (same) {
    cout << 0 << endl;
    return 0;
  }

  cout << sum - mn << endl;

  return 0;
}


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

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

	int N,K,Q;
	int i,j;
	int tmp;
	int answer;
	int counter=0;
	double ave;

	cin >> N >> K >> Q;
	
	int points[N]={};

	for(i=0;i<Q;i++){
		cin >> tmp;
		points[tmp-1]++;
	}

	for(i=0;i<N;i++){
		if(K-Q+points[i]>0){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		
		}
	}


	return 0;
}



Measured memory_bytes: 1024
N = int(input())
S=[]
for i in range(N):
    S.append(input())
AC=0
WA=0
TLE=0
RE=0


for i in S:
    if i=="AC":
        AC=AC+1
    elif i=="WA":
        WA=WA+1
    elif i=="TLE":
        TLE=TLE+1
    else:
        RE=RE+1

print("AC x "+str(AC))
print("WA x "+str(WA))
print("TLE x "+str(TLE))
print("RE x "+str(RE))

Measured memory_bytes: 16324
#include <stdio.h>

int main(int argc, char const *argv[]) {
  char str1[27];
  (void)scanf("%s", str1);

  for (size_t i = 1; i < sizeof(str1) / sizeof(str1[0]); i++) {
    if(str1[i] == '\0'){
      printf("yes\n");
      return 0;
    }else{
      for (size_t j = 0; j < i; j++) {
        if (str1[j] == str1[i]) {
          printf("no\n");
          return 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };

signed main() {
	int n, x; cin >> n >> x;
	int cnt = 1;
	int nx = 0;
	rep(i, n) {
		int l; cin >> l; nx += l;
		if (nx <= x)cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int a,b,h;
cin >> a >> b >> h;
cout << (a+b)*h/2 << endl;

return 0;
}

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

int n, a[100005], dp[100005];

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  dp[1] = 0;
  dp[0] = 0x3f3f3f3f;
  for (int i = 2; i <= n; i++)
   	dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]),
                dp[i - 2] + abs(a[i] - a[i - 2]));
  cout << dp[n] << endl;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
int c[2] = {0};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();

  vector<int> v(n);

  for (int i = 0; i < n; i++) {
    if (s[i] == 'L') {
      v[i] += c[i % 2];
      v[i - 1] += c[1 - (i % 2)];
      c[0] = c[1] = 0;
    } else {
      c[i % 2]++;
    }
  }

  c[0] = c[1] = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'R') {
      v[i] += c[i % 2];
      v[i + 1] += c[1 - (i % 2)];
      c[0] = c[1] = 0;
    } else {
      c[i % 2]++;
    }
  }

  cout << v[0];
  for (int i = 1; i < n; i++) cout << " " << v[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 1104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  int N,T;
  int min;
  int i,j,k;
  int c[100],t[100];
  int ans=0;
  scanf("%d %d",&N,&T);
  for(i=0;i<N;i++){
    scanf("%d %d",&c[i],&t[i]);
  }
  
  min=1001;
  for(i=0;i<N;i++){
    if(t[i]>T){
      c[i]=1001;
    }
    if(c[i]<min){
      min=c[i];
    }
  }
  if(min>1000)
    printf("TLE\n");
  else
    printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 128
package main

import "fmt"

func main(){
	var a,b,c int
	fmt.Scanf("%d %d %d", &a, &b, &c)

	disp(a, b, c)
}

func disp(a, b, c int){
	if a + b + c > 21 {
		fmt.Printf("bust\n")
		return
	}
	fmt.Printf("win\n")
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  string s; cin >> s;
  string ans = "AC";
  if(s[0] != 'A') ans = "WA";
  int c = 0;
  for(int i = 2; i < s.size()-1; i++){
    if(s[i] == 'C') c++;
  }
  if(c != 1) ans = "WA";
  c = 0;
  for(int i = 0; i < s.size(); i++){
    if('A' <= s[i] && s[i] <= 'Z') c++;
  }
  if(c != 2) ans = "WA";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
typedef vector<string> vs;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
const ll MOD=1000000007;
const ll mod=998244353;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void precompute(){

	return;
}
void solve(){
	ll a,b,c;
	cin>>a>>b>>c;
	cout<<min(c,a+b+1)+b;
	return;
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	precompute();
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}

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

int main(){
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	
	int dh = 60*h2 + m2 - 60*h1 - m1;
	cout<<dh-k<<endl;
	
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline

def main():
    S=input()

    A=[0]*(len(S)-1)
    mode="L"
    s=0
    b=0
    e=0
    l=0
    for i in range(len(S)):
        c=S[i]
        if mode=="L" and c==mode:
            mode="R"
            b=i-1
        elif mode=="R" and c==mode:
            mode="L"
            e=i-1

            calc(A,s,b,e)
            
            s=i
        elif c=="\n":
            e=i-1
            calc(A,s,b,e)

    print(*A)

def calc(A, s, b, e):
    l=e-s+1

    A[b]=(b-s)//2+(e-b)//2+1
    A[b+1]=l-A[b]

main()

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

const int MAXN=1e5+10;
vector<int> v[MAXN];
int h[MAXN];

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n,m,f=1,ans=0;
    cin>>n>>m;
    
    for(int i=1;i<=n;i++)
        cin>>h[i];
    
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    
    for(int i=1;i<=n;i++){
        f=1;
        for(vector<int>::iterator it=v[i].begin();it!=v[i].end();it++)
            if(!(h[i]>h[*it]))
                f=0;
        if(f==1)
            ans++;        
    }
    
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 10288
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	cout << (min(abs(A - B), abs(A - C)) == abs(A - B) ? 'A' : 'B') << endl;;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s=System.Console.ReadLine();
            int count = 0,_count=0;
            for(int i = 0; i < 3; i++)
            {
                if (s[0] == s[i]) count++;
                if (s[1] == s[i+1]) _count++;
            }
            if (count == 3 || _count == 3) System.Console.WriteLine("Yes");
            else System.Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define MAXN 1000000
#define MOD 998244353
#define LL long long
int n,m;
int inv[MAXN+5],fac[MAXN+5];
int ans;
int fst_pow(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=(1LL*res*a)%MOD;
		a=(1LL*a*a)%MOD;
		b>>=1;
	}
	return res;
}
void prepare()
{
	fac[0]=1;
	for(int i=1;i<=n+m;i++)
	fac[i]=(1LL*fac[i-1]*i)%MOD;
	inv[n+m]=fst_pow(fac[n+m],MOD-2);
	for(int i=n+m-1;i>=0;i--)
	inv[i]=(1LL*inv[i+1]*(i+1))%MOD;
}
int Comb(int a,int b)
{
	return 1LL*(1LL*fac[a]*inv[a-b]%MOD)*inv[b]%MOD;
}
int main()
{
	scanf("%d%d",&n,&m);
	if(n<m)swap(n,m);
	prepare();
	for(int i=1;i<=m;i++)
		ans=(ans+1LL*Comb(2*i,i)*Comb(n+m-2*i,n-i)%MOD)%MOD;
	ans=1LL*ans*fst_pow(Comb(m+n,n),MOD-2)%MOD;
	ans=1LL*ans*fst_pow(2,MOD-2)%MOD;
	printf("%d",ans+n);
}

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

int min(int a, int b){
    if(a < b){
      return a;
    }else{
      return b;
    }
}
int abs(int a){
    if(a<0){
      a=a*(-1);
    }
    return a;
}
int main(){
  int N,K;
  cin>>N>>K;

  
  long long h[N];
  for(long long i=0;i<N;i++){
    cin>>h[i];
  }
  if(N==2){
    cout<<h[1]-h[0]<<endl;
    return 0;
  }
  
  long long dp[N];
  for(long long i=0;i<N;i++){
    dp[i]=1e13;
  }
  dp[0]=0;
  
  for(int i=1;i<N;i++){
    for(int j=max(0,i-K);j<=i;j++){
      dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
    }
  }
  cout<<dp[N-1]<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
	int n,i,j;
	long long int a[10000],b=0,c;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		b+=a[i];
	}
	for(i=0;i<n;i++){
		for(j=n;j>i;j--){
			if(a[j-1]<a[i]){
				c=a[j-1];
				a[j-1]=a[i];
				a[i]=c;
			}
		}
	}
	printf("%lld %lld %lld\n",a[0],a[n-1],b);
	return 0;
}

Measured memory_bytes: 676
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>
#include <iterator>
using namespace std;

namespace {

}

int main()
{
	string S;

	cin >> S;

	string s2 = S.substr(8, 2);

	cout << "2018/01/" + s2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,P,Q,R,x[i];
	scanf("%d%d%d",&P,&Q,&R);
	//A-B=P B-C=Q A-C=R
	
		x[1]=P+R; x[4]=R+Q; 
		x[2]=P+Q;
		x[3]=Q+R; x[5]=Q+P;
		x[6]=R+P;
	 	
	int	min=x[1];
		for(i=1;i<7;i++){
		if(min>x[i]){
			min=x[i];
			}
		}
	printf("%d\n",min);
	
	return 0;
}

		
			

Measured memory_bytes: 128
use input::Input;

fn main() {
    let mut input = Input::default();

    let n = input.parse();
    let a = (0..n).map(|_| input.parse()).collect::<Vec<u64>>();

    let mut x = 0;
    for i in 0..n {
        x ^= a[i];
    }
    for i in 0..n {
        if i > 0 {
            print!(" ");
        }
        print!("{}", x ^ a[i]);
    }
    println!("");
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 15088
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#define MAX_BIT 50
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  bool first=true;
  ll n,k,ans=0,need,eidx;
  cin >> n >> k;
  if(n%2==0) need = n/2-1;
  else need = n/2;
  k++;
  vector<ll> a(n),btc(MAX_BIT);
  for(int i=0;i<n;i++){
    cin >> a[i];
    for(ll j=0;j<MAX_BIT;j++){
      if(a[i]&(1ll << j)){
        btc[j]++;
      }
    }
  }
  for(ll i=0;i<MAX_BIT;i++){
    if(((1ll<<i)&k)== 0){
      continue;
    }
    ll tmp = 0;
    for(ll j=0;j<MAX_BIT;j++){
      if(j<i){
        tmp += (1ll<<j)*max(btc[j],n-btc[j]);
      }else if(j==i){
        tmp += (1ll<<j)*btc[j];
      }else{
        if((k&(1ll<<j))==0){
          tmp += (1ll<<j)*btc[j];
        }else{
          tmp += (1ll<<j)*(n-btc[j]);
        }
      }
    }
    ans = max(tmp,ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
K,N=map(int,list(input().split(" ")))
A=list(map(int,input().split(" ")))
A.sort()
dis=[]
for i in range(N):
    if i==N-1:
        dis.append(A[0]+K-A[i])
    else:
        dis.append(A[i+1]-A[i])
m=max(dis)
print(K-m)



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

int main(){
  string s, t;
  cin >> s >> t;
 
  int ct=0;
  for(int i=0; i<3; i++){
    if(s[i]==t[i]) ct++;
  }
  cout << ct << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	vector<int> a(n), b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];

	set< vector<int> > st;

	int ans = 0,s = 0, t = 1;
	while(s != b.size()) {
		vector<int> v;
		REP(j, s, t) {
			v.push_back(b[j]);
		}

		bool flag = false;
		int id = 0;
		rep(j, n) {
			if(a[j] == v[id]) {
				id++;
				if(id == v.size()) {
					flag = true;
					break;
				}
			}
		}

		if(flag) {
			t++;
			ans = max(ans, (int)v.size());
		} else {
			s++;
			if(s == t) t++;
		}

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1312
/**
 * author:    Ziel
 * created:   13.04.2020 19:42:34
**/

#include <bits/stdc++.h>

using namespace std;

const int N = 100100, INF = 1000000100;

int n, k, h[N];
long long dp[N];

int main() {
	scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d", h + i);
    }
    for (int i = 2; i <= n; i++) {
        dp[i] = INF;
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= k && i - j >= 1; j++) {
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    printf("%lld", dp[n]);
    
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,x,y,z,l,n,m,a,r,f;
  long long min,max,sum;
  //vector<vector<int>> A(n, vector<int>(m, 0));
  vector<int> B(26, 0);
  string s,g;
  string s1;
  
  sum = 0;
  while(1){
  	cin >> s;
    if(s == "-")break;
    cin >> n;
    for(int i=0;i<n;++i){
      cin >> m;
      g = s.substr(0, m);
      s.erase(0, m);
      s += g;
    }
    
    cout << s << endl;
  }
}


Measured memory_bytes: 3168
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>



ll f(ll h)
{
	if (h==1) return 1;
	if (h>1) return 1+2*f(h/2);
}



int main(int argc, char *argv[])
{
	ll h;
	cin >>h;

	cout<<f(h)<<endl;
	return 0;
}


Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

i = 0

while A > 0 or C > 0:
    if i % 2 == 0:
        C = C - B
    else:
        A = A - D

    if A <= 0:
        print('No')
        break
    elif C <= 0:
        print('Yes')
        break

    i+=1

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<long int> a(n);
  vector<pair<long int, long int>> cb(m);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  for(int i = 0; i < m; i++){
    long int b_tmp, c_tmp;
    cin >> b_tmp >> c_tmp;
    cb.at(i) = make_pair(c_tmp, b_tmp);
  }
  sort(a.rbegin(), a.rend());
  sort(cb.rbegin(), cb.rend());
  int j = 0;
  int count = 0;
  long int out = 0;
  for(int i = 0; i < n; i++){
    if(count == n) break;
    if(j < m){
      while(a.at(i) <= cb.at(j).first){
        if(n - count - cb.at(j).second >= 0){
          out += cb.at(j).first * cb.at(j).second;
          count += cb.at(j).second;
          j++;
          if(j == m) break;
        }else{
          out += cb.at(j).first * (n - count);
          count += n - count;
          break;
        }
      }
    }
    if(count == n) break;
    count++;
    out += a.at(i);
  }
  cout << out;
}

Measured memory_bytes: 2560
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  }
  template<class T>inline void Max(T &x, T y) {
    if (y > x) x = y;
  }
  template<class T>inline void Min(T &x, T y) {
    if (y < x) x = y;
  }
}
using namespace Header_Template;

const int N = 1e5 + 10;
int n;
li c, v[N], x[N], s[N];
li a[N], b[N];
multiset<li> S;

int main(void) {
  read(n), read(c);
  for (int i = 1; i <= n; ++i)
    read(x[i]), read(v[i]);
  s[0] = 0;
  for (int i = 1; i <= n; ++i)
    s[i] = s[i - 1] + v[i];

  li ans = 0;
  for (int i = 1; i <= n; ++i) {
    a[i] = s[i] - x[i];
    b[i] = s[n] - s[i - 1] - (c - x[i]);
    Max(ans, max(a[i], b[i]));
  }
  for (int i = 1; i <= n; ++i) S.insert(b[i]);
  for (int i = 1; i <= n; ++i) {
    S.erase(S.find(b[i]));
    if (S.size()) Max(ans, a[i] - x[i] + *--S.end());
  }
  S.clear();
  for (int i = 1; i <= n; ++i) S.insert(a[i]);
  for (int i = n; i; --i) {
    S.erase(S.find(a[i]));
    if (S.size()) Max(ans, b[i] - (c - x[i]) + *--S.end());
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << 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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

vector<pair<ll, char>> RLE(const string &s) {
	ll cnt = 0;
	ll n = s.length();
	vector<pair<ll, char>> res;
	for (ll i = 0; i < s.size(); i++) {
		cnt++;
		if (i == (ll)s.size()-1) {
			res.push_back(make_pair(cnt,s[i]));
			break;
		}
		if (s[i] != s[i+1]) {
			res.push_back(make_pair(cnt,s[i]));
			cnt = 0;
		}
	}
	return res;
}

int main(int argc, char const *argv[]) {
    ll n,k; cin>>n>>k;
    string s; cin>>s;

    vector<pair<ll, char>> t = RLE(s);
    int ans = 0;
    for (auto &&e: t) ans += e.first-1;

    cout << min(n-1, ans+k*2) << '\n';

    return 0;
}

Measured memory_bytes: 2548
N = (int)(input())
T = list(map(lambda x: int(x), input().split()))
V = list(map(lambda x: int(x), input().split()))

dp = [[-float('inf')]*(101) for _ in range(N+1)]
V.append(0)

dp[0][0] = 1

for i in range(N):
    for v in range(V[i]+1):
        for vv in range(V[i]+1):
            past_dist = dp[i][v]
            if 2*V[i]-v-vv <= T[i]:
                a = V[i]-v
                b = V[i]-vv
                c = (v+V[i])*a/2 + V[i]*(T[i] - a - b) + (vv+V[i])*b/2
                dp[i+1][vv] = max(dp[i+1][vv], c+past_dist)
            elif T[i] >= abs(vv-v):
                ta = (vv-v+T[i])/2
                tb = (T[i]+v-vv)/2
                c = (2*v+ta)*ta/2 + (vv+v+ta)*tb/2
                dp[i+1][vv] = max(dp[i+1][vv], c+past_dist)

print(dp[N][0]-1)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  FOR(i, 1, 10) FOR(j, 1, 10) {
    if (i * j == n) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> l(n);
    int sum = 0;
    for (int i=0; i<n; ++i){
        cin >> l[i];
        sum += l[i];
    }
    sort(l.begin(), l.end());
    if(l[n-1] < sum - l[n-1]){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


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

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

	ll ans = 10000000000;

	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			int a = 1, b = 1;
			ll c = i, d = n / i;
			//cout << c << ' ' << d << endl;
			while (c >= 10) {
				c /= 10;
				a++;
			}
			while (d >= 10) {
				d /= 10;
				b++;
			}
			//cout << a << ' ' << b << endl;
			ans = min(ans, (ll)max(a, b));
		}
	}

	dunk(ans);

	return 0;
}

Measured memory_bytes: 256
// I am bad ok?
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e5 + 5;

int c[N];
string s;

int32_t main() { cin.tie(0)->sync_with_stdio(0);
  cin >> s;
  int n = s.size();
  s = ' ' + s;
  for (int i = 1; i <= n; i++) {
    s[i] -= 'a';
  }
  for (int ch = 0; ch < 26; ch++) {
    set<int> s;
    memset(c, 0, sizeof c);
    for (int i = 1; i <= n; i++) {
      c[i] = c[i - 1] + (::s[i] == ch);
      auto k = s.lower_bound(2 * c[i] - i);
      if (k != s.begin()) {
        k--;
        for (int j = 0; j <= i - 2; j++) {
          if (2 * c[j] - j < 2 * c[i] - i) {
            return cout << j + 1 << ' ' << i, 0;
          }
        }
      }
      s.insert(2 * c[i - 1] - (i - 1));
    }
  }
  cout << -1 << ' ' << -1;
}

Measured memory_bytes: 8444
#include <stdio.h>

int main()
{
    int contests, displayRating, innerRating = 0;
    
    scanf("%d %d", &contests, &displayRating);
    
    if(contests < 10)
    {   // diplayRating = innerRating - (100 * (10 - contests) with math transformation gives:
        innerRating = displayRating + (100 * (10 - contests));
    }
    else
    {
        innerRating = displayRating;
    }
    
    printf("%d", innerRating);
    
    return 0;
}


Measured memory_bytes: 128
n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    A,B,C=map(int,input().split())
    a.append(A)
    b.append(B)
    c.append(C)

dp=[ [0]*3 for _ in range(n+1) ]

for i in range(n):
    dp[i+1][0]= max( dp[i][1]+a[i] , dp[i][2]+a[i] )
    dp[i+1][1]= max( dp[i][0]+b[i] , dp[i][2]+b[i] )
    dp[i+1][2]= max( dp[i][0]+c[i] , dp[i][1]+c[i] )
print(max(dp[n]))

Measured memory_bytes: 77784
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;

int main(){
    int N; 
    cin >> N;
    int A[200000];
    int order[200000];
    for (int i = 1; i <= N; i++){
        cin >> A[i];
    }
    for(int i = 1; i <= N; i++){
        order[A[i]] = i;
    }
    for(int i = 1; i <= N; i++){
        cout << order[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 4376
#include <stdio.h>

int main(void){

    int n,x,t,a;

    scanf("%d %d %d",&n,&x,&t);


    if(n%x==0){
        a = n/x;
    }else{
        a = n/x +1;
    }
    printf("%d\n",a*t);

    return 0;
}

Measured memory_bytes: 1728
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        if b==[a[k][j:j+m] for k in range(i,i+m)]:print('Yes');exit()
        else:pass
print('No')

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

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

print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include <stdio.h>
int main(void){
    int array[1001];
    int i,j,a,n;
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d",&a);
        array[i]=a; 
        }
    
    for(j=n;j>0;j--){
        
        if(j==1) printf("%d",array[j-1]);
        else printf("%d ",array[j-1]);
    }
    
    printf("\n");
    return 0;
}


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

int main(){
  int n,p; cin>>n>>p;
  string s; cin>>s;
  if(p==2||p==5){
    ll cnt=0;
    REP(i,n)if((s[i]-'0')%p==0)cnt+=i+1;
    cout<<cnt<<endl;
    return 0;
  }
  vector<ll> cnt(p);
  ll cur=0,t=1;
  cnt[0]=1;
  REP(i,n){
    cur=t*(s[n-i-1]-'0')+cur;
    cur%=p;
    t=10*t%p;
    cnt[cur]++;
  }
  ll ans=0;
  REP(i,p)ans+=cnt[i]*(cnt[i]-1)/2;
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "AC") {
      ac += 1;
    } else if (s == "WA") {
      wa += 1;
    } else if (s == "TLE") {
      tle += 1;
    } else if (s == "RE") {
      re += 1;
    }
  }
  cout << "AC x " << ac << '\n';
  cout << "WA x " << wa << '\n';
  cout << "TLE x " << tle << '\n';
  cout << "RE x " << re << '\n';
  return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
 
int main() {
	string s,t ;
	cin >> s >> t;
	string st = t.substr(0, t.size()-1);
	if(st==s)
		cout << "Yes";
	else
		cout << "No";
	return 0;

}

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

int main(){
  int n,x,y; cin>>n>>x>>y;
  x-=1;
  y-=1;
  
  vector<int> dist(n,0);
  for (int i=0; i<n-1; i++){
    for (int j=i+1; j<n; j++){
      dist[min(j-i,abs(i-x)+1+abs(j-y))]+=1;
    }
  }
  
  for (int k=1; k<=n-1; k++) cout<<dist[k]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int main() {
  int n;
  for(;;) {
    cin >> n;
    if(n == 0) break;
    string s[n];

    int pm, pe, pj;
    for(int i=0; i<n; ++i) {
      cin >> pm >> pe >> pj;
      if(pm == 100 || pe == 100 || pj == 100) s[i] = "A";
      else if((pm + pe) / 2 >= 90) s[i] = "A";
      else if((pm + pe + pj) / 3 >= 80) s[i] = "A";
      else if((pm + pe + pj) / 3 >= 70) s[i] = "B";
      else if((pm + pe + pj) / 3 >= 50 && (pm >= 80 || pe >= 80)) s[i] = "B";
      else s[i] = "C";
    }

    for(int i=0; i<n; ++i) cout << s[i] << endl;

  }
}




Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int a;
  cin >> a;
  if(a==111){
    cout << 3;
  }
  if(a==11){
    cout << 2;
  }
  if(a==101){
    cout << 2;
  }if(a==110){
    cout << 2;
  }if(a==1){
    cout << 1;
  }if(a==10){
    cout << 1;
  }if(a==100){
    cout << 1;
  }if(a==0){
    cout << 0;
  }
}


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

const char* echo(int N, char* S) {
  if(N % 2 == 1) {
    return "No";
  }

  for(int i=0; i < N/2 ;i++){
        if(S[i] != S[i + N/2]){
            return "No";
        }
    }

  return "Yes";
}

int main() {
    int N;
    char S[102];
    scanf("%d %s", &N, S);
  printf("%s\n", echo(N, S));

  return 0;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n, m;
    while(cin >> n >> m, n||m){
        int ans = -1, x = 0,face[1005];
        rep(i,n) cin >> face[i];
        rep(j,m){
            int inp;
            cin >> inp;
            x+=inp;
            x = min(x, n - 1);
            x+=face[x];
            if(x >= n - 1 && ans == -1){
                ans = j + 1;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1164
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            long ans = 0;
            for (int a = 1; a <= k; a++)
                for (int b = 1; b <= k; b++)
                    for (int c = 1; c <= k; c++)
                        ans += gcd(a, gcd(b, c));
            out.println(ans);
        }

        int gcd(int a, int b) {
            if (b == 0)
                return a;
            else
                return gcd(b, a % b);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  ll N;
  cin >> N;
  vector<ll> a(5);
  REP(i, 5) cin >> a[i];
  ll mn = a[0];
  REP(i, 5) {
    if (a[i] < mn) mn = a[i];
  }
  cout << ((N + mn - 1) / mn) + 4ll << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    vector<pair<string, int>> v;
    REP(i, N){
        string s;
        cin >> s;
        int t;
        cin >> t;
        v.pb(pair<string, int>(s,t));
    }
    string X;
    cin >> X;
    
    int ans = 0;
    bool f = false;
    REP(i, N){
        if(f) ans += v[i].se;
        if(v[i].fi == X) f = true;
    }

    pr(ans);
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	//ios::sync_with_stdio(false);
	ll N, v;
	while(cin>>N) {
		deque<ll> q;
		bool pb = true;
		REP(i, N) {
			cin>>v;
			if(pb) q.push_back(v);
			else q.push_front(v);
			pb = !pb;
		}
		if(!pb) reverse(ALL(q));
		stringstream ss;
		REP(i, N) {
			ll v = q.front(); q.pop_front();
			cout<<v;
			if(i+1<N) cout<<" ";
		}
		cout<<endl;
	}
	
	return 0;
}


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

const int N = 3e5 + 5, MOD = 998244353;

using i64 = long long;

i64 fact[N], inv[N];

i64 ant, k, a, b;
int n;


static i64 expow(i64 b, i64 e) {
	i64 ant = 1;
	for (; e > 0; e/= 2) {
		if (e % 2)
			ant = ant * b % MOD;
		b = b * b % MOD; }
	return ant; }

static i64 comb(int n, int k) {
	return fact[n] * inv[k] % MOD * inv[n - k] % MOD; }


int main() {
#ifdef HOME
	freopen("agc25b.in", "r", stdin);
	freopen("agc25b.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	fact[0] = 1;
	for (int i = 1; i < N; ++i)
		fact[i] = fact[i - 1] * i % MOD;
	inv[N - 1] = expow(fact[N - 1], MOD - 2);
	for (int i = N - 2; i >= 0; --i)
		inv[i] = inv[i + 1] * (i + 1) % MOD;

	cin >> n >> a >> b >> k;

	for (int i = 0; i <= n && i * a <= k; ++i)
		if ((k - i * a) % b == 0 && (k - i * a) / b <= n)
			ant = (ant + comb(n, i) * comb(n, (k - i * a) / b)) % MOD;

	cout << ant << endl;

	return 0; }



Measured memory_bytes: 4992
//by yjz
#include<bits/stdc++.h>
#include<ctime>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
char s[500111];
int n;
int inc1()
{
	s[0]++;
	int it=0;
	while(s[it]>'9')s[it]-=10,s[++it]++;
	n=max(n,it+1);
	return it;
}
int main()
{
	scanf("%s",s);
	n=strlen(s);
	reverse(s,s+n);
	int cnt=0;
	int lastmx=-1,lasti=-1,lastupd=-1;
//	cerr<<"n="<<n<<endl;
	while(n)
	{
		cnt++;
		int i=n-1,mx=-1,pre=-1;
		if(lasti<=i&&lastupd+1<=i&&lastmx!=-1)
		{
			mx=lastmx;
			pre=n-1;
			i=max(lasti,lastupd+1);
			
		}
//		cerr<<"i="<<i<<endl;
		bool failed=0;
		for(;i>=0;i--)
		{
//			cerr<<i<<":"<<mx<<endl;
			if(s[i]-'0'>mx)
			{
				mx=s[i]-'0';
				pre=i;
			}
			else if(s[i]-'0'<mx)
			{
				failed=1;
				lastmx=mx;lasti=i+1;
				for(int j=pre;j<n;j++)s[j]='0';
				n=pre;
				lastupd=inc1();
				break;
			}
		}
		while(n>0&&s[n-1]=='0')n--;
//		cerr<<"n="<<n<<endl;
//		for(int i=n-1;i>=0;i--)cerr<<s[i];cerr<<endl;
		if(!failed)break;
	}
	putsi(cnt);
	return 0;
}

Measured memory_bytes: 768