akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::string s; std::cin >> s;

  int left = 0, right = 0;
  int cnt = 0;
  for(int i=0; i<sz(s); i++) {
    if ( s[i] == '(' ) cnt++;
    else {
      if ( cnt == 0 ) left++;
      else cnt--;
    }
  }
  right = cnt;
  rep(i,left) std::cout << "(";
  std::cout << s;
  rep(i,right) std::cout << ")";
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	while(cin>>n){
		cin>>m;
		int res=1;
		while(res){
			res=n%m;
			n=m;
			m=res;
		}
		cout<<n<<endl;
	}
	return 0;
}

Measured memory_bytes: 1156
# -*- coding: utf-8 -*-

def get_digits_sum(val_str):
    digits_sum = 0
    for i in range(len(val_str)):
        digits_sum += int(val_str[i])

    return digits_sum

N = int(input())

if N==2:
    sum_min = 2

for i in range(2, N, 1):
    A = i
    B = N - i
    a_sum = get_digits_sum(str(A))
    b_sum = get_digits_sum(str(B))
    if i==2:
        sum_min = a_sum + b_sum
    elif sum_min > a_sum + b_sum:
        sum_min = a_sum + b_sum
        
print(sum_min)

Measured memory_bytes: 9096
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){

    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    int A[N];
    ll total = 0;
    for(int i=0; i<N; i++){
        int Ai;
        cin >> Ai;
        Ai = Ai-i-1;
        A[i] = Ai;
        total += Ai;
    }

    sort(A, A+N);
    int middle = A[N/2];
    ll ans = 0;
    for(int i=0; i<N; i++){
        ans += abs(A[i] - middle);
    }

    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

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

int m, n;

void dfs(int x, int pm, string str)
{
	if(pm == n)
	{
		cout << str << endl;
		return;
	}
	for (int i = min(x, n - pm); i > 0; i--)
	{
		dfs(i, pm + i, str + toString(i) + (i + pm != n ? " " : ""));
	}
}

int main(void)
{
	ios::sync_with_stdio(false);
	while(cin >> n && n)
	{
		dfs(n, 0, "");
	}
	return 0;
}

Measured memory_bytes: 1216
n, m = map(int, input().split())
a = list()
for i in range(n):
	a.append(list(map(int, input().split())))
b = list()
for i in range(m):
	b.append(int(input()))
for i in range(n):
	ans = 0
	for j in range(m):
		ans += a[i][j] * b[j]
	print(ans)


Measured memory_bytes: 6004
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  if(n%2){
    for(int i=1,j=2*m;m>0&&i<j;i++,j--){
      cout<<i<<" "<<j<<endl;
      m--;
    }
  }else{
    for(int i=1,j=n/2;m>0&&i<j;i++,j--){
      cout<<i<<" "<<j<<endl;
      m--;
    }
    for(int i=n/2+1,j=n-1;m>0&&i<j;i++,j--){
      cout<<i<<" "<<j<<endl;
      m--;
    }
  }
  return 0;
}


Measured memory_bytes: 3580
n = int(input())
Plan = []
for i in range(n):
  Plan.append(list(map(int, input().split())))
Plan.sort(lambda x: x[0])
x = 0
y = 0
t = 0
for txy in Plan:
  t_new, x_new, y_new = txy
  dx = abs(x_new - x)
  dy = abs(y_new - y)
  dt = abs(t_new - t)
  if dt >= dx + dy and dt % 2 == (dx + dy) % 2:
    continue
  else:
    print("No")
    break
else:
  print("Yes")

Measured memory_bytes: 66392
import sys
from collections import Counter, deque, defaultdict, OrderedDict
from math import factorial
from fractions import Fraction
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))


MOD = 998244353
n = INT()
d = LIST()
if d[0] != 0:
    print(0)
    sys.exit()
d = d[1:]
c = dict(Counter(d))
c =  OrderedDict(sorted(c.items()))
c = list(c.values())
if len(c) != max(d):
    print(0)
    sys.exit()
res = 1
for i in range(1, len(c)):
    res *= c[i-1]**c[i]

print(res%MOD)

Measured memory_bytes: 127016
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

string n;

void main() {
    int n;
    scan(n);

    if (n / 100 == n % 10) {
        writeln("Yes");
    }
    else {
        writeln("No");
    }
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
A,B=list(map(int,input().split()))
n_l=[[] for i in range(A)]
from collections import deque
import itertools
for i in range(B):
   N,M= list(map( int,input().split()))
   n_l[N-1].append(M)
   n_l[M-1].append(N)
all_l=list(range(2,A+1))
first_list=[]
for i in n_l[0]:
   all_l_n=all_l.copy()
   for v in itertools.permutations(all_l_n):
      first_list.append(v)
ans=0
first_list=list(set(first_list))
for x in first_list:
   if x[0] in n_l[0]:
      s=1
      for k in range(len(x)-1):
         if x[k+1] in n_l[x[k]-1]:
            pass
         else:
            s=0
            break
      if s == 1:
         ans+=1
print(ans)

Measured memory_bytes: 7532
#include<bits/stdc++.h>
using namespace std;
template<typename V>
bool tomin(V&x,V y){if(y<x){x=y;return true;}return false;}
template<typename V>
bool tomax(V&x,V y){if(x<y){x=y;return true;}return false;}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
#define lowbit(x) ((x)&-(x))
const int M=1e5+5;
int n,A[M];
int pre(int i){
    i--;
    if(i==0)return n;
    return i;
}
int nxt(int i){
    i++;
    if(i>n)return 1;
    return i;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&A[i]);
    int ans=A[1];
    for(int i=2;i<=n;i++){
        ans^=A[i];
    }
    // cout<<ans<<endl;
    if(ans)puts("No");
    else puts("Yes");
    // for(int i=1;i<=n;i++)
    //     if((A[pre(i)]^A[nxt(i)])!=A[i]){
    //         exit(0);
    //     }
    return 0;
}

Measured memory_bytes: 640
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

dif = 1000000 
ans = 0 

for i in range(N):
        temp = T - H[i] * 0.006
        c = abs(temp - A)
        if c < dif:
                ans = i + 1 
                dif = c 

print(ans)

Measured memory_bytes: 3064
n,m=map(int,input().split())
h=list(map(int, input().split()))
l=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
ans=0
for i,ii in enumerate(l):
  for j in set(ii):
    if h[i]<=h[j]:
      break
  else:
    ans+=1
print(ans)

Measured memory_bytes: 31968
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int mincost[5001];
vector<pii> tx(5001);
vector<vector<int>> way(5001);
int main() {
	int n;
	cin >> n;
	while (n--) {
		string buf;
		cin >> buf;
		vector<pair<int, vector<int>>> g;
		int s = 0,n=1;
		bool f = 0;
		vector<int> stack;
		g.push_back(make_pair(-1, vector<int>()));
		stack.push_back(0);
		for (int i = 1; i < buf.size(); i++) {
			switch (buf[i]) {
			case '[':
				f = 0;
				g.push_back(make_pair(-1, vector<int>()));
				g[stack.back()].second.push_back(n);
				stack.push_back(n++);
				break;
			case ']':
				stack.pop_back();
				break;
			default:
				if (f)break;
				g.back()=make_pair(stoi(string(buf.c_str() + i))/2+1, vector<int>());
				g[stack.back()].second.push_back(n);
				f = 1;
			}
		}
		while (g[0].first == -1) {
			for (int i = 0; i < g.size(); i++) {
				if (g[i].first != -1 || g[g[i].second[0]].first == -1)continue;
				vector<int> buf;
				for (int j = 0; j < g[i].second.size(); j++) {
					buf.push_back(g[g[i].second[j]].first);
				}
				sort(buf.begin(), buf.end());
				g[i].first = accumulate(buf.begin(), buf.begin() + (buf.size() + 2) / 2, 0);
			}
		}
		cout << g[0].first<<endl;
	}
}

Measured memory_bytes: 3456
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i], A[i]--;

    map<ll, int> rec;
    vector<ll> sum(N+1);

    if(K == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    rec[0]++;
    for(int i=0; i<N; i++) {
        sum[i+1] = (sum[i] + A[i]) % K;

        /*
        fprintf(stderr, "sum = %lld, ", sum[i+1]);
        fprintf(stderr, "add = %lld\n", rec[ sum[i+1] ]);
        */        

        // sum[i+1] と和が同じもの
        ans += rec[ sum[i+1] ];

        // sum[i+1] を追加
        rec[ sum[i+1] ]++;

        if(i - K + 2 >= 0) {
            rec[ sum[i-K+2] ]--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main () {
    string n;
    cin >> n;
    REP(i, n.size()) {
        if(n[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

}

 


Measured memory_bytes: 3596
A, B, C = map(int,input().split())
ans = 0
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    a = B // 2 + C // 2
    b = A // 2 + C // 2
    c = A // 2 + B // 2
    if A == a and B == b and C == c:
        ans = -1
        break
    A = a
    B = b
    C = c
    ans += 1
print(ans)

Measured memory_bytes: 9196
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val X, Y = sc.nextInt()
  val matched = for {
    i <- 0 to X
    j <- 0 to X
    if i + j == X
    if i * 2 + j * 4 == Y 
  } yield ()
  println(if (matched.isEmpty) "No" else "Yes")
}


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

signed main() {
  
  int N;
  cin >> N;
  int sum;
  vector<int> x(N);
  
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    sum += x[i];
  }
  
  vector<int> ans(N);
  ans[0] = sum;
  for (int i = 0; i < (N-1)/2; i++) {
    ans[0] -= 2 * x[2 * i + 1];
  }
  
  for (int i = 1; i < N; i++) {
    ans[i] = 2 * x[i-1] - ans[i-1];
  }
  
  for (int i = 0; i < N-1; i++) {
    cout << ans[i] << ' ';
  }
  cout << ans[N-1] << endl;

}

Measured memory_bytes: 2944
package main

import "fmt"

func main() {
	var a, b int64

	fmt.Scan(&a)
	fmt.Scan(&b)

	g0 := gcd(a, b)

	g := g0

	answer := 1
	for p := int64(2); p * p <= g0; p++ {
		if !(g % p == 0 && isprime(p)) {
			continue
		}
		answer++
		for g % p == 0 {
			g /= p
		}
	}
	if g > 1 {
		answer++
	}
	fmt.Println(answer)
}

func gcd(a, b int64) int64 {
	if a % b == 0 {
		return b
	} else {
		return gcd(b, a % b)
	}
}

func isprime(n int64) bool {
	for i := int64(2); i * i <= n; i++ {
		if n % i == 0 {
			return false
		}
	}
	return true
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;


int main(){
    int A, B;
    cin >> A >> B;
    int S = (A - 1) * (B - 1);
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $n, $x);
$p = explode(' ', trim(fgets(STDIN)));
$d = abs($p[0] - $x);
for ($i = 1; $i < $n; $i++) {
	$d = gcd(abs($p[$i] - $x), $d);
}
echo $d;

function gcd($n, $m) {
	return $n % $m ? gcd($m, $n % $m) : $m;
}

Measured memory_bytes: 12792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SONI ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int maxn=5e5+15;
const int maxm=5000+15;
const int mod=1e9+9;
const int inf=0x3f3f3f3f;
const int MOD=1000000007;

int main()
{
    SONI;
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    int dp[n];
    for(int i=0;i<n;i++)
    dp[i]=inf;
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=(i+k);j++)
        {
            if(j<n)
            dp[j]=min(dp[j],dp[i]+abs(arr[j]-arr[i]));
        }
    }
    cout<<dp[n-1];
    return 0; 
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------
V<ll>m[11];
ll color[100];
//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    ll k;cin>>k;
    map<ll,ll>m;
    bitset<64>x;
    for(ll i=0;i<k;i++){
        ll b;cin>>b;
        color[b]=1;
        x[b]=1;
    }
    ll tmp=x.to_ullong();
    ll cnt=0;
    for(int bit=0;bit < (1<<n); bit++)
    {
        if(bit&~tmp)continue;
        cout<<bit<<":";
        for(ll j=0;j<n;j++){
            if(bit&(1<<j))cout<<" "<<j;
        }
        cout<<endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a;
  cin >> a;
  ll ans,k=0;
  ll n=a;
  while(a>9){
    a/=10;
    k++;
  }
  ans=9*k+a-1;
  if((n+1)%(ll)pow(10,k)==0)ans++;
  cout << ans;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();

        final Map<Long, Integer> counter = new HashMap<>();
        for (int i = 0; i < n; i++) {
            final long v = scanner.nextLong();
            counter.compute(v, (key, value) -> value == null ? 1 : value + 1);
        }

        final List<Long> keys = counter.keySet().stream()
                .sorted(Comparator.reverseOrder())
                .collect(Collectors.toList());

        if (counter.get(keys.get(0)) >= a) {
            System.out.println(keys.get(0));
            final int value = counter.get(keys.get(0));
            BigInteger sum = BigInteger.ZERO;
            BigInteger tmp1 = BigInteger.ONE;
            BigInteger tmp2 = BigInteger.ONE;
            for (int i = 1; i < a; i++) {
                tmp1 = tmp1.multiply(BigInteger.valueOf(value - i + 1));
                tmp2 = tmp2.multiply(BigInteger.valueOf(i));
            }
            for (int i = a; i <= Math.min(value, b); i++) {
                tmp1 = tmp1.multiply(BigInteger.valueOf(value - i + 1));
                tmp2 = tmp2.multiply(BigInteger.valueOf(i));
                sum = sum.add(tmp1.divide(tmp2));
            }
            System.out.println(sum);
            return;
        }

        int accumulation = 0;
        double sum = 0;
        for (final long key : keys) {
            final int value = counter.get(key);
            if (accumulation + value < a) {
                accumulation += value;
                sum += key * value;
                continue;
            }

            final int needed = a - accumulation;
            sum += needed * key;
            System.out.println(sum / (double) a);

            BigInteger tmp1 = BigInteger.ONE;
            BigInteger tmp2 = BigInteger.ONE;
            for (int i = 1; i <= needed; i++) {
                tmp1 = tmp1.multiply(BigInteger.valueOf(value - i + 1));
                tmp2 = tmp2.multiply(BigInteger.valueOf(i));
            }
            System.out.println(tmp1.divide(tmp2));
            return;
        }
    }
}


Measured memory_bytes: 27348
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,A[100001],cn[100001];
  cin >> N;
  fill(cn,cn+100001,0);
  REP(i,N)cin >> A[i];
  REP(i,N){
    cn[A[i]]++;
  }
  if(N % 2 == 0){
    for(int i=0;i<N;i++){
      if(i==0){
        if(cn[i] != 0){
          cout << "0" << endl;
          return 0;
        }
      }else{
        if(cn[i] != 0 && cn[i] != 2){
          cout << "0" << endl;
          return 0;
        }
      }
    }
  }else{
    for(int i=0;i<N;i++){
      if(i==0){
        if(cn[i] != 1){
          cout <<"0" << endl;
          return 0;
        }
      }else{
        if(cn[i] != 0 && cn[i] != 2){
          cout << "0" << endl;
          return 0;
        }
      }
    }
  }
  if(N % 2 == 1){
    N--;
  }
  cout << bpow(2,N/2,1000000007) << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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

int main(){
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	if((2 * (A < C) - 1) * (2 * (B < C) - 1) < 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
//#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

const double PI = acos(-1);
const double EPS = 1e-9;

const int MX = 305;
const int MM = 1000000007;

int A[MX][MX];

int main()
{
	set<int> L;
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= M; i++) L.insert(i);
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= M; j++) scanf("%d", A[i]+j);
	}
	int ans = N;
	while(L.size()){
		int cnt[MX] = {};
		for(int i = 1; i <= N; i++){
			for(int j = 1; j <= M; j++){
				if( L.count(A[i][j])){
					cnt[A[i][j]] += 1;
					break;
				}
			}
		}
		int mx = 0;
		for(int i = 1; i <= M; i++){
			if( cnt[i] > cnt[mx] ) mx = i;
		}
		ans = min(ans, cnt[mx]);
		L.erase(mx);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
//#define int long long
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define maxn 100005
using namespace std;
int dp[maxn];
vector<int> g[maxn];
bitset<maxn> vis;
int dfs(int s)
{
	vis[s] = 1;
	for(int ch : g[s])
	{
		if(!vis[ch]) dfs(ch);
		dp[s] = max(dp[s], 1 + dp[ch]);
	}
	return dp[s];
}


signed main()
{
	
	int n, m; cin >> n >> m;
	for(int i=0; i<m; i++)
	{
		int x, y; cin >> x >> y;
		g[x].push_back(y);
	}
	memset(dp, 0, sizeof(dp));
	vis.reset();
	for(int i=1; i<=n; i++)
	{
		if(!vis[i]) int x = dfs(i);
	}
	int ans = *max_element(dp+1, dp+1+n);
	cout << ans << "\n";
	
}


Measured memory_bytes: 8192
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
h = w = 0
for k, v in c.items():
    if v >= 2 and k > w:
        if k > h:
            if v >= 4:
                h = k
                w = k
            else:
                w = h
                h = k
        else:
            w = k
print(h * w)


Measured memory_bytes: 24224
package main

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

var sc = bufio.NewScanner(os.Stdin)

type Tenbo struct {
	High int
	Neer []int
	Good bool
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()

	ts := make([]Tenbo, n+1)
	for i := 1; i <= n; i++ {
		ts[i].High = nextInt()
		ts[i].Good = true
	}
	for i := 0; i < m; i++ {
		a := nextInt()
		b := nextInt()
		if ts[a].High < ts[b].High {
			ts[a].Good = false
			continue
		}
		if ts[a].High > ts[b].High {
			ts[b].Good = false
			continue
		}

		// a.h = b.h
		ts[a].Good = false
		ts[b].Good = false

	}

	var ret int
	for k, v := range ts {
		if k == 0 {
			continue
		}
		if v.Good {
			ret++
		}
	}
	fmt.Println(ret)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 8644
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}



ll count(ll n,ll x){
    if(n>=0) return n/x + 1;
    else return 0;
}

int main(void){
    ll a,b,x;
    cin>>a>>b>>x;
    cout<<count(b,x)-count(a-1,x)<<endl;
    return 0;
}

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

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator &itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() {return i;}
  Iterator &end() {return n;}
};

template<class T> T at(vector<T> v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

pair<long long, long long> mem[310][310];
long long a[310];

pair<long long, long long> solve(long long s, long long t) {
  if (mem[s][t].first != -1) return mem[s][t];
  if (s == t - 1) return mem[s][t] = make_pair(0, a[s]);
  long long res = 1e9;
  long long sum = -1;
  for (long long i : range(s + 1, t)) {
    auto p1 = solve(s, i);
    auto p2 = solve(i, t);
    long long k1 = p1.second, k2 = p2.second, c = 0, r = 0;
    sum = k1 + k2;
    while (k1 || k2) {
      r += (k1 % 10) * (k2 % 10) + c;
      if (k1 % 10 + k2 % 10 + c >= 10) c = 1;
      else c = 0;
      k1 /= 10;
      k2 /= 10;
    }
    res = min(res, p1.first + p2.first + r + c);
  }
  return mem[s][t] = make_pair(res, sum);
}

int main() {
  long long n;
  cin >> n;
  for (long long i : range(n)) cin >> a[i];
  for (long long i : range(310)) for (long long j : range(310)) mem[i][j].first = -1;
  cout << solve(0, n).first << endl;
}

Measured memory_bytes: 2704
#include <stdio.h>
#define N 101

int main() {
  int n, i, j, a[N], flag=0,min, count=0, temp;
  scanf("%d",&n);
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for(i = 0; i < n; i++) {
    min = i;
    for( j = i; j < n; j++){
      if(a[min] > a[j]){
        min = j;
        flag = 1;
      }
    }
    temp = a[i];
    a[i] = a[min];
    a[min] = temp;
    if(flag) {
      count++;
      flag = 0;
    }
  }
  for(i = 0; i < n; i++){
    printf("%d", a[i]);
    if(i < n-1){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 2740
#include <bits/stdc++.h>
#define mod 1000000007
#define pie M_PI
#define maxm 2147483647
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define yes "YES\n"
#define no "NO\n"
#define ENDL "\n"

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const long long maxs = 100000000;

void get(ll &num)
{
    scanf("%lld", &num);
}

void getd(ll &num1, ll &num2)
{
    scanf("%lld %lld", &num1, &num2);
}

void output(ll num)
{
    printf("%lld\n", num);
}
void outputd(ll num1, ll num2)
{
    printf("%lld %lld\n", num1, num2);
}

int main()
{

    // ios_base::sync_with_stdio(0);
    // cin.tie(NULL);
    // cout.tie(NULL);
    ll t = 1;
    ll n;

    while(t--)
    {
        string st;
        get(n);
        int a[4] = {0};
        FOR(i, 0, n)
        {
            cin >> st;
            if(st == "AC")
                a[0]++;
            if(st == "WA")
                a[1]++;
            if(st == "TLE")
                a[2]++;
            if(st == "RE")
                a[3]++;

        }
        cout << "AC x " << a[0] << endl;
        cout << "WA x " << a[1] << endl;
        cout << "TLE x " << a[2] << endl;
        cout << "RE x " << a[3] << endl;

    }


}


Measured memory_bytes: 3628
S = input()
a = [chr(ord('a') + i) for i in range(26)]
for l in S:
    a.remove(l)
if a != []:
    print(S+a[0])
else:
    b = []
    k = 1
    for l in reversed(S):
        b.append(l)
        b.sort()
        if b[-1] != l:
            print(S[0:-k]+b[b.index(l)+1])
            break
        k+=1
    else:
        print(-1)

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

int main(){
    string A, B, C;
    cin >> A >> B >> C;
    int alen = A.length();
    int blen = B.length();
    if(A[alen-1] == B[0] && B[blen-1] == C[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

void exec(){
  int n, h[MAX_N];
  ll dp[MAX_N];
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> h[i];
    dp[i] = INF;
  }

  dp[0] = 0;

  for (int i = 0; i < n; i++){
    for (int j = 1; j <= 2; j++){
      if (i + j < n){
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i + j]));
      }
    }
  }

  cout << dp[n-1] << endl;


}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  double sum_rev = 0.0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    sum_rev += (double)1 / a[i];
  }
  printf("%.10f\n", 1 / sum_rev);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
	return *(int*)b-*(int*)a;
}
int main(){
	int n,i,r=0,t=1;
	int arr[999];
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&arr[i]);
	qsort(arr,n,4,compare);
	for(i=0;i<n;i++){
		r+=t*arr[i];
		t=-t;
	}
	printf("%d\n",r);
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

signed main(){
    string S;cin>>S;
    int ans=0;
    int num=0;
    rep(i,S.size()){
        if(S[i]=='B')num++;
        else ans+=num;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    ll gate[200000];
    REP(i,m){
      gate[input()]++;
      gate[input()+1]--;
    }
    ll ans = 0;
    ll now = 0;
    REP(i,n+1){
      now += gate[i];
      if(now>=m)ans++;
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  set<int> S;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    S.insert(a);
  }
  
  if (S.size() == N) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 9600
until(n,m=gets.split.map(&:to_i)).all?(&:zero?)do
r,p,a=[],[],[]
n.times{r.unshift(gets.gsub("?",".").split)}
m.times{p<<gets.split}
p.each{|p|r.each{|r|if/#{r[1]}/=~p[0]&&p[1]=~/#{r[2]}/
a<<p*" "if/p/=~r[0]
break
end}}
puts a.size,a
end

Measured memory_bytes: 9240
S, T = gets.chomp, gets.chomp

I = [nil]*('z'.ord-'a'.ord+1)
IS = [nil]*S.size
S.chars.reverse_each.with_index{|c,i|
	c, i = c.ord-'a'.ord, S.size-1-i
	IS[i], I[c] = I[c], i
}

ICache = [nil]*('z'.ord-'a'.ord+1)
p T.each_char.inject(0){|i,c|
	id, im, c = i/S.size*S.size, i%S.size, c.ord-'a'.ord
	ic = (ICache[c]&&ICache[c]<=im) ? ICache[c] : I[c]
	break -1 unless ic
	ic = IS[ic] while ic && ic < im
	ic = ic.nil? ? id+S.size+I[c] : id+ic
	ICache[c] = ic%S.size
	next ic+1
}


Measured memory_bytes: 10364
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
int main(){
  ll n;
  cin>>n;
  vll a(n);
  vll b1(60);
  rep(i,n){
    cin>>a[i];
    bitset<60> g(a[i]);
    rep(j,60){
      if(g.test(j)){
        b1[j]++;
      }
    }
  }
  sort(rall(a));
  ll ans=0;
  rep(i,n-1){
    bitset<60> g(a[i]);
    ll cu=59;
    while(cu+1>0){
      if(g.test(cu)) break;
      cu--;
    }
    for(int j=cu;j>=0;j--){
      ll s=modpow(2,j,MOD);
      if(g.test(j)){
        ans+=s*(n-i-b1[j]);
        b1[j]--;
        ans%=MOD;
      }
      else{
        ans+=s*(b1[j]);
        ans%=MOD;
      }
    }
  }
  COUT(ans);
}

Measured memory_bytes: 2560
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;

ll H,N;
vector<ll> dp;
vector<ll> A,B;
void Update(ll num) {
   vector<ll> dp1(H+10,INF);
   rep(i,0,H+10) {
      if (i-A[num]>=0)dp1[i] = min(dp[i],dp1[i-A[num]]+B[num]);
      else dp1[i] = min(dp[i],B[num]);
   }
   swap(dp,dp1);
   return;
}

int main(void) {
   cin>>H>>N;
   dp.resize(H+10,INF);
   dp[0] = 0;
   A.resize(N);
   B.resize(N);
   rep(i,0,N) cin>>A[i]>>B[i];

   rep(i,0,N) Update(i);
   // rep(i,0,H+10) cout<<i<<" "<<dp[i]<<endl;
   cout<<dp[H]<<endl;



   return 0;

}



Measured memory_bytes: 384
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min([a, b])
if a == b == ba and b:
    ans -= 1
print(ans)


Measured memory_bytes: 3700
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import           Data.Char


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las


solve :: Int -> Int
solve 1 = 1
solve n = (solve $ n `div` 2) * 2 + 1

main = do
    h <- readInt
    print $ solve h




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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
  cout << "ABC";
	int n;
	cin >> n;
	if(n/100 == 0)
		cout << 0;
	if(n/10 == 0)
		cout << 0;
	cout << n << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>

using namespace std;

const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,-1,0,1 };
const int LIT = 1e9 + 7;
int n, m;
int arr[200001];

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> arr[i];

    long long ans = 0;
    for (int i = 1; i < n; i++) {
        if (arr[i] < arr[i - 1]) {
            ans += arr[i - 1] - arr[i];
            arr[i] = arr[i - 1];
        }
    }
    cout << ans;

}

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


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

const int MOD = 998244353;

struct mint {
  int n;
  mint(int n_ = 0) : n(n_) {}
};

mint operator-(mint a) { return a.n == 0 ? a : MOD - a.n; }
mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return a.n == 0 || b.n == 0 ? 0 : (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

mint modpow(mint a, long long b) {
  mint res = 1;
  while (b > 0) {
    if (b & 1) res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}

mint modinv(mint n) {
  int a = n.n;
  int b = MOD;
  int s = 1;
  int t = 0;
  while (b != 0) {
    int q = a / b;
    a -= q * b;
    s -= q * t;
    swap(a, b);
    swap(s, t);
  }
  if (s < 0) s += MOD;
  return s;
}

mint operator/(mint a, mint b) { return a * modinv(b); }
mint operator/=(mint &a, mint b) { return a = a / b; }


namespace {
  ll read() {
    ll x;
    cin >> x;
    return x;
  }

  string reads() {
    string s;
    cin >> s;
    return s;
  }

  template<class T>
  void writeln(T x) {
    cout << x << '\n';
  }

  template<class T, class... TS>
  void writeln(T x, TS... xs) {
    cout << x << ' ';
    writeln(xs...);
  }

  template<class T>
  void write(T x) {
    cout << x << ' ';
  }

  void newline() {
    cout << '\n';
  }
}

template<class T>
void H(T *a, int l, int r) {
  if (r - l == 1) return;
  int n = r - l;
  int m = (l + r) / 2;
  H(a, l, m);
  H(a, m, r);
  for (int i = l; i < m; i++) {
    int j = i + n / 2;
    T x = a[i];
    T y = a[j];
    a[i] = x + y;
    a[j] = x - y;
  }
}

int main() {
  int N = read();
  vector<int> A(1<<N);
  mint s = 0;
  REP(i, 1<<N) A[i] = read(), s += A[i];
  vector<mint> P(1<<N);
  REP(i, 1<<N) P[i] = A[i] / s;
  vector<mint> U(1<<N, MOD - 1);
  U[0] = (1<<N) - 1;
  H(P.data(), 0, 1<<N);
  H(U.data(), 0, 1<<N);
  vector<mint> B(1<<N);
  for (int i = 0; i < 1<<N; i++) {
    B[i] = U[i] / (P[i] - 1);
  }
  H(B.data(), 0, 1<<N);
  mint d = -B[0] / (1<<N);
  REP(i, 1<<N) {
    B[i] /= 1<<N;
    B[i] += d;
    writeln(B[i]);
  }
}

   
struct init {
  init() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} init_;




Measured memory_bytes: 6912
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;


int main(){
	int a,p,ans=0;
	cin>>a>>p;
	ans=(a*3+p)/2;
	print(ans);

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 100000
 
int CanLay(int, int, int, int *);
 
int CanLay(int n, int k, int m, int *weight)
{
    int i;
    int stack = 0;
    int numTracks = 1;
 
    for(i = 0; i < n; i++)
    {
        if(weight[i] > m) return 0;
        stack += weight[i];
        if(stack > m)
        {
            stack = weight[i];
            numTracks++;
        }
    }
    if(numTracks <= k) return 1;
    else return 0;
}

int main()
{
    int i;
    int n, k;
    int l, m, r;
    int weight[N];
    int maxWeight;
     
    scanf("%d %d", &n, &k);
    for(i = 0; i < n; i++)
    {
        scanf("%d", &weight[i]);
    }
     
    l = 0;
    r = 10000 * n / k;
    while(1)
    {
        m = (l + r) / 2;
        if(l == m) break;
        if(CanLay(n, k, m, weight))
        {
            r = m;      
        }
        else
        {
            l = m;
        }
    }
    printf("%d\n", r);
     
    return 0;
}


 

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

using namespace std;

int main(void) {
  int n, m;
  while (cin >> n >> m, n) {
    vector< vector<int> > G(n);
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      u--, v--;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    
    set<int> st;
    st.insert(0);
    for (int i = 0; i < G[0].size(); i++) {
      int v = G[0][i];
      st.insert(v);
      for (int j = 0; j < G[v].size(); j++) {
        st.insert(G[v][j]);
      }
    }
    cout << st.size() - 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3324