akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void print(int A[], int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		printf("%d", A[i]);
		if (i != n - 1)
			printf(" ");
	}
	printf("\n");
}

void insertionSort(int A[], int N)
{
	int i, j,tmp;

	for (i = 1; i < N; i++)
	{
		j = i;
		while (j > 0 && A[j - 1] > A[j])
		{
			tmp = A[j - 1];
			A[j - 1] = A[j];
			A[j] = tmp;

			j--;
		}
		print(A, N);
	}
}

void bubbleSort(int A[], int N,int *count)
{
	int flag = 0;
	int i, j,tmp;

	for (i = 0; i < N; i++)
	{
		for (j = N - 1; j > 0; j--)
		{
			if (A[j - 1] > A[j])
			{
				tmp = A[j - 1];
				A[j - 1] = A[j];
				A[j] = tmp;
				flag = 1;
				(*count)++;
			}
		}
		if (flag == 0)
			break;
		else
			flag = 0;
	}
}

void selectionSort(int A[], int N,int *count)
{
	int i, j;
	int key,tmp;

	for (i = 0; i < N; i++)
	{
		key = i;
		for (j = i; j < N; j++)
		{
			if (A[j] < A[key])
				key = j;
		}
		if (i != key)
		{
			tmp = A[i];
			A[i] = A[key];
			A[key] = tmp;
			(*count)++;
		}
	}
}


int binary_search(int A[], int N, int key)
{
	int left, right, middle;

	left = 0, right = N - 1;

	while (left <= right)
	{
		middle = (left + right) / 2;
		if (A[middle] == key)
			return 1;
		else if (A[middle] > key)
			right = middle - 1;
		else if (A[middle] < key)
			left = middle + 1;
	}
	return 0;
}

#define SIZE 1000

int stack[SIZE];
int pos;

void init()
{
	pos = 0;
}

int isEmpty()
{
	if (pos == SIZE)
	{
		printf("ERROR\n");
		return 1;
	}
	return 0;
}

void push(int x)
{
	stack[pos++] = x;
}

int pop()
{
	int x;
	x = stack[--pos];

	return x;
}

int main()
{
	char t;
	int x, y;

	while (scanf("%s", &t) != EOF)
	{
		switch (t)
		{
			case '+':
			{
				x = pop();
				y = pop();
				push(y + x);
				break;
			}
			case '-':
			{
				x = pop();
				y = pop();
				push(y - x);
				break;
			}
			case '*':
			{
				x = pop();
				y = pop();
				push(y * x);
				break;
			}
			default:
			{
				push(atoi(&t));
				break;
			}
		}
	}

	printf("%d\n", stack[0]);

	return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  int ret = 0;
  rep(i,N){
    int a;
    cin >> a;

    if((i+1)%2==1 && a%2==1) ret++;
  }
  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 3620
//#include <bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int n,m;
int a[200001];
int main(){
    cin>>n>>m;
    int mx=0;
    for(int i=0;i<m;i++){
        scanf("%d",&a[i]);
    }
    a[m]=n+a[0];
    for(int i=1;i<=m;i++)
        mx=max(a[i]-a[i-1],mx);
    
    cout<<n-mx;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define maxl __LONG_LONG_MAX__
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for(int i = 0; i < n; i++)
#define rev(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i=1; i < n; i++)
#define rev1(i, n) for(int i=n ; i > 0; i--)
#define FOR(i, a, b) for(int i=a ; i < b; i++)
#define trace(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 n_ones(x) __builtin_popcountll(x)
#define n_trailzero(x) __builtin_ctzll(x)
#define n_leadingzero(x) __builtin_clz(x)
#define sz(a) (ll)(a.size())
#define all(v) v.begin(),v.end()

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef stack<ll> stk;
typedef queue<ll> que;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_setll;
typedef tree<char,null_type,less<char>,rb_tree_tag,
tree_order_statistics_node_update> indexed_setc;

ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);} 
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}

ll mod = 1e9 + 7;
ld PI = 3.14159265358979;
void solve()
{	
	ld r;
	cin>>r;
	cout<<setprecision(9)<<2 * PI * r<<endl;
	return;
}

int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
	ll t = 1;
	//cin>>t;
	rep(i, t)
		solve();
	return 0;
	
}

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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    int maxABC = max(A, max(B, C));
    int minABC = min(A, min(B, C));
    int sum = A + B + C;
    if (3 * maxABC % 2 == sum % 2)
    {
        cout << (maxABC * 3 - sum) / 2 << endl;
        return 0;
    }
    else
    {
        cout << ((maxABC+1) * 3 - sum) / 2 << endl;
        return 0;
    }
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector <long long> a(n), b(n);
    long long s = 0;
    for (int j = 0; j < n; j++) {
        cin >> a[j];
    }
    for (int j = 0; j < n; j++) {
        cin >> b[j];
    }
    for (int j = 0; j < n; j++) {
        if (b[j] > a[j]) {
            s += b[j] - a[j] >> 1;
        }
        else {
            s -= a[j] - b[j];
        }
    }
    if (s < 0)
        cout << "No";
    else
        cout << "Yes";
}


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

typedef long long LL;
#define dbg(x) cerr << #x"=" << x << endl;
const int MAX_N = 2100;
const int MOD = 1e9+7;
LL C[MAX_N][MAX_N];

int main(){
   // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    for(int i = 0; i < MAX_N; ++i) {
        C[i][0] = 1;
        C[i][i] = 1;
    }
    for(int i = 1; i < MAX_N; ++i){
        for(int j = 1; j < i; ++j){
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD; 
        }
    }
    int N,K;
    cin >> N >> K;
    for(int i = 1; i <= K; ++i){
        int a = N-K-i+1;
        if(a < 0) {
            cout << 0 << endl;
        } else {
            cout << C[K-1][i-1] * C[N-K+1][i] % MOD << endl; 
        }
    }
    return 0;
}

Measured memory_bytes: 33280
from collections import Counter,defaultdict
import sys,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,w = inpl()
ww = [0] * n
vv = [0] * n
for i in range(n):
    ww[i],vv[i] = inpl()
dp = [[mod for i in range(sum(vv)+1)] for j in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(sum(vv)+1):
        if j >= vv[i]:
            dp[i+1][j] = min(dp[i][j], dp[i][j-vv[i]]+ww[i])
        else:
            dp[i+1][j] = dp[i][j]
for i in range(sum(vv)+1)[::-1]:
    if dp[n][i] <= w:
        print(i)
        break



            


Measured memory_bytes: 169132
#include <iostream>
#include <string.h>
using namespace std;
int main(){
    int K,l;
    string S;
    cin >> K >> S;
    l = S.length();
    if (l > K){
        for(int i = 0; i < K; i++){
            cout << S[i];
        }
        cout << "..." << endl;
    }else {
        cout << S << endl;
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  vector<int> ans(N);
  for(int i=0; i<N; i++){
    ans.at(a.at(i)-1) = i+1;
  }
  for(int i=0; i<N; i++){
    cout << ans.at(i) << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

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

ll n;
vector<ll> a(3), b(3);

ll dp[30000000];

ll calc(vector<ll> buy, vector<ll> sell, ll m) {
    memset(dp, 0, sizeof(dp));
    rep(i, (int)buy.size()) {
        for(ll v = 0; v + buy[i] <= m; v++) {
            chmax(dp[v + buy[i]], dp[v] + sell[i]);
        }
    }

    ll res = m;
    for(ll v = 0; v <= m; v++) chmax(res, dp[v] + m - v);
    return res;
}

void solve() {
    cin >> n;
    rep(i, 3) cin >> a[i];
    rep(i, 3) cin >> b[i];

    n = calc(a, b, n);
    n = calc(b, a, n);

    cout << n << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 234752
<?php
fscanf(STDIN, '%d', $N);
$info = array();
$subInfo = array();
for($i = 1; $i < $N; $i++) {
	fscanf(STDIN, "%d %d %d", $C, $S, $F);
	array_push($subInfo, $C);
	array_push($subInfo, $S);
	array_push($subInfo, $F);
	array_push($info, $subInfo);
	$subInfo = array();
}

$ans = array();
$bound = 0;
for($i = 1; $i < $N; $i++) {
	$midSum = 0;
	for($j = $bound; $j < ($N-1); $j++) {
		if ($j === $bound) {
			$midSum = $info[$j][0] + $info[$j][1];
		} else {
			if ($midSum > $info[$j][1]) {
				if($midSum%$info[$j][2] === 0){
					$midSum += $info[$j][0];
				} else {
					$midSum = $midSum + ($info[$j][2] - $midSum%$info[$j][2]) + $info[$j][0];
				}
			} else if ($midSum === $info[$j][1]) {
				$midSum += $info[$j][0];
			} else {
				$midSum = $info[$j][1];
				$midSum += $info[$j][0];
			}
		}
	}
	array_push($ans, $midSum);
	$bound++;
}

array_push($ans, 0);
foreach ($ans as $num) {
	echo $num.PHP_EOL;
}

Measured memory_bytes: 4728
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll inf = (1 << 29);
template<typename T>
T GCD(T a, T b) {
	while (max(a, b) % min(a, b)) {
		if (a > b)a = a % b;
		else b = b % a;
	}
	return min(a, b);
}
template<typename T>
T LCM(T a, T b) {
	return a / GCD(a, b)*b;
}
bool prime(ll a) {
	for (int i = 2; i <= sqrt(a); i++) {
		if (!(a%i))return false;
	}
	return true;
}
int main() {
	ll a, b;
	cin >> a >> b;
	cout << (a - 1)*(b - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
    int n,m,i,j,k,flag=1;
    scanf("%d%d", &n,&m);
    char a[n][n], b[m][m];
    for(i=0; i<n; i++) scanf("%s", &a[i][0]);
    for(i=0; i<m; i++) scanf("%s", &b[i][0]);
    for(i=0; i<=n-m; i++)
    {
        for(j=0; j<=n-m; j++)
        {
            flag=1;
            for(k=0; k<m; k++)
            {
                if(strncmp(&a[i+k][j], &b[k][0], m)!=0)
                {
                    flag=0;
                    break;
                }
            }
            if(flag==1)
            {
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //StringBuilder bd = new StringBuilder();
        //ArrayList<Integer> A = new ArrayList<Integer>();
        int[] A = new int[26];
        Arrays.fill(A, 0);
        String str;

        boolean flag = false;

        String s = sc.next();
        String t = sc.next();

        s = s + s;

        for (int i=0; i<s.length()/2; i++) {
            if (s.substring(i, i+t.length()).equals(t)) {
                System.out.println("Yes");
                flag = true;
                break;
            }
        }
        if (flag == false) {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 26308
#include <iostream>
#include <cmath>

int main()
{
  int N;
  std::cin >> N;
  int A[N];
  for ( int i = 0; i < N; i++ ) std::cin >> A[i];

  int ans = 0;

  for ( int i = 0; i < N; i++ ) {
    for ( int j = i+1; j < N; j++ ) {
      int diff = std::abs(A[i] - A[j]); 
      if ( ans < diff ) {
        ans = diff;
      }
    }
  }

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


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

using I = long long;

int main() {
  int N;
  cin >> N;
  vector<vector<int>> B(N, vector<int>(2));
  for(auto& i: B) cin >> i[0] >> i[1], sort(begin(i), end(i));
  sort(begin(B), end(B));

  I l = (*min_element(begin(B), end(B), [](auto l, auto r) {return l[1] < r[1];}))[1];
  I h = (*max_element(begin(B), end(B), [](auto l, auto r) {return l[1] < r[1];}))[1];
  I ans = (B[N-1][0]-B[0][0]) * (h-l);
  multiset<I> S;
  for(auto i: B) S.emplace(i[0]);
  I d = h - B[0][0];
  for(auto i: B) {
    S.erase(S.find(i[0]));
    S.emplace(i[1]);
    ans = min(ans, d*(*rbegin(S)-*begin(S)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 20608
import numpy as np

D = int(input())

C = ([int(x) for x in input().split()])

for d in range(D):
        exec('s{} = ([int(x) for x in input().split()])'.format(d))

d = 0
lday = np.array([0] * 26)
C = np.array(C)

while d != D:
    exec("curs = np.array(s{})".format(d))
    pos_max_i = np.argmax(curs)
    decl = C * ( np.array([d]*26 ) - lday )
    neg_min_i = np.argmin(decl)
    if np.abs(curs[pos_max_i]) > np.abs(decl[neg_min_i]):
        lday[pos_max_i] = d
        print(pos_max_i+1)
    else:
        lday[neg_min_i] = d
        print(neg_min_i+1)
    d += 1

Measured memory_bytes: 27400
#include<iostream>
#include<stack>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if(a<=b){cout<<"Impossible"<<endl;return 0;}
	stack<int> s;
	char c[10];
	int n=a+b;
	s.push(0);
	for(int i=1;i<n;i++)
		if(!s.empty())
		{
			int u=s.top();
			cout<<"? "<<u<<' '<<i<<endl;
			cin>>c;
			if(c[0]=='N')s.pop();
			else s.push(i);
		}
		else s.push(i);
	string ans;
	for(int i=0;i<n;i++)
	{
		cout<<"? "<<s.top()<<' '<<i<<endl;
		cin>>c;
		ans+=c[0]=='Y'?'1':'0';
	}
	cout<<"! "<<ans<<endl;
	return 0;
}

Measured memory_bytes: 724
N = int(input())
ABC = [list(map(int, input().split())) for i in range(N)]
INF = 1 << 100
dp = [[0] * 3 for i in range(N + 1)]
for i in range(1, N+1):
    for j in range(3):
        for k in range(3):
            if j == k : continue
            dp[i][k] = max(ABC[i-1][k] + dp[i - 1][j], dp[i][k])
print(max(dp[N]))

Measured memory_bytes: 47344
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 505
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n,r[M];
double X[M],ans;
int main()
{
	while(~scanf("%d",&n))
	{
		REP(i,1,n) RI(r[i]);
		X[1] = r[1];
		
		REP(i,2,n)
		{
			X[i] = r[i];
			
			REP(j,1,i-1)
			{
				double lim = r[j] + r[i];
				lim *= lim;
				lim -= pow(abs(r[j]-r[i]), 2);
				lim = sqrt(lim);

				X[i] = max(X[i], X[j]+lim);
			}
		}

		ans=0.0;
		REP(i,1,n)
		{
			ans = max(ans, X[i]+r[i]);
		}
		printf("%.10f\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3232
N,C,K=map(int,input().split())
import heapq
T=[]
heapq.heapify(T)
for i in range(N):
    heapq.heappush(T,int(input()))

ans=1
p=1
start=heapq.heappop(T)

for i in range(N-1):
    t=heapq.heappop(T)
    p+=1
    if p<=C and t<=start+K:
        continue
    else:
        start=t
        ans+=1
        p=1

print(ans)

Measured memory_bytes: 55256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int cnt=100000;
  rep(i,0,n+1){
    int c=i;
    int d=n-i;
    int cur=0;
    while(c>0){
      cur+=c%6;
      c/=6;
    }
    while(d>0){
      cur+=d%9;
      d/=9;
    }
    cnt=min(cnt,cur);
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N; cin >> N;
	string S; cin >> S;
	int mp[5000];
	int sum[3][5000] = { 0 };
	int ans = 0;
	REP(i, N) {
		if (S[i] == 'R') {
			mp[i] = 0;
			sum[0][i + 1]++;
		}
		if (S[i] == 'G') {
			mp[i] = 1;
			sum[1][i + 1]++;
		}
		if (S[i] == 'B') {
			mp[i] = 2;
			sum[2][i + 1]++;
		}
		sum[0][i + 1] += sum[0][i];
		sum[1][i + 1] += sum[1][i];
		sum[2][i + 1] += sum[2][i];
	}

	REP(i, N - 2) {
		if (mp[i] == 0) {
			ans += (sum[1][N] - sum[1][i])*(sum[2][N] - sum[2][i]);
		}
		if (mp[i] == 1) {
			ans += (sum[2][N] - sum[2][i])*(sum[0][N] - sum[0][i]);
		}
		if (mp[i] == 2) {
			ans += (sum[1][N] - sum[1][i])*(sum[0][N] - sum[0][i]);
		}
		//cout << ans << endl;
		FOR(j, 1, N) {
			if (i + j * 2 >= N)break;
			if (S[i] != S[i + j] && S[i] != S[i + j * 2] && S[j + i] != S[i + j * 2]) {
				ans--;
			}
		}
		//cout << ans << endl;


	}





	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3788
N=int(input())
A=list(map(int,input().split()))
m=1000
num=0
for x in range(N-1):
  if A[x]>A[x+1]:
    m+=A[x]*num
    num=0
  elif A[x]<A[x+1]:
    num+=m//A[x]    
    m-=A[x]*(m//A[x])
m+=A[N-1]*num
print(m)

Measured memory_bytes: 9188
n = input()
a = list(map(int, input().split()))
c = 0

def d(a, c):
    for index, item in enumerate(a):
        if item % 2 == 0:
            a[index] = int(item / 2)
        else:
            return c
    c += 1
    return d(a, c)

print(d(a, c))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(ll i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(ll i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

#define print(d, arr) REP(i, d) cout << arr[i] << " "; cout << endl;
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }

int main() {
    ll N, p[50];
    cin >> N;
    
    ll count = 0;
    REP(i, N) {
        cin >> p[i];
        if (i + 1 != p[i]) {
            count++;
        }
    }
    
    if (count == 0 || count == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}


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

int main(){
	long long n,l,t;
	scanf("%lld%lld%lld",&n,&l,&t);
	pair<long long,int> x[n];int w;
	for(int i=0;i<n;i++){
		scanf("%lld%d",&x[i].first,&w);
		x[i].second=(w==1?1:-1);
	}
	long long ans[n],offset=0;
	for(int i=0;i<n;i++){
		ans[i]=x[i].first+x[i].second*t;
		offset+=(ans[i]>0?ans[i]:ans[i]-l+1)/l;
		ans[i]%=l;ans[i]+=l;ans[i]%=l;
	}
	offset%=n;offset+=n;offset%=n;
	sort(ans,ans+n);
	for(int i=0;i<n;i++){
		printf("%lld\n",ans[(i+offset)%n]);
	}
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <sstream>
#include <climits>
#include <fstream>
#include <cmath>

using namespace std;

/// ********* debug template by Bidhan Roy *********

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const unordered_set< T > &v ) {
    os << "[";
    typename unordered_set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const unordered_map< F, S > &v ) {
    os << "[";
    typename unordered_map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    } 
    return os << "]";
}

#define debug(x) cerr << #x << " = " << x << endl;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<bool> VB;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<LL> VLL;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<VB> VVB;
typedef vector<VI> VVI;
typedef vector<VC> VVC;
typedef vector<VLL> VVLL;
typedef vector<VD> VVD;
typedef vector<VS> VVS;

// TEMPLATE DEFINITIONS END

int a, b, c;

void read_input(){
    cin >> a >> b >> c;
}

void solve(){

    if(a == b && a == c){
        cout << "No\n";
    }else
    if(a != b && a != c && b != c){
        cout << "No\n";
    }else{
        cout << "Yes\n";
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    read_input();
    solve();
    return 0;
}


Measured memory_bytes: 256
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,a[200005],b[200005];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n*2-1;++i)scanf("%d",a+i);
    int o=1;
    for(int k=17;k>=0;--k){
        int _=o+(1<<k);
        if(_>=n*2) continue;
        for(int i=1;i<=n*2-1;++i){
            if(a[i]<_)b[i]=0;
            else b[i]=1;
        }
        int l=n,r=n;
        while(l>1&&b[l-1]!=b[l])--l;
        while(r<n*2-1&&b[r+1]!=b[r])++r;
        if((min(n-l,r-n)^b[n])&1)o=_;
    }
    printf("%d\n",o);
    //system("pause");
    return 0;
}


Measured memory_bytes: 1792
def solve(n, s):
    if n < s:
        return -1
    if n == s:
        return n + 1

    sqn = int((n - 1) ** 0.5) + 1
    # 3桁以上
    for b in range(2, sqn + 1):
        tmp = 0
        k = n
        while k > 0:
            d, m = divmod(k, b)
            tmp += m
            k = d
        if tmp == s:
            return b
    # 2桁
    for p in range(sqn - 1, 0, -1):
        b, m = divmod(n - s, p)
        if m != 0:
            continue
        b += 1
        if p + n % b == s:
            return b
    return -1


n = int(input())
s = int(input())
print(solve(n, s))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int n, k, x[100010], sum[100010];
    cin >> n >> k;
    REP(i, n)
    cin >> x[i];

    int ans = 1000000000;
    for (int i = 0; i <= n - k; i++)
    {
        ans = min(ans, abs(x[i]) + x[i + k - 1] - x[i]);
        ans = min(ans, abs(x[i + k - 1]) + x[i + k - 1] - x[i]);
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;

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

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

    int n;
    cin >> n;
    set<string> s;

    rep(i, n){
        string t;
        cin >> t;
        s.insert(t);
    }

    cout << s.size() << "\n";

    return 0;
}


Measured memory_bytes: 19248
#include<stdio.h>
#include<stdlib.h>
#define N 2000000
#define K 10000

int main(){
  unsigned short *A,*B;
  int n;
  int C[K];
  int i,j;

  
  scanf("%d",&n);

  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

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

  for(i=0;i<K;i++)C[i]=0;

  for(j=1;j<=n;j++)C[A[j]]++;

  for(i=1;i<K;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<n;i++)printf("%d ",B[i]);
  printf("%d\n",B[n]);


  return 0;
}




Measured memory_bytes: 9588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            a = int.Parse(Console.ReadLine());
            Console.WriteLine("{0}", a*a*a);
        }
    }
}


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

using namespace std;

struct Sieve
{
    vector<int> isprime;

    vector<int> minpfactor;

    Sieve(int MAX) : isprime(MAX, true), minpfactor(MAX, 0)
    {
        isprime[0] = false;
        isprime[1] = false;
        int nsqrt = ceil(sqrt(MAX) + 0.1);
        for (int p = 2; p < nsqrt; p++)
        {
            if (!isprime[p])
                continue;
            minpfactor[p] = p;
            for (int mult = p * p; mult < MAX; mult += p)
            {
                isprime[mult] = false;
                minpfactor[mult] = p;
            }
        }
        for (int p = nsqrt; p < MAX; p++)
            if (isprime[p])
                minpfactor[p] = p;
    }
};

vector<int> fast_prime_factorize(int a, vector<int> &minprimefactor)
{
    vector<int> pfactors;
    while (a > 1)
    {
        pfactors.push_back(minprimefactor[a]);
        a /= minprimefactor[a];
    }
    return pfactors;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    Sieve es(1100000);

    vector<int> numbers(1100000);
    for (auto &&ai : a)
    {
        vector<int> pfactors = fast_prime_factorize(ai, es.minpfactor);
        int prevp = 0; // 素数の重複を除く
        for (auto &&pf : pfactors)
        {
            if (pf == prevp)
                continue;
            prevp = pf;
            numbers[pf]++;
        }
    }

    auto fold = [numbers](int m) -> bool {
        return accumulate(numbers.begin(), numbers.end(), true, [m](bool lhsb, int rhs) -> bool {
            bool rhsb = rhs < m;
            return lhsb && rhsb;
        });
    };

    bool ispairwise = fold(2);
    bool issetwise = fold(n);

    string answer;
    if (ispairwise)
        answer = "pairwise coprime";
    else if (issetwise)
        answer = "setwise coprime";
    else
        answer = "not coprime";

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 24272
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N;cin>>N;
  int a[110];
  for(int i=0;i<N;i++)cin>>a[i];

  int ans=INF;
  for(int i=-300;i<=300;i++){
    int temp=0;
    for(int j=0;j<N;j++){
      temp+=(i-a[j])*(i-a[j]);
    }
    ans=min(ans,temp);
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    ll x;
    cin >> x;
    ll sum = 1000*(x/500);
    x%=500;
    cout << sum + (x/5)*5 << endl;

    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import java.math.BigDecimal
import java.math.BigInteger

fun main() {
    val n = readLine()!!.toInt()
    val lList = readLine()!!.split(" ").map(String::toBigInteger)

    val slList = lList.sorted()

    var result = BigInteger.ONE
    run loop@{
        slList.forEach{
            if(it == BigInteger.ZERO){
                result = BigInteger.ZERO
                return@loop
            }else{
                result = result.times(it)
                if(result > 1000000000000000000.toBigInteger()){
                    result = (-1).toBigInteger()
                    return@loop
                }
            }
        }
    }

    println(result)
}

Measured memory_bytes: 74436
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  int F[N][10];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 10; j++){
      cin >> F[i][j];
    }
  }
  int P[N][11];

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

  int Fcnt[N] = {0};
  long long Ans = 0,Amax = -100000000000000000;
  for(int i = 1; i <(1<<10); i++){
    for(int j = 0; j < 10; j++){
      if(i&(1<<j)){
        for(int k = 0; k < N; k++){
          if(F[k][j] == 1) ++Fcnt[k];
        }
      }
    }
    for(int j = 0; j < N; j++){
      Ans += P[j][Fcnt[j]];
      Fcnt[j] = 0;
    }
    Amax = max(Amax,Ans);
    Ans = 0;
  }

  printf("%lld\n",Amax);
  return 0;



}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
	for j in range(b+1):
		for k in range(c+1):
			if 500*i+100*j+50*k==x:
				ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define N 200001
vector<int> adj[N];
int ans[N];
bool vis[N];
void dfs(int x)
{
    vis[x]=1;
    for(int i:adj[x])
    {
        if(!vis[i])
        {
        dfs(i);
        ans[x]++;
        }
    }
}

signed main() {
    int t,n;
    cin>>n;
    for(int i=2;i<n+1;i++)
    {
        cin>>t;
        adj[i].push_back(t);
        adj[t].push_back(i);
        ans[i] = 0;
        vis[i]=0;
    }
    dfs(1);
    
    for(int i=1;i<n+1;i++)
    cout<<ans[i]<<endl;
    return 0;
}

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

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs

const int MAXN = 205000;

int n;
int a[MAXN];

int main() { 

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

  int cur = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == cur) {
      cur++;
    }
  }

  if (cur == 1) {
    cout << -1 << endl;
    return 0;
  }

  cout << n - (cur - 1) << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define REP(i,j,n) for(int i = j;i < (n);i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl
int main(){
  int a, b;
  cin >> a >> b;
  int pro = a*b;
  if(pro%2 == 0) cout << "Even" << endl;
  else cout << "Odd" << endl;
}


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

using namespace std;
#define ll long long

int main(){
  ll K;
  cin >> K;
  int N = 50;
  vector<ll> a(N, K/N);
  for(int i=0; i<N; i++)
    a[i] += i;
  for(int i=0; i<K%N; i++){
    for(int j=0; j<N; j++){
      if(i == j)
        a[j] += N;
      else
        a[j]--;
    }
  }
  cout << N << endl;
  for(int i=0; i<N; i++)
    cout << a[i] << ' ';
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int n;
    cin>>n;
    vl a(n);
    cin>>a;
    vl cs(n+1);
    REP(i,n)cs[i+1]=cs[i]+a[i];
    ll mi=LINF;
    REP(i,n-1){
        ll x=cs[i+1];
        ll y=cs[n]-x;
        chmin(mi, abs(x-y));
    }
    print(mi);
}


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

int main(){
    int A,B;

    cin >> A >> B;

    if(A <= 5)cout << 0 << endl;
    else if (A <= 12) cout << B / 2 << endl;
    else cout << B << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int main() {
  int N; cin >> N;
  int Input[N];
  for (int i = 0; i < N; i++ ) {
    cin >> Input[i];
  }

  for (int i = N - 1; i >= 1; i--) {
    if (Input[i-1] > Input[i]) {
      Input[i-1]--;
    }
  }

  for (int i = 0; i < N-1; i++) {
    if (Input[i] > Input[i+1] ) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a >= b) {
			System.out.println("delicious");
		} else {
			if(x < b - a) {
				System.out.println("dangerous");
			} else {
				System.out.println("safe");
			}
		}
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    ll Q,H,S,D;
    cin >> Q >> H >> S >> D;
    ll N;
    cin >> N;
    ll mi = min(4*Q,min(2*H,S));
    ll Dmi = D*(N/2)+(N%2==1?mi:0);
    ll res = min(mi*N,Dmi);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
function main(input) {


    input = input.split(' ').map(x => Number(x))

    if (Math.max(input[0], input[1]) > 8) {
        console.log(':(')
    } else {

        console.log('Yay!')
    }

}

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


Measured memory_bytes: 21064
import kotlin.math.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main() {
    val x = readLong()

    val memo = mutableMapOf<Int, Long>()

    fun p(c: Int): Long {
        val m = memo[c]
        if (m != null) {
            return m
        }
        val p = Math.pow(c.toDouble(), 5.0).toLong()
        memo[c] = p
        return p
    }

    var a = 0
    while (a < 256) {
        (-256..256).forEach {
           if (p(a) - p(it) == x) {
               println("$a $it")
               return
           }
        }
        a++
    }
}




Measured memory_bytes: 36848
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int x, k, d; cin >> x >> k >> d;
  x = abs(x);

  if(x / k >= d){
    cout << x - k * d << endl;
  }else{
    if((k - x/d) % 2 == 0){
      cout << x % d << endl;
    }else{
      cout << abs(x % d - d) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3632
n, k, q = map(int, input().split())
L = [k for i in range(n)]
a = [int(input()) for i in range(q)]

for i in a:
    L[i-1] = L[i-1] + 1

for i in range(len(L)):
    if q  < L[i]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 10488
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
namespace ywy{
	inline int get(){
		int n=0;char c;while((c=getchar())||23333){
			if(c>='0'&&c<='9')break;if(c=='-')goto s;
		}n=c-'0';while((c=getchar())||23333){
			if(c>='0'&&c<='9')n=n*10+c-'0';else return(n);
		}s:while((c=getchar())||23333){
			if(c>='0'&&c<='9')n=n*10-c+'0';else return(n);
		}
	}
	typedef struct _b{
		int dest;int nxt;
	}bian;bian memchi[1000001];int gn=1,heads[100001],deg[100001],mxdeg[100001];
	inline void add(int s,int t){
		memchi[gn].dest=t;memchi[gn].nxt=heads[s];heads[s]=gn;gn++;
	}
	void dfs(int pt,int baba){
		mxdeg[pt]=deg[pt];for(register int i=heads[pt];i;i=memchi[i].nxt){
			if(memchi[i].dest==baba)continue;dfs(memchi[i].dest,pt);mxdeg[pt]=max(mxdeg[pt],mxdeg[memchi[i].dest]);
		}
	}int ans;
	void solve(int pt,int baba){
		if(deg[pt]==1){
			ans++;return;
		}if(deg[pt]==2&&baba){
			for(register int i=heads[pt];i;i=memchi[i].nxt){
				if(memchi[i].dest==baba)continue;solve(memchi[i].dest,pt);
			}return;
		}int son=0;for(register int i=heads[pt];i;i=memchi[i].nxt){
			if(memchi[i].dest==baba)continue;if(mxdeg[memchi[i].dest]<=2){
				son=memchi[i].dest;break;
			}
		}for(register int i=heads[pt];i;i=memchi[i].nxt){
			if(memchi[i].dest==baba||memchi[i].dest==son)continue;solve(memchi[i].dest,pt);
		}
	}
	void ywymain(){
		int n=get();for(register int i=1;i<n;i++){
			int s=get()+1,t=get()+1;deg[s]++;deg[t]++;add(s,t);add(t,s);
		}if(n<=2){
			cout<<1<<endl;return;
		}int mx=0;for(register int i=1;i<=n;i++)mx=max(mx,deg[i]);
		if(mx<=2){
			cout<<1<<endl;return;
		}for(register int rt=1;rt<=n;rt++){
			if(deg[rt]>2){
				dfs(rt,0);if(mxdeg[rt]<=2){
					cout<<1<<endl;return;
				}solve(rt,0);cout<<ans<<endl;return;
			}
		}
	}
}
int main(){
	ywy::ywymain();return(0);
}

Measured memory_bytes: 5504
/*
  Reference:-
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;

int main(){
    std::ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    int ar[n];
    forn(i,n)cin>>ar[i];
    if(n<=k){
        cout<<abs(ar[0]-ar[n-1]);
        return 0;
    }
    int dp[n]={0};
    dp[1]=abs(ar[1]-ar[0]);
    for(int i=2;i<n;i++){
        dp[i]=INT_MAX;
        for(int j=max(0,i-k);j<=i-1;j++){
            dp[i]=min(dp[i],dp[j]+abs(ar[j]-ar[i]));
        }
    }
    cout<<dp[n-1];

    return 0;
}


Measured memory_bytes: 1024
import sys
import collections
import math
input=sys.stdin.readline


n,x=map(int,input().split())
l=list(map(int,input().split()))
l.append(x)
l.sort()
#print(l)
b=abs(l[0]-l[1])
li=[b]
lis=[]
#print(li)
for i in range(1,len(l)-1):
    a=abs(l[i]-l[i+1])
    li.append(a)
    b=min(a,b)
li=set(li)
for i in range(1,round(math.sqrt(b)+1)):
    if b%i==0:
        lis.append(i)
        lis.append(b//i)
lis.sort()
#rint(lis)
for i in lis:
    for j in li:
        if j%i!=0:
            break
    else:
        num=i
print(num)

Measured memory_bytes: 14636
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

void solve(){
  int k; cin >> k;
  int ans;
  if(k % 2 == 0){
    ans = k / 2 * k / 2;
  }
  else{
    ans = (k / 2 + 1) * (k / 2);
  }
  cout << ans << endl;
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    const ll dx = x2 - x1, dy = y2 - y1;
    ll x3 = x2 - dy, y3 = y2 + dx;
    ll x4 = x1 - dy, y4 = y1 + dx;
    cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
    return 0;
}


Measured memory_bytes: 504