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

using namespace std;

const int N = 101;
const int K = 1e5 + 5;
const int mod = 1e9 + 7;

int dp[N][K];
int pre[K];
int arr[N];

inline int add(int a, int b) {
  a += b;
  if(a >= mod) a -= mod;
  if(a < 0) a += mod;
  return a;
}

inline int mul(int a, int b) {
  return (long long) a * b % mod;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  int sum = 0;
  for(int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum = sum + arr[i];
  }
  if(sum < k) {
    cout << 0 << "\n";
    return 0;
  }
  for(int i = 0; i <= arr[0]; ++i) {
    dp[0][i] = 1;
  }
  int sofar = arr[0];
  for(int i = 1; i < n; ++i) {
    pre[0] = dp[i - 1][0];
    sofar += arr[i];
    for(int j = 1; j <= k; ++j) {
      pre[j] = add(pre[j - 1], dp[i - 1][j]);
    }
    for(int j = 0; j <= min(k, sofar); ++j) {
      int ind = j - arr[i] - 1;
      if(ind < 0) dp[i][j] = pre[j];
      else dp[i][j] = add(pre[j], -pre[ind]);
    }
  }
  cout << dp[n - 1][k];
  cout << "\n";
}

Measured memory_bytes: 39680
#include <iostream>

using namespace std;

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  if (r <= x && x <= W - r) {
    if (r <= y && y <= H - r) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3128
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int a[1000], b[1000], i,s[1000];
	i = 1;
	while (1) {
		cin >> a[i] >> b[i];
		if (a[i] == 0 && b[i] == 0) { break; }
		s[i] = 0;
		i++;
	}
	for (int n = 1;n <= i - 1;n++) {
		for (int j = 1;j <= a[n] - 2;j++) {
			for (int k = j+1;k <= a[n] - 1;k++) {
				for (int l = k+1;l <= a[n];l++) {
					if (j + k + l == b[n] ) { s[n] = s[n] + 1; }
				}
			}
		}
	}
	for (int m = 1;m <= i - 1;m++) { cout << s[m] << endl; }
	return 0;
}


Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[] array = new int[a];
        int count = 0;
        for(int i = 0; i < a; i++){
            array[i] = sc.nextInt();
            if(array[i] >= b){
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 46452
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String read = null;
        try {
            read = br.readLine();
            br.close();
        } catch (IOException e){
            e.printStackTrace();
        }
        String str[] = read.split(" ", 0);
        int h = Integer.parseInt(str[0]);
        int a = Integer.parseInt(str[1]);
        PrintWriter pw = new PrintWriter(System.out);
        int i = 0;
        while (h > 0) {
            h = h - a;
            i++;
        }
        pw.println(i);
        pw.flush();
    }
}

Measured memory_bytes: 21076
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res



def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = list(set(a))
    d = Counter(a)
    if a[0] != 0:
        print(0)
    elif a[0] == 0 and d[0] > 1:
        print(0)
    else:
        ans = 1
        for i in range(1, len(s)):
            if d[s[i] - 1] == 0 and s[i] > 0:
                print(0)
                exit()
            ans = (ans * modpow(d[s[i - 1]], d[s[i]], 998244353)) % 998244353
        print(ans)
            

    
    

        
        
        
            

    
   


if __name__ == '__main__':
    main()


Measured memory_bytes: 104544
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextLine() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(nextLine())
	if e != nil {
		panic(e)
	}
	return i
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func sumSlice(nums []int) int {
	sum := 0
	for _, n := range nums {
		sum += n
	}
	return sum
}

func binarySearch(target int, list []int) int {
	left := 0
	right := len(list) - 1
	mid := (left + right) / 2

	for {
		if list[mid] < target {
			left = mid + 1
		} else {
			right = mid
		}
		mid = (left + right) / 2
		if left >= right {
			break
		}
	}
	return mid
}

func main() {
	scanner.Split(bufio.ScanWords) // switch to separating by space
	// scanner.Buffer([]byte{}, 1000000009) // switch to read large size input

	N := nextInt()
	heights := scanNums(N)

	answer := "Yes"

	for i := N - 1; 1 <= i; i-- {
		if heights[i-1]-heights[i] > 1 {
			answer = "No"
		}
		if heights[i-1]-heights[i] == 1 {
			heights[i-1]--
		}
	}

	fmt.Println(answer)
}


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

const int DIAG = 1;
const int RIGHT = 2;
const int DOWN = 3;
int main(){
	string s,t;
	cin >> s >> t;
	
	vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1));
	vector<vector<int>> traceback(s.size()+1, vector<int>(t.size()+1));
	
	rep(i,dp.size()-1){
		rep(j,dp[0].size()-1){
			if(s[i] == t[j]){
				dp[i+1][j+1] = dp[i][j] + 1;
				traceback[i+1][j+1] = DIAG;
			}
			else{
				dp[i+1][j+1] = max( dp[i+1][j], dp[i][j+1] );
				
				if(dp[i+1][j+1] == dp[i+1][j]){
				    traceback[i+1][j+1] = DOWN;
				}
				else{
				    traceback[i+1][j+1] = RIGHT;
				}
			}
		}
	}
	
	// traceback
	string res;
	int i=s.size(),j=t.size();
	while(i >= 1 && j >= 1){
		if(traceback[i][j] == RIGHT) i--;
		else if(traceback[i][j] == DOWN) j--;
		else{
			res += s[i-1];
			i--; j--;
		}
	}
    reverse(res.begin(), res.end());
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 70912
n, m = gets.split(" ").map(&:to_i)
bridges = Hash.new

m.times do |i|
  a, b = gets.split(" ").map(&:to_i)
  bridges[a] = b if bridges[a].nil? || b < bridges[a]
end

#dp[i]: 互いに共通部分を持たない区間を最大何個[1,i)に入れられるか
dp = Array.new(n+1, 0)

1.upto(n) do |i|
  dp[i] = dp[i-1] if dp[i] < dp[i-1]
  if j = bridges[i]
    dp[j] = dp[i] + 1  if  dp[j] < dp[i] + 1
  end
end

puts dp[n]



Measured memory_bytes: 9084
s = input()
t = s[::-1]
u = ''
for i in range(len(s)):
  if t[i] == 'b':
    u += 'd'
  elif t[i] == 'd':
    u += 'b'
  elif t[i] == 'p':
    u += 'q'
  elif t[i] == 'q':
    u += 'p'
if s == u:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9108
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;
 
using namespace std;
bool cmp( const pair<int , int> p1 , const pair<int , int > p2  ){
    return p1.second < p2.second ;
}
int main(){
    FAST() ;
    int N , K ; cin >> N >> K ;
    int freq[200001] = { 0 } ;
    for( int i = 0 ; i < N ; i++ ){
        int x ; cin >> x ;
        freq[x]++ ;
    }
    vector<pair<int , int> > v ;
    for( int i = 1 ; i < 200001 ; i++ ){
        if( freq[i] != 0 ){
            v.push_back({ i , freq[i] } ) ;
        }
    }
    sort(v.begin(), v.end(), cmp ) ;
    bigint ans = 0 ;
    if( K >= v.size() ){
        cout << 0 << endl ;
        return 0 ;
    }
    for( int i = 0 ; i < v.size() - K ; i++ ){
        ans += v[i].second ;
    }
    cout << ans << endl ;
    return 0 ;
}


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

const ll mod=1e9+7;

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

/*-------------------------------------------*/


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

    int n,k;
    cin>>n>>k;
    vector<ll>a(n),sum1(n+1),sum2(n+1);
    ll ans=0;

    rep(i,n){
        cin>>a[i];
        sum1[i+1]=sum1[i]+a[i];
        sum2[i+1]=sum2[i]+max(0ll,a[i]);
    }

    rep(i,n-k+1){
        chmax(ans,sum2[i]-sum2[0]+max(0ll,sum1[i+k]-sum1[i])+sum2[n]-sum2[i+k]);
    }

    cout<<ans<<endl;
}

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

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

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

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() {
    double l;
    cin>>l;
    cout<<setprecision(10)<<(l/3)*(l/3)*(l/3)<<endl;

    return 0;
}


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

int main(){
    int n; cin >> n;
    string s; cin >> s;
    ll ans = 1;
    ll ch[30];
    for(int i = 0; i < 30; i++) ch[i] = 0;
    for(int i = 0; i < n; i++) ch[s[i] - 'a']++;
    int sum = 0;
    for(int i = 0; i < 30; i++){
        sum += ch[i];
        if(ch[i] > 0) ans = (ans * (ch[i]+1)) %mod;
    }
    cout << (ans-1)%mod << endl;
    

    return 0;
}

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

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int d[n];
    rep(i, n) cin >> d[i];
    sort(d, d + n);
    int mn = d[n/2-1];
    int mx = d[n/2];
    int ans = mx - mn;

    cout << ans << endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <iterator>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <utility>
#include <functional>
#include <stack>
#include <deque>
#include <sstream>
using namespace std;

#define ll long long
#define mod 1000000007
#define ld long double
#define infinity (ll)1e18+1
#define PI 3.14159265358979

#define pdd pair<ld,ld>
#define pll pair<ll, ll>
#define pii pair<int,int>

#define MP make_pair
#define SZ size()
#define PB push_back

#define vi vector<int>//ll
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define vch vector<char>
#define vb vector<bool>
#define vld vector<ld>
#define vs vector<string>

#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(ll i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define ALL(a) a.begin(), a.end()
#define X first
#define Y second
#define MAXN 100001

ll power(ll n, ll to, ll modulo = mod)
{
	if (to == 0) return 1;
	if (to == 1) return n%modulo;
	int exp = 1;
	ll ans = n;
	while (2 * exp <= to)
	{
		ans *= ans;
		ans %= modulo;
		exp *= 2;
	}
	return ((ans*power(n, to - exp, modulo)) % modulo);
}

int main()
{
	srand(time(NULL));
	clock_t startTime = clock();
	ios_base::sync_with_stdio(false), cin.tie(0);
	//ifstream in("In.txt");


	int n; cin >> n;
	vll a(n); FOR(i, 0, n)cin >> a[i];

	vll b;

	if (n % 2 == 0)
	{
		RFOR(i, n, 0)
			if (i % 2 == 1)
				cout << a[i] << " ";
		FOR(i,0,n)
			if (i%2==0)
				cout << a[i] << " ";
	}
	else
	{
		RFOR(i, n, 0)
			if (i % 2 == 0)
				cout << a[i] << " ";
		FOR(i, 0, n)
			if (i % 2 == 1)
				cout << a[i] << " ";
	}


	

	return 0;
}
//don't forget about MAXN, mod and infinity

Measured memory_bytes: 3840
#include<iostream>
#include<map>
#include<string>

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

	std::map<std::string, int> mp;

	//書き込み(特定の場合のみのパターンなので書き換えて)
	for (int i = 0; i < n; i++) {
		std::string str;
		std::cin >> str;

		mp[str]++;
	}

	std::cout<<mp.size()<<std::endl;
	return 0;
}

Measured memory_bytes: 19120
from collections import deque
from copy import deepcopy

def parse():
  H, W = map(int, input().split(" "))
  grid = []
  grid.append(["#" for x in range(W + 2)])
  for y in range(H):
    grid.append(list("#" + input() + "#"))
  grid.append(["#" for x in range(W + 2)])
  return H, W, grid

def print_grid(grid):
  H = len(grid)
  W = len(grid[0])
  for y in range(H):
    for x in range(W):
      print(grid[y][x], end="")
    print("")
  print("")

def print_visited(visited):
  H = len(visited)
  W = len(visited[0])
  for y in range(H):
    for x in range(W):
      if visited[y][x]:
        print(1, end="")
      else:
        print(0, end="")
    print("")
  print("")

def print_grid_with_paths(grid, paths):
  H = len(grid)
  W = len(grid[0])
  for y in range(H):
    for x in range(W):
      if (x, y) in paths:
        print("*", end="")
      else:
        print(grid[y][x], end="")
    print("")
  print("")

def main():
  H, W, grid = parse()

  visited = [[False for x in range(W + 2)] for y in range(H + 2)]
  for y in range(H + 2):
    for x in range(W + 2):
      if x == 0 or x == W + 1 or y == 0 or y == H + 1:
        visited[y][x] = True
  visited[0][0] = True

  # print_grid(grid)
  # print_visited(visited)

  vecs = [(0, -1), (0, 1), (-1, 0), (1, 0)]

  # 幅優先探索で最短経路を求める
  q = deque([(1, 1, [])])
  while len(q) > 0:
    x, y, paths = q.popleft()
    paths.append((x, y))
    # print_grid_with_paths(grid, paths)
    # input()
    
    # 終了条件
    if y == H and x == W:
      # print(paths)
      ans = 0
      for y in range(H + 2):
        for x in range(W + 2):
          # 経路は除外
          if (x, y) in paths:
            continue

          if grid[y][x] == ".":
            ans += 1

      # 最短経路周辺に"#"を置く数をカウント
      # prev_x, prev_y = paths[0]
      # cur_x, cur_y = paths[1]
      # for next_x, next_y in paths[2:]:
      #   for vec in vecs:
      #     adj_x = cur_x + vec[0]
      #     adj_y = cur_y + vec[1]

      #     # 経路上のマスの色は変えない
      #     if adj_x == prev_x and adj_y == prev_y:
      #       continue
      #     if adj_x == next_x and adj_y == next_y:
      #       continue
          
      #     # マスの色を変える
      #     if grid[adj_y][adj_x] == ".":
      #       grid[adj_y][adj_x] = "#"
      #       ans += 1
      #   prev_x, prev_y = cur_x, cur_y
      #   cur_x, cur_y = next_x, next_y
      #   # print_grid(grid)
      #   # input()
      print(ans)
      exit(0)

    for vec in vecs:
      next_x = x + vec[0]
      next_y = y + vec[1]
      if grid[next_y][next_x] == "#":
        continue

      if not visited[next_y][next_x]:
        visited[next_y][next_x] = True
        q.append((next_x, next_y, deepcopy(paths)))

  print(-1)

if __name__ == "__main__":
  main()

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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
*/

using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define PI 3.1415926535897932384626433832795
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
*/

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main()
{
    #ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
    string s;
    cin>>s;
    stack<char> st;
    int ans = 0;
    for(int i=0;i<s.size();i++)
    {
        if(st.empty())
        {
            st.push(s[i]);
        }
        else
        {
            char c = st.top();
            if((c=='0' && s[i]=='1') || (c=='1' && s[i]=='0'))
            {
                st.pop();
                ans+=2;
            }
            else
            {
                st.push(s[i]);
            }
        }
    }

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

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



int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    map<ll, ll> MAP; 
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        MAP[A[i]] ++;
    }
    for (auto t : MAP) {
        if (t.second <= 1) MAP.erase(t.first);
    }

    //　コンビネーション配列
    vector<ll> vec(N+1);
    for (ll i = 0; i <= N; i++) {
        if (i-1 < 0) continue;
        vec[i] = i*(i-1)/2;
    }

    ll count = 0;

    for (auto t : MAP) {
        if (t.second >= 2) {
            count += vec[t.second];
        }
    }

    vector<ll> ans(N);
    for (int i = 0; i < N; i++) {
        if (MAP[A[i]] <= 1) ans[i] = count;
        else if (MAP[A[i]] == 2) ans[i] = count-1;
        else ans[i] = count-vec[MAP[A[i]]]+vec[MAP[A[i]]-1];
    }
    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 14208
#include<stdio.h>

int main(void)
{
	int a, b, w, n, i;
	int no[30] = { 0 };
	int temp = 0;

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

	for (i = 0; i < w; i++)
		no[i] = i + 1;

	for (i = 0; i < n; i++)
	{
		scanf("%d,%d", &a, &b);
		temp = no[a-1];
		no[a-1 ] = no[b - 1];
		no[b-1] = temp;
	}

	for (i = 0; i < w; i++)
		printf("%d\n", no[i]);

	scanf("%d", &a);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;

using Graph = vector<vector<int>>;
const int MAX = 610000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

  COMinit();

  int N, K;
  cin >> N >> K;

  int ans = 1;
  if(K >= N-1){
    cout << COM(N+N-1, N) << endl;
  }
  else{
    rep(i,K){
      int M = i+1;
      ans += COM(N, N-M) * COM(N-1, M);
      ans %= MOD;
    }
    cout << ans << endl;
  }
  
}

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

public final class Main {
	public static void main(String[] args) throws java.lang.Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] arg;
		long t[] = new long[n];
		long a[] = new long[n];
		for (int i = 0; i < n; i++) {
			arg = br.readLine().split(" ");
			t[i] = Integer.parseInt(arg[0]);
			a[i] = Integer.parseInt(arg[1]);

		}

		Solver sol = new Solver();
		System.out.println(sol.solve(t, a));
	}

}

class Solver {

	long solve(long[] t, long[] a) {

		long tempT = 0, tempA = 0;
		for (int i = 1; i < t.length; i++) {

			if (t[i] >= t[i - 1] && a[i] >= a[i - 1]) {

				tempT = t[i];
				tempA = a[i];

			} else {
				for (long j = Math.max(t[i - 1] / t[i], a[i - 1] / a[i]); true; j++) {
					tempT = t[i] * j;
					tempA = a[i] * j;
					if (tempT >= t[i - 1] && tempA >= a[i - 1])
						break;
				}

			}
			t[i] = tempT;
			a[i] = tempA;

		}
		return t[t.length - 1] + a[a.length - 1];
	}

}// 3
//13 11
//4 9
//1 2


Measured memory_bytes: 22356
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){

  int n,pv,tv,pc;
  cin >> n;
  int tc[n+1];
  cin >> pv >> tv >> pc;
  for(int i=0;i<n;i++){
    cin >> tc[i];
  }

  int max=n+1,sum=0,cou=0;
  double best;
  int can[n];
  for(int i=0;i<n;i++)can[i] = 0;

  sum+=pc;

  best = (double)sum/pv;
  tc[n+1]=0;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(tc[max]<tc[j] && can[j] == 0)max=j;
    }
    sum+=tc[max];
    can[max]=1;
    cou++;
    max=n+1;
 
    if((double)sum/(pv+tv*cou) > best){
      //cout << "Bbest = " << best << endl;
      //cout  << "cou = " << cou << endl;
      best = (double)sum/(pv+tv*cou);
      //cout << "Abest = " << best << endl;
    }

    // for(int h = 0;h<n;h++)cout << can[h] << endl;
    // cout << endl;

  }

  cout << (int)floor(best) << endl;



}

Measured memory_bytes: 0
//
// Created by chuan on 2020-04-10.
//

#include <iostream>
#include <numeric>
#include <algorithm>
#include <string>
#include <vector>

using ll = long long ;

using namespace std;

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

    int K, N; cin>>K>>N;
    vector<int> distances(N);
    ll prev = 0;
    for (int i = 0; i < N; ++ i){
        int v;
        cin>>v;
        distances[i] = v- prev;
        prev = v;
    }
    distances.push_back(K-prev+distances.front());
    distances.front() = 0;

    auto p = max_element(distances.begin(), distances.end());

    *p = 0;
    long long s = accumulate(distances.begin(), distances.end(), 0);
    cout<<s <<endl;


    return 0;
}


Measured memory_bytes: 1792
n,m = map(int,input().split())
graph = [[False for i in range(n)] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1][b-1],graph[b-1][a-1] = True,True

def dfs(num,visited):
    if visited==[True]*n:
        return 1
    res = 0
    for i in range(n):
        if graph[num][i] and not visited[i]:
            visited[i] = True
            res += dfs(i,visited)
            visited[i] = False
    return res

visit = [True] + [False] * (n-1)
print(dfs(0,visit))


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  int n;
  cin>>n;
  int h[n];
  int dp[n];
  dp[0]=0;
  REP(i,n){
    cin>>h[i];
  }
  REP(i,n-1){
    if(h[i]>=h[i+1]){
      dp[i+1]=dp[i]+1;
    }else{
      dp[i+1]=0;
    }
  }
  sort(dp,dp+n);
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
n=int(input())
a=[int(i) for i in input().split()]

c=[0 for i in range(8)]
r=0

for i in a:
    if 1<=i and i<=399:
        c[0]+=1
    elif 400<=i and i<=799:
        c[1]+=1
    elif 800<=i and i<=1199:
        c[2]+=1
    elif 1200<=i and i<=1599:
        c[3]+=1
    elif 1600<=i and i<=1999:
        c[4]+=1
    elif 2000<=i and i<=2399:
        c[5]+=1
    elif 2400<=i and i<=2799:
        c[6]+=1
    elif 2800<=i and i<=3199:
        c[7]+=1
    elif 3200<=i:
        r+=1

s=0
for i in c:
    if i!=0:
        s+=1

b=s+r

if s==0:
    s=1
    b=r

print(s,b)

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

int main(){
    char x,y;
    int x2, y2;

    cin >> x >> y;

    if(x == 'A'){
        x2 = 10;
    } else if(x == 'B'){
        x2 = 11;
    }else if(x == 'C'){
        x2 = 12;
    }else if(x == 'D'){
        x2 = 13;
    }else if(x == 'E'){
        x2 = 14;
    }else if(x == 'F'){
        x2 = 15;
    }

    if(y == 'A'){
        y2 = 10;
    } else if(y == 'B'){
        y2 = 11;
    }else if(y == 'C'){
        y2 = 12;
    }else if(y == 'D'){
        y2 = 13;
    }else if(y == 'E'){
        y2 = 14;
    }else if(y == 'F'){
        y2 = 15;
    }

    if(x == y){
        cout << "=" << endl;
    } else if(x > y){
        cout << ">" << endl;
    } else if(x < y){
        cout << "<" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int K;
    cin >> K;

    cout << (K/2)*((K+1)/2) << endl;
    return 0;
}

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

int main(int argc, char const *argv[]) {
  std::vector<int> data;

  for (size_t i = 0; i < 5; i++) {
    int tmp;
    std::cin >> tmp;
    data.push_back(tmp);
  }

  int sum = 0;
  std::vector<int> dig_data;

  for (size_t i = 0; i < data.size(); i++) {
    int tmp;
    tmp = data.at(i);
    if (tmp >= 100) {
      tmp-=100;
      dig_data.push_back(tmp%10);
    } else if (tmp >= 10){
      dig_data.push_back(tmp%10);
    } else {
      dig_data.push_back(tmp);
    }
  }

  int index = 0;
  for (size_t i = 0; i < dig_data.size(); i++) {
    if (dig_data.at(index) > dig_data.at(i) && dig_data.at(i) != 0) {
      index = i;
    }
  }

  for (size_t i = 0; i < dig_data.size(); i++) {
    if (i == index) continue;
    sum += ceil((float)data.at(i)/10)*10;
  }
  sum += data.at(index);

  std::cout << sum << '\n';
}


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

using namespace std;
int main(){
	string s;
	cin >> s;
	if(s[0]=='S') cout << "Cloudy" << endl;
	if(s[0]=='C') cout << "Rainy" << endl;
	if(s[0]=='R') cout << "Sunny" << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val reader = System.`in`.bufferedReader()
    val array = arrayOfNulls<String>(48828125)
    val stringBuilder = StringBuilder()
    repeat(Integer.parseInt(reader.readLine())) {
        val command = reader.readLine().split(" ")
        when (command[0]) {
            "insert" -> array.insert(command[1])
            "find" -> {
                stringBuilder.append(
                    if (array.find(command[1])) {
                        "yes"
                    } else {
                        "no"
                    })
                stringBuilder.append("\n")
            }
        }
    }
    stringBuilder.deleteCharAt(stringBuilder.lastIndex)
    println(stringBuilder.toString())
}

fun Array<String?>.insert(str: String) {
    this[str.getHash()] = str
}

fun Array<String?>.find(key: String) = this[key.getHash()] != null

fun String.getHash(): Int {
    var sum = 0
    for (c in this) {
        sum *= 5
        sum += c.getInt()
    }
    return sum
}

fun Char.getInt() = when(this) {
    'A' -> 1
    'C' -> 2
    'G' -> 3
    'T' -> 4
    else -> 0
}



Measured memory_bytes: 388820
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr = Counter(src)

def is_valid(ctr):
    if N%2:
        if ctr[0] != 1:
            return False
        for i in range(2,N,2):
            if ctr[i] != 2:
                return False
    else:
        for i in range(1,N,2):
            if ctr[i] != 2:
                return False
    return True

if is_valid(ctr):
    MOD = 10**9+7
    print(2**(N//2) % MOD)
else:
    print(0)


Measured memory_bytes: 14820
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for (int i = 0; ; i++) {
		if (i % 2 == 0) {
			c -= b;
			if (c <= 0) {
				cout << "Yes\n";
				return 0;
			}
		} else {
			a -= d;
			if (a <= 0) {
				cout << "No\n";
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3100
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
from itertools import permutations
ans=0
for i in permutations(range(n),n):
    for j in range(1,n):
        ans+=((xy[i[j]][0]-xy[i[j-1]][0])**2+(xy[i[j]][1]-xy[i[j-1]][1])**2)**0.5
for i in range(1,n+1):
    ans/=i
print(ans)

        


Measured memory_bytes: 74512
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
   
    ll n;
    cin >> n;
    ll max1 = 0;
    ll max2 = 0;
    ll max1Id = 0;
    ll max2Id = 0;
    ll a,b;
    cin >> a >> b;
    if(a >= b){
        max1Id = 1;
        max2Id = 2;
        max1 = a;
        max2 = b;
    }else{
        max1Id = 2;
        max2Id = 1;
        max1 = b;
        max2 = a;
    }
    for (ll i=3;i<=n;i++){
        ll tmp;
        cin >> tmp;
        if(tmp > max1){
            max2Id = max1Id;
            max2 = max1;
            max1 = tmp;
            max1Id = i;
        }else if(tmp > max2){
            max2Id = i;
            max2 = tmp;
        }
    }
    if(max1 == max2){
        for(ll i=0;i<n;i++){
            cout << max1 << endl;
        }
    }else{
        for (ll i=1;i<=n;i++){
            if(i==max1Id){
                cout << max2 << endl;
            }else{
                cout << max1 << endl;
            }
        }
    }

}

Measured memory_bytes: 1664
program main;
 
var
	n, i, sum : int64;
   
begin
	sum := 0;
	readln(n);
    for i := 1 to n do begin
    	if (i mod 3 <> 0) and (i mod 5 <> 0)
    		then sum := sum + i;
    end;
    writeln(sum);
end.

Measured memory_bytes: 1376
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,i;
    ll res=0;
    cin>>n;
    vector <int>a(n+1);
    for(i=0;i<=n;i++)
    {
        cin>>a[i];
    }
    vector <int>b(n);
    for(i=0;i<n;i++)
    {
        cin>>b[i];
    }
    for(i=0;i<n;i++)
    {
        int tem=min(a[i],b[i]);
        res+=tem;
        b[i]-=tem;
        a[i]-=tem;
        tem=min(a[i+1],b[i]);
        res+=tem;
        b[i]-=tem;
        a[i+1]-=tem;

    }

cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    
        var sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        
        var st = new SegmentTree(300001, 0);
        for(int i = 0; i < n; i++){
            int a = Integer.parseInt(sc.next());
            int min = Math.max(a-k, 0);
            int max = Math.min(a+k, 300000);
            st.update(a, st.getMax(min, max+1) +1);
        }
    
        System.out.println(st.getMax(0, 300001));
    }
    
    static class SegmentTree {
        int n;
        int[] node;
        
        public SegmentTree(int size, int defaultValue) {
            n = 1;
            while(n < size) n <<= 1;
            node = new int[2*n-1];
            Arrays.fill(node, defaultValue);
        }
        public SegmentTree(int[] a, int defaultValue) {
            n = 1;
            while(n < a.length) n <<= 1;
            node = new int[2*n-1];
            System.arraycopy(a, 0, node, n-1, a.length);
            Arrays.fill(node, n-1+a.length, 2*n-1, defaultValue);
            for(int i = n-2; i >= 0; i--){
                node[i] = Math.max(node[i*2+1], node[i*2+2]);
            }
        }
        void update(int i, int x){
            i += n-1;
            node[i] = x;
            while(i > 0){
                i = (i-1)/2;
                node[i] = Math.max(node[i*2+1], node[i*2+2]);
            }
        }
        int getMax(int a, int b){
            return getMax(a, b, 0, 0, n);
        }
        int getMax(int a, int b, int k, int l, int r){
            if(r <= a || b <= l) return Integer.MIN_VALUE;
            if(a <= l && r <= b) return node[k];
            int vl = getMax(a, b, k*2+1, l, (l+r)/2);
            int vr = getMax(a, b, k*2+2, (l+r)/2, r);
            return Math.max(vl, vr);
        }
        int get(int i){
            return node[i+n-1];
        }
    }
}

Measured memory_bytes: 62896
#!/usr/bin/env python3
import numpy as np
import math
import re

n = int(input())

x = input()
max = 0
for i in range(n):
    s = 0
    list1 = set(x[0:i])
    list2 = set(x[i:n])
    for j in list1:
        if j in list2:
            s += 1
    if s > max:
        max = s
print(max)

Measured memory_bytes: 12416
double x,y,r,X,Y,R;main(n){for(scanf("%d",&n);n--;printf("%d\n",x+R<r?2:x+r<R?-2:!(x>r+R)))scanf("%lf%lf%lf%lf%lf%lf",&x,&y,&r,&X,&Y,&R),x=hypot(X-x,Y-y);}

Measured memory_bytes: 652
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <queue>

using namespace std;

#define ll long long

class Main {
public:
	int rec(int n, vector<pair<int, int> >& edges, vector<bool>& prevs, int last) {
		bool isCleared = true;
		for (int i = 0;i < prevs.size();i++) {
			isCleared &= prevs[i];
		}
		if (isCleared) {
			return 1;
		}

		int sum = 0;
		for (int i = 0;i < edges.size();i++) {
			auto edge = edges[i];
			int v = last;

			if (edge.first == v || edge.second == v) {
				int u = (edge.first == v ? edge.second : edge.first);

				if (prevs[u]) continue;

				prevs[u] = true;
				sum += rec(n, edges, prevs, u);
				prevs[u] = false;
			}
		}

		return sum;
	}

	int getNum(int n,vector<pair<int, int> >& edges, int start){
		vector<bool> prevs(n, false);
		prevs[start] = true;

		return rec(n, edges, prevs, start);
	}
};


int main()
{
	Main main;
	int n;
	int en;
	vector<pair<int, int> > edges;

	cin >> n >> en;
	for (int i = 0;i < en;i++) {
		int a, b;
		cin >> a >> b;
		pair<int, int> p(a-1, b-1);
		edges.push_back(p);
	}

	cout << main.getNum(n, edges,0) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1e18;
template<class T>inline bool read(T &x){
	x=0;register char c=getchar();register bool f=0;
	while (!isdigit(c)){if (c==EOF) return 0;f^=c=='-';c=getchar();}
	while (isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if (f) x=-x;
	return 1;
}

template<class T>inline void print(T x){
	if (x<0) putchar('-'),x=-x;
	if (x>9) print(x/10);
	putchar(x%10^48);
}
template<class T>inline void print(T x,char c){print(x);putchar(c);}
template<class T,class ...S>inline bool read(T &x,S &...y){return read(x)&&read(y...);}

ll f[100][100][2],c[100],ans;
bool vis[100][100][2];
int n;
char s[100][100];
bool check(int now,int pos,int d){
	if (d){for (int i=1,j=pos;i<j;i++,j--)if (s[now][i]!=s[now][j])return 0;}
	else{for (int i=pos,j=strlen(s[now]+1);i<j;i++,j--)if (s[now][i]!=s[now][j]) return 0;}
	return 1;
}
ll dp(int now,int pos,int d){
	if (vis[now][pos][d]) return f[now][pos][d];
	vis[now][pos][d]=1;
	f[now][pos][d]=inf;
	if (check(now,pos,d)) return f[now][pos][d]=0;
	bool flag;
	for (int i=1,j,k;i<=n;i++){
		flag=1;
		if (d){for (j=pos,k=1;j>0&&k<=strlen(s[i]+1);k++,j--)if (s[now][j]!=s[i][k]){flag=0;break;}}
		else {for (j=pos,k=strlen(s[i]+1);j<=strlen(s[now]+1)&&k>0;j++,k--)if(s[now][j]!=s[i][k]){flag=0;break;}}
		if (!flag) continue;
		if (d){
			if (j==0) f[now][pos][d]=min(f[now][pos][d],c[i]+dp(i,k,0));
			else f[now][pos][d]=min(f[now][pos][d],c[i]+dp(now,j,1));
		}else{
			if (k==0) f[now][pos][d]=min(f[now][pos][d],c[i]+dp(now,j,0));
			else f[now][pos][d]=min(f[now][pos][d],c[i]+dp(i,k,1));
		}
	}
	return f[now][pos][d];
}

int main(){
	read(n);
	for (int i=1;i<=n;i++)
	scanf("%s",s[i]+1),read(c[i]);
	ans=inf;
	for (int i=1;i<=n;i++)
	ans=min(ans,c[i]+dp(i,1,0));
	if (ans==inf) print(-1);
	else print(ans);
}

Measured memory_bytes: 3840
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,l,r,x=0,y=inf;
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    cin >> l >> r;
    x=max(x,l),y=min(y,r);
  }
  cout << max(0,y-x+1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#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()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const 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; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; 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> inline void add(T &a, int 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(10);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}


// https://atcoder.jp/contests/dp/submissions/3944283
int n;
ll c;
vector<ll> a, dp;

// Convex Hull Trick
ll A(int j) { return -2 * a[j]; }
ll B(int j) { return dp[j] + a[j] * a[j]; }
ll C(int i) { return c + a[i] * a[i]; }
ll f(int j, int x) { return A(j) * x + B(j); }
using pll = pair<ll, ll>;
struct CHT {
    deque<int> d;
    ll get(int x) {
        while (sz(d) >= 2) { // a, b,
            int a = d.front();
            d.pop_front();
            int b = d.front();
            if (f(a, x) <= f(b, x)) {
                d.push_front(a);
                break;
            }
        }
        return f(d[0], x);
    }
    void add(int x) { // z, y, x
        while (sz(d) >= 2) {
            int y = d.back();
            d.pop_back();
            int z = d.back();
            
            ll a1 = A(y), b1 = B(y), a2 = A(z), b2 = B(z), a3 = A(x), b3 = B(x);
            if ((b3 - b1) * (a2 - a1) >= (a1 - a3) * (b1 - b2)) {
                d.push_back(y);
                break;
            }
        }
        d.push_back(x);
    }
};



void solve() {
    cin >> n >> c;
    
    a.resize(n);
    cin >> a;
    dp.resize(n);
    dp[0] = 0;
    
    CHT d;
    d.add(0);
    
    rep3(i, 1, n) {
        dp[i] = d.get(a[i]) + C(i);
        d.add(i);
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 3968
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABuyingSweets solver = new ABuyingSweets();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABuyingSweets {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int x = in.nextInt();
            int y = in.nextInt();
            n -= x;
            int c = n / y;
            out.print(n - c * y);
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public void close() {
        }

    }
}
    


Measured memory_bytes: 21332
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EColorfulHats2 solver = new EColorfulHats2();
        solver.solve(1, in, out);
        out.close();
    }

    static class EColorfulHats2 {
        NumberTheory.Mod107 m = new NumberTheory.Mod107();

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.readIntArray(n);

            int[] count = new int[n + 1];
            count[0] = 3;
            long answer = 1;
            for (int x : a) {
                answer = m.mult(answer, count[x]);
                count[x]--;
                count[x + 1]++;
                if (answer == 0)
                    break;
            }

            out.println(answer);
        }

    }

    static class NumberTheory {
        public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
            ArrayList<Long> factorial = new ArrayList<>();
            ArrayList<Long> invFactorial = new ArrayList<>();

            public abstract long modulus();

            public Modulus() {
                super();
                factorial.add(1L);
                invFactorial.add(1L);
            }

            public long mult(long a, long b) {
                return (a * b) % modulus();
            }

        }

        public static class Mod107 extends NumberTheory.Modulus<NumberTheory.Mod107> {
            public long modulus() {
                return 1_000_000_007L;
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }
}



Measured memory_bytes: 35164