akhauriyash/Code-Regression huggingface dataset:
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() { 
	int n; cin>>n;
	vector<int> a(n);
	rep(i,0,n) cin>>a[i];
	sort(a.begin(),a.end());
	ll ans=0,sub=0;
	if(n%2){
		rep(i,1,n-1){
			if(i%2==0) ans+=2*a[n-i/2];
			else ans-=2*a[(i-1)/2];
		}
		ans+=a[(n-1)/2]+a[(n-1)/2+1];
		rep(i,1,n-1){
			if(i%2==0) sub-=2*a[i/2-1];
			else sub+=2*a[n-(i+1)/2];
		}
		sub-=a[(n-1)/2]+a[(n-1)/2-1];
	}
	else{
		rep(i,1,n-1){
			if(i%2==0) ans+=2*a[n-i/2];
			else ans-=2*a[(i-1)/2];
		}
		ans+=a[n/2]-a[n/2-1];
		rep(i,1,n-1){
			if(i%2==0) sub-=2*a[i/2-1];
			else sub+=2*a[n-(i+1)/2];
		}
		sub+=a[n/2]-a[n/2-1];
	}
	cout<<max(ans,sub)<<endl;
	return 0;
}


Measured memory_bytes: 640
Taro = 0
Hanako = 0

n = int(input())
for i in range(n):
  T_card, H_card = input().split()
  if T_card > H_card:
    Taro += 3
  elif T_card < H_card:
    Hanako += 3
  else:
    Taro += 1
    Hanako += 1

print(Taro,Hanako)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;

#define fi first
#define se second


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n > 81) cout << "No" << '\n';
    else {
        for (int i = 9; i >= 2; --i) {
            if (n%i == 0) {
                n = n/i;
                break;
            }
        }
        if (n <= 9) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	string s;
	cin>>s;
	long long ans=1;
	int cnt[26] = {},sum=s.size();
	rep(i,s.size()){
		cnt[s[i]-'a']++;
	}
	for(char c : s){
		ans += sum - cnt[c-'a'];
		sum--;
		cnt[c-'a']--;
	}
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 720
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    private static double x;
    private static double max;
    private static double min;
    private static String val;
    
    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        max=0;
        min=1000000000;
        while((val = br.readLine()) != null){
        	x = Double.parseDouble(val);
          	if(x > max){
           		max=x;
           	}
           	if(x < min){
           		min=x;
           	}
        }
        System.out.println(max-min);
    }
}

Measured memory_bytes: 16916
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(void){
	double a,b,c,d,x,y;
	cin>>a>>b>>c>>d;
	x = c-a;
	y = b-d;
	if(x<0)x =x*-1;
	if(y<0)y =y*-1;
	printf("%lf\n",sqrt(x*x+y*y));
	return 0;
}


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b)
    {
        cout<<"a > b"<<endl;
    }
    else if(a<b)
    {
        cout<<"a < b"<<endl;
    }
    else
        cout<<"a == b"<<endl;
    return 0;
}



Measured memory_bytes: 3108
// C.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <set>

using namespace std;

//typedef pair<int, int> II;
//typedef set<II> IISet;

int main(int argc, char *argv[])
{
	bool ans = false;
	int n, m;
	cin >> n >> m;
//	IISet s;
	set<int> s[200001];
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		s[a].insert(b);
		s[b].insert(a);
	}
	for (int a : s[1]) {
		if (s[a].find(n) != s[a].end()) {
			ans = true;
			break;
		}
	}
	cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	return 0;
}


Measured memory_bytes: 28416
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<fstream>
using namespace std;

using ll = long long;
const int MAXI = 1024 * 128;

int n;
vector<vector<int> > g;

void input() {
	cin >> n;
	g.resize(n);
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
}

int findD(int x, int y) {
	queue<int> q;
	vector<int> d(n, 0);
	q.push(x);
	d[x] = 1;
	while (!d[y]) {
		int v = q.front();
		q.pop();
		for (int i = 0; i < g[v].size(); i++) {
			if (!d[g[v][i]]) {
				d[g[v][i]] = d[v] + 1;
				q.push(g[v][i]);
			}
		}
	}
	return d[y] - 1;
}

int algo() {

	int sum = 0;

	for (int i = 0; i < n; i++) {
		if (g[i].size() < 3)
			continue;
		int leaves = 0;
		for (int j = 0; j < g[i].size(); j++) {
			int p = i;
			int v = g[i][j];
			while (g[v].size() == 2) {
				if (g[v][0] != p) {
					p = v;
					v = g[v][0];
				}
				else {
					p = v;
					v = g[v][1];
				}
			}
			if (g[v].size() == 1)
				leaves++;
		}
		if (leaves) {
			sum += leaves - 1;
		}
	}

	return sum;
}

int main() {

	input();

	int sum = algo();
	if (sum)
		cout << sum;
	else
		cout << 1;


	/*
	for (int i1 = 0; i1 < n; i1++) {
		for (int i2 = i1 + 1; i2 < n; i2++) {
			for (int i3 = i2 + 1; i3 < n; i3++) {
				set<string> s;
				bool y = 1;
				for (int k = 0; k < n; k++) {
					string str = to_string(findD(i1, k)) + to_string(findD(i2, k)) + to_string(findD(i3, k));
					if (s.count(str)) {
						y = 0;
					}
					s.insert(str);
				}
				if (y)
					cout << i1 << " " << i2 << " " << i3 << endl;
			}
		}
	}
	*/
	

	return 0;
}

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

struct queues {
	char name[11];
	int time;
	int next;
};

int main( void ) 
{
	struct queues ps[100001];
	int i;
	int n,q;
	int cnt,cur,pre;
	int time,res;
	int head;
	
	scanf( "%d%d", &n, &q );
	head=0;
	for( i=0; i<n; i++ ) {
		scanf( "%s%d", ps[i].name, &ps[i].time );
		ps[i].next=i+1;
	}
	
	res=time=cnt=0;
	pre=cur=head;
	while( cnt<n ) {
		res=ps[cur].time-q;
		if( res <= 0 ) {
			time+=ps[cur].time;
			printf( "%s %d\n", ps[cur].name, time );
			
			if( head == cur ) {
				head=ps[cur].next;
			} else {
				ps[ pre ].next=ps[cur].next;
			}
			cnt++;
		} else {
			time+=q;
			ps[cur].time=res;
			pre=cur;
		}
		cur=ps[cur].next;
		
		if( n<=cur ) { 
			cur=head;
		}	
	}
	
	return 0;
}

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



int main() {
    int i,j,N,H,W,count=0;
    cin >> H >> W >> N;
    /*vector<int> P(N);
    vector<int> Q(N)*/;
    for(i=0;i<H;i++){
        count+=W;
        if(count>=N) break;
    }
    count=0;
    for(j=0;j<W;j++){
        count+=H;
        if(count>=N) break;
    }
    int ans = min(i,j);
    cout << ans+1 << endl;
    return 0;
}


Measured memory_bytes: 256
local s=io.read()
local t=io.read()

sanagram={}
tanagram={}
for i=1,#s do
    table.insert(sanagram,s:sub(i,i))
end
for i=1,#t do
    table.insert(tanagram,t:sub(i,i))
end
table.sort(sanagram)
table.sort(tanagram,function(a,b)
    return a>b
end)

if table.concat(sanagram,"")<table.concat(tanagram,"") then
    print("Yes")
else
    print("No")
end

Measured memory_bytes: 888
/*
By Tianyi Chen. All rights reserved.
Date: 2017-04-15
*/
#include<bits/stdc++.h>
using namespace std;
int n,ans=1,a[100001],inc;
int main(){
 scanf("%d",&n);for(int i=0;i<n;++i)scanf("%d",a+i);
 inc=a[1]>a[0]?1:a[1]<a[0]?-1:0;
 for(int i=2;i<n;++i){
  if(inc==1&&a[i]<a[i-1]||inc==-1&&a[i]>a[i-1])++ans,inc=0;
  else if(a[i]!=a[i-1])inc=a[i]>a[i-1]?1:-1;
 }
 printf("%d\n",ans);
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int i, x=1;
    for(i = 1; i <= 10000; i++){
        scanf("%d",&x);
       if(x == 0){
           break;
       }
       1 <= x <= 10000;
       printf("Case %d: %d\n",i,x);
    }
   return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
 
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))
 
typedef long long ll;
 
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int r,d,x; cin>>r>>d>>x;
  int res[10];
  
  rep(i,10) {
    if(i==0) {
      res[i] = r*x-d;
    } else {
      res[i] = r*res[i-1]-d;
    }
  }
  
  rep(i,10) {
    cout<<res[i]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n, q, count = 0;
  cin >> n;
  long int S[n];
  for(int i = 0; i < n; i++)
    cin >> S[i];
  cin >> q;
  while(q--){
    long int T;
    cin >> T;
    int i = n;
    while(i--){
      if(S[i] == T){
        count++;
        break;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int> arr;
    while (true) {
        string a, b, op;
        int result = 0;
        cin >> a >> op >> b;
        if (op == "?") {
            break;
        }
        else if (op == "+") {
            result = atoi(a.c_str()) + atoi(b.c_str());
        }
        else if (op == "-") {
            result = atoi(a.c_str()) - atoi(b.c_str());
        }
        else if (op == "*") {
            result = atoi(a.c_str()) * atoi(b.c_str());
        }
        else if (op == "/") {
            result = atoi(a.c_str()) / atoi(b.c_str());
        }
        arr.emplace_back(result);
    }
    for (auto itr = arr.begin(); itr != arr.end(); ++itr) {
        cout << *itr << endl;
    }

    return 0;
}


Measured memory_bytes: 3164
#include<cstdio>
#include<cstring> 
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=5e5+5;
char a[10];
int x;
int main(){
	scanf("%d",&x);
	int ans=x/500*1000+x%500/5*5;
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  VI h(n);
  rep(i,n) cin >> h[i];
  
  sort(h.begin(), h.end());
  ll atks = 0;
  rep(i,n-k){
    atks += h[i];
  }
  
  cout << atks << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
using namespace std;
int A[100];
int B[100];

int N,M,Z;

void mult(int a[110][110],int b[110][110],int c[110][110]){
	
	for(int i = 0 ; i < N ; i++){
		for(int j = 0 ; j < N ; j++){
			c[i][j] = 0;
			for(int k = 0 ; k < N ; k++)
				c[i][j] |= a[i][k]&b[k][j];
		}
	}
}

void pow(int a[110][110],int b,int t[110][110]){
	
	if( b == 0 ){
		for(int i = 0 ; i < N ; i++)
			for(int j = 0 ; j < N ; j++)
				t[i][j] = i==j;
			
	}else{
		int tmp[110][110]={};
		int tmp2[110][110]={};
		mult(a,a,tmp);

		pow(tmp,b/2,tmp2);

		
		
		if( b & 1 ){
			mult(tmp2,a,tmp);
			for(int i = 0 ; i < N ; i++)
				for(int j = 0 ; j < N ; j++)
					t[i][j] = tmp[i][j];
		}else{
			for(int i = 0 ; i < N ; i++)
				for(int j = 0 ; j < N ; j++)
					t[i][j] = tmp2[i][j];
		}
		

	}
}

int main(){
	while(cin >> N >> M >> Z && Z){
		
		int n = N;
		
		vector< pair<int,int> > vertex;
		int g[110][110] = {};
		
		vertex.push_back(make_pair(0,M));
		for(int i = 0 ; i < M ; i++){
			int a,b;
			cin >> a >> b;
			a--,b--;
			vertex.push_back(make_pair(a,i));
			vertex.push_back(make_pair(b,i));
			A[i] = a;
			B[i] = b;
		}
		
		for(int i = 0 ; i < vertex.size() ; i++){
			for(int j = 0 ; j < vertex.size() ; j++){
				for(int k = 0 ; k < M ; k++){
					if( k != vertex[i].second && k == vertex[j].second){
						if( A[k] == vertex[i].first && B[k] == vertex[j].first){
							g[i][j] = 1;
						}
						if( B[k] == vertex[i].first && A[k] == vertex[j].first){
							g[i][j] = 1;
						}
					}
				}
			}
		}
		N = vertex.size();
		int res[110][110]={};
		pow(g,Z,res);	
		

		
		int ans = 0;
		for(int i = 0 ; i < N ; i++){
			//cout << i << " " << vertex[i].first << endl;
			if( vertex[i].first == n-1 ){
				if( res[0][i] ) ans = 1;
			}
		
		}
		cout << (ans?"yes":"no") << endl;
		
	}
}

Measured memory_bytes: 4224
import numpy as np

n = int(input())
h = list(map(int, input().split()))

l = np.array([0 for _ in range(n)])
start = 0
count = 0
for i in range(n-1):
  if h[i] >= h[i+1]:
    count += 1
  else:
    l[start:i] += count
    start = i+1
    count = 0
else:
  l[start:] += count

print(max(l))

Measured memory_bytes: 23376
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        int index;

        Scanner scan = new Scanner(System.in);
        index = Integer.valueOf(scan.next()) - 1;
        int[] b = new int[index];

        for(int i=0;i<index; i++){
            b[i] = Integer.valueOf(scan.next());
        }

        int answer = b[0];
        for(int i=1;i<index; i++) {
               //自分が一番小さい
               if(b[i] <= b[i-1]){
                   answer += b[i];
               }
               //左側が一番小さい
               else if(b[i] > b[i-1]){
                   answer += b[i-1];
               }
        }
        answer += b[index-1];

        System.out.println(answer);

    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
#define out(a) printf("%d",a)
#define writeln printf("\n")
const int N=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,m;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
ll readl()
{
	ll s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read(); m=read();
	printf("%d",n%m?1:0);
	return 0;
}
	

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

int main(){
    char a,b;
    cin>>a>>b;
    if (a==b)
    {
        /* code */
        cout<<'H'<<endl;
    }
    else if(a=='H'&&b=='D')
    {
        cout<<"D"<<endl;
    }
    else if (a=='D'&&b=='H')
    {
        /* code */
        cout<<"D"<<endl;
    }
    
    
    
    }


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

int main() {
    int k, x;
    cin >> k >> x;
    for (int i = x - k + 1; i <= x + k - 1; i++) {
        if (i < x + k - 1) cout << i << " ";
        else cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define lli long long int
#define llu long long unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,s,e) for(i=s; i<e; i++)
#define mod 1000000007
#define F first
#define S second
#define plli pair<lli,lli>
#define pqlli priority_queue<lli>
#define test(t) cin>>t; while(t--)
using namespace std;
int main()
{
	IOS;
	lli n, s = 0;
	cin>>n;
	lli a[n], pre[n+1] = {0};
	for(lli i = 0; i<n; i++)
	cin>>a[i], pre[i+1] = pre[i] + a[i];
	
	lli ans = INT_MAX;
	for(lli i = 0; i<n+1; i++)
	{
		lli one = pre[i];
		lli two = pre[n] - pre[i];
		lli diff = abs(two - one);
		ans = min(ans, diff);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3328
import numpy as np


def main():
    N = int(input())
    xs = np.array([tuple(map(int, input().split()))
                   for _ in range(N)], np.float32)
    dmap = dist(xs)
    s = 0.
    for i, p in enumerate(permutations(np.arange(N))):
        d = sum(dmap[p[k - 1], p[k]] for k in range(1, N))
        s += d
    print(s / (i + 1))


def permutations(iterable, r=None):
    pool = tuple(iterable)
    n = len(pool)
    r = n if r is None else r
    if r > n:
        return
    indices = list(range(n))
    cycles = list(range(n, n-r, -1))
    yield tuple(pool[i] for i in indices[:r])
    while n:
        for i in reversed(range(r)):
            cycles[i] -= 1
            if cycles[i] == 0:
                indices[i:] = indices[i+1:] + indices[i:i+1]
                cycles[i] = n - i
            else:
                j = cycles[i]
                indices[i], indices[-j] = indices[-j], indices[i]
                yield tuple(pool[i] for i in indices[:r])
                break
        else:
            return


def dist(xs):
    x, y = xs.T
    z = np.sqrt(np.power(x[:, None] - x[None], 2)
                + np.power(y[:, None] - y[None], 2))
    return z


if __name__ == "__main__":
    main()

Measured memory_bytes: 12688
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner (System.in);
		
		int n = sc.nextInt();
		long d = sc.nextInt();
		int cnt=0;
		boolean flgSame = false;
		
		ArrayList<Integer> arrX = new ArrayList<>();
		ArrayList<Integer> arrY = new ArrayList<>();
		
		for(int i=0;i<n;i++) {
			long x = sc.nextInt();
			long y = sc.nextInt();
			if(d*d >=x*x + y*y) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 59364
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstring>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
#define all(v) v.begin(), v.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

int w, h;
int k[501][501];
bool visit[501][501];

struct room{
	int sec, x, y;
	room(int s, int x, int y):sec(s), x(x), y(y){}
	bool operator<(const room &r) const {
		return sec > r.sec;
	}
};

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

void createMap(int x, int y, vi &s, vi &c){
	memset(visit, 0, sizeof(visit));
	priority_queue<room> q;
	q.push(room(1, x, y));
	visit[y][x] = 1;
	int sec = 0, cnt = 0;
	while(!q.empty()){
		room r = q.top();
		q.pop();

		if(r.sec > sec){
			s.push_back(sec);
			c.push_back(cnt);
			sec = r.sec;
		}
		cnt++;

		rep(i, 4){
			int nx = r.x + dx[i], ny = r.y + dy[i];
			if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if(visit[ny][nx]) continue;
			visit[ny][nx] = true;
			q.push(room(k[ny][nx], nx, ny));
		}
	}
	s.push_back(sec);
	c.push_back(cnt);
}


int main(){
	int R;
	while(cin >> R, R){
		vi sec[2];
		vi cnt[2];
		rep(m, 2){
			int x, y;
			cin >> w >> h >> x >> y;
			rep(i, h) rep(j, w) cin >> k[i][j];
			createMap(x-1, y-1, sec[m], cnt[m]);
		}

		int ans = INF;
		int size = sec[1].size();
		rep(i, sec[0].size()){
			int pos = lower_bound(all(cnt[1]), R-cnt[0][i])-cnt[1].begin();
			if(pos == size) continue;
			ans = min(ans, sec[0][i]+sec[1][pos]);
		}
		cout << ans << endl;
	}

    return 0;
}

Measured memory_bytes: 4676
function main(input) {
  var temp = input.split('\n');
  for (var i=0; i<temp.length; i++) {
    var data = temp[i].split(' ');
    var a = parseInt(data[0]);
    var op = data[1];
    var b = parseInt(data[2]);
    if (op == "+")
      console.log(a+b);
    else if (op == '-')
      console.log(a-b);
    else if (op == '*')
      console.log(a*b);
    else if (op == '/')
      console.log(Math.floor(a/b));
    else 
      break;
  }
}

var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
main(x);


Measured memory_bytes: 15408
/*input
7
1 2 3 2 1 999999999 1000000000
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double

typedef pair<int,int> pi;

typedef vector<int> vi;
typedef vector<pi> vpi;

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

#define gcd __gcd

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int n,j,k,l;
int a[100001];

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  cin >> n;
  for(int i = 0;i < n;i++)cin >> a[i];
  int i = 0;
  //j = 1;
  int ans = 0;
  while(i < n){
    ans++;
    while(a[i] == a[i+1])i++;
    j = i+1;
   // cout << a[i] << " " << a[j] << endl;
    bool dir = (a[i] > a[j]);
    j++;
    while(j < n){
      if(a[j] >= a[j-1] && (!dir) ){j++;continue;}
      if(a[j] <= a[j-1] && (dir) ){j++;continue;}
      //i = j-1;
      //cout << j << endl;
      //zcout << a[j] << " " << a[j-1] << " " << dir << endl;
      break;
    }
    i = j;
  }
  cout << ans;
  return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll Q;
    cin >> Q;
    vec L(Q), R(Q);
    REP(i,0,Q) cin >> L[i] >> R[i];

    ll N = 100000;
    vec F(N+1, true);
    F[0] = false;
    F[1] = false;
    for(ll i=2; i*i<=N; ++i) {
        if(F[i]) {
            for(ll j=2*i; j<=N; j+=i) {
                F[j] = false;
            }
        }
    }

    vec G(N+1);
    for(ll i=1; i<=N; i+=2) G[i] = F[i] & F[(i+1)/2];
    vec C(N+1, 0);
    REP(i,0,N) C[i+1] = C[i] + G[i+1];

    REP(i,0,Q) PR(C[R[i]]-C[L[i]-1]);

    return 0;
}

/*



*/

Measured memory_bytes: 7216
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	char a[100010];
	int b[100010];
	int s;
	long long t;
	for (int i = 0; i < 100010; i++){
		a[i] = 0;
		b[i] = 0;
	}
	
scanf("%s", a);
	
scanf("%lld", &t);
s = strlen(a);
for (int i = 0; i < s; i++){
	b[i] = (123 - a[i]) % 26;
}
int ss;
for (int i = 0; i < s; i++){
	ss = ss + b[i];
	if (ss <= t)a[i] = 97;
	else ss = ss - b[i];
}
a[s - 1] = 97 + ((a[s - 1] - 97 + t - ss) % 26);

	printf("%s\n", a);
	return 0;
}

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

string s;

int main()
{
    cin >> s;
    for (int i = 0; i < s.length(); i++)
        if (i % 2 == 0 && s[i] == 'L' || i % 2 == 1 && s[i] == 'R') {
            printf("No\n");
            return 0;
        }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if (r<=x && x<=(w-r) && r<=y && y<=(h-r))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(ll a=b;a<=c;a++)
#define PER(a,b,c) for(ll a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<ll,ll>
#define pii pair<pair<ll,ll>,ll>
using namespace std;
const ll MAXN=1e6+5;
ll n,m,t;
map<ll,ll> v;
int main(){
    cin>>n;
    ll ans=0;
    REP(i,1,n){
        ll tmp;
        cin>>tmp;
        ans+=v[i-tmp];
        v[(i+tmp)]++;
    }
    cout<<ans;
}

Measured memory_bytes: 25840
k, n = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
kyo = []

for i in range(n-1):
    kyo.append(abs(a[i] - a[i+1]))

kyo.append((k - a[-1]) + a[0])
kyo.sort()
print(sum(kyo[:-1]))

Measured memory_bytes: 26444
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct Graph{
	int n;
	int longest;
	int edgesum;
	vector<vector<pair<int,int> > >G;
	void init(int _n)
	{
		n=_n;
		G.resize(n);
		int a[n];
		edgesum=0;
		for(int i=0;i<n-1;i++)
		{
			cin>>a[i];a[i]--;
		}
		for(int i=0;i<n-1;i++)
		{
			int b;cin>>b;edgesum+=b;
			G[i+1].push_back(make_pair(a[i],b));
			G[a[i]].push_back(make_pair(i+1,b));
		}
	}
	int dfs(int u,int p,int nowcost)
	{
		int ret=0;
		longest=max(longest,nowcost);
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i].first,cost=G[u][i].second;
			if(v==p||G[v].size()<2)continue;
			ret+=cost*2+dfs(v,u,nowcost+cost);
		}
		return ret;
	}
	int get(int u)
	{
		longest=0;
		return dfs(u,-1,0)-longest+edgesum;
	}
	void solve()
	{
		int ans=1e9;
		for(int u=0;u<n;u++)ans=min(ans,get(u));
		cout<<ans<<endl;
	}
};
main()
{
	int N;
	while(cin>>N,N)
	{
		Graph G;
		G.init(N);
		G.solve();
	}
}



Measured memory_bytes: 3164
import sys
sys.setrecursionlimit(pow(10,6))

N = int(input())
Edges = list([] for _ in range(N))
for n in range (N-1):
    x, y = map(int, input().split())
    Edges[x-1].append(y-1)
    Edges[y-1].append(x-1)

def dfs(cur_node, parent_node):
    grundy = 0
    for child_node in Edges[cur_node]:
        if child_node == parent_node:
            continue
        else:
            grundy ^= (dfs(child_node, cur_node) + 1)
    return grundy

G = dfs(0, -1)
if G == 0:
    print("Bob")
else:
    print("Alice")

Measured memory_bytes: 114536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

    int n,q;
    vector<vector<ll>> G(200010);
    vector<ll> cost(200010);
    vector<bool> visited(200010,false);

    void dfs(ll v, ll pv){
        visited[v] = true;
        if(v!=0) cost[v] += cost[pv];
        for(auto nv: G[v]){
            if(visited[nv]==false) dfs(nv,v);
        }
    }


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

    rep(i,n-1){
        ll a,b; cin>>a>>b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a); 
    }

    rep(i,q){
        ll a,b; cin>>a>>b;
        a--;
        cost[a]+=b;
    }

    dfs(0,0);
    rep(i,n-1) cout<<cost[i]<<" ";
    cout<<cost[n-1]<<endl;
}

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

using namespace std;  

typedef long long ll;
typedef long double ld;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rs resize
#define all(x) x.begin(), x.end()   

void pre(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void pudge(){
    int x;
    string s;
    cin >> x >> s;
    for (int i = 0; i < s.length(); i++){
        s[i] += x;
        if (s[i] > 'Z')
            s[i] -= 'Z' - '@';
    }
    cout << s;
}

int main(){ 
    pre();  
    pudge();
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))

a = [10**10] * n

a[0] = 0
for i in range(0,n):
    for x in range(1,k+1):
        j = i+x
        if j >= n:
            continue
        a[j] = min(a[j], a[i] + abs(h[i] - h[j]))

print(a[n-1])


Measured memory_bytes: 84316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

ld dp[303][303][303];
ld n;

ld calc(ll i, ll j, ll k){
    if(i == 0 && j == 0 && k == 0){
        return 0.0;
    }
    if(dp[i][j][k] != 0.0){
        return dp[i][j][k];
    }

    dp[i][j][k] = 1.0;

    if(i){
        dp[i][j][k] += calc(i-1, j+1, k) * i / n;
    }
    if(j){
        dp[i][j][k] += calc(i, j-1, k+1) * j / n;
    }
    if(k){
        dp[i][j][k] += calc(i, j, k-1) * k / n;
    }

    dp[i][j][k] *= n / (double)(i + j + k);

    return dp[i][j][k];

}

int main(void){
    cin >> n;

    ll a = 0, b = 0, c = 0;
    rep(i, 0, n){
        ll tmp;
        cin >> tmp;
        if(tmp == 3) a++;
        if(tmp == 2) b++;
        if(tmp == 1) c++;
    }

    printf("%.12Lf\n", calc(a, b, c));
}


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

int main()
{
	int a, b;
	char op;
	while (cin >> a >> op >> b, op != '?') {
		switch (op)
		{
		case '+':
			cout << a + b << endl;
			break;
		case '-':
			cout << a - b << endl;
			break;
		case '*':
			cout << a * b << endl;
			break;
		case '/':
			cout << a / b << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
using namespace std;
int N,T,c,t,i;
int INF = 100000;
int ans = INF;
int main(){
  cin >> N >>T;
  for (i=0;i<N; i++){
    cin >> c >> t;
    if (t<=T){
      ans = min (ans , c);
    }
  }
  if(ans == INF){
    cout << "TLE" << endl;
  }else {
    cout << ans << endl;
  }
  return 0;
}

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

ll k,a,b;

int main(){
    cin >> k >> a >> b;
    ll res=1;
    if(a+2>=b){
        res+=k;
    }
    else if(a+2<b){
        if(k<=a-1){
            res+=k;
        }
        else if(k>a-1&&(k-a+1)%2==1){
            res+=a-1;
            res+=(b-a)*((k-a+1)/2);
            res+=1;
        }
        else if(k>a-1&&(k-a+1)%2==0){
            res+=a-1;
            res+=(b-a)*((k-a+1)/2);
        }
    }
    cout << res << endl;
}  

Measured memory_bytes: 3604
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <chrono> 
using namespace std::chrono;
#define fl(i,z,n) for(int i=z;i<=(n);i++)
#define flr(i,z,n) for(int i=z;i>=(n);i--)
using namespace std;
#define ll long long 
#define pa(a,s) fl(i,0,s-1) cout<<*(a+i)<<" "; cout<<nl;
#define pv(v) fl(i,0,v.size()-1) cout<<v[i]<<" "; cout<<nl;
#define read(v) fl(i,0,v.size()-1) cin>>v[i];
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define vll vector<ll>
#define sll set<ll>
#define spll set<pll>
#define debnl(x) cout<<#x<<"="<<x<<nl;
#define deb(x) cout<<#x<<"="<<x<<" ";
#define mkp(x,y) make_pair(x,y)
#define ump unordered_map
#define ff first
#define ss second
#define in insert
#define sz size
#define len length
#define nl '\n'
#define pb push_back
#define in insert
#define ub upper_bound
#define lb lower_bound
#define ld long double
const int MXN=3e5+10;
vll x(MXN,0),y(MXN,0);
ll mod=1e9+7;
void solve(){
    ll h,w,m;
    cin>>h>>w>>m;
    set<pll> ss;
    fl(i,0,m-1){
        ll a,b;
        cin>>a>>b;
        x[a]++;
        y[b]++;
        ss.insert({a,b});
    }
    int mx=0,my=0;
    set<ll> xx,yy;
    mx=*max_element(x.begin(),x.end());
    my=*max_element(y.begin(),y.end());
    fl(i,1,h) if(x[i]==mx) xx.insert(i);
    fl(i,1,w) if(y[i]==my) yy.insert(i);
    ll ans=mx+my;
    int ok=0;
    for(auto a:xx){
        for(auto b:yy){
            if(ss.find({a,b})==ss.end()){
                ok=1;
                break;
            }
        }
    }
    if(!ok) ans--;
    cout<<ans<<nl;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); ll t=1;
    //cin>>t; //comment for single test
    while(t--) solve();
}

Measured memory_bytes: 54664
from math import gcd
a, b, c, d = map(int, input().split())
lcm = c*d // gcd(c, d)
ans = b - (b//c + b//d - b//lcm) - (a-1 - ((a-1)//c + (a-1)//d - (a-1)//lcm))
print(ans)

Measured memory_bytes: 9180
def countyaku(m):
    count = 0
    for i in range(1,m+1):
        if m%i==0:
            count += 1
    if count == 8:
        return True
    else:
        return False
n = int(input())
if n<105:
    print(0)
else:
    ans = 0
    for j in range(105,n+1,2):
        if countyaku(j):
            ans += 1
    print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int s[55][55];
int x[55],y[55],t[55];

int main(void){
	int i,j;

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int W,H,T,p;
	cin >> W >> H >> T >> p;
	for(i=0;i<p;i++) cin >> x[i] >> y[i] >> t[i];
	for(i=0;i<H;i++) for(j=0;j<W;j++) cin >> s[i][j];

	int ans=0;
	for(i=0;i<p;i++){
		if(s[y[i]][x[i]]) ans+=s[y[i]][x[i]];
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long int ll;

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

    ll ans = b / x - a / x;
    if(a % x == 0){
        ans++;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = 1000000000;
int main(){
    int H, N;
    cin >> H >> N;
    int A[N+1], B[N+1];
    for(int i=1;i<=N;i++){
      cin >> A[i] >> B[i];
    }
    int dp[H+1][N+1];

    for(int j=0;j<=N;j++){
      dp[0][j] = 0;
    }
    for(int i=0;i<=H;i++){
      dp[i][1] = B[1]*((i+A[1]-1)/A[1]);
    }

    for(int i=1;i<=H;i++){
      for(int j=2;j<=N;j++){
        if(i>A[j]){
          dp[i][j] = min(dp[i][j-1], dp[i-A[j]][j]+B[j]);
        }else{
          dp[i][j] = min(dp[i][j-1], B[j]);
        }      
      }
    }

    cout << dp[H][N] <<endl;

  	return 0;
}





Measured memory_bytes: 39296
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	cin >> n;
	vector<int> cards(n);
	REP(i, n)
		cin >> cards[i];
	ll ans = 0;
	REP(i, n) {
		if (cards[i] >= 2) {
			ans += cards[i] / 2;
			cards[i] %= 2;
		}
		if (i != n - 1) {
			int mi=min(cards[i], cards[i + 1]);
			cards[i] -= mi;
			cards[i + 1] -= mi;
			ans += mi;
		}
	}
	cout << ans << endl;
}

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

int main(){
  int N;
  int A, B;
  int maxA = 0;
  int ans = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A; cin >> B;
    if(A>maxA){ maxA = A; ans = A+B; }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long s64;
s64 sumArray[200000];
int N;

void calcLR(int first, int last, int leftLast, s64* left, s64* right)
{
    *left = sumArray[leftLast];
    if (first != 0)
    {
        *left -= sumArray[first - 1];
    }
    *right = sumArray[last] - sumArray[leftLast];
}

int findLeftLast(int first, int last, int candFirst, int candLast, int depth)
{
    if (depth > 200000)
    {
        return 0;
    }
    if (candLast - candFirst == 1)
    {
        s64 left, right;
        calcLR(first, last, candFirst, &left, &right);
        s64 diff1 = abs(left - right);
        calcLR(first, last, candLast, &left, &right);
        s64 diff2 = abs(left - right);
        if (diff1 < diff2)
        {
            return candFirst;
        }
        else
        {
            return candLast;
        }
    }
    int llast = (candFirst + candLast) / 2;
    s64 left, right;
    calcLR(first, last, llast, &left, &right);
    if (left == right)
    {
        return llast;
    }
    else if (left < right)
    {
        if (llast == last - 1)
        {
            return llast;
        }
        return findLeftLast(first, last, llast, candLast, depth + 1);
    }
    else
    {
        if (llast == 0)
        {
            return llast;
        }
        return findLeftLast(first, last, candFirst, llast, depth + 1);
    }
}

int main()
{
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        int a;
        cin >> a;
        if (i == 0)
        {
            sumArray[i] = a;
        }
        else
        {
            sumArray[i] = sumArray[i - 1] + a;
        }
    }

    auto calc = [](int first, int last, s64* min, s64* max) {
        int leftLast = findLeftLast(first, last, first, last - 1, 0);
        s64 left, right, diff;
        calcLR(first, last, leftLast, &left, &right);
        if (left < right)
        {
            *min = left;
            *max = right;
        }
        else
        {
            *min = right;
            *max = left;
        }
    };

    s64 diffMin = -1;
    for (int leftLast = 1; leftLast <= N - 3; ++leftLast)
    {
        s64 leftMin, leftMax, rightMin, rightMax;
        calc(0, leftLast, &leftMin, &leftMax);
        calc(leftLast + 1, N - 1, &rightMin, &rightMax);
        s64 diff = max(leftMax, rightMax) - min(leftMin, rightMin);
        if (diffMin == -1 || diff < diffMin)
        {
            diffMin = diff;
        }
    }
    cout << diffMin << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<map>
#include<queue>
#include<cmath>
#include<ctime>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
inline int read(){
	int ans=0,fh=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		ans=ans*10+ch-'0',ch=getchar();
	return ans*fh;
}
const int maxn=1e5+100;
int f[maxn],n,h[maxn];
int main(){
//	freopen(".in","r",stdin);
	n=read();
	for(int i=1;i<=n;i++) scanf("%d",&h[i]);
	f[1]=0,f[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++)
		f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
	printf("%d\n",f[n]);
	return 0;
}








Measured memory_bytes: 896
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] a = new long[n];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		long [] sum = new long[n + 1];
		for(int i = 0; i < n; i++) sum[i + 1] = (sum[i] + a[i]) % m;
		Map<Long, Integer> map = new HashMap<>();
		for(int i = 0; i < n + 1; i++) {
			if(map.containsKey(sum[i])) map.put(sum[i], map.get(sum[i]) + 1);
			else map.put(sum[i], 1);
		}
		long ans = 0;
		for(long key : map.keySet()) {
			if(map.get(key) >= 2) {
				long x = map.get(key);
				ans += x * (x - 1) / 2;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 63492
#include<bits/stdc++.h>
using namespace std;
#define  vi vector<long long int>
#define  set1 set<long long int>
#define  pb push_back
#define  map1 map<long long int,long long int>
#define  ll long long int
#define  mp make_pair
#define  inf 1e17
#define  minf INT_MIN
#define  setbits(x) __builtin_popcountll(x)
#define  pres(x,y) fixed<<setprecision(y)<<x
#define  pair1 pair<long long int,long long int>
#define  mk(arr,n,type) type *arr=new type[n];
#define  mod 1000000007
#define  pi  3.1415926535897932384626433832
#define  ins insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//find_by_order() --> returns an iterator to the k-th largest element (counting from zero)
//order_of_key()  --> the number of items in a set that are strictly smaller than our item.
#define  w(t) long long int t;t=1;while(t--)


void solve() {

	ll n, w;
	cin >> n >> w;
	ll wt[n], val[n];
	for (ll i = 0; i < n; i++) {
		cin >> wt[i] >> val[i];
	}
	ll dp[n + 1][w + 1];
	memset(dp, 0, sizeof(dp));

	for (ll i = 1; i <= n; i++) {
		for (ll j = 1; j <= w; j++) {
			if (wt[i - 1] <= j) {
				dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - wt[i - 1]]);
			}
			else
				dp[i][j] = dp[i - 1][j];
		}
	}
	cout << dp[n][w ] << "\n";


}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("inp.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	w(t) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 82444
#include <stdio.h>

int main(){
  int v[5],k;
  int test = 0;
  for(int i=0; i<5; i++)
    scanf("%d", &v[i]);
  scanf("%d", &k);
  for(int i=0; i<5; i++){
    for(int j=i+1; j<5; j++){
      if(v[j]-v[i] > k)
        test++;
    }
  }
  if(test == 0)
    printf("Yay!\n");
  else
    printf(":(\n");
  return 0;
}


Measured memory_bytes: 128
n, m = gets.split(" ").map(&:to_i)
ary = []
m.times do
  ary << gets.split(" ").map(&:to_i)
end
 
if m == 0
  if n == 1
    puts 0
    exit
  else
    puts 10**(n-1)
    exit
  end
end
 
ary = ary.sort!
 
# [1,0]がOKなとき
if n == 1 && ary.include?([1, 0])
  puts 0
  exit
end
 
# [1,0]がダメなとき
if n > 1 && ary.include?([1, 0])
  puts -1
  exit
end
 
if m >= 2
  (m-1).times do |i|
    if ary[i][0] == ary[i+1][0] && ary[i][1] != ary[i+1][1]
      puts -1
      exit
    end
  end
end
 
num = "0"*n
 
m.times do |i|
  num[(ary[i][0]-1)] = "#{ary[i][1]}"
end
 
if num[0] != "0"
  puts num.to_i
else
  num[0] = "1"
  puts num.to_i
end


Measured memory_bytes: 1788
#include"bits/stdc++.h"
using namespace std;

int main() {
    string s1, s2;
    cin >> s1 >> s2;
    for (int i = 0; i < s1.size(); i++) {
        if (s1[i] != s2[s2.size() - 1 - i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
int n;
string s;
ll ans = 0;

void solve(ll x,ll y){
    if(x==n+1){
        ans += y;
        return;
    }
    ll cur = 0;
    for(ll i=x;i<=n;i++){
        cur = (10*cur) + (s[i]-'0');
        solve(i+1,y+cur);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n+2];
    for(int i=1;i<=n;i++)cin>>a[i];
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(a[i]==i){
            cnt++;
            swap(a[i],a[i+1]);
        }
    }
    cout<<cnt<<endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
  ll a,b,c,d;
  cin >>a>>b>>c>>d;
  ll e=lcm(c,d);
  ll x=a/c,y=a/d,z=a/e;
  if(a%c) x++;
  if(a%d) y++;
  if(a%e) z++;
  ll ans=0;
  if(c*x<=b) ans+= (b-c*x)/c +1;
  if(d*y<=b) ans+= (b-d*y)/d +1;
  if(e*z<=b) ans-= (b-e*z)/e +1;
  ans= b-a+1-ans;
  cout <<ans<<endl;
}


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

int main(){
    int n;
    cin >> n;
    vector <int> b(n);
    vector <int> ans;
    rep(i,n){
        cin >> b[i];
    }

    int k,k2=0;
    rep(i,n){
        k=n-i;
        rep(j,n){
            //cout << k << endl;
            if(b[n-j-1]==k){
                //cout << k << n-j-1 << endl;
                b[n-j-1]=-10;
                ans.push_back(k);
                break;
            }
            if(b[n-j-1]!=-10){
                --k;
            }
            if(j==n-1){
                //cout << i << endl;
                k2=1;
            }
        }
    }

if(k2==0){
    rep(i,n){
        cout << ans[n-i-1] << endl;
    }
}
else{
    cout << -1 << endl;
}

    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using std::min;
ll n;
ll minn=LLONG_MAX;
int main()
{
    scanf("%lld",&n);
    for (ll i=1;i*i<=n;i++)
    if (n%i==0) minn=min(minn,i+n/i-2);
    printf("%lld\n",minn);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  long long x,y;cin>>x>>y;
  long long res=1ll<<60;
  if (y>=x)res = min(res,y-x);
  if (y>=-x)res = min(res,y+x+1);
  if(-y>=x)res = min(res,-y-x+1);
  if(-y>=-x)res =min(res,-y+x+2);
  cout<<res<<endl;
}


Measured memory_bytes: 384