akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
    int n, k;
    
    scanf("%d%d", &n, &k);

    if(k == 1 || n == k){
        printf("%d\n", 0);
        return 0;
    }

    printf("%d\n", n - k);

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i]--;
  }
  int i = 0, cnt = 0;
  bool fail = true;
  while (cnt < N) {
    if (i == 1) {
      fail = false;
      break;
    }
    cnt++;
    i = a[i];
  }
  if (fail)
    cout << -1 << endl;
  else {
    cout << cnt << endl;
  }
  return 0;
}

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

using namespace std;

#define int ll

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}


signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, W; cin >> n >> W;
  vi w(n), v(n);
  REP(i, n) {
    cin >> w[i] >> v[i];
  }

  vvi dp(n);
  REP(i, n) {
    dp[i].resize(W+1);
  }
  dp[0][w[0]] = v[0];

  FOR(i, 1, n) {
    REP(j, W-w[i]+1) {
      dp[i][j+w[i]] = max(dp[i][j+w[i]], dp[i-1][j] + v[i]);
    }
    REP(j, W+1) {
      dp[i][j] = max(dp[i][j], dp[i-1][j]);
    }
  }

  int ans = 0;
  REP(i, W+1) {
    ans = max(ans, dp[n-1][i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 78592
#include<set>
#include<iostream>
#include<string>
#include<cstddef>

using ui = std::uint32_t;

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

	ui left{}, right{};
	ui count{};
	std::string ps{ "" };

	std::string tmp;
	tmp.reserve( 1000000 );
	for( ui i{};i<s.size();++i  ){

		tmp.clear();
		for( ui j{i}; j<s.size() 
			 && (
				 tmp.empty()
				 ||(ps.size() == tmp.size() && ps == tmp )
				 ); ++j )
		{

			//if( !tmp.empty() )
			//	std::cout << "\t>>" << tmp << "\n";
			//else
			//	std::cout << "\n_________________\nempty\n";

			tmp += s[j];
		}

//		std::cout << i << ":" << tmp << "\n";


		if(ps!=tmp)
			++count;

		ps = tmp.c_str();
		i += tmp.size() - 1;
	}

	std::cout << count << "\n";

	return 0;
}

Measured memory_bytes: 640
N=int(input())
S=input()
T=input()
mod=1000000007
if S[0]==T[0]:
    ans=3
    p=0
    i=1
else:
    ans=6
    p=1
    i=2
while i<N:
    if S[i]==T[i] and p==0:
        ans = (ans*2)%mod
        i+=1
        p=0
    elif S[i]==T[i] and p==1:
        #ans = (ans*2)%mod
        i+=1
        p=0
    elif S[i]!=T[i] and p==0:
        ans = (ans*2)%mod
        i+=2
        p=1
    elif S[i]!=T[i] and p==1:
        ans = (ans*3)%mod
        i+=2
        p=1  
print(ans)

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

using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, e;
    cin >> b >> e;
    reverse(v.begin() + b, v.begin() + e);
  }
  for (int i = 0; i < n; i++) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
using namespace std;


using ll = long long int;

/// <summary>
/// GCDを計算します
/// </summary>
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
	if (a < b) {
		NumType tmp = a;
		a = b;
		b = tmp;
	}

	NumType r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

/// <summary>
/// 約数を数えます
/// </summary>
template <typename NumType>
NumType cntDivisor(const NumType& num) {
	NumType cnt = 0;
	for (NumType i = 1; i * i <= num; ++i) {
		if (num % i == 0) {
			cnt++;
			if (i * i != num) cnt++;
		}
	}

	return cnt;
}

/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"



int main() {
	int N;
	cin >> N;

	vector<int> W(N);

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

	vector<int> ans;
	int be = 0, en = 0;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < i; j++) {
			be += W[j];
		}
		for (int j = i; j < N; j++) {
			en += W[j];
		}
		if (be - en == 0) {
			cout << 0 << endl;
			return 0;
		}

		ans.emplace_back(abs(be - en));

		be = 0;
		en = 0;
	}

	sort(ans.begin(), ans.end());

	cout << ans[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  throw std::runtime_error("error!");
  return -1;
}

int main()
{
  int S;
  string str;
  cin >> str;
  S = str.size();
  int N = S-1;
  ll sumval = 0;
  // 2^Nのビット全探索
  REP(i,pow(2,N)){
    ll tmpsamval = 0;
    ll tmp = 0;
    REP(j,N){
      int current = ctoi(str[j]);
      // printf("current:%d tmp:%lld, push:%d\n",current,tmp,(i>>j)&0x01);
      if ((i>>j)&0x01){
        tmpsamval += current + tmp;
        tmp = 0;
      }
      else{
        tmp = 10*(tmp+current);

      }
    }
    // printf("current:%d tmp:%lld\n",ctoi(str[N]),tmp);
    tmpsamval += ctoi(str[N]) + tmp;
    tmp = 0;
    sumval += tmpsamval;
  }

  printf("%lld\n",sumval);

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
long long f[100];
int main()
{
    int n;
    cin>>n;
    f[0]=2;f[1]=1;
    for(int i=2;i<=n;i++)
    {
        f[i]=f[i-1]+f[i-2];
    }
    cout<<f[n]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h> 
#include <string.h> 
int main()
{ 
    char s[258] = {}, tmp[258] = {}; 
    int m, h, i, l; 
    while(scanf("%s", s) && s[0] != '-'){ scanf("%d", &m);
    while(m--){ scanf("%d", &h); 
    strcpy(tmp, s + h); s[h] = '\0'; 
    strcat(tmp, s); 
    strcpy(s, tmp); 
        
    }
    puts(s); 
        
    } 
    return 0; 
    
} 





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

int main(){
    int w, h, n;
    cin >> w >> h >> n;
    vector <int> x(n), y(n), a(n);
    rep(i,n) cin >> x[i] >> y[i] >> a[i];

    int a1 = 0, a2 = w, a3 = 0, a4 = h;

    for(int i=0; i<n; i++){
        if(a[i] == 1){
            if(x[i] > a1){
                a1 = x[i];
            }
        }
        if(a[i] == 2){
            if(x[i] < a2){
                a2 = x[i];
            }
        }
        if(a[i] == 3){
            if(y[i] > a3){
                a3 = y[i];
            }
        }
        if(a[i] == 4){
            if(y[i] < a4){
                a4 = y[i];
            }
        }
    }

    if(((a2-a1)<=0) || ((a4-a3)<=0)){
        cout << 0 << endl;
    }
    else{
        cout << (a2-a1)*(a4-a3) << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    char a;
    cin >> a;
    if (a=='A'){
        cout << "T" << endl;
    }else if (a=='T'){
        cout << "A" << endl;
    }else if (a=='C'){
        cout << "G" << endl;
    }else{
        cout << "C" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    println(problem137_b(a, b))
}

fun problem137_b(a: Int, b: Int): String {

    val result = arrayListOf<Int>()

    val max = b + (a - 1)

    val min = b - (a - 1)

    for (i in min..max) {
        result.add(i)
    }

    return result.joinToString(" ")
}


Measured memory_bytes: 31400
#include <stdio.h>

int
main(int argc, char *argv[])
{
  char s[100001]; int i, flag;
  scanf("%s", s);

  for(char c = 'a'; c <= 'z'; c++){
    i = 0; flag = 0;
    while(s[i] != '\0'){
      if(s[i] == c){
	flag++;
	break;
      }
      i++;
    }
    if(flag == 0){
      printf("%c\n", c);
      break;
    }
    else if(c == 'z')printf("None\n");
  }

  return 0;
}

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

using namespace std;
int main() {
    int h;
    int w;

    cin >> h;
    cin >> w;
    vector<vector<int> > popu;

    popu.resize(h);
    for (int i = 0; i < h; i++) {
        popu[i].resize(w);
        for (int j = 0; j < w; j++) {
            cin >> popu[i][j];
        }
    }

    int min_v = 2100000000;

    for (int i = 0; i < h; i++) {
        for  (int j = 0; j < w; j++) {
            int sum = 0;
            for (int ii = 0; ii < h; ii++) {
                for (int jj = 0; jj < w; jj++) {
                    sum += (min(abs(i-ii),abs(j-jj)))*popu[ii][jj];
                }
            }
            if (min_v > sum) {
                min_v = sum;
            }
        }
    }

    cout << min_v << endl;
    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N; cin >> N;
  vector<double> v(N);
  double ANS; ANS=0;
  
  for(int i=0; i<N; i++){
    cin >> v[i];
  }
  
  sort(v.begin(), v.end());
  
  ANS = v[0];
  
  for(int i=1; i<N; i++){
    ANS = ANS/2 + v[i]/2;
  }
  cout << ANS << endl;
}


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

using namespace std;

typedef long long int64;

int main()
{
  int64 dp[51][2501] = {{}};
  int N, A, X[50];

  cin >> N >> A;
  for(int i = 0; i < N; i++) cin >> X[i];
  dp[0][0] = 1;
  for(int i = 0; i < N; i++) {
    for(int j = 49; j >= 0; j--) {
      for(int k = 2500; k >= X[i]; k--) {
        dp[j + 1][k] += dp[j][k - X[i]];
      }
    }
  }


  int64 ret = 0;
  for(int i = 1; i <= N; i++) {
    ret += dp[i][A * i];
  }
  cout << ret << endl;
}

Measured memory_bytes: 1280
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

count = 0
for i in range(n):
    temp = a[i]
    s = 0
    for j in range(m):
        s += temp[j]*b[j]
    s += c
    if s > 0:
        count += 1

print(count)

Measured memory_bytes: 38384
#include <math.h>
#include <stdio.h>
#include <string.h>
void swap_int(int *x, int *y) {int temp;temp = *x;*x = *y;*y = temp;}
void swap_char(char *x, char *y) {char temp;temp = *x;*x = *y;*y = temp;}
int max(int x, int y) { return x > y ? x : y; }
int min(int x, int y) { return x > y ? y : x; }

int main(){
    int n,dat[26];
    char s[200];

    for(int i=0;i<26;i++)dat[i]=0;

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf(" %c",&s[i]);
        dat[s[i]-0x41]=1;
    }
    int cnt=0;
    for(int i=0;i<26;i++){
        if(dat[i]==1)cnt++;
    }
    if(cnt==3){
        printf("Three\n");
    }else{
        printf("Four\n");
    }
    return 0;
}

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

using ll = long long;
using Field = vector<vector<ll>>;
using Graph = vector<vector<ll>>;
using VI = vector<int>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VC = vector<char>;
using PI = pair<int, int>;

#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

vector<vector<int>> dp(110, vector<int>(10010));
int N, W;
vector<int> v(1000), w(1000);

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

    cin >> N >> W;
    REP(i, N) {
        cin >> v[i] >> w[i];
    }

    for (int i = 0; i <= W; i++) {
        if (i >= w[0]) {
            chmax(dp[0][i], dp[0][i - w[0]] + v[0]);
        }

    }

    for (int i = 1; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j >= w[i]) {
                chmax(dp[i][j], dp[i - 1][j]);
                chmax(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
                chmax(dp[i][j], dp[i][j - w[i]] + v[i]);
            } else {
                chmax(dp[i][j],dp[i - 1][j]);
            }
        }
    }

    cout << dp[N - 1][W] << endl;



    return 0;
}


Measured memory_bytes: 7544
#include<iostream>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int l=a.length();
	int x1=0,x2=0;//石头，布 
	int ans=0;
	for(int i=0;i<=l-1;i++)
	{
		if(a[i]=='g')
		{
			if(x1>x2)
			{
				ans++;
				x2++;
			}
			else
			{
				x1++;
			}
		}
		if(a[i]=='p')
		{
			if(x1>x2)
			{
				x2++;
			}
			else
			{
				ans--;
				x1++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
N, T = map(int, input().split())
arrc = []
arrt = []

for i in range(1,N+1):
  c, t = map(int, input().split())
  arrc.append(c)
  arrt.append(t)

if min(arrt) > T:
  print("TLE")
else:
  ans = arrc[0]
  for i in range(0,N):
    if arrt[i] <= T:
      if arrc[i] < ans:
        ans = arrc[i]
  print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H,A,count,o;
  cin>>H>>A;
	for(int i=0;i<A;i++){
      cin>>o;
      count+=o;
    }
	if(count>=H){
      cout<<"Yes";
    }
  else{
    cout<<"No";
  }
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
double a[1005];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	double sum=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%lf",&a[i]);
		sum+=a[i];
	}
	sum=sum/m/4.0;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=sum)
		{
			cnt++;
		}
	}
	if(cnt>=m)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
/*
	author: Ibrahim-Elsayed (Codeforces Handle)
	date: 8/28/2020
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
const double PI = acos(-1);
const int MOD = 1000000007;

const int mxN = 1e5;
int n;
int dp[mxN+1];
int arr[mxN+1];

int go(int i) { // min cost starting from stone i to reach stone n;
	if(i == n) {
		return 0;
	}
	if(i > n) {
		return int(1000000025);
	}
	if(dp[i] != -1) {
		return dp[i];
	}
	int c1 = 1000000025, c2 = 1000000025;
	if(i+1 <= n) c1 = go(i+1) + abs(arr[i] - arr[i+1]);
	if(i+2 <= n) c2 = go(i+2) + abs(arr[i] - arr[i+2]);
	int ans = min(c1, c2);
	return dp[i] = ans;
}

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

	cin >> n;
	for(int i = 1; i <= n; i++) cin >> arr[i];
	memset(dp, -1, sizeof(dp));
	cout << go(1);

	return 0;
}


Measured memory_bytes: 9124
#include <iostream>
#include <cmath>

using namespace std;

const int MAXN=100000;

int dp[MAXN]={0};
int a[MAXN]={0};

int main()
{
    int n;

    cin >>n;

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

    dp[0]=0;

    for (int i=1; i<n; ++i)
    {
        int mini=-1;

        for (int j=1; j<=2; ++j)
        {
            if (i-j>=0)
            {
                if (mini==-1 or mini>dp[i-j]+abs(a[i]-a[i-j]))
                    mini=dp[i-j]+abs(a[i]-a[i-j]);
            }
        }

        dp[i]=mini;
    }

    cout <<dp[n-1];

    return 0;
}


Measured memory_bytes: 1024
class Pool
  def initialize(s, e)
    @s, @e = s, e
    @area = 0
  end

  def ==(other)
    @s == other.s && @e == other.e
  end

  attr_accessor :s, :e, :area
end

terrain = gets.chomp
rex = Regexp.new(/\\_*\//)
pools = []
loop do
  pairs = terrain.scan(rex)
  break if pairs.size == 0
  pairs.each {|p|
    s = terrain.index(p)
    e = s + p.size - 1
    children = pools.select{|x| s < x.s && x.e < e}
    if children.size > 0
      pool = children.first
      pool.area = children.map(&:area).inject(:+)
      children.drop(1).each {|c| c.area = 0}
    else
      pool = Pool.new s, e
      pools << pool
    end
    pool.s = s
    pool.e = e
    pool.area += p.size - 1
    terrain[s, p.size] = "_" * p.size
  }
end

pools.delete_if{|p| p.area == 0}
puts pools.size == 0 ? 0 : pools.map{|p| p.area}.inject(:+)
puts pools.size == 0 ? 0 : "#{pools.size} #{pools.sort_by!(&:s).map(&:area).join(" ")}"

Measured memory_bytes: 66576
n = int(raw_input())
a = map(int, raw_input().split())
b = map(int, raw_input().split())

diff = [bi - ai for (ai, bi) in zip(a, b)]
if sum(diff) < 0:
    print('No')
    exit()

sum_of_2minus = -sum(filter(lambda x: x < 0, diff))
capable_2x = sum(map(lambda y: int(y / 2), filter(lambda x: x > 1, diff)))
if capable_2x < sum_of_2minus:
    print('No')
    exit()

print('Yes')

Measured memory_bytes: 4348
#include<stdio.h>

int main()
{
    int len,a,b,k,i,chk;
    double items;
    
    len=scanf("%d %d %d",&a,&b,&k);
    items = b - a;
    chk = items / 2 + 0.5;
    
    if(k > chk)
    {
        while(a <= b)
        {
            printf("%d\n",a);
            a++;
        }
    }
    else
    {
        for(i=0;i<k;i++)
        {
            printf("%d\n",a+i);
        }
        for(i=k-1;i>=0;i--)
        {
            printf("%d\n",b-i);
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 128
// ==============================================
// Library
// ==============================================
#define _CRT_SECURE_NO_WARNINGS

// When you are using the gcc compiler, you need only the following lines.
// #include <bits/stdc++.h>

// When you are using other compilers, you need the following line instead.
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

// If you use this function, "cin" speeds up.
// However, you can not mix "cin" and "scanf", "cout" and "printf".
void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ==============================================
// ==============================================

int main()
{
	fastIOS();

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

	LL ans = k * pow((k - 1), n - 1);
	cout << ans << "\n";
}

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

using namespace std;

const int N = 1e5;

int a[N + 10];
int main() {
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        sum += abs(a[i] - a[i - 1]);
    }
    sum += abs(a[n]);
    for(int i = 1; i <= n; ++i) {
        int tmp = sum;
        tmp -= abs(a[i] - a[i - 1]);
        tmp -= abs(a[i + 1] - a[i]);
        tmp += abs(a[i + 1] - a[i - 1]);
        cout << tmp << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
import sys
n=int(input())
L=[list(map(int,input().split())) for i in range(n)]
L.insert(0,[0,0,0])
for i in range(n):
    a,b=L[i+1][0]-L[i][0],abs(L[i+1][1]-L[i][1])+abs(L[i+1][2]-L[i][2])
    if (a-b)%2==0 and a>=b:
        continue
    else:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 27300
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    std::string a, b, c;
    std::cin>>a>>b>>c;

    char ch = 'A' - 'a';
    std::cout<<(char)(a[0] + ch)<<(char)(b[0] + ch)
        <<(char)(c[0] + ch)<<std::endl;

    return 0;
}

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

using namespace std;
	
int main(){
	int n,l;
	cin >> n >> l;
	string s[n];
	
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	
	string temp;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(s[i]>s[j]){
				temp=s[i];
				s[i]=s[j];
				s[j]=temp;
			}
		}
	}
	
	for(int i=0;i<n;i++){
		cout << s[i];
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 256
def main():
    A, B, C, D = input()
    for ab in ['+', '-']:
        for bc in ['+', '-']:
            for cd in ['+', '-']:
                if eval(A + ab + B + bc + C + cd + D) == 7:
                    print(A + ab + B + bc + C + cd + D + '=7')
                    return


main()


Measured memory_bytes: 2940
import heapq

n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
ans=0
q=[]
heapq.heappush(q,-arr[0]) #人1がすでに到着しているとしたとき、得られる値はa0に等しい
for i in range(1,n):
 tmp=heapq.heappop(q) #Pythonの優先度付きキューは最小値を取り出すので-を掛けて最大値を取り出せるようにしている
 tmp*=-1
 ans+=tmp #各時点でのmin(ai,aj)の最大値を答えに足し合わせる
 heapq.heappush(q,-arr[i]) #新たに割り込める場所として追加された人iと人kの間・人kと人jの間で得られる値akを優先度付きキューに追加する
 heapq.heappush(q,-arr[i])
print(ans)

Measured memory_bytes: 31680
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

bool is_palindrome(string s){
    string t = s;
    reverse(s.begin(), s.end());
    return s == t;
}
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if(is_palindrome(s)&&is_palindrome(s.substr(0,(n-1)/2))&&is_palindrome(s.substr((n+1)/2))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

return 0;
}

Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 入力値を取得
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		// 回文数列を作成
		List<Integer> kaibun = new ArrayList<Integer>();
		for(int i = 1; i <= 9 ; i++){
			String value = String.valueOf(i);
			String tmpStr = value + "000" + value;
			Integer tmpInt = Integer.parseInt(tmpStr);
			kaibun.add(tmpInt);
			for(int j = 1; j <= 9 ; j++){
				String value2 = String.valueOf(j);
				String tmpStr2 = value + "0" +value2 + "0" + value;
				String tmpStr3 = value + value2 + "0" + value2 + value;
				Integer tmpInt2 = Integer.parseInt(tmpStr2);
				Integer tmpInt3 = Integer.parseInt(tmpStr3);
				kaibun.add(tmpInt2);
				kaibun.add(tmpInt3);
				for(int k = 1; k <= 9 ; k++){
					String value3 = String.valueOf(k);
					String tmpStr4 = value + value2 + value3 + value2 + value;
					Integer tmpInt4 = Integer.parseInt(tmpStr4);
					kaibun.add(tmpInt4);
				}
			}
		}
		Collections.sort(kaibun);
		kaibun = kaibun.stream().distinct().collect(Collectors.toList());
		int startIndex = 0;
		int endIndex = 0;
		for(int i = 0; i < kaibun.size(); i++){
			if(a <= kaibun.get(i)){
				startIndex = i;
				break;
			}
		}
		for(int j = startIndex; j < kaibun.size(); j++){
			if(b < kaibun.get(j)){
				endIndex = j -1;
				break;
			}else if(b.equals(kaibun.get(j))){
				endIndex = j;
				break;
			}
		}
		int count = endIndex - startIndex + 1;
		System.out.println(count);
	}
}

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

#define eps 1e-8
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)

typedef long long LL;
bool vis[100];

int main(){
    string s;
    string ans1="",ans2="";
    cin>>s;
    int len=s.size();
    for(int i=0;i<len;i++) vis[s[i]-'a']=1;
    for(int i=0;i<26;i++){
        if(!vis[i]){
            char c=i+'a';
            ans1=s+c;
            break;
        }
    }
    if(ans1.size()!=0){
        cout<<ans1<<endl;
        return 0;
    }
    for(int i=len-2;i>=0;i--){
        int Flag=INF;
        for(int j=i+1;j<len;j++){
            if(s[j]>s[i]){
                if(Flag==INF) Flag=j;
                else if(s[j]<s[Flag]) Flag=j;
            }
        }
        if(Flag!=INF){
            for(int j=0;j<i;j++) cout<<s[j];
            cout<<s[Flag];
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


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

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  bool ok = false;
  if(n==m&&n!=l) ok = true;
  else if(n==l&&n!=m) ok = true;
  else if(m==l&&n!=m) ok = true;
  cout << (ok? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

n,a,b=map(int,raw_input().split())
v=[int(i) for i in raw_input().split()]
chk=[i for i in set(v)]
chk.sort()
if len(chk)==1:
    print chk[0]*1.0
    print sum(pscl(n)[a:b+1])
    exit()
d={}
for i in v:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
total=ans=tmp=0
t=a
for p,i in enumerate(chk[::-1]):
    if d[i]<t:
        total=total+i*d[i]
        t=t-d[i]
    elif p==0 and d[i]>=t:
        print i*1.0
        print sum(pscl(d[i])[a:min(b,d[i])+1])
        break
    else:
        total=total+i*t
        print total*1.0/a
        print pscl(d[i])[t]
        break

Measured memory_bytes: 32748
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli a,b,c;
    cin >> a >> b >> c;
    bool ch = false;
    if(a==b){
        if(a!=c){
            ch = true;
        }
    }
    if (c == b)
    {
        if (a != c)
        {
            ch = true;
        }
    }
    if (c == a)
    {
        if (b != c){
            ch = true;
        }
    }
    YN(ch);
}

Measured memory_bytes: 3552
#include <iostream>
#include <string>
#include <map>
using namespace std;
string z(int i){string s="";if(i>25){s+='a'+i/25;i%=25;}s+='a'+i;return s;}
int main(){
	string s;
	map<string,int>m;
	int i=0;
	cout<<"?shiritori"<<endl<<flush;
	for(;i<50;i++){
		cin>>s;
		if(s[0]!='i'||m[s]){cout<<"!OUT"<<endl;return 0;}
		m[s]=1;cout<<string("?")+s[s.size()-1]+z(i)+"i"<<endl<<flush;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
void solve()
{
	ll n,m;
	cin>>n>>m;
	vector<pair<ll,ll>> a(m);
	vector<ll> v,k;
	for(ll i=0;i<m;i++)
	{
		cin>>a[i].first>>a[i].second;
		if(a[i].first==1)
			v.push_back(a[i].second);
		if(a[i].second==1)
			v.push_back(a[i].first);
		if(a[i].first==n)
			k.push_back(a[i].second);
		if(a[i].second==n)
			k.push_back(a[i].first);
	}
	if(m==1)
	{
		cout<<"IMPOSSIBLE";
		return;
	}
	map<ll,ll> mp;
	for(ll i=0;i<v.size();i++)
	{
		mp[v[i]]++;
	}
	for(ll i=0;i<k.size();i++)
	{
		if(mp[k[i]]>0)
		{
			if(k[i]!=1)
			{
				cout<<"POSSIBLE";
				return;
			}
		}
	}
	cout<<"IMPOSSIBLE";
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 20184
#include <stdio.h>

int sum(int a, int b , int t)
{
    int sum;
    sum = b * (t / a) ;
    return sum;
}
int main(void)
{
    int A, B, T ;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&T);
    printf("%d",sum(A, B, T));
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    string s;
    cin >> s;

    int date = stoi(s);

    int shita = date % 100;
    int ue = date / 100;
    bool yymm = false;
    bool mmyy = false;
    
    if(1 <= ue && ue <= 12){
        mmyy = true;
    }
    if(1 <= shita && shita <= 12){
        yymm = true;
    }

    if(mmyy && yymm){
        cout << "AMBIGUOUS" << endl;
    }
    else if(mmyy && !yymm){
        cout << "MMYY" << endl;
    }
    else if(!mmyy && yymm){
        cout << "YYMM" << endl;
    }
    else{
        cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#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 LL long long
#define INF 999999999
using namespace std;

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A*B > C*D){
    cout << A*B << endl;
  }else{
    cout << C*D << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, char *argv[])
{
	int x,a,b,s;
	while((scanf("%d %d %d",&x,&a,&b))!=EOF)
	{
		s=a-b;
		if(s<0)s=-s;
		if(s>x)printf("dangerous\n");
		else{
			if(a>=b)printf("delicious\n");
			else printf("safe\n");
		} 		
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;

int main(){
    int H,A;
    cin >> H >> A;

    cout << (H+A-1)/A;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<(#a)<<':'<<(a)<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

bool isOk(ll key,ll value){
  return key < value;
}

int binary_search(vector<ll> a,ll key){
  ll ok = a.size();
  ll ng = -1;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<int> a(n),b(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  ll plus = 0, minus = 0;
  ll bad = 0;
  vector<ll> points;
  rep(i,n){
    if(a[i] < b[i]){
      bad += abs(a[i] - b[i]);
    }else points.pb(a[i]-b[i]);
  }
  if(bad == 0){
    print(0);
    return 0;
  }


  int ans = -1;
  sort(all(points));reverse(all(points));
  ll tmp = 0;
  rep(i,points.size()){
    tmp += points[i];
    if(bad <= tmp){
      ans = i+1 + n - (points.size());
      break;
    }
  }
  print(ans);
  return 0;
} 


Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define int long long
inline int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int k=1,kk=0;if (c=='-')c=getchar(),k=-1;
	while (c>='0'&&c<='9')kk=kk*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(int x){if (x<0)putchar('-'),x=-x;if (x)write(x/10),putchar(x%10+'0');}
void writeln(int x){write(x);if (x==0)putchar('0');puts("");}
void doit(int x,int y,int l,int r){
	int ll=(l-1)%(x+y)+1,rr=(r-1)%(x+y)+1;if (r-rr==l-ll){
		for (int i=ll;i<=x&&i<=rr;i++)ll=i+1,putchar('A');
		for (int i=ll;i<=rr;i++)putchar('B');
	}else{
		int dd=((r-rr)-(l-ll))/(x+y)-1;
		for (int i=ll;i<=x;i++)ll=i+1,putchar('A');
		for (int i=ll;i<=x+y;i++)putchar('B');ll=dd;
		for (int i=1;i<=dd;i++){
			for (int j=1;j<=x;j++)putchar('A');
			for (int j=1;j<=y;j++)putchar('B');
		}ll=1;
		for (int i=ll;i<=x&&i<=rr;i++)ll=i+1,putchar('A');
		for (int i=ll;i<=rr;i++)putchar('B');
	}
}int q,a,b,x,y,dd,mid,xx1,yy1,xx2,yy2,kk,ll,rr,ans;
struct lsg{int x,y,l,r,d;}ff[100];
signed main(){
	q=read();for (int i=1;i<=q;i++){
		a=read();b=read();x=read();y=read();memset(ff,0,sizeof(ff));
		if (a>=b){
			dd=a/b;if (a%b!=0)dd++;
			if (a/(b+1)+(a%(b+1)>0)<dd){
				int kk=a/(b+1)+(a%(b+1)>0),fff=a-b*kk;
				ff[4].x=1;ff[4].d=fff;
				a-=fff;dd=kk;
			}ll=1;rr=b;
			while (ll<rr){
				int mid=(ll+rr+1)/2,xx=a-mid*dd,yy=b-mid,ddd;
				if (xx<0){rr=mid-1;continue;}
				if (xx){ddd=yy/xx;if (yy%xx)ddd++;}else {if (yy==0)ddd=0;else ddd=1e9;}
				if (ddd<=dd)ll=mid;else rr=mid-1;
			}int xx=a-ll*dd,yy=b-ll;
			ff[1].x=dd;ff[1].y=1;ff[1].d=ll;if (yy){
			ff[3].y=dd;ff[3].x=1;ff[3].d=(yy-1)/dd;xx-=ff[3].d;yy-=ff[3].d*dd;
			ff[2].x=xx;ff[2].y=yy;ff[2].d=1;
			}
		}else{
			swap(a,b);dd=a/b;if (a%b)dd++;
			if (a/(b+1)+(a%(b+1)>0)<dd){
				int kk=a/(b+1)+(a%(b+1)>0),fff=a-b*kk;
				if (x<=fff)doit(0,1,x,min(y,fff));
				y-=fff;x-=fff;a-=fff;dd=kk;
			}ll=1;rr=b;
			while (ll<rr){
				int mid=(ll+rr+1)/2,xx=a-mid*dd,yy=b-mid,ddd;
				if (xx<0){rr=mid-1;continue;}
				if (xx){ddd=yy/xx;if (yy%xx)ddd++;}else {if (yy==0)ddd=0;else ddd=1e9;}
				if (ddd<=dd)ll=mid;else rr=mid-1;
			}int xx=a-ll*dd,yy=b-ll;
			ff[1].x=dd;ff[1].y=1;ff[1].d=ll;if (yy){
			ff[3].y=dd;ff[3].x=1;ff[3].d=(yy-1)/dd;xx-=ff[3].d;yy-=ff[3].d*dd;
			ff[2].x=xx;ff[2].y=yy;ff[2].d=1;
			}swap(ff[1],ff[3]);swap(ff[1].x,ff[1].y);swap(ff[2].x,ff[2].y);swap(ff[3].x,ff[3].y);
		}for (int i=1;i<=4;i++){
			ff[i].l=ff[i-1].r+1;ff[i].r=ff[i].d*(ff[i].x+ff[i].y)+ff[i-1].r;if (ff[i].l>ff[i].r)continue;
			if (x<=ff[i].r&&y>=ff[i].l)doit(ff[i].x,ff[i].y,max(x,ff[i].l)-ff[i].l+1,min(y,ff[i].r)-ff[i].l+1);
		}puts("");
	} 
}/*
5
8 10 1 18
*/

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
def solve(N,A):
    liss = []
    lis = []
    lis.append(A[0])
    a = A[0]
    for i in range(1,N):
        if len(lis)==1 or prev==0:
            prev = A[i]-a
        elif (A[i]-a)*prev<0:
            liss.append(lis)
            lis = []
        lis.append(A[i])
        a = A[i]
    liss.append(lis)
    ans = len(liss)
    return ans
print(solve(N,A))

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
//ダイクストラ法:スタートから任意の地点での最短距離を求める
//計算量:(頂点+辺)log(頂点) 
//egde:1002, path:1001 + 1000*999/2 -> 10^6 
//始点,終点,隣接リスト(pathlist[edge.A]=(edgeB,legth))-->距離(notfound:INFLL);
vector<double> Dikstra(int start, vector<vector<pair<int, double>>> &pathlist)
{
	int edge=pathlist.size();
	pair<double, int> cerching;
	priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q; //start to distance,[ditance ,islandNo.]
	vector<double > D(edge, INFLL);																//distance (ans)
	vector<bool>had(edge,false);
	D[start] = 0;
	q.emplace(0LL, start);




	while (!q.empty()){
		cerching = q.top();
		q.pop();
		if (had[cerching.second] == false){
			had[cerching.second] = true;


			for (auto i = pathlist[cerching.second].begin(); i != pathlist[cerching.second].end(); i++){
				if (had[i->first] == false){
					chmin(D[i->first], (cerching.first) + (i->second));
					q.emplace(D[i->first], i->first);
				}
			}
		}
	}


return D;
}
int main(){
	int n;
	pair<int,int>s,g;
	int ans=0;
	cin >>s.F>>s.S>>g.F>>g.S;
	cin>>n;
	vector<pair<pair<int,int>,int>>data(n+2);
	rep(i,n){
		cin>>data[i].F.F>>data[i].F.S>>data[i].S;
	}
	data[n]=mp(mp(s.F,s.S),0);
	data[n + 1] = mp(mp(g.F, g.S), 0);
	//rep(i,n+2){
		//clog<<data[i].F.F<<" "<<data[i].F.S<<" -- "<<data[i].S<<endl;
	//}
	//clog<<endl;
	vector<vector<pair<int,double>>>path(n+2);
	rep(i,n+2){
		rep(j,n+2){
			path[i].emplace_back(j,max(0.0,hypot((data[i].F).F-(data[j].F).F,(data[i].F).S-(data[j].F).S)-data[i].S-data[j].S));
		//	clog<<path[i].back().S<<" ";
		}
		//path[i][i].S=0.0;
		//clog<<endl;
	}
	vector<double>res=Dikstra(n,path);
	//rep(i,n+2){
	//	clog<<res[i]<<" ";
	//}
	//clog<<endl;
	printf("%.15lf\n",res[n+1]);
	//out << res[n+1] << endl;
}

Measured memory_bytes: 26616
/*
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

int ls[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  cin >> n;
  int n2 = n * 2;

  for (int i = 0; i < n2; i++) cin >> ls[i];
  sort(ls, ls + n2);

  int sum = 0;
  for (int i = 0; i < n2; i+= 2) sum += ls[i];
  printf("%d\n", sum);
  return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	set<int> A;
	for( int i = 0; i < N; ++i ) {
		int x;
		cin >> x;
		A.insert( x );
	}

	int k = A.size();
	cout << (k & 1 ? k : k-1) << endl;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/24  Problem: code-festival-2016-qual-c_c / Link: https://code-festival-2016-qualc.contest.atcoder.jp/tasks/codefestival_2016_qualC_c?lang=en  ----- */
/* ------問題------

アルピニストである高橋君と青木君は最近ある有名な山脈を踏破しました。この山脈はN 個の山からなっており、西から東に向けて山1,山2,…,山Nと一直線に並んでいます。高橋君は西から、青木君は東からこの山脈を踏破しました。
山i の高さはhi ですが、二人とも各hi の値は忘れてしまいました。その代わり、各i(1≦i≦N) に対して、山i の山頂にたどり着いた時の、それまでに登った山(山i も含む)の高さの最大値を記録しています。 高橋君の記録した値はTi で、青木君の記録した値はAi です。
各山の高さhi が正の整数であることはわかっています。山の高さの列としてありうるものが何通りあるかを109+7 で割ったあまりを求めてください。
ただし記録が間違っていてありうる山の高さの列が存在しないこともあります。この場合は0を出力してください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VL a(N);
	VL t(N);
	FOR(i, 0, N) {
		cin >> t[i];
	}
	FOR(i, 0, N) {
		cin >> a[i];
	}
	ans = 1;
	if (t.back() != a.front())ans = 0;
	FOR(i, 1, N-1) {
		if (t[i] != t[i - 1] && a[i] != a[i + 1]) {
			if (t[i] != a[i]) {
				ans = 0;
			}
		}
		else if (t[i] != t[i - 1]) {
			if (t[i] > a[i]) {
				ans = 0;
			}
		}
		else if (a[i] != a[i + 1]) {
			if (a[i] > t[i]) {
				ans = 0;
			}
		}
		else {
			ans *= min(a[i], t[i]);
			ans %= MOD;
		}
	}



	cout << ans << "\n";

	return 0;
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

int main() {
    int N; cin >> N;
    V<int> A(N);
    multiset<int> s;
    rep (i, N) {
        cin >> A[i];
        s.insert(A[i]);
    }
    rep(i, N) {
        s.erase(s.find(A[i]));
        cout << *s.rbegin() << endl;
        s.insert(A[i]);
    }
    return 0;
}

Measured memory_bytes: 11776
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int, pii> pip;
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
 
vector<string> split(const string &s, char c = ' '){
	vector<string> ret;
	stringstream ss(s);
	string t;
	while(getline(ss,t,c)){
		ret.pb(t);
	}
	return ret;
}


int main(){
	string str;
	vector<string> v;
	bool f;
	while(cin>>str){
		if(str[0] == '-') break;
		f = true;
		v = split(str, '.');
		string s, t;
		int a = atoi(v[0].c_str());
		//cout<<v[1]<<endl;
		int b = v.size()>1?atoi(v[1].c_str()):0;
		//cout<<"OK"<<endl;
		//cout<<a<<" "<<b<<endl;
		if(b % 5 != 0) {
			cout<<"NA"<<endl;
			continue;
		}
		double e = atof(str.c_str()) - a;
		while(a > 0){
			s += (char)('0' + a % 2);
			a /= 2;
			if(s.size() > 8) {
				f = false;
				break;
			}
		}
		while(s.size() < 8) s += '0';
		reverse(all(s));
		double d = (double)1/2;
		while(e > 0.0){
			if(e >= d){
				t += '1';
				e -= d;
			} 
			else{
				t += '0';
			}
			d *= (double)1/2;
			if(t.size() > 4){
				f = false;
				break;
			}
		}
		while(t.size() < 4) t += '0';

		cout<<(f?(s+"."+t):"NA")<<endl;
	}
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
	string s;
	cin>>s;
	auto l=s.find('A');
	auto r=s.rfind('Z');
	cout<<r-l+1<<endl;
	return 0;
}


Measured memory_bytes: 640
#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 main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int n = s.size() + t.size();
  string ans(n, 'a');
  for (int i = 0; i < s.size(); i++) {
    ans[i * 2] = s[i];
  }
  for (int i = 0; i < t.size(); i++) {
    ans[i * 2 + 1] = t[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

class program
{
    static void Main()
    {
        int S = int.Parse(Console.ReadLine());

        int H = S / 3600;
        int M = (S % 3600) / 60;
        int s = ((S % 3600) % 60);

        Console.WriteLine("{0}:{1}:{2}", H, M, s);


    }
}

Measured memory_bytes: 9152