akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
        using namespace std;
        long long  N,A,B;
        long long value[51];
        bool comp(long long a,long long b)
        {
            return a>b?true:false;
        }

        long long dp[51][51];

        void init()
        {
        	memset(dp,0,sizeof(dp));
        	dp[0][0]=1;
        	for(int i=1;i<=50;i++)
        	{
        		dp[i][0]=1;
        		for(int j=1;j<=i;j++)
        			dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
        	}
        }
        int main(void)
        {
            cin>>N>>A>>B;
            init();
            for(int i=0;i<N;i++)
            {
                cin>>value[i];
            }
            sort(value,value+N,comp);
            double sum=0.0;
            for(int i=0;i<=A-1;i++)
            {
                sum+=value[i];
            }
            long long  num=0,k=0;
        		for(int i=0;i<N;i++)
        		{
        			if(value[i]==value[A-1])
        			{
        				num++;
        				if(i<A)
        					k++;
        			}
        		}
        		long long ans=0;
        		if(k==A)//前A个相同,可以增加个数
        		{
        			for(int i=A;i<=B;i++)
        				ans+=dp[num][i];
        		}
        		else
        			ans+=dp[num][k];

            printf("%.15f\n",sum/A);
            cout <<ans <<endl;
            return 0;
        }


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;
#define MOD 998244353LL
using namespace std;
 
struct CNK{
	const ll mod = 998244353LL;
	int mx;
   
private:
	vector<ll> fac , ifac;
	   
public:
	CNK(int max){
		mx = max;
	   
		fac.resize(max + 1);
		ifac.resize(max + 1);
	   
		fac[0] = ifac[0] = 1;
	   
		for(int i = 1 ; i <= max ; ++i){
			fac[i] = 1LL * fac[i - 1] * i % mod;
			ifac[i] = fpow(fac[i], mod - 2);
		}
	}
   
	ll fpow(ll a , ll b){
		ll ans = 1;
		while(b > 0){
			if(b & 1){
				ans = (1LL * ans * a) % mod;
			}
			a = (1LL * a * a) % mod;
			b /= 2;
		}
		return ans;
	}
   
	ll cnk(int n , int k){
		assert(mx >= n);
		if (n < 0 || k < 0 || k > n) return 0;
		return 1LL * fac[n] * ifac[n - k] % mod * ifac[k] % mod;
	}
};
 
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
 
	int n , a , b;
	ll k;
	cin >> n >> a >> b >> k;
	ll ans = 0;
	CNK cnk((int)3e5 + 16);
	//cout << "green red blue\n";
	rep(x1 , n + 1){
		int x2 = (k - x1 * a) / b;
		if(1LL * a * x1 + 1LL * b * x2 != k) continue;
		ans += (cnk.cnk(n , x1) * cnk.cnk(n , x2)) % MOD;
		ans %= MOD;
	}
	cout << ans % MOD << endl;
 
	return 0;
}

Measured memory_bytes: 4992
<?php

    fscanf(STDIN, "%d", $n);
    $S = explode(" ", trim(fgets(STDIN)));
    fscanf(STDIN, "%d", $q);
    $T = explode(" ", trim(fgets(STDIN)));

    $ans = 0;
    for ($i = 0; $i < $q; $i++) {
        if (search($n, $S, $T[$i])) {
            $ans++;
            // echo $T[$i] . "found\n";
        } else {
            // echo $T[$i] . "not found\n";
        }
    }
    echo $ans . PHP_EOL;

    function search($n, $S, $a) {
        $ret = null;

        $l = 0;
        $r = $n-1;
        if ($S[$l] == $a || $S[$r] == $a) {
            return true;
        }

        while(is_null($ret)) {
            $m = ceil(($l + $r) / 2);
            if ($l == $m || $r == $m) {
                return false;
            }

            // echo "l:{$l} r:{$r} m:{$m}\n";

            if ($S[$m] == $a) {
                return true;
            } elseif ($S[$m] > $a) {
                $r = $m;
            } else {
                $l = $m;
            }
        }
    }

Measured memory_bytes: 41432
from math import factorial
X, Y = map(int, input().split())
mod = 10**9 + 7

def comb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod

N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

if ((X + Y) % 3 != 0):
    print(0)
else:
    n = - (X - 2 * Y) / 3
    m = (2 * X - Y) / 3
    if not (n % 1 == 0 and m % 1 == 0):
        print(0)
    else:
        if n < 0 or m < 0:
            print(0)
        else:
            print(comb(int(n+m), int(n), mod))

Measured memory_bytes: 121860
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        double r = Double.parseDouble(in.readLine());

        double pi = Math.PI;
        double S = r * r * pi;
        double R = 2 * r * pi;
        System.out.printf("%.6f %.6f", S, R);
    }
}

Measured memory_bytes: 24596
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a(n);
  REP(i,n) a[i] = s[i] - '0';

  //bit全探索
  ll sum = 0;
  REP(bit, 1<< n){
    ll d = 1;
    ll sumtmp = 0;
    REP(i,n){
      if(bit >> i&1) {
        sum += sumtmp;
        sumtmp = 0;
        }
      else{
        sumtmp *= 10;
        sumtmp += a[i];
      }
    }
    sum += sumtmp;
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3636
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N);
    for(int i=0; i<N; i++) cin >> P[i];
    for(int i=0; i<N; i++) cin >> Q[i];

    int cnt = 0, a = -1, b = -1;
    vector<int> perm(N);
    iota(perm.begin(), perm.end(), 1);
    do {
        if(perm == P) a = cnt;
        if(perm == Q) b = cnt;
        cnt++;
    }while(next_permutation(perm.begin(), perm.end()));

    cout << abs(a - b) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	private static int DIV = 1000000007;
	public static void main(String[] args) {
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] ax = new long[n];
		long[] ay = new long[m];
		for (int i = 0;i < n;i++) ax[i] = sc.nextLong();
		for (int i = 0;i < m;i++) ay[i] = sc.nextLong();
		Arrays.sort(ax);
		Arrays.sort(ay);
		long retx = 0;
		for (int i = 0;i < n;i++) {
			retx += (2*i-n+1)*ax[i];
			retx %= DIV;
		}
		long rety = 0;
		for (int i = 0;i < m;i++) {
			rety += (2*i-m+1)*ay[i];
			rety %= DIV;
		}
		System.out.println(retx*rety%DIV);
	}
}


Measured memory_bytes: 94280
#include <iostream>

using namespace std;

#define NMAX 1000001
bool p[NMAX];
int c, cnt[NMAX];
void show(){
  for(int i = 0; i < 20; i++){
    cout << "@" << i << ":" << p[i] << endl;
  }
}
void prime(){
  fill(p, p+NMAX, true);
  p[0] = p[1] = false;
  for(int i = 4; i < NMAX; i+=2)p[i] = false;
  for(int i = 3; i*i < NMAX; i+=2){
    if(p[i]){
      for(int j = i+i; j < NMAX; j+=i){
	p[j] = false;
      }
    }
  }
  for(int i = 0; i < NMAX; i++){
    if(p[i])c++;
    cnt[i] = c;
  }
}
int main(){
  prime();
  int n;
  while(cin >> n){
    cout << cnt[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 6044
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
            int[] S = Input.ScanIntArray();
          Console.WriteLine((S[0]+S[1])%24);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = new int[3];

            for (int i = 0; i < 3; i++)
            {
                input[i] = Int32.Parse(Console.ReadLine());
            }

            int afterBuyAYen = input[0] - input[1];
            int afterBuyBYen = afterBuyAYen % input[2];

            Console.WriteLine(afterBuyBYen);


        }
    }
}


Measured memory_bytes: 11092
while gets
	data = $_.chomp.split(',').map(&:to_f)
	v2,v1 = data.pop,data.pop
	l = data.inject{|x,y| x+y}
	p = l * (v1/(v1+v2))
	i = t = 0
	while t < p
		t += data[i]
		i += 1
	end
	puts i
end

Measured memory_bytes: 6116
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H,W = map(int,readline().split())

A = '.' * (W+2)
for _ in range(H):
    A += '.' + readline().rstrip().decode('utf-8') + '.'
A += '.' * (W+2)

start = 1 * (W+2) + 1
goal = H * (W+2) + W

v = start
fail = False
for _ in range(H+W-2):
    if A[v+1] == '#':
        v += 1
        continue
    elif A[v+W+2] == '#':
        v += (W+2)
        continue
    fail = True
    break

cnt = A.count('#')
bl = (cnt == H + W - 1) and (not fail)
answer = 'Possible' if bl else 'Impossible'
print(answer)

Measured memory_bytes: 3064
n,a,b,c=map(int,input().split())
L=[int(input()) for _ in range(n)]

ans=float('inf')
for i in range(4**n):
  G=[[] for _ in range(4)]
  for j in range(n):
    G[(i//(4**j))%4].append(L[j])
  if len(G[0])==0 or len(G[1])==0 or len(G[2])==0: continue
  tmp=0
  for j in range(3):
    tmp+=max(0,len(G[j])-1)*10
    if j==0: tmp+=abs(a-sum(G[j]))
    if j==1: tmp+=abs(b-sum(G[j]))
    if j==2: tmp+=abs(c-sum(G[j]))
  ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    int n = s.size(), t = n;
    for (int i = 1; i < n; i++)
        if (s[i] != s[i - 1])
            t = min(max(i, n - i), t);
    cout << t;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
#define lim 100010

int ABS(int x){return x>0?x:-x;}
int MIN(int x,int y){return x<y?x:y;}

int n,A,B,C;
int l[8];


int dfs(int cur,int a,int b,int c){
	if(cur==n){
		if(MIN(MIN(a,b),c)>0)
		return ABS(a-A)+ABS(b-B)+ABS(c-C)-30;
		return 1e9;
	}
	int ret0 = dfs(cur+1,a,b,c);
	int ret1 = dfs(cur+1,a+l[cur],b,c)+10;
	int ret2 = dfs(cur+1,a,b+l[cur],c)+10;
	int ret3 = dfs(cur+1,a,b,c+l[cur])+10;
	return MIN(MIN(MIN(ret0,ret1),ret2),ret3);
}

int main(void){
	scanf("%d%d%d%d",&n,&A,&B,&C);
	for(int i=0;i<n;i++)scanf("%d",&l[i]);
	printf("%d",dfs(0,0,0,0));
	
	return 0;
}

Measured memory_bytes: 128
use proconio::input;

fn main() {
	input!(a: usize);
	input!(b: String);

	let v: Vec<char> = b.chars().collect();

	let mut result1 = a * (v[0] as usize - 48);
	let result2 = a * (v[2] as usize - 48);
	let result3 = a * (v[3] as usize - 48);

	//println!("{}, {}, {}", result1, result2, result3);

	result1 += (result2 / 10) + (result3 / 100);
	if (result2 % 10) + ((result3 % 100) / 10) >= 10 {
		result1 += 1;
	}

	println!("{}", result1);
}


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

int main()
{
	
	int n;
	cin>>n;
	int a[n+1][3];
	for(int i=1;i<=n;i++)
		for(int j=0;j<3;j++)
		cin>>a[i][j];
	int dp[n+1][3];
	memset(dp,-1,sizeof(dp));
	dp[1][0] = a[1][0];
	dp[1][1] = a[1][1];
	dp[1][2] = a[1][2];
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			for(int k=0;k<3;k++)
			{
				if(j != k)
				dp[i][j] = max(dp[i][j],dp[i-1][k]+a[i][j]);
			}
		}
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
	
	
	
	return 0;
}

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

int main() {
   int s;
   cin >> s;
   vector<int> v;
   v.push_back(s);

   int i=0,a,ans;
   while(1){
      if(v[i]%2==1){
      a=3*v[i]+1; 
      v.push_back(a);
      }else{
      a=v[i]/2; 
      v.push_back(a);
   }
      i++;

      if(count(all(v),v[i])==2){
      ans=i+1; break;
      }
   }
   cout << ans << endl;
}

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

main(){
  ios_base::sync_with_stdio(false);
  int n;
  bool flag=true;
  cin >> n;
  
  while(n != 0 && flag){
    if(n % 10 == 9) flag = false;
    n /= 10;
  }
  
  if(flag) cout << "No" << endl;
  else cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int main()
{
	string s;
	cin >> s;
	if (s == "ABC")
		printf("ARC");
	else
		printf("ABC");

	return 0;
}

Measured memory_bytes: 3256
#include<stdio.h>
 
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};
 
typedef struct node * NodePointer;
 
NodePointer nil;
 
NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while( cur != nil && cur->key != key ){
    cur = cur->next;
  }
  return cur;
}
 
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}
 
void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}
 
void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  
}
 
void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}
 
void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}
 
void delete(int key){
  NodePointer t = listSearch(key);
  if ( t == nil ) return;
  deleteNode(t);
}
 
 
void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}
 
int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if(!( 0 <= key && key <= 2000000000))printf("error") ;
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        delete(key); nd++;
      }
      size--;
    }
    if ( size > 1000000 )  printf("error"); 
  }
 
 
  if(!( np+nd <= 2000000))printf("error") ;
  if(!( nd <= 20))printf("error") ;
  printList();
 
 
  return 0;
}

Measured memory_bytes: 34976
#include<bits/stdc++.h>
using namespace std;
int i,j;
int x,a,b,c;
int rez;
int main(){
    cin >> a >> b >> c;
    cin >> x;
    x/=50;
    while(10*i<=x && i<=a){
        j=0;
        while(2*j<=x-10*i && j<=b){
            if(x-10*i-2*j<=c)
            rez++;
            j++;
        }
        i++;
    }
    cout<<rez;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
B - Cakes and Donuts
https://atcoder.jp/contests/abc105/tasks/abc105_b

"""
import sys


def solve(N):
    for i in range(26):
        for j in range(15):
            if 4 * i + j * 7 == N:
                return 'Yes'
    return 'No'


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 2940
#include<iostream>

using namespace std;

int main(void) {
    int N, X;
    int min = 10000;
    
    cin >> N >> X;

    int m[N];
    int count = N;

    for (int i = 0; i < N; i++) cin >> m[i];

    for (int i = 0; i < N; i++) {
        X -= m[i];
        if (m[i] < min) {
            min = m[i];
        }
    }

    count += int(X/min);

    cout << count << endl;

}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


MOD = 10**9 + 7


def main():
    N, = read_h()

    ans = 1
    for i in range(1, N + 1):
        ans *= i
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.Scanner;

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

            for (int i = 0; i < n; i++) {
                x[i] = sc.nextInt();
            }

            long ans = 0;

            for (int i = 0; i < n - 1; i++) {
                long dist = x[i + 1] - x[i];
                long walkCost = dist * a;
                if ( walkCost < b ) {
                    ans += walkCost;
                } else {
                    ans += b;
                }
            }

            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 50144
// Spreadsheet.c
// 表計算を行う簡単なプログラムを作成します。
// 表の行数rと列数c、r × c の要素を持つ表を読み込んで、
// 各行と列の合計を挿入した新しい表を出力するプログラムを作成して下さい。
// 【入力】
// 最初の行にrとcが空白区切りで与えられます。
// 続くr行にそれぞれc個の整数が空白区切りで与えられます。
// 【出力】
// (r+1) × (c+1) の新しい表を出力して下さい。
// 各行の隣り合う整数は１つの空白で区切って下さい。
// 各行の最後の列としてその行の合計値を、各列の最後の行としてその列の合計値を、
// 最後の行・列に表全体の合計値を挿入して下さい。
// 【制約】
// ・1 ≤ r, c ≤ 100
// ・0 ≤ 要素 ≤ 100
// 【例】
// 入力：
// 4 5
// 1 1 3 4 5
// 2 2 2 4 5
// 3 3 0 1 1
// 2 3 4 4 6
// 出力
// 1 1 3 4 5 14
// 2 2 2 4 5 15
// 3 3 0 1 1 8
// 2 3 4 4 6 19
// 8 9 9 13 17 56
#include<stdio.h>

int main( void) {
  int r, c;
  int matrix[ 100 + 1][ 100 + 1] = {};
  
  scanf( "%d %d", &r, &c);

  // 表データの入力
  for ( int i = 0; i < r; i++) {
    for ( int j = 0; j < c; j++) {
      scanf( "%d", &matrix[i][j]);
      matrix[i][c] += matrix[i][j];
      matrix[r][j] += matrix[i][j];
      matrix[r][c] += matrix[i][j];
    }
  }

  // 新しい表の出力
  for ( int i = 0; i <= r; i++) {
    for ( int j = 0; j <= c; j++) {
      printf( "%d", matrix[i][j]);
      if ( j < c) printf( " ");
    }
    printf( "\n");
  }

  return 0;
}



Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
int main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);
   int a,b;
   cin>>a>>b;
   if(a==b || abs(a-b)==1 || abs(b-a)==1){
      cout<<"Yay!"<<endl;
   }
   else{
      cout<<":("<<endl;
   }
   }

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int K = sc.nextInt();
    int X = sc.nextInt();

    sc.close(); 

    for (int i = X - K + 1; i < K + X; i++) {
      System.out.print(i + " ");
    }

    System.out.println("");
  
  }

}

Measured memory_bytes: 21716
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
ll n,a[200005],b[200005],f[4005][4005],c[4005][4005],ans;
ll quick_pow(ll x,ll a)
{
	ll ans=1;
	while(a)
	{
		if(a&1)ans=ans*x%MOD;
		x=x*x%MOD;
		a>>=1;
	}
	return ans;
}
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i],&b[i]);
		f[-a[i]+2000][-b[i]+2000]++;
	}
	c[0][0]=1;
	for(int i=0;i<=4000;i++)
	for(int j=0;j<=4000;j++)
	{
		c[i][j]%=MOD;
		c[i+1][j]+=c[i][j];
		c[i][j+1]+=c[i][j];
	}
	for(int i=0;i<=4000;i++)
	for(int j=0;j<=4000;j++)
	{
		f[i][j]%=MOD;
		f[i+1][j]+=f[i][j];
		f[i][j+1]+=f[i][j];
	}
	for(int i=1;i<=n;i++)
	  ans+=f[a[i]+2000][b[i]+2000];
	ans%=MOD;
	for(int i=1;i<=n;i++)
	  ans=(ans-c[a[i]*2][b[i]*2]+MOD)%MOD;
	printf("%lld\n",ans*quick_pow(2,MOD-2)%MOD);
	return 0;
}

Measured memory_bytes: 253952
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;



int main(){

	int n,tmp,row_sum,col_sum[11];

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

		for(int i=0; i < 11; i++)col_sum[i] = 0;

		for(int i=0; i < n; i++){
			row_sum = 0;
			for(int k=0; k < n; k++){
				scanf("%d",&tmp);
				printf("%5d",tmp);
				row_sum += tmp;
				col_sum[k] += tmp;
			}
			printf("%5d\n",row_sum);
			col_sum[n] += row_sum;
		}
		for(int i=0; i <= n; i++)printf("%5d",col_sum[i]);
		printf("\n");
	}

    return 0;
}

Measured memory_bytes: 2608
n = int(input())
l = list(map(int,input().split()))

count = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i] == l[j] or l[j] == l[k] or l[k] == l[i]:
                continue
            max_l = max(l[i],l[j],l[k])
            if 2*max_l < l[i]+l[j]+l[k]:
                count +=1
print(count)

Measured memory_bytes: 8992
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll a, b, c, x;
    cin >> a >> b >> c >> x;
    ll count = 0;
    REP(num_500, a + 1) {
        REP(num_100, b + 1) {
            REP(num_50, c + 1) {
                if (500 * num_500 + 100 * num_100 + 50 * num_50 == x) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import math
N = int(input())
a = list(map(int,input().split()))
b = [0]*N
ans = []
for k in range(N,0,-1):
    if a[k-1]%2 != b[k-1]%2:
        ans.append(k)
        b[0] += 1
        b[k-1] += 1
        for l in range(2,math.floor(math.sqrt(k))+1):
            if k % l == 0:
                if l*l == k:
                    b[l-1] += 1
                else:
                    b[l-1] += 1
                    b[k//l-1] += 1
print(len(ans))
if len(ans) > 0:
    print(*ans)


Measured memory_bytes: 71132
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n; 
	vector<int> a(n);
	int ma=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		ma=max(ma,a[i]);
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]==ma)cnt++;
	}
	//cout << cnt << " " << ma << endl;
	if(cnt>1){
		for(int i=0;i<n;i++){
			cout << ma << endl;
		}
	}
	else{
		int maa=0;
		for(int i=0;i<n;i++){
			if(a[i]!=ma){
				maa=max(maa,a[i]);
			}
		}
		
		for(int i=0;i<n;i++){
			if(ma==a[i]){
				cout << maa << endl;
			}
			else{
				cout << ma << endl;
			}
		}
	}
}

Measured memory_bytes: 2432
//#include <bits/stdc++.h>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <cmath>

#define X first
#define Y second
#define ls rt<<1
#define rs rt<<1|1
#define getmid ((l+r)>>1)
#define PB push_back
#define EP emplace_back
#define MP make_pair
#define lowbit(x) ((x)&-(x))
#define ALL(x) x.begin(),x.end()
#define mst(x,a) memset(x, a, sizeof(x))
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep1(i,n) for(int i=1; i<=(n); i++)
#ifdef LOCAL
    #define dbg(a) cout << #a": " << a << endl;
#else
    #define dbg(a)
#endif // LOCAL

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;

const int N = 2200 + 10;
const int M = 1e5 + 10;
const int mod = 998244353;
const double eps = 1e-10;
const double pi = acos(-1.0);

int n;
ll a[M];
int prime[N+1],tot;
vector<ll> ve;
gp_hash_table<ll,bool> sq;
gp_hash_table<ll,int> cnt;
gp_hash_table<ll,ll> mp;

void getPrime(){
    for(int i=2; i<=N; i++){
        if(!prime[i]) prime[++tot] = i;
        for(int j=1; j<=tot && prime[j]<=N/i; j++){
            prime[i*prime[j]] = 1;
            if(i%prime[j]==0) break;
        }
    }
}

void getSquare(){
    for(ll i=1; i*i<=10000000000; i++){
        sq[i*i] = 1;
    }
}

int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
#endif // LOCAL
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    getPrime();
    getSquare();
    cin>>n;
    for(int i=1; i<=n; i++) cin>>a[i];
    int ans = 0;
    bool one = false;
    for(int i=1; i<=n; i++){
        ll t = a[i];
        ll x = 1, y = 1;
        for(int j=1; j<=tot; j++){
            if(t%prime[j]==0){
                int num = 0;
                while(t%prime[j]==0) {
                    t /= prime[j];
                    num++;
                }
                num %= 3;
                for(int k=1; k<=num; k++) x *= prime[j];
                for(int k=(3-num)%3; k; k--) y *= prime[j];
            }
            if(t==1) break;
        }
        if(t!=1) {
            if(sq[t]) {
                x *= t;
                y *= (int)sqrt(t+0.5);
            } else {
                if((double)t*t*y<=1e10) {
                    x *= t;
                    y *= t*t;
                } else {
                    ans++;
                    continue;
                }
            }
        }
        if(x==1) {
            if(!one) {
                one = true;
                ans++;
            }
            continue;
        }
        mp[x] = y;
        if(++cnt[x]==1) ve.PB(x);
    }
    for(ll val: ve) {
        if(!cnt[val]) continue;
        int x = cnt[val];
        int y = cnt[mp[val]];
        ans += max(x, y);
        cnt[mp[val]] = 0;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 35820
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        a: [u64; n],
    }
    let mut dict = HashMap::new();
    let mut ans = 0;
    for i in 0..n {
        *dict.entry(a[i]).or_insert(0) += 1;
    }
    for (k, v) in dict.iter() {
        if v % 2 == 1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 12540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



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

  FOR(i,0,s.length()-1){
    if(i%2==0){
        if(s[i]=='L'){
            cout << "No" << endl;
            return 0;
        }
    }
    if(i%2==1){
        if(s[i]=='R'){
            cout << "No" << endl;
            return 0;
        }
    }
  }

  cout << "Yes" << endl;

}



Measured memory_bytes: 384
def count(i, j, k):
    if i == j and j == k:
        return 1
    elif i == j or j == k or i == k:
        return 3
    else:
        return 6

def solve(K, S):
    ans = 0
    for i in range(K, -1, -1):
        for j in range(i, -1, -1):
            k = S - (i + j)
            if k >= 0 and k <= j:
                ans += count(i, j, S - (i + j))
    return ans

k, s = tuple(int(x) for x in input().split())
print(solve(k, s))

Measured memory_bytes: 3188
def two_ten(n):
    ans = ''
    while n:
        if n%2 == 0:
            ans += '0'
        else:
            ans += '1'
        n = n/2
    else:
        lis = list(ans)
        lis.reverse()
        return ''.join(lis).zfill(5)
    
def kawaii(lis):
    ans = []
    s = ''
    for v in lis:
        for c in v:
            s += c
            if s in dic:
                ans.append(dic[s])
                s = ''
    else:
        print ''.join(ans)

dic = {'101':' ', '000000':"'", '000011':',', '10010001':'-', '010001':'.', 
       '000001':'?', '100101':'A', '10011010':'B', '0101':'C', '0001':'D', 
       '110':'E', '01001':'F', '10011011':'G', '010000':'H', '0111':'I', 
       '10011000':'J', '0110':'K', '00100':'L', '10011001':'M', '10011110':'N', 
       '00101':'O', '111':'P', '10011111':'Q', '1000':'R', '00110':'S', '00111':'T', 
       '10011100':'U', '10011101':'V', '000010':'W', '10010010':'X', '10010011':'Y', '10010000':'Z'}

mathematics = {'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5, 'G':6, 'H':7, 
               'I':8, 'J':9, 'K':10, 'L':11, 'M':12, 'N':13, 'O':14, 'P':15, 
               'Q':16, 'R':17, 'S':18, 'T':19, 'U':20, 'V':21, 'W':22, 'X':23,
               'Y':24, 'Z':25, ' ':26, '.':27, ',':28, '-':29, "'":30, '?':31,}

while True:
    try:
        lis = []
        for c in raw_input():
            lis.append(two_ten(mathematics[c]))
        else:
            kawaii(lis)
    except EOFError:
        break

Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
	int A, B;
	cin >> A >> B;
  int count=0;
  for (int i=A; i<B+1; i++){
  if ((i-10000*(i/10000))/1000 == ((i-i%10)/10)%10 && i/10000 == i %10){
    //kaibun teki nara count++ suru
    count++;
  }
  }
	cout << count<< endl;
}

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

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

int main()
{
 int n;
 cin>>n;
 int arr[n];
 for(int i=0; i<n; i++)
    cin>>arr[i];
 int ans = frog1(arr, n);
 cout<<ans;
 return 0;
}



Measured memory_bytes: 4408
#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 all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int N;
cin >> N;
if(N == 1) cout << "Hello World" << endl;
else {
    int A,B;
    cin >> A >> B;
    cout << A + B << endl;
}

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353 ;
const long long hell = (long long) 1000000007;

using namespace std;
#include <stdio.h>

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x%hell*res%hell)%hell;
    x=(x%hell*x%hell)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;
   
   while(test--)
   solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/

void solve(){
    int a,b;
    cin>>a>>b;
    
    int res=-1;
    for(int i=1;i<=1500;i++){
        int x=i*8;
        x/=100;
        int y=i*10;
        y/=100;
        
        if(x==a and y==b){
            res=i;
            break;
        }
    }
    cout<<res;
}    


///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

typedef struct{
  vector<int> to;
}edge;

const int V_MAX = 1e5+1;
bool used[2][V_MAX];
edge G[2][V_MAX];
ll num[2];
vector<vector<int> > node;
set<PII> st;
//cur=0:x,cur=1:y
//vertex:頂点
ll dfs(int cur,int vertex){
  if(used[cur][vertex]) return 0;
  used[cur][vertex] = true;
  num[cur]++;
  ll n_edge = 0;
  rep(i,G[cur][vertex].to.size()){
    PII p;
    if(cur == 0) p = PII(vertex,G[cur][vertex].to[i]);
    else p = PII(G[cur][vertex].to[i],vertex);
    if(st.count(p)) continue;
    st.insert(p);
    n_edge++;
    n_edge += dfs(cur^1,G[cur][vertex].to[i]);
  }
  return n_edge;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  node.resize(2);
  int N;cin >> N;
  rep(i,N){
    int x,y;cin >> x >> y;
    G[0][x].to.push_back(y);
    G[1][y].to.push_back(x);
    node[0].push_back(x);
    node[1].push_back(y);
  }
  sort(all(node[0]));
  sort(all(node[1]));
  node[0].erase( unique(all(node[0])), node[0].end() );
  node[1].erase( unique(all(node[1])), node[1].end() );

  ll ans = 0;
  rep(i,node[0].size()){
    if(used[0][node[0][i]])continue;
    num[0] = 0;
    num[1] = 0;
    ll n_edge = dfs(0,node[0][i]);
    ans += max(0ll, num[0]*num[1] - n_edge);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 19568
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    int dp[n];
    dp[0]=0;

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

        //cout<<i<<" : "<<dp[i]<<endl;

    }

    cout<<dp[n-1];
}


Measured memory_bytes: 4368
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    N = int(input())
    MAX = 3501
    for h in range(1, MAX):
        gcdNh = gcd(N, h)
        for n in range(1, MAX):
            gcdNhn = gcd(gcdNh, n)
            denom = N * h * n // gcdNhn**2
            num = 4 * denom // N - denom // h - denom // n
            if num > 0 and denom % num == 0:
                w = denom // num
                print(h, n, w)
                return


if __name__ == "__main__":
    main()


Measured memory_bytes: 79580
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
ll modpow(ll a,ll n,ll mod){
	ll ans=1;
	for(;n>0;n>>=1,a=a * a % mod){
		if(n%2==1){
			ans = ans * a % mod;
		}
	}

	return ans;
}
int main(){
	ll n,a,b;
    cin >> n >> a >> b;
    ll mod=1000000007;
    ll x1=1,x2=1;
    for(ll i=1;i<=a;i++){
        x1=x1*(n-i+1)%mod;
        x2=x2*i%mod;
    }
    ll x=x1*modpow(x2,mod-2,mod)%mod;
    ll y1=1,y2=1;
    for(ll i=1;i<=b;i++){
        y1=y1*(n-i+1)%mod;
        y2=y2*i%mod;
    }
    ll y=y1*modpow(y2,mod-2,mod)%mod;
    cout << (modpow(2,n,mod)+(mod-x)+(mod-y))%mod-1;
    return 0;
}


Measured memory_bytes: 256
//Fish
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

struct Point {
    int x, y, d;
    Point() {}
    Point(int x, int y, int d): x(x), y(y), d(d) {}
};

struct Rectangle {
    Point p1, p2;
    Rectangle() {}
    Rectangle(Point p1, Point p2): p1(p1), p2(p2) {}
};

int main() {
    int N, K;
    vector<ll> X, Y, D;
    cin >> N >> K;
    Rectangle R[N];
    int x1, y1, d1, x2, y2, d2;
    for(int i = 0; i < N; i++) {
        cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;
        R[i] = Rectangle(Point(x1, y1, d1), Point(x2, y2, d2));
        X.push_back(x1); X.push_back(x2);
        Y.push_back(y1); Y.push_back(y2);
        D.push_back(d1); D.push_back(d2);
    }

    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    sort(D.begin(), D.end());
    X.erase(unique(X.begin(), X.end()), X.end());
    Y.erase(unique(Y.begin(), Y.end()), Y.end());
    D.erase(unique(D.begin(), D.end()), D.end());
    int G[X.size() - 1][Y.size() - 1][D.size() - 1];
    if(X.size() == 1 || Y.size() == 1 || D.size() == 1) {
        cout << 0 << endl;
    } else {
        for(int i = 0; i < X.size() - 1; i++) {
            for(int j = 0; j < Y.size() - 1; j++) {
                for(int k = 0; k < D.size() - 1; k++) {
                    G[i][j][k] = 0;
                }
            }
        }
        for(int n = 0; n < N; n++) {
            for(int i = int(distance(X.begin(), lower_bound(X.begin(), X.end(), R[n].p1.x))); i < int(distance(X.begin(), upper_bound(X.begin(), X.end(), R[n].p2.x))) - 1; i++) {
                for(int j = int(distance(Y.begin(), lower_bound(Y.begin(), Y.end(), R[n].p1.y))); j < int(distance(Y.begin(), upper_bound(Y.begin(), Y.end(), R[n].p2.y))) - 1; j++) {
                    for(int k = int(distance(D.begin(), lower_bound(D.begin(), D.end(), R[n].p1.d))); k < int(distance(D.begin(), upper_bound(D.begin(), D.end(), R[n].p2.d))) - 1; k++) {
                        G[i][j][k]++;
                    }
                }
            }
        }
        ll v = 0;
        for(int i = 0; i < X.size() - 1; i++) {
            for(int j = 0; j < Y.size() - 1; j++) {
                for(int k = 0; k < D.size() - 1; k++) {
                    if(G[i][j][k] >= K) {
                        v += (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) * (D[k + 1] - D[k]);
                    }
                }
            }
        }
        cout << v << endl;
    }

    return 0;
}


Measured memory_bytes: 6952
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const lli inf = 1e18 + 7;

int n;
int a[maxn];

lli f[maxn];

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
}

void solve()
{
    f[0] = 0;
    for(int i = 1; i <= n; ++i)
        f[i] = f[i - 1] + a[i];
    for(int i = 1; i <= n; ++i)
        cerr << f[i] << ' ';
    lli ans = inf, cur = 0;
    lli cost = 0;
    for(int i = 1; i <= n; ++i)
    {
        lli k;
        if(i & 1)
        {
            if(f[i] + cur <= 0)
            {
                k = 1 - (f[i] + cur);
                cost += k;
                cur += k;
            }
        }
        else
        {
            if(f[i] + cur >= 0)
            {
                k = f[i] + cur + 1;
                cost += k;
                cur -= k;
            }
        }
    }
    ans = min(ans, cost);
    cost = cur = 0;
    for(int i = 1; i <= n; ++i)
    {
        lli k;
        if(i & 1)
        {
            if(f[i] + cur >= 0)
            {
                k = f[i] + cur + 1;
                cost += k;
                cur -= k;
            }
        }
        else
        {
            if(f[i] + cur <= 0)
            {
                k = 1 - (f[i] + cur);
                cost += k;
                cur += k;
            }
        }
    }
    ans = min(ans, cost);
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 1408
#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--)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w,h,n;cin >> w >> h >> n;
    vector<int> u(w),v(h);
    rep(i,0,n){
        int x,y,a;cin >> x >> y >> a;
        x--,y--;
        if(a==1){
            rep(j,0,x+1){
                u[j]=true;
            }
        }
        if(a==2){
            rep(j,x+1,w){
                u[j]=true;
            }
        }
        if(a==3){
            rep(j,0,y+1){
                v[j]=true;
            }
        }
        if(a==4){
            rep(j,y+1,h){
                v[j]=true;
            }
        }
    }
    int ans=0;
    rep(i,0,w){
        rep(j,0,h){
            if(!u[i]&&!v[j]){
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3664