akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int x[20],y[20];
int N;
double res;
double visited[20];
int dir[20];

void tansaku(int f, int cur) {
    dir[cur] = f;
    if(cur >= N-1) {
        double tmp=0;
        //printf("%d ", dir[0]);
        REP(i, 0, N-1) {
            //printf("->%d ", dir[i+1]);
            int p = dir[i+1], q = dir[i];
            double dx = x[p]-x[q], dy = y[p]-y[q];
            res += sqrt(dx*dx + dy*dy);
            tmp += sqrt(dx*dx+dy*dy);
        }
        //printf(" : %lf\n", tmp);
        return ;
    }
    REP(t, 0, N) if(!visited[t]) {
        visited[t] = true;
        tansaku(t, cur + 1);
        visited[t] = false;
    }
}

void solve(){
    REP(i, 0, N) { visited[i] = true; tansaku(i, 0); visited[i] = false;}
    REP(i, 1, N+1) res /= (double)i;
}

int main()
{
    scanf("%d", &N);
    REP(i, 0, N) scanf("%d %d", &x[i], &y[i]);
    solve();
    printf("%.10lf\n", res);
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
#ifdef DEBUG
	printf("");
#endif

	int a, b, c;
	int tmp;

	scanf("%d %d %d", &a, &b, &c);
	if (a+b!=c) {
		tmp = abs(a - b) - c;
	}
	else {
		tmp = 0;
	}
	if (tmp == 0) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}


	return 0;
}

Measured memory_bytes: 128
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
	for j in range(1,105):
		for k in range(1,105):
			v = i*i+j*j+k*k+i*j+j*k+k*i;
			if v<10050:
				ans[v]+=1
for i in range(n):
	print(ans[i+1])

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
// typedef pair<int, P> PP;
// typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

typedef pair<char, char> P;

int n, q;
string str;
vector<P> vec;
int ni(int now){
  rep(i,q){
    if(str[now] != vec[i].fi)continue;
    if(vec[i].se == 'L')now--;
    else now++;
    if(now < 0)return -1;
    if(n <= now)return 1;
  }
  return 0;
}

int solve1(){
  int l = -1, r = n;
  while(l+1 < r){
    int mid = (l+r)/2;
    if(ni(mid) == -1)l = mid;
    else r = mid;
    // cout << l << " " << r << endl;
  }
  return l;
}
int solve2(){
  int l = -1, r = n;
  while(l+1 < r){
    int mid = (l+r)/2;
    if(ni(mid) == 1)r = mid;
    else l = mid;
  }
  return r;
}

signed main(){
  cin >> n >> q >> str;
  rep(i,q){
    char x, y;cin >> x >> y;
    vec.push_back(P(x, y));
  }
  int l = solve1();
  int r = solve2();
  // cout << l << " " << r << endl;
  if(l >= r)cout << 0 << endl;
  else cout << r-l-1 << endl;
  // rep(i,n)cout << ni(i) << endl;
  return 0;
}





Measured memory_bytes: 1024
n = int(input())
points = []
for i in range(n):
    x, y, h = map(int, input().split())
    points.append((x, y, h))
points.sort(key=lambda x:x[2], reverse=True)


def f(points):
    for x in range(0, 101):
        for y in range(0, 101):
            p = points[0]
            h = abs(x - p[0]) + abs(y - p[1]) + p[2]
            same = True
            for i in range(1, len(points)):
                p = points[i]
                h_p = max(0, h - abs(x - p[0]) - abs(y - p[1]))
                if h_p != p[2]:
                    same = False
                    break
            if same:
                return x, y, h
    return -1,-1,-1


ans = f(points)
print("{} {} {}".format(ans[0], ans[1], ans[2]))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

ll num[55][2],point[55][2];

int main(void)
{
    ll m,n,i,j,k=1,d,sum=0;
    string s,s1;
    cin>>s>>s1;
    for(i=0;i<s1.size();i++)
        cout<<s[i]<<s1[i];
    if(s.size()!=s1.size())
        cout<<s[s.size()-1];

    return 0;
}


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

int main() {

	int n, t;
	cin >> n >> t;

	long long int a[100000];
	rep(i, 0, n) cin >> a[i];
	int cnt = 0;
	long long int p = 0;
	long long int max = 0;
	rep(i, 0, n) {
		if (i == 0) p = a[i];
		if (p > a[i]) p = a[i];
		else if (p < a[i]) {
			long long int tmp = a[i] - p;
			if (max == tmp) cnt++;
			else if(max < tmp){
				cnt = 1;
				max = tmp;
			}
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<functional>
typedef long long ll;
int main() {
	int n = 0,num = 0,ans = 0;
	std::vector<int> save = {};
	std::map<int, int> m = {};
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> num;
		if (m[num] == 0) {
			save.push_back(num);
		}
		m[num]++;
	}

	for (int i = 0; i < save.size();i++) {
		if (m[save[i]] % 2 == 1){
			ans++;
		}
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 5368
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int p=0;
    for(int i=0; i<k; i++)
{
        p=p+arr[i];

}
    cout<<p<<endl;



}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int fact[10] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
int cantor(int a[],int n) {
    int res = 0;
    for(int i = 0;i < n; ++i) {
        int cnt = 0;
        for(int j = i + 1;j < n; ++j) if(a[j] < a[i]) cnt  ++;
        res += cnt * fact[n - i - 1];
    }
    return res + 1;
}
int main() {
    int n,a,b,s[N];
    cin >> n;
    for(int i = 0;i < n; ++i) cin >> s[i];
    a = cantor(s,n);
    for(int i = 0;i < n; ++i) cin >> s[i];
    b = cantor(s,n);
    cout << abs(a - b);
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ?	trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }
int main() {
  int a, b, c, d, e, k;	cin>>a>>b>>c>>d>>e>>k;
  TorF(e-a>k, ":(", "Yay!");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    int a,b,c;
    cin >> a >> b >> c;
    int cnt = 0;
    for(int i = 100;i >= 0;i--){
        if(a%i == 0 && b%i == 0){
            cnt++;
        }
        if(cnt == c){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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; }

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

    ll L, R; cin >> L >> R;
    if (R-L >= 2019) {
        cout  << 0 << '\n';
        return 0;
    }
    ll min = 2019;
    FOR (i, L%2019, (R-L) + (L % 2019)) {
        FOR (j, i+1, (R-L) + (L % 2019) + 1) {
            if ((i*j) % 2019 < min) min = (i*j) % 2019;
            if (min == 0) {
                cout  << 0 << '\n';
                return 0;
            }
        }
    }
    cout << min << '\n';
    return 0;
}



Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
MOD=10 ** 9 + 7
n, a, b = MI()

ans = (pow(2, n, MOD) - 1) % MOD
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
ans -= combination(n, a)
ans -= combination(n, b)
print(ans % MOD)


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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)


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

    if(s=="SAT") ANS(1);
    if(s=="SUN") ANS(7);
    if(s=="MON") ANS(6);
    if(s=="TUE") ANS(5);
    if(s=="WED") ANS(4);
    if(s=="THU") ANS(3);
    if(s=="FRI") ANS(2);
    return 0;
}


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

typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define precise(x) cout<<fixed<<setprecision(12)<<x
#define test cout<<"#";

const ll INF = 1e18L + 5;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	vector<double> v(n);
	for(ll x = 0; x < n; x++)
		cin>>v[x];
	double ans[n+1][n+1];
	ans[0][0] = 1;
	for(ll x = 1; x <= n; x++)
		ans[0][x] = 0;
	for(ll x = 1; x <= n; x++)
		ans[x][0] = 1;
	for(ll x = 1; x <= n; x++)
	{
		for(ll y = 1; y<=n; y++)
		{
			ans[x][y] = ans[x-1][y-1]*v[x-1] + ans[x-1][y]*(1 - v[x-1]);
		}
	}
	precise(ans[n][(n+1)/2]);
}

Measured memory_bytes: 70656
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int paper[12][12] = {0}, x, y, size, i, j, white = 0, max = 0;
	
	while (scanf("%d,%d,%d", &x, &y, &size) != EOF){
		switch (size){
		 case 1:
		 	for (i = x - 1; i <= x + 1; i++){
				for (j = y - 1; j <= y + 1; j++){
					if (i >= 0 && j >= 0 && abs(x - i) + abs(y - j) <= 1){
						paper[i][j]++;
					}
				}
		 	}
			break;
			
		 case 2:
		 	for (i = x - 1; i <= x + 1; i++){
				for (j = y - 1; j <= y + 1; j++){
					if (i >= 0 && j >= 0){
						paper[i][j]++;
					}
				}
		 	}
			break;
		
		 case 3:
		 	for (i = x - 2; i <= x + 2; i++){
				for (j = y - 2; j <= y + 2; j++){
					if (i >= 0 && j >= 0 && abs(x - i) + abs(y - j) <= 2){
						paper[i][j]++;
					}
				}
		 	}
			break;
			
		}
	}
	
	for (i = 0; i < 10; i++){		
		for (j = 0; j < 10; j++){
			if (paper[i][j] == 0){
				white++;
			}
			if (max < paper[i][j]){
				max = paper[i][j];
			}
		}		
	}
	
	printf("%d\n%d\n", white, max);
	
	return (0);
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var n = ReadLine().Split().Select(int.Parse).ToArray();
		var x = n[0];
		var b = n[2] - n[1];
		if(b <= 0)
			WriteLine("delicious");
		else if(b <= x)
			WriteLine("safe");
		else
			WriteLine("dangerous");
	}
}


Measured memory_bytes: 18880
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
using P = pair<int, int>;
int main(){
    int x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    int h=y2-y1;
    int w=x2-x1;
    cout<<x2-h<<" "<<y2+w<<" "<<x1-h<<" "<<y1+w<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int x, y;
    cin >> x >> y;
    for (int i=0; i<=x; i++) {
        if (i*2+(x-i)*4 == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<algorithm>
#include<iostream>

using namespace std;

int div(int N){
  if( N % 2 == 1) return 0;
  else return div(N/2) + 1;
}

int main(){

  int N,a,b,c=0; cin >> N;
  for (int i=1; i < N+1; i++) {
     a = div(i);
     if(b < a){
        b = a; c = i;
      }
   }
  if(N ==1 ) cout << 1 << endl;
  else cout << c  << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

int main() {
  int X,N;
  cin >> X >> N;
  int p[N];
  for(int i=0;i<N;i++){
    cin >> p[i];
  }
  int kiroku;
  if(N==0){
    cout << X;
  }
  else{
    vector<int> v;
    for(int i=0;i<=101;i++){
      v.push_back(i);
    }
    for(int i=0;i<N;i++){
      for(int j=0;j<v.size();j++){
        if(v[j]==p[i]){
          v.erase(v.begin()+j);
        }
      }
    }
    //sort(v.begin(), v.end());
    int min=100;
    /*for(int i=0;i<v.size();i++){
      cout << v[i] << " ";
    }
    cout << endl;*/
    for(int i=0;i<v.size();i++){
      if(min>abs(X-v[i])){
        min=abs(X-v[i]);
        kiroku=v[i];
        //cout << kiroku << " ";
      }
    }
    cout << kiroku;
  }
  cout << endl;
  return 0;
}


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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	int N; cin >> N;
	vector<ll> A(N);
	for(int i = 0; i < N; ++i) cin >> A[i];
	ll M = 0;
	for(int i = 2; i < N; ++i) M ^= A[i];
	ll S = A[0]+A[1];
	corner(S<M,-1);
	corner((S-M)%2,-1);
	ll X = (S-M)/2, Y = X;
	corner(X>A[0],-1);
	S -= X+Y;
	for(ll i = 40; 0 <= i; --i) {
		if(!((1LL<<i) & S)) continue;
		corner((1LL<<i) & X,-1);
		if(X + (1LL<<i) <= A[0]) {
			X += (1LL<<i);
		}
		else {
			Y += (1LL<<i);
		}
	}
	corner(X==0,-1);
	cout << A[0]-X << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long  int lli;


int main()
{
	lli n;
	cin>>n;

	lli k;
	cin>>k;

	vector<lli> h(n);

	for(lli i=0;i<n;i++) 
		cin>>h[i];

	vector<lli> cost(n, INT_MAX);
	cost[0] = 0;

	for(lli i=1;i<n;i++)
	{
		for(lli j=1;j<=k && i - j >= 0;j++)
		{
			cost[i] = min(cost[i], cost[i-j] + abs(h[i-j] - h[i]) );
		}
	}
	
	cout<<cost[n-1]<<endl;
}

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

using namespace std;

/*
再帰関数での全探索
bit全探索(2^n通り)
*/

void many_equals();

void train_ticket();

void all_green();

int main()
{
  //many_equals();
  //train_ticket();
  all_green();

}


void many_equals()
{
  string S;
  cin >> S;
  vector<int> a(S.size());

  for (int i = 0; i < S.size(); ++i)
  {
    a[i] = S[i] - '0';
  }

  cout << (1 << (S.size() - 1)) << "\n";;

  long long int n_sum = 0;
  for (int i = 0; i < 1 << (S.size() - 1); ++i)
  {
    //cout << i << "\n";
    long long int tmp = a[0];
    for (int p = 0; p < S.size() - 1; ++p)
    {
      //p left shift先にあれば
      if (i & 1 << p)
      {
        n_sum += tmp;
        tmp = a[p + 1];
      }
      else
      {
        tmp = tmp * 10 + a[p + 1];
      }
    }
    n_sum += tmp;
  }

  cout << n_sum << "\n";
}

void train_ticket()
{
  string abcd;
  cin >> abcd;
  vector<int> a(abcd.size());
  for (int i = 0; i < abcd.size(); ++i)
  {
    a[i] = abcd[i] - '0';
  }

  vector<char> sign(3);

  for (int i = 0; i < 1 << (abcd.size() - 1); ++i)
  {
    int v_sum = a[0];
    for (int j = 0; j < abcd.size() - 1; ++j)
    {
      if (i & 1 << j)
      {
        v_sum += a[j + 1];
        sign[j] = '+';
      }
      else
      {
        v_sum -= a[j + 1];
        sign[j] = '-';
      }
    }
    //iの位置は+,それ以外は-を行う判定
    if (v_sum == 7)
    {
      for (int k = 0; k < 3; ++k)
      {
        cout << abcd[k] << sign[k];
      }
      cout << abcd[3] << "=7\n";

      return;
    }
  }
}

void all_green()
{
  int D, G;
  cin >> D >> G;
  vector<pair<int, int>> p_c(D);
  for (int i = 0; i < p_c.size(); ++i)
  {
    cin >> p_c[i].first >> p_c[i].second;
  }

  int ans = INT_MAX;
  for (int bit = 0; bit < (1 << p_c.size()); ++bit)
  {
    int s = 0, cnt = 0, rest_max = -1;
    for (int i = 0; i < p_c.size(); ++i)
    {
      if (bit & 1 << i)
      {
        s += 100 * (i + 1) * p_c[i].first + p_c[i].second;
        cnt += p_c[i].first;
      }
      else
      {
        rest_max = i;
      }
    }

    if (s < G)
    {
      int s1 = 100 * (rest_max + 1);
      // ピッタリの個数ずらし
      int need = (G - s - 1) / s1 + 1;
      if (need >= p_c[rest_max].first) continue;
      cnt += need;
    }
    ans = min(ans, cnt);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=3e3+5;
int dp[N][N],ssz,tsz;
string s,t;
vector< char > ans;
void rec(int i, int j) {
    if(!i||!j)
        return;
    //cout<<i<<" "<<j<<'\n';
    if(dp[i][j]>dp[i-1][j]&&dp[i][j]>dp[i][j-1]){
        ans.pb(s[i-1]);
        rec(i-1,j-1);
    }
    else{
        if(dp[i-1][j]==dp[i][j])
            rec(i-1,j);
        else
            rec(i,j-1);
    }
    return;
}
int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);

    cin>>s>>t;
    ssz=s.size(); tsz=t.size();

    memset(dp,-1,sizeof dp);
    for(int i=0;i<N;i++)
        dp[0][i]=dp[i][0]=0;

    for(int i=1;i<=ssz;i++){
        for(int j=1;j<=tsz;j++){
            if(s[i-1]==t[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

        }
    }
    rec(ssz,tsz);
    for(int i=ans.size()-1;i>=0;i--)
        cout<<ans[i];
    cout<<'\n';
    return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    int64_t n;
    cin >> n;

    string s;
    cin >> s;

    if (n % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }

    if (s.substr(0, n / 2) == s.substr(n / 2)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(),v.end());
    for (int i = 0; i < q; ++i) {
        int l, r;
        scanf("%d %d", &l, &r);
        cout << upper_bound(v.begin(),v.end(), r) - lower_bound(v.begin(),v.end(), l) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3428
N=int(input())
B=list(map(int,input().split()))

s=0
for i in range(0,N):
    if i==0:
        s=s+B[0]
    elif i!=N-1:
        s=s+min([B[i-1],B[i]])
    else:
        s=s+B[N-2]
print(s)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int A, B;
	cin >> A >> B;

	int kotae = -1e9;
	kotae = max(kotae, A + B);
	kotae = max(kotae, A - B);
	kotae = max(kotae, A * B);

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
// aarsh01rsh@gmail.com
// Aarsh Sharma
#include<bits/stdc++.h>
using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}
string to_string(char ch) {
  string s(1, ch);
  return '\'' + s + '\'';
}
string to_string(const char *s) {
  return to_string((string)s);
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define f(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long long int ll;
#define int ll
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
typedef vector<ll> vll;

const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 1e5 + 10;

int32_t main() {
  fast_io();

  int a, b; cin >> a >> b;
  int t = 1, ans = 0;
  while (t < b) {
    t += a-1;
    ans++;
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 256
import Data.List
main=interact $ f.map read.words.head.tail.lines
f x 
  | odds <= fours = "Yes"
  | odds == fours + 1  && twos ==0 = "Yes"
  | otherwise = "No"
  where odds = g 1 x + (g 3 x)
        twos = g 2 x
        fours = g 0 x
g::Int->[Int]->Int
g k x = length $ filter ((k==).flip mod 4) x

Measured memory_bytes: 12924
use proconio::{fastout, input};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {in_s: String};
    let mut nums = HashMap::new();
    let mut val = 0;
    let mut mul = 1;

    nums.insert(0, 1);

    for c in in_s.as_str().chars().rev() {
        let x: usize = c.to_string().parse().unwrap();

        val = (val + mul * x) % 2019;
        mul = (mul * 10) % 2019;

        if !nums.contains_key(&val) {
            nums.insert(val, 0);
        }

        nums.insert(val, nums[&val] + 1);
    }

    let mut count = 0;

    for (_, v) in &nums {
        if *v < 2 {
            continue;
        }

        count += *v * (*v - 1) / 2;
    }

    println!("{}", count);
}


Measured memory_bytes: 2568
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def main():
    N, A, B = map(int, input().split())
    if abs(A-B)%2==0:
        ret = abs(A-B)//2
    else:
        A, B = min(A, B), max(A, B)
        ret = min(B-(B-A+1)//2, N-(B-A-1)//2-A)
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

void rotate (string &s)
{
    s=s[s.size()-1]+s.substr(0,s.size()-1);
}

main()
{
    fast;
    int n,i;
    cin>>n;
    int a[n];
    ll ans=0;
    for (i=0;i<n;i++)
    {
        cin>>a[i];
        ans+=a[i]-1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let lines1 = lines.shift().split(/\s/).map((v) => v - 0);
    let N = lines1[0];
    let M = lines1[1];
    let Ks = new Array(M+1).fill(0);
    for (let n = 0; n < N; n++) {
        let ln = lines.shift().split(/\s/).map((v) => v - 0);
        let K = ln.shift();
        for (let m = 0; m < K; m++) {
            Ks[ln[m]] += 1;
        }
    }

    let ans = Ks.reduce((ac, value, index, array) => (value == N) ? ac + 1 : ac, 0);

    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21192
//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

//logx(a^n)=loga(a^n)/logx(a)
//logx(a*b)=logx(a)+logx(b)
//logx(y)=log(y)/log(x)

#define ordered_set tree<ll,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define putf push_front
#define gainb pop_back

#define gainf pop_front
#define len(x) (ll)x.size()

// 1/b%mod=b^(m-2)%mod
// (a>>x)&1==0

typedef double db;
typedef long long ll;

const ll ary=3e2+5;
const ll mod=1e9+7;
const ll inf=1e18;

using namespace std;
using namespace __gnu_pbds;
ll h,w,k,t[ary][ary];
char c[ary][ary];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>h>>w>>k;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>c[i][j];
		}
	}
	ll id=0;
	int li=1000;
	for(int i=1;i<=h;i++){
		ll q=0;
		for(int j=1;j<=w;j++){
			q+=(c[i][j]=='#');
		}
		if(!q){
			for(int j=1;j<=w;j++){
				t[i][j]=t[i-1][j];
			}
		}
		else{
			id++;
			ll ch=1;
			li=min(li,i);
			for(int j=1;j<=w;j++){
				t[i][j]=id;
				if(c[i][j]=='#'&&j!=w&&ch!=q){
					ch++;
					if(id<k){
						id++;
					}
				}
			}			
		}
	}
	for(int i=li-1;i>=1;i--){
		for(int j=1;j<=w;j++){
			t[i][j]=t[i+1][j];
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cout<<t[i][j]<<" ";
		}
		cout<<"\n";
	}
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
int main() {
	fast();
 
    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    ll n;
    cin >> n;
    ll a, b;
    cin >> a >> b;
    ll ans = xmodpow(2ll, n, MOD);
    ans = xmod(ans-1, MOD);
    ll A = 1;
    ll B = 1;
    for(ll i=1; i<=a; i++){
        A*=i;
        A%=MOD;
    }
    for(ll i=1; i<=b; i++){
        B*=i;
        B%=MOD;
    }
    A = xmodpow(A, MOD-2, MOD);
    B = xmodpow(B, MOD-2, MOD);
    for(ll i=n-a+1; i<=n; i++){
        A*=i;
        A%=MOD;
    }
    for(ll i=n-b+1; i<=n; i++){
        B*=i;
        B%=MOD;
    }
    A+=B;
    A%=MOD;
    ans = xmod(ans-A, MOD);
    out(ans);
}

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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    int t_p = 0, h_p = 0;

    for (int i = 0; i < n; i++) {
        string t, h;
        cin >> t >> h;
        
        if (t == h) {
            t_p++;
            h_p++;
        } else if (t < h) {
            h_p += 3;
        } else {
            t_p += 3;
        }
    }

    cout << t_p << ' ' << h_p << endl;
    return 0;

}



Measured memory_bytes: 3132
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int N;
    cin >> N;
    vector<int> B(N - 1);
    cin >> B;

    int ans = 0;
    REP(i, N - 2) {
        ans += min(B[i], B[i + 1]);
    }
    ans += B[0];
    ans += B[N - 2];

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

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main (int argc, char *argv[]) {
	map<string,vector<int> > dict;
	string word;
	int page_num;
	while (cin >> word >> page_num) {
		// New
		if (dict.count(word) == 0) {
			dict.insert(make_pair(word,vector<int>(1,page_num)));
		}
		// Add
		else {
			dict[word].push_back(page_num);
		}
	}
	map<string,vector<int> >::iterator it = dict.begin();
	while (it != dict.end()) {
		cout << it->first << endl;
		vector<int> sorted = it->second;
		sort(sorted.begin(), sorted.end());
		for(int i = 0; i < sorted.size(); ++i) {
			cout << sorted[i];
			if (i != sorted.size()-1) cout << " ";
		}
		cout << endl;
		it++;
	}
	return 0;
}

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




int main()
{
    int N, M, x, y, color, dist;
    std::scanf("%d", &N);
    std::scanf("%d", &M);
    for (int i = 0; i < M; i++) {
        std::scanf("%d %d", &x, &y);
        x = std::min(x, N-x+1);
        y = std::min(y, N-y+1);
        if (y > x) std::swap(x, y);
        color = (x % 3 == 0) ? 3 : x % 3;
        if (x == y) {
            std::printf("%d\n", color);
        } else {
            dist = N - ((x-1)* 2);
            if (y > x+dist-1 || y < x ) {
                ((y % 3) == 0) ? std::printf("%d\n", 3) : std::printf("%d\n", y%3 );
            } else {
                std::cout << color << std::endl;
            }
        }
    }
    return 0;
}



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

int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int>>jobs(m);//二重配列、m日後まで
  rep(i,n){
    int a,b;
    cin>>a>>b;
    if(a>m)continue;//m日後までに終わらなければ、対象外
    jobs[m-a].push_back(b);
    //jobs配列に期限までの余裕日数毎に分類し、報酬を入力
  }
  priority_queue<int>q;//プライオリティ・キューで報酬の最大値を出力
  ll ans=0;//long longなので注意
  for(int i=m-1;i>=0;--i){//後ろからチェックしていく
    for(int b:jobs[i]){//jobs配列から余裕日数毎に報酬を取り出す
      q.push(b);//プライオリティ・キューに入れていく
    }
    if (!q.empty()){//プライオリティ・キューが空になるまで
      ans+=q.top();//報酬の最大値を取り出す
      q.pop();//最大値を捨てる
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5632
X,N =map(int,input().split())
pb = list(map(int,input().split()))
p =[]
for i in range(0,102):
    p.append(i)
An = []
ab =[]
Answer =[]
for i in range(1,N+1):
    p.remove(pb[i-1])
for j in range(len(p)):
    An.append(p[j])
    ab.append(abs(p[j]-X))
abmi = ab[0]
for i in range(len(p)):
    if abmi > ab[i]:
        Answer = []
        Answer.append(An[i])
        abmi = ab[i]
    if abmi == ab[i]:
        Answer.append(An[i])
print(min(Answer))

Measured memory_bytes: 9240
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    String string = scanner.next();
    int countR = 0;
    int countB = 0;
    for (int i = 0; i < n; i++) {
      if (string.charAt(i) == 'R') {
        countR++;
      } else {
        countB++;
      }
    }
    if (countR > countB) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

}


Measured memory_bytes: 23380
#include<bits/stdc++.h>			//edit by thidailoc
using namespace std;			//team three wolves
typedef long long ll;
ll arr[1000000];
int main(){
//	freopen("locin.txt","r",stdin);
	ll n,c,k,head=0,prevv=0,ans=0;
	cin>>n>>c>>k;
	
	for(ll i=0;i<n;i++)scanf("%lld",&arr[i]);
	
	sort(arr,arr+n);
	
	for(ll i=0;i<n;i++){
		if(arr[i]-arr[prevv]>k or i-prevv+1>c){
		//	cout<<"pr"<<prevv<<"i"<<i<<" ";
			prevv=i;
			ans++;
		}
	}
	cout<<ans+1;
}

Measured memory_bytes: 1024
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    S = input()
    ans = 99999

    for i in range(0, len(S)-2):
        N = int(S[i:i+3])
        ans = min(ans, abs(N - 753))

    print(ans)

main()


Measured memory_bytes: 5068
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(){

    int a;string b;
    cin>>a>>b;
    int R=0;
    for(int i=0;i<a;i++){
        if(b[i]=='R')
        {R++;}
    }
    if(2*R>a){cout<<"Yes"
    <<endl;}
    else {cout << "No"<<endl;}



}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

dic = {}
ans = 0
# for t in A:
#     if t in dic.keys():
#         continue
#     tmp = A.count(t)
#     dic[t] = tmp
#     ans += tmp*(tmp-1)//2

for a in A:
    tmp = dic.get(a)
    if tmp == None:
        dic[a] = 1
    else:
        dic[a] = tmp + 1

for key in list(dic.keys()):
    tmp = dic.get(key)
    ans += tmp * (tmp - 1) // 2
    

for a in A:
    val = dic.get(a)
    print(ans-val+1)

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

int main(){
#define pii pair < int , int >
	vector < pii > ed; int N; cin >> N;
	if(N & 1){
		for(int i = 1 ; i < N ; ++i) ed.push_back(pii(i , N));
		--N;
	}
	for(int i = 1 ; N - i + 1 > i ; ++i)
		for(int j = i + 1 ; j < N - i + 1 ; ++j)
			if(j != i && j != N - i + 1){
				ed.push_back(pii(i , j));
				ed.push_back(pii(N - i + 1 , j));
			}
	cout << ed.size() << endl;
	for(auto t : ed) cout << t.first << ' ' << t.second << endl;
	return 0;
}

Measured memory_bytes: 384
/**
*    author:  y_takano
*    created: 22.06.2020 15:17:54
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

using namespace std;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  string s;
  int m, h;

  while (1)
  {
      cin >> s;
      if (s == "-")
      { 
          break;
      }
      
      cin >> m;
      REP(i, m)
      {
          cin >> h;
          s = s.substr(h) + s.substr(0, h);
      }
      cout << s << '\n';
  }

  return 0;
}


Measured memory_bytes: 3084
N,M = map(int,input().split())

list = [list(map(int,input().split())) for i in range(N) ]

list.sort()
sum = 0
cnt = 0

for A,B in list:
    if cnt + B >= M:
        sum += A*(M - cnt)
        cnt += M - cnt
        break
    sum += A*B
    cnt += B

print(sum)

Measured memory_bytes: 27760
import java.util.*; 
import java.lang.*; 


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                long X = scan.nextLong();
                long K = scan.nextLong();
                long D = scan.nextLong();              
                  
                if(X<=0){
                    long sho = -(X/D);
                    long amari = X%D+D;

                    if(sho>=K){
                        System.out.println(Math.abs(X+(K*D)));
                        System.exit(0);
                    }
                    
                    long Xhu = -(amari-D);
                    long Xsei = amari;
                    
                    if((K-sho)%2==0){
                        System.out.println(Xhu);
                    }else{
                        System.out.println(Xsei);
                    }
                    
                }else{
                    long sho = X/D;
                    long amari = X%D;
                    if(sho>=K){
                        System.out.println(Math.abs(X-(K*D)));
                        System.exit(0);
                    }
            
                    long Xhu = -(amari-D);
                    long Xsei = amari;
                    
                    if((K-sho)%2==1){
                        System.out.println(Xhu);
                    }else{
                        System.out.println(Xsei);
                    }
                }
                
        }
}

Measured memory_bytes: 35836
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
ans = 0
for i in range(n):
    if a[a[i] - 1] == i + 1:
        ans += 1
print(ans // 2)

Measured memory_bytes: 15956