akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long goal = sc.nextLong();
        long num1 = 1;
        long num2 = goal;
      
      	for(int i = 1; i <= goal/i; i++){
        	if(goal % i == 0){
            	num1 = i;
                num2 = goal / i;
            }
		}
        System.out.println(num1 + num2 - 2);
     }
}

Measured memory_bytes: 35660
while True:
    a, b = map(int, input().split())
    if a or b:
        for i in range(0, a):
            for j in range(0, b):
                if i == 0 or i == a - 1 or j == 0 or j == b - 1:
                    print('#', end = '')
                else:
                    print(".", end = '')
            print()
        print()
    else:
        break


Measured memory_bytes: 7008
n=int(input())
p=[int(i) for i in input().split()]
ans=chk=0
for a,i in enumerate(p):
    a+=1
    if a==i and chk==1:
        chk=0
    elif a==i:
        ans+=1
        chk=1
    else:
        chk=0
print(ans)

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

//   a/b mod c
ll moddiv(ll a,ll b){
	ll x0=MOD,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%MOD;
      if (x2==1){
        ans=(n2+MOD)%MOD;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%MOD)*b-t)/b;
}
//剰余の割ざん

//aのn乗 mod c
ll expmod(ll a,ll n){
  ll ans=1LL,aa=a,beki=n;
  for(int i=0;i<64;i++){
    if (beki%2==1) ans=ans*aa%MOD;
    aa=aa*aa%MOD;
    beki/=2;
    if (beki==0)break;
  }
  return ans;
}




int now,n,k;

int main(){
  int ans=0;
  cin >> n >>k;
  int nk=n-k;

  vector<vector<ll>> vv = vector<vector<ll>>(nk+1, vector<ll>(k+1, 0LL));


  REP(i,nk+1){
    vv[i][0]=1;
  }


  REP(i,nk+1){
    REP(j,i+1){
      vv[i][1]=(vv[i][1]+vv[j][0])%MOD;
    }
  }
  
ll d=1LL;
for(int kk=1;kk<k;kk++){  
d=d*kk%MOD;
ll tmp=0LL;
int j=0;
  REP(i,nk+1){
    for(;j<i;j++){
      tmp+=vv[j][kk]*(k-kk);
      tmp%=MOD;
    }
    vv[i][kk+1]=(vv[i][kk+1]+tmp)%MOD;
    vv[i][kk+1]=moddiv(vv[i][kk+1],kk);
  }
}


REP(i,k){
  cout<<vv[nk][i+1]<<endl;
}

  return 0;
}

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

const int INF=100000000;

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

   if(n==25)
      cout<<"Christmas"<<endl;
   else if(n==24)
      cout<<"Christmas Eve"<<endl;
   else if(n==23)
      cout<<"Christmas Eve Eve"<<endl;
   else if(n==22)
      cout<<"Christmas Eve Eve Eve"<<endl;

}


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

int main()
{
	int N;
	cin >> N;
	vector<int> pos( N + 1 );
	for( int i = 0; i < N; i++ ) {
		int a;
		cin >> a;
		pos[a] = i + 1;
	}

	set<int> st;
	st.insert( 0 );
	st.insert( N + 1 );
	long long ans = 0;
	for( int i = 1; i < N + 1; i++ ) {
		long long ii = pos[i];
		auto pa = st.insert( ii );
		auto it = pa.first;
		long long l = *prev( it );
		long long r = *next( it );
		ans += ( ii - l ) * ( r - ii ) * i;
	}

	cout << ans << endl;
}


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

int main(){
  #define int long long int
  int a,b,gcm;
  cin>>a>>b;
  int c=a*b;
  if(a<b){
    int tmp=a;
    a=b;
    b=tmp;
  }
  gcm=a%b;
  while(gcm!=0){
    a=b;
    b=gcm;
    gcm=a%b;
  }
  cout<<c/b<<endl;
}


Measured memory_bytes: 256
Array.(Scanf.scanf " %d %s %s %s" @@ fun n a b c ->
  init n (fun i ->
    match List.(length @@ sort_uniq compare [a.[i];b.[i];c.[i]]) with
    | 3 -> 2
    | 2 -> 1
    | _ -> 0
  ) |> fold_left (+) 0 |> print_int)

Measured memory_bytes: 384
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
D = []

for i in range(M):
    b, c = map(int, input().split())
    D.append((c, b))
A.sort()
D.sort(reverse=True)
i = 0
for c, b in D:
    for j in range(i, min(i + b, N)):
        A[j] = max(c, A[j])
    i += b

print(sum(A))









Measured memory_bytes: 72088
let () = Scanf.scanf "%d\n" @@ fun n ->
  let hs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun h -> h in
  Printf.printf "%d\n" @@ snd @@ Array.fold_left (fun (m, acc) h ->
    max m h, acc + if m <= h then 1 else 0) (min_int, 0) hs

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = \
    std::priority_queue<T, std::vector<T>, std::greater<T> >;

signed main() {
  ll A, B, C, K, ans = 0;
  cin >> A >> B >> C >> K;
  {
    ll t = min(A, K);
    ans += t;
    K -= t;
  }
  {
    ll t = min(B, K);
    K -= t;
  }
  {
    ll t = min(C, K);
    ans -= t;
    K -= t;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};


int N;
vector<int> A;

int main() {
    int maxs = 100005;
    cin >> N;
    A.resize(maxs);
    int a;
    for(auto i = 0; i<N; i++){
        cin >> a;
        A[a]++;
    }
    
    int ans = 0;
    
    int count2 = 0;
    
    int count1 = 0;
    
    for(auto i = 0; i<maxs; i++){
        
        ans += (A[i]-1)/2;
        A[i] -=(A[i]-1)/2 * 2;
        
        if (A[i] == 2) count2++;
        if (A[i] == 1) count1++;
    }
    
    if (count2 %2 == 1) count1--;
    
    cout << count1 + count2 << endl;
    
    
    
    
    return 0;
}









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

int main(){
	int n,l;
	multiset<string> s;
	string p,ans="\0";
	cin>>n>>l;
	for(int i=0;i<n;i++){
		cin>>p;
		s.insert(p);
	}
	for(auto it:s)
		ans+=(it);

	cout<<ans<<endl;
}

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

X.sort()
min_power = float('inf')
for i in range(X[0], X[-1]+1):
    tmp = 0
    for x in X:
        tmp += pow(x - i, 2)
    min_power = min(min_power, tmp)
    
print(min_power)

Measured memory_bytes: 39152
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
using pii = pair<int, int>;

int main()
{
    int N;
    cin >> N;
    vector<pii> right_left;
    rep(i, 0, N)
    {
        int X, L;
        cin >> X >> L;
        right_left.emplace_back(X+L-1, X-L);
    }

    sort(right_left.begin(), right_left.end());

    int cnt = 0;
    int right_most = -1000000010;
    rep(i, 0, N)
    {
        int right, left;
        tie(right, left) = right_left[i];

        if (right_most<left)
        {
            ++cnt;
            right_most = right;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1400
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
  [a, b, c] <- sort <$> readInts
  print $ a + b + c - 2 * b

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef pair<string,int> as;

string s;
map<string,int> len;
map<as,int> arr;

string array_name(size_t &p){
  string res;
  while(p<s.size() && isalpha(s[p]))res += s[p++];
  return res;
}

int number(size_t &p){
  int res = 0;
  while(p<s.size() && isdigit(s[p]))res = res*10 + (int)(s[p++]-'0');
  return res;
}

int expression(size_t &p){
  if(isdigit(s[p]))return number(p);
  string s = array_name(p);
  int id = expression(++p);
  p++;
  if(id<0)return -1;
  if(id >= len[s])return -1;
  if(arr.count(as(s,id)) == 0)return -1;
  return arr[as(s,id)];
}

int assignment(size_t &p){
  string s = array_name(p);
  int id = expression(++p);
  p += 2;
  int x = expression(p);
  if(id<0 || x<0)return -1;
  if(id >= len[s])return -1;
  arr[as(s,id)] = x;
  return x;
}

int declaration(size_t &p){
  string s = array_name(p);
  int l = number(++p);
  len[s] = l;
  return 1;
}

int statement(void){
  size_t p = 0;
  if(s.find("=") == string::npos)return declaration(p);
  return assignment(p);
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  for(;;){
    len.clear(); arr.clear();

    int cnt = 0, bug = 0;
    cin >> s;
    while(s != "."){
      int res = statement();
      
      cin >> s; cnt++;
      if(res<0 && bug==0)bug = cnt;
    }
    if(cnt==0)break;
    cout << bug << endl;
  }
}

Measured memory_bytes: 1320
#include <iostream>
#include <string>
#include <cassert>
#include <cctype>
#include <cstdio>

using namespace std;

bool IsPrime(int num) {
    if (num < 2)        return false;    // 2未満は素数
    if (num == 2)       return true;     // 2は素数
    if (num % 2 == 0)   return false;    // 2で割り切れれば素数ではない

    int i = 3;
    while (i * i <= num) {
        if (num % i == 0)
            return false;
        i += 2;
    }
    return true;
}


// 時間切れ
int main(void) {

    int N;
    cin >> N;

    int total = 0;
    for (int i = 0; i < N; ++i) {
        int e;
        cin >> e;
        if (IsPrime(e))
            ++total;
    }

    printf("%d\n", total);

    return 0;
}

Measured memory_bytes: 1144
#include<stdio.h>
#define INFTY 1000000
#define M 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int min(void);

int D[M][M];
int n;

int main() {

  int a,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++) {
    for(j=0;j<n;j++) {
      scanf("%d",&a);
      if(a == -1) D[i][j] = INFTY;
      else D[i][j] = a;
    }
  }

  printf("%d\n",min());

  return 0;

}

int min() {

  int u,v,minv,sum=0;
  int d[M],p[M],color[M];
  int i,j,k;
  
  for(i=0;i<n;i++) {
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1) {

    minv = INFTY;
    u = -1;

    for(i=0;i<n;i++) {
      if(minv > d[i] && color[i] != BLACK) {
	u = i;
	minv = d[i];
      }
    }

    if(u == -1) break;

    color[u] = BLACK;

    for(v=0;v<n;v++) {
      if( color[v] != BLACK && D[u][v] != INFTY ) {
	if(d[v] > D[u][v]) {
	  d[v] = D[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }

  for(i=0;i<n;i++) {
    if(p[i] != -1) sum += D[i][p[i]];
  }

  return sum;

}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
map<ll,ll > ma;
vector<ll> ki;
vector<pair<ll,ll> > it;
void sieve()
{
    ma[1] = 1;
    int i;;
    for( i=3; i*i<=20000010; i=i+2)
    {
        if(ma[i]==0)
        {
            for(int j=i*i; j<=20000010; j=j+(2*i))
            {
                ma[j] = 1;
            }
        }

    }
    int c1,c2;
    c1 = 3;
    c2 = 3;
    for(i=5; i<=20000010; i=i+2)
    {
        if(ma[i]==0)
        {
            c1=c2;
            c2=i;
            if((c2-c1)==2)
            {
                it.push_back({c1,c2});
            }
        }
    }
}

int main()
{

    ll i,j,k,a,b,c,n,t,m,d,r,g,y,f;
    vector<ll> v,s,ss,vv;
    map<ll,ll> ma,ha;
    string st,et,mt;
    long double aa,bb;
    cin>>n;
    for(i=1;i<n;i++){
        cin>>a;
        ma[a]++;
    }
    for(i=1;i<=n;i++){
        cout<<ma[i]<<endl;
    }
}


Measured memory_bytes: 16104
#include <cstdio>
#include <functional>
#include <vector>
using namespace std;

//@@@@@@@@@@@
//@ snippet SegTree
//@ alias   segtree
//@ options head
template<class Monoid>
struct SegTree {
  using Func = function<Monoid(Monoid, Monoid)>;
  const int sz;
  const Func fn;
  const Monoid unity;
  vector<Monoid> dat;

  SegTree(int n, const Monoid &u, Func f)
    : sz(1 << (__lg(n+5) + 1)), fn(f), unity(u), dat(sz*2, unity) {}

  void set(int k, const Monoid &v) { dat[k + sz] = v; }

  Monoid& operator[] (int k) { return dat[k + sz]; }

  void build() { for (int k = sz-1; k > 0; --k) dat[k] = fn(dat[2*k], dat[2*k+1]); }

  void update(int k, const Monoid &v) {
    dat[ k += sz ] = v;
    while(k >>= 1) dat[k] = fn(dat[2*k], dat[2*k+1]);
  }

  Monoid query(int a, int b) const {
    Monoid L = unity,  R = unity;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = fn(L, dat[a++]);
      if (b & 1) R = fn(dat[--b], R);
    }
    return fn(L, R);
  }
};
//@@@@@@@@@

void AOJ_DSL_2_A()
{
  int N, Q;
  int com, x, y;

  scanf("%d%d", &N, &Q);
  SegTree<int> seg(N, (1LL << 31) - 1, [](int a, int b){ return min(a,b); });

  while(Q--) {
    scanf("%d%d%d", &com, &x, &y);
    if (com == 0) {
      seg.update(x, y);
    } else {
      printf("%d\n", seg.query(x, y+1));
    }
  }

  return;
}

int main()
{
  AOJ_DSL_2_A();
  return 0;
}




Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int x, y;
    cin >> x >> y;
    int ans = 0;
    ans += max(0,400000 - 100000* x);
    ans += max(0,400000 - 100000* y);
    if (ans == 600000) ans += 400000;
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

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

  ll n;
  cin >> n;

  if (n % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  for (int i = 1; i <= int(log10(1e18) / log10(5)); i++) {
    ans += n / (ll(pow(5, i)) * 2);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4060
List = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(List[int(input())-1])

Measured memory_bytes: 9044
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

typedef long long ll;

int main()
{
    string S;
    cin >> S;
    int K;
    cin >> K;
    set<string> ans;
    for(int i=0; i<S.size(); i++){
        string tmp;
        for(int j=i; j<min(i+5, (int)S.size()); j++){
            tmp+=S[j];
            ans.insert(tmp);
        }
        auto it=ans.begin();
        if(ans.size()>K){
            for(int c=0; c<K; c++) it++;
            ans.erase(it);
        }
    }
    
    auto it=ans.begin();
    for(int c=0; c<K-1; c++) it++;
    cout << *it << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll k,n; cin >> k >> n; ll wa = 0;
  vl lo(n); vl lodi(n-1);
  rep(i,n){
    ll x; cin >> x; lo[i] = x;
  }
  
  sort(all(lo));
  rep(i,n-1){
     lodi[i] = (lo[i+1]-lo[i]);
  }
  
  sort(all(lodi));
  wa = max(lodi[n-2],k-lo[n-1]+lo[0]);
  
  cout << k-wa << endl;
}

Measured memory_bytes: 3328
n, m = map(int, input().split())
h = list(map(int, input().split()))

ma = [0]*n
for _ in range(m):
    a, b = map(int, input().split())
    ma[a-1] = max(h[b-1], ma[a-1])
    ma[b-1] = max(h[a-1], ma[b-1])

ans = 0
for i in range(n):
    if h[i]>ma[i]:
        ans += 1
print(ans)

Measured memory_bytes: 20116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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

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

void mod(ll &val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int H,W;
    ll M;
    cin >> H >> W >> M;
    vector<P> h(H);
    vector<P> w(W);
    for(int i = 0;i < H;i++) {
        h.at(i).second = i;
    }
    for(int i = 0;i < W;i++) {
        w.at(i).second = i;
    }
    map<P,int> ma;
    for(int i = 0;i < M;i++) {
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        h.at(A).first++;
        w.at(B).first++;
        ma[P(A,B)]++;
    }
    sort(h.begin(),h.end());
    reverse(h.begin(),h.end());
    sort(w.begin(),w.end());
    reverse(w.begin(),w.end());
    int hmax = h.at(0).first;
    int wmax = w.at(0).first;
    vector<int> hcnt;
    vector<int> wcnt;
    for(int i = 0;i < H;i++) {
        if(h.at(i).first == hmax) {
            hcnt.push_back(h.at(i).second);
        }
    }
    for(int i = 0;i < W;i++) {
        if(w.at(i).first == wmax) {
            wcnt.push_back(w.at(i).second);
        }
    }
    ll hsum = hcnt.size();
    ll wsum = wcnt.size();
    if(hsum * wsum >= M + 1) {
        cout << hmax + wmax << endl;
    }
    else {
        bool ret = false;
        for(int i = 0;i < hsum;i++) {
            for(int j = 0;j < wsum;j++) {
                if(!ma.count(P(hcnt.at(i),wcnt.at(j)))) {
                    ret = true;
                }
            }
        }
        if(ret == true) {
            cout << hmax + wmax << endl;
        }
        else {
            cout << hmax + wmax - 1 << endl;
        }
    }
}

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

#define INF INT_MAX

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

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

    int N,K;
    cin >> N >> K;
    
    int ans = 0;

    ans = N - K;
    if(K == 1){cout << 0 << endl;return 0;}
    if(ans < 0)ans = 0;

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline

_, k = map(int, input().split())
s = list(map(int, list(input())))
# print(s)
is_count_zero = True
s0 = [0]
s1 = []
s0_ptr = 0
s1_ptr = -1
for c in s:
    if is_count_zero and c == 0:
        s0[s0_ptr] += 1
    elif not is_count_zero and c == 0:
        s0.append(1)
        s0_ptr += 1
        is_count_zero = True
    elif is_count_zero and c == 1:
        s1.append(1)
        s1_ptr += 1
        is_count_zero = False
    else: # not is_count_zero and c == 1
        s1[s1_ptr] += 1

# print(s0,s1)
is_end_one = True if len(s0) == len(s1) else False

if k >= len(s0):
    print(sum(s0)+sum(s1))
# elif k == 0:
#     if s1 == []:
#         print(0)
#     else:
#         print(max(s1))
else:
    ans = 0
    sum_range = 0
    n = len(s0)-k+1
    for i in range(n):
        if i == 0:
            sum_range = sum(s0[:k]) + sum(s1[:k])
            ans = max(ans, sum_range)
        elif i == n-1:
            sum_range = sum(s0[i:]) + sum(s1[i-1:])
            ans = max(ans, sum_range)
        elif i == 1:
            sum_range = sum_range - s0[0] + s0[k] + s1[k]
            ans = max(ans, sum_range)
        elif i != 0:
            sum_range = sum_range - s0[i-1] + s0[i+k-1] - s1[i-2] + s1[i+k-1]
            ans = max(ans, sum_range)
    print(ans)


Measured memory_bytes: 5352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int total = 0;
        for (int i = 0; i < m; i++) {
            total += in.nextInt();
        }

        if (total > n) {
            System.out.println(-1);
        } else {
            System.out.println(n - total);
        }
    }
}


Measured memory_bytes: 46844
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N, M;
	cin >> N >> M;
	int n = N - M;
	int m = M;

	int nTime = n * 100;
	int mTime = m * 1900;
	long long time = nTime + mTime;
	for (int i = 0; i < m; ++i) {
		time *= 2;
	}

	cout << time << endl;
	return 0;
}

Measured memory_bytes: 3628
n,a,b=map(int,input().split())

di = 10**9+7

def pow_k(x,nt):
    if nt==0:
        return 1
    K=1
    while nt>=2:
        if nt%2!=0:
            K=(K*x)%di
        x=(x*x)%di
        nt//=2
    return (K*x)%di

ans = pow_k(2,n)-1

mi = max(a,b)

lis = [n-i for i in range(mi)]
lisr = [i+1 for i in range(mi)]


for i in range(1,mi):
    lis[i] = (lis[i-1]*lis[i])%di
    lisr[i] = pow_k(lisr[i],di-2)

for i in range(1,mi):
    lisr[i] = (lisr[i-1]*lisr[i])%di


hik =(lis[a-1]*lisr[a-1])%di
hik2 = (lis[b-1]*lisr[b-1])%di


ans = (ans - hik - hik2)%di

#print((lis[3-1]*lisr[3-1])%di)

print(ans)


Measured memory_bytes: 55244
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
using Graph = vector<vector<ll> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

/*参考記事*/
/*https://www.hamayanhamayan.com/entry/2019/01/12/152428*/

ll n;
vector<ll>E[101010];
ll m;

ll dp[101010];//dp[cu]=頂点cuの部分木の塗り方において頂点cuが黒色に塗られていて、かつ黒色の頂点が全て連結である塗り方の総数
void dfs1(int cu,int pa=-1){//普通の木DP
    dp[cu]=1;
    for(int to:E[cu]){
        if(to==pa)continue;
        dfs1(to,cu);
        dp[cu]*=dp[to]+1;//dp[to]+1をかける理由は白色の場合は部分木が全て白色になり1通りになるから
        dp[cu]%=m;
    }
}

ll ans[101010];
void dfs2(int cu,int pa=-1){
    ans[cu]=1;
    for(int to:E[cu]){
        ans[cu]*=dp[to]+1;//遷移の際に親となるノードのdpの値を調整しているからこれでOK
        ans[cu]%=m;
    }

    int n = E[cu].size();
    vector<ll>lft(n),rht(n);
    for(int i=0;i<n;i++){
        lft[i]=rht[i]=dp[E[cu][i]]+1;
    }
    for(int i=1;i<n;i++){
        lft[i]*=lft[i-1];
        lft[i]%=m;
    }
    for(int i=n-2;i>=0;i--){
        rht[i]*=rht[i+1];
        rht[i]%=m;
    }
    rep(i,n){
        if(E[cu][i]==pa)continue;//dfs2でも親には戻らないようにしなきゃいけない
        dp[cu]=1;
        if(i!=0)dp[cu]*=lft[i-1];
        dp[cu]%=m;
        if(i+1<n)dp[cu]*=rht[i+1];
        dp[cu]%=m;
        dfs2(E[cu][i],cu);
    }
}

int main(){
    cin >> n >> m;
    rep(i,n-1){
        int x,y;
        cin >> x >> y;
        x--;y--;
        E[x].push_back(y);
        E[y].push_back(x);
    }
    dfs1(0);
    dfs2(0);
    rep(i,n)cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 20880
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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














int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    cout << ((c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b))? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long int n,i,j,k=0;
	cin>>n;
	long int a[n];
	for(i=0;i<n;i++){cin>>a[i];}
		sort(a,a+n);
	long double g=a[0];
	for(i=1;i<n;i++){
		g=(g+a[i])/2;
	}
	cout<<g;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	printyn(a == b && b == c);
	
	Please AC;
}


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

int N, K;
vector<int> a;
vector<int> dp;

bool dfs(int i) {
    if (dp[i] != -1) return dp[i];
    bool res = false;
    for (int j = 0; j < N; ++j) {
        if (i - a[j] >= 0) res |= (!dfs(i - a[j]));
        else break;
    }
    return dp[i] = res;
}

int main() {
    cin >> N >> K;
    a.resize(N);
    int min_a = 1 << 30;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        min_a = min(min_a, a[i]);
    }

    dp.resize(K + 1);
    for (int i = 0; i < min_a; ++i) dp[i] = false;
    for (int i = min_a; i <= K; ++i) dp[i] = -1;

    cout << (dfs(K) ? "First" : "Second") << endl;
}


Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;

int main() {
	static long long N, A[1000][1000];
	static long long COUNT[1000000] = {};
	static bool used[1000000] = {};
	static vector<long long> V[1000000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - 1; j++) cin >> A[i][j], A[i][j]--;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - 2; j++) {
			long long From = A[i][j], To = A[i][j + 1];
			long long FA, TA;
			if (i < From) FA = N * i + From;
			else FA = N * From + i;
			if (i < To) TA = N * i + To;
			else TA = N * To + i;
			V[TA].push_back(FA);
			COUNT[FA]++;
		}
	}
	vector<long long> VX;
	long long NOW = N * (N - 1) / 2;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			long long P = i * N + j;
			if (COUNT[P] == 0) VX.push_back(P);
		}
	}
	for (int i = 0; i < N * N; i++) {
		vector<long long> VY;
		if (VX.empty() && NOW != 0) {
			cout << -1 << endl;
			return 0;
		}
		if (NOW == 0) {
			cout << i << endl;
			return 0;
		}
		for (int X : VX) {
			NOW--;
			for (int Next : V[X]) {
				COUNT[Next]--;
				if (COUNT[Next] == 0) VY.push_back(Next);
			}
		}
		VX = VY;
	}
}

Measured memory_bytes: 54912
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int product = a*b;
        if(product%2==0) System.out.println("Even");
        else System.out.println("Odd");
    }
}

Measured memory_bytes: 21716
# frozen_string_literal: true

n, m = gets.split.map(&:to_i)
arr = Array.new(n + 1) { [] }
m.times do
  a, b = gets.split.map(&:to_i)
  arr[a] << b
  arr[b] << a
end
que = []
que << 1
depth = []
depth[1] = 0
res = []
until que.empty?
  v = que.shift
  arr[v].each do |i|
    next if depth[i] != nil

    depth[i] = depth[v] + 1
    que << i
    res[i] = v
  end
end
puts :Yes
(2..n).each do |i|
  puts res[i]
end


Measured memory_bytes: 33376
#include <iostream>
#include <cstring>
using namespace std;
char c[10000];
int k;
int main(void)
{
    cin>>k>>c;
    int l=strlen(c);
    if(l<=k)cout<<c<<endl;
    else
    {
        for(int i=0;i<k;i++)cout<<c[i];
        cout<<"..."<<endl;
    }
    return 0;
}

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

int main() {
  int a,b;
  string s;
  int n;
  cin >> n;
  vector<tuple<string,int,int>>t(n);
  for(int i=0;i<n;i++){
  cin >> s >> a;
  b=i+1;  
  t.at(i)=make_tuple(s,100-a,b);  
  }  
  sort(t.begin(),t.end());
  for(int i=0;i<n;i++){
  tie(s,a,b)=t.at(i);  
  cout << b << endl;  
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ToStreak
{
    class ABC116_A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] abc = ReadInts();
            Console.WriteLine(abc[0] * abc[1] / 2);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,P;
  cin>>N>>P;
  map<int,int> A;
  for(int i=2;i<=P/i && P!=1;i++){
    int k=0;
    for(;P%i==0;P/=i)
      k++;
    if(k!=0)
      A[i]=k;
  }
  if(P!=1)
    A[P]=1;
  int ans=1;
  for(pair<int,int> p:A)
    ans*=pow(p.first,p.second/N);
  cout<<ans<<endl;
}

Measured memory_bytes: 3936
n = int(input())
L = [-1,-1,-1]
ans = 1
color = list(map(int,input().split()))
for i in range(n):
    k = L.count(color[i]-1)
    ans = (ans*k)%(10**9+7)
    for j in range(3):
        if L[j] == color[i]-1:
            L[j] += 1
            break
print(ans)

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

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

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

#define INF 2123456789
#define IINF 9123456789123456789

void use_cio() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}
// template <typename... Args>
// void dbg(Args... args) {
//     ((cout << args << " "), ...);
//     cout << endl;
// }
//--------------------------------------------------//
int n, m, q;
int t[400010];
int ans[100010];
vector<pair<pair<int, pii>, int>> Vi;
void upd(int p, int val) {
    for (t[p += n] += val; p > 1; p >>= 1) t[p >> 1] = t[p] + t[p ^ 1];
}
int qry(int l, int r) {
    int res = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
        if (l & 1) res += t[l++];
        if (r & 1) res += t[--r];
    }
    return res;
}
int main() {
    use_cio();
    cin >> n >> m >> q;
    n++;
    rep(i, m) {
        int p, q;
        cin >> p >> q;
        Vi.push_back({{n - p, {0, q}}, 0});
    }
    rep(i, q) {
        int p, q;
        cin >> p >> q;
        Vi.push_back({{n - p, {1, q}}, i});
    }
    sort(all(Vi));
    for (auto inp : Vi) {
        int x = inp.first.second.first;
        int p = inp.first.first;
        int q = inp.first.second.second;
        //cout << x << " " << p << " " << q << " " << inp.second << endl;
        if (x == 0) {
            upd(q, 1);
        } else {
            ans[inp.second] = qry(0, q + 1);
        }
    }
    rep(i, q) cout << ans[i] << endl;
}

Measured memory_bytes: 10604
from bisect import bisect_left, bisect_right

def solve():
    N, K = map(int, input().split())
    As = list(map(int, input().split()))

    As.sort()
    i = bisect_left(As, K)
    Bs = As[:i]
    M = len(Bs)

    def isOK(x):
        bitset = 1<<(K-1)
        for i, B in enumerate(Bs):
            if i == x: continue
            bitset |= bitset>>B
        return bitset & ((1<<Bs[x])-1)

    ng, ok = -1, M
    while abs(ok-ng) > 1:
        mid = (ng+ok) // 2
        if isOK(mid):
            ok = mid
        else:
            ng = mid

    print(ok)


solve()


Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll K, A, B;

int main()
{
    cin >> K;
    cin >> A >> B;
    for (ll i = 1; i <= 2000; i++) {
        if (K * i >= A && K * i <= B) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
}

Measured memory_bytes: 3636
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try {
			System.setIn(new FileInputStream("src/aoj0028/input.txt"));
			System.setOut(new PrintStream(new FileOutputStream("src/xxxyyyy/result.txt")));
		} catch (FileNotFoundException e) {
		}
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
		while(sc.hasNext()) {
			int key = sc.nextInt();
			int value = 0;
			if( map.containsKey(key) ) value = map.get(key);
			map.put(key, value + 1);
		}
		int most = 0;
		for(int value : map.values()) {
			most = max(most, value);
		}
		for(int key : map.keySet()) {
			if( most == map.get(key))
				System.out.println(key);
		}
	}
	
	void debug(Object... os) {
		System.err.println(deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,N;
    int S =0;
    cin >> H >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  S += A[i];
  }
  if(H>S){
    cout <<"No" << endl;
  }
  else{
    cout << "Yes" << endl;
}
}

Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=200005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
	lli a[MaxN],b[MaxN];
int main(){
	cin.tie(0),ios_base::sync_with_stdio(0);
	lli N,i,j,p,q;
	cin>>N;
	vector <lli> aux;
	lli med1,med2,res;
	for(i=0;i<N;i++){
		cin>>a[i]>>b[i];
	}
	for(i=0;i<N;i++){
		aux.push_back(a[i]);
	}
	sort(aux.begin(),aux.end());
	if(N%2==0){
		med1=aux[N/2-1]+aux[N/2];	
	}
	else med1=aux[N/2];
	aux.clear();
	for(i=0;i<N;i++){
		aux.push_back(b[i]);
	}
	sort(aux.begin(),aux.end());
	if(N%2==0){
		med2=aux[N/2-1]+aux[N/2];
	}
	else med2=aux[N/2];
	res=abs(med2-med1)+1;
	cout<<res<<"\n";
}		


Measured memory_bytes: 7968
import java.util.*;
import java.lang.*;

public class Main {
    static class pair{
        double f,s;
        pair(double f,double s){
            this.f=f;
            this.s=s;
        }
    }
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int c=in.nextInt();
        int A[]=new int[c+1];
        int B[]=new int[c+1];
        int C[]=new int[c];
        for(int i=1;i<=c;i++)
              A[i]=in.nextInt();
        for(int i=1;i<=c;i++)
              B[i]=in.nextInt();
        for(int i=1;i<c;i++)
              C[i]=in.nextInt();
        long sum=0;
        int h=-1;
        for(int i=1;i<=c;i++){
            sum+=B[A[i]];
            if(h+1==A[i])
                sum+=C[h];
            h=A[i];
        }
        System.out.println(sum);
        in.close();
    }
}


Measured memory_bytes: 24916
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Test
{
    public static void Main()
    {
        while (true)
        {
            string[] str = Console.ReadLine().Split(' ');
            int h = int.Parse(str[0]);
            int w = int.Parse(str[1]);
            if (h == 0 && w == 0)break;
            
            for(int i= 0; i < h; ++i)
            {
               
                for (int j = 0; j < w; ++j)
                {
                    if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
                    {
                        Console.Write("#");
                    }
                    else
                        Console.Write(".");

                }



                Console.Write("\n");

            }
            Console.Write("\n");
        }
        return ;
    }
}


Measured memory_bytes: 15764
#include<stdio.h>
#include<string.h>
#define M(a,b) a<b?b:a
char s[4010],t[4010];
int dp[4010][4010]={0},n,m,i,j,r;
int main()
{
	for(;~scanf("%s%s",s+1,t+1);)
	{
		memset(dp,0,sizeof(dp));
		n=strlen(s+1),m=strlen(t+1);
		for(i=1,r=0;i<=n;i++)
			for(j=1;j<=m;j++)
			{
				dp[i][j]=s[i]==t[j]?dp[i-1][j-1]+1:0;
				r=M(r,dp[i][j]);
			}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 63380
# https://atcoder.jp/contests/abc107/tasks/abc107_b
from copy import deepcopy
h, w = map(int, input().split())
matrix = []
for _ in range(h):
    row = list(input())
    matrix.append(row)

# delete row
rows = []
for i in range(h):
    white = False
    for j in range(w):
        if matrix[i][j] == '#':
            break
    else:
        white = True
    if white:
        rows.append(i)
t = []
for i in range(h):
    if i in rows:
        continue
    t.append(matrix[i])
h -= len(rows)
matrix = t

# delete col
cols = []
for i in range(w):
    white = False
    for j in range(h):
        if matrix[j][i] == '#':
            break
    else:
        white = True
    if white:
        cols.append(i)

t = []
for i in range(h):
    row = []
    for j in range(w):
        if j in cols:
            continue
        row.append(matrix[i][j])
    t.append(row)
w -= len(cols)
matrix = t
for r in matrix:
    print(''.join(r))

Measured memory_bytes: 39792
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

const long long INF = (1LL << 60);

class Edge{
    public:
        long long to, cost;
        Edge(long long to, long long cost) : to(to) ,cost(cost) {}
};

class Node{
    public:
        long long dis;
        bool isUsed;
        Node(){
            this->dis = INF;
            this->isUsed = 0;
        }
};

typedef vector<vector<Edge>> AdjList;

vector<Node> dijkstra(AdjList g, long long start, long long n){
    vector<Node> node(n);
    priority_queue<long long, vector<pair<long long, long long>>, greater<pair<long long, long long>>> q;

    q.push(make_pair(0, start));
    node[start].dis = 0;

    pair<long long, long long> u;
    while(not q.empty()){
        u = q.top(); q.pop();
        long long current = u.second;
        node[current].isUsed = 1;

        rep(i,g[current].size()){
            long long next = g[current][i].to;
            if(node[next].isUsed == 0){
                if(node[next].dis > node[current].dis + g[current][i].cost){
                    node[next].dis = node[current].dis + g[current][i].cost;
                    q.push(make_pair(node[next].dis, next));
                }
            }
        }
    }
    return node;
}

int main(){
    long long n;
    cin >> n;
    AdjList g(n);

    rep(i,n - 1){
        long long a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].emplace_back(Edge{b,c});
        g[b].emplace_back(Edge{a,c});
    }

    long long q, k;
    cin >> q >> k;
    k--;

    vector<Node> node = dijkstra(g, k, n);
    rep(i,q){
        long long a, b;
        cin >> a >> b;
        a--; b--;
        cout << node[a].dis + node[b].dis << endl;
    }

}


Measured memory_bytes: 18928
def Get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def Get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def Get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def Get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end

w,a,b=Get_i()
if a<b
  puts a+w>b ? 0 : b-(a+w)
else
  puts b+w>a ? 0 : a-(b+w)
end

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


int main(){
  string S; cin >> S;
  int N=S.size();
  
  int red=0,blue=0;
  for(int i=0; i<N; i++){
    if(S[i]=='0') red++;
    else blue++;
  }
  cout << N-abs(red-blue) << endl;
}

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

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

using namespace std;

typedef long long ll;

// 2 3 5 7 11 13 17 19 23
// 13 17 19 23

bool use[101];
vector<ll> volume[101];
int current_time[101];
vector<ll> buf[101];
int pm[4] = {13,17,19,23};

int main(){
  int N;
  while( cin >> N, N ) {
  ll lcm = 1;
    rep(i,N) {
      use[i] = false;
      volume[i].clear();
    }
    rep(i,4) buf[pm[i]].clear();
    rep(i,N){
      int size;
      cin >> size;
      volume[i].resize(size);
      cin >> current_time[i];
      rep(j,size) cin >> volume[i][j];
      if( size != 13 && size != 17 && size != 19 && size != 23 ) {
        lcm = lcm / __gcd(lcm,(ll)size) * (ll)size;
        use[i] = true;
      } else {
        if( buf[size].empty() ) buf[size].resize(size,0);
        rep(j,size) {
          buf[size][j] += volume[i][(current_time[i]+j)%size];
        }
      }
    }
    ll maxi = 0;
    for(ll i=0;i<lcm;i++){
      ll maxi_sub = 0;
      rep(j,N) if( use[j] ){
        maxi_sub += volume[j][current_time[j]];
        ( current_time[j] += 1 ) %= (int)volume[j].size();
      }
      maxi = max(maxi,maxi_sub);
    }
    rep(i,4) {
      ll maxi_sub = 0;
      rep(j,buf[pm[i]].size()) maxi_sub = max(maxi_sub,buf[pm[i]][j]);
      maxi += maxi_sub;
    }
    cout << maxi << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
import math

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

ceil = lambda number: math.ceil(number / 10) * 10

minutes = [A, B, C, D, E]
ceiled_minutes = list(map(ceil, minutes))

maximum_diff = 0
for minute in minutes:
    ceiled = ceil(minute)
    diff = ceiled - minute
    if diff == 0: continue

    if maximum_diff is None or diff > maximum_diff:
        maximum_diff = diff

answer = sum(ceiled_minutes) - maximum_diff
    
print(answer)


Measured memory_bytes: 3064