akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations, permutations
from math import sqrt, factorial


def main():
    N = int(input())
    locations = list()
    for _ in range(N):
        x, y = list(map(int, input().split(' ')))
        locations.append((x, y))
    # Calculate distance between two towns
    d = [[0 for _ in range(N)] for _ in range(N)]
    for edge in combinations(range(N), 2):
        from_town = edge[0]
        to_town = edge[1]
        from_x, from_y = locations[from_town]
        to_x, to_y = locations[to_town]
        d[from_town][to_town] = sqrt((from_x - to_x)**2 + (from_y - to_y)**2)
        d[to_town][from_town] = d[from_town][to_town]
    # Calculate total distance of each route
    route_d_sum = 0
    for route in permutations(range(N), N):
        route_d = 0
        for i in range(N - 1):
            route_d += d[route[i]][route[i + 1]]
        route_d_sum += route_d
    # Calculate average
    print(route_d_sum / factorial(N))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++) cin >> h[i];

    int m=0,c=0;
    for(int i=1;i<n;i++){
        if(h[i-1]>=h[i]){
            c++;
            m = max(m,c);
            //cout << m << endl;
        }else{
            c=0;
        } 
    }

    cout << m << endl;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n,m;
  cin >> n >> m;
  vi k(n);
  vvi a(n,vi(m,0));
  rep(i,n){
    cin >> k.at(i);
    rep(j,k.at(i)){
      cin >> a.at(i).at(j);
    }
  }
  bool like;
  int answer = 0;
  rep(i,m){
    like = false;
    rep(j,n){
      rep(l,k.at(j)){
        if(a.at(j).at(l) == i+1){
          like = true;
          break;
        }
        like = false;
      }
      if(!like) break;
    }
    if(like) answer++;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


////////////////////////////////////////////////////////////////////////////////////////
int main(){
    
    int n,m;
    cin >> n >> m;

    if (n == m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>

const int maxn=1e5+5;
int n,m,f[maxn],deg[maxn],fre[maxn];
vector<int> ad[maxn];
/// tao dinh ao noi dc voi tat ca cac dinh khac => tim dg di dai nhat tu dinh day den 1 dinh nao do
void DFS(int u)
{
    fre[u]=1;
    for(auto &v:ad[u]) if(!fre[v])
    {
        f[v]=max(f[v],f[u]+1);
        deg[v]--;
        if(deg[v]==0)
        {
            DFS(v);
        }
    }
}

main()
{
    //freopen("test.inp","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>m;
    forinc(i,1,m)
    {
        int u,v;
        cin>>u>>v;
        ad[u].push_back(v);
        deg[v]++;
    }
    forinc(i,1,n) if(!fre[i]&&deg[i]==0) DFS(i);
    cout<<*max_element(f+1,f+n+1);
}


Measured memory_bytes: 9984
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>


const char* YesNo(bool b)
{
	if (b)
	{
		return "Yes";
	}
	else
	{
		return "No";
	}
}

int main()
{
	int H, N;
	std::cin >> H >> N;
	std::vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		std::cin >> A[i];
	}

	bool ans = std::accumulate(begin(A), end(A), 0) >= H;
	std::cout << YesNo(ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;
 
int main(){
    int n,m;
    int d[300][4];
    int dp[3][301];
    string tmp;
 
    while(cin >> n >> m) {
        // input
        for(int i = 0; i < n; i++) {
            cin.ignore();
            getline(cin, tmp);
            for(int j = 0; j < 4; j++) cin >> d[i][j];
        }
        // init
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j <= m; j++) dp[i][j] = 0;
        }
    
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < 3; j++) {
                dp[j][d[i][0]] = max(dp[j][d[i][0]], d[i][j+1]);
            }
        }
        // dp
        for(int i = 0; i < 3; i++) {
            for(int j = 1; j <= m; j++) {
                for(int k = 0; k <= j/2; k++) {
                    dp[i][j] = max(dp[i][j], dp[i][k]+dp[i][j-k]);
                }
            }
        }
    
        int ans = 0;
        for(int i = 0; i < 3; i++) {
            ans = max(ans, dp[i][m]);
        }
        cout << ans << endl;
    }
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

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

int main()
{
    int H, W; cin >> H >> W;
    int c[H][W], dist[H][W];
    int Bn = 0;
    rep(i,H){
        rep(j,W){
            char cij; cin >> cij;
            if(cij == '.') c[i][j] = 1;
            else if(cij == '#') c[i][j] = 0, ++Bn;
            dist[i][j] = -1;
        }
    }
    dist[0][0] = 0;
    queue<P> q;
    q.push(make_pair(0, 0));
    while(!q.empty()){
        P u = q.front(); q.pop();
        rep(i,4){
            P v = make_pair(u.first+dx[i], u.second+dy[i]);
            if(v.first>=0 && v.first<H && v.second>=0 && v.second<W){
                if(dist[v.first][v.second] == -1 && c[v.first][v.second] == 1){
                    dist[v.first][v.second] = dist[u.first][u.second]+1;
                    q.push(v);
                }
            }
        }
    }
    if(dist[H-1][W-1] == -1) cout << -1 << endl;
    else cout << H*W-Bn-dist[H-1][W-1]-1 << endl;
}

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

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

    int a,b,c;
    cin>>a>>b>>c;
    if(b*c>=a) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);
    map<long, long> zz;
    long i;
    for(i=0; i<n; i++) {
        long a;
        scanf("%ld", &a);
        zz[a]++;
    }

    long cnt=0;
    while( !zz.empty() ) {
        auto it = zz.rbegin();
        long curr=it->first;
        long tmp=1;
        while(tmp<=curr) {
            tmp*=2;
        }
        long p = tmp - curr;
        if(p<curr) {
            auto it2 = zz.find(p);
            if(it2!=zz.end()) {
                if(it2->second==1) {
                    zz.erase(it2);
                }
                else {
                    it2->second --;
                }
                if(it->second==1) {
                    zz.erase(curr);
                }
                else {
                    it->second --;
                }
                cnt++;
                continue;
            }
        }
        else if(p==curr) {
            if(it->second>1) {
                it->second -= 2;
                cnt++;
                continue;
            }
        }
        else {
            return 33;
        }
        zz.erase(curr);
    }
    printf("%ld\n", cnt);

    return 0;
}



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

#define llong long long /*{{{*/
#define ii pair<int, int>
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )

template<typename a> ostream& operator<<(ostream& cout, const vector<a>& b) {
  cout << "[";
  if (len(b)) cout << b[0];
  rep1(i, len(b) - 1) cout << ", " << b[i];
  return cout << "]";
}

template<typename u, typename v> ostream& operator<<(ostream& cout, const pair<u, v> a) {
  return cout << "(" << a.xx <<", " << a.yy << ")";
}/*}}}*/


int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n ;cin >> n;
  if (n == 1) cout << "Hello World";
  else {
    int u, v; cin >> u >> v;
    cout << u + v;
  }
  
  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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 factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    ll ans = 0;
    vector<vector<ll>> nxt(60, vector<ll>(n));
    rep(i, n) cin >> nxt[0][i], nxt[0][i]--;
    rep1(i, 59) rep(j, n) nxt[i][j] = nxt[i-1][nxt[i-1][j]];
    rep(i, 60) if (k&(1ll<<i)) ans = nxt[i][ans];
    cout << ++ans << endl;
    return 0;
}

Measured memory_bytes: 98748
#include<bits/stdc++.h>
#define ll long long
#define inv2 500000004
using namespace std;
const int maxn=200210,maxm=8000,mod=1000000007;
int jc[maxm+10],ijc[maxm+10];
int f[maxm/2+10][maxm/2+10];
int n,a[maxn],b[maxn];
ll poww(ll x,int y){
    ll ans=1;
    while(y){
    	if(y&1){
    		ans=ans*x%mod;
    	}
    	x=x*x%mod;
    	y>>=1;
    }
    return ans;
}
int C(int n,int m){
	return 1ll*jc[n]*ijc[m]%mod*ijc[n-m]%mod;
}
int main(){
    scanf("%d",&n);
    jc[0]=1;
    for(int i=1;i<=maxm;i++){
    	jc[i]=1ll*jc[i-1]*i%mod;
    }
    ijc[maxm]=poww(jc[maxm],mod-2);
    for(int i=maxm-1;i>=0;i--){
    	ijc[i]=1ll*ijc[i+1]*(i+1)%mod;
    }
    for(int i=1;i<=n;i++){
    	scanf("%d%d",&a[i],&b[i]);
        f[2002-a[i]][2002-b[i]]++;
    }
    for(int i=1;i<=maxm/2+2;i++){
    	for(int j=2;j<=maxm/2+2;j++){
    		f[i][j]=(f[i][j]+(f[i-1][j]+f[i][j-1])%mod)%mod;
    	}       
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=(ans+f[a[i]+2002][b[i]+2002])%mod;
        ans=(ans-C(2*a[i]+2*b[i],2*a[i]))%mod;
    }
    ans=(ans+mod)%mod;
    ans=1ll*inv2*ans%mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 64512
#include <stdio.h>
#define LEN 100005
typedef struct{
  char name[10];
  int t;
}P;
int head,tail,n;
P Q[LEN];

P dequeue()
{
  P x;
  x=Q[head];
  head=(head+1)%LEN; /*リングバッファで一周したら先頭に戻る*/
  return x;
}
int min(int a,int b)
{
  if(a<b)
  {
    return a;
  }
  else
  {
    return b;
  }
}

void enqueue(P x)
{
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

int main()
{
  int c,elaps=0;
  int i,q;
  P u;
  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++)
  {
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  tail = n + 1;
  head = 1;
  while(head != tail)
  {
    u=dequeue();
    c=min(q,u.t);
    u.t-=c;
    elaps += c;
    if(u.t>0)
    {
      enqueue(u);
    }
    else
    {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}


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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<P> graph[100005];
vector<int> color(100005, -2);

void dfs(int p, int c) {
  color[p] = c;
  for(auto e: graph[p]) {
    if (color[e.first] == -2) {
      if ((e.second%2)==0) {
        dfs(e.first, c);
      } else {
        dfs(e.first, -c);
      }
    }
  }
}


signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  rep(i, n-1) {
    int u, v, w; cin >> u >> v >> w;
    graph[u].emplace_back(v, w);
    graph[v].emplace_back(u, w);
  }

  dfs(1, 1);

  for(int i=1; i<=n; i++) {
    if (color[i]==1) {
      cout << 1 << '\n';
    } else {
      cout << 0 << '\n';
    }
  }

}

Measured memory_bytes: 9856
#include <iostream>
#include <vector>

int main() {
    int N; std::cin >> N;
    std::vector<int> a(N);
    for (int i = 0; i < N; ++i) std::cin >> a[i];

    /* 尺取りり法 */
    long long res = 0;
    int right = 0;
    int sum = 0; 
    for (int left = 0; left < N; ++left) {
        while (right < N && ((sum ^ a[right]) == sum + a[right])) {
          sum += a[right];
          ++right; // rightは0~Nまで動く
        }

        if (left == right) ++right;
        else sum -= a[left]; // a[left]を削除(sum ^= a[left]でも可能)

        res += (right - left);
    }

    std::cout << res << std::endl;

    return 0;
}


Measured memory_bytes: 4008
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        LinkedList<int> l = new LinkedList<int>();
        for (int i = 0; i < n; i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            if (s[0] == "insert")
            {
                l.AddFirst(int.Parse(s[1]));
            }
            else if (s[0] == "delete")
            {
                l.Remove(int.Parse(s[1]));
            }
            else if (s[0] == "deleteFirst")
            {
                l.RemoveFirst();
            }
            else if (s[0] == "deleteLast")
            {
                l.RemoveLast();
            }
        }
        int cnt = l.Count;
        for (int i = 0; i < cnt - 1; i++)
        {
            Console.Write("{0} ", l.First.Value);
            l.RemoveFirst();
        }
        Console.WriteLine(l.First.Value);
    }
}


Measured memory_bytes: 71392
//a[i]は、min(b[i],b[i-1])
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  int n;
  cin>>n;
  cout<<n*n*n<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "mydebug.h"
#else
#define debug(...)
#endif
typedef long long ll;typedef unsigned long long ul; typedef vector<ll> vl;

int main() {
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll N, A, B;
  cin >> N>>A >> B;


  ll ap=A%2;
  ll bp=B%2;

  if(ap==bp)
    cout << "Alice" << endl;
  else
    cout << "Borys" << endl;

}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007
ll fac[1000000];
ll finv[1000000];
ll inv[1000000];

void comb_init(){
  fac[0] = 1;
  for(int i=1;i<1000000;i++){
    fac[i] = i*fac[i-1];
    fac[i] %= MOD;
  }
  inv[1] = 1;
  for(int i=2;i<1000000;i++){
    inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
  }
  finv[0] = 1;
  for(int i=1;i<1000000;i++){
    finv[i] = inv[i]*finv[i-1];
    finv[i] %= MOD;
  }
}

ll comb(ll n,ll k){
  ll c = fac[n];
  c *= finv[k];c %= MOD;
  c *= finv[n-k];c %= MOD;
  return c;
}
int main(){
  ll h,w,k;
  cin >> h >> w >> k;
  ll count = 0;
  vector<pair<ll,ll> > ichigo[h];
  string s;
  for(int i=0;i<h;i++){
    cin >> s;
    for(int j=0;j<w;j++){
      if(s[j] == '#'){
        count += 1;
        ichigo[i].push_back(make_pair(j,count));
      }
    }
  }

  ll ans[h][w];
  ll temp = 0;
  for(int i=0;i<h;i++){
    if(ichigo[i].size() == 0) continue;
    for(int j=temp;j<i;j++){
      for(int q=0;q<ichigo[i].size();q++){
        ichigo[j].push_back(ichigo[i][q]);
      }
    }
    temp = i+1;
  }

  if(temp < h){
    for(int j=temp;j<h;j++){
      for(int q=0;q<ichigo[temp-1].size();q++){
        ichigo[j].push_back(ichigo[temp-1][q]);
      }
    }
  }

  ll color;
  ll l,r;

  for(int i=0;i<h;i++){
    l = 0;
    for(int q=0;q<ichigo[i].size();q++){
      r = ichigo[i][q].first;
      color = ichigo[i][q].second;
      for(int j=l;j<r+1;j++){
        ans[i][j] = color;
      }
      l = r+1;
    }
    for(int j=l;j<w;j++){
      ans[i][j] = color;
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }



  return 0;
}


Measured memory_bytes: 3840
#include "atcoder/all"
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using namespace atcoder;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) fixed << setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  dsu d(N);
  REP(i, M) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    d.merge(a, b);
  }
  set<ll> s;
  REP(i, N) s.insert(d.leader(i));
  cout << s.size() - 1 << endl;

  return 0;
}


Measured memory_bytes: 7632
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int dp[100010][2]; //dp[v][下向き]
int n, col[100010], deg[100010], white[100010], cost, ans;
vector<vi> e;

void rec(int c, int p){
	white[c] += col[c];
	vector<pi> a, b;
	
	deg[c] = c != p;
	for(int i : e[c]) if(i != p){
		rec(i, c);
		if(!white[i]) continue;
		deg[c]++;
		white[c] += white[i];
		cost += 2;
	}
	if(!white[c]) return;
	
	for(int i : e[c]) if(i != p && white[i]){
		dp[c][0] = max(dp[c][0], dp[i][0] + (col[c] != deg[c] % 2) - (col[c] != (deg[c] + 1) % 2) + 1);
		dp[c][1] = max(dp[c][1], dp[i][1] + (col[i] != deg[i] % 2) - (col[i] != (deg[i] + 1) % 2) + 1);
		
		a.emplace_back(dp[i][0] + (col[c] != deg[c] % 2) - (col[c] != (deg[c] + 1) % 2) + 1, i);
		b.emplace_back(dp[i][1] + (col[i] != deg[i] % 2) - (col[i] != (deg[i] + 1) % 2) + 1, i);
		
		//if(i == 2) dbg(dp[i][1], (int)(col[i] != deg[i] % 2), col[i] != (deg[i] + 1) % 2);
	}
	if(col[c] != deg[c] % 2) cost++;
	sort(all(a), greater<pi>()); sort(all(b), greater<pi>());
	if(a.size()) ans = max(ans, a[0].first);
	if(b.size()) ans = max(ans, b[0].first);
	
	//dbg(c, a);
	
	rep(i, 2) rep(j, 2) if(i < a.size() && j < b.size() && a[i].second != b[j].second){
		//if(ans < a[i].first + b[j].first) dbg(c, ans, i, j, a[i], b[j])
		ans = max(ans, a[i].first + b[j].first);
	}
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n; e.resize(n);
	rep(i, n - 1){
		int a, b; cin >> a >> b; a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	{
		string s; cin >> s;
		rep(i, n) col[i] = s[i] == 'W';
	}
	rep(i, n) if(col[i]){
		rec(i, i);
		break;
	}
	dbg(cost, ans);
	cout << cost - ans << endl;
	
	return 0;
}

Measured memory_bytes: 23404
#include <iostream>
#include <algorithm>
#include <math.h> 
using namespace std;
int main(){
  int n, m;
  int t[100100];
  int p[110];
  int x[100100];
  int ans[110];
  int total = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> t[i];
    total += t[i];
  }

  cin >> m;
  for(int i = 0; i < m; i++){
    cin >> p[i] >> x[i];
  }
  
  for(int i = 0; i < m; i++){
    ans[i] = total - t[p[i] - 1] + x[i];
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s;
		
		s = sc.next();
		
		sc.close();
		
		int n = s.length();
		
		String ans = "", tmp1, tmp2;
		
		int i = 1, length = n;
		
		while(true) {
			length = n - i;
			ans = s.substring(0,  length);
			if(length % 2 == 0) {
				tmp1 = ans.substring(0, length / 2);
				tmp2 = ans.substring(length / 2, length);
				if(tmp1.equals(tmp2))break;
			}			
			++i;
		}
		
		System.out.println(length);
	}

}


Measured memory_bytes: 22868
n, k = map(int, input().split())
n0 = n//k
ans = pow(n0, 3)
if k%2 == 0:
    # a,b,c全ての余りがk/2のパターン
    r = n%k
    ans += pow(n0+int(n%k>=k//2), 3)
print(ans)


Measured memory_bytes: 9060
import sys
from io import StringIO
import unittest
from collections import Counter

def resolve():
    n, k, q = map(int, input().split())
    a = [int(input()) for _ in range(q)]

    counter = Counter(a)

    for i in range(1, n+1):
        if k - q + counter[i] > 0:
            print('Yes')
        else:
            print('No')


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """6 3 4
3
1
3
2"""
        output = """No
No
Yes
No
No
No"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """6 5 4
3
1
3
2"""
        output = """Yes
Yes
Yes
Yes
Yes
Yes"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """10 13 15
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9"""
        output = """No
No
No
No
Yes
No
No
No
Yes
No"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 14268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{ll to, cost;};
vector<edge> G[100000];
ll d[100000];
const ll INF = 1e18;
void dfs(ll v) {
  if (d[v] == INF) {d[v] = 0;}
  for (ll i = 0; i < G[v].size(); i++) {
    edge e = G[v][i];
    if (d[e.to] == INF) {
      d[e.to] = d[v] + e.cost;
      dfs(e.to);
    }
  }
}
int main() {
  ll N; cin >> N;
  for (ll i = 0; i < N-1; i++) {
    ll a,b,c; cin >> a >> b >> c;
    a--; b--;
    G[a].push_back({b,c}); G[b].push_back({a,c});
  }
  fill(d,d+N, INF);
  ll Q, K; cin >> Q >> K; K--;
  dfs(K);
  for (ll i = 0; i < Q; i++) {
    ll x, y; cin >> x >> y; x--; y--;
    cout << d[x]+d[y] << endl;
  }
}

Measured memory_bytes: 14336
#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;

const int MOD = 100000;
int dp[2][(1<<20)],H,W;
bool CONTINUE[1<<20];
char G[20][20];
/*
dp[(x,y) & 1][column][Is the left is J?] := the number % 10^5
 */

inline void compute(int other){

  dp[0][0] = 1;

  rep(y,H)rep(x,W) {
    int phase = ( x + y * W ) & 1;
    rep(i,(1<<W)) dp[!phase][i] = 0;
    rep(bitmask,(1<<W)){     

      int nbitmask = bitmask;

      if( G[y][x] == 'O' ) goto O;
      if( G[y][x] == 'I' ) goto I;

      // put J
      if( x-1 >= 0 ) nbitmask &= ~(1<<(x-1));
      if( x+1 != W ) nbitmask |= (1<<x);
      ( dp[!phase][nbitmask] += ( dp[phase][bitmask] ) ) %= MOD;
      //if( x != W-1 ) ( dp[!phase][nbitmask][1] += ( dp[phase][bitmask][0] + dp[phase][bitmask][1] ) ) %= MOD;
      //else           ( dp[!phase][nbitmask][0] += ( dp[phase][bitmask][0] + dp[phase][bitmask][1] ) ) %= MOD;
      if( G[y][x] == 'J' ) goto Skip;

    O:;
      // put O
      nbitmask = bitmask;
      nbitmask &= ~(1<<x);
      ( dp[!phase][nbitmask] += dp[phase][bitmask] ) %= MOD;
      /*
      // となりがJでない
      ( dp[!phase][nbitmask][0] += dp[phase][bitmask][0] ) %= MOD;

      // となりがJ
      if( x-1 >= 0 ) {
        nbitmask |= (1<<(x-1));
        ( dp[!phase][nbitmask][0] += dp[phase][bitmask][1] ) %= MOD;
        nbitmask &= (~(1<<(x-1)));
      }
      */
      if( G[y][x] == 'O' ) goto Skip;

    I:;
      // put I
      nbitmask = bitmask;
      nbitmask &= ~(1<<x);
      if( x-1 >= 0 ) nbitmask &= ~(1<<(x-1));
      if( !( ( bitmask>>x ) & 1 ) ) {
        ( dp[!phase][nbitmask] += dp[phase][bitmask] ) %= MOD;
      }
      
    Skip:;
      
    }
  }

  int sum = 0;
  rep(i,(1<<W)) ( sum += dp[(H*W)&1][i] ) %= MOD;

  int total = 1;
  rep(i,other) ( total *= 3 ) %= MOD;
  cout << ( total - sum + MOD ) % MOD << endl;
}

int main(){

  scanf("%d %d",&H,&W);
  int other = 0;
  rep(i,H)rep(j,W){
    cin >> G[i][j];
    other += (G[i][j]=='?');
  }
  compute(other);
  return 0;
}

Measured memory_bytes: 9420
#include <stdio.h>
int main(){
	int a,b,c,d;
	int m,n;
	scanf("%d ",&a);
	scanf("%d ",&b);
	scanf("%d ",&c);
	scanf("%d",&d);
	m=a*b;
	n=c*d;
	if(m>n) printf("%d\n",m);
	else printf("%d\n",n);
	
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N, K;
    cin >> N >> K;
    int res = 0;
    while (N) {
        N /= K;
        res ++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];
//平方根　= sqrt

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

  if (n<=999) {
    cout << "ABC" << endl;
  }
  else {
    cout << "ABD" << endl;
  }
}


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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define int long long
using namespace std;
const int N=2e3+2;
const int inf=1e9+7;
vector<int> adj[N];
int num[N],sum[N],f[N];
string s;
void dfs(int x,int p){
	if(s[x-1]=='1'){
		num[x]=1;
	}
	else{
		num[x]=0;
	}
	sum[x]=0;
	for(int i=0;i<adj[x].size();i++){
		if(adj[x][i]!=p){
			dfs(adj[x][i],x);
			num[x]+=num[adj[x][i]];
			sum[x]+=sum[adj[x][i]]+num[adj[x][i]];	
		}
	}
	bool cac=true;
	for(int i=0;i<adj[x].size();i++){
		if(adj[x][i]!=p){
			if(sum[adj[x][i]]+num[adj[x][i]]>sum[x]/2+f[adj[x][i]]){
				f[x]=f[adj[x][i]]+(sum[x]-sum[adj[x][i]]-num[adj[x][i]]);
				cac=false;
				break;
			}
		}
	}
	if(cac){
		f[x]=sum[x]/2;
	}
}
signed main(){
	int n,i,j,k,l,min1=inf;
	cin>>n>>s;
	for(i=1;i<n;i++){
		cin>>j>>k;
		adj[j].push_back(k);
		adj[k].push_back(j);
	}
	for(i=1;i<=n;i++){
		dfs(i,i);
		if(sum[i]%2){
			continue;
		}
		for(j=0;j<adj[i].size();j++){
			if(sum[adj[i][j]]+num[adj[i][j]]>sum[i]/2+f[adj[i][j]]){
				break;
			}
			if(j==adj[i].size()-1){
				min1=min(min1,sum[i]/2);
			}
		}
	}
	if(min1==inf){
		cout<<-1;
	}
	else{
		cout<<min1;
	}
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
int getGCD(int a,int b){
  if(b == 0){
    return a;
  }else{
    return getGCD(b,a%b);
  }
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  
  int n,x;
  cin >> n >> x;
  int diff[n];
  REP(i,n){
    cin >> diff[i];
    diff[i] = abs(diff[i]-x);
  }
  int gcd = diff[0];
  FOR(i,1,n){
    gcd = getGCD(gcd,diff[i]);
  }
  
  cout << gcd << endl;
  
  return 0;
}


Measured memory_bytes: 3920
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a * n, b) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

const int INF = 1e+9 * 2;
double eps = 1e-10;

int main() {
	int n[128] = {0}, c = 0, maxim = 0;
	while(cin >> n[c++]);
	int cnt[128] = {0};
	for(int i = 0; i < c; ++i)
		cnt[n[i]]++;
		
	for(int i = 0; i <= 100; ++i)
		if(maxim < cnt[i])
			maxim = cnt[i];
	for(int i = 0; i <= 100; ++i)
		if(maxim == cnt[i])
			cout << i << endl;
	
	return 0;
}

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

const int N = 2e5 + 5;

int n, a[N];

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) cin>>a[i];
	sort(a + 1, a + n + 1);
	for(int i = 2; i <= n; i++)
	   if(a[i] == a[i - 1]) {
	   	cout<<"NO"<<endl;
	   	return 0;
	   }
	cout<<"YES"<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	scan(N);
	rep(i,N){
		string X,Y;
		scan(X);scan(Y);
		int dp[1001][1001]={{}};
		rep1(x,X.size()){
			rep1(y,Y.size()){
				int v=dp[x-1][y-1]+(X[x-1]==Y[y-1]);
				if(dp[x-1][y]>v) v=dp[x-1][y];
				if(dp[x][y-1]>v) v=dp[x][y-1];
				dp[x][y]=v;
			}
		}
		prin(dp[X.size()][Y.size()]);
	}
	return 0;
}



Measured memory_bytes: 7076
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n;
  cin>>n;
  char s;
  map<char, LL> mp;
  REP(i, n) {
    cin>>s;
    ++mp[s];
  }

  if(n==1){
    cout<<1<<endl;
    return 0;
  }
  LL ans=1;

  for(auto itr=mp.begin(); itr!=mp.end(); ++itr){
    ans = ans * (itr->second + 1);
    ans %= MOD;
  }
  --ans;
  cout<<ans<<endl;

  return 0;
}


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

class CF2017QBB
{
	static public void Main(string[] args)
	{
		Dictionary<int,int> DDic = new Dictionary<int,int>();
		Dictionary<int,int> TDic = new Dictionary<int,int>();
		int N = int.Parse(Console.ReadLine());
		string[] vals = Console.ReadLine().Split(' ');

		for(int i=0; i < N; i++)
		{
			int D = int.Parse(vals[i]);
			if(DDic.ContainsKey(D))
			{
				DDic[D]++;
			}
			else
			{
				DDic[D] = 1;
			}
		}

		int M = int.Parse(Console.ReadLine());
		vals = Console.ReadLine().Split(' ');
		for(int i=0; i<M; i++)
		{
			int T = int.Parse(vals[i]);
			if(TDic.ContainsKey(T))
			{
				TDic[T]++;
			}
			else
			{
				TDic[T] = 1;
			}
		}
		
		bool ans = true;
		foreach(var t in TDic.Keys)
		{
			if(!DDic.ContainsKey(t))
			{
				ans = false;
				break;
			}
			if(TDic[t] > DDic[t])
			{
				ans = false;
				break;
			}
		}

		if(ans)
			Console.WriteLine("YES");
		else
			Console.WriteLine("NO");
	}
}


Measured memory_bytes: 57608
#include <stdio.h>
#define N 8
#define NOT_FREE 1
#define FREE 0
int A[N][N],row[N],col[N],dops[2*N-1],dneg[2*N-1];
void printBoard(void){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(A[i][j]==1){
	if(row[i]!=j)return; 
     }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }



}
void putQueen(i){
  int j;
  if(i==N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE||dops[i+j]==NOT_FREE||dneg[i-j+N-1]==NOT_FREE)continue;
    row[i]=j;
    col[j]=NOT_FREE;
    dops[i+j]=NOT_FREE;
    dneg[i-j+N-1]=NOT_FREE;
    putQueen(i+1);
    row[i]=FREE;
    col[j]=FREE;
    dops[i+j]=FREE;
    dneg[i-j+N-1]=FREE;
  }
}
/*void printBoard(void){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      printf(".");
    }
    printf("\n");
  }



  }*/
int main(){
  int i,j,k,r,c;
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
    for(j=0;j<N;j++){
      A[i][j]=0;

    }

  }
  for(i=0;i<2*N-1;i++){
    dops[i]=FREE;
    dneg[i]=FREE;
  }

  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d %d",&r,&c);
    A[r][c]=1;
  }
  putQueen(0);

  return 0;
}



Measured memory_bytes: 2108
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(X):
    n500 = X // 500
    n5 = (X % 500) // 5
    ans = 1000 * n500 + 5 * n5
    return ans


if __name__ == "__main__":

    # X
    #
    X = int(input())
    ans = solv(X)

    print(ans)


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    m = max(a)
    ans = 0
    for _ in range(m):
        b = a[:]
        for i in range(n):
            if a[i]:
                if i == 0 or a[i-1] == 0:
                    ans += 1
                b[i] -= 1
        a = b[:]

    print(ans)
        

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""


Measured memory_bytes: 9380
using System;
using System.Linq;

class C
{
	static void Main()
	{
		Func<long[]> read = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
		var h = read();
		var t = read().ToList();
		t.Add(int.MaxValue);
		Console.WriteLine(Enumerable.Range(0, (int)h[0]).Sum(i => Math.Min(h[1], t[i + 1] - t[i])));
	}
}


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

int main() {

    int x;
    cin >> x;
    
    if (x == 30 || x >= 30){
        cout << "Yes" << endl;
    }
    
    else { cout << "No" << endl;
         }
    
    
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vll = vector<ll>;
#define x first
#define y second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define szz(x) (int) (x).size()
#define FOR(i,a,b) for (int i = (a), _for = (b); i < _for; i++)
#define REP(i,n) FOR(i,0,(n))
#define _ << " " <<
const ll MOD = 1000000007ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;
inline ll SUB(ll a, ll b) { return a-b >= 0ll ? a-b : a-b+MOD; }
inline ll ADD(ll a, ll b) { return a+b >= MOD ? a+b-MOD : a+b; }
inline ll MUL(ll a, ll b) { return a*b % MOD; }

int n, W;
ll dp[103][100003];
ll w[103], v[103];


ll f(int i, ll j) {
  if (i == -1) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  return dp[i][j] = max(
    j - w[i] >= 0 ? (v[i] + f(i - 1, j - w[i])) : 0,
    f(i - 1, j)
  );
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(dp, -1, sizeof(ll) * 103 * 100003);

  cin >> n >> W;
  REP(i,n) cin >> w[i] >> v[i];
  cout << f(n-1, W) << endl;
}



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

int A, B;
int main()
{
	cin >> A >> B;
	if ((A + B) % 2 == 0)
	{
		cout << (A + B) / 2 << endl;
	} else
	{
		cout << "IMPOSSIBLE" << endl;
	}

	cin.get();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <list>
#include <set>
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
using namespace std;
using ll = long long;
const int INF = 1e9 + 1;
ll MOD = 1e9+7;
ll dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
ll dy[9] = {-1,  0,  1,-1, 0, 1,-1, 0, 1};

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

    int D, N;
    cin >> D >> N;
    int cnt = 0;
    int step, i = 0;
    if(D == 0){     step = 1;}
    else if(D == 1){     step = 100;}
    else if(D == 2){     step = 10000;}
    while(true){
        i += step;
        if(D==0 && i % 100 != 0){   cnt++;}
        if(D==1 && (i/100) % 100 != 0){   cnt++;}
        if(D==2 && (i/10000) % 100 != 0){   cnt++;}
        if(cnt == N){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a,b,c;
	int temp;
	scanf("%d %d %d",&a,&b,&c);
	if(b<a)
	{
		temp=a;
		a=b;
		b=temp;
	}
	if(c<b)
	{
		temp=b;
		b=c;
		c=temp;
	}
		if(b<a)
	{
		temp=a;
		a=b;
		b=temp;
	}
	printf("%d %d %d\n",a,b,c);
		return 0;
}

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

int main(){
	int a,b,k;
	cin >> a >> b >> k;
	int counts = 0;
	int hani = max(a,b);
	for(int i = hani; i > 0; i--){
		if(a%i == 0 && b%i == 0) counts++;
		if(counts == k){
			cout << i << endl;
			return 0;
		}
		}
}

Measured memory_bytes: 3608
from itertools import permutations

N=int(input())
A=tuple(map(int,input().split()))
B=tuple(map(int,input().split()))
a=[i for i in range(1,N+1)]
tmp=list(permutations(a))
#print(tmp)
x=0
y=0

for i in range(len(tmp)):
    if tmp[i]==A:
        x=i
        break
for i in range(len(tmp)):
    if tmp[i]==B:
        y=i
        break
print(abs(x-y))

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

int main() {
	int a, b;
	char ch;
	bool b_loop = true;
	std::cout << std::setprecision(10);
	std::cout << std::fixed;
	while (b_loop) {
		std::cin >> a >> ch >> b;
		switch (ch) {
		case '?':
			b_loop = false;
			break;
		case '+':
			std::cout << a + b << std::endl;
			break;
		case '-':
			std::cout << a - b << std::endl;
			break;
		case '*':
			std::cout << a * b << std::endl;
			break;
		case '/':
			std::cout << a / b << std::endl;
			break;
		case '%':
			std::cout << a % b << std::endl;
			break;
		}
	}
	return 0;
}

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

using namespace std;

int main() {
	int K, N; cin >> N >> K;
	int h[N];
	for (int i = 0; i < N; i++) cin >> h[i];
	sort(h, h+N);
	// int index = 0;
	int min = h[N-1] - h[0] + 1;
	for (int i = 0; i <= N - K; i++) {
		int dif = h[i+K-1] - h[i];
		if (dif < min) {min = dif;}
	}
	cout << min;
	return 0;
}

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

int main(void){
    // Your code here!
    long long N;cin>>N;
    int ans=0;
    for(int i=1;i<N;i++){
        for(int j=1;i*j<N;j++){
            if(N-i*j>0){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
N, M = map(int, input().split())
if N > M:
  N, M = M, N
if N == 1:
  if M == 1:
    print(1)
  else:
  	print(max(0, M-2))
elif N == 2:
  print(0)
else:
  print((N-2)*(M-2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#ifdef dbg
#include "./printer.hpp"
#else
#define dump(x) void(0)
#endif

#define MOD 1000000007
using namespace std;
#define ll long long
inline long  toInt(string s) {long  v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main(){
  ll n;
  cin >> n;
  for(ll i = 0; i < n; i++){
    ll a,b,c;
    cin >> a >> b >> c;
    ll ma = max(a,b);
    ma = max(ma,c);
    if(a*a + b*b + c*c - ma*ma == ma*ma){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}

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


int main(){
    int N, x, y;
    cin >> N >> x >> y;
    // max
    cout << min(x, y) << " ";
    if (x + y <= N){
        cout << 0 << endl;
    }
    else{
        cout << x + y - N << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast std::ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
using namespace std;

void solve(){
    fast
    int h,w,n;
    cin>>h>>w;
    cin>>n;
    vector<int>v(n+1);
    for(int i=1;i<=n;i++)
         cin>>v[i];
    //sort(v.begin(),v.end());
    int A[h][w];
    int k=1;
    bool b=true;
    for(int i=0;i<h;i++){
        if(b){
            for(int j=0;j<w;j++){
               A[i][j]=k;
               v[k]--;
               if(v[k]==0)
                   k++;
               
            }
            b=false;
        }
        else{
            for(int j=w-1;j>=0;j--){
                A[i][j]=k;
                v[k]--;
               if(v[k]==0)
                   k++;
            }
            b=true;
        }
        
    }
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<A[i][j]<<" ";
        }
        cout<<"\n";
    }
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

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

	    s = s.replaceAll("eraser", "-");
	    s = s.replaceAll("erase", "-");
	    s = s.replaceAll("dreamer", "-");
	    s = s.replaceAll("dream", "-");
	    s = s.replaceAll("-", "");

	    if (s.length() == 0){
	    	System.out.println("YES");
	    }else{
	    	System.out.println("NO");
	    }
	}
}

Measured memory_bytes: 31500