akhauriyash/Code-Regression huggingface dataset:
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    v_list = list(map(int, input().split()))
    v_list_even = v_list[::2]
    v_list_odd = v_list[1::2]
    counter_even = Counter(v_list_even)
    counter_odd = Counter(v_list_odd)
    if counter_even.most_common()[0][0] == counter_odd.most_common()[0][0]:
        even_first = counter_even.most_common()[0][1]
        odd_first = counter_odd.most_common()[0][1]
        if len(counter_even.most_common()) == 1:
            even_second = 0
        else:
            even_second = counter_even.most_common()[1][1]
        if len(counter_odd.most_common()) == 1:
            odd_second = 0
        else:
            odd_second = counter_odd.most_common()[1][1]
        ans = min(len(v_list_even) - even_first + len(v_list_odd) - odd_second, len(v_list_even) - even_second + len(v_list_odd) - odd_first)
    else:
        ans = len(v_list_even) - counter_even.most_common()[0][1] + len(v_list_odd) - counter_odd.most_common()[0][1]
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 19040
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <functional>
#include <numeric>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

constexpr int MAX_N = 100000;

using ll = long long;

ll N;
ll L[MAX_N], R[MAX_N];
std::vector<ll> ls = { 0 }, rs = { 0 };

int main()
{
  scanf( "%lld", &N );
  rep( i, N )
  {
    scanf( "%lld%lld", L+i, R+i );

    ls.push_back( L[i] );
    rs.push_back( R[i] );
  }

  std::sort( ls.rbegin(), ls.rend() );
  std::sort( all(rs) );

  // 5,3,1,0
  // 0,2,4,6

  ll rS = 0, lS = 0;
  ll ans = 0;
  rep( k, N )
  {
    if( ls[k] > rs[k] )
    {
      lS += ls[k];
      rS += rs[k];
    }

    ans = std::max( ans, 2*(lS-rS) );
  }

  printf( "%lld\n", ans );

  return 0;
}

Measured memory_bytes: 3564
<?php
$n = trim(fgets(STDIN));
$a = trim(fgets(STDIN));

if($n < 500 && $n > $a){
    echo "No";
    exit;
}
if($n <= $a || ($n % 500) <= $a){
    echo "Yes";
}else{
    echo "No";
}
?>

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

int main(){
	int n;
	cin >> n;
	string s;
	vector<vector<int>> l(1000000, vector<int>(0));
	vector<vector<int>> r(1000000, vector<int>(0));
	rep(ii, n){
		cin >> s;
		int a = 0;
		int b = 0;
		int am = 0;
		int bm = 0;
		int sn = s.size();
		rep(i, sn){
			if(s.at(i) == ')'){
				a++;
			}else{
				a--;
			}
			if(s.at(sn-1-i) == '('){
				b++;
			}else{
				b--;
			}
			if(a > am) am = a;
			if(b > bm) bm = b;
		}
		if(bm - am > 0){
			l.at(am).push_back(bm);
		}else{
			r.at(bm).push_back(am);
		}
	}
	rep(i, 1000000){
		sort(l.at(i).begin(), l.at(i).end());
		reverse(l.at(i).begin(), l.at(i).end());
	}
	rep(i, 1000000){
		sort(r.at(i).begin(), r.at(i).end());
		reverse(r.at(i).begin(), r.at(i).end());
	}
	int suml = 0;
	int sumr = 0;
	int fl = 0;
	int fr = 0;
	rep(i, 1000000){
		rep(j, l.at(i).size()){
			suml -= i;
			if(suml < 0){
				fl = 1;
				break;
			}
			suml += l.at(i).at(j);
		}
		if(fl == 1) break;
	}
	rep(i, 1000000){
		rep(j, r.at(i).size()){
			sumr -= i;
			if(sumr < 0){
				fr = 1;
				break;
			}
			sumr += r.at(i).at(j);
		}
		if(fr == 1) break;
	}
	if(fl == 1 || fr == 1 || suml != sumr){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    RSORT(a);
    int sum1 = 0, sum2 = 0;
    rep(i, n) {
        if (i%2==0) sum1 += a[i];
        else sum2 += a[i];
    }
    cout << (sum1-sum2) << endl;
    return 0;
}


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

int main(){
	int a,b;
	while(cin >> a >> b){
		int sum; sum = a + b;
		int cnt = 0;
		while(sum!=0){
		sum /=10;
		cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

#define endl '\n'
//#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a[32] {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};
    int k;
    cin >> k;
    cout << a[k-1];

    return 0;
}


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

int main () {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  for (int i = 0; i < n; i++) {
    int x = a.at(i), j = i-1;
    while (j >= 0 && a.at(j) > x) {
      a.at(j+1) = a.at(j);
      j--;
    }
    a.at(j+1) = x;
    for (int i = 0; i < n; i++) {
      if (i == n-1) cout << a.at(i) << endl;
      else cout << a.at(i) << ' ';
    }
  }
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

ll a[100005];
ll v[200005];
ll pref[100005];

int main() {
	ll n, m;
	scanf("%lld%lld", &n, &m);
	for (int i=0 ; i<n ; i++) {
		scanf("%lld", a+i);
		v[a[i]]++;
	}
	sort(a, a+n);
	reverse(a, a+n);
	for (int i=200004 ; i>=0 ; i--) {
		v[i] += v[i+1];
	}
	//cout <<"v["<<0<<"] = "<<v[0]<<endl;
	ll pos = 0;
	ll jump = 1<<20;
	ll cnt;
	while (jump/=2) {
		//cout <<"pos = "<<pos<<endl;
		ll x = pos + jump;
		if (x >= 200005) continue;
		cnt = 0;
		for (int i=0 ; i<n ; i++) {
			//cout <<"cnt = "<<cnt<<endl;
			//cout <<":   "<<x-a[i]<<endl;
			cnt += v[max(0LL, x-a[i])];
		}
		//cout <<"x = "<<x<<"   cnt = "<<cnt<<endl;
		if (cnt >= m) {
			pos = x;
		}
	}
	//pos--;
	//cout <<"pos = "<<pos<<endl;
	cnt = 0;
	pref[0] = a[0];
	for (int i=1 ; i<n ; i++) {
		pref[i] = pref[i-1] + a[i];
	}
	ll sol = 0;
	for (int i=0 ; i<n ; i++) {
		ll x = pos - a[i];
		//cout <<"x = "<<x<<endl;
		if (v[max(0LL, x)]) {
			sol += /*pref[v[x]] + */a[i]*(v[max(0LL,x)]*2) /*- (a[i]>=x)*a[i]*/;
			cnt += v[max(0LL, x)];
		}
		//cout <<"sol = "<<sol<<endl;
	}
	//cout <<"sol = "<<sol<<"   cnt = "<<cnt<<endl;
	sol -= (cnt-m) * pos;
	printf("%lld\n", sol);
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

int main(void){
    char a[4];
    int check = 0;
    scanf("%s",a);

    for(int i=0;i<4;i++){
        if(a[i]==a[i+1]){
            check++;
        }
    }

    if(0 < check){
        printf("Bad\n");
    }else{
        printf("Good\n");
    }


}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

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

    ll N;
    cin >> N;
    vl L(N);
    REP(i, N) cin >> L[i];
    sort(L.begin(), L.end());

    ll res = 0;
    REP(i, N)REP(j, N)REP(k, N){
        if(i<j and j<k and L[i]+L[j]>L[k] and L[i] != L[j] and L[j]!=L[k] and L[k]!=L[i]) res++;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3668
import queue

h, w = map(int, input().split())
maze = [[(False, False, False, False) for _ in range(w)] for _ in range(h)]
inputs = [list(map(lambda x: x == "#", input())) for _ in range(h)]

def bfs(x, y):
    q = queue.Queue()
    visited = [[False for _ in range(w)] for _ in range(h)]
    visited[x][y] = True
    q.put((x, y, 0))

    max_length = 0

    while not q.empty():
        vx, vy, length = q.get()
        if inputs[vx][vy]:
            continue
        max_length = max(max_length, length)
        print(x, y, vx, vy)
        (ue, migi, hidari, shita) = maze[vx][vy]
        if not ue:
            if not visited[vx - 1][vy]:
                visited[vx - 1][vy] = True
                q.put((vx - 1, vy, length + 1))
        if not migi:
            if not visited[vx][vy + 1]:
                visited[vx][vy + 1] = True
                q.put((vx, vy + 1, length + 1))
        if not hidari:
            if not visited[vx][vy - 1]:
                visited[vx][vy - 1] = True
                q.put((vx, vy - 1, length + 1))
        if not shita:
            if not visited[vx + 1][vy]:
                visited[vx + 1][vy] = True
                q.put((vx + 1, vy, length + 1))
    
    return max_length

for x in range(h):
    for y in range(w):
        ue = (x == 0) or inputs[x - 1][y]
        migi = (y == w - 1) or inputs[x][y + 1]
        hidari = (y == 0) or inputs[x][y - 1]
        shita = (x == h - 1) or inputs[x + 1][y]

        maze[x][y] = (ue, migi, hidari, shita)

result = 0

def bfs(x, y):
    q = queue.Queue()
    visited = [[False for _ in range(w)] for _ in range(h)]
    visited[x][y] = True
    q.put((x, y, 0))

    max_length = 0

    while not q.empty():
        vx, vy, length = q.get()
        max_length = max(max_length, length)
        (ue, migi, hidari, shita) = maze[vx][vy]
        if not ue:
            if not visited[vx - 1][vy]:
                visited[vx - 1][vy] = True
                q.put((vx - 1, vy, length + 1))
        if not migi:
            if not visited[vx][vy + 1]:
                visited[vx][vy + 1] = True
                q.put((vx, vy + 1, length + 1))
        if not hidari:
            if not visited[vx][vy - 1]:
                visited[vx][vy - 1] = True
                q.put((vx, vy - 1, length + 1))
        if not shita:
            if not visited[vx + 1][vy]:
                visited[vx + 1][vy] = True
                q.put((vx + 1, vy, length + 1))
    
    return max_length

for x in range(h):
    for y in range(w):
        point = maze[x][y]
        if not inputs[x][y] and sum(point) >= 2:
            result = max(result, bfs(x, y))

print(result)


Measured memory_bytes: 4020
#include<iostream>

using namespace std;

int main(){
    int a,b,c,d,N;

    cin>>N;
    a=N/1000;
    b=(N/100)%10;
    c=(N/10)%10;
    d=N%10;

    if(a==b&&b==c||b==c&&c==d){
        cout<<"Yes"<<endl;
    }

    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
// 6/28 バーチャル参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

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

    priority_queue<int> p, q;
    rep(i, N) p.push(A[i]);
    // sort(A.begin(), A.end(), greater<int>());
    
    // 最初の１個は特殊扱い
    int first = p.top();
    p.pop();
    // q.push(A[0]);
    q.push(first);

    // 次から点数を数えていく。
    // qから最大を１つ取り出し、加点する。
    // pの最大をqに2つ加える。
    ll res = 0;
    while (!p.empty()) {
        int next = p.top();
        p.pop();

        int mx = q.top();
        q.pop();
        q.push(next);
        q.push(next);

        res += mx;
    }

    cout << res << endl;
}

Measured memory_bytes: 6416
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  
  vector<vector<char>> data(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> data.at(i).at(j);
    }
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (data.at(i).at(j) == '#'){
        break;
      }
      else if (j == W-1){
        for (int k = 0; k < W; k++) {
          data.at(i).at(k) = ' ';
        }
      }
    }
  }
  
  for (int j = 0; j < W; j++) {
    for (int i = 0; i < H; i++) {
      if (data.at(i).at(j) == '#'){
        break;
      }
      else if (i == H-1){
        for (int k = 0; k < H; k++) {
          data.at(k).at(j) = ' ';
        }
      }
    }
  }
  
  int A = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (data.at(i).at(j) != ' '){
        cout << data.at(i).at(j);
        A++;
      }
      if (j == W-1 && A != 0){
          cout << endl;
      }
    }
    A = 0;
  }
}
  
          
        
       

Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int check(char *s,int sl){
	rep(i,sl/2){
		if(s[i]!=s[sl/2+i]){
			return 0;
		}
	}
	return 1;
}


int main(){
	
	char s[200];
	scanf("%s",&s);
	int sl=0;
	rep(i,200){
		if(int(s[i])>=97 && int(s[i])<=122){
			sl++;
		}else{
			break;
		}
	}
	while(1){
		s[sl-1]=1;
		sl-=1;
		s[sl-1]=1;
		sl-=1;
		if(check(s,sl)){
			cout<<sl<<endl;
			return 0;
		}else{
			//cout<<s<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n), cnt(n+1, 0);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) cnt[a[i]]++;
    
    long long ans = 0;
    for(int i=1;i<=n;i++){
        ans += (long long) cnt[i]*(cnt[i]-1) / 2;
    }
    
    for(int k=0;k<n;k++){
        long long c = cnt[a[k]];
        long long t = ans;
        t += (c-1)*(c-2) / 2 - c*(c-1)/2;
        cout << t << endl;
    }
    
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main(){
  char s[100001];
  cin >> s;
  int n=strlen(s);
  int r=0,l=0,k;
  int t[n];
  rep(i,n){
      t[i]=0;
  }
  rep(i,n-1){
    if(i%2==0)l++;
    else r++;
	if(s[i]=='R'&&s[i+1]=='L'){
        k=i;
    }
    if(s[i]=='L'&&s[i+1]=='R'){
      if(k%2==0)t[k]=l,t[k+1]=r;
      else t[k]=r,t[k+1]=l;
      l=0;
      r=0;
    }
  }
  if((n-1)%2==0)l++;
  else r++;
  if(k%2==0)t[k]=l,t[k+1]=r;
  else t[k]=r,t[k+1]=l;
  rep(i,n)cout << t[i] << " ";
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int num[201000];
int N, M;
int A[201000];
int B = 500;
int BAN[201000];
int ZERO[200000];
int RANGEBAN[201000];
int L;

void f(int l, int r, int val) {
    chmin(r, N);
    chmax(l, 0);
    for(int i = 0; i < L; i++) {
        int nowl = i * B;
        int nowr = (i+1) * B;
        if(l <= nowl and nowr <= r) {
            RANGEBAN[i] += val;
            continue;
        }
        if(nowl > r or nowr < l) continue;
        for(int j = nowl; j < nowr; j++) {
            if(l <= j and j < r) {
                if(BAN[j] == 0) ZERO[i]--;
                BAN[j] += val;
                if(BAN[j] == 0) ZERO[i]++;
            }
        }
    }
}

int main() {
    cin >> N >> M;
    L = (N + B - 1) / B;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
        num[A[i]]++;
    }
    for(int i = 0; i < N; i++) {
        ZERO[i/B]++;
    }
    for(int i = 0; i < N; i++) {
        f(i + 1 - num[i], i + 1, 1);
    }
    for(int t = 0; t < M; t++) {
        int X, Y;
        cin >> X >> Y;
        X--;
        Y--;
        f(A[X] + 1 - num[A[X]], A[X] + 1, -1);
        num[A[X]]--;
        f(A[X] + 1 - num[A[X]], A[X] + 1, 1);
        f(Y + 1 - num[Y], Y + 1, -1);
        num[Y]++;
        f(Y + 1 - num[Y], Y + 1, 1);
        A[X] = Y;
        int ans = 0;
        for(int i = 0; i < L; i++) {
            if(RANGEBAN[i] == 0) ans += ZERO[i];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

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

	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = scan.nextInt();
	int d = scan.nextInt();
	int diff = 0;
	
	/* aliceが早い */
	if(a < c){
	    diff = Math.min(b-c,d-c);
	}
	/* bobが早い */
	else if(c < a){
	    diff = Math.min(b-a,d-a);
	}
	/* 同時に押した */
	else{
	    diff = Math.min(b,d)-a;
	}

	if(diff < 0){
	    System.out.println(0);
	}else{
	    System.out.println(diff);
	}
    }
}


Measured memory_bytes: 21972
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================
int n;
vi D;
vvi M;

void print() {
	REP3(i, 1, n) {
		cout << i << " " << ((D[i] == INF) ? -1 : D[i]) << "\n";
	}
}

void antBfs() {
	D[1] = 0;
	queue<int> q;
	q.push(1);

	int u;
	while (!q.empty()) {
		u = q.front(); q.pop();
		REP3(i, 1, n) {
			if (M[u][i] == 0) continue;
			if (D[i] != INF) continue;
			D[i] = D[u] + 1;
			q.push(i);
		}
	}

	print();
}

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

	cin >> n;

	D.resize(n + 1, INF);
	M.resize(n + 1, vi(n + 1));

	int u, k, v;
	REP3(i, 1, n) {
		cin >> u >> k;
		REP3(j, 1, k) {
			cin >> v;
			M[u][v] = 1;
		}
	}

	antBfs();
	return 0;
}

Measured memory_bytes: 3176
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char s[99],t[99];
ll sn,tn;

void f(ll p){
	char*ss=s+p;
	rep(i,0,tn)if(ss[i]!='?'&&ss[i]!=t[i])return;
	rep(i,0,p)putchar(s[i]=='?'?'a':s[i]);
	printf("%s",t);
	rep(i,p+tn,sn)putchar(s[i]=='?'?'a':s[i]);
	exit(0);
}

int main(){
	scanf("%s%s",s,t);
	sn=strlen(s);
	tn=strlen(t);
	for(ll p=sn-tn;p>=0;p--)f(p);
	puts("UNRESTORABLE");
}

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

int main() {
	string s,p;
	
	cin>>s>>p;
	int l = p.length();
	int inc = 0;

	for(int i=0;i<l;++i){
		if(s.find(p) != string::npos){inc = 1;break;}
		
		s = s[s.length()-1] + s.substr(0,s.length()-1);
	}
	
	cout<<(inc?"Yes":"No")<<endl;
	
}

Measured memory_bytes: 1192
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

class SegmentTree {
    size_t sz_, rsz_;
    vector<ll> v_;

    int construct(size_t idx) {
        if (idx >= sz_-1) return v_[idx];
        return v_[idx] = max(construct(2*idx+1), construct(2*idx+2));
    }

    ll query(size_t a, size_t b, size_t k, size_t l, size_t r) {
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return v_[k];
        size_t mid = (l+r) / 2;
        ll lv = query(a, b, 2*k+1, l, mid);
        ll rv = query(a, b, 2*k+2, mid, r);
        return max(lv, rv);
    }

public:
    SegmentTree(size_t n): rsz_(n) {
        sz_ = 1;
        while (sz_ < rsz_) sz_ *= 2;
        v_.resize(2*sz_ - 1, 0);
    }

    SegmentTree(vector<ll> &v): rsz_(v.size()) {
        sz_ = 1;
        while (sz_ < rsz_) sz_ *= 2;
        v_.resize(2*sz_ - 1, 0);
        for (size_t i = 0; i < rsz_; i++) {
            v_[sz_-1+i] = v[i];
        }
        (void)construct(0);
    }

    // return min value in [a, b)
    ll query(size_t a, size_t b) {
        return query(a, b, 0, 0, sz_);
    }

    void update(size_t idx, ll k) {
        idx += sz_-1;
        v_[idx] = k;
        while (idx > 0) {
            idx = (idx - 1) / 2;
            v_[idx] = max(v_[2*idx+1], v_[2*idx+2]);
        }
    }

    void print() {
        size_t vsz = v_.size();
        for(size_t i = 0; i < vsz; i++) {
            cout << v_[i] << " ";
        }
        cout << endl;
    }

};

int N;
ll h[200010], a[200010];

void solve()
{
    ll hm = 0;
    REP (i, N) hm = max(hm, h[i]);
    SegmentTree st(hm+1);
    REP (i, N) {
        ll val = max(st.query(h[i], h[i]+1), st.query(0, h[i])+a[i]);
        st.update(h[i], val);
    }
    cout << st.query(0, hm+1) << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP (i, N) cin >> h[i];
    REP (i, N) cin >> a[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 7552
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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

ll gcd(ll a,ll b) {if(a%b==0) return(b); else return(gcd(b,a%b));}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll A,B,C,D; cin>>A>>B>>C>>D;
  
  ll ans=B-A+1;
  
  cout<<ans-(B/C-(A-1)/C+B/D-(A-1)/D-(B/lcm(C,D)-(A-1)/lcm(C,D)))<<'\n';
  
         
  return 0;
}


Measured memory_bytes: 3636
#include "iostream"
#include "vector"
#include "algorithm"
#include "set"


using namespace std;

long long gcd(long long a,long long b){
    if(b==0) return a;
    return gcd(b,a%b);
}

const int N = 1e6+7;
bool p[N];


int main(){
    long long  a,b,d,i;
    cin>>a>>b;

    d = gcd(a,b);


    /*

    for(i=1;i*i<=d;i++){
        if(i*i==d) res.push_back(i);
        else if(d%i==0) {
            res.push_back(i);
            res.push_back(d/i);
        }
    }

    */
    for(i=2;i<N;i++){
        if(!p[i]){
            int t = i+i;
            while(t<N) {
                if (!p[t]) p[t] = true;
                t += i;
            }
        }
    }


    long long res = 1,c,td;
    for(i=2;i*i<=d;i++){
        if(!p[i] && d%i==0){
            res ++;
            while(d%i==0) {
                d /= i;
            }
        }
    }
    if(d>1) res++;

    cout<<res;

    return 0;
}



Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
#if !defined(ONLINE_JUDGE)
#include "prettyprint/prettyprint.hpp"
#endif//*/

using namespace std;
typedef long long ll;

#define all(x) x.begin(), x.end()

template<class Container> istream& operator>> (istream &in, vector<Container> &c) {for(auto &x :c) in >> x; return in; }
template<class A, class B> istream& operator>> (istream &in, pair<A, B> &c) {in >> c.first >> c.second; return in; }
template<class Container> ll gcd(Container &a) { auto g = *a.begin(); for(auto &x : a) g = __gcd(g, x); return g; }
template<typename T> T Min(const T &a){ return a; }
template<typename T, typename ...Args> T Min(const T &a, const Args&... args) { T b = Min(args...); return (a < b ? a : b);}
template<typename T> T Max(const T &a) { return a; }
template<typename T, typename ...Args> T Max(const T &a, const Args&... args) { T b = Max(args...); return (a > b ? a : b); }
template<typename T> T gcd(const T &a){ return a; }


int main()
{
    int t = 1;
    while(t--)
    {
        int n; cin >> n;
        vector<int> a(n + 1);
        for(int i = 1; i <= n; i++) cin >> a[i];
        map<int, vector<int>> f;
        map<int, vector<int>> s;
        for(int i = 1; i <= n; i++)
        {
            f[a[i] + i].push_back(i);
            s[i - a[i]].push_back(i);
        }
        ll answer = 0;
        for(int i = 1; i <= n; i++)
        {
            int l = 0, r = s[a[i] + i].size();
            while(r - l > 1)
            {
                int mid = (r + l)/2;
                if(s[a[i] + i][mid] <= i) l = mid;
                else r = mid;
            }
            if(!s[a[i] + i].empty() && s[a[i] + i][l] > i) r = l;
            if(r < s[a[i] + i].size())
            {
                answer += (int)s[a[i] + i].size() - r;
            }
            l = 0, r = f[i - a[i]].size();
            while(r - l > 1)
            {
                int mid = (r + l)/2;
                if(f[i - a[i]][mid] <= i) l = mid;
                else r = mid;
            }
            if(!f[i - a[i]].empty() && f[i - a[i]][l] > i) r = l;
            if(r < f[i - a[i]].size())
            {
                answer += (int)f[i - a[i]].size() - r;
            }
        } cout << answer;

    }
}

Measured memory_bytes: 72308
def main () :

    M,D = map(int,input().split())

    if (D <= 10) :
        print("0")
        return
    
    count = 0
    for m in range(1,M+1) :
        for d in range(11, D+1) :
            str_d = str(d)
            d1 = int(str_d[0])
            d10 = int(str_d[1])

            if (d1 < 2 or d10 < 2) :
                continue

            if (m == d1 * d10) :
                count += 1
    
    print(count)






main()



Measured memory_bytes: 3060
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=200005;
int n,h,w;
set<int>s[maxn];

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d%d",&h,&w,&n);
	REP(i,w)s[h+1].insert(i);
	REP(i,n){
		int x,y;
		scanf("%d%d",&x,&y);
		s[x].insert(y);
	}
	int mx=1;
	REP(i,h){
		if(!s[i+1].empty()&&(*s[i+1].begin()<=mx)){
			printf("%d\n",i);
			return 0;
		}
		if(mx+1<=w&&!s[i+1].count(mx+1))mx++;
	}
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 28416
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B,C;
  string ans = "No";
  cin >> A>> B;
  for (int i=1; i<4; i++){
    if (A*B*i %2 == 1){
        ans = "Yes"; 
    }
  }
  cout << ans << endl;
}

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

int main() {
    int n;
	scanf("%d",&n);
	int dp[2][3]; memset(dp,0,sizeof(dp));
	int a,b,c;
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&a,&b,&c);
		dp[1][0]=max(dp[0][1],dp[0][2])+a;
		dp[1][1]=max(dp[0][0],dp[0][2])+b;
		dp[1][2]=max(dp[0][0],dp[0][1])+c;
		dp[0][0]=dp[1][0];
		dp[0][1]=dp[1][1];
		dp[0][2]=dp[1][2];
	}
	printf("%d",max(dp[0][0],max(dp[0][1],dp[0][2])));
}

Measured memory_bytes: 256
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

string bin(int64 n){
    string s = "";
    while(n>0){
        string b = to_string(n%2);
        s = b+s;
        n>>=1;
    }
    return s;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 N,K;
    cin >> N >> K;
    vector<int64> A(N);
    REP(i,N) cin >> A[i];

    vector<int64> cumsum(N+1,0);
    REP(i,N){
        cumsum[i+1] = cumsum[i];
        cumsum[i+1] += A[i];
    }

    const int bit_length = 41; //log2(10^9 * 1000) < 40
    vector<vector<bool>> bits;
    REP(l,N){
        for(int r=l+1;r<=N;r++){
            int64 S = cumsum[r] - cumsum[l];
            vector<bool> tmp(bit_length, false);
            int i = 0;
            while(S){
                tmp[i] = S&1;
                S>>=1;
                i++;
            }
            bits.emplace_back(tmp);
        }
    }
    vector<int> bits_cnt(bit_length, 0);
    for(auto bit_:bits){
        REP(i,bit_length){
            bits_cnt[i] += bit_[i];
        }
    }

    int64 ans=0;
    vector<bool> removed(bits.size() , false);
    for(int i=bit_length-1; i>=0; i--){ //上から採用する
        if(bits_cnt[i] >= K){
            ans += pow(2,i);
            REP(b,bits.size()){
                if(not bits[b][i] & not removed[b]){ //使えないやつの排除
                    removed[b] = true;
                    REP(j,bit_length){
                        bits_cnt[j] -= bits[b][j];
                    }
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 36356
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

ll dp[100005];

int main()
{
    ll n;
    cin >> n;
    ll r = 100005;
    rep(i, r){
        dp[i] = INF;
    }
    dp[0] = 0;

    reps(i, 100000){
        dp[i] = min(dp[i], dp[i-1]+1);
        int p6 = 1;
        while(pow(6, p6) <= i){
            ll tmp0 = i-pow(6, p6);
            dp[i] = min(dp[i], dp[tmp0]+1);
            p6++;
        }
        int p9 = 1;
        while(pow(9, p9) <= i){
            ll tmp1 = i-pow(9, p9);
            dp[i] = min(dp[i], dp[tmp1]+1);
            p9++;
        }
    }
    cout << dp[n];
}

Measured memory_bytes: 1280
#include <algorithm>
#include <stdio.h>
using namespace std;
int main(){
    bool big=true,less=true;
    int n,a[20],tot=1;
    scanf("%d%d",&n,&a[0]);
    for(int i=1;i<n;i++){
        scanf("%d",&a[i]);
        big&=a[i]<a[i-1];
        less&=a[i]>a[i-1];
        tot*=i;
    }
    tot*=n;
    for(int i=1;i<tot;i++)next_permutation(a,a+n);
    if(!less){
        printf("%d",a[0]);
        for(int i=1;i<n;i++)printf(" %d",a[i]);
        printf("\n");
    }
    next_permutation(a,a+n);
    printf("%d",a[0]);
    for(int i=1;i<n;i++)printf(" %d",a[i]);
    printf("\n");
    if(!big){
        next_permutation(a,a+n);
        printf("%d",a[0]);
        for(int i=1;i<n;i++)printf(" %d",a[i]);
        printf("\n");
    }
}


Measured memory_bytes: 2756
#!/usr/bin/env python3
n = int(input())
h = list(map(int, input().split()))
streak = 0
history = []
for i in range(n-1):
    if h[i] >= h[i+1]:
        streak += 1
    else:
        history.append(streak)
        streak = 0
history.append(streak)
print(max(history))

Measured memory_bytes: 14224
import java.util.*;

class Main {
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int cnt = 0;
      int step = 0;
      String S = sc.next();
      String[] a = new String[4];
      int[] b = new int[4];
            
      for(int i=0; i<S.length(); i++) {
        if(i==0) {
        	a[0] = S.substring(i,i+1);
        	b[0] = b[0] + 1;
        } else {
        	if(S.substring(i,i+1).equals(a[0])) {
        		b[0] = b[0] + 1;
        	} 
        	else if (a[1]==null) {
        		a[1] = S.substring(i,i+1);
        		b[1] = 1;
        	}
        	else if (S.substring(i,i+1).equals(a[1])) {
        		b[1] = b[1] + 1;
        	}
        }
      }
      
      if(b[0]==2 && b[1]==2) {
    	  System.out.print("Yes");
      } else {
    	  System.out.print("No");
      }
  }  
}

Measured memory_bytes: 23764
// "static void main" must be defined in a public class.
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        //要素数
        long n = str.length()-1;
        //最終的な合計を格納する値
        long total = 0;
        String hi = new String();
        
        //System.out.println(n);
        //ビット全探索で探索を行う
        for(long i = 0; i < Math.pow(2,n); i++){
            //System.out.println(i);
            String ans = new String();
            hi = new String();
            for(int j = 0; j <= n; j++){
                ans += Character.toString(str.charAt(j));

                //+を挟むタイミングでans文字列に格納してある数だけ合計に足す
                if((1 & i >> j) == 1){
                    total += Long.parseLong(ans);
                    //System.out.println(ans);
                    hi += (ans + "+");
                    ans = new String();
                    }
                }
            hi += (ans);
            ///System.out.println(hi);
            //System.out.println(ans);
            total += Long.parseLong(ans);
            }
            System.out.println(total);
        }
        
    }

Measured memory_bytes: 24276
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <time.h>
#define ll long long
#define mp(a,b) make_pair(a,b)
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define ss(s) scanf("%s",&s)
#define pi(n) printf("%d\n",n)
#define pl(n) printf("%lld\n",n)
#define newline cout << endl;
using namespace std;

int main(){
  clock_t tStart = clock();
  ll n; sl(n);
  if(n%2==0) pl(n);
  else pl(n*2);
  //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, K;
    cin >> N >> K;

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, k, a[2100];

    cin >> n >> k;
    REP(i, n)
    cin >> a[i];

    ll ans = 0;
    REP(i, n)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (a[i] > a[j])
                (ans += 1) %= MOD;
        }
    }

    (ans *= k) %= MOD;

    ll m = k - 1;
    ll mm = m * (m + 1) / 2;
    mm %= MOD;

    REP(i, n)
    {
        int t = 0;
        REP(j, n)
        {
            if (a[j] < a[i])
                t++;
        }

        ans += (ll)t * mm % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();
    println!(
        "{}{}{}",
        s.chars().nth(0).unwrap(),
        s.len() - 2,
        s.chars().last().unwrap()
    );
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include<cmath>
#include<vector>
#include<tuple>
#include <ctime>
#include<algorithm>
#include <initializer_list>
#include <cstring> 
#include <queue>

using namespace std;
 
#define tii tuple<int,int>
#define vi vector<int>
#define vii vector<vi>
#define ll long long
#define vl vector<ll>
#define vll vector<vl>
 
#define mymod 1000000007
#define mx 99999999
#define mn -99999999
#define sz 200002

ll power(ll a, ll b, ll p)
{
    if(a<2)
    return a;
    ll ans = 1;
    while(b)
    {
        if(b%2)
        {
            ans *= a;
            ans %= p;
        }
        b = b/2;
        a = (a*a)%p;
    }
    return ans;
}

ll mgcd(ll a, ll b)
{
    if(a==0)
        return b;
    return mgcd(b%a,a);
}

int main() {
    clock_t tstart = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // Start
    int n;
    cin>>n;
    cout<< (n*(n+1))/2;
    // cout<<"\n\nTotal Time Taken : "<<(double)(-tstart + clock())/CLOCKS_PER_SEC<<"sec\n\n";
    return 0;
}
 


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

#define ll long long
int main() {
  ll K;
  cin >> K;
  
  int count = 1;
  int temp = 7;
  int add = 7;
  while(count <= K) {
    
    if (temp % K == 0) {
      cout << count << endl;
      return 0;
    }
    
    count++;
    add *= 10;
    add %= K;
    temp += add;
    temp %= K;
  }
  
  cout << -1 << endl;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

#define N 105
#define K 100'005

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

  auto a = new int32_t[N];
  for (int32_t i = 0; i < n; ++i) {
    cin >> a[i];
  }

  auto dp = new bool[K];
  for (int32_t i = 0; i <= k; ++i) {
    dp[i] = false;
    for (int32_t j = 0; j < n; ++j) {
      if (a[j] > i) {
        continue;
      }
      if (!dp[i-a[j]]) {
        dp[i] = true;
        break;
      }
    }
  }

  if (dp[k]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
}


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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long N;
	scanf("%lld",&N);
	long long K;
	scanf("%lld",&K);
	std::vector<long long> p(N);
	for(ll i = 0 ; i < N ; i++){
		scanf("%lld",&p[i]);
	}

	vector<double> exp(N);
	for (ll i = 0; i < N; ++i)
	{
		exp[i] = static_cast<double>(1 + p[i]) / 2.0;
	}
	double max_sum = 0;
	double sum = 0;
	for (ll k = 0; k < K; ++k)
	{
		sum += exp[k];
	}
	max_sum = sum;
	for (ll i = K; i < N; ++i)
	{
		sum -= exp[i - K];
		sum += exp[i];
		max_sum = max(max_sum, sum);
	}
	printf("%.7f\n", max_sum);

	return 0;
}


Measured memory_bytes: 3328
#include <cstdio>

using namespace std;

int a[10];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);// don't forget &
    for (int i = 1; i <= n; i++) {
        a[i] = -1;
    }
    bool f = true;
    while (m--) {
        int x, y;
        scanf("%d%d", &x, &y);// don't forget &
        if (a[x] != -1 && a[x] != y) {
            f = false;
            continue;
        }
        a[x] = y;
    }
    if (n != 1 && a[1] == 0) {
        f = false;
    }
    if (!f) {
        puts("-1");
    }else {
        int first = 1;
        if (n == 1) {
            first = 0;
        }
        for (int i = 1; i <= n; i++) {
            if (a[i] == -1) {
                a[i] = first;
            }
            first = 0;
            printf("%d", a[i]);
        }
    }
    
    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int):

    if N % 2 == 1:
        print(0)
    else:
        ans = N // 10
        for i in range(1, 100000):
            tmp = N // (10 * (5**i))
            if tmp == 0:
                break
            ans += tmp
        print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#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;
typedef long long ll;

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	int ans = (n + max(h, w) - 1) / max(h, w);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384