akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <vector>

int dfs(int visited, int v,
        const std::vector<std::vector<std::pair<int, int>>> &redges,
        std::map<std::pair<int, int>, int> &dp,
        int ans, int acc) {
  auto it = dp.find(std::make_pair(visited, v));
  if (it != dp.end()) {
    return it->second;
  }
  int cost = -1;
  for (auto edge : redges[v]) {
    if (!(visited & (1 << edge.first))) {
      continue;
    }
    int tmp = dfs(visited - (1 << v),
                  edge.first,
                  redges, dp, ans, acc + edge.second);
    if (tmp == -1) {
      continue;
    }
    tmp += edge.second;
    if (cost == -1 || cost > tmp) {
      cost = tmp;
    }
  }
  dp[std::make_pair(visited, v)] = cost;
  return cost;
}

int main() {
  int V, E;
  std::cin >> V >> E;
  std::vector<std::vector<std::pair<int, int>>> redges(V);
  for (int i = 0; i < E; i++) {
    int fr, to, weight;
    std::cin >> fr >> to >> weight;
    redges[to].push_back(std::make_pair(fr, weight));
  }
  int all_visited = (1<<V) - 1;

  int ans = -1;
  for (int start = 0; start < 1; start++) {
    std::map<std::pair<int, int>, int> dp;
    dp[std::make_pair(1<<start, start)] = 0;
    for (auto edge : redges[start]) {
      int cost = dfs(all_visited, edge.first, redges, dp, ans, edge.second);
      if (cost == -1) {
        continue;
      }
      cost += edge.second;
      if (ans == -1 || ans > cost) {
        ans = cost;
      }
    }
  }
  std::cout << ans << std::endl;                                                                                                                                                                                                              
  
}



Measured memory_bytes: 18428
#include <climits>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  int CH, CW;
  cin >> CH >> CW;
  CH--, CW--;
  int DH, DW;
  cin >> DH >> DW;
  DH--, DW--;
  vector<string> S(H);
  rep(i, H) cin >> S[i];

  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>,
                 greater<tuple<int, int, int>>>
      que;
  que.emplace(0, CH, CW);
  vector<vector<int>> dist(H, vector<int>(W, INT_MAX));
  dist[CH][CW] = 0;

  while (!que.empty()) {
    int warp, y, x;
    tie(warp, y, x) = que.top();
    que.pop();
    if (y == DH && x == DW) {
      cout << warp << endl;
      return 0;
    }
    for (int i = -2; i <= 2; ++i) {
      for (int j = -2; j <= 2; ++j) {
        if (i == 0 && j == 0) continue;
        int ny = y + i;
        int nx = x + j;
        int nwarp = warp + 1;
        if ((i == 0 && (j == -1 || j == 1)) || (j == 0 && (i == -1 || i == 1)))
          nwarp = warp;
        if (ny < 0 || nx < 0 || H <= ny || W <= nx) continue;
        if (S[ny][nx] != '.') continue;
        if (dist[ny][nx] <= nwarp) continue;
        dist[ny][nx] = nwarp;
        que.emplace(nwarp, ny, nx);
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 8568
local n = io.read("*n", "*l")
local s = io.read()
local t = {}
for i = 1, 26 do t[i] = 0 end
for i = 1, n do
  local p = s:sub(i, i):byte() - 96
  t[p] = t[p] + 1
end
local ret = 1
for i = 1, 26 do
  ret = (ret * (1 + t[i])) % 1000000007
end
print(ret - 1)


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

int main() {
	string ss;
	cin >> ss;
	int arr[26]={};
	for (int i=0; i<ss.length(); i++){
		arr[(ss[i]-'a')]++;
	}
	for (int i=0; i<26; i++){
		if (arr[i]>1){
			cout << "no\n";
			return 0;
		}
	}
	cout << "yes\n";
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> flowers(n);
for(ll i = 0; i < n; i++)
    cin >> flowers[i];
ll ans = 0;
for(ll i = 1; i < n; i++){
    if(flowers[i] - flowers[i - 1] < 0)
        ans += abs(flowers[i] - flowers[i - 1]);
}
cout << ans + flowers[n - 1] << endl;
}

Measured memory_bytes: 256
def myAnswer(N:int,H:list) -> str:
   pre = H.pop(0) - 1
   for h in H:
      if(pre < h):
         pre = h - 1
      elif(pre > h):
         return "No"
      else:
         pre = h
   return "Yes"


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   H = list(map(int,input().split()))
   print(myAnswer(N,H[:]))
if __name__ == '__main__':
   main()



Measured memory_bytes: 15020
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    ll n,d;
    cin>>n>>d;
    //vector<pair<ll,ll>> v(n);
    ll cnt=0;
    rep(i,n)
    {
        ll x,y;
        cin>>x>>y;
        if((d*d)>=(x*x+y*y))
        cnt++;
    }
    cout<<cnt<<endl;
    
}

Measured memory_bytes: 3668
import sys
import collections
import copy
def input(): return sys.stdin.readline().strip()
A= input()
B=input()
ans = ""
n = len(A)+len(B)
for i in range(n):
    if i%2 == 0:
        ans= ans+A[i//2]
    else:
        ans= ans+B[(i-0)//2]
print(ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int sum = 0;
  for(int i = 1; i < 100000001; i *= 10) {
    sum += N / i % 10;
  }
  if(N % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

int main()
{
int r,c;
cin >> r >> c;
vector<vector<int>> rc(r, vector<int>(c));
vector<int> sumr(c);
int sum=0;
for (int i=0;i<r;i++)
{
int sumc=0;
for (int j=0;j<c;j++)
{
cin >> rc.at(i).at(j) ;
sumc+=rc.at(i).at(j);
sumr.at(j)+=rc.at(i).at(j);
cout << rc.at(i).at(j) << " ";
}
cout << sumc << endl;
sum+=sumc;
}
for(int j=0;j<c;j++)
{
cout << sumr.at(j) << " ";
}
cout << sum << endl;
}



Measured memory_bytes: 3204
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

//文字列としての数字を
//整数数型に変換する関数
long long getint(string str) {
	long long ret = 0;

	for (int i = 0; i < str.size(); i++) {
		ret = ret * 10 +(str[i] - '0');
	}

	return ret;
}

int main() {

	string s; cin >> s;

	//一文字なら＋を入れる余地がないので、表示して終了
	if (s.size() == 1) {
		cout << s << endl;
		return 0;
	}
	

	//s[0] s[1] s[2]…という添字の向きだと扱いにくいのでひっくり返す
	//…s[2] s[1] s[0]になる
	reverse(s.begin(), s.end());

	long long ans = 0;

	//＋が入る隙間の数
	int l = s.size() - 1;

	//＋の有無のパターンを全列挙
	//ビットが立ってる位置には＋を入れる

	//…s[2] l[1] s[1] l[0] s[0]
	//という対応になっている
	for (int bit = 0; bit < (1 << l); bit++) {
		
		//各＋の間にある数字を表す文字列
		string tmp ="";

		tmp += s[0];
		
		for (int i = 0; i < l; i++) {

			if ((bit >> i) & 1) {
				ans += getint(tmp);
				tmp = s[i+1];
			}
			else {
				tmp= s[i+1]+tmp;
			}

			if (i == l - 1) {
				ans += getint(tmp);
			}
		}
	}

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			for(int i = 0;i< 3;i++) {
				System.out.print(s[i].substring(0,1).toUpperCase());
			}
//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)

ll mod=1e9+7;
vector <ll> factorials, inv_factorials;

ll modExp(ll x, ll n)
{
    if (n==0) return 1;
    if (n==1) return x%mod;
    ll ans = modExp(x,n/2);
    ans = (ans*ans)%mod;
    if (n%2) ans*=x;
    return ans%mod;
}

ll modInv(ll a)
{
    return modExp(a, mod-2);
}

void calculate(ll N)
{
    factorials.resize(N+1);
    inv_factorials.resize(N+1);
    factorials[0]=1;
    for (int i=1; i<=N; ++i) factorials[i]=(factorials[i-1]*i)%mod;
    inv_factorials[N]=modInv(factorials[N]);
    for (int i=N-1; i>=0; --i) inv_factorials[i]=((i+1)*inv_factorials[i+1])%mod;
}

ll choose(ll N, ll K)
{
    if (N<0 || K<0) return 0;
    if (K>N) return 0;
    return (((factorials[N]*inv_factorials[N-K])%mod)*inv_factorials[K])%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N,M;
    cin >> N >> M;
    calculate(M);
    ll Aways=(choose(M,N)*factorials[N])%mod;
    ll Bways=Aways;
    for (int i=1; i<=N; ++i)
    {
        Bways += ((i%2) ? (-1): (1)) * (choose(N,i) * ((choose(M-i, N-i) * factorials[N-i])%mod))%mod;
        Bways %= mod;
    }
    cout << (mod+(Aways*Bways)%mod)%mod << "\n";
    return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll X; cin >> X;
    vector<ll> factor;
    for (int i = 1; i <= sqrt(X); i++) {
        if (X % i == 0) {
            factor.push_back(i);
            factor.push_back(X/i);
        }
    }

    for (auto i: factor) {
        for (ll j = -1000; j <= 1000; j++) {
            ll A = j + i;
            ll B = j;
            if (pow(A, 5) - pow(B, 5) == X) {
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }
}

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

int main(){
	int weight;
	while(cin >> weight){
		if(weight == 0) break;
		int minimum_cost = 100000000;
		for(int i = 0; (i-1) * 200 < weight; i++){
			int w2 = weight - 200 * i;
			for(int j = 0; (j-1) * 300 < w2; j++){
				int w3 = w2 - 300 * j;
				int k = 0;
				while(k * 500 < w3) k++;
				int cost = (i / 5) * 1520 + (i % 5) * 380
					+ (j / 4) * 1870 + (j % 4) * 550
					+ (k / 3) * 2244 + (k % 3) * 850;
				if(i * 200 + j * 300 + k * 500 == weight)
					minimum_cost = min(minimum_cost, cost);
			}
		}
		cout << minimum_cost << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

template <typename T>
int bfs(int sx, int sy, int gx, int gy, const T& maze){
    const int INF = 1e8;
    queue<pair<int, int>> que;
    int H = maze.size(), W = maze[0].size();
    vector<vector<int>> d(H, vector<int>(W, INF));
 
    que.push(pair<int, int>(sx, sy));
    d[sy][sx] = 0;
 
    int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
    while (que.size()) {
		pair<int, int> p = que.front();
		que.pop();
 
		if ((p.first == gx) && (p.second == gy)) break;
 
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			
			if ((0 <= nx) && (nx < W) && (0 <= ny) && (ny < H)) {
				if ((maze[ny][nx] == '.') && (d[ny][nx] == INF)) {
		    		que.push(pair<int, int>(nx, ny));
		    		d[ny][nx] = d[p.second][p.first] + 1;
				}
	    	}
		}
    }
 
    return d[gy][gx];
}

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> map(H);
	for (int i = 0; i < H; ++i) { cin >> map[i]; }

	int len = bfs(0, 0, W - 1, H - 1, map);
	if (len == 1e8) {
		cout << -1 << endl;
		return 0;
	}

	int cnt = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (map[i][j] == '#') { ++cnt; }
		}
	}

	int res = (H * W) - cnt - (len + 1);
	cout << res << endl; 

	return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        abc: [i32; 3],
    };
    let mut abc = abc;
    abc.sort();

    if abc[0] != abc[2] &&
        (abc[0] == abc[1] || abc[1] == abc[2]) {
        println!("Yes");
    }
    else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<cstring>
#define MAX 100005
using namespace std;

int main(){
	int n,m;
	int x[MAX],y[MAX];
	cin>>n>>m;
	int i=0;
	while(i<m){
		scanf("%d %d",&x[i],&y[i]);
		x[i]--;y[i]--;
		i++;
	}
	int box[2][MAX]={0};
	box[1][0]=1;
	for(i=0;i<m;i++){
		if(box[1][x[i]]==1){
			box[1][y[i]]=1;
			if(box[0][x[i]]==0) box[1][x[i]]=0;
		}
		box[0][y[i]]++;
		box[0][x[i]]--;
	}
	int ans=0;
	for(i=0;i<n;i++){
		if(box[1][i]==1){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
} 

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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 int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;


int main() {

	string s;
	cin >> s;
	if (s == "ARC")cout << "ABC" << endl;
	else cout << "ARC" << endl;
}


Measured memory_bytes: 3568
#include<stdio.h>

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    double ans = 0.0;
    for(int i=1; i<=n; i++){
        double buf = 1.0/n;
        int x = i;
        while(x < k){
            x*=2;
            buf = buf/2.0;
        }
        ans += buf;
    }
    printf("%.12f", ans);

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N, K;
const int MAX_N = 100010;
int root;
vector<int> edges[MAX_N];
int ans;

int dfs(int cur, int par)
{
  int m = 0;
  for (auto &val : edges[cur])
  {
    if (val != par)
    {
      m = max(m, dfs(val, cur));
    }
  }
  m++;
  if (cur == 1 or par == 1)
  {
    return 0;
  }
  if (m < K)
  {
    return m;
  }
  ans++;
  return 0;
}
int main()
{
  cin >> N >> K;
  cin >> root;
  for (int i = 1; i < N; i++)
  {
    int a;
    cin >> a;
    edges[a].push_back(i + 1);
    edges[i + 1].push_back(a);
  }
  dfs(1, 0);
  if (root != 1)
  {
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  	cin>>n;
   vector<int> vec(n);
  for(int i=0;i<n;i++){
   cin>>vec.at(i);
  }
  
  sort(vec.begin(),vec.end());

  int sum=1;
  for(int j=1;j<n;j++){
    if(vec.at(j-1)<vec.at(j)){
       sum+=1;
       }
    else{
      sum+=0;
    }
       }
       cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    string S;
    cin>>S;
    bool ok=true;

    rep(i,1,S.size()+1){
        if((i%2)==1){
            if(S[i-1]=='L'){
                ok=false;
            }
        }
        else {
            if(S[i-1]=='R'){
                ok=false;
            }
        }
    }

    if(ok){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

int main() {

    string r="qwertasdfgzxcvb", l="yuiophjklnm";
    string str;

    sort(r.begin(), r.end());
    sort(l.begin(), l.end());

    int rr=0, ll=0;
    int alp[30];
    rep(i, r.size()+l.size()) {
        if ( i == r[rr]-'a') {
            alp[i] = 1;
            rr++;
        }
        else {
            alp[i] = -1;
            ll++;
        }
    }

    while (true) {

        cin >> str;
        if (str == "#") break;

        int cnt=0, prev=alp[str[0]-'a'];
        for (int i=1; i<str.size(); ++i) {
            if (prev != alp[str[i]-'a']) {
                prev = alp[str[i]-'a'];
                cnt++;
            }
        }

        cout << cnt << endl;

    }

    return 0;
}

Measured memory_bytes: 3168
#include<iostream>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	if(x%y==0)
		cout<<-1<<endl;
	else
	{
		for(long long i=x+x;i<=1e18;i+=x)
		if(i%y!=0)
		{
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    int d = N % 10;
    switch (d) {
        case 3:
            print("bon");
            return 0;
        case 0:
        case 1:
        case 6:
        case 8:
            print("pon");
            return 0;
        default:
            break;
    }

    print("hon");
    
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <climits>
#include <iomanip>
#include <string.h>
#include <algorithm>
#include <functional>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define clr(a,b) memset((a),b,sizeof(a))
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define sz(a) int((a).size())
#define pb push_back

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N = (int)2e5+77;

ll n,m,k,x,y;
ll a[N];

int main() {
    fast;
    cin >> n >> k;
    forn(i, n) cin >> a[i];
    ll dp[5555] = {0};
    dp[0] = 1;
    for (int j = 0; j < n; j++) {
        for (int i = 5555; i >= 0; i--) {
            if (i-a[j]>=0 and  dp[i - a[j]] != 0) dp[i] = dp[i] + dp[i - a[j]];
        }
    }
    ll ans = 0;
    forn(i, 5001) {
        if (k == (i & 1))
            ans += dp[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
 
int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a >= b && a >= c) printf("%d\n", b + c);
	else if (b >= a && b >= c) printf("%d\n", a + c);
	else if (c >= a && c >= b) printf("%d\n", a + b);
	return 0;
}

Measured memory_bytes: 128
def generate(x):
    for i in [3, 5, 7]:
        yield x * 10 + i

n = int(input())
nums = [3, 5, 7]
ans = 0
num = 0
p = 0
while num < n:
    for res in generate(nums[p]):
        nums.append(res)
        num = res
        if res <= n and set(list(str(res))) == set(list(str(357))):
            ans += 1
    p += 1

print(ans)

Measured memory_bytes: 4260
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

int main() {
	ll n,k;
	ll res = 0;
	int ishave[101] = { 0 };
	scanf("%lld", &n);
	scanf("%lld", &k);
	ll d = 0;
	ll temp;
	FOR(i, 1, k) {
		scanf("%lld", &d);
		FOR(j, 1, d) {
			scanf("%lld", &temp);
			ishave[temp] = 1;
		}
	}
	FOR(i, 1, n) {
		if (ishave[i] == 0) {
			res++;
		}
	}
	printf("%lld\n", res);
	return(0);
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int A, B, C, D;
  ci(A, B, C, D);
  if(A + B > C + D){
    co("Left");
  }
  else if(A + B == C + D){
    co("Balanced");
  }
  else{
    co("Right");
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  double a,b;
  cin >> a >> b;
  printf("%lf",a/b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a==b)
	 printf("Draw"); 
	else if(a==1)
	 printf("Alice");
	else if(b==1)
	 printf("Bob");
	else if(a>b)
	 printf("Alice");
	else
	 printf("Bob");
	
	 
	 return 0; 
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	int D1,D2,M1,M2;
	cin >> M1 >> D1 >> M2 >> D2;
        if(D2==1){
		cout << "1" << endl;
	} else {
		cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
wvs = []
for _ in range(N):
    wvs.append(list(map(int, input().split())))


def chmax(x, w1, w2, diff):
    if dp[x][w1] < dp[x-1][w2]+diff:
        dp[x][w1] = dp[x-1][w2]+diff
        return True
    return False


dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
    for sum_w in range(W+1):
        # 貰うDP
        if sum_w-wvs[i][0] >= 0:
            # 品物を選んだ場合(選ぶために必要な重さを減らした状態に価値を追加した状態と比較)
            chmax(i+1, sum_w, sum_w-wvs[i][0], wvs[i][1])
        chmax(i+1, sum_w, sum_w, 0)  # 品物を選んでない場合
print(max(dp[N]))


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

int main() {
  int S;
  cin >> S;
  int h = S / 3600;
  int m = (S - h * 3600) / 60;
  int s = S - h * 3600 - m * 60;
  cout << h << ":" << m << ":" << s << endl;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
   string s;
   cin>>s;
   int cnt=0;
   for (int i = 0; i < s.size()/2; i++)
   {
       if(s[i]!=s[s.size()-1-i]) cnt++;
   }
   cout<<cnt<<endl;
   
    return 0;
}

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

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,0,n) cin >> a[i];
	vsort(a);
	deque<ll> deq;
	rep(i,0,n) deq.push_back(a[i]);
	deque<ll> b;
	b.push_back(deq.front());
	deq.pop_front();
	ll i = 0;
	while( deq.size() > 0 ){
		if( deq.size() >= 2 ){
			if( i % 2 == 0 ){
				ll fr = deq.back();
				deq.pop_back();
				ll ba = deq.back();
				deq.pop_back();
				b.push_back( ba );
				b.push_front(fr );
			}
			else{
				ll fr = deq.front();
				deq.pop_front();
				ll ba = deq.front();
				deq.pop_front();
				b.push_back( ba );
				b.push_front(fr );
			}
		}
		else{
			if( i % 2 == 0 ){
				ll fr = deq.back();
				deq.pop_back();
				b.push_front( fr );
			}
			else{
				ll fr = deq.front();
				deq.pop_front();
				b.push_front( fr);
			}
		}
		i++;
	}
	ll cnt = 0;
	ll bef = b.front();
	b.pop_front();
	while( b.size() > 0 ){
		cnt += abs( bef - b.front() );
		bef = b.front();
		b.pop_front();
	}
	ll ans1 = cnt;
	rep(i,0,n) deq.push_back(a[i]);
	b.push_front(deq.back());
	deq.pop_back();
	
	i = 0;
	while( deq.size() > 0 ){
		if( deq.size() >= 2 ){
			if( i % 2 ){
				ll fr = deq.back();
				deq.pop_back();
				ll ba = deq.back();
				deq.pop_back();
				b.push_back( ba );
				b.push_front(fr );
			}
			else{
				ll fr = deq.front();
				deq.pop_front();
				ll ba = deq.front();
				deq.pop_front();
				b.push_back( ba );
				b.push_front(fr );
			}
		}
		else{
			if( i % 2 ){
				ll fr = deq.back();
				deq.pop_back();
				b.push_front( fr );
			}
			else{
				ll fr = deq.front();
				deq.pop_front();
				b.push_front( fr);
			}
		}
		i++;
	}
	cnt = 0;
	bef = b.front();
	b.pop_front();
	while( b.size() > 0 ){
		cnt += abs( bef - b.front() );
		bef = b.front();
		b.pop_front();
	}
	
	cout << max ( cnt , ans1 ) << endl;

	ret 0;
}


Measured memory_bytes: 1920
#include <iostream>

using namespace std;

int main()
{
  int n; cin >> n;
  int a;
  bool approved = true;
  for (int i = 0; i < n; i++)
  {
    cin >> a;
    if (a % 2 == 0)
    {
      if (a % 3 != 0 && a % 5 != 0)
      {
        approved = false;
        break;
      }
    }
  }
  if (approved) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
int n,mx;
int x[1000000];
bool check(int n)
{
	for (int i=2;i*i<=n;i++)
		if (n%i==0) return false;
	return true;
}
int main()
{
	cin>>n;
	int t=1,a=2,b=3,c=5,d=6,e=7,f=10;
	int a1=a,b1=b,c1=c,d1=d,e1=e,f1=f;
	x[0]=1;
	for (int i=1; ;i++)
	{
		if (a*a1<=1000) {a*=a1; x[t]=a; t++;}
		if (b*b1<=1000) {b*=b1; x[t]=b; t++;}
		if (c*c1<=1000) {c*=c1; x[t]=c; t++;}
		if (d*d1<=1000) {d*=d1; x[t]=d; t++;}
		if (e*e1<=1000) {e*=e1; x[t]=e; t++;}
		if (f*f1<=1000) {f*=f1; x[t]=f; t++;}
		if (a*a1>1000 && b*b1>1000 && c*c1>1000 && d*d1>1000 && e*e1>1000 && f*f1>1000)
			break;
	}
	for (int i=11;i<=1000;i++)
	{
		//if (check(i))
		//{
			int k=i;
			int k1=k;
			for (int j=1; ;j++)
			{
				if (k*k1<=1000) {k*=k1; x[t]=k; t++;}
				else break;
			}
		//}
	}
	sort(x,x+t);
	/*for (int i=0;i<t;i++)
		cout<<x[i]<<" ";
	cout<<endl;*/
	for (int i=0;i<t;i++)
		if (x[i+1]>n) {cout<<x[i]; break;}
		else if (x[i]==n) {cout<<x[i]; break;}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  int p,y;
  pair<pair<int, int>, int> a[m];
  rep(i,m){
    cin >> p >> y;
    a[i]=mp(mp(p,y),i);
  }
  sort(a,a+m);
  pair<int, pair<int, int> > b[m];
  b[0]=mp(a[0].second,mp(a[0].first.first,1));
  //  printf("%06d%06d\n", a[0].first.first,1);
  int j=1;
  rep1(i,m-1){
    if(a[i].first.first==a[i-1].first.first){
      j++;
      b[i]=mp(a[i].second,mp(a[i].first.first,j));
      //      printf("%06d%06d\n", a[i].first.first,j);     
    }
    else{
      j=1;
      b[i]=mp(a[i].second,mp(a[i].first.first,j));
      //      printf("%06d%06d\n", a[i].first,j);
    }
  }
  sort(b,b+m);
  rep(i,m){
    printf("%06d%06d\n", b[i].second.first,b[i].second.second); 

  }
    
  return 0;
    

}


Measured memory_bytes: 3840
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int X,A,B;
	while(~scanf("%d%d%d",&X,&A,&B)){
		if(B <= A) printf("delicious\n");
		else if(X + A >= B) printf("safe\n");
		else printf("dangerous\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846264338
#define int long long
#define double long double
struct RMQ{
  int n;
  vector<int> dat;
  const int def=0;
  RMQ(){}
  RMQ(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,def);
  }
  void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return def;
    if(a<=l&&r<=b) return dat[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
  int query(int k){
    return dat[k+n-1];
  }
};

typedef pair<int,int> P;
signed main(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  
  int n;
  cin>>n;
  P p[n];
  for(int i=0;i<n;i++) cin>>p[i].first>>p[i].second;
  if(x1>x2){
    swap(x1,x2);
    swap(y1,y2);
  }
  if(y1>y2){
    for(int i=0;i<n;i++) p[i].second*=-1;
    y1*=-1;
    y2*=-1;
  }
  sort(p,p+n);
  vector<int> cx(n+2,x1),cy((n+2),y1);
  int cnx=0,cny=0;
  auto add_vx = [&](int x){
    cx[cnx++]=x;
  };
  auto add_vy = [&](int y){
    cy[cny++]=y;
    /*
    if(y1>y2) cy[cny++]=y-1;
    else cy[cny++]=y-1;
    */
  };

  add_vx(x1);
  add_vy(y1);
  add_vx(x2);
  add_vy(y2);
  
  
  for(int i=0;i<n;i++){
    add_vx(p[i].first);
    add_vy(p[i].second);
  }
  
  sort(cx.begin(),cx.end());
  cx.erase(unique(cx.begin(),cx.end()),cx.end());
  sort(cy.begin(),cy.end());
  cy.erase(unique(cy.begin(),cy.end()),cy.end());
  
  map<int,int> mx,my;
  for(int i=0;i<(int)cx.size();i++) mx[cx[i]]=i;
  for(int i=0;i<(int)cy.size();i++) my[cy[i]]=i;
  map<int,int> px,py;
  for(int i=0;i<n;i++){
    px[p[i].second]=p[i].first;
    py[p[i].first]=p[i].second;
  }
  RMQ rmq(cy.size()+100);
  double base=(abs(x1-x2)+abs(y1-y2))*100;
  double diff=5*PI-20,diff2=10*PI-20;
  double  ans=1e15;
  for(int i=mx[x1];i<=mx[x2];i++){
    int x=cx[i];
    if(!py.count(x)) continue;
    int y=py[x];
    int t=rmq.query(my[y1],my[y]);
    rmq.update(my[y],t-1);
  }
  int k=-rmq.query(my[y1],my[y2]+1);
  //cout<<k<<endl;
  if(k==min(abs(x2-x1),abs(y2-y1))+1) ans=base+diff*(k-1)+diff2;
  else ans=base+diff*k;
  printf("%.15Lf\n",ans);
  return 0;
}


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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> X(N);
    for (int64_t& x : X) {
        cin >> x;
    }

    int64_t ans = LLONG_MAX;
    for (int64_t i = 1; i <= 100; i++) {
        int64_t curr_value = 0;
        for (int64_t x : X) {
            curr_value += (x - i) * (x - i);
        }
        ans = min(ans, curr_value);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
 int d,i,a,s,b;
 while(scanf("%d", &d)!= EOF){
     s=0;
     b=(600/d);
     for(i=1;i<b;i++)
  {

      a=d*(i*d*i*d);
      s+=a;
  }
printf("%d\n",s);
if(d==0){
break;}
}
return 0;
}


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

class UnionFind {
public:
    // parent node index if not root index
    // minus size of the tree if root index
    std::vector<int> data;

    UnionFind( int n ) {
        data.resize( n, -1 );
    }

    int find( int x ) {
        if ( data[x] < 0 ) {
            return x;
        } else {
            int r = find( data[x] );
            data[x] = r;
            return r;
        }
    }

    void unite( int x, int y ) {
        int r = find( x );
        int s = find( y );
        if ( r != s ) {
            data[r] += data[s];
            data[s] = r;
        }
    }

    int count( int x ) {
        return -data[find(x)];
    }
};

int main() {
    int NMAX = 1e5;
    int N;
    cin >> N;
    UnionFind uf(2 * NMAX);
    int x,y;
    for ( int i = 0; i < N; i++ ) {
        cin >> x >> y;
        x--, y--;
        uf.unite(x,y+NMAX);
    }

    map<int, int> nx, ny;
    for ( int i = 0; i < 2 * NMAX; i++ ) {
        int r = uf.find(i);
        int c = uf.count(r);
        if ( c <= 1 ) continue;
        if ( i < NMAX ) {
            nx[r]++;
        } else {
            ny[r]++;
        }
    }

    ll dots = 0;
    for( auto q : nx ) {
        dots += (ll)q.second * ny[q.first];
    }
    ll ans = dots - N;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 50;
ll k, a[60];

int main() {
	cin>>k;
	
	cout<<N<<endl;
	ll t = k / N;
	ll m = k % N;
	for(int i=0;i<N;i++)a[i] = i + t;

	for(int i=0;i<m;i++)a[i] += (N - m + 1);
	for(int i=m;i<N;i++)a[i] -= m;
	
	for(int i=0;i<N;i++)
		printf("%lld%c",a[i],i==49?'\n':' ');
		
	return 0;
}

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

int main() {
    string s;cin>>s;
    int n = s.size();
    sort(s.begin(),s.end());
    rep(i,n-1)if(s[i+1]==s[i]){
        cout<<"no"<<endl;
        return 0;
    }
    cout<<"yes"<<endl;
	return 0;
}

Measured memory_bytes: 3588
n = int(input())

xyh = [list(map(int, input().split())) for _ in range(n)]

xyh.sort(key=lambda x:x[2], reverse=True)

for i in range(101):
    meta = False
    for j in range(101):
        H = 0
        flag = True
        for x, y, h in xyh:
            #print(x, y, h, H)
            if H == 0:
                H = abs(x - i) + abs(y - j) + h
            elif max(H - abs(x - i) - abs(y - j), 0) != h:
                flag = False
                break
        if flag:
            print(i, j, H)
            meta = True
            break
    if meta:
        break


Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int h[5];
  while (cin >> h[0], h[0]) {
    for (int i = 1; i < 5; i++) {
      cin >> h[i];
    }
    map<int, int> mp;
    for (int i = 0; i < 5; i++) {
      mp[h[i]]++;
    }
    if (mp.size() == 1 || mp.size() == 3) {
      for (int i = 0; i < 5; i++) {
        cout << 3 << endl;
      }
    } else {
      auto it = mp.begin();
      int a = it->first, b = (++it)->first;
      if (a > b) swap(a, b);
      if (a == 1 && b == 3) swap(a, b);
      for (int i = 0; i < 5; i++) {
        cout << (h[i] == a ? 1 : 2) << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3072
N = int(input())
L_list = list(map(int, input().split()))
L_list.sort()

count = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if(L_list[i] != L_list[j] != L_list[k]):
                if(L_list[i] + L_list[j] > L_list[k]):
                    count += 1

print(count)

Measured memory_bytes: 9052
import time as ti


class MyQueue(object):
    """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 50010
        self.queue = [0] * self.length
        # counter = 0
        # while counter < self.length:
        #     self.queue.append(Process())
        #     counter += 1
        self.head = 0
        self.tail = 0

    # def enqueue(self, name, time):
    def enqueue(self, process):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        self.queue[self.tail] = process
        # self.queue[self.tail].name = name
        # self.queue[self.tail].time = time
        self.tail = (self.tail + 1) % self.length

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        # self.queue[self.head].name = ""
        # self.queue[self.head].time = 0
        self.queue[self.head] = 0
        self.head = (self.head + 1) % self.length

    def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

    def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False


class Process(object):
    """process class
    """

    def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

    def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time


def time_forward(my_queue, interval, current_time,):
    """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """

    value = my_queue.queue[my_queue.head].forward_time(interval)
    if value <= 0:
        current_time += (interval + value)
        print my_queue.queue[my_queue.head].name, current_time
        my_queue.dequeue()

    elif value > 0:
        current_time += interval
        name, time = my_queue.queue[my_queue.head].name, \
                     my_queue.queue[my_queue.head].time
        my_queue.enqueue(my_queue.queue[my_queue.head])
        my_queue.dequeue()

    return current_time


my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
    name, time = raw_input().split()

    my_queue.enqueue(Process(name, int(time)))
    counter += 1

# end_time_list = []
current_time = 0
while not my_queue.is_empty():
    current_time = time_forward(my_queue, q, current_time)

Measured memory_bytes: 26484
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

cnt = 0
for i in range(n-1):
    y = a[i] + a[i+1] - x
    if y > 0:
        a[i+1] = max(0, a[i+1]-y)
        cnt += y
print(cnt)

Measured memory_bytes: 14132
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#define mod 1000007
using namespace std;                       
typedef long long ll;
char a[300];
 int main(){
 	 int n,t;
 	   cin>>n;
 	    cin>>a;
 	     t=strlen(a);
 	     if(t<=n)
 	     cout<<a<<endl;
 	      if(t>n){
 	      	 for(int i=0;i<n;i++)
 	      	    cout<<a[i];
 	      	    cout<<"...";
		   }
	}
 	   

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

int main() {
     int N;
	 string S;
	 cin >> N >> S;
	 int count=0;
	 for (int i=0; i<S.length()-2; i++){
	     if (S.substr(i,3)=="ABC") count++;
	 }
	 cout << count << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

ll X[4], N;

int main() {
    for(int i = 0; i < 4; i++) scanf("%lld", &X[i]);
    scanf("%lld", &N);
    N *= 4;
    for(int i = 1; i < 4; i++) X[i] = min(X[i], X[i - 1] * 2);
    ll ans = N / 8 * X[3], nw = 0, nwa = N % 8 ? 1e18 : 0;
    N %= 8;
    for(int i = 2; i >= 0; i--)
        if(N & (1 << i)) ans += X[i];
    printf("%lld\n", ans + nw);
    return 0;
}

Measured memory_bytes: 128