akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
#define mod (long)(998244353)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
#define long long long
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int N, W;
vector<int> w;
vector<long> v;

long dp[102][102030];

long knapsack(int now, int weight){
    if(weight > W){
        return -1e18;
    }else if(now == N){
        return 0;
    }else if(dp[now][weight] != -1){
        return dp[now][weight];
    }
    return dp[now][weight] = max(knapsack(now + 1, weight), knapsack(now + 1, weight + w[now]) + v[now]);
}

int main(){
    cin >> N >> W;
    w.resize(N);
    v.resize(N);
    for(int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << knapsack(0, 0) << endl;
}


Measured memory_bytes: 81536
#include<bits/stdc++.h>
using namespace std;
int n,a[100002];
long long ans=0,tmp=0;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]) tmp+=a[i];
		else{
			ans+=tmp/2;
			tmp=0;
		}
	}
	ans+=tmp/2;
	printf("%lld\n",ans);
//	cout<<clock()*1.0/CLOCKS_PER_SEC<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

const long long int MOD = 1e9 + 7;

int make_rooted_tree(std::vector<std::vector<long long int> > &G, /*long long int N,*/ std::vector<long long int> &visited, long long int root, std::vector<std::vector<long long int> > &G_rooted);

long long int fill_count(std::vector<std::vector<long long int> > &G_rooted, long long int index, long long int color, std::vector<std::vector<long long int> > &count);

int main(){
  
  // read problem
  long long int N, tmp_x, tmp_y;
  scanf("%lld", &N);
  
  std::vector<std::vector<long long int> > G(N);
  for(long long int i = 0; i < N-1; i++){
    scanf("%lld%lld", &tmp_x, &tmp_y);
    G[tmp_x-1].push_back(tmp_y-1);
    G[tmp_y-1].push_back(tmp_x-1);
  }
  
  // make rooted tree
  std::vector<long long int> visited(N);
  std::vector<std::vector<long long int> > G_rooted(N);
  make_rooted_tree(G, visited, 0, G_rooted);
 
  /*for(long long int i = 0; i < N; i++){
    std::cerr << "i:" << i << " to: ";
    for(long long int j = 0; j < G_rooted[i].size(); j++){
      std::cerr << G_rooted[i][j] << " ";
    }std::cerr << std::endl;
  }*/
  
  // solve problem
  std::vector<std::vector<long long int> > count(N);
  for(long long int i = 0; i < N; i++){
    count[i].push_back(0);
    count[i].push_back(0);
  }
  
  fill_count(G_rooted, 0, 0, count);
  fill_count(G_rooted, 0, 1, count);
  
  std::cout << (count[0][0] + count[0][1])%MOD << std::endl;
  
  return 0;
}

int make_rooted_tree(std::vector<std::vector<long long int> > &G, /*long long int N,*/ std::vector<long long int> &visited, long long int root, std::vector<std::vector<long long int> > &G_rooted){
  
  // the root is visited
  visited[root] = 1;
  for(long long int i = 0; i < G[root].size(); i++){
    // the point connected to i is not visited yet
    if(visited[G[root][i]] == 0){
      G_rooted[root].push_back(G[root][i]);
      make_rooted_tree(G, visited, G[root][i], G_rooted);
    }
  }
  return 0;
}

long long int fill_count(std::vector<std::vector<long long int> > &G_rooted, long long int index, long long int color, std::vector<std::vector<long long int> > &count){
  // if already calculated
  if(count[index][color] > 0){
    return count[index][color];
  }
  // if the answer have to be newly calculated
  else{
    // if the node has no child
    if(G_rooted[index].size() == 0){
      count[index][color] = 1;
      return 1;
    }
    // if the node has child
    else if(color == 0){
      long long int ans = 1;
      for(long long int i = 0; i < G_rooted[index].size(); i++){
        ans *= (fill_count(G_rooted, G_rooted[index][i], 0, count) + fill_count(G_rooted, G_rooted[index][i], 1, count));
        ans %= MOD;
      }
      count[index][color] = ans;
      return ans;
    }
    else{// if(color == 1)
      long long int ans = 1;
      for(long long int i = 0; i < G_rooted[index].size(); i++){
        ans *= fill_count(G_rooted, G_rooted[index][i], 0, count);
        ans %= MOD;
      }
      count[index][color] = ans;
      return ans;
    }
  }
}


Measured memory_bytes: 24448
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main() //input->compute->output
{
        int N, M;
        cin >> N >> M;
        vector<string> A(N), B(M);
        rep(i, N)
        {
                cin >> A[i];
        }

        rep(i, M)
        {
                cin >> B[i];
        }

        int c, r;
        bool flag = false;

        rep(h, N - M + 1)
        {
                rep(i, N - M + 1)
                {
                        if (A[h].substr(i, M) == B[0])
                        {
                                r = h;
                                c = i;
                                int m = 0;
                                for (int k = r; k < r + M; k++)
                                {
                                        if (A[k].substr(c, M) == B[m])
                                        {
                                                m++;
                                        }
                                }
                                if (m == M)
                                {
                                        cout << "Yes" << endl;
                                        return 0;
                                }
                        }
                }
        }

        cout << "No" << endl;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n, i, max, min;
    long long sum;
    cin >> n;
    int retu[n];
    sum = 0;
    for (i=0; i<n; i++){
        cin >> retu[i]; 
        sum += retu[i];
    }
    max = retu[0];
    min = retu[0];
    for (i=0; i<n; i++){
        if (retu[i]>max){
            max = retu[i];
        }
        if (retu[i]<min){
            min = retu[i];
        }
    }
    cout << min << " " << max <<" " << sum << endl;
    return 0;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> c(h);
    for (int i = 0; i < h; i++) {
        cin >> c.at(i);
    }

    for (int i = 0; i < h; i++) {
        cout << c.at(i) << endl;
        cout << c.at(i) << endl;
    }
}   

Measured memory_bytes: 256
H, W = map(int, input().split())

if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()
if H == 1 or W == 1:
    print(1)
    exit()
ans = 1 << 30
w = W//2
for h in range(1, H+1):
    s1 = w*h
    s2 = (W-w)*h
    s3 = W*(H-h)
    ans = min(ans, max(s1,s2,s3)-min(s1,s2,s3))
W, H = H, W
w = W//2
for h in range(1, H+1):
    s1 = w*h
    s2 = (W-w)*h
    s3 = W*(H-h)
    ans = min(ans, max(s1,s2,s3)-min(s1,s2,s3))
ans = min(ans, H, W)
print(ans)

Measured memory_bytes: 9164
S = gets.chomp
T = gets.chomp

start = Array.new(26) { -1 }
goal = Array.new(26) { -1 }

impossibble = false
0.upto(S.size - 1) do |i|
  s = S[i].ord - 'a'.ord
  t = T[i].ord - 'a'.ord

  if start[s] != -1 || goal[t] != -1
    if start[s] != t || goal[t] != s
      impossibble = true
      break
    end
  end

  start[s] = t
  goal[t] = s
end

if impossibble
  puts 'No'
else
  puts 'Yes'
end


Measured memory_bytes: 4348
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[0]*n
def calc(n,k,h,dp):
    for i in range(1,n):
        dp[i]=min([dp[j] + abs(h[i]-h[j]) for j in range(max(i-k,0),i)])

calc(n,k,h,dp)
print(dp[-1])


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

long *alp[26];

int main(void) {

  char s[100001],t[100001];
  scanf("%s %s", s, t);
  long s_length = strlen(s);
  long t_length = strlen(t);
  long alp_s[26];
  for (long i = 0; i < 26; i++) {
    alp_s[i] = 0;
  }
  long num;
  for (long i = 0; i < s_length; i++) {
    num = s[i]-'a';
    alp[num] = realloc(alp[num], sizeof(long)*(alp_s[num]+1));
    alp[num][alp_s[num]] = i;
    alp_s[num]++;
  }
  long check[26];
  long set = 0;
  long characters;
  long cur = 0;
  long max;
  long start,end,center;
  while (cur != t_length) {
    for (long i = 0; i < 26; i++) {
      check[i] = 0;
    }
    max = -1;
    for (long i = cur; i < t_length; i++) {
      num = t[i]-'a';
      if (alp_s[num] == 0) {
        printf("-1\n");
        return 0;
      }
      if (check[num] == alp_s[num]) {
        set++;
        cur = i;
        break;
      }
      if (alp[num][alp_s[num]-1] < max) {
        set++;
        cur = i;
        break;
      }
      if (alp[num][check[num]] > max) {
        max = alp[num][check[num]];
        check[num]++;
      } else {
        start = check[num];
        end = alp_s[num]-1;
        while (start+1 != end) {
          center = (start+end)/2;
          if (alp[num][center] > max) {
            end = center;
          } else {
            start = center;
          }
        }
        max = alp[num][end];
        check[num] = end+1;
      }
      if (i == t_length-1) {
        cur = t_length;
        characters = max+1;
      }
    }
  }
  long ans = set*s_length+characters;
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 1792
import java.io.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        long A, B, K;
        A = Long.parseLong (arr[0]);
        B = Long.parseLong (arr[1]);
        K = Long.parseLong (arr[2]);
        System.out.println (
            String.valueOf (A - Math.min (A, K)) + " " +
            String.valueOf (B - Math.min (B, K - Math.min (A, K))));
        return;
    }
}

Measured memory_bytes: 36840
// 2020 0404 161 D Lunlun Number
//
#include <algorithm>
#include <complex>
#include <string>
#include <deque>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <queue>
#include <utility>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main() {
    // K = E5 -> 3.2E9 で愚直に全列挙はむり
    int K;
    cin >> K;
    vector<ll> a;
    for(int i = 1; i <= 9; ++i) a.push_back(i);
    while(1){
        if (K <= a.size()) {
            cout << a[K-1] << endl;
            return 0;
        }
        K -= a.size();
        vector<ll> old;
        swap(old, a);
        for(ll x : old) {
            for (int i = -1; i <= 1; i++){
                int d = x % 10 + i;
                // dの1の位に-1, 0, 1をたしたものをおしりに付け足す
                // 33 -> 332, 333, 334
                if(d < 0 || d > 9) continue;
                ll nx = x*10 + d;
                a.push_back(nx);
            }
        }
    }


    return 0;
}

Measured memory_bytes: 1712
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            if(h==0 && w ==0) break;
           
            for(int x =0;x<w;x++){
                System.out.print("#");
            }
            System.out.println("");
            for(int y=1;y<h-1;y++){
                System.out.print("#");
                for(int x = 1;x<w-1;x++){
                    System.out.print(".");
                }
                System.out.print("#");
                System.out.println("");
            }
            for(int x =0;x<w;x++){
                System.out.print("#");
            }
            System.out.println("");
            System.out.println("");
        }
        sc.close();    
    }
}



Measured memory_bytes: 32736
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int main(){

	int c1,c2,c3;
	bool cards[10+1];	

	while(~scanf("%d %d %d",&c1,&c2,&c3)){
		fill(cards,cards+11,true);
		cards[c1]=false;
		cards[c2]=false;
		cards[c3]=false;

		int total=0;
		int c=0;
		for(int i=1;i<=10;i++){
			if(cards[i]){
				total++;
				if(c1+c2+i <= 20){
					c++;
				}
			}
		}

		if(c*2 >= total){
			cout << "YES" << endl;
		}

		else{
			cout << "NO" << endl;
		}


	}
}

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

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    ll a = inputValue();
    ll b = inputValue();
    ll c = inputValue();
    ll d1 = 4 * a * b;
    ll d2 = (c - a - b)*(c - a - b);
    if(d1<d2 && c >= (a+b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

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

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

  string n;
  cin >> n;

  cout << "ABC" + n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string s;
  cin>>s;
  long long int ans=9999999999;
  for(long long int i=0; i<s.length()-2; i++){
    long long int hoge=(s[i]-'0')*100+(s[i+1]-'0')*10+s[i+2]-'0';
    ans=min(ans,abs(753-hoge));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();        
        int[] a = r.ii();
        int N = a[0],
            M = a[1];        
        int[][] data = new int[M][3];
        HashMap<Integer, ArrayList<int[]>> prefs = new HashMap<>();
        for(int[] iData : data){
            int[] PY = r.ii();
            int P = PY[0];
            iData[0] = P;
            iData[1] = PY[1];
            if(!prefs.containsKey(P)){
                prefs.put(P, new ArrayList<>());
            }
            prefs.get(P).add(iData);
        }
        for(ArrayList<int[]> pref : prefs.values()){
            pref.sort(Comparator.comparing(iData->iData[1]));
            int i = 1;
            for(int[] iData : pref) iData[2] = i++;
        }                
        for(int[] iData : data) System.out.printf("%06d%06d\n", iData[0], iData[2]);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }

        String[] ss() throws IOException{
            return readLine().split(" ");
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
    }
}

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

using namespace std;

typedef unsigned long long ll;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define II pair <int,int>

const int N=2e5+10;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t;
    cin >> t;
    set <string> s;
    FOR(i,1,t) {
        string h; cin >> h;
        s.insert(h);
    }
    cout << s.size();
}
    

Measured memory_bytes: 19180
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]

a.sort()

res = 0
c = 1
for i in range(1,n):
    if a[i] == a[i-1]:
        c += 1
        continue
    res += c%2
    c = 1
res += c%2
print(res)

Measured memory_bytes: 7388
import java.util.*;
 public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
      	int N = scanner.nextInt();//会社に何人いるか
      
      //List <Integer> n = new ArrayList<Integer>();//各社員の部下の数を格納
      List <Integer> a = new ArrayList <Integer>();//各社員の上司番号を格納
      int n[] = new int[N];
      for(int i=0; i<N; i++){
      //n.add(0);//各社員の部下の数の表記を一旦0と置く...[0,0,0,0,0]
        n[i] = 0;
      }
      
      for(int i=0; i<N-1; i++){
         a.add(scanner.nextInt());//各社員の上司番号を入れる...[1,1,2,2]
      }
      
      int b = 0;
      for(int i=0; i<N-1; i++){
        b = a.get(i);//[1,1,2,2]をbに一つずつ代入していく
        //n.set(b-1,n.get(b-1)+1);//n.set(0,1)...0番目のところに1を置き換える
        //n.get(b-1)+1はi=0で始まっているため,nの0番目に+1加算していくことを表している
        n[b-1] +=1;//[b-1]番目にずつ1加算していく
      }
      for(int i=0; i<N; i++){
       System.out.println(n[i]);
      }
    }
 }

Measured memory_bytes: 66100
total_time = 0
max_save = 0
for i in range(5):
    time = int(input())
    spent_time = (time // 10 + int(bool(time % 10)))* 10
    max_save = max(max_save, spent_time - time)
    total_time += spent_time
print(total_time - max_save)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);


ll gcd(ll a, ll b){

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

ll gcdd(ll a, ll b , ll c){

  return gcd(gcd(a,b),c);
}


int main() {


ll N,K;
cin>>N>>K;
ll ans=min(N%K, abs((N%K)-K));
    cout<<ans<<endl;

  
  return 0;
}


Measured memory_bytes: 3560
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;

signed main(){
    cin >> N;
    if(N >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 100005
#define eps 1e-8
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
char s[305];
int K,dp[305][305][305],N;
void update(int &x,int y) {
    x = max(x,y);
}
void Solve() {
    scanf("%s",s + 1);
    read(K);
    N = strlen(s + 1);
    for(int i = 1 ; i <= N ; ++i) 
	for(int j = 0 ; j <= K ; ++j)
	    dp[i][i][j] = 1;
    for(int d = 2 ; d <= N ; ++d) {
	for(int i = 1 ; i <= N ; ++i) {
	    int j = i + d - 1;
	    if(j > N) break;
	    for(int k = 0 ; k <= K ; ++k) {
		if(k) update(dp[i][j][k],dp[i][j][k - 1]);
		update(dp[i][j][k],dp[i + 1][j][k]);
		update(dp[i][j][k],dp[i][j - 1][k]);
		if(s[i] == s[j]) update(dp[i][j][k],dp[i + 1][j - 1][k] + 2);
		else if(k) update(dp[i][j][k],dp[i + 1][j - 1][k - 1] + 2);
	    }
	}
    }
    out(dp[1][N][K]);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 110464
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;

const int N=300005;

int n,a,b,now,x,m;
int f[N];

int main(){
	int i,j;
	scanf("%d%d%d",&n,&a,&b);
	if (a+b>n+1){
		printf("-1\n");
		return 0;
	}
	if (1ll*a*b<1ll*n){
		printf("-1\n");
		return 0;
	}
	if (a+b==n+1){
		for (i=1;i<a;i++) printf("%d ",i);
		printf("%d ",n);
		for (i=a+1;i<=n;i++) printf("%d ",n-(i-a));
		return 0;
	} 
	for (i=1;i<=a;i++) f[i]=n-(a-i);
	b--; m=a; x=n-a;
	while (b){
		now=min(n-m-b+1,a);
		for (i=1;i<=now;i++) f[m+i]=x-(now-i);
		m+=now; b--; x-=now;
	}
	if (m!=n){
		printf("-1\n");
		return 0;
	}
	for (i=1;i<=n;i++) printf("%d ",f[i]);
	return 0;
} 

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;

struct BIT{
    // [1, n]
    vector<int>bit;
    int N;
    void init(int n){
        N = n;
        bit.resize(n, 0);
    }
    BIT(int n=0){
        init(n);
    }
    int sum(int i){
        int s = 0;
        while(i>0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i, int x){
        while(i <= N){
            bit[i] += x;
            i += i & -i;
        }
    }
};

int dp[4020][4020];

int main(){
    
    for(int i=0; i<4020; i++){
        for(int j=0; j<4020;j++){
            dp[i][j] = 1145141919;
        }
    }
    dp[0][0]=0;

    int N;
    cin >> N;
    BIT bit(4020);
    vector<int>bpos(N+1), wpos(N+1);
    for(int i = 1; i <= 2*N; i++){
        char c;
        int a;
        cin >> c >> a;
        if(c=='B')bpos[a] = i;
        else wpos[a] = i;
        bit.add(i, 1);
    }

    for(int b=0; b<=N; b++){
        for(int w=0; w<=N; w++){
            if(b < N){
                dp[b+1][w] = min(dp[b+1][w], dp[b][w] + bit.sum(bpos[b+1]-1));
            }
            if(w < N){
                dp[b][w+1] = min(dp[b][w+1], dp[b][w] + bit.sum(wpos[w+1]-1));
                bit.add(wpos[w+1], -1);
            }
        }
        for(int w=1;w<=N;w++)bit.add(wpos[w], 1);
        if(b<N)bit.add(bpos[b+1], -1);
    }
    cout << dp[N][N] << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

string s,t;
vector<int> idx;

int main(){
  cin>>s;
  int n=s.size();
  rep(i,n){
    if(s[i]=='x')continue;
    t+=s[i];
    idx.push_back(i);
  }
  int m=t.size();
  if(m==0){
    cout<<0<<endl;
    return 0;
  }
  rep(j,m/2){
    if(t[j]!=t[m-1-j]){
      cout<<-1<<endl;
      return 0;
    }
  }
  string a,b;
  if(m%2==1){
    a=s.substr(0,idx[m/2]);
    reverse(all(a));
    b=s.substr(idx[m/2]+1,n-1-idx[m/2]);
  }else{
    a=s.substr(0,idx[m/2-1]);
    reverse(all(a));
    b=s.substr(idx[m/2]+1,n-1-idx[m/2]);
  }
  int l=0,r=0;
  int res=0;
  while(l<a.size()||r<b.size()){
    if(l==a.size()){
      r++;
      res++;
    }else if(r==b.size()){
      l++;
      res++;
    }else{
      if(a[l]!=b[r]){
        if(a[l]=='x')l++;
        else r++;
        res++;
      }else l++,r++;
    }
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1148
def solve():
    H,N = map(int,input().split())
    ap = []
    mp = []

    for _ in range(N):
        a,b = map(int,input().split())
        ap.append(a)
        mp.append(b)
    
    ap_max = max(ap)
    
    dp = [[float('inf')] * (H+ap_max+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0
    
    for i in range(N):
        for sum_h in range(H+ap_max+1):
            dp[i+1][sum_h] = min(dp[i][sum_h-ap[i]] + mp[i], dp[i][sum_h])
            dp[i+1][sum_h] = min(dp[i+1][sum_h-ap[i]] + mp[i], dp[i][sum_h])
    
    ans = float('inf')
    for sum_h in range(H, H+ap_max+1):
        ans = min(ans,dp[N][sum_h])

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 249584
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_s = sorted(a)
    a_set = set(a_s)
    maxv = max(a)
    res = [0] * maxv
    rep = 0
    for i in a_s:
        if i in a_set:
            if res[i-1] == 0:
                for j in range(i, maxv+1, i):
                    res[j-1] += 1
            else:
                res[i-1] +=1
    cnt = 0
    for i in range(n):
        if res[a[i]-1] == 1:
            cnt += res[a[i]-1]
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 36100
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	int n,m;
	cin>>n>>m;
	for(int i=0; i<=n;i++)
	{
		int r=n-i;
		if(i*2 + r*4 == m)
		{
			cout<<"Yes";
			return;
		}
	}
	cout<<"No";
	return;
}

int main()
{
	solve();
	return 0;
}

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

#define LL 					long long
#define ULL 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define vi 					vector<int>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz(x)				(int)(x).size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = 1e9 + 5;
const int mod = 1e9 + 7;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

int n;
char inp[15];

bool cek() { return inp[0]=='Y' && inp[1]=='A' && inp[2]=='K' && inp[3]=='I'; }

int main() {
	scanf("%s", inp);
	n = strlen(inp);
	if (n>=4 && cek()) puts("Yes");
	else puts("No");
	return 0;
}



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

int main(){
    int N;
    cin >> N;
    vector<int> H(N+2);
    H[0] = 1000000001;
    H[N+1] = 1000000001;
    rep(i,N) cin >> H[i + 1];
    int ans = -1;
    int res = -1;
    for (int i = 0; i < N + 1; i++){
        if (H[i] >= H[i + 1]){
            res++;
        } else {
            H[i] = 1000000001;
            res = 0;
        }
        if (res > ans) ans = res;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int64_t pow_rem(int64_t x, int64_t m, int64_t rem)
{
	if (m == 0) {
		return 1;
	}
	if (m == 1) {
		return x;
	}

	if (m & 1) {
		int64_t val = pow_rem(x, m / 2, rem);
		val = val * val;
		val %= rem;
		val *= x;
		val %= rem;
		return val;
	}
	else {
		int64_t val = pow_rem(x, m / 2, rem);
		val = val * val;
		val %= rem;
		return val;
	}
}

int64_t pow_remdiv(int64_t val, int64_t rem)
{
	return pow_rem(val, rem - 2, rem);
}


int64_t divide_rem(int64_t divident, int64_t dividor, int64_t rem)
{
	int64_t ret = pow_remdiv(dividor, rem);
	ret *= divident;
	ret %= rem;

	return ret;
}


vector<int64_t> factors;
vector<int64_t> finvs;
void precalc_nCr(int n, int64_t rem) {
	factors = vector<int64_t>(n + 1);
	finvs = vector<int64_t>(n + 1);

	{
		int64_t f = 1;
		factors[0] = 1;
		FOR_LE(i, 1, n) {
			f *= i;
			f %= rem;
			factors[i] = f;
		}
	}
	{
		int64_t inv = divide_rem(1, factors[n], rem);
		finvs[n] = inv;
		FOR_DW(i, n - 1, 0) {
			inv *= i + 1;
			inv %= rem;
			finvs[i] = inv;
		}
	}
}

int64_t nCr_postcalc(int n, int k, int64_t rem) {
	int64_t val = factors[n];
	val *= finvs[n - k];
	val %= rem;
	val *= finvs[k];
	val %= rem;
	return val;
}

int64_t kRem = 1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; int k; cin >> n >> k;
	vector<int64_t> as(n);
	FOR_LT(i, 0, n) {
		cin >> as[i];
	}
	sort(as.begin(), as.end());

	int64_t maxs = 0;
	int64_t mins = 0;

	precalc_nCr(n, kRem);

	FOR_LT(i, 0, n - k + 1) {
		int64_t ncr = nCr_postcalc(n - i - 1, k - 1, kRem);

		int64_t maxv = ncr * as[n - 1 - i];
		maxv %= kRem;
		int64_t minv = ncr * as[i];
		minv %= kRem;
		maxs += maxv;
		maxs %= kRem;
		mins += minv;
		mins %= kRem;
	}

	int64_t ans = maxs - mins;
	ans %= kRem;
	if (ans < 0) ans += kRem;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
use std::vec::Vec;
use std::collections::HashMap;

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

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

fn read_touple<T: std::str::FromStr + Clone>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0].clone(), v[1].clone())
}

fn main() {
    let (n, m) = read_touple::<usize>();
    let mut v = Vec::new();
    for _ in 0..m {
      let x = read_touple::<String>();
      let a: usize = x.0.parse().ok().unwrap();
      let b: String = x.1.parse().ok().unwrap();
      let mut c = 0;
      if b == "WA" {
        c = 0;
      } else {
        c = 1;
      }
      v.push((a, c));
    }
    let mut ac: usize = 0;
    let mut wa: usize = 0;

    let mut map = HashMap::new();
    for &(p, _) in v.iter() {
      map.insert(p, (0, false));
    }

    for &(p, s) in v.iter() {
      let x = match map.get(&p) {
        Some(&x) => x,
        _ => (0, false),
      };
      
      let (a, b) = x;
      if s == 1 && b == false {
         ac += 1;
         wa += a;
         map.insert(p, (a, true));
      }

      if s == 0 && b == false {
        map.insert(p, (a+1, false));
      }
    }

    println!("{} {}", ac, wa);
}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int H, W, D;
vector<pair<int, int>> A;
int Q;

int main(void) {
    cin >> H >> W >> D;
    A.resize(H * W + 1);
    // 5回WA
    // なんか走査のX,Yが逆になってた
    REP(y, 0, H) {
        REP(x, 0, W) {
            int a;
            cin >> a;
            A[a] = pair<int, int>(x, y);
        }
    }

    int d[90001] = {};
    for(int i = D + 1; i <= H * W; ++i) {
        d[i] = d[i - D] + abs(A[i].first - A[i - D].first) + abs(A[i].second - A[i - D].second);
    }

    cin >> Q;
    rep(i, Q) {
        int L, R;
        cin >> L >> R;
        cout << (d[R] - d[L]) << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
import sys

import numpy as np


def main():
    def readline() -> str:
        s = sys.stdin.readline()
        return s.rstrip()

    n, d = map(int, readline().split())  # type: int, int
    coordinates: np.ndarray = np.array(
        tuple(
            tuple(map(int, readline().split())) for _ in range(n)
        )
    )

    distance: np.ndarray = coordinates ** 2
    distance = np.array((1, 1)) @ distance.T
    distance = np.sqrt(distance)

    answer: int = np.sum(distance <= d)

    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 56952
import sys
n,m = [int(x) for x in sys.stdin.readline().split()]
x = [int(x) for x in sys.stdin.readline().split()]
y = [int(x) for x in sys.stdin.readline().split()]
r = 0
mod = 10**9+7
def sumof(a,b):
	s = 0
	for i in range(a):
		s += (2*(i+1)-a-1)*b[i]
		s %= mod
	return s
r = (sumof(n,x)*sumof(m,y))%mod
print(r)

Measured memory_bytes: 19376
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(),v.end()
#define PI acos(-1)

const ll INF = 10010001010;

ll lcm(ll a,ll b)
{
    return a * b / __gcd(a, b);
}

typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    int maxE = 0;
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
        maxE = max(maxE, L[i]);
        sum += L[i];
    }
    sum -= maxE;
    if (maxE < sum)
    {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
package main
import "fmt"
func main() {
  var h,w int
  var s string
  fmt.Scan(&h,&w)
  black := Points{}
  white := Points{}
  for i:=0;i<h;i++ {
    fmt.Scan(&s)
    for j:=0;j<w;j++ {
      if s[j:j+1] == "#" {
        black = append(black,Point{i+1,j+1})
      } else {
        white = append(white,Point{i+1,j+1})
      }
    }
  }
  if abs(len(black)-len(white)) > (h-1)*(w-1) {
    var max int
    for i:=0;i<len(white);i++ {
      var m int = h*w+1
      for j:=0;j<len(black);j++ {
        var t int = white[i].Distance(black[j])
        if m > t { m = t }
      }
      if max < m { max = m }
    }
    fmt.Println(max)
  } else {
    var a [][]int = newmatrix(h+2,w+2)
    for i:=0;i<len(black);i++ {
      a[black[i].x][black[i].y] = 1
    }
    var k int = 0
    for ;!check(h,w,a);k++ {
      var b [][]int = newmatrix(h+2,w+2)
      for i:=1;i<h+1;i++ {
        for j:=1;j<w+1;j++ {
          if a[i][j] == 1 {
            b[i][j] = 1
            b[i-1][j] = 1
            b[i+1][j] = 1
            b[i][j-1] = 1
            b[i][j+1] = 1
          }
        }
      }
      a = b
    }
    fmt.Println(k)
  }
}
func abs(n int) int {
  if n < 0 { return -n }
  return n
}
func newmatrix(h,w int) [][]int {
  var a [][]int = make([][]int,h+2)
  for i:=0;i<h+2;i++ {
    a[i] = make([]int,w+2)
  }
  return a
}
func check(h,w int,a [][]int) bool {
  for i:=1;i<h+1;i++ {
    for j:=1;j<w+1;j++ {
      if a[i][j] == 0 { return false }
    }
  }
  return true
}
type Point struct { x,y int }
func(p Point) Distance(t Point) int {
  return abs(p.x-t.x)+abs(p.y-t.y)
}
type Points []Point

Measured memory_bytes: 49280
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int array[] = new int[n];
    long count = 1;
    int start = 0;
    for (int i = 0; i < n; i++) {
      array[i] = sc.nextInt();
    }
    
    int work = array[0];
    for (int i = 1; i < n;) {
      if ((work & array[i]) == 0) {
        work ^= array[i];
        i++;
        count += i - start;
      } else {
        work ^= array[start];
        start++;
      }
    }
    System.out.println(count);
  }
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"
#define int ll

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

  int N;
  cin>>N;
  vector<int>L(N);
  for(int i=0;i<N;i++)cin>>L[i];
  int ans=0;
  sort(rng(L));
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(L[i]==L[j])continue;
      for(int k=j+1;k<N;k++){
        if(L[i]==L[k]||L[j]==L[k])continue;
        if(L[i]+L[j]>L[k])ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	string res;

	string a[] = { "A", "T", "C", "G" };

	for (int i = 0; i < 4; i++)
	{
		if (s == a[i])
		{
			if (i % 2 == 0)
			{
				res = a[i + 1];
			}
			else
			{
				res = a[i - 1];
			}
		}
	}

	println(res);
}


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

const int MN = 100010;

int N, M, Q;
vi g[MN];
int v[MN], d[MN], c[MN];
int f[11][MN];

int main() {
	cin >> N >> M;

	rep(i, M) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].pb(b); g[b].pb(a);
	}

	cin >> Q;

	memset(f, -1, sizeof(f));

	rep(i, Q) {
		cin >> v[i] >> d[i] >> c[i];
		--v[i];
		f[d[i]][v[i]] = i;
	}

	for (int i = 10; i > 0; --i) {
		rep(j, N) {
			if (f[i][j] == -1) continue;
			for (int &to : g[j]) {
				f[i-1][to] = max(f[i-1][to], f[i][j]);
			}
		}
	}

	rep(i, N) {
		int a = -1;
		rep(j, 11) a = max(a, f[j][i]);
		printf("%d\n", a == -1 ? 0 : c[a]);
	}

	return 0;
}

Measured memory_bytes: 11896
from collections import Counter
N = int(input())
S = []
for _ in range(N):
  S.append(input())
C = Counter(S).most_common()
_,M = C[0]
L = []
for a,b in C:
  if b == M:
    L.append(a)
print(*sorted(L) ,sep = "\n")    

Measured memory_bytes: 45036
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int A,B;
	cin >>A >> B;
	if(B%A==0){
		println(A+B);
	}
	else{
		println(B-A);
	}
	return 0;
}


Measured memory_bytes: 256
H, W = gets.split.map( &:to_i )
Board = Array.new( H ) do
	gets.strip
end

def inside( y, x )
	return 0 <= y && y < H && 0 <= x && x < W
end

que = Array.new
que << [ 0, 0 ]

dy = [ 0, 1, 0, -1 ]
dx = [ 1, 0, -1, 0 ]

distances = Array.new( H ) do
	Array.new( W, -1 )
end
distances[0][0] = 1

while !que.empty? do
	y, x = que.shift

	4.times do |d|
		ny = y + dy[d]
		nx = x + dx[d]

		if inside( ny, nx ) && Board[ ny ][ nx ] == '.' && distances[ ny ][ nx ] == -1 then
			distances[ ny ][ nx ] = distances[y][x] + 1
			que << [ ny, nx ]
		end
	end
end


res = 0
H.times do |i|
	W.times do |j|
		if Board[i][j] == '.' then
			res += 1
		end
	end
end
res -= distances[ H - 1 ][ W - 1 ]

puts ( distances[ H - 1 ][ W - 1 ] == -1 ? -1 : res )


Measured memory_bytes: 1788
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
    int x[4],y[4];
    cin>>x[0]>>y[0]>>x[1]>>y[1];
    int dx = x[1] - x[0];
    int dy = y[1] - y[0];
    x[2] = x[1] - dy;
    y[2] = y[1] + dx;
    x[3] = x[2] - dx;
    y[3] = y[2] - dy;

    cout<<x[2]<<" "<<y[2]<<" "<<x[3]<<" "<<y[3]<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <cmath>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>

// short keywords

#define ipow(a,b) (ll)pow(a,b)
#define pi(a,b) pair<ll,ll>(a,b)
#define pis(a,b) pair<ll,string>(a,b)
#define pc(c,d) pair<ll,pair<ll,string>>(c,d)
#define pp(a,b,c) pair<pair<ll,ll>,ll>(pi(a,b),c)
#define ps(a,b,c) pair<string,pair<ll,ll>>(a,pi(b,c))

// for loops

#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define mod 1000000007
using namespace std;

// short keywords2
typedef long long ll;
typedef set<ll>::iterator sit;
typedef vector <ll> ::iterator vit;
typedef map<ll,ll>::iterator mit;
typedef multimap<ll,ll>::iterator mmit;

class Task
{
public:
    void solve(istream& in,ostream& out)
    {
        ll n,c,b;
        in>>n>>c>>b;
        ll a[n];

        rep(i,n)
        {
            in>>a[i];
        }

        ll res=0;

        reps(i,1,n-1)
        {
            if(c*(a[i]-a[i-1])>b)
            {
                res+=b;
            }
            else
            {
                res+=c*(a[i]-a[i-1]);
            }
        }

        out<<res<<endl;
    }

    ll c(ll a,ll b)
    {
        ll res=0;
        reps(i,1,15)
        {
            if(a/(ll)pow(b,i)!=0)
            {
                res+=a/(ll)pow(b,i);
            }
            else
            break;
        }

        return res;
    }

    bool isprime(ll n)
    {
        if(n==1 || (n%2==0 && n!=2))
        {
            return false;
        }
        else if(n==2 || n==3)
        {
            return true;
        }
        else
        {
            ll res=0;
            for(ll i=3 ;i<=(ll)sqrt(n) ;i+=2)
            {
                if(n%i==0)
                {
                    res++;
                    break;
                }
            }

            if(res==0)
            {
                return true;
            }
            else
            return false;
        }
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Task solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in,out);
	out.flush();

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
    double n;
    double c=1,b=0;
    double ans=0;
    cin>>n;
    vector<long long int>a(1000000);
    for(int i=0;i<n;i++){
        cin>>a[i];
        c=c*a[i];
    }
    
    for(int i=0;i<n;i++){
        b=b+c/a[i];
    }
    ans= (double)(c/b);
    cout<<ans<<endl;


   return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.length();
    int ans = 1, wait = 0, ok = 0;
    for (int i = 1; i < n; ++ i)
        if (wait == 1){
            ++ ans;
            wait = 0;
            ok = 1;
        }
        else if (ok == 1){
            ++ ans;
            ok = 0;
        }
        else if (s[i] != s[i - 1])
            ++ ans;
        else
            wait = 1;
    cout << ans << endl;
}


Measured memory_bytes: 640