akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

#define int ll

const ll mod = 1e9 + 7;

ll cir[5000][5001];
ll sum[5000][5001];
int num[5001];

int n;
ll k;
int p[5000];
ll c[5000];

ll solver1(){
	

	for(int s=0;s<n;s++){
		int t = p[s];
		int u = 0;
		cir[s][u] = c[t];
		u++;
		while(t!=s){
			t = p[t];
			cir[s][u] = c[t];
			u++;
		}
		num[s] = u;
	}

	for(int i=0;i<n;i++) sum[i][0] = 0ll;
	
	
	for(int i=0;i<n;i++){
		for(int j=1;j<=num[i];j++){
			sum[i][j] = sum[i][j-1] + cir[i][j-1];
		}
	}

	//for(int i=0;i<n;i++) cout << sum[i][num[i]] << endl;

	ll ans = -1e18;
	
	for(int i=0;i<n;i++){
		for(int j=1;j<=min(k,num[i]);j++){
			int num2 = (k-j)/num[i];
			ans = max( num2 * max(0ll,sum[i][num[i]]) + sum[i][j], ans);
		}
	}

	return ans;
}

main(){
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> p[i];
		p[i]--;
	}
	for(int i=0;i<n;i++) cin >> c[i];

	printf("%lld\n", solver1());
	

	return 0;
}


Measured memory_bytes: 394540
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define resort(v) sort((v).rbegin(), (v).rend())
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
//const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

/*signed*/int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a < c && c < b) {
        puts("Yes");
    }
    else if (c > b && c < a) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 3592
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  int n;
  string s1, s2;
  cin >> n >> s1 >> s2;
  VL dp(n + 1);
  int pos = 0;
  while (pos < n) {
    if (s1[pos] == s2[pos]) {
      ll fac = pos == 0 ? 0 :
	s1[pos - 1] == s2[pos - 1] ? 2 : 1;
      dp[pos + 1] = pos == 0 ? 3 : dp[pos] * fac % mod;
      pos += 1;
    } else {
      ll fac = pos == 0 ? 0 :
	s1[pos - 1] == s2[pos - 1] ? 2 : 3;
      dp[pos + 2] = pos == 0 ? 6 : dp[pos] * fac % mod;
      pos += 2;
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  long long countR=0,countG=0,countB=0;
  cin >> N;
  string S;
  cin >> S;
  for(long long i=0;i<N;i++){
    if(S[i]=='R'){
      countR++;
    }
    else if(S[i]=='G'){
      countG++;
    }
    else{
      countB++;
    }
  }
  long long ans = countR * countG * countB;
  for(long long i=0;i<N-2;i++){
    for(long long k=1; i+2*k<N; k++){
      if(S[i]!=S[i+k] && S[i+k]!=S[i+2*k] && S[i+2*k]!=S[i]){
        ans--;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#define ll long long
using namespace std;



int main(){
   
  string S;

  cin>>S;

  if((S[0]=='A'&&S[1]=='A'&&S[2]=='A')||(S[0]=='B'&&S[1]=='B'&&S[2]=='B')){
     cout<<"No"<<endl;
  }
  else cout<<"Yes"<<endl;
  
    return 0;
}


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

#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;

using Graph = vector<vector<int>>;

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

    
    int N,X,M;
    cin>>N>>X>>M;
    int v[M+1]{};
    rep(i,M+1)v[i]=-1;
    int x=X;
    x%=M;
    int ans=0;
    bool z=false;
    rep(i,N){
        int nv=x*x;
        nv%=M;
        if(v[x]!=-1){
            //x=nv;
            z=true;
            break;
        }
        v[x]=nv;
        x=nv;

    }

    int c=0;
    int nn=x;
    int co=0;
    while(z){
        c++;
        co+=nn;
        nn=v[nn];
        if(nn==x)break;
    }
    //cout<<"-----------------"<<endl;
    //int a=0;
    int y=X%M;
    rep(i,N){
        if(z&&y==nn){
            int o=(N-1-i)/c;
            i+=o*c;
            ans+=o*co;
            if(i>=N-1){
                ans+=y;
                break;
            }
        }
        ans+=y;
        y=v[y];
    }
    cout<<ans<<endl;





}


Measured memory_bytes: 4400
from collections import defaultdict

def check(a, pre):
    ans = 0
    while a % 2 == 0:
        ans += 1
        a //= 2
        if ans == pre:
            break
    return ans


def main():
    # num = int(input())
    data = input()
    print(data.count('1'))



if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>

int m, n;
int w[100];

std::vector< std::vector<int> > memo(21, std::vector<int>(101));

const int MAX_WIDTH = 1500000;


int dfs(int i, int j){
    if(memo[i][j] != -1){
        return memo[i][j];
    }

    if(i >= m){
        return memo[i][j] = ( (j<n) ? -1 : 0 );
    }
    if(j >= n){
        return memo[i][j] = 0;
    }

    int ans = INT_MAX;

    int width = 0;
    int res;
    for(int k=j; k<n; ++k){
        width += w[k];

        res = dfs(i+1, k+1);
        if(res >= 0){
            ans = std::min(ans, std::max(width,res));
        }
    }

    return memo[i][j] = ans;
}

int main(void){
    while(std::cin >> m >> n){
        if(m == 0 && n == 0) break;
        for(int i=0; i<n; ++i){
            std::cin >> w[i];
        }

        for(int i=0; i<=m; ++i){
            for(int j=0; j<=n; ++j){
                memo[i][j] = -1;
            }
        }
        std::cout << dfs(0,0) << std::endl;
    }
}

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

int a[4];
int n, m, ans = 0;
bool stat = true;
int main(){	
	std::memset(a,-1,sizeof(a));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x, y;
		scanf("%d%d",&x,&y);
		if(a[x] != -1 && a[x] != y){
			stat = false; break;
		}
		a[x] = y;
	}
	if(n == 1){
		if(a[1] == -1) a[1] = 0;
		if(stat) printf("%d\n", a[1]);
		else printf("-1");
	}
	else{
		if(a[1] == 0) stat = false;
		if(a[1] == -1) a[1] = 1;
		for(int i=2;i<=n;i++) if(a[i] == -1) a[i] = 0;
		for(int i=1;i<=n;i++) ans = 10 * ans + a[i];
		if(stat) printf("%d\n", ans);
		else printf("-1");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <map>
using namespace std;
long long int MOD = 1000000000 + 7;
using ll = long long;

int main() {
	ll n, m;
	cin >> n >> m;
	map<ll, vector<string>> prob2result;
	for (ll i = 0; i < m; ++i) {
		ll key;
		string res;
		cin >> key >> res;
		prob2result[key].push_back(res);
	}
	ll cntwa = 0;
	ll cntac = 0;
	for (auto it = prob2result.begin(); it != prob2result.end(); ++it) {
		bool hasac = false;
		for (ll i = 0; i < it->second.size(); ++i) {
			if (it->second.at(i) == "AC") {
				hasac = true;
				break;
			}
		}
		if (hasac == false) {
			continue;
		}
		for (ll i = 0; i < it->second.size(); ++i) {
			if (it->second.at(i) == "AC") {
				cntac++;
				break;
			}
			else {
				cntwa++;
			}
		}
	}
	cout << cntac << " " << cntwa << endl;
}


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

using namespace std;

struct Point{
  double x;
  double y;
  
  Point(double xi, double yi) : x(xi), y(yi){}
  
  Point& operator+=(const Point& p){
    this->x += p.x;
    this->y += p.y;
    return *this;
  }
  
  Point& operator-=(const Point& p){
    this->x -= p.x;
    this->y -= p.y;
    return *this;
  }
  
  bool operator<(const Point& p) const{
    return atan2(y, x) < atan2(p.y, p.x);
  }
};

Point operator+(const Point& p1, const Point& p2){
  return Point(p1) += p2;
}

double distance(const Point& p1, const Point& p2){
  double dx = p1.x - p2.x;
  double dy = p1.y - p2.y;
  return sqrt(dx * dx + dy * dy);
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int N;
  cin >> N;
  
  vector<Point> engines;
  for(int i = 0; i < N; i++){
    double x, y;
    cin >> x >> y;
    engines.push_back(Point(x, y));
  }
  
  sort(engines.begin(), engines.end());
  
  Point me(0, 0);
  const Point o(0, 0);
  double reach = 0;
  int low = 0;
  int high = 0;
  while(low < N){
    while(high < low + N && distance(me, o) <= distance(me + engines[high % N], o)){
      me += engines[high % N];
      high++;
    }
    reach = max(reach, distance(me, o));
    if(low == high){
      me += engines[high++];
    }
    me -= engines[low++];
  }
  
  cout << fixed << setprecision(10) << reach << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int A, B, C, D; cin >> A >> B >> C >> D;
    int ans = 0;
    rep(i, 101)if (A <= i && B >= i && C <= i && D >= i)ans++;
    cout << (ans!=0? ans-1:0) << endl;
}

Measured memory_bytes: 3588
/**
 * Created by karayuu on 2019/05/23
 */
fun main(args: Array<String>) {
    val count = readLine()!!.toInt()
    var taro_point = 0
    var hanako_point = 0

    for (i in 1..count) {
        val (taro, hanako) = readLine()!!.split(" ")
        when {
            taro < hanako -> hanako_point += 3
            taro == hanako -> {
                taro_point += 1
                hanako_point += 1
            }
            else -> taro_point += 3
        }
    }
    println("$taro_point $hanako_point")
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N+1), B(N);
    REP(i, N+1) cin >> A[i];
    REP(i, N) cin >> B[i];

    ll res = 0;
    REP(i, N){
    	REP(j, 2){
    		ll taosu = min(A[i+j], B[i]);
    		res += taosu;
    		A[i+j] -= taosu;
    		B[i] -= taosu;
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r;
  string str,ans;
  ans="Yes";
  cin>>r>>str;
  if(r%2==0){
    r=r/2;
    for(int i=0; i<r; i++){
      if(str.at(i)!=str.at(i+r)){
        ans="No";
      }
    }
  }
  else{
    ans="No";
  }
  cout<<ans;
}

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

using namespace std;

int main() {
	int n;
	string a, b;
	string p1 = "98765432109";
	string p2 = "01234567890";
	cin >> n;
	getline(cin, a);
	for (int i = 0; i < n; i++) {
		getline(cin, a);
		getline(cin, b);
		for (int j = a.size()-1; j >= 0; j--) {
			if (a[j] == 'J') {
				string c = "";
				c += b[b.size()-1];
				b = b.substr(0, b.size()-1);
				c += b;
				b = c;
			} else if (a[j] == 'C') {
				string c = "";
				c = b.substr(1);
				c += b[0];
				b = c;
			} else if (a[j] == 'E') {
				string c1 = b.substr(0, b.size()/2);
				if (b.size() % 2 == 0) {
					string c2 = b.substr(b.size()/2);
					b = c2+c1;
				} else {
					string c2 = b.substr(b.size()/2+1);
					string c3 = "";
					c3 += b[b.size()/2];
					b = c2+c3+c1;
				}
			} else if (a[j] == 'A') {
				string c = "";
				for (int k = b.size()-1; k >= 0; k--) {
					c += b[k];
				}
				b = c;
			} else if (a[j] == 'P') {
				for (int k = 0; k < b.size(); k++) {
					if (0 <= b[k]-'0' && b[k]-'0' <= 9) {
						for (int l = 0; l < p1.size()-1; l++) {
							if (b[k] == p1[l]) {
								b[k] = p1[l+1];
								break;
							}
						}
					}
				}
			} else {
				for (int k = 0; k < b.size(); k++) {
					if (0 <= b[k]-'0' && b[k]-'0' <= 9) {
						for (int l = 0; l < p2.size()-1; l++) {
							if (b[k] == p2[l]) {
								b[k] = p2[l+1];
								break;
							}
						}
					}
				}
			}
		}
		cout << b << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>

int main()
{
    int L, R, d, i, c = 0;
    scanf("%d%d%d", &L, &R, &d);
    for (i = L; i <= R; i++)
    {
        if (i % d == 0)
        {
            c++;
        }
    }
    printf("%d", c);
    return 0;
}

Measured memory_bytes: 1736
N=int(input())

word_set=set()
last_tail=""
for i in range(N):
  W=input()
  if W in word_set:
    print("No")
    break
  else:
    word_set.add(W)
    
  if len(word_set)>1 and last_tail!=W[0]:
    print("No")
    break
  else:
    last_tail=W[-1]
    
else:
  print("Yes")

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

typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
  
ll N;
VL A;
VL ans;

int main(){ 
    cin>>N;
    A = VL (N+1,0);
    ans = VL (N+1,0);
    rep(i,2,N+1){
        cin>>A[i];
        ans[A[i]]++;
    }
    rep(i,1,N+1){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 6384
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <list>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000007LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
	int n;
	ll T[SIZE];
	scanf("%d",&n);
	ll a=0,s=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&T[i]);
		a += T[i];
	}
	ll minv;
	a -= T[0];
	s = T[0];
	minv = abs(a-s);
	for(int i=1;i<(n-1);i++){
		a -= T[i];
		s += T[i];
		minv = min(minv,abs(a-s));
	}

	printf("%lld\n",minv);

	return 0;
}


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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  for (auto&& c : s) {
    c = 'A' + (c + n - 'A') % 26;
    cout << c;
  }
  return 0;
}


Measured memory_bytes: 3636
a, b = map(int, input().split())
if 0 < a and 0 < b:
    print("Positive")
elif a < 0 and b < 0:
    if (abs(a-b) + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")
else:
    print("Zero")


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //4文字
            string val = Console.ReadLine();

            List<string> a = new List<string>();
            List<string> b = new List<string>();
            List<string> c = new List<string>();
            List<string> d = new List<string>();


            foreach (char ch in val)
            {
                string str = ch.ToString();

                //最初
                if (a.Count == 0)
                {
                    a.Add(str);
                }
                else
                {
                    if (str == a[0])
                    {
                        a.Add(str);
                    }
                    else if (b.Count == 0 || str == b[0])
                    {
                        b.Add(str);
                    }
                    else if (c.Count == 0 || str == c[0])
                    {
                        c.Add(str);
                    }
                    else
                    {
                        d.Add(str);
                    }
                }
            }


            bool result = false;

            if (a.Count == 2 && b.Count == 2)
                result = true;

            Console.WriteLine(result?"Yes":"No");
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
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 = 1LL << 60;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(b,n*a)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef pair<double,int>Q;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int t[105],v[105],sum;
int mn[40005];
int main(){
	int n;
	cin>>n;
	repn(i,n){cin>>t[i];sum+=t[i]*2;}
	repn(i,n)cin>>v[i];
	for(int i=0;i<40005;i++){
		mn[i] = i;
	}
	for(int i=sum;i>=0;i--){
		mn[i] = min(sum-i,mn[i]);
	}
	int cur=0;
	repn(i,n){
		for(int j=cur;j<=cur+2*t[i];j++){
			mn[j] = min(mn[j],v[i]*2);
		}
		for(int j=cur;j>=0;j--){
			mn[j] = min(mn[j],v[i]*2+cur-j);
		}
		for(int j=cur+2*t[i];j<=sum;j++){
			mn[j] = min(mn[j],v[i]*2+j-cur-2*t[i]);
		}
		cur+=2*t[i];
	}
	double ans = 0.0;
	for(int i=0;i<sum;i++){
		ans+=double(mn[i])+double(mn[i+1]);
	}
	printf("%.12f\n",ans*0.125);
}

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

template <typename T>
struct point {
    T x;
    T y;

    point(T x = 0, T y = 0) : x(x), y(y) {}

    friend ostream& operator<<(ostream& os, const point p) {
        os << fixed << setprecision(10) << p.x << " " << p.y;
        return os;
    }
};

template <typename T>
struct vec {
    T x;
    T y;

    vec(T x, T y) : x(x), y(y) {}

    vec(point<T> a) {
        x = a.x;
        y = a.y;
    }
    
    vec(point<T> a, point<T> b)  {
        x = b.x - a.x;
        y = b.y - a.y;
    }

    double magnitude() {
        return sqrt(x * x + y * y);
    }
};

template <typename T>
vec<T> scale(vec<T> v, double mag) {
    return vec<T>(v.x * mag, v.y * mag);
}

template <typename T>
T dot_product(vec<T> u, vec<T> v) {
    return u.x * v.x + u.y * v.y;
}

template <typename T>
point<T> translate(point<T> p, vec<T> v) {
    return point<T>(p.x + v.x, p.y + v.y);
}

int main() {

    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    point<double> p1(x1, y1);
    point<double> p2(x2, y2);

    vec<double> v(p1, p2);

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        double x, y;
        cin >> x >> y;

        point<double> p(x, y);

        vec<double> u(p1, p);

        double len = dot_product(u, v) / v.magnitude() / v.magnitude();

        vec<double> vec_q = scale(v, len);

        point<double> q(vec_q.x, vec_q.y);

        point<double> ans = translate(q, vec<double>(point<double>(0, 0), p1));

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3288
a = int(input())
als = [0]*(30000)
for i in range(0,10**6+2):
    als[a] = 1
    if a%2 == 0:
        a = a//2
    else:
        a = 3*a+1
    if als[a] == 1:
        print(i+2)
        exit()

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int sum=0;
    rep(i,n*(n-1)/2){
      int in;cin>>in;
      sum+=in;
    }
    cout<<sum/(n-1)<<endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	s[k-1] += ('a'-'A');
	cout<<s<<endl;
}

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

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

	map< int, vector<int> > memo;
	rep(i, 0, M)
	{
		int c, d;
		cin >> c >> d;
		memo[c].push_back(i);
		memo[d].push_back(i);
	}

	ll ans = 0;
	set<int> first, second;
	int memo_index = -1;
	rep(i, 1, N + 1)
	{
		ans++;
		
		if (memo[i].size() == 0) continue;

		if (memo_index < 0) memo_index = i;

		for (int n : memo[i])
		{
			if (first.find(n) == first.end())
				first.insert(n);
			else
				second.insert(n);
		}

		if (first.size() == second.size())
		{
			ans += (i - memo_index) * 2;
			memo_index = -1;
			first.clear();
			second.clear();
		}
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 3296
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <deque>

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

using namespace std;

typedef long long ll;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  vector<pair<int, int> > p(n);

  rep(i, n) {
    cin >> a[i];
    p[i] = make_pair(a[i], i);
  }
  
  sort(p.begin(), p.end());

  int ans = 0;
  rep(i, n) {
    if ( p[i].second%2 != i%2 ) { ans++; }
  }

  cout << (ans+1)/2 << endl;

  return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main {
    public static void main(String args[]) {
  Scanner sc = new Scanner(System.in);
  int x = sc.nextInt();
  int n = sc.nextInt();
  
  boolean[] ok = new boolean[201];
  for(int i =0;i<n;i++){
      int c = sc.nextInt();
      ok[c] =true;
  }
  int result = 500;
  int diff = 500;
  for(int i =0;i<=200;i++){
      if(!ok[i]){
          int abs = Math.abs(x-i);
          if(abs<diff){
              result =i;
              diff = abs;
          }else if(abs == diff){
                result = Math.min(result, i);
          }
      }
  }
  System.out.println(result);
    }
}

Measured memory_bytes: 35980
#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;
  if (a%3==0||b%3==0||(a+b)%3==0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)
#define add(x,y)(x=(x+y)%MOD)

int main(){
	char c;
	scanf("%c",&c);
	if(c<96)putchar(65);
	else putchar(97);
}

Measured memory_bytes: 1596
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    vector<ll> x(5);;

    rep(i,0,5)
        cin >> x[i];

    rep(i,0,5)
    {
        if (x[i]==0)
        {
            cout << i+1 << endl;
            return 0;
        }
    } 

    return 0;
}


Measured memory_bytes: 3492
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            if (s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else if (s == "ARC")
            {
                Console.WriteLine("ABC");
            }
        }
    }
}

Measured memory_bytes: 25788
#include<iostream>

using namespace std;

int main(){

   string S;
   cin>> S;

   string t="CODEFESTIVAL2016";
   int cnt=0;
   for(int i=0; i<S.size(); i++){
      cnt+=(S[i]!=t[i]);
   }

   cout<< cnt<< endl;

   return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
inline int read(){
	int f=1,ans=0;char c;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}
const int N=2001;
int n,a[N],ans;
int main(){
	n=read();
	for(int i=1;i<=2*n;i++) a[i]=read();
	sort(a+1,a+2*n+1);
	for(int i=1;i<=2*n;i+=2) ans+=a[i];
	printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);

using ll = int64_t;
using ull = uint64_t;

using namespace std;

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

    int s, w;
    cin >> s >> w;
    cout << (w >= s ? "unsafe" : "safe");

    return 0;
}


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

using namespace std;

#ifdef Lin1043
    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
    #define massert(...) assert(...)
#else
    #define DEBUG(...)
    #define massert(...)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

struct iopener
{
    iopener()
    {
#ifdef Lin1043
        freopen("./in" , "r" , stdin);
#endif
    }
} iop;

typedef long long LL;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}

const int N = 100000 + 5;

int n , A[N]; LL Ans;

int main()
{
    read(n);
    rep(i , 1 , n)
        read(A[i]);
    rep(i , 1 , n)
    {
        if(i > 1 && A[i] && A[i - 1])
        {
            A[i]-- , Ans++;
        }
        Ans += A[i] / 2 , A[i] %= 2;
    }
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 640
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(n: usize, a: Vec<usize>, b: Vec<u32>, c:Vec<u32>) -> u32 {
  let mut score = b.iter().sum();
  for i in 1..n {
    if a[i - 1] + 1 == a[i] {
      score += c[a[i - 1]];
    }
  }
  score
}

fn main() {
  input! {
    n: usize,
    a: [usize1; n],
    b: [u32; n],
    c: [u32; n - 1]
  };

  println!("{0}", solve(n, a, b, c));
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max(a+b*10+c,max(a+c*10+b,max(b+a*10+c,max(b+c*10+a,max(c+a*10+b,c+b*10+a)))));
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;

const int N=5e5+1;

ll n,k;
int ar[N];

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    int ans=INT_MAX;
    for(int x=0;x<=100;x++){
        int sum=0;
        for(int i=0;i<n;i++) sum+=(ar[i]-x)*(ar[i]-x);
        ans=min(ans,sum);
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S;
    string T;
    cin >> S >> T;

    ll ans = 0;
    ll N = S.size();
    map<char, vector<ll>> pos;
    rep(i, N) {
        pos[S[i]].emplace_back(i);
    }
    ll now = -1;
    rep(i, T.size()) {
        if (pos[T[i]].empty()) {
            cout << -1 << '\n';
            return;
        } else {
            auto idx = lower_bound(pos[T[i]].begin(), pos[T[i]].end(), now + 1) - pos[T[i]].begin();
            if (idx == pos[T[i]].size()) {
                ans += N - 1 - now + pos[T[i]][0] + 1;
                now = pos[T[i]][0];
            } else {
                ans += (pos[T[i]][idx] - now);
                now = pos[T[i]][idx];
            }
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1736
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<cstdint>
//#include<>
using namespace std;

typedef vector< vector<int> > Mat;
typedef pair<int,int> pii;

typedef int64_t i64;typedef int32_t i32;
typedef int16_t i16;typedef int8_t i8;
typedef uint64_t ui64;typedef uint32_t ui32;
typedef uint16_t ui16;typedef uint8_t ui8;

typedef i32 int__;
#define rep(i,j) for(int__ i=0;i<j;i++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);i++)
#define repeat_eq(i,j,k) for(int__ i=(j);i<=(k);i++)
#define all(v) begin(v),end(v)

const i32 INF=1<<30;//=10E10

int h,w,c;

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

int count_same(Mat& vv){
  stack<pii> stk;
  vector<vector<bool> > used(h,vector<bool>(w,false));
  used[0][0]=true;
  stk.push(pii(0,0));

  int ans=0;
  while(!stk.empty()){
    int x=stk.top().second;
    int y=stk.top().first;
    stk.pop();
    ans++;
    rep(i,4){
      int nx=x+dx[i];
      int ny=y+dy[i];
      if( 0<=ny && ny<h && 0<=nx && nx<w ){
	if(vv[ny][nx]==vv[0][0] && !used[ny][nx]){
	  stk.push(pii(ny,nx));
	}
	used[ny][nx]=true;
      }
    }
  }
  return ans;
}

void change(Mat &vv,int col){
  stack<pii> stk;
  vector<vector<bool> > used(h,vector<bool>(w,false));
  
  int precol=vv[0][0];
  vv[0][0]=col;
  used[0][0]=true;
  stk.push(pii(0,0));
  
  while(!stk.empty()){
    int x=stk.top().second;
    int y=stk.top().first;
    stk.pop();
    
    rep(i,4){
      int nx=x+dx[i];
      int ny=y+dy[i];
      if( 0<=ny && ny<h && 0<=nx && nx<w ){
	if(vv[ny][nx]==precol && !used[ny][nx]){
	  vv[ny][nx]=col;
	  stk.push(pii(ny,nx));
	}
	used[ny][nx]=true;
      }
    }
  }
}

int rec(Mat vv,int col,int cnt){
  if(col>0)change(vv,col);

  int ans=0;
  if(cnt==4){
    change(vv,c);
    ans=count_same(vv);    
  }
  else{
    repeat_eq(i,1,6){
      if(vv[0][0]!=i){
	ans=max(ans,rec(vv,i,cnt+1));      	      
      }
    }
  }
  return ans;
}

int main()
{
  while(true){
    cin>>h>>w>>c;
    if(!h && !w && !c)break;
    Mat vv(h,vector<int>(w));
    rep(i,h)rep(j,w)cin>>vv[i][j];
    cout<<rec(vv,-1,0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
# 隣接マスにも黒が存在するか
def check(x, y):
    for i, j in zip(dirx, diry):
        nx = i + x
        ny = j + y
        if nx in range(h) and ny in range(w) and field[nx][ny] == '#':
            return True
    return False


h, w = map(int, input().split())
field = [[c for c in input().strip()] for _ in range(h)]

dirx = [0, 1, 0, -1]
diry = [1, 0, -1, 0]

for i in range(h):
    for j in range(w):
        # そのマスが黒かチェック
        if field[i][j] == '#':
            if not check(i, j):
                print('No')
                exit()
print('Yes')


Measured memory_bytes: 9216
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
#define MAXH 31
#define MAXW MAXH
#define MAXC 4
#define INF (1<<20)
typedef enum {STRA=0,RIGHT=1,BACK=2,LEFT=3,STOP=4} TYPE;
int W,H;
int F[MAXH][MAXW];
int cost[MAXC+1]; // cost[STOP]=0;
int D[MAXH][MAXW][4];
bool visited[MAXH][MAXW][4];

class State {
public:
  int i,j,d,c; // i,j,direction,cost
  State (int i, int j, int d, int c) : i(i),j(j),d(d),c(c) {}
  bool operator < (const State &s) const {
    return c > s.c;
  }
};

bool ok(int i, int j) {
  return 1 <= i && i <= H && 1 <= j && j <= W;
}

int solve() {
  priority_queue<State> PQ;
  for(int i=1;i<=H;i++) {
    for(int j=1;j<=W;j++) {
      for(int k=0;k<MAXC;k++) {
	D[i][j][k]=INF;
      }
    }
  }
  memset(visited,0,sizeof(visited));
  PQ.push(State(1,1,RIGHT,0));
  D[1][1][RIGHT]=0;
  // x=>l, y=>k
  int di[][4]={ {-1, 0, 1, 0},
		{ 0, 1, 0,-1},
		{ 1, 0,-1, 0},
		{ 0,-1, 0, 1}};
  int dj[][4]={ { 0, 1, 0,-1},
		{ 1, 0,-1, 0},
		{ 0,-1, 0, 1},
		{-1, 0, 1, 0}};
  while(!PQ.empty()) {
    State u = PQ.top(); PQ.pop();
    int i = u.i, j=u.j, d=u.d, c=u.c;
    if(i==H&&j==W) {
      return D[i][j][d];
    }
    visited[i][j][d]=true;
    
    for(int k=0;k<4;k++) {
      int ui = i + di[d][k];
      int uj = j + dj[d][k];
      if(!ok(ui,uj)) continue;
      if(k == F[i][j]) { // no cost
	int _cost = D[i][j][d] + 0;
	if(_cost < D[ui][uj][(d+k)%4]) {
	  D[ui][uj][(d+k)%4] = _cost;
	  PQ.push(State(ui,uj,(d+k)%4,_cost));
	}
      } else { // have to pay cost
	int _cost = D[i][j][d] + cost[k];
	if(_cost < D[ui][uj][(d+k)%4]) {
	  D[ui][uj][(d+k)%4] = _cost;
	  PQ.push(State(ui,uj,(d+k)%4,_cost));
	}
      }
    } // for4
    
  }
}

main() {
  while(cin>>W>>H,W) {
    for(int i=1;i<=H;i++) {
      for(int j=1;j<=W;j++) {
	cin>>F[i][j];
      }
    }
    for(int i=0;i<MAXC;i++) 
      cin>>cost[i];
    cout << solve() << endl;
  }
}

Measured memory_bytes: 1028
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll k; cin >> k;
    vector<ll> dp(k, INF);
    dp[1] = 1;
    
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> q;
    q.push(pair<ll, ll>(dp[1], 1));

    while (!q.empty()) {

        ll c = q.top().first;
        ll v = q.top().second;
        q.pop();

        ll n1 = (v + 1) % k;
        ll n2 =  v * 10 % k;
        if (chmin(dp[n1], dp[v] + 1))
            q.push(pair<ll, ll>(dp[n1], n1));
        if (chmin(dp[n2], dp[v]))
            q.push(pair<ll, ll>(dp[n2], n2));

    }

    cout << dp[0] << endl;
    
}

Measured memory_bytes: 2168
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    int n;
    int cnt[30];
    for (int i = 0; i < 30; i++) {
        cnt[i]=0;
    }
    cin>>n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin>>s[i];
    }

    for (int i = 0; i <= 25; i++) {
        int ret = 1e9;
        for (int j = 0; j < n; j++) {
            int tcnt=0;
            for (int k = 0; k < s[j].size(); k++) {
                if(s[j][k]==(char)(i+'a'))tcnt++;
            }
            ret=min(ret,tcnt);
        }
        cnt[i]=ret;
    }

    for(int i = 0;i<=25;i++){
        if(cnt[i]==0)continue;
        for (int j = 0; j < cnt[i]; j++) {
            cout<<(char)(i+'a');
        }
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	int N;
    cin>>N;
    int ans=1;

    vector<string>S(N);
    for(int i=0;i<N;i++){
        cin>>S[i];
    }
    sort(S.begin(), S.end());
    for(int i=0;i<N-1;i++){
        if(S[i]!=S[i+1]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9504
w, a, b = map(int, input().split())
if b <= a <= b + w:
    print(0)
elif b <= a+w <= b+w:
    print(0)
elif a <= b <= a + w:
    print(0)
elif a <= b+w <= a+w:
    print(0) 
elif a+w < b :
    print(b-a-w)
elif b+w < a :
    print(a-b-w)

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

int main(){
    long long n;
    cin >> n;
    vector<long long> a;
    vector<int> p(1000001,0);
    rep(i,n){
        long long t;
        cin >> t;
        a.push_back(t);
    }
    sort(a.begin(),a.end());
    rep(i,n){
        if(p.at(a.at(i))==0){
            if(i<n-1){
                if(a.at(i)==a.at(i+1))p.at(a.at(i))=1;
            }   
            for(long long j=2;a.at(i)*j<1000001;j++)p.at(a.at(i)*j)=1;
        }
    }
    long long ans=0;
    rep(i,n){
        if(p.at(a.at(i))==0)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int a,b,c; std::cin >> a >> b >> c;
  std::cout << std::min( {a+b, b+c, c+a} ) << std::endl;
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if a >= 6 && a <= 12 {
		fmt.Println(b / 2)
		return
	}
	if a < 6 {
		fmt.Println(0)
		return
	}
	fmt.Println(b)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t; cin>>s>>t;vector<int>ss(26),tt(26);
	for(auto&&i:s)++ss.at(i-'a'); for(auto&&i:t)++tt.at(i-'a');
	sort(ss.begin(),ss.end()); sort(tt.begin(),tt.end());
	cout<<(ss==tt?"Yes"s:"No"s)<<endl;
}

Measured memory_bytes: 776