akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    while(1){
        cin >> H >> W;
        if(H==0 && W==0){
            break;
        }
        for(int i=0; i<H; i++){
            if(W%2>0){
                if(i%2==0){
                    for(int T=0; T<W; T++){
                        if(T%2==0){
                            cout << "#";
                        }
                        else if(T%2!=0){
                            cout << ".";
                        }
                    }
                }
                if(i%2!=0){
                    for(int Y=0; Y<W; Y++){
                        if(Y%2==0){
                            cout << ".";
                        }
                        if(Y%2!=0){
                            cout << "#";
                        }
                    }
                }
            }
            else if(W%2==0){
                if(i%2!=0){
                    for(int P=0; P<W/2; P++){
                        cout << "." << "#";
                    }
                }
                else if(i%2==0){
                    for(int R=0; R<W/2; R++){
                        cout << "#" << ".";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3116
#include <stdio.h>
#include <ctype.h>

int main() {

  char ch[1200];
  int i,n;
  n=0;
  char a[1200];

  while(1) {
    scanf("%c",&a[n]);
    if(a[n] == '\n') {
      break;
    }
    ch[n] = a[n];
    if('A' <= a[n] && a[n] <= 'Z') {
      ch[n] = a[n] + 32;
    } else if(a[n] >= 'a' && a[n] <= 'z') {
      ch[n] = a[n] - 32;

    }
    
    
    n = n +1;
    
  }
  
  for(i=0; i<n ; i++) {
    printf("%c" ,ch[i]);
  }
  printf("\n"); 
  return 0;
  
}





  

 



Measured memory_bytes: 2068
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	LL N, K;
	cin >> N >> K;
	LL ans = K;
	for (int i = 2; i <= N; ++i) {
		{
			ans *= (K - 1);
		}
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>

#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#define all(c) c.begin(),c.end()
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-7
typedef long long ll;
inline int toInt(std::string s) { int v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
#define X real()
#define Y imag()
typedef pair<int, int> pii;

int main()
{
	ll N, M;
	cin >> N >> M;
	if (N == 1 && M == 1)
	{
		cout << 1 << endl;
	}
	else if (N == 1 || M == 1)
	{
		cout << max(N, M) - 2 << endl;
	}
	else {
		cout << (N - 2) * (M - 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int MOD = 1000000007;

int main(void){
    int N; cin >> N;
    string S; cin >> S;
    
    int ans = 1;
    for(int i = 1; i < N; i++){
        if (S[i] != S[i-1]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
N,K = list(map(int,input().split()))
x = list(map(int,input().split()))
minTime = 10000000000
for i in range(N-K+1):
    time = 0
    minValue = x[i]
    maxValue = x[i+K-1]
    if minValue < 0 and maxValue < 0:
        time = minValue * -1
    elif minValue >= 0 and maxValue >= 0:
        time = maxValue
    elif minValue < 0 and maxValue >= 0:
        leftTime = minValue * -1
        rightTime = maxValue
        if leftTime < rightTime:
            time = leftTime * 2 + rightTime
        else:
            time = leftTime + rightTime * 2
    if time < minTime:
        minTime = time
print(minTime)

Measured memory_bytes: 20132
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)

ans = {True: "POSSIBLE",
    False: "IMPOSSIBLE"}

print(ans[len(set(edge[0]) & set(edge[-1])) > 0])


Measured memory_bytes: 137132
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

static class CodeJam
{
    static int Solve(int N, Tuple<long, long>[] balls)
    {
        var set = new HashSet<Tuple<long, long>>(balls);
        var min = N;
        for (int i = 0; i < N; ++i)
        {
            var a = balls[i];
            for (int j = 0; j < N; ++j)
            {
                if (i == j) { continue; }
                var b = balls[j];
                long p = b.Item1 - a.Item1;
                long q = b.Item2 - a.Item2;
                int cnt = balls.Count(ball => !set.Contains(new Tuple<long, long>(ball.Item1 - p, ball.Item2 - q)));
                min = Math.Min(cnt, min);
            }
        }
        return min;
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var balls = new Tuple<long, long>[N];
        for (int i = 0; i < N; ++i)
        {
            var V = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            balls[i] = new Tuple<long, long>(V[0], V[1]);
        }
        Console.WriteLine(Solve(N, balls));
    }
}


Measured memory_bytes: 17612
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	while ( true )
	{
		int n, k;
		cin >> n >> k;

		if ( !( n | k ) )
		{
			break;
		}

		VI as( n );

		EACH( a, as )
		{
			cin >> a;
		}

		VI csum( 1, 0 );

		partial_sum( ALL( as ), back_inserter( csum ) );

		int res = INT_MIN;

		for ( int i = 0; i + k <= n; i++ )
		{
			res = max( res, csum[ i + k ] - csum[i] );
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 2136
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;

int main(){
    string s;
    cin>>s;
    if(s.size()==1) cout<<min(s[0]-'0',10-(s[0]-'0')+1);else{
   int ans=0,res=0;
   s='0'+s;int len=s.size();
   for(int i=len-1;i>=1;i--){
       if(i==0) continue;
        if(s[i]>'5') {
            res+=10-(s[i]-'0');
            s[i]='0';
            s[i-1]++;
        }
        else if(s[i]=='5' && s[i-1]>='5'){
            res+=10-(s[i]-'0');
            s[i]='0';
            s[i-1]++;
        }
   }
  // cout<<s<<endl;
   for(int i=0;i<len;i++)
    ans+=s[i]-'0';
   cout<<ans+res;
    }
    //int ans=0;
    //for(int i=0;i<s.size();i++) ans+=min(s[i]-'0',10-(s[i]-'0')+1);
    //cout<<ans;
    return 0;
}


Measured memory_bytes: 2308
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 29;
const double EPS = 1e-10;

const ll mod = 100000007;

ll dp1[100010];
ll dp0[100010];
ll sum0[100010];
ll sum1[100010];

void maketable(ll *dp, ll *sum, int w){

  memset(dp, 0, sizeof(dp));
  memset(sum, 0, sizeof(sum));
  dp[0] = 1;
  for(int i = 1; i < 100010; i++){
    for(int j = 1; j <= w; j++){
      if(i - j >= 0) dp[i] = (dp[i] + dp[i-j]) % mod;
    }
  }
  rep(i, 100010){
    sum[i] = dp[i];
    if(i > w) sum[i] = (sum[i] + sum[i-w]) % mod;
  }
}

int main(){
  string str;
  maketable(dp0,sum0,3);
  maketable(dp1,sum1,5);
  while(cin >> str && str != "#"){
    int pos = 0;
    ll res = 1;
    while(pos < (int)str.size()){
      char ch = str[pos];
      int len = 0;
      while(pos < (int)str.size() && str[pos] == ch){
	pos++;
	len++;
      }
      if(ch == '8' || ch == '0'){
	res = (res * sum0[len]) % mod;
      }else{
	res = (res * sum1[len]) % mod;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 4268
n = int(input())
a = list(map(int, input().split()))
ans = [0, 0]
s = [0, 0]
for k in range(2):
  for i in range(n):
    t = (i + k) % 2 * 2 - 1
    s[k] += a[i]
    d = max(0, t * s[k] + 1)
    ans[k] += d
    s[k] += -t * d
print(min(ans))


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

int main() {
  long long n; cin >>n;
  vector<long long>a(n);
  for(long long i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  map<long long,long long>mp;
  for(long long x:a){
    if(mp.count(x)){
      mp.at(x)++;
    }else{
      mp[x]=1;
    }
  }
  long long kotae=0;
  long long sum=0;
  auto begin=mp.begin(),end=mp.end();
  for(auto iter=begin;iter!=end;iter++){
    sum=iter->second;
    if(mp.count(iter->first-1))sum+=mp.at(iter->first-1);
    if(mp.count(iter->first+1))sum+=mp.at(iter->first+1);
    kotae=max(kotae,sum);
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 4992
N,K = map(int,input().split())

if K == 0:
  print(N**2)
  exit()

ans = 0
for b in range(1,N+1):
  if b <= K: continue
  else: ans += N//b*(b-K) + max(0,(N-(N//b)*b)-K+1)

print(ans)

Measured memory_bytes: 39152
N = int(input())
list = []
for i in range(1, N + 1):
    if i % 3 == 0 and i % 5 == 0:
        "FizzBuzz"
    elif i % 3 == 0:
        "Fizz"
    elif i % 5 == 0:
        "Buzz"
    else:
        list.append(i)
print(sum(list))

Measured memory_bytes: 30032
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int f=0;
	long long int n;
	cin>>n;
	long long int p=0,r;
	//if(n%7==0)
	//n=n/7;
	for(long double i=1;i<=n;i++)
	{
	p=(p*10+7)%n;	//r=p/n;
	if(p==0)
	{
	f=1;
	r=i;
	break;
}
}
	if(f==1)
	cout<<r<<endl;
	else
	cout<<"-1"<<endl;
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int n, m, a, b;
  
  scanf("%d%d", &n, &m);
  vector<int> city(n+1, 0);
  
  for(int i = 0; i < m; i++){
    scanf("%d%d", &a, &b);
    city[a]++;
    city[b]++;
  }
  
  for(int i = 1; i <= n; i++){
    printf("%d\n", city[i]);
  }
  
}


Measured memory_bytes: 256
val mod = (1e9 + 7).toInt()

fun main() {
  val n = readLine()!!.toLong()
  
  var res = pow(10, n)
  res = (res - pow(9, n) - pow(9, n) + mod + mod) % mod
  res = (res + pow(8, n)) % mod
  println(res)
}
 
fun pow(a:Long, n:Long):Long {
	var res = 1L
  	var a = a
  	var n = n
  	while(n > 0) {
    	if(n % 2 == 1L) res = (res * a) % mod  
      	n = n / 2
        a = (a * a) % mod
    }
  	return res
}

Measured memory_bytes: 34068
n, d = map(int,input().split())
points = []

for i in range(n):
  points.append(list(map(int,input().split())))

def distance(a, b):
  dist = 0
  
  for a, b in zip(a, b):
    dist += (a - b) ** 2

  if dist == 0:
    return False
  return int(dist ** 0.5) ** 2 == dist

count = 0

for pa in points:
  for pb in points:
    if distance(pa, pb):
      count += 1

print(count // 2)

Measured memory_bytes: 9464
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		char n[] = N.toCharArray();
		//boolean ok[] = new boolean[3];
		//Arrays.fill(ok, true);
		int count = 0;
		for(int i=0;i<3;i++) {
		//System.out.println(n[i]);
			if(n[i] == '7') {
				count ++;
			}
		}
		if(count>0) {
	System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		
	}
}

Measured memory_bytes: 35440
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	cout<<(n/2+(n%2))<<endl;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (int)1e9+7

class UnionFind {
private:
    int size_;
    vector<int> par, rank;
public:
    UnionFind() : size_(0), par(vector<int>(0)), rank(vector<int>(0)) {}
    UnionFind(int size_) : size_(size_) {
        par.resize(size_), rank.resize(size_);
        rep(i,size_) par[i] = i, rank[i] = 0;
    }
    // 現在のsize_を返す
    int size() { return size_; }
    // 親を返す
    int root(int x) { return (par[x] == x) ? x : par[x] = root(par[x]); }
    // ２つの頂点を連結する
    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
    // 親が同じかを判定する
    bool same(int x, int y) { return root(x) == root(y); }
};

struct edge {
    int u, v, cost;
    edge(int u, int v, int cost) : u(u), v(v), cost(cost) {}
};

int d[105][105], ans, n, m, a, b, c;
vector<edge> v;

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

    cin >> n >> m;
    rep(i,n) rep(j,n) d[i][j] = (i == j) ? 0 : INF;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b >> c;
        d[a-1][b-1] = d[b-1][a-1] = c;
        v.push_back(edge(a-1,b-1,c));
    }

    rep(k,n) {
        rep(i,n) {
            rep(j,n) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    rep(i,v.size()) {
        if (d[v[i].u][v[i].v] != v[i].cost) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
package main

import "fmt"

func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}

func minMax(a, b, c int64) (min, max int64) {
	if a > b {
		a, b = b, a
	}
	if a > c {
		a, c = c, a
	}
	if b > c {
		b, c = c, b
	}
	min = a
	max = c
	return
}

func divideVerticalDiff(h, w, x int64) int64 {
	s1 := x * h
	w1 := (w - x) / 2
	w2 := (w - x) - w1
	s2 := w1 * h
	s3 := w2 * h
	min, max := minMax(s1, s2, s3)
	return max - min
}

func divideHorizontalDiff(h, w, x int64) int64 {
	s1 := x * h
	h1 := h / 2
	h2 := h - h1
	s2 := (w - x) * h1
	s3 := (w - x) * h2
	min, max := minMax(s1, s2, s3)
	return max - min
}

func calcMin(h, w int64) int64 {
	result := int64(10000000000)
	for x := int64(0); x <= w; x++ {
		minDiff := min(divideVerticalDiff(h, w, x), divideHorizontalDiff(h, w, x))
		if minDiff < result {
			result = minDiff
		}
	}
	return result
}

func main() {
	var h, w int64
	fmt.Scan(&h, &w)

	fmt.Println(min(calcMin(h, w), calcMin(w, h)))
}

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

int main(){
  int n,ans=1,i,cou1=0,cou2=0;
  char c[200010];
  
  scanf("%d",&n);
  scanf("%s",c);
  for(i=0;i<n;i++)if(c[i]=='R')cou1++;
  for(i=0;i<cou1;i++)if(c[i]=='R')cou2++;
  
  printf("%d\n",cou1-cou2);
  return 0;
}

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


int main(){
    ll a,b,v,w,t;

    cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    ll dis = abs(b-a);
    ll x = v-w;
    ll dismax = x*t;
    if(dismax>=dis){
        cout<<"YES"<<endl;
    }
    else {
        cout<<"NO"<<endl;
    }

}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<29;
const bool debug = 0;

int N;
int p[5000], c[5000];

int solve(int x) {
	copy(p, p + N, c);
	
	int res = x;
	c[0] -= x;
	
	FOR(i, 1, N) {
		if (c[i - 1] > 0) {
			res += c[i - 1] * 2;
			c[i] -= c[i - 1];
		}
	}
	
	if (c[N - 1] > 0) res += c[N - 1];
	return res;
}

int main() {
  cin >> N;
  REP(i, N) scanf("%d", p + i);
  
  int ans = INF;
  REP(i, p[0] + 1) chmin(ans, solve(i));
  cout << ans << endl;
  
	return 0;
}

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

int main() {
	int yen;
	int k;
	cin >> yen >> k;
	int digits[10] = {0,0,0,0,0,0,0,0,0,0};
	for(int i = 0; i < k; i++){
		int d;
		cin >> d;
		digits[d]++;
	}
	vector<int> valid;
	vector<int> backyen;
	int index = 0;
	for(int i = 0; i < 10; i++){
		if(digits[i] == 0){
			index++;
			valid.push_back(i);
		}
	}
	int ans = 0;
	int power = 0;
	int x = yen;
	while(x != 0){
		int flag = 0;
		int d = x%10;
		for(int i = 0; i < index; i++){
			if(valid[i] == d){
				flag = 1;
				i = index;
			}
		}
		if(flag == 1) x = x/10;
		else{
			yen++;
			x = yen;
		}
	}
	
	cout << yen << endl;
	
}

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

int main() {
  int n,y; cin>>n>>y;
  vector<int> A(3, -1);
  rep(i, y/10000+1) {
    rep(j, y/5000+1) {
      if (i+j>n) continue;
      int tmp=y-10000*i-5000*j;
      if ((tmp>=0)&&(tmp/1000+i+j==n)) {
        A[0]=i;
        A[1]=j;
        A[2]=tmp/1000;
        break;
      }
    }
  }
  rep(i, 3) cout<<A[i]<<" ";
  cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
using ll = unsigned long long;

int main(){
    int n;
    cin>>n;
    set<ll> s;
    for(int i=0;i<n;i++){
        ll t;
        cin>>t;
        s.insert(t);
    }

    ll ans=1;
    for(ll t : s){
        ans=ans/__gcd(ans,t)*t;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
### subroutines

def count_rec(k, i, n)
  if k == 1
    i0 = Math.sqrt(n + 0.5).floor
    return (i0 * i0 == n && i0 >= i) ? 1 : 0
  end

  count = 0
  i0 = i

  loop do
    i0sq = i0 * i0
    n0 = n - i0sq
    break if n0 < i0sq
    count += count_rec(k - 1, i0, n0)
    i0 += 1
  end

  count
end

### main

loop do
  n = gets.to_i
  break if n == 0

  puts count_rec(4, 0, n)
end

Measured memory_bytes: 6100
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)

//グローバル変数宣言
 ll p=0,q=0,r=0;

int main()
{
  ll n;
  cin>>n;
  vl a(n),b(n);
  rep(i,n){
    cin>>a[i];
    b[i]=a[i];
  }
  sortm(b);
  rep(i,n){
  if (b[0]==b[1])
  {
    print(b[0])
  }else
  {
    if(a[i]==b[0]){
      print(b[1])
    }else print(b[0])
  }
  
  }
}

Measured memory_bytes: 6352
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)

int abs(int a,int b){
    if(a>b)return a-b;
    else return b-a;
}

int main(){
    int N;
    int h[100000];
    cin>>N;
    rep(i,N) cin>>h[i];
    int cost[100001];
    cost[1] = 0;
    cost[2] = abs(h[0]-h[1]);
    int hoge;
    for(int i=3;i<N+1;i++) cost[i] = min(cost[i-1] + abs(h[i-1]-h[i-2]) , cost[i-2] + abs(h[i-1]-h[i-3]));
    cout<< cost[N] << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] low = new int[n];
		
		for(int i = 0; i < n; i++){
			int input = sc.nextInt();
			low[i] = input;
		}
		
		
		int j = 0;
		int count = 0;
		for(j = 1; j < low.length; j++){
			if(j+1 >= low.length){
				break;
			}
			if(low[j-1] < low[j] && low[j] < low[j+1]){
				count++;
			}
			else if(low[j+1] < low[j] && low[j] < low[j-1]){
				count++;
			}
		}
		System.out.println(count);
	}
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int x; cin >> x;
    ll ans = 0;
    while(x>=5){
        if(x>=500){ x-=500; ans += 1000;}
        else{ x-=5; ans += 5;}
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}
const int N=3000+5;
int dp[N][N][2];
int A[N];
/*int recur(int l,int r,int step)
{
    if(l>r)
    return 0;
    if(l==r)
    return A[l];
    if(r-l==1)
    {
        if(step)
        return max(A[l],A[r]);
        else
        return min(A[l],A[r]);
    }
    if(dp[l][r][step]!=-1)
    return dp[l][r][step];
    int ans;
    if(step)
    {
        ans=max(A[l]+recur(l+1,r,0),A[r]+recur(l,r-1,0));
    }
    else
    {
        ans=min(recur(l+1,r,1),recur(l,r-1,1));
    }
    return dp[l][r][step]=ans;
    

}*/

int recur(int l,int r,int step)
{
    if(l>r)
    return 0;
    if(r-l==1)
    {
        if(step==0)
        return max(A[l],A[r]);
        else
        
        return min(A[l],A[r]);
 
    }

    if(dp[l][r][step]!=-1)
    return dp[l][r][step];

    int ans=0;
    if(step==0)
    ans=max(A[l]+recur(l+1,r,1),A[r]+recur(l,r-1,1));
    else
    ans=min(recur(l+1,r,0),recur(l,r-1,0));

    return dp[l][r][step]=ans;
}
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int n;
    cin>>n;
    int s=0;
    for(int i=0;i<n;i++)cin>>A[i],s+=A[i];
    memset(dp,-1,sizeof(dp));
    
    int x = max(A[0]+recur(1,n-1,1),A[n-1]+recur(0,n-2,1));
    //test2(x,s-x);
    cout<<x-s+x;


return 0;
}

Measured memory_bytes: 141440
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int n = sc.nextInt();
int[] x=new int[n+1];
int[] y=new int[n+1];
for(int i=1;i<=n;i++){x[i]=sc.nextInt();y[i]=x[i];}
Arrays.sort(x);
int m=(x[n/2]+x[n/2+1])/2;
for (int i = 1; i <= n; i++) {
    if(y[i]<=m){
        out.println(x[n/2+1]);
    }else{
        out.println(x[n/2]);
    }
}
}
}

Measured memory_bytes: 92432
#include<stdio.h>

int main()

{

  int x,b,res;
  char c;

  scanf ("%d %c %d",&x, &c, &b);
  switch(c)
  {
    case '+': res=x+b;
    printf("%d",res);
    break;

    case '-': res=x-b;
    printf("%d",res);
    break;

  }

  return 0;
}

Measured memory_bytes: 1700
#include<stdio.h>
int main(){
    int a[4];
    int b,c;
    int n;
    scanf("%d",&n);
    for(int i=3;i>=0;i--){
        a[i]=n%10;
        n=n/10;

    }
    b=a[0]*10+a[1];     //first two
    c=a[2]*10+a[3];     // next two
    if(c<13 && c>0 && (b>12 || b<1))
    printf("YYMM");
    else if(b<13 && b>0 && (c>12 || c<1))
    printf("MMYY");
    else if(b<13 && b>0 && c<13 && c>0) 
    printf("AMBIGUOUS");
    else
    printf("NA");
    return 0;
}

Measured memory_bytes: 1728
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi p(n);
	rep(i, n) cin >> p[i];
	int ans = 0;
	repn(i, 1, n - 1){
		vi cur = {p[i - 1], p[i], p[i + 1]};
		sort(all(cur));
		if(cur[1] == p[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include<cstdio>
#define MAX 10000
#define NIL -1

struct node {int parent,left,right;};

node t[MAX];
int n, D[MAX],H[MAX];

void setdepth(int u,int d){
  if(u==NIL) return;
  D[u]=d;
  setdepth(t[u].left,d+1);
  setdepth(t[u].right,d+1);
}

int setheight(int u){
  int h1=0,h2=0;
  if(t[u].left!=NIL)
    h1=setheight(t[u].left)+1;
  if(t[u].right!=NIL)
    h2=setheight(t[u].right)+1;
  return H[u]=(h1>h2?h1:h2);
}

int getsibling(int u){
  if(t[u].parent==NIL) return NIL;
  if(t[t[u].parent].left!=u&&t[t[u].parent].left!=NIL)
    return t[t[u].parent].left;
  if(t[t[u].parent].right != u&&t[t[u].parent].right!=NIL)
    return t[t[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",t[u].parent);
  printf("sibling = %d, ",getsibling(u));
  int deg=0;
  if(t[u].left!=NIL) deg++;
  if(t[u].right!=NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(t[u].parent==NIL){
    printf("root\n");
  }else if(t[u].left==NIL&&t[u].right==NIL){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root=0;
  scanf("%d",&n);

  for(int i=0;i<n;i++) t[i].parent=NIL;

  for(int i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    t[v].left=l;
    t[v].right=r;
    if(l!=NIL) t[l].parent=v;
    if(r!=NIL) t[r].parent=v;
  }

  for(int i=0;i<n;i++) if(t[i].parent==NIL) root=i;
  setdepth(root,0);
  setheight(root);
  for(int i=0;i<n;i++) print(i);

  return 0;
}



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

using namespace std;

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

#define INF (1<<(4*4-1))
#define MOD 1000000007

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

   int N;
   cin>>N;
   vector<ll>a(N);
   for(int i=0;i<N;i++)cin>>a[i];

   for(int i=0;i<N;i++)a[i]-=(i+1);

   int b;
   sort(a.begin(),a.end());
   if(N%2){
      b = a[N/2];
   }
   else{
      b = (a[N/2]+a[N/2-1])/2;
   }

   ll ans = 0;
   for(int i=0;i<N;i++){
      ans += abs(b-a[i]);
   }

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


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll H, W, N;
  IN(H,W,N);
  vpll O1;
  vpll O;
  REP(i,N){
    ll X, Y;
    IN(X,Y);
    X--;
    Y--;
    if(X<Y) continue;
    O.pb(make_pair(X, Y));
    O1.pb(make_pair(X-Y, Y));
  }

  sort(ALL(O1));

  ll d_tmp = -1;
  ll y_tmp = -1;
  vll O2(W, -1);
  ll count = 0;
  REP(i,O1.size()){
    ll d = O1[i].first;
    ll y = O1[i].second;
    if(d!=count) continue;
    if(d==d_tmp || y<y_tmp) continue;
    count++;
    d_tmp = d;
    y_tmp = y;
    O2[y] = d+y+1;
  }
  ll last = 0;
  REP(i,W){
    if(O2[i]<0){
      O2[i]=last;
      last++;
    }else{
      last=O2[i]+1;
    }
  }

  //vec_print(O2);

  ll ans = H;
  REP(i,O.size()){
    ll X = O[i].first;
    ll Y = O[i].second;
    //debug_print(X, Y);
    if(X<O2[Y]) continue;
    chmin(ans, X);
  }

  OUT(ans);



  return 0;
}


Measured memory_bytes: 10464
s = input()

s_list = list(s)

length = int(len(s) / 2 + 1)
count = 0

for dd in range(length):
    if s_list[dd] != s_list[len(s) -1 - dd]:
        s_list[len(s) -1 - dd] = s_list[dd]
        count += 1

print(count)

Measured memory_bytes: 3060
h, w, k = map(int, input().split())
s = [[0] * (w+1)] + [[0] + list(map(int, list(input()))) for _ in range(h)]

c = [[0 for _ in range(w+1)] for _ in range(h+1)]

for i in range(1, h+1):
    temp = 0
    for j, x in enumerate(s[i]):
        temp += x
        c[i][j] = c[i-1][j] + temp

inf = float('inf')
ans = inf
mb = 1 << (h-1)
for i in range(1 << (h-1)):
    b = list(map(int, list(reversed(bin(mb + i)[2:]))))
    temp = sum(b) - 1
    L = 0
    #print(b)
    for R in range(1, w+1):
        U = 0
        for D in range(1, h+1):
            if b[D-1] == 1:
                if c[D][R] - c[U][R] - c[D][L] + c[U][L] > k:
                    #print(c[D][R],c[U][R],c[D][L],c[U][L])
                    if R - L == 1:
                        temp = inf
                    else:
                        temp += 1
                    L = R - 1
                    break
                U = D
        #print(temp)
        if temp == inf:
            break
    ans = min(ans, temp)

print(ans)

Measured memory_bytes: 44892
def examA():
    S = SI()
    if S=="AAA" or S=="BBB":
        print("No")
    else:
        print("Yes")
    return

def examB():
    N, A, B = LI()
    loop = N//(A+B)
    ans = loop*A + min(A,N%(A+B))
    print(ans)
    return

def examC():
    A, B = LI()
    ans = -1
    for i in range(1,20000):
        if i*8//100==A:
            if i*10//100==B:
                ans = i
                break
    print(ans)
    return

def examD():
    S = SI()
    Q = I()
    rev = 0
    L = ""; R = ""
    for _ in range(Q):
        q = LSI()
        if q[0]=="1":
            rev += 1
        else:
            c = int(q[1])
            if (c+rev)%2==1:
                L += q[2]
            else:
                R += q[2]
    ans = ""
    if rev%2==0:
        ans = L[::-1] + S + R
    else:
        ans = R[::-1] + S[::-1] + L
    print(ans)
    return

def examE():
    N, P = LI()
    S = SI()
    A = [0]*(N+1)
    cur = 0
    if P==5:
        ans = 0
        for i in range(N):
            if int(S[N-1-i])%5==0:
                ans += N-i
        print(ans)
        return
    elif P==2:
        ans = 0
        for i in range(N):
            if int(S[N-1-i])%2==0:
                ans += N-i
        print(ans)
        return

    for i in range(N):
        s = int(S[N-1-i])
        cur += s*pow(10,i,P)
        A[i+1] = cur%P
    D = [0]*P
    for a in A:
        D[a] += 1
    ans = 0
    #print(A)
    for d in D:
        ans += d*(d-1)//2

    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examE()

"""

"""

Measured memory_bytes: 43228
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if(n*a < b)
    cout << n*a << endl;
  else 
    cout << b << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC75_C
{
    class Program
    {
        static bool[][] g;
        static bool[] visited;
        static int n;
        static void dfs(int v)
        {
            visited[v] = true;
            for (int i = 0; i < n; i++)
            {
                if (!g[v][i]) continue;
                if (visited[i]) continue;
                dfs(i);
            }
        }

        static void Main(string[] args)
        {
            const int nmax = 50;
            var s = Console.ReadLine().Split();
            n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            g = new bool[nmax][];
            visited = new bool[nmax];
            for (int i = 0; i < nmax; i++)
            {
                visited[i] = false;
                g[i] = new bool[nmax];

                for (int j = 0; j < nmax; j++)
                {
                    g[i][j] = false;
                }
            }
            var a = new int[nmax][];

            for (int i = 0; i < m; i++)
            {

                a[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
                g[a[i][0] - 1][a[i][1] - 1] = true;
                g[a[i][1] - 1][a[i][0] - 1] = true;

            }

            int count = 0;

            for (int i = 0; i < m; i++)
            {
                g[a[i][0] - 1][a[i][1] - 1] = g[a[i][1] - 1][a[i][0] - 1] = false;

                for (int j = 0; j < n; j++) visited[j] = false;

                dfs(0);
                bool b = false;
                for (int j = 0; j < n; j++) if (!visited[j]) b = true;
                if (b) count++;
                g[a[i][0] - 1][a[i][1] - 1] = g[a[i][1] - 1][a[i][0] - 1] = true;

            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    ll n, m;
    cin >> n >> m;
    if (2*n >= m) cout << m/2 << endl;
    else cout << n + (m - 2*n)/4 << endl;
    return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e13 + 5);

using ql = pair<ll, ll>;

const int MAX_N = (int)(3e2 + 5);

int n, m;
ll l;

ll cost[MAX_N][MAX_N];

int q;

ql jump[MAX_N][MAX_N];

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  scanf("%lld", &l);

  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      cost[i][j] = INF;
      cost[j][i] = INF;

      jump[i][j] = ql(INF, INF);
      jump[j][i] = ql(INF, INF);
    }
    cost[i][i] = 0L;
    jump[i][i] = ql(INF, INF);
  }

  for (int i = 0; i < m; ++i) {
    int a, b;
    ll c;

    scanf("%d %d %lld", &a, &b, &c);

    cost[a][b] = c;
    cost[b][a] = c;
  }

  for (int s = 1; s <= n; ++s) {
    priority_queue<pair<ql, int>, vector<pair<ql, int>>, greater<pair<ql, int>>>
        pq;

    pq.push(make_pair(ql(0L, 0L), s));

    jump[s][s] = ql(0L, 0L);

    while (!pq.empty()) {
      auto cur = pq.top();
      pq.pop();

      ll times = cur.first.first;
      ll running = cur.first.second;
      int node = cur.second;

      if (cur.first > jump[s][node]) continue;

      for (int i = 1; i <= n; ++i) {
        if (s == i) continue;
        if (cost[node][i] > l) continue;

        ll streched_running = running + cost[node][i];

        ll next_times = (streched_running > l) ? times + 1 : times;
        ll next_running =
            (streched_running > l) ? cost[node][i] : streched_running;

        auto candidate = ql(next_times, next_running);

        if (jump[s][i] <= candidate) continue;

        jump[s][i] = candidate;

        pq.push(make_pair(candidate, i));
      }
    }
  }

  scanf("%d", &q);

  for (int i = 0; i < q; ++i) {
    int s, t;
    scanf("%d %d", &s, &t);

    ll ans = (jump[s][t].first == INF) ? -1L : jump[s][t].first;

    printf("%lld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 3908
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
typedef pair<pi,int> pii;

int n;
set <int> coords;
vector <pii> points;
//0 is red, 1 is blue

int main() {
	FAST
	cin >> n;
	for (int i =0;i<n;i++) {
		int x,y; cin >> x >> y;
		points.push_back(pii(pi(x,y),0));
	}
	for (int i=0;i<n;i++) {
		int x,y; cin >> x >> y;
		points.push_back(pii(pi(x,y),1));
	}
	sort(points.begin(),points.end());
	int ans = 0;
	for (auto cur: points) {
		int y = cur.f.s;
		if (cur.s == 0) { // red
			coords.insert(y);
		} else { // blue
			auto it = coords.lower_bound(y);
			if (it == coords.begin()) continue;
			it--;
			//cout << (*it) << "\n";
			coords.erase(it);
			ans++;
			//cout << cur.f.f << " " << y << " " << ans << "\n";
		}
	}
	cout << ans;
}	



Measured memory_bytes: 256
#include<iostream>
#define ll long long
using namespace std;
ll gcd(ll a,ll b)
{
	ll dividend = a>=b ? a:b;
	ll divisor = a<=b ? a:b;
	
	while(divisor!=0)
	{
		ll remainder = dividend%divisor;
		dividend = divisor;
		divisor = remainder;
	}
	return dividend;
}
int main()
{
	ll a,b;
	cin>>a>>b;
	cout<<(a*b)/gcd(a,b);
	
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Console;

public static class Program
{
    public static void Main()
    {
        var line = ReadLine();
        Int16 a = 0;
        long count = 0;
        for(a=0; a < (1 << (line.Length - 1)); ++a)
        {
            List<char> temp = new List<char>(){ line[0] };
            for(int i = 0; i < line.Length - 1; ++i)
            {
                if((a & (1 << i)) != 0)
                {
                    count += int.Parse(new string(temp.ToArray()));
                    temp.Clear();
                }
                temp.Add(line[i + 1]);
            }
            count += long.Parse(new string(temp.ToArray()));
        }
        WriteLine(count);
    }
}

Measured memory_bytes: 27792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n;
    cin>>n;
    REP(i,32000){
        if(i*i>n){
            cout<<(i-1)*(i-1);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
int D[40][40];
int cnt[3][40];
#define loop(i,N) for(int (i)=0; (i)<(N); ++(i))
using namespace std;
int main() {
	long long N, C, t, r = -1;
	cin >> N >> C;
	loop(i, C) loop(n, C) cin >> D[i+1][n+1];
	loop(i, N) loop(n, N) {
		cin >> t;
		++cnt[(i+n+2)%3][t];
	}
	for (int c1 = 1; c1 <= C; ++c1) {
		for (int c2 = 1; c2 <= C; ++c2) {
			if (c1 == c2) continue;
			for (int c3 = 1; c3 <= C; ++c3) {
				if (c3 == c2) continue;
				if (c3 == c1) continue;

				long long res = 0;
				for (int i = 1; i <= C; ++i)
					res += cnt[0][i] * D[i][c1];

				for (int i = 1; i <= C; ++i) 
					res += cnt[1][i] * D[i][c2];

				for (int i = 1; i <= C; ++i) 
					res += cnt[2][i] * D[i][c3];

				r = (r == -1 ? res : std::min(res, r));

			}
		}
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 256