akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int main()
{
  int p,q,r;
  cin >> p >> q >> r;
  vector<int> ans(6);
  ans.at(0)=p+q;
  ans.at(1)=r+q;
  ans.at(2)=p+r;
  ans.at(3)=q+r;
  ans.at(4)=r+p;
  ans.at(5)=q+p;

  sort(ans.begin(),ans.end());

  cout << ans.at(0) << endl;
  
  

  
  
  
}

Measured memory_bytes: 256
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
brr = gets.chomp.split.map(&:to_i)
crr = gets.chomp.split.map(&:to_i)
sum = 0
n.times do |i|
	sum += brr[arr[i] - 1]
	if i > 0
		sum += crr[arr[i] - 2] if arr[i] == arr[i-1] + 1
	end
end
puts sum 


Measured memory_bytes: 14248
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int n;
    cin >> n;
    double x = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        x += 1.0 / a;
    }

    cout << fixed << setprecision(10) << 1.0 / x << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
    $S=explode(" ",trim(fgets(STDIN)));
    $N=$S[0];
    $A=$S[1];
    $B=$S[2];
    while(true){
        //A
        $An=0;
        if ($A<$B){
            $An=1;
        }else{
            $An=-1;
        }
        if ($A+$An==$B){
            $An=-$An;
        }
        $A+=$An;
        if ($A<1 || $A>$N) {
            $win=1;
            break;
        }
        //B
        $Bn=0;
        if ($B<$A){
            $Bn=1;
        }else{
            $Bn=-1;
        }
        if ($B+$Bn==$A){
            $Bn=-$Bn;
        }
        $B+=$Bn;
        if ($B<1 || $B>$N) {
            $win=0;
            break;
        }
    }
    if ($win==0){
        echo ("Alice");
    }else{
        echo ("Borys");

    }
    ?>

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int ret=0,f=1;
    char ch=getchar();
    while(ch>'9'||ch<'0')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        ret=(ret<<1)+(ret<<3)+ch-'0';
        ch=getchar();
    }
    return ret*f;
}
int n,m,sum,a[105],x,t;
int main()
{
    n=read();
    for(register int i=1;i<=n;i++)
    {
        a[i]=read();
        sum+=a[i];
    }
    m=read();
    for(register int i=1;i<=m;i++)
    {
        x=read();
        t=read();
        printf("%d\n",sum-a[x]+t);
    }
    return 0;
}

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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define _upgrade                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template <typename _T>
inline void _DBG(const char *s, _T x)
{
    cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a)
{
    while (*s != ',')
        cerr << *s++;
    cerr << " = " << x << ',';
    _DBG(s + 1, a...);
}

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr \
    if (0)   \
    cout
#endif

// ********************** CODE ********************** //

bool ok(int p1, int p2, bool s1, bool s2)
{
    if((p1 - p2) % 2 == 0)
        return s1 == s2;
    else
        return s1 != s2;
}

bool sex(int i)
{
    cout << i << "\n";
    cout.flush();
    string ans; cin >> ans;
    if(ans == "Vacant")
    {
        exit(0);
    }
    if(ans == "Male")
        return 1;
    else
        return 0;
}

int main()
{
    int n; cin >> n;
    int l = 0;
    int sl = sex(0);
    int r = n - 1;
    int sr = sex(n - 1);
    while(l + 1 < r)
    {
        int m = (l + r) / 2;
        bool sm = sex(m);
        if(ok(l, m, sl, sm))
            l = m, sl = sm;
        else
            r = m, sr = sm;
    }
    return 0;
}


Measured memory_bytes: 852
#include <stdio.h>

int main(void) {
  int x, a, b;

  scanf("%d", &x);
  scanf("%d", &a);
  scanf("%d", &b);

  x -= a;

  while (x >= b) {
    x -= b;
  }

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

  return 0;
}

Measured memory_bytes: 128
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

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

def func(a):
    rtn = 0
    while a % 2 == 0:
        a //= 2
        rtn+=1
    return rtn

for i in range(n):
    a[i] = func(a[i])
print(min(a))



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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

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

	ll a;
 	cin >> a;
	string s;
	cin >> s;
	if (a < 3200) s = "red";
	cout << s << endl;
 	return 0;
}


Measured memory_bytes: 256
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)

Measured memory_bytes: 9152
A,B,C,D=map(int,input().split())

c=B//C-(A-1)//C
d=B//D-(A-1)//D

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a
L=C*D//gcd(C,D)
l=B//L-(A-1)//L
print(int(B-A+1-c-d+l))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint x(N+2);
    for(int i=1;i<=N;i++) cin>>x[i];
    x[0]=x[N+1]=0;


    int sum=0;
    REP(i,N+1) sum+=abs(x[i+1]-x[i]);

    for(int i=1;i<=N;i++){
        int diff=-(abs(x[i]-x[i-1])+abs(x[i+1]-x[i]))+abs(x[i+1]-x[i-1]);
        cout<<sum+diff<<endl;
    }
}


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

    typedef long long int ll;
    #define pb         push_back
    #define mp         make_pair
    #define F          first
    #define S          second
    #define fl(i,a,b)  for(ll i=a;i<b;i++)
    #define pll        pair<ll,ll>
    #define pii        pair<int,int>
    #define all(v)     v.begin(),v.end()
    #define M 1000000007
    #define tr(v, it) for(auto it = v.begin(); it != v.end(); it++)
    using namespace std;

    int main()
    {

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

       int n;
       cin>>n;
        int arr[n];
        for(int i=0; i<n; i++)
            cin>>arr[i];
        vector<int> dp(n+1, INT_MAX);

        dp[1]=0;
        dp[0]=0;
        for(int i=2; i<=n; i++)
        {
            if(i-1>= 1)
                dp[i]=min(dp[i], dp[i-1]+abs(arr[i-1]-arr[i-2]));
            if((i-2)>=1)
                dp[i]= min(dp[i], dp[i-2]+abs(arr[i-1]-arr[i-3]));
        }
        cout<<dp[n];
        return 0;

    }



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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	int result = 0;
	for( int i = 0; i < N; ++i ) {
		int x;
		cin >> x;
		result += x - 1;
	}

	cout << result << endl;

	return 0;
}


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

using namespace std;

int n, m, q;
int a[51], b[51], c[51], d[51];
int arr[51];
int ans = 0;

void f(int depth, int last){
    if(depth > n){
        int sc = 0;
        for(int i = 1; i <= q; i++){
            if(arr[b[i]] - arr[a[i]] == c[i]) sc += d[i];
        }

        ans = max(ans, sc);
        return;
    }
    
    for(int i = last; i <= m; i++){
        arr[depth] = i;
        f(depth + 1, i);
    }
}

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

    cin >> n >> m >> q;

    for(int i = 1; i <= q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];

    f(1, 1);

    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3596
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[int(input()) - 1])

Measured memory_bytes: 9172
from itertools import accumulate


def main():
    section_num = int(input())
    length = list(map(int, input().split()))
    accumulate_length = list(accumulate(length))
    answer = float("inf")
    for i in range(0, section_num):
        answer = min(answer, abs(accumulate_length[-1] - 2 * accumulate_length[i]))
    print(answer)


if __name__ == '__main__':
    main()



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

using namespace std;


void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    int res = 0;
    for (int i = 1; i < n-1; i++) {
        if (a[i-1]>a[i] && a[i]>a[i+1]) res++;
        if (a[i-1]<a[i] && a[i]<a[i+1]) res++;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp
{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=0,tail=0,n;

void enqueue(P);
P dequeue(void);

int main()
{
  int elaps=0,c=0;
  int i,q;
  P u;
  scanf("%d%d",&n,&q);

  for(i=1;i<=n;i++)
    {
      scanf("%s",Q[i].name);
      scanf("%d",&Q[i].t);
      enqueue(Q[i]);
    }

  while(c<n)
    {
      u=dequeue();
      if(u.t > q)
	{
	elaps+=q;
	u.t-=q;
	enqueue(u);
	}
      else if(u.t <= q)
	{
	  c++;
	  elaps+=u.t;
	  printf("%s %d\n",u.name,elaps);
	}
    }
  return 0;
}

void enqueue(P x)
{
  if(head == (tail +1)%LEN)
    {
      printf("error(over flow)");
    }
  Q[tail]=x;
  if(tail+1 == LEN)
    {
      tail=0;
    }
  else
    {
      tail++;
    } 
}


P dequeue(void)
{
  P x;
  if(head == tail)
    {
      printf("error(under flow)");
    }
  x=Q[head];
  if(head+1 == LEN)
    {
      head =0;
    }
   else
    {
      head++;
    }
  return x;
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1000010, M = 25;

int a, b;

int main()
{
	cin >> a >> b;
	for (int i = 1; i < N; i ++ )
	{
		int x = i * 2 / 25;
		int y = i / 10;
		if (x && y && x == a && y == b)
		{
			cout << i << endl;
			return 0;
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

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

        String s = in.next();
        for(int i = 0; i < s.length(); i++) {
            if(i%2==0) System.out.print(s.charAt(i));
        }
        System.out.println();
    }
}


Measured memory_bytes: 28760
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
#include <math.h>

using namespace std;

struct PC{
	int login_time;
};


bool** timeTable;

void func(int numPC,int numStudent){

	for(int i = 0; i < 10001; i++){
		for(int k = 0; k < 721;k++){
			timeTable[i][k] = false;
		}
	}

	PC pcInfo[1001];

	int r,time,pc_id,student_id,type;

	scanf("%d",&r);

	for(int i = 0; i < r; i++){
		scanf("%d %d %d %d",&time,&pc_id,&student_id,&type);

		if(type == 1){ //?????°???????¨????
			pcInfo[pc_id].login_time = time;
		}else{ //?????°??¢???????¨????<bool??¨????????????>
			for(int k = pcInfo[pc_id].login_time; k <= time; k++){
				timeTable[student_id][k-540] = true;
			}
			pcInfo[pc_id].login_time = 0;
		}
	}

	int q,start,end,count,left,right;

	scanf("%d",&q);

	for(int i = 0; i < q; i++){
		scanf("%d %d %d",&start,&end,&student_id);

		count = 0;
		left = -1,right = -1;

		for(int k = start; k <=end; k++){
			if(timeTable[student_id][k-540]){
				if(left == -1){
					left = k-540;
				}else{
					right = k - 540; //?¬????false?????????????????\??????????????§?????????right??´??°
				}
				if(k == end){
					if(right == -1){ //????????????????????°??????????????´???
						//Do nothing
					}else{
						count += right - left;
					}
				}
			}else{
				if(right != -1){
					count += right - left;
					left = right = -1;
				}
			}
		}
		printf("%d\n",count);
	}
}


int main(){

	int numPC,numStudent;

	timeTable = new bool*[10001];
	for(int i = 0; i < 10001; i++){
		timeTable[i] = new bool[721];
	}

	while(true){
		scanf("%d %d",&numPC,&numStudent);
		if(numPC == 0 && numStudent == 0)break;

		func(numPC,numStudent);
	}

    return 0;
}

Measured memory_bytes: 10484
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i=s; i<t; ++i)
#define pb push_back
using namespace std;
using P = pair<int,int>;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef tuple<int,int,int> T;
typedef vector<P> vp;
typedef vector<T> vt;

// head
int main(void){
  int r;
  cin >> r;
  const double PI=3.14;
  cout << 2*r*PI << endl;
  return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)


P tree[1000000];
int value[1000000];
int ind = 1;

void Preorder(int i=0){
	if(i)cout << ' ' << value[i];
	if(~tree[i].first)Preorder(tree[i].first);
	if(~tree[i].second)Preorder(tree[i].second);
}
void Inorder(int i=0){
	if(~tree[i].first)Inorder(tree[i].first);
	if(i)cout << ' ' << value[i];
	if(~tree[i].second)Inorder(tree[i].second);
}
void Postorder(int i=0){
	if(~tree[i].first)Postorder(tree[i].first);
	if(~tree[i].second)Postorder(tree[i].second);
	if(i)cout << ' ' << value[i];
}
void in(int x){
	int v = 0;
	while(1){
		if(x<value[v]){
			if(~tree[v].first){
				v = tree[v].first;
			}else{// -1の時
				value[ind] = x;
				tree[v].first = ind;
				ind++;
				return;
			}
		}else{
			if(~tree[v].second){
				v = tree[v].second;
			}else{// -1の時
				value[ind] = x;
				tree[v].second = ind;
				ind++;
				return;
			}
		}
	}
}

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

	FOR(i,0,1000000)tree[i]={-1,-1};
	FOR(i,0,1000000)value[i]=-1;
	value[0] = 2000000002;

	int n;
	cin >> n;
	FOR(i,0,n){
		string s;
		cin >> s;
		if(s=="insert"){
			int key;
			cin>>key;
			in(key);
		}else{
			Inorder();
			cout << '\n';
			Preorder();
			cout << '\n';
		}
	}
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li sum_e[300300];
li sum_w[300300];

int main() {
    string s;
    cin >> s;
    li res = 0;
    rep(i, sz(s)) {
        res += (s[i] == '+' ? 1 : -1);
    }
    cout << res << endl;



    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(int(i) for i in input().split())
"""
N = 5
H = [1,2,1,1,3]
"""
if len(H) == 1:
    print("Yes")

for i in range(1,N):
    if H[-i-1] - H[-i] > 0:
        H[-i-1] = H[-i-1] - 1
        # print(H[-i])
        # print(H[-i-1])
        if H[-i-1] - H[-i] > 0:
            print("No")
            break
    if i == N-1:
        print("Yes")

Measured memory_bytes: 14396
h,w = gets.chomp.split.map(&:to_i)
ps = h.times.map{gets.chomp.chars}
ans = Array.new(2*h){Array.new(w)}

(2*h).times do |i|
	w.times do |j|
		ans[i][j] = ps[i/2][j]
	end
end

ans.each do |a|
	puts a.join
end

Measured memory_bytes: 3836
rate = [0 for _ in range(8)]
frate = 0

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

for i in range(n):
    if a[i] < 400:
        rate[0] += 1

    elif a[i] < 800:
        rate[1] += 1

    elif a[i] < 1200:
        rate[2] += 1

    elif a[i] < 1600:
        rate[3] += 1

    elif a[i] < 2000:
        rate[4] += 1

    elif a[i] < 2400:
        rate[5] += 1

    elif a[i] < 2800:
        rate[6] += 1

    elif a[i] < 3200:
        rate[7] += 1

    else:
        frate += 1

#print(rate)

iro = len(list(filter(lambda x: x != 0, rate)))

if iro == 0:
    print(1, frate)

elif frate == 0:
    print(iro, iro)

else:
    print(iro, iro + frate)


Measured memory_bytes: 3064
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	a, _ := sc.NextInt()
	v, _ := sc.NextInt()
	b, _ := sc.NextInt()
	w, _ := sc.NextInt()
	t, _ := sc.NextInt()
	ans := solve(a, v, b, w, t)
	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func solve(a, v, b, w, t int) bool {
	dist := a - b
	if dist < 0 {
		dist *= -1
	}
	velocity := v - w
	return dist-velocity*t <= 0
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}


Measured memory_bytes: 1756
//writer：Sakura
//problem：
//id：
//from：

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
//#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

//快读（可去）
/**/
inline int read(){
	int S=0,W=1;
	char CH=getchar();
	while(CH<='0' || CH>'9'){
		if(CH=='-')W=-1;
		CH=getchar();
	}
	while(CH>='0' && CH<='9')S=S*10+CH-'0',CH=getchar();
	return S*W;
}

int n;
string s;
int ans=0;
int cnt=0;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	cin>>s;
	for(int i=1;i<n;i++){
		cnt=0;
		for(char c='a';c<='z';c++){
			bool left=false,right=false;
			for(int j=0;j<i;j++){
				if(s[j]==c)left=true;
			}
			for(int j=i;j<n;j++){
				if(s[j]==c)right=true;
			}
			if(left && right)cnt++;
		}
		ans=max(ans,cnt);
	}
	printf("%d\n",ans);
	return 0;
}



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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

void solve() {
	double ans = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		double x;
		string u;
		cin >> x >> u;
		if (u == "JPY") {
			ans += x;
		} else {
			ans += x * 380000.0; 
		}
	}

	cout << fixed << setprecision(9) << ans << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#define PI acos(-1.0)
using namespace std;
const int N = 1e5 + 5;
int l[N],r[N];
int main(){
	int n,m;
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		scanf("%d %d",&l[i],&r[i]);
	}
	sort(l,l+m);
	sort(r,r+m);
	if(r[0] >= l[m-1])
	cout << r[0] - l[m-1] + 1 << endl;
	else cout << 0 <<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if (a==b) cout << c << endl;
  else if(a==c) cout << b << endl;
  else cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll n, k;
	cin >> n >> k;
	VecB a(n, true);
	rep(i, k){
		ll d;
		cin >> d;
		rep(i, d){
			ll b;
			cin >> b;
			a[--b] = false;
		}
	}

	ll ans = 0;
	rep(i, n) if(a[i]) ans++;
	co(ans);

	return 0;
}


Measured memory_bytes: 3628
/* When Talent doesn't work, Hard work beats Talent*/

#include"bits/stdc++.h"

using namespace std;

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI=3.141592653589793;

void solve()
{
	long double a,b,h,m;
	cin>>a>>b>>h>>m;
	long double ang=m*6;
	long double s=(h+m/60.0)*30;
	ang=abs(s-ang);
	ang=ang*PI/180;
	long double len= a*a + b*b - 2*a*b*cos(ang);
	len=sqrt(len);
	cout<<fixed<<setprecision(20)<<len<<nl;
	return ;
}

int32_t main()
{
	FastIO;
	solve();
	return 0;
}


Measured memory_bytes: 4124
#include <iostream>
#include <math.h>
using namespace std;

bool sosuu(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  int n, s=0, a;
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> a;
    if (a!=1 && sosuu(a)) {
      s++;
    }
  }
  cout << s << endl;
  return 0;
}



Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[200009];
long long F[200009];
main() {
	int n;
	cin >> n;
	for (int i = 0;i < n-1; i++) {
		int a,b;
		cin >>a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for (int i  = 1; i <= n;i++) 
		sort(adj[i].begin(),adj[i].end());
	long long ans = 0;
	for (int i = 1; i <= n;i++) {
		F[i] = F[i-1];
		int  it =lower_bound(adj[i].begin(),adj[i].end(),i) - adj[i].begin();
		it--;
		if (it < 0) {
			F[i] = F[i-1] + i;
			continue;
		}
		int cur = i,val = 1;
		for (int j = it; j >= 0; j--) {
			F[i] += 1ll*(cur - adj[i][j])*val;
			val--;
			cur = adj[i][j];
		}
		F[i] += 1ll*(adj[i][0])*(val);
	}
	for (int i = 1; i <= n; i++)
		ans += F[i];
	cout << ans;
}

Measured memory_bytes: 16476
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
ans = 0
cnt = 1
pos = 0
for i in range(n-1):
    if cnt == 2:
        pos += 1
        cnt = 0
    ans += a[pos]
    cnt += 1
print(ans)


Measured memory_bytes: 94200
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;

template<class T>inline void read(T &re)
{
    char ch;int f=1;
    while((ch=getchar())<'0'||ch>'9')
    if(ch=='-')f=-1;
    re=ch-48;
    while((ch=getchar())>='0'&&ch<='9')
    re=(re<<3)+(re<<1)+ch-48;
    re*=f;
}

inline int min(int x,int y){
    return x<y?x:y;
}

struct node{
    int x,y,w;
}ch[maxn];

int fa[maxn];
long long w[maxn],min1[maxn],min2[maxn];

inline bool comp(const node &a,const node &b){
    if(a.y!=b.y)return a.y<b.y;
    return a.x<b.x;
}

inline int getfa(int x){
    if(fa[x]==x)return x;
    int nf=getfa(fa[x]);
    w[x]+=w[fa[x]];
    return fa[x]=nf;
}

inline bool unionn(int a,int b,long long W)
{
    int a1=getfa(a),b1=getfa(b);
    if(a1!=b1){
        fa[a1]=b1;
        w[a1]=W+w[b]-w[a];//b-a+b1-b+a-a1=W+w[b]-w[a]=b1-a1
        return true;
    }
    else return w[a]==W+w[b];//b-a+b1-b=b1-a=w[a] 判断是否会矛盾 
}

int main()
{
//	freopen("then1.in","r",stdin);
//	freopen("then.out","w",stdout);
    int T,r,c,n;
        bool fl=true;
        read(r);read(c);//h l
        read(n);
        for(register int i=1;i<=n;++i){
            read(ch[i].x);read(ch[i].y);read(ch[i].w);//h l val
            if(ch[i].w<0)fl=false;
        }
        if(fl==false){
            printf("No\n");
            return 0;
        }
        else if(r==1){
            printf("Yes\n");
            return 0;
        }
        for(register int i=1;i<=r;++i){
            fa[i]=i;w[i]=0;
        }
        std::sort(ch+1,ch+1+n,comp);
        for(register int i=1;i<n;++i)
        if(ch[i].y==ch[i+1].y)
            if(!unionn(ch[i].x,ch[i+1].x,ch[i+1].w-ch[i].w))
                fl=false;
        
        for(register int i=1;i<=r;++i)
        min1[i]=min2[i]=2e16;
        
        for(register int i=1;i<=n;++i){
            int rt=getfa(ch[i].x);
            min1[rt]=min(min1[rt],ch[i].w+w[ch[i].x]);
        }
        for(register int i=1;i<=r;++i){
            int rt=getfa(i);
            min2[rt]=min(min2[rt],-w[i]);
        }
        for(register int i=1;i<=r;++i)
        if(fa[i]==i&&min2[i]+min1[i]<0){
            fl=false;break;
        }
        if(fl)printf("Yes\n");
        else printf("No\n");
    return 0;
}

Measured memory_bytes: 4096
def reverse_insort(a, x):
    lo = 0
    hi = len(a)
    while lo < hi:
        mid = (lo + hi) // 2
        if x > a[mid]:
            hi = mid
        else:
            lo = mid + 1
    return lo


n = int(input())

ans = []
ans.append(int(input()))

for i in range(n - 1):
    t = int(input())
    ch = 0
    if t <= ans[-1]:
        ans.append(t)
    else:
        ans[reverse_insort(ans, t)] = t

print(len(ans))


Measured memory_bytes: 7072
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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 namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll a, b, n;
    cin >> a >> b >> n;

    if (n >= b) n = b-1;

    cout << a * n / b << endl;
    


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

Measured memory_bytes: 3580
#include <cstdio>
#define R(i, n) for(int i = 0;i < n;i++)
#define RR(i, n) for(int i = n;i >= 0;i--)
#define F(i, m, n) for(int i = m;i < n;i++)
#define FR(i, m, n) for(int i = m; i >= n; i--)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define P(a) printf("%d", a)
using namespace std;


int A, B;

int main() {
	S2(A, B);
	if (A != 1 && B != 1) P(1);
	else if (A != 2 && B != 2) P(2);
	else P(3);
}

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

public class Main {

	static Scanner scanner;
    static int min=Integer.MAX_VALUE;
    static long G;
    static long[] P;
    static long[] C;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int D=gi();
	    G=gl();
	    P=new long[D];
	    C=new long[D];
	    for (int i=0; i<D;i++) {
	    	P[i]=gl();
	    	C[i]=gl();
	    }


        List<Integer> l= new ArrayList<Integer>();
        f(l, D);
        System.out.println(min);
//	    if(max>s-max) {
//	    	System.out.println(s-max-1);
//	    }
	}

	public static void f(List<Integer> l, int n) {
		if(l.size()==n) {
			long score=0;
			int c=0;
			for (int i=0; i<n;i++) {
				int index=l.get(i);
				if(index*100*P[index-1] +C[index-1] >=G-score) {
				    for (int j=0; j<P[index-1]; j++) {
					    score+=index*100;
					    c++;
					    if(j==P[index-1]-1) score+=C[index-1];
				    	if(score>=G) {
						    if (c<min)min=c;
					    	return;
				    	}
			    	}
				} else {
					score +=index*100*P[index-1] +C[index-1];
					c+=P[index-1];
				}
			}
			return;
		}
		for (int i=1; i<=n;i++) {
			if (!l.contains(i)) {
				List<Integer> nl=new ArrayList<Integer>();
				nl.addAll(l);
				nl.add(i);
				f(nl, n);
			}
		}
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

typedef long long LL;

const int maxn=1e5+5;
const LL big=1e9;

LL S,a,b;

int main()
{
	scanf("%lld",&S);
	
	// (0,0) (1e9,1) (b,a) S=1e9*a-b
	a=(S+big-1)/big, b=big*a-S;
	printf("0 0 %lld 1 %lld %lld\n",big,b,a);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	
	int a=0, b=0;
	for(int i=2; i<=n; i++){
		a = a+i-1;
	}
	for(int j=2; j<=m; j++){
		b = b+j-1;
	}
	printf("%d\n", a+b);
	return 0;
}

Measured memory_bytes: 2084
n = int(input())
x0 = [[0,0,0]]
for i in range(n):
    x0 += [list(map(int,input().split()))]
flag = 1
for i in range(1,n+1):
    x1 = x0[i-1]
    x2 = x0[i]
    dt = x2[0]-x1[0]
    dx = abs(x2[1]-x1[1])
    dy = abs(x2[2]-x1[2])
    if dx+dy-dt>0:
        flag=0
        break
    else:
        if (dt-dx-dy)%2==1:
            flag = 0
            break
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27380
import sys

n,k=map(int,input().split())
s=list(map(int,input().split()))
s.sort(reverse=True)

if k<len(s):
  for i in range(k):
    s[i]=0
else:
  for i in range(n):
    print(0)
    sys.exit()

print(sum(s))

Measured memory_bytes: 26764
<?php
list($n,$k)=explode(" ",trim(fgets(STDIN)));
$a=explode(" ",trim(fgets(STDIN)));
$ans=count($a);
$a=array_count_values($a);
rsort($a);
$i=0;
$k=min(count($a),$k);
while($i<$k){
    $ans-=$a[$i];
    ++$i;
}
echo $ans;

Measured memory_bytes: 29680
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) counts(N, 0);
    int ret = 0;
    const int MOD = 1000000007;

    FOR(i, 0, N) {
        int a;
        cin >> a;
        counts[a]++;
        if (counts[a] > 2)
            goto done;
    }

    ret = 1;
    for (int d = N - 1;d >= 0;d -= 2) {
        int cnt = d == 0 ? 1 : 2;
        if (counts[d] != cnt) {
            ret = 0;
            goto done;
        }
        if (cnt == 2)
            ret = ret * 2 % MOD;
    }

done:
    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 768
#include<stdio.h>
#define MOD (10007)
int t[1001][7];

void exclude(int i,char c){
    if(c=='J'){
	t[i][3]=t[i][5]=t[i][6]=0;
    }
    if(c=='O'){
	t[i][2]=t[i][4]=t[i][6]=0;
    }
    if(c=='I'){
	t[i][1]=t[i][4]=t[i][5]=0;
    }
}

int main(void){
    int n;
    char s[1001];
    int i,j;
    int ans;

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

    for(i=0;i<=6;i++){
	t[1][i]=1;
    }
    exclude(1,'J');
    exclude(1,s[0]);

    for(i=2;i<=n;i++){
	t[i][0]=(t[i-1][0]+t[i-1][1]+t[i-1][2]+t[i-1][3]+t[i-1][4]+t[i-1][5]+t[i-1][6])%MOD;
	t[i][1]=(t[i-1][0]+t[i-1][1]+t[i-1][2]+t[i-1][3]+t[i-1][4]+t[i-1][5])%MOD;
	t[i][2]=(t[i-1][0]+t[i-1][1]+t[i-1][2]+t[i-1][3]+t[i-1][4]+t[i-1][6])%MOD;
	t[i][3]=(t[i-1][0]+t[i-1][1]+t[i-1][2]+t[i-1][3]+t[i-1][5]+t[i-1][6])%MOD;
	t[i][4]=(t[i-1][0]+t[i-1][1]+t[i-1][2]+t[i-1][4])%MOD;
	t[i][5]=(t[i-1][0]+t[i-1][1]+t[i-1][3]+t[i-1][5])%MOD;
	t[i][6]=(t[i-1][0]+t[i-1][2]+t[i-1][3]+t[i-1][6])%MOD;
	exclude(i,s[i-1]);
    }

    ans=0;
    ans=(t[n][0]+t[n][1]+t[n][2]+t[n][3]+t[n][4]+t[n][5]+t[n][6])%MOD;
    printf("%d\n",ans);

    return 0;
}

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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

bool dp[2][5001][5001];

void dodp(const vi& v,int p) {
	dp[p][0][0]=1;
	for (int i=0;i<v.size();i++) for (int j=0;j<5000;j++) if (dp[p][i][j]) {
		dp[p][i+1][j]=1;
		if (j+v[i]<=5000) dp[p][i+1][j+v[i]]=1;
	}
}

vi a;
int N,K,r;

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

	cin >> N >> K;
	a.resize(N);
	for (int &i:a) cin >> i;
	dodp(a,0);
	reverse(a.begin(),a.end());
	dodp(a,1);
	reverse(a.begin(),a.end());
	for (int i=0;i<N;i++) {
		int j=i,k=N-1-i,M=0;
		for (int l=0,m=K-1;l<K;l++) if (dp[0][j][l]) {
			for (;l+m>=K || !dp[1][k][m];m--);
			smax(M,l+m);
		}
		if (M+a[i]<K) r++;
	}
	cout << r << endl;
}

Measured memory_bytes: 49152
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main(){
    string S;
    cin >> S;
    
    int ans = 10000;
    int tmp = 0;
    for(int i = 0; i < S.length()-2; i++){
        tmp = stoi(S.substr(i, 3));
        if(abs(tmp - 753) < ans){
            ans = abs(tmp - 753);
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
	int N, K;
	int h[100000];
	long flog[100000];

	scanf("%d", &N);
	scanf("%d", &K);


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

	flog[0] = 0;
	flog[1] = abs(h[0] - h[1]);
	int min, dst, minnum;
	for (int i = 2; i < N; i++) {
		min = dst = flog[i - 1] + abs(h[i - 1] - h[i]);
		minnum = 1;
		for (int k = 1; k <= K; k++) {
			if (i - k < 0) break;
			dst = flog[i - k] + abs(h[i - k] - h[i]);
			if (dst < min) {
				min = dst;
				minnum = k;
			}
		}
		flog[i] = min;
	}

	printf("%ld", flog[N - 1]);

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-12;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

void run() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (a > b) {
        cout << "0\n";
        return;
    }
    if (n == 1) {
        cout << (a == b ? 1 : 0) << "\n";
    } else if (n == 2) {
        cout << "1\n";
    } else {
        cout << a + b * (n - 1) - (a * (n - 1) + b) + 1 << "\n";
    }
}


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

int main() {
    int n;
    cin >> n;
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        m[a]++;
    }

    bool ok = false;
    if (m.size() == 1) {
        int a = m.begin() -> first;
        if (a == n - 1 || 2 * a <= n) ok = true;
    }
    else if (m.size() == 2) {
        int x = m.begin() -> second, y = m.rbegin() -> second;
        int a = m.rbegin() -> first;
        int b = m.begin() -> first;
        if (a - b == 1 && x < a && 2 * (a - x) <= y) ok = true;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int a;
string s;

int main(void) {

	cin >> a;
	cin >> s;

	if (a >= 3200) { cout << s << endl; }
	else { cout << "red" << endl; }


	return 0;
}

Measured memory_bytes: 256
import copy

N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())

argmax_A = A.index(max(A))
B = copy.copy(A)
del(B[argmax_A])
ans = max(B)

for i in range(N):
    if i == argmax_A:
        print(ans)
    else:
        print(A[argmax_A])

Measured memory_bytes: 58712
#include<iostream>

using namespace std;

#define MAX 500

int main(){

	int n;
	int w,h;
	int map[MAX+1][MAX+1];
	int x,y;
	int s,t;
	int cnt,max;

	while(1){
		cin>>n;
		if(n==0) break;
		cin>>w>>h;

		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				map[i][j]=0;
			}
		}

		for(int i=0;i<n;i++){
			cin>>x>>y;
			map[y][x]=1;
		}

		cin>>s>>t;

		max=0;

		for(int i=1;i<=h-t+1;i++){
			for(int j=1;j<=w-s+1;j++){
				cnt=0;
				for(int k=0;k<t;k++){
					for(int l=0;l<s;l++){
						if(map[i+k][j+l]==1) cnt++;
					}
				}
				if(max<cnt) max=cnt;
			}
		}
		cout<<max<<endl;
	}

}

Measured memory_bytes: 1360
import java.util.Scanner;

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

      //整数の個数を格納
        int N = scanner.nextInt();
	 //N個の整数を配列に格納
        int[] a = new int[N];
	 //条件を満たす整数をカウント
        int countflag = 0;

        for(int i = 0; i <= a.length - 1; i++) {
            a[i] = scanner.nextInt();
        }

      //マスの番号が奇数、かつマスに書かれた整数が奇数であるかを判定
        for(int j = 1; j <= N; j++) {
            if((j % 2 == 1) && (a[j - 1] % 2 == 1)) {
                countflag++;
            }
        }

      //結果を出力
        System.out.println(countflag);
	  //スキャナーの解放
        scanner.close();
    }
}

Measured memory_bytes: 35724
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("F:/cpp/input.txt", "r", stdin);
    freopen("F:/cpp/output.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, c, k, ans = 0;
    cin >> a >> b >> c >> k;
    if (k)
    {
        if (k >= a)
        {
            k -= a;
            ans += a;
        }
        else
        {
            ans += k;
            k = 0;
        }
    }
    if (k)
    {
        if (k >= b)
        k -= b;
        else
        k = 0;
    }
    if (k)
    {
        ans -= k;
    }
    cout << ans;
    return 0;
}

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

const int N = 100005;

struct Info{ int s, e, x, y; };

int n, A, t[N], q;
Info a[N];

int main(){
    scanf("%d%d", &A, &n);
    a[0] = {0, A, 0, 0};
    for(int i = 1; i <= n; i++){
        scanf("%d", t + i);
        int dt = t[i] - t[i - 1];
        auto &p = a[i - 1];
        int ns = p.s, ne = p.e;
        if(~i & 1){ ns += dt; ne += dt; }
        else{ ns -= dt; ne -= dt; }
        if(ns >= A) a[i] = {A, A, 0, A};
        else if(ne > A) a[i] = {ns, A, p.x, p.y + ne - A};
        else if(ne <= 0) a[i] = {0, 0, A, 0};
        else if(ns < 0) a[i] = {0, ne, p.x - ns, p.y};
        else a[i] = {ns, ne, p.x, p.y};
    }
    scanf("%d", &q);
    for(int x, y, z; q--; ){
        scanf("%d%d", &x, &y);
        z = int(upper_bound(t, t + n + 1, x) - t - 1);
        y = max(a[z].s, min(a[z].e, a[z].s + y - a[z].x));
        if(z & 1) y = min(A, y + x - t[z]);
        else y = max(0, y - x + t[z]);
        printf("%d\n", y);
    }
}

Measured memory_bytes: 3200
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(A, B),
    get_number(C, D),
    X is max(A * B, C * D),
    writeln(X).


Measured memory_bytes: 8156