akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 1e6+5;


signed main(){
    IOS();
    int n; cin>>n;
    vector<int> a(n);
    for (int i = 0; i<n; ++i) cin>>a[i];
    sort(ALL(a), greater<int>());
    a.pb(0);
    for (int i = 1; ; ++i) {
        if (i == n+1 || a[i-1] < i) {
            --i;
            bug(i);
            int goup = a[i-1] - i;
            int gor = 0;
            for (int j = i+1; a[j-1] >=i; ++j, ++gor);
            bug(goup, gor);
            if (goup % 2 == 0 && gor % 2 == 0) cout<<"Second"<<endl;
            else cout<<"First"<<endl;
            break;
        }
    }


}


Measured memory_bytes: 1024
from bisect import bisect_right
n, m = map(int, input().split())
py = [tuple(map(int, input().split())) for _ in range(m)]
d = dict()
for p, y in py:
    if p not in d.keys():
        d[p] = [y]
    else:
        d[p].append(y)

for v in d.values():
    v.sort()

for p, y in py:
    print(str(p).zfill(6) + str(bisect_right(d[p], y)).zfill(6))


Measured memory_bytes: 36932
#include <bits/stdc++.h>
using namespace std;
struct point{int x, y;};
int main() {
  vector<long long> arm;
  for (int i = 30; i >= 0; i--) {
    arm.push_back(1 << i);
  }
  int n;
  cin >> n;
  vector<point> p;
  int judge;
  for (int i = 0; i < n; i++) {
    point pp;
    cin >> pp.x >> pp.y;
    if (i == 0) {
      if ((pp.x + pp.y) & 1) judge = 1;
      else judge = 0;
    } else {
      if (((pp.x + pp.y) & 1) != judge) {
        puts("-1");
        return 0;
      }
    }
    p.push_back(pp);
  }
  if (!judge) arm.push_back(1);
  cout << arm.size() << endl;
  for (int i = 0; i < arm.size(); i++) {
    cout << arm[i];
    if (i != arm.size() - 1) cout << " ";
  }
  cout << endl;
  for (int i = 0; i < p.size(); i++) {
    int xx = p[i].x, yy = p[i].y;
    int px = 0, py = 0;
    for (int j = 0; j < arm.size(); j++) {
      int xxx = xx - px, yyy = yy - py;
      //R
      if (xxx >= 0 && abs(yyy) <= xxx) {
        cout << 'R';
        px += arm[j];
      }
      //L
      else if (xxx <= 0 && abs(yyy) <= abs(xxx)) {
        cout << 'L';
        px -= arm[j];
      }
      //U
      else if (yyy > 0) {
        cout << 'U';
        py += arm[j];
      }
      //D
      else {
        cout << 'D';
        py -= arm[j];
      }
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
const int IMAX = 200010;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
	unko() : fac(), ifac(), inv() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
	}
	int comb(int A, int B) {
		return ll(fac[A]) * ifac[B] % mod * ifac[A - B] % mod;
	}
} f;

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


	int N, K;
	cin >> N >> K;


	ll kotae = 0;
	rep(i, min(N, K + 1)) {
		kotae += ll(f.comb(N - 1, i)) * f.comb(N, i) % mod;
	}

	kotae %= mod;
	co(kotae);


	Would you please return 0;
}

Measured memory_bytes: 2560
formed_datasets = []

def repeated_num(line)
  line.map { |num, _| num }.sort.each_with_object([]) { |n, a| 
    !a.last.nil? && a.last[0] == n ? a.last[1] += 1 : a << [n, 1]
  }.map { |n, i| n if i > 1 }.compact
end

def checker(arr)
  arr.find_all { |n, _| repeated_num(arr).include?(n) }.map { |_, c| c }
end

def row_check(puzzle)
  puzzle.map { |row| checker(row) }.flatten(1)
end

def column_check(puzzle)
  puzzle.transpose.map { |col| checker(col) }.flatten(1)
end

def square_check(puzzle)
  squared = Array.new(9).map { [] }

  puzzle.each_with_index do |r, i|
    r.each_with_index do |n, j|
      squared[i / 3 * 3 + j / 3] << n
    end
  end
  
  squared.map { |chunk| checker(chunk) }.flatten(1)
end

gets.to_i.times do
  puzzle = Array.new(9) { Array.new(9) }

  9.times do |i|
    gets.split.map(&:to_i).each_with_index { |num, j| puzzle[i][j] = [num, [i, j]]}
  end

  repeated_num_coor =
    (row_check(puzzle) + column_check(puzzle) + square_check(puzzle)).uniq

  formed_datasets << puzzle.map { |row|
    row.map { |n, c| repeated_num_coor.include?(c) ? "*#{n}" : " #{n}" }.join
  }.join("\n")
end

puts formed_datasets.join("\n\n")

Measured memory_bytes: 9244
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807/2;
const int MOD = 1000000007;
const int N_MAX = pow(10,2);
const int V_MAX = pow(10,5);

int main() {
  ll N, W; cin >> N >> W;
  ll a[N+1][2]; for(int i=1; i<=N; i++) rep(j, 2) cin >> a[i][j];

  ll dp[N_MAX+1][V_MAX+1] = {}; rep(i,N_MAX+1) fill_n(dp[i],V_MAX+1,INF);
  dp[0][0] = 0;
  for (int i=1; i<=N; i++) for (int j=0; j<=V_MAX; j++) {
    if (j>=a[i][1]) dp[i][j] = min(dp[i-1][j], dp[i-1][j-a[i][1]]+a[i][0]);
    else dp[i][j] = dp[i-1][j];
  }

  int result = 0;
  rep(j, V_MAX+1) if (dp[N][j] <= W) result = max(result, j);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 79232
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <fstream>
#include <numeric>


using namespace std;

#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b

int K, A, B;

int main() {

    cin >> K;
    cin >> A >> B;

    for (int i = A; i <= B; i++) {
        if (i % K == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }


    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3632
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end

N, M= inputs[0].split(" ").map(&:to_i)
$ng_list = Hash.new
inputs[1..-1].map do |s|
  ng = s.split(" ").map(&:to_i)[0]
  $ng_list[ng] = true
end

def count(n)
  cnts = []
  i = -1
  while i < n; i += 1;
    if $ng_list[i]
      cnts[i] = 0
      next
    elsif i == 0
      cnts[i] = 1
      next
    elsif i == 1
      cnts[i] = 1
      next
    else
      res = cnts[i - 1] + cnts[i - 2]
      cnts[i] = res
      next
    end
  end

  cnts.last
end

p count(N) % 1000000007

Measured memory_bytes: 433020
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<fstream>
#include<map>
#include<bitset>
#include<unordered_map>
#include<cstring>
#include<cctype>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
ll fix_mod(ll x, ll y)
{
	return (y + x % y) % y;
}
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);


}
int n,c;
vector<ll>v;
ll mem[(int)1e5 + 10];
ll solve(int i)
{
	if (i == n-1)return 0;
	ll& ret = mem[i];
	if (~ret)return ret;
	ret = solve(i + 1) + abs(v[i + 1] - v[i]);
	for (int k = 2; k <= c; k++)
		if (k + i < n)ret = min(ret, solve(i + k) + abs(v[i + k] - v[i]));
	return ret;
}
int main()
{
	Mohammed_Atef_Hassan
		clr(mem, -1);
		cin >> n>>c;
	v = vector<ll>(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	ex(solve(0));
}

Measured memory_bytes: 6528
import math

S = int(input())

x = S // 3
y = S % 3

ans = 0

if 3<=S:
  for i in range(x):
    a = S - 3 * (i + 1)
    b = math.factorial(a+i) // math.factorial(a) // math.factorial(i)
    b %= 1000000007
    ans += b
    ans %= 1000000007
else:
  ans = 0
  
print(ans)


Measured memory_bytes: 73716
while True:
    n,k=map(int,raw_input().split())
    if n==k==0:break
    L=[input() for i in range(n)]
    maxInt=-10000000
    temp=sum(L[:k])
    for i in range(k,n):
        maxInt=max(maxInt,temp)
        temp=temp+L[i]-L[i-k]
    print maxInt

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef pair<int,int> pii;

int N,M;
bool vis[100010];
int dis[100010];
vector<pii> V[100010];
bool flag = false;

void DFS(int v,int d)
{
    if(!vis[v])
    {
        vis[v] = true;
        dis[v] = d;
    }
    else
    {
        if(dis[v] != d)
        flag = true;
        return;
    }

    for(int i = 0; i < V[v].size(); i++)
    {
        pii now = V[v][i];
        DFS(now.fi,now.se + d);
    }
    return;
}

int main()
{
    scanf("%d%d",&N,&M);
    for(int i = 0; i < M; i++)
    {
        int l,r,d;
        scanf("%d%d%d",&l,&r,&d);
        V[l].push_back(mk(r,d));
        V[r].push_back(mk(l,-d));
    }

    for(int i = 1; i <= N; i++)
    {
        if(!vis[i])
        {
            DFS(i,0);
        }
    }

    if(flag)printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define re(v) {for(auto &_re : v) cin >> _re;}
#define rre(v){for(auto &_re : v) for(auto &_rre : _re) cin >> _rre;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define prr(v) {for(auto _prr : v) cout << _prr.ff << " " << _prr.ss << endl;}
#define eb emplace_back
using namespace std;
const ll M = 1e9 + 7;
const ll mod = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define int long long
ll binpow(ll a, ll b, ll m){
	ll res = 1;
	while(b > 0){
		if(b&1) res = res * a % m;
		a = a * a % m;
		b>>=1;
	}
	return res;
}
const int maxn = 2e5 + 10;
ll fat[maxn + 1];
ll ifat[maxn + 1];
void solve(){
	fat[0] = 1;
	for(int i=1;i<=maxn;i++){
		fat[i] = fat[i-1] * i % M;
	}
	ifat[maxn] = binpow(fat[maxn], M-2, M);
	for(int i=maxn-1;i>=0;i--){
		ifat[i] = ifat[i+1] * (i+1) % M;
	}
	auto C = [&](int n,int k){
		if(k >= n) return 1LL;
		return (fat[n] * ifat[k] % M) * ifat[n-k] % M;
	};
	auto ways = [&](int x, int y, int o_x, int o_y){
		// (0,0) -> (i,j) = C(i+j, j)
		return C(o_x + o_y - x - y, o_y - y);
	};
	int h,w,n;
	cin >> h >> w >> n;
	vector<pii> p(n);
	for(pii &y : p){
		cin >> y.ff >> y.ss;
		y.ff--; y.ss--;
	}
	p.pb({h-1,w-1});
	sort(td(p), [&](pii a, pii b){
		return (a.ff == b.ff ? a.ss < b.ss : a.ff < b.ff);
	});
	ll dp[n+1];
	for(int i=0;i<=n;i++){
		dp[i] = ways(0, 0, p[i].ff, p[i].ss);
	}
	//cout << dp[1] << endl;
	for(int i=0;i<=n;i++){
		for(int j=0;j<i;j++){
			if(p[j].ss > p[i].ss) continue;
			ll aux = ways(p[j].ff, p[j].ss, p[i].ff, p[i].ss);
			dp[i] -= dp[j] * aux;
			dp[i] %= M;
		}
		//cout << dp[i] << " ";
	}
	//cout << endl;
	cout << (dp[n]+M)%M << endl;
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }  
}

Measured memory_bytes: 6844
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll x = ceil(a*1.0/d), y = ceil(c*1.0/b);
    //cout << x<< " " << y << endl;
    cout  << (x < y ? "No":"Yes")<<endl;
}
   

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  //int t;scanf("%d", &t);while(t--)
  solve();
  return 0;
}


Measured memory_bytes: 3760
import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

class DualSegmentTree:
    def __init__(self, n) :
        self.n = n
        self.N0 = 1 << n.bit_length()
        self.data = [0] * (self.N0*2)

    def update(self, l, r, val) :
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] = self.data[l] + val
                l += 1
            if r & 1:
                self.data[r-1] = self.data[r-1] + val
                r -= 1
            l //= 2
            r //= 2

    def query(self, i):
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = ret + self.data[i]
        return ret




def main():
    N,D,A = list(map(int,input().split()))

    enemy = []
    for i in range(N):
        x,h = list(map(int,input().split()))
        if h%A==0:
            enemy.append([x,h//A])
        else:
            enemy.append([x,h//A+1])

    enemy.sort(key=lambda x:x[0])
    def bisect(index):
        x = enemy[index][0]
        if enemy[N-1][0] <= x + 2*D:
            return N-1
        l = index
        r = N-1
        while r-l>1:
            if enemy[(r+l)//2][0] <= x + 2*D:
                l = (r+l)//2
            else:
                r = (r+l)//2
        return l
    ST = DualSegmentTree(N)

    for i in range(N):
        ST.update(i,i+1,enemy[i][1])

    count = 0
    for i in range(N):
        v = ST.query(i)
        if v>0:
            count += v
            j = bisect(i)
            ST.update(i,j+1,-v) 

    print(count)

if __name__ == '__main__':
    main()



Measured memory_bytes: 88204
#include<bits/stdc++.h>
#include <iterator>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
using namespace std;
vector<pii> point;
int main(){
   
   ll n;
   cin>>n;
   ll min_diff=1e18,max_diff=-1e18;
   ll min_sum=1e18,max_sum=-1e18;
   for(ll i=1;i<=n;i++){
   	ll x,y;
   	cin>>x>>y;
   	point.pb(mpa(x,y));
   	min_diff=min(min_diff,x-y);
   	max_diff=max(max_diff,x-y);
   	min_sum=min(min_sum,x+y);
   	max_sum=max(max_sum,x+y);
    }
    
    ll ans=-1e18;
    
    for(ll i=0;i<n;i++){
    	ll x=point[i].ff;
    	ll y=point[i].ss;
		ll cs=x+y;
    	ll cd=x-y;
    	ans=max(ans,abs(min_sum-cs));
    	ans=max(ans,abs(max_sum-cs));
    	ans=max(ans,abs(min_diff-cd));
    	ans=max(ans,abs(max_diff-cd));
	}
	cout<<ans;
   
  
   
}
    
   
   

  
   
 

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

int main() {
  int n, k;
  cin >> n >> k;
  int sum = 0;
  
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x <= k - x)
      sum += x * 2;
    else
      sum += (k - x) * 2;
  }
  
  cout << sum << endl;
}


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

#define ll long long

using namespace std;

int n;
int l[100010], r[100010];
ll len[100010], lazyn, lazyp;
priority_queue<ll> neg;
priority_queue<ll, vector<ll>, greater<ll> > pos;
ll ans = 0;

int main(){
    scanf("%d", &n);

    scanf("%d%d", &l[0], &r[0]);
    len[0] = r[0] - l[0];
    neg.push(l[0]);
    pos.push(l[0]);

    for(int i = 1; i < n; i++){
        scanf("%d%d", &l[i], &r[i]);
        len[i] = r[i] - l[i];

        lazyp += len[i - 1];
        lazyn -= len[i];

        if(l[i] >= pos.top() + lazyp){
            pos.push(l[i] - lazyp);
            pos.push(l[i] - lazyp);
            ans += l[i] - (pos.top() + lazyp);
            neg.push(pos.top() + lazyp - lazyn);
            pos.pop();
        } else if (l[i] <= neg.top() + lazyn){
            neg.push(l[i] - lazyn);
            neg.push(l[i] - lazyn);
            ans += neg.top() + lazyn - l[i];
            pos.push(neg.top() + lazyn - lazyp);
            neg.pop();
        } else {
            pos.push(l[i] - lazyp);
            neg.push(l[i] - lazyn);
        }
    }

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

    return 0;
}

Measured memory_bytes: 3564
local a, b = io.read("*n", "*n")
local c = 0
for i = a, b do
  local s = tostring(i)
  if s:sub(1, 1) == s:sub(5, 5)
  and s:sub(2, 2) == s:sub(4, 4) then
    c = c + 1
  end
end
print(c)


Measured memory_bytes: 880
#include <cstdio>
#include <cstring>

char a[100005];

int main() {
    int n, k, tmp;
    scanf("%s", a);
    scanf("%d", &k);
    n = strlen(a);
    for(int i = 0; i < n; i++) {
	if(i != n - 1 && a[i] == 'a') continue;
	if(i == n - 1) {
	    a[i] = (a[i] - 'a' + k) % 26 + 'a';
	    continue;
	}
	tmp = 'z' - a[i] + 1;
	if(tmp <= k) {
	    k -= tmp;
	    a[i] = 'a';	    
	}
    }
    printf("%s\n", a);
    return 0;
}


Measured memory_bytes: 384
n=int(input())
x=list(input().split())
x=[int(s) for s in x]
if n==1 or len(set(x))==1:
    print(0)
else:
    b_li=[]
    for i in range(min(x),max(x)):
        a_li=[]
        for j in range(n):
            a=(x[j]-i)**2
            a_li.append(a)
        b=sum(a_li)
        b_li.append(b)
    print(min(b_li))


Measured memory_bytes: 3064
s = input()
a = ["A","T","G","C"]
b = []
n = len(s)
for i in range(n):
    if s[i] in a:
        b.append(1)
    else:
        b.append(0)

for i in range(1,n):
    if b[i]>0:
        b[i] = b[i-1] + 1

print(max(b))

Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

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

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

ll n,k;
vector<vector<int>> g;

int main(){
  int ans=0;
  cin >> n >> k;
  vector<int> a(n),b(n),c(n),d(n,-1);//bは自分位置が先頭のとき次どこが先頭になるかを記憶する変数、c(n)は繰り下がりフラグ
  REP(i,n) cin>>a[i];
  
  g.resize(200000);


  for(int i=0;i<n;i++) {
    a[i]--;
    g[a[i]].emplace_back(i);
  }
  
  for(int i=0;i<n;i++) {
    int bb=a[i];
    ans=-1;
    for(auto to : g[bb]) {
      if (to>i){
        ans=to;
        break;
      }
    }
    if (ans!=-1){
      b[i]=(ans+1);
      c[i]=0;
    }else{
      b[i]=g[bb][0]+1;
      c[i]=1;
    }
    
    if (b[i]==n){
      b[i]=0;
      c[i]++;
    }

  }

  //dは初期を0,0としたときの先頭移動記憶変数
  ll idx_d=0,row=0;

  for(int i=0;i<n+1;i++) {
    d[idx_d]=row;
    row+=c[idx_d];
    idx_d=b[idx_d];
    if (d[idx_d]!=-1)break;
  }
  //idx_dは0になっているはず・・・
  //これで先頭位置がrow,0になった
  /*
  cout<<row<<endl;
  for(int i=0;i<n;i++) {
    cout<<b[i]<<" "<<c[i]<<endl;
  }
   */
  
  k%=row;
  //もう一度
  row=0;idx_d=0;
  for(int i=0;i<n+1;i++) {
    if (row==k)break;
    row+=c[idx_d];
    if (row==k)break;
    idx_d=b[idx_d];
  }
  //最終行の戦闘はidx_d !!!

  row=0;
  for(int i=0;i<n+1;i++) {
    if (idx_d>=n)break;
    int bb=a[idx_d];
    ans=-1;
    for(auto to : g[bb]) {
      if (to>idx_d){
        ans=to;
        break;
      }
    }
    if (ans!=-1){
      idx_d=ans+1;
      continue;
    }

    cout<<(a[idx_d]+1)<<" ";
    idx_d++;
  }
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int A, B;
	cin >> A >> B;

	if( A+B >= 10 ) {
		cout << "error\n";
	}
	else {
		cout << A+B << endl;
	}

	return 0;
}


Measured memory_bytes: 256
def main():
  n=int(input())
  s=input()
  dp=[[0]*(n+1) for i in range(n+1)]
  ans=0
  for i in reversed(range(n)):
    for j in reversed(range(i+1,n)):
      if s[i]==s[j]:
        dp[i][j]=dp[i+1][j+1]+1
        ans=max(ans,min(j-i,dp[i][j]))
  print(ans)
        

if __name__=='__main__':
  main()

Measured memory_bytes: 270080
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a;i < b;i++)
#define rrep(i,a,b) for(int i = a;i >= b;i--)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << #x << ": " << x << endl;
typedef long long ll;
using namespace std;

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

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

   int a,b;
   cin >> a >> b;
   cout << a - (b -1) << endl;

   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
    int f[N2];
    int space;
    string path;
    
    bool operator < (const Puzzle &p) const{
        for(int i = 0;i<N2;i++){
            if(f[i] == p.f[i]) continue;
            return f[i] > p.f[i];
        }
        return false;
    }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const int dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p){
    for(int i = 0;i<N2;i++)
    if(p.f[i] != (i+1)) return false;
    return true;
}

string bfs(Puzzle s){
    queue<Puzzle> Q;
    map<Puzzle, bool> V;
    Puzzle u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;
    
    while(!Q.empty()){
        u = Q.front(); Q.pop();
        if(isTarget(u)) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for(int r = 0;r<4;r++){
            int tx = sx+dx[r];
            int ty = sy+dy[r];
            if(tx<0 || ty<0 || tx >=N || ty >=N) continue;
            v = u;
            swap(v.f[u.space], v.f[tx*N+ty]);
            v.space = tx*N+ty;
            if(!V[v]){
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    
    return "unsolvable";
}

int main(){
    Puzzle in;
    
    for(int i = 0;i<N2;i++){
        cin >> in.f[i];
        if(in.f[i] == 0 ){
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = bfs(in);
    cout << ans.size() << endl;
    
    return 0;
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<31)
#define INFLL (1L<<63)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int N, M;
bool G[8][8];
int state[8];

bool all_visited(void) {
  rep(i, N) if(state[i] == 0) return false;
  return true;
}

int dfs(int nn) {
  int cnt = 0;
  state[nn] = 1; // visiting
  rep(n, N) {
    if (!G[n][nn] || state[n] != 0 || n == nn)
      continue;
    cnt += dfs(n);
  }
  cnt = cnt == 0 ? all_visited() : cnt;
  state[nn] = 0;
  return cnt;
}

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, 8) rep(j, 8) G[i][j] = false;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a][b] = true;
    G[b][a] = true;
  }
  cout << dfs(0) << endl;
  return 0;
}


Measured memory_bytes: 256
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=1e5+5;
const int mod=1e9+7;

ll n,p[20],s[20];
signed main(){
    FastIO;
    cin>>n;
    s[0]=p[0]=1;
    int len=1;
    rep(i,1,13){
        p[i]=p[i-1]*26;
        s[i]=s[i-1]+p[i];
        if(n>=s[i]) len=i+1;
    }
    n-=s[len-1];
//    cout<<n<<"::"<<len<<endl;
    string s;
    while(len--){
        s+=char('a'+n%26);
        n/=26;
    }
    reverse(all(s));
    cout<<s;
    return 0;
}


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

#define A 12

int main()
{
  int n,i,j;
  int alpha[A]={3,5,7,9,11,13,15,17,19,21,23,25},beta;
  string s,t;
  bool f;
  getline(cin,s);
  while(getline(cin,s)){
    f=true;
    t=s;
    if(t.find("this ",0)==0)f=false;
    if(t.find("that ",0)==0)f=false;
    if(t.find(" this",t.size()-5)==t.size()-5)f=false;
    if(t.find(" that",t.size()-5)==t.size()-5)f=false;
    if(t.find(" this ")!=string::npos)f=false;
    if(t.find(" that ")!=string::npos)f=false;
    for(i=0;f && i<A;i++){
      for(beta=0;f && beta<26;beta++){
	t=s;
	for(j=0;j<t.size();j++){
	  if(t[j]==' ')continue;
	  t[j]-='a';
	  t[j]=(t[j]*alpha[i]+beta)%26;
	  t[j]+='a';
	}
	if(t.find("this ",0)==0)f=false;
	if(t.find("that ",0)==0)f=false;
	if(t.find(" this",t.size()-5)==t.size()-5)f=false;
	if(t.find(" that",t.size()-5)==t.size()-5)f=false;
	if(t.find(" this ")!=string::npos)f=false;
	if(t.find(" that ")!=string::npos)f=false;
      }
    }
    cout<<t<<endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<string>

using namespace std;

int main(){
  	int n;
	cin >> n;
  	float a[n];
  	string b[n];
  	float result = 0;
  	for(int i=0;i<n;i++) {
    	cin >> a[i] >> b[i];
      	if (b[i]=="JPY"){
        	result += a[i];
        }else{
        	result += a[i] * 380000.0;
        }
    }
  
	cout << result <<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::{stdin,Read};
use std::str::FromStr;

fn main(){
    let x = read::<i64>();
    let y = read::<i64>();
    if x - y >= -1 && x - y <=1 {
        println!("Brown");
    }
    else{
        println!("Alice");
    }
}

#[allow(dead_code)]
fn read_str() -> Vec<char>{
    let s :String = read();
    s.chars().collect::<Vec<char>>()
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().unwrap_or_else(|_| panic!("Faild to parse {}", s))
}


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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

#define F first
#define S second

LL binpow (LL x, LL p , LL m) {
	x %= m;
	LL res = 1;
	while (p) {
		if (p&1) {
			res = res * x % m;
		}
		x = x* x % m;
		p >>= 1;
	}
	return res;
}

int main() {
	fastio();
	
	LL s;
	cin >> s;

	if (s < 3) cout << "0\n";
	else {
		vector<LL> d(s+1, 0);
		d[0] = 1;
		for (LL i = 3; i <= s; ++i) {
			for (LL j = 3; j <= s; ++j) {
				if (i - j >= 0) {
					d[i] += d[i-j];
					d[i] %= MOD;
				}
				else {
					break;
				}
			}
		}
		cout << d[s] << "\n";
	}

}

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

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

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

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

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

vector<int> to[200100];
vector<int> ans;
void dfs(int u, int p=-1){
    for(int v: to[u]){
        if(v == p) continue;
        ans[v] += ans[u];
        dfs(v, u);
    }
}

int main()
{
    int N, Q; cin >> N >> Q;
    rep(i,N-1){
        int a, b; cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(N);  // vectorのサイズをNに変更する、デフォルトは0らしい
    rep(i,Q){
        int p, x; cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);
    rep(i,N){
        cout << ans[i];
        if(i != N-1) cout << " ";
    }cout << endl;
}

Measured memory_bytes: 23424
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>

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

    int a,b;
    cin>>a>>b;
    int ans=a*b-a-b+1;
    cout<<ans;
return(0);
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	n, s, t := scanInt(sc), scanString(sc), scanString(sc)
slideStart:
	for i := 0; i < len(s); i++ {
		for j := i; j < len(s); j++ {
			if s[j] != t[j-i] {
				continue slideStart
			}
		}
		return i + len(t)
	}
	return 2 * n
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
import java.io.*
import java.util.*
import java.lang.Math.*


fun main() {
    val (A,B,H,M) = rd.readIntArray()

    val alpha = 30*H + 0.5*M
    val beta = 6*M

    val ans = when {
         alpha <= beta -> {
             val theta = (beta -alpha)/180*PI
             sqrt(A*A + B*B - 2*A*B*cos(theta))
         }
        else -> {
            val theta = (alpha - beta)/180*PI
            sqrt(A*A + B*B - 2*A*B*cos(theta))
        }
    }

    println("%.12f".format(ans))
}


//val rd = debug.Reader("abc", "168", "c", "sample-1")
val rd = Reader()
fun main(args: Array<String>) {
    Thread(null, MainThread(), "mainThread", 128 * 1024 * 1024).start()
}


const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
class MainThread : Runnable {
    override fun run() { main() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


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

int main(){
  string s;
  cin >> s;
  int k;
  cin >> k;
  int count=0;
  int first;
  for (int i=0;i<s.size();i++){
    if(s.at(i)=='1'){
      count++;
    }
    else{
      first=i;
      break;
    }
  }
  if(k>count){
    cout << s.at(first) << endl;
  }
  else {
    cout << 1 << endl;
  }
}



Measured memory_bytes: 256
def digit_sum(x)
  x.to_s.split('').map{|c| c.ord - '0'.ord}.reduce('+')
end

def calc(a, b)
  digit_sum(a) + digit_sum(b)
end

def main(argv)
  n = gets.chomp.to_i

  m =1e+9.to_i
  (1..((n + 1) / 2)).each do |a|
    b = n - a
    m = [m, calc(a, b)].min
  end
  puts m.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

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

int main() {
  int n;
  cin >> n;
  int a[n], c[n-1];
  rep(i,n) {
    cin >> a[i];
    --a[i];
  }
  int sum = 0;
  rep(i,n) {
    int b;
    cin >> b;
    sum += b;
  }
  rep(i,n-1) cin >> c[i];
  
  rep(i,n) {
    if (a[i+1]-a[i] == 1) {
      sum += c[a[i]];
    }
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
import fractions
N, K = map(int, input().split())
A = list(map(int, input().split()))
if max(A) >= K:
    for i, a in enumerate(A):
        if i == 0:
            gcd = a
            continue
        gcd = fractions.gcd(gcd, a)
    if K % gcd == 0:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Measured memory_bytes: 88172
let sort array n =
  let rec bubble_sort a c =
    let rec bubble c = function
      | 0 -> a,c
      | i ->
        let ai,aj = a.(i),a.(i-1) in
        bubble
          (if ai < aj then (a.(i) <- aj; a.(i-1) <- ai; c+1) else c) (i-1)
    in
    match bubble 0 n with
      v,0 -> v,c
    | v,t -> bubble_sort v (c+t)
  in
  bubble_sort array 0
    
let () =
  let n = read_int () in
  let a = read_line () |> Str.split (Str.regexp " ")
          |> List.map int_of_string |> Array.of_list in
  let sorted,c = sort a (n-1) in
  Array.iteri
    (fun i x -> Printf.printf (if i=n-1 then "%d\n" else "%d ") x) sorted;
  Printf.printf "%d\n" c

Measured memory_bytes: 2464
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h> 
#include <iostream>
#include <map>
#include <cmath>
#include<set>
#include <vector>
#include<bitset>
#include <string>
#include<queue>
#include <algorithm>
#include<set>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define vl vector<long long >;
//#define rep(i,a,b) for(int i=a;i<b;++i)
//typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<int,int>ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef long long ll;
const int N=105;//const int NN=1000000001;
//int A[N];int B[N];
#define INF 1e18L+5
//int dp[2][NN];
//int dp[N][N][N]={0};
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

/*void show(vi v,int valeur){
    int count=0;
    
    rep(i,0,(int)v.size()){
        ++count;
        cout<<v[i]<<" " ;
        if(count==valeur){cout<<"\n";count=0;}
    }
}*/
 int main() {
        ios_base::sync_with_stdio(false); cin.tie(NULL);int n,c;
  
  cin>>n>>c;
  vi a(n+1),b(n+1);ll somme=0;
  rep(i,0,n){
      cin>>b[i]>>a[i];somme+=a[i];
  }
  vector<long long> dp(somme+1,INF);dp[0]=0;
  rep(i,0,n){
      for(int value=(somme-a[i]);value>=0;--value){
          dp[value+a[i]]=min(dp[value+a[i]],b[i]+dp[value]);
      }
  }
  ll ans=0;
  ++somme;
  rep(i,0,(somme)){
      if(dp[i]<=c)ans=max(ans,(ll)i);
  }
  cout<<ans;
   return 0;
 }



Measured memory_bytes: 3996
y=[0]*100
while True:
    try:
        y[int(input())-1]+=1
    except:
        break
    
flag=False
for i in range(100)[::-1]:
    if flag:
        exit()
    for j in range(100):
        if y[j]==i:
            flag=True
            print(j+1)


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

using namespace std;
const float pi = 3.14159;
int area(int r){
    return r * r;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int r;
    cin >> r;
    cout << area(r) << endl;
}

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

int main() {

    string s;

    cin >> s;

    string ans = "First";

    if(s.size()%2 == 1 && s[0] == s[s.size()-1] || s.size()%2 == 0 && s[0] != s[s.size()-1]){
        ans = "Second";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  int N; cin >> N;
  vi a(N); REP(i,N) cin >> a[i];

  SORT(a);

  int ans = 0;
  int prev = a[0];
  int cnt = 0;
  REP(i,N) {
    if (i==N-1) {
      if (prev==a[i]) {
        cnt++;
      }
      if (prev!=cnt) {
        ans += (cnt>prev?cnt-prev:cnt);
      }
    }

    if (prev==a[i]) {
      cnt++;
    }
    else {
      if (prev!=cnt) {
        ans += (cnt>prev?cnt-prev:cnt);
        cnt = 1;
      }
      else {
        cnt = 1;
      }
    }
    prev = a[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll m,n; cin>>m>>n;
	ll ans=0;
	vector<pair<ll,int> > vec;
	for(int i=0;i<m;i++)
	{
		ll x; cin>>x;
		vec.pb(mp(x,0));
	}
	for(int i=0;i<n;i++)
	{
		ll x; cin>>x;
		vec.pb(mp(x,1));
	}
	sort(vec.begin(),vec.end());
	ll R = n + 1; ll C = m + 1;
	for(int i=0;i<vec.size();i++)
	{
		ll cost=vec[i].fi; ll ty=vec[i].se; 
		if(ty==0)
		{
			ans+=R*cost;
			C--;
		}
		else
		{
			ans+=C*cost;
			R--;
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 6256
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        Set<String> campanies = new HashSet<>();
        for(char c : s.toCharArray()){
            campanies.add(String.valueOf(c));
        }
 
        System.out.println(campanies.size() > 1 ? "Yes" : "No");
    }
}

Measured memory_bytes: 23380
#include <iostream>
#include <string>

int main()
{
	std::string s; std::cin >> s;
	std::string ans("consonant");
	if(s=="a" || s=="e" || s=="i" || s=="o" || s=="u") ans = "vowel";
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {

	int n;
	cin >> n;

	printf("%.10f\n", (n + 1)/2/(double)n);

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N;
	int count = 1;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	for (int i = 0; i < N; i++) {
		if (A.at(i) == count) {
			count++;
		}
	}
	if (count == 1) cout << -1 << endl;
	else  cout << N - count + 1 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
 
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int x=abs(b-a),y=abs(c-b),z=abs(a-c);
    cout << x+y+z - max({x,y,z}) << endl;
}


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

int main(){
    int A,B,n,k=0,c;
    cin>>n;
    int a[n],b[n];
    vector<int>graph[n],color[n];
    for(int i=0;i<n-1;i++){
        int A,B;
        cin>>A>>B;
        A--;B--;
        a[i]=A;b[i]=B;
        graph[A].push_back(B);
    }

    bool visited[n];
    for(auto& x:visited)x=false;

    map<pair<int,int>,int>m;

    queue<int>q;
    q.push(0);
    visited[0]=true;
    while(!q.empty()){
        int p=q.front();q.pop();
        for(auto& x:graph[p])if(!visited[x]){visited[x]=true;q.push(x);}
        c=1;
        for(int i=0;i<graph[p].size();i++){
            if(m[pair<int,int>(p,graph[p][i])]!=0){i++;continue;}
            while(find(color[p].begin(),color[p].end(),c)!=color[p].end())c++;
            color[p].push_back(c);
            color[graph[p][i]].push_back(c);
            m[pair<int,int>(p,graph[p][i])]=c;
            m[pair<int,int>(graph[p][i],p)]=c;
        }
        k=max(k,c);
    }
    cout<<k<<endl;
    for(int i=0;i<n-1;i++)cout<<m[pair<int,int>(a[i],b[i])]<<endl;
    return 0;
}

Measured memory_bytes: 23424
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
signed main()
{
  int x,a,b; cin >> x >> a >> b;
  int A = abs(x-a);
  int B = abs(x-b);
  if(A<B) cout << "A" << "\n";
  else cout << "B" << "\n";
}

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

const int MAX_C = 8;

int main() {
	pair< int, string > colors[MAX_C] = {
		make_pair< int, string >(0x000000, "black"),
		make_pair< int, string >(0x0000ff, "blue"),
		make_pair< int, string >(0x00ff00, "lime"),
		make_pair< int, string >(0x00ffff, "aqua"),
		make_pair< int, string >(0xff0000, "red"),
		make_pair< int, string >(0xff00ff, "fuchsia"),
		make_pair< int, string >(0xffff00, "yellow"),
		make_pair< int, string >(0xffffff, "white")
	};
	string color, cname;
	int r, g, b, _r, _g, _b, min, dist;
	
	while(cin >> color, color != "0"){
		r = strtol(color.substr(1, 2).c_str(), NULL, 16);
		g = strtol(color.substr(3, 2).c_str(), NULL, 16);
		b = strtol(color.substr(5, 2).c_str(), NULL, 16);
		
		min = ~(1 << 31);
		cname;
		
		for(int i = 0; i < MAX_C; ++i){
			_r = (colors[i].first & 0xff0000) >> 16;
			_g = (colors[i].first & 0x00ff00) >> 8;
			_b = (colors[i].first & 0x0000ff);
			
			dist = (r - _r) * (r - _r) + (g - _g) * (g - _g) + (b - _b) * (b - _b);
			
			if(dist < min){
				min = dist;
				cname = colors[i].second;
			}
		}
		cout << cname << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
//Sasayego! Sasayego! Shinzou wo Sasageyo!

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x)  cerr << #x << " = " << x << endl
#define lid (id << 1)
#define rid (lid ^ 1)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 2e3 + 5;
const ll INF = 1e18;
const ll MOD = 924844033;

int fct[maxN], arumin[2 * maxN][maxN];

int main(){
	time_t START = clock();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	fct[0] = 1;
	for (int i = 1; i < maxN; i++)
		fct[i] = (1ll * i * fct[i - 1]) % MOD;
	int n, k; scanf("%d%d", &n, &k);
	int q = n / k, r = n % k;
	arumin[0][0] = 1;
	int v = 0;
	for (int x = 0; x < 2 * k; x++){
		int l = q + (x < 2 * r);
		for (int i = 1; i <= l; i++)
			for (int j = 0; j <= n; j++){
				arumin[v + i][j] = arumin[v + i - 1][j];
				if (i > 1 && j > 0)
					arumin[v + i][j] += arumin[v + i - 2][j - 1];
				arumin[v + i][j] %= MOD;
			}
		v += l;
	}
	int res = 0;
	for (int i = 0; i <= n; i++)
		res = (0ll + res + MOD + 1ll * (1 - 2 * (i & 1)) * arumin[v][i] * fct[n - i] % MOD) % MOD;
	printf("%d\n", res);
	time_t FINISH = clock();
	cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
	return 0;
}
 


Measured memory_bytes: 35184
N, L = map(int,input().split())

A = list(map(int,input().split()))

MAX = 0
index = -1

for i in range(N-1):
    if A[i] + A[i+1] > MAX:
        MAX = A[i] + A[i+1]
        index = i+1

if MAX < L:
    print("Impossible")
else:
    print("Possible")
    for i in range(1,index):
        print(i)
    for i in range(N-1,index,-1):
        print(i)
    print(index)

Measured memory_bytes: 14060
import math
A,B,H,M = map(int,input().split())
a = 30*H + 0.5*M
b = M*6
if abs(a-b) < 180:
    ab = abs(a-b)
else:
    ab = 360 - abs(a-b)
ab1 = round(math.cos(math.radians(ab)),20)
ans = round(math.sqrt(A**2 + B**2 - 2 * A* B*ab1),20)
print(round(ans,20))

Measured memory_bytes: 9520
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	string s;
	cin >> s;

	int ans = 0;

	if (s == "SUN")
	{
		ans = 7;
	}
	else if (s == "MON")
	{
		ans = 6;
	}
	else if (s == "TUE")
	{
		ans = 5;
	}
	else if (s == "WED")
	{
		ans = 4;
	}
	else if (s == "THU")
	{
		ans = 3;
	}
	else if (s == "FRI")
	{
		ans = 2;
	}
	else if (s == "SAT")
	{
		ans = 1;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
s = list(input())
t = list(input())

s.sort()
t.sort()
t = t[::-1]

import sys

for i, j in zip(s, t):
    if j > i:
        print('Yes')
        sys.exit(0)

if len(s) < len(t):
    for i in s:
        if i not in t:
            print('No')
            sys.exit(0)

    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060