akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
    int f=0; x=0; char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
    if(f) x=-x;
}

const int N=1000005;
int a[N],n,c0,c1,c2;
char s[N];

int main(){
    read(n),n--;
    scanf("%s",s);
    rep(i,0,n){
        a[i]=s[i]-'1';
        if(a[i]==0) c0++;
        else if(a[i]==1) c1++;
        else c2++;
    }
    if(c1==0){
        int ans=0;
        rep(i,0,n){
            if(a[i]==2&&(n&i)==i) ans^=1;
        }
        cout<<ans*2<<endl;
    }
    else{
        int ans=0;
        rep(i,0,n){
            if(a[i]==1&&(n&i)==i) ans^=1;
        }
        cout<<ans<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 5248
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
	int n; 
	llong t;
	cin >> n >> t;
	int cnt=1;
	llong a, a_min=INF, profit=-INF, tmp;
	REP(i, n){
		cin >> a;
		a_min = min(a_min, a);
		tmp = a - a_min;
		if(tmp > profit){
			cnt = 1;
			profit = tmp;
		} else if(tmp == profit){
			cnt++;
		}
	}
	cout << cnt << '\n';
	
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; i++)
			A[i] = sc.nextLong();
		long mod = (long) Math.pow(10, 9) + 7;

		long ans = 0;
		long base = 1;
		for (int i = 0; i <= 60; i++) {
			long zeroNum = 0;
			long oneNum = 0;

			for (int j = 0; j < N; j++) {
				long bit = ((A[j] >> i) & 1);

				if (bit == 0) {
					zeroNum++;
				} else {
					oneNum++;
				}
			}

			ans += (zeroNum * oneNum % mod) * (base % mod) % mod;
			ans %= mod;
			base *= 2;
		}

		System.out.println(ans);

	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 28900
#include <stdio.h>
#include <vector>
using namespace std;
typedef vector<int> Row;
//---------------------------------------
//---------------------------------------

int main(void)
{
	int r, c; 
	int num;       
	int r_sum = 0;          //?????????????¨?
	Row c_sum(101, 0); 	   //?????????????¨?(?????????0????????????0)

	
	scanf("%d %d", &r, &c);
	
	for(int i = 0; i < r; i++){
		r_sum = 0;
		for(int j = 0; j < c; j++){
			scanf("%d", &num);
			r_sum += num;
			c_sum[j] += num;
			printf("%d ", num);
		}
		printf("%d\n", r_sum);
		c_sum[c] += r_sum;
	}
    for(int j = 0; j < c; j++){
		printf("%d ", c_sum[j]);
	}
	printf("%d\n", c_sum[c]);
	
	return 0;
}

Measured memory_bytes: 2724
let rec seq l n flg = function
    i when i = 11 -> l
  | i -> let m = if flg then n*.2. else n/.3.
         in seq (n::l) m (not flg) (i+1);;

let rec read () =
  try let num = read_float () in
      print_float (List.fold_left (+.) 0. (seq [] num true 1));print_newline ();read ()
  with End_of_file -> ();;

let () = read ();;

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

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}
 
int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(is_palindrome(s) && is_palindrome(s.substr(0,(n-1)/2)) && is_palindrome(s.substr((n+1)/2))){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}

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

int main(void) {
	int case_num,now_case;
	char cards[10][2];
	int i;
	int score,aces;
	scanf("%d",&case_num);
	for(now_case=0;now_case<case_num;now_case++) {
		for(i=0;i<10;i++)scanf("%s",cards[i]);
		score=aces=0;
		for(i=0;i<2;i++) {
			if(isdigit(cards[i][0])) {
				score+=cards[i][0]-'0';
			} else if(cards[i][0]=='A') {
				score+=11;
				aces++;
			} else {
				score+=10;
			}
			for(;aces>0 && score>21;aces--)score-=10;
		}
		if(score==21){puts("blackjack");continue;}
		for(i=2;i<10;i++) {
			if(score>17 || (score==17 && aces!=1))break;
			if(isdigit(cards[i][0])) {
				score+=cards[i][0]-'0';
			} else if(cards[i][0]=='A') {
				score+=11;
				aces++;
			} else {
				score+=10;
			}
			for(;aces>0 && score>21;aces--)score-=10;
		}
		if(score>21)puts("bust"); else printf("%d\n",score);
	}
	return 0;
}

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

void solve(long long A, long long B, long long C, long long K)
{
    long long ans = 0;
    if (K > 0)
    {
        if (K < A)
        {
            ans += K;
            K = 0;
        }
        else
        {
            ans += A;
            K -= A;
        }
    }
    if (K > 0)
    {
        if (K < B)
        {
            K = 0;
        }
        else
        {
            K -= B;
        }
    }
    if (K > 0)
    {
        if (K < C)
        {
            ans -= K;
            K = 0;
        }
        else
        {
            ans -= C;
            K -= C;
        }
    }

    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long K;
    scanf("%lld", &K);
    solve(A, B, C, K);
    return 0;
}


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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    ll N;
    cin >> N;
    ll X[N],tmp[N],tmpp=0,tmppp[2]={},cmp=0;
    map<ll,ll>m;
    for(ll i = 0; i < N; i++) {
        cin >> X[i];
        tmp[i] = X[i];
    }
    sort(X,X+N);
    
    tmppp[0] = X[N/2-1];
    tmppp[1] = X[N/2];
    
    for (ll i = 0; i < N; i++) {
        if(tmp[i] <= tmppp[0]) {
            cout << tmppp[1] << endl;
        }else {
            cout << tmppp[0] << endl;
        }
    }
  	
    return 0;
}


Measured memory_bytes: 5248
import math
while True:
    n = int(input())
    if n == 0:
        break
    m = list(map(int,input().split()))
    h = sum(m)/n
    b = 0
    for i in range(n):
        a = (m[i]-h)**2
        b += a
    print("{0:.8f}".format(math.sqrt(b/n)))


Measured memory_bytes: 5704
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
ll MOD = 1000000007;

int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    ll tmpA = a / x;
    ll tmpB = b / x;
    if (a % x == 0) tmpB += 1;
    cout << tmpB - tmpA << endl;
    return 0;
}


Measured memory_bytes: 256
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D&lang=jp*/

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

struct area_data{
    int n;
    int area;
};

int main(){
    stack<int> down;
    stack<struct area_data> st;

    for(int n=0;cin.peek()!='\n';n++){
        char s;
        cin>>s;
        if(s=='\\'){
            down.push(n);
        }else if(s=='/' && !down.empty()){
            struct area_data tmp={down.top(),0};
            while (!st.empty() && tmp.n< st.top().n){
                tmp.area+= st.top().area;
                st.pop();
            }
            tmp.area += n - tmp.n;
            st.push(tmp);
            down.pop();
        }
    }
    int areas=0;
    vector<int> output;
    while(!st.empty()){
        output.push_back(st.top().area);
        areas+=output.back();
        st.pop();
    }
    cout<< areas <<endl;
    cout<<output.size();
    reverse(output.begin(),output.end());
    for(int i:output){
        cout<<" "<<i;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D;
  int S;
  int T;
  
  cin >> D >> T >> S;
  
  if((S*T) >= D){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
 }

Measured memory_bytes: 3472
#include <iostream>
#include <algorithm>  
#include <vector>
#include <map> 

using namespace std;
#include <math.h>    // for sqrt
#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

    long cnt = 0;
    repeat(i, n) {
      if (i==0) {
        cnt++;
        continue;
      }

      if (s[i-1] == s[i]) {
        continue;
      } else {
        cnt++;
      }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll N, H;
  cin >> N >> H;
  vector<pll> attack(N * 2);
  for (ll i = 0; i < N; ++i) {
    ll a, b;
    cin >> a >> b;
    attack.at(i * 2) = {a, 1};
    attack.at(i * 2 + 1) = {b, 0};
  }
  sort(attack.begin(), attack.end());
  reverse(attack.begin(), attack.end());
  ll ans = 0;
  for (ll i = 0; i < 2 * N; ++i) {
    pll now = attack.at(i);
    if (now.second == 1) {
      ans += (H + now.first - 1) / now.first;
      break;
    }
    else {
      H -= now.first;
      ans += 1;
    }
    if (H <= 0) {
      break;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    string s;
    cin>>s;
    int n=s.length();
    int c[26]={0};
    for(auto x:s)
    c[x-'a']++;
    for(int i=0;i<26;i++)
    if(c[i]==0)
    {
        cout<<char(i+'a');return;
    }
    cout<<"None";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3716
//In the name of Allah

#include <bits/stdc++.h>

using namespace std;

const int N = 223456;

int a[N];
deque < int > b;

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i % 2) {
      b.push_back(a[i]);
    } else {
      b.push_front(a[i]);
    }
  }
  if (n % 2) {
    for (auto it = b.begin(); it != b.end(); it++) {
      cout << *it << ' ';
    }
  } else {
    for (auto it = b.rbegin(); it != b.rend(); it++) {
      cout << *it << ' ';
    }
  }
  return 0;
}

Measured memory_bytes: 3840
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector> 
#define LL long long
using namespace std;
const int N=2e5+10;
struct NODE{
	int k,l,r;
	bool operator <(const NODE &other)
	const { return k<other.k; }
}node[N];
priority_queue<int,vector<int>,greater<int> >que;//小根堆,注意空格！！！！ 
int main()
{
	int T,n;
	scanf("%d",&T);
	while(T)
	{
		T--;
		LL sum=0;
		LL now=0;
		int cnt=0; 
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%d",&node[i].k,&node[i].l,&node[i].r);
			now+=max(node[i].l,node[i].r);
		}
		sort(node+1,node+n+1);
		int j=1;
		for(int i=1;i<=n;i++)
		{
			while(j<=n&&node[j].k<=i)
			{
				if(node[j].l>=node[j].r) //注意等于的情况不要漏掉
				{
					sum+=node[j].r;
					que.push(node[j].l-node[j].r);
				}
				j++;
			}
			while(que.size()>i)	que.pop();
		}
		while(que.size())
		{
			sum+=que.top();
			cnt++;
			que.pop();
		}
		j=n;
		for(int i=n;i>0;i--)
		{
			while(j&&node[j].k>=i)
			{
				if(node[j].r>node[j].l)
				{
					sum+=node[j].l;
					que.push(node[j].r-node[j].l);
				}
				j--;
			}
			while(que.size()>n-i)	que.pop();
		}
		while(que.size())
		{
			sum+=que.top();
			cnt++;
			que.pop();
		}
		cout<<sum<<endl;
	}
	return 0;
}



Measured memory_bytes: 6196
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];


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

    cout << min(N%K,K-(N%K)) << endl;

}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	int c[m], dp[n+1];
	for (int i = 0; i < m; ++i){
		cin >> c[i];
	}
	for (int i = 0; i < n + 1; ++i){
		dp[i] = n + 1;
	}
	dp[0] = 0;
	while(dp[n] == n + 1){
		for (int i = 0; i < m; ++i){
			for (int j = 0; j < n; ++j){
				if (dp[j] < n + 1 && j + c[i] < n + 1){
					dp[j+c[i]] = min(dp[j+c[i]], dp[j] + 1);
				}
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}

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

template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  std::vector<bool> is_prime(100001,true);
  std::vector<int> pr;
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<100001;i++){
    if(!is_prime[i])continue;
    pr.push_back(i);
    for(int j=2*i;j<100001;j+=i)is_prime[j]=false;
  }
  int S=pr.size();
  //cout<<S<<endl;
  //cout<<pr[350]<<endl;
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  std::vector<int> w(S);
  for(int i=0;i<S;i++)w[i]=pr[i]*pr[i]*pr[i];
  for(int i=0;i<N;i++){
    for(int j=0;j<350;j++){
      if(v[i]<w[j])break;
      if(v[i]%w[j]==0)v[i]/=w[j--];
    }
  }
  map<int,int> m;
  for(int i=0;i<N;i++)m[v[i]]++;
  int ans=0;
  for(auto p:m){
    if(p.second<0)continue;
    if(p.first==1)continue;
    int res=1,n=p.first;
    for(int j=0;j<S;j++){
      if(n<pr[j]*pr[j])break;
      if(n%pr[j])continue;
      if(n%(pr[j]*pr[j])==0){res*=pr[j];n/=pr[j]*pr[j];}
      else {res*=pr[j]*pr[j];n/=pr[j];}
    }
    res*=n*n;
    //cout<<"P"<<p.first<<" "<<res<<endl;
    if(m.count(res)){
      ans+=max(p.second,m[res]);
      m[res]=-1;
    }
    else ans+=p.second;
  }
  if(m[1])ans++;
  fin(ans);
}


Measured memory_bytes: 7424
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return b;
    }
    return gcd(b, a % b);
}

int main()
{
    ll X, Y;
    cin >> X >> Y;

    cout << (X + Y / 2) << endl;
}

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


int main(){
  string a,b;
  cin >> a >> b;
  int cal=stoi(a+b);
  for(int i=1;i<=1000;++i){
    if(i*i==cal){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

int main() {
	int h1,m1,h2,m2,k;
	std::cin >> h1 >> m1 >> h2 >> m2 >> k;

	std::cout << (h2 - h1) * 60 + m2 - m1 - k << std::endl;
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int N;
long long A[100000], B[100000];

int main() {
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> A[i] >> B[i];
  }
  long long m = 0, c = 0;
  for (int i=N-1; i>=0; i--) {
    A[i] += m;
    int d = ((A[i]+B[i]-1) / B[i]);
    int s = (d * B[i]) - A[i];
    m += s;
    c += s;
  }
  cout << c << "\n";
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;

    vector<int> l;
    inputVector(l, N);

    sort(all(l));

    vector<int> a(N + 1);
    int ret = LLONG_MAX;
    while (a[N] == 0) {
        int len[3] = {0, 0, 0};
        int cnt[3] = {0, 0, 0};
        rep(i, N) {
            if (a[i] == 0) continue;
            len[a[i] - 1] += l[i];
            cnt[a[i] - 1]++;
        }
        bool ok = true;
        rep(i, 3) {
            if (cnt[i] == 0) ok = false;
        }

        if (ok) {
            int cost = 0;
            cost += abs(A - len[0]);
            cost += abs(B - len[1]);
            cost += abs(C - len[2]);
            rep(i, 3) cost += 10 * (cnt[i] - 1);

            ret = min(ret, cost);
        }

        int idx = 0;
        while (true) {
            a[idx]++;
            if (a[idx] < 4) break;
            a[idx] = 0;
            idx++;
        }
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>h>>w;
    if(h%3==0||w%3==0)Cout(0);
    else{
        ans=min(h,w);
        rrep(i,1,w){
            a=i*h;
            b=(w-i)*(h/2);
            tmp=h/2;
            if(h%2==1)tmp++;
            c=(w-i)*tmp;
            ans=min({ans,max({a,b,c})-min({a,b,c})});
        }
        rrep(i,1,h){
            a=i*w;
            b=(h-i)*(w/2);
            tmp=w/2;
            if(w%2==1)tmp++;
            c=(h-i)*tmp;
            ans=min({ans,max({a,b,c})-min({a,b,c})});
        }
        Cout(ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main() {
  int n;
  cin>>n;
  int a[10005];
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  int cnt=0;
  for (int i=0; i<n; i++) {
    while (a[i]%2==0) {
      a[i]/=2;
      cnt++;
    }
  }
  cout<<cnt<<endl;     
  return 0;
}




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


int main() {
	int a;
	string s;
	cin >> a;
	cout << endl;
	cin >> s;
	if (2799 <= a && a < 3200) {
		cout << "red"<<endl;
	}
	else if (3200 <= a && a < 5000) {
		cout << s << endl;
	}

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

def sumXOR(arr, n, MOD):
    ret = 0
    for i in range(0, 64):
        zc = 0
        oc = 0
        idsum = 0
        for j in range(0, n):
            if (arr[j] % 2 == 0):
                zc = zc + 1
            else:
                oc = oc + 1
            arr[j] //= 2
        idsum = oc * zc * (1 << i)
        ret += idsum
        ret %= MOD
    return ret

print(sumXOR(A, N, 10**9 + 7))


Measured memory_bytes: 122808
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
  cin>>N;
  vector<int>V(N);
  vector<int>C(N);
  for(int i=0;i<N;i++){
   cin>>V.at(i); 
  }
  for(int i=0;i<N;i++){
   cin>>C.at(i);
  }
  int sum=0;
  for(int i=0;i<N;i++){
   if(V.at(i)>C.at(i)){
   sum=sum+(V.at(i)-C.at(i));
   }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3644
//g++  5.4.0

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

#define ll long long int
ll c[27]={0};
ll l[27][1000001];

ll bsearch(ll *ar,ll l,ll r,ll v){
    
    ll ret = -1;
    while(l<=r){
        ll m = (l+r)/2;
        if(ar[m]>=v){
            ret = ar[m];
            r = m-1;
        }
        else
            l = m+1;
    }
    return ret;
}
    

void solve(string s,string tt){
    
    ll n = s.length();
    ll m = tt.length();
    ll i;
    
    for(i=0;i<n;i++){
        ll t = s[i]-'a';
        l[t][c[t]++] = i;
    }
    
    int loop=0;
    int pos=-1;
    
    for(i=0;i<m;i++){
        
        ll t = tt[i]-'a';
        if(c[t]==0){
            cout<<"-1";
            return ;
        }
        
        ll ret = bsearch(l[t],0,c[t]-1,pos+1);
        if(ret==-1){
            loop++;
            pos = l[t][0];
        }
        else 
            pos = ret;     
    }
    
    cout<<loop*n + pos+1ll;
}

int main()
{
   
    string s,t;
    
    cin>>s>>t;
    solve(s,t);
    
    return 0;     
}

Measured memory_bytes: 53888
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    rep(i,n-k)
    {
        if(a[i]<a[k+i]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 4048
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0) {
				break;
			}
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++ ) {
					System.out.print('#');
				}	
				System.out.println();
			}
			System.out.println();
		}
		sc.close();
	}

}



Measured memory_bytes: 37324
#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;
 
#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

#define int long long
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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 (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)
    
void solve(){
    int x;
    cin >> x;
    cout << 1-x << endl;
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed;
    solve();
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;
ll gcd( ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main (void) {
    ll N, ans;
    cin >> N;
    ll Sum = 0;
    REP(ll,i,1,N+1){
        REP(ll,j,1,N+1){
            REP(ll,k,1,N+1){
                Sum += gcd(i,gcd(j,k));
            }
        }
    }
    cout << Sum << endl;
    return 0;
}

Measured memory_bytes: 3592
import math

N, K = map(int, input().split())

Z = 10**9 + 7
X = 0

# for i in range(K, N+1):
#     a = list(range(i))
#     b = list(range(N + 1 - i, N + 1))
#     X = X + (sum(b) - sum(a) + 1)

for i in range(K, N+1):
    a = (0 + (i - 1)) * i / 2
    b = (N + (N - i + 1)) * i / 2
    X = X + (b - a + 1)

print(math.floor((X + 1)%Z))

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, k;
bool used[15] = {};
vector<int> ret;


vector<vector<int>> permutation(int n, vector<vector<int>>& per) {
    for(int i = 1; i <= n; i++) {
        if (used[i]) continue;
        used[i] = true;
        ret.push_back(i);
        permutation(n, per);
        ret.pop_back();
        used[i] = false;
    }
    if (ret.size() == n) per.push_back(ret);
    return per;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<vector<int>> per;
    while (true) {
        cin >> n >> k;
        if (n == 0) break;
        int card[n] = {};
        rep(i, n) cin >> card[i];
        set<string> st;
        rep(i, 1 << n) {
            int cnt = 0;
            vector<int> idx;
            rep(j, n) if (i>>j & 1) {
                cnt++;
                idx.push_back(j);
            }
            if (cnt != k) continue;
            vector<vector<int>> per;
            per = permutation(k, per);
            rep(j, per.size()){
                string tmp = "";
                rep(l, k) {
                    tmp += to_string(card[idx[per[j][l] - 1]]);
                }
                st.insert(tmp);
            }
        }
        cout << st.size() << endl;
    }
}

Measured memory_bytes: 3464
a,b,c=map(int,input().split())
i=0
count=0
while True:
    a,b=max(a,b)%min(a,b),min(a,b)
    if a==0:
        break
while count<c:
    i+=1
    if b%i==0:
        count+=1
print(b//i)

Measured memory_bytes: 3060
def g;gets.split.map &:to_i;end
r=1..n=g[0]
w=[[]]+r.map{[0]+[1e9]*n}
r.map{f,_,*t=g;t.map{|i|w[f][i]=1}}
r.map{|k|w.map!{|i|i=i.zip(w[k]).map{|a,b|[a,b+i[k]].min}}}
g[0].times{s,d,v=g;puts v<(c=w[s][d]+1)?:NA:c}

Measured memory_bytes: 6288
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const ll INF = 1e15;
const double eps = 1e-6;
const ll MOD = 1000000007;

int main() {
	ll A, B;
	cin >> A >> B;
	vector<vector<ll>> d(A+1, vector<ll>(B+1));
	for (int i = 1;i <= A;i++)
		for (int j = 1;j <= B;j++)
			cin >> d[i][j];
	vector<vector<ll>> e(101, vector<ll>(101, 0));
	for (ll a = 1;a <= A;a++)
		for (ll b = 1;b <= B;b++)
			for (ll ua = 0;ua <= 100;ua++)
				for (ll ub = 0;ub <= 100;ub++)
					e[ua][ub] = max(e[ua][ub], d[a][b] - (a * ua + b * ub));
	bool ok = true;
	for (ll a = 1;a <= A;a++)
		for (ll b = 1;b <= B;b++) {
			bool nowok = false;
			for (ll ua = 0;ua <= 100;ua++)
				for (ll ub = 0;ub <= 100;ub++)
					if (e[ua][ub] + a * ua + b * ub == d[a][b])
						nowok = true;
			ok &= nowok;
		}
	if (!ok)
		cout << "Impossible" << endl;
	else {
		ll cnt = 0;
		cout << "Possible" << endl;
		cout << "202 " << 101 * 101 + 100 + 100 << endl;
		for (int i = 1;i <= 100;i++) {
			cout << i << " " << i + 1 << " " << "X" << endl;
			cnt++;
		}
		for (int i = 102;i <= 201;i++) {
			cout << i << " " << i + 1 << " " << "Y" << endl;
			cnt++;
		}
		for (int ua = 0;ua <= 100;ua++)
			for (int ub = 0;ub <= 100;ub++) {
				cout << ua + 1 << " " << 202 - ub << " " << min(100LL, e[ua][ub]) << endl;
				cnt++;
			}
		cout << "1 202" << endl;

//		cout << cnt << endl;
	}
	return 0;
}


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

int main()
{
	int k;
	cin >> k;
	int count = 0;
	int temp = 0;
	for (int i = 1; i <= k; ++i) {
		temp = (temp % k) * 10 + 7;
		count++;
		if (temp % k == 0) {
			cout << count;
			return 0;
		}
	}
	cout << -1;
	return 0;
	/*int ans = 0, ans2 = 0;
	int x;
	cin >> x;
	char z[200000];
	char zt[200000];
	for (int i = 0; i < x; i++)
	{
		cin >> z[i];
	}
	for (int i = 0; i < x; i++)
	{
		zt[i] = z[i];
	}
	for (int i = 0; i < x; i++)
	{
		if (z[i] == 'W' && z[i + 1] == 'R')
		{
			z[i + 1] = 'W';
			ans++;
		}
	}
	for (int i = 0; i < x; i++)
	{
		if (zt[i] == 'W' && zt[i + 1] == 'R')
		{
			zt[i] = 'R';
			zt[i + 1] = 'W';
			ans2++;
		}
	}
	if (ans < ans2)
	{
		cout << ans;
	}
	else cout << ans2;
	return 0;*/
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


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


    return 0;
    

}

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

namespace AtCoder_20190707_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            int trainFee = int.Parse(input[0]) * int.Parse(input[1]);

            int taxiFee = int.Parse(input[2]);

            if (trainFee < taxiFee)
            {
                Console.WriteLine(trainFee.ToString());
            }
            else
            {
                Console.WriteLine(taxiFee.ToString());
            }
        }
    }
}

Measured memory_bytes: 13140
from sys import stdin
from collections import deque

# not AC
# def get_result(data):
#     S, Q = data[0][0], int(data[1][0])
#     for i in range(Q):
#         if data[i+2][0] == '1':
#             S = S[::-1]
#         else:
#             F, C = data[i+2][1], data[i+2][2]
#             if F == '1':
#                 S = C + S
#             else:
#                 S = S + C
#     return S


def get_result(data):
    S, Q = data[0][0], int(data[1][0])
    # 文字列と反転状況を別で判断する
    ans = deque(S)
    cnt = 0
    for i in range(Q):
        if data[i+2][0] == '1':
            cnt += 1
        else:
            F, C = data[i+2][1], data[i+2][2]
            if F == '1':
                if cnt % 2 == 0:
                    # 前に追加
                    ans.appendleft(C)
                else:
                    ans.append(C)
            else:
                if cnt % 2 == 0:
                    ans.append(C)
                else:
                    ans.appendleft(C)

    ans = ''.join(ans)
    if cnt % 2 == 1:
        ans = ans[::-1]

    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(str, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 57324
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int N;

int main(){
    cin>>N;
    out((N%2==0?N:N*2));
}

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

int main()
{
    char a;
    int ans=0;
    while(cin>>a)
    {
        a=(int)a-'0';
        ans+=a;
    }
    if(ans%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using vi = vector<int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

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

  IN(N);

  int A[N][N-1];
  int done[N];
  REP(i, N) {
    done[i] = 0;
    REP(j, N-1){
      cin >> A[i][j];
      --A[i][j];
    }
  }
  int ans = 0;
  while (true) {
    ++ans;
    bool flags[N];
    REP(i, N)
      flags[i] = false;
    bool changed = false;
    REP(i, N) {
      if (flags[i])
        continue;
      if (done[i] == N-1)
        continue;
      int rival = A[i][done[i]];
      if (rival < i)
        continue;
      if (A[rival][done[rival]] == i && !flags[rival]) {
        ++done[i];
        ++done[rival];
        flags[rival] = true;
        changed = true;
      }
    }
    bool is_finished = true;
    REP(i, N) {
      if (done[i] != N-1)
        is_finished = false;
    }
    if (is_finished) {
      OUT(ans);
      break;
    }
    if (!changed) {
      OUT(-1);
      break;
    }
  }

  return 0;
}


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

using namespace std;

#define int long long

typedef pair<int,int> ii;
ii a[200011];
int n;

bool cmp(const ii &a, const ii &b)
{
	return a.second < b.second;
}
int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	for (int i=1;i<=n;i++)
		cin >> a[i].first >> a[i].second;
	sort(a+1,a+1+n,cmp);
	int cur_t = 0;
	int i = 1;
	while(i <= n)
	{
		int t = a[i].second;
		int tmp = 0;
		while(a[i].second == t)
		{
			tmp += a[i].first;
			i++;
		} 
		if (cur_t + tmp > t)
		{
			cout << "No";
			return 0;			
		}
		cur_t += tmp;
	}
	cout << "Yes";
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;
 
 ll mod=1e9 +7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

ll pre[200005]={0};

pair<ll,ll> func(ll x,vector<ll>&a,ll n)
{
  ll num=0,i;
  ll res=0;
  rep(i,0,n-1)
  {
    ll it=lower_bound(a.begin(),a.end(),x-a[i])-a.begin();
    num+=n-it;
    res+=pre[n-1]-pre[it-1];
    res+=(n-it)*a[i];
  }
  return {res,num};

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    Sieve();
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
      ll i,j,n,m;
      cin>>n>>m;
      vector<ll>a(n),b(n),c(n);
      rep(i,0,n-1) cin>>a[i];
      sort(a.begin(),a.end());
      pre[0]=a[0];
      rep(i,1,n-1) pre[i]=pre[i-1]+a[i];

      ll lo=0,hi=200005;
      ll ans=-1;
      while(hi>=lo)
      {
        ll mid=(lo+hi)/2;
        if(func(mid,a,n).second>=m)
        {
          lo=mid+1;
        }
        else
        {
          // ans=mid;
          hi=mid-1;
        }
      }
      ans=func(lo-1,a,n).first;
      ans-=(func(lo-1,a,n).second-m)*(lo-1);
      cout<<ans;



    }
    return 0;
   }

Measured memory_bytes: 17452
#include <bits/stdc++.h>
using namespace std;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define pb push_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;


const ll modo=1e9+7;
const ll inf=2e14;
const ll ms=(2e5) +5;

int ar[ms];
int n,k;

ll dp[ms][4][2]={0};

ll callme()
{
    int i,j,m,p;
    int xx;
    dp[0][0][0]=1;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=k;j++)
        {
           for(m=0;m<=9;m++)
           {
               xx=j;
               if(m)xx++;
               if(xx>k)continue;
               dp[i][xx][1]+=dp[i-1][j][1];
               if(ar[i]>m)
               {
                   dp[i][xx][1]+=dp[i-1][j][0];
               }
               else if(ar[i]==m)
               {
                   dp[i][xx][0]+=dp[i-1][j][0];
               }
           }
        }
    }
    return dp[n][k][0]+dp[n][k][1];
}

int main()
{
    idfc;
    string s;
    cin>>s;
    n=s.length();
    int i;
    for(i=1;i<=n;i++)
    {
        ar[i]=s[i-1]-48;
    }
    //int k;
    cin>>k;
    cout<<callme();
    return 0;
}

Measured memory_bytes: 256
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(A);
    READV(B);
    READV(N);
    ll x=min(B-1,N);
    cout<<((A*x)/B)-(A*(x/B))<<endl;

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3804
t = list(map(int, input().split()))

min_t = 1000

for i in range(3):
    if i == 2:
        min_t = min(min_t, t[i] + t[0])
    else:
        min_t = min(min_t, t[i] + t[i+1])

print(min_t)


Measured memory_bytes: 2940
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		while(n-- > 0){
			String s = sc.nextLine().replaceAll("Hoshino","Hoshina");
			System.out.println(s);
		}
	}
}

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

#define int long long

signed main() {
	string s;
	cin >> s;
	int n = s.size();
	int a[26];
	for (int i = 0; i < 26; i++) {
		a[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		a[(int)(s[i] - 'a')]++;
	}
	int res = (n*(n - 1)) / 2;
	for (int i = 0; i < 26; i++) {
		res -= (a[i] * (a[i] - 1) / 2);
	}
	cout << (res+1) << endl;
	return 0;
}

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

int main(){
    int n,*R,i,dis,max=-1000000000,min;
    cin >> n;
    R = new int[n];
    for(i=0;i<n;i++){
        cin >> R[i];
    }
    min = R[0];
    for(i=1;i<n;i++){
        dis = R[i] - min;
        if(max<dis){
            max = dis;
        }
        if(min>R[i]){
            min = R[i];
        }
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 3884
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
using ll = long long; using ld = long double;
using pii = pair<int,int>; using pil = pair<int,ll>;
using pli = pair<ll,int>; using pll = pair<ll,ll>;
const int MOD = 1000000007, MOD2 = 998244353;
const int INF = 0x3f3f3f3f, INF2 = 0x3f3f3f37;
const ll LINF = 0x3f3f3f3f3f3f3f3f, LINF2 = 0x3f3f3f3f3f3f3f3d;

int dp[102][2][4];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string n; int k;
    cin >> n >> k;
    vector<int> a(n.size());
    for (int i = 0; i < n.size(); ++i) a[i] = n[i] - '0';
    memset(dp, -1, sizeof dp);
    function<int(int, int, int)> solve = [&](int idx, int lim, int cnt) {
        if (cnt > k) return 0;
        if (idx >= n.size()) return int(cnt == k);
        if (dp[idx][lim][cnt] != -1) return dp[idx][lim][cnt];
        int res = 0;
        for (int i = 0; i <= (lim ? a[idx] : 9); ++i)
            res += solve(idx + 1, lim ? i == a[idx] : 0, cnt + !!i);
        return dp[idx][lim][cnt] = res;
    };
    cout << solve(0, 1, 0) << '\n';
}

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

using namespace std;

int main(void){
	while (1){
		int n;
		scanf("%d", &n);
		if (n == 0)return 0;
		vector<char> code1;
		vector<char> code2;
		for (int i = 0; i < n; i++){
			char a, b;
			scanf(" %c %c", &a, &b);
			code1.push_back(a);
			code2.push_back(b);
		}
		int m;
		scanf("%d", &m);
		vector<char> ans;
		for (int i = 0; i < m; i++){
			char a;
			scanf(" %c", &a);
			ans.push_back(a);
			for (int j = 0; j < n; j++){
				if (ans[i] == code1[j]){
					ans[i] = code2[j];
					break;
				}
			}
			printf("%c", ans[i]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 1308
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var name string
	var n, score int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n)

	rests := make([]string, n)
	for i, _ := range rests {
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &name, &score)
		rests[i] = fmt.Sprintf("%s %03d %d", name, 101-score, i+1)
	}
	sort.Strings(rests)

	tmp := make([]string, 3)
	for _, v := range rests {
		tmp = strings.Split(v, " ")
		fmt.Println(tmp[2])
	}
}


Measured memory_bytes: 1852