akhauriyash/Code-Regression huggingface dataset:
from collections import deque

s_input = [char for char in input()]
q = int(input())
s = deque()
s_rev = deque()
s.extend(s_input)
s_rev.extendleft(s_input)
flag = True #T:inputと同順、F:逆順
count_append = 0 #文字の追加回数
for i in range(q):
  query = input().split()
  if query[0] == "1":
    flag = not flag
  else:
    if flag:
      if query[1] == "1":
        s.appendleft(query[2])
        s_rev.append(query[2])
      else:
        s.append(query[2])
        s_rev.appendleft(query[2])
    else:
      if query[1] == "1":
        s.append(query[2])
        s_rev.appendleft(query[2])
      else:
        s.appendleft(query[2])
        s_rev.append(query[2])
    count_append += 1
s_output = ""
if flag:
  for i in range(len(s_input) + count_append):
    s_output += s.popleft()
else:
  for i in range(len(s_input) + count_append):
    s_output += s.pop()
print(s_output)

Measured memory_bytes: 9844
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;



set<ll> divisor(ll n)
{
	set<ll> value;
	for( ll i=1; i*i<=n;i++)
	{
		
			if (n % i == 0)
			{
				value.insert(i);
				if (i * i != n)
				{
					value.insert(n / i);
				}
			}
		
	}
	return value;
}


void solve()
{
	int x;
	cin>>x;
	vector<ll>cand;
	rep(i,1000){
		ll k=powl(i,5);
		cand.push_back(k);
	}
	int a,b=0;
	rep(i,1000){
		rep(j,1000){
			ll t,u;
			t=cand[i]-cand[j];
			u=cand[i]+cand[j];
			if(t==x){
				a=i; b=j;
				break;
			}
			if(u==x){
				a=i;
				b=-j;
				break;
			}
		}
	}
	cout<<a<<" "<<b<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 3720
using System;

namespace tenka1_2018_d
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int sum = 0; int k = 0;
			for (; sum < n; k++) sum += k;
			k--;
			if (sum == n)
			{
				Console.WriteLine("Yes");
				Console.WriteLine(k + 1);
				int[,] ret = new int[k + 1, k];
				int count = 1;
				for (int i = 0; i < k; i++)
				{
					for (int j = 0; j < k - i; j++)
					{
						ret[i, i + j] = count + j;
						ret[i + j + 1, i] = count + j;
					}
					count += k - i;
				}
				for (int i = 0; i <= k; i++)
				{
					Console.Write(k);
					for (int j = 0; j < k; j++) Console.Write(" " + ret[i, j]);
					Console.WriteLine();
				}
			}
			else Console.WriteLine("No");
		}
	}
}

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

using namespace std;

#define ll long long int
#define get(a) ll a; cin >> a;
#define show(a) cout << a << endl;
#define full(p) p.begin(), p.end()
#define sz(a) (ll)(a.size())
#define pb push_back

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	////////////////////////////////
	get(a);
	if(a == 7 or a == 5 or a == 3)
	cout << "YES" << endl;
	else
	cout << "NO" << endl;	

	return 0;
}

Measured memory_bytes: 3648
#include<iostream>

#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

using namespace std;

int main(){
  char ss[20];
  cin>>ss;
  REP(i,0,4) cout<<ss[i];
  cout<<' ';
  REP(i,0,8) cout<<ss[i+4];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
vector<int>graph[100005];
double dp[305][305][305];
double solve(int x,int y,int z,int n)
{
    if(x<0 || y<0 || z<0)
    return 0;
    if(x==0 && y==0 && z==0)
    return 0;
    if(dp[x][y][z]> -0.9)
    return dp[x][y][z];
    double ex=n+x*(solve(x-1,y,z,n))+y*(solve(x+1,y-1,z,n))+z*(solve(x,y+1,z-1,n));
    double p=x+y+z;
    dp[x][y][z]=ex/p;
    return dp[x][y][z];
}
int main() {
    int n,i,x;
    cin>>n;
    int one=0,two=0,three=0;
    memset(dp,-1,sizeof(dp));
    for(i=0;i<n;i++)
    {
        cin>>x;
        if(x==1)
        one++;
        else if(x==2)
        two++;
        else if(x==3)
        three++;
    }
    double k=solve(one,two,three,n);
    cout<<fixed<<setprecision(10)<<k<<"\n";
	return 0;
}

Measured memory_bytes: 224256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void debug() { std::cerr << '\n'; }
template <class H, class... T> void debug(H &&head, T &&... args) {
    std::cerr << head;
    sizeof...(args) == 0 ? std::cerr << "" : std::cerr << ' ';
    debug(std::forward<T>(args)...);
}
template <class T> void debug(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cerr << v[i];
        i == v.size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
    }
}
template <class T> void debug(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cerr << v[i][j];
            j == v[i].size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
        }
    }
}

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

    int a;
    cin >> a;
    print(a * a * a);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define D(a) cout<<#a<<": ";for(auto i:a)cout<<i<<' ';cout<<endl;
using namespace std;
int main()
{
    long long A, B, C, K; cin >> A >> B >> C >> K;
    long long ans = K % 2 ? B - A : A - B;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
#define MOD 1000000007

char A[23333],B[23333],C[23333];
int _10[23333];

int cmp(char *A,char *B,int l)
{
    for (int i=l-1;i>=0;--i)
        if (A[i]>B[i])
            return 1;
        else if (A[i]<B[i])
            return -1;
    return 0;
}

long long calc(char *A,char *B)
{
    long long ret=0;
    int l1=strlen(A),l2=strlen(B);
    if (l1<l2) return 0;
    for (int i=0;i<=l1-l2;++i)
    {
        long long tmp=0,tmp2=0;
        int cc=cmp(A+i,B,l2);
        if (cc>=0&&(i!=l1-l2||i==0||l2!=1||B[0]!='0'))
        {
            if (cc==0)
            {
                for (int j=i-1;j>=0;--j)
                    tmp=(tmp*10+A[j]-'0')%MOD;
                tmp=(tmp+1)%MOD;
            }
            else tmp=_10[i];
        }
        for (int j=l1-1;j>=i+l2;--j)
            tmp2=(tmp2*10+A[j]-'0')%MOD;
        if (l2==1&&B[0]=='0'&&tmp2>0&&i!=0) --tmp2;
        tmp=(tmp+tmp2*_10[i])%MOD;
        ret=(ret+tmp)%MOD;
    }
    return ret;
}

int main()
{
    _10[0]=1;
    for (int i=1;i<=10003;++i) _10[i]=_10[i-1]*10ll%MOD;
    scanf("%s%s%s",A,B,C);
    int l1=strlen(A),l2=strlen(B),l3=strlen(C);
    for (int i=0;i<l1-i-1;++i) swap(A[i],A[l1-i-1]);
    for (int i=0;i<l2-i-1;++i) swap(B[i],B[l2-i-1]);
    for (int i=0;i<l3-i-1;++i) swap(C[i],C[l3-i-1]);
    if (A[0]=='0'&&l1==1) cout<<calc(B,C)<<endl;
    else
    {
        int carry=1;
        for (int i=0;i<l1;++i)
            if (carry)
            {
                if (--A[i]<'0') A[i]='9',carry=1;
                else carry=0;
            }
        if (A[l1-1]=='0') A[l1-1]=0,--l1;
        long long ret1=calc(A,C),ret2=calc(B,C);
        cout<<((ret2+MOD-ret1)%MOD)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1236
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int N, K;
    cin >> N >> K;

    int mini = 1;

    rep(i, N)
    {
        mini = min(mini * 2, mini + K);
    }
    cout << mini << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

MOD = 1000000007

n , m = map(int,input().split())

count = [-1] * (n+1)
for i in range(m):
    count[int(input())] = 0

for i in range(1,n+1):
    if count[i] == 0:
        continue
    
    if i == 1:
        count[i] = 1 
    elif i == 2:
        count[i] = count[i-1] + 1
    else:
        count[i] = (count[i-1] + count[i-2]) % MOD

print(count[n])


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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A){
    if (A.size() == n+1) {
        int now = 0;
        rep(i, q){
            if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }
    A.push_back(A.back());
    while (A.back() <= m){
        dfs(A);
        A.back()++;
    }
}

int main() {
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i, q)cin >> a[i] >> b[i] >> c[i] >> d[i];
    dfs(vector<int>(1,1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;
public class Main{
	static final int[][] dxy = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

	static void Islands(int h, int w, int i, int j, int[][] c){
		c[i][j] = 0;
		for(int k=0; k<8; k++){
			int ii = i + dxy[k][0];
			int jj = j + dxy[k][1];
			if(0<=ii&&0<=jj&&ii<h&&jj<w&&c[ii][jj]==1)Islands(h, w, ii, jj, c);
		}
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		while(w!=0){
			int[][] c = new int[h][w];
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					c[i][j] = sc.nextInt();
				}
			}
			int cnt = 0;
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					if(c[i][j]==1){
						Islands(h, w, i, j, c);
						cnt++;
					}
				}
			}
			System.out.println(cnt);
			w = sc.nextInt();
			h = sc.nextInt();
		}
	}
}


Measured memory_bytes: 44488
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#include <unordered_map>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;

int n, m,dp[100005],used[100005],ans;
vector<int> g[100005];

void dfs(int v)
{
	if (used[v])
		return;
	used[v] = 1;
	for (int i = 0; i < g[v].size(); i++)
	{
		dfs(g[v][i]);
		dp[v] = max(dp[v], dp[g[v][i]] + 1);
	}
}

int main()
{
	cin >> n >> m;
	while (m--)
	{
		int a, b;
		cin >> a >> b;
		g[a].PB(b);
	}
	for (int i = 1; i <= n; i++)
	{
		dfs(i);
		ans = max(dp[i],ans);
	}
	cout << ans << endl;
	return 0;
}

/*


*/

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


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

	string s;
	cin >> s;
	bool ok = false;
	ll n = s.size();
	FOR(i,0,n){
		FOR(j,0,n-i){
			string k;
			k += s.substr(0,i);
			k += s.substr(i+j,n-i-j);
			if(k=="keyence")ok=true;
		}
	}
	if(ok){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

}


Measured memory_bytes: 256
n=input()
record=0
swit=0
atgc=['A', 'T', 'G', 'C']
for i in range(len(n)):
    if n[i] in atgc:
        swit+=1
        if swit>record:
            record=swit
    else:
        swit=0
        if swit>record:
            record=swit
print(record)

Measured memory_bytes: 2940
n = int(input())
a = list(map(int, input().split()))
a.reverse()
count = 0
for i in range(n-1):
    if a[i+1] > a[i]:
        a[i+1] -= 1
for i in range(n-1):
    if a[i+1]>a[i]:
        count +=1
if count == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14224
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
#define ALL(X) X.begin(), X.end()
using lint = long long;
template <typename T>
void print_container(std::vector<T> vec)
{
    for (auto iter = vec.begin(); iter != vec.end(); ++iter)
    {
        std::cout << *iter << " ";
    }
    std::cout << std::endl;
}

int main()
{
    lint n;
    scanf("%lld", &n);

    lint ans = 0;

    for (int i = 1; i <= n; ++i)
    {
        lint step = i;
        lint first = i;
        lint num = n / step;
        lint last = step * num;

        ans += (first + last) * num / 2;
    }

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


Measured memory_bytes: 3256
# -*- coding:utf-8 -*-
import re
import sys
N, M = map(int,input().split())
A = [ input() for i in range(N) ] 
B = [ input() for i in range(M) ]
for tmp in range(N-M+1):
    for tmp2 in range(N-M+1):
        flag = True
        for tmp3 in range(M):
            for tmp4 in range(M):
                if A[tmp+tmp3][tmp2+tmp4] != B[tmp3][tmp4]:
                    flag = False
        if flag:
            print("Yes")
            sys.exit()
print("No")
    #if A[tmp].find(B[tmp2]):
    #   pattern = re.complie(B[tmp2])
    #   iterator = re.finditer(pattern, A[tmp])

Measured memory_bytes: 3188
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
/*        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
        int a = int.Parse(input[2]);
//        int b = int.Parse(input[3]);*/
//        string temp = ReadLine();
        int a = int.Parse(ReadLine());
        int b = int.Parse(ReadLine());
        int c = int.Parse(ReadLine());
        int d = int.Parse(ReadLine());
//        string a = ReadLine();
//        string b = ReadLine();
//        string c = ReadLine();
        a = Min(a,b);
        c = Min(c,d);
        WriteLine(a+c);
    }
}

Measured memory_bytes: 13140
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    static int result = Integer.MAX_VALUE;
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int[] l = new int[n];
		for(int i = 0; i < n; i++){
		    l[i] = sc.nextInt();
		}

		// 計算
		int[] v = new int[n + 1];
		dfs(n, 0, v, a, b, c, l);
		
		// 出力
		System.out.println(result);
        
	}
	static void dfs(int n, int depth, int[] v, int a, int b, int c, int[] l){
	    if(depth == n){
	        //System.out.println(result);
	        result = min(result, calc(n, v, a, b, c, l));
	    }else{
	        for(int i = 0; i < 4; i++){
	            v[depth] = i;
	            dfs(n, depth + 1, v, a, b, c, l);
	        }
	    }
	}
	static int calc(int n, int[] v, int a, int b, int c, int[] l){
	    int mp = 0;
	    // A
	    int lenA = 0;
	    int mixA = 0;
	    for(int i = 0; i < n; i++){
	        if(v[i] == 0){
	            lenA += l[i];
	            mixA++;
	        }
	    }
	    if(lenA == 0) return Integer.MAX_VALUE;
	    mp += abs(a - lenA) + (mixA - 1)*10;
	    // B
	    int lenB = 0;
	    int mixB = 0;
	    for(int i = 0; i < n; i++){
	        if(v[i] == 1){
	            lenB += l[i];
	            mixB++;
	        }
	    }
	    if(lenB == 0) return Integer.MAX_VALUE;
	    mp += abs(b - lenB) + (mixB - 1)*10;
	    // C
	    int lenC = 0;
	    int mixC = 0;
	    for(int i = 0; i < n; i++){
	        if(v[i] == 2){
	            lenC += l[i];
	            mixC++;
	        }
	    }
	    if(lenC == 0) return Integer.MAX_VALUE;
	    mp += abs(c - lenC) + (mixC - 1)*10;
	    
	    return mp;
	}
}


Measured memory_bytes: 23944
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n, m;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    cin >> m;
    vector<string> t(m);
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }
    int maxx = 0;
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        for (int j = 0; j < n; j++) {
            if (s[j] == s[i])
                cnt++;
        }
        for (int j = 0; j < m; j++) {
            if (t[j] == s[i])
                cnt--;
        }
        maxx = max(maxx, cnt);
    }
    cout << maxx << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int n,a;
vector<int> x;

int main() {
  cin >>n >>a;
  x.assign(n, 0); rep(i, n){ int buf; cin >>buf; x.at(i) = buf-a; }
  vector<vector<ll>> dp(n+1, vector<ll>(5000, 0));
  // dp[i][j]...i個目までのカードを使って和をjにするのが何通りあるか
  dp[0][0] = 1;
  for (int i=0; i<n; i++){
    for (int j=0; j<5000; j++){
      int now = j <= 2500 ? j : j-5000; // 今jが何の値を表しているか
      int next = now + x.at(i);
      next = next >= 0 ? next : next+5000; // x.at(i)を足した時のindex
      dp[i+1][j] += dp[i][j];
      dp[i+1][next] += dp[i][j];
    }
  }
  ll res = dp[n][0] - 1; // 一枚も選ばないものも含まれているので
  cout <<res <<endl;
}

Measured memory_bytes: 2304
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		int h = in.nextInt();
		if (h == 0) return false;

		int[][] t = new int[h][5];
		for (int i=0; i<h; i++) {
			for (int j=0; j<5; j++) {
				t[i][j] = in.nextInt();
			}
		}

		int ans = 0;
		while (true) {
			boolean f = false;
			for (int i=0; i<h; i++) {
				for (int j=0; j<3; j++) {
					if (t[i][j] == -1) continue;
					int pos = j;
					while (pos < 5 && t[i][j] == t[i][pos]) pos++;
					if (pos - j >= 3) {
						for (int k=j; k<pos; k++) {
							ans += t[i][k];
							t[i][k] = -1;
						}
						f = true;
					}
				}
			}

			for (int i=h-1; i>0; i--) {
				for (int j=0; j<5; j++) {
					if (t[i][j] > 0) continue;
					int pos = i - 1;
					while (pos > 0 && t[pos][j] < 0) pos--;
					t[i][j] = t[pos][j];
					t[pos][j] = -1;
				}
			}

			if (!f) break;
		}

		out.println(ans);

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while (solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 53708
#include<stdio.h>
int main()
{
    int a,b,c,x;
    scanf("%d%d%d",&a,&b,&c);
    x=b/a;
    if(x<=c)
    {
        x=x;
    }
    else{x=c;}
    printf("%d",x);

    return 0;
}



Measured memory_bytes: 2120
x=int(input())
a=0
a=(x//11)*2
if x<=6:
	print(1)
elif x<=11:
	print(2)
else:
	if x%11==0:
		print(a)
	elif x%11<=6:
		a+=1
		print(a)
	elif  x%11<=11:
		a+=2
		print(a)
		


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

int main(void){
	string first;

	while(cin >> first){
		if(first[0] == '-') break;
		int m;
		cin >> m;
		for(int i=0; i<m; i++){
			int sh;
			cin >> sh;
			string rem = first.substr(sh, first.size());
			first = rem + first.substr(0, sh);
		}
		cout << first << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
#include <stdio.h>

int main(void) {
    int a[7], b[7];
    int i;

    for (i=0; i<7; i++) {
        scanf("%d %d", &a[i], &b[i]);
    }

    for (i=0; i<7; i++) {
        printf("%d\n", a[i]-b[i]);
    }

    return 0;
}

Measured memory_bytes: 600
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int b[SIZE];
int main(){
    int M; R(M);
    FOR(i,1,M)R(b[i]);
    VI an;
    for(int i=M;i>0;i--){
        for(int j=i+i;j<=M;j+=i)b[i]^=b[j];
        if(b[i])an.PB(i);
    }
    W(SZ(an));
    W(an);
    return 0;
}


Measured memory_bytes: 2424
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    bool isRev = false;
    deque<int> b;
    rep(i,n) {
        if (isRev) b.push_front(a[i]);
        else b.push_back(a[i]);
        isRev = !isRev;
    }
    if (isRev) {
        rep(i,n) {
            cout << b[n-1-i] << " ";
        }
        cout << endl;
    } else {
        rep(i,n) {
            cout << b[i] << " ";
        }
        cout << endl;
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i,n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;    // python でいうところの dictionary
    }

    ll ans = 0;
    for (auto& p : mp) {
        int s = p.second;
        ans += (ll)s*(s-1)/2; // sCs-1 (コンビネーション) の計算
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11256
#include <iostream>

using namespace std;

#define ll long long
#define double long double
#define FOR(i,a,b) for(long i = a; i <= b; i++)
#define FOD(i,b,a) for(long i = b; i >= a; i--)

#define DEBUG(x) cerr << #x << " = " << x << endl

#define mod 1000000007

ll color(ll point){
	if (point <= 399) return 0;
	if (point <= 799) return 1;
	if (point <= 1199) return 2;
	if (point <= 1599) return 3;
	if (point <= 1999) return 4;
	if (point <= 2399) return 5;
	if (point <= 2799) return 6;
	if (point <= 3199) return 7;
	return 8;
}

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

	ll n, a[10005];
	ll c[10]  =  {}, cnt = 0;
	cin >> n;
	FOR(i,1,n) cin >> a[i];
	
	FOR(i,1,n) c[color(a[i])]++;
	FOR(i,0,7) if (c[i]) cnt++;
	if (cnt==0) {
		cout << 1 << " " << cnt + c[8];
	} else {
		cout << cnt << " " << cnt + c[8];
	}
	
	

	return 0;
}





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

int main()
{
	long long gx,gg,qx,qg,max;
	cin >> gx >> gg >> qx >> qg;
	
	if (gx>qx)
		max=gx;
	else
		max=qx;
	
	for (long long i=1; i<=max+2; i++)
	{
		qx-=gg;
		if (qx<=0)
		{
			cout << "Yes" << endl;
			return 0;
		}
		
		gx-=qg;
		
		if (gx<=0)
		{
			cout << "No" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int N, d[109];
    cin >> N;
    rep(i,N){
        cin>>d[i];
    }
    sort(d,d+N);
    int count = 1;
    rep(i,N-1){
        if(d[i+1] - d[i] > 0) count ++;
    }
    cout << count << endl;
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int n;
int main() {
    cin >> n;
    int r[n];
    rep(i,0,n){
        cin >> r[i];
    }
    int ans = INT_MIN;
    int mi = r[0];
    rep(i,1,n){
        ans = max(ans,r[i]-mi);
        mi = min(mi,r[i]);
    }
    pout(ans);
    return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/29  Problem: 070_abc_b / Link: https://abc070.contest.atcoder.jp/tasks/abc071_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	ans = min(b,d) - max(a,c);
	if (ans < 0)ans = 0;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define MAX_V 11
#define INF (1e9)
#define cost first
#define node second
using namespace std;
typedef pair <int, int> P;
int n,m;
vector<P> G[101];

//prim
int prim(){
  int res = 0;
  bool visited[101]={};
  int D[101];
  for(int i=0;i<n;i++) D[i] = INF;
  priority_queue <P, vector<P>, greater<P> > Q;
  Q.push(P(0,0));
  while(!Q.empty()){
    P t = Q.top(); Q.pop();
    if(visited[t.node]) continue;
    visited[t.node] = true;
    res += t.cost;
    for(int i=0;i<G[t.node].size();i++){
      int nnode = G[t.node][i].node;
      int ncost = G[t.node][i].cost;
      if(D[nnode] > ncost) Q.push(P(ncost,nnode)),D[nnode]=ncost;
    }
  }
  return res;
}

/*
void init(int n){
  for(int i=0;i<n;i++) G[i].clear();
}
*/

// warshall froyd
	  
int d[MAX_V][MAX_V];
int used[MAX_V];

void init(){
  for(int i=0;i<MAX_V;i++)
    for(int j=0;j<MAX_V;j++) i!=j ? d[i][j]=INF : d[i][j]=0;
}
  
void warshall_froyd(){
  for(int k=0;k<MAX_V;k++)
    for(int i=0;i<MAX_V;i++)
      for(int j=0;j<MAX_V;j++) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
}



int main() {
  while(1){
    cin >> n;
    if(!n)break;
    init();
    int v = 0;
    for(int i=0;i<n;i++){
      int a,b,c;
      cin >>a>>b>>c;
      d[a][b] = c;
      d[b][a] = c;
      v = max(a,max(b,v));
    }
    warshall_froyd();
    int ans = INF;
    int node=-1;
    for(int i=0;i<=v;i++){
      int sum = 0;
      for(int j=0;j<=v;j++) sum+= d[i][j];
      if(ans > sum) ans=sum , node = i;
    }
    cout <<node <<" "<< ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <string.h>
int p(char a[],char b,int n){
    int i;
    int j;
    int c = 0;
    for(i=0;i<n;i++){
       if(a[i] == b){
           c++;
           if(c == 2){
               return 1;
           }
       }
        
    }
    return 0;
}

int main(void)
{
    int i;
    int n;
    int j;
    int ans[30] = {0};
    char s1[30] = {0};
    char s2[30] = {0};
    int count = 0;
    scanf("%s",s1);
    n = strlen(s1);
    for(i=0;i<n;i++){
        s2[i] = s1[i];
    }
    for(i=0;i<n;i++){
        ans[i] = p(s1,s1[i],n);
        //printf("%d\n",ans[i]);
    }
    for(i=0;i<n;i++){
        if(ans[i] == 0){
            count++;
        }
    }
    //printf("%d\n",count);
    if(count != n){
        printf("no\n");
    }else{
        printf("yes\n");
    }
    return 0;
    
}

Measured memory_bytes: 128
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
n = int(input())
#n, d = map(int, sys.stdin.readline().split())
s = input()
#a = list(map(int, sys.stdin.readline().split()))

rc = 0
for i in range(n):
    if s[i] == "R":
        rc += 1

wc = 0
for i in range(rc):
    if s[i] == "W":
        wc += 1

print(wc)


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

int main() {
	ll H, W;
	scanf("%lld %lld", &H, &W);
	ll ans = INF, sum;
	for(ll i = 1; i < H; ++i) {
		ll tmp = (H - i) / 2;
		sum = max(i * W, (H - i - tmp) * W) - min(i * W, tmp * W);
		ans = min(ans, sum);
		tmp = W / 2;
		sum = max(i * W, (H - i) * (W - tmp)) - min(i * W, (H - i) * tmp);
		ans = min(ans, sum);
	}
	for(ll i = 1; i < W; ++i) {
		ll tmp = (W - i) / 2;
		sum = max(i * H, (W - i - tmp) * H) - min(i * H, tmp * H);
		ans = min(ans, sum);
		tmp = H / 2;
		sum = max(i * H, (W - i) * (H - tmp)) - min(i * H, (W - i) * tmp);
		ans = min(ans, sum);
	}
	printf("%lld\n", ans);
	return 0;
}

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

using ll = long long;
ll H;

// 敵の体力がtarget_lifeの1体のときにそれを倒すのに必要な攻撃数
ll attack(ll target_life){
    if(target_life == 1) return 1;
    return attack(target_life / 2) * 2 + 1;
}

void solve(){
    std::cout << attack(H) << std::endl;
}


int main(){
    scanf("%lld%*c", &H);

    solve();

    return 0;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


N, P = map(int, input().split())
ans = 1
# print(factorization(P))
for insi, num in factorization(P):
    if num >= N:
        ans *= (insi ** (num // N))
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> a(N);

    long long sum=0, minNum=2020202021, sum2=0;

    for(int i=0; i<N; i++){
	cin >> a[i];
	sum += a[i];
    }
    for(int i=0; i<N; i++){
	sum-=a[i];
	sum2+=a[i];

	if(abs(sum-sum2) < minNum)
	    minNum=abs(sum-sum2);
    }
    cout << minNum << endl;
}



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

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a); i >= (b); i--)
#define ALL(container) (container).begin(), (container).end()

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int main() {
  int A, B, T;
  cin >> A >> B >> T;
  cout << T / A * B;

  return 0;
}


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

int main(){

    int n;
    cin >> n;
    int a[n+1];

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

    int total = 0;
    for(int i=0; i<n+1; i++){
        total += abs(a[(i+1)%(n+1)] - a[i]);
    }

    for(int i=1; i<=n; i++){
        int temp = total - abs(a[i] - a[i-1]) - abs(a[(i+1)%(n+1)] - a[i]) + abs(a[(i+1)%(n+1)] - a[i-1]);
        cout << temp << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[5];
  for(int i=0;i<5;i++)
    cin>>a[i];
  for(int i=0;i<5;i++){
  	if(a[i]==0){
      cout<<i+1;
      return 0;
    }
  }
  return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, y, r, p;
string s, t;
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	ll a,b;
	cin>>n>>a>>b;
	vll x(n);
	ll ans = 0;
	for(ll i=0;i<n;i++) cin>>x[i];

	for(ll i=1;i<n;i++) {
		ans += min((x[i]-x[i-1])*a,b);
	}

	cout<<ans;
}

int main() {
	fastio; randomINT;
	//cin>>t;
	while (T--) {
		MAIN();
	}
	return 0;
}


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

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

    ll N, K, Q;
    cin >> N >> K >> Q;
    vector<int> count(N, 0);
    rep(i,Q){
        int a;
        cin >> a;
        a--;
        
        count[a]++;
    }
    
    rep(i,N){
        if(Q-count[i] >= K){
            cout << "No" << endl;
        }else{
            
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
-- `chebyshev n' returns the number of primes between n+1 and 2n.
-- for example:
--   chebyshev 10 == 4   (11, 13, 17, 19)
--   chebyshev 13 == 3   (17, 19, 23)

chebyshev :: Int -> Int
chebyshev n = length $ filter isPrime [n + 1 .. 2 * n]

isPrime :: Int -> Bool
isPrime n = and $ map (\d -> mod n d /= 0) divisors
  where
    divisors = takeWhile (\d -> d * d <= n) ([2] ++ [3,5..])

main :: IO ()
main = do
  n <- readLn
  if n == 0
     then return ()
     else do print $ chebyshev n
             main

Measured memory_bytes: 4216
#include <iostream>
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

int main() {
    int N,divisor=0,cnt=0;
    cin >> N;

    fi(i,1,N){
        if(i&1){
            fi(j,1,i){
                if(i%j==0){
                    divisor++;
                }
            }
            if(divisor==8)
                cnt++;
            divisor=0;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    map<int, vector<int>> m;
    REP(n, N) {
        int a, b;
        cin >> a >> b;
        m[a].pb(b);
    }

    ll ans = 0;
    priority_queue<int, vector<int>> q;
    FOR(a, 1, M + 1) {
        for(auto e: m[a]) q.push(e);

        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10880
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	ar := make([]int, n)
	for i := range ar {
		fmt.Scan(&ar[i])
	}
	sort.Ints(ar)
	br := make(sousas, m)
	for i := 0; i < m; i++ {
		var bb, cc int
		sv := sousa{}
		fmt.Scan(&bb, &cc)
		sv.b = bb
		sv.c = cc
		br[i] = sv
	}
	sort.Sort(br)
	sum := 0
	bri := 0
	for i := 0; i < n; i++ {
		v := ar[i]
		if bri < m {
			if v < br[bri].c {
				v = br[bri].c
				br[bri].b--
				if br[bri].b == 0 {
					bri++
				}
			}
		}
		sum += v
	}
	fmt.Println(sum)
}

type sousa struct {
	b int
	c int
}

type sousas []sousa

func (d sousas) Len() int {
	return len(d)
}

func (d sousas) Swap(i, j int) {
	d[i], d[j] = d[j], d[i]
}

func (d sousas) Less(i, j int) bool {
	return d[i].c > d[j].c
}


Measured memory_bytes: 9116
import java.awt.geom.Point2D;
import java.util.*;

import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1175();
	}	
	class AOJ1175{
		AOJ1175(){
			while(sc.hasNext()){
				N=sc.nextInt();
				if(N==0)	break;
				solve();
			}
		}
		int N;
		void solve(){
			Circle[] c=new Circle[N];
			int[] a=new int[N];
			for(int i=0; i<N; ++i){
				c[i]=new Circle(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()-1);
				for(int j=0; j<i; ++j)if(c[i].r+c[j].r > c[i].p.distance(c[j].p))	a[i] |= (1<<j);
			}
			int ans=N;
			boolean[] dp=new boolean[1<<N];
			dp[(1<<N)-1]=true;
			for(int i=(1<<N)-1; i>=0; --i)if(dp[i]){
				for(int j=0; j<N; ++j)if((i&(1<<j))>0 && (i&a[j])==0){
					for(int k=j+1; k<N; ++k)if(j!=k && (i&(1<<k))>0 && (i&a[k])==0 && c[j].c==c[k].c){
						int tmp=(1<<j)|(1<<k);
						int next=i&(((1<<N)-1)^tmp);
//						System.out.println(Integer.toBinaryString(i)+" "+Integer.toBinaryString(tmp)+" "+Integer.toBinaryString(next));
						dp[next]=true;
						ans=min(ans, Integer.bitCount(next));
					}
				}
			}
			System.out.println(N-ans);
		}
		class Circle{
			Point2D p;
			double r;
			int c;
			Circle(double x,double y,double r,int c){
				this.p=new Point2D.Double(x,y);
				this.r=r;
				this.c=c;
			}
		}
	}
}

Measured memory_bytes: 223700
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr, tails, sort)
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

isTriangle :: Int -> Int -> Int -> Bool
isTriangle a b c = a < b + c && b < c + a && c < a + b

naive = do
  n <- readLn :: IO Int
  xs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ length [ (a,b,c) | a:xss <- tails xs, b:xsss <- tails xss, c <- xsss, isTriangle a b c ]

-- v は昇順にソートされているとする。
-- count a v は a 以上の要素の個数を数える。
countGE :: Int -> U.Vector Int -> Int
countGE a v | U.null v = 0
            | U.length v == 1 = case compare a (U.head v) of
                                  LT -> 1
                                  EQ -> 1
                                  GT -> 0
            | otherwise = let n = U.length v
                              n2 = n `quot` 2
                          in case compare a (v U.! n2) of
                               LT -> countGE a (U.take n2 v) + n - n2
                               EQ -> countGE a (U.take n2 v) + n - n2
                               GT -> countGE a (U.drop n2 v)

main = do
  n <- readLn :: IO Int
  xs <- mergeSort . U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ sum [ countGE (c_min + 1) ys - countGE c_max ys
              | i <- [0..n-1]
              , let a = xs U.! i
              , j <- [i+1..n-1]
              , let b = xs U.! j
              , let c_min = max (a - b) (b - a)
              , let c_max = a + b {- c < a + b, b - a < c, a - b < c -}
              , let ys = U.drop (j+1) xs
              ]

mergeSortBy :: (U.Unbox a) => (a -> a -> Ordering) -> U.Vector a -> U.Vector a
mergeSortBy !cmp !vec = doSort vec
  where
    doSort vec | U.length vec <= 1 = vec
               | otherwise = let (xs, ys) = U.splitAt (U.length vec `quot` 2) vec
                             in merge (doSort xs) (doSort ys)
    merge xs ys = U.create $ do
      let !n = U.length xs
          !m = U.length ys
      result <- UM.new (n + m)
      let loop !i !j
            | i == n = U.copy (UM.drop (i + j) result) (U.drop j ys)
            | j == m = U.copy (UM.drop (i + j) result) (U.drop i xs)
            | otherwise = let !x = xs U.! i
                              !y = ys U.! j
                          in case cmp x y of
                               LT -> do UM.write result (i + j) x
                                        loop (i + 1) j
                               EQ -> do UM.write result (i + j) x
                                        UM.write result (i + j + 1) y
                                        loop (i + 1) (j + 1)
                               GT -> do UM.write result (i + j) y
                                        loop i (j + 1)
      loop 0 0
      return result

mergeSort :: (U.Unbox a, Ord a) => U.Vector a -> U.Vector a
mergeSort = mergeSortBy compare


Measured memory_bytes: 1020