akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            sS = System.Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iSrc = sS.Length;
            int iDes = sS.Replace("ABC", "").Length;
            int iOut = (iSrc - iDes) / 3;

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn extgcd(a: i64, b: i64, x: &mut i64, y: &mut i64) -> i64 {
    let mut d = a;
    if b == 0 {
        *x = 1;
        *y = 0;
    } else {
        d = extgcd(b, a % b, y, x);
        *y -= (a / b) * (*x);
    }
    return d;
}

fn mod_inverse(a: i64, m: i64) -> i64 {
    let mut x: i64 = 0;
    let mut y: i64 = 0;
    extgcd(a, m, &mut x, &mut y);
    (m + x % m) % m
}

struct ModFactorial {
    fact: Vec<i64>,
}

// returns n! under mod m
impl ModFactorial {
    fn new(n: i64, m: i64) -> ModFactorial {
        let mut fact = vec![1; n as usize + 1];
        for i in 2..fact.len() {
            fact[i] = (i as i64 * fact[i - 1]) % m;
        }
        ModFactorial { fact: fact }
    }
}

fn pow_m(n: i64, mut p: i64, m: i64) -> i64 {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % m;
            p /= 2;
        } else {
            ret = ret * r % m;
            p -= 1;
        }
    }
    ret
}

fn main() {
    let v: Vec<usize> = read_vec();
    let (n, a, b, c, d) = (v[0], v[1], v[2], v[3], v[4]);

    let big_int: i64 = 1000_000_000 + 7;
    let fact = ModFactorial::new(n as i64, big_int).fact;
    let inv_fact = fact.iter()
        .map(|&x| mod_inverse(x, big_int))
        .collect::<Vec<_>>();

    let mut dp = vec![vec![0i64; n + 1]; n + 1];
    for i in 0..n + 1 {
        dp[i][0] = 1;
    }

    for i in a..b + 1 {
        for j in 1..n + 1 {
            dp[i][j] = dp[i - 1][j]; // k = 0;
            for k in c..d + 1 {
                if j < k * i {
                    continue;
                }
                if j > n + k * i {
                    break;
                }
                let mut temp = dp[i - 1][j - k * i];
                temp *= fact[n - j + k * i];
                temp %= big_int;
                temp *= inv_fact[n - j];
                temp %= big_int;

                temp *= pow_m(inv_fact[i], k as i64, big_int);
                temp %= big_int;

                temp *= inv_fact[k];
                temp %= big_int;
                dp[i][j] += temp;
                dp[i][j] %= big_int;
            }
        }
    }
    println!("{}", dp[b][n]);
}


Measured memory_bytes: 12540
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535897932384626433

int main(void)
{
  double a,b,h,m;
  scanf("%lf %lf %lf %lf", &a, &b, &h, &m);

  double tl, ts;

  tl = m*6;
  ts = (h+m/60)*30;

  double ang;
  ang = tl-ts;
  if(ang>180) ang *= -1;
  else if(ang<0) ang += 360;

  double l=a*a+b*b-2*a*b*cos(ang*2*PI/360.0);
  //printf("ang = lf\n", ang );
  printf("%.20lf", sqrt(l));
  return 0;
}



  

Measured memory_bytes: 2596
k=int(input())

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)

ans=0
import itertools
for x in itertools.product(range(1,k+1),repeat=3):
    a,b,c=x
    ans+=gcd(gcd(a,b),c)
print(ans)


Measured memory_bytes: 79728
from math import sqrt, ceil

primes = [2]
for n in range(3, 101):
    if any(n % i == 0 for i in range(2, n)):
        continue
    primes.append(n)

def fact(n):
    p = 1
    for i in range(2, n+1):
        p *= i
    return p

def calc_factors(n):
    factors = {}
    for p in primes:
        while n % p == 0:
            factors[p] = factors.get(p, 0)+1
            n //= p
    return factors

def solve(N):
    n = fact(N)
    factors = calc_factors(n)

    nums = {3:0,5:0,15:0,25:0,75:0}
    for p, c in factors.items():
        if c >= 2:
            nums[3] = nums.get(3,0)+1
        if c >= 4:
            nums[5] = nums.get(5,0)+1
        if c >= 14:
            nums[15] = nums.get(15,0)+1
        if c >= 24:
            nums[25] = nums.get(25,0)+1
        if c >= 74:
            nums[75] = nums.get(75,0)+1
    print(sum([
            nums[5] * (nums[5] - 1) * (nums[3]-2) // 2,
            nums[15] * (nums[5] - 1) ,
            nums[25] * (nums[3] - 1) ,
            nums[75] ]))
N = int(input())
solve(N)


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/
int main(){
	int N,A,B,C,D;
	string S;


	cin >> N >> A >> B >> C >> D;
	cin >> S;
	bool ans = false;
	S = "#" + S + "#";

	if ((A < B) and (B < D) and (D < C)){
		FORq(i,B,D){
			if (S[i-1] == '.' and S[i] == '.' and S[i+1] == '.'){
				ans = true;
			}
		}
		FORq(i,A,C){
			if (S[i] == '#' and S[i+1] == '#'){
				ans = false;
			}
		}

	}else{
		ans = true;
		FORq(i,A,D){
			if (S[i] == '#' and S[i+1] == '#'){
				ans = false;
			}
		}

	}

	if (ans) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string str;
    while(cin>>str){
        int a=0,b=0,c=0;
        for(int i=0;i<3;i++){
            if(str[i]=='a')a++;
            if(str[i]=='b')b++;
            if(str[i]=='c')c++;
        }
        if(a&&b&&c)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long ll;

//#define foi(a, b) for (LL i = a; a < b ? i < b : b > i; a < b ? i++ : i--)
//#define foj(a, b) for (LL j = a; a < b ? j < b : b > j; a < b ? j++ : j--)

using namespace std;

int main()
{
                                                                                                   ios_base::sync_with_stdio(false);
                                                                                                   cin.tie(NULL);
   int node, edge;
   cin >> node >> edge;
   vector<vector<int>> adj(node + 1);
   for (int i = 1; i <= edge; i++)
   {
      int a, b;
      cin >> a >> b;
      adj[a].pb(b);
      adj[b].pb(a);
   }

   queue<int> q;
   vector<bool> visited(node + 1, false);
   vector<int> distance(node + 1, 0);

   visited[1] = true;
   distance[1] = 0;
   q.push(1);

   while (!q.empty())
   {
      int s = q.front();
      q.pop();

      // process node s
      for (auto u : adj[s])
      {
         if (visited[u])
            continue;

         visited[u] = true;
         distance[u] = s;
         q.push(u);
      }
   }
   for (int x = 2; x <= node; x++)
   {
      if (distance[x] == 0)
      {
         cout << "No" << endl;
         exit(0);
      }
   }
   cout << "Yes" << endl;
   for (int x = 2; x <= node; x++)
   {
      cout << distance[x] << endl;
   }
   return 0;
}


Measured memory_bytes: 10212
#include <stdio.h>

int main()
{
    int a, b, c;
    int temp;
    scanf("%d %d %d", &a, &b, &c);
    
    if (a > b) {
        temp=a; a=b; b=temp;
    }
    if (b > c) {
        temp=b; b=c; c=temp;
        if (a > b) {
            temp=a; a=b; b=temp;
        }
    }
    printf("%d %d %d\n", a,b,c);
    return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    pair<int,int> p[m];
    for(int i=0;i<m;i++){
        int b,c;
        cin>>b>>c;
        p[i]={c,b};
    }
    sort(p,p+m,greater<pair<int,int>>());
    int crt=0;
    int cnt[m];
    memset(cnt,0,sizeof(cnt));
    for(int i=0;i<m;i++){
        int c=p[i].first;
        int b=p[i].second;
        int it=lower_bound(a+crt,a+n,c)-a;
        if(it-crt<=b){
            cnt[i]=it-crt;
            crt=it;
        }else{
            cnt[i]=b;
            crt=crt+b;
        }
        if(crt==m)break;
    }
    ll ans=0;
    for(int i=crt;i<n;i++){
        ans+=a[i];
    }
    for(int i=0;i<m;i++){
        ans+=(ll)cnt[i]*p[i].first;
    }
    cout<<ans<<endl;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    int h[n];
    rep(i, n) cin >> h[i];
    int num = 0;
    rep(i, n){
        if(h[i] >= k) num++;
    }
    cout << num << endl;

    return 0;
}

Measured memory_bytes: 640
import Control.Applicative

main = do
  [w, h, x, y, r] <- map (\x -> read x :: Int) . words <$> getLine
  putStrLn $ 
    if x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h
      then "Yes"
      else "No"

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

int main() {

int64_t A,B,K;
  cin >> A >> B >> K;
  if(A - K <0){
    B = B - (K - A);
    if (B < 0){
     B = 0;
    }
    A = 0;
  }else{
     A = A - K; 
    }
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_A&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        m, f, r = map(int, input().split())
        if m == -1 and f == -1 and r == -1:
            break
        grade = '@'
        if m == -1 or f == -1:
            grade = 'F'
        elif m + f >= 80:
            grade = 'A'
        elif m + f >= 65:
            grade = 'B'
        elif m + f >= 50:
            grade = 'C'
        elif m + f >= 30:
            if r >= 50:
                grade = 'C'
            else:
                grade = 'D'
        else:
            grade = 'F'
        print(grade)



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

Measured memory_bytes: 7776
import sys
s = input()
t = input()
table = [[len(s) for i in range(len(s))] for j in range(26)]
sset = set(s)
tset = set(t)
for i in range(len(s)):
  table[ord(s[i])-97][i] = 0
for letter in sset:
  i = ord(letter) - 97
  for j in range(len(s)):
    table[i][len(s)-j-2] = min(table[i][len(s)-j-1] +1, table[i][len(s)-j-2])
  for j in range(len(s)):
    if table[i][len(s)-j-2] < len(s): break
    table[i][len(s)-j-2] = min(table[i][len(s)-j-1] +1, table[i][len(s)-j-2])

if tset - sset:
  print(-1)
  sys.exit()
    
place = 0
ans = 0
for i in range(len(t)):
  letter = t[i]
  move = table[ord(t[i])-97][place]
  ans += move + 1
  place = (place + move+1)%len(s)
print(ans)

Measured memory_bytes: 118348
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int a[100100];
int check[100100];
int check1[100100];
vector<pair<int, int>> vt;
vector<pair<int, int>> vt1;
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		if (i % 2)
			check[a[i]]++;
		else
			check1[a[i]]++;
	}
	for (int i = 0; i < 100100; i++)
	{
			vt.push_back({ check[i],i });
			vt1.push_back({ check1[i],i });
	}
	sort(vt.begin(), vt.end());
	sort(vt1.begin(), vt1.end());
	int t = vt.size();
	if (vt[t - 1].second == vt1[t - 1].second)
	{
		printf("%d", n - max(vt[t - 1].first + vt1[t - 2].first, vt[t - 2].first + vt1[t - 1].first));
	}
	else
		printf("%d", n - vt[t - 1].first - vt1[t - 1].first);
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    int sum = 0;
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    sort(A.rbegin(), A.rend());
    int num = 0;
    rep(i, N) {
        if (4 * M * A[i] >= sum) {
            num++;
        }
    }

    if (num >= M) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

using namespace std;

long long gcd(long long a, long long b) {
    long long int mod = a % b;
    if (mod == 0) {
        return b;
    } else {
        return gcd(b, mod);
    }
}

long lcm(long a, long b) {
    return (a * b) / gcd(a, b);
}

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

    long long ans = 1;
    for (int i = 0; i < n; ++i) {
        long long t;
        cin >> t;
        ans = lcm(ans, t);
    }

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


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

int main(){
  int n;
  cin >> n;
  
  int cnt = 0;
  for(int i = 1; i <=n; i++){
    int a;
    cin >> a;
    if(a != i)
      cnt++;
  }
  
  if(cnt <= 2)
    cout << "YES\n";
  else
    cout << "NO\n";
}

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

typedef long long ll;
using namespace std;

int main()
{
  int W, H, N; cin >> W >> H >> N;
  vector<int> x(N), y(N), a(N);
  for (int i = 0; i < N; ++i) cin >> x[i] >> y[i] >> a[i];

  int x_lower = 0, x_upper = W, y_lower = 0, y_upper = H;
  for (int i = 0; i < N; ++i) {
    switch (a[i]) {
    case 1:
      x_lower = max(x_lower, x[i]);
      break;
    case 2:
      x_upper = min(x_upper, x[i]);
      break;
    case 3:
      y_lower = max(y_lower, y[i]);
      break;
    case 4:
      y_upper = min(y_upper, y[i]);
      break;
    }
  }

  // printf("Debug: x_lower: %d, x_upper: %d, y_lower: %d, y_upper: %d\n", x_lower, x_upper, y_lower, y_upper);

  cout << (x_upper <= x_lower or y_upper <= y_lower ? 0 : (x_upper-x_lower)*(y_upper-y_lower));
}

Measured memory_bytes: 256
public class Main {

  private static void solve() {
    long x = Math.abs(nl());
    long k = nl();
    long d = nl();

    long y = x / d;

    long ans = x - y * d;

    if (y >= k) {
      System.out.println(x - k * d);
    } else {
      long z = k - y;
      if (z % 2 == 0) {
        System.out.println(ans);
      } else {
        System.out.println(d - ans);
      }
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 36744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(11);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  set<pii> s;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    s.emplace(a, b);
  }

  vector<ll> ans(10);
  // 左上の座標全探索
  set<pii> used;
  for (pii e : s) {
    rep3(dy, -2, 1) rep3(dx, -2, 1) {
      int y = e.F + dy;
      int x = e.S + dx;
      if (used.count(pii(y, x))) continue;
      if (y <= 0 || x <= 0 || y + 2 > h || x + 2 > w) continue; // debuged
      used.emplace(y, x);
      // cerr << y << " " << x << endl;

      int cnt = 0;
      rep(i, 3) rep(j, 3) {
        int y_ = y + i;
        int x_ = x + j;
        if (s.count(pii(y_, x_))) ++cnt;
      }
      ++ans[cnt];
    }
  }
  cerr << 1LL * (w - 2) * (h - 2) << " " << accumulate(all(ans), 0LL) << endl;
  ans[0] = 1LL * (w - 2) * (h - 2) - accumulate(all(ans), 0LL); // debuged, << endl 付いてた...
  cerr << "ans0 " << ans[0] << endl;
  rep(i, 10) cout << ans[i] << endl;
}


Measured memory_bytes: 47104
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

//

int coins[] = {500, 100, 50, 10, 5, 1};

int main() {

    while(true) {
        int price; cin >> price;
        if (price == 0) break;
        int change = 1000-price;
        int cnt = 0;

        for (int c : coins) {
            int v = change / c;
            cnt += v;
            change -= (v*c);
        }

        cout << cnt << endl;

    }

    return 0;
}


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


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

	int n,t;
	int max=0,sum = 0;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		if(max < t)
		{
			max = t;
		}
		sum += t;
	}

	if(sum-max > max)
	{
		cout << "Yes" << '\n';
	}
	else
	{
		cout << "No" << '\n';
	}
	return 0;
}
		

Measured memory_bytes: 256
from collections import deque
n = int(input())
a = list(map(int,input().split()))
e = deque([])
for i in range(n):
    if i%2:
        e.appendleft(a[i])
    else:
        e.append(a[i])
if n%2:
    for i in range(n):
        print(e[(n-1)-i],end=" ")
else:
    for i in range(n):
        print(e[i],end=" ")
print()

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!
struct BinaryIndexedTree {
  vector<int> x; int n;
  BinaryIndexedTree(int n) : x(n+1,0), n(n) {}
  void add(int i, int a){
    i+=1; while(i<=n){ x[i]+=a; i+=(i&-i); }
  }
  int prefix_sum(int i){
    int s=0;
    while(i>0) { s+=x[i]; i-=(i&-i); }
    return s;
  }
};
//

void solve(long long N, std::vector<long long> P) {
  BinaryIndexedTree bit(N);
  vector<pair<ll,ll>> IP(N);
  rep(i,N){
    IP[i] = mp(P[i],i);
  }
  sort(all(IP));
  ll ret = 0;
  rep(i,N){
    int j = IP[i].second;
    int k = bit.prefix_sum(j);
    if(k==0){
      ret++;
    }
    bit.add(j,1);
  }
  cout << ret << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  long long N;
  std::cin >> N;
  std::vector<long long> P(N);
  for (int i = 0; i < N; i++) {
    std::cin >> P[i];
  }
  solve(N, std::move(P));
  return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto& e : v) {
        cin >> e;
    }
    int sol = 0;
    for (int i = 1; i<n-1; i++) {
        int mini = min({v[i], v[i-1], v[i+1]});
        int maxi = max({v[i], v[i-1], v[i+1]});
        if (v[i] != mini && v[i] != maxi)
            sol++;
    }
    cout << sol << endl;
    return 0;
}


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

using namespace std;

int main () {
	int n;
	cin >> n;
	set<int> ss;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		ss.insert(x);
	}
	cout << ss.size() << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int A;
    //A
    int B;
    //B
    cin >> A >> B;
    //A,Bの順で標準入力
    cout << (A + B) % 24 << endl;
    //AとBを足した和を出力,足した和が24を超えた場合は24を超えた数を出力(伝われ)
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(GCD(a, b) + " " + 1l * a * b / GCD(a, b));
		}
		sc.close();
	}

	public static int GCD(int x, int y) {
		int tmp;
		while ((tmp = x % y) != 0) {
			x = y;
			y = tmp;
		}
		return y;
	}
}

Measured memory_bytes: 26124
a,b,m = map(int,input().split())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))

cst = min(ai) + min(bi)

for i in range(m):
    x,y,c = map(int,input().split())
    if cst > ai[x-1]+bi[y-1]-c:
        cst = ai[x-1]+bi[y-1]-c

print(cst)


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

#define MAX 100

int main(void) {
	int N;
	cin >> N;
	double sq = (int)sqrt((double)N);
	int sqReal = (sq == (int)sq) ? sq - 1 : sq;
	int ans = 0;
	/*for (int a = 1; a < N; a++) {
		for (int b = a; a * b < N; b++) {
			for (int c = 1; a * b + c <= N; c++) {
				if (a * b + c == N) {
					a++;
					if (a == b) a++;
					break;
				}
			}
		}
	}
	では計算量が O(n^2) (?) でだめだから*/

	for (int a = 1; a < N; a++) {
		if (N % a)	ans += N / a;
		else		ans += N / a - 1;
	}

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

Measured memory_bytes: 3192
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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;
    int zero = 0, one = 0;
    for(char c: s){
        if(c == '0') zero++;
        else one++;
    }
    cout << min(zero, one)*2 << ln;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int n,maxx;
vector <int> v[100005]; 
int dp[100005];
void dfs1(int pos,int fa){
	int nz=0;
	for (int i=0;i<v[pos].size();++i){
		if (v[pos][i]==fa)continue;
		dfs1(v[pos][i],pos);
		dp[pos]+=dp[v[pos][i]];
		nz+=(dp[v[pos][i]]!=0);
	}
	dp[pos]+=max(0,(int)(v[pos].size())-(fa!=(-1))-nz-1);
}
int main(){ 
	scanf("%d",&n);
	for (int i=1;i<n;++i){
		int a,b;
		scanf("%d%d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for (int i=1;i<n;++i){
		if (v[i].size()>v[maxx].size())maxx=i;
	}
	dfs1(maxx,-1);
	cout<<max(1,dp[maxx]);
}

Measured memory_bytes: 13824
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

// べき乗の剰余
lint modpow(lint x, lint y, lint m) {
    if (y == 0) return 1;
    lint res = modpow(x, y / 2, m);
    return res * res % m * (y & 1 ? x : 1) % m;
}

int main(void) {
    string s;
    cin >> s;
    int l = s.length();
    const lint MOD = 1e9 + 7;
    
    int ra = 0, rb = 0, rc = 0, rq = 0;
    repeat (i, l) {
        if (s[i] == 'A') ++ra;
        else if (s[i] == 'B') ++rb;
        else if (s[i] == 'C') ++rc;
        else if (s[i] == '?') ++rq;
        else assert(false);
    }
    
    auto calc = [&](int la, int lq, int rc, int rq) -> lint {
        lint x, y, z, w;
        lint ret = 0;
        
        x = modpow(3, lq, MOD);
        x = (x * la) % MOD;
        y = modpow(3, lq - 1, MOD);
        y = (y * lq) % MOD;
        
        z = modpow(3, rq, MOD);
        z = (z * rc) % MOD;
        w = modpow(3, rq - 1, MOD);
        w = (w * rq) % MOD;
        
        //dump(x); dump(y); dump(z); dump(w); el;
        ret = (x + y) % MOD * (z + w) % MOD;
        ret %= MOD;
        return ret;
    };
    
    lint ans = 0;
    int la = 0, lb = 0, lc = 0, lq = 0;
    repeat (i, l) {
        if (s[i] == 'A') {
            --ra;
            ++la;
        }
        else if (s[i] == 'B') {
            --rb;
            ans += calc(la, lq, rc, rq);
            ans %= MOD;
            ++lb;
        }
        else if (s[i] == 'C') {
            --rc;
            ++lc;
        }
        else if (s[i] == '?') {
            --rq;
            //dump(la); dump(lq); dump(rc); dump(rq); dump(calc(la, lq, rc, rq)); el;
            ans += calc(la, lq, rc, rq);
            ans %= MOD;
            ++lq;
        }
        else assert(false);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

//↑template↑


ll  gcd(ll  a, ll  b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}


ll n, k[100005], ans;
int main() {
	cin >> n;
	vector<ll>a(n, 0), b(n, 0);
	for (int i = 0; i < n; ++i) { cin >> k[i]; }
	for (int i = 1; i < n; ++i) {
		a[i] = gcd(a[i - 1], k[i - 1]);
		b[n - i - 1] = gcd(b[n - i], k[n - i]);
	}

	for (int i = 0; i < n; ++i) {
		ans = max(gcd(a[i], b[i]), ans);
	}
	cout << ans << endl;
}

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

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, ga, gb, gc;
  cin >> n >> ga >> gb >> gc;
  vector<int> lens(n);
  REP(i, n) cin >> lens[i];

  i64 minmp = ga + gb + gc;
  vector<int> tmp(n, -1);

  auto calc = [&](auto rec, int i, int ta, int tb, int tc, i64 mp) -> void {
    if (mp > minmp) return;
    if (i == n) {
      if (ta == 0 || tb == 0 || tc == 0) return;
      mp += abs(ta - ga) + abs(tb - gb) + abs(tc - gc);
      if (minmp > mp) {
        minmp = mp;
      }
      return;
    }
    int x = lens[i];
    tmp[i] = 0;
    rec(rec, i + 1, ta, tb, tc, mp);
    if (ta < ga) {
      tmp[i] = 1;
      rec(rec, i + 1, ta + x, tb, tc, ta > 0 ? (mp + 10) : mp);
    }
    if (tb < gb) {
      tmp[i] = 2;
      rec(rec, i + 1, ta, tb + x, tc, tb > 0 ? (mp + 10) : mp);
    }
    if (tc < gc) {
      tmp[i] = 3;
      rec(rec, i + 1, ta, tb, tc + x, tc > 0 ? (mp + 10) : mp);
    }
  };
  calc(calc, 0, 0, 0, 0, 0);
  cout << minmp << endl;
}


Measured memory_bytes: 3636
from itertools import combinations
n=int(input())
A=[i+1 for i in range(n)]
num=n if n%2==1 else n+1

B=[]
for a,b in combinations(A,2):
    if a+b!=num:B.append([a,b])

print(len(B))
for i in B:print(*i)

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

void fnInput(int& rnLapDist, vector<int>& rvnOnePos)
{
  int nOneDistSiz;
  cin >> rnLapDist >> nOneDistSiz;
  rvnOnePos.resize(nOneDistSiz);

  for (int& nOneDist : rvnOnePos)
    cin >> nOneDist;
}
  
double fnMinMoveDist(int nLapDist, const vector<int>& cnrvnOnePos)
{
  int nMaxOneDist = 0;

  int i;
  for (i = 0; i < cnrvnOnePos.size() - 1; i++)
    nMaxOneDist = max(nMaxOneDist, abs(cnrvnOnePos[i + 1] - cnrvnOnePos[i]));

  nMaxOneDist = max(nMaxOneDist, abs(nLapDist -cnrvnOnePos[i]) + cnrvnOnePos[0]);
  return nLapDist - nMaxOneDist;
}
  
int main()
{
  int nLapDist;
  vector<int> vnOnePos;

  fnInput(nLapDist, vnOnePos);
  cout <<  fnMinMoveDist(nLapDist, vnOnePos) << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001

int gcd(int a, int b) {
    if(a < b) swap(a, b);
    if (b==0) return a;
    return gcd(b, a%b);
}

int main() {
    int n, d;
    int x[11][11];

    cin >> n >> d;

    for(int i=0; i<n; i++) {
        for(int j=0; j<d; j++) {
            cin >> x[i][j];
        }
    }
    
    int ans=0;

    for(int i=0; i<n; i++) {
        for(int j=i+1; j<n; j++) {
            double sq = 0;
            for(int k=0; k<d; k++) {

                sq += pow(x[i][k]-x[j][k], 2.0);

            }
            sq = sqrt(sq);

            if (floor(sq) == ceil(sq)) ans++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
if __name__ == '__main__':
    N, K = map(int, input().split())
        
    prob = 0
    
    for i in range(1, N+1):    
        for n in range(1000):
            if K <= i*2**n:
                num = n
                break
        
        prob += (1/N)*((1/2)**num)
    print(prob)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
typedef pair<int, int> P;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
struct edge {
  int to;
  int dist;
};
////////////////////////////////////////////////
int main() {
  init();
  int n, m;
  cin >> n >> m;
  vector<vector<edge>> G(n);
  REP(i, m) {
    int l, r, d;
    cin >> l >> r >> d;
    l--;
    r--;
    G[l].push_back(edge{r, d});
    G[r].push_back(edge{l, -d});
  }
  vecbool seen(n, false);
  vecint pos(n, 0);
  bool ok = true;
  REP(i, n) {
    if (seen[i]) continue;
    queue<int> q;
    q.push(i);
    seen[i] = true;
    while (!q.empty() && ok) {
      int now = q.front();
      q.pop();
      for (auto& e : G[now]) {
        int test = pos[now] + e.dist;
        if (seen[e.to]) {
          if (test != pos[e.to]) {
            ok = false;
            break;
          }
        } else {
          seen[e.to] = true;
          pos[e.to] = test;
          q.push(e.to);
        }
      }
    }
    if (!ok) {
      break;
    }
  }
  // REP(i, n) { cout << pos[i] << " "; }
  // cout << endl;
  // sort(all(pos));
  // if (pos[n - 1] - pos[0] > 1e9) {
  //   ok = false;
  // }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int n, ma=0;
	vector<int> v;
	int su, ev, xo;


	cin>> n;
	v.resize(n);

	rep(i, n){
		cin >> v[i];
		ma=max(v[i], ma);
	}

	int tmp=1;
	while(1){
		tmp*=2;
		if(ma<tmp) break;
	}
	ev=tmp-1;
	//cout<< ev <<endl;

	su=v[0];
	for(int i=1;i<n;i++) {
		//su=(su&v[i])&(su|v[i]);
		su=su^v[i];
	}

	if(n%2==1) su=su^ev;

	rep(i, n){
		xo=su^v[i];
		cout<< xo <<endl;
	}
 
	return 0;
}

Measured memory_bytes: 4008
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

ll N , A, B;
vector<ll> X;

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

  cin >> N >> A >> B;
  rep(i,N){
    ll inp; cin >> inp;
    X.pb(inp);
  }

  ll ans = 0;

  rep(i, N){
    if(i == 0) continue;
    ll dis = X[i] - X[i-1];
    ans += min(B, dis*A);
  }

  cout << ans << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
//======================================================================
// Contents    : AOJ ITP1_4_D
//               n 個の整数において、最小値、最大値、合計値を求める
// Input       : n , a
// Output      : min max sum
// Constraints : 0 < n ≤ 10000
//               −1000000 ≤ a ≤ 1000000
// Author      : 廣部智也
// LastUpdate  : 2020/06/03
// Since       : 2020/06/03
//======================================================================

#include <stdio.h>
#include <stdlib.h>                                                  // exit 関数を使用するため

#define LOWER_LIMIT_N        1
#define UPPER_LIMIT_N   100000
#define LOWER_LIMIT_A -1000000
#define UPPER_LIMIT_A  1000000
/* #define PRINT_ERROR printf("Input error\n") */

int Input_error( int number, int LOWER_LIMIT, int UPPER_LIMIT );    // 入力エラーを判断する関数

int main()
{
	int n = 0, a = 0;
	int min = 1000000 , max = -1000000;
	long int sum = 0;

    // データの入力
    scanf("%d", &n );  

    // 入力エラーの判断
    Input_error( n, LOWER_LIMIT_N, UPPER_LIMIT_N );

	while ( n-- > 0 ) {

        // データの入力
		scanf("%d", &a );

        // 入力エラーの判断
        Input_error( a, LOWER_LIMIT_A, UPPER_LIMIT_A );

        // データの処理
		if ( a < min ) min = a;
		if ( a > max ) max = a;
		sum += a;
	}

    // データの出力
	printf("%d %d %ld\n", min, max, sum );
	return 0;
}

//============================================================
// Contents    : 入力エラーを判断
// Input       : 調べる変数, 下限, 上限
// Output      : エラーなら強制終了
// Author      : 廣部智也
// LastUpdate  : 2020/06/05
// Since       : 2020/06/05
//============================================================
int Input_error( int number, int LOWER_LIMIT, int UPPER_LIMIT){
    
    if( number < LOWER_LIMIT || number > UPPER_LIMIT ){ 
        printf("Input error\n");
        exit(1);
    }

    return 0;
}


Measured memory_bytes: 2100
/*
 * Author: ylx
 * Lang: c++
 * Prog: agc027D
 */
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x, int y)
{
	if (x < y)
		x = y;
}
void qmin(int &x, int y)
{
	if (x > y)
		x = y;
}
inline int read()
{
	char s;
	int k = 0, base = 1;
	while ((s = getchar()) != '-' && s != EOF && !(isdigit(s)))
		;
	if (s == EOF)
		exit(0);
	if (s == '-')
		base = -1, s = getchar();
	while (isdigit(s))
		k = k * 10 + (s ^ '0'), s = getchar();
	return k * base;
}
inline void write(ll x)
{
	static char cnt, num[20];
	cnt = 0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (; x; x /= 10)
		num[++cnt] = x % 10;
	for (; cnt; putchar(num[cnt--] + 48))
		;
}
const int maxm = 1e5 + 100;
const int maxn = 2000 + 10;
int n, m;
int p[maxm], cnt;
ll pr[maxn];
ll a[510][510];
int main()
{
#ifdef ylx
	freopen("agc027D.in", "r", stdin);
	freopen("agc027D.out", "w", stdout);
#endif
	n = read();
	m = 1e5;
	for (int i = 2; i <= m; i++)
		if (!p[i])
		{
			pr[++cnt] = i;
			if (cnt == 2 * n + 1)
				break;
			for (int j = i + i; j <= m; j += i)
			{
				p[j] = 1;
			}
		}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			a[i][j] = 1;
		}
	for (int i = 1; i <= n; i++)
	{
		for (int j = (i & 1) ? 1 : 2; j <= n; j += 2)
		{
			a[i][j] = pr[(i + j) / 2] * pr[(i - j + n + 1) / 2 + n];
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = (i & 1) ? 2 : 1; j <= n; j += 2)
		{
			a[i][j] = a[i - 1][j] * a[i + 1][j];
			if (i == 1 || i == n)
				a[i][j] = a[i][j - 1] * a[i][j + 1];
			if (!a[i][j])
				a[i][j] = max(a[i - 1][j], 1ll) * max(a[i + 1][j], 1ll) * max(a[i][j - 1], 1ll) * max(a[i][j + 1], 1ll);
			a[i][j]++;
		}
	}
	if (n == 2)
		a[2][1] += 150;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			write(a[i][j]);
			putchar(' ');
		}
		putchar('\n');
	}
	return 0;
}
//2019年 02月 24日 星期日 18:28:29 CST

Measured memory_bytes: 5504
/* ***************************************
Author        :Scau.ion
Created Time  :2016/10/30 12:50:41 UTC+8
File Name     :ion.cpp
*************************************** */
 
#include <bits/stdc++.h>
 
#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);
 
using namespace std;
 
const int maxn=300000;
 
int a[maxn];
bool b[maxn],cango[maxn];
 
int main()
{
    IOS;
	int n;
    cin>>n;
    int tot=n*2-1;
    for (int j=1;j<=tot;++j)
        cin>>a[j];
    int l=1,r=tot;
    while (l+1<r)
    {
        int mid=(l+r)/2;
        for (int j=1;j<=tot;++j)
        {
            if (a[j]<mid) b[j]=0;
            else b[j]=1;
        }
        b[0]=b[1];
        b[tot+1]=b[tot];
        for (int j=1;j<=tot;++j)
        {
            if (b[j]!=b[j-1]&&b[j]!=b[j+1]) cango[j]=1;
            else cango[j]=0;
        }
        int ha=0;
        while (ha<n-1&&b[n-ha-1]!=b[n-ha]&&b[n+ha+1]!=b[n+ha]) ++ha;
        if (b[n-ha]) l=mid;
        else r=mid;
    }
    cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  map< int, int > mp;
  int sum = 0;
  mp[sum]++;
  REP(i, N) {
    int a;
    cin >> a;
    sum += a;
    sum %= M;
    mp[sum]++;
  }
  int ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    int val = itr->second;
    ans += val * (val - 1) / 2;
  }
  print(ans);
  // print();
}

Measured memory_bytes: 4224
import Data.List

main :: IO ()
main = do
  getLine
  ws <- lines <$> getContents
  if all (==1) $ map length $ group $ sort ws
     then putStrLn $ srtr ws
     else putStrLn "No"
  
srtr :: [String] -> String
srtr  [] = "Yes"
srtr  [_] = "Yes"
srtr (x:y:xs)
  | last x == head y = srtr (y:xs)
  | otherwise = "No"

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

	int n;
	cin >> n;
	vector<int> h;
	rep(i,n) {
		int a;
		cin >> a;
		h.push_back(a);
	}

	int ans = 1;
	FOR(i,1,n) {
		bool flag = true;
		FOR(j,0,i) {
			if (h[j]>h[i]) {
				flag = false;
				break;
			}
		}
		if (!flag) {
			continue;
		}
		ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256