akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
//#include <unordered_map>
//#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")

using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()

//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18; // segment tree size
const ll MOD = 998244353;
const int INF = 0x3f3f3f3f; // memset(dp, 0x3f, sizeof(dp)), 2*INF < INT_MAX
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10; // double EPS

pll in[100050];

ll L[100050];
ll Lsum[100050];
ll R[100050];
ll Rsum[100050];
int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lld %lld", &L[i], &R[i]);

	sort(L + 1, L + N + 1);
	reverse(L + 1, L + N + 1);
	for (i = 1; i <= N; i++) Lsum[i] = Lsum[i - 1] + L[i];
	sort(R + 1, R + N + 1);
	for (i = 1; i <= N; i++) Rsum[i] = Rsum[i - 1] + R[i];

	ll ans = 0;
	for (i = 1; 2 * i <= N; i++) ans = max(ans, 2 * Lsum[i] - 2 * Rsum[i]);
	for (i = 1; 2 * i - 1 <= N; i++) {
		ans = max(ans, 2 * Lsum[i] - 2 * Rsum[i - 1]);
		ans = max(ans, 2 * Lsum[i - 1] - 2 * Rsum[i]);
	}
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n==22) cout<<"Christmas Eve Eve Eve";
	if(n==23) cout<<"Christmas Eve Eve";
	if(n==24) cout<<"Christmas Eve";
	if(n==25) cout<<"Christmas";
	return 0;
} 

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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int x,y;
int n;
int posX[1000];
int posY[1000];
int g[1000][1000];
int cnt[1000];
int prev[1000];
int buff[2][1000];
bool flag[2][1000];
bool *f,*prevf;
int *st, *st2;
int sp,sp2;

#define DBL(x) ((x)*(x))

int main(){
  int cc = getInt();

  while( cc --> 0 ){
    int sx,sy;
    sp = sp2 = 0;
    st = buff[0]; st2 = buff[1];
    f  = flag[0]; prevf = flag[1];

    n = getInt();
    x = getInt();
    y = getInt();

    sx = getInt();
    sy = getInt();

    REP(i,n){
      cnt[i] = 0;
      posX[i] = getInt();
      posY[i] = getInt();
      prev[i] = -10000;
      flag[0][i] = flag[1][i] = false;

      int dist = DBL(posX[i] - sx) + DBL(posY[i] - sy);
      if(dist <= DBL(10))
        st[sp++] = i;
    }

    REP(i,n) rep(j,i+1,n){
      int dist = DBL(posX[i] - posX[j]) + DBL(posY[i] - posY[j]);
      if(dist <= DBL(50)){
        g[i][cnt[i]++] = j;
        g[j][cnt[j]++] = i;
      }
    }

    int ans;

    for(ans = 0; ans <= n; ans++){
      int time = x * ans;
      sp2 = 0;

      if(sp == 0) break;

      REP(i,sp) prev[st[i]] = time + x;
      REP(i,sp){
        int mm = st[i];
        //printf(" %d%c",mm,i==sp-1?'\n':' ');

        REP(j,cnt[mm]){
          int next = g[mm][j];
          prevf[next] = false;

          if(f[next]) continue;
          if(prev[next] + y >= time + x) continue;
          f[next] = true;
          st2[sp2++] = next;
        }
      }

      swap(sp, sp2);
      swap(st, st2);
      swap(f, prevf);
    }

    if(ans == n + 1) puts("You're always welcome!");
    else printf("%d\n",ans*x);
  }

  return 0;
}

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

int main(){
    int n;
    cin>>n;
    if(n%1000!=0)cout<<1000-n%1000<<endl;
    else cout<<0<<endl;
}

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

  string A,B;
  cin>>A>>B;
  char a=0;
  char b=0;
  if(A.length()>B.length()){
  
    cout<<"GREATER";
    return 0;
  }
  else if(A.length()<B.length()){
  
    cout<<"LESS";
    return 0;
  }
  for(size_t i=0;i<=A.length()-1;i++){
  
    a=A[i];
    b=B[i];
    if(a>b){
    
      cout<<"GREATER";
      return 0;
    }
    else if(a<b){
    
      cout<<"LESS";
      return 0;
    }
  }
  cout<<"EQUAL";
  return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main()
{
    const auto primes = [] {
        bitset<1000000 + 1> b;
        auto t = b;
        t.set();
        t[0] = false;
        t[1] = false;
        int i = 0;
        while (true) {
            bool done = false;
            while (!t[i]) {
                ++i;
                if (i == t.size()) {
                    done = true;
                    break;
                }
            }
            if (done) {
                break;
            }

            b[i] = true;
            for (int j = i; j < t.size(); j += i) {
                t[j] = false;
            }
        }
        return b;
    }();

    while (true) {
        int a, b;
        cin >> a >> b;
        if (a == 0 && b == 0) {
            return 0;
        }

        auto f = [&primes](int x) {
            vector<int> r;
            int j = 2;
            while (true) {
                while (!primes[j]) {
                    ++j;
                }
                if (x == 1) {
                    break;
                }
                if (x % j == 0) {
                    r.push_back(j);
                    x /= j;
                }
                else {
                    j += 1;
                }
            }
            r.erase(unique(begin(r), end(r)), end(r));
            return r;
        };

        auto pa = f(a);
        auto pb = f(b);

        auto g = [](const vector<int>& v) {
            auto s = accumulate(begin(v), --end(v), 0);
            return v.back() - s;
        };

        if (g(pa) > g(pb)) {
            cout << "a" << endl;
        }
        else {
            cout << "b" << endl;
        }
    }
}

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

int main()
{
    int n, a, b;
    string str;
    cin >> n >> a >> b >> str;
    int cnt = a + b;
    for (int i = 0; i < n; ++i)
    {
        if (str[i] == 'a' && cnt > 0)
        {
            cout << "Yes" << endl;
            --cnt;
        }
        else if (str[i] == 'b' && cnt > 0 && b > 0)
        {
            cout << "Yes" << endl;
            --cnt;
            --b;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main(void) {
    long n, m;
    cin >> n >> m;

    const long sc = min(n, m / 2);
    n -= sc;
    m -= 2 * sc;

    const long cc = m / 4;

    cout << (sc + cc) << endl;
    return 0;
}


Measured memory_bytes: 256
N = int( input())
S = [ input() for _ in range(N)]
ans = 0
A = 0
B = 0
T = 0
for s in S:
    t = 0
    if s[0] == "B":
        B += 1
        t += 1
    if s[-1] == "A":
        A += 1
        t += 1
    if t == 2:
        T += 1
    for i in range( len(s)-1):
        if s[i] == "A" and s[i+1] == "B":
            ans += 1
if A == B:
    if A == 0:
        pass
    elif T == A:
        ans += A-1
    else:
        ans += min(A,B)
else:
    ans += min(A,B)
print(ans)

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	str s;
	cin >> s;
	for(auto x : s) cout << (x == 'P' ? 'P' : 'D');
	return 0;
}


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

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

  //素因数分解
  vector<pair<ll,int>> f;
  const ll m = n;
  for(ll i = 2; i * i <= m; i++){
    int x = 0;
    while(n%i==0){
      n /= i;
      x++;
    }
    f.emplace_back(i,x);
  }
  if(n!=1) f.emplace_back(n,1);
  
  //操作回数を数える
  int ans = 0;
  for(auto p : f){
    int e = p.second;
    int b = 1;
    while(e>=b){
      e -= b;
      b++;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 19792
import sys
sys.setrecursionlimit(100000)

N,M=[int(a) for a in input().split()]
AB=[[int(a) for a in input().split()] for _ in range(M)]
edges = [[] for _ in range(N)]
for a, b in AB:
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

colors = [None]*N
def dfs(curr, c):
    colors[curr] = c
    for node in edges[curr]:
        if colors[node] == colors[curr]:
            return False
        if colors[node] is None and not dfs(node, not c):
            return False
    return True

if not dfs(0, True):
    print((N*(N-1))//2 - M)
else:
    nw = sum(colors)
    print(nw*(N-nw)-sum([colors[a-1]^colors[b-1] for a, b in AB]))

Measured memory_bytes: 135640
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

bustered_counter = 0
for i in range(N):
    dif = A_list[i] - B_list[i]
    if dif >= 0:
        bustered_counter += B_list[i]
    elif A_list[i + 1] + dif >= 0:
        bustered_counter += B_list[i]
        A_list[i + 1] += dif
    else:
        bustered_counter += A_list[i] + A_list[i + 1]
        A_list[i + 1] = 0

print(bustered_counter)

Measured memory_bytes: 18468
#include <stdio.h>
using namespace std;

int main(void) {
  int sum;
  while (scanf("%d", &sum)+1) {
    if (sum > 36) {
      printf("0\n");
      continue;
    }

    int count = 0;
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    for (a = 0; a <= 9; a++) {
      for (b = 0; b <=9; b++) {
        for (c = 0; c <= 9; c++) {
          for (d = 0; d <= 9; d++) {
            if ((a + b + c + d) == sum) count++;
          }
        }
      }
    }
    printf("%d\n", count);
  }
}

Measured memory_bytes: 1036
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 1e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , m , k , mnA = INF , mnB = INF , ans = INF , A[MAXN] , B[MAXN] , C[MAXN] , x[MAXN] , y[MAXN];

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

    cin >> n >> m >> k;
    for(ll i = 1 ; i <= n ; i++){
        cin >> A[i];
        mnA = min(mnA , A[i]);
    }
    for(ll i = 1 ; i <= m ; i++){
        cin >> B[i];
        mnB = min(mnB , B[i]);
    }

    for(ll i = 1 ; i <= k ; i++){
        cin >> x[i] >> y[i] >> C[i];
        ans = min(ans , A[x[i]] + B[y[i]] - C[i]);
    }
    cout << min(ans , mnA + mnB) << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
const int mod = 1000000007;
const double PI = 3.1415926535898;

int32_t main()
{




      int a,b,h,m;
      cin >> a >> b >> h >> m;


      double minute = (double)(m)/60 * 360;

      double hour = (double)(60*h + m)/720 * 360;


      double diff = abs(hour-minute);
      diff = min(diff,360-diff);



  




      double ans = sqrt(a*a + b*b - 2*a*b*cos(diff*PI/180));

      cout << fixed << setprecision(20) << ans ;



    return 0;
}



Measured memory_bytes: 4164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <limits.h>
#include <math.h>

int solve(int n, char *s)
{
    int i;
    int len;
    int white, black;
    int w, b;
    int cnt;
    int min;

    // 最後の黒をつぶす
    for (i = n - 1; i >= 0; i--) {
        if (s[i] == '#') {
            s[i] = '\0';
        } else {
            break;
        }
    }
    // 最初の白を飛ばす
    while(*s == '.') {
        s++;
    }
    len = strlen(s);
    if (len < 2) {return 0;}

    white = 0;
    black = 0;
    for (i = 0; i < len; i++) {
        if (s[i] == '.') {
            white++;
        } else {
            black++;
        }
    }

    w = 0; // work
    b = 0; // work
    // 前を白，後ろを黒とする．
    min = white;
    for (i = 0; i < len; i++) {
        if (s[i] == '.') {
            w++;
        } else {
            b++;
        }

        // 前を白，後ろを黒とする．
        cnt = b + (white - w);
        if (cnt < min) {min = cnt;}
    }

    return min;
}

int main(int argc, char *argv[])
{
    int n;
    char s[200001];
    int i;
    int cnt;
    int ans;

    scanf("%d", &n);
    scanf("%s", s);

    ans = solve(n, s);

    printf("%d\n", ans);

    return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
//    freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> s;
    int len = s.length();
    if(len < 4) {
        cout << "No\n";
        return 0;
    }
    if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I')
        cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

	vector<int> A(N);
	rep(i, N) cin >> A[i];

	vector<int> B(N);
	rep(i, N) cin >> B[i];

	ll sumA = 0;
	rep(i, N) sumA += A[i];

	ll sumB = 0;
	rep(i, N) sumB += B[i];

	if (sumA < sumB)
	{
		cout << -1;
		return 0;
	}

	ll count = 0;

	ll over = 0;
	vector<ll> overs;
	ll under = 0;

	rep(i, N)
	{
		if (A[i] < B[i])
		{
			count++;
			under += B[i] - A[i];
		}
		else if(A[i] > B[i])
		{
			overs.push_back(A[i] - B[i]);
		}
	}

	//降順
	sort(all(overs), greater<ll>());

	for (auto over : overs)
	{
		if (under <= 0) break;

		under -= over;

		count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> W(N); for (auto &w : W) cin >> w;
    vector<int> S(N+1);
    for (int i = 0; i < N; i++) S[i+1] = S[i] + W[i];
    int ans = 1e9;
    for (int i = 1; i < N; i++) {
        ans = min(ans, abs(S[i] - (S[N] - S[i])));
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
sum = 0
ans = 0
for i,a in enumerate(A):
    sum += a

    if sum == x:
        ans = i + 1
        break
    elif sum > x:
        break
    elif i + 1 == N and sum < x:
        ans = i
        break
    ans = i + 1


print(ans)


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


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

  vector<char> v;
  for (int i = 0; i < (int)s.size(); i++) {
    if (i+1 < (int)s.size() && s[i] == 'B' && s[i+1] == 'C') { v.push_back('X'); i++; }
    else v.push_back(s[i]);
  }
  // cout << s << endl;
  // pv(ALL(v));
  ll ans = 0;
  ll a = 0;
  for (int i = 0; i < (int)v.size(); i++) {
    if (v[i] == 'A') a++;
    else if (v[i] == 'X') ans += a;
    else a = 0;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define double      long double
//std::cout << std::fixed;std::cout << std::setprecision(10);

const int N=1e5 + 5;
const int M=1e9 + 7;

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	std::cout << std::fixed;std::cout << std::setprecision(12);
	double sum =0;
	int a[10];
	a[1] = 1;
	rep(i,2,8)
	{
		a[i] = i*a[i-1];
	}
	int n;
	cin >> n;
	int T = a[n];
	double f =  T;
	//cout << T << endl;
	vector<pair<double,double>> v;
	rep(i,1,n)
	{
		double x,y;
		cin >> x >> y;
		v.pb({x,y});
	}
	while(T--)
	{
		next_permutation(v.begin(), v.end()); 
		double temp  = 0;
		rep(i,0,n-2)
		{
			 double dis = (v[i].first - v[i+1].first)*(v[i].first - v[i+1].first);
			dis += (v[i].second-v[i+1].second)*(v[i].second-v[i+1].second);
			dis = sqrt(dis);
			temp += dis;
		}
		sum += temp;
	}
	cout << sum/f << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j,h;
  int d[13],e[13];
  while(scanf("%d",&n),n){
    for(i=0;i<n;i++)scanf("%d",&d[i]);
    for(i=0;1;i++){
      int c[1300]={0};
      for(j=0;j<n;j++)c[d[j]]++;
      h=1;
      for(j=0;j<n;j++){
	e[j]=c[d[j]];
	if(e[j]!=d[j])h=0;
      }
      if(h)break;
      for(j=0;j<n;j++)d[j]=e[j];
    }
    printf("%d\n",i);
    for(i=0;i<n;i++){
      if(i)printf(" ");
      printf("%d",d[i]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

struct UnionFind{
	vector<int> par;

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

	ll work = a[0];
	rep(i,n-2){
		if(abs(a[n-1]-a[i+1]*2) < abs(a[n-1]-work*2))work = a[i+1];
	}

	cout << a[n-1] << " " << work << endl;
	return 0;
}


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

int main() {
	int M, N, ans = INT_MIN;
	cin >> M >> N;
	for (int i = 0; i < M; ++i) {
		int sum = 0;
		for (int j = 0; j < N; ++j) {
			int tmp;
			cin >> tmp;
			sum += tmp;
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}


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

#define MAX_E 501
#define MAX_V 101
#define INF 1e9

using namespace std;

int cost[MAX_V][MAX_V]; // cost[u][v]テ」ツ?ッティツセツコe=(u,v)テ」ツ?ョテ」ツつウテ」ツつケテ」ツδ?テ・ツュツ佚・ツ慊ィテ」ツ?療」ツ?ェテ」ツ??・ツ?エテ・ツ青暗」ツ?ッINF)
int mincost[MAX_V]; // テゥツ崢?・ツ青?テ」ツ?凝」ツつ嘉」ツ?ョティツセツコテ」ツ?ョテヲツ慊?・ツーツ湘」ツつウテ」ツつケテ」ツδ?
bool used[MAX_V];   // テゥツ?づァツつケiテ」ツ?傾テ」ツ?ォテ・ツ青ォテ」ツ?セテ」ツつ古」ツ?ヲテ」ツ??」ツつ凝」ツ??
int V;

int prim() {
  for (int i = 0; i < V; ++i) {
    mincost[i] = INF;
    used[i] = false;
  }
  mincost[0] = 0;
  int res = 0;

  while (true) {
    int v = -1;
    // Xテ」ツ?ォテ・ツアツ榲」ツ?陛」ツ?ェテ」ツ??ゥツ?づァツつケテ」ツ?ョテ」ツ??」ツ?。Xテ」ツ?凝」ツつ嘉」ツ?ョティツセツコテ」ツ?ョテ」ツつウテ」ツつケテ」ツδ暗」ツ?古ヲツ慊?・ツーツ湘」ツ?ォテ」ツ?ェテ」ツつ凝ゥツ?づァツつケテ」ツつ津ヲツ篠「テ」ツ??
    for (int u = 0; u < V; u++) {
      if (!used[u] && (v == -1 || mincost[u] < mincost[v]))
        v = u;
    }

    if (v == -1)
      break;
    used[v] = true;    // テゥツ?づァツつケvテ」ツつ湛テ」ツ?ォティツソツステ・ツ環?
    res += mincost[v]; // ティツセツコテ」ツ?ョテ」ツつウテ」ツつケテ」ツδ暗」ツつ津・ツ環?」ツ?暗」ツつ?

    for (int u = 0; u < V; u++) {
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }

  return res;
}

int main(){
    int n, m;
    while(cin >> n >> m, n != 0 || m != 0){
        V = n;
        for(int i=0;i<MAX_V;++i)
            for(int j=0;j<MAX_V;++j)
                cost[i][j] = INF;
        for(int i=0;i<m;++i){
            int a, b, c;
            cin >> a >> b >> c;
            cost[a][b] = c;
            cost[b][a] = c;
        }
        cout << prim() << endl;
    }

    return 0;
}


Measured memory_bytes: 3008
using System;
using System.Linq;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var inputs = Console.ReadLine().Split(' ').ToList();
                var term1 = int.Parse(inputs[0]);
                var op = inputs[1];
                var term2 = int.Parse(inputs[2]);
                int result;
                switch (op)
                {
                    case "+":
                        result = term1 + term2;
                        break;
                    case "-":
                        result = term1 - term2;
                        break;
                    case "*":
                        result = term1 * term2;
                        break;
                    case "/":
                        result = term1 / term2;
                        break;
                    case "?":
                        goto Finish;
                    default:
                        throw new InvalidOperationException();
                }

                Console.WriteLine($"{result}");
            }

            Finish:
            return;
        }
    }
}



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

int main() {
  int n, t = 0;
  cin >> n;

  vector<pair<int, int> > p(n);
  for (int i = 0; i < n; i++) cin >> p[i].second >> p[i].first;
  sort(p.begin(), p.end());

  for (int i = 0; i < n; i++) {
    t += p[i].second;
    if (t > p[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1792
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn read_vec_char() -> Vec<char> {
    read::<String>().chars().collect()
}

fn read_mat<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_mat_char(n: usize) -> Vec<Vec<char>> {
    (0..n).map(|_| read_vec_char()).collect()
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut ans = 0;
    let mut t = a[0];
    let mut k = 0;
    for i in 0..n {
        if k < i {
            k = i;
            t = a[i];
        }
        while k < n-1 && t & a[k+1] == 0 {
            t ^= a[k+1];
            k += 1;
        }
        if k == n-1 {
            ans += (k + 1 - i) * (k + 2 - i) / 2;
            break;
        }
        ans += k + 1 - i;
        t ^= a[i];
    }
    println!("{}",ans);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m;
vi a;

int main(){
	cin>>n>>m;
	a=vi(n);
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.rbegin(),a.rend());
	vl dp(m+1),s(m+1);
	dp[m]++;
	for(int i=0;i<n;i++){
		vl DP(m+1);
		for(int j=0;j<=m;j++){
			(s[j]*=n-i)%=mod;
			(DP[j%a[i]]+=dp[j]+s[j])%=mod;
			(s[j]+=dp[j])%=mod;
		}
		dp=DP;
	}
	ll res=0;
	for(int i=0;i<=m;i++) (res+=i*dp[i])%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 2560
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);
			char a = s[0].charAt(s[0].length()-1);
			char b = s[1].charAt(0);
			char c = s[1].charAt(s[1].length()-1);
			char d = s[2].charAt(0);
			if(a==b && c == d) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N, K;
    cin >> N >> K;
    cout << K * (ll)pow(K - 1, N - 1) << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    string s;
    cin >> s;


    char tmp = s[0];
    REP(i,2){
        if(tmp != s[i]){
            cout << "Yes" << endl;
            return 0;

        }
    }

            cout << "No" << endl;

}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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

int main() {
    int a, b;
    cin>> a>> b;

    int c = a+b;

    cout << (c+2-1)/2 << endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    if(k%2)cout<<(n/k)*(n/k)*(n/k)<<endl;
    else cout<<(n/k)*(n/k)*(n/k)+((n+k/2)/(k/2)/2)*((n+k/2)/(k/2)/2)*((n+k/2)/(k/2)/2)<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

//A Book Shop With a Frequent Greetings
public class Main{


	class E implements Comparable<E>{
		int id, t;
		public E(int id, int t) {
			this.id = id;
			this.t = t;
		}
		public int compareTo(E o) {
			return t-o.t;
		}
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		int L = 100000, INF = 1<<29;
		while(T--!=0){
			int n = sc.nextInt(), X = sc.nextInt(), Y = sc.nextInt();
			int sx = sc.nextInt(), sy = sc.nextInt();
			int[][] p = new int[n][2];
			for(int i=0;i<n;i++)for(int j=0;j<2;j++)p[i][j]=sc.nextInt();
			boolean[][] e = new boolean[n][n];
			for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)if(Math.hypot(p[i][0]-p[j][0], p[i][1]-p[j][1])<=50)e[i][j]=e[j][i]=true;
			int[] last = new int[n];
			Arrays.fill(last, -150);
			int res = 0;
			PriorityQueue<E> q = new PriorityQueue<E>();
			for(int i=0;i<n;i++)if(Math.hypot(p[i][0]-sx, p[i][1]-sy)<=10)q.add(new E(i, 0));
			while(!q.isEmpty()){
				E ev = q.poll();
				if(L<ev.t){
					res = INF; break;
				}
				if(ev.t-Y>last[ev.id]){
					last[ev.id] = ev.t+X;
					res = Math.max(res, last[ev.id]);
					for(int i=0;i<n;i++)if(e[ev.id][i])q.add(new E(i, ev.t+X));
				}
			}
			System.out.println(res==INF?"You're always welcome!":res);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 46000
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>

using namespace std; 
using boost::algorithm::join;

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  string s = join(arr, "");
  cout << s << endl;
}

Measured memory_bytes: 256
loop do
  h, w = gets.chomp.split(' ').map{|x| x.to_i}
  break if h == 0 and w == 0

  tiles = []
  h.times{tiles << gets.chomp}

  x, y = 0,0
  loop do
    if tiles[y][x] == '>'
      tiles[y][x] = ' '
      x+=1
    elsif tiles[y][x] == '<'
      tiles[y][x] = ' '
      x-=1
    elsif tiles[y][x] == '^'
      tiles[y][x] = ' '
      y-=1
    elsif tiles[y][x] == 'v'
      tiles[y][x] = ' '
      y+=1
    elsif tiles[y][x] == '.'
      puts "#{x} #{y}"
      break 
    else
      puts 'LOOP'
      break 
    end
  end
end

Measured memory_bytes: 6116
parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,m=parseMap(split(readline()))
    food=[0 for i in 1:m]
    for i in 1:n
        a=parseMap(split(readline()))
        for j in 2:a[1]+1
            food[a[j]]+=1
        end
    end
    println(sum([div(i,n) for i in food]))
end
main()

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

using namespace std;

using ll = long long;

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

    const int n = s.size();
    int k = 0;
    if (n % 2 == 0) {
        int r = n / 2, l = r - 1;
        while (0 <= l - k && r + k < n) {
            if (s[r] != s[l - k] || s[l] != s[r + k]) break;
            ++k;
        }
    }
    else {
        int mid = n / 2;
        while (0 <= mid - k && mid + k < n) {
            if (s[mid] != s[mid - k] || s[mid] != s[mid + k]) break;
            ++k;
        }
    }
    return n / 2 + k;
}

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

    cout << Solve() << endl;

    return 0;
}


Measured memory_bytes: 512
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.length();
  auto is_circular = [](string s) { return equal(begin(s), end(s), rbegin(s)); };
  bool ans = is_circular(S) && is_circular(S.substr(0, (N - 1) / 2)) && is_circular(S.substr((N + 1) / 2));
  cout << (ans ? "Yes" : "No") << endl;
}


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

using namespace std;

int n, a[100010];

int main(){
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  for(int i=n-1;i>=1;i--){
    if(a[i]>a[i+1]) a[i]--;
  }
  string res = "Yes";
  for(int i=2;i<=n;i++){
    if (a[i]<a[i-1]){
      res="No";
      break;
    }
  }
  
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 640
n = int(input())
w = []
for _ in range(n):
    ww = list(input())
    w.append(ww)
    
bool = True
for i in range(n-1):
    if w.count(w[i]) == 1:
        if w[i][-1] == w[i+1][0]:
            continue
        else:
            bool = False
            break
    else:
        bool = False
        break
        
print('Yes' if bool else 'No')

Measured memory_bytes: 3064
from numpy import zeros, maximum            
                                            
n, W, *wv = map(int, open(0).read().split())
t = zeros(W+1, int)                         
for i in range(n):                          
    w = wv[i * 2]                           
    v = wv[i * 2 + 1]                       
    t[w:] = maximum(t[w:], t[:-w]+v)        
print(t[-1])                                

Measured memory_bytes: 15476
#include <iostream>
//#include <algorithm>
#include <stdio.h>
//#include <math.h>

using namespace std;

int main(void){
    // Your code here!
int x;
int i=0;

while( scanf("%d",&x)!=EOF && x!=0 ){
    printf("Case %d: %d\n",++i,x); //printf("Case %d: %d\n",++i,tmp)
}

    return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll n;
    cin >> n;
    map<ll, ll> mp;
    for (ll x = 2; x <= 1000000; x++){
        while (n % x == 0){
            mp[x]++;
            n /= x;
        }
    }
    if (n > 1) mp[n] = 1;
    int ans = 0;
    for (auto p : mp){
        ll x = p.second;
        ll s = 0;
        FOR(i,1,100){
            s += i;
            if (x < s){
                ans += i - 1;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define il inline
#define rg register
using namespace std;
typedef long long LL;
const LL m_63=1061109567;
const LL m_127=2139062143;
const LL inf=2147483647;
const double pi=atan(1.0)*4.0;
const LL llf=9223372036854775807;
const LL mod=998244353;
const LL N=1e6+7;
const LL M=5007;
LL n,m,a[N],b[N],p[N],bz[M][M],flag,sum;
il LL read(){
	LL x(0),ff(1);char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')ff=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*ff;
}
il void write(LL x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
il void fre(){
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
}
int main(){
//	fre();
	n=read(),m=read();
	for(rg int i=1;i<=m;++i)a[i]=read(),b[i]=read();
	for(rg int i=1;i<=n;++i){
		p[i]=1;bz[i][i]=1;
		for(rg int j=m;j>=1;--j){
			int x=a[j],y=b[j];
			if(!bz[i][x]&&!bz[i][y])continue;
			if(bz[i][x]&&bz[i][y]){p[i]=0;break;}
			bz[i][x]=bz[i][y]=1;
		}
	}
	for(rg int i=1;i<n;++i){
		for(rg int j=i+1;j<=n;++j){
			if(p[i]&&p[j]){
				flag=0;
				for(rg int k=1;k<=n;++k){
					if(bz[i][k]&&bz[j][k]){flag=1;break;}
				}
				if(!flag)++sum;
			}
		}
	}
	printf("%lld\n",sum);
	return 0;
}
/*
4 3
1 2
3 4
2 3

*/

Measured memory_bytes: 21248
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <array>
#include <set>
#include <climits>
#include <cassert>
#include <bitset>
using namespace std;
long long ans (long long h){
    if(h==0){
        return 1;
    }
    if(h==1){
        return 1;
    }
    if(h==2){
        return 3;
    }
    return ans(h/2)*2ll+1ll;
}
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    long long h;cin>>h;
    cout<<ans(h)<<endl;
    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	vector<int> a(1001);
	int ans = 0;
	for(int i = 1; i <= n ; i++) {
		int b;
		cin >> b;
		cerr << a[b] << " " << i << endl;
		if(a[b] != 0 && i - a[b] == 1) {
			ans++;
		}
		else a[b] = i;
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <iostream>

#define INF (500 * 500 * 1000 + 1)
#define MIN(X, Y) (X < Y ? X : Y)


using namespace std;

int main()
{
    int n, c;
    int D[33][33];
    int C[505][505];

    cin >> n >> c;
    
    for (int i = 1; i <= c; i++) {
        for (int j = 1; j <= c; j++) {
            cin >> D[i][j];
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> C[i][j];
        }
    }

    int ans = INF;
    int csum[3][34] = {};
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {

            for (int k = 1; k <= c; k++) {
                csum[(i + j) % 3][k] += D[C[i][j]][k];
            }
        }
    }
                

    for (int i = 1; i <= c; i++) {
        for (int j = 1; j <= c; j++) {
            for (int k = 1; k <= c; k++) {

                if (i == j || j == k || i == k) {
                    continue;
                }
                
                ans = MIN(ans, csum[0][i] + csum[1][j] + csum[2][k]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1280
import numpy as np
n, k = map(int, input().split())
f = lambda:list(map(int, input().split()))
h = np.array(f())
dp = np.zeros(n,'i8')

for i in range(1, n):
  s = max(i-k, 0)
  dp[i] = np.min(dp[s:i]+np.abs(h[s:i]-h[i]))
print(dp[-1])

Measured memory_bytes: 22920
use input::Input;

fn main() {
    let mut input = Input::new();

    let n: usize = input.parse();
    let mut k: usize = input.parse();
    let v = (0..n)
        .map(|_| input.parse::<usize>() - 1)
        .collect::<Vec<_>>();

    let mut cp = 0;
    let mut np = v[cp];
    for _ in 0..n {
        if k == 0 {
            println!("{}", cp + 1);
            return;
        }
        cp = np;
        np = v[cp];
        k -= 1;
    }

    let mut w = vec![false; n];
    let mut cnt = 0;
    while !w[np] {
        w[np] = true;
        cp = np;
        np = v[np];
        cnt += 1;
    }

    for _ in 0..k % cnt {
        cp = np;
        np = v[cp];
    }

    println!("{}", cp + 1);
}

#[allow(dead_code)]
pub mod input {
    use std::io::{self, BufRead, StdinLock};
    use std::str::{FromStr, SplitAsciiWhitespace};

    pub struct Input<'a> {
        lock: StdinLock<'static>,
        iter: SplitAsciiWhitespace<'a>,
    }

    fn naive_read<'a>(lock: &mut StdinLock) -> SplitAsciiWhitespace<'a> {
        let mut s = Box::leak(Box::new(String::new()));
        lock.read_line(&mut s).expect("failed to read");
        s.split_ascii_whitespace()
    }

    impl<'a> Input<'a> {
        pub fn new() -> Self {
            let mut lock = Box::leak(Box::new(io::stdin())).lock();
            let iter = naive_read(&mut lock);
            Self { lock, iter }
        }
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            self.lock.read_line(&mut s).ok().expect("failed to read");
            s
        }
        pub fn parse<T: FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.iter.next() {
                x
            } else {
                self.iter = naive_read(&mut self.lock);
                self.iter.next().expect("reached EOF")
            };
            x.parse().ok().expect("failed to parse")
        }
    }
}


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


typedef struct {
    int stone;
} person;

int main(){
    int n, p;
    while (1){
	cin >> n >> p;
	if (n == 0 && p == 0) break;
	int def = p;
	person entree[50];
	for (int i = 0; i < 50; i++)
	    entree[i].stone = 0;

	int e = 0;

	int j = 0;
	while (1){
	    
	    if (entree[j%n].stone == def) {
		e = j%n;
		break;
	    }
	    if (p == 0){
		p = entree[j%n].stone;
		entree[j%n].stone = 0;
	    }
	    // take one stone
	    else {
		p--;
		entree[j%n].stone++;
	    }
	    j++;
	}

	
	cout << e << endl;
    }
}

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

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

  int price = 700;
  for (int i = 0; i < 3; ++i) {
    if (s.at(i) == 'o') {
      price += 100;
    }
  }
  cout << price << endl;
}

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

int main() {
	int x, y;
	cin >> x;
	cin >> y;
 
	if (x == 1) {
		if (y == 2) {
			cout << 3 << endl;
		}
		else {
			cout << 2 << endl;
		}
	}
	else if (x == 2) {
		if (y == 1) {
			cout << 3 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	else {
		if (y == 2) {
			cout << 1 << endl;
		}
		else {
			cout << 2 << endl;
		}
	}
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    ans = 0
    x = 0
    n = int(input())
    s = input()
    for i in range(n):
        if s[i] == 'I':
            x += 1
            ans = max(ans, x)
        else:
            x -= 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int K = sc.nextInt();
		int a[] = new int[N];
		for(int i=0;i<N;i++) {
			a[i] =sc.nextInt();
		}
		if (a[0]>=0) {
			System.out.println(a[K-1]);
			return;
		}
		if (a[N-1]<=0) {
			System.out.println(Math.abs(a[N-K]));
			return ;
		}
		int afterZero=0,befZero=0;
		for(int i=0;i<N;i++) {
			if (a[i]<=0) {
				befZero++;
			} else {
				break;
			}
		}
		afterZero=N-befZero;
		int min = Integer.MAX_VALUE;
		for (int i=0;i<=befZero&&i<=K;i++) {
			if (K-i>afterZero) {
				continue;
			}
			int total;
			if (i==0) {
				total = a[befZero+K-1];
			} else if (i==K) {
				total = Math.abs(a[befZero-i]);
			} else {
				total = Math.abs(a[befZero-i])*2+a[befZero+K-i-1];
			}
			if (total<min) {
				min = total;
			}
		}
		for (int i=0;i<=afterZero&&i<=K;i++) {
			if (K-i>befZero) {
				continue;
			}
			int total;
			if (i==0) {
				total = Math.abs(a[befZero-K]);
			} else if (i==K) {
				total = a[befZero+K-1];
			} else {
				total = Math.abs(a[befZero+i-1])*2+Math.abs(a[befZero-(K-i)]);
			}
			if (total<min) {
				min = total;
			}
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 49780
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using V = std::vector<T>;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N, M, v, P;
  cin >> N >> M >> v >> P;
  V<i64> A(N);
  REP(i, N) cin >> A[i];
  sort(A.rbegin(), A.rend());
  i64 pth = A[P - 1];

  auto check = [&](int x) -> bool {
    --x;
    if (x < P) return true;
    if (x > N - 1) return false;
    i64 cnt1 = (P - 1) + (N - x);
    i64 h = A[x] + M;
    if (h < pth) return false;
    if (cnt1 >= v) return true;
    i64 room = 0;
    for (int i = P - 1; i < x; ++i) {
      room += h - A[i];
    }
    return (cnt1 * M + room >= M * v);
    // return room >= M*v;

    // i64 window = v - cnt1;
    // assert(window > 0);
    // i64 rem = M;
    // V<i64> delta(N + 1);
    // for (int i = P - 1; i + window <= x; ++i) {
    //   delta[i] += i > 0 ? delta[i - 1] : 0;
    //   i64 y = A[i] + delta[i];
    //   if (y > h) return false;
    //   i64 d = h - y;
    //   rem -= d;
    //   if (rem <= 0) return true;
    //   delta[i] += d;
    //   delta[i + window] -= d;
    // }
    // return false;
  };

  i64 ok = P, ng = N + 1;
  while (ng - ok > 1) {
    i64 mid = (ok + ng) / 2;
    if (check(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
}


Measured memory_bytes: 3996