akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
    double n;
    cin>>n;
    vector<double> x(n),y(n);
    vector<int> city(n);
    rep(i,n) cin>>x[i]>>y[i];
    double sum=0;
    int cnt=0;
    
    iota(city.begin(),city.end(),0);
    do{
        rep(i,n-1){
            sum+=sqrt(pow((x[city[i+1]]-x[city[i]]),2)+pow((y[city[i+1]]-y[city[i]]),2));
        }
        cnt++;
    }while(next_permutation(city.begin(),city.end()));
    
    cout<<fixed<<setprecision(11)<<sum/cnt<<endl;
    return 0; 
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

ll harshad(ll n){
    string s = to_string(n);
    ll res = 0;
    for(int i=0;i<s.size();i++){
        res += (ll)(s[i]-'0');
    }
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    cout << (n % harshad(n) == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
# aが1〜Nの整数、bがN〜1の整数だったら、和は全て同じ。
# そこから、例えば5番目だけ大きくしたいなら、a5〜aNとb1〜b5までにtを足せば良い。a5+b5は2t増えて、他はt増える。
# 最大にしたいところにN足して、次に大きくしたいところにN-1足して、以下同様。
# この「ある区間に一定要素を足す」は……imosすればよい。最初と最後だけメモっておいて最後に累積和。

n = int(input())
indices = list(map(int, input().split()))

a_diff = [1] * n # 1〜Nの差分をここに書いちゃう
b_diff = [-1] * n

for plus, idx in enumerate(indices):
    idx -= 1
    a_diff[idx] += plus
    # a_diff[最終要素の次] -= plus は不要。

    b_diff[0] += plus
    if idx +1 < n:
        b_diff[idx+1] -= plus

a = []
now = 1
for i in range(n):
    now += a_diff[i]
    a.append(now)

b = []
now = n+1
for i in range(n):
    now += b_diff[i]
    b.append(now)

print(' '.join(map(str, a)))
print(' '.join(map(str, b)))


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

int main(){
  int a, b, c, x;
  cin>>a>>b>>c;
  if(a>b){
    x=a;
    a=b;
    b=x;
  }
  if(b>c){
    x=b;
    b=c;
    c=x;
  }
  if(a>b){
    x=a;
    a=b;
    b=x;
  }
  cout<<a<<" "<<b<<" "<<c<<endl;
  return 0;
}

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


typedef long long ll;


int main() {
	ll X, K, D;
	cin >> X >> K >> D;
	if (X < 0) X = -X;

	ll a = X / D;
	if (a >= K) {
		cout << (X - K * D) << endl;
	}
	else {
		K -= a;
		X -= a * D;
		if (K % 2)
			cout << D - X << endl;
		else
			cout << X << endl;
	}

	return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
const int N=310;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,m,a[N][N],cnt[N],ban[N];
bool check(int mid) {
    memset(ban,0,sizeof(ban));
    memset(cnt,0,sizeof(cnt));
    int t=m;
    for(int i=1;i<=n;i++) ++cnt[a[i][1]];
    while(t) {
        int p=0;
        for(int i=1;i<=m;i++) if(cnt[i]>cnt[p]) p=i;
        if(cnt[p]<=mid) break;
        ban[p]=1;
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                if(!ban[a[i][j]]) { ++cnt[a[i][j]];break; }
        --t;
    }
    return t>0;
}
int main() {
    n=gi(),m=gi();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) a[i][j]=gi();
    int l=1,r=n,ret=n;
    while(l<=r) {
        int mid=(l+r)>>1;
        if(check(mid)) {
            ret=mid,r=mid-1;
            //cerr<<ret<<endl;
        }
        else l=mid+1;
    }
    printf("%d\n",ret);
    return 0;
}


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


const int N = 205;
int n, m, cnt, a[N], b[N];

bool cmp (int x, int y) {
	bool s1 = x & 1, s2 = y & 1;
	return s1 > s2;
}
int main () {
	cin >> n >> m, cnt = 0;
	for (int i = 1; i <= m; ++i) {
		cin >> a[i];
		if (a[i] & 1) ++cnt;
	}
	if (m == 1) {
		if (n <= 2) return printf("%d\n%d\n%d\n", a[1], 1, n), 0;
		printf("%d\n", a[1]);
		printf("%d\n", 2);
		if (n & 1) printf("%d %d\n", 1, n - 1);
		else printf("%d %d\n", 2, n - 2);
		return 0;
	}
	if (cnt > 2) return puts("Impossible"), 0;
	sort(a + 1, a + 1 + m, cmp), swap(a[2], a[m]);
	b[1] =  a[1] - 1;
	for (int i = 2; i < m; ++i) b[i] = a[i];
	b[m] = a[m] + 1;
	for (int i = 1; i <= m; ++i) printf("%d%c", a[i], i < m ? ' ' : '\n');
	cout << (b[1] ? m : m - 1) << endl;
	for (int i = b[1] ? 1 : 2; i <= m; ++i) printf("%d%c", b[i], i < m ? ' ' : '\n');
	return 0;
}

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

int main()
{
    int a,b,h,t;
    cin >> a >> b >> h;

    if(a > b){
        t = a;
        a = b;
        b = t;
    }

    int  area;
    area = a*h + (b-a)*h/2;
    cout << area;
 
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#define ll long long
#define lld long double
#define llu unsigned long long int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define mod 1000000007
#define mod1 998244353
#define pi 3.1415926535897
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("B-small-attempt0.in", "r", stdin);freopen("output.txt", "w", stdout);
    //std::cout << std::setprecision(9);
    //std::cout << std::fixed;
    ll i;
    string s;
    cin>>s;
    map<char, ll> m;
    for(i=0;i<4;i++)
        m[s[i]]++;
    for(i=0;i<4;i++)
    {
        if(m[s[i]]!=2)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/agc041/tasks/agc041_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, A, B;
  cin >> N >> A >> B;

  if ((B - A) % 2 == 0) {
    drop((B - A) / 2);
  }

  if (N - A < B - 1) {
    ll a = A + (N - B);
    ll b = N;
    ll res = min(N - A, N - B + (b - a + 1) / 2);
    drop(res);
  } else {
    ll a = 1;
    ll b = B - (A - 1);
    ll res = min(B - 1, A - 1 + (b - a + 1) / 2);
    drop(res);
  }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;

int main(){
	int N,Q;
	cin>>N>>Q;
	map<int,int>arr;
	int a,b;
	for(int i=0;i<N-1;++i){
		cin>>a>>b;
		arr[b] = a;
	}
	map<int,int>arr1;
	int p,x;
	for(int i=0;i<Q;++i){
		cin>>p>>x;
		arr1[p] += x;
	}
	for(int i=1;i<=N;++i){
		if(i==1){
			cout<<arr1[1]<<" ";
		}
		else{
			cout<<arr1[i] + arr1[arr[i]]<<" ";
			arr1[i] += arr1[arr[i]];
		}
	}
	cout<<endl;
}


Measured memory_bytes: 21120
#include<stdio.h>
#include<string.h>
#define LEN 100005

//プロセスを表す構造体
typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

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

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b;} //最小値を返す

int main() {
    int elaps = 0, c;
    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);
    }
    head = 1; tail = n + 1;

    //シミュレーション
    while(head != tail) {
        u = dequeue();
        c = min(q, u.t); //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: 11848
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,q[501],dp[1<<24],num[501],t[1<<24];
bool ch[30];
string s[501];
int B(){
  memset(dp,-1,sizeof(dp));
  dp[0]=0;
  memset(t,-1,sizeof(t));
  r(i,n){
    r(j,(1<<m))if(dp[j]>=0)t[j^num[i]]=max(t[j^num[i]],dp[j]+1);
    r(j,(1<<m))dp[j]=max(dp[j],t[j]);
  }
  return dp[0];
}
int A(int d,int x){
  int res=0;
  if(d==n){
    r(i,m){
      int c=0;
      r(j,n)if(ch[j]&&s[j][i]=='1')c++;
      if(c%2)return 0;
    }
    return x;
  }
  res=max(res,A(d+1,x));
  ch[d]=1;
  res=max(res,A(d+1,x+1));
  ch[d]=0;
  return res;
}
main(){
  while(cin>>n>>m,n){
    r(i,n)cin>>s[i];
    r(i,n){
      int x=0;
      for(int j=m-1,k=0;j>=0;j--,k++)if(s[i][j]=='1')x+=(1<<k);
      num[i]=x;
    }
    if(n<m)cout<<A(0,0)<<endl;
    else cout<<B()<<endl;
  }
}

Measured memory_bytes: 134292
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {

    int N;
    cin >> N;
    vector<long> BS;
    for (int i = 0; i < N - 1; ++i) {
        long B;
        cin >> B;
        BS.push_back(B);
    }

    long sum = BS[0];
    for (int i = 1; i < N - 1; ++i) {
        sum += min(BS[i], BS[i - 1]);
    }
    sum += BS[N - 2];

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
char s[maxn];
int main()
{
   while(~scanf("%s",s))
   {
       int n = strlen(s);
       int da = 0;
       for(int i = 0; i < n; ++i)
       if(s[i] == '+')
       da++;
       else
        da--;
       cout<<da<<endl;
   }

}
















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

 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  int ans =0;
  int current = 1;
  bool arrival = false;
  for(int i=0; i<N; i++){
    if( current == 2){
      arrival = true;
      break;
    }else{
      current = a.at(current -1) ;
      ans++;
      if (current == 1){
        ans = -1;
        break;
      }
    }
  }
  if (arrival == false){
    ans = -1;
  }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdio.h>
   #include <stdlib.h>
   #include <time.h>

int main(void) {
   
      int e=0;
      int s=0;
      
      scanf("%d %d",&e,&s);
      if((e<=8)&&(s<=8))
      {
      printf("Yay!\n");
      	
      } 
       else
       {
       	printf(":(\n");
       }
       return 0;
  
}

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

int main(){
  int n;
  cin >> n;
  
  vector<int> p(n);
  
  rep(i,n) cin >> p[i];
  
  int k= 0;
  rep(i,n) if(p[i] != i+1)k++;
  
  if(k<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
}
  


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string A, B;
  cin >> A >> B;
  if (A.size() > B.size()) puts("GREATER");
  else if (A.size() < B.size()) puts("LESS");
  else if (A > B) puts("GREATER");
  else if (A < B) puts("LESS");
  else puts("EQUAL");
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

#define F first
#define S second
#define pb push_back
#define ll long long
#define int long long

using namespace std ;

const int MAXN = 501 * 1001 , MOD = 1e9 + 7 ; 

int deg[MAXN] ; 

int32_t main()
{
	ios::sync_with_stdio(0) ; cin.tie(0) ; 
	int n , m ; 
	cin >> n >> m ; 
	for(int i = 0 ; i < m ; i ++ ) 
	{
		int x , y ; 
		cin >> x >> y ; 
		deg[x] ++ ; 
		deg[y] ++ ; 
	}
	for(int i = 1 ; i <= n ; i ++ ) if(deg[i]%2==1) return cout << "NO" << endl , 0 ; 
	cout << "YES" << endl ; 
}

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

#define X first
#define Y second

const int MAXN = 1e5 + 5;
long long ans;
long long a[MAXN], b[MAXN];
vector<long long> s;
int n;

void input();
void solve();

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	input();
	solve();
	return 0;
}

void input() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i], s.push_back(-a[i] - b[i]), ans -= b[i];
}

void solve() {
	sort(s.begin(), s.end());
	for (int i = 0; i < n; i += 2)
		ans -= s[i];
	cout << ans;
}


Measured memory_bytes: 2676
N = int(input())
P = []

def is_prime(n: int):
    if n == 2:
        return True
    if n == 1 or n % 2 == 0:
        return False
    for p in range(3, int(n**0.5)+1, 2):
        if n % p == 0:
            return False
    return True

for i in range(5, 55555+1):
    # 素数かつ5で割って1余る数を列挙する
    # 5で割って1余る数だけならどれを5を選んでも5で割り切れる合成数になるから
    if is_prime(i) and i % 5 == 1:
        P.append(i)

print(*P[:N])

Measured memory_bytes: 41180
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int a,b; cin >> a >> b;
  int c[100000000][1900000000];
  c[-1][11110] = a;
  cout << max(a - 2*b, 0) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define mp(a, b) make_pair((a),(b))
#define bs(n) ((ull)1<<(ull)n)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
constexpr double eps = 0.000000001;


int main() {
    ll n;
    cin >> n;
    auto a = new pair<ll, ll>[n * 2];
    rep(i, n * 2) {
        cin >> a[i].first;
        a[i].second = (i < n ? -1 : 1);
    }
    sort(a, a + (n * 2));
    list<ll> v;
    ll p = 0;
    rep(i, n * 2) {
        if (p * a[i].second < 0) {
            v.push_back(abs(p));
        }
        p += a[i].second;
    }
    ll r = 1;
    for (auto &e:v) r = (r * e) % mod;
    cout << r << endl;
}


Measured memory_bytes: 6528
// This template is based on Mr. tonymontaro's template (https://atcoder.jp/users/tonymontaro).
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();

        int n = in.intNext();
        int m = in.intNext();

        StringBuilder result = new StringBuilder();
        if (n * m % 2 == 0) {
          result.append("Even");
        } else {
          result.append("Odd");
        }
        // result.append(n);
        // result.append("Even");
        // result.append(m);
        // int half = m / 2;
        // int ln = half * 2;
        // for (int i = 1; i <= half; i++) result.append(String.format("%d %d\n", i, ln - i + 2));
        // int k = half * 2 + 2;
        // if (m % 2 == 1) {
        //     half += 1;
        //     ln = half * 2;
        // }
        // for (int i = 0; i < half; i++) result.append(String.format("%d %d\n", i + k, ln - i - 1 + k));
        out.println(result);

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;

int main(){
	int n;
	cin>>n;
	vi a;
	a.resize(n);
	ll occ[n + 1];
	for(int i = 0; i < n + 1; i++) occ[i] = 0;
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		cin>>a[i];
		if (a[i] > n) ans ++;
		else occ[a[i]]++;
	}
	for(int i = 0; i < n + 1; i++){
		if (occ[i] < i) ans +=occ[i];
		else ans += (occ[i] - i);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++) 
#define rrep(i,n) for(int i = 1; i <= (int)(n); i++) 
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod = 1000000007;
//const ll INF = mod * mod;
//const double pi = 3.14159265358979;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if(n < 5) {
        puts("NO");
        return 0;
    }
    while(!s.empty()) {
        string a = s.substr(0,5);
        int m = s.size();
        if(a != "dream" && a != "erase") {
            puts("NO");
            return 0;
        }
        else if(a == "dream") {
            if(m == 5) s.erase(0,5);
            else if(m == 7) s.erase(0,7);
            else if(s[5] != 'e') s.erase(0,5);
            else if(s[7] != 'a') s.erase(0,7);
            else s.erase(0,5);
        }
        else if(a == "erase") {
            if(m == 5) s.erase(0,5);
            else if(m == 6) s.erase(0,6);
            else if(s[5] == 'r') s.erase(0,6);
            else s.erase(0,5);
        }
    }
    puts("YES");
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

ll keta(ll a){
  ll res=0;
  while(a>0){
    res++;
    a/=10;
  }
  return res;

}
int  main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin>>n;
  ll res=1e9;
  repi(i,1,1e5+1){
    if(n%i>0)continue;
    chmin(res,max(keta(i),keta(n/i)));
  }
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/rope>

using namespace std;
using namespace __gnu_cxx;

random_device rd;
mt19937 rnd(rd());
#define pt pair<int, int>
#define x first
#define y second
#define what_is(x) cerr << #x << " is " << x << endl;
#define ok cerr << "ok" << endl;
#define endl '\n'
#define int long long
#define ld long double

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

	int k, a, b;
	cin >> k >> a >> b;
	int x = b / k * k;
	if (x >= a && x <= b)
		cout << "OK" << endl;
	else
		cout << "NG" << endl;

	return 0;
}


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

#define int long long

signed main()
{
    int i=0, j=0, ans=0;
    int n;
    cin>>n;

    for(i=1;i<=n;i++){
        if((i%3)&&(i%5)){
            ans+=i;
        }
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <cstdio>

const int N = 11;

int a, b, d[N][N], delta[101][101];
bool ok[N][N];

int main()
{
    scanf("%d%d", &a, &b);
    int cnt = 0, left = a * b;
    for (int i = 1; i <= a; ++ i) {
        for (int j = 1; j <= b; ++ j) {
            scanf("%d", d[i] + j);
            cnt = std::max(cnt, d[i][j]);
        }
    }
    for (int i = 0; i <= cnt; ++ i) {
        for (int j = 0; j <= cnt; ++ j) {
            int& dt = delta[i][j];
            dt = 0;
            for (int x = 1; x <= a; ++ x) {
                for (int y = 1; y <= b; ++ y) {
                    dt = std::max(dt, d[x][y] - i * x - j * y);
                }
            }
            for (int x = 1; x <= a; ++ x) {
                for (int y = 1; y <= b; ++ y) {
                    if (dt + i * x + j * y == d[x][y]) {
                        left -= !ok[x][y];
                        ok[x][y] = true;
                    }
                }
            }
        }
    }
    if (left) {
        puts("Impossible");
    } else {
        puts("Possible");
        printf("%d %d\n", 2 * (cnt + 1), 2 * cnt + (cnt + 1) * (cnt + 1));

        for (int i = 0; i < cnt; ++ i) {
            printf("%d %d X\n", i + 1, i + 2);
            printf("%d %d Y\n", i + cnt + 3, i + cnt + 2);
        }
        for (int i = 0; i <= cnt; ++ i) {
            for (int j = 0; j <= cnt; ++ j) {
                printf("%d %d %d\n", i + 1, j + cnt + 2, delta[i][j]);
            }
        }
        printf("%d %d\n", 1, cnt + 2);
    }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n := getInt()
	cnt := make([]int, n)
	for i := 0; i < n; i++ {
		a := getInt()
		cnt[a]++
	}

	ans := 1
L:
	for i := range cnt {
		switch i % 2 {
		case n % 2:
			if cnt[i] != 0 {
				ans = 0
				break L
			}
		default:
			if (i == 0) && (cnt[i] == 1) {
				continue
			} else if (i != 0) && (cnt[i] == 2) {
				ans = (ans * 2) % mod
				continue
			} else {
				ans = 0
				break L
			}
		}
	}
	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#include<string.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX_LIMIT 100000
#define mp make_pair
#define pb push_back
#define bb back
#define CHARS_TOTAL 256
#define e endl
using namespace std;
int main(){
       ll n;
       cin>>n;
       ll c=0,x,i;
       for(i=1;i<=n;i++){
           x=floor(log10(i) + 1);
           if(x%2==1){
               c++;
           }
       }
       cout<<c<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#define push push_back
#define m make_pair
#define N_MAX 10
#define INF (1e9)
#define s second
#define f first
using namespace std;
typedef pair<string,string> P;
void func(int,string);
string s[N_MAX],t[N_MAX],a,b;
vector<P> v;
set<string> Set;
int n,minc;

int main(){
  while(1){
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>s[i]>>t[i];
    for(int i=0;i<n;i++) v.push(m(s[i],t[i]));
    cin>>a>>b;
    minc=INF;
    if(a.size()>b.size()) swap(a,b);
    func(0,a);
    if(minc!=INF) cout<<minc<<endl;
    else cout<<-1<<endl;
    Set.clear();
    v.clear();
  }
  return 0;
}

void func(int d,string str){
  if(str==b) minc=min(minc,d);
  if(str.size()>b.size()) return ;
  if(Set.find(str)==Set.end()) Set.insert(str);
  else return ;
  string cpstr=str;
  for(int i=0;i<v.size();i++){
    for(int j=0;j<str.size();j++){
      if(str.size()-j<v[i].f.size()) continue;
      string su=str.substr(j,v[i].f.size());
      if(su==v[i].f){
	str.replace(j,v[i].f.size(),v[i].s);
	j+=v[i].s.size()-1;
      }
    }
    func(d+1,str);
    str=cpstr;
  }
}

Measured memory_bytes: 1428
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String Str = sc.next();
    int N = Str.length();
    int harf = 0;
    if(N%2==0){
      harf = N/2;
    }else{
      harf = (N-1)/2;
    }    
    for (int i = 0; i < harf; i++) {
    char c1 = Str.charAt(i);
    char c2 = Str.charAt(N-1-i);
    if(c1 != c2){
      System.out.println("No");   
      return;
    }
    }
    int harf2 =0;
    if(harf%2==0){
       harf2 = N/2;
    }else{
       harf2 = (N-1)/2;
    }  
    String Str2 = Str.substring(0,harf);
    for (int j = 0; j < harf2; j++) {
      char c3 = Str2.charAt(j);
      char c4 = Str2.charAt(harf-1-j);
      if(c3 != c4){
        System.out.println("No");   
        return;
      }
      }
    System.out.println("Yes");   
    return;
  }

}



Measured memory_bytes: 23636
[x,k,d] = [int(i) for i in input().split()]
x = abs(x)

if k < x//d:
    print(x - k * d)
else:
    k -= x // d
    x -= (x // d) * d
    if k % 2:
        print(abs(x-d))
    else:
        print(x)


Measured memory_bytes: 61784
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> lpii;
typedef unsigned long long ull;
const double eps = 1e-8;
const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 2e5 + 10;
int vis[N];
int a[N];
int l1, l2, l;
int n;
ll k;
int d[N];
void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> d[i];
    }
    vis[1] = 1;
    l = 0;
    a[l] = 1;
    int x = d[1];
    while(!vis[x]) {
        vis[x] = 1;
        a[++l] = x;
        x = d[x];
    }

    for(int i = 0; i <= l; i++) {
        if(a[i] == x) {
            l1 = i;
            break;
        }
    }
    if(k <= 1ll * l1) {
        cout << a[(int) k] << endl;
    }
    else {
        k -= (1ll *l1);
        k %= (l - l1 + 1);
        cout << a[(int)k + l1] << endl;
    }
}

int main() {
#ifdef ONLINE_JUDGE
#else
    freopen("std1.in","r",stdin);
#endif
    ios::sync_with_stdio(false);
    int t = 1;
    //cin >> t;
    //scanf("%d", &t);
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 5844
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;cin>>N;
	vector<long> A(N);
	long count=0,sum=0;
	for(int i=0;i<N;i++){
        cin>>A[i];
		if(A[i]<0){
            A[i]=-A[i];
			count++;
		}sum+=abs(A[i]);
	}if(count%2==0){
		cout<<sum<<endl;
	}else{
		long k=*min_element(A.begin(),A.end());
		cout<<sum-2*k<<endl;
	}
}

Measured memory_bytes: 1024
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 


#define lo long long int



int main() {
	int a, b,c,k;
	cin >> a >> b>>c>>k;

	cout << a + b + c+fmax(a,fmax(b,c)) * (pow(2, k) - 1);
	//system("pause");
	return 0;

}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

class data{
public:
    lli cost,line;

    bool operator<(const data &r) const
    {
        return line < r.line;
    }
};

signed main(){

    lli n;
    cin>>n;

    vector<data> v(n);

    REP(i,0,n){
        lli a,b;
        cin>>a>>b;
        v[i].cost = a;
        v[i].line = b;
    }
    sort(v.begin(),v.end());

    lli cost=0;
    REP(i,0,n){
        cost += v.at(i).cost;
        if(cost > v.at(i).line){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;



	return 0;
}

Measured memory_bytes: 3328
def main():
    n, m = map(int, input().split())
    student = [[int(x) for x in input().split()] for _ in range(n)]
    point = [[int(x) for x in input().split()] for _ in range(m)]
    answer = [0 for _ in range(n)]
    for i, begin in enumerate(student):
        a, b = begin
        dist = float("inf")
        for j, goal in enumerate(point):
            c, d = goal
            if abs(a - c) + abs(b - d) < dist:
                dist = abs(a - c) + abs(b - d)
                answer[i] = j + 1
    print("\n".join(map(str, answer)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int a = int.Parse(input[1]);
    int b = int.Parse(input[2]);
    int c = int.Parse(input[3]);
    int d = int.Parse(input[4]);
		string s = Console.ReadLine();
		bool answer = true;

    for(int i = a+1; i < c; i++)
    {
      if(s[i] == '#' && s[i-1] == '#') answer = false;
    }

    for(int i = b+1; i < d; i++)
    {
      if(s[i] == '#' && s[i-1] == '#') answer = false;
    }

    if(d < c)
    {
      answer = false;
      for(int i = b; i <= d; i++)
      {
        if(s[i] == '.' && s[i-1] == '.' && s[i-2] == '.') answer = true;
      }
    }

		Console.WriteLine(answer?"Yes":"No");
	}
}

Measured memory_bytes: 11616
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int go[100005][60];
int main(){
    int n;
    scanf("%d",&n);
    LL a[100005];
    LL ori[100005];
    for(int i = 1;i<=n;i++){
       scanf("%lld",&a[i]);
      //  a[i]=rand();
       // ori[i]=a[i];
    }
    LL dis[100005];
    for(int i = 1;i<n;i++){
        dis[i]=a[i+1]-a[i];
    }
    LL m,k;
    scanf("%lld %lld",&m,&k);
    int q[100005];
    int aa[100005];
    for(int i = 1;i<n;i++)
        aa[i]=i;
    for(int i = 1;i<=m;i++){
        scanf("%d",&q[i]);
        swap(aa[q[i]],aa[q[i]-1]);
    }
    for(int i = 1;i<n;i++){
        go[aa[i]][0]=i;
    }
    for(int i = 1;i<60;i++){
        for(int j=1;j<n;j++){
            go[j][i]=go[go[j][i-1]][i-1];
        }
    }
    int ans[100005];
    for(int j = 1;j<n;j++){
        int now=j;
        for(int i=0;i<60;i++){
            if((1ll<<i)&k)now=go[now][i];
        }
        ans[now]=j;
     //   printf("%d\n",now);
    }
    printf("%lld\n",a[1]);
    LL now=a[1];
    for(int i = 1 ;i<n;i++){
        now+=dis[ans[i]];
        printf("%lld\n",now);
    }
}
/*

b[i]*K!/(i)!*(K-i)!
*/

Measured memory_bytes: 27392
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
int arrayMax(int a[], const int N){
    int maxv = 0;
    rep(i, N)maxv = max(a[i], maxv);
    return maxv;
}
/* -- template -- */

int main(){
    int N;
    double M;cin >> N >> M;
    double sum = 0.0;
    double A[N];rep(i, N){cin >> A[i];sum += A[i];}
    int count = 0;
    rep(i, N)if(A[i] >= sum /(4.0 * M))++count;
    if(count >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<set>
int N,M,A[2010],B[2010],a[2010],b[2010];
struct edge{int to,val;edge*next;}E[40010],*ne=E,*fir[2010],*fir2[2010];
void link(int u,int v,int val=0){*ne=(edge){v,val,fir[u]};fir[u]=ne++;}
void link2(int u,int v,int val=0){*ne=(edge){v,val,fir2[u]};fir2[u]=ne++;}
std::set<int>chs[2010];
bool edel[2010],cdel[2010];
int fa[2010],dep[2010],ans=0;
int lca(int x,int y){
	while(x!=y)dep[x]>dep[y]?x=fa[x]:y=fa[y];
	return x;
}
void tag2(int x,int y){
	while(x!=y){
		if(dep[x]>dep[y]){
			if(!edel[x])edel[x]=1,ans+=2;
			x=fa[x];
		}
		else{
			if(!edel[y])edel[y]=1,ans+=2;
			y=fa[y];
		}
	}
}
void init(int i){
	for(edge*e=fir[i];e;e=e->next)if(e->to!=fa[i]){
		fa[e->to]=i;
		dep[e->to]=dep[i]+1;
		init(e->to);
	}
}
void dfs(int i){
	for(edge*e=fir[i];e;e=e->next)if(e->to!=fa[i]){
		dfs(e->to);
	}
	if(i==1)return;
	//printf("i=%d\n",i);
	//printf("3=(%d,%d) cdel3=%d\n",a[3],b[3],cdel[3]);
	for(std::set<int>::iterator it=chs[i].begin(),it2;it!=chs[i].end();it=it2){
		it2=it;++it2;
		int id=*it;
		if(cdel[id]||a[id]==b[id])chs[i].erase(it);
		//else printf("%d(%d,%d)\n",id,a[id],b[id]);
	}
	if(!edel[i]){
		if(chs[i].size()==1){
			ans++;
			int id=*chs[i].begin();
			if(a[id]==i)a[id]=fa[i];
			else b[id]=fa[i];
			chs[fa[i]].insert(id);
			edel[i]=1;
		}
		if(chs[i].size()>1){
			std::set<int>::iterator it=chs[i].begin();
			int id1=*it;
			int id2=*++it;
			bool ty1=a[id1]==i,ty2=a[id2]==i;
			int to1=ty1?b[id1]:a[id1],to2=ty2?b[id2]:a[id2];
			int l=lca(i,to1)^lca(i,to2)^lca(to1,to2);
			tag2(i,l);
			link2(id1,id2,ty1==ty2);
			link2(id2,id1,ty1==ty2);
			cdel[id1]=1;
			chs[i].erase(id1);
			if(ty2){
				chs[a[id2]].erase(id2);
				a[id2]=ty1?b[id1]:a[id1];
				chs[a[id2]].insert(id2);
			}
			else{
				chs[b[id2]].erase(id2);
				b[id2]=ty1?b[id1]:a[id1];
				chs[b[id2]].insert(id2);
			}
			//printf("%d:(%d,%d)\n",id2,a[id2],b[id2]);
			for(it=chs[i].begin();it!=chs[i].end();++it){
				int id=*it;
				if(a[id]==i)a[id]=fa[i];
				else b[id]=fa[i];
				chs[fa[i]].insert(id);
			//printf("id=%d (%d,%d) cdel=%d\n",id,a[id],b[id],cdel[id]);
			}
		}
		//printf("ans=%d\n",ans);
		//printf("3=(%d,%d) cdel3=%d\n",a[3],b[3],cdel[3]);
	}
	else{
		for(std::set<int>::iterator it=chs[i].begin();it!=chs[i].end();++it){
			int id=*it;
			if(a[id]==i)a[id]=fa[i];
			else b[id]=fa[i];
			chs[fa[i]].insert(id);
		}
	}
}
bool cvis[2010],col[2010];
void cdfs(int i,int c){
	cvis[i]=1;
	col[i]=c;
	for(edge*e=fir2[i];e;e=e->next)
		if(!cvis[e->to])cdfs(e->to,c^e->val);
}
int main(){
	scanf("%d%d",&N,&M);
	for(int i=1,u,v;i<N;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u);
	for(int i=0;i<M;i++){
		scanf("%d%d",A+i,B+i);
		chs[a[i]=A[i]].insert(i);
		chs[b[i]=B[i]].insert(i);
	}
	init(1);
	dfs(1);
	printf("%d\n",ans);
	for(int i=0;i<M;i++)if(!cvis[i])cdfs(i,0);
	for(int i=0;i<M;i++){
		if(col[i])printf("%d %d\n",B[i],A[i]);
		else printf("%d %d\n",A[i],B[i]);
	}
}

Measured memory_bytes: 56320
import java.math.*;
import java.util.*;
public class Main
{
        public static void main(String[] args)
        {
            Scanner cin = new Scanner(System.in);
            int a;
            a = cin.nextInt();
            BigInteger t = new BigInteger("1000000000000000000");
            BigInteger ans = BigInteger.valueOf(1);
            for(int i=1;i<=a;i++)
            {
                int f;
                BigInteger n = cin.nextBigInteger();
                int vis = n.compareTo(BigInteger.valueOf(0));
                if (vis == 0)
                {
                    ans = BigInteger.valueOf(0);
                }
                f = ans.compareTo(t);
                if(vis != 0 && f <= 0)
                ans = ans.multiply(n);
            }
            int k = ans.compareTo(t);
            if(k <= 0)
                System.out.println(ans);
            else System.out.println("-1\n");
        }
}

Measured memory_bytes: 59576
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>> a(h+2,vector<char>(w+2,'#'));
    for(int i=1;i<=h;i++){for(int j=1;j<=w;j++){cin>>a[i][j];}}
    rep(i,h+2){
        rep(j,w+2){
            cout<<a[i][j];
        }
        cout<<endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int k, a, b, c;
    cin >> k >> a >> b;
    c = b % k;
    if (b - c >= a)
    {
        cout << "OK" << endl;
    }
    else
    {
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
using System;

namespace AOJ.Volume1
{
    public class CollatzProblem
    {
        public static int Main()
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }

                int cnt = 0;
                while (n > 1)
                {
                    if (n % 2 == 0) { n = n / 2; }
                    else { n = n * 3 + 1; }
                    cnt++;
                }
                Console.WriteLine(cnt);
            }
            return 0;
        }
    }
}

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);std::cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    string T,W;
    int count = 0;
    std::cin >> W;
    for(int i=0,l=W.size();i<l;i++){
        if(W[i]>='A'&&W[i]<='Z') W[i]+=('a'-'A');
    }
    while(cin>>T){
        if(T=="END_OF_TEXT") break;
        for (int i = 0,l=T.size(); i < l; i++)
        {
            if(T[i]>='A'&&T[i]<='Z') T[i]+=('a'-'A');
        }
        if(W==T)count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3208
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = sc.nextInt();
		
		long ans = 0;
		int last = 0;
		for(int i=0; i<N; i++) {
			int a = sc.nextInt();
			int eat = Math.max(0, last+a-x);
			ans += eat;
			last = a-eat;
		}
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 32264
// // --------------------<optimizations>--------------------
// #pragma GCC optimize("O3")
 
// //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
// #pragma comment(linker, "/stack:200000000")
// //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
// #pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}

// map<ll, list<ll>> m;
map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    // cin >> t;
    while(t--) {
        ll n, x=360;
        cin >> n;
        for(ll i=1; i<=n; i++) {
            if(x*i%n==0) {
                x*=i;
                break;
            }
        }
        cout << (int)(x/n) << endl;
    }
}

Measured memory_bytes: 3160
<?php
$S=intval(fgets(STDIN));
$sec=$S%60;
$m=intval($S/60);
$d=0;

if($m>=60){
    $d=intval($S/3600);
    $m=$m-$d*60;
}

echo $d.":";
echo $m.":";
echo $sec."\n";
?>


Measured memory_bytes: 9188
import sys

n = int(sys.stdin.readline().rstrip())

def to_neg_base(n, neg_base):
    if neg_base > -2:
        sys.exit('base must be at most -2')
    b = abs(neg_base)
    res = [0] * 100
    if n >= 0:
        res[0] = n
        i = 0
    else:
        q, r = divmod(n, b)
        res[0] = r; res[1] = abs(q)
        i = 1

    while res[i] >= b:
        q, r = divmod(res[i], b)
        m = min(q, res[i+1])
        q -= m
        res[i+1] -= m
        res[i] = r
        res[i+1] += (b - 1) * q
        res[i+2] += q
        i += 1

    res = ''.join(list(map(str, res)))[::-1]
    try: 
        return int(res[res.index('1'):])
    except:
        return 0

def main():
    return to_neg_base(n, -2)

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  int ans = 0;
  vector<int> count(3, 0); // BXXA, Bxx, xxA
  rep(i, N)
  {
    string s;
    cin >> s;
    rep(j, s.size() - 1)
    {
      if (s[j] == 'A' && s[j + 1] == 'B')
        ans++;
    }

    if (s.front() == 'B' && s.back() == 'A')
      count[0]++;
    else if (s.front() == 'B')
      count[1]++;
    else if (s.back() == 'A')
      count[2]++;
  }

  ans += count[0] + min(count[1], count[2]);
  if (count[0] > 0 && count[1] + count[2] == 0)
    ans--;

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# TLE 乙
from collections import deque


s = input()
q = int(input())
usd = False
d = deque(s)

for _ in range(q):
    t, *fc = input().split()
    t = int(t)
    if fc:
        fc[0] = int(fc[0])

    if t == 1:
        usd = not usd
        continue
    if t == 2:
        if (fc[0] == 1 and not usd) or (fc[0] == 2 and usd):
            d.appendleft(fc[1])
        else:
            d.append(fc[1])

s = ''.join(list(d))
if usd:
    s = s[::-1]
print(s)

Measured memory_bytes: 8564
#include<bits/stdc++.h>
 
#define    pi          acos(-1) 
#define    all(x)      (x).begin(),(x).end()
#define    fill(x,y)   memset(x, y, sizeof(x))
#define    gcd(x,y)    __gcd(x,y)
#define    lcm(x,y)    (x*(y/gcd(x,y))
#define    trace(x)    cout << #x << " = " << x << endl
#define    bug         cout << "Bug check" << endl
#define    endl        '\n'
 
using namespace std; 

int main(){
	//freopen("in.txt","r", stdin);
	//freopen("out.txt","w", stdout);
 
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	int n; cin >> n;
	cout << ceil(n/2.0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
    	long N;
     
    	long d,dtem,ans=0;
     
    	long H=0,Htem=0;
     
    	cin >> N;
    	vector<long> a(N,0);
     
    	for(int i=0;i<N;i++){
    		cin >> a[i];
    	}
     
    	for(int i=0;i<N-2;++i){
    		if(i>N){break;}
    		d=a[i+1]-a[i];
    		dtem=a[i+2]-a[i+1];

			if(d>0){ H=1;
			}else if(d<0){ H=2;
			}else {}
			
    		if(d<0 && dtem>0){
    			ans++;
    			i++;
				H=0;
    		}else if(d>0 && dtem<0){
    			ans++;
    			i++;
				H=0;
    		}else if(d==0 && dtem>0 && H==2){
    			ans++;
    			i++;
				H=0;
			}else if(d==0 && dtem<0 && H==1){
    			ans++;
    			i++;
				H=0;
			}
    	}
     
     
    	cout << ans+1 << endl;


    	return 0;
    }

Measured memory_bytes: 1024