akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define ll long long int

int main(void)
{
    
    // vector<ll >A(H);
     //vector<ll >B(H);
    string a, b;

    cin >> a;
   

    if (a == "ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }
}

    

Measured memory_bytes: 3592
n,a,b=map(int,input().split())
#整数の数はb-a+1
#最小の１つと最大の1つを除いたn-2個について考える
if n==1 and a!=b:
    print(0)
    exit()
elif n==1 and a==b:
    print(1)
    exit()
elif a>b:
    print(0)
    exit()
elif a==b:
    print(1)
    exit()
m=a*(n-2)#最小
M=b*(n-2)#最大
ans=M-m+1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	string s; cin >> s;
	{
		string t;
		rep(i, s.size()){
			if(i + 1 < s.size() && s[i] == 'B' && s[i + 1] == 'C'){
				t += 'D';
				i++;
			}
			else t += s[i];
		}
		s = t;
	}
	dbg(s);
	ll ans = 0;
	for(int i = s.size() - 1, j = 0; i >= 0; i--){
		if(s[i] != 'A' && s[i] != 'D'){
			j = 0;
		}
		else if(s[i] == 'A') ans += j;
		else j++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define fi first
#define se second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int h,w,n;
int sx,sy;
string s,t;

signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>h>>w>>n;
    cin>>sx>>sy;
    vector<char> s(n),t(n);
    rep(i,n){
        cin>>s.at(i);
    }
    rep(i,n){
        cin>>t.at(i);
    }
    int ssx=sx,ssy=sy;
    //右に落とす！
    rep(i,n){
        if(s.at(i)=='R')sy++;
        if(sy>w){
            cout<<"NO"<<endl;
            return 0;
        }
        if(t.at(i)=='L' and sy>1)sy--;
    }
    sy=ssy;
    //左に落とす！
    rep(i,n){
        if(s.at(i)=='L')sy--;
        if(sy<=0){
            cout<<"NO"<<endl;
            return 0;
        }
        if(t.at(i)=='R' and sy<w)sy++;
    }
    //上に落とす！
    rep(i,n){
        if(s.at(i)=='U')sx--;
        if(sx<=0){
            cout<<"NO"<<endl;
            return 0;
        }
        if(t.at(i)=='D' and sx<h)sx++;
    }
    sx=ssx;
    //下に落とす!
    rep(i,n){
        if(s.at(i)=='D')sx++;
        if(sx>h){
            cout<<"NO"<<endl;
            return 0;
        }
        if(t.at(i)=='U' and sx>1)sx--;
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 640
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
Y,Z=0,0
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
  Y,Z=-1,-10**20
  for j in range(26):
    if Y==-1:
      Y,Z=0,X[0]+S[i][0]
    if Z<X[j]+S[i][j]:
      Y,Z=j,X[j]+S[i][j]
  X[Y]=0
  print(Y+1)

Measured memory_bytes: 68468
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_122
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nq=ReadInts();
            int n = nq[0];
            int q = nq[1];
            string s = Read();
            int[][] lrs = new int[q][];
            for(int i = 0; i < q; i++)
            {
                lrs[i] = ReadInts();
                lrs[i][0]--;
                lrs[i][1]--;
            }
            int[] cnts = new int[n];
            for(int i = 1; i < n; i++)
            {
                cnts[i] = cnts[i - 1];
                if (s[i - 1] == 'A' && s[i] == 'C')
                {
                    if (i > 1)
                    {
                        cnts[i] = cnts[i - 2] + 1;
                    }
                    else
                    {
                        cnts[i] = 1;
                    }
                }
                //Write(cnts[i] + " ");
            }
            //WriteLine();
            for(int i = 0; i < q; i++)
            {
                int val = cnts[lrs[i][1]];
                    val -= cnts[lrs[i][0]];
                WriteLine(val);
            }
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 23236
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) a[i] = 0;

  REP(i,n-1){
    int x; cin >> x;
    --x;
    a[x]++;
  }

  for(auto x: a) cout << x << endl;
  return 0;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    int h1,h2,m1,m2,k;
    cin >>h1>>m1>>h2>>m2>>k;
    int ans;
    ans=(h2-h1)*60+(m2-m1)-k;
    printf("%d",ans);
    return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}

int main() {
	char c;
	std::cin >> c;
	std::cout << (char)(c + 1) << std::endl;
	return 0;
}


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

typedef long long int ll;

int main(){
  string s;
  cin>>s;
  if(s.length()%2==1){
    ll i=0,j=s.length()-1;
    ll flag=0;
    while(i<j){
      if(s[i]!=s[j]){
        flag=1;
        break;
      }
      i++;
      j--;
    }
    if(flag){
      //cout<<"1"<<endl;
      cout<<"No"<<endl;
    }
    else{
      ll len=(s.length()-1)/2;
      string temp=s.substr(0,len);
      i=0;
      j=temp.length()-1;
      flag=0;
      while(i<j){
        if(temp[i]!=temp[j]){
          flag=1;
          break;
        }
        i++;
        j--;
      }
      if(flag){
        //cout<<2<<endl;
        cout<<"No"<<endl;
      }
      else{
        ll n=s.length();
        len=n-((n+3)/2)+1;
        temp=s.substr(((n+1)/2),len);
        i=0;
        j=temp.length()-1;
        flag=0;
        while(i<j){
          if(temp[i]!=temp[j]){
            flag=1;
            break;
          }
          i++;
          j--;

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


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

int main() {
  int N,A;
  cin >> N >> A;
  int a = N%500;
  
  if(A>= a){
    cout << "Yes" << endl;
  } else {
    cout << "No"<< endl;
  }
  
  return 0;
}


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

int main(){
	
	int i,j;
	for(i = 1; i < 10; i++){
		for(j = 1; j < 10; j++){
			printf("%dx%d=%d\n",i,j,(j*i));
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    int soma=0, maior=0,min=0;

    scanf("%d",&n);

    int x[n];

    for(int cont=0;cont<n;++cont){
        scanf("%d",&x[cont]);
        if(x[cont]>maior){
            maior=x[cont];
        }
    }

    for(int cont=0;cont<=maior;++cont){
            soma=0;
        for(int i=0;i<n;++i){
            soma+=((x[i]-cont)*(x[i]-cont));
        }
        if(min==0){
            min=soma;
        }
        if(soma<min){
            min=soma;
        }
    }

    printf("%d\n", min);

    return 0;
}


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

#define forn(i, n)          for(int i = 0; i < n; ++i)
#define MEMSET_INF          127 // ~2B
#define MEMSET_HALF_INF     63  // ~1B

using namespace std;

typedef long long           ll;
typedef vector<int>         vi;
typedef vector<vi>          vvi;
typedef pair<int, int>      ii;
typedef vector<ii>          vii;
typedef set<int>            si;
typedef map<string, int>    msi;

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

    string s, t; cin >> s >> t;
    int count = 0;
    for(int i = 0; i < s.size(); ++i) {
        if(s.at(i) != t.at(i)) ++count;
    }
    printf("%d\n", count);

}

Measured memory_bytes: 3792
from operator import itemgetter

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

PY=[]
for i in range(m):
    PY.append(list(map(int,input().split())))
    PY[i].append(i)

PY.sort()

#print(PY)

no=1
PY[0][1]=1
no=2
for i in range(1,m):
    if PY[i-1][0]!=PY[i][0] :
        no=1
    PY[i][1]=no
    no+=1

PY.sort(key=itemgetter(2))

#print(PY)

for i in range(m):
    aa=str('%06d'%PY[i][0])
    bb=str('%06d'%PY[i][1])
    print(aa+bb)


Measured memory_bytes: 32456
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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 execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    ll H, W, K;
    cin >> H >> W >> K;

    string column[H] = {};
    for(int i = 0; i < H; i++){
        cin >> column[i];
    }

    int count = 0;

    int nx = 1 << W;
    int ny = 1 << H;

    for(unsigned int y = 0; y < ny; y++){
    for(unsigned int x = 0; x < nx; x++){
        int n = 0;
        for(int h = 0; h < H; h++){
        if(y & (1<<h)) continue;
        for(int w = 0; w < W; w++){
            if(x & (1<<w)) continue;
            if(column[h][w] == '#')
            {
                n++;
                if(K < n) goto out;
            }
        }
        }
        if(n == K) count++;
out: ;
    }
    }



    cout << count << endl;
}


Measured memory_bytes: 3640
//include
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>(b);i--)
#define REP(i,n)  FOR(i,0,n)

#define INF (1<<21)

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define VISITED 1
#define NOT_VISITED 0

//typedef
//-------------------------------------------
typedef long long ll;

int g[21][21];
int visited[21];
int d[21];
int n;

int dijkstra(int start) {
    d[start] = 0;

    while(1) {
        int u = -1;
        int tmpd = INF;
        REP(i, n + 1) {
            if (visited[i] == NOT_VISITED) {
                if (tmpd > d[i]) {
                    u = i;
                    tmpd = d[i];
                }
            }
        }
        if (u < 0) break;
        visited[u] = VISITED;

        REP(i, n + 1) {
            if (g[u][i] != INF && visited[i] == NOT_VISITED) {
               if ((d[u] + g[u][i]) < d[i]) {
                   d[i] = d[u] + g[u][i];
               }
            }
        }
    }
    return 1;
}

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

    REP(i, 21) REP(j, 21) g[i][j] = INF;
    int m;
    cin >> n;
    cin >> m;
    REP(i, m) {
        string str;
        cin >> str;
        stringstream ss(str);
        string buf;
        vector<int> tmp;
        while (getline(ss, buf, ',')) {
            tmp.push_back(stoi(buf));
        }
        int a = tmp[0];
        int b = tmp[1];
        int c = tmp[2];
        int d = tmp[3];

        g[a][b] = c;
        g[b][a] = d;
    }

    string str;
    cin >> str;
    stringstream ss(str);
    string buf;
    vector<int> tmp;
    while (getline(ss, buf, ',')) {
        tmp.push_back(stoi(buf));
    }
    int s = tmp[0];
    int goal = tmp[1];
    int v = tmp[2];
    int p = tmp[3];

    REP(i, 21) visited[i] = NOT_VISITED;
    REP(i, 21) d[i] = INF;
    dijkstra(s);
    int up = d[goal];

    REP(i, 21) visited[i] = NOT_VISITED;
    REP(i, 21) d[i] = INF;
    dijkstra(goal);
    int down = d[s];

    cout << v - p - (up + down) << endl;

    return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

ll modPow(const ll a, const ll n, const ll p)
{
    if (n == 1) return a % p;
    if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    ll num = modPow(a, n / 2, p);
    return (num * num) % p;
}

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    
    ll sumAll = modPow(2, n, MOD);
    sumAll = sumAll == 0 ? MOD - 2 : sumAll - 1;

    ll aX = 1, aY = 1;
    REP(i, a)
    {
        aX = aX * (n - i);
        aX = aX % MOD;
        aY = aY * (a - i);
        aY = aY % MOD;
    }
    // フェルマーの小定理
    ll aYinv = modPow(aY, MOD - 2, MOD);
    ll aMod = (aX * aYinv) % MOD;

    ll bX = 1, bY = 1;
    REP(i, b)
    {
        bX = bX * (n - i);
        bX = bX % MOD;
        bY = bY * (b - i);
        bY = bY % MOD;
    }
    // フェルマーの小定理
    ll bYinv = modPow(bY, MOD - 2, MOD);
    ll bMod = (bX * bYinv) % MOD;
    
    ll ans = sumAll - aMod;
    ans = ans < 0 ? ans + MOD : ans;
    ans = ans - bMod;
    ans = ans < 0 ? ans + MOD : ans;

    cout << ans << endl;
}


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

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

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

    sort(A.begin(), A.end());

    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if((A[j] - A[i]) % (n - 1) == 0){
                cout << A[i] << ' ' << A[j] << endl;
                return 0;
            }
        }
    }


    return 0;
}


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

#define MAX (7368791+1)

using namespace std;

bool a[MAX];

int main(void) {
	int m, n;
	while (cin >> m >> n, m || n) {
		fill(a, a+MAX, true);
		int count = 0;
		for (int i = m; i < MAX; i++) {
			if (a[i] == true) {
				if (count == n) {
					cout << i << endl;
					break;
				}
				count++;
				for (int j = i + i; j < MAX; j += i) {
					a[j] = false;
				}
			}
		}
	}
	return 0;
}


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

int main(){
    int N;
    cin>>N;
    vector<int> dp(N+1);
    dp[0]=0;
    for(int i=1;i<=N;i++){
        int one=dp[i-1]+1;
        int six;
        int s=6;
        while(i-s>=0){
            s*=6;
        }
        s/=6;
        six=dp[i-s]+1;
        int nine;
        int n=9;
        while(i-n>=0){
            n*=9;
        }
        n/=9;
        nine=dp[i-n]+1;
        dp[i]=min(one,min(six,nine));
    }
    cout<<dp[N]<<endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        long n = nl(), m = nl();

        long ans = 0;

        long simple = Math.min(n, m / 2);
        ans += simple;
        n -= simple;
        m -= simple * 2;

        ans += m / 4;

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

int main(void){
    int N,K;
    int ans=1;
    int cnt=0;
    cin>>N>>K;

    int sum=K-1;

    while(cnt<N){//操作A
        sum=ans*2;
        if(ans>=K)
            break;
        ans=sum;
        cnt++;
    }

    for(int i=0;i<N-cnt;i++){
        ans+=K;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#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++)
using namespace std;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a, b; cin >> a >> b;
    if (a >= 1 && a <= 9 && b >= 1 && b <= 9 ) cout << a * b << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld %lld",&n,&k);
  result = k * (ll)powl(k-1,n-1);
  printf("%lld",result);
  
  return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  int x,a,b;
  cin >> x >> a >> b;
  int d1 = abs(x-a);
  int d2 = abs(x-b);
  int d = min(d1,d2);
  if(d==d1)
    cout << "A" << endl;
  else
    cout << "B" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

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

    switch(d){
        case 25:
            cout << "Christmas" << endl;
            break;
        case 24:
            cout << "Christmas Eve" << endl;
            break;
        case 23:
            cout << "Christmas Eve Eve" << endl;
            break;
        case 22:
            cout << "Christmas Eve Eve Eve" << endl;
            break;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	string S; cin >> S;
	cout << S.substr(0, S.size() - 8) << endl;
	return 0;
}

Measured memory_bytes: 3604
mod = 10**9+7
n, m = list(map(int, input().split()))
dp = [0]*(n+1)
dp[0] = 1
ok = [1]*(n+1)
for i in range(m):
    a = int(input())
    ok[a] = 0

for i in range(n):
    if not ok[i]:
        continue
    for j in range(1,3):
        if i+j <= n:
            dp[i+j] = (dp[i+j] + dp[i])%mod

print(dp[-1])

Measured memory_bytes: 7788
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
template<typename weight_t> using graph = vector<vector<pair<int,weight_t>>>;
bool dfs(const graph<int> &g,const vector<int> &x,vector<int> &val,const int i=1){
    //st[i]=iを和として実現できるか
    bitset<5001> st;
    st[0]=1;
    //子をすべて調べる
    loop(itr,g[i].size()){
        int j=g[i][itr].first;
        if(j<i)continue;//親
        if(!dfs(g,x,val,j))return false;
        //x[j]かval[j]をそれぞれの子について足し合わせる必要がある
        st=(st<<x[j])|(st<<val[j]);
    }
    //st[x[i]],st[x[i-1]],...,st[0]のうち最初に実現できる（st[k]==1となる）kを取る
    int k=x[i];
    while(k>=0&&st[k]==0)--k;
    if(k<0)return false;
    //このときsum_{j:iの子}(x[j]とval[j]の適切な方をひとつ)=k なので、
    //（選ばなかった方の和）= sum_{j:iの子}(x[j]+val[j])-k がなりたち、これが最小である。
    //つまり、x[i]-kを頂点iに書けば条件を満たすことができ、val[i]=sum_{j:iの子}(x[j]+val[j])-k
    int sum=-k;
    loop(itr,g[i].size()){
        int j=g[i][itr].first;
        if(j<i)continue;//親
        sum+=x[j]+val[j];
    }
    val[i]=sum;
    return true;
}
int main(){
    int n;
    cin >> n;
    graph<int> g(n+1);
    vector<int> x(n+1);
    rep(i,2,n+1){
        int p;
        cin >> p;
        g[i].push_back({p,1});
        g[p].push_back({i,1});
    }
    rep(i,1,n+1)cin >> x[i];
    //val[j]=(自分と違う色の子が持っている数の和の最小値)
    vector<int> val(n+1);
    cout << (dfs(g,x,val)?"POSSIBLE":"IMPOSSIBLE") << endl;
    return 0;
}

Measured memory_bytes: 1664
n = int(input())
a = list(map(int, input().split()))
b = [i for i in range(1, n+1)]
list_score = [list(e) for e in zip(a, b)]

list_score.sort()

ans = []

for i in range(n):
    ans.append(list_score[i][1])

print(*ans)

Measured memory_bytes: 26020
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


int main(){
    int K;string S;
    cin >> K >> S;
    int length= S.length();
    int len = min(K,length);
    rep(i,len) {
        cout << S[i];
    }

    

    if(K<length) {
        cout  << "..." << endl;
    }else {
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3540
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];

int check(llong P){
    int i = 0;
    for (int j=0; j < k; j++){
        llong s = 0;
        while(s + T[i] <= P){
            s += T[i];
            i++;
            if (i == n) return n;
        }
    }
    return i;
}

int solve(){
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while( right - left > 1){
        mid = (left + right) / 2;
        int v = check(mid);
        if ( v >= n ) right = mid;
        else left = mid;
    }
    
    return right;
}

main(){
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> T[i];
    llong ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3872
#!/usr/bin/python
# -*- coding: utf-8 -*-

import numpy as np

def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return np.array(x)

N = int(input())
A = list(map(int,input().split()))

money = 1000
stock = 0

for i in range(0,N-1):
    
    if A[i] < A[i+1]:
        stock = stock + money//A[i]
        money = money - (money//A[i])*A[i]
    else:
        money = money + stock*A[i]
        stock = 0

if stock > 0:
    money = money + stock*A[N-1]
print(money)




Measured memory_bytes: 27048
import itertools

n,m = map(int, input().split())
edge_set = {tuple(map(int, input().split())) for _ in range(m)}
counter = 0

for i in itertools.permutations(range(2, n+1), n-1):
  path = [1] + list(i)
  path_set = {tuple(sorted(edge)) for edge in zip(path, path[1:])}
  
  if path_set <= edge_set:
    counter += 1
 
  
print(counter)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
long N;
main()
{
	cin>>N;
	long ans=N*(N+1)*(N+2)/6;
	for(int i=1;i<N;i++)
	{
		long u,v;cin>>u>>v;
		ans-=min(u,v)*(N-max(u,v)+1);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sq(x) ((x)*(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<"\n"
#define fi first
#define se second
const double pi = 3.14159265358979323846;
#define uni(c) (c).resize(unique(all(c))-(c).begin())
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};   // for matrix movement:
void cp()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
void solve()
{
	ll n; cin >> n;
	ll a[n];
	fo(i, n) {
		cin >> a[i];
	}
	if (n == 1) {
		cout << "0";
		return;
	}
	sort(a, a + n, greater<int>());
	ll ans = a[0];
	ll c = 2;
	for (int i = 1; i < n; i++)
	{
		if (n - c >= 2)
		{
			ans += 2 * a[i];
			c += 2;
		}
		else {
			if (c < n)
				ans += a[i];
			c++;
			break;
		}

	}
	cout << ans;

}
int main()
{
	fast;
	//cp();
	ll t = 1;
	//cin >> t;
	while (t--)
		solve();


	return 0;
}

Measured memory_bytes: 5220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    double t = 0.5 * w * h;

    printf("%.12f %d\n", t, (x * 2 == w && y * 2 == h));

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unsigned long long int ull;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;

vector<ll> fac(10000000),inv(10000000),finv(10000000);
void initCOM(){
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(int i=2;i<10000000;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<0||k<0) return 0;
    if(n-k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
vector<ll> prime_factor(ll m){
    vector<ll> res;
    for(int i=2;i*i<=m;i++)if(m%i==0){
        ll cnt=0;
        while(m%i==0){
            m/=i;
            cnt++;
        }
        res.push_back(cnt);
    }
    if(m>1) res.push_back(1);
    return res;
}
int main(){
    initCOM();
    ll n,m;cin>>n>>m;
    auto p=prime_factor(m);
    ll ans=1;
    for(auto b:p){
        ans=ans*COM(b+n-1,n-1)%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 237508
#include<iostream>
using namespace std;
int func(int a,int b,int c);
int ball[10];

int main(){
  int n;
  cin >> n;
  while(n--){
    for(int i=0;i<10;i++) cin >> ball[i];
    if(func(0,0,0) != 0) cout << "YES\n";
    else cout << "NO\n";
  }
}
int func(int a,int b,int c){
  int ans=0;
  if(a == 10) return 1;
  if(ball[a]>b) ans += func(a+1,ball[a],c);
  if(ball[a]>c) ans += func(a+1,b,ball[a]);
  return ans;
}
  

Measured memory_bytes: 1124
import java.util.Scanner;

class Main {

	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);

        // 1
		// String s = scanner.next();
		// System.out.println((s.length() == 6 && s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) ? "Yes" : "No");
        
        // 2
        int x = scanner.nextInt();
        int res = x / 500 * 1000 + x % 500 / 5 * 5;
        System.out.println(res);
        scanner.close();
	}
}

Measured memory_bytes: 23508
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_CREATE_MAX	100000									// 最大生物数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Create[D_CREATE_MAX];								// 生物
static int siCCnt;												// 生物数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// ソート関数 - int昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int *lipVal1 = (int *)pzpVal1;
	int *lipVal2 = (int *)pzpVal2;

	// 昇順
	if (*lipVal1 > *lipVal2) {
		return(1);
	}
	else if (*lipVal1 < *lipVal2) {
		return(-1);
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 生物数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siCCnt);

	// 生物 - 取得
	for (i = 0; i < siCCnt; i++) {
		fscanf(szpFpI, "%d", &si1Create[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 生物 - ソート
	qsort(si1Create, siCCnt, sizeof(int), fSortFnc);

	// サイズ・色数 - 初期値
	long long llSize = si1Create[0];
	int liCnt = 1;

	// サイズ・色数 - 取得
	for (i = 1; i < siCCnt; i++) {
		if (llSize * 2 < si1Create[i]) {
			liCnt = 1;
		}
		else {
			liCnt++;
		}
		llSize += si1Create[i];
	}

	// 結果 - セット
	sprintf(lc1Out, "%d\n", liCnt);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 892
// Nurbakyt Madibek
// Look at my code! IT'S AWESOME

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)1e5 + 5;
const int mod = (int)1e9 + 7;

int n, m;
char a[105][105];

int moves[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};

int dfs(int x, int y) {
    if (x == n && y == m) {
        return 1;
    }
    int cnt = 0;
    for (int i = 0; i < 2; i++) {
        int nx = x + moves[i][0], ny = y + moves[i][1];
        if (nx > 0 && nx <= n && ny > 0 && ny <= m && a[nx][ny] == '#') {
            cnt++;
        }
    }
    if (cnt != 1) {
        return -1;
    }
    for (int i = 0; i < 2; i++) {
        int nx = x + moves[i][0], ny = y + moves[i][1];
        if (nx > 0 && nx <= n && ny > 0 && ny <= m && a[nx][ny] == '#') {
            int res = dfs(nx, ny);
            if (res == -1)
                return res;
            return res + 1;
        }
    }
    assert(0);
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    int v = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            if (a[i][j] == '.')
                continue;
            v++;
        }
    if (a[1][1] == '#' && a[n][m] == '#' && dfs(1, 1) == v) {
        puts("Possible");
    }
    else
        puts("Impossible");
    return 0;
}


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

using namespace std;

void solve(long long N, long long K, std::vector<long long> t,
           std::vector<long long> d) {
    vector<pair<long long, long long> > vs;
    for (int i = 0; i < N; i++) {
        vs.push_back({d[i], t[i]});
    }
    sort(vs.rbegin(), vs.rend());
    for(int i = 0 ; i < vs.size() ; i++)
        swap(vs[i].first, vs[i].second);
    long long tot = 0;
    set<long long> ts;
    vector<long long> remCand;
    for (int i = 0; i < K; i++) {
        if (!ts.count(vs[i].first)) {
            ts.insert(vs[i].first);
        } else {
            remCand.push_back(vs[i].second);
        }
        tot += vs[i].second;
    }
    sort(remCand.rbegin(), remCand.rend());

    long long ans = tot + 1ll * ts.size() * ts.size();
    for(int i = K ; i < N ; i++){
        if( !ts.count(vs[i].first) && remCand.size() > 0 ){
            tot += vs[i].second;
            tot -= remCand.back();
            remCand.pop_back();
            ts.insert(vs[i].first);
            ans = max<long long>(tot + 1ll * ts.size() * ts.size(), ans);
        }
    }
    cout << ans << endl;


}

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> t(N);
    std::vector<long long> d(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &t[i]);
        scanf("%lld", &d[i]);
    }
    solve(N, K, std::move(t), std::move(d));
    return 0;
}


Measured memory_bytes: 6768
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin>>n;
	if(n<=111){
		cout<<111<<endl;
	}else if(n<=222){
		cout<<222<<endl;
	}else if(n<=333){
		cout<<333<<endl;
	}else if(n<=444){
		cout<<444<<endl;
	}else if(n<=555){
		cout<<555<<endl;
	}else if(n<=666){
		cout<<666<<endl;
	}else if(n<=777){
		cout<<777<<endl;
	}else if(n<=888){
		cout<<888<<endl;
	}else if(n<=999){
		cout<<999<<endl;
	}
	return 0;
}



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


int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N+1);
    REP(i,1, N+1) cin >> A[i];
    REP(i,K+1,N+1){
        if(A[i-K] < A[i]) cout << "Yes" << endl;
        else if(A[i-K] >= A[i]) cout << "No" << endl;
    }
}

Measured memory_bytes: 4840
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	string A,B,C,a,b,c;
	cin >> A >> B >> C;
	char x='a';
	a=A;
	b=B;
	c=C;
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	reverse(c.begin(),c.end());
	while (A.length()>=0 && B.length()>=0 && C.length()>=0) {
		if (x=='a') {
			if (a.length()!=0) {
				x=a[a.length()-1];
				a.pop_back();
			}
			else {
				cout << "A";
				break;
			}
		}
		if (x=='b') {
			if (b.length()!=0) {
				x=b[b.length()-1];
				b.pop_back();
			}
			else {
				cout << "B";
				break;
			}
		}
		if (x=='c') {
			if (c.length()!=0) {
				x=c[c.length()-1];
				c.pop_back();
			}
			else {
				cout << "C";
				break;
			}
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void dijkstra(const Graph &g, int s,
                  vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}

vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u])
    path.push_back(u);
  reverse(path.begin(), path.end());
  return path;
}


typedef complex<double> P;
typedef pair<int, P> PA;

int main() {
  int n ;
  while(cin>>n,n) {
    vector<PA> v;
    map<int,int> mp;
    Graph g(n);
    REP(i,n) {
      int b,x,y;
      cin >> b >> x >> y;
      P a = P(x,y);
      REP(j,v.size()) {
        int id = (v[j]).first;
        P p = (v[j]).second;
        if (abs(a-p) <= 50) {
          g[i].push_back(Edge(i,j,abs(a-p)));
          g[j].push_back(Edge(j,i,abs(a-p)));
        }
      }
      mp[b] = i;
      v.push_back(PA(b,a));
    }
    int m;
    cin >> m;
    while(m--) {
      int s,t;
      cin >> s >> t;
      vector<int> dist, prev;
      dijkstra(g,mp[s],dist,prev);
      if (dist[mp[t]] == INF) {
        cout << "NA" << endl;
      } else {
        vector<int> path = buildPath(prev,mp[t]);
        REP(i,path.size()) {
          if (i) cout << " ";
          cout << v[path[i]].first;
        }
        cout << endl;
      }
    }
    
  }
}

Measured memory_bytes: 0
def solve():
    [N,A,B] = [int(n) for n in input().split()]
    X = [int(x) for x in input().split()]
    
    ans = 0

    for i in range(1, N):
        ans += min(A * abs(X[i]-X[i-1]), B)

    return ans


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
    int a,b,c,k; cin >> a >> b>> c >> k;
    ll ans = 0;
    ans += min(a, k);
    k -= min(a, k);
    if(k>0){
      k -= b;
      if(k>0){
        ans -= min(k, c);
      }

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


Measured memory_bytes: 3628
#include <stdio.h>
#define M 1000000007

int
main(int argc, char *argv[])
{
  char s[1000001] = {}; int n;
  scanf("%d", &n);
  scanf("%s", s);

  int d[100] = {};
  int i = 0; int cnt = 0;
  while(s[i] != 0){
    if(d[s[i] - 'a'] == 0) cnt++;
    d[s[i] - 'a']++;
    i++;
  }

  unsigned long long ans = (1 << cnt) % M, temp;
  
  for(int j = 0; j < 26; j++){
    if(d[j] != 0){
      temp = (ans * ((M + 1)/2)) % M;
      ans = ((1 + d[j]) * temp) % M;
    }
  }

  printf("%llu\n", ans - 1);
  

  return 0;
}
 

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

void bubbleSort(int *array, int N) {
    int cnt = 0;
    while (true) {
        bool is_sorted = true;
        for (size_t i = N - 1; i >= 1; i--) {
            if (array[i] < array[i - 1]) {
                int temp = array[i];
                array[i] = array[i - 1];
                array[i - 1] = temp;
                is_sorted = false;
                cnt++;
            }
        }
        if (is_sorted)
            break;
    }

    for (int i = 0; i < N; i++) {
        cout << array[i] << ((i != N - 1) ? " " : "\n");
    }
    cout << cnt << endl;
}

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

    int n;
    cin >> n;
    int *array = new int[n];
    rep(i, n) cin >> array[i];
    bubbleSort(array, n);
}



Measured memory_bytes: 3168
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = (1 << 31) - 1;


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vector<vector<ll>> dp(n+1);
	rep(i, n+1) {
		dp[i].resize(5);
		rep(j, 5) {
			dp[i][j] = pow(inf,2);
		}
	}
	rep(j, 5) {
		dp[0][j] = 0;
	}
	rep(i, n) {
		rep(j, 5) {
			ll base = inf;
			rep(k, j + 1) {
				base = min(base, dp[i][k]);
			}
			ll add = 0;
			if (j == 0 || j == 4)add = a[i];
			if (j == 1 || j == 3) {
				if (a[i] == 0) add = 2;
				else add=(a[i] % 2 ? 1 : 0);
			}
			if (j == 2) {
				if (a[i] == 0) add = 1;
				else add = (a[i] % 2 ? 0 : 1);
			}
			dp[i + 1][j] = base + add;
		}
	}
	ll ans = pow(inf,2);
	rep(i, 5) {
		ans = min(ans, dp[n][i]);
	}
	cout << ans << endl;
	return 0;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    // 後ろから解くかわりにすべての文字列を「左右反転」する
    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    // 端から切っていく
    bool can = true;
    for (int i = 0; i < S.size();) {
        bool can2 = false; // 4 個の文字列たちどれかで divide できるか
        for (int j = 0; j < 4; ++j) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) { // d で divide できるか
                can2 = true;
                i += d.size(); // divide できたら i を進める
            }
        }
        if (!can2) { // divide できなかったら
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

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

int main(){
    int n;
    cin >> n;
    int a0,a1;
    cin >> a0 >> a1;
    int max = gcd(a0,a1);
    for(int i = 2; i < n; i++){
        int ai;
        cin >> ai;
        max = gcd(max, ai);
    }
    cout << max << endl;
}



Measured memory_bytes: 256