akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

struct edge {
	const int to, cost;
	edge(const int to_, const int cost_):to(to_), cost(cost_) {}
};
using Graph = vector<vector<edge>>;
constexpr int INF = (1 << 29);
constexpr int MAX_N = 2000;
bool used[MAX_N];

inline int calc(const int x1, const int y1, const int z1, const int x2, const int y2, const int z2, const int s) {
	const int dx = s - abs(x1 - x2);
	const int dy = s - abs(y1 - y2);
	const int dz = s - abs(z1 - z2);
	if(min({dx, dy, dz}) <= 0) return 0;
	return 2 * (dx * dy + dy * dz + dz * dx);
}

int dfs(const int v, const int p, const int rest, const Graph &G) {
	if(rest == 0) {
		int res = 0;
		for(const auto &e : G[v]) {
			if(used[e.to] && e.to != p) res += e.cost;
		}
		return res;
	}
	used[v] = true;
	int res = -INF;
	for(const auto &e : G[v]) {
		if(!used[e.to]) res = max(res, dfs(e.to, v, rest - 1, G) + e.cost);
	}
	used[v] = false;
	return res;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	for(int n, k, s; cin >> n >> k >> s && n;) {
		vector<int> x(n), y(n), z(n);
		for(int i = 0; i < n; ++i) {
			cin >> x[i] >> y[i] >> z[i];
		}

		Graph G(n);
		for(int i = 0; i < n; ++i) {
			for(int j = i + 1; j < n; ++j) {
				const int area = calc(x[i], y[i], z[i], x[j], y[j], z[j], s);
				if(area) {
					G[i].emplace_back(j, area);
					G[j].emplace_back(i, area);
				}
			}
		}

		int mx = -INF;
		for(int i = 0; i < n; ++i) {
			mx = max(mx, dfs(i, -1, k - 1, G));
		}
		cout << (mx < 0 ? -1 : s * s * 6 * k - mx) << endl;
	}
	return EXIT_SUCCESS;
}

Measured memory_bytes: 3124
#include<stdio.h>

int main()
{
  int d1[6];
  int d2[6];
  int m;
  int temp;

  for(int i = 0; i < 6; i++)
    {
      scanf("%d", &d1[i]);
    }
  for(int i = 0; i < 6; i++)
    {
      scanf("%d", &d2[i]);
    }
  while(1)
    {
      while(1)
	{
	  for(int i = 0; i < 6; i++)
	    {
	      if(d1[1] == d2[i])
		{
		  m = i;
		}
	    }
	  if(d1[1] == d2[1])
	    {
	      break;
	    }
	  temp = d2[0];
	  if(m == 3)
	    {
	      d2[0] = d2[3];
	      d2[3] = d2[5];
	      d2[5] = d2[2];
	      d2[2] = temp;
	    }
	  if(m == 2)
	    {
	      d2[0] = d2[2];
	      d2[2] = d2[5];
	      d2[5] = d2[3];
	      d2[3] = temp;
	    }
	  if(m == 4 || m == 0)
	    {
	      d2[0] = d2[4];
	      d2[4] = d2[5];
	      d2[5] = d2[1];
	      d2[1] = temp;
	    } 
	  if(m == 1 || m == 5)
	    {
	      d2[0] = d2[1];
	      d2[1] = d2[5];
	      d2[5] = d2[4];
	      d2[4] = temp;
	    }
	}
      if(d1[4] != d2[4])
	{
	  printf("No\n");
	  return 0;
	}
      while(1)
	{
	  for(int i = 0; i < 6; i++)
	    {
	      if(d1[0] == d2[i])
		{
		  m = i;
		}
	    }
	  if(d1[0] == d2[0])
	    {
	      break;
	    }
	  temp = d2[0];
	  if(m == 3)
	    {
	      d2[0] = d2[3];
	      d2[3] = d2[5];
	      d2[5] = d2[2];
	      d2[2] = temp;
	    }
	  if(m == 2)
	    {
	      d2[0] = d2[2];
	      d2[2] = d2[5];
	      d2[5] = d2[3];
	      d2[3] = temp;
	    }
	  if(m == 5)
	    {
	      d2[0] = d2[5];
	      d2[5] = temp;
	      temp = d2[2];
	      d2[2] = d2[3];
	      d2[3] = temp;
	    }
	}
      if(d1[5] != d2[5] || d1[2] != d2[2])
	{
	  printf("No\n");
	  return 0;
	}
      else
	{
	  printf("Yes\n");
	  return 0;
	}
    }
}



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

int main(){
  int n,res;
  stack<pair<int,int> > stk;
  while(cin >> n,n){
    res = 0;
    for(int i = 0;i < n / 2;i++) {
      int a,b;
      cin >> a >> b;
      if(stk.empty()){
	stk.push(make_pair(b,2));
	continue;
      }
      pair<int,int> p = stk.top();stk.pop();
      if(p.first == a){
	if(a == b) stk.push(make_pair(p.first,p.second + 2));
	else {
	  if(stk.empty()) stk.push(make_pair(b,p.second + 2));
	  else{
	    pair<int,int> p2 = stk.top();stk.pop();
	    stk.push(make_pair(p2.first,p2.second + p.second + 2));
	  }
	}
      }else{
	if(a == b){
	  stk.push(p);
	  stk.push(make_pair(a,2));
	}
	else{
	  stk.push(make_pair(p.first,p.second + 2));
	}
      }
    }
    if(n % 2 == 1){
      int a;
      cin >> a;
      if(a == 0) res++;
    }
    while(!stk.empty()){
      pair<int,int> p = stk.top();stk.pop();
      if(p.first == 0) res += p.second;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3096
sx,sy,tx,ty = map(int,input().split())
TSX = tx - sx
TSY = ty - sy
print("U"*TSY+"R"*TSX+"D"*TSY+"L"*TSX+"D"+"R"*(TSX+1)+"U"*(TSY+1)+"L"+"U"+"L"*(TSX+1)+"D"*(TSY+1)+"R")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>

#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define perr(i,a,b) for(int i=a;i>b;i--)
#define pb push_back
#define eb emplace_back
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-12;
const double PI=acos(-1.0);
const double ATRconst=PI/180.0;
const ll mod=998244353;
ll max_3(ll a,ll b,ll c){if(a>b&&a>c)return a;if(b>c)return b;return c;}
ll min_3(ll a,ll b,ll c){if(a<b&&a<c)return a;if(b<c)return b;return c;}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll n){ll r=1;while(n){if(n&1)r=(r*a)%mod;n>>=1;a=(a*a)%mod;}return r;}



void solve()
{
    int n;
    cin>>n;
    if(n%10==0||n%10==1||n%10==6||n%10==8)
        cout<<"pon\n";
    else if(n%10==3)
        cout<<"bon\n";
    else
        cout<<"hon\n";
}
int main()
{
    closeSync;
    //multiCase
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3048
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;

void bubble_sort(int nums[100], int n){
    int count, temp=0;
    count = 0;
    for(int i=0; i<n; i++){
        for(int j=n-1; j>i; j--){
            if(nums[j-1] > nums[j]){
                count++;
                temp = nums[j];
                nums[j] = nums[j-1];
                nums[j-1] = temp;
            }
        }
    }
    
    for(int i=0; i<n; i++){
        cout << nums[i];
        if(i<n-1){
            cout << " ";
        }
    }
    cout << endl;
    cout << count << endl;
}

int main()
{
    int N;
    int num[100];
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> num[i];
    }
    bubble_sort(num, N);
    return 0;
}


Measured memory_bytes: 3104
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;

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

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
        cout << "Yes" << endl;
    }
    else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) {
        cout << "Yes" << endl;
    }
    else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
function main(input) {
  input = input.trim();
  const [a, b, k] = input.split(' ').map(n => Number(n));
  const array = [];
  for (let i = 1; i <= 100; i++) {
    if (a%i === 0 && b%i === 0) array.push(i);
  }
  const result = array[array.length-k]
  console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main()
{
	int n, l, r;
	while (cin >> n >> l >> r, n | l | r) {
		r += 1;
		vector<int> A(n);
		for (int i = 0; i < n; i++) {
			cin >> A[i];
		}
		vector<int> v(r, n % 2 == 0);
		for (int i = n - 1; i >= 0; i--) {
			for (int j = A[i]; j < r; j += A[i]) {
				v[j] = i % 2 == 0;
			}
		}
		cout << count(v.begin() + l, v.begin() + r, 1) << endl;
	}
	return 0;
}



Measured memory_bytes: 3116
while (True):
    n = int(input())
    if (n != 0):
        stu = list(map(int, input().split()))
        s = sum(stu) / n
        var = 0
        for i in range(n):
            var += (stu[i] - s) ** 2
        print((var / n) ** 0.5)
    else:
        break


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

static const long long INFTY = (1LL<<32);

int n;
long long d[100][100];

void warshall_floyd(){
    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            if(d[i][k] == INFTY) continue;
            for(int j = 0; j < n; j++){
                if(d[k][j] == INFTY) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main(){
    int E, u, v, c;
    cin >> n >> E;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            d[i][j] = ((i == j) ? 0 : INFTY);
        }
    }
    for(int i = 0; i < E; i++){
        cin >> u >> v >> c;
        d[u][v] = c;
    }
    
    warshall_floyd();
    
    bool negative = 0;
    for(int i = 0; i < n; i++){
        if(d[i][i] < 0) negative = 1; //閉路がマイナスだったら
    }
    if(negative){
        cout << "NEGATIVE CYCLE" << endl;
    }
    else{
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(j != 0) cout << " ";
                if(d[i][j] == INFTY) cout << "INF";
                else cout << d[i][j];
            }
            cout << endl;
        }
    }
    return 0;
    
}


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

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;


int main(){
    int k, a, b;
    cin >> k >> a >> b;
    if (((a - 1)/ k + 1)*k <= b) cout << "OK" << endl;
    else cout << "NG" << endl;
}


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

int main(){
    string S;
    cin >> S;    
    int a;
    a=S.length();
    int b, c;
    b=(a-1)/2;
    c=(a+3)/2;
    int counter = 0;
    string p, q;
    p = S.substr(0,b);
    q = S.substr(c-1,b); 
    if(p==q){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
from functools import reduce
from math import gcd, sqrt,ceil


n = int(input())
a = list(map(int,input().split()))
m = 10**6

a_gcd = reduce(gcd,a)
if a_gcd != 1:
    print("not coprime")
    exit(0)
isset = a_gcd == 1
hurui = [i for i in range(m+1)]
for i in range(2,ceil(sqrt(m))+1):
    for j in range(2,ceil(sqrt(i))+1):
        if i==2:
            continue
        if i%j == 0:
            break
    else:
        for k in range(i+i,m,i):
            if hurui[k] != k:
                continue
            hurui[k] = i
    continue
s = set()
p_f = True
for ai in a:
    t = set()
    while(ai > 1):
        t.add(hurui[ai])
        ai //= hurui[ai]
    for ti in t:
        if ti in s:
            p_f = False
        else:
            s.add(ti)

if p_f:
    print("pairwise coprime")
elif isset:
    print("setwise coprime")

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

int main() {
	int x,y;
	cin >> x>> y;
	if (x < y) {
		cout << "a < b" << endl;
}
	if (x > y) {
		cout << "a > b" << endl;
	}
	if (x == y) {
		cout << "a == b" << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <vector>
#include <string>
using namespace std;
 
int main (){
        long long N,D;
        cin >> N >>D;
        long long ans;
        
        if(N==0){
            if(D==100){
                ans= 101;
            }else{
                ans=D;
            }
            
        }else if(N==1){
            if(D==100){
                ans= 10100;
            }else{
                ans=D*100;
            }
            
        }else if(N==2){
            if(D==100){
                ans= 1010000;
            }else{
                ans=D*10000;
            }
            
        }
 
        cout << ans << endl;
 
        return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
sc = []
for i in range(m): sc.append(list(map(int, input().split())))

for i in range(10**n):
    flg = True
    if len(str(i)) == n:
        for j in sc:
            # print(int(str(i)[j[0]-1]))
            if int(str(i)[j[0]-1]) != j[1]:
                flg = False
        if flg:
            print(i)
            exit()
print(-1)

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

int c[27];
int s[366][27];
int t[366];

int last_day(int d,int type){
    int lday=0;
    for(int i=1;i<=d;i++){
        if(t[i]==type) lday=i;
    }
    
    return lday;
}

int dissatisfied(int d){
    int dis=0;
    for(int j=1;j<=26;j++){
        dis+=c[j]*(d-last_day(d,j));
    }
    return dis;
}


int solve(int d){
    int res=0;
    for(int i=1;i<=d;i++){
        res=res+s[i][t[i]]-dissatisfied(i);
    }
    return res;
}
 
 
int main(void){
    int D;cin>>D;
    
    for(int i=1;i<=26;i++){
        cin>>c[i];
    }
    
    for(int i=1;i<=D;i++){
        for(int j=1;j<=26;j++){
            cin>>s[i][j];
        }
    }
    
    for(int i=1;i<=D;i++){
        cin>>t[i];
    }
    
    for(int i=1;i<=D;i++){
        cout<<solve(i)<<endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 3612
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;

using i32 = int;
using i64 = long long;

#define REP(i, stop) for (int i = 0; i < stop; ++i)

template<typename T>
T read() {
  T a = 0;
  for(;;) {
    char c = getchar();
    if (c & 16) {
      a = a * 10 + c - 48;
    } else {
      return a;
    }
  }
}

i64 A[1000], B[1000], C[1000];
i64 AB[3000];
signed main() {
  i32 X = read<i32>(),
      Y = read<i32>(),
      Z = read<i32>(),
      K = read<i32>();
  REP(i, X) A[i] = -read<i64>();
  REP(i, Y) B[i] = -read<i64>();
  REP(i, Z) C[i] = -read<i64>();
  sort(A, A + X);
  sort(B, B + Y);
  sort(C, C + Z);
  using P = pair<i64, i32>;
  set<P> Q, R;
  Q.insert({A[0] + B[0], 0});
  i32 L = min(K, X * Y);
  REP(i, L) {
    i64 p = (*Q.begin()).first;
    i64 q = (*Q.begin()).second;
    AB[i] = p;
    Q.erase(Q.begin());
    i32 u = q >> 10;
    i32 v = q & 1023;
    if (u + 1 < X && (u + 1) * v < L) Q.insert({A[u + 1] + B[v], q + 1024});
    if (v + 1 < Y && u * (v + 1) < L) Q.insert({A[u] + B[v + 1], q + 1});
  }
  R.insert({AB[0] + C[0], 0});
  REP(_, K) {
    i64 p = (*R.begin()).first;
    i64 q = (*R.begin()).second;
    printf("%lld\n", -p);
    R.erase(R.begin());
    i32 u = q >> 10;
    i32 v = q & 1023;
    if (u + 1 < L && (u + 1) * v < K) R.insert({AB[u + 1] + C[v], q + 1024});
    if (v + 1 < Z && u * (v + 1) < K) R.insert({AB[u] + C[v + 1], q + 1});
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b);
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

int l[2*N], r[2*N], L[2*N], R[2*N], k;
vi v, ans;

bool calc(int i, int j){
	int ans = 0;
	if(i >= 0){
		ans++;
		ans += L[i];
	} if(j < sz(v) and j != -1) {
		 ans++;
		 ans += R[j];
	}
	return ans >= k;
}

void solve(){
	int n, c;
	string s;
	cin >> n >> k >> c >> s;
	for(int i = 0; i < n; i++){
		if(s[i] == 'o')v.pb(i+1);
		l[i] = r[i] = -1;
	}
	int pos = 0;
	for(int i = 0; i < sz(v); i++){
		while(pos < sz(v) and v[i]+c >= v[pos])pos++;
		if(pos < sz(v))
			r[i] = pos;
	}
	pos = sz(v)-1;
	for(int i = sz(v)-1; i >= 0; i--){
		while(pos >= 0 and v[i]-c <= v[pos])pos--;
		if(pos >= 0)
			l[i] = pos;
	}
	for(int i = 0, j = sz(v)-1; i < sz(v); i++, j--){
		if(l[i] != -1){
			L[i]++;
			L[i] += L[l[i]];
		}
		if(r[j] != -1){
			R[j]++;
			R[j] += R[r[j]];
		}
	}
	for(int i = 0; i < sz(v); i++){
		int aux = 0;
		aux |= calc(i-1, r[i]);
		aux |= calc(l[i], i+1);
		if(i+1 < sz(v) and i-1 >= 0 and (v[i+1] - v[i-1]) >= c+1){
			aux |= calc(i-1, i+1);
		}
		if(!aux and (L[i] + R[i] + 1) >= k) ans.pb(v[i]);
	}
	for(auto i:ans)cout << i << endl;
}

int main(){
	fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 8864
#include<stdio.h>

#define N 500000

void merge(int, int, int);
void mergeSort(int, int);

int c=0;
int Q[N];
int L[N];
int R[N];

int main(){
int i, n;
  scanf("%d", &n);
  for(i=0 ; i<n ; i++) scanf("%d", &Q[i]);
  mergeSort(0, n);

  for(i=0 ; i<n-1 ; i++) printf("%d ", Q[i]);
  printf("%d\n", Q[i]);
  printf("%d\n", c);

  return 0;
}

void merge(int left, int mid, int right){
  int n1, n2, i, j, k;

  n1 = mid - left;
  n2 = right - mid;

  for(i=0 ; i<=n1-1 ; i++) L[i] = Q[left+i];
  for(i=0 ; i<=n2-1 ; i++) R[i] = Q[mid+i];

  L[n1] = 1000000000;
  R[n2] = 1000000000;
  i = 0;
  j = 0;

  for(k=left ; k<right ; k++){
    c++;
    if(L[i] <= R[j]){
      Q[k] = L[i];
      i++;
    }
    else{
      Q[k] = R[j];
      j++;
    }
  }
}

void mergeSort(int left, int right){
  int mid;

  if(left+1 < right){
    mid = (left + right) / 2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

Measured memory_bytes: 5484
def main():
    N, K  = [int(i) for i in input().split()]
    A  = [int(i) for i in input().split()]
    v = {0: 1}
    n = [0]
    r = 0
    t = 0
    for i, a in enumerate(A, 1):
        if i >= K:
            v[n[i - K]] -= 1
        t += a
        j = (t - i) % K
        r += v.get(j, 0)
        v[j] = v.get(j, 0) + 1
        n.append(j)

    return r


print(main())


Measured memory_bytes: 38948
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i
count = 0
0.upto(a) do |i|
  break if i * 500 > x
  0.upto(b) do |j|
    0.upto(c) do |k|
      sum = i * 500 + j * 100 + k * 50
      count = count + 1 if sum == x
    end
  end
end
puts count


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef long double ld;
typedef V<int> vi;

const double INF = 1e15 + 7;

struct P{
	double x, y, r;
	P(double _x=0, double _y=0, double _r=0) {
		x = _x, y = _y, r = _r;
	}
} a[1024];

double dist(int i, int j) {
	return max(0., sqrt(pow(a[i].x - a[j].x, 2) + pow(a[i].y - a[j].y, 2)) - a[i].r - a[j].r);
}

double d[1024];
bool used[1024];

int32_t main()
{
	IO_OP;
	
	int n, xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt >> n;
	a[0] = P(xs, ys);
	for(int i=1;i<=n;i++) {
		int x, y, r;
		cin >> x >> y >> r;
		a[i] = P(x, y, r);
	}	
	a[++n] = P(xt, yt);
	for(int i=1;i<=n;i++)
		d[i] = INF;
	for(int i=1;i<=n;i++) {
		int k, mn = INF;
		for(int j=0;j<=n;j++) {
			if(!used[j] && d[j] < mn) {
				mn = d[j];
				k = j;
			}
		}
		for(int j=0;j<=n;j++) {
			if(j == k) continue;
			if(d[k] + dist(k, j) < d[j]) {
				d[j] = d[k] + dist(k, j);
				used[j] = 0;
			}
		}
		used[k] = 1;
	}
	cout << fixed << setprecision(10) << d[n] << endl;
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	for {
		var n, x int
		fmt.Scan(&n, &x)
		if n == 0 && x == 0 {
			break
		}
		ans := 0
		for i := 1; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				for k := j + 1; k <= n; k++ {
					if i+j+k == x {
						ans++
					}
				}
			}
		}
		fmt.Println(ans)
	}
}



Measured memory_bytes: 1124
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
 
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
#ifdef _MSC_VER
	freopen("e.in", "r", stdin);
#endif
	std::ios::sync_with_stdio(false);
	int n, m, c;
	cin >> n >> m >> c;
	vector<pair<int, int>> sx(n), sy(m);
	for (int i = 0; i < n; i++) {
		sx[i].second = i;
	}
	for (int i = 0; i < m; i++) {
		sy[i].second = i;
	}
	set<pair<int, int>> a;
	for (int i = 0; i < c; i++) {
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		++sx[x].first;
		++sy[y].first;
		a.insert(make_pair(x, y));
	}
	sort(sx.rbegin(), sx.rend());
	sort(sy.rbegin(), sy.rend());
	int ret = 0;
	for (const auto& gx : sx) {
		for (const auto& gy : sy) {
			int d = a.count(make_pair(gx.second, gy.second));
			ret = max(ret, gx.first + gy.first - d);
			if (d == 0) {
				break;
			}
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 21964
#include <cstdio>
#include <algorithm>
#include <iostream>
#define lowbit(i) (i&(-i))
using namespace std;
const int maxn = 2e5+5;
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
signed main (){
	string s;
	cin>>s;
	if(s=="ABC")
		cout<<"ARC";
	else
		cout<<"ABC";
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
int M = 1e9 + 7;
#define PI 3.1415926535
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long double a, b, h, m;
  cin >> a >> b >> h >> m;
  long double dh = h * 30.0 + m * 0.5;
  long double dm = m * 6.0;
  long double theta = abs(dh - dm);
  long double ans = a * a + b * b - (2.0) * a * b * (cos ( theta * PI / 180.0 ));
  ans = sqrt(ans);
  cout << fixed << setprecision(13) << ans ;
}

Measured memory_bytes: 4184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

//素因数分解
template <class T>
map<T,T> prime_factor(T x){
	map<T,T> ans;
	for(T i=2;i*i<=x;i++){
		while(x%i==0){
			x/=i;
			ans[i]++;
		}
	}
	if (x!=1){
		ans[x]=1;
	}
	return ans;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	ll g=0;
	map<ll,ll> mp;
	rep(i,n){
		cin>>a[i];
		g=gcd(g,a[i]);
		map<ll,ll> ret=prime_factor(a[i]);
		for(auto [x,y]:ret){
			mp[x]++;
		}
	}
	if(g!=1){
		cout<<"not coprime"<<endl;
		return 0;
	}
	for(auto [x,y]:mp){
		if(y>=2){
			cout<<"setwise coprime"<<endl;
			return 0;
		}
	}
	cout<<"pairwise coprime"<<endl;
}

Measured memory_bytes: 15804
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll p,q,r;
  cin >> p >> q >> r;
  cout << min(p+q, min(p+r, min(q+r, 1000LL))) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

int main(){
    int N;
    cin >> N;
    int fx;
    
    string S;
    S = to_string(N);
    vector<int> a;
    for(int i = 0; i < S.length(); i++){
        a.push_back(S[i] - '0');
    }
    
    fx = accumulate(a.begin(), a.end(), 0);
    
    if(N % fx == 0){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

Measured memory_bytes: 256
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String s = "0123456789ABCDEF";
		String a = sc.next(), b = sc.next();
		System.out.println(s.indexOf(a)==s.indexOf(b) ? '=' : s.indexOf(a)<s.indexOf(b) ? '<' : '>');
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35288
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
long long n;
int ans;
int main()
{
	scanf("%lld",&n);
	n++;
	while(n>=10)
	{
		ans+=9;
		n/=10;
	}
	ans+=n-1;
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n=sc.nextLong(),m=sc.nextLong();
        if(n==1&&m==1){
            System.out.println(1);
        }else if(n==1||m==1){
            System.out.println(n*m-2);
        }else{
            System.out.println((n-2)*(m-2));
        }
        
    }
}

Measured memory_bytes: 23764
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static class Edge {
		int to, cost;

		public Edge(int to, int cost) {
			this.to = to;
			this.cost = cost;
		}
	}

	static List<Edge>[] g;
	static int[] color;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt(); // 頂点数
		g = new ArrayList[N + 1]; // 辺の情報
		color = new int[N + 1]; // 塗る色

		for (int i = 0; i < N + 1; i++) {
			g[i] = new ArrayList<Edge>();
		}

		for (int i = 0; i < N - 1; i++) { // 辺はN-1本
			int u = sc.nextInt();
			int v = sc.nextInt();
			int w = sc.nextInt();
			g[u].add(new Edge(v, w));
			g[v].add(new Edge(u, w));
		}

		dfs(1, 0, 0);

		for (int i = 1; i < N + 1; i++) {
			System.out.println(color[i]);
		}

		sc.close();
	}

	public static void dfs(int u, int parent, long sum) {
		color[u] = (int) (sum % 2l);
		for (Edge e : g[u]) {
			if (e.to == parent) {
				continue;
			}
			dfs(e.to, u, sum + e.cost);
		}
	}

}


Measured memory_bytes: 109072
#include<stdio.h>
#include<string.h>

int main(){
	//?????¨???????????°?????£?¨?
	int a, b, n, x, y, i, j;
	//????????°??????????????????????????£?¨?
	int dp[17][17];
	//while?????§??\?????????????????§????????????
	while( scanf("%d %d", &a, &b) != EOF && a && b ){
		
		//????????°????????????
		memset( dp, -1, sizeof(dp) );
		
		//?????????????????????????????°???????????????
		scanf( "%d", &n );
		
		//???????????????????????????????????????????????¨???????????????????????°???0?????????
		for( i = 0; i <= a; i++ ){
			dp[i][0] = 0;
		}
		for( i = 0; i <= b; i++ ){
			dp[0][i] = 0;
		}
		
		dp[1][1] = 1; //?????????????????????????????°???1?????????
		
		for( i = 0; i < n; i++ ){
			//????????????????????????????????????????????????
			scanf( "%d %d", &x, &y );
			
			//???????????????????????????????????°???0?????????
			dp[x][y] = 0;
		}
		for( i = 1; i <= a; i++ ){ 
			for( j = 1; j <= b; j++ ){
				//????????°????????§???????????????????????´????¨???????????????????
				if( dp[i][j] != -1 ){
					continue;
				}
				
				//?????¨??°??????????????°????????????????????????????????°??¨?????????????????????????????°???????¨?
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			}
		}
		
		//????????°???????????????
		printf( "%d\n", dp[a][b] );
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
vector<pair<int,int> > v;
int ds[100010];
vector<int> G[100010];
map<pair<int,int>,int> mp;
bool flag=false;
bool vis[100010];
void dfs(int now){
    vis[now]=1;
    if(ds[now]%2==1){
        flag=!flag;
    }
    for(int i=0;i<G[now].size();i++){
        if(vis[G[now][i]]) continue;
        if(flag) {
            mp[make_pair(now,G[now][i])]++;
            dfs(G[now][i]);
            if(flag){
                mp[make_pair(now,G[now][i])]++;
            }
        }else{
            dfs(G[now][i]);
            if(flag){
                 mp[make_pair(now,G[now][i])]++;
            }
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,tv;scanf("%d%d",&u,&tv);
        v.push_back(make_pair(u,tv));
        ds[u]++;
    }
    if(m%2==1){
        return 0*puts("-1");
    }
    for(int i=0;i<v.size();i++){
        G[v[i].first].push_back(v[i].second);
        G[v[i].second].push_back(v[i].first);
    }
    dfs(1);
    for(int i=0;i<v.size();i++){
        if((mp[make_pair(v[i].first,v[i].second)]+mp[make_pair(v[i].second,v[i].first)])%2==1)
        {
            cout<<v[i].second<<" "<<v[i].first<<endl;
        }else{
            cout<<v[i].first<<" "<<v[i].second<<endl;
        }
    }






    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> h(N), dp(N);
  REP(i, N) cin >> h[i];

  dp[0] = 0;

  for (int i = 1; i < N; i++) {
    if (i == 1) {
      dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
    } else {
      dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
                  dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  }

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

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}

template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
	string s;
	cin>>s;
	string t="abcdefghijklmnopqrstuvwxyz";
	map<char,bool>used;
	int n=s.size();
	rep(i,s.size()){
		used[s[i]]=s[i]==s[i];
	}
	if(n==26){
		if(s=="zyxwvutsrqponmlkjihgfedcba"){
			cout<<-1<<endl;
		}else{
			string ss=s;
			rep(i,26){
				bool ans=false;
				int ite=25-i;
				rep(j,26){
					string tmp=ss;
					tmp[ite]=t[j];
					if(tmp>s&&!used[t[j]]){
						cout<<tmp<<endl;
						ans=true;
						j=26;
						i=26;
					}
				}
				if(!ans){
					used[ss[ite]]=false;
					ss.pop_back();
				}
			}
		}
	}else{
		
		rep(i,26){
			string tmp=s;
			tmp.push_back(t[i]);
			if(tmp>s&&!used[t[i]]){
				cout<<tmp<<endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  int points[n][3];
  for(int i=0;i<n;i++)
    for(int j=0;j<3;j++)
      cin>>points[i][j];
  for(int i=1;i<n;i++)
  {
  	points[i][0]+=(points[i-1][1]>points[i-1][2]?points[i-1][1]:points[i-1][2]);
  	points[i][1]+=(points[i-1][0]>points[i-1][2]?points[i-1][0]:points[i-1][2]);
  	points[i][2]+=(points[i-1][1]>points[i-1][0]?points[i-1][1]:points[i-1][0]);
  }
  int max=points[n-1][0];
  for(int i=1;i<3;i++)
  	if(points[n-1][i]>max)
  		max=points[n-1][i];
  cout<<max<<endl;
  return 0;
}

Measured memory_bytes: 1408
import sys
s = input()
t = input()
#s = "contest"
#t = "son"

wrap_count = 0
index = -1

for c in t:
    index = s.find(c, index+1)
    if index != -1:
        continue
    wrap_count += 1
    index = s.find(c)
    if index == -1:
        print(-1)
        sys.exit()

print(len(s) * wrap_count + index + 1)

Measured memory_bytes: 3316
def binn(n):
    if n == 0: return
    r = n % -2
    if r != 0:
        r = 1
    binn((n - r) // -2)
    print(r, end="")

n = int(input())
if n == 0:
    print(0)
else:
    binn(n)
    print()



Measured memory_bytes: 38384
import Data.Array.IO

main :: IO ()
main = do
  [n, x] <- (map read . words) <$> getLine :: IO [Int]
  as <- (map read . words) <$> getLine :: IO [Int]
  asArr <- newListArray (0, n - 1) as :: IO (IOArray Int Int)
  print =<< solve asArr 1 n x 0

solve :: IOArray Int Int -> Int -> Int -> Int -> Int -> IO Int
solve asArr ptr n x cnt
  | ptr == n = return cnt
  | otherwise = do
      a0 <- readArray asArr (ptr - 1)
      a1 <- readArray asArr ptr
      if a0 + a1 <= x
        then solve asArr (ptr + 1) n x cnt
        else do
          let toEat = (a0 + a1 - x)
          if a1 >= toEat
            then do
              writeArray asArr ptr (a1 - toEat)
              solve asArr (ptr + 1) n x (cnt + toEat)
            else do
              writeArray asArr ptr 0
              writeArray asArr (ptr - 1) (a0 - (toEat - a1))
              solve asArr (ptr + 1) n x (cnt + toEat)


Measured memory_bytes: 61820
# include <stdio.h>
int a[103], b[103];
int main()
{
    int p1=0, p2=0, m=100;
    long long n;
    scanf("%lld",&n);
    ++n;
    while(n > 1)
    {
        if(n&1) a[++p1] = m--, --n;
        else b[++p2] = m--, n>>=1;
    }
    printf("%d\n",p1+p2<<1);
    for(int i=1; i<=p1; ++i)
        printf("%d ",a[i]);
    for(int i=p2; i>=1; --i)
        printf("%d ",b[i]);
    for(int i=101-p1-p2; i<=100; ++i)
        printf("%d ",i);
    puts("");
    return 0;
}

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

#define int long long

using namespace std;

 main () {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	int len = n - 1;
	for (int i = 0;i <= len;i ++) {
		int j = len - i;
		int l1 = a + c * i;
		int r1 = a + d * i;
		int l2 = c * j;
		int r2 = d * j;
		l1 -= r2;
		r1 -= l2;
		if (l1 <= b && b <= r1) {
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
	return 0;
}

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

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

  int n, m, p, v, a[100100];
  cin >> n >> m >> v >> p;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + n + 1, greater<int>());

  vector<long long> sum(n + 1, 0);
  for (int i = 1; i <= n; i++)
    sum[i] = sum[i - 1] + a[i];

  int ans = 0;
  for (int i = 1; i <= n;)
  {
    int j = i;
    while (j <= n && a[j] == a[i])
      j++;

    if (i <= p) ans += j - i;
    else if (a[i] + m >= a[p])
    {
      long long canVote = (n - i + 1LL) * m;
      canVote += (i - p - 1LL) * (a[i] + m) - (sum[i - 1] - sum[p]);
      canVote += (p - 1LL) * m;
      canVote += a[i] + m - a[p];
      if (canVote >= 1LL * m * v)
        ans += j - i;
    }
    i = j;
  }

  cout << ans << endl;
}


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

int main() {
int k,n;
cin >> k >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
a.push_back(a[0]+k);
int l = 0;
rep(i,n){
  l = max(l,a[i+1]-a[i]);
}
int ans = k-l;
cout << ans << endl;

}

Measured memory_bytes: 1792
#include <complex>
#include <cstdio>
using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std{
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const P& a, const P& b) {
	return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}
bool in_triangle(const P& p1,const P& p2,const P& p3,const P& p){
	return cross(p2-p1,p-p1)>0 && cross(p3-p2,p-p2)>0 && cross(p1-p3,p-p3)>0;
}
int main(){
	double x1,y1,x2,y2,x3,y3,x,y;
	for(;~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x,&y);){
		P p1(x1,y1),p2(x2,y2),p3(x3,y3),p(x,y);
		bool in=in_triangle(p1,p2,p3,p)||in_triangle(p2,p1,p3,p);
		puts(in?"YES":"NO");
	}
}

Measured memory_bytes: 1044
#include <stdio.h>

int main(void){
    int a[100], i, j, n, tmp, k;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for(k = 0; k < n; k++)
    {
        if(k > 0) printf(" ");
        printf("%d", a[k]);
    }
    printf("\n");

    for (i = 1; i < n; i++)
    {
        tmp = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > tmp)
        {
            a[j + 1] = a[j];
            j--;
            a[j + 1] = tmp;
        }
        for(k = 0; k < n; k++)
        {
            if(k > 0) printf(" ");
            printf("%d", a[k]);
        }
        printf("\n");
    }
    return 0;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
#define dpair pair<double,double>

template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
template <typename Val>
void show_vec(vector<Val> *v){
  cout<<endl;
  rep(i,v->size()){
    cout<<v->at(i)<<" ";
  }
  cout<<endl;
}
//---------------------------------------------------------------
int main(){

  int X,N,ans,det;
  cin>>X>>N;

if(N!=0){
  vec p(N);
  det = 1000;
  rep(i,N){
    cin>>p.at(i);
  }
  int i = -10;
  int ind = 0;
  sort(p.begin(),p.end());
  while(1){
    if(i!=p.at(ind)){
      if(abs(X-i)<det){
        ans = i;
        det = abs(X-i);
      }else if(abs(X-i)==det){
        if(i<ans)ans = i;
      }
    }else if(ind<N-1){
      ind++;
    }
    i++;
    if(i==110)break;

  }
}else{
  ans = X;
}

  cout<<ans<<endl;




}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int w,h,n; cin >> w >> h >> n;
  vector<int> x(n),y(n),a(n);
  set<P<int,int>>st;
  for(int i = 0; i < n; ++i)cin >> x[i] >> y[i] >> a[i];
  for(int i = 0; i < n; ++i){    
    for(int j = 1; j <= w; ++j){
      for(int k = 1; k <= h; ++k){
	if(a[i] == 1 && j <= x[i])st.emplace(j,k);
	if(a[i] == 2 && j > x[i])st.emplace(j,k);
	if(a[i] == 3 && k <= y[i])st.emplace(j,k);
	if(a[i] == 4 && k > y[i])st.emplace(j,k);
      }
    }
  }
  cout << w*h - st.size() << endl;
  return 0;
}


Measured memory_bytes: 4028
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    grid = [[True for _ in range(n)] for _ in range(n)]

    # KeyInsight
    # 補グラフ
    if n % 2 == 0:
        for i in range(n):
            grid[i][n - i - 1] = False
    else:
        for i in range(n):
            grid[i][n - i - 2] = False

    ans = list()

    for i in range(n):
        for j in range(i, n):
            if i != j and grid[i][j]:
                ans.append((i, j))

    print(len(ans))

    for ai, bi in ans:
        print(ai + 1, bi + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3996
n = int(input())
a = [int(input()) for _ in range(n)]

left = [a[0]]
right = [a[-1]]
for i in range(1, n):
    left.append(max(left[i-1], a[i]))
    right.append(max(right[i-1], a[n-i-1]))
right = right[::-1]
print(right[1])

for i in range(1, n-1):
    print(max(left[i-1], right[i+1]))
print(left[-2])

Measured memory_bytes: 15744
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,x,i,j,cc=0;
    cin>>n;
    ll ara[n];
    ll mx=-1;
    for(i=0;i<n;i++){
        cin>>ara[i];
        if(ara[i]>mx){
            mx=ara[i];
            j=i;
        }
    }
    ll mx2=-1;
    ll k=0;
    for(i=0;i<n;i++){
        if(i==j)continue;
        if(ara[i]>mx2){
            mx2=ara[i];
            k=i;
        }
    }
    for(i=0;i<n;i++){
        if(i==j)cout<<mx2<<endl;
        else cout<<mx<<endl;
    }
return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n = 100000, z[100005] = {}, q, l, r;
    vector<int> p;
    vector<bool> b(100000);
    b[0] = b[1] = 1;
    for (int i = 2; i < n; i++) {
        if (!b[i]) p.push_back(i);
        for(int j = 0, s = (int)p.size(); j < s && i * p[j] < n; j++) {
            b[p[j] * i] = 1;
            if (i % p[j] == 0) break;
        }
    }
    for (int i = 3; i < 100000; i++, i++) if (!b[i] && !b[i / 2 + 1]) z[i] = 1;
    for (int i = 1; i <= 100000; i++) z[i] += z[i - 1];
    cin >> q;
    while (q--) cin >> l >> r, cout << z[r] - z[l - 1] << '\n';
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は２つの値の組を表せる

int main(){
    int A,B; cin >> A >> B;
    for (int i=1; i<=1009; i++){
        if (floor(i*0.08)==A && floor(i*0.1)==B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256