akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<set>
#include<map>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db double
#define M 1000000007
#define INF 1e18
#define pi 3.1415926535897932384626433832795028841971

#define MAX 100005

using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}

struct pll{
	lli x,y;
};
bool comp(pll a,pll b){
	if(a.x==b.x)	return a.y<b.y;
	else	return a.x<b.x;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	char ch;
	db aa,bb,cc;
	string s1,s2,s3,s4,str;
    lli i,j,k,a,b,n,c,m,sum=0,ans=0,temp,t,q;
    cin >> str;
    n=str.length();
    if(!(n&1))	cout << "No";
    else{
    	c=0;
    	for(i=0;i<n/2;i++){
    		if(str[i]==str[n-1-i])	c++;
    		else	break;
		}
		if(c!=n/2){
			cout << "No";return 0;
		}
		a=(n-1)/2;c=0;
		for(i=0;i<a/2;i++){
			if(str[i]==str[a-1-i])	c++;
			else	break;
		}
		if(c!=a/2){
			cout << "No";return 0;
		}
		a=n+3;a/=2;
		a--;c=0;
		for(i=a;i<(n-a)/2+a;i++){
			if(str[i]==str[n-1-i+a])	c++;
		}
		a=(n+3)/2;
		a=n-a+1;
		if(c!=a/2)	cout << "No";
		else	cout << "Yes";
	}
    
    
    return 0;
}

















/* UJJWAL KESHRI */

Measured memory_bytes: 256
N = gets.strip.to_i
A = gets.strip.split(' ').map(&:to_i)

money = 1000
stock = 0
(N-1).times do |i|
  if (A[i]<A[i+1])
    new_stock = (money/A[i]).to_i
    money -= new_stock*A[i]
    stock+=new_stock
  else
    money += stock*A[i]
    stock = 0
  end
end
money += stock*A[-1]
puts money

Measured memory_bytes: 14412
q, h, s, d = map(int, input().split())
n = int(input())
l_1 = min(min(q*4, h*2), s)
l_2 = min(l_1*2, d)
ans = (n // 2) * (l_2) + (n - ((n // 2) * 2)) * (l_1)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long int i,a,b,z=0;
	cin>>a>>b;
	for(i=a;i<=b;i++)
	{
		int n,x=0;
	    ostringstream str1; 
        str1 <<i; 
     	string s = str1.str(); 
		n=s.size();
		for(int j=0;j<n/2;j++)
		{
	
			if(s[j]==s[n-j-1])
			{
				x++;
			}
			else
			{
				break;
			}
		}
		if(x==n/2)
		{
			z++;
		}
	}
	cout<<z;
	
}

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

int main() {
  int N, K;
  std::cin >> N >> K;
  
  int now = 1;
  int i;
  for (i = 0; i < N; i++){
    if (now <= K){
      now *= 2;
    }
    else{
      now += K;
    }
  }
  std::cout << now << std::endl;
}


Measured memory_bytes: 3572
while 1:
    try:
        n,r = map(int,raw_input().split())
        if r == 1: cs = [int(raw_input())]
        else: cs = map(int,raw_input().split())
    except:
        break
    C = range(n)
    A,B,C = C[n/2:],C[:n/2],[]
    for i in range(r):
        c = cs[i]
        while A or B:
            C += A[:c] + B[:c]
            A = A[c:]
            B = B[c:]
        A,B,C = C[n/2:],C[:n/2],[]
    print A[-1]

Measured memory_bytes: 4232
#include <iostream>
using namespace std;
int	A(), main();

int main()
{
    return A();
}

int A() {
	int M, D;
	cin >> M >> D;
	
	int count = 0;

	for (int im = 1; im <= M; im++) {
		for (int id = 1; id <= D; id++) {
			int d10, d1;
			d10 = id / 10;
			d1 = id % 10;

			if (d10 <= 1 || d1 <= 1) continue;
			if (d10 * d1 == im) {
				//cout << im << "/" << id << " is SEKINOHI" << endl;
				count++;
			}
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdint.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <deque>

using namespace::std;

int ri()
{
	int x;
	scanf("%d", &x);

	return x;
}

int64_t ri64()
{
	int64_t x;
	scanf("%lld", &x);

	return x;
}

void wi(int x)
{
	printf("%d\n", x);
}

void wvi(vector<int> &v)
{
	for (int i = 0; i < v.size(); i++)
		printf("%d ", v[i]);
	printf("\n");
}

void dbg(string &str, int x)
{
	cout << str << ": ";
	wi(x);
}

void dbg(string &str, vector<int> &x)
{
	cout << str << ": ";
	wvi(x);
}

int main()
{
        int N = ri();
        int M = ri();

        int sum = 0;
        for (int i = 0; i < M; i++)
                sum += ri();

        if (sum > N)
                wi(-1);
        else
                wi(N - sum);

	return 0;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    
    // if(K==0){
    //     pr(max_element(ALL(A)));
    //     return 0;
    // }

    ll l = 0, r = MOD;
    while(r-l>1){
        ll mid = (l+r)/2;
        ll k = 0;
        REP(i, N){
            // double tmp = A[i];
            // ll wt = 0;
            // while(tmp>(double)mid){
            //     tmp/=2;
            //     k += 1<<wt;
            //     wt++;
            // }
            if(mid<A[i]){
                k += A[i]/mid;
            }
        }
        if(k <= K) r = mid;
        else l = mid;
    }
    pr(r);
}

Measured memory_bytes: 4780
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    string S;
    cin >> S;
    int ans = 700;
    REP(i, 3) {
        if (S[i] == 'o') { ans += 100; }
    }
    printAns(ans);
}


Measured memory_bytes: 256
N=int(input())
L=list(map(int,input().split()))

import itertools
p = itertools.combinations(L,3)
cnt=0
for v in p:
    if v[0]!=v[1] and v[1]!=v[2] and v[0]!=v[2]:
        if v[0] < v[1]+v[2] and v[1] < v[0]+v[2] and v[2] < v[0]+v[1]:
            cnt+=1
print(cnt)

Measured memory_bytes: 9204
#include<stdio.h>

int main()
{
	int m, f, r;
	int sum;
	
	while(1)
	{
		scanf("%d %d %d", &m, &f, &r);
		sum = m + f;

		if (m == -1 && f == -1 && r == -1) break;
		else if (m == -1 || f == -1) printf("F\n");
		else if (sum >= 80) printf("A\n");
		else if (sum >= 65) printf("B\n");
		else if (sum >= 50) printf("C\n");
		else if (sum >= 30) {
			if (r >= 50) printf("C\n");
			else printf("D\n");
		}
		else printf("F\n");
	}
	return 0;
}

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll dep(ll now){
	return now*(now-1)/2;
}
int main() {
	ll a,b;
	cin>>a>>b;
	cout << dep(a)+dep(b);
	// your code goes here
	return 0;
}

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

int main(int argc, char *argv[]) {
        double N = 0;
        double T = 0;
        double A = 0;
        std::vector<double> heights;

        std::cin >> N;
        std::cin >> T;
        std::cin >> A;
        double current_h;
        for (int i = 0; i < N; i++) {
                std::cin >> current_h;
                heights.push_back(current_h);
        }

        double min_temp_sub = INT_MAX;
        double temp_sub = 0;
        double ave_temp = 0;
        int answer = 0;
        for(int j = 0; j < N; j++) {
                ave_temp = T - ((heights[j] * 6) / 1000);
                temp_sub = ((A - ave_temp) > 0) ? (A - ave_temp) : ((A - ave_temp) * -1);
                if (temp_sub <= min_temp_sub) {
                        min_temp_sub = temp_sub;
                        answer = j + 1;
                }
        }

        std::cout << answer << std::endl;
        return 0;
}


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

int w[100];

int abs(int a,int b){
    if(a-b>0) return a-b;
    return b-a;
}

int main(void){
    int n;
    
    cin >> n;
    
    for(int i=0;i<n;i++){
        cin >> w[i];
    }
    
    int sumi,suma,ans=10000;
    
    for(int i=1;i<=100;i++){
        sumi=0,suma=0;
        for(int j=1;j<=n;j++){
            if(i>=j){
                sumi+=w[j-1];
            }
            else{
                suma+=w[j-1];
            }
        }
        ans=min(ans,abs(sumi,suma));
    }
    
    cout << ans << endl;
    
    return 0;
    
}


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

int main(){
    string s;
    cin >> s;
    stack <char> st;
    int ans=0;

    st.push(s[0]);
    for (int i = 1; i < s.length(); i++){
        if(st.size()>0){
            
            if(st.top() == s[i]){
                st.push(s[i]);
            }else{
                st.pop();
                ans +=2;
            }

        }else{
            st.push(s[i]);
        }
    }
    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 512
sa = list(str(input()))
sb = list(str(input()))
sc = list(str(input()))
pa, pb, pc = 0, -1, -1

read = sa[0]
while True:
  if read == 'a':
    pa += 1
    if pa == len(sa):
      print('A')
      break
    read = sa[pa]
  elif read == 'b':
    pb += 1
    if pb == len(sb):
      print('B')
      break
    read = sb[pb]
  else:
    pc += 1
    if pc == len(sc):
      print('C')
      break
    read = sc[pc]


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MAX = 200010;
int main() {
    int n; string x;
    cin >> n >> x;
    int pc = 0;
    rep(i, n) {
        if ((x[i] - '0')) pc++;
    }
    vector<int> base_0(n), base_1(n);

    base_0[n-1] = 1;
    base_1[n-1] = 1;
    int val_0 = 0;
    int val_1 = 0;
    for (int i=n-1;i>=0;i--) {
        val_0 += (x[i] - '0') * base_0[i];
        val_1 += (x[i] - '0') * base_1[i];
        val_0 %= (pc+1);
        if (pc != 1)
        val_1 %= (pc-1);
        if (i!=0) {
            base_0[i-1] = base_0[i]*2;
            base_0[i-1] %= (pc+1);
            base_1[i-1] = base_1[i]*2;
            if (pc != 1)
            base_1[i-1] %= (pc-1);
        }
    }
    //埋め込み
    vector<int> f(MAX, 0);
    f[0] = 0;
    rep(i, 200002) {
        f[i+1] = 1 + f[(i+1)%__builtin_popcount(i+1)];
    }
    //操作
    rep(i, n) {
        int num;
        if ((x[i]-'0')&&pc==1) {
            cout << 0 << endl;
            continue;
        }
        else if ((x[i]-'0')) num = (val_1 - base_1[i] + (pc-1))%(pc-1);
        else num = (val_0 + base_0[i])%(pc+1);
        //printf("num:%d\n", num);
        cout << f[num] + 1<< endl;
    }
}


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

int main(){
  int N;
  int t_0 = 0,x_0 = 0,y_0 = 0;
  int t_1,x_1,y_1;
  int t_d,x_d,y_d;

  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> t_1 >> x_1 >> y_1;
    t_d = abs(t_1 - t_0);
    x_d = abs(x_1 - x_0);
    y_d = abs(y_1 - y_0);

    if(t_d < x_d + y_d or t_d%2 != (x_d+y_d)%2){
      cout << "No" << endl;
      return 0;
    }
    t_0 = t_1;
    x_0 = x_1;
    y_0 = y_1;
  }

  cout << "Yes" << endl;
  return 0;

}

Measured memory_bytes: 256
board=[list(map(int,input().split())) for _ in range(3)]
flag=[[False]*3 for _ in range(3)]
n=int(input())
for _ in range(n):
  tmp=int(input())
  for i in range(3):
    for j in range(3):
      if board[i][j]==tmp:
        flag[i][j]=True
if flag[0][0]==True and flag[0][1]==True and flag[0][2]==True:
  print('Yes')
elif flag[1][0]==True and flag[1][1]==True and flag[1][2]==True:
  print('Yes')
elif flag[2][0]==True and flag[2][1]==True and flag[2][2]==True:
  print('Yes')
elif flag[0][0]==True and flag[1][0]==True and flag[2][0]==True:
  print('Yes')
elif flag[0][1]==True and flag[1][1]==True and flag[2][1]==True:
  print('Yes')
elif flag[0][2]==True and flag[1][2]==True and flag[2][2]==True:
  print('Yes')
elif flag[0][0]==True and flag[1][1]==True and flag[2][2]==True:
  print('Yes')
elif flag[0][2]==True and flag[1][1]==True and flag[2][0]==True:
  print('Yes')
else:
  print('No')

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

const int MAX = 100005;
const int MOD = 1000000007;
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;
}

int A[MAX];

int main() {
    int n, a, l, r;

    scanf("%d", &n);
    for (int i = 0; i <= n; i++) A[i] = 0;
    for (int i = 0; i <= n; i++) {
        scanf("%d", &a);
        if (A[a] == 0) A[a] = i + 1;
        else {
            l = min(A[a], i+1);
            r = max(A[a], i+1);
            break;
        }
    }

    COMinit();
    for (int i = 1; i <= n+1; i++) {
        long long ans;
        ans = (COM(n+1, i) - COM(l-1+n+1-r, i-1) + MOD) % MOD;
        printf("%lld\n", ans);
    }

    return 0;
}


Measured memory_bytes: 3968
if __name__ == '__main__':
    while True:
        # ??????????????\???
        deck = input()
        if deck == '-':
            break
        shuffle_count = int(input())
        positions = [int(input()) for _ in range(shuffle_count)]

        # ?????£??????????????????
        for p in positions:
            first_half = deck[:p]
            second_half = deck[p:]
            deck = second_half + first_half

        # ???????????????
        print(deck)

Measured memory_bytes: 7680
k, s = map(int, input().split())

count = 0
for x in range(k+1) :
    for y in range(k+1) :
      if ((s-x-y) <= k) and ((s-x-y) >= 0) :
            # print("{0} {1} {2}".format(x, y, s-x-y))
            count += 1

print(count)

Measured memory_bytes: 2940
MOD=1000000007
s = [int(x) if x!="?" else -1 for x in input()]
n=len(s)
count=0
dp=[[0 for j in range(13)] for i in range(n+1)]
dp[0][0]=1
for i in range(n):
  if count%50==0:
    for m in range(13):
      dp[i][m] =dp[i][m]%MOD
  
  for j in range(13):
    #　i+1番目が？のときは０〜９の可能性
    if s[i]==-1:
      count+=1
      for k in range(10):
        dp[i+1][(j*10+k)%13]+=dp[i][j]
        

    #  i+1番目が?じゃないとき
    else:
      dp[i+1][(j*10+s[i])%13]+=dp[i][j]

print(dp[n][5]%MOD)


Measured memory_bytes: 168264
n, x = map(int, input().split())
a = list(map(int, input().split()))
num = len(a)
a.sort(reverse=True)
for i in range(num):
    x -= a.pop()
    if x < 0:
        print(i)
        exit()
    if x == 0:
        print(i + 1)
        exit()
print(num - 1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    int s,w;
    cin >> s >> w;
    pf(s <= w? "unsafe":"safe" );
    return 0;
}



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

namespace Atc_0034
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            var X = Console.ReadLine();

            int cnt = 0;

            for (int i = 0; i < X.Length - 2; i++)
            {
                if (X.Substring(i, 3) == "ABC")
                {
                    cnt++;
                }

            }

            Console.WriteLine(cnt);

        }
    }
}


Measured memory_bytes: 25968
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
vvi a;
ll m;

double dist(int x,int y){
    double z = 0;
    for(int i=0;i<m;i++){
        z+=abs(a[x][i]-a[y][i])*abs(a[x][i]-a[y][i]);
    }
    return z;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,y,z;
    cin>>n>>m;
    a.assign(n,vi(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            double g = dist(i,j);
            g = sqrt(g);
            if(floor(g)==ceil(g))ans++;
        }
    }
    cout<<ans;
    
    

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a[1000], b[1000], c[1000], num, i = 0, flag[1000] = { 0 };

	scanf("%d", &num);

	while (i < num) {
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
		if ((a[i] * a[i] == b[i] * b[i] + c[i] * c[i]) || (b[i] * b[i] == a[i] * a[i] + c[i] * c[i]) || (c[i] * c[i] == b[i] * b[i] + a[i] * a[i]))
			flag[i] = 1;
		i++;
	}

	for (i = 0; i < num; i++) {
		if (flag[i] == 1) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		
	}

	return 0;


}

Measured memory_bytes: 592
import java.util.Scanner;

public class Main {
    static int ans;

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        double EPS = 1e-10;
        while (true) {
            // 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。 各データセットは以下のとおりです。
            //
            // 1行目 第1の多角形の頂点の数 m（整数）
            // 2行目 第1の多角形の頂点1の情報 v1（整数）
            // 3行目 第1の多角形の頂点2の情報 v2
            // ：
            // m行目 第1の多角形の頂点m-1の情報 vm-1
            // m+1行目 第2の多角形の頂点の数 n（整数）
            // m+2行目 第2の多角形の頂点1の情報 v1（整数）
            // m+3行目 第2の多角形の頂点2の情報 v2
            // ：
            // m+n行目 第2の多角形の頂点n-1の情報 vn-1
            int m = sc.nextInt();
            if (m == 0)
                break;
            int[] vs = new int[m - 1];
            for (int i = 0; i < m - 1; i++) {
                vs[i] = sc.nextInt();
            }
            int n = sc.nextInt();
            int[] us = new int[n - 1];
            for (int i = 0; i < n - 1; i++) {
                us[i] = sc.nextInt();
            }
            double a1 = calcArea(vs);
            double a2 = calcArea(us);
            if (Math.abs(a1 - a2) < EPS)
                System.out.println(0);
            else if (a1 > a2)
                System.out.println(1);
            else
                System.out.println(2);
        }
    }

    public static double calcArea(int vs[]) {
        double area = 0;
        int sum = 0;
        for (int i = 0; i < vs.length; i++) {
            area += Math.abs(Math.sin(Math.PI * vs[i] / 180)) / 2;
            sum += vs[i];
        }
        area += Math.abs(Math.sin(Math.PI * (360 - sum) / 180)) / 2;
        return area;
    }
}

Measured memory_bytes: 12000
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
d={}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1

t=[]
for i in d:
    t.append(d[i])
t.sort(reverse=True)
ans=len(t)
chk=0
#print(t)
for i in t:
    i-=1
    if chk==0:
        chk=i%2
    else:
        chk-=i%2
print(ans-chk)


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const ll MOD = 998244353;
const int MX = 1000010;

ll powmod(ll x, ll k) {
	ll res = 1;
	for (; k; k /= 2, x = x * x % MOD) {
		if (k & 1) {
			res = res * x % MOD;
		}
	}
	return res;
}

ll inv[MX], fact[MX], ifact[MX];

void init() {
    inv[1] = 1;
    for (int i = 2; i < MX; ++i) {
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
    }
    fact[0] = ifact[0] = 1;
    for (int i = 1; i < MX; ++i) {
        fact[i] = fact[i-1] * i % MOD;
        ifact[i] = ifact[i-1] * inv[i] % MOD;
    }
}

ll comb(int n, int r) {
    if (n < 0 || r < 0 || r > n) return 0;
    return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

ll slow(int N, const vi& A) {
	ll s = 0;
	rep(i, N) {
		rep(j, i) {
			ll d = __gcd(A[i], A[j]);
			s += (ll)A[i] / d * A[j];
			s %= MOD;
		}
	}
	return s;
}

int main() {
	init();

	int N; cin >> N;
	vi A(N); rep(i, N) cin >> A[i];

	//dump(slow(N, A));
	
	vi cnt(MX);
	rep(i, N) ++cnt[A[i]];

	vector<ll> sum(MX);

	ll ans = 0;

	for (int i = MX-1; i >= 1; --i) {
		ll t = 0;
		for (int j = i; j < MX; j += i) {
			t += (ll)cnt[j] * j;
			t %= MOD;
		}

		t = t * t % MOD;

		for (int j = i * 2; j < MX; j += i) {
			sum[i] = (sum[i] + MOD - sum[j]) % MOD;
		}

		sum[i] = (sum[i] + t) % MOD;
		ans = (ans + sum[i] * inv[i]) % MOD;

	}

	rep(i, N) ans = (ans + MOD - A[i]) % MOD;
	ans = ans * inv[2] % MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 36224
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int alpha[26];
	rep(i,26)alpha[i]=0;
	string s;
	cin>>s;
	rep(i,s.size())alpha[(int)(s[i]-'a')]++;
	bool check=true;
	rep(i,26)if(alpha[i]%2==1)check=false;
	cout<<((check)?"Yes":"No")<<endl;
	return 0;
}

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


int main()
{
    int len = 0;
    int cnt = 0;
    char s[100];
    scanf("%s", s);
    len = strlen(s);
    int i = 0;
    int j = len - 1;
    while (i < j)
    {
        if(s[i++] != s[j--]){
            cnt++;
        }
    }
    printf("%d\n", cnt);
    

    return 0;
}



Measured memory_bytes: 128
import collections
n=int(input())
A=[int(i) for i in input().split()]
AA=collections.Counter(A)
AK=AA.keys()
AV=AA.values()

ans=True
if n%3!=0:
  ans=False
else:
  nn=n//3
  if len(AK)>3:
    ans=False
  elif len(AK)==3:
    a,b,c=AK
    if AA[a]!=nn or AA[b]!=nn or AA[c]!=nn:
      ans=False
    else:
      if a^b!=c or b^c!=a:
        ans=False
  elif len(AK)==2:
    a,b=AK
    if a*b!=0:
      ans=False
    else:
      if a<b:
        a,b=b,a
      if AA[a]!=2*nn or AA[b]!=nn:
        ans=False
  else:
    for a in AK:
      if a!=0:
        ans=False
if len(AK)==1:
  for a in AK:
    if a==0:
      ans=True
print("Yes" if ans==True else "No")

Measured memory_bytes: 14468
# input
n, m, d = map(int, input().split())

if (n - d) < (1 + d):
    ex =(2 * (n - d)) / (n ** 2)
    ans = ex * (m - 1)
else:
    ex = 2 * (n - d) / (n ** 2)
    if d == 0:
        ans = ex * (m - 1) / 2
    else:
        ans = ex * (m - 1)

print(ans)


Measured memory_bytes: 3060
#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)

int main(void){

	while(1){
		int d,e;
		cin>>d>>e;
		if(d==0) break;
		
		double mindif = 1000000.0;
		REP(i,d+1){
			double x = i, y = d-i;
			double dif = abs(sqrt((x)*(x)+(y)*(y)) - (double)e);
			if(dif < mindif) mindif = dif;
		}

		cout<<mindif<<endl;
	}

	return 0;
}



Measured memory_bytes: 3188
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

void hora(int tc) {
	string s;
	int lo = -1, hi = -1;
	cin>>s;
	if(s.size() == 2) {
		if(s[0] == s[1]) lo = 1, hi = 2;
	}
	else {
		for(int i = 0;i < s.size() - 2;i++) {
			if(s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) lo = i + 1, hi = i + 3;
		}
	}
	cout<<lo<<" "<<hi<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




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

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
    ll i, j, k;
    ll a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
map<int,int> memo;
int main() {
  int N;
  cin>>N;
  int64_t min=9223372036854775806;
  for(int i=1;i<N+1;i++){
    int s;
    cin>>s;
    memo[i]=s;
  }
  for(int i=-1;i<100;i++){
    int64_t S1=0;
    for(int j=0;j<N;j++){
      S1=S1+(memo[j+1]-i-1)*(memo[j+1]-i-1);
    }
    if(S1<min){
      min=S1;
    }
  }
  
  
  
  cout<<min<<endl;

}


Measured memory_bytes: 256
import numpy as np
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

S = int(input())
T = S**0.5
# 平方数でない
if int(T)**2 != S:
    T = int(T)+1
    U = int(T**2 - S)
    dv = make_divisors(U)
    rootU = int(U**0.5)
    idx = 0
    a = 10**9
    for i in range(len(dv)):
        if abs(dv[i]-rootU) <= a:
            a = abs(dv[i]-rootU)
            idx = i
    a = dv[idx]
    b = int(U/a)
    res = ['0', '0', str(T), str(a), str(b), str(T)]
    print(' '.join(res))
else:
    T = int(T)
    res = ['0', '0', str(T), '0', '0', str(T)]
    print(' '.join(res))


Measured memory_bytes: 12516
import java.util.Scanner;
public class Main{
	Scanner sc=new Scanner(System.in);
	int n,m;
	
	void a(){
		for(int i=0; i<4; i++){
			n=sc.nextInt();
			m=sc.nextInt();
		
		
			if(n==1){
				System.out.println(6000*m);
			}else if(n==2){
				System.out.println(4000*m);
			}else if(n==3){
				System.out.println(3000*m);
			}else if(n==4){
				System.out.println(2000*m);
			}
		}
	}
	
	public static void main(String[]agrs){
		new Main().a();
	}
}
		

Measured memory_bytes: 17164
#include<bits/stdc++.h>
using namespace std;
int main(){
   long long int n,m,ans;
  cin>>n>>m;
  if(n*2>=m){//mにそろえる n余り
    cout<<m/2<<endl;
  }else{//nにそろえる mあまり
    ans=n+((m-n*2)/4);
    cout<<ans<<endl;
  }
}

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

S = input()
key = 'keyence'
K = []

if key in S:
    print('YES')
    exit()


for i in range(len(key)+1):
    K.append([key[:i],key[i:]])

for i in range(len(K)):
    if K[i][0] in S and K[i][1] in S:
        if S[0] == 'k' and S[-1] == 'e':
            print('YES')
            exit()
print('NO')




Measured memory_bytes: 3064
import java.util.Scanner;


public class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int y = sc.nextInt();
	sc.close();
	System.out.printf("%d %d %f\n",(int)x/y, x%y, x/(double)y);
}
}

Measured memory_bytes: 17340
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n;
string s;
int a[11];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
   cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>s;
  if(s[0]==s[1] && s[1]==s[2])cout<<"Yes"<<endl;
  else if(s[1]==s[2] && s[2]==s[3])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    ll N = s.size();
    ll ans = 0;
    rep(i, 0, N){
        ll tmp = 0;
        rep(j, i, N){
            if(s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') tmp++;
            else break;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
	$N=+fgets(STDIN);
	$A=explode(' ',fgets(STDIN));
	$c[0]=3;
	$s=1;
	$m=10**9+7;
	for($i=0;$i<$N;$i++)
	{
		$s=$s*$c[+$A[$i]]--%$m;
		$c[$A[$i]+1]++;
	}
	echo $s;

Measured memory_bytes: 35632
N = int(input())
A = list(map(int, input().split()))
M = max(A) + 1

counts = [0 for _ in range(M)]
for a in A:
  counts[a] += 1

integers = [1 for _ in range(M)]
integers[0] = 0
integers[1] = 0
max_count = 0
for i in range(M):
   if integers[i] >= 1:
    count = 0
    for j in range(i,M,i):
      count += counts[j]
      integers[j] = 0
    max_count = max(max_count,count)

if max_count == N:
  answer = 'not coprime'
elif max_count >= 2:
  answer = 'setwise coprime'
else:
  answer = 'pairwise coprime'

print(answer)

Measured memory_bytes: 217704
n = int(input())
H = list(map(int, input().split()))
ok = True
m = 0
for h in H:
    if h-1 >= m:
        m = h-1
    elif h >= m:
        m = h
    else:
        ok = False
        break
if ok:
    print('Yes')
else:
    print('No')


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

int main()
{
int n;
cin>>n;
int a,b,c;
int pr=0,pr2=0;
long long tot=0;
     for(int i=0;i<n;i++)
{
  cin>>a>>b>>c;
  long long pre_tot=tot;
   tot= (a);
   int min_tim= abs(pr-b)+abs(pr2-c);
  pre_tot+=min_tim;
  
   if((tot-pre_tot)%2 || tot<pre_tot ){cout<<"No";return 0;}
   pr=b,pr2=c;
}
cout<<"Yes";
     return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n,k;
  scanf("%d", &n);
  char s[n+1];
  scanf("%s %d", s, &k);
  for (int i = 0; i < n; i++) {
    if (s[i] != s[k-1]) {
      s[i] = '*';
    }
  }
  printf("%s\n", s);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int h1,h2,m1,m2,k;
    
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    if ((h2-h1)*60 + m2-m1 - k >= 0){
        cout << (h2-h1)*60 + m2-m1 - k << endl;
    }
    else {
        cout << 0 << endl;
    }
    
}


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

using namespace std;

#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;


int main() {
    fast;
    cin.tie(0);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w" , stdout);
#endif*/
    lld j, i, n;
    cin >> n;
    lld a[n];
    for (i = 0; i < n; i++) {
        cin >> a[i];
    }
    lld p[n], q[n], cnt = 0;
    map<lld, lld> mp;
    for (i = 0; i < n; i++) {
        p[i] = a[i] + i;
        q[i] = i - a[i];
        mp[q[i]]++;
    }
    for (i = 0; i < n; i++) {
        cnt += mp[p[i]];
    }
    cout << cnt << endl;
}

Measured memory_bytes: 31052
import java.util.*;

//update 2019/12/13

public class Main{

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    long a = nextLong();
    long b = nextLong();

    long gcdab = (long)euku((double)a,(double)b);

    long lcm = a*b/gcdab;

      System.out.println(lcm);

  }

  public static double euku(double a,double b){

    if(a%b!=0){
      return euku(b,a%b);
    }
    else{
      return b;
    }

  }

  static String next(){
    return sc.next();
  }

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

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char aaa){
    return aaa - 48;
  }

  public static int maxInt(int[] a,int lng){
    int max=a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }

  public static int minInt(int[] a,int lng){
    int min=a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }

  public static long maxLong(long[] a,int lng){
    long max=a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }

  public static long minLong(long[] a,int lng){
    long min=a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }

}


Measured memory_bytes: 23252
# include <stdio.h>

# include <math.h>

int main (void)
{
	double a;//the empty sockets of a power strips
	double b;//the requirment of the empty sockets
	double n;//the min of the power strips
	double t;//temporary varible

	scanf("%lf%lf", &a, &b);

	n = (b-1)/(a-1);

	t = n;

	n = floor(n);

	if(t>n)
		n = n+1;

	printf("%.0lf", n);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n, a, b;
	cin >> n >> a >> b;
	Array x(n, 0);
	REP(i, n) cin >> x[i];

	ll ans = 0;
	REP(i, n-1) {
		ll cost = (x[i + 1] - x[i])*a;
		chmin(cost, b);
		ans += cost;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

typedef struct _dice {
	int label[6];
	int sum;
	int eor;
	int min;
	int max;
} DICE, *PDICE;

int rotation[6][5] =
	{
		{ /* N */ 1, 2, 6, 5},
		{ /* S */ 1, 5, 6, 2},
		{ /* E */ 1, 4, 6, 3},
		{ /* W */ 1, 3, 6, 4},
		{ /* L */ 2, 3, 5, 4},
		{ /* R */ 2, 4, 5, 3}
	};

int RN[] = { 'N', 'S', 'E', 'W', 'L', 'R' };

int aid(int c) {
	switch (c) {
	case 'N': return 0;
	case 'S': return 1;
	case 'E': return 2;
	case 'W': return 3;
	case 'L': return 4;
	case 'R': return 5;
	default: return -1;
	}
}

void rotate(PDICE dice, int c) {
	int a = aid(c);
	int t, i;
	
	if (a < 0) {
		return;
	}
	
	t = dice->label[rotation[a][0] - 1];
	for (i = 0; i < 3; i++) {
		dice->label[rotation[a][i] - 1] =
			dice->label[rotation[a][i + 1] - 1];
	}
	dice->label[rotation[a][3] - 1] = t;
}

void fit(PDICE dice, int p, int n) {
	int i;
	for (i = 0; i < 4; i++) {
		if (dice->label[p] == n) {
			return;
		}
		rotate(dice, 'N');
	}
	for (i = 0; i < 4; i++) {
		if (dice->label[p] == n) {
			return;
		}
		rotate(dice, 'W');
	}
	for (i = 0; i < 4; i++) {
		if (dice->label[p] == n) {
			return;
		}
		rotate(dice, 'L');
	}
}

int matchDice(PDICE dice1, PDICE dice2) {
	int i;
	for (i = 0; i < 6; i++) {
		if (dice1->label[i] != dice2->label[i]) {
			return 0;
		}
	}
	return -1;
}

int matchDiceTurn(DICE dice1, DICE dice2, int c) {
	int i;
	for (i = 0; i < 4; i++) {
		if (matchDice(&dice1, &dice2)) {
			return 1;
		}
		rotate(&dice1, c);
	}
	return 0;
}

int isSameDice(DICE dice1, DICE dice2) {
	DICE temp;
	int i;
	if (dice1.sum != dice2.sum) {
		return 0;
	}
	if (dice1.eor != dice2.eor) {
		return 0;
	}
	if (dice1.min != dice2.min) {
		return 0;
	}
	if (dice1.max != dice2.max) {
		return 0;
	}
	if (matchDiceTurn(dice1, dice2, 'L')) {
		return 1;
	}
	temp = dice1;
	rotate(&temp, 'N');
	rotate(&temp, 'N');
	if (matchDiceTurn(temp, dice2, 'L')) {
		return 1;
	}
	for (i = 0; i < 4; i++) {
		temp = dice1;
		rotate(&temp, RN[i]);
		if (matchDiceTurn(temp, dice2, 'L')) {
			return 1;
		}
	}
	return 0;
}

int main(void) {
	DICE dice[100];
	int i, j;
	int n;
	int f = 1;
	
	scanf("%d", &n);
	
	for (j = 0; j < n; j++) {
		dice[j].sum = 0;
		dice[j].eor = 0;
		dice[j].min = 100;
		dice[j].max = 0;
		for (i = 0; i < 6; i++) {
			scanf("%d", &dice[j].label[i]);
			dice[j].sum += dice[j].label[i];
			dice[j].eor ^= dice[j].label[i];
			if (dice[j].label[i] > dice[j].max) {
				dice[j].max = dice[j].label[i];
			}
			if (dice[j].label[i] < dice[j].min) {
				dice[j].min = dice[j].label[i];
			}
		}
		fit(&dice[j], 0, dice[j].max);
	}
	
	for (i = 0; f && i < n - 1; i++) {
		for (j = i + 1; f && j < n; j++) {
			if (isSameDice(dice[i], dice[j])) {
				f = 0;
			}
		}
	}	
	
	if (f) {
		puts("Yes");
	} else {
		puts("No");
	}

	return 0;
}

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

using namespace std;

#define F 		first
#define S 		second
#define ll 		long long
#define ld 		long double
#define pii		pair<int, int>
#define vi 		vector<int>
#define mii 	map<int, int>
#define umii 	unordered_map<int, int>
#define pb		push_back
#define mk		make_pair
#define all(a)	a.begin(), a.end()
#define ask(x) 	cerr << #x << " = " << x << "\n";
#define INF 	1000000007
#define hell 	998244353

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ld a, b;
	cin >> a >> b;

	cout << fixed << setprecision(0) << floor(a * b);	

	return 0;
}

Measured memory_bytes: 3812
from collections import deque
import sys
sys.setrecursionlimit(10**8)

def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    Ch -= 1
    Cw -= 1
    Dh -= 1
    Dw -= 1
    S = [list(input()) for _ in range(H)]
    visited = [[False] * W for _ in range(H)]
    cnt = [[float('inf')] * W for _ in range(H)]
    dh = [1,0,-1,0]
    dw = [0,1,0,-1]
    visited[Ch][Cw] = True
    cnt[Ch][Cw] = 0
    Q = deque([[Ch,Cw]])
    while Q:
        h, w = Q.popleft()
        c = cnt[h][w]
        if h == Dh and w == Dw:
            break
        for i in range(4):
            nh = h + dh[i]
            nw = w + dw[i]
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.':
                if cnt[nh][nw] > c:
                    cnt[nh][nw] = c
                    Q.appendleft([nh,nw])
        nc = c + 1
        for j in range(-2,3):
            for k in range(-2,3):
                nh = h + j
                nw = w + k
                if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.':
                    if cnt[nh][nw] > nc:
                        cnt[nh][nw] = nc
                        Q.append([nh,nw])

    if cnt[Dh][Dw] == float('inf'):
        print(-1)
    else:
        print(cnt[Dh][Dw])




if __name__ == "__main__":
    main()


Measured memory_bytes: 171476
l,d=0,0
w,h,n=map(int,input().split())
for _ in [0]*n:
    x,y,a=map(int,input().split())
    if a==1 and l<x:l=x
    elif a==2 and w>x:w=x
    elif a==3 and d<y:d=y
    elif a==4 and h>y:h=y
if w<=l or h<=d:print(0)
else:print((w-l)*(h-d))

Measured memory_bytes: 3064
import Data.List
import Control.Applicative

main = do
  p <- getContents
  let n = read $ head $ words $ head $ lines p :: Int
      m = read $ last $ words $ head $ lines p :: Int
      list  = tail $ lines p -- list !! i = S_i
      sorted = sort list
      result = concat sorted
  putStr $ result


Measured memory_bytes: 1404
n, k = map(int,input().split())
d = list(map(str,input().split()))

ans = 0
for i in range(n,100000):
    s = str(i)
    pay = True
    for j in range(len(s)):
        if s[j] in d:
            pay = False
            break
    if pay:
        ans = i
        break
print(ans)

Measured memory_bytes: 39536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	const int inf = 1000000000;
	int h, n;
	cin >> h >> n;
	vector<int> dp(h + 1, inf);
	dp[0] = 0;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		rep(j, h) {
			int k = min(j + a, h);
			dp[k] = min(dp[k], dp[j] + b);
		}
	}

	dunk(dp[h]);

	return 0;
}

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  writeln((n+110)/111*111);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> l(n),r(n);
    int ans = 1;
    rep(i,n) cin >> a[i];
    rep(i,n-1) l[i+1] = gcd(l[i],a[i]);
    for(int i=n-1;i>=1;i--){
        r[i-1]=gcd(r[i],a[i]);
    }
    rep(i,n) ans=max(ans,gcd(l[i],r[i]));
    cout << ans << endl;
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long t = 1L;
        for (int i = 1; i <= n; i++) {
            t *= i;
            t %= (Math.pow(10, 9) + 7);
        }
        System.out.println((int)(t % (Math.pow(10, 9) + 7)));
    }

}


Measured memory_bytes: 21588
s=chomp(readline())
t=chomp(readline())
N=length(s)
nxt=zeros(Int,N,26)
nownxt=-ones(Int,26)
for i=2*N:-1:1
	if i<=N
		for j=1:26
			nxt[i,j]=nownxt[j]
		end
	end
	nownxt[Int(s[mod1(i,N)])-96]=i-1
end
p=-1
ans=0
for c=t
	q=0
	if p<0
		q=nownxt[Int(c)-96]
	else
		q=nxt[p+1,Int(c)-96]
	end
	if q<0
		println(-1)
		exit()
	end
	ans+=q-p
	p=q%N
end
println(ans)


Measured memory_bytes: 154136