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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

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

  if (K > (N - 1) * (N - 2) / 2){
    cout << -1 << endl;
    return 0;
  }

  vector <Pii> ans;
  for (int i = 2; i <= N; i++){
    ans.push_back({1, i});
  }

  int cnt = (N - 1) * (N - 2) / 2;
  for (int i = 2; i <= N; i++){
    for (int j = i + 1; j <= N; j++){
      if (cnt == K) break;
      ans.push_back({i, j});
      cnt--;
    }
    if (cnt == K) break;
  }

  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++){
    cout << ans[i].fi << " " << ans[i].se << endl;
  }

  return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, x);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

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 main(void) {
  multimap<int, int> m;
  for (int i = 0; i < 3; i++) {
    int a, b;
    cin >> a >> b;
    m.emplace(make_pair(a, b));
    m.emplace(make_pair(b, a));
  }
  int cnt = 0;
  for (int i = 1; i <= 4; i++) {
    if (m.count(i) == 1 || m.count(i) == 2) {
      cnt++;
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  if (cnt == 4) {
    cout << "YES" << endl;
  }
  return 0;
}

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

int main(){
  int h,w,m;
  cin>>h>>w>>m;
  vector<set<int>> b(h);
  vector<int> sums_h(h,0);
  vector<int> sums_w(w,0);
  int bh,bw;
  for(int i=0;i<m;i++){
    cin>>bh>>bw;
    sums_h.at(bh-1)++;
    sums_w.at(bw-1)++;
    b.at(bh-1).insert(bw-1);
  }
  int result=0;
  int max_h=0;
  int max_w=0;
  vector<int> index_h;
  vector<int> index_w;
  for(int i=0;i<h;i++){
    if(max_h<sums_h.at(i)){
      max_h=sums_h.at(i);
      index_h.clear();
      index_h.push_back(i);
    }else if(max_h==sums_h.at(i)){
      index_h.push_back(i);
    }
  }
  for(int j=0;j<w;j++){
    if(max_w<sums_w.at(j)){
      max_w=sums_w.at(j);
      index_w.clear();
      index_w.push_back(j);
    }else if(max_w==sums_w.at(j)){
      index_w.push_back(j);
    }
  }
  for(int i=0;i<index_h.size();i++){
    for(int j=0;j<index_w.size();j++){
      if(!b.at(index_h.at(i)).count(index_w.at(j))){
        cout<<max_h+max_w<<endl;
        return 0;
      }
    }
  }
  cout<<max_h+max_w-1<<endl;
}
 

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

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

multiset <pi> a, b;
int n, pos;
ll ret;
void move (int l, int r) {
	if (pos < l) {
		ret += l - pos;
		pos = l;
	}
	if (pos > r) {
		ret += pos - r;
		pos = r;
	}
} ;

ll travel (multiset <pi> l, multiset <pi> r, int o) {
	int i, u, v;
	ret = pos = 0;
	for (i = 1; i <= n; i ++) {
		if (o) tie(u, v) = *l.rbegin();
		else tie(v, u) = *r.begin();
		l.erase (l.find(pi (u, v))), r.erase (r.find(pi (v, u)));
		move (u, v), o ^= 1;
	}
	move (0, 0);
	return ret;
}

int main () {
	int i, u, v;
	scanf ("%d", &n);
	for (i = 1; i <= n; i ++) {
		scanf ("%d%d", &u, &v);
		a.insert (pi(u, v));
		b.insert (pi(v, u));
	}
	printf ("%lld\n", max(travel (a, b, 0), travel (a, b, 1)));
	return 0;
}

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

int main()
{
	string s,an="";
	cin>>s;
	for(auto i: s)
	if(i=='B'){if(an.size())an.pop_back();}
	
	else an.push_back(i);
	cout<<an<<endl;
	
}





Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k;

int main(){
  ll ans=1;
  cin >> k;
  ll x=7;
  

  for(ll i=0;i<1000000;i++){
	  x%=k;
	  if (x==0)break;
	  x*=10;
      x+=7;
	  ans++;
  }
  if (ans==1000001){
	  cout<<-1<<endl;
	  return 0;
  }

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

Measured memory_bytes: 3628
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
  while(true){
    int n,k;
    scanf("%d %d",&n,&k);
    if(n==0&&k==0) return 0;
    int a[n];
    for(int i=0;i<n;i++) scanf("%d",a+i);
    int sum = 0,ans = 0;
    for(int i=0;i+k<=n;i++){
      if(i==0){
        for(int j=0;j<k;j++) sum += a[i+j];
        ans = sum;
      }else{
        sum = sum - a[i-1] + a[i+k-1];
        ans = max(ans,sum);
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 3140
N = int(input())
A=[]
A.append(1)
for i in range(1,7):
    A.append(6**i)
for i in range(1,6):
    A.append(9**i)
A.sort()
dp=[10*5+5]*(N+1)
dp[0]=0
for i in range(1,N+1):
    for s in range(len(A)):
        if i-A[s]>=0:
            dp[i]=min(dp[i-A[s]]+1,dp[i])
print(dp[N])

Measured memory_bytes: 41836
#include <stdio.h>

int main(int argc, char const *argv[]){
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c); 

	if(a + b + c == 17 && a * b * c == 175) printf("YES");
	else  printf("NO"); 

	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int absDiff(int a,int b){
	if(a<b)
	return b-a;
	else
	{
		return a-b;
	}
	
}
int fact(int n){
	int result;
	if(n==0)
	result=1;
	else if(n==1)
	result=1;
	else{
		result=n*fact(n-1);
	}
	return result;
}
int main(){
	int n;
	int p=0,q=0;
	scanf("%d",&n);
	int a[n+1];
	int b[n+1];
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		int count=0;
		for(int j=1;j<i;j++){
			if(a[j]<a[i]){
				count++;
			}
		}
		p+=(a[i]-count-1)*(fact(n-i));
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
		int count=0;
		for(int j=1;j<i;j++){
			if(b[j]<b[i])
			count++;
		}
		q+=(b[i]-count-1)*fact(n-i);
	}
	p++;
	q++;
	printf("%d\n",absDiff(p,q));

}

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

int main(){
    int N,Y;
    bool f=false;
    
    cin >> Y >> N;

    for (int i=0;i<=N/10000;i++){
        for (int j=0;j<=(N-10000*i)/5000;j++){
            int k = (N -10000*i - 5000* j)/1000;
            if (i+j+k==Y){
                cout << i << " " << j << " " << k << endl;
                f = true;
                break;
            }
        }
        if (f){
            break;
        }
    }

    if (f == false){
        cout << -1 << " " << -1 << " " << -1 << endl;
    }
    }

    //sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});


Measured memory_bytes: 256
'use strict'

function main(input) {
  input = input.split('\n')
  const n = ~~input[0]
  const troopers = input[1]

  const accumulation = [0]
  //Array.apply(null, {
  //   length: n + 1
  // }).map(v => 0)

  for (let i = 0; i < n; i++) {
    if (troopers[i] == 'W') {
      accumulation[i + 1] = accumulation[i] + 1
    } else {
      accumulation[i + 1] = accumulation[i]
    }
  }
  // accumulation.shift()
  // console.log(accumulation)

  let min = Number.MAX_SAFE_INTEGER
  for (let i = 0; i < n; i++) {
    // W M E

    let w = accumulation[i] // 左側のWの数
    let e = n - (i+1) - (accumulation[n] - accumulation[i + 1])
    let tmp = w + e
    // console.log(w, e)

    min = min > tmp ? tmp : min
  }
  console.log(min)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 16332
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         int K=gi();
         int R=gi();
         int S=gi();
         int P=gi();
         String T=gs();
         Map<Character,Integer> m=new HashMap<Character,Integer>();
         m.put('r', P);
         m.put('s', R);
         m.put('p', S);
         m.put('n', -1);

         int ans=0;
         List<Boolean> l=new ArrayList<Boolean>();
         for (int i=0; i<N;i++) {
        	 char c=T.charAt(i);
        	 char cmk='n';
        	 if(i-K>=0)cmk=T.charAt(i-K);
        	 if(c!=cmk || !l.get(i-K)) {
        	     if(c=='r') {
        		     ans+=P;
        	     } else if(c=='s'){
        		     ans+=R;
        	     } else {
        		     ans+=S;
        	     }
        	     l.add(true);
        	 } else {
        		 l.add(false);
        	 }

         }


         System.out.println(ans);
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

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


int main()
{
    long long int Q,H,S,D,N;
    cin>>Q>>H>>S>>D>>N;

    double Min,Max;
    double Q1,H1,S1,D1;
    Q1=Q*4;
    H1=H*2;
    S1=S;
    D1=D/2;

    Min=min(Q1,min(H1,min(S1,D1)));

    if(Min==Q1)
    {
        long long int Ans1=N*(Q)*4;
        cout<<Ans1<<endl;
    }
    else
    {
        if(Min==H1)
        {
            long long int Ans1=N*(H)*2;
            cout<<Ans1<<endl;
        }
        else
        {
            if(Min==S1)
            {
                long long int Ans1=N*(S);

                cout<<Ans1<<endl;
            }
            else
            {
                long long int Ans,Z,Ans1;
                Ans=N/2;
                Z=N%(2);
                Max=min(S1,min(Q1,H1));

                if(Max==S1)
                {
                    Ans1=Ans*(D)+(Z*(S));
                }
                else
                {
                    if(Max==H1)
                    {
                        Ans1=Ans*(D)+(Z*(2)*(H));
                    }
                    else
                    {
                        Ans1=Ans*(D)+(Z*(4)*Q);
                    }
                }

                cout<<Ans1<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e10;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if (k <= a){
        PRINT(k);
    }
    else if (k <= a+b){
        PRINT(a);
    }
    else{
        PRINT(a-(k-(a+b)));
    }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
#define foi(n) for(ll i=0;i<n;i++)
using namespace std;
int main(){
 
  string s,t;
  cin>>s>>t;
  ll n=s.length();
  ll n2=t.length();
  ll ans=INT_MAX;
  
  for(ll i=0;i<n-n2+1;i++){
  	ll cnt=0;
  	for(int j=i;j<i+n2;j++){
  		if(s[j]!=t[j-i]) cnt++;
  	}
  	ans=min(ans,cnt);
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 3600
#include <cstdio>
using namespace std;

int main(int argc, char** argv)
{
	int n;
	long long last, res = 0LL;
	scanf("%d%lld", &n, &last);
	while(--n)
	{
		long long x;
		scanf("%lld", &x);
		if(x < last)
		{
			res += last - x;
			x = last;
		}
		last = x;
	}
	printf("%lld\n", res);
	return 0;
}

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



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }

  if(b==0){
    return a;
  }

  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }

  return b;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  /*
  解法2
  (答え)=((総和の2乗)-(2乗の総和))/2
  ということがわかるので，それを実装

  2で割る部分は解法1と同じ

  */
  long int n;
  scanf("%ld",&n);

  long int A[n];
  
  //総和
  long int all=0;
  
  //2乗の総和
  long int sq_all=0;

  long int MOD=1e9+7;

  for(int i=0;i<n;i++){
    scanf("%ld",&A[i]);
    all+=A[i];

    //常にMODを取る！
    all%=MOD;

    sq_all+=modpow(A[i],2,MOD);
    
    //常にMODを取る！
    sq_all%=MOD;
  }


  //MOD上の2の逆元
  long int v=modinv(2,MOD);

  long int ans=modpow(all,2,MOD);
  ans-=sq_all;
  ans+=MOD;
  ans%=MOD;

  //常にMODを取る！
  printf("%ld\n",ans*v%MOD);

  return 0;
}

Measured memory_bytes: 3288
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
	)

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextInt64() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}


func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func (io *Io) PrintBool(b bool, trueS, falseS string) {
	if b {
		io.PrintLn(trueS)
	} else {
		io.PrintLn(falseS)
	}
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func absi(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

type Int64s []int64
func (f Int64s) Len() int {
	return len(f)
}
func (f Int64s) Less(i, j int) bool {
	return f[i] < f[j]
}

func (f Int64s) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}


func solve(io *Io) {
	n := io.NextInt()

	ans := 0
	for i := 0; i < n; i++ {
		ans += io.NextInt() - 1
	}

	io.PrintLn(ans)
}

func main() {
	io := NewIo()
	defer io.Flush()

	solve(io)
}


Measured memory_bytes: 768
#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;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll h, w, k, cnt = 1, ans = 0;
  cin >> h >> w >> k;
  int c[h][w];
  memset(c, 0, sizeof(c));
  string s;
  rep(i, h) {
    cin >> s;
    rep(j, w) if (s[j] == '#') c[i][j] = cnt++;
  }
  int t = 0;
  rep(i, h) {
    t = 0;
    rep(j, w) {
      if (c[i][j] != t && c[i][j] != 0)
        t = c[i][j];
      else
        c[i][j] = t;
    }
  }

  rep(i, h) {
    t = 0;
    rrep(j, w) {
      if (c[i][j] != t && c[i][j] != 0)
        t = c[i][j];
      else
        c[i][j] = t;
    }
  }

  rep(j, w) {
    t = 0;
    rep(i, h) {
      if (c[i][j] != t && c[i][j] != 0)
        t = c[i][j];
      else
        c[i][j] = t;
    }
  }

  rep(j, w) {
    t = 0;
    rrep(i, h) {
      if (c[i][j] != t && c[i][j] != 0)
        t = c[i][j];
      else
        c[i][j] = t;
    }
  }

  rep(i, h) {
    rep(j, w) cout << c[i][j] << " ";
    cout << endl;
  }

  return 0;
}


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

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(), a.end());
	map<int,int> mp;
	rep(i,n) mp[a[i]]++;
	a.erase(unique(a.begin(), a.end()),a.end());

	n = a.size();
	if (n>0) {
		vector<bool> dp(a[n-1]+1, true);
		rep(i,n) {
			if (mp[a[i]] > 1)
				dp[a[i]] = false;
		}
		rep(i,n) {
			for(int j=2;j*a[i]<=a[n-1];j++)
				dp[j*a[i]]=false;
		}
		
		int count=0;
		rep(i,n) {
			if (dp[a[i]]) {
				count++;
			}
		}
		cout << count << endl;
	} else {
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 13380
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    sort(A.rbegin(), A.rend());
    int sum = accumulate(A.begin(), A.end(), 0);
    for(int i=0; i<M; i++) {
        if(4*M*A[i] < sum) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;

    int ans = 0,cnt = 0;
    for(int i=1;i<=1000;i++){
        cnt += i;
        if(cnt-a == (cnt+i+1)-b){
            ans = cnt-a;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,x[51][4],a[300][300];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
map<int,int>z[2];
void asu(int p){
  int cnt=1;
  vector<int>v;
  r(i,n)r(j,4)if(j%2==p)v.push_back(x[i][j]);
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  r(i,v.size())z[p][v[i]]=cnt,cnt+=2;
}
void make_G(){
  r(i,n){
    for(int j=z[0][x[i][0]];j<=z[0][x[i][2]];j++)
      a[z[1][x[i][1]]][j]=1,a[z[1][x[i][3]]][j]=1;
    for(int j=z[1][x[i][1]];j<=z[1][x[i][3]];j++)
      a[j][z[0][x[i][0]]]=1,a[j][z[0][x[i][2]]]=1;
  }
}
void bfs(int y,int x){
  a[y][x]=1;
  queue<pair<int,int> >q;
  q.push(make_pair(y,x));
  while(!q.empty()){
    pair<int,int>p=q.front();q.pop();
    y=p.first,x=p.second;
    r(i,4){
      int yy=y+dy[i],xx=x+dx[i];
      if(yy<0||xx<0||yy>=300||xx>=300)continue;
      if(!a[yy][xx]){
        a[yy][xx]=1;
        q.push(make_pair(yy,xx));
      }
    }
  }
}
int main(){
  while(cin>>n,n){
    int ans=0;
    memset(a,0,sizeof(a));
    r(i,2)z[i].clear();
    r(i,n){
      r(j,4)cin>>x[i][j];
      if(x[i][0]>x[i][2])swap(x[i][0],x[i][2]);
      if(x[i][1]>x[i][3])swap(x[i][1],x[i][3]);
    }
    r(i,2)asu(i);
    make_G();
    r(i,300)r(j,300)if(!a[i][j])ans++,bfs(i,j);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
int main(){
    int n,k;cin >> n >> k;
    string s;cin >> s;
    vector<int> length;
    int cnt=1;
    bool plus=(s[0]=='1') ? true : false;
    for(int i=1;i<n;i++){
        if(s[i]=='0'){
            if(!plus) cnt++;
            else{
                length.push_back(cnt);
                cnt=1;
                plus=false;
            }
        }
        else{
            if(plus) cnt++;
            else {
                length.push_back(-cnt);
                cnt=1;
                plus=true;
            }
        }
    }
    if(plus) length.push_back(cnt);
    else length.push_back(-cnt);
    int Cnt=0;
    int sum=0;
    int end=0;
    int size=length.size();
    int ans=0;
    for(int i=0;i<size;i++){
        int which=0;
        if(end<size) which=(length[end]>0) ? 0 : 1;
        while(end<size&&Cnt+which<=k){
            if(length[end]<0){
                Cnt++;
                sum+=-length[end];
            }
            else{
                sum+=length[end];
            }
            end++;
            if(end<size) which=(length[end]>0) ? 0 : 1;
        }
        ans=max(ans,sum);
        sum-=(length[i]>0) ? length[i] : -length[i];
        Cnt-=(length[i]<0) ? 1 : 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1020
H, W, N = map(int, input().split())
XY = [list(map(int, input().split())) for i in range(N)]
n = 0
XY.sort()
for x, y in XY:
    if x - n == y:
        n += 1
    elif x - n < y:
        continue
    else:
        print(x-1)
        exit()
print(H)


Measured memory_bytes: 52712
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"assert.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	vector<int>a(n),b(n),c(n);
	for(int i=0;i<n;++i)cin>>a[i];
	for(int i=0;i<n;++i)cin>>b[i];	
	for(int i=0;i<n;++i)cin>>c[i];
	sort(all(a));sort(all(b));sort(all(c));
	vector<ll>db(n,-1);
	for(int i=0;i<n;++i)
	{
		int x=upper_bound(c.begin(),c.end(),b[i])-c.begin();
		db[i]=n-x;
	}
	for(int i=n-2;i>=0;--i)
	{
		db[i]+=db[i+1];
	}
	ll ans=0;
	for(int i=0;i<n;++i)
	{
		int x=upper_bound(b.begin(),b.end(),a[i])-b.begin();
		if(x<n)
			ans+=db[x];
	}
	cout<<ans<<'\n';
}

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

bool cmp(const pair<string, int>&i, const pair<string, int>&j)
{
    return i.second > j.second;
}



int main() {
            int AC = 0 , WA= 0 , TLE =0 , RE=0;
            int n ; cin >> n ;  string s ;
             for ( int i = 0 ; i < n ; i ++ ) {
                  cin >> s;
                   if ( s == "AC")
                       AC++;
                   else if ( s == "TLE")
                       TLE++;
                   else if ( s == "WA")
                       WA++;
                   else
                       RE++;
             }

        cout << "AC x "<<AC<<endl;
        cout << "WA x "<<WA<<endl;
        cout << "TLE x "<<TLE<<endl;
        cout << "RE x "<<RE<<endl;
    
        return 0;
    }

Measured memory_bytes: 3616
#include<cstdio>
#define abs(x) ((x>0)?x:(-(x)))
int H,W,D,A;
int Q,L,R;
int px[90001] ,py [90001];
int d[90001];
int  main()
{
    scanf ("%d %d %d",&H,&W,&D);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            scanf ("%d",&A);
            px[A]=i,py[A]=j;
        }
    }
    for(int i=D+1;i<=H*W;i++){ 
        d[i]=d[i-D]+abs(px[i]-px[i-D])+ abs(py[i]-py[i-D]);
    } 
    scanf ("%d",&Q);
    while(Q--){ 
        scanf ("%d%d",&L,&R);
        printf ("%d\n",d[R]-d[L]);
    } 
}

Measured memory_bytes: 2176
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b && b == c) cout << "No" << endl;
  else if(a == b || b == c || c == a) cout << "Yes" << endl; 
  else cout << "No" << endl;
  return 0;
}


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

void dfs(ve<ve<int>> &G, ve<int> &ans,int i, int j,int a){
    ans[i] += a;
    for(int x:G[i]){
        if(x==j) continue;
        dfs(G,ans,x,i,ans[i]);
    }
    return;
}

int main(){
    int n,q;
    cin >> n >> q;
    ve<ve<int>> G(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ve<int> ans(n);
    rep(i,q){
        int p,x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(G,ans,0,-1,0);
    rep(i,n) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

void solve() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::pair<int, int> > c(m);
  // first:s second:c
  rep(i,m) std::cin >> c[i].first >> c[i].second;
  rep(x, std::pow(10, n)) {
    std::vector<int> d(1, x%10);
    int nx = x / 10;
    while (nx) {
      d.push_back(nx%10);
      nx /= 10;	
    }
    std::reverse(d.begin(), d.end());
    if (d.size() != n) continue;
    bool ok = true;
    rep(i,m) if (d[c[i].first-1] != c[i].second) ok = false;
    if (ok) {
      std::cout << x << std::endl;
      return;
    }
  }
  std::cout << -1 << std::endl;
  return;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  int res = 0;
  res = s.size();
  int count = 0;
  for(int i = 0;i < s.size();i++){
    if(s[i] == 'S')count++;
    if(s[i] == 'T'){
      if(count > 0){
        count--;
        res -= 2;
      }
    }
  }
  cout << res << endl;
}

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

int main() {
   string s;
   cin >> s;
   int l=s.size();
   set<char> c;
   rep(i,l)
   c.insert(s[i]);
   cout << (l==c.size() ? "yes" : "no") << endl;
}

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

#define ll long long

int main() {
	ll n, ret = 0;	cin >> n;
	for (ll x = 1; x <= n; x ++) {
		if ( (x % 3 == 0) || (x % 5 == 0)) {

		}
		else {
			ret += x;
		}
	}
	cout << ret << "\n";
}


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

int main()
{
    int m, n;
    cin >> n >> m;
    vector<int> data(n);
    double count = 0;
    rep(i, n)
    {
        cin >> data[i];
        count += data[i];
    }
    sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
    if (data[m - 1] < count / (4 * m))
    {
        cout <<"No";
    }
    else{
        cout <<"Yes";
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, vs, cs):
    """Test Case
    >>> print_ans(3, [10, 2, 5], [6, 3, 4])
    5
    >>> print_ans(4,[13, 21, 6, 19], [11, 30, 6, 15])
    6
    >>> print_ans(1,[1],[50])
    0
    """
    vs = np.array(vs)
    cs = np.array(cs)
    tmps = vs - cs
    ans_list = tmps[tmps > 0]
    if len(ans_list) == 0:
        print("0")
    else:
        print(np.sum(ans_list))
if __name__ == '__main__':
    N = int(input().rstrip())
    vs = list(map(int, input().rstrip().split()))
    cs = list(map(int, input().rstrip().split()))
    print_ans(N, vs, cs)


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

using namespace std;

typedef long long int ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define E(a) cout << #a << ' ' << a << '\n'


const ll M=5e5+5,LG=17,inf=1e18;

int n,m;

pll seg[M];

pll get(ll l,ll r)
{
	pll res={inf,0};
	for (;l<r;l/=2,r/=2)
	{
		if (l&1) smin(res,seg[l++]);
		if (r&1) smin(res,seg[--r]);
	}
	return res;
}

ll calc(ll l,ll r)
{
	if (l==r)
		return 0;
	pll x=get(l,r);
	return calc(l,x.Y)+calc(x.Y+1,r)+x.X*(x.Y-l+1)*(r-x.Y);
}

int main()
{
	cin >> n;
	ll s=0;
	For(i,0,n)
	{
		cin >> seg[i+n].X;
		seg[i+n].Y=i+n;
	}
	Ford(i,n-1,0)
	{
		seg[i]=min(seg[2*i],seg[2*i+1]);
	}
	cout << calc(n,2*n);
}


Measured memory_bytes: 15872
#include "bits/stdc++.h"
using namespace std;

#define int long long

int gcd(int a, int b) {
  if (b == 0) return a;
  else if (a < b) return gcd(b, a);
  else return gcd(b, a % b);
}


signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  // int M;
  array<int, 100000> A;;
  // string S;
  // string T;

  int X;
  
  cin >> N >> X;
  for (auto it = A.begin(); it < A.begin() + N; ++it) cin >> *it;

  for (auto it = A.begin(); it < A.begin() + N; ++it) *it = abs(X - *it);
  
  sort(A.begin(), A.begin() + N);

  for (auto it = A.begin(); it < A.begin() + N; ++it) {
    if (it == A.begin()) num = *it;
    else num = gcd(num, *it);
  }

  cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define mp(x,y) 	     make_pair(x,y)
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define loop(n,i,a)      for(int i=a;i<n;i++)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        loop(n,i,0){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i;
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define pp               pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define intersect(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
//int m=10000009;
//int arr[100000];
#define M 					1000000007 
int isprime(int n)
{
        if(n<=1) return 0;
        if(n<=3) return 1;
        if(n%2==0 ||n%3==0)
        return 0;
    for(int i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)
        return 0;
    }
    return 1;
}
#define PI 3.1415926535
signed main(){
				fast
				//	freopen("input.txt","r",stdin);
				//	freopen("output.txt","w",stdout);
				int n;
				cin>>n;
				double ans=0,a[n],t=n;
				for(int i=0;i<n;i++)
				{
					cin>>a[i];
					
				}
				sort(a,a+n);
				ans = a[0];
				for(int i=1;i<n;i++)
			{
				ans  = (ans+a[i])*(1.0)/2;
			}
			cout<<ans;
			}
			
				
		
		 
		 


Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}

module Main where

import qualified Data.ByteString.Char8 as B8
import Data.Maybe (fromJust)
import Data.Char (toUpper,isDigit)
import Data.List
import qualified Data.Map as M
import Data.Array.IO
import Data.IORef
import Data.Ix (range)
import Control.Monad
import Control.Applicative
import Text.Printf
import Data.Time.Calendar
import Debug.Trace

readDigits = map read <$> words <$> getLine :: IO [Int]
readDigits' = map read <$> lines <$> getContents :: IO [Int]

--
main :: IO ()
main = do
    fn <$> readDigits >>= putStrLn
    where
    fn [a,b,c]
        | a < b && b < c = "Yes"
        | otherwise = "No"

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

using namespace std;

const int N = 2e6+7;
int n, a[N], qtd[N];
bool excluded[N];

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	scanf("%d", &n);

	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		qtd[a[i]]++;
	}
	
	sort(a, a+n);

	int ans = 0;

	for (int i = 0; i < n; i++){
		if (!excluded[a[i]]){
			if (qtd[a[i]] == 1) ans += 1;
			int x = a[i];
			for (int j = x+x; (j < N && j <= a[n - 1]) ; j += x){
				excluded[j] = true;
			}
		}
	}

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

	return 0;
}

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

using namespace std;

int main(void) {
    long n;
    cin >> n;

    vector<long> a(n);
    for(auto &e: a) cin >> e;

    long r = 0;
    for(long i=0; i<n; i++) {
        r += a[i]/2;
        a[i] -= a[i]/2*2;
        if(i+1<n && a[i+1]>0)
            r += a[i], a[i+1] -= a[i];
    }

    cout << r << endl;
}


Measured memory_bytes: 1152
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	key    int
	parent *Node
	left   *Node
	right  *Node
}

var root *Node

func insert(z *Node) {
	var y *Node
	x := root
	for x != nil {
		y = x
		if z.key < y.key {
			x = y.left
		} else {
			x = y.right
		}
	}
	z.parent = y
	if y == nil {
		root = z
	} else if z.key < y.key {
		y.left = z
	} else {
		y.right = z
	}
}

func printByInOrder(w io.Writer, n *Node) {
	if n.left != nil {
		printByInOrder(w, n.left)
	}
	fmt.Fprint(w, " ", n.key)
	if n.right != nil {
		printByInOrder(w, n.right)
	}
}

func printByPreOrder(w io.Writer, n *Node) {
	fmt.Fprint(w, " ", n.key)
	if n.left != nil {
		printByPreOrder(w, n.left)
	}
	if n.right != nil {
		printByPreOrder(w, n.right)
	}
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	for i := 0; i < N; i++ {
		op := sc.nextStr()
		if op == "insert" {
			insert(&Node{sc.nextInt(), nil, nil, nil})
		} else {
			printByInOrder(wtr, root)
			fmt.Fprintln(wtr)
			printByPreOrder(wtr, root)
			fmt.Fprintln(wtr)
		}
	}

	wtr.Flush()
}



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

typedef long long ll;

int n;
ll a[20];

inline void down(ll &x, const ll y) {x > y ? x = y : 0;}

ll dfs(int l, int r, int cl, int cr) {
	if (l > r) return 0;
	int i; ll ret = LLONG_MAX;
	for (i = l; i <= r; ++i) down(ret, (cl + cr) * a[i] + dfs(l, i - 1, cl, cl + cr) + dfs(i + 1, r, cl + cr, cr));
	return ret;
}

int main() {
	int i;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) scanf("%lld", a + i);
	printf("%lld\n", a[1] + a[n] + dfs(2, n - 1, 1, 1));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
//#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
int main(){
	
	/*string s;
	int f=1,f1=1,co=0;
	cin>>s;
	/*char a='Z';
	cout<<(int)a<<endl;*/
	/*
	if(s[0]!='A')f=0;
	if(s[s.size()-1]=='C')f=0;
	for(int i=1;i<s.size();i++){
		if(65<=(int)s[i] && (int)s[i]<=90 && s[i]!='A' && s[i]!='C')f=0;
		if(s[i]=='C')co++;
		if(co!=1)f=0;
		cout<<f;
	}
	cout<<endl;
	if(f)cout<<"AC"<<endl;
	else cout<<"WA"<<endl;*/
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(n*a,b)<<endl;
	
	
	
	
	
	
}

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

int     main() {
        int N;
        cin >>N;
        vector<string> s(N);
        for (int i=0; i<N; i++) {
                string ss;
                cin >>ss;
                sort(ss.begin(), ss.end());
                s.at(i)=ss;
        }
        sort(s.begin(), s.end());
        vector<long> c(0);
        long j=0;
        c.push_back(1);
        for (int i=1; i<N; i++) {
                if (s.at(i)==s.at(i-1)) {
                        c.at(j)++;
                } else {
                        j++;
                        c.push_back(1);
                }
        }
        sort(c.begin(), c.end());
        reverse(c.begin(), c.end());
        long S=0;
        for (int i=0; i<c.size(); i++) {
                if (1<c.at(i)) {
                        long SS = c.at(i)*(c.at(i)-1)/2;
                        S += SS;
                } else break;
        }
        cout <<S <<endl;
};

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	string s, t;
	cin >> s >> t;
	
	rep(i, (int)s.size() - (int)t.size() + 1){
		bool ok = 1;
		rep(j, t.size()) if(s[i + j] != t[j] && t[j] != '_') ok = 0;
		if(ok){
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 1188
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));



int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    map<int,int> count;
    for(int a : A) count[a]++;
    vector<int> B;
    for(auto p : count){
        B.push_back(p.se);
    }
    sort(all(B));
    int n = B.size();
    int num = n;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(num <= K) break;
        ans += B[i];
        num --;
    }
    cout << ans << endl;
}

Measured memory_bytes: 14364
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>
typedef long long LL;

using namespace std;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

int main(void) {
	LL n;
	cin >> n;
	vector<LL>t(n);
	for (LL i = 0; i < n; i++)cin >> t[i];
	LL ans = 1;
	for (LL i = 0; i < n; i++) {
		ans = lcm(ans, t[i]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
def plus(x, y):
    return x+y
def minus(x, y):
    return x-y

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

can = True
if sum(a) < sum(b):
    can = False
    
dif = list(map(minus, a, b))
dif.sort()

count = 0
shortage = list((filter(lambda x: x<0, dif)))
sumofshortage = sum(shortage)
count += len(shortage)

sumofsurplus = 0
for i in dif[::-1]:
    if sumofsurplus+sumofshortage < 0:
        sumofsurplus += i
        count += 1
    else:
        break

if can:
    print(count)
else:
    print(-1)

Measured memory_bytes: 18356
def f(s):
  l=len(s)
  if l%2==0:
    return s[:l//2]==s[l//2:]
s=input()
L=len(s)
for i in range(1,L):
  a=s[:L-i]
  if f(a):
    ans=len(a)
    break
print(ans)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll INM = 114514;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

struct edge {
	ll from, to, cost;
};

ll d[2502];

int main() {
	IOS();
	ll n, m, p;
	cin >> n >> m >> p;
	vector<edge> e(m);
	for (int i = 0; i < m; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		e[i] = (edge){a, b, -c + p};
	}
	for (int i = 1; i <= n; i++) {
		d[i] = INF;
	}
	bool ok = true;
	d[1]	= 0;
	for (int j = 0; j <= 2 * n; j++) {
		bool update = false;
		for (int i = 0; i < m; i++) {
			edge t = e[i];
			if (d[t.from] != INF && d[t.to] > d[t.from] + t.cost) {
				d[t.to] = d[t.from] + t.cost;
				if (j >= n) {
					d[t.to] = -INF;
				}
				update = true;
				if (t.to == n && j >= n) {
					ok = false;
				}
			}
		}
	}
	dump(ok ? max(0ll, -d[n]) : -1);
	return 0;
}

Measured memory_bytes: 384
bingo=[]
for i in range(3):
    bingo.append([int(i) for i in input().split()])
n=int(input())

b=[]
for i in range(n):
    b.append(int(input()))
    
def game(n):
    global bingo
    for gyou in bingo:
        for i in range(3):
            if gyou[i]==n:
                gyou[i]=None


for i in b:
    game(i)
    
ans=0
for i in bingo:
    if i==[None]*3:
        ans+=1
        
for i in range(3):
    if [bingo[0][i],bingo[1][i],bingo[2][i]]==[None]*3:
        ans+=1
if [bingo[0][0],bingo[1][1],bingo[2][2]]==[None]*3 or [bingo[0][2],bingo[1][1],bingo[2][0]]==[None]*3:
    ans+=1
if ans==0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

vector<int> fac, finv, inv;

void comb_init(int n) {
  fac  = vector<int>(n);
  finv = vector<int>(n);
  inv  = vector<int>(n);
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < n; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
 
int comb(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  comb_init(10000);

  FOR(i, 1, K+1){
    cout << (comb(N-K+1, i)*comb(K-1, i-1))%MOD << "\n";
  }

  return 0;
}

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

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3592