akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200011;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  vector<int> p(n), pre(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &p[i]);
  }
  for (int i = 1; i < n; ++i) {
    if (p[i] < p[i - 1]) {
      pre[i] = i;
    } else {
      pre[i] = pre[i - 1];
    }
  }
  // for (int i = 0; i < n; ++i) {
  //   printf("%d%c", pre[i], " \n"[i == n - 1]);
  // }
  set<int> st;
  for (int i = 0; i < k; ++i) {
    st.insert(p[i]);
  }
  int ans = 1;
  int num = (pre[k - 1] == 0);
  for (int i = k; i < n; ++i) {
    int mn = *st.begin(), mx = *st.rbegin();
    if (p[i - k] != mn || p[i] < mx) {
      ++ans;
      num += (pre[i] <= i - k + 1);
    }
    st.erase(p[i - k]);
    st.insert(p[i]);
  }
  if (num > 1) {
    ans -= (num - 1);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 11136
package main

import (
	"fmt"
)

// 以下の問題
// https://atcoder.jp/contests/abc137/tasks/abc137_b

func main() {
	var K, X int
	fmt.Scan(&K, &X)

	for i := X - K + 1; i <= X+K-1; i++ {
		fmt.Print(i ," ")
}
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
using namespace std;
double s[105], t[105];
int main() {
     int n;
     scanf( "%d", &n );
     double res = 0;
     for( int i = 0; i < n; i++ )
          scanf( "%lf", &s[i] );
     for( int i = 0; i < n; i++ ) {
          scanf( "%lf", &t[i] );
     }
     s[n] = t[n] = 0;
     for(int i=n-1;i>=0;i--)
     {
          t[i]=min(t[i],t[i+1]+s[i]);
     }
     double sum = 0;
     double v = 0;
     for( int i = 0; i < n; i++ ) {
          if( t[i + 1] >= t[i] ) {
               if( s[i] >= t[i] - v ) {
                    double x = t[i] - v;
                    sum += v * x + x * x / 2;
                    v = t[i];
                    sum += ( s[i] - x ) * v;
               } else {
                    sum += v * s[i] + s[i] * s[i] / 2;
                    v += s[i];
               }
          }
          if( t[i + 1] < t[i] ) {
               if(v+s[i]>=t[i+1])
               {
                    double x = ( t[i + 1] - v + s[i] ) / 2;
                    if( v + x <= t[i] ) {
                         sum += v * x + x * x / 2;
                         v += x;
                         x = s[i] - x;
                         sum += v * x - x * x / 2;
                         v -= x;
                    } else {
                         x = t[i] - v;
                         sum += v * x + x * x / 2;
                         v += x;
                         x = s[i] - x - t[i] + t[i + 1];
                         sum += v * x;
                         x = t[i] - t[i + 1];
                         sum += v * x - x * x / 2;
                         v -= x;
                    }
               }
               else
               {
                    sum+=v*s[i]+s[i]*s[i]/2;
                    v+=s[i];
               }
          }
     }
     printf( "%lf\n", sum );
}


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

using namespace std;

const int nax = 1e5+103;
int n, k;
int dp[nax];
int a[nax];
int f(int i){
	if (i==n-1) return 0;
	if(dp[i]!=-1) return dp[i];
	int ans = abs(a[i]-a[i+1])+f(i+1);
	for(int j=2; j<=k; j++){
		if(i+j<n) ans = min(ans, abs(a[i]-a[i+j])+f(i+j));
	}
	return dp[i]=ans;
}
int main(){
	cin>>n>>k;
	for(int i=0; i<n; i++) cin>>a[i];
	memset(dp, -1, sizeof dp);
	cout<<f(0)<<endl;
	return 0;
}

Measured memory_bytes: 5760
N = int(input())
h = [int(i) for i in input().split()]
dp = [0]*N
dp[1] = abs(h[1]-h[0])
for i in range(2, N):
  dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
print(dp[-1])

Measured memory_bytes: 13928
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    prime_cnt = [0] * (n + 1)
    for i in range(1, n + 1):
        for j in range(0, n + 1, i):
            prime_cnt[j] += 1

    res = 0
    for i in range(1, n + 1):
        res += i * prime_cnt[i]
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 151804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9+1;
const ll LINF = 1e18+1;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#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 RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}
template<typename T> T lcm(T a,T b){return a*b/gcd(a, b);}


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
    IN(ll, k);
    vector<bool> a(k,false);
    int c = 1;
    int n = 7%k;
    a[n] = true;
    while (n!=0) {
        n = (10*n+7)%k;
        c++;
        if (n!=0&&a[n]) {
            COUT(-1);
            return 0;
        }
        a[n] = true;
    }
    COUT(c);
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    string s;cin>>s;
    char c=' ';
    s.insert(s.begin()+4,c);
    cout<<s<<endl;
}

Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = np.full((N, N), 10 ** 10)
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s - 1][t - 1] = graph[t - 1][s - 1] = w
graph = floyd_warshall(graph, directed=False)
graph = floyd_warshall(graph <= L, directed=False)
graph[np.isinf(graph)] = 0

Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(graph[s - 1][t - 1]) - 1)
print(*ans, sep='\n')

Measured memory_bytes: 17628
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int a,b;cin>>a>>b;
    cout << max(a-b,0) << endl;
    return 0;
}

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

using namespace std;

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

  int N; cin>>N;
  vector<vector<int>> table(N, vector<int>(N-1));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N-1; j++) {
      int t; cin>>t;
      t--;
      table[i][j] = t;
    }
  }
  vector<int> is(N, 0);
  unordered_set<int> cands;
  auto check = [&](int x) {
    if (is[x] < N-1) {
      int o = table[x][is[x]];
      if (is[o] < N-1 and table[o][is[o]] == x) {
        cands.insert(x);
        cands.insert(o);
      }
    }
  };
  for (int i = 0; i < N; i++) {
    check(i);
  }
  int d = 0;
  while (not cands.empty()) {
    vector<bool> played(N, false);
    vector<int> ncands;
    for (auto i : cands) {
      ncands.push_back(i);
      int o = table[i][is[i]];
      if (not played[i] and not played[o]) {
        played[i] = played[o] = true;
        ++is[i];
        ++is[o];
      }
    }
    cands.clear();
    for (auto c : ncands)
      check(c);
    d++;
  }
  bool suc = true;
  for (int i = 0; i < N; i++) {
    suc &= is[i] == N-1;
  }
  cout << (suc ? d : -1) << endl;

  return 0;
}


Measured memory_bytes: 6272
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,ans=0;
	string a,b,c;
	cin >> n;
	cin >> a;
	cin >> b;
	cin >> c;
	for(i=0; i<n; ++i){
		if(a[i]==b[i] && b[i]==c[i] && c[i]==a[i]){
			continue;
		}else if(a[i]==b[i] || b[i]==c[i] || c[i]==a[i]){
			ans += 1;
		}else{
			ans += 2;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mpo(ll x, int n, ll a) {
  ll ret = 1;
  x %= a;
  while (n) {
    if (n % 2) {
      ret *= x;
      ret %= a;
    }
    x = x * x;
    x %= a;
    n /= 2;
  }
  return ret;
}
int main () {
  int N;
  cin >> N;
  ll pl = 0;
  ll mn = 0;
  ll sum = 0;
  vector<bool>bi(N);
  for (int i = 0; i < N; i ++) {
    char c;
    cin >> c;
    if (c == '0') bi[i] = false;
    else {
      bi[i] = true;
      sum ++;
    }
  }
  if (sum > 1) {
    for (int i = 0; i < N; i ++) {
      if (bi[i]) {
        mn += mpo(2, N - i - 1, sum - 1);
        mn %= (sum - 1);
      }
    }
  }
  for (int i = 0; i < N; i ++) {
    if (bi[i]) {
      pl += mpo(2, N - i - 1, sum + 1);
      pl %= (sum + 1);
    }
  }
  for (int i = 0; i < N; i ++) {
    ll warareru, waru;
    if (!(bi[i])) {
      warareru = pl;
      waru = sum + 1;
      warareru += mpo(2, N - i - 1, sum + 1);
      warareru %= (sum + 1);
    }
    else {
      if (sum == 1) {
        cout << 0 << endl;
        continue;
      }
      warareru = mn;
      waru = sum - 1;
      warareru -= mpo(2, N - i - 1, sum - 1);
      if (warareru < 0) warareru += (sum - 1);
      warareru %= (sum - 1);
    }
    int ans = 1;
    while (warareru) {
      ll war = warareru;
      waru = 0;
      while (war) {
        waru += (war % 2);
        war /= 2;
      }
      warareru %= waru;
      //cout << warareru << ' ' << waru << endl;
      ans ++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3652
from collections import deque


N, X, Y = map(int, input().split())
to = [[] for _ in range(N)]

for i in range(N - 1):
    to[i].append(i + 1)
    to[i + 1].append(i)

X, Y = X - 1, Y - 1
to[X].append(Y)
to[Y].append(X)


def main():
    ans = [0] * N
    for i in range(N):
        dist = [-1] * N
        dist[i] = 0
        que = deque([i])

        while que:
            v = que.popleft()
            for nv in to[v]:
                if dist[nv] == -1:
                    dist[nv] = dist[v] + 1
                    if nv > i:
                        ans[dist[nv]] += 1
                    que.append(nv)

    print(*ans[1:], sep='\n')


if __name__ == "__main__":
    main()

Measured memory_bytes: 75988
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
void prime_factorize(ll n, vector<ll> & ret)
{
    if (n <= 1)	return;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            prime_factorize(i, ret);
            prime_factorize(n / i, ret);
            return;
        }
    }
    ret.push_back(n);
    return;
}
int main()
{
    /*int c; cin >> c;
    if (30 <= c) cout << "Yes" << endl;
    else cout << "No" << endl;
    */

    /*ll n, d; cin >> n >> d;
    d *= d;
    int ans = 0;
    rep(i, n) {
        ll x, y; cin >> x >> y;
        ll dd = x * x + y * y;
        if (dd <= d) ans++;
    }
    cout << ans << endl;
    */

    /*ll k; cin >> k;
    if (k % 2 == 0) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, 100100) {
        vector<ll> fact = prime_factorize(k);
        for (ll l : fact) {
            if (l == k) {
                cout << 
            }
        }
    }
    */
    

    /*int k; cin >> k;
    string s; cin >> s;
    int num = s.size();
    int w, r;
    w = r = 0;
    for (char c : s) {
        if (c == 'R') r++;
        else w++;
    }
    if (w == 0 || r == 0) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> rnum, wnum;
    rep(i, num) {
        if (s[i] == 'R') rnum.push_back(i);
        else wnum.push_back(i);
    }
    sort(ALL(wnum));
    sort(rALL(rnum));
    num = min(wnum.size(), rnum.size());
    int ans = 0;
    rep(i, num) {
        if (rnum[i] < wnum[i]) break;
        ans++;
    }
    cout << ans << endl;
    */

    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    ll mx = 0;
    rep(i, n) {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    ll l, r, m;
    l = 0; r = mx; // l : kより大きい回数で切らなければならない
    while (l + 1 < r) {
        m = (l + r) / ll(2);
        // 長さmにするために切る回数
        ll num = 0;
        rep(i, n) {
            if (a[i] <= m) continue;
            int tmpnum = (int)floor(double(a[i]) / double(m));
            if (a[i] % m == 0) tmpnum--;
            num += tmpnum;
        }
        if (m == 262703496) cout << m << "," << num << endl;
        if (k < num) l = m;
        else r = m;
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
main(){
  int N,A;
  cin>>N>>A;
  vector<int>xs(N+1);
  for(int i=1;i<=N;++i){
    cin>>xs[i];
  }
  const int X=max(*max_element(xs.begin(),xs.end()),A);
  // dp[j][k][s] is the number of cases in which k x_i are selected
  // from x_1, ..., x_j and the sum is s.
  vector<vector<vector<int>>>dp(N+1,vector<vector<int>>(N+1,vector<int>(N*X+1)));
  for(int j=0;j<=N;++j){
    for(int k=0;k<=N;++k){
      for(int s=0;s<=N*X;++s){
        if(j==0&&k==0&&s==0){
          dp[j][k][s]=1;
        }else if(j>=1&&s<xs[j]){  // Can not select x_j.
          dp[j][k][s]=dp[j-1][k][s];
        }else if(j>=1&&k>=1&&s>=xs[j]){
          dp[j][k][s]=
              dp[j-1][k][s]+          // if x_j is not selected.
              dp[j-1][k-1][s-xs[j]];  // if x_j is selected.
        }else{
          dp[j][k][s]=0;
        }
      }
    }
  }
  int sum=0;
  for(int k=1;k<=N;++k){
    sum+=dp[N][k][k*A];
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 52224
#include <stdio.h>
#include <stdlib.h>

int N;
char S[114514];

int main(void) {
	int i;
	int kita = 0, higasi = 0;
	if (scanf("%d", &N) != 1) return 1;
	if (scanf("%114513s", S) != 1) return 1;
	for (i = 0; i < N; i++) {
		if ('A' <= S[i] && S[i] <=  'M') kita++;
		else if ('N' <= S[i] && S[i] <= 'Z') kita--;
		else if ('a' <= S[i] && S[i] <= 'm') higasi++;
		else if ('n' <= S[i] && S[i] <= 'z') higasi--;
	}
	printf("%d\n", abs(kita) + abs(higasi));
	if (kita > 0) {
		for (i = 0; i < kita; i++) putchar('A');
	} else if (kita < 0) {
		for (i = 0; i > kita; i--) putchar('N');
	}
	if (higasi > 0) {
		for (i = 0; i < higasi; i++) putchar('a');
	} else if (higasi < 0) {
		for (i = 0; i > higasi; i--) putchar('n');
	}
	putchar('\n');
	return 0;
}



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

std::pair<int, int> item(const std::string& s)
{
    int N = s.size(), cur = 0;
    std::string coef, expo;
    bool xf = 0;
    
    while (cur < N && s[cur] != 'x') {
        coef += s[cur++];
    }
    
    xf = (cur < N && s[cur] == 'x');
    cur += (cur + 1 < N && s[cur + 1] == '^' ? 2 : 1);

    while (cur < N) {
        expo += s[cur++];
    }

    coef = (coef.empty() ? "1" : coef);
    expo = (expo.empty() ? (xf ? "1" : "0") : expo);
    
    return std::make_pair(stoi(coef), stoi(expo)); 
}

int main()
{
    std::string s, t;
    std::cin >> s;
    
    using ll = long long;
    std::vector<char> op;
    std::vector<std::pair<ll, ll>> f;
    
    ll N = 0;
    for (char c : s) {
        if (c == '+' || c == '-') {
            f.emplace_back(item(t));
            op.emplace_back(c);
            
            N = std::max(N, f.back().second);
            t.clear();
        } else {
            t += c;            
        }
    }    
    f.emplace_back(item(t));
    
    for (ll i = 2525, cnt = 0; cnt < N; i--) {        
        ll res = f[0].first * pow(i, f[0].second);
        for (int j = 1; j < (int)f.size(); j++) {
            if (op[j - 1] == '+') {
                res += f[j].first * pow(i, f[j].second);
            } else {
                res -= f[j].first * pow(i, f[j].second);
            }
        }
        if (res == 0) {
            cnt += 1;
            std::cout << "(x" << (i > 0 ? "-" : "+") << std::to_string(abs(i)) + ")";
        }
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

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

    if (R < 1200)
        cout << "ABC" << endl;
    else if (R < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
int n;
int m;

ll a[100010];
vector<int> edges[100010];

vector<priority_queue<ll,vector<ll>,greater<ll>>> tree;

void dfs()
{
    vector<bool> vis(n,false);

    for (int i = 0; i < n;i++)
    {
        if(vis[i] == false)
        {
            tree.push_back(priority_queue<ll,vector<ll>,greater<ll>>());
            priority_queue<ll,vector<ll>,greater<ll>> &now = tree[tree.size() - 1];
            queue<int> que;
            que.push(i);

            while(!que.empty())
            {
                int v = que.front();
                que.pop();

                if(vis[v]) continue;
                vis[v] = true;
                now.push(a[v]);

                for(int to : edges[v])
                {
                    que.push(to);
                }
            }
        }
    }
}

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

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

    for (int i = 0; i < m;i++)
    {
        int x, y;

        cin >> x >> y;

        edges[x].push_back(y);
        edges[y].push_back(x);
    }

    dfs();

    ll result = 0;
    priority_queue<ll,vector<ll>,greater<ll>> vec;
    int cou = n - m - 1;
    cou *= 2;
    if(cou == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < tree.size();i++)
    {
        result += tree[i].top();
        tree[i].pop();
        cou--;
        while(!tree[i].empty())
        {
            vec.push(tree[i].top());
            tree[i].pop();
        }
    }

    while(cou > 0 && !vec.empty())
    {
        result += vec.top();
        vec.pop();
        cou--;
    }

    if(cou > 0)
    {
        cout << "Impossible" << endl;
        return 0;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 11892
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll a,b;cin>>a>>b;

  if(a==0){
    if(b>0)out(b);
    else out(abs(b)+1);
    return 0;
  }else if(b==0){
    if(a>0)out(a+1);
    else out(abs(a));
    return 0;
  }

  if(a>b){
    if(a<0)out(a-b+2);
    else{
      if(b<0)out(abs(abs(a)-abs(b))+1);
      else out(a-b+2);
    }
  }
  else{
    if(b<0)out(b-a);
    else{
      if(a<0)out(abs(abs(a)-abs(b))+1);
      else out(b-a);
    }
  }


  return 0;
}


Measured memory_bytes: 256
// By Atul Rathore

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

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()
{
	fastio;
	int n;
	cin>>n;
	int a[n]={};
	f(n-1)
	{
		int x;
		cin>>x;
		a[x-1]++; 
	}
	f(n)cout<<a[i]<<"\n";
		
	
	
	
}


Measured memory_bytes: 4444
#include<stdio.h>

int main()
{
    int i;
    long long a,b,k;
    scanf("%lld %lld %lld",&a,&b,&k);
    if(a>=k){
        a=a-k;
    }
    else{
        k=k-a;
        a=0;
        if(b>=k){
            b=b-k;
        }
        else{
            b=0;
        }
    }
    printf("%lld %lld",a,b);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MAX_N=100;
ll MAX_V=1000;
ll INF=1e18;
ll dp[101][100*1000+1];
int main()
{
    int n,W;
    cin>>n>>W;
    int w[n],v[n];
    for(int i=0; i<n; i++){
        cin>>w[i]>>v[i];
    }
    fill(dp[0],dp[0]+MAX_N*MAX_V+1,INF);
    dp[0][0]=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<=MAX_N*MAX_V; j++){
            if(j<v[i]){dp[i+1][j]=dp[i][j];}
            else{
                dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
            }
        }
    }
    int res;
    for(int i=0; i<=MAX_N*MAX_V; i++){
        if(dp[n][i]<=W)res=i;
    }
    cout<<res<<endl;
} 

Measured memory_bytes: 79104
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
cnt = [[0,0] for i in range(61)]
for i in range(61):
    for j in range(N):
        if ((A[j] >> i) & 1):
            cnt[i][1] += 1
        else:
            cnt[i][0] += 1

ans = 0
for i in range(61):
    ans += (cnt[i][0] * cnt[i][1]) * (2**i)
    ans %= mod
print(ans)

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

std::string S;
int dp[20][2][2][2][2];

int rec(int i, int f, int f7, int f5, int f3){
    if(i == S.size()){
        return f7 && f5 && f3;
    }

    if(dp[i][f][f7][f5][f3] != -1){
        return dp[i][f][f7][f5][f3];
    }

    int mx = f ? 9 : S[i] - '0', res = 0;
    if(!f7 && !f5 && !f3){
        res += rec(i + 1, f || (0 < mx), f7, f5, f3);
    }
    for(int j=3;j<=std::min(7, mx);j+=2){
        res += rec(i + 1, f || (j < mx), f7 || (j == 7), f5 || (j == 5), f3 || (j == 3));
    }

    return dp[i][f][f7][f5][f3] = res;
}

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

    std::cin >> S;

    memset(dp, -1, sizeof(dp));
    
    int res = rec(0, 0, 0, 0, 0);
    std::cout << res << std::endl;
}


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

int N;int INF=1000007;

struct edge{
  int to,cap,rev;
  edge (int t,int c,int r) {
    to=t;cap=c;rev=r;
  }
};

void add_edge(int a,int b,int cap,vector<vector<edge>> &g) {
  g[a].push_back(edge(b,cap,g[b].size()));
  g[b].push_back(edge(a,0,g[a].size()-1));
}

int dfs(int v,int t,int f,vector<vector<edge>> &g,vector<int> &used) {
  if (v==t) return f;
  used[v]=1;
  for (edge &e:g[v]) {
    if (used[e.to]==0 && e.cap>0) {
      int d=dfs(e.to,t,min(f,e.cap),g,used);
      if (d>0) {
        e.cap-=d;
        g[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t,vector<vector<edge>> g) {
  int flow=0;
  while (true) {
    vector<int> used(g.size(),0);
    int f=dfs(s,t,INF,g,used);
    if (f==0) return flow;
    flow+=f;
  }
}

int main() {
  cin >> N;int A[N][2];int B[N][2];
  for (int i=0;i<N;i++) {
    cin >> A[i][0] >> A[i][1];
  }
  for (int i=0;i<N;i++) {
    cin >> B[i][0] >> B[i][1];
  }
  vector<vector<edge>> g(2*N+2);
  for (int i=0;i<N;i++) {
    add_edge(0,i+1,1,g);
  }
  for (int i=0;i<N;i++) {
    for (int j=0;j<N;j++) {
      if (A[i][0]<B[j][0] && A[i][1]<B[j][1]) {
        add_edge(i+1,j+N+1,1,g);
      }
    }
  }
  for (int i=0;i<N;i++) {
    add_edge(i+N+1,2*N+1,1,g);
  }
  cout << max_flow(0,2*N+1,g) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;
int main(){
    int num;
    cin >> num;
    long long a[87];  
    a[0] = 2;
    a[1] = 1;
    for (long i = 2; i < 87; i++)
    {
        a[i] = a[i-1] + a[i-2];
    }
      
    cout << a[num] << endl;
    return 0;
}

Measured memory_bytes: 256
/*****************************************************
 				*	Logged in : HABIBUR RAHMAN						 *
				*	Dept	  : COMPUTER SCIENCE AND ENGINEERING	 *
				*													 *
				*	KHULNA UNIVERSITY OF ENGINEERING AND TECHNOLOGY  *
				******************************************************/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<string> vs;
typedef pair<ll,ll> pll;
#define fast_io 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) 				v.begin(),v.end()
#define allr(v) 			v.rbegin(),v.rend()
#define rep(i,a,b) 			for(ll i=a;i<=b;i++)
#define rep0(i,n)			for(ll i=0;i<n;i++)
#define rrep0(i, n) 		for(ll i=(ll)(n);i>0;--i)
#define rrep(i, a, b) 		for(ll i=(ll)(a);i>=(ll)(b);--i)
#define pb(z) 				push_back(z)
#define ff					first
#define ss 					second
#define caset 				int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define sz(X) 				((ll)(X).size())
#define scan(X) 			scanf("%s", (X))
#define ms(v,val)			memset((v),(val),sizeof((v)))
#define ms0(X) 				memset((X), 0, sizeof((X)))
#define ms1(X) 				memset((X), -1, sizeof((X)))
#define m_p(a,b)            make_pair(a,b)
#define get_pos(c,x) 		(lower_bound(c.begin(),c.end(),x)-c.begin())
#define lcm(a,b)            (a*b)/__gcd(a,b)
#define INF9                1000000010
#define INF18               4000000000000000010
#define bpll(a)             __builtin_popcountll(a)
#define sqr(a)              ((a)*(a))
#define nl					"\n"
#define mod					1e9+7;
#define mx_el(v)			*max_element(all(v));
#define mn_el(v)			*min_element(all(v));
#define pcase(z,x)    		cout<<"Case "<<z<<": "<<x<<"\n"
const double pi = 2*acos(0) ;
#define display(v)			vi :: iterator it;for(it=(v).begin();it!=(v).end();it++){cout << *it << " " ;}cout << endl;
#define taking(n,v) 		for(ll i=0;i<(n);i++){ll inp;cin>>inp;(v).push_back(inp);}

void start(){
      #ifndef ONLINE_JUDGE 
      freopen("input.txt" , "r" , stdin) ;
      freopen("output.txt" , "w" , stdout) ;
      #endif
}
ll dp[1000005];
void solve()
{
 	 ll n;cin>>n;
 	 vll v;
 	 taking(n,v);
 	 sort(all(v));
 	 ll ans=0;
 	 rep0(i,n){
 	 	dp[v[i]]++;
	  }
	  for(int i=0;i<100003;i++){
	  	ll cnt=dp[i]+dp[i+1]+dp[i+2];
	  	ans=max(ans,cnt);
	  }
	  cout << ans << nl;
}
int main() {
	//fast_io
	//start();
    //caset{
    	//cout << "Case " << tt << ": ";
		  solve();
	//}
	
	return 0;
}

Measured memory_bytes: 4512
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using std::vector;
using std::find;
using std::distance;
using namespace std;

struct UnionFind {
    vector<int> par; 
    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return; 
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(N);

    for(int i = 0; i < M; i++) {
        int  x, y, z;
        cin >> x >> y >> z;
        tree.unite(x-1, y-1); 
    }

    int cnt=1;
    for(int i=0;i<N;i++){
        if(!tree.same(0,i)){
            tree.unite(0, i);
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

class BIT{
public:
  int n,bit[555555];
  BIT(){fill(bit,bit+555555,0);}
  void add(int i,int x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  int sum(int i){
    int s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
};

BIT b,b2;

void Main() {
  int T;
  string s,t;
  cin >> s >> t >> T;
  b.n=s.size()+1;
  b2.n=t.size()+1;
  rep(i,s.size()) {
    if(s[i]=='A') b.add(i+1,1);
  }
  rep(i,t.size()) {
    if(t[i]=='A') b2.add(i+1,1);
  }
  while(T--) {
    int l1,l2,r1,r2;
    cin >> l1 >> r1 >> l2 >> r2;
    int x1,y1,x2,y2;
    x1=b.sum(r1)-b.sum(l1-1);
    x2=b2.sum(r2)-b2.sum(l2-1);
    y1=r1-l1+1-x1;
    y2=r2-l2+1-x2;
    bool f=0;
    {
      ll d=x1*2+y1;
      ll c=x2*2+y2;
      if(d%3==c%3) f=1;
    }
    if(!f) {
      ll d=x1+y1*2;
      ll c=x2+y2*2;
      if(d%3==c%3) f=1;
    }
    if(f) pr("YES");
    else pr("NO");
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

Measured memory_bytes: 5200
#include <stdio.h>

int Euclidean(int a, int b);

int main(void){
  int i, n, a[10], gcd, lcm;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  lcm = a[0];
  for(i = 1; i < n; i++){
    gcd = Euclidean(lcm, a[i]);
    lcm = a[i] * (lcm / gcd);
  }
  printf("%d\n", lcm);
  return 0;
}


int Euclidean(int a, int b){
  int r;

  if(a < b){
    r = a;
    a = b;
    b = r;
  }
  while(b != 0){
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



int main(){
    int a[3][3];
    bool an[3][3];
    rep(i,3){
        rep(j,3){ 
            cin >> a[i][j];
            an[i][j]=false;
        }
    }

    int n; cin >> n;
    int b[n];

    rep(i,n) cin >> b[i];

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<n;k++){
                if(a[i][j]==b[k]){
                    an[i][j]=true;
                }
            }
        }
    }
    string ans="No";
    for(int i=0;i<3;i++){
        if(an[i][0] and an[i][1] and an[i][2]){ 
            ans="Yes";
        }
        if(an[0][i] and an[1][i] and an[2][i]){ 
            ans="Yes";
        }
    }
    if(an[0][0] and an[1][1] and an[2][2]){ 
        ans ="Yes";
    }
    if(an[0][2] and an[1][1] and an[2][0]){ 
        ans ="Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T = 1;
	for(int t = 1; t <= T; t++){
		int k;
		cin >> k;
		int n = 0;
		for(int i = 1; i <= k; i++){
			n = n * 10 + 7;
			if(n % k == 0){
				cout << i << "\n";
				return 0;
			}else{
				if(n > k){
					n %= k;
				}
			}
		}
		cout << -1 << "\n";
	}
}



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

std::vector<int> vec;

int a, b, c, ans;

int main() {
    std::cin >> a >> b >> c;
    vec = {a, b, c};
    std::sort(vec.begin(), vec.end());
    std::reverse(vec.begin(), vec.end());
    ans = vec[0]*10+vec[1]+vec[2];
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int a(int,int);

int main()
{

  int x, y;

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

  if(x>y) printf("%d\n",a(x,y));
  else if(x<y) printf("%d\n",a(y,x));
  else printf("%d\n",x);

  return 0;
  
}


int a(int a,int b)
{

  int d;

  while(b!=0){
    d = a%b;
    a = b;
    b = d;
  }

  return a;
  
}



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

int main() {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  A--, B--, C--, D--;
  string S;
  cin >> S;

  bool flag = true;
  for (int i = A; i < C; i++) {
    if (S.at(i) == '#' && S.at(i + 1) == '#') {
      flag = false;
    }
  }

  for (int i = B; i < D; i++) {
    if (S.at(i) == '#' && S.at(i + 1) == '#') {
      flag = false;
    }
  }

  if (C > D) {
    flag = false;
    for (int i = B; i < D + 1; i++) {
      if (S.at(i - 1) == '.' && S.at(i) == '.' && S.at(i + 1) == '.')
        flag = true;
    }
  }

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()


void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

//ifstream &cin
void solve(){

}

const double eps = 1e-9;

int main() {
    fastik();
    ll n, k;
    cin >> n >> k;
    cout << setprecision(16) << fixed;
    double ans = 0;
    if(n >= k){
        ans += (double)(n-k+1)/(double)n;
    }
    double nn = n;
    double kk = k;
    fore(i,1,min(k-1,n)){
        double ii = i;
        ans += 1/nn * 1/(pow(2,ceil(log2(kk/ii))));
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  vector<ll> sort_a = A;
  sort(sort_a.begin(), sort_a.end());
  reverse(sort_a.begin(), sort_a.end());
  ll ans = 0;
  if (N % 2 == 0) {
    for (ll i = 0; i < N / 2; ++i) {
      ans += 2 * sort_a.at(i);
    }
    for (ll i = N / 2; i < N; ++i) {
      ans -= 2 * sort_a.at(i);
    }
    ans -= sort_a.at(N / 2 - 1);
    ans += sort_a.at(N / 2);
  }
  else {
    //sbs
    for (ll i = 0; i < N / 2; ++i) {
      ans += 2 * sort_a.at(i);
    }
    for (ll i = N / 2; i < N; ++i) {
      ans -= sort_a.at(i) * 2;
    }
    for (ll i = 0; i < 2; ++i) {
      if (i + N / 2 >= N) {
        continue;
      }
      ans += sort_a.at(i + N / 2);
    }

    //bsb
    ll temp = 0;
    for (ll i = 0; i < N / 2 + 1; ++i) {
      temp += sort_a.at(i) * 2;
    }
    for (ll i = N / 2 + 1; i < N; ++i) {
      temp -= sort_a.at(i) * 2;
    }
    for (ll i = 0; i < 2; ++i) {
      temp -= sort_a.at(N / 2 - i);
    }
    // cout << ans << ' ' << temp << endl;
    ans = max(ans, temp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1920
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>

int main() {
	int N;
	int a[100010];
	scanf("%d",&N);
	for (int i = 0; i < N;i++) {
		scanf("%d",&a[i]);
		
	}
	int c=0;
	for (int i = 0; i < N; i++) {
		if (a[i] == i+1 ) {
			if ( a[i+1] == i+2 && i + 2 <= N) {
				i++;
			}
			c++;
		}
	}
	printf("%d\n",c);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int x[N], y[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
  }
  
  double d[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      d[i][j] = sqrt((x[i]-x[j]) * (x[i]-x[j]) + (y[i]-y[j]) * (y[i]-y[j]));
    }
  }
  
  double ave = 0.0;
  
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ave += d[i][j] * 2 / N;
    }
  }
  
  cout << fixed << setprecision(10) << ave << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    string A, B;
    cin >> A >> B;
    string ans;
    if (A.length() > B.length()) {
        cout << "GREATER" << std::endl;
        return 0;
    }
    else if (B.length() > A.length()) {
        cout << "LESS" << std::endl;
        return 0;
    }
    else {
        for (int i = 0; i < A.length(); ++i) {
            int an = A[i] - '0';
            int bn = B[i] - '0';
            if (an > bn) {
                cout << "GREATER" << std::endl;
                return 0;
            }
            else if (bn > an) {
                cout << "LESS" << std::endl;
                return 0;
            }
        }
    }
    cout << "EQUAL" << std::endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    c = Counter(A)
    v = list(sorted(c.values()))
    print(sum(v[:-K]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 32032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
    static FastScanner sc = new FastScanner();
    public static void main(String[] args) {
       int n=sc.nextInt();
       if (n>=30){
           System.out.println("Yes");
       }
       else{
           System.out.println("No");
       }

    }

        static void sortint(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static void sort(long[] a) {
        ArrayList<Integer> l = new ArrayList<>();
        for (long i : a) l.add((int) i);
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}





Measured memory_bytes: 32812
#include <iostream>
#include <string>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int solve(string s){
    if(s[0]==s[1]&&s[1]==s[2]&&s[2]==s[3])return -1;
    
    for(int cou=0;;cou++){
        if(s=="6174")return cou;
        
        string L,S;
        L=S=s;
        sort(L.begin(),L.end(),greater<char>());
        sort(S.begin(),S.end());
        int x=atoi(L.c_str())-atoi(S.c_str());
        for(int i=3;i>=0;i--,x/=10){
            s[i]='0'+x%10;
        }
      
    }
}
int main(void){
  while(1){
      string n;
      cin>>n;
      if(n=="0000")break;
      
      int ans=solve(n);
      if(ans==-1)cout<<"NA"<<endl;
      else cout<<ans<<endl;
  }
}

Measured memory_bytes: 3160
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N,K=mis()
    import numpy as np
    print(len(str(np.base_repr(N,K))))

main()







Measured memory_bytes: 22024
#include <stdio.h>
#include <climits>

int main(){
    int n, temp, min = INT_MAX, ans = INT_MIN;
    scanf("%d",&n);

    for(int i = 0; i < n; i++){
        scanf("%d", &temp);
        
        if((temp - min) > ans){
            ans = (temp - min);
        }
        
        if(temp < min){
            min = temp;
        }
    }    
    printf("%d\n",ans);
}



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

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

    int h[n];
    rep(i, n) {
        cin >> h[i];
    }

    int dp[n+1];

    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(h[0] - h[1]);
    for(int i = 2; i < n; i++) {
        dp[i+1] = min( dp[i] + abs(h[i-1] - h[i]), dp[i-1] + abs(h[i-2] - h[i]) );
    }

    cout << dp[n] << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

ll gcd(ll x, ll y) {
    if (x > y) swap(x, y);
    ll m = 1;
    while (m != 0) {
        m = y % x;
        y = x;
        x = m;
    }
    return y;
}

ll lcd(ll x, ll y) {
    return x / gcd(x, y) * y;
}

int main() {

    ll n, m;
    cin >> n >> m;

    vector<ll> numbers(n);
    rep(i, n)cin >> numbers[i];


    ll l = 1;
    rep(i, n) {
        l = lcd(l, numbers[i] / 2);
    }

    rep(i, n) if (l / (numbers[i] / 2) % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }

    ll nm = m - l;
    if (nm < 0) {
        cout << 0 << endl;
        return 0;
    }

    cout <<  (m / l + 1) / 2 << endl;

}

Measured memory_bytes: 1152