akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int n;
ll a[100010];


bool rec(){
	int even=0;
	rep(i,n) if(a[i]%2==0) even++;
	const int odd=n-even;
	if(even%2==1) return true;
	if(even%2==0 and odd!=1) return false;
	ll g=0;
	
	bool minus=false;
	
	rep(i,n){
		if(a[i]>=2 and a[i]%2==1){
			a[i]--;
			minus=true;
		}
	}

	if(minus==false) return false;

	rep(i,n) g=__gcd(g,a[i]);
	rep(i,n) a[i]/=g;

	return rec()==false;
}

int main(void){
	cin >> n;
	rep(i,n) cin >> a[i];

	if(rec())
		puts("First");
	else
		puts("Second");


	return 0;
}

Measured memory_bytes: 1024
from collections import Counter
N,C = map(int, input().split())
cost = [list(map(int, input().split())) for _ in range(C)]
color = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

# 3 groups
mod3 = {0:[], 1:[], 2:[]}
for i in range(N):
    for j in range(N):
        m = (i+j)%3
        mod3[m].append(color[i][j])

cnts = [Counter(mod3[i]) for i in range(3)]

ans = float('inf')
for p1 in range(C):
    for p2 in range(C):
        if p2==p1: continue
        for p3 in range(C):
            if p3==p1 or p3==p2: continue
            p = [p1,p2,p3]
            cond = 0
            for i in range(3):
                for col in cnts[i].keys():
                    cond += cnts[i][col]*cost[col][p[i]]
            ans = min(ans, cond)
            #print(cond, p)
print(ans)
    

Measured memory_bytes: 7948
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(input())

    An = map(int, input().split())
    Bn = map(int, input().split())
    Cn = map(int, input().split())

    A = sorted(An)
    B = sorted(Bn)
    C = sorted(Cn)

    print(sum([bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in B]))
    return


main()


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

n,m = map(int,input().split())
A = []
B = []
C = []
for i in range(m):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    c_list = list(map(int,input().split()))
    c = 0
    for j in range(B[i]):
        c += 2**(c_list[j]-1)
    C.append(c)

dp = [[10**9]*(2**n) for _ in range(m+1)]
dp[0][0] = 0

for i in range(1,m+1):
    for j in range(2**n):
        dp[i][j] = min(dp[i][j],dp[i-1][j])
        dp[i][j|C[i-1]] = min(dp[i][j|C[i-1]], dp[i-1][j]+A[i-1])

print(dp[m][2**n-1] if dp[m][2**n-1]!=10**9 else -1)

Measured memory_bytes: 75244
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,m;
cin>>n>>m;

long long ans[n]={0};
long long wans[n]={0};
for(int i=0;i<m;i++){
  int p;
  string s;
  cin>>p>>s;
  if(ans[p-1]==0&&s=="AC"){
    ans[p-1]=1;
  }
  if(ans[p-1]==0&&s=="WA"){
    wans[p-1]++;
  }
}
long long ans1=0;
long long ans2=0;
for(int i=0;i<n;i++){
  if(ans[i]==1){
    ans1++;
    ans2+=wans[i];
  }
}
cout<<ans1<<' '<<ans2<<endl;

  return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>


int main()
{
	using namespace std;

	// \[gÎÛÆ·éReiðpÓ
	deque<int> nums;
	for(int i=0;i<10;i++){
		int temp=0;
		cin>>temp;
		nums.push_back(temp);
	}

	// \[gÀs
	sort( nums.begin(), nums.end(),greater<int>());

	// ÊðoÍ
	deque<int>::iterator it = nums.begin();
	
	for(int i=0;i<3;i++){
		cout << *it << endl;
		++it;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
const int MAX=1e9+7;
const int mod=1e9+7;
#define INF 0x3f3f3f3f
#define ll long long

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int t;
	cin>>t;
	if(t&1)cout<<(t+1)/2;
	else cout<<t/2;
	
	
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long dp[3010][3010];
int a[3010];
 
void solve()
{
  int n; cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    dp[i][i] = a[i];
  }
  
  for (int len = 2; len <= n; len++)
  {
    for (int i = 0; i + len - 1 < n; i++)
    {
      int j = i + len - 1;
      dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);
    }
  }
  
  if (n % 2 == 1) cout << dp[0][n - 1] << endl;
  else cout << dp[0][n - 1] << endl;
}
 
int main()
{
  solve();
  return 0;
}

Measured memory_bytes: 70016
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int f1,f2;
	f1=a/100;
	f2=a%100;
	if(1<=f1&&f1<=12&&1<=f2&&f2<=12)
	{
		cout<<"AMBIGUOUS";
	} else if(1<=f1&&f1<=12&&(f2<1||f2>12))
	cout<<"MMYY";
	else if(1<=f2&&f2<=12&&(f1<1||f1>12))
	cout<<"YYMM";
	else cout<<"NA";
	return 0;
	
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define mod 1000000007
using namespace std;

int main() {
	int n;
	cin >> n;
	long long int ans;
	ans = 1;
	for (int i = 1; i <= n; i++)
		ans = ans * i % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import math

N, H = map(int, input().strip().split(" "))
al = []
bl = []
for i in range(N):
    a, b = map(int, input().strip().split(" "))
    al.append(a)
    bl.append(b)

a_max = max(al)
sorted_bl = sorted(filter(lambda b: b > a_max, bl))[::-1]

attacks = 0
for b in sorted_bl:
    H -= b
    attacks += 1
    if H <= 0:
        break

a_attacks = max(math.ceil(H / a_max), 0) #Hがマイナスの時を場合わけで0にしないと、
print(attacks + a_attacks)

Measured memory_bytes: 12472
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
  int n;
  cin>>n;
  vint v(n);
  rep(i,n) cin>>v[i];
  reverse(ALL(v));
  rep(i,n){
    if(i) cout<<" ";
    cout<<v[i];
  }
  cout<<endl;
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1196
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dict := make(map[string]int)
	dict[" "] = 0
	dict["I"] = 1
	dict["V"] = 5
	dict["X"] = 10
	dict["L"] = 50
	dict["C"] = 100
	dict["D"] = 500
	dict["M"] = 1000
	for scanner.Scan() {
		line := strings.Split(scanner.Text(), "")
		line = append(line, " ")
		sum := 0
		for i := 0; i < len(line)-1; i++ {
			if dict[line[i]] < dict[line[i+1]] {
				sum -= dict[line[i]]
			} else {
				sum += dict[line[i]]
			}
		}
		fmt.Println(sum)
	}
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N, K;
    cin >> N >> K;
    
    vec<int> h(N+10);
    rep(i, N) cin >> h[i];
    vec<int> dp(N+10,1e9+7);
    dp[1] = 0;

    for(int i=1;i<=N-1;++i)for(int j=1;j<=K&&i+j<=N;++j){
        dp[i+j] = min(dp[i+j],dp[i]+abs(h[i-1]-h[i+j-1]));
    }
    cout << dp[N] << endl;
}


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

using i8  = int8_t;using i16 = int16_t;using i32 = int32_t;using i64 = int64_t;using u8  = uint8_t;using u16 = uint16_t;using u32 = uint32_t;using u64 = uint64_t;using f32 = float;using f64 = double;
using vi32 = vector<i32>;using vi64 = vector<i64>;using vvi32 = vector<vi32>;using vvi64 = vector<vi64>;using pi32 = pair<i32,i32>;using pi64 = pair<i64,i64>;

#define FOR(i,a,b) for(i64 i=(a), i##_len=(b); i<i##_len; ++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,x) for(i64 i=1;i<=(i64)(x);i++)
#define RREPS(i,x) for(i64 i=((i64)(x));i>0;i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define SZ(x) ((i64)(x).size())
#define CLR(ar,val) memset(ar, val, sizeof(ar))
#define cauto const auto&
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

i32 dx[4]={1,0,-1,0};
i32 dy[4]={0,1,0,-1};
const i32 INF32 = 0x3F3F3F3F;
const i64 INF64 = 0x3F3F3F3F3F3F3F3F;

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void Main();
i32 main() {cin.tie(nullptr);ios_base::sync_with_stdio(false);cout << fixed << setprecision(15);Main();return 0;}

void Main() {
    //-------------------------------------------------------------------------
    i64 n; cin >> n;
    i64 arr[n];
    REP(i,n) cin >> arr[i];
    i64 ans = 0;
    for (i64 i = 0; i < n; i++) {
        i64 minj = i;
        for (i64 j = i; j < n; j++) {
            if (arr[j] < arr[minj]) minj = j;
        }
        if (i != minj) {
            ans++;
            arr[i] ^= arr[minj] ^= arr[i] ^= arr[minj];
        }
    }
    for (i64 i = 0; i < n; i++) cout << arr[i] << (i == (n - 1) ? '\n' : ' ');
    cout << ans << endl;
    //-------------------------------------------------------------------------
}


Measured memory_bytes: 3156
card=[]
card_m=[]
for i in ('S','H','C','D'):
	for j in range(1,14):
		a=i+' '+str(j)
		card.append(a)
b=int(input())
for i in range(b):
	c=input()
	card.remove(c)
for j in range(len(card)):
	print(card[j])
	
	


Measured memory_bytes: 5600
N = int(input())

def nume(x):
    return x*(x-1)/2-(x-1)

save = []

for i in range(N):
    s = ''.join(sorted(input()))
    save.append(s)

save.sort()

cnt = 0
serial = 1
for i in range(N-1):
    if save[i] == save[i+1]:
        cnt += 1
        serial += 1
    else:
        cnt += int(nume(serial))
        serial = 1

cnt += int(nume(serial))
print(cnt)

Measured memory_bytes: 10640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

string s;
int dp[212345][28];
int previ[212345][28]; // prev-i

int g[212345][28];

int main() {
	cin >> s;
	
	REP(i, s.size()) s[i] -= 'a';
	s.insert(0, "a"); s[0] = 26; // st
	s += (char)(27); // ed
	
	REP(i, 28) g[0][i] = 0;
	
	REP(i, s.size() - 1) {
		REP(j, 28) {
			if (s[i] == j) continue;
			g[i + 1][j] = g[i][j];
		}
		g[i + 1][s[i]] = i;
	}
	
	memset(previ, -1, sizeof(previ));
	fill(dp[0], dp[s.size()], INF);
	
	dp[s.size() - 1][27] = 0;
	
	for (int i = s.size() - 1; i > 0; i--) { // 0-indexed
		REP(j, 28) {
			if (dp[i][j] == INF) continue;
			REP(k, 26) {
				if (chmin(dp[g[i][k]][s[i]], dp[i][j] + 1))
					previ[g[i][k]][s[i]] = i;
			}
		}
	}
	
	vector<string> v;
	
	REP(i, 28) {
		if (dp[0][i] == INF) continue;
		int pos = previ[0][i], cnt = dp[0][i];
		
		string now = "";
		REP(j, 26) if (g[pos][j] == 0) {
			now += j + 'a';
			break;
		}
		
		while (pos != s.size() - 1) {
			now += s[pos] + 'a';
			REP(j, 28) if (dp[pos][j] == cnt - 1) {
				pos = previ[pos][j];
				cnt--;
				break;
			}
		}
		
		v.push_back(now);
	}
	
	sort(ALL(v));
	int mi = INF;
	string ans;
	REP(i, v.size()) if (chmin(mi, v[i].size())) ans = v[i];
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 70276
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = -1000000;
        int min = 1000000;
        long sum = 0;
        for(int i=0; i<n; i++){
            int a = sc.nextInt();
            if(a>max){
                max = a;
            }
            if(a<min){
                min = a;
            }
            sum += a;
        }
        System.out.println(min + " " + max + " " + sum);
    }
}


Measured memory_bytes: 42180
#include <stdio.h>
#include <string.h>
int main(void){
    char s[200100]={'\0'};
    scanf("%s",s);
    int loop1;
    int st=-1;
    int go=-1;
    for(loop1=0;loop1<200001;loop1++){
        if(st==-1){
            if(s[loop1]=='A'){
                st=loop1;
            }
        }
        if(st!=-1){
            if(s[loop1]=='Z'){
                go=loop1;
            }
        }
    }
    int ans=go-st;
    printf("%d\n",ans+1);
    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	vector<bool>primes(100100,true);
	primes[0] = false; primes[1] = false;
	for(int i = 2; i<100100; ++i){
		if(primes[i]){
			for(int j = 2; i*j<100100; ++j){
				primes[i*j] = false;
			}
		}
	}
	vector<bool> likes(100100,false);
	for(int i = 3; i<100100; ++i){
		if(primes[i]){
			if(primes[(i+1)/2]){
				likes[i] = true;
			}
		}
	}
	vector<int> cnt(100100, 0);
	REP(i,100010){
		cnt[i] += cnt[i-1] + (likes[i]);
	}
	int Q; cin>>Q;
	vector<ip> in(Q);
	rep(i,Q)cin>>in[i].first>>in[i].second;
	rep(i,Q){
		cout<<cnt[in[i].second] - cnt[in[i].first-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 1000000007


int main() {

	int c = 0;
	string s,t;
	cin>>s>>t;
	for(ll i=0;i<3;i++)
		if(s[i]==t[i])
			c++;
	cout<<c<<endl;
		

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,ll> P;
typedef vector<P> vip;

int psm(int a){
    int ret=0;
    while(a!=0){
        ret+=a%10;
        a/=10;
    }
    return ret;
}
void solve(){
    int n,a,b;cin>>n>>a>>b;
    int ans = 0,c;
    for (int i=1;i<=n;i++){
        c = psm(i);
        if (c>=a&&c<=b) ans+=i;
    }
    cout << ans <<endl;
}

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


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

using namespace std;
const int inf=0x3f3f3f3f;
int main()
{
    int n;
    scanf("%d",&n);
    int x=1;
    while(x<=n)
    {
        x*=2;
    }
    cout<<x/2<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val a = readLine()!!.split(" ").map{it.toLong()}
    val uf = UnionFind(N + 1L)

    for (i in 1..M) {
        val (x, y) = readLine()!!.split(" ").map{it.toLong()}
        uf.unite(x, y)
    }

    val qs = Array(N + 1) { PriorityQueue<Long>() }
    for (i in 0L until N) {
        val v = uf.find(i).toInt()
        qs[v].add(a[i.toInt()])
    }

    if (N - 1 == M) {
        println(0)
        return
    }

    var res = 0L
    var cnt = 0
    val Q = PriorityQueue<Long>()

    for (i in 0 until N) {
        if (qs[i].isNotEmpty()) {
            cnt++
            res += qs[i].poll()
            Q.addAll(qs[i])
        }
    }

    while (Q.isNotEmpty() && cnt < (N - M - 1) * 2) {
        res += Q.poll()
        cnt++
    }

    if (cnt == (N - M - 1) * 2) {
        println(res)
    } else {
        println("Impossible")
    }
}

class UnionFind(n: Long) {
    val size = n.toInt()

    private val parent: Array<Long>
    private val cardinality: Array<Long>

    init {
        parent = Array(size) { -1L }
        cardinality = Array(size) { 1L }
    }

    /**
     * Find a root element of a set `x` belongs to.
     */
    fun find(x: Long): Long {
        return if (parent[x.toInt()] == -1L) {
            x
        } else {
            parent[x.toInt()] = find(parent[x.toInt()])
            parent[x.toInt()]
        }
    }

    /**
     * Unite sets contain two elements `x` and `y`.
     * If `x` and `y` already belong to a same set, nothing happens.
     *
     * @return If `x` and `y` belong to a same set, return false.
     */
    fun unite(x: Long, y: Long): Boolean {
        val u = find(x).toInt()
        val v = find(y).toInt()
        if (u == v) {
            return false
        }

        val newSize = cardinality[v] + cardinality[u]

        if (cardinality[u] < cardinality[v]) {
            parent[u] = v.toLong()
            cardinality[v] = newSize
        } else {
            parent[v] = u.toLong()
            cardinality[u] = newSize
        }

        return true
    }

    /**
     * Check whether `x` and `y` belongs to a same set.
     *
     * @return `true` if `x` and `y` are in a same set.
     */
    fun same(x: Long, y: Long): Boolean {
        return find(x) == find(y)
    }

    /**
     * Get a size of a set `x` belongs to.
     */
    fun getCardinalityOf(x: Long): Long {
        return cardinality[find(x).toInt()]
    }
}


Measured memory_bytes: 97760
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define fs first
#define sc second
#define P pair<int, int>
#define mk_p make_pair
const int N = 2e5 + 11;
int n, a[N], sum[N], K;
int main(){
	cin>>n>>K;
	for(int i = 1;i <= n; i++)scanf("%d", &a[i]), sum[i] = sum[i-1] + a[i] + 1;
	int ans = 0;
	for(int i = 1;i <= n - K + 1; i++){
		int r = i + K - 1;
		ans = max(ans, sum[r] - sum[i-1]);
	}
	printf("%.15lf\n", 1.0 * ans / 2.0);
	return 0;
}

Measured memory_bytes: 1792
import sys


def input():
    return sys.stdin.readline()[:-1]


H, W = map(int, input().split())

A = [[1 if s == "#" else 0 for s in input()] for i in range(H)]

lu = [[1<<20] * (W+2) for j in range(H + 2)]

for ii in range(H * W):
    i = ii // W + 1
    j = ii % W + 1
    lu[i][j] = min(lu[i - 1][j], lu[i][j - 1]) + 1
    if A[i - 1][j - 1]:
        lu[i][j] = 0
    elif j < W and A[i - 1][j]:
        lu[i][j] = 1

for ii in range(H * W):
    i = H - ii // W
    j = W - ii % W
    lu[i][j] = min(lu[i + 1][j] + 1, lu[i][j + 1] + 1, lu[i][j])

dist = []
[dist.extend(l[1:-1]) for l in lu[1:-1]]
print(max(dist))


Measured memory_bytes: 115292
//============================================================================
// Name        : CountingSort.cpp
// Author      : Ken
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

void WriteVector(vector<int>& A){
	for(int i=0; i<A.size()-1; i++){
		cout << A.at(i) << " ";
	}
	cout << A.at(A.size()-1) << "\n";
}

void CountingSort(vector<int>& A, vector<int>& B, int k){
	vector<int> C(k+1);

	for(int j=0; j<A.size(); j++){
		C.at(A.at(j)) = C.at(A.at(j)) + 1;
	}

	for(int i=1; i<=k; i++){
		C.at(i) = C.at(i) + C.at(i-1);
	}

	//WriteVector(C);

	for(int j=A.size()-1; j>=0; j--){
		//cout << "here1 ";
		//cout << "A.at(" << j << ") = " << A.at(j) << " ";
		B.at(C.at(A.at(j))-1) = A.at(j);
		//cout << "here2 ";
		C.at(A.at(j)) --;
		//cout << "here3\n";
	}
}

int main() {
	int n;
	const int k = 10000;
	vector<int> A, B;
	cin >> n;
	for(int i=0; i<n; i++){
		int input;
		cin >> input;
		A.push_back(input);
		B.push_back(0);
	}

	CountingSort(A, B, k);
	WriteVector(B);

	return 0;
}



Measured memory_bytes: 18724
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N; cin>>N;
  ll T[N],V[N],a=0,A[N];
  for(int i=0; i<N; i++){ll t; cin>>t; t*=2; T[i]=t; a+=t, A[i]=a;}
  for(int i=0; i<N; i++){ll v; cin>>v; v*=2; V[i]=v;}
  ll s=0, t=0, Z[a+1]; Z[0]=0, Z[a]=0;
  for(int i=1,j=0; i<a; i++){
    Z[i]=V[j];
    if(i==A[j]){
      j++;
      Z[i]=min(Z[i],V[j]);
    }
  }
  for(int i=1; i<=a; i++){
    Z[i]=min(Z[i],Z[i-1]+1);}
  for(int i=a-1; i>=0; i--){
    Z[i]=min(Z[i],Z[i+1]+1);
  }
//  for(int i=139; i<=a; i++){cout<<"i:"<<i<<" Z:"<<Z[i]<<endl;}
  double ans=0;
  for(int i=0; i<a; i++){
    ans+=Z[i];
    if(Z[i]<Z[i+1]) ans+=0.5;
    else if(Z[i]>Z[i+1]) ans-=0.5;
  }
  cout<<fixed<<setprecision(10)<<ans/4<<endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int main(){
    int a,b;
    cin >> a >> b;
    int s = 0;
    s += max(0,(4-a)*100000);
    s += max(0,(4-b)*100000);
    if(a==1&&b==1){
        s += 400000;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
S = input().strip()
T = input().strip()
ans = "UNRESTORABLE"
for i in range(len(S)-len(T), -1, -1):
    ok = True
    for j in range(len(T)):
        if not (S[i+j] == '?' or S[i+j] == T[j]):
            ok = False

    if ok:
        a = S[:i]+T+S[i+len(T):]
        a = a.replace("?", "a")
        if ans == "UNRESTORABLE" or a < ans:
            ans = a
print(ans)


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

int main (void) {
    int     n;
    char    s[101];
    scanf("%d%s", &n, s);

    if ( n%2 ){
        printf("No\n");
        return EXIT_SUCCESS;
    }
    if ( strncmp(s, &s[n/2], n/2) )
        printf("No\n");
    else
        printf("Yes\n");

    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, A: "List[int]"):
    dp = [[-1]*2 for _ in range(45)]
    dp[43][0] = 0
    for i in range(43,-1,-1):
        count = 0 # その桁の1の個数
        for j in range(N):
            if (1 << i & A[j]):
                count += 1
        
        ## 確定から確定
        if dp[i+1][1] >= 0:
            dp[i][1] = max(dp[i+1][1] + max(count,N-count)*(1<<i),dp[i][1])

        if dp[i+1][0] >= 0:
            if K & 1<<i: # Kが１の時
                ## 未確定から未確定
                dp[i][0] = max(dp[i+1][0]+(N-count)*(1<<i),dp[i][0])
                #　未確定から確定
                dp[i][1] = max(dp[i+1][0] + count*(1<<i),dp[i][1])
            else: # Kが0の時
                ## 未確定から未確定
                dp[i][0] = max(dp[i+1][0] + count*(1<<i) ,dp[i][0])
    
    print(max(dp[0][0],dp[0][1]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


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

int main() {
  int N;
  int t[110000], x[110000], y[110000];
  cin >> N;
  t[0] = x[0] = y[0] = 0;
  for (int i = 0; i < N; i++) {
    cin >> t[i+1] >> x[i+1] >> y[i+1];
  }

  bool can = true;
  for (int i = 0; i < N; i++) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if (dt < dist) can = false;
    if (dist % 2 != dt % 2) can = false;
  }

  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 1408
def f(s, cost, route, ans):
    route.append(s)
    ans += cost[s]
    del cost[s]
    for k, c in data.items():
        if s in k:
            a, b = k
            if s == a:
                if not b in route:
                    if not b in cost or c < cost[b]:
                        cost[b] = c
                        del data[(a, b)]
            elif s == b:
                if not a in route:
                    if not a in cost or c < cost[a]:
                        cost[a] = c
                        del data[(a, b)]
    if cost:
        s = sorted(cost.items(), key=lambda x: x[1])[0][0]
        return f(s, cost, route, ans)
    return ans

while 1:
    n, m = map(int, raw_input().split())
    if n == m == 0: break
    data = {}
    for i in range(m):
        a, b, c = map(int, raw_input().split())
        data[(a, b)] = c
    print f(0, {0:0}, [], 0)

Measured memory_bytes: 4336
import java.util.*;

class Main {
   public static void main(String[] args)
   {
      Scanner scan = new Scanner(System.in);
      int     n    = Integer.parseInt(scan.next());

      final int MAX = 100000 + 1;

      int[] count = new int[MAX];
      count[0] = count[1] = count[2] = 0;
      boolean[] primes = new boolean[MAX];

      primes[2] = true;

      for(int i = 3; i < MAX; i += 2){
          primes[i] = true;
          }

      for(int i = 3; i * i < MAX; i += 2){
          if(primes[i]){
             for(int j = i * 2; j < MAX; j += i){
                 primes[j] = false;
                 }
             }
          }
      for(int i = 3; i < MAX; i++){
          if(primes[i] == true){
             if(primes[(i + 1) / 2] == true){
                count[i] = count[i - 1] + 1;
                }
             else{
                 primes[(i + 1) / 2] = false;
                 count[i]            = count[i - 1];
                 }
             }
          else{
              count[i] = count[i - 1];
              }
          }
      //System.out.println(count);

      for(int i = 0; i < n; i++){
          int a   = Integer.parseInt(scan.next());
          int b   = Integer.parseInt(scan.next());
          int cou = 0;

          if(a == b){
             cou = count[a] - count[a - 1];
             System.out.println(cou);
             }
          else{
              cou = count[b] - count[a - 1];
              System.out.println(cou);
              }
          }
   }
}


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

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var q = new Queue<int>[n];
        for (int i = 0; i < n; i++) q[i] = new Queue<int>();
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var t = int.Parse(line[1]);
            if (line[0] == "0") Console.WriteLine(q[t - 1].Dequeue());
            else
            {
                var qn = getLane(n, q);
                q[qn].Enqueue(t);
            }
        }
    }
    static int getLane(int n, Queue<int>[] q)
    {
        var min = 10001;
        var res = 0;
        for (int i = 0; i < n; i++)
        {
            var qc = q[i].Count();
            if (qc < min) { min = qc; res = i; }
        }
        return res;
    }
}



Measured memory_bytes: 20600
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    AB=LLIN(N)
    AB.sort(reverse=True)
    print(AB[0][0]+AB[0][1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 57052
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, 0, n) cin >> s[i];

  bool ok = true;
  map<string, ll> mp;
  mp[s[0]]++;
  rep(i, 1, n){
    if(s[i-1][sz(s[i-1])-1] != s[i][0] || mp[s[i]] != 0) ok = false;
    mp[s[i]]++;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MAX=500005;
int s[MAX],n,cnt=0;int temp1[MAX/2],temp2[MAX/2];
void pr(){
	for(int i=0;i<n;i++)cout<<s[i]<<" ";
	cout<<endl;
} 
void merge(int a[],int left,int right){
	int mid=left+(right-left)/2;
	int len1=mid-left,len2=right-mid;
	for(int i=0;i<len1;i++)temp1[i]=a[left+i];
	for(int i=0;i<len2;i++)temp2[i]=a[mid+i];
	int k=left,i=0,j=0;
	while(i<len1&&j<len2){
		if(temp1[i]>=temp2[j]){
			a[k++]=temp2[j++];
		}else if(temp1[i]<temp2[j]){
			a[k++]=temp1[i++];
		}
		cnt++;
	}
	cnt+=len1+len2-i-j;
	while(i<len1)a[k++]=temp1[i++];
	while(j<len2)a[k++]=temp2[j++];
	
}
void MergeSort(int a[],int left,int right){
	if(right==left+1)return;
	if(left<right){
		int mid=left+(right-left)/2; 
		MergeSort(a,left,mid);
		MergeSort(a,mid,right);
		merge(a,left,right);
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>s[i];
	MergeSort(s,0,n);
	int first=1;
	for(int i=0;i<n;i++){
		if(first)first=0;else cout<<" ";
		cout<<s[i];
	}
	cout<<endl<<cnt<<endl;
	return 0;
}


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

int main(void)
{
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a == b || a == c || b == c)
  {
    if(a == b && a == c && b == c)
    {
      cout << "No";
    }
    else
    {
      cout << "Yes";
    }
  }
  else
  {
    cout << "No";
  }
  
  return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


bool rec(i64 rem, vector<i64> A) {
    if (rem == 0) {
        if (A[1] > A[0] && A[2] > A[1]) return true;
        return false;
    }

    bool ans = false;
    REP(i, 3) {
        vector<i64> B = A;
        B[i] *= 2;
        ans |= rec(rem - 1, B);
    }
    return ans;
}


int main() {
    vector<i64> A(3);
    REP(i, 3) cin >> A[i];

    i64 K; cin >> K;
    if (rec(K, A)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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


int main(){

    int n;
    cin>> n;
    long double temp,ans=0;
    for(int i= 0; i<n; ++i){
        cin>> temp;
        ans+= 1/temp;
    }
    cout<<setprecision(20)<<endl;
    cout<< 1/ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;
//const u32 P=;
//inline u32 &inc(u32 &a, u32 b) {return (a+=b)<P?a:(a-=P);}
//inline u32 &dec(u32 &a, u32 b) {return (a-=b)&0x80000000?(a+=P):a;}
//inline u32 sum(u32 a, u32 b) {return (a+=b)<P?a:a-P;}
//inline u32 dif(u32 a, u32 b) {return (a-=b)&0x80000000?a+P:a;}
//u64 power(u64 a, int b) {
//	u64 ans=1;
//	for(; b; a=a*a%P, b/=2) if(b&1) ans=ans*a%P;
//	return ans;
//}

int main() {
	int h1=rd(), m1=rd(), h2=rd(), m2=rd(), k=rd();
	int s=h1*60+m1, t=h2*60+m2;
	printf("%d\n", t-s-k);
	return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;
using ll = int64_t;

ll MOD = 998244353;

ll pow(ll v, int p) {
  if (p == 0) return 1;
  if (p == 1) return v;
  ll ret = pow(v, p / 2);
  ret *= ret;
  ret %= MOD;
  if (p % 2 == 1) {
    ret *= v;
    ret %= MOD;
  }
  return ret;
}

ll inv(ll v) {
  return pow(v, MOD - 2);
}

int N;
int A[1000000];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", A + i);
  }
  vector<vector<int>> divisor(1000001);
  for (int i = 1; i < divisor.size(); i++) {
    for (int j = i; j < divisor.size(); j += i) {
      divisor[j].push_back(i);
    }
  }
  vector<ll> sum(divisor.size());
  vector<ll> sum2(divisor.size());
  vector<ll> sub(divisor.size());
  for (int i = 0; i < N; i++) {
    for (int d : divisor[A[i]]) {
      sum[d] += A[i];
      sum2[d] += (ll)A[i] * A[i];
    }
  }
  ll ans = 0;
  for (int i = divisor.size() - 1; i > 0; i--) {
    if (sum[i] == 0) continue;
    sum[i] %= MOD;
    sum2[i] %= MOD;
    ll cur = sum[i] * sum[i] - sum2[i];
    if (cur < 0) cur += MOD;
    cur %= MOD;
    cur *= inv(i * 2);
    cur += MOD - sub[i];
    cur %= MOD;
    if (cur == 0) continue;
    ans += cur;
    for (int d : divisor[i]) {
      if (d == i) continue;
      sub[d] += cur * i / d;
      sub[d] %= MOD;
    }
  }
  cout << ans % MOD << endl;
}


Measured memory_bytes: 141056
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;

int N, K;
int main() {
	ll res = 0;
	scanf("%d %d", &N, &K);
	for (int a = 1; a <= N; a++) {
		if ((2 * a) % K != 0) {
			continue;
		}
		int r = K - (a % K);
		if (r <= N) {
			res += ((ll)(N - r) / K + 1) * ((N - r) / K + 1);
		}
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 256
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

using POS = int;
using COST = int;
using EDGES = map<POS, vector<pair<POS, COST>>>;

PQ<pair<COST, POS>> q;
map<POS, COST> d;
EDGES es;
int k;

void add_edge(POS from, POS to, COST cost){
  es[from].emplace_back(mp(to, cost));
}

void init_d(){
}

void init_es(){
  rep(i, k){
    es[i].pb(mp((i+1)%k, 1));
    es[i].pb(mp((i*10)%k, 0));
  }
}

int solve(){
  cin>>k;

  init_es();
  init_d();

  q.push(mp(1LL, 1LL));
  while (!q.empty()){
    // 取り出し
    auto cp = q.top(); q.pop();
    auto cost = cp.first;
    auto pos = cp.second;

    if (d.find(pos)==d.end() || cost < d[pos]) {
      d[pos] = cost;
      for (const auto &e:es[pos]){
        auto npos = e.fi;
        auto ncost = cost + e.se;
        q.push(mp(ncost, npos));
      }
    }
  }
  // dump(d);
  // dump(es);
  cout << d[0] << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 20464
n,t = list(map(int,input().strip().split()))
a = list(map(int,input().strip().split()))

result = 0
for i in range(n-1):
  if a[i] + t > a[i+1]:
    result += a[i+1] - a[i]
  else:
    result += t
result += t
print(result)

Measured memory_bytes: 25196
N=int(input())

A=[-1]*(N+1)

for i in range(1,N+1):
    A[i]=int(input())
A=A+[0]

count=0

for j in range(N,0,-1):
    if A[j]<=A[j-1]+1:
        if A[j]==A[j+1]-1:
            continue
        else:
            count+=A[j]
    else:
        count=-1
        break


print(count)

Measured memory_bytes: 50648
N = 3
glid = []
for i in range(N):
    glid.append(list(map(int, input().split())))

# print(glid)
a = [0] * 3
b = [0] * 3
for i in range(100):
    a[0] = i
    for j in range(N):
        b[j] = glid[0][j] - a[0]

    for j in range(1, N):
        a[j] = glid[j][0] - b[0]

f = True
for i in range(N):
    for j in range(N):
        if glid[i][j] != a[i] + b[j]:
            f = False
print('Yes' if f else 'No')


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int S, h, m, s;
	
	scanf("%d", &S);
	
	h = S / 3600;
	m = (S % 3600) / 60;
	s = (S % 3600) % 60;
	
	printf("%d:%d:%d\n", h, m, s);
	
	return 0;
}

Measured memory_bytes: 592
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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;
}
struct Edge {
  int from, to, cost, rev;
  Edge(int from, int to, int cost, int rev)
      : from(from), to(to), cost(cost), rev(rev) {}
};
struct Graph {
  int V;
  vector<vector<Edge>> G;
  vector<int> used;
  Graph(int V) : V(V) {
    used = vector<int>(V, 0);
    G = vector<vector<Edge>>(V);
  }
  void add_edge(int from, int to, int cost = 1) {
    G[from].push_back(Edge(from, to, cost, G[to].size()));
    G[to].push_back(Edge(to, from, 0, G[from].size() - 1));
  }
  int augment_path(int s, int t, int f) {
    if (s == t)
      return f;
    used[s] = true;
    rep(i, 0, G[s].size()) {
      Edge &e = G[s][i];
      if (!used[e.to] && e.cost > 0) {
        int d = augment_path(e.to, t, min(f, e.cost));
        if (d > 0) {
          e.cost -= d;
          G[e.to][e.rev].cost += d;
          return d;
        }
      }
    }
    return 0;
  }
  int max_flow(int s, int t) {
    int flow = 0;
    while (1) {
      used = vector<int>(V, 0);
      int f = augment_path(s, t, INF);
      if (f == 0)
        break;
      flow += f;
    }
    return flow;
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int V, E;
  cin >> V >> E;
  Graph g(V);
  rep(i, 0, E) {
    int a, b, c;
    cin >> a >> b >> c;
    g.add_edge(a, b, c);
  }
  cout << g.max_flow(0, V - 1) << endl;

  return 0;
}



Measured memory_bytes: 3208
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    rep(i,n){
        ll cnt = 1;
        int hig = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        int low = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
        cnt *= hig;
        cnt *= low;
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

using namespace std;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

typedef int64_t ll;
typedef pair<int, ll> P;

int n;
ll c;
vector<ll> val, pos;

vector<P> toleft, toright;

void init()
{
	cin >> n >> c;

	val.resize(n + 1, 0);
	pos.resize(n + 1, 0);
	REP1C(i, n) { cin >> pos[i] >> val[i]; }

	toleft.resize(n + 1);
	toright.resize(n + 1);
	toright[0] = toleft[0] = P(0, 0);
}

int main()
{
	init();
	ll best, tmp;

	best = tmp = 0;
	REP1C(i, n)
	{
		tmp += val[i];
		if (chmax(best, tmp - pos[i]))
			toright[i] = P(i, best);
		else
			toright[i] = toright[i - 1];
	}

	best = tmp = 0;
	for (int i = n; i >= 1; --i)
	{
		tmp += val[i];
		if (chmax(best, tmp - 2 * (c - pos[i])))
			toleft[i] = P(i, best);
		else
		{
			if (i == n)
				toleft[i] = P(0, 0);
			else
				toleft[i] = toleft[i + 1];
		}
	}

	ll ans = 0;
	REP1C(i, n)
	{
		chmax(ans, toright[i].second);
		if (toright[i].first != n)
			chmax(ans, toright[i].second + toleft[toright[i].first + 1].second);
	}

	best = tmp = 0;
	REP1C(i, n)
	{
		tmp += val[i];
		if (chmax(best, tmp - 2 * pos[i]))
			toright[i] = P(i, best);
		else
			toright[i] = toright[i - 1];
	}

	best = tmp = 0;
	for (int i = n; i >= 1; --i)
	{
		tmp += val[i];
		if (chmax(best, tmp - (c - pos[i])))
			toleft[i] = P(i, best);
		else
		{
			if (i == n)
				toleft[i] = P(0, 0);
			else
				toleft[i] = toleft[i + 1];
		}
	}

	REP1C(i, n)
	{
		chmax(ans, toleft[i].second);
		if (toleft[i].first != 0)
			chmax(ans, toleft[i].second + toright[toleft[i].first - 1].second);
	}

	cout << ans << endl;
}


Measured memory_bytes: 4992
n,y=gets.split.map(&:to_i)
y/=1000

[*0..n].repeated_combination(2){|a,b|
  p=a
  q=b-a
  r=n-b
  if 10*p+5*q+r==y
    puts [p,q,r]*" "
    exit
  end
}

puts "-1 -1 -1"

Measured memory_bytes: 1788