akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

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

    ll cnt = 0;

    ll a = min(N, M / 2);

    N -= a;
    M -= 2 * a;
    cnt += a;

    cnt += M / 4;

    cout << cnt << endl;
}

Measured memory_bytes: 3632
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int k = ni();
    int[] h = na(n);
    Arrays.sort(h);
    
    long ret = Long.MAX_VALUE;
    for (int i = 0; i < n - k + 1; i ++) {
      ret = Math.min(ret, Math.abs(h[i] - h[i + k - 1]));
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

LL cnt[8];
LL tot1 = 0,tot2 = 0;

int main(){
	for(LL i = 1;i <= 7;i ++) cin >> cnt[i];
	tot2 += (cnt[2] << 1) + ((cnt[1] >> 1) << 2) + ((cnt[4] >> 1) << 2) + ((cnt[5] >> 1) << 2);
	if(cnt[1] && cnt[4] && cnt[5]){
		cnt[1] --; cnt[4] --; cnt[5] --;
		tot1 = 6;
		tot1 += (cnt[2] << 1) + ((cnt[1] >> 1) << 2) + ((cnt[4] >> 1) << 2) + ((cnt[5] >> 1) << 2);
	}
	cout << (max(tot1,tot2) >> 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h> 
int main (void) {
int W,H,x,y,r ;
 
scanf("%d %d",&W,&H) ;  

 scanf("%d %d",&x,&y) ;  

 scanf("%d",&r) ;
if(W>=x+r && H>=y+r && x>0&&y>0 ){
printf("Yes\n");
}
else{ printf("No\n") ;
}
return 0; }

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

int main ()
{
	int s;
	int w;

	cin >> s >> w;
	if (w >= s)
		cout << "unsafe";
	else
		cout << "safe";
	return 0;
}

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

pair<unordered_map<long long, int>, vector<long long>> compress(const vector<long long> &src){
    vector<long long> unzip = src;
    sort(begin(unzip), end(unzip));
    unzip.erase(unique(begin(unzip), end(unzip)), end(unzip));
    unordered_map<long long, int> zip;
    for (int i = 0; i < unzip.size(); ++i) zip[unzip[i]] = i;
    return make_pair(zip, unzip);
}
struct Rectangle{
    long long x1;
    long long y1;
    long long x2;
    long long y2;
    Rectangle(long long _x1 = 0, long long _y1 = 0, long long _x2 = 0, long long _y2 = 0): x1(_x1), y1(_y1), x2(_x2), y2(_y2){}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<Rectangle> rects(N);
    vector<long long> xs;
    vector<long long> ys;
    xs.reserve(2 * N);
    ys.reserve(2 * N);
    for (auto & rec : rects) {
        cin >> rec.x1 >> rec.y1 >> rec.x2 >> rec.y2;
        xs.push_back(rec.x1);
        xs.push_back(rec.x2);
        ys.push_back(rec.y1);
        ys.push_back(rec.y2);
    }
    unordered_map<long long, int> zipx, zipy;
    vector<long long> unzipx, unzipy;
    tie(zipx, unzipx) = compress(xs);
    tie(zipy, unzipy) = compress(ys);
    int nx = unzipx.size();
    int ny = unzipy.size();
    vector<vector<int>> imos(nx, vector<int>(ny, 0));
    for (auto & rec : rects){
        int x1 = zipx[rec.x1];
        int x2 = zipx[rec.x2];
        int y1 = zipy[rec.y1];
        int y2 = zipy[rec.y2];
        ++imos[x1][y1];
        --imos[x1][y2];
        --imos[x2][y1];
        ++imos[x2][y2];
    }
    for (int i = 0; i < nx; ++i) for (int j = 0; j < ny - 1; ++j) imos[i][j + 1] += imos[i][j];
    for (int j = 0; j < ny; ++j) for (int i = 0; i < nx - 1; ++i) imos[i + 1][j] += imos[i][j];
    long long ans = 0;
    for (int i = 0; i < nx - 1; ++i) for (int j = 0; j < ny - 1; ++j) if (imos[i][j]) ans += (unzipx[i + 1] - unzipx[i]) * (unzipy[j + 1] - unzipy[j]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 66228
n,k=map(int,input().split())
h=[]
ma=10**9
for i in range(n):
  a=int(input())
  h.append(a)
h.sort()

for i in range(n-k+1):
  sa=h[k-1+i]-h[i]
  if sa<ma:
    ma=sa
    
print(ma)

Measured memory_bytes: 13392
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQUE(c)   sort(ALL((c)));(c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

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

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
Money = 1000
Stock = 0
for i in range(N-1):
    if A[i] > A[i+1]:
        Money += A[i]*Stock
        Stock = 0
    else:
        Stock += Money // A[i]
        Money %= A[i]
print(Stock*A[N-1]+Money)

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

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

    string s; cin >> s;
    REP(i, (int)s.length())
    {
        if(i % 2 == 0) cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

long long count_val( long long x , long long cur ){
  if(cur > x) return 0;
  //cout << cur << endl;
  int p;
  if(cur==0) p=0;
  else p=(int)log10(cur)+1;
  int check[3]={0,0,0};
  long long tmp_cur=cur;
  for(int i=0;i<p;i++){
    if(tmp_cur % 10 == 3) check[0]++;
    else if(tmp_cur % 10 == 5) check[1]++;
    else if(tmp_cur % 10 == 7) check[2]++;
    tmp_cur = tmp_cur/10;
  }
  int t=0;
  if(check[0]*check[1]*check[2]) t=1;
  //cout << p << endl;
  return t+count_val(x,cur+(long long)3*(long long)pow(10,p))+count_val(x,cur+(long long)5*(long long)pow(10,p))+count_val(x,cur+(long long)7*(long long)pow(10,p));

}



int main(void){

  int N;
  cin >> N;

  int cnt=0;

  if(N < 357){
    cout << 0 << endl;
    return 0;
  }
  else{

    cout << count_val(N,0) << endl;

  }

  return 0;
}


Measured memory_bytes: 512
//駐車場があり、以下の二種類のプランのどちらかを
//選んで駐車できます。
//プラン 1: T時間駐車した場合、A×T円が駐車料金となる。
//プラン 2: 駐車した時間に関わらず B円が駐車料金となる。
//N時間駐車するとき、駐車料金は最小でいくらになるか
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,A,B;
  	cin>>N>>A>>B;
  if((N*A)>=B){
  	cout<<B<<endl;}
  if((N*A)<B){
  	cout<<N*A<<endl;}
}

Measured memory_bytes: 256
import itertools
# 学びたい数: M
# 理解度初期値: 0
# 参考書数: N
# ゴール: 全理解度をX以上。最小購入金額

N, M, X = map(int, input().split())

# 参考書の定義
sankousyo = []
rikaido = [0]*M

for i in range(N):
    sankousyo.append(list(map(int, input().split())))

# 購入する参考書の価格
minBag = 10**9

# bit全探索
n = len(sankousyo)
for i in range(2 ** n):
    bag = []
    rikaido = [0]*M
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(sankousyo[j][0])  # フラグが立っていたら bag に参考書を詰める
            # 全て理解度を超えているかチェック
            flg = True
            for m in range(M):
                rikaido[m] += sankousyo[j][m+1]
                if rikaido[m] < X:
                    flg = False
            if flg == True and minBag > sum(bag):
                minBag = sum(bag)
    #print(bag, rikaido)

if minBag == 10**9:
    print(-1)
else:
    print(minBag)



Measured memory_bytes: 68684
m1, d1 = map(int, input().strip().split(' '))
m2, d2 = map(int, input().strip().split(' '))
 
if m1 in (1, 3, 5, 7, 8, 10, 12) and d1 == 31:
    print('1')
elif m1 == 2 and d1 == 28:
    print('1')
elif m1 in (4,6,9,11) and d1 == 30:
    print('1')
else:
    print('0')

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

//#include <atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> wsum(n + 1, 0), bsum(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == '.') {
      wsum[i] = wsum[i - 1] + 1;
      bsum[i] = bsum[i - 1];
    } else {
      wsum[i] = wsum[i - 1];
      bsum[i] = bsum[i - 1] + 1;
    }
    //  cout << wsum[i] << ' ' << bsum[i] << endl;
  }

  int ans = (1U << 31) - 1;
  for (int i = 0; i <= n; i++) {
    int change = 0;
    // 0~i番目を白にする。(0番目は無し)
    change += bsum[i] - bsum[0];
    // i+1~n 番目を黒にする。
    change += wsum[n] - wsum[i];
    ans = min(ans, change);
  }

  cout << ans << endl;
}

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

int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u) a--;
    if (t == u) b--;
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
n, q = gets.split.map(&:to_i)
Job = Struct.new 'Job', :name, :time
jobs = n.times.map do
  name, time = gets.chomp.split
  Job.new(name, time.to_i)
end
t = 0
while jobs.size > 0
  j = jobs.shift
  if j.time > q
    t += q
    jobs << Job.new(j.name, j.time - q)
  else
    t += j.time
    puts "#{j.name} #{t}"
  end
end



Measured memory_bytes: 11556
n = int(input())
s = input()
left = 0
right = s[1:].count('E')
cnt = [left + right]

for i in range(1, n):
    if s[i-1] == 'W':
        left += 1
    if s[i] == 'E':
        right -= 1
    cnt.append(left + right)

print(min(cnt))

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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    for(int i =0; i< s.size() -1; ++i){
        if(s[i] == ',')
            s[i]= ' ';
    }
    cout << s <<endl;
}

Measured memory_bytes: 256
A,B,C,X,Y = map(int,input().split())

ans = 0
if A + B < C * 2:
    ans =  A * X + B* Y
else:
    ans = min(X,Y) * C * 2 
    x = min(X,Y)
    X -= x
    Y -= x
    
    ans += min(X * A + Y * B,X * C * 2+ Y * C * 2)

print(ans)

Measured memory_bytes: 38420
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans[n];
    rep(i, n) {
        ans[i] = 0;
    }
    
    int cntr = 0;
    rep(i, n) {
        if(s[i] == 'R') {
            cntr++;
        }
        else {
            ans[i] += cntr/2;
            ans[i-1] += (cntr+1)/2;
            cntr = 0;
        }
    }

    int cntl = 0;
    for(int i = n-1; i >= 0; i--) {
        if(s[i] == 'L') {
            cntl++;
        }
        else {
            ans[i] += cntl/2;
            ans[i+1] += (cntl+1)/2;
            cntl = 0;
        }
    }

    rep(i, n-1) {
        cout << ans[i] << " ";
    }
    cout << ans[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.length();
    int m=t.length();

    int **dp=new int*[n+1];
    for(int i=0;i<=n;i++){
      dp[i]=new int[m+1];
      for(int j=0;j<=m;j++){
        dp[i][j]=0;
      }
    }

    for(int i=0;i<=n;i++){
      dp[i][0]=0;
    }

    for(int i=0;i<=m;i++){
      dp[0][i]=0;
    }
    for(int i=1;i<=n;i++){
      for(int j=1;j<=m;j++){
        if(s[i-1]==t[j-1]){
          dp[i][j]=dp[i-1][j-1]+1;
        }
        else{
          dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
        }
      }
    }
    string ans="";



    // for(int i=0;i<=n;i++){
    //   for(int j=0;j<=m;j++){
    //     cout<<dp[i][j]<<" ";
    //   }
    //   cout<<endl;
    // }
int i = n, j = m;
   while (i > 0 && j > 0)
   {
      // If current character in X[] and Y are same, then
      // current character is part of LCS
      if (dp[i][j]>dp[i-1][j] && dp[i][j]>dp[i][j-1] && dp[i][j]==(dp[i-1][j-1]+1))
      {
          ans = s[i-1]+ans; // Put current character in result
          i--; j--; ;     // reduce values of i, j and index
      }

      // If not same, then find the larger of two and
      // go in the direction of larger value
      else if (dp[i-1][j] > dp[i][j-1])
         i--;
      else
         j--;
   }
















    // for(int i=n;i>=1;){
    //   for(int j=m;j>=1;){
    //     if(dp[i][j]>dp[i-1][j] && dp[i][j]>dp[i][j-1] && dp[i][j]==(dp[i-1][j-1]+1)){
    //       ans=s[i-1]+ans;
    //       i=i-1;
    //       j=j-1;
    //     }
    //     else if(dp[i][j]==dp[i-1][j]){
    //       i=i-1;
    //       j=j;
    //     }
    //     else{
    //       i=i;
    //       j=j-1;

    //     }
    //     if(i<=0 || j<=0){
    //       break;
    //     }
    //   }
    //   if(i<=0){
    //       break;
    //     }
    // }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 35456
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int q;
ll a,b;
int main(){
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%lld%lld",&a,&b);
        if (a > b)swap(a,b);
        ll s = floor(sqrt(a*b));
        if (s == a)s++;
        ll t = (a*b-1)/s;
        if (t == b)t--;

        printf("%lld\n", s + t - 2);
    }
}


Measured memory_bytes: 128
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 b=1<<r
 f=[1]*b
 for m in range(b):
  if f[m]:
   f[~m]=0
   t=0
   for s in d:
    c=bin(m^s).count('1')
    t+=c if c>r//2 else r-c
   if a<t:a=t
 print(a)


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

#include <iostream>
#include <cmath>
using namespace std;

int n,q;
int A[50];

int check(int i, int m){
  if(m==0) return 1;
  if(i>= n)return 0;
  int res = check(i+1,m) || check(i+1,m-A[i]);
  return res;
}
int main(){
  int m;
  cin >> n;
  for(int i=0;i<n;i++) cin >> A[i];
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> m;
    if(check(0,m))
      cout << "yes" <<"\n";
    else
      cout<< "no" << "\n";
  }
}

Measured memory_bytes: 3100
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define printx(x) printf("%lld\n",x);
#define printxy(x,y) cout << x << y <<endl;
#define printxyz(x,y,z) cout << x << y << z <<endl;
#define deba(a) cout << #a << a << endl;
#define debab(a,b) cout << #a << a << #b << b << endl;
ll dp[1000001];
ll solve(ll i, ll a[], ll n, ll k)
{
	if (i == n - 1)
		return 0;
	if (dp[i] != -1)
		return dp[i];
	vi y;
	// x = abs(a[i] - a[i + 1]) + solve(i + 1, a, n, k);
	// if (i + 2 < n)
	// 	y = abs(a[i] - a[i + 2]) + solve(i + 2, a, n, k);
	for (int j = 1; j <= k; j++)
	{
		if (i + j < n)
		{
			ll x = abs(a[i] - a[i + j]) + solve(i + j, a, n, k);
			y.pb(x);
		}
	}
	// ll n = y.size();
	return dp[i] = *min_element(all(y));
}
int main()
{
	fast;
	ll n, k;
	cin >> n >> k;
	ll a[n];
	rep(i, 0, n)
	cin >> a[i];
	mems(dp, -1);
	cout << solve(0, a, n, k);
	return 0;
}

Measured memory_bytes: 26268
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 1e18
    
const int N=2e5+5;
// const int M=1e9+7;
int modularExponentiation(int x,int n,int M)
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
int dp[N];
int go(int x)
{
	if(x==0)
	return 0;
	int &ans=dp[x];
	if(ans!=-1) return ans;
	ans=0;
	int pp=bp(x);
	if(pp!=0)
	ans=1+go(x%pp);
	return ans;
}
void solve()
{
	memset(dp,-1,sizeof(dp));
	int n;
	cin>>n;
	string s;
	cin>>s;
	s='a'+s;
	int dp1[n+1]={0},dp2[n+1]={0},dp3[n+1]={0};//x,x-1,x+1;
	int curr=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='1')
		curr++;
	}
	for(int i=n;i>=1;i--)
	{
		
		if(curr>1)
		dp2[i]=modularExponentiation(2,n-i,curr-1);
		dp3[i]=modularExponentiation(2,n-i,curr+1);
		// cout<<dp3[i]<<endl;
	}
	int pp1[n+1]={0},pp2[n+1]={0},pp3[n+1]={0};
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='1')
		{
			if(curr>1)
			{
				pp2[i]=pp2[i-1]+dp2[i];
				pp2[i]%=(curr-1);
			}
			pp3[i]=pp3[i-1]+dp3[i];
			pp3[i]%=(curr+1);
		}
		else
		{
			if(curr>1)
			{
				pp2[i]=pp2[i-1];
				pp2[i]%=(curr-1);
			}
			pp3[i]=pp3[i-1];
			pp3[i]%=(curr+1);
		}
	}
	for(int i=1;i<N;i++)
	{
		go(i);
	}
	// cout<<curr<<endl;
	for(int i=1;i<=n;i++)
	{
		int pp;
		if(s[i]=='0')
		{
			 pp=(pp3[n]+dp3[i])%(curr+1);
			 //cout<<pp<<endl;
			pp=go(pp);
			pp++;
			
		}
		else
		{
			if(curr==2)
			{
				pp=1;
			}
			else if(curr==1)
			{
				pp=0;
			}
			else{
			 pp=(pp2[n]-dp2[i]+curr-1)%(curr-1);
			pp=go(pp);
			pp++;
			}
		}
		cout<<pp<<endl;
	}
}

signed main()
{
	int t=1;
	// cin>>t;
	for(int tc=1;tc<=t;tc++)
	{
		solve();
	}
}

Measured memory_bytes: 14660
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;
int xs[10],ys[10];
int H,W,N;
string S[1002];
int main()
{
	scanf("%d%d%d",&H,&W,&N);
	for(int i=0;i<W+2;i++){
		S[0]+='X';
		S[H+1]+='X';
	}
	for(int i=1;i<=H;i++){
		string x;
		cin >> x;
		S[i]+='X'+x+'X';
	}
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			if(S[i][j]!='X'&&S[i][j]!='.'){
				if(S[i][j]=='S'){
					xs[0]=j;
					ys[0]=i;
				}
				else{
					xs[S[i][j]-'0']=j;
					ys[S[i][j]-'0']=i;
				}
			}
		}
	}
	int XX[1002][1002];
	bool FF[1002][1002];
	int ans=0;
	vector<pair<int,int> >vec1;
	vector<pair<int,int> >vec2;
	int dx[4]={-1,0,0,1};
	int dy[4]={0,-1,1,0};
	for(int x=0;x<N;x++){
		vec1.clear();
		vec2.clear();
		for(int i=0;i<H+2;i++)for(int j=0;j<W+2;j++){
			XX[i][j]=-1;
			FF[i][j]=false;
		}
		int cou=0;
		XX[ys[x]][xs[x]]=cou;
		FF[ys[x]][xs[x]]=true;
		vec1.push_back(make_pair(ys[x],xs[x]));
		while(XX[ys[x+1]][xs[x+1]]==-1){
			vec2.clear();
			for(int i=0;i<vec1.size();i++){
				for(int j=0;j<4;j++){
					if(S[vec1[i].first+dy[j]][vec1[i].second+dx[j]]=='X')continue;
					if(XX[vec1[i].first+dy[j]][vec1[i].second+dx[j]]!=-1)continue;
					if(FF[vec1[i].first+dy[j]][vec1[i].second+dx[j]])continue;
					vec2.push_back(make_pair(vec1[i].first+dy[j],vec1[i].second+dx[j]));
					FF[vec1[i].first+dy[j]][vec1[i].second+dx[j]]=true;
				}
			}
			vec1.clear();
			for(int i=0;i<vec2.size();i++)vec1.push_back(vec2[i]);
			cou++;
			for(int i=0;i<vec1.size();i++){
				XX[vec1[i].first][vec1[i].second]=cou;
			}
			
		}
		ans+=XX[ys[x+1]][xs[x+1]];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7164
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line, long.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var c = Array.ConvertAll(line, long.Parse);
        Array.Sort(a); Array.Sort(c);
        var res = 0L;
        foreach (var x in b)
            res += getSmall(a, x) * getBig(c, x);
        Console.WriteLine(res);
    }
    public static long getBig(long[] a, long targ)
    {
        var s = 0; var t = a.Length - 1; var st = 0;
        if (a[t] <= targ) return 0;
        if (a[0] > targ) return t + 1;
        while (t - s >= 2)
        {
            st = (s + t) / 2;
            if (a[st] > targ) t = st;
            else s = st;
        }
        return a.Length - t;
    }
    public static long getSmall(long[] a, long targ)
    {
        var s = 0; var t = a.Length - 1; var st = 0;
        if (a[t] < targ) return t + 1;
        if (a[0] >= targ) return 0;
        while (t - s >= 2)
        {
            st = (s + t) / 2;
            if (a[st] < targ  ) s = st;
            else t = st;
        }
        return s + 1;
    }
}


Measured memory_bytes: 40592
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	int i,j,n;cin>>n;
	static int kra[502][502];
	static int hto[502][502];
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			hto[i][j]=1;
			kra[i][j]=min({i,j,n+1-i,n+1-j});
		}
	}
	llint ans=-n*n;
	for(int h=0;h<n*n;h++){
		int p;cin>>p;p--;
		int y=p/n+1,x=p%n+1;
		ans+=kra[y][x];
		kra[y][x]--;
		hto[y][x]=0;
		queue<pair<int,int>>que;
		que.push(mp(y,x));
		while(que.size()){
			tie(y,x)=que.front();que.pop();
			if(kra[y-1][x]>kra[y][x]+hto[y-1][x]){kra[y-1][x]--;que.push(mp(y-1,x));}
			if(kra[y+1][x]>kra[y][x]+hto[y+1][x]){kra[y+1][x]--;que.push(mp(y+1,x));}
			if(kra[y][x-1]>kra[y][x]+hto[y][x-1]){kra[y][x-1]--;que.push(mp(y,x-1));}
			if(kra[y][x+1]>kra[y][x]+hto[y][x+1]){kra[y][x+1]--;que.push(mp(y,x+1));}
		}
		
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5144
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


A = [int(sys.stdin.buffer.readline()) for _ in range(5)]

ans = INF
for last_i in range(5):
    cnt = 0
    for i in range(5):
        if i == last_i:
            continue
        cnt += math.ceil(A[i] / 10) * 10
    cnt += A[last_i]
    ans = min(ans, cnt)

print(ans)


Measured memory_bytes: 14492
#include <iostream>

using namespace std;

int main(){
    long long a, b, r, g, l;
    while(cin >> a >> b){
        l = a*b;
        if(a < b) swap(a,b);
        do{
            r = a % b;
            a = b;
            b = r;
        }while(r);
        g = a; l /= g;
        cout << g <<' '<<l <<endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

#define REP(i,n) for ( int i = 0; i < (int)n; i++ )
#define FOR(i,c) for ( __typeof((c).begin())i=(c).begin(); i != (c).end(); i++ )
#define ALL(c) (c).begin(), (c).end()

typedef vector <int> VI;
int a, b;

bool solve( VI L, int d ) {
  if ( d >= (int)L.size() ) {
    return true;
  }
  int ba = a;
  int bb = b;
  if ( L[d] > a ) {
    a = L[d];
    if ( solve( L, d + 1 ) ) return true;
    a = ba;
  }
  if ( L[d] > b ) {
    b = L[d];
    if ( solve( L, d + 1 ) ) return true;
    b = bb;
  }
  return false;
}

int main() {
  int n;
  while ( cin >> n ) {
    for ( int i = 0; i < n; ++ i ) {
      VI L( 10 );
      for ( int j = 0; j < 10; ++ j ) {
	cin >> L[j];
      }
      a = 0;
      b = 0;
      cout << ( solve( L, 0 ) ? "YES" : "NO" ) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main()
{double w,h,x,y;
double area;
while(cin>>w>>h>>x>>y)
{area=w*h/2.00;
cout<<area<<" ";
if(x==w/2&&y==h/2)
cout<<1;
else cout<<0;
}
return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> vi(n);
    rep(i, n) cin >> vi[i];

    for (int i = n - 1; i >= 0; --i) {
        cout << vi[i];
        cout << ((i != 0) ? " " : "\n");
    }

    return 0;
}


Measured memory_bytes: 3136
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B = map(int, read().split())

    if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
        print('Possible')
    else:
        print('Impossible')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61920
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int money = 0;
		int blue = sc.nextInt();
		HashMap<String, Integer> blueCards = new HashMap<String, Integer>();
		for (int i = 0; i < blue; i++) {
			String s = sc.next();
			if (blueCards.containsKey(s)) {
				int value = blueCards.get(s);
				blueCards.put(s, ++value);
			} else {
				blueCards.put(s, 1);
			}
		}

		int red = sc.nextInt();
		//HashMap<String, Integer> redCards = new HashMap<String, Integer>();
		for (int i = 0; i < red; i++) {
			String s = sc.next();
			if (blueCards.containsKey(s)) {
				int value = blueCards.get(s);
				blueCards.put(s, --value);
			}
		}

		int max = 0;
		for (String s : blueCards.keySet()) {
			int value = blueCards.get(s);
			max = Math.max(max, value);
		}
		System.out.println(max);

	}
}


Measured memory_bytes: 21716
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int max = 0;
		int last = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (max < a) {
				max = a;
			}
			if (i == 0) {
				last = a;
			} else {
				last = gcd(last, a);
			}
		}
		if (k <= max && k % last == 0) {
			System.out.println("POSSIBLE");
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
	
	static int gcd(int x, int y) {
		if (x % y == 0) {
			return y;
		} else {
			return gcd(y, x % y);
		}
	}
}


Measured memory_bytes: 48796
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // min, max, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define rep(i,n) rep1(i,0,n)
#define rep1(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const int inf = 1<<30;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
const double PI = acos(-1);
int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int d[1000000];
    rep(i, n + 10) d[i] = 0;
    rep1(i,1,n){
        if(s[i-1]=='A'&&s[i]=='C')
            d[i] = 1;
    }
    rep1(i, 1, n) d[i] += d[i - 1];
    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        cout << d[r] - d[l] << endl;
    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const int N=300+7;
char arr[N][N];
int pre[N];
int mark[N][N];
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)   scanf("%s",arr[i]+1);
    int pos=0;
    int ss=1;
    for(int i=1;i<=n;i++){
        bool flag=false ;
        for(int j=1;j<=m;j++) {
            if(arr[i][j]=='#'){
                flag=true;
                mark[i][j]=ss++;
            }
        }
        if(!flag) pre[i]=1;
    }
    for(int i=1;i<=n;i++){
        if(pre[i]!=1) {
            for(int j=1;j<=m;j++){
                if(mark[i][j]) {
                    for(int k=j-1;k>=1;k--){
                        if(mark[i][k]) break;
                        mark[i][k]=mark[i][j];
                    }
                    for(int k=j+1;k<=m;k++){
                        if(mark[i][k]) break;
                        mark[i][k] =mark[i][j];
                    }
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(!pre[i]){
            pos=i;
            break;
        }
    }
    if(!pos) {
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cout<<mark[i][j]<<" ";
            }
            cout<<endl;
        }
    }
    else {
        for(int i=pos;i>=1;i--){
            if(pre[i]){
                for(int j=1;j<=m;j++){
                    mark[i][j]=mark[i+1][j];
                }
            }
        }
        for(int i=pos;i<=n;i++){
            if(pre[i]){
                for(int j=1;j<=m;j++){
                    mark[i][j]=mark[i-1][j];
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cout<<mark[i][j]<<" ";
            }
            cout<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

ll sentou(ll n){
    while(n>=10){
        n=n/10;
    }
    return n;
}

int main(){
    ll n,i,j,sita,ue;
    cin>>n;
    ll c[10][10];
    rep(i,10){
        rep(j,10){
            c[i][j]=0;
        }
    }
    rep(i,n+1){
        sita=i%10;
        ue=sentou(i);
        if(sita!=0 || ue!=0){
            c[ue][sita]+=1;
        }
    }
    ll ans=0;
    rep(i,10){
        rep(j,10){
            ans+=c[i][j]*c[j][i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
from math import ceil
n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]

def can_beet(t):
    ans = False
    d = 0
    for v in h:
        sub = v - (b * t)
        if sub > 0:
            d += ceil(sub / (a - b))
    if d <= t:
        ans = True
    return ans

l = -1
r = 10 ** 9 + 1
while r - l > 1:
    mid = (r + l) // 2
    if can_beet(mid):
        r = mid
    else:
        l = mid
print(r)

Measured memory_bytes: 50648
N = int(input())
u = list(map(int,input().split()))
s_u = sorted(u)
for x in range(N-1):
  s_u = sorted(s_u)
  tmp = s_u.copy()
  val = (tmp[0] + tmp[1]) / 2
  if len(s_u) != 1:
    s_u.remove(tmp[0])
    s_u.remove(tmp[1])
  s_u.insert(0,val)
print(s_u[0])


Measured memory_bytes: 3188
from collections import Counter
n = int(input())
ns = [input() for i in range(n)]
m = int(input())
ms = [input() for i in range(m)]
cn = dict(Counter(ns).most_common())
cm = dict(Counter(ms).most_common())
for i in cn.keys():
    cn[i] -= cm[i] if i in cm else 0
print(max(sorted(cn.values(), reverse=True)[0], 0))


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        for(int j = 1; j < 10; j++){
            for(int i = 1; i < 10; i++) {
                if(i * j == N) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 23764
/*共通祖先までの距離を比べればいい
1,Nから始めたものが衝突するところを見て, 

*/
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;cin>>N;
  vector<vector<long>>T(N);
  for(long i=0;i<N-1;i++){
    long a,b;cin>>a>>b;
    T[a-1].push_back(b-1);T[b-1].push_back(a-1);
  }
  vector<long>B(N,-1);B[0]=0;queue<long>q;q.push(0);
  while(q.size()){
    long f=q.front();q.pop();
    for(long n:T[f]){
      if(B[n]==-1){B[n]=B[f]+1;q.push(n);}
    }
  }
  vector<long>W(N,-1);W[N-1]=0;queue<long>p;p.push(N-1);
  while(p.size()){
    long f=p.front();p.pop();
    for(long n:T[f]){
      if(W[n]==-1){W[n]=W[f]+1;p.push(n);}
    }
  }
  long x=0,y=0;
  for(long i=0;i<N;i++){
    if(B[i]<=W[i])x++;
    else y++;
  }
  cout<<(x>y?"Fennec":"Snuke");
  
  
}




Measured memory_bytes: 7936
use std::cmp;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let t: Vec<usize> = (0..n).map(|_| sc.read()).collect();
    let v: Vec<usize> = (0..n).map(|_| sc.read()).collect();

    let t_sum = t.iter().sum();
    let mut max_v = vec![0; t_sum + 1];

    let mut pos = 0;
    for i in 0..n {
        let ti = t[i];
        let vi = v[i];
        max_v[pos] = cmp::min(max_v[pos], vi);
        for _ in 0..ti {
            max_v[pos + 1] = cmp::min(max_v[pos] + 1, vi);
            pos += 1;
        }
    }

    pos = t_sum;
    max_v[t_sum] = 0;
    for i in (0..n).rev() {
        let ti = t[i];
        for _ in 0..ti {
            max_v[pos - 1] = cmp::min(max_v[pos] + 1, max_v[pos - 1]);
            pos -= 1;
        }
    }

    let mut ans = 0.0;
    pos = 0;
    for i in 0..n {
        let ti = t[i];
        let vi = v[i];
        for _ in 0..ti {
            let cur = max_v[pos] as f64;
            let next = max_v[pos + 1] as f64;
            ans += cur + (next - cur) / 2.0;
            if cur == next && vi as f64 > cur {
                ans += 0.25;
            }
            pos += 1;
        }
    }

    println!("{}", ans);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 4352
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

string s[105];
int main(){
    int n,l;
    cin>>n>>l;
    for(int i=0;i<n;i++)
        cin>>s[i];
    sort(s,s+n);
    rep(i,0,n-1)
        cout<<s[i];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    vi A(N), B(N); F0R(i, N) cin >> A[i] >> B[i];
    sort(all(A));
    sort(all(B));
    ll X, Y; 
    if (N % 2 == 1) {
        X = A[N/2];
        Y = B[N/2];
    } else {
        X = A[N/2 - 1] + A[N/2];
        Y = B[N/2 - 1] + B[N/2];
    }

    cout << Y-X+1 << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 4788
h,w = map(int,input().split())
field = [input() for _ in range(h)]

ans = 'Yes'
for hi in range(h):
  for wi in range(w):
    if field[hi][wi] == '#': 
      is_one = True
      for dw,dh in ((-1,0),(0,1),(1,0),(0,-1)):        
        if (0<= hi+dh < h) and (0<= wi+dw < w) :          
          if field[hi][wi] == field[hi+dh][wi+dw]:
            is_one = False      
      if is_one:
        ans ='No'
  
print(ans)    

Measured memory_bytes: 3064
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    
    public static void main(String[] args) {
        int N = ni();
        int L = ni();
        int minI = -1;
        int minAbs = Integer.MAX_VALUE;
        for (int i = 1; i <= N; i++) {
            int a = L+i-1;
            if (Math.abs(a) < minAbs) {
                minI = i;
                minAbs = Math.abs(a);
            }
        }
        
        int ans = 0;
        for (int i = 1; i <= N; i++) {
            if (i == minI) continue;
            ans += L+i-1;
        }
        so.println(ans);
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0);
    }

    private static long[] nlongs(int n, int offset) {
        long[] a = new long[offset + n];
        for (int i = 0; i < n; i++)
            a[offset + i] = nl();
        return a;
    }
}


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

using namespace std;

int main() {
  int d;
  cin >> d;
  if (d==22) cout << "Christmas Eve Eve Eve";
  if (d==23) cout << "Christmas Eve Eve";
  if (d==24) cout << "Christmas Eve";
  if (d==25) cout << "Christmas";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int n;
	while (cin >> n && n) {
		vector<int> d(n);
		int sum = 0;
		for (int i = 0; i < n; ++i) cin >> d[i];
		sort(d.begin(), d.end());
		for (int i = 1; i < n - 1; ++i) sum += d[i];
		cout << sum / (n - 2) << endl;
	}
	return 0;
}


Measured memory_bytes: 3032
#include <stdio.h>

int main(){
  char c, tmp;
  
  scanf("%c", &c);
  for(int i = 0;i < 2;i++){
    scanf("%c", &tmp);
    if(c != tmp){
      printf("Yes\n");
      break;
    }
  }
  if(c == tmp){
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128