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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

// a = max(a, b), a = min(a, b)
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; }

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

int main(){
    int N;
    cin >> N;
    REP(i, N){
        int A;
        cin >> A;
        if(A % 2 == 0){
            if(A % 3 != 0 && A % 5 != 0) {
                print("DENIED");
                return 0;
            }
        }
    }
    print("APPROVED");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>	
#include<vector>
using namespace std;
int main (){
  int h,w;
  while(cin >> h >> w,h){
    int min=h*h+w*w;
    vector<pair<int,int> > ans(1000);
    int k=0,judge=1,l=0;
    while(judge){ 
      for(int i=1;i<=150;i++){
        for(int j=i+1;j<=150;j++){
          if((min+l==i*i+j*j)&&(!((i==h)&&(j==w)))){
            if(!(l==0&&i<h)){
              ans[k].first=i;
              ans[k].second=j;
              k++;
              judge=0;
            }
          }
        }
      }
    l++;
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<1000;i++){
      if(ans[i].first!=0){
        cout << ans[i].first << " " << ans[i].second << endl;
        break;	
      }
    }
  }
}

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

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

    if(a+b==3)
        cout<<"3"<<endl;
    else if(a+b==4)
        cout<<"2"<<endl;
    else
        cout<<"1"<<endl;
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())

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

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int N;
vpii P;
void solve(){
    cin>>N;
    rep(i,N) {int a; cin>>a; P.push_back(make_pair(a,i+1));}
    SORT(P);
    rep(i,N) cout<<P[i].second<<" ";
    cout<<endl;
    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 1780
var
  i,n,s,max:longint;
  ch:char;
begin
  readln(n);
  for i:=1 to n do
    begin
      read(ch);
      if ch='I' then inc(s)
        else dec(s);
      if s>max then max:=s;
    end;
  writeln(max);
end.

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

void YesNo(bool x) {
    cout << (x ? "Yes" : "No") << endl;
}

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int INF = 1000 * 1000 * 1000;
vector<vector<int> > g(2000);
int n , k;
int parent[2000];
int dist[2000];
int dist1[2000] , dist2[2000];
int q[2000];
int m;
void bfs(int u)
{
	memset(dist , -1 , sizeof dist);
	int qh = 0 , qt = 0;
	dist[u] = 0;
	q[qt++] = u;
	while(qh != qt)
	{
		int u = q[qh++];
		for(int i = 0; i < g[u].size(); i++)
		{
			int v = g[u][i];
			if(dist[v] == -1)
			{
				q[qt++] = v;
				dist[v] = dist[u] + 1;
			}
		}
	}
}
void bfs1(int u)
{
	memset(dist1 , -1 , sizeof dist1);
	int qh = 0 , qt = 0;
	dist1[u] = 0;
	q[qt++] = u;
	while(qh != qt)
	{
		int u = q[qh++];
		for(int i = 0; i < g[u].size(); i++)
		{
			int v = g[u][i];
			if(dist1[v] == -1)
			{
				q[qt++] = v;
				dist1[v] = dist1[u] + 1;
			}
		}
	}
}
void bfs2(int u)
{
	memset(dist2 , -1 , sizeof dist2);
	int qh = 0 , qt = 0;
	dist2[u] = 0;
	q[qt++] = u;
	while(qh != qt)
	{
		int u = q[qh++];
		for(int i = 0; i < g[u].size(); i++)
		{
			int v = g[u][i];
			if(dist2[v] == -1)
			{
				q[qt++] = v;
				dist2[v] = dist2[u] + 1;
			}
		}
	}
}
int findFur()
{
	int mxDist = 0;
	int fur;
	for(int i = 0; i < n; i++)
	{
		if(dist[i] > mxDist)
		{
			mxDist = dist[i];
			fur = i;
		}
	}
	return fur;
}
void findDiametr()
{
	bfs(0);
	int fur = findFur();
	//cout << fur << endl;
	bfs(fur);
	int fur2 = findFur();
	//cout << fur2 << endl;
	m = dist[fur2];
}
int calcAns(int u , int v)
{
	int ans = 0;
	dist1[u] = 0;
	bfs1(u);
	dist2[v] = 0;
	bfs2(v);
	for(int i = 0; i < n; i++)
	{
		//cout << max(dist1[i] , dist2[i]) << " ";
		if(max(dist1[i] , dist2[i]) > k)
		{
			ans++;
		}
	}
	return ans;
}

int main()
{
	//freopen("input.txt" , "r" , stdin);
	scanf("%d %d" , &n , &k);
	for(int i = 0; i < n - 1; i ++)
	{
		int u , v;
		scanf("%d %d" , &u , &v);
		u--;v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	findDiametr();

	//cout << m << endl;
	int minAns = INF;
	if(m - k <= 0)
	{
		cout << 0;
		return 0;
	}
	for(int i = 0; i < n; i++)
	{
		bfs(i);
		for(int j = i + 1; j < n; j++)
			if(dist[j] == k)
			{
				minAns = min(minAns , calcAns(i , j));
			}
	}
	cout << minAns;
	//freopen("output.txt" , "w" , stdout);

}



Measured memory_bytes: 384
import math
import numpy as np

a =  int(input())
b =  int(input())
c =  int(input())
d =  int(input())
e =  int(input())
x = []
s = 0

if a % 10 != 0:
  x.append(a % 10)

if b % 10 != 0:
  x.append(b % 10)

if c % 10 != 0:
  x.append(c % 10)


if d % 10 != 0:
  x.append(d % 10)


if e % 10 != 0:
  x.append(e % 10)

s = 0

if len(x) != 0:
  if np.amin(x) !=0:
    s = 10
  y = np.amin(x)
else:
  s = 0
  y = 0

print(math.ceil(a/10)*10 +  math.ceil(b/10)*10 +  math.ceil(c/10)*10 +  math.ceil(d/10)*10 +  math.ceil(e/10)*10 +  y -s )



Measured memory_bytes: 12520
//Ahadul Haque, MBSTU,ICT
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define TEST int test; cin >> test ;while(test--)
#define endl "\n"
int main()
{
    ll n;
    cin>>n;
     if(n==0)
        cout<<"1"<<endl;
     else
        cout<<"0"<<endl;






    return 0;
}








Measured memory_bytes: 3548
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);String x;int i,n;Map<Integer,Set<String>>m=new TreeMap<Integer,Set<String>>();for(;!(x=s.next()).equals("0,0");){z=x.split(",");if(!m.containsKey(n=new Integer(z[1])))m.put(n,new HashSet<String>());m.get(n).add(z[0]);}for(;s.hasNext();System.out.println(i)){x=s.next();i=m.size();for(int k:m.keySet()){if(m.get(k).contains(x))break;--i;}}}}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

string w = "keyence";

int main()
{
    ios_base::sync_with_stdio(0);
    string a;
    cin >> a;
    int n = a.size();
    if (a == w)
    {
        cout << "YES";
        return 0;
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = i; j < n; ++j)
        {
            string x = "";
            for (int k = 0; k < n; ++k)
                if (k < i || k > j)
                    x += a[k];
            if (x == w)
            {
                cout << "YES";
                return 0;
            }
        }
    }
    cout << "NO";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int h, w, i, j, min, large, minh, minw;
    scanf("%d %d",&h, &w);
    while(h) {
        large = h * h + w * w;
        min = large + 100;
        minh = 150;
        minw = 150;
        for(i = 1; i < 150; i++ ) {
            for(j = i + 1; j < 150; j++ ) {
                if(i == h && j == w) {
                    continue;
                }
                if(large <= i*i+j*j ) {
                    if(large == i*i+j*j && i < h) {
                        continue;
                    }
                    if(min > i*i+j*j) {
                        min = i*i+j*j;
                        minh = i;
                        minw = j;
                    } else if(minh > i ) {
                        minh = i;
                        minw = j;
                        
                    }
                }
            }
        }
        printf("%d %d\n",minh, minw);
        scanf("%d %d",&h,&w);
    }
    return 0;
}
                

Measured memory_bytes: 600
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,k=0;
    cin>>n>>k;
    lli res=(n/k);
    res*=1ll*(res*res);
    if(k&1)
        cout<<res;
    else
    {
        int temp=n/(k/2);
        ++temp;
        temp/=2;
        lli ans=temp;
        ans*=1ll*(ans*ans);
        cout<<(res+ans);
    }
    cout<<endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
r,s,p=map(int,input().split())
T=input()
cnt=0
N=[0]*n
for i in range(n):
    if N[i]==1:
        continue
    if i+k<=n-1:
        if T[i]==T[i+k]:
            N[i+k]=1
    
    if T[i]=='r':
        cnt+=p
    elif T[i]=='s':
        cnt+=r
    else:
        cnt+=s

print(cnt)

Measured memory_bytes: 4084
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main(void) {
  double r;
  //input
  cin >> r;
  printf("%f %f \n",(r * r * M_PI),(2 * M_PI * r));
//  cout << d << " " << r << " " << f << endl;
  return 0;
}



Measured memory_bytes: 3292
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;
	int K;
	cin >> K;

	lint S_sz = S.size();
	if (S == string(S_sz, S[0])) {
		cout << K * S_sz / 2 << "\n";
		return 0;
	}

	lint cnt1 = 0, cnt2 = 0;
	char prev = S[0];
	for (int i = 1; i < S_sz; i++) {

		if (S[i] == prev) {
			cnt1++;
			prev = '*';
		}
		else prev = S[i];
	}	
	prev = S[0];
	for (int i = 1; i < 2 * S_sz; i++) {

		if (S[i % S_sz] == prev) {
			cnt2++;
			prev = '*';
		}
		else prev = S[i % S_sz];
	}

	cout << cnt1 + (cnt2 - cnt1) * (K - 1) << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long int ll;
int main()
{
  ll n;
  cin>>n;
  ll a[2][n];
  for(int i=0;i<2;i++)
  for(int j=0;j<n;j++) cin>>a[i][j];

  ll dp[2][n];
  dp[0][0]=a[0][0],dp[1][0]=dp[0][0]+a[1][0];
  for(int i=0;i<2;i++)
  for(int j=1;j<n;j++)
  {
    if(i==0) dp[i][j]=dp[i][j-1]+a[i][j];
    else dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
  }

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

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cassert>
#include<climits>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 300000

using namespace std;

double dp[20][MAX];
int N;
double input[20];

int main(){

  cin >> N;
  rep(i,N)cin >> input[i];

  rep(i,N)rep(j,MAX)dp[i][j] = IINF;

  rep(i,MAX){
    dp[0][i] = abs(input[0]-i)/input[0];
  }
 
  rep(i,N-1){
    REP(j,1,MAX){
      if(dp[i][j] == IINF)  continue;
      for(int k=j;k<MAX;k+=j){
	dp[i+1][k] = min(dp[i+1][k],
			 max(dp[i][j],abs(input[i+1]-k)/input[i+1]));
      }
    }
  }


  double ans = IINF;
  rep(i,MAX){
    ans = min(ans,dp[N-1][i]);
  }

  printf("%.12f\n",ans);
  return 0;
}

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

int main(int argc, char const *argv[])
{
	string s,t;
	cin>>s>>t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (s<t)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


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

int main(void) {
  string A, B;
  string out;
  cin >> A >> B;

  if (A.length() > B.length() || (A.length() == B.length() && A > B))
    out = "GREATER";
  else if (A.length() < B.length() || (A.length() == B.length() && A < B))
    out = "LESS";
  else
    out = "EQUAL";
  cout << out << endl;
  return 0;
}

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

int main(){
    while (true){
        int H,W;
        cin >> H >> W;
        if(H==0 && W==0){
            break;
        }
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3084
H,W=map(int,input().split())

S=[]

for i in range(H):
    tmp=list(input())
    S.append(tmp)

ope=[-1,0,1]

for i in range(H):
    ans=[]
    for j in range(W):
        if S[i][j]=="#":
            ans=ans+["#"]
        else:
            c=0
            for k in ope:
                for l in ope:
                    y=i+k
                    x=j+l
                    if x>-1 and x<W and y>-1 and y<H:
                        #print(y,x)
                        if S[y][x]=="#":
                            c+=1
            ans=ans+list(str(c))
    ans2="".join(ans)
    print(ans2)

Measured memory_bytes: 3064
import heapq

n, m = map(int, input().split())

baito = [[] for i in range(m + 1)]

for i in range(n):
    a, b = map(int, input().split())
    if a > m:
        continue
    else:
        heapq.heappush(baito[a], -b)

houshuusum = 0

kouho = []

for i in range(1, m + 1):
    if len(baito[i]) > 0:
        heapq.heappush(kouho, (heapq.heappop(baito[i]), i))

    if len(kouho) > 0:
        houshuu, idx = heapq.heappop(kouho)
        houshuusum += houshuu

        if len(baito[idx]) > 0:
            heapq.heappush(kouho, (heapq.heappop(baito[idx]), idx))


print(-houshuusum)


Measured memory_bytes: 17860
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;
const int N = 1e6+10;
int n,m,k,q,x,y;
int h[N],w[N],e[N],ne[N],idx;

ll dist[N];
bool st[N];

void add(int a,int b,int c)
{
    e[idx] = b,w[idx] = c,ne[idx] = h[a],h[a] = idx++;
}

void spfa()
{
    memset(dist,0x3f,sizeof dist);
    dist[k] = 0;
    queue<int>q;
    q.push(k);
    
    st[k] = true;
    
    while(q.size())
    {
        int t = q.front();
        q.pop();
        
        st[t] = false;
        
        for(int i = h[t];i!=-1;i=ne[i])
        {
            int j = e[i];
            if(dist[j]>dist[t] + w[i])
            {
                dist[j] = dist[t] + w[i];
                if(!st[j])
                {
                    q.push(j);
                    st[j] = true;
                }
            }

        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >>n;
    memset(h,-1,sizeof h);
    m = n-1;
    while(m--)
    {
        int a,b,c;
        cin >>a>>b>>c;
        add(a,b,c);
        add(b,a,c);
    }
    
    cin >> q>>k;
    spfa();
    while(q--)
    {
        cin >>x >>y;
        cout << dist[x] + dist[y] << endl;
    }
    spfa();
    
    return 0;
}

Measured memory_bytes: 19200
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

const int maxn = 200000;
int n, k;
int a[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> k >> n;
	
	int ret = k;
	for(int i = 0; i < n; i++){
	    cin >> a[i];
	    if(i) ret = min(ret, k - (a[i] - a[i - 1]));
	} 
	ret = min(ret, k - (k - a[n - 1] + a[0]));
	
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

#define N 100000

typedef struct{
  char x;
  int n;
  int r;
}Card;

void quickSort(Card[],int,int);
int partition(Card[],int,int);
int isStable(Card[]);

int n;

int main(){
  int i;
  Card A[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf(" %c %d",&A[i].x,&A[i].n);
    A[i].r=i;
  }

  quickSort(A,0,n-1);  

  if(isStable(A)) printf("Stable\n");
  else printf("Not stable\n");

  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].x,A[i].n);
  }

  return 0;
}

void quickSort(Card A[],int p,int r){
  int q;
  if(p<r){
    q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
  return;
}

int partition(Card A[], int p, int r){
  int x,i,j;
  Card tmp;

  x=A[r].n;

  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].n<=x){
      i = i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }

  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

  return i+1;
}

int isStable(Card A[]){
  int i;

  for(i=0;i<n;i++){
    if( A[i].n == A[i+1].n && A[i].r > A[i+1].r ) return 0;
  }
  
  return 1;
}

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




int main(){
   string s,p;cin>>s>>p;
   int c=0;
   for(int i=0;i<s.length();i++){
    if(s[i]==p[i])
        c++;
   }


   cout<<s.length()-c<<endl;

    return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = m; i < n; i++)
#define printhello std::cout << "hello" << endl;
using ll=long long;
using namespace std;

int main(){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int main()
{
	string s;
	int a,b;
	while(cin >> s >> a >> b)
	{
		int ans = 200*a+300*b;
		int sum = a+b;
		cout << s << ' ' << sum << ' ' << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,x,ans;
map<int,int> mp;
vector<int> v;
int main()
{
	cin>>n>>m;
	while (n--)
	{
		cin>>x;
		mp[x]++;
	}
	if (mp.size()<=m)
	{
		cout<<0;
		return 0;
	}
	for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		v.push_back(it->second);
	}
	sort(v.begin(),v.end());
	for (i=0;i+m<mp.size();i++) ans+=v[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 10748
N = list(input())

num = 0
ans = 0
for i in range(len(N)-1, -1, -1):
    n = int(N[i])
    if n+num == 5 and i > 0 and int(N[i-1]) >= 5:
        ans += 5
        num = 1
    elif n+num < 6:
        ans += n+num
        num = 0
    else:
        ans += 10-(n+num)
        num = 1

ans += num
print(ans)

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B;
    cin >> A >> B;

    cout << max(A+B, max(A-B, A*B)) << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scan()
	x, y := 0, 0
	for _, v := range s {
		if string(v) == "0" {
			x++
		} else {
			y++
		}
	}
	fmt.Println(smaller(x, y) * 2)
}


Measured memory_bytes: 2104
#include <iostream>
using namespace std;
#define ll long long
int main()
{
    string s;
    ll q;
    cin >> s;
    cin >> q;
    string k;
    string h;
    ll flag = 0;
    for (ll i = 0; i < q; i++)
    {
        int p;
        cin >> p;
        if (p == 1)
        {              //このとき反転させられる。→どっち向きになったのかの情報を持っておく。
            flag += 1; //これが奇数の時には反転している。
        }
        else if (p == 2)
        {
            int y;
            cin >> y;
            char f;
            cin >> f;
            if ((y + flag) % 2 == 1)
            {
                k= f + k; //これは本来の文字列の向きの先頭につける者。
            }
            else
            {
                h = h + f;
            }
        }
    }
    if (flag % 2 == 1)
    {
        reverse(s.begin(), s.end());
        reverse(k.begin(),k.end());
		reverse(h.begin(),h.end());
        cout << h+s+k << endl;
        return 0;
    }
    cout << k+s+h << endl;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  
  if(a>=10||b>=10){cout<<-1<<endl;}
  else{cout<<a*b<<endl;}

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio> 
using namespace std;
const int maxn = 1e5+5;
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
int n,a,b,c;
string op[maxn];
char ans[maxn];
bool res[4];
void dfs(int i){
    if(a<0||b<0||c<0)
        return;
    if(i==n+1){
        puts("Yes");
        for(int i=1;i<=n;i++)
            printf("%c\n",ans[i]);
        exit(0);
    }
    if(op[i]=="AB"){
       if(res[1]==1){
            res[i]*=-1;
            a++;b--;
            ans[i]='A';
            dfs(i+1);
            a--;b++;
            a--;b++;
            ans[i]='B';
            dfs(i+1);
            a++;b--;
       }
       else{
            res[i]*=-1;
            a--;b++;
            ans[i]='B';
            dfs(i+1);
            a++;b--;
            a++;b--;
            ans[i]='A';
            dfs(i+1);
            a--;b++;
       }
    }
    if(op[i]=="AC"){
        if(res[1]==1){
            res[i]*=-1;
            a++;c--;
            ans[i]='A';
            dfs(i+1);
            a--;c++;
            a--;c++;
            ans[i]='C';
            dfs(i+1);
            a++;c--;
       }
       else{
            res[2]*=-1;
            a--;c++;
            ans[i]='C';
            dfs(i+1);
            a++;c--;
            a++;c--;
            ans[i]='A';
            dfs(i+1);
            a--;c++;
       }
    }
    if(op[i]=="BC"){
        if(res[3]==1){
            res[3]*=-1;
            b++;c--;
            ans[i]='B';
            dfs(i+1);
            b--;c++;
            b--;c++;
            ans[i]='C';
            dfs(i+1);
            b++;c--;
       }
       else{
            res[i]*=-1;
            b--;c++;
            ans[i]='C';
            dfs(i+1);
            a++;b--;
            b++;c--;
            ans[i]='B';
            dfs(i+1);
            b--;c++;
       }
    }
}
int main(){
    n=readint(),a=readint(),b=readint(),c=readint();
    res[1]=res[2]=res[3]=1;
    for(int i=1;i<=n;i++)
        cin>>op[i];
    dfs(1);
    puts("No");
    return 0;
}

Measured memory_bytes: 11660
/* package whatever; // don't place package name! */

import java.util.Scanner;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner cin = new Scanner(System.in);
		
		while (cin.hasNext()){
			int a = cin.nextInt();
			int b = cin.nextInt();
			int gcd = GCD(a, b);
			int lcm = a / gcd * b;
			
			System.out.println(gcd + " " + lcm);
		}
	}
	
	private static int GCD(int a, int b)
	{
		if (a % b != 0){
			return (GCD(b, a % b));
		}
		else {
			return (b);
		}
	}
}

Measured memory_bytes: 26204
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from heapq import heappush, heappop

def main():
    q = II()
    Q = []
    for _ in range(q):
        Q.append(LI())
    lows, highs = [], []
    slow, shigh = 0, 0
    bias = 0
    for q in Q:
        if q[0] == 2:
            odd = -lows[0] if len(highs) != len(lows) else 0
            ans = -lows[0], bias + shigh - slow + odd
            print(*ans)
        else:
            _, a, b = q
            bias += b
            if not lows:
                lows = [-a]
                slow = a
            else:
                if a <= -lows[0]:
                    heappush(lows, -a)
                    slow += a
                    if len(lows) > len(highs) + 1:
                        x = -heappop(lows)
                        heappush(highs, x)
                        slow -= x
                        shigh += x
                else:
                    heappush(highs, a)
                    shigh += a
                    if len(highs) > len(lows):
                        x = heappop(highs)
                        heappush(lows, -x)
                        shigh -= x
                        slow += x
    return

main()

Measured memory_bytes: 105436
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
int main() {
    string num;
     
    while(cin >> num){
        if(num == "0"){
            break;
        }else{
            int sum = 0;
    for(int i = 0; i < num.length(); i++){
        sum = (num[i] - '0') + sum;
    }
            cout << sum << endl;
        }
    }
    return 0;
}


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

#define ll long long
using namespace std;
vector<string>x;
long long n;
map<string,int>mp;
long long res;
int main()
{
	cin>>n;
	res=0;
	for(long long i=0;i<n;i++)
	{
		string s;
		cin>>s;
		sort(s.begin(),s.begin()+s.size());
		res+=mp[s];
		mp[s]++;
	}
	cout<<res;
	puts("");
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define ll long long
#define pii pair<ll,ll>
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<<x<<endl;
#define FIO ios::sync_with_stdio(false);
#define ALL(x) x.begin(),x.end()
#define LOG 20
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1|1)

const int maxn=1e6+10;
using namespace std;
int h,w,k;
int a[20][1005];
int main(){
    string s[10];
	cin>>h>>w>>k;
	int ans =maxn;
	for(int i=0;i<h;i++)cin>>s[i];
	for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            a[i][j]=s[i][j]-'0';
    //for(int i=0;i<h;i++)
     //   for(int j=0;j<w;j++)
     //       cout<<a[i][j]<<" \n"[j==w-1];
	for(int c=0;c<(1<<(h-1));c++){
        int cnt = __builtin_popcount(c);
        int m[20]={0},v[20]={0};
        for(int i=0;i<h;i++) v[i]=0;
        for(int i=1,j=0;i<h;i++)
            if((c>>(i-1))&1) m[i]=++j;
            else m[i]=j;
        int f=0;
        //if(c==2)
            //for(int i=0;i<h;i++) cout<<m[i]<<" \n"[i==h-1];
        for(int i=0;i<w;i++){
            for(int j=0;j<h;j++){
                if(v[m[j]]+a[j][i]>k){
                    cnt++;
                    for(int l=0;l<h;l++) v[m[l]]=0;
                    for(int l=0;l<h;l++) v[m[l]]+=a[l][i];
                    break;
                }
                else{
                    v[m[j]]+=a[j][i];
                }
            }
            //if(c==2) for(int l=0;l<h;l++) bug(v[m[l]])
            for(int l=0;l<h;l++) if(v[m[l]]>k) f=1;
        }
        //if(c==2)cout<<f<<" "<<cnt<<" "<<c<<endl;
        if(!f)ans = min(ans,cnt);
	}
	cout<<ans<<endl;
    return 0;
}

/**
#define X first
#define Y second
#define PB push_back
#define ll long long
#define pii pair<ll,ll>
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<<x<<endl;
#define FIO ios::sync_with_stdio(false);
#define ALL(x) x.begin(),x.end()
#define LOG 20
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1|1)

const int maxn=1e6+10;
using namespace std;
**/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<LP> pos(N);
    REP(i,N) cin>>pos[i].first>>pos[i].second;
    int par = (abs(pos[0].first)+abs(pos[0].second))%2;
    REP(i,N){
        int par2 = (abs(pos[i].first)+abs(pos[i].second))%2;
        pos[i] = LP(pos[i].first+pos[i].second,pos[i].first-pos[i].second);
        if(par2!=par){
            cout<<-1<<endl;
            return 0;
        }
    }
    vector<ll> d;
    for(int i=30;i>=0;i--) d.push_back(1LL<<i);
    if(par%2==0) d.push_back(1);
    cout<<d.size()<<endl;
    for(int j=0;j<d.size();++j) cout<<d[j]<<" ";
    cout<<endl;
    for(int i=0;i<N;i++){
        int xdir,ydir;
        ll xsum=0,ysum=0;
        for(int j=0;j<(int)d.size();j++){
            if(xsum<=pos[i].first) xdir=1,xsum+=d[j];
            else xdir=-1,xsum-=d[j];
            if(ysum<=pos[i].second) ydir=1,ysum+=d[j];
            else ydir=-1,ysum-=d[j];
            if(xdir==1&&ydir==1) cout<<"R";
            else if(xdir==1&&ydir==-1) cout<<"U";
            else if(xdir==-1&&ydir==-1) cout<<"L";
            else cout<<"D";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#include <set>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){
  
  int a,b;
  cin >> a >> b;
  
  if(a % 2 == 0 || b % 2 == 0) cout << "Even" << endl;
  else						   cout << "Odd"  << endl;


 return 0;
}

Measured memory_bytes: 256
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <vector>
    #include <iostream>
    #include <queue>
    #include <unordered_map>
    #include <cmath>
    #include <queue>
    #include <string>
    #include <random>
    using namespace std;
    typedef long long ll;
    const int maxn = 100005;
     
    ll f[41][2];
    int c[41];
     
    void pd(ll&ret, ll val){
      if(ret<val)ret=val;
    }
     
    int main() {
    #ifdef suiyuan2009
      freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
      //freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout);
    #endif
      int n;
      ll K;
      cin>>n>>K;
      for(int i=0;i<n;i++) {
        ll x;
        cin >> x;
        for (int j = 0; j < 40; j++)if (x & (1LL << j))c[j]++;
      }
      memset(f, -1,sizeof(f));
      f[40][1] = 0;
      for(int i=39;i>=0;i--){
        if(f[i+1][1]!=-1){
          int lim = ((K&(1LL<<i)) > 0LL ? 1:0);
          if(lim==0){
            pd(f[i][1],f[i+1][1] + (1LL<<i)*c[i]);
          } else {
            pd(f[i][1], f[i+1][1] + (1LL<<i)*(n-c[i]));
            pd(f[i][0], f[i+1][1] + (1LL<<i)*c[i]);
          }
        }
        if(f[i+1][0]!=-1){
          pd(f[i][0],f[i+1][0]+(1LL<<i)*c[i]);
          pd(f[i][0],f[i+1][0]+(1LL<<i)*(n-c[i]));
        }
      }
      cout<<max(f[0][1], f[0][0])<<endl;
      return 0;
    }

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

template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class like_bool> inline void POSS(like_bool condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class like_bool> inline void Poss(like_bool condition){ if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class like_bool> inline void First(like_bool condition){ if(condition)cout << "First" << endl; else cout << "Second" << endl; }
template<class like_bool, class output> inline void negative(like_bool condition, output num){ if(condition)cout << -1 << endl; else cout << num << 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}};
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; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define bitcount(n) __builtin_popcount(n)

int segment_tree_size = 1;
vector<int> segment_tree;

void plus_item(int point, int num){
    point += segment_tree_size - 1;
    segment_tree[point] += num;
    while(point > 0){
        point = (point - 1) / 2;
        segment_tree[point] += num;
    }
}

int get_sum(int left, int right, int now = 0, int point_left = 0, int point_right = segment_tree_size){
    if(point_right <= left || right <= point_left){
        return 0;
    }else if(left <= point_left && point_right <= right){
        return segment_tree[now];
    }else{
        return get_sum(left, right, now * 2 + 1, point_left, (point_left + point_right) / 2) +
               get_sum(left, right, now * 2 + 2, (point_left + point_right) / 2, point_right);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    while(n > segment_tree_size){
        segment_tree_size *= 2;
    }
    segment_tree.resize(segment_tree_size * 2 - 1, 0);
    for(int i = 0; i < q; i++){
        int com, x, y;
        cin >> com >> x >> y;
        if(com){
            cout << get_sum(x - 1, y) << endl;
        }else{
            plus_item(x - 1, y);
        }
    }
}




Measured memory_bytes: 3900
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i <= g; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b)
{
    ll tmp;
    ll c;
    if (a < b)
    {
        tmp = a;
        a = b;
        b = tmp;
    }

    do
    {
        c = a % b;
        a = b;
        b = c;
    } while (c != 0);

    return a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int two(int a)
{
    int ans = 0;

    while (a % 2 == 0)
    {
        ans++;
        a /= 2;
    }

    return ans;
}

int main(void)
{
    int N, M;
    int a;
    int i, j;
    ll l = 1;
    int ans = 0;
    int flag;

    cin >> N >> M;

    cin >> a;
    a /= 2;
    l = lcm(l, a);
    flag = two(a);

    rep(i, 0, N - 2)
    {
        cin >> a;
        a /= 2;
        if (flag != two(a))
        {
            cout << 0 << endl;
            return 0;
        }

        l = lcm(l, a);
    }

    
    cout << (M / l + 1) / 2 << endl;
}

Measured memory_bytes: 256
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        n: u64,
        a: [u64; n],
    }
    let m = a.into_iter().fold(1_u64, |acc, ai| acc.saturating_mul(ai));
    if m > 10_u64.pow(18) {
        println!("{}", -1);
    } else {
        println!("{}", m);
    }
}


Measured memory_bytes: 4584
#include<iostream>
#include<stack>
const int N = 100;
using namespace std;
int n,M[N][N];
int color[N],nt[N],d[N],f[N],start;
int next(int u){
	for(int i=nt[u];i<n;i++){
        nt[u] = i+ 1;
        if(M[u][i]) return i;
    }
	return -1;
}
void dfs_visit(int u){
    for(int i=0;i<n;i++) nt[i] = 0;
    stack<int> s;
	s.push(u);
	color[u] = 1;
	d[u] = ++start;
	while(!s.empty()){
		int x = s.top();
		int v = next(x);
		if(v!=-1){
			if(!color[v]){
				s.push(v);
				d[v] = ++start;
				color[v] = 1;
			}
		}else{
			s.pop();
            color[x] = 1;
			f[x] = ++start;
		}
	}
}
void dfs(){
	start = 0;
	for(int i=0;i<n;i++)
            if(!color[i])
	            dfs_visit(i);
	for(int i=0;i<n;i++)
		printf("%d %d %d\n",i+1,d[i],f[i]);
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int u,k,v;
		scanf("%d%d",&u,&k);
		while(k--){
			scanf("%d",&v);
			M[u-1][v-1] = 1;
		}
	}
	dfs();
	return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int H, W;
    cin >> H >> W;
    string S[H];
    REP(i, H) cin >> S[i];

    bool grid[H][W];
    REP(i, H) REP(j, W) grid[i][j] = S[i][j] == '.';

    int num[H][W];
    REP(i, H) REP(j, W) num[i][j] = 0;
    REP(i, H)
    {
        int s = 0;
        REP(j, W)
        {
            if (!grid[i][j])
            {
                FOR(k, s, j) num[i][k] = j-1-s;
                s = j+1;
            }
            else
            if (j == W-1)
            {
                FOR(k, s, j+1) num[i][k] = j-s;
            }
        }
    }

    int ret = 0;
    REP(i, W)
    {
        int s = 0;
        REP(j, H)
        {
            if (!grid[j][i])
            {
                FOR(k, s, j) { ret = max(num[k][i]+(j-1-s), ret); }
                s = j+1;
            }
            else
            if (j == H-1)
            {
                FOR(k, s, j+1) { ret = max(num[k][i]+(j-s), ret); }
            }
        }
    }

    cout << (ret+1) << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;

int MOD = 1e9+7;

// ll po(ll b, ll p){ return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD;}
// ll pomd(ll a, ll k, ll md) { ll p; if (k == 0){ return 1; } p = pomd(a, k / 2, md); p = p * p % md; if (k % 2){ p = p * a % md; } return p; }
// vi arr(N); for(int i{1}; i<N; ++i) for(int j=i; j<N; j+=i) d[j]++; // counting divisors
//bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }

#define mp make_pair
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define rot(s, k) rotate(s.begin(), s.begin()+ s.size()-(k%s.size()), s.end()); //+ve = right, -ve = left

void setIO(string name = ""){
    freopen((name+".in").c_str(), "r", stdin); 
    freopen((name+".out").c_str(), "w", stdout);
}	

int main(){
 	ios_base::sync_with_stdio(0); cin.tie(0); 
	// setIO();
	int n; cin >> n;
	cout << (n%2==0?double((n/2))/n:double(((n/2))+1)/n) << "\n";

}


Measured memory_bytes: 3824
#include<stdio.h>
 
#define Max 45
 
int F[Max];
 
int fibonacci(int n){
  if( n == 0 || n == 1)
    return F[n] = 1;
  if( F[n] != NULL ) 
    return F[n];
  return F[n] = fibonacci(n - 2) + fibonacci(n - 1);
}
 
int main(){
 
  int n, i, A;
 
  scanf("%d",&n);
 
  for( i = 0 ; i <= n  ; i++)
    A = fibonacci(i);
 
  printf("%d\n",A);
 
  return 0;
}

Measured memory_bytes: 2728
#include<stdio.h>

int main(){
	int a,b=0,i;
	scanf("%d",&a);
	for(i=1;i<4;i++){
      if(a%10==1){
        b+=1;
      }
      a=a/10;
    }
  printf("%d\n",b);
  return 0;
}
  

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

int main(void) {
	int N;
	cin >> N;
	string S;
	cin >> S;
	bool Insertion[100];
	for (int i = 0; i < N;i++)Insertion[i] = true;
	for (int i = 0; i < N; i++) {
		if (S[i] == '(' && Insertion[i]) {
			for (int j = i + 1; j < N; j++) {
				if (S[j] == ')' && Insertion[j]) {
					Insertion[i] = Insertion[j] = false;
					break;
				}
			}
		}
	}
	string ans = S;
	for (int i = 0; i < N; i++) {
		if (Insertion[i]) {
			if (S[i] == ')') {
				ans = "(" + ans;
			}
			else {
				ans = ans + ")";
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long lli;

int N, M, K, L;
vector<pair<int, string> > V;
map<string, int> m;
vector<int> H;


int needCost(pair<int, string> &a, pair<int, string> &b) {
  if(a <= b) return 0;
  return a.first - b.first + ((a.second > b.second) ? 1 : 0);
}

bool isTrue(int a) {
  int line = K-a;
  lli cost = 0;
  for(int i = 0; i < a; ++i) {
    cost += needCost(V[H[i]], V[line]);
    if(H[i] <= line) ++line;
  }
  return cost <= L;
}

int solve() {
  int l, r, ans;
  l = 0; r = min(M+1, K+1); ans = 0;
  while(l < r) {
    int a = (l+r)/2;
    if(isTrue(a)) {
      ans = a;
      l = a+1;
    } else {
      r = a;
    }
  }
  return ans;
}

int main() {
  while(cin >> N >> M >> K >> L && (N || M || K || L)) {
    V.clear();
    m.clear();
    H.clear();
    for(int i = 0; i < N; ++i) {
      pair<int, string> p;
      cin >> p.second >> p.first;
      p.first *= -1;
      V.push_back(p);
    }
    sort(V.begin(), V.end());

    for(int i = 0; i < V.size(); ++i) {
      m[V[i].second] = i;
    }

    for(int i = 0; i < M; ++i) {
      string name;
      cin >> name;
      H.push_back(m[name]);
    }
    sort(H.begin(), H.end());
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 8720
#include <iostream>
#include <algorithm>
using namespace std;
int N, M;
pair<int, pair<int, int>> p[100010];
int main() {
    cin >> N >> M;
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(b, make_pair(a, i));
    }

    sort(p, p + M);
    int cnt[100010] = {};
    pair<int, int> ans[100010];
    for(int i = 0; i < M; ++i) {
        cnt[p[i].second.first]++;
        ans[p[i].second.second] = make_pair(p[i].second.first, cnt[p[i].second.first]);
    }
    for(int i = 0; i < M; ++i) {
        printf("%06d%06d\n", ans[i].first, ans[i].second);
    }
}


Measured memory_bytes: 3840
a, b = map(int, input().split())
ans = int(1e18)

def check(l):
    return max(l) - min(l)

if a % 3 == 0 or b % 3 == 0:
    ans = 0
else:
    x = a // 3
    y = a - x
    box = [x*b, b*(y//2), b*(y//2 + y%2)]
    ans = min(ans, check(box))
    box = [x*b, y*(b//2), y*(b//2 + b%2)]
    ans = min(ans, check(box))
    
    x = a // 3 + 1
    y = a - x
    box = [x*b, b*(y//2), b*(y//2 + y%2)]
    ans = min(ans, check(box))
    box = [x*b, y*(b//2), y*(b//2 + b%2)]
    ans = min(ans, check(box))

    (a, b) = (b, a)
    x = a // 3
    y = a - x
    box = [x*b, b*(y//2), b*(y//2 + y%2)]
    ans = min(ans, check(box))
    box = [x*b, y*(b//2), y*(b//2 + b%2)]
    ans = min(ans, check(box))
    
    x = a // 3 + 1
    y = a - x
    box = [x*b, b*(y//2), b*(y//2 + y%2)]
    ans = min(ans, check(box))
    box = [x*b, y*(b//2), y*(b//2 + b%2)]
    ans = min(ans, check(box))


print(ans)


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

unsigned long long cnt = 0;
const int INF = 1001001001;

void step(int* array, int left, int mid, int right)
{
    int L[200000], R[200000], l=0, r=0;
    for(int i=left;i<mid;++i) L[i - left] = array[i];
    for(int i=mid;i<right;++i) R[i - mid] = array[i];
    L[mid - left] = R[right - mid] = INF;
    for(int i=left; i<right; ++i)
    {
        if(L[l] <= R[r])
        {
            array[i] = L[l++];
        }
        else{
            array[i] = R[r++];
            cnt += (mid - left - l);
        }
    }
}

void count_inversion(int* array, int left, int right)
{
    if(left < right - 1){
        int mid = (left + right) / 2;
        count_inversion(array, left, mid);
        count_inversion(array, mid, right);
        step(array, left, mid, right);
    }
}

int main()
{
    int n, array[200000];
    cin >> n;
    for(int i=0;i<n;++i) cin >> array[i];
    count_inversion(array, 0, n);
    cout << cnt << endl;
}



Measured memory_bytes: 4672