akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> plus(N);
    rep(i,N) {
        cin >> A[i];
        plus[i] = A[i] + i + 1;
    }
    map<int, int> numbers;

    long long count = 0;

    for (int j = 1; j < N; j++) {
        if (numbers.find(plus[j - 1]) != numbers.end()) numbers[plus[j - 1]] ++;
        else numbers.insert(make_pair(plus[j - 1], 1));

        if (numbers.find(j + 1 - A[j]) != numbers.end()) {
            count += numbers[j + 1 - A[j]];
        }
    }

    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 14256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <cmath>
#include <string.h>
#include <assert.h>
#include <stack>
#include <sstream>
#include <map>
#include <set>
#define FRE freopen("c:\\users\\sky123\\desktop\\input.txt","r",stdin)
#define FF freopen("output.txt", "w", stdout)
#define PI 3.1415926535897932384626433832795028
#define ee 2.7182818284590452354
#define pi acos(-1.0)
#define eps 1e-5
#define M 100000
#define Inf 0x80000000
#define LL long long
#define inf 100000000
using namespace std;
LL even[M],odd[M],list[M],a[M],b[M];
LL gcd(LL a,LL b)
{
	return b==0?a:gcd(b,a%b);
}
int main()
{
	LL n,m,i,x,k,l,j,y,z,bi,bj,bk,g,a0;
	bool flag,ok,flag1;
	while(scanf("%lld",&n),n)
	{
		m=n*(n+1)/2;
		k=0;
		l=0;
		for(i=0;i<m;i++)
		{
			scanf("%lld",&x);
			list[i]=x;
			if(x%2==0)
				even[k++]=x;
			else 
				odd[l++]=x;
		}
		sort(list,list+m);
		flag=true;
		for(i=0;i<k&&flag;i++)
		{
			for(j=i+1;j<k&&flag;j++)
			{
				bi=even[i];
				bj=even[j];
				bk=odd[0];
				g=gcd(bi,bk);
				bi/=g;
				bk/=g;
				//g=gcd(bj,bk);
				//bj/=g;
				//bk/=g;
				bj/=bk;
				a0=(LL)sqrt(bi*bj);
				//a0=gcd(even[i],even[j]);
				if(a0==0)
					continue;
				flag1=true;
				z=0;
				for(x=0;x<k;x++)
				{
					if(even[x]%a0!=0)
					{
						flag1=false;
						break;
					}
					a[x]=even[x]/a0;
					b[z++]=a0*a[x];
				}
				if(!flag1)
					continue;
				for(x=0;x<k;x++)
					for(y=x+1;y<k;y++)
						b[z++]=a[x]*a[y];
				sort(b,b+z);
				ok=true;
				for(x=0;x<z;x++)
				{
					if(b[x]!=list[x])
					{
						ok=false;
						break;
					}
				}
				if(ok)
				{
					printf("%lld\n",a0);
					sort(a,a+n);
					flag=false;
					for(x=0;x<n;x++)
					{
						if(x==0)
							printf("%lld",a[x]);
						else
							printf(" %lld",a[x]);
					}
					printf("\n");
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1968
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
bool huiwen(string s)
{
	int len=s.size();
	for(int i=0;i<len/2;i++){
		if(s[i]!=s[len-i-1]) return false;
	}
	return true;
}
int main()
{
	string s;
	cin>>s;
	int n=s.size();
	int l1=(n-1)/2,l2=n-(n+3)/2+1;
	if(huiwen(s.substr(0,l1))&&huiwen(s.substr((n+3)/2-1,l2))&&huiwen(s)){
		cout<<"Yes\n";
	}else{
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main()
{
    int M, D, d1, d10, count = 0;
    cin >> M >> D;
    for(int i=4;i<M+1;i++){
        for(int j=22; j < D+1; j++){
            d1 = j % 10;
            if(d1 < 2) continue;
            d10 = j / 10;
            if(d1 * d10 == i) count++;
        }
    }
    cout << count << endl;
}

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


int main()
{
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> wars(M);
	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		wars[i].first = b;
		wars[i].second = a;
	}
	sort(wars.begin(), wars.end());
	for (int i = 0; i < M; i++)
	{
		int tmp = wars[i].first;
		wars[i].first = wars[i].second;
		wars[i].second = tmp;
	}
	int ans = 0;
	int last = 0;
	for (int i = 0; i < M; i++)
	{
		if (last < wars[i].first) {
			last = wars[i].second - 1;
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, T, A, bestI int
	var mind float64
	fmt.Scan(&N)
	fmt.Scan(&T)
	fmt.Scan(&A)
	Hn := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&Hn[i])
	}
	mind = math.MaxFloat64
	for i, v := range Hn {
		Td := math.Abs(float64(A) - (float64(float64(T) - float64(0.006*float64(v)))))
		// log.Printf("[dbg01] i->%d Hi->%d Td->%.1f\n", i, v, Td)
		if mind > Td {
			mind = Td
			bestI = i
			// log.Printf("[dbg02] i->%d, mind->%.1f\n", i, Td)
		}
	}
	fmt.Println(bestI + 1)
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String strNum = "";
		ArrayList<String> numArray = new ArrayList<String>();
		while(true) {
			strNum = br.readLine();
			if (strNum.equals("0")) {
				break;
			}
			numArray.add(strNum);
		}
		for (int i = 0; i < numArray.size(); i++) {
			System.out.println("Case " + (i+1) +": " + numArray.get(i));
		}
	}

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};


int main(){
  int n;
  int x;
  cin >> n;
  x = n % 10;
  if(x == 3) cout << "bon" << endl;
  else if(x == 0 || x == 1 || x == 6 || x == 8) cout << "pon" << endl;
  else cout << "hon" << endl;
  return 0;
}

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

#define fi first
#define se second
#define ll long long

const int N = 2020;

using namespace std;

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ll a, b, c, d, e, f;
        cin >> a >> b >> c >> d >> e >> f;
        ll A = 0, B = 0;
        a *= 100;
        b *= 100;
        for(ll i = 0; i <= f; i += a){
                for(ll j = 0; i + j <= f; j += b){
                        ll t1 = i + j;
                        for(ll h = 0; h + t1 <= f; h += c){
                                for(ll k = 0; k + h + t1 <= f; k += d){
                                        ll t2 = k + h;
                                        if(e * (t1 / 100) < t2){
                                                continue;
                                        }
                                        if(B * (t1 + t2) <= t2 * (A + B)){
                                                A = t1;
                                                B = t2;
                                        }
                                }
                        }
                }
        }
        cout << A + B << " " << B << "\n";
}


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


int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll sum = n * (n - 1) / 2;
    cout<<sum<<"\n";
	return 0;
}


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

int main(){
    int K,N;cin>>N>>K;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    long long ans=0;
    for (int i = 0; i < K; i++)
    {
        ans+=p[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    vector<string> A(N);
    vector<string> B(M);
    for(auto& e : A)
        cin >> e;
    for(auto& e : B)
        cin >> e;


    for(int i = 0; i < N - M + 1; ++i)
    {
        auto pos = A[i].find(B[0]);
        if(string::npos != pos)
        {
            bool ans = true;
            for(int j = 1; j < M; ++j)
            {
                if(A[i + j].substr(pos, M) != B[j])
                {
                    ans = false;
                    break;
                }
            }
            if(ans)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int M, N;
  cin>>N>>M;
  vector<int> vec(2 * M);
  vector<int> ans(N, 0);
  for(int i = 0; i < 2 * M; i++){
    cin>>vec.at(i);
    for(int j = 0; j < N; j++){
      if(vec.at(i) == j + 1){
        ans.at(j)++;
      }
    }
  }
  for(int i = 0; i < N; i++){
    cout<<ans.at(i)<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main(){
  int N, M;
  pair<int, int> a[10000];

  while(cin >> N >> M && N > 0){

    rep(i, N){
      cin >> a[i].second >> a[i].first;
    }



    sort(a, a+N);
    reverse(a, a+N);


    int ans = 0;

    rep(i, N){
      if(M >= a[i].second){
        M = M - a[i].second;
      } else {
        ans += a[i].first * (a[i].second - M);
        M = 0;
      }
    }

    cout << ans << endl;

  }
}


Measured memory_bytes: 3180
import numpy as np

N, M = map(int, input().split())
n_img = []
m_img = []

for _ in range(N):
    n_img.append([0 if e == '#' else 1 for e in list(input())])
for _ in range(M):
    m_img.append([0 if e == '#' else 1 for e in list(input())])

n_img = np.array(n_img)
m_img = np.array(m_img)


def areSameM(m1, m2):
    s = np.sum(np.sum(abs(m1 - m2)))
    return s == 0


flag = False

for i in range(N - M):
    for j in range(N - M):
        if areSameM(n_img[i:i + M, j:j + M], m_img):
            flag = True
            break
    if flag:
        break

if N == M:
    flag = areSameM(n_img, m_img)

print('Yes' if flag else 'No')


Measured memory_bytes: 12444
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

def scc(V, E):
    g = defaultdict(list)
    rg = defaultdict(list)
    for u, v in E:
        g[u].append(v)
        rg[v].append(u)


    o = []
    visited = set()
    used = set()
    for u in V:
        if u in visited:
            continue

        s = [(u, True)]
        while s:
            u, f = s.pop()
            if f:
                if u in visited:
                    continue
                visited.add(u)
                s.append((u, False))
                for v in g[u]:
                    if v in visited:
                        continue
                    s.append((v, True))
            else:
                o.append(u)



    def dfs(u, done, o):
        done.add(u)
        for v in g[u]:
            if v in done:
                continue
            done.add(v)
            dfs(v, done, o)
        o.append(u)

    def dfs_rev(u, done, c):
        done.add(u)
        c.append(u)
        for v in rg[u]:
            if v in done:
                continue
            dfs_rev(v, done, c)

    # done = set()
    # oo = []
    # for v in V:
    #     if v in done:
    #         continue
    #     dfs(v, done, oo)

    # print('---')
    # print(o)
    # print(oo)


    done = set()
    ans = []
    while o:
        u = o.pop()
        if u in done:
            continue
        vv = []
        dfs_rev(u, done, vv)
        ans.append(vv)


    return ans


def atcoder_practice2_g():
    N, M = map(int, input().split())

    E = []
    for _ in range(M):
        a, b = map(int, input().split())
        E.append((a, b))
    V = list(range(N))
    vv = scc(V, E)
    print(len(vv))
    for r in vv:
        print(len(r), *r)


def test():
    g = {
        1: [2],
        5: [2],
        2: [4, 3],
        3: [4, 7, 6],
        4: [5, 8],
        6: [9],
        7: [8],
        8: [9],
        9: [7, 10],
        10: []
    }

    V = list(range(1, 11))
    E = []
    for u, e in g.items():
        for v in e:
            E.append((u, v))

    vv = scc(V, E)
    for r in vv:
        print(r)


if __name__ == "__main__":
    # test()
    atcoder_practice2_g()


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

int main(int argc, const char * argv[]) {
    int N;
    
    cin >> N;
    
    for (int i = 0; i <= 25; i++) {
        for (int j = 0; j <= 14; j++) {
            if (((i * 4) + (j * 7)) == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    
    return 0;
}

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

int main(){
  int N;

  while(std::cin >> N){
    std::vector<int> A(N);
    for(int i = 0; i < N; ++i) std::cin >> A[i];

    int X = 0;
    for(int i = 0; i < N; ++i){
      X ^= A[i];
    }

    for(int i = 0; i < N; ++i) A[i] ^= X;

    for(int i = 0; i < N; ++i){
      std::cout << A[i] << " ";
    }
    std::cout << "\n";
  }

  return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    ll n;

    cin>> n;

    ll c= 0, t;

    for(ll i=0; i<n; i++)
    {
        cin>> t;

        while ( t%2== 0)
        {
             c++;
             t/=2;
        }

    }

    cout << c;
    nl;
    return 0;
}




Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

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

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 ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N, K; cin >> N >> K;
  vector<int> h(N);
  rep(i, N) cin >> h[i];

  vector<int> dp(100010, INF);
  dp[0] = 0;
  for (int i = 0; i < N; ++i){
    for (int j = 1; j <= K; ++j){
      chmin(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
    }
  }
  cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =200002;
const int MOD =1000000007;


   
     signed main(){
 int n;
 cin>>n;
 int f[n][10];
 for(int i=0;i<n;i++)for(int j=0;j<10;j++)cin>>f[i][j];
 int p[n][11];
 for(int i=0;i<n;i++)for(int j=0;j<11;j++)cin>>p[i][j];
 int ans=-MOD*MOD;
 for(int i=1;i<(1ll<<10);i++){
     int ans2=0;
     for(int j=0;j<n;j++){
         int x=0;
         for(int k=0;k<10;k++)if(bool((1ll<<k)&i)&f[j][k])x++;
         ans2+=p[j][x];
        
     }
     ans=max(ans,ans2);
    
 }
 cout<<ans<<endl;
   }
     


 


 






    





      

        


Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define ABS(a) ((a)>(0)?(a):-(a))

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int main(void){
    
    int N; scanf("%d", &N);
    int *a = (int *)malloc(N * sizeof(int));
    for (int i = 0; i < N; i++) 
        scanf("%d", &a[i]);
    qsort(a, N, sizeof(a[0]), asc);
    int ans = abs(a[N/2-1] - a[N/2]);
    free(a);
    printf("%d\n",ans);
}


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

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> S(n);
	for (auto& e: S) scanf("%d", &e);
	std::sort(S.begin(), S.end());
	int q;
	scanf("%d", &q);
	int count{};
	for (int i{}; i < q; i++)
	{
		int T;
		scanf("%d", &T);
		int left{}, right{n};
		while (right - left > 1)
		{
			int mid{(left + right) / 2};
			if (S[mid] > T) right = mid;
			else left = mid;
		}
		if (S[left] == T) count++;
	}
	printf("%d\n", count);

	return 0;
}


Measured memory_bytes: 3264
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[200010];
ll kai[200010];
ll beki(ll n,ll k){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=mod;
    }
    now*=now;
    now%=mod;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n){
  return beki(n,mod-2);
}
void nckinit(ll n){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=mod;
  }
  gya[n]=gyaku(kai[n]);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=mod;
  }
  gya[0]=1;
}    
ll nck(ll n,ll k){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  ret*=gya[k];
  ret%=mod;
  return ret;
}
ll npk(ll n,ll k){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  return ret;
}
int main(){
  int n;cin>>n;
  int a[n][n];
  rep(i,0,n-1){
    rep(j,i+1,n){
      int t=i^j;
      rep(k,0,30){
        int y=Pow(2,k);
        if(y>t){
          a[i][j]=k;
          break;
        }
      }
    }
  }
  rep(i,0,n-1){
    rep(j,i+1,n)cout<<a[i][j]<<" ";
    cout<<endl;
  }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  int z=MAX;
  for(int i=0; i<n; i++) {
    int x;
    cin >> x;
    m-=x;
    z=min(z,x);
  }
  cout << n+m/z << endl;
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct disjoint_set {
  int n;
  vector<int> prt;
  disjoint_set (int n) 
    : n(n)
    , prt(n, -1)
  {}
  bool is_root (int x) {return prt[x] < 0;}
  int size (int x) {return prt[find(x)];}
  bool equiv (int x, int y) {return find(x) == find(y);}
  int find (int x) {
    if (is_root(x)) return x;
    else return prt[x] = find(prt[x]);
  }
  bool unite (int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (size(x) < size(y)) swap(x, y);
    prt[x] += prt[y];
    prt[y] = x;
    return true;
  }
};
int main() {
  int n, q;
  cin >> n >> q;
  disjoint_set djs(n);
  while (q--) {
    int c;
    cin >> c;
    if (c) {
      int x, y;
      cin >> x >> y;
      cout << (djs.equiv(x, y)) << endl;
    } else {
      int x, y;
      cin >> x >> y;
      djs.unite(x, y);
    }
  }
  return 0;
}


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

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

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int main() {
    int i, x, y;
    while(1) {
        x = iin();
        y = iin();
        if (x == 0 && y == 0) break;
        if (x < y) {
            printf("%d %d\n", x, y);
        } else {
            printf("%d %d\n", y, x);
        }
    }
    return 0;
}



Measured memory_bytes: 2040
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) cout << n << '\n';
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    VI h(n); REP(i,n) cin >> h[i];
    int num = h[n-1];
    for(int i=n-2; i>=0; i--){
        if(h[i]-1>num){No; return 0;}
        chmin(num,h[i]);
    }
    Yes;

    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    for (int i = 1; i < S.size(); ++i){
        if (S[i - 1] == 'A' and S[i] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
from math import sqrt
def distance(a,b):
    return sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)

N=int(input())
towns=[tuple(map(int,input().split())) for _ in range(N)]
dis_town=[[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        dis_town[i][j]=distance(towns[i],towns[j])
combs=list(itertools.permutations(range(N)))
total=0
for comb in combs:
    for i in range(N-1):
        total+=dis_town[comb[i]][comb[i+1]]

print(total/len(combs))


Measured memory_bytes: 7972
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    vector<int>v(n);
    for(i=0;i<n;i++)
        cin>>v[i];
    for(i=0;i<n-1;i++)
    {
        if(i==0)
        {
        if(v[i]-v[i+1]>1)
        {
            cout<<"No";
            return(0);
        }
        }
        else
        {
            if(v[i]-v[i+1]>1)
            {
                cout<<"No";
                return(0);
            }
            if(i+1<=n-1)
            {
            if(v[i]==v[i-1]&&v[i]>v[i+1])
            {
                cout<<"No";
                return(0);
            }
            }
        }
        if(v[i]>v[i-1])
        {
            v[i]--;
        }
    }
    cout<<"Yes";
}


Measured memory_bytes: 640
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
int main()
{
fast;
ll a,b;
cin>>a>>b;
ll x=a+b;
ll y=a-b;
ll z=a*b;
ll ans=max(x,max(y,z));
cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;
typedef pair<int, char> Pair;

int main () {
    int n;
    while (cin >> n, n) {
        vector<Pair> v(26);
        REP (i, 0, 26) {
            v[i] = make_pair(0, 'A' + i);
        }
        REP (i, 0, n) {
            char c;
            cin >> c;
            v[c - 'A'].first++;
            auto copies = v;
            sort(copies.begin(), copies.end(), greater<Pair>());
            int first = copies[0].first;
            int second = copies[1].first;
            int rest = n - i - 1;
            if (first > second + rest) {
                cout << copies[0].second << ' ' << i + 1 << endl;
                REP (j, 0, rest) {
                    char temp;
                    cin >> temp;
                }
                break;
            }
            if (rest == 0) {
                cout << "TIE" << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

int main() {
  std::string s;
  std::cin >> s;
  int x, y;
  std::cin >> x >> y;
  int N = (int) s.size();
  std::vector<int> step(1, 0);
  for (int i = 0; i < N; ++i) {
    if (s[i] == 'F') { ++step.back(); }
    else { step.push_back(0); }
  }
  std::vector<std::vector<bool>> dp_lr(step.size() + 1, std::vector<bool>(2 * N + 1, false));
  std::vector<std::vector<bool>> dp_ud(step.size() + 1, std::vector<bool>(2 * N + 1, false));
  bool u = false, d = false, l = false, r = true;
  dp_lr[0][N] = true;
  dp_ud[0][N] = true;
  for (unsigned i = 0; i < step.size(); ++i) {
    if (u) {
      for (int j = -N; j <= N; ++j) {
        dp_lr[i + 1][N + j] = dp_lr[i][N + j];
        dp_ud[i + 1][N + j] = dp_ud[i + 1][N + j] || (N + j - step[i] >= 0 && dp_ud[i][N + j - step[i]]);
      }
    }
    if (d) {
      for (int j = -N; j <= N; ++j) {
        dp_lr[i + 1][N + j] = dp_lr[i][N + j];
        dp_ud[i + 1][N + j] = dp_ud[i + 1][N + j] || (N + j + step[i] <= 2 * N && dp_ud[i][N + j + step[i]]);
      }
    }
    if (l) {
      for (int j = -N; j <= N; ++j) {
        dp_ud[i + 1][N + j] = dp_ud[i][N + j];
        dp_lr[i + 1][N + j] = dp_lr[i + 1][N + j] || (N + j + step[i] <= 2 * N && dp_lr[i][N + j + step[i]]);
      }
    }
    if (r) {
      for (int j = -N; j <= N; ++j) {
        dp_ud[i + 1][N + j] = dp_ud[i][N + j];
        dp_lr[i + 1][N + j] = dp_lr[i + 1][N + j] || (N + j - step[i] >= 0 && dp_lr[i][N + j - step[i]]);
      }
    }
    if (r) {
      u = true;
      d = true;
      l = false;
      r = false;
    } else {
      u = false;
      d = false;
      l = true;
      r = true;
    }
  }
  std::cout << (dp_lr[step.size()][x + N] && dp_ud[step.size()][y + N] ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <cmath>
#include <vector>

int main()
{
    int win_the_turn = 0;
    std::string Atcoder;
    std::cin >> Atcoder;
    int size_atcoder = Atcoder.size();
    for(int j = 0; j < size_atcoder; j++){
        if(Atcoder[j] == 'g') win_the_turn++; 
    }
    int g_number = std::ceil((double)size_atcoder/2.0);
    std::cout << win_the_turn - g_number;
    return 0;
}


Measured memory_bytes: 512
import numpy as np
N, M, Q = map(int, input().split())

#input
lst = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    lst[R][L] += 1

lst = np.array(lst)
# print (lst)

#2次元累積和
for i in range(1, N + 1):
    lst[:,i] += lst[:, i - 1]
for j in range(1, N + 1):
    lst[j,:] += lst[j - 1, :]


#output
for _ in range(Q):
    p, q = map(int, input().split())
    print (lst[q, q] - lst[p-1, q] - lst[q, p-1] + lst[p-1, p-1])

# print (lst)

Measured memory_bytes: 16964
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, m, c[N], s;
V<int> e[N];
bool dfs(int a, int p){
  for(int b : e[a]) if(b != p){
    if(b == s) return true;
    if(sz(e[b]) == 4) continue;
    if(dfs(b, a)) return true;
  }
  return false;
}
bool check(){
  FOR(i, 0, n) if(sz(e[i])==4){
    s = i;
    break;
  }
  return dfs(s, -1);
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].pb(b);
    e[b].pb(a);
    c[a]++;
    c[b]++;
  }
  sort(c, c+n);
  reverse(c, c+n);
  FOR(i, 0, n)if(c[i]&1){
    cout << "No" << endl;
    return 0;
  }
  if(n >= 3 && (c[0]>=6 || c[2]==4 || c[1]==4&&check())){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 7296
N_K = [int(i) for i in input().split()]

N = N_K[0]
K = N_K[1]

num_list = [int(i) for i in input().split()]
num_list.sort()

nums = [0] * (200001)

for i in range(0, N):
    nums[num_list[i]] += 1

nums.sort(reverse = True)

print(N - sum(nums[:K]))


Measured memory_bytes: 25876
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>

using namespace std;

int R[200008];
int n, dif, minv;

void input (){
  cin>>n;
  for(int i=0;i<n;i++)cin>>R[i];
}

void solve(){
  dif=-2000000000;
  minv=R[0];
  for(int i=1;i<n;i++){
    dif=max(dif,R[i]-minv);
    minv=min(minv,R[i]);
  }
  cout<<dif<<endl;
}
int main(){
  input();
  solve();
}

Measured memory_bytes: 3880
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    S = input()[:-1]

    A = [[] for _ in range(3)]
    for i in range(N):
        if S[i:i+1] == "R":
            A[0].append(i)
        if S[i:i+1] == "G":
            A[1].append(i)
        if S[i:i+1] == "B":
            A[2].append(i)

    res = 0
    for P in itertools.permutations(range(3)):
        a = P[0]
        b = P[1]
        c = P[2]
        for i in A[a]:
            x = bisect.bisect_left(A[b], i)
            for j in A[b][x:]:
                res += len(A[c]) - bisect.bisect_left(A[c], j)
    
    for l in range(1, math.ceil(N/2)):
        n = 0
        while n+l*2 < N:
            if S[n] != S[n+l] and S[n+l] != S[n+l*2] and S[n+l*2] != S[n]:
                res -= 1
            n += 1
    
    print(res)


if __name__ == '__main__':
    main()

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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    int A, B;
    cin >> A >> B;
    if(A <= 8 && B <= 8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;

int main() {
	int N;
	cin >> N;
	if (N < 1000) {
		cout << "ABC"<< endl;
	}
	else {
		cout << "ABD" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
a,b,c,d = map(int,input().split())
ans = 0
ans += b // c - (a-1) // c
ans += b // d - (a-1) // d
l = lcm(c,d)
ans -= b // l - (a-1) // l
print(b-a+1-ans) 

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
LL n,a,b;

int main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    
    cin >> n >> a >> b;
    LL k = n%(a+b);
    LL ans = 0;
    ans += ((n-k)/(a+b))*a;
    ans += min(k, a);
    cout << ans;


    cout.flush();
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
const int MN = 510;
int n;
int g[MN][MN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
    cin >> n;
    bool allw = true;
    bool allg = true;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < n; j++) {
            g[i][j] = (s[j] == '#' ? 1 : 0);
            if (g[i][j]) allw = false;
            if (!g[i][j]) allg = false;
        }
    }
    if (allw) {
        cout << -1 << endl;
        return 0;
    }
    if (allg) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 100000;
    for (int i = 0; i < n; i++) {
        bool al = false;
        for (int j = 0; j < n; j++) {
            if (g[j][i]) {
                al = true;
                break;
            }
        }
        int buf = 0;
        if (!al) buf++;
        for (int j = 0; j < n; j++) {
            if (!g[i][j]) buf += 2;
        }
        for (int j = 0; j < n; j++) {
            if (!g[i][j]) continue;
            bool f = true;
            for (int k = 0; k < n; k++) {
                if (!g[k][j]) {
                    f = false;
                    break;
                }
            }
            if (!f) buf++;
        }
        ans = min(ans, buf);
    }
    if (ans > 10000) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
#include       <set>
#include       <map>
#include     <queue>
#include     <cmath>
#include    <cstdio>
#include    <cctype>
#include    <vector>
#include   <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int maxn = 105;

ll fast_pow(ll a,ll b,ll mod){
    ll ans = 1;
    while(b){
        if(b&1)
            ans = ans*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ans;
}

int w[maxn], v[maxn];
int dp[maxn*4][maxn];

int main(){
    int n, W, c;
    scanf("%d%d",&n,&W);
    for(int i=0;i<n;i++)
        scanf("%d%d",&w[i],&v[i]);
    for(int i=1;i<n;i++)
        w[i] -= w[0]-1;
    c = w[0]-1;
    w[0] = 1;//
    for(int i=0;i<n;i++)
        for(int j=(i+1)*4;j>=w[i];j--)
            for(int k=1;k<=i+1;k++){
                dp[j][k] = max(dp[j][k],dp[j-w[i]][k-1]+v[i]);
    }
    int ans = 0;
    for(int j=n*4;j>=0;j--)
        for(int k=1;k<=n;k++){
            if(1ll*k*c+j<=W){
                ans = max(ans,dp[j][k]);
            }
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 384
#include<iostream>
using namespace std;
bool check(int a, int b, int c){
  if( ( a*a + b*b ) == c*c ) return true;
  else return false;
}

int main()
{
  int n,a,b,c;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a >> b >> c;
    if(check(a,b,c) ||check(b,c,a) ||check(c,a,b))
      cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;

int n, a[MAXN];

int main(){
	scanf("%d",&n);
	a[0] = 2e9;
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	sort(a+1, a+n+1);
	reverse(a+1, a+n+1);
	auto fun = [&](int v){
		int s = 0, e = n + 1;
		while(s != e){
			int m = (s+e)/2;
			if(a[m] > v) s = m+1;
			else e = m;
		}
		return s;
	};
	int mxp = 0;
	while(a[mxp + 2] >= mxp + 2) mxp++;
	int updiag = a[mxp + 1] - mxp;
	int ridiag = fun(mxp) - mxp - 1;
	bool win = 0;
	if(updiag % 2 == 1 && ridiag % 2 == 1){
		win = 0;
	}
	else{
		win = 1;
	}
	puts(win ? "First" : "Second");
}


Measured memory_bytes: 640
#include <cstdio>

using namespace std;

int main(void)
{
    for (;;) {
        int n, p;
        int m[50] = {0}, k, t;

        scanf("%d %d", &n, &p);
        if (n == 0 && p == 0)
            break;

        k = p;
        for (t = 0;; t = (t + 1) % n) {
            if (k == 0) {
                k = m[t];
                m[t] = 0;
            } else {
                --k;
                ++m[t];
                if (m[t] == p)
                    break;
            }
        }

        printf("%d\n", t);
    }

    return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define DEBUG(x) cout << #x << " = " << x << endl
#define pb push_back
using namespace std;
typedef long long ll;


const int MAXN = 100000;
ll a[MAXN];
vector <ll> hj;
int main()
{
    //freopen("input.txt", "r", stdin);
    ll n;
    cin >> n;
    ll pow = 1, k = 0;
    while (pow*2-1 <= n)
    {
        pow *= 2;
        k++;
    }

    n -= pow-1;
    ll l = k;
    ll len = 2*k;
    while(n > 0)
    {
        while (pow > n)
        {
            l--;
            pow /= 2;
        }
        n -= pow;
        a[l]++;
        len += 2;
    }
    cout << len << endl;

    ll x = 0;
    for (int i = 0; i <= k; i++)
    {
        if (i != 0) cout << i << " ";
        for (int j = 0; j < a[i]; j++)
        {
            cout << x + j + 50 << " ";
        }
        x += a[i];
    }

    for (int i = 0; i <= k; i++)
    {
        if (i != 0) cout << i << " ";
    }
    for (int i = x-1; i >= 0; i--)
    {
        cout << i+50 << " ";
    }

    return 0;
}



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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  ll res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      res += v[i] * v[j];
    }
  }
  cout << res << endl;
}


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

int main(){
  
  int n,f=0;
  cin>>n;
  vector <int> v(n);
  for(int i=0;i<=n-1;i++)
    cin>>v[i];
   for(int i=0;i<=n-1;i++)
   {
     if(v[i]%2==0)
     {
       if(v[i]%3!=0 && v[i]%5!=0)
       {
         f=1;
       }
     }
   }
  if(f==0)
    cout<<"APPROVED";
  else
    cout<<"DENIED";
  
  
  return 0;
  
}
         
  


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

typedef long long int ll;

int main () {
    ll x,y,a,b,c; cin >> x >> y >> a >> b >> c;
    vector<ll> redApple(a, 0);
    vector<ll> greenApple(b, 0);
    vector<ll> apple(c, 0);
    for (int i = 0; i < a; i++) {
        cin >> redApple[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> greenApple[i];
    }
    for (int i = 0; i < c; i++) {
        cin >> apple[i];
    }
    sort(redApple.begin(), redApple.end());
    sort(greenApple.begin(), greenApple.end());
    sort(apple.begin(), apple.end());

    vector<ll> allApple(0);
    for (int i = 1; i <= x; i++) {
        allApple.push_back(redApple[a-i]);
    }
    for (int i = 1; i <= y; i++) {
        allApple.push_back(greenApple[b-i]);
    }
    sort(allApple.begin(), allApple.end());

    for (int i = 0; i < (x+y); i++) {
        int allIdx = i;
        int cIdx = c - 1 - i;
        if (cIdx < 0) {
            break;
        }
        if (allApple[allIdx] >= apple[cIdx]) {
            break;
        }
        allApple[allIdx] = apple[cIdx];
    }
    ll ans = 0;
    for (int i = 0; i < (int)allApple.size(); i++) {
        ans += allApple[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int H, W, K;
    cin >> H >> W >> K;

    vector<vector<char>> C(H, vector<char>(W, '.'));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){ 
            cin >> C[i][j];
        }
    }
    
    int out = 0;
    for (int m = 0; m < (1 << H); m++){
        for (int n = 0; n < (1 << W); n++){
            int black = 0;
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    if (((m >> i) & 1) == 0 && ((n >> j) & 1) == 0 and C[i][j] == '#'){
                        black++;
                    }
                }
            }

            if (black == K){
                out++; 
            }
        }
    }
    cout << out << endl;
}


Measured memory_bytes: 3596