akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.*;
public class Main {
    static int ans = Integer.MAX_VALUE;
    static int n;
    static int[] a;
    static int[] l;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new int[3];
        for (int i = 0; i < 3; i++) {
            a[i] = sc.nextInt();
        }
        l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }
        int[] k = new int[n];
        dfs(0, k);
        System.out.println(ans);
    }
    public static void dfs(int depth, int[] k) {
        // System.out.println("depth = " + depth);
        // System.out.println("k = " + Arrays.toString(k));
        // System.out.println("n = " + n);
        if (depth == n) {
            ans = Math.min(ans, calc(k));
            return;
        }
        for (int i = 0; i < 4; i++) {
            k[depth] = i;
            dfs(depth + 1, k);
        }
    }
    public static int calc(int[] k) {
        int cnt1 = 0;
        int cnt2 = 0;
        int cnt3 = 0;
        int sum1 = 0;
        int sum2 = 0;
        int sum3 = 0;
        for (int i = 0; i < n; i++) {
            if (k[i] == 0) {
                sum1 += l[i];
                cnt1++;
            }
            if (k[i] == 1) {
                sum2 += l[i];
                cnt2++;
            }
            if (k[i] == 2) {
                sum3 += l[i];
                cnt3++;
            }
        }
        if (cnt1 == 0 || cnt2 == 0 || cnt3 == 0) {
            return Integer.MAX_VALUE;
        }
        int ans = Math.abs(a[0] - sum1) + Math.abs(a[1] - sum2) + Math.abs(a[2] - sum3)
            + 10 * (cnt1 + cnt2 + cnt3 - 3);
        return ans;
    }
}


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

const long long mod = 1e9 + 7;

int main(int argc, char const *argv[])
{
    int n, m; cin >> n >> m;
    int a[m];
    int oks[n+1];
    for (int i=0; i<n+1; i++) oks[i] = 1;
    for (int i=0; i<m; i++) {
        int a; cin >> a;
        oks[a] = 0;
    }

    long long dp[n+1];
    for (int i=0; i<=n; i++) dp[i] = 0;
    dp[0] = 1;
    for (int now=0; now<n; ++now) {
        for (int next=now+1; next<=min(n, now+2); ++next) {
            if (oks[next] == 1) {
                dp[next] += dp[now];
                dp[next] %= mod;
            }
        }
    }
    cout << dp[n] << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n;
  cin >> n;
  if(n >= 30)cout << "Yes" << endl;
  else cout << "No"  << endl;
  

  

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b; cin>>a>>b;
    string s1;
    for(int i=0;i<b;i++){
        s1=s1+to_string(a);
    }
    string s2;
    for(int i=0;i<a;i++){
        s2=s2+to_string(b);
    }
    cout<<min(s1,s2);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
int binary_search_index(Int Y, vi &q){
    int left = 0, right = q.size() - 1;
    while (right >= left) {
        int mid = left + (right - left) / 2;
        if (q[mid] == Y) return mid;
        else if (q[mid] > Y) right = mid - 1;
        else if (q[mid] < Y) left = mid + 1;
    }
    return -1;
}


int main() {
    Int L,R,ans;
    cin >> L >>R;

    ans = inf;
    Int mod = 2019;
    Int diff = R-L;
    if(diff > 2018){
        ans = 0;
    }else{
        rep(i,diff){
            REP(j,i+1,diff+1){
                if(i==j){continue;}
                int LL = (L+i)%mod;
                int RR = (L+j)%mod;
                ans = min(ans, (LL*RR)%mod );
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
use std::io::Read;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let num :u32 = read();
    let mut string = String::new();
    std::io::stdin().read_line(&mut string).ok();

    if num >= 3200 {
        println!("{}", string);
    } else {
        println!("red");
    }
}

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

int main() {
  int j=0;
  string s;

  cin >> s;
  vector<int> ans(s.length());
  vector<int> rs(s.length()), sr(s.length());

  for(int i = 0; i < s.length()-1; ++i)
  {
    if(s[i] == 'R' && s[i+1] == 'L')
    {
      rs[j] = i;
    }
    else if(s[i] == 'L' && s[i+1] == 'R')
    {
      sr[j] = i;
      ++j;
    }
  }
  sr[j] = s.length()-1;

  j = 0;
  for(int i = 0; i < s.length(); ++i)
  {
    if(sr[j] < i)
    {
      ++j;
    }

    if(i < rs[j])
    {
      if((rs[j]-i)%2 == 0)
      {
        ans[rs[j]]++;
      }
      else ans[rs[j]+1]++;
    }
    else
    {
      if((i-rs[j])%2 == 0)
      {
        ans[rs[j]]++;
      }
      else ans[rs[j]+1]++;
    }
  }
  for(int i = 0; i < s.length(); i++)
  {
	  cout << ans[i] << ' ';
  }
}

Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

// read to vector
#define M_RV(ident, type, cnt) \
    vector<type> ident(cnt);\
    for(int lcnt; lcnt < cnt; lcnt++) cin >> ident[lcnt];

#define M_RANGE(ident) ident.begin(), ident.end()

// https://qiita.com/EqualL2/items/b4683db7ab4e90545bb2
int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

template <typename T>
T tmpl_abs(T n) {
    return n < 0 ? -n : n;
}

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

    M_RV(ls, int, n);

    int max = *max_element(M_RANGE(ls));
    int sum = accumulate(M_RANGE(ls), 0);

    cout << (sum-max > max ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[2000];
signed main(){
  int n;
  scanf("%lld", &n);
  rep(i,n)scanf("%lld", &a[i]);
  int sum = 0;
  rep(i,n)sum += a[i];
  int idx = 0, d = inf;
  rep(i,n){
    chmin(d, llabs(sum-a[i]*n));
  }
  rep(i,n){
    if(llabs(sum-a[i]*n) == d){
      printf("%lld\n", i);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int V[50], C[50];
    for(int i=0;i<N;i++)
        cin >> V[i];
    for(int i=0;i<N;i++)
        cin >> C[i];
        
    int X = 0, Y = 0;
    for(int i=0;i<N;i++){
        if(V[i] > C[i]){
            X += V[i];
            Y += C[i];
        }
    }
    
    cout << X - Y << endl;

}

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

int main() {
	
	// your code here
	int a,b,c,prod=0,flag=0;
	cin>>a>>b;
	if(a<b){
		for(c=a;c<=b;c++){
		if((a*b*c)%2 != 0)
			flag++;
	}
	}
	else if(a>b){
		for(c=b;c<=a;c++){
		if((a*b*c)%2 != 0)
			flag++;
	}
	}
	else {
		if((a*b) %2 !=0)
			flag++;
	}
	if(flag>0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long L_L;
L_L GCD(L_L a,L_L b)
{
	L_L c;
	while((c=a%b)!=0)
	{
		a=b;
		b=c;
	}
	return b;
} 
L_L LCM(L_L a,L_L b)
{
	return a*b/GCD(a,b);
} 
int main()
{
	L_L a,b;
	scanf("%lld %lld",&a,&b);
	printf("%lld",LCM(a,b));
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<tuple>
#include<complex>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
#define EPS (long double) 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

using namespace std;

int main() {
	int n, w;
	cin>>n>>w;
	vector<P> itm(n);
	REP(i, n) cin>>itm[i].first>>itm[i].second;
	ll dp[n + 1][w + 1];
	REP(i, w + 1) dp[0][i] = 0;
	FOR(i, 1, n + 1) {
		REP(j, w + 1) {
			if(j >= itm[i - 1].second) dp[i][j] = max(dp[i - 1][j], dp[i][j - itm[i - 1].second] + itm[i - 1].first);
			else dp[i][j] = dp[i - 1][j];
		}
	}
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 10996
strs = input()
N = int(input())

Len = len(strs)

allstr = [] 
flag = 0

for i in range(Len):
    tmp = list(range(i+1))
    tmp.reverse()
    for j in tmp:
#        print(strs[Len-i-1:Len-j])
        allstr.append(strs[Len-i-1:Len-j])
        allstr2 = list(set(allstr))
        if len(allstr2) > 5:
            if allstr[5:6] > allstr[4:5] and flag == 1:
#                print(allstr[5:6], allstr[4:5])
                allstr = allstr[0:5]
                break
            allstr2.sort()
            allstr = allstr2[0:5]
            flag = 1
#            print(allstr2)
        

allstr2 = list(set(allstr))        
allstr2.sort()

print(allstr2[N-1])

Measured memory_bytes: 3448
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
  // input
    vector<vector<int>> c(4, vector<int>(4));
    for(int i = 1;i < 4 ; i++) {
        for(int j = 1; j < 4; j++){
            cin >> c[i][j];
        } 
    }

  // compute
    int sum; 
    sum = 0;
    set<int> st1;
    set<int> st2;
    set<int> st3;
    set<int> st4;
    bool p,q,r,s,t;
    

    for(int i = 1;i < 4; i++) {
        st1.insert(c[i][2] - c[i][1]);
        st2.insert(c[i][3] - c[i][2]);
    }
    for(int i = 1;i < 4; i++) {
        st3.insert(c[2][i] - c[1][i]);
        st4.insert(c[3][i] - c[2][i]);
    }

    for(int i = 1;i < 4 ; i++) {
        for(int j = 1; j < 4; j++){
            sum += c[i][j];
        } 
    }

    p = (st1.size() == 1);
    q = (st2.size() == 1);
    r = (st3.size() == 1);
    s = (st4.size() == 1);
    t = (sum % 3 == 0);

  // output  

    if(p && q && r && s && t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
typedef long long       ll;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define fore(i, b, e)      for(int i = b; i < e; i++)
#define forr(i, b, e)      for(int i = b; i < e; i++)
#define forg(i, b, e, m)  for(int i = b; i < e; i+=m)
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef pair<int, ii>  iii;
typedef vector<int>     vi;

typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double PI = acos(-1);
const double EPS = 1e-9;
#define tam 1234567
int dp[300][300];
int arr[300];
int n;
int f(int pos,int ant)
{
    if (pos==2*n)
    {
        return 0;
    }
    if (dp[pos][ant]!=-1)
    {
        return dp[pos][ant];
    }
    int tot=0;
    if (pos+1<=2*n)
    tot=f(pos+2,ant)+arr[pos]; 
    if (ant==0)
    tot=max(tot,f(pos+1,pos));
    else
    tot=max(tot,f(pos+1,0)+arr[ant]);
    return dp[pos][ant]=tot;
}
int main()
{
    memset(dp,-1,sizeof dp);
    
    cin>>n;
    forr(i,1,2*n+1)
    {
        cin>>arr[i];
    }    
    sort(arr+1,arr+2*n+1);
    
    cout<<f(1,0)<<endl;
}
// PLUS ULTRA!

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

using namespace std;



int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector <int> v(n, 0);
    for(int i = 0; i < n; ++i)
        cin >> v[i];
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    cout << v.size() << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>

using namespace std;

int main()
{
	long long int a, b, a0, b0;
	int da[60], db[60];
	scanf("%lld", &a);
	scanf("%lld", &b);
	if(a==b){
		printf("%d\n", 1);
		return 0;
	}
	a0=a, b0=b;
	long long int p[60];
	p[0]=1;
	for(int i=1; i<60; i++){
		p[i]=p[i-1]*2;
	}
	int i0=59;
	for(int i=59; i>=0; i--){
		da[i]=a0/p[i];
		a0=a0%p[i];
		db[i]=b0/p[i];
		b0=b0%p[i];
		
	}
  for(int i=59; i>=0; i--){
    if(da[i]==db[i]){
      i0--;
    }else{
      break;
    }
  }
	if(i0==0){
		printf("%d\n", 2);
		return 0;
	}
	for(int i=59; i>i0; i--){
		a-=((long long int)(da[i])*p[i]);
	}
	int i1=-1, i2=-1;
	for(int i=i0-1; i>=0; i--){
		if(da[i]==1){
			i1=i;
			break;
		}
	}
	for(int i=i0-1; i>=0; i--){
		if(db[i]==1){
			i2=i;
			break;
		}
	}
	
	long long int ans=0;
	ans+=(p[i0]-a);
	if(i1<=i2){
		ans+=p[i0];
	}else{
		ans+=(p[i0]-a);
		ans+=p[i2+1];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
S = input()
N = len(S)
k = 0
pc = ""
i = 0
while i<N:
    c = S[i]
    i += 1
    if c==pc:
        if i==N:
            break
        while c==pc:
            if i==N:
                break
            c += S[i]
            i += 1
        else:
            k += 1
            #print(c)
            pc = c
    else:
        k += 1
        #print(c)
        pc = c
print(k)


Measured memory_bytes: 3500
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;

LL n,x,W,v,w;
LL dp[105][100005] = {0};

int main(){
	memset(dp,0x3f,sizeof(dp));
	dp[0][0] = 0;
	scanf("%lld %lld",&n,&W);
	x = n * 1000;
	for(LL i = 1;i <= n;i ++){
		scanf("%lld %lld",&w,&v);
		for(LL j = 0;j <= x;j ++){
			dp[i][j] = dp[i - 1][j];
			if(j >= v) dp[i][j] = min(dp[i][j],dp[i - 1][j - v] + w);
		}
	}
	for(LL i = x;i >= 0;i --){
		if(dp[n][i] <= W){
			printf("%lld\n",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 82304
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f
let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

let list_of_string str =
  let len = String.length str in
  let rec f i = if i >= len then [] else str.[i] :: f (i+1) in
  f 0

let lim_width = 16002
let cp = lim_width / 2

let swt ax = match ax with 'X' -> 'Y' | 'Y' -> 'X'

let rec parse ax acc xs =
  match xs with
  | [] -> if acc = 0 then [] else [(acc, ax)]
  | (x::xs') ->
      if x = 'T' then
        if acc = 0 then parse (swt ax) 0 xs'
        else (acc, ax) :: parse (swt ax) 0 xs'
      else parse ax (acc+1) xs'

let () =
  let s0::_ as s = read_line () |> list_of_string in
  let [xp; yp] = read_ints 2 in
  let f_first = s0 = 'F' in
  let steps = parse 'X' 0 s in
  let xs' = steps |> List.filter (fun z -> snd z = 'X') |> List.map fst in
  let (x0, xs) = match xs' with
  | (z::zs) when f_first -> (z, zs)
  | _                    -> (0, xs') in
  let ys = steps |> List.filter (fun z -> snd z = 'Y') |> List.map fst in

  let dp = Array.make lim_width 0 in
  let bak = Array.make lim_width 0 in

  let result = List.for_all (fun (ss, src, dst) ->
    Array.fill dp 0 lim_width 0; dp.(src) <- 1;
    List.iter (fun s ->
      Array.fill bak 0 lim_width 0;
      for_iter_ 0 lim_width (fun i ->
        if dp.(i) = 1 then (
          if i-s >= 0        then bak.(i-s) <- 1;
          if i+s < lim_width then bak.(i+s) <- 1
        ));
      for_iter_ 0 lim_width (fun i -> dp.(i) <- bak.(i));
    ) ss;
    dp.(dst) = 1) [(xs, cp+x0, cp+xp); (ys, cp, cp+yp)] in

  print_endline @@ if result then "Yes" else "No"


Measured memory_bytes: 3456
N,Y = map(int,input().split())

ok = False
ans = (-1,-1,-1)
for i in range(N+1):
  for j in range(N-i+1):
    k = N - i - j
    t = 10000 * i + 5000 * j + 1000 * k
    if Y == t:
      ok = True
      ans = (i,j,k)
      break
  if ok:
    break

print(ans[0],ans[1],ans[2])

      

Measured memory_bytes: 3064
use proconio::input;

fn divisors(n: usize) -> Vec<usize> {
    let mut d = vec![];
    for i in 1.. {
        if i * i > n {
            break;
        }
        if n % i == 0 {
            d.push(i);
            if i != n / i {
                d.push(n / i);
            }
        }
    }
    d.sort();
    d
}

fn main() {
    input! {
        n: usize,
    };
    let mut ans = 0;
    for &d_i in divisors(n).iter() {
        if d_i == 1 {
            continue;
        }
        if n % (d_i - 1) == n / (d_i - 1) {
            ans += d_i - 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=2000000001;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int n,m,a[100][100];
int ans=0;

bool check(int x,int y) {
  if(x<0 || x>=n) return false;
  if(y<0 || y>=m) return false;
  return true;
}

void dfs(int nx,int ny,int cnt) {
  ans=max(ans,cnt);
  for(int i=0; i<4; i++) {
    int x=nx+dx[i],y=ny+dy[i];
    if(check(x,y) && a[x][y]) {
      a[x][y]=0;
      dfs(x,y,cnt+1);
      a[x][y]=1;
    }
  }
}

int main() {
  while(cin >> m >> n && (n||m)) {
    rep(i,n) {
      rep(j,m) cin >> a[i][j];
    }
    ans=0;
    rep(i,n) {
      rep(j,m) {
	if(a[i][j]) {
	  a[i][j]=0;
	  dfs(i,j,1);
	  a[i][j]=1;
	}
      }
    }
    pr(ans);
  }
  return 0;
}


Measured memory_bytes: 1196
h, w = list(map(int, input().split()))
# b = list(map(int, input().split()))
if h == 1 and w == 1:
    print(1)
elif h == 1:
    print(w-2)
elif w == 1:
    print(h-2)
else:
    print(h*w-h*2-(w-2)*2)


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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string str;
stack<char> s;
char c;
int main(){
	while(getline(cin,str)){
		while(!s.empty()){
			s.pop();
		}
		bool flag =true;
		if(str.length()==1&&str[0]=='.')
			break;
		for(int i = 0;i <str.length();i++){
			if(str[i]=='('){
				s.push('(');
			}else if(str[i]=='['){
				s.push('[');
			}else if(str[i]==')'){
				if(s.empty()){
					flag =false;
					break;
				}
				c = s.top();
				if(c!='('){
					flag = false;
					break;
				}
				s.pop();
			}else if(str[i]==']'){
				if(s.empty()){
					flag =false;
					break;
				}
				c =s.top();
				if(c!='['){
					flag =false;
					break;
				}
				s.pop();
			}
		}
		if(flag&&s.empty())
			cout <<"yes"<<endl;
		else
			cout <<"no"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	string s;
	while(cin>>N) {
		map<string, int> h;
		string ans = "Yes";
		string prev;
		REP(i, N) {
			cin>>s;
			if(h.count(s)) ans="No";
			h[s]++;
			if(prev.size() && prev[prev.size()-1]!=s[0]) ans="No";
			prev=s;
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define M 100005
const int P=1e9+7;
char S[M];
int cnt[30];
int main(){
	int n;
	scanf("%d%s",&n,S+1);
	for(int i=1;i<=n;i++)
		cnt[S[i]-'a']++;
	int ans=1;
	for(int i=0;i<26;i++)
		ans=1LL*ans*(cnt[i]+1)%P;
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;ll x;cin>>n>>x;
    vll a(n);rep(i,n)cin>>a[i];
    ll ans=(ll)0;
    rep(i,n-1){
        if(a[i]>x){
            ans+=a[i]-x;
            a[i]=x;
        }
        if(a[i]+a[i+1]>x){
            ans+=a[i+1]-x+a[i];
            a[i+1]=x-a[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m, n;
const int maxn = 1005;
int a[maxn];
int main(){
	cin >> n >> m;
	double q = (double)1 / (4 * m);
	ll tot = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		tot += a[i];
	}
	double res = tot * q;
	int ok = 0;
	ll tmp = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] >= res){
			tmp++;
			continue;

		}
		else{
			ok = 1;
		}
	}
	if(tmp >= m)
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    set<char> tmp;
    tmp.insert(a[i]);
    tmp.insert(b[i]);
    tmp.insert(c[i]);
    if(tmp.size() == 1) continue;
    if(tmp.size() == 2) {
      ans += 1;
      continue;
    }
    if(tmp.size() == 3) { ans += 2; }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
require 'pp'
n = gets.to_i
a = gets.split.map(&:to_i)

if a.count(1) == 0
  p -1
  exit
end

ind = 1
cnt = 0
n.times do |i|
  if a[i] == ind
    ind += 1
  else
    cnt += 1
  end
end
p cnt



Measured memory_bytes: 14940
#![allow(unused_mut, non_snake_case, unused_macros,unused_imports)]
use std::cmp::{max, min, Ordering};
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
fn main(){
    input!{N:usize,W: [chars; N]}
    let N:usize = N;
    let W:Vec<Vec<char>> = W;
    let mut set:HashSet<String> = HashSet::new();
    for i in 1..N{
        if W[i-1][W[i-1].len()-1] != W[i][0]{
            println!("No");
            return;
        }
    }
    for i in 0..N{
        set.insert(W[i].iter().map(|&s| s as char).collect::<String>());
    }
    if set.len() != N{
        println!("No");
    }else{
        println!("Yes");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
long long a[100010];
int main() {
  int i,n,flg;
  long long ans;
  
  cin >> n;
  flg=0;
  for (i=0;i<n;++i)
  {
    cin >> a[i];
    if (a[i]==0)
      ++flg;
  }
  
  ans=0;
  if (flg ==0)
  {
	  ans=a[0];
  	for (i=1;i<n;++i)
	{
      if (a[i] > 1000000000000000000 / ans)
      {
        	ans = -1;
        	break;
      }
      else
      {
	      ans *= a[i];
      }
  	}
  }
  cout << ans << endl;
}

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

const ll INF = 1LL << 60;
const int MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

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

    ll a, b, c;
    multimap<ll, ll, greater<ll> > Map;
    priority_queue< ll, vector<ll>, greater<ll> > Q;
    REP(i, N) {
        cin >> a;
        Q.push(a);
    }
    REP(i, M) {
        cin >> b; cin >> c;
        Map.emplace(c, b);
    }

    for (auto e: Map) {
        if (Q.top() >= e.first) break;
        REP(i, e.second) {
            if (Q.top() >= e.first) break;
            Q.pop();
            Q.push(e.first);
        }
    }

    ll sum = 0;
    while (!Q.empty()) {
        sum += Q.top(); Q.pop();
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 7284
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//おまじない



int main() {

	ll a, b, c, d;

	cin >> a >> b >> c >> d;

	cout << max(a*b, c*d) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int R, G, B, N;
    int ans = 0;
    scanf("%d%d%d%d", &R, &G, &B, &N);
    int r, g;
    
    for (r = 0;; r++){
        if(r * R > N){
            break;
        }
        for (g = 0;; g++){
            if((r * R + g * G)> N){
                break;
            }
            if((N - R * r - G * g) % B == 0){
                //printf("%d %d %d\n", r, b, g);
                ans += 1;
            }
        }
    }
    printf("%d\n", ans);
    return 0; 
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

int main()
{
	int N, M;
	int ans = 0;
	string s;
	map<string, int> mp;

	
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> s;

		if (mp.find(s) != mp.end())
		{
			mp[s]++;
		}
		else
		{
			mp[s] = 1;
		}
	}

	cin >> M;
	for (int i = 0; i < M; i++)
	{
		cin >> s;

		if (mp.find(s) != mp.end())
		{
			mp[s]--;
		}
		else
		{
			mp[s] = -1;
		}
	}

	for (auto it : mp)
	{
		if (it.second > ans)
		{
			ans = it.second;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
str = {}  # 辞書
ans = 0
for i in range(N):
	word = []
	tmp = input()
	for j in range(10):
		word.append(tmp[j])
	word.sort()  # s_iがソートされる
	word_add = ""
	for j in range(10):
		word_add += word[j]
		# word_addにs_iがソートされたものが入る
	
	# "aaabc"があればstr["aaabc"]を1増やし、
	# なければ新しく作って初期値1を入れる 
	if word_add in str:
		str[word_add] += 1
	else:
		str[word_add] = 1

for i in str.values():
	ans += i * (i-1) // 2

print(ans)

Measured memory_bytes: 17892
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    int ans = 100;
    FOR(i, 1, (int)1e5){
        if(n % i == 0){
            ll b = n / i;
            ans = min(ans, (int)max(log10(i), log10(b)) + 1);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int a = 0;
    int b = 0;
    int c = 0;
    for(int i = 0;i < 3;i++) {
        if(s[i]=='a') {
            a++;
        } else if(s[i] == 'b') {
            b++;
        } else {
            c++;
        }
    }

    if(a!=1 || b != 1 || c != 1) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int N, M;
    cin >> N >> M;
    Graph G(N);
    rep(i, M){
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    vector<int> connect(N, -1);

    for(int c = 0; c < N; c++){
        if(connect[c] != -1) continue;

        queue<int> que;
        connect[c] = c;
        que.push(c);

        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(int i = 0; i < G[v].size(); i++){
                int v2 = G[v][i];
                if(connect[v2] != -1) continue;
                connect[v2] = c;
                que.push(v2);
            }
        }
    }

    int q;
    cin >> q;
    rep(i, q){
        int s, t;
        cin >> s >> t;
        if(connect[s] == connect[t]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 8588
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n = 3;
    vi a(n); for(auto& e : a) cin >> e;
    sort(_all(a));

    cout << a[2] - a[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, k;
    cin >> n >> k;

    set<ll> st;
    vl a(n);
    rep(i, n) {
        cin >> a[i];
        st.insert(a[i]);
    }
    sort(all(a));

    vl count(n);  // count[i] : aのi番目(iは0-index)に小さい数の個数
    ll t = a[0];
    ll k1 = 0;
    rep(i, n) {
        if(t < a[i]) {
            t = a[i];
            k1++;
        }
        count[k1]++;
    }
    sort(all(count));

    if(st.size() <= k) {
        out(0);
    }
    else {
        ll cnt = 0;
        ll ans = 0;
        rep(i, n) {
            if(count[i] == 0) {
                continue;
            }
            ans += count[i];
            cnt++;
            if(cnt >= st.size() - k) {
                break;
            }
        }
        out(ans);
    }

    re0;
}

Measured memory_bytes: 12800
#include <cstdio>
#include <cstring>

int main(){
int x = 0, mx = 0, len; char str[105];
scanf("%d", &len); scanf("%s", str);
for(int i=0; i<len; i++){
if(str[i]=='I') x++; else x--;
if(x>mx) mx = x;
}
printf("%d\n", mx);
return 0;
}

Measured memory_bytes: 128
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()

    E = list(map(lambda x:abs(x-K),A))
    E = set(E)
    C = [A[i+1]-A[i] for i in range(N-1)]
    C = set(C)
    D = set(A)
    if E&D:
        print("POSSIBLE")
        exit()

    print("IMPOSSIBLE")
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 79000
#include <iostream>
#include <iomanip>

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

using namespace std;

struct cell
{
	int xl, xr, h;
	int val;
	cell *l, *r;

	cell(int xl, int xr, int h)
		: xl(xl), xr(xr), h(h), l(NULL), r(NULL)
	{
	}

	~cell()
	{
		delete l;
		delete r;
	}

	bool is_leaf() { return l == NULL && r == NULL; }
	int width() { return xr - xl; }
	int bottom_area() { return width() * 30; }

	int capacity() { return bottom_area() * h; }
	int sub_capacity() { return is_leaf() ? 0 : l->capacity() + r->capacity(); }
	int max_margin() { return capacity() - sub_capacity(); }
	int margin() { return max_margin() - val; }
	bool is_full() { return val == max_margin(); }

	int sub_value() { return is_leaf() ? 0 : l->value() + r->value(); }
	int value() { return val + sub_value(); }

	void part(int x, int h)
	{
		if (is_leaf())
		{
			l = new cell(xl, x, h);
			r = new cell(x, xr, h);
		}
		else if (x < l->xr)
		{
			l->part(x, h);
		}
		else if (r->xl < x)
		{
			r->part(x, h);
		}
	}

	void clear()
	{
		val = 0;
		if (!is_leaf())
		{
			l->clear();
			r->clear();
		}
	}

	int water(int x, int v)
	{
		if (!is_leaf())
		{
			if (x < l->xr)
			{
				v = l->water(x, v);
				if (v != 0) v = r->water(r->xl, v);
			}
			else if (r->xl < x)
			{
				v = r->water(x, v);
				if (v != 0) v = l->water(l->xr, v);
			}
		}

		int inc = min(v, margin());
		val += inc;
		return v - inc;
	}

	double water_height(int x)
	{
		if (is_leaf() || val > 0)
		{
			return (double)value() / bottom_area();
		}
		else if (x < l->xr)
		{
			return l->water_height(x);
		}
		else if (r->xl < x)
		{
			return r->water_height(x);
		}
		return -1;
	}
};

int main()
{
	int D;
	cin>>D;
	while(D--)
	{
		int N,M,L,div[51] = { 0 },flow[10][2];
		cin>>N;
		rep(i,N)
		{
			int x, h;
			cin>>x>>h;
			div[h] = x;
		}

		cell root(0, 100, 50);
		for (int h = 50; h > 0; --h)
		{
			if (div[h] > 0) root.part(div[h], h);
		}

		cin>>M;
		rep(i,M) cin>>flow[i][0]>>flow[i][1];

		cin>>L;
		rep(i,L)
		{
			int x, t;
			cin>>x>>t;
			root.clear();
			rep(j,M)
			{
				root.water(flow[j][0], t * flow[j][1]);
			}
			cout << fixed << setprecision(5) << root.water_height(x) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
	int a,i;
	int j = 0;
	vector<int> s,t;
	for (i = 0; i < 6; i++) {
		cin >> a;
		s.push_back(a);
	}
	string d;
	cin >> d;
	int n = d.size();
	for (j = 0; j < n; j++) {
		if (d[j] == 'S') {
			t = { s[4],s[0],s[2],s[3],s[5],s[1] };
			s = t;
		}
		else if (d[j] == 'N') {
			t = { s[1],s[5],s[2],s[3],s[0],s[4] };
			s = t;
		}
		else if (d[j] == 'W') {
			t = { s[2],s[1],s[5],s[0],s[4],s[3] };
			s = t;
		}
		else if(d[j] == 'E') {
			t = { s[3],s[1],s[0],s[5],s[4],s[2] };
			s = t;
		}
	}
	cout << s[0] << endl;
	return 0;
}


Measured memory_bytes: 3176
#include<stdio.h>
int main()
{
    int a,b,c;
    // 初期整数の入力
    scanf("%d%d%d", &a,&b,&c);

    if((a<c&&b>c)||(a>c&&b<c)){
    printf("Yes");
    }
  	else printf("No");
  
  return 0;
}


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

int main() {
  int a[3];
  rep(i, 3) cin >> a[i];
  sort(a, a + 3);
  if (a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3484
Main = input => {
  input = input.split("\n");
  const tmp = input[0].split(" ");
  const n = Number(tmp[0]);
  const k = Number(tmp[1]);
  const q = Number(tmp[2]);
  var sums = new Array(n).fill(0);
  for (var i = 1; i <= q; i++) {
    sums[input[i]-1]++;
  }
  sums.forEach(sum => console.log(q-sum < k ? "Yes" : "No"));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 31236
N, L = map(int,input().split())
l, r = L, L + N - 1
total = (L - 1) * N + N * (N + 1) // 2
if l <= 0 and r >= 0:
    print(total)
if l > 0:
    total -= l
    print(total)
if r < 0:
    total -= r
    print(total)

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

int main()
{

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


    int a[4];
    for (int i = 0; i < 4; ++i)
        scanf("%d", a + i);

    sort(a, a + 4);

    if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
        printf("YES");
    else
        printf("NO");
}


Measured memory_bytes: 256
import math
n = int(input())
a = list(map(int, input().split()))
#

sosu = [1 for _ in range(10**6+1)]
sosu[0] = 0
sosu[1] = 1
i = 2
while i < len(sosu):
    j = i*2
    if sosu[i] == 0:
        i += 1
        continue
    while j < len(sosu):
        sosu[j] = 0
        j += i
    i += 1

sosus = []
for i in range(2, len(sosu)):
    if sosu[i]:
        sosus.append(i)

sosuset = set()
flag = 0
GCD = a[0]
for i in range(n-1, -1, -1):
    J = 0
    j = sosus[J]
    GCD = math.gcd(GCD, a[i])

    while j*j <= a[i]:
        if a[i]%j == 0 and j in sosuset:
            flag = 1
            break
        while a[i]%j == 0:
            a[i]//=j
            sosuset.add(j)
        J += 1
        j = sosus[J]
    if a[i] in sosuset:
        flag = 1
    if a[i] != 1:
        sosuset.add(a[i])


if GCD == 1 and flag == 0:
    print("pairwise coprime")
elif GCD == 1 and flag == 1:
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 239276
using System;
public class Class1
{
	public static void Main()
	{
		string dataSet =Console.ReadLine();
		string[] data=dataSet.Split();
		int n=int.Parse(data[0]);//row
		int m=int.Parse(data[1]);//column		
		int[] columnSum=new int[m];
		int sum=0;
		
		for (int i =0; i < n; i++)
		{
			string matrixSet =Console.ReadLine();
			string[] matrix=matrixSet.Split();
			int rowSum=0;
			for(int j =0;j<m;j++)
			{
				
				rowSum+=int.Parse(matrix[j]);
				columnSum[j]+=int.Parse(matrix[j]);
			}	
			Console.WriteLine(matrixSet+" "+rowSum);
			sum+=rowSum;			
		}
	
		for(int k=0;k<m;k++)
		{				
				Console.Write(columnSum[k]+" ");				
		}
		Console.Write(sum+"\r\n");		
	}		
}

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

int main(void) {

    int64_t N;
    int64_t side;
    int cnt = 0;
    int64_t sum = 1;

    map<int64_t,int64_t> sides;
    cin >> N;
    
    for(int i=0;i<N;i++) {
        cin >> side;        
        sides[side]++;
    }

//    for(auto &it:sides) {
//        it.second /= 2;
//    }

    for(map<int64_t,int64_t>::reverse_iterator it = sides.rbegin();it != sides.rend();++it) {
        while((it->second-=2) >= 0) {
            if(cnt++ < 2) {
                sum *= it->first;
                if(cnt == 2) break;
            } else {
                break;
            }
        }
        if(cnt == 2)break;
    }

    if(cnt == 2) {
        cout << sum << "\n";
    } else {
        cout << "0\n";
    }
    
    return 0;
}


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



int main() {
    ios::sync_with_stdio(false);
    int n, k, ans = 0;
    int a[100];

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n);

    cout << a[n-1] - a[0];

    return 0;
}


Measured memory_bytes: 256