akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int N;
cin >> N;

int ans = 0;

vi V(N),C(N),S(N);
rep(i,N) cin >> V[i];
rep(i,N) {
    cin >> C[i];
    S[i] = V[i] - C[i];
    if(S[i] > 0) ans+= S[i];
}

cout << ans << endl;


return 0;
}

Measured memory_bytes: 256
const main = input => {
  const n = input.trim()
  let ans = ''
  for (let i = 0; i < 3; i++) {
    ans += 10 - parseInt(n.substr(i, 1))
  }
  console.log(ans)
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29420
s = input()
ops = "+-"

for op1 in ops :
    for op2 in ops :
        for op3 in ops :
            exp = s[0]+op1+s[1]+op2+s[2]+op3+s[3]
            val = eval(exp)
            if val == 7 :
                print(exp + '=7')
                exit(0)


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

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

int dist[10][10];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int h,w;
	cin >> h >> w;
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			cin >> dist[i][j];
		}
	}
	for(int k = 0; k < 10; k++) {
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < h*w; i++) {
		int x;
		cin >> x;
		if(x != -1) {
			ans+= dist[x][1];
		}
	}
	cout << ans;
	return 0;
}



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

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X.at(i).at(j);
        }
    }
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            int x = 0;
            for (int k = 0; k < D; k++) {
                int tmp = X.at(i).at(k) - X.at(j).at(k);
                x += tmp * tmp;
            }
            if (sqrt(x) == (int)sqrt(x)) ans++;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int a[200000],b[200000];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	bool flg[8] = {};
	int over = 0;
	for(int i=0; i<N; i++){
		int rate;
		cin >> rate;
		if(rate < 3200) flg[rate/400] = true;
		else over++;
	}
	int ans = 0;
	for(int i=0; i<8; i++){
		if(flg[i]) ans++;
	}

	cout << (ans!=0?ans:1) << " " << ans+over << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;
using Graph = vector<vector<int>>;

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

vector<bool> seen;

void dfs(const Graph& G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int abs_B(long long num, long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

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

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

bool permutation(vector<int>& vec, vector<int>& P) {
    bool ok = true;
    for (int i = 0; i < vec.size(); i++) {
        //cout << vec.at(i);
        if (vec.at(i) != P.at(i)) {
            ok = false;
        }
    }
    return ok;
}

/*bool nibu(vector<int>& retu,int key) {

}*/

const long long MOD = 1000000007;
const int INF = 1001001001;

int main() {
    int N;
    cin >> N;
    vector<long long> retu(N);
    for (int i = 0; i < N; i++) {
        cin >> retu.at(i);
    }
    int count = 0;
    int ans = 0;
    sort(retu.begin(), retu.end());
    long long A;

    for (int i = 0; i < N - 1; i++) {
        if (retu.at(i) == retu.at(i + 1)) {
            count++;
        }
        else if (retu.at(i) != retu.at(i + 1) && count % 2 == 0) {
            ans++;
            count = 0;
        }
        else count = 0;

        if (i == N - 1) A = count;
    }
    if (count % 2 == 0) {
        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

bool sub(int a, int b) {
  return (a | b) == b;
}

const int N = 55;
const int M = (1 << 18);
int kek[M], fbit[M], C[N][N], a[N], b[N], cur[N], calc[N];

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  C[0][0] = 1;
  for (int i = 1; i <= 50; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
  }
  int n, k, s, t;
  cin >> n >> k >> s >> t;
  if (!sub(s, t)) {
    cout << 0 << '\n';
    exit(0);
  } 
  int tn = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (sub(s, a[i]) && sub(a[i], t)) {
      b[tn++] = a[i];
    }
  }
  n = tn;
  vector<int> bts;
  for (int i = 0; i < 18; i++) {
    if (((s ^ t) >> i) & 1) {
      bts.pb(i);
    }
  }
  for (int i = 0; i < n; i++) {
    int vl = 0;
    for (int j = 0; j < SZ(bts); j++) {
      if ((b[i] >> bts[j]) & 1) {
        vl |= 1 << j;
      }
    }
    b[i] = vl;
  }
  int L = SZ(bts);
  int ans = 0;
  for (int mask = 1; mask < (1 << L); mask++) {
    for (int i = 0; i < L; i++) {
      if ((mask >> i) & 1) {
        fbit[mask] = i;
        break;
      }
    }
  }
  //0..k - 1
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      calc[i] += C[i][j];
    }
  }
  kek[0] = (1ll << n) - 1;
  for (int fpos = 0; fpos < n; fpos++) {
    for (int j = 1; j < (1 << L); j++) {
      kek[j] = 0;
    }
    for (int i = fpos + 1; i < n; i++) {
      cur[i] = b[fpos] ^ b[i];
      for (int j = 0; j < L; j++) {
        if (!((cur[i] >> j) & 1)) {
          kek[1 << j] |= 1ll << i;
        } 
      }
    }
    int add = calc[n - fpos - 1];
    for (int mask = 1; mask < (1 << L); mask++) {
      kek[mask] = kek[mask ^ (1 << fbit[mask])] & kek[1 << fbit[mask]];
      if (__builtin_popcount(mask) & 1) {
        add -= calc[__builtin_popcountll(kek[mask])];
      } 
      else {
        add += calc[__builtin_popcountll(kek[mask])];
      }
    }
    ans += add;
  }
  cout << ans << '\n';
} 

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

ll f(ll x,ll y){
    return (x-y)*(x-y);
}

int main() {
    ll n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> y(n);
    vector<ll> num(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        num[i] = i;
    }
    double sum = 0;
    ll cnt = 0;
    sort(all(num));
    do {
        for (int i = 0; i < n - 1; ++i) {
            sum += sqrt(f(x[num[i]], x[num[i+1]]) + f(y[num[i]], y[num[i + 1]]));
        }
        cnt++;
    } while (next_permutation(all(num)));
    double ans=sum/cnt;
    cout << setprecision(20) << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  double index;
  cin >> index;
  double sum = 0;
  int loop = 1;
  while (sum < index){
    sum = sum + (double)pow(26, loop);
    ++loop;
  }
  --loop;
  double l_index = index;
  for (int i = 1; i < loop; ++i){
    l_index -= pow(26, i);
  }

  vector<double> num(loop);
  string result(loop, 'a');
  --l_index;

  for (int i = 0; i < loop; ++i){
    num.at(i) = (int)((double)l_index / (double)pow(26, loop - i - 1));  
    //cout << num.at(i) << endl;
    result.at(i ) = 'a' + num.at(i);
    l_index -= pow(26, loop - i - 1) * num.at(i) ;
  }
  // num.at(loop-1) = l_index / pow(26, 0);
  //result.at(loop-1) = 'a' + num.at(loop-1)-1;
  
  cout << result << endl;
}



Measured memory_bytes: 4164
<?php
fscanf(STDIN, '%d %d %d', $cnt, $x, $y);
$ans = array_fill(0, $cnt, 0);
for ($i=1; $i <= $cnt; $i++) { 
    for ($j=$i+1; $j <= $cnt; $j++) { 
        $dist = min($j - $i, abs($x - $i) + abs($j - $y) + 1, abs($y - $i) + abs($x - $j) + 1);
        $ans[$dist]++;
    }
}
unset($ans[0]);
echo implode("\n", $ans);
echo "\n";

Measured memory_bytes: 4728
#include<stdio.h>
#include <string.h>
#include<math.h>

int main(){
	int w,n,i,x;
	int v[31],a[31],b[31];
	
	scanf("%d",&w);
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d,%d",&a[i],&b[i]);
	}
	for(i=1;i<=w;i++){
		v[i]=i;
	}
	for(i=1;i<=n;i++){
		x=v[a[i]];
		v[a[i]]=v[b[i]];
		v[b[i]]=x;
	}
	for(i=1;i<=w;i++){
		printf("%d\n",v[i]);
	}
	return 0;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/b.in", "r", stdin);
//  freopen("../IO/b.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int x;
  in >> x;
  out << !x << '\n';
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,x;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        scanf("%lld",&x);
        n-=x;
    }
    if(n<0)
        cout<<-1<<endl;
    else cout<<n<<endl;
}


Measured memory_bytes: 3668
package main

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

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	n := nextInt()
	vecs := make([][]int, n)
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			vecs[u-1] = append(vecs[u-1], nextInt()-1)
		}
	}

	ds := make([]int, n)
	fs := make([]int, n)
	founds := make([]bool, n)
	t := 0
	for i := range founds {
		if !founds[i] {
			t = dfs(vecs, ds, fs, founds, i, t)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(w, i+1, ds[i], fs[i])
	}

	w.Flush()
}

func dfs(vecs [][]int, ds, fs []int, founds []bool, i, t int) (time int) {
	t++
	ds[i] = t
	founds[i] = true
	for _, v := range vecs[i] {
		if !founds[v] {
			t = dfs(vecs, ds, fs, founds, v, t)
		}
	}
	t++
	fs[i] = t

	return t
}



Measured memory_bytes: 1176
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define irep(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define rrep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

const int MOD = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    bool exi[26] = { false };
    for (auto c : s)
        exi[c - 'a'] = true;
    bool flag = false;
    rep(i, 0, 26) {
        if (!exi[i]) {
            flag = true;
            cout << (char)(i + 'a') << endl;
            break;
        }
    }
    if (!flag)
        cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807


int main() {
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    reverse(a.begin(),a.end());
    vector<ll> asum(n);
    asum[0] = a[0];
    for(int i = 1; i < n; i++){
        asum[i] = asum[i-1] + a[i];
    }


    ll ans = LLINF;
    for(int i = 1; i <= n; i++){
        bool overflow = false;
        ll cost = (i+n)*x;
        cost += 5*asum[i-1];
        ll prevcost = cost;
        ll num = 2*i-1;
        ll cnt = 1;
        while(num < n){
            ll coef = 2*cnt+3;
            cost += coef*(asum[num]-asum[num-i]);
            if(prevcost > cost){overflow = true;}
            else{prevcost = cost;}
            cnt++;
            num += i;
        }
        if(overflow){continue;}
        cost += (2*cnt+3)*(asum[n-1]-asum[num-i]);
        ans = min(ans, cost);
    }
    cout << (ll)(ans) << endl;
    return 0;
}


Measured memory_bytes: 3328
# coding: utf-8
ABCD = input() # ABCDの入力
op = ["*", "*", "*"] #解答出力のため演算子用の変数listを用意
def operate(ans, i): #再帰関数で解く
    if i == 3:
        if ans == 7:
            print("{}{}{}{}{}{}{}=7".format(ABCD[0], op[0], ABCD[1], op[1], ABCD[2], op[2], ABCD[3]))
            exit()
    else:
        op[i] = op[i].replace("*", "+").replace("-", "+") # 演算子の書き換え
        operate(ans + int(ABCD[i + 1]), i + 1)
        op[i] = op[i].replace("+", "-") # 演算子の書き換え
        operate(ans - int(ABCD[i + 1]), i + 1)
operate(int(ABCD[0]), 0)

Measured memory_bytes: 3064
#include <stdio.h>
int min(int a,int b){
    if(a > b){
        return b;
    }else return a;
}

int main(void){
    int N, i, min_count=100000;
    scanf("%d",&N);
    int a[N];
    
    for(i=0; i<N; i++)
    {
        scanf("%d",&a[i]);  
    }
    
    for(i=0; i<N; i++){
        int count=0;
        while(a[i] % 2 == 0){
            a[i] = a[i] / 2;
            count++;
        }
    
    min_count = min(count, min_count);
    
    }    

    printf("%d\n", min_count);   
    
    return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    cin.tie( 0 );
    ios::sync_with_stdio( false );
    
    int n;
    cin >> n;
    cin.ignore(); //<-----!!!!!!!!!!
    string s;
    
    while( getline(cin, s) ){
        
        string tmp = s;
        bool flag = false;
        auto pos = s.find( "Hoshino" );
        
        while( pos != string::npos ){
            
            if( pos != string::npos ){
                
                s.replace( pos, 7, "Hoshina" );
                pos = s.find( "Hoshino", pos , 7 );
                flag = true;
            }
        }
        cout << ( flag ? s : tmp ) << endl;
    }
    return 0;
}

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

int main(void)
{
  int N,M,i,j,H[100001],A[100001],B[100001],max,res[100001]={},sum=0;
  // res[i]=0 2は良い展望台

  scanf("%d %d",&N,&M);

  for(i=1;i<=N;i++)
  {
    scanf("%d",&H[i]);
  }

  for(i=1;i<=M;i++)
  {
    scanf("%d %d",&A[i],&B[i]);

    if(H[A[i]]>H[B[i]])
    {
      res[B[i]]=1;
    }

    else if(H[B[i]]>H[A[i]])
    {
      res[A[i]]=1;
    }
    
    else
    {
      res[A[i]]=1;
      res[B[i]]=1;
    }
  }

  for(i=1;i<=N;i++)
  {
    if(res[i]==0)
    {
      //printf("%d\n",i);
      sum++;
    }
  }

  
  printf("%d",sum);

  return 0;
}

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

struct city{
	int x;
	int y;
	int num;
	int ans;
};

bool comp_city_x(city &c1,city &c2){
	return c1.x<c2.x;
}

bool comp_city_n(city &c1,city &c2){
	return c1.num<c2.num;
}

int main(){
	int N;
	cin >> N;
	vector<city> C(N);
	for(int i=0;i<N;i++){
		int X,Y;
		cin >> X >> Y;
		C[i].x=X;
		C[i].y=Y;
		C[i].num=i;
	}
	
	sort(C.begin(),C.end(),comp_city_x);
	
	if(C[N-1].y==N){
		for(int i=0;i<N;i++)cout << N << endl;
		return 0;
	}
	
	dsu d(N);
	
	vector<bool> flag(N,false);
	vector<int> m(N,0);
	m[N-1]=C[N-1].y;
	for(int i=N-2;i>=0;i--)m[i]=max(m[i+1],C[i].y);
	for(int i=0;i<N;i++){
		if(flag[i])continue;
		int M=0,Mi=i;
		for(int j=i+1;j<N;j++){
			if(C[i].y>m[j])break;
			if(C[i].y<C[j].y){
				d.merge(i,j);
				flag[j]=true;
				if(M<C[j].y){
					flag[Mi]=true;
					Mi=j;
					M=C[j].y;
				}
			}
		}
	}
	
	for(int i=0;i<N;i++)C[i].ans=d.size(i);
	
	sort(C.begin(),C.end(),comp_city_n);
	
	for(int i=0;i<N;i++)cout << C[i].ans << endl;
	
	return 0;
}

Measured memory_bytes: 8048
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<complex>

using namespace std;

typedef complex<double> P;

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

double dot(P a,P b){
  return a.real()*b.real()+a.imag()*b.imag();
}

double dist(P a,P b,P c){
  if(dot(c-b,a-b)*dot(c-a,b-a)>0){
    return fabs(cross(a-b,c-b)/abs(a-b));
  }else{
    return min(abs(c-b),abs(c-a));
  }
}

int main(){
  for(int W,N;cin>>W>>N,W|N;){
    vector<int> x[223],y[223];
    double d[223];
    for(int i=0;i<N;i++){
      d[i]=1e9;
      int M;
      cin>>M;
      x[i].resize(M);
      y[i].resize(M);
      for(int j=0;j<M;j++){
	cin>>x[i][j]>>y[i][j];
	d[i]=min<double>(d[i],x[i][j]);
      }
    }
    double ans=W;
    bool u[223]={};
    for(int i=0;i<N;i++){
      double m=1e9;
      int mx;
      for(int j=0;j<N;j++){
	if(!u[j]&&d[j]<m){
	  m=d[j];
	  mx=j;
	}
      }
      u[mx]=true;
      for(auto e:x[mx]){
	ans=min(ans,d[mx]+W-e);
      }
      for(int j=0;j<x[mx].size();j++){
	for(int k=0;k<N;k++){
	  for(int l=0;l<x[k].size();l++){
	    d[k]=min(d[k],d[mx]+hypot(x[mx][j]-x[k][l],y[mx][j]-y[k][l]));
	    auto t=d[k];
	    d[k]=min(d[k],d[mx]+dist(P(x[mx][j],y[mx][j]),P(x[mx][(j+1)%x[mx].size()],y[mx][(j+1)%x[mx].size()]),P(x[k][l],y[k][l])));
	    d[k]=min(d[k],d[mx]+dist(P(x[k][l],y[k][l]),P(x[k][(l+1)%x[k].size()],y[k][(l+1)%y[k].size()]),P(x[mx][j],y[mx][j])));
	  }
	}
      }
    }
    cout.precision(9);
    cout<<fixed<<ans<<endl;
  }
}

Measured memory_bytes: 1304
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; 
using namespace std;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    data_set;
#define rep(i,l,r)   for(int i=(l);i<(r);i++)
#define deb(x)     cout << (#x) << " is " << (x) << endl
#define dbg(x)     cout << x << ' '
#define here cout << " Hey baitch!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld PI = 3.1415926535898;
struct pt
{
	int op;
	int cl;
	int id;
};
bool comp(pt x, pt y) {
	return (x.op * y.cl > y.op * x.cl);
}
int32_t main()
{
	SYNC
	int n;	cin >> n;
	vector<string> v(n);
	rep(i,0,n) cin >> v[i];
	vector<pt> a(n);
	rep(i,0,n) {
		string s = v[i];
		int mn = 0;
		int cnt = 0;
		a[i].op = 0, a[i].cl = 0;
		for(auto it : s) {
			if(it == '(')	a[i].op++;
			else	a[i].cl++;
		}
		a[i].id = i;
	}
	sort(all(a),comp);
	string ans;
	rep(i,0,n) {
		ans += v[a[i].id];
	}
	int cnt = 0;
	for(auto it : ans) {
		if(it == '(')	cnt++;
		else 	cnt--;
		if(cnt < 0)	return cout << "No",0;
	}
	if(cnt != 0)	return cout << "No",0;
	cout << "Yes";
    return 0;
}

Measured memory_bytes: 59944
#include <iostream>
#include <string>

#define cal(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
    string s, t;
    cin >> s;
    t = "Yes";
    cal(i, s.length()){
        if((i + 1) % 2 != 0){
            if(s.substr(i,1) == "L"){
                t = "No";
                break;
            }
        }else{
            if(s.substr(i,1) == "R"){
                t = "No";
                break;
            }
        }
    }
    cout << t;
    return 0;
}


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

int main(){
  ll n;
  cin >> n;
  int m=sqrt(n);
  cout << m*m << endl;
}
    

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

char ch[233];

int n;

map <long long, int> mp;

int main() {
    scanf("%d%s", &n, ch);
    for(int i = 0; i < (1 << n); i++) {
        long long hsh = __builtin_popcount(i);
        for(int j = 0; j < n; j++) if(i >> j & 1) hsh = hsh * 131 + ch[j];
        for(int j = n - 1; j >= 0; j--) if(!(i >> j & 1)) hsh = hsh * 131 + ch[j];
        mp[hsh]++;
    }
    reverse(ch, ch + 2 * n);
    long long ans = 0;
    for(int i = 0; i < (1 << n); i++) {
        long long hsh = __builtin_popcount(i);
        for(int j = 0; j < n; j++) if(i >> j & 1) hsh = hsh * 131 + ch[j];
        for(int j = n - 1; j >= 0; j--) if(!(i >> j & 1)) hsh = hsh * 131 + ch[j];
        ans += mp[hsh];
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 33024
#include "bits/stdc++.h"
using namespace std;

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

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
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 };

/* -----  2017/05/27  Problem: AGC 015 D / Link: http://agc015.contest.atcoder.jp/tasks/agc015_d  ----- */
/* ------問題------



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



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

ll A, B;

ll ans = 0LL;

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

	cin >> A >> B;

	stack<int>a, b;
	ll AA, BB;
	AA = A; BB = B;

	//おんなじ部分は削る
	while (AA != BB) {
		a.push(AA % 2);
		b.push(BB % 2);
		AA /= 2;
		BB /= 2;
	}

	ll RA = 0; ll RB = 0;//正規化済みの数
	while (!a.empty()) {
		RA = RA * 2 + a.top(); a.pop();
		RB = RB * 2 + b.top(); b.pop();
	}
	if (RA == RB) {
		cout << 1 << endl;
		return 0;
	}

	if (RA == 0) {
		ll h = 1;
		while (h <= RB)h *= 2;
		h /= 2;
		ans = 2 * h - 1;
		if (RA != A)ans++;//元の数と違えば2^(桁)通り
		cout << ans << endl;
		return 0;
	}

	if (RA == 1) {
		ll h = 1;
		while (h <= RB)h *= 2;
		h /= 2;
		ans = 2 * h - 1;
		cout << ans << endl;
		return 0;
	}

	ll h = 1;
	while (h <= RB)h *= 2;
	h /= 2;

	ll ans = h - RA;//[RA,2^(h)=(Bの最高の桁))

	ll h2 = 1;
	while (h + h2 <= RB)h2 *= 2;//RBの二番目の高いビット
	h2 /= 2;

	if (h2 > 0) {
		ans += h2 * 2;//[100...0,1001...0]は2^(二番目のbit)
		ll s = max(h2 * 2, RA);
		ans += h - s;
	}
	else {
		ans += h - RA + 1;
		//100..0には[RA,01111...]までのORをとっても重複する数がないので2*([RA,01111...])+(10000..0)
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
/**************************************************************
    User: ZincSabian
    Language: C++
****************************************************************/
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
inline ll _() {
	ll x=0,f=1; char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())
		if(ch=='-')f=-f;
	for(;ch>='0'&&ch<='9';ch=getchar())
		x=x*10+ch-'0';
	return x*f;
}
#define _ _()
double a[105];
int main() {
	int n=_;
	double sum=0;
	for(int i=0;i<n;i++) 
		scanf("%lf",&a[i]);
	for(int i=0;i<n;i++)
		sum+=a[i]; 
	double ave=sum/n;
//	printf("%.lf\n",ave);
	int ans=0;
	for(int i=1;i<n;i++)
		if(fabs(a[i]-ave)<fabs(a[ans]-ave)) ans=i;
	printf("%d\n",ans);
} 

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


int main(){
    string s;cin>>s;
    int n=s.length();
    vector<int> v(n,0);
    int count=1;
    for(int i=0;i<n-1;i++){
       if(s[i]=='R'&&s[i+1]=='L'){
           int cnt=1;
           while((i-cnt)>=0&&s[i]==s[i-cnt])cnt++;
           v[i]=cnt;
           cnt=1;
           while((i+cnt+1)<n&&s[i+1]==s[i+cnt+1])cnt++;
           v[i+1]=cnt;
       }
    }
    
   for(int i=0;i<n-1;i++){
        if(v[i]==0||v[i+1]==0)continue;
       else{ int r=v[i],l=v[i+1];
        v[i]=(r+1)/2+l/2;
        v[i+1]=r/2+(l+1)/2;i++;}
    }
    for(int i:v)cout<<i<<' ';
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long int ll;
long long int mod=998244353;
ll power[3009];
int n,s;
int a[3009];
ll dp[3009][3009];
int main()
{
    cin>>n>>s;
    for(int i=1;i<=n;i++) cin>>a[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
        for( int j=0;j<=s;j++){if(j>=a[i]) dp[i][j]=(2*dp[i-1][j]+dp[i-1][j-a[i]])%mod; else dp[i][j]=(2*dp[i-1][j])%mod;}
    cout<<dp[n][s];
    
}


Measured memory_bytes: 74144
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=100005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli arr[MaxN];
int main(){
	cin.tie(0),ios_base::sync_with_stdio(0);
	lli N,i,j,p,q,res=0;
	cin>>N;
	for(i=2;i*i<=N;i++){
		p=0,q=1;
		while(N%i==0){
			N=N/i;
			p+=1;
		}
		while(p>0){
			p-=q;
			res+=1;
			q+=1;
		}
		if(p<0)res-=1;
	}
	if(N>1)res+=1;
	cout<<res<<"\n";
}

Measured memory_bytes: 3216
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int v, e;
    cin >> v >> e;

    vector<vector<int>> edge(v, vector<int>(v, INF));
    rep(i, e){
        int s, t, d;
        cin >> s >> t >> d;
        edge[s][t] = d;
    }

    vector<vector<int>> cost(1 << v, vector<int>(v, INF));
    rep(i, v){
        cost[1][0] = 0;
    }
    for(int s = 0; s < (1 << v); s++){
        rep(i, v){
            if(s != 0 && (s >> i) % 2 == 0){
                continue;
            }
            rep(j, v){
                if((s >> j) % 2 == 1 || edge[i][j] == INF){
                    continue;
                }
                if(cost[s | (1 << j)][j] > cost[s][i] + edge[i][j]){
                    cost[s | (1 << j)][j] = cost[s][i] + edge[i][j];
                }
            }
        }
    }

    int ans = INF;
    rep(i, v){
        if(ans > cost[(1 << v) - 1][i] + edge[i][0]){
            ans = cost[(1 << v) - 1][i] + edge[i][0];
        }
    }
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int n,k;
	cin >> n >> k;
	vi h(n);
	rep(i,n) cin >> h[i];
	sort(all(h));
	reverse(all(h));
	ll ans = 0;
	for(int i = k; i < n; i++) ans += h[i];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int h,w;
  cin>>h>>w;
  int a[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a[i][j];
    }
  }
  vector<pair<P,P>> p;
  int c=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]%2==1){
        if(j!=w-1){
          c++;
          a[i][j+1]++;
          p.push_back(make_pair(P(i+1,j+1),P(i+1,j+2)));
        }else if(j==w-1&&i!=h-1){
          c++;
          a[i+1][j]++;
          p.push_back(make_pair(P(i+1,j+1),P(i+2,j+1)));
        }
      }
    }
  }
  cout<<p.size()<<endl;
  for(int i=0;i<p.size();i++){
    cout<<p[i].first.first<<" "<<p[i].first.second<<" "<<p[i].second.first<<" "<<p[i].second.second<<endl;
  }
}

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

#define min(a, b) a < b ? a : b
#define max(a, b) a > b ? a : b

int main(void)
{
	int a, b;

	scanf("%d %d", &a, &b);
	
	/*if (a == 1) {
		if (b == 1) printf("Draw\n");
		else printf("Alice\n");
	} else if (b == 1) {
		printf("Bob\n");
	} else {
		if (a == b) {
			printf("Draw\n");
		} else if (a > b) {
			printf("Alice\n");
		} else {
			printf("Bob\n");
		}
	}*/
	if (a == 1) a += 13;
	if (b == 1) b += 13;
	if (a > b) {
		printf("Alice\n");
	} else if (a < b) {
		printf("Bob\n");
	} else {
		printf("Draw\n");
	}

	return (0);
}

Measured memory_bytes: 128
//“ In order to be irreplaceable, one must always be different”
#include <bits/stdc++.h>
using namespace std;
# define ll long long
#define endl "\n"
# define pi 3.14159265359
# define str string
# define vll vector<ll>
# define vstr vector<str>
# define vchar vector<char>
# define pb push_back
# define popb pop_back
# define pf push_front
# define popf pop_front
# define sll set<ll>
# define schar set<char>
//find()
//erase(x) removes element x
//erase(position,position)
# define qll queue<ll>
# define qstr queue<str>
//front(),back()
# define stll stack<ll>
# define ststr stack<str>
//top()
# define dll deque<ll>
//at()
# define mll map<ll,ll>
#define mchar map<char, ll>
# define mstr map<str,ll>
# define mss map<str,str>
# define mci map<char,ll>
# define vp vector< pair<ll,ll> >
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
# define r(x,y) for(int x=y;x>=0;x--)
# define fr(x,y,z) for(int x=y;x<z;x++)
# define rr(x,y,z) for(int x=y;x>z;x--)
ll power(ll a , ll b){ll res=1;for(ll i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll gcd(ll a, ll b){
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}
void print(vll a){
    for(int i=0;i<a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
vll inp(int n){
    vll a;
    ll x;
    f(i,n){
        cin>>x;
        a.pb(x);
    }
    return a;
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll x,y;
    cin>>y>>x;
    ll s=0;
    ll a[x];
    f(i,x){
        cin>>a[i];
        s+=a[i];
    }
    if(s<=y){
        cout<<y-s;
    }
    else{
        cout<<-1;
    }
}

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


def solve(N: int):
    p = 0
    if N % 2 == 0:
        p = 1 / 2
    else:
        p = ((N - 1) / 2 + 1) / N
    print("{0:.10f}".format(p)) 
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
const main = (input) => {
  input = input.split(' ');
  const a = parseInt(input[0], 10);
  const b = parseInt(input[1], 10);
  const c = parseInt(input[2], 10);
  const d = parseInt(input[3], 10);
  
  if (a*b>=c*d) {
    console.log(a*b);
  }else if (a*b<=c*d){
    console.log(c*d);
  }else{
    console.log(a*b);
  }
  
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const A_MAX = 1000;
ll const B_MAX = 1000;

int main() {
  ll X;
  cin >> X;
  ll a, b;
  for (ll i = 0; i < A_MAX; i++) {
    for (ll j = 0; j < B_MAX; j++) {
      ll target_1 = pow(i, 5) - pow(j, 5);
      ll target_2 = pow(i, 5) - pow(-j, 5);
      if (target_1 == X) {
        cout << i << " " << j << endl;
        return 0;
      }
      if (target_2 == X) {
        cout << i << " " << -j << endl;
        return 0;
      }
    }
  }
  return 0;
}

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

int main(){
    int N,T;
    int A[100000];
    cin>>N>>T;
    int ma,mi;
    int dif;
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(i==0){
            ma=A[i];
            mi=A[i];
            dif=0;
        }else{
            dif=max(A[i]-mi,dif);
            mi=min(mi,A[i]);
        }
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(i==0){
            ma=A[i];
            mi=A[i];
        }else{
            if(A[i]-mi==dif) ans++;
            mi=min(mi,A[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(void) {
    int N;
    int sum,maxsum = INT_MIN;
    cin >> N;
    
    // 縦について全2^10通り試せば良い

    vector<vector<int>> shop(10,vector<int>(N));
    for(int i=0;i<N;i++) {
        for(int j=0;j<10;j++) {
            cin >> shop[j][i];
        }
    }

    vector<vector<int>> gain(11,vector<int>(N));
    for(int i=0;i<N;i++) {
        for(int j=0;j<11;j++) {
            cin >> gain[j][i];
        }
    }

    for(int i=1;i<(1<<10);i++) {
        vector<int> openshop(N,0);
        for(int j=0;j<10;j++) {
            if((i >> j)&1) {
                for(int k=0;k<N;k++) {
                    openshop[k] += shop[j][k];
                }
            }
        }
    
        sum = 0;
        for(int j=0;j<N;j++) {
            sum += gain[openshop[j]][j];
        }
        if(maxsum < sum) {
            maxsum = sum;
        }
    }

    cout << maxsum << endl;
    return 0;
}


Measured memory_bytes: 256
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <vector>
#include <queue>


typedef long long llong;
using namespace std;

int bitDP[10][110] = { 0 };

int main() {
	for (int i = 0; i < 1024; i++) {
		int present_num = 0;
		int present_i = i;
		int present_cnt = 0;
		int present_sum = 0;
		while (present_num != 10) {
			if (present_i % 2) {
				present_sum += present_num;
				present_cnt++;
			}
			present_num++;
			present_i = present_i >> 1;
		}
		bitDP[present_cnt][present_sum]++;
	}
	int n, s;
	while (1) {
		cin >> n >> s;
		if (n == 0)break;
		cout << bitDP[n][s] << endl;
		
	}
	
	return 0;
}
 


Measured memory_bytes: 3068
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#include <assert.h>
#define FOR(i,a,n) for(i=(a);i<(n);i++)
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 100005
#define LOCAL
#ifdef LOCAL
    #define DEBUG(...) printf(" "__VA_ARGS__)
#else
    #define DEBUG(...)
#endif /* LOCAL */
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}

int que[2500][2];
int dist[50][50];
char map[50][50];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int main(void)
{
	int h,w,front,rear,x,y,nx,ny,sum=0,i,j;
	scanf("%d%d",&h,&w);
	FOR(i,0,h){
		scanf("%s",map[i]);
		FOR(j,0,w){
			if(map[i][j]=='.') sum++;
			dist[i][j]=INF;
		}
	}
	dist[0][0]=1;
	front=rear=0;
	que[rear][0]=0,que[rear++][1]=0;
	while(front!=rear){
		x=que[front][0],y=que[front++][1];
		FOR(i,0,4){
			nx=x+dx[i],ny=y+dy[i];
			if(nx<0||ny<0||nx>=h||ny>=w||map[nx][ny]=='#') continue;
			if(dist[nx][ny]>dist[x][y]+1){
				dist[nx][ny]=dist[x][y]+1;
				que[rear][0]=nx,que[rear++][1]=ny;
			}
		}
	}
	if(dist[h-1][w-1]==INF) puts("-1");
	else printf("%d\n",sum-dist[h-1][w-1]);
	return 0;
}
    
    


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

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

int main()
{
    int n;
    scanf("%d",&n);
    bool ok = true;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d",t+1,x+1,y+1);
        if(!ok) continue;
        int dd = abs(x[1]-x[0]) + abs(y[1]-y[0]);
        int dt = t[1] - t[0]; 
        if(dd > dt || (dt-dd)&1) ok = false;
        t[0] = t[1];
        x[0] = x[1];
        y[0] = y[1];
    }
    puts(ok?"Yes":"No");
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;

int main(int argc, char const *argv[]) {
    char str[1001];

    while (true) {
        scanf("%s", str);
        if (str[0] == '0') {
            break;
        }

        int sum = 0;
        int inputLength = strlen(str);
        for (int i = 0; i < inputLength; i++) {
            sum += (str[i] - '0');
        }

        printf("%d\n", sum);
    }

    return 0;
}



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

int main()
{
   string s,t;
   cin >> s>>t;

   sort(s.begin(), s.end());
   sort(t.begin(), t.end());
   reverse(t.begin(), t.end());
   if(s<t){
   cout<<"Yes"<<endl;
   }
   else
   cout<<"No"<<endl;
   
   return 0;
}


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

int solve(string S){
    int max_global = 0;
    int max_current = 0;
    for (int i = 0; i < S.size(); ++i) {
        if(S[i] == 'R'){
            max_current++;
            max_global = max(max_global,max_current);
        }else{
            max_global = max(max_global,max_current);
            max_current = 0;
        }
    }
    return max_global;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("../input.txt","r",stdin);

    string S;
    cin >> S;

    cout << solve(S);
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;

ll N;
ll T;
ll t[200100];
ll ans = 0;
int main(){
  cin >> N >> T;
  rep(i,N){
    cin >> t[i];
  }
  sort(t,t+N);
  rep(i,N-1){
    ans += min(t[i+1]-t[i],T);
  }
  ans += T;
  cout << ans << endl;
}


Measured memory_bytes: 1792
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

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

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);

#ifdef BUGGY
	bool DEBUG = 1;
#endif
#ifndef BUGGY
	bool DEBUG = 0;
#endif

int N, M, X, Y;
int maxA, minB;

int main()
{
	scanf("%d %d %d %d", &N, &M, &X, &Y);
	maxA = X;
	minB = Y;

	for (int i = 0; i < N; i++) {
		int temp;
		scanf("%d", &temp);
		maxA = max(maxA, temp);
	}


	for (int i = 0; i < M; i++) {
		int temp;
		scanf("%d", &temp);
		minB = min(minB, temp);
	}

	if (maxA < minB) {
		printf("No War\n");
	} else {
		printf("War\n" );
	}

	return 0;
}
/*
	Powered by Buggy Plugin
*/

Measured memory_bytes: 256
n,y=map(int,input().split())
array=[-1,-1,-1]
for i1 in range(n+1):
  for i2 in range(n+1-i1):
    if 10000*i1+5000*i2+1000*(n-i1-i2)==y:
      array=[i1,i2,n-i1-i2]
      break
print(array[0],array[1],array[2])

Measured memory_bytes: 3060
S=input()
first = S[:2]
second= S[2:]
ans=""


if int(first) > 12 or int(first) == 0:#MM
	if int(second) <= 12 and int(second) >= 1:#YY
		ans="YYMM"
	if int(second) > 12 or int(second) == 0:#YY
		ans="NA"

elif int(first) <= 12 and int(first) >= 1:#YY
	if int(second) <= 12 and int(second) >= 1:#YY
		ans="AMBIGUOUS"
	if int(second) > 12 or int(second) == 0:#YY
		ans="MMYY"

print(ans)

Measured memory_bytes: 9212
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        
        int x_max = x + r;
        int y_max = y + r;
        int x_min = x - r;
        int y_min = y - r;
        
        if ((x_max <= w) && (y_max <= h) && (x_min >= 0) && (y_min >= 0)) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26364
H, W, A, B = map(int,input().split())
P = 10**9+7
# H, W, A, B = map(int,"2 3 1 1".split())

M = H+W-1
factlist = [1] * (H+W)
factinvlist = [1] * (H+W)
t = 1
for i in range(M):
	t = (t * (i+1)) % P
	factlist[i+1] = t
t = pow(factlist[M],P-2,P)
factinvlist[M] = t
for i in range(M):
	t = (t * (M-i)) % P
	factinvlist[M-i-1] = t

def comb(i,j):
	return (factlist[i+j] * factinvlist[i] * factinvlist[j]) % P

s = 0
i = 0
while H-A-i-1 >= 0 and B+i <= W and A+i <= H and W-B-i-1 >= 0:
#	print((H-A-i,B+i+1))
	s = (s + comb(H-A-i-1,B+i) * comb(A+i,W-B-i-1)) % P
	i += 1	
print(s)



Measured memory_bytes: 18804
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)
#define N_MAX 200000

using namespace std;

typedef long long int Int;

Int dp[N_MAX][2];

int main(void) {
    string L;
    
    cin>>L;
    int n = L.size();
    dp[0][0] = 1;
    for(int i = 0;i < n;i++) {

        if(L[i] == '0') {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1];
        } else {
            dp[i+1][1] = (dp[i][0]+dp[i][1])%MOD;
        }

        if(L[i] == '0') {
            (dp[i+1][1] += dp[i][1]*2 % MOD) %= MOD;
        } else {
            (dp[i+1][0] += dp[i][0]*2 % MOD) %= MOD;
            (dp[i+1][1] += dp[i][1]*2 % MOD) %= MOD;
        }
    }

    Int sum = (dp[n][0]+dp[n][1])%MOD;

    cout<<sum<<endl;

    return 0;
}




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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  
  sort(all(a));
  bool b=1;
  
  rep (i, n) if (a[i] == a[i+1]) b=0;
  
  if (b == 1) dunk("YES");
  else dunk("NO");
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
  for (int i = 1; i <= 9; i++) {
      if (N%i != 0) continue;
      if (N / i <= 9 and N / i >= 1) {
	  cout << YES << endl;
	  return;
      }
  }
  cout << NO << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
num_array = []
min_total = []
num = input()

for i in num:
    num_array.append(i)

for i in range(len(num_array) - 2):
    total = num_array[i] + num_array[i+1] + num_array[i+2]
    min_total.append(abs(int(total) - 753))

print(min(min_total))



Measured memory_bytes: 2940
#include <stdio.h>

#define MAX (1 << 17) /* 131072 */

int ki[MAX * 2 - 1];

void ki_set(int idx, int value) {
	int pos = (MAX - 1) + idx;
	ki[pos] = value;
	for (;;) {
		int c1, c2;
		pos = (pos - 1) / 2;
		c1 = ki[pos * 2 + 1];
		c2 = ki[pos * 2 + 2];
		ki[pos] = c1 >= c2 ? c1 : c2;
		if (pos == 0) break;
	}
}

int ki_get_i(int idx, int qmin, int qmax, int smin, int smax) {
	if (qmax <= smin || smax <= qmin) { /* クエリがセグメントから完全に外れている */
		return -1;
	} else if (qmin <= smin && smax <= qmax) { /* セグメントがクエリに完全に含まれる */
		return ki[idx];
	} else {
		int smid = smin + (smax - smin) / 2;
		int l = ki_get_i(idx * 2 + 1, qmin, qmax, smin, smid);
		int r = ki_get_i(idx * 2 + 2, qmin, qmax, smid, smax);
		return l >= r ? l : r;
	}
}

int ki_get(int min, int max) {
	return ki_get_i(0, min, max, 0, MAX);
}

int N;
int A[114514];

/* start以降の要素で、target以上の最初のものを探す */
int ki_mofu(int start, int target) {
	int yes = start, no = N; /* [start, yes)の要素にtarget未満のものしか無い */
	if (ki_get(start, N) < target) {
		return N;
	}
	while (yes + 1 < no) {
		int mid = yes + (no - yes) / 2;
		if (mid <= start) yes = mid;
		else if (ki_get(start, mid) < target) yes = mid; else no = mid;
	}
	return yes;
}

int main(void) {
	int i;
	int count = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
		ki_set(i, A[i]);
	}
	while (ki_get(0, N) >= 0) {
		int current_pos, current_value;
		count++;
		current_pos = 0;
		current_value = -1;
		for (;;) {
			int next_pos = ki_mofu(current_pos, current_value + 1);
			if (next_pos >= N) break;
			current_value = A[next_pos];
			ki_set(next_pos, -1);
			current_pos = next_pos + 1;
		}
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 1408
N,X = map(int,input().split())

L = [1]
for i in range(50) :
    L.append(L[-1]*2+3)

def dp(n,x) :
    if x == 0 :
        return 0
    elif n == 0 :
        return 1
    elif n >= 1 :
        if x == 1 :
            return 0
        elif x <= L[n-1]+1 :
            return dp(n-1,x-1)
        elif x == L[n-1]+2 :
            return dp(n-1,x-1)+1
        elif x <= L[n]-1 :
            return dp(n-1,x-1)+1+dp(n-1,x-L[n-1]-2)
        else :
            return dp(n-1,x-1)*2+1
ans = dp(N,X)
print(ans)


Measured memory_bytes: 3064