akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007LL

vector<int> v[1048576];

int num[500010],pre[500010],sum[500010],n;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline ll pls(const ll &x,const ll &y) { return (x+y<mod)?x+y:x+y-mod; }
inline ll mns(const ll &x,const ll &y) { return (x-y<0)?x-y+mod:x-y; }
inline ll ksm(ll x,ll y) { ll res=1;for (;y;y>>=1,x=x*x%mod) if (y&1) res=res*x%mod;return res; }

inline ll gao(int x)
{
	if (!v[x].size()) return 0;
	ll ans=0,res=0,sumf=0;
	for (int i=0;i<v[x].size();i++)
	{
		int now=v[x][i];
		ll hh=1;
		if (i>0) res=pls(res,sumf*(sum[v[x][i]]-sum[v[x][i-1]])%mod);
		hh=pls(hh,res);
		sumf=pls(sumf,hh);
		ans=hh;
	}
	return ans;
}

inline ll gao1(int x)
{
	if (!v[x].size()) return 0;
	ll ans=0,res=0,sumf=0;
	for (int i=0;i<v[x].size();i++)
	{
		int now=v[x][i];
		ll hh=1;
		if (i>0) res=pls(res,sumf*(sum[v[x][i]]-sum[v[x][i-1]])%mod);
		hh=pls(hh,res);
		sumf=pls(sumf,hh);
	}
	return sumf;
}

int main()
{
	n=rd();
	for (int i=1;i<=n;i++) num[i]=rd();
	for (int i=1;i<=n;i++) pre[i]=pre[i-1]^num[i];
	for (int i=1;i<=n;i++) sum[i]=sum[i-1]+(pre[i]==0);
	for (int i=1;i<=n;i++) v[pre[i]].push_back(i);
	if (pre[n]!=0)
	{
		printf("%lld\n",gao(pre[n]));
		return 0;
	}
	ll ans=0;
	for (int i=1;i<1048576;i++) ans=pls(ans,gao1(i));
	int hh=0;
	for (int i=1;i<=n;i++) if (!pre[i]) hh++;
	hh--;
	ans=pls(ans,ksm(2,hh));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 40308
s = int(input())
a1 = int(s ** 0.5)
a2 = a1 + 1
if s - a1 ** 2 > a2 ** 2 - s:
    a = a2
    b = abs(s - a ** 2)
    print(0, end = " ")
    print(0, end = " ")
    print(a, end = " ")
    print(1, end = " ")
    print(b, end = " ")
    print(a)
elif s != 10 ** 18:
    a = a1
    b = abs(s - a ** 2)
    print(1, end = " ")
    print(0, end = " ")
    print(a + 1, end = " ")
    print(b, end = " ")
    print(0, end = " ")
    print(a)
else:
    print(0, end = " ")
    print(0, end = " ")
    print(10 ** 9, end = " ")
    print(0, end = " ")
    print(0, end = " ")
    print(10 ** 9)    

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll , ll> P;
typedef pair<ll, ll> PL;
const ll INT_INF = 2147483646;
const ll ll_INF = 9223372036854775807;
ll mod = 1e9+7;

bool SecondCompare(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
       return a.second>b.second;
}


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

    if((a*b)%2 == 1)    cout << "Yes\n";
    else    cout << "No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N],b[N];
int c[N],d[N];
int _to[N],_xo[N];
bool vis[N],vit[N];
int n;
void check(int n){
	for(int i=1;i<=n;++i){
		if(a[i]>b[i]) return ;
	}
	puts("Yes");
	exit(0);
}
struct node{
	int v,id;
	friend bool operator < (const node &a,const node &b){
		return a.v<b.v;
	}
};
vector<node> v1;
vector<node> v2;
bool sool(int x,int num){
	if(vis[x] && num<n) return false;
	vis[x]=true;
	if(num==n) return true;
	sool(_xo[x],num+1);
}
bool xool(int x,int num){
	if(vit[x] && num<n) return false;
	vit[x]=true;
	if(num==n) return true;
	xool(_to[x],num+1);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]),c[i]=a[i];
	for(int i=1;i<=n;++i) scanf("%d",&b[i]),d[i]=b[i];
	sort(c+1,c+1+n);sort(d+1,d+1+n);
	check(n);
	for(int i=1;i<=n;++i){
		if(c[i]>d[i]){
			puts("No");return 0;
		}
	}
	for(int i=2;i<=n;++i){
		if(c[i]<=d[i-1]){
			puts("Yes");return 0;
		}
	}
	for(int i=1;i<=n;++i){
		v1.push_back(node{a[i],i});
		v2.push_back(node{b[i],i});
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	for(int i=1;i<=n;++i){
		_to[v1[i-1].id]=v2[i-1].id;
		//_xo[v1[i-1].id]=i;
	}
	if(xool(_to[1],0)) puts("No");
	else puts("Yes");
}

Measured memory_bytes: 4076
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res


n,m=l_in()

print(n*(n-1)//2+m*(m-1)//2)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
const int IINF = (1 << 30);

int main(int argc, char const *argv[])
{
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    vector<vector<int>> dp(500, vector<int>(500, IINF));
    dp[0][0] = 0;
    rep(i, n)
    {
        auto next = dp;
        rep(j, 500)
        {
            rep(k, 500)
            {
                if (j - a[i] < 0 || k - b[i] < 0)
                {
                    continue;
                }
                next[j][k] = min(next[j][k], dp[j - a[i]][k - b[i]] + c[i]);
            }
        }
        dp = next;
    }
    int ans = IINF;
    rep(i, 1, 500)
    {
        rep(j, 1, 500)
        {
            if (i % ma == 0 && j % mb == 0 && i / ma == j / mb)
            {
                ans = min(ans, dp[i][j]);
            }
        }
    }
    if (ans == IINF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2272
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nk = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var hei = new int[nk[0]];
        for (var i = 0; i < nk[0]; i++) hei[i] = ToInt32(ReadLine());
        Array.Sort(hei);
        var min = int.MaxValue;
        for(var i = 0; i < nk[0]; i++)
        {
            if (nk[1] + i-1 >= nk[0]) break;
            min = Min(min, hei[nk[1] + i-1] - hei[i]);
        }
        WriteLine(min);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


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

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    int max_r=-1000000000;
    int min_r;
    scanf("%d", &min_r);
    for(int i=1; i<n; i++){
        int r;
        scanf("%d", &r);
        max_r=max(max_r, r-min_r);
        min_r=min(min_r, r);
    }
    printf("%d\n", max_r);
    return 0;
}

Measured memory_bytes: 2744
b1 = [Array.new(10,0),Array.new(10,0),Array.new(10,0)]
b2 = [Array.new(10,0),Array.new(10,0),Array.new(10,0)]
b3 = [Array.new(10,0),Array.new(10,0),Array.new(10,0)]
b4 = [Array.new(10,0),Array.new(10,0),Array.new(10,0)]
all = [b1,b2,b3,b4]

n = gets.to_i

for i in 1..n

notice = gets.split.map(&:to_i)
b = notice[0]-1
f = notice[1]-1
r = notice[2]-1
v = notice[3]
all[b][f][r] += v

end


for j in 1..3

for i in 1..3
puts " "+all[j-1][i-1].join(" ")
end

puts ("#" * 20)

end

for i in 1..3
puts " "+all[3][i-1].join(" ")
end





Measured memory_bytes: 6888
#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[i];
	}
	sort(a.begin(), a.end());
	if (a.back() - a.front() >= 2) {
		cout << "No" << endl;
		return 0;
	}
	if (a.back() == a.front()) {
		cout << (a.back() == N - 1 || a.back() * 2 <= N ? "Yes" : "No") << endl;
		return 0;
	}
	int x = lower_bound(a.begin(), a.end(), a.back()) - a.begin(), y = N - x, var = a.back();
	cout << (x + 1 <= var && var <= x + y / 2 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ll n,m,i,k=0,j;
  cin>>n>>m;
  vector<vector<ll>>a;
  a.resize(n);
  for(  i=0; i<n; i++ ){
    a[i].resize(2);
  }
  for(i=0;i<n;i++)
  {
      for(j=0;j<2;j++)
      cin>>a[i][j];
  }
  sort(a.begin(),a.end());
  for(i=0;i<n&&m>0;i++)
  {
      if(m>a[i][1])
      {
          m=m-a[i][1];
          k=k+a[i][1]*a[i][0];
      }
      else
      {
          k=k+a[i][0]*m;
          m=0;
      }
  }
  cout<<k<<endl;
}

Measured memory_bytes: 5760
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>

using namespace std;

int main(){
	int n;
	int a,b,c,d;
	scanf("%d",&n);
	a=n/1000;
	b=(n%1000)/100;
	c=(n%100)/10;
	d=n%10;
	if((a==b && a==c) || (b==c && c==d)||(a==b && a==c &&a==d))    printf("Yes\n");
	else
		printf("No\n");
		return 0;
}

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

int maze[21][21];

int main(){
while(1){

    int cnt = 0;
    int n;

    cin >> n;
    if(n == 0) break;
    for(int i=0; i < 21; i++)for(int j=0; j < 21; j++) maze[i][j] = 0;

    for(int i=0; i< n; i++){
        int x, y;
        cin >> x >> y;
        maze[x][y] = 1;
    }

    int m;
    int nx = 10, ny = 10;
    cin >> m;
    for(int i=0; i < m; i++){
        char deg;
        int dis;
        cin >> deg >> dis;
        if(deg == 'N'){
            for(int j=0; j < dis; j++){
                ny += 1;
                if(maze[nx][ny] == 1){
                    cnt++;
                    maze[nx][ny] = 0;
                }
            }
        }
        else if(deg == 'S'){
            for(int j=0; j < dis; j++){
                ny -= 1;
                if(maze[nx][ny] == 1){
                    cnt++;
                    maze[nx][ny] = 0;
                }
            }
        }
        else if(deg == 'E'){
            for(int j=0; j < dis; j++){
                nx += 1;
                if(maze[nx][ny] == 1){
                    cnt++;
                    maze[nx][ny] = 0;
                }
            }
        }
        else if(deg == 'W'){
            for(int j=0; j < dis; j++){
                nx -= 1;
                if(maze[nx][ny] == 1){
                    cnt++;
                    maze[nx][ny] = 0;
                }
            }
        }

    }


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

}

    return 0;
}



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

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

	int n, m;
	cin >> n >> m;

	int maxl, minr;
	maxl = 0;
	minr = INT_MAX;
	rep(i, m)
	{
		int l, r;
		cin >> l >> r;
		maxl = max(maxl, l);
		minr = min(minr, r);
	}
	if (minr - maxl < 0)
		cout << 0 << endl;
	else
		cout << minr - maxl + 1 << endl;
}


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

using namespace std;

int n,ans,a[1<<20],f[1<<20][2];

void pd(int &x,int &y){
	if (y==-1) return;
	if (x==-1){swap(x,y); return;}
	if (a[x]<a[y]) swap(x,y);
}

void fmt(int n){
	for (int i=0;i<n;++i){
		int t=1<<i;
		for (int j=0;j<1<<n;j+=t<<1)
			for (int k=0;k<t;++k){
				int t1=j+k,t2=j+t+k;
				int d1=f[t1][0],d2=f[t1][1],d3=f[t2][0],d4=f[t2][1];
				pd(d1,d3); pd(d2,d3); pd(d2,d4); pd(d3,d4);
				f[t2][0]=d1;
				if (d2!=d1) f[t2][1]=d2;
				else if (d3!=d1) f[t2][1]=d3;
				else if (d4!=d1) f[t2][1]=d4;
			}
	}
}

int main(){
	scanf("%d",&n);
	for (int i=0;i<1<<n;++i){
		scanf("%d",&a[i]);
		f[i][0]=i; f[i][1]=-1;
	}
	fmt(n);
	for (int i=1;i<1<<n;++i){
		ans=max(ans,a[f[i][0]]+a[f[i][1]]);
		printf("%d\n",ans);
	}
	
	return 0;
}
			

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define PB push_back
using namespace std;
using VI = vector<int>;
// LatexBegin
#define NX(x) ((x+k)%n)
#define C(a,b) (V[a]==V[b]?V[NX(a)]<V[NX(b)]:V[a]<V[b])
#define go(XD) V2[sa[0]]=N=0; \
  for(int i=1;i<n;i++) N+=XD, V2[sa[i]]=N; V=V2;
#define RSP sa, n, N+1
void RS(auto &sa, int n, int N, auto &V) { 
  VI B(N), t(n); for (auto &v : sa) B[V[v]]++;
  partial_sum(ALL(B), B.begin()); int i = n;
  while (i--) t[--B[V[sa[i]]]] = sa[i]; sa = t;
}
VI SA(string &s) { int n = s.size(), k = 0, N = 255;
  VI sa(n), V(n), V2(n); iota(ALL(sa), 0); 
  RS(RSP, s); go(s[sa[i - 1]] != s[sa[i]]);
  for (int k = 1 ; N + 1 < n ; k <<= 1, k %= n) { 
    for (auto &v : sa) (v += n - k) %= n; RS(RSP, V);
    go(C(sa[i - 1], sa[i]) || C(sa[i], sa[i - 1]));
  } return sa; 
}
VI LCP(string &s, auto &sa) { int n = s.size();
  VI lcp(n), ra(n); for (int i=0;i<n;i++) ra[sa[i]]=i;
  for (int i = 0, k = 0 ; i < n ; i++) {
    if (ra[i]) while(s[i+k] == s[sa[ra[i]-1]+k]) k++;
    lcp[ra[i]] = k; k = max(0, k - 1);
  } return lcp; 
}
// LatexEnd
typedef long long LL;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s; cin >> s; s += '$';
    auto sa = SA(s);
    auto lcp = LCP(s, sa);
    LL sum = 0;
    for (int i = 0 ; i < lcp.size() ; i++)
        sum += lcp[i];
    cout << 1ll * s.size() * (s.size() - 1) / 2 - sum << '\n';
}

Measured memory_bytes: 13412
n = int(input())
count = [0,0,0,0]
for _ in range(n):
    i = input()
    if i=='AC':
        count[0]+=1
    elif i=='WA':
        count[1]+=1
    elif i=='TLE':
        count[2]+=1
    else:
        count[3]+=1
print('AC x',count[0])
print('WA x',count[1])
print('TLE x',count[2])
print('RE x',count[3])

Measured memory_bytes: 9212
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef vector<int> vint;
#define rep(i,n) for(lint i = 0;i < n;i++)
#define all(x) x.begin(),x.end()
#define clr(a) memset(a,0,sizeof(a))

int main(void){
    lint N,T;
    cin >> N >> T;
    lint *c = new lint[N];
    lint *t = new lint[N];
    rep(i,N)
        cin >> c[i] >> t[i];
    lint cost = 10000;
    rep(i,N){
        if(cost > c[i] && T >= t[i]){
            cost = c[i];
        }
    }
    if(cost != 10000)
        cout << cost;
    else
        cout << "TLE";
    return 0;
}
/*
ループ for(lint i = 0;i < N;i++)
ソート sort(a,a+N);
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=8;
int n,m,p,N,M,ans;
char mat[maxn][maxn];
int main()
{
	scanf("%d%d%d",&n,&m,&p);
	N=1<<n;
	M=1<<m;
	for (int i=0;i<n;i++) scanf("%s",mat[i]);
	for (int I=0;I<N;I++)
		for (int J=0;J<M;J++)
		{
			int cnt=0;
			for (int i=0;i<n;i++)
				if (!((1<<i)&I))
					for (int j=0;j<m;j++)
						if (!((1<<j)&J) && mat[i][j]=='#') cnt++;
			if (cnt==p) ans++;
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    double R1,R2;
    cin>>R1>>R2;
    double R3=(R1*R2)/(R1+R2);
    cout<<fixed<<setprecision(10)<<R3<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
int N;
cin>>N;
 int a=0,b=0;
for(int i=0;i<N;i++){
  int p;
   cin>>p;
  a+=p;
    b=max(b,p);
  }
  int c=a-b/2;
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
n, k = map(int, input().split())

if n == 0:
  print(n)
  sys.exit()

if n >= k:
  n = n % k

for i in range(10**18):
  if abs(k-n) < n:
    n = abs(k-n)
  else:
    break

print(n)

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();

    ll X,Y;
    ll ans;
    scanf("%lld %lld", &X, &Y);

    if ( X - Y == 0 ){
        if ( X % 3 == 0 ){
            ll N = 2 * X / 3;
            ans = COM(N,N/2);
        }
        else{
            ans = 0;
        }
    }
    else if ( X > Y ){
        ll dif = X - Y;
        if ( ( Y - dif ) % 3 == 0){
            ll N = 2 * ( Y - dif ) / 3 + dif;
            ans = COM( N, ( Y - dif )/3 + dif );
        }
        else{
            ans = 0;
        }
    }
    else if ( X < Y ){
        ll dif = Y - X;
        if ( ( X - dif ) % 3 == 0){
            ll N = 2 * ( X - dif ) / 3 + dif;
            ans = COM( N, ( X - dif )/3 + dif );
        }
        else{
            ans = 0;
        }
    }

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

}

Measured memory_bytes: 23680
A=int(input())
B=int(input())
C=int(input())
X=int(input())
x=0
s=0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if X==500*i+100*j+50*k:
        s=s+1
print(s)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vl vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    ll ans=LINF;
    ll sum=0;
    ll cnt=0;
    REP(i,n){
        sum+=vec[i];
        if(i%2){
            if(sum>=0){
                cnt+=abs(sum)+1;
                sum=-1;
            }
        }else{
            if(sum<=0){
                cnt+=abs(sum)+1;
                sum=1;
            }
        }
    }
    chmin(ans,cnt);
    sum=0;
    cnt=0;
    REP(i,n){
        sum+=vec[i];
        if(i%2){
            if(sum<=0){
                cnt+=abs(sum)+1;
                sum=1;
            }
        }else{
            if(sum>=0){
                cnt+=abs(sum)+1;
                sum=-1;
            }
        }
    }
    chmin(ans,cnt);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

bool dp[6000][6000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    dp[0][0] = true;
    double mx = -1;
    int A = 0, B = 0;
    rep(i,f+1)rep(j,f+1){
        if(!dp[i][j]) continue;
        if(i+100*a+j <= f) dp[i+100*a][j] = true;
        if(i+100*b+j <= f) dp[i+100*b][j] = true;
        if(i+j+c <= f && j+c <= e*(i/100)) dp[i][j+c] = true;
        if(i+j+d <= f && j+d <= e*(i/100)) dp[i][j+d] = true;
        if(i+j == 0) continue;
        double milk = (double)(100*j) / (double)(i+j);
        if(mx < milk){
            mx = milk;
            A = i+j;
            B = j;
        }
    }
    cout << A << " " << B << endl;
	return 0;
}

Measured memory_bytes: 14592
//Never Quit...!!
/*
freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      */
#include<bits/stdc++.h>
#define ull unsigned long long int 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define ll long long 
#define ld long double 

int power(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int ncr(int n, int r) { int C[r+1]; memset(C, 0, sizeof(C)); C[0] = 1; for(int i = 1; i <= n; i++) {int t=i;if(r<t)t=r; for (int j = t; j > 0; j--) C[j] = C[j] + C[j-1]; }return C[r];} 
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}

using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  int a[n];
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  int b[k+1]={};
  sort(a,a+n);
  for (int i = 1; i <=k ; ++i)
  {
   for(int j=0; j<n ; j++)
   {
    if(a[j]<=i && b[i-a[j]]== 0)
        {
          b[i]=1;
          break;
        }
   }
  }
  if(b[k])
    cout<<"First";  
  else 
    cout<<"Second";

return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	vector<pair<ll,ll>> points;
	for(int i=0; i<n; ++i){
		ll x,y;
		cin>>x>>y;
		points.push_back({x,y});
	}

	auto get_dist = [&](int a, int b){
		double val =  (points[a].first - points[b].first) * (points[a].first-points[b].first) + ( points[a].second - points[b].second) * ( points[a].second - points[b].second);
		return sqrt(val);
	};

	ll cnt=0;
	double ans=0.0;
	vector<int> range;
	for(int i=0; i<n; ++i){ range.push_back(i); }
	do{
		cnt++;
		double now = 0.0;
		for(int i=0; i<n-1; ++i){
			now += get_dist(range[i],range[i+1]);
		}
		ans += now;
	}while( next_permutation(range.begin(),range.end()));

	cout.precision(10);
	ans /= cnt;
	cout<<fixed<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdint>

int main()
{
    int64_t N;

    scanf("%lld", &N);

    int64_t result = N;

    int64_t max = std::sqrt(N);

    for (int64_t i = 1; i <= max; ++i)
    {
        if ((N / i) * i == N)
        {
            int64_t r = (i - 1) + ((N / i) - 1);
            if (result > r)
            {
                result = r;
            }
        }
    }

    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int N;
	int K;

	scanf("%d %d", &N, &K);

	char S[N + 1];
	scanf("%s", S);

	S[K - 1] += ('a' - 'A'); 

	printf("%s\n", S);


	return 0;
}


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


int main(){
    int n,m;
    cin >> n >> m;
    int ans = n;
    rep(i,m){
        int a;
        cin >> a;
        ans -= a;
    }
    if(ans < 0) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1000000

void prim(int);
int n,M[MAX][MAX];

int main(){
  int i,j;
  int a,b,c,d;//k,c,u,v
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&a,&b);
    for(j=0;j<b;j++){
      scanf("%d%d",&c,&d);
      M[a][c]=d;
    }
  }
  prim(0);

  return 0;

}

void prim(int a){
  int minv,u;
  int d[MAX],color[MAX];
  int i,j;

  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=WHITE;
  }

  d[0]=0;
  color[0]=GRAY;
  while(1){
    minv=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(j=0;j<n;j++){
      if(color[j]!=BLACK&&M[u][j]!=INF){
	if(d[j]>d[u]+M[u][j]){
	  d[j]=d[u]+M[u][j];
	  color[j]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
}



Measured memory_bytes: 2112
_,*S=*$<;p~((0...S.size).map{|i|d,p,q,r=0,0,1<<i;(d,p,q,r=d-1,p|q,0,p&q^q;s,t=r;(q|=S[-t.bit_length].to_i 2;s^=t)while(t=s&-s)>0;0<q&r&&x)while 0<q;d}.min rescue 0)

Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

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

	int p = 100000;

	for (int i = 0; i < n; i++)
	{
		p += p * 0.05;
		ostringstream w;
		string ww,x;
		w << p;
		ww = w.str();
		int y = 0;
		y = ww.size();
		x = ww.substr(y - 3,3);
		if (x != "000")
		{
			p = ((p / 1000) + 1) * 1000;
		}
		
	}
	cout << p << endl;
}



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

class A
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = new int[n].Select(_ => decimal.Parse(Console.ReadLine())).ToArray();

		var d = a.Select(x =>
		{
			var s = x.ToString().TrimEnd('0');
			var i = s.IndexOf('.');
			var p10 = i == -1 ? 0 : s.Length - 1 - i;
			var d2 = 1M;
			for (int k = 0; k < p10; k++) d2 *= 10;
			var d1 = x * d2;

			while (d1 % 2 == 0 && d2 % 2 == 0)
			{
				d1 /= 2;
				d2 /= 2;
			}
			while (d1 % 5 == 0 && d2 % 5 == 0)
			{
				d1 /= 5;
				d2 /= 5;
			}

			int p2 = 0, p5 = 0;
			while (d1 % 2 == 0)
			{
				d1 /= 2;
				p2++;
			}
			while (d1 % 5 == 0)
			{
				d1 /= 5;
				p5++;
			}
			while (d2 % 2 == 0)
			{
				d2 /= 2;
				p2--;
			}
			while (d2 % 5 == 0)
			{
				d2 /= 5;
				p5--;
			}
			return (p2, p5);
		}).GroupBy(x => x).ToDictionary(g => g.Key, g => g.LongCount());

		var r = 0L;
		foreach (var (x, c1) in d)
		{
			foreach (var (y, c2) in d)
			{
				if (x.p2 + y.p2 < 0 || x.p5 + y.p5 < 0) continue;
				r += c1 * c2;
				if (x == y) r -= c1;
			}
		}
		Console.WriteLine(r / 2);
	}
}


Measured memory_bytes: 47196
S = input()

ans = len(S)

abc = "abcdefghijklmnopqrstuvwxyz"

def do(x,c):
    if x.count(c)==len(x):
        return 0
    res = ""
    for i in range(len(x) - 1):
        if (x[i]==c or x[i+1]==c):
            res += c
        else:
            res += x[i]
    return 1+do(res,c)

for c in abc:
    ans = min(ans,do(S,c))

print(ans)

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

int main(){
    string s;
    cin >> s;
    
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == ','){
            s[i] = ' ';
        }
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

flag = True

for a in A:
    if a%2 == 0:
        if a%3 == 0 or a%5 == 0:
            None
        else:
            flag = False

if flag:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS 1

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const LL mod = 1e9 + 7;
const int maxn = 5e5 + 7;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0);

LL f[maxn],inv[maxn];

void init() {
    inv[0] = f[0] = inv[1] = f[1] = 1;
    for(LL i = 2 ; i <= maxn ; i++) {
        inv[i] = ((mod - mod / i) * inv[mod%i]) % mod;
        f[i] = i;
    }
    for(LL i = 2 ; i <= maxn ; i++) {
        inv[i] = (inv[i] * inv[i-1]) % mod;
        f[i] = (f[i] * f[i-1]) % mod;
    }
}

LL C(LL x,LL y) {
    return f[x] * inv[y] % mod * inv[x-y] % mod;
}

LL A(LL x,LL y) {
    return f[x] * inv[x-y] % mod;
}

int main() {

#ifndef ONLINE_JUDGE
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	long _begin_time = clock();
#endif

    int n;
    sd(n);
    LL a, b;
    slld(a), slld(b);
    LL sum = a + b;
    LL Xor = 0;
    rep(i,3,n) {
        LL x;
        slld(x);
        Xor ^= x;
    }

    bool flag = false;
    if(sum < Xor || (sum - Xor) % 2 != 0) flag = true;

    LL And = sum - Xor >> 1;
    LL ans = And;
    per(i,60,0) {
        int xx = ((And >> i) & 1LL);
        int yy = ((Xor >> i) & 1LL);
        if(xx && yy) {
            flag = true;
            break;
        }
        if(!xx && yy && ((ans | (1LL << i)) <= a)) {
            ans |= (1LL << i);
        }
    }

    if(!ans || ans > a || flag) puts("-1");
    else plld(a-ans);

#ifndef ONLINE_JUDGE
	long _end_time = clock();
	// cout << "time = " <<  _end_time - _begin_time << endl;
#endif
    return 0;
}

Measured memory_bytes: 3816
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[4],ans;
int main()
{
	for (int i=1;i<=3;i++) scanf("%d",&a[i]);
	sort(a+1,a+4); int k=a[2]-a[1];
	ans+=k/2; if (k&1) ans+=2;
	ans+=a[3]-a[2];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }

string pc = "peach", ap = "apple";

int main() {
	string line;
	while ( getline(cin, line) ) {
		int n = (int)line.sz;
		for_(i, 0, n-5+1) {
			string sub = line.substr(i, 5);
			if (sub==pc) line.replace(i, 5, ap);
			else if (sub==ap) line.replace(i, 5, pc);
		}
		cout << line << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1188
s = list(input())

days = 0
if s[1] == "R":
  days += 1
  if s[0] == "R":
    days += 1
  if s[2] == "R":
    days += 1
    
else:
  if s[0] == "R" or s[2] == "R":
    days = 1
    
print(days)

Measured memory_bytes: 61868
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
ll conb(int a, int b) {
	ll p = 1;
	FOR(i, 1, b+1) {
		p = p*(a - i + 1) / i;
	}
	return p;
}


int main() {
	int n, m;
	double l;
	cin >> n >> m >> l;
	vector<vector<pair<double, double>>> goal(n,vector<pair<double,double>>(m+1));//time ,prob
	REP(i, n) {
		double pro,time,v;
		cin>> pro>> time>> v;
		pro /= 100.0;
		REP(j,m+1) {
			goal[i][j] = {l/v+time*(j),(double)conb(m,j)*pow(pro,j)*pow(1.0-pro,m-j)};
		}
	}
	REP(i, n) {
		double ans=0.0;
		REP(j, m+1) {
			double res=goal[i][j].second;
			bool win=true;
			REP(k, n) {
				if (i == k)
					continue;
				double res2=1.0;
				REP(l,m+1) {
					if (goal[i][j].first<goal[k][l].first-1e-9) {
						res *= res2;
						break;
					}
					else {
						res2 -= goal[k][l].second;
						if (l == m)
							win = false;
					}
				}
			}
			if(win)
			ans += res;
		}
		printf("%.8lf\n", ans);
	}
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
ll c[1005][3];
int main(){
    int n,m; cin >> n >> m;
    
    rep(i,n){
        rep(j,3){
            cin >> c[i][j];
        }
    }
    ll ans = -1;

    rep(i,8){
        vector<ll> d;
        rep(j,n){
            ll value = 0;
            rep(k,3){
                if(i & (1<<k)) value += c[j][k];
                else value -= c[j][k];
            }
            d.push_back(value);
        }
        ll tmp = 0;
        sort(RALL(d));
        rep(i,m) tmp += d[i];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
int main(){
	int n;cin>>n;
    vi a(100005,0);
	int ans =0;
    rep(i,n){
		int b;cin>>b;
		if(a[b])ans++;
		a[b]++;
	}
    cout<<n-ans-(ans%2)<<endl;
}

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

int main(){
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  
  int L = A+B;
  int R = C+D;
 
  string ans;
  
  if(L>R) ans = "Left";
  else if(L<R) ans = "Right";
  else ans = "Balanced";
 
  cout << ans << endl;
}


Measured memory_bytes: 256
/*input
4 5
1 2
1 3
3 2
2 4
3 4
*/
#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;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
vector<int> v[maxn];
int dist[maxn];
int dfs(int u){
	if(sz(v[u])==0) return 0;
	if(dist[u]!=-1) return dist[u];
	for(auto x:v[u]){
		dist[u]=max(dist[u],1+dfs(x));
	}
	return dist[u];
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	memset(dist,-1,sizeof(dist));
	REP(i,m){
		int a,b;
		cin>>a>>b;
		--a;
		--b;
		v[a].pb(b);
	}
	int ans=0;
	REP(i,n){
		ans=max(ans,dfs(i));
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 8192
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int main(){
	
	char c[201];
	string s;
	string front, back;
	scanf("%s", c);
	s = c;
	
	int i;
	for(i = s.size() - 1; i > 0; i--){
		if(i % 2 == 0){	
	
			s.resize(i);
			front = s;
			
			back = s.substr(i / 2);
			front.resize(i / 2);
			
			if(front == back) break;
		}
	}
	
	printf("%d\n", i);
	
	return 0;
}

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

int cti(char c) {
    return c - '0';
}

int main() {
    string n; cin >> n;
    int sumN = 0;
    rep(i,n.size()) {
        sumN += cti(n[i]);
    }
    if (sumN % 9 == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3716
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>

#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

using namespace std;

int main(){

  char ch;
  char s[27]={"abcdefghijklmnopqrstuvwxyz"};
  int counter[27]={0};
  int i,j=0;
 
  while(cin >>ch){
    ch=tolower(ch);
    if(ch>='a' && ch<='z') counter[ch-'a']++;
  }

  for(i=0;i<26;i++){
    cout <<s[i] <<" " <<":" <<" " <<counter[i] <<endl;
  }

  return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
ll gcd (ll a,ll b){
	if(a>b){
		ll r = a % b;
		while(r!=0){
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}else{
		ll r = b % a;
		while(r!=0){
			b = a;
			a = r;
			r = b % a;
		}
		return a;
	}
}
int main(void){
	int n;cin >> n;
	ll X,x[n];
	ll ans = 0;
	cin >> X;
	for(int i=0;i<n;i++){
		cin >> x[i];
		if(i==0) {
			ans = max(X,x[i])-min(X,x[i]);
			continue;
		}
		ans = gcd(max(X,x[i])-min(X,x[i]),ans);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int main() {
  ll n, minn = 1e15;
  cin >> n;
  REP(i, 5) {
    ll tmp;
    cin >> tmp;
    minn = min(minn, tmp);
  }
  ll res =  (4 + (n/minn) + (n%minn?1:0));
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  string n;
  cin >> n;
  cout << "ABC" << n << endl;
  return 0;
}


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

int main() {
  uint32_t A = 0, B = 0, C = 0, D = 0;
  std::cin >> A >> B >> C >> D;

  uint32_t start = std::max(A, C), end = std::min(B, D);
  std::cout << (end > start ? end - start : 0) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30

int main()
{
    string S;
    int K;
    cin >> K >> S;
    int L = S.length();
    if(L<=K)cout << S << endl;
    else{
        REP(i,K)cout << S[i];
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

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

int main(){
    int n; cin >> n;
    if(n%10==2 ||n%10==4 ||n%10==5 ||n%10==7 ||n%10==9) out("hon");
    else if(n%10==0||n%10==1||n%10==6||n%10==8) out("pon");
    else out("bon");
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n,m,a[15][15];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	int ans=0;
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++){
			int s=0;
			for(int k=1;k<=m;k++)
				s+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			int tmp=sqrt(s);
			if(tmp*tmp==s)ans++;
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;




int main(){
	int N; cin >> N;
	string s,t; cin >> s >> t;
	rep(i,N){
		string v = s.substr(i,N-i);
		string w = t.substr(0,N-i);
		if(v == w){
			cout << N+i << endl;
			return 0;
		}
	}
	cout << 2*N << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)

char G[5][5][5];
bool A[28], B[28];

int count(int i, int j, int k, char t){
  int cnt = 0;
  REP(dx, -1, 2) REP(dy, -1, 2) REP(dz, -1, 2){
    if ( dx == 0 && dy == 0 && dz == 0 ) continue;
    int ni = i + dx;
    int nj = j + dy;
    int nk = k + dz;
    if ( ni < 0 || nj < 0 || nk < 0 || ni >= 5 || nj >= 5 || nk >= 5 ) continue;
	 if ( G[ni][nj][nk] == t ) cnt++;
  }
    return cnt;
}

void simulate(){
  char T[5][5][5];
  rep(i, 5) rep(j, 5) rep(k, 5) T[i][j][k] = G[i][j][k];
  
  rep(i, 5) rep(j, 5) rep(k, 5) {
    if ( G[i][j][k] == '0' ){
      if ( A[count(i, j, k, '1')] ) T[i][j][k] = '1';
    } else {
      if ( !B[count(i, j, k, '1')] ) T[i][j][k] = '0';
    }
  }

  rep(i, 5) rep(j, 5) rep(k, 5) G[i][j][k] = T[i][j][k];
}

void solve(int N, int tcase){
  rep(i, 5) rep(j, 5) rep(k, 5) cin >> G[i][j][k];
  vector<int> a, b;
  int M1, M2;
  rep(i, 28) A[i] = B[i] = false;
  cin >> M1;
  rep(i, M1){
    int x; cin >> x;
    A[x] = true;
  }
  cin >> M2;
  rep(i, M2){
    int x; cin >> x;
    B[x] = true;
  }
    rep(i, N) simulate();
  
    if ( tcase > 1 ) cout << endl;

  cout << "Case " << tcase << ":" << endl;
  rep(i, 5){
    if (i ) cout << endl;
    rep(j, 5){
      rep(k, 5){
	cout << G[i][j][k];
      }
      cout << endl;
    }
  }
}

main(){
  int N;
  for ( int t = 1;cin>> N, N; t++ ) solve(N, t);
}

Measured memory_bytes: 1164