akhauriyash/Code-Regression huggingface dataset:
// E - Two Currencies

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

const int MAX_N = 50;
const int MAX_COIN = 2500;
const ll INF = 9223372036854775807;
const int UNCONF = 0;
const int CONF = 1;

using IDX = pair<int, int>; //（都市番号, 所持する銀貨の数）をNodeのindexとする

struct Edge {
	pair<int, int> to;
	ll cost;
};

struct Node {
	vector<Edge> edges;
	int status;
	ll min_cost;
};

// ダイクストラ法（優先度付きキューを使用）
// n: ノード数, start_idx: 開始ノードのインデックス
void Dijkstra(Node nodes[MAX_N][MAX_COIN + 1], int n, IDX start_idx) {
	for (int i=0; i<n; i++) {
		for (int j=0; j<=MAX_COIN; j++) {
			nodes[i][j].status = UNCONF;
			nodes[i][j].min_cost = INF;
		}
	}

	nodes[start_idx.first][start_idx.second].min_cost = 0;

	// PQ: <コスト, ノード番号>のpairを格納する優先度付きキュー（コストが大きいもの優先）
	// ノード番号は（都市番号, 所持する銀貨の数）のpair
	priority_queue<pair<ll, IDX>, vector<pair<ll, IDX>>, greater<pair<ll, IDX>>> PQ;
	PQ.push(make_pair(0, start_idx));

	while (!PQ.empty()) {
		pair<ll, IDX> p = PQ.top();
		PQ.pop();
		ll cost = p.first;
		Node& node = nodes[p.second.first][p.second.second];

		if (cost > node.min_cost) continue; // 他にコストの低いルートが見つかったので使わない

		node.status = CONF;

		for (Edge edge : node.edges) {
			Node& next_node = nodes[edge.to.first][edge.to.second];
			ll next_cost = (edge.cost == INF) ? INF : node.min_cost + edge.cost;
			if (next_node.status != CONF) {
				if (next_cost < next_node.min_cost) {
					next_node.min_cost = next_cost;
					PQ.push(make_pair(next_cost, edge.to));
				}
			}
		}
	}
}

Node nodes[MAX_N][MAX_COIN + 1]; // nodes[都市番号(0-index)][所持する銀貨の数]
int U[100], V[100], A[100], B[100];
int C[50], D[50];

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

	for (int i=0; i<M; i++) {
		cin >> U[i] >> V[i] >> A[i] >> B[i];
		U[i]--;
		V[i]--;
	}

	for (int i=0; i<N; i++) {
		cin >> C[i] >> D[i];
	}

	// 都市間の移動の辺を張る
	for (int i=0; i<M; i++) {
		for (int j=A[i]; j<=MAX_COIN; j++) {
			nodes[U[i]][j].edges.push_back(Edge{make_pair(V[i], j-A[i]), B[i]});
			nodes[V[i]][j].edges.push_back(Edge{make_pair(U[i], j-A[i]), B[i]});
		}
	}

	// 銀貨の補充の辺を張る
	for (int i=0; i<N; i++) {
		for (int j=0; j<=MAX_COIN; j++) {
			nodes[i][j].edges.push_back(Edge{make_pair(i, min(MAX_COIN, j+C[i])), D[i]});
		}
	}

	// ダイクストラ法を実行
	Dijkstra(nodes, N, make_pair(0, min(MAX_COIN, S)));

	// 結果の表示
	for (int i=1; i<N; i++) {
		ll ans = INF;
		for (int j=0; j<=MAX_COIN; j++) {
			ans = min(ans, nodes[i][j].min_cost);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 24764
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
const ll N = 1e5 + 1;
typedef pair<ll,ll> LL;
LL a[3*N];
ll u,v,n,q,i,dp[1024][N];
ll gen(ll x,ll y){
    if(x<1024) return dp[x][y];
    ll ans=gen(x/2,y);
    if(a[x].second<=y){
    	ans=max(ans,a[x].first+gen(x/2,y-a[x].second));
	}
    return ans;
}
int main(){
	cin>>n;
    for (i=1;i<=n;i++){
    	cin>>a[i].first>>a[i].second;
	}
    for(i=1;i<1024;i++){
        for (ll j=1;j<N;j++){
            dp[i][j]=dp[i/2][j];
            if(j>=a[i].second){
            	dp[i][j]=max(dp[i][j],a[i].first+dp[i/2][j-a[i].second]);
			} 
        }
    }
    cin>>q;
    while(q--){
        cin>>u>>v;
        cout<<gen(u,v)<<endl;
    }
}

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

N = int(input())
S = input().rstrip('\r\n')
counts = [0] * N
count = 0
for i, s in enumerate(S):
    counts[i] += count
    if s == 'W':
        count += 1
count = 0
for i, s in enumerate(S[::-1]):
    counts[N-1-i] += count
    if s == 'E':
        count += 1
ans = min(counts)
print(ans)

Measured memory_bytes: 15476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<pr> vp;
typedef vector<vp> vpp;
typedef vector<vector<ll> > graph;
#define pb push_back
#define mp make_pair
#define endl '\n'
void set_val(vector<ll>& v, ll val){for(ll i=0;i<v.size();i++) v[i]=val;}

ll mod = pow(10,9) + 7;
ll modulo = 998244353;
double pi = 3.141592653589793238;
ll i_mov[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
ll j_mov[8] = {1, 1, 1, 0, -1, -1, -1, 0};


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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout<<setprecision(10);
    int a,b ,c ,d;
    cin>>a>>b>>c>>d;
    int t = c/b;
    if(c%b) t++;
    int l = a/d;
    if(a%d) l++;
    if(t<=l) cout<<"Yes";
    else
    cout<<"No";
    
    
} 

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] L = new long[N+1];
        L[0] = 2;
        L[1] = 1;
        for(int i = 2; i <= N; i++) {
            L[i] = L[i-1] + L[i-2];
        }
        System.out.println(L[N]);
    }
}

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

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

  int prefix = 0;
  int level = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '(') {
      ++level;
    } else {
      if (--level < 0) {
        level = 0;
        ++prefix;
      }
    }
  }
  cout << string(prefix, '(') << s << string(level, ')') << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char str[64];
	int i, a, b, c, d;
	
	a = b = c = d = 0;
	
	scanf("%s", str);
	for (i = 0; str[i] != '\0'; i++){
		if (str[i] >= '0' && str[i] <= '9'){
			b = 1;
		}
		else if (str[i] >= 'A' && str[i] <= 'Z'){
			c = 1;
		}
		else if (str[i] >= 'a' && str[i] <= 'z'){
			d = 1;
		}
	}
	
	if (i >= 6){
		a = 1;
	}
	
	if (a && b && c && d){
		puts("VALID");
	}
	else {
		puts("INVALID");
	}
	
	return (0);
}

Measured memory_bytes: 524
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define pb push_back
#define mp make_pair
#define err(x) cout<<#x<<"= "<<x<<endl;
#define rep(i,n) for(int i =0; i< n; i++)
#define ff first
#define ss second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 100010

vi visited;
vi timr,scc,par;
vi llist[SIZE];
int ans,t;
int dfs(int v){
	visited[v] = 1;
	timr[v] = t++;
	scc[v] = t-1;
	rep(i,llist[v].size()){
		int nxt = llist[v][i];
		if(nxt == par[v]);
		else if(!visited[nxt]){
			par[nxt] = v;
			int ret = dfs(nxt);
			if(ret> timr[v])
				ans++;
			scc[v] =  min(scc[v],scc[nxt]);
		}
		else{
			scc[v] = min(scc[v] , scc[nxt]);
		}
	}
//	cout<<v<< ' '<<scc[v]<<' '<<timr[v]<<endl;
	return scc[v];
}


int main(){
	ios::sync_with_stdio(false);
	ans = 0;
	t=0;
	int n,m;
	cin>>n>>m;
	visited.assign(n,0);
	scc.assign(n,0);
	par.assign(n,-1);
	timr.assign(n,0);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		llist[a].pb(b);
		llist[b].pb(a);
	}
	dfs(0);
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 2688
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define v vector
#define ALL(x) x.begin(),x.end()
#define rALL(x) x.rbegin(),x.rend()
#define endl '\n'
#define F first
#define S second
#define DEBUG

template<typename T> void DBG(const char* name, T&& H) {
	cerr << name << " = " << H << ')' << endl;
}

template<typename T, typename... Args> void DBG(const char* names, T&& H, Args&&... args) {
	const char* NEXT = strchr(names+1, ',');
	cerr.write(names, NEXT-names) << " = " << H << " |";
	DBG(NEXT+1, args...);
}

#ifdef DEBUG
	#define dbg(...) cerr << __FUNCTION__ << ' ' <<__LINE__ << " : (", DBG(#__VA_ARGS__, __VA_ARGS__)
#else
	#define dbg(...)
#endif

using ll = long long;
using ld = long double;

const long long mod = 998244353;
const long double PI = acos(-1.0);
const long long INF = 1e18;
const int maxN = 2e5+1;

void Solve() {
	int N, count = 0;
	cin >> N;
	string s;
	cin >> s;
	vector<int> red;
	for(int i = 0; i < s.size(); i ++) {
		if(s[i] == 'R') red.push_back(i);
	}
	int limit = red.size();
	for(int i = 0; i < limit; i ++) {
		if(s[i] == 'R') continue;
		count ++;
		s[i] = 'R';
		s[red.back()] = 'W';
		red.pop_back();
	}
	cout << count << endl;
}

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

	int tt = 1;
	while(tt --) {
		Solve();
	}
	
	return 0;
}

Measured memory_bytes: 4436
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        long sum = 0;
        HashMap<Long, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i ++ ) {
            A[i] = sc.nextLong();
        }

        for (int i = 0; i < N; i ++ ) {
            sum += A[i];
            map.put(A[i], map.getOrDefault(A[i], 0) + 1);
        }

        int T = sc.nextInt();

        while (T > 0) {
            long B = sc.nextLong();
            long C = sc.nextLong();


            if (map.containsKey(B)) {
                int countB = map.get(B);
                sum -= countB * B;


                sum += countB * C;
                map.put(C, map.getOrDefault(C, 0) + countB);
                map.remove(B);
            }
            System.out.println(sum);


            T -- ;
        }

    }
}


Measured memory_bytes: 67156
#include <stdio.h>

#define WHITE 1
#define GRAY 0
#define BLACK -1

void dfs(void);
void visit(int);

int f[102],d[102],color[102],time,n,vv[102][102],k[102];

int main()
{
  int i,j,u;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&u);

    scanf("%d",&k[u]);

    for(j=0;j<k[u];j++){
      scanf("%d",&vv[u][j]);
    }
  }

  dfs();

  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }

  return 0;
}

void dfs(void){
  int u;
  for(u=1;u<=n;u++){
    color[u] = WHITE;
    time = 0;
  }
  for(u=1;u<=n;u++){

    if(color[u] == WHITE) visit(u);
  }
}

void visit(int u){
  int i,v;
  color[u] = GRAY;
  d[u] = ++time;
  for(i=0;i<k[u];i++){
    v=vv[u][i];
    if(color[v] == WHITE) visit(v);
  }
  color[u] = BLACK;
  f[u] = ++time;   
}
 

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

using namespace std;
int main()
{
    int n,n1;
    cin>>n>>n1;int val=0;
    for(int i=0;i<n;i+=1){
        val = val*10+n1;
    }
    int v=0;
    for(int i=0;i<n1;i+=1){
        v = v*10+n;
    }
    if(v>val) cout<<v<<endl;
    else if(v==val) cout<<v<<endl;
    else cout<<val<<endl;


    return 0;
}


Measured memory_bytes: 256
//
//  ALDS1_2_C.cpp
//  
//
//  Created by ?¢¨????????£??? on 2015/11/24.
//
//

#include <stdio.h>
#include <iostream>
using namespace::std;

struct Card{
    char suit;
    char value;
};

void checkStable(Card A1[], Card A2[], int N){
    int stable_flg = 1;

    for (int i = 0; i < N; i++) {
        if (A1[i].suit != A2[i].suit) {
            stable_flg = 0;
        }
    }

    if (stable_flg) {
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
}

void printArray(Card A[], int N){
    for (int i = 0; i < N; i++) {
        cout << A[i].suit << A[i].value;
        if(i != N-1){
            cout << " ";
        }
    }
    cout << endl;
}

void bubbleSort(Card A[], int N){
    int flag = 1;
    int cnt = 0;
    while (flag) {
        flag = 0;
        for (int j = N-1; j > 0; j--) {
            if (A[j].value < A[j-1].value) {
                swap(A[j], A[j-1]);
                flag = 1;
                cnt++;
            }
        }
    }
    
}

void selectionSort(Card A[], int N){
    int flag = 0;
    int cnt = 0;
    int minj;
    for (int i=0; i<N; i++) {
        minj = i;
        flag = 0;
        for (int j=i; j<N; j++) {
            if (A[minj].value > A[j].value) {
                minj = j;
                flag = 1;
            }
            
        }
        if (flag)cnt++;
        
        swap(A[minj], A[i]);
    }
}



int main(int argc, const char * argv[]) {
    int n;
    Card C1[100], C2[100], C3[100], C4[100];
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> C1[i].suit >> C1[i].value;
        C2[i] = C1[i];
    }

    
    bubbleSort(C1, n);
    selectionSort(C2,n);
    printArray(C1, n);
    cout << "Stable" << endl;
    printArray(C2, n);
    checkStable(C1, C2, n);
    return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(long long N, long long Z, long long W, std::vector<long long> a){
    if(N==1)cout<<abs(a[N-1]-W)<<endl;
    else cout<<max(abs(a[N-1]-W),abs(a[N-2]-a[N-1]))<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long Z;
    scanf("%lld",&Z);
    long long W;
    scanf("%lld",&W);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    func(N, Z, W, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;using int32=int_fast32_t;using uint32=uint_fast32_t;using int64=int_fast64_t;using uint64=uint_fast64_t;using pi=pair<int32,int32>;using pll=pair<int64,int64>;using vi=vector<int32>;using vvi=vector<vector<int32>>;using vll=vector<int64>;using ll=int64;using ull=uint64;
#define all(x) x.begin(),x.end()
inline ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int ans=0;
    char c=getchar();
    while(c>='!'&&c<='~'){
        int m=0;
        while(c=='T'||c=='A'||c=='G'||c=='C'){
            m++;
            c=getchar();
        }
        ans=max(ans,m);
        c=getchar();
    }
    printf("%d",ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll a,b;
	rl2(a,b);
	ll g=__gcd(a,b);
	ll ans=a*b/g;
	wl(ans);
	NL;
	return 0;
}

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &v : a) {cin >> v; --v;}
    int ans = 0;
    for (int i = 0; i < n;)
    if (a[i] == i) {
        int j = i;
        while (j < n && a[j] == j) ++j;
        ans += (j - i + 1) / 2;
        i = j;
    }
    else ++i;
    cout << ans << '\n';
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
    int N, A[105], i;
    double X;
    X=0;
    scanf("%d", &N);
    for (i=1; i<=N; i++) {
        scanf("%d", &A[i]);
        X+=1.0/(double)A[i];
    }
    X=1.0/X;
    printf("%f", X);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
vector<int> x = {1,-1,0,0};
vector<int> y = {0,0,-1,1};
int main(){
    vector<vector<int>> data(3,vector<int>(3));
    int sum = 0;
    rep(i,0,3){
        rep(j,0,3){
            cin >> data[i][j];
            sum += data[i][j];
        }
    }
    if(sum%3!=0){
        cout<<"No"<<endl;
        return 0;
    }

    vector<int> height(3);
    vector<int> width(3);
    rep(i,0,3){
        rep(j,0,3){
            height[i]+=data[i][j];
        }
    }
    rep(i,0,3){
        rep(j,0,3){
            width[i]+=data[j][i];
        }
    }

    if((height[0]-height[1])%3==0&&(height[2]-height[0])%3==0&&(width[0]-width[1])%3==0&&(width[2]-width[0])%3==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    

  return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int sum = 0;
    int mod10 = 10;
    for (int i = 0; i < 5; i++)
    {
        int v;
        cin >> v;
        mod10 = min(mod10, v % 10 == 0 ? 10 : v % 10);
        v = (v + 9) / 10 * 10;
        sum += v;
    }
    sum -= 10 - mod10;
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;


int main(){
	ll k,a,b; cin >> k >> a >> b;
	if(b/k == (a-1)/k) puts("NG");
	else puts("OK");
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    int flag = 1;
    long long count = 0;
    while(flag == 1){
        flag = 0;
        for(int i = 0; i < N; i++){
            if(a[i] % 2 == 0){
                a[i] /= 2;
                count++;
                flag = 1;
            }
        }
    }
    cout << count << endl;
}

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

void get_forest_size(const vector<int> &u,const vector<int> &v,vector<vector<int>> &forest){
	const int N = u.size() + 1;
	vector<int> us(N-1,0),vs(N-1,0),num(N,0),did(N-1,0);
	set<int> connect[N];
	for(int i=0;i<N-1;i++){
		connect[u[i]].insert(i);
		connect[v[i]].insert(i);
	}
	queue<int> Q;
	for(int i=0;i<N;++i)
		if(connect[i].size()==1)
			Q.push( *connect[i].begin() );
	while( Q.size() ){
		int ie = Q.front();
		Q.pop();
		int isu = connect[u[ie]].size() == 1;
		(isu?us[ie]:vs[ie]) = num[(isu?u[ie]:v[ie])] + 1;
		num[(isu?v[ie]:u[ie])] += (isu?us[ie]:vs[ie]);
		connect[(isu?u[ie]:v[ie])].clear();
		connect[(isu?v[ie]:u[ie])].erase(ie);
		if(connect[(isu?v[ie]:u[ie])].size()==1){
			Q.push( *connect[(isu?v[ie]:u[ie])].begin() );
		}
		if(not did[ie]) did[ie] = (isu?1:2);
	}
	forest.resize(N);
	for(int i=0;i<N-1;i++){
		( did[i]==1 ? vs[i] = N - us[i] : us[i] = N - vs[i] );
		forest[u[i]].push_back(vs[i]);
		forest[v[i]].push_back(us[i]);
	}
	return;
}

ll calc(ll a,ll b,ll p){//a^(b) mod p   
	if(b==0)return 1;
	ll y = calc(a,b/2,p);y=(y*y)%p;
	if(b & 1) y = (y * a) % p;
	return y;
}

int main(){
	ll N,ans=0,MOD=1000000007LL;
	cin >> N;
	vector<int> u(N-1),v(N-1);
	for(int i=0;i<N-1;i++){
		cin >> u[i] >> v[i];
		u[i]--;v[i]--;
	}
	vector<vector<int>> fs;
	get_forest_size(u,v,fs);
	for(int i=0;i<N;i++){
		ll sum = 0;
		for(auto s : fs[i]){
			sum += s;
			( ans += MOD - calc(2,s,MOD) + 1 ) %= MOD;
		}
		( ans += calc(2,sum,MOD) ) %= MOD;
		( ans += MOD - 1 ) %= MOD;
	}
	( ans *= calc(calc(2,N,MOD),MOD-2,MOD) ) %= MOD;
	cout << ans << endl;
}

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

#define int long long
#define pb emplace_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);
const int N = 105;
const int W = 1e5 + 5;
int dp[N][W];
int32_t main(){
	fast;
	int n,w;
	cin >> n >> w;
	
	int cost[n] , weight[n];
	
	f(i,0,n)    cin >> cost[i] >> weight[i];
	
	for(int i=0 ; i<=n ; i++)
	{
		for(int j = 0 ; j <= w ; j++)
		{
			if(i == 0 ||  j == 0)
				dp[i][j] = 0;
			else if( cost[i-1] <= j)
				dp[i][j] =  max( dp[i-1][j] , dp[i-1][j - cost[i-1]] + weight[i-1]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	
	cout << dp[n][w];
}







Measured memory_bytes: 80128
#include <iostream>

using namespace std;

int main(){
    int N, K;
    int a[100];
    int a_min = 10000000;
    bool dp[100001];//i個で自分の手番になったときに勝てるならtrue
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        a_min = min(a[i], a_min);
    }
    for(int i = 1; i < a_min; i++) dp[i] = false;
    dp[a_min] = true;
    for(int i = a_min+1; i <= K; i++){
        for(int j = 0; j < N; j++){
            if(i-a[j] >= 0 && !dp[i-a[j]]){
                dp[i] = true;
                break;
            }
            if(j == N-1) dp[i] = false;
        }
    }
    if(dp[K]) cout << "First" << endl;
    else cout << "Second" << endl;
}

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

int main()
{
  string S, T;
  cin >> S >> T;
  int counter = 0;
  for (int i = 0; i < 3; ++i)
    if (S[i] == T[i])
      ++counter;
  cout << counter;
  return 0;
}


Measured memory_bytes: 256
// D.

#include <iostream>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>

using namespace std;

typedef long long LL;
typedef vector<LL> LLVec;

LL a;
LL b;

bool possible(LLVec &v, LL x) {
	LL r = x;
	for (int i = 0; i != v.size(); ++i) {
		LL c = max(0LL, v[i] - b * x);
		r -= (c + (a - b) - 1) / (a - b);
	}
	return r >= 0;
}

int main(int argc, char *argv[]) {
	LL n, low = 0, high = 0;
	cin >> n >> a >> b;
	LLVec v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		high += (v[i] + a - 1) / a;
	}
	while (high - low > 1) {
		LL mid = (high + low) / 2;
		if (possible(v, mid)) {
			high = mid;
		} else {
			low = mid;
		}
	}
	cout << high << endl;
	return 0;
}


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

using namespace std;

const int md = 1000000007;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) {
    a -= md;
  }
}

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

const int N = 310;

int a[N][N];
int f[N][N];
int p2[N * N];
int c[N][N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", a[i] + j);
    }
  }
  int rank = 0;
  for (int e = 0; e < n; e++) {
    bool found = false;
    for (int i = e; i < n; i++) {
      for (int j = e; j < n; j++) {
        if (a[i][j] == 1) {
          for (int jj = 0; jj < n; jj++) {
            swap(a[i][jj], a[e][jj]);
          }
          for (int ii = 0; ii < n; ii++) {
            swap(a[ii][j], a[ii][e]);
          }
          found = true;
          break;
        }
      }
      if (found) break;
    }
    if (!found) break;
    rank++;
    for (int i = e + 1; i < n; i++) {
      if (a[i][e] == 1) {
        for (int j = e; j < n; j++) {
          a[i][j] ^= a[e][j];
        }
      }
    }
  }
  p2[0] = 1;
  for (int i = 1; i < N * N; i++) {
    p2[i] = p2[i - 1];
    add(p2[i], p2[i - 1]);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (j == 0) c[i][j] = 1; else
      if (i == 0) c[i][j] = 0; else {
        c[i][j] = c[i - 1][j];
        add(c[i][j], c[i - 1][j - 1]);
      }
    }
  }
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  for (int k = 1; k <= n; k++) {
    for (int r = 0; r <= k; r++) {
      int dec = 0;
      for (int t = 1; t <= r; t++) {
        add(dec, mul(p2[r - 1], c[r][t]));
      }
      int inc = mul(mul(p2[n - r] + md - 1, p2[r]), mul(p2[n - r] + md - 1, p2[r]));
      f[k][r] = mul(f[k - 1][r - 1], dec);
      add(f[k][r], mul(f[k - 1][r + 1], inc));
      add(f[k][r], mul(f[k - 1][r], (p2[n + n] - 0LL - inc - dec) % md + md));
    }
  }
  printf("%d\n", f[n][rank]);
  return 0;
}


Measured memory_bytes: 1792
using System;

namespace abc077_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();
            Console.WriteLine(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0] ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i=(l); i<(r); ++i)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

bool is_prime(ll n){
    if(n<=1) return false;
    for(ll i=2; i*i<=n; ++i) if(n%i==0) return false;
    return true;
}

bool is_2017like(ll n){
    if(n%2==1 && is_prime(n) && is_prime((n+2)/2)) return true;
    return false;
}


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

    vector<int> cum(100005, 0);
    rep(i, 1, 100005){
        if(is_2017like(i)) cum[i] = cum[i-1]+1;
        else cum[i] = cum[i-1];
    }

    int q; cin >> q;
    while(q--){
        int l,r; cin >> l >> r;
        cout << cum[r]-cum[l-1] << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
ll f[2][5010];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),R=gi(),L=gi();
	memset(f,63,sizeof f);
	f[0][0]=0;int t=0;
	for(int i=1,a;i<=n;++i){
		a=gi();memset(f[!t],63,sizeof f[!t]);
		for(int j=0;j<=n;++j){
			if(j<a)cnk(f[!t][a],f[t][j]),cnk(f[!t][j],f[t][j]+R);
			cnk(f[!t][std::max(j,a)],f[t][j]+L);
		}
		t^=1;
	}
	ll ans=9e18;for(int i=0;i<=n;++i)cnk(ans,f[t][i]);
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



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

	int N;
	cin >> N;
	vector<int>A(1);

	cin >> A[0];
	REP(i, 1, N) {
		int a;
		cin >> a;
		if (A.back() != a)A.push_back(a);
	}
	N = A.size();
	if (N <= 2) {
		cout << 1 << endl;
		return 0;
	}

	int state = A[0] < A[1] ? 1 : -1;
	int ans = 1;
	REP(i, 2, N) {
		int newstate = A[i - 1] < A[i] ? 1 : -1;
		if (state != newstate) {
			ans++;
			if (i + 1 < N) {
				state = A[i] < A[i + 1] ? 1 : -1;
			}
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 1400
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

const ld pi = 3.141592653589793;

#ifdef EBUG
#define debug(x) cout << "\033[31m" << #x << ": " << x << "\033[0m\n";
#else
#define debug(x)
#endif

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

ll n, a[100005], nodes[100005], ans;

int main() {
  cin >> n;
  rep(i, n + 1) {
    cin >> a[i];
  }

  if (n == 0) {
    if (a[0] == 1) {
      cout << "1" << endl;
    } else {
      cout << "-1" << endl;
    }
    return 0;
  }

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

  // rep(i, n + 1) {
  //   rep(j, nodes[i]) {
  //     cout << "* ";
  //   }
  //   cout << endl;
  // }
  // cout << endl;

  nodes[0] = 1;
  for (int i = 1; i <= n; i++) {
    nodes[i] = min(nodes[i], (nodes[i - 1] - a[i - 1]) * 2);
    if (nodes[i] <= 0) {
      cout << "-1" << endl;
      return 0;
    }
  }

  if (nodes[n] < a[n]) {
    cout << "-1" << endl;
    return 0;
  }

  // rep(i, n + 1) {
  //   rep(j, nodes[i]) {
  //     cout << "* ";
  //   }
  //   cout << endl;
  // }

  rep(i, n + 1) {
    ans += nodes[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 5172
def gi() gets.to_i end
def gs() gets.chomp end
def gim() gets.split.map(&:to_i) end
def gsm() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end
#####

k = gi
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
puts list[k-1]

Measured memory_bytes: 1788
#include <stdio.h>
 
int main(){
  unsigned int a,b;
  unsigned long c; 
  
  scanf("%d %d",&a,&b);
  c = a * b;
  if((c%2) == 0){
    printf("Even\n");
  }else{
    printf("Odd\n");
  }
  return 0;
}

Measured memory_bytes: 128
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn
  xs <- U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let result :: Int
      result = U.maximum $ U.scanl' (\k (a,b) -> if a >= b then k + 1 else 0) 0 $ U.zip xs (U.tail xs)
  print result


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N;
  set<string> s;
  string in;

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> in;
    s.insert(in);
  }

  cout << s.size() << endl;

  return 0;
}

Measured memory_bytes: 19260
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}
/*
ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}*/

int main() {
	cin >> n;
	cin >> s;
	vector<ll> a(n,0);
	vector<ll> b(n, 0);
	vector<ll> c(n, 0);
	map<ll, ll> mpb;
	map<ll, ll> mp;
	rep(i, n-2) {
		if (mp[(ll)(s[i]-'0')] == 0) {
			mp[(ll)(s[i] - '0')]++;
			a[i] = 1;
		}
	}
	ll cnt = 0;
	for (ll i = n - 1; i > 1; i--) {
		if (mpb[(ll)(s[i] - '0')] == 0) {
			mpb[(ll)(s[i] - '0')]++;
			++cnt;
		}
		c[i] = cnt;
		b[i - 1] = c[i];
	}
	ll res = 0;
	rep(i, n) {
		if (a[i] == 1) {
			map<ll, ll> mpc;
			for (ll j = i + 1; j < n - 1; j++) {
				if (mpc[(ll)(s[j] - '0')] == 0) {
					mpc[(ll)(s[j] - '0')]++;
					res += b[j];
				}
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define PB(a,n) FOR(i,0,n){ll buf; scanf("%lld",&buf); a.pb(buf); }
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define INF 111111111111111111
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[8] = { 1,-1,0,0,1,1,-1,-1 }, ddy[8] = { 0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 111111



int main(void) {
  ll a, b;
  cin >> n >> a >> b;
  vll x;
  PB(x, n);
  FOR(i, 1, n) sum += min(b, a*llabs(x[i] - x[i - 1]));
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1400
def dist(A, B):
    return ((A[0]-B[0])**2 + (A[1]-B[1])**2)**.5


def circumcenter(A, B, C):
    # check if the points are colinear
    x1, y1 = B[0] - A[0], B[1] - A[1]
    x2, y2 = C[0] - A[0], C[1] - A[1]
    if abs(x1*y2 - x2*y1) < 1e-12:
        return None
    a = dist(B, C)
    b = dist(C, A)
    c = dist(A, B)
    cosA = (b**2+c**2-a**2) / (2*b*c)
    cosB = (c**2+a**2-b**2) / (2*c*a)
    cosC = (a**2+b**2-c**2) / (2*a*b)
    x = (a*cosA*A[0] + b*cosB*B[0] + c*cosC*C[0]) / (a*cosA + b*cosB + c*cosC)
    y = (a*cosA*A[1] + b*cosB*B[1] + c*cosC*C[1]) / (a*cosA + b*cosB + c*cosC)
    return x, y


N = int(input())
points = [tuple(map(int, input().split())) for i in range(N)]
if N == 2:
    print(dist(points[0], points[1]) / 2)
    exit()

ans = float('inf')

for i in range(N-1):
    for j in range(i+1, N):
        x = (points[i][0] + points[j][0]) / 2
        y = (points[i][1] + points[j][1]) / 2
        c = (x, y)
        r = dist(c, points[i])
        if r > ans:
            continue
        for point in points:
            d = dist(c, point)
            if abs(d - r) > 1e-6 and d > r:
                break
        else:
            ans = min(ans, r)

for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            c = circumcenter(points[i], points[j], points[k])
            if c is None:
                continue
            r = dist(c, points[i])
            if r > ans:
                continue
            for point in points:
                d = dist(c, point)
                if abs(d - r) > 1e-6 and d > r:
                    break
            else:
                ans = min(ans, r)
print(ans)


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

int main() {
    int N = 0;
    float sum;
    float amount[10];
    char kind[10][3];
    scanf("%d", &N);

    for(int i=0; i<N; i++) {
        scanf("%f %s", &amount[i], kind[i]);
        if(strcmp(kind[i], "JPY") == 0) {
            sum += amount[i];
        } else if(strcmp(kind[i], "BTC") == 0) {
            sum += amount[i]*380000.0;
        } else {
            continue;
        }
    }
    printf("%f\n", sum);
}

Measured memory_bytes: 128
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    X = int(input())

    B = 0
    res = {}
    while True:
        b = B ** 5
        if b not in res:
            res[b] = B
        if -b not in res:
            res[-b] = -B
        if X + b in res:
            return print(res[X + b], B)
        if X - b in res:
            return print(res[X - b], -B)
        B += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 74928
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	int n,k;cin>>n>>k;
	int ans=0;
	rep(i,n)
	{
		int foo;cin >> foo;
		ans+=2*min(foo,k-foo);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
input_lines = int(input())
tango=[]
lastchar = ''
for i in range(input_lines):
    s = input().rstrip()
    if len(lastchar) > 0 and not s[0] in lastchar or s in tango:
        print('No')
        break
    tango.append(s)
    lastchar = s[-1]
else:
    print('Yes')


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

int main()
{
    int a,b;
    cin >> a >> b;
    cout << ((a<10 and b<10)?a*b:-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
int A,B,C,D;
scanf("%d %d",&A,&B);
C = A;
A = 0;
for(int i=1;i<C;i++){
	A = A + i;
}
D = B;
B = 0;
for(int i=1;i<D;i++){
	B = B + i;
}
printf("%d",A+B);

return 0;
}


Measured memory_bytes: 1680
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> grh;
vector<int> prt, mxv;
vector<map<int, int>> mps;
vector<int> dp;
int fnc (int crr, int c) {
  auto& mp = mps[crr];
  if (mp.find(c) != mp.end()) return mp[c];
  int ret = 1;
  for (int nxt : grh[crr]) if (nxt != prt[crr]) {
      prt[nxt] = crr;
      if (nxt < c) {
        ret += fnc(nxt, c);
      }
  }
  mp[c] = ret;
  return ret;
}
void dfs (int crr) {
  int p = prt[crr];
  int d = mxv[prt[p]];
  int c = mxv[p] = max(d, p);
  if (crr < d) {
    dp[crr] = dp[p] + fnc(crr, c) - fnc(crr, d);
  } else if (crr > d) {
    dp[crr] = dp[p] + fnc(crr, c);
  }
  for (int nxt : grh[crr]) if (nxt != prt[crr]) {
      prt[nxt] = crr;
      dfs(nxt);
  }
}
int main() {
  cin >> n;
  grh.resize(n);
  prt.resize(n, 0);
  mxv.resize(n, 0);
  mps.resize(n);
  dp.resize(n, 0);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    grh[--a].push_back(--b);
    grh[b].push_back(a);
  }
  dfs(0);
  for (int i = 1; i < n; i++) {
    cout << dp[i];
    if (i < n - 1) {
      cout << ' ';
    } else {
      cout << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 55552
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

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

  char c;
  cin >> c;

  c+=1;

  cout << c << endl;

  return 0;
}


Measured memory_bytes: 256
S = input()
T = input()
l = len(S) - len(T) + 1
ans = len(T)
t = len(T)
for i in range(l):
  s = S[i:i+t]
  ans = min(ans, len([0 for i in range(t) if T[i] != s[i]]))
print(ans)

Measured memory_bytes: 9136
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p%i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

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

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL N;
	cin >> N;
	LL sn = 0;
	string s = to_string(N);
	FOR(i, 0, s.length()) {
		sn += s[i] - '0';
	}
	if (N%sn == 0) { O("Yes"); }
	else O("No");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

template <typename T>
using Vec = std::vector<T>;

constexpr int Inf = 1e9;

int main() {
	int h, n;
	std::cin >> h >> n;
	
	Vec<int> as(n), bs(n);
	for (int i = 0; i < n; ++i)
		std::cin >> as[i] >> bs[i];

	Vec<int> dp(h + 1, Inf);
	dp[0] = 0;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < n; ++j) {
			auto&& dst = dp[std::min(i + as[j], h)];

			dst = std::min(dp[i] + bs[j], dst);
		}
	}

	std::cout << dp[h] << std::endl;
}

Measured memory_bytes: 256