akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;

std::vector<ll> enum_div(ll n)
{
    std::vector<ll> ret;
    for (ll i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) {
                ret.push_back(n/i);
            }
        }
    }

    ret.push_back(n);
    std::sort(ret.begin(), ret.end());

    return ret;
}

ll func(ll N, ll n) {
    int A = 0;
    ll temp = n;
    while (temp > 0) {
        temp /= 10;
        A++;
    }

    int B = 0;
    ll pair = N / n;
    while (pair > 0) {
        pair /= 10;
        B++;
    }

    return std::max(A, B);
}
 
int main(int argc, char *argv[])
{
    ll N;
    std::cin >> N;

    std::vector<ll > ans = enum_div(N);
    ll min = 100000000000;
    for (ll i = 0; i < ans.size(); i++) {
        if (min > func(N, ans[i])) {
            min = func(N, ans[i]);
        }
    }

    std::cout << min << std::endl;

    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))

if n != k:
    memo = [0] * (n + 1)

    for i in range(n):
        memo[i] = memo[i - 1] + p[i]

    ans = 0
    for i in range(k, n):
        ans = max(ans, memo[i] - memo[i - k])

    ans = (ans + k) / 2
    print(ans)
else:
    ans = (sum(p) + k) / 2
    print(ans)


Measured memory_bytes: 25060
#include <bits/stdc++.h>
#define maxn 500010
using namespace std;
char s[maxn];
int a[maxn], dp[maxn];
int main() {
    int n;
    scanf("%d%s", &n, s+1);
    for (int i = 1; i <= n; ++i) {
        if (s[i] == '0') a[i] = i;
        else a[i] = a[i-1];
    }
    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i-1];
        if (s[i] == '1') {
            if (s[i-1] == '0' && s[i-2] == '1') {
                dp[i] = max(dp[i], dp[a[i-2]]+ (i-2) - a[i-2]);
                dp[i] = max(dp[i], dp[a[i-2]+1] + (i-2) - (a[i-2]+1));
            }
            else if (a[i]>1 && s[a[i]-1] == '1') dp[i] = max(dp[i], dp[a[i]-2] + i - a[i]);
        }
    }
    printf("%d\n", dp[n]);
    return 0;
}

Measured memory_bytes: 4608
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;

typedef long long ll;

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

const ll INF=1LL<<60;

int N;
ll h[100010];
ll dp[100010];

int main(){
	int N,k; cin>>N>>k;
	for(int i=0;i<N;i++)cin>>h[i];
	for(int i=0;i<100010;i++)dp[i]=INF;
	dp[0]=0;
	for(int i=0;i<N;i++){
		for(int j=1;j<k+1;j++){
			if(i>=j)chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[N-1]<<endl;
}


Measured memory_bytes: 1792
# B - Fusing Slimes

N = int(input())
x = list(map(int, input().split()))
MOD = 10**9 + 7

# n! (MOD p)
def factorial_mod(n, p):
    tmp = 1
    for i in range(1, n+1):
        tmp *= i
        tmp %= p
    return tmp

# 逆数の累積和
rv = [1]
for i in range(2, N):
    rv.append(rv[-1] + pow(i, MOD-2, MOD))

ans = 0
for i in range(N-1):
    ans += ((x[i+1] - x[i]) * rv[i]) % MOD

ans *= factorial_mod(N-1, MOD)
ans %= MOD
print(ans)

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = a; i <= b; ++i) {
        auto s = to_string(i);
        int ok = 1;
        for (int j = 0; j < s.size(); ++j) {
            if (s[j] != s[s.size() - j - 1]) {
                ok = 0;
            }
        }
        ans += ok;
    }
    cout << ans;

}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k;
  	cin >> k;
  	string s;
    cin >> s;
  if (s.size() <= k){
    cout << s << endl;
  }
  else {
    for(int i=0; i < k;i++){
      cout << s.at(i);
    }
   cout << "..." << endl;
  }
}

Measured memory_bytes: 3600
import java.util.*
import java.math.*
import kotlin.math.*

fun readLn()=readLine()!!
fun readInt()=readLn().toInt()
fun readInts()=readLn().split(" ").map{it.toInt()}
fun readLong()=readLn().toLong()
fun readLongs()=readLn().split(" ").map{it.toLong()}

val out=mutableListOf<String>()
fun printLine(s:String){out.add(s)}
fun output(){println(out.joinToString("\n"))}

fun main(){
    var (n,m)=readInts()
    var h=readInts().toIntArray()
    var mx=Array(n+1){0}
    repeat(m){
        var (u,v)=readInts()
        u--;v--
        mx[u]=max(mx[u],h[v])
        mx[v]=max(mx[v],h[u])
    }
    var ans=0
    for(i in 0 until n)if(h[i]>mx[i])ans++
    printLine("$ans")
    output()
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long L, a, b, m;
    cin >> L >> a >> b >> m;
    function <long long (long long, long long)> pow = [&](long long x, long long p) {
        if (p == 0) return 1LL;
        auto y = pow(x, p/2);
        auto z = (y*y) % m;
        return p%2 == 1 ? (x*z) % m : z;
    };
    function<long long (int, long long)> f = [&](int k, long long r) {
        if (r == 0) {
            return 0LL;
        }
        if (r % 2 == 1) {
            return (1 + pow(10, k) * f(k, r-1)) % m;
        }
        auto y = f(k, r/2);
        auto factor = pow(pow(10, k), r/2);
        return (y + y * factor) % m;
    };
    function<long long (int, long long)> g = [&](int k, long long r) {
        if (r == 0) {
            return 0LL;
        }
        if (r % 2 == 1) {
            return (pow(10, k) * (f(k, r-1) + g(k, r-1))) % m;
        }
        auto y = g(k, r/2);
        auto factor = pow(pow(10, k), r/2);
        auto extra = (((r/2) % m) * f(k, r/2)) % m;
        return (y + y * factor + extra * factor) % m;
    };
    auto calc = [&](long long a0, long long l, long long k) {
        long long part_1 = (f(k, l) * ((a0 + (l-1) * b) % m)) % m;
        long long part_2 = (g(k, l) * (b % m)) % m;
        return (part_1 - part_2 + m) % m;
    };
    vector<pair<int, int>> digits(19);
    long long pow_ten = 1;
    for (int i = 0; i < 17; ++i) pow_ten *= 10;
    long long multiplier = 1;
    long long result = 0;
    for (int digit = 18; digit >= 1; --digit, pow_ten /= 10) {
        long long l_0 = max((pow_ten - a + b-1)/b, 0LL);
        if (l_0 >= L) {
            continue;
        }
        long long l = L - l_0;
        result = (result + calc(a + l_0 * b, l, digit) * multiplier) % m;
        multiplier = (multiplier * pow(pow(10, digit), l)) % m;
        L = l_0;
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define ll long long
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  set<char>se;
  string s;
  cin>>s;
  rep(i,s.size()){
    se.insert(s[i]);
  }
  if(s.size()==se.size())cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin

n, m = [int(x) for x in stdin.readline().rstrip().split()]
al = [int(x) for x in stdin.readline().rstrip().split()]
al.sort()

l = []
for i in range(m):
  b, c = [int(x) for x in stdin.readline().rstrip().split()]
  l.append((c,b))

l.sort()
l.reverse()

idx=0 
for c,b in l:
  for i in range(b):
    if (len(al) <= idx):
      break
    if c < al[idx]:
      break
    al[idx] = c
    idx += 1

print(sum(al))


Measured memory_bytes: 63656
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int k, a, b;
  cin >> k >> a >> b;
  bool ans = false;

  for(int i = a; i <= b; i++){
    if(i % k == 0){
      ans = true;
      break;
    }
  }
  if(ans){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3588
let is_square x =
  let rec iter i =
    if i * i > x then false
    else if i * i = x then true
    else iter (i + 1)
  in float_of_int x |> sqrt |> int_of_float |> iter

let solve a b =
  let ab = a ^ b |> int_of_string in
  if is_square ab then "Yes" else "No"

let () = Scanf.scanf "%s %s" solve |> print_string

Measured memory_bytes: 2432
#include<iostream>
using namespace std;
//Minimum Cost Flow O(FE log V)
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<limits>
template<typename T>
struct MCF{
	struct edge{
		int to,rev,cap;
		T cost;
	};
	vector<vector<edge> >G;
	vector<T>h,d;
	vector<int>pv,pe;
	MCF(int n_=0):G(n_),h(n_,0),d(n_),pv(n_),pe(n_){}
	void add_edge(int from,int to,int cap,T cost)
	{
		G[from].push_back({to,(int)G[to].size(),cap,cost});
		G[to].push_back({from,(int)G[from].size()-1,0,-cost});
	}
	T min_cost_flow(int s,int t,int f)//ans or -1
	{
		T ret=0;
		while(f>0)
		{
			priority_queue<pair<T,int>,vector<pair<T,int> >,greater<pair<T,int> > >P;
			fill(d.begin(),d.end(),numeric_limits<T>::max());
			d[s]=0;
			P.push(make_pair(0,s));
			while(!P.empty())
			{
				pair<T,int>p=P.top();P.pop();
				if(d[p.second]<p.first)continue;
				for(int i=0;i<G[p.second].size();i++)
				{
					edge&e=G[p.second][i];
					if(e.cap>0&&d[e.to]>d[p.second]+e.cost+h[p.second]-h[e.to])
					{
						d[e.to]=d[p.second]+e.cost+h[p.second]-h[e.to];
						pv[e.to]=p.second;
						pe[e.to]=i;
						P.push(make_pair(d[e.to],e.to));
					}
				}
			}
			if(d[t]==numeric_limits<T>::max())return -1;
			for(int u=0;u<G.size();u++)h[u]+=d[u];
			int d=f;
			for(int u=t;u!=s;u=pv[u])d=min(d,G[pv[u]][pe[u]].cap);
			f-=d;
			ret+=d*h[t];
			for(int u=t;u!=s;u=pv[u])
			{
				G[pv[u]][pe[u]].cap-=d;
				G[u][G[pv[u]][pe[u]].rev].cap+=d;
			}
		}
		return ret;
	}
};
main()
{
	int N,E,F;
	cin>>N>>E>>F;
	MCF<int>mf(N);
	for(int i=0;i<E;i++)
	{
		int u,v,c,d;cin>>u>>v>>c>>d;
		mf.add_edge(u,v,c,d);
	}
	cout<<mf.min_cost_flow(0,N-1,F)<<endl;
}



Measured memory_bytes: 3208
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef  long long int ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    ll prod=1;
    ll a[n];
    for(int i=0;i<n;i++)    cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
        if(a[i]<=1000000000000000000/prod) 
            prod *= a[i];
        //cout<<prod<<endl; 
        else{
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<prod<<endl;
    return 0;
}



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

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

    static vector<int> jobs[100000];
    for(int i=0;i<n;i++){
        int a, b;
        cin >> a >> b;
        jobs[a-1].push_back(b);
    }
    priority_queue<int> q;
    int64_t ans = 0;

    for(int i=0;i<m;i++){
        for(auto j: jobs[i]) q.push(j);
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }

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

Measured memory_bytes: 5632
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 1005
using namespace std;
typedef long long ll;
int n=2,m;
ll a[maxn][maxn];
ll dp[maxn][maxn];
int main()
{
	scanf("%d",&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%lld",&a[i][j]);
	ll ans=a[1][1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(i+1<=n)
				dp[i+1][j]=max(dp[i+1][j],dp[i][j]+a[i+1][j]);
			if(j+1<=m)
				dp[i][j+1]=max(dp[i][j+1],dp[i][j]+a[i][j+1]);
		}
	}
	printf("%lld\n",ans+dp[n][m]);
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000007;
const ll inv2 = (mod + 1) / 2;
int n;
ll a, b;
ll c0, ans = 1;
typedef pair<ll, ll>pii;
map<pii, pii>mp;
ll Pow(ll a, ll b) {
	ll res = 1ll;
	while (b) {
		if (b & 1)res = res * a%mod;
		a = a * a%mod;
		b >>= 1;
	}
	return res;
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lld%lld", &a, &b);
		if (a == 0 && b == 0)c0++;
		else {
			if (b < 0)a = -a, b = -b;
			ll g = abs(gcd(a, b));
			a /= g; b /= g;
			if (a > 0)mp[pii(a, b)].first++;
			else mp[pii(b, -a)].second++;
		}
	}
	for (auto p : mp) {
		ll tmp = (Pow(2, p.second.first) + Pow(2, p.second.second) + mod - 1) % mod;
		ans = ans * tmp%mod;
	}
	printf("%lld\n", (ans + mod - 1 + c0) % mod);
	return 0;
}

Measured memory_bytes: 19220
#include <stdio.h>
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main(){

    int a1, a2, b1, b2, k;
    cin >> a1 >> a2 >> b1 >> b2 >> k;

    int diff = (b1*60) + b2 - (a1*60) - a2;

    int res = diff - k;

    cout << res;

    return 0;

}

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

int main() {

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

  int num = 1;
  for (int i = 0; i < N; i++) {
    if (num * 2 < num + K) {
      num *= 2;
    }
    else {
      num += K;
    }
  }
  cout << num << endl;
}


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

using namespace std;

int main() {
   int N, Y;
   cin >> N >> Y;
   Y /= 1000;

   for (int i = 0; i <= N; i++) {
      for (int j = 0; j <= N - i; j++) {
         int k = N - i - j;
         if (10 * i + 5 * j + k == Y) {
            cout << i << " " << j << " " << k << endl;
            return 0;
         }
      }
   }
   cout << -1 << " " << -1 << " "  << -1 << endl;
   return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
 int n;
  cin>>n;
  int a[n],b[n],c[n-1];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(int i=0;i<n;i++)
    cin>>b[i];
  for(int i=0;i<n-1;i++)
    cin>>c[i];
  int ans=b[a[0]-1];
  for(int i=1;i<n;i++)
  {
    int index=a[i];
    ans+=b[index-1];
    if(a[i]==1+a[i-1])
    ans+=c[a[i]-2];
  }
  cout<<ans<<"\n";
  return 0;
}
 
  

Measured memory_bytes: 256
def warshall_floyd(d,route):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]: 
                    d[i][j] = d[i][k] + d[k][j]
                    route[i][j] = route[i][k] + route[k][j]
    return d

n,w = map(int,input().split())
INF = 10**5
d = [[INF for i in range(n)] for i in range(n)]
route = [[[] for i in range(n)] for i in range(n)]
for i in range(w):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    d[x][y] = z
    d[y][x] = z
    route[x][y].append(i)
    route[y][x].append(i)
for i in range(n):
    d[i][i] = 0

warshall_floyd(d,route)
ans = w
s = set()
for i in range(n):
    for j in range(n):
        for k in route[i][j]:
            if k not in s:
                ans -= 1
                s.add(k)
print(ans)

Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
int main()
{
	
	int n,cnt=0;
	cin>>n;
	for (int i=1;i<=n;i+=2){
//		cout<<"i = "<<i<<endl;
		int k=0;
		for (int j=1;j<=i;++j)
			if (i%j==0) k++;
		if (k==8) cnt++;
	}
	cout<<cnt<<endl;
	
}


Measured memory_bytes: 256
/**
 *   Author:  Shahbib Ayman Shabib
 *   FROM RMSTU
**/
#include <bits/stdc++.h>
#define ll                      long long
#define Fast                    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define min3(a,b,c)             min(a,min(b,c))
#define min4(a,b,c,d)           min(d,min3(a,b,c))
#define max3(a,b,c)             max(a,max(b,c))
#define max4(a,b,c,d)           max(d,max3(a,b,c))
#define sob(v)                  v.begin(),v.end()
#define recall(v)               v.rbegin(),v.rend()
#define pb                      push_back
#define eb                      emplace_back
#define setbits(x)              __builtin_popcountll(x)
#define zrobits(x)              __builtin_ctzll(x)
#define scf(x)                  scanf("%d", &x)
#define scf2(x, y)              scanf("%d %d", &x, &y)
#define scf3(x, y, z)           scanf("%d %d %d", &x, &y, &z)
#define scff4(p,x, y, z)        scanf("%d %d %d %d",&p, &x, &y, &z)
#define scfll(x)                scanf("%lld", &x)
#define scsfll2(x, y)           scanf("%lld %lld", &x, &y)
#define scfll3(x, y, z)         scanf("%lld %lld %lld", &x, &y, &z)
#define read                    freopen("input.txt","r",stdin)
#define write                   freopen("output.txt","w",stdout)
#define prnt                    cout << endl
#define gcd(a,b)                __gcd(a,b)
#define lcm(a,b)                (a)*(b)/gcd(a,b)
using namespace std;
/*************************************
*          A S S E M B L E         *
**************************************/
bool isPrime(ll n){if(n <= 1)return false;for (ll i = 2; i * i < n; i++)if (n % i == 0)return false;return true;}
ll fact(ll n){ll res = 1;for(ll i = n;i>=1;i--)res *= i;return res;}
ll nCr(ll n,ll r){return (fact(n)/(fact(r)*fact(n-r)));}
ll nPr(ll n,ll r){return fact(n)/fact(n-r);}
ll modpow(ll a, ll n, ll mod){ll res=1;while(n>0){if(n&1) res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
#define mod 100000009
inline int add(int a,int b){if((a+=b)>=mod)a-=mod;return a;}
inline int dec(int a,int b){if((a-=b)<0)a+=mod;return a;}
inline int mult(int a,int b){long long t=1ll*a*b;if(t>=mod)t%=mod;return t;}
inline int power(int a,int b){int out=1;while(b){if(b&1)out=mult(out,a);a=mult(a,a);b>>=1;}return out;}
vector<ll> primes;
bool prime[mod];
void sieve(){
    memset(prime,true,sizeof(prime));
    prime[0] = prime[1] = false;
    primes.pb(2);
    for(ll i = 4;i<=mod;i+=2)
        prime[i] = false;
    for(ll i = 3;i<=mod;i+=2){
        if(prime[i] == true){
                primes.pb(i);
            for(ll j = i*2;j<=mod;j+=i)
                prime[j] = false;
        }
    }
}

/*************************************
*  E N D    G A M E   S T A R T S    *
**************************************/
int main()
{
	int n, k;
	cin >> n >> k;
	cout << min(1,n % k) << endl;

	return 0;


  cout << "No" << endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define pi acos(-1)
#define mx 1000000000
#define mod 1000000009
#define pii pair<int,int>
#define psi pair<string,int>
#define vi vector<int>
typedef long long ll;
using namespace std;
void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("inputf.txt", "r", stdin);
    freopen("outputf.txt", "w", stdout);
#endif
    fastio();
    int i,j,t,n,m;
    //cin>>t;
    //while(t--){
     cin>>n>>m;
     vector<string>v(n);
     for(i=0;i<n;i++)cin>>v[i];
     sort(v.begin(),v.end());
     for(i=0;i<n;i++)cout<<v[i]; 
    //}
 return 0;
}



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

typedef long long ll;

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

int dist[51][51];

int main() {
    int H, W;
    int count = 0;
    cin >> H >> W;

    vector<string>S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    for (int i = 0; i < 51; i++) {
        for (int j = 0; j < 51; j++) {
            dist[i][j] = -1;
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '.') {
                count++;
            }
        }
    }

    dist[0][0] = 0;
    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));

    while (!que.empty()) {
        int h = que.front().first;
        int w = que.front().second;
        que.pop();
        for (int dir = 0; dir < 4; dir++) {
            int nh = h + dx[dir];
            int nw = w + dy[dir];

            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (dist[nh][nw] != -1) continue;
            if (S[nh][nw] == '#') continue;
            dist[nh][nw] = dist[h][w] + 1;
            que.push(make_pair(nh, nw));
        }
    }
    if (dist[H-1][W-1] == -1) {
        cout << -1 << endl;
    } else {
        cout << count - dist[H-1][W-1] -1 << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n,k,a[200010];
long long sum;
bool cmp(int i,int j){
	return i>j;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=k;i++)sum-=a[i];
	if(sum<0)sum=0;
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   string s;
   cin>>s;
   
   cout<<s.substr(0,3);
   
   
   return 0;        
}  
  
   

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

int main(){
	vector<int> height(10);

	for (int i = 0; i < 10; i++)
		cin >> height[i];

	sort(height.begin(), height.end(), greater<int>());
	
	for (int i = 0; i < 3; i++)
		cout << height[i] << endl;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<stdlib.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 500000
#define MAX 10000

typedef struct{
  int color; //全て白(0)に初期化済み
  int distance;
  int parent;
}DOT;

typedef struct{
  int to;
  int dis;
}Gyou;

DOT A[MAX];
DOT pq[20000];//これで限界
Gyou *G[MAX];

//===================
int H;//PQのtail　==0でempty

void swap_pq(DOT *a,DOT *b){
  DOT c=*a;*a=*b;*b=c;
}

void maxHeapify(int i){
  int l = 2*i;
  int r = 2*i+1;
  int largest;
  // 左の子、自分、右の子で値が最大のノードを選ぶ
  if(l <= H && pq[l].distance > pq[i].distance)largest = l;
  else largest = i;
  if(r <= H && pq[r].distance > pq[largest].distance)largest = r;
  // i の子の方が値が大きい場合
  if(largest != i){
    swap_pq(&pq[i],&pq[largest]); 
    maxHeapify(largest); // 再帰的に呼び出し
  }
}

void Insert(DOT X){
  int i;
  i=++H;

  pq[i]=X;  
  while(i>=2&&pq[i/2].distance<pq[i].distance){
    swap_pq(&pq[i],&pq[i/2]);
    i=i/2;
  }
}

DOT Extract(void){
  DOT max;
  
  max=pq[1];
  pq[1]=pq[H--];
  maxHeapify(1);
  return max;
}
//=====================
int MinTree(int n){
  int total=0;
  
  
  int i;
  int u,v;
  DOT waste;

  int min_box=INFTY;
  int flag=0;
 
  int gyou_size;
    
  A[0].distance=0;
  waste.distance=0;
  waste.parent=0;
  Insert(waste);
  
  while(H!=0){
    waste=Extract();
    u=waste.parent;
    //左はmaxや最少でない可能性あり、右はextractから出てきたため,そこまでの最少
    // if(A[u].distance<waste.distance*(-1))continue;
    A[u].color=BLACK;

    gyou_size=0;//列のサイズ調べる
    for(i=0;i<n;i++){
      if(G[u][i].dis==-1)break;
      gyou_size++;
    }
           
    for(i=0;i<gyou_size;i++){//uから伸びてる手で一番短いもの探索
      v=G[u][i].to;
      if(A[v].color!=BLACK && A[v].distance > A[u].distance + G[u][i].dis){
	A[v].distance=A[u].distance+G[u][i].dis;//~v=~u+u~vで最少~ｖの
	
	waste.distance=A[v].distance*(-1);
	waste.parent=v;
	Insert(waste);

	A[v].color=GRAY;
      }
    }
  }
  //for(v=1;v<n;v++){
  // total+=G[v][A[v].parent].dis;
  //}
  return total;
}
//======================================
int main(){
  int n;
  int i,j,k;
  int dis,agree,from,to;
  
  for(i=0;i<MAX;i++){//INITIATE 
    A[i].parent=-1;
    A[i].distance=INFTY;
  }
 
  scanf("%d",&n);//INPUT
    
  for(i=0;i<n;i++){//線形グラフ作る列がそれぞれ違う
    scanf("%d%d",&from,&agree);

    G[i]=malloc(sizeof(Gyou)*(agree+1));//最後に余分に-1のgyou作成
    G[i][agree].dis=-1;
    
    for(j=0;j<agree;j++){
      scanf("%d%d",&to,&dis);
      G[from][j].to=to;
      G[from][j].dis=dis;
    }
  }

  MinTree(n);
  
  for(i=0;i<n;i++){
    printf("%d %d\n",i,A[i].distance);//PRINT
  }
  return 0;
}



Measured memory_bytes: 5812
#include <iostream>
#include <iomanip> // setprecision
#include <algorithm> // max, min, sort
#include <vector>
// #include <bits/stdc++.h>
 
using namespace std;

const double EPS = 1e-10;
int ans;

void calc(double cur, int a, int min, int n)
{
    // cout << "cur: " << cur << " a: " << a << " min: " << min << endl;
    // for(int i=0; i<used.size(); i++) cout << used[i] << " ";
    // cout << endl;

    if(cur < EPS && cur > -EPS && a >= 1 && n >= 0)
    {
        // cout << "ans" << endl;
        ans++;
        return;
    }
    min = max(min, (int)(1.0 / (cur + EPS)));
    if(cur < 0 - EPS || a < 1 || n < 0 || a < min) return;

    // int min2 = min;
    // while(cur + EPS < 1.0/min2) min2++;
    // min = max(min2, min);
    //cur + EPS > 1.0 / min
    //min > 1.0/(cur + EPS)

    double d = cur - 1.0/min;
    if(d > 0 - EPS)
    {
        calc(d, a / min, min, n - 1);
    }

    calc(cur, a, min + 1, n);

}

int main()
{
    int p, q, a, n;
    while(cin >> p >> q >> a >> n, p != 0 && q != 0 && a != 0 && n != 0)
    {
        // Global 変数の初期化忘れずに
        ans = 0;

        calc(p * 1.0/q, a, 1, n);

        cout << ans << endl;
    }

  return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    string Sa, Sb, Sc; cin >> Sa >> Sb >> Sc;
    int Ai = 0,  Bi= 0, Ci = 0;
    
    char tmp = 'a';
    while (1)
    {
        if (tmp=='a') {
            if (Ai==Sa.size()) {cout << 'A' << endl; break;}
            tmp = Sa[Ai], Ai++;
        }
        if (tmp=='b') {
            if (Bi==Sb.size()) {cout << 'B' << endl; break;}
            tmp = Sb[Bi], Bi++;
        }
        if (tmp=='c') {
            if (Ci==Sc.size()) {cout << 'C' << endl; break;}
            tmp = Sc[Ci], Ci++;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3688
#include<stdio.h>

 


int main(void){
    int k,s,res=0;
    scanf("%d%d",&k,&s);
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
                if(0<=s-i-j && s-i-j<=k){
                        res++;
                }
            
            }
        }
    

    printf("%d",res);
    return 0;


}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
const int SIZE=2e5+5;
struct Bit{
	ll bit[SIZE];
	Bit(){}
	void init(){
		zero(bit);
	}
	ll get(int k){
		k++;
		ll ret=0;
		while(k>0){
			ret+=bit[k];
			k-=k&-k;
		}
		return ret;
	}
	void add(int k,ll val){
		k++;
		while(k<SIZE){
			bit[k]+=val;
			k+=k&-k;
		}
	}
}bit;
int n;
ll k;
ll sum[SIZE];
int main(){
	bit.init();
	int sz=0;
	scanf("%d%lld",&n,&k);
	sum[sz++]=0;
	for(int i=1;i<=n;i++){
		scanf("%lld",&sum[sz]);
		sum[sz]-=k;
		sum[sz]+=sum[sz-1];
		sz++;
	}
//	for(int i=0;i<=n;i++)cout<<sum[i]<<' ';cout<<endl;
	vector<ll>vs;
	for(int i=0;i<sz;i++){
		vs.push_back(sum[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
//	foreach(itr,vs)cout<<*itr<<' ';cout<<endl;
	ll ret=0;
	for(int i=0;i<sz;i++){
		int pos=lower_bound(all(vs),sum[i])-vs.begin();
		ret+=bit.get(pos);
		bit.add(pos,1LL);
	}
	printf("%lld\n",ret);
	return 0;
}

Measured memory_bytes: 5492
/**
 *    author:  tourist
 *    created: 20.01.2020 17:50:16       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, d;
  cin >> n >> x >> d;
  vector<int> m(n), p(n);
  cin >> m[0];
  for (int i = 1; i < n; i++) {
    cin >> m[i] >> p[i];
    --p[i];
  }
  vector<int> sz(n, 1);
  for (int i = n - 1; i > 0; i--) {
    sz[p[i]] += sz[i];
    m[p[i]] = min(x + 1, m[p[i]] + m[i]);
  }
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(), [&](int i, int j) {
    return m[i] * 1LL * sz[j] < m[j] * 1LL * sz[i];
  });
  vector<int> take(n);
  int weight = 0;
  int add = 0;
  for (int i : order) {
    take[i] = min(i == 0 ? x : d, (x - weight) / m[i]);
    weight += take[i] * m[i];
    add += take[i] * sz[i];
  }
  vector<vector<long long>> dp(n + 1, vector<long long>(2 * n * n * n + 1, (long long) 1e18));
  dp[0][n * n * n] = weight;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 2 * n * n * n; j++) {
      if (dp[i][j] > (long long) 1e17) {
        continue;
      }
      for (int delta = -n; delta <= n; delta++) {
        if (take[i] + delta < 0 || take[i] + delta > (i == 0 ? x : d)) {
          continue;
        }
        dp[i + 1][j + delta * sz[i]] = min(dp[i + 1][j + delta * sz[i]], dp[i][j] + delta * 1LL * m[i]);
      }
    }
  }
  int ans = 0;
  for (int j = 0; j <= 2 * n * n * n; j++) {
    if (dp[n][j] <= x) {
      ans = max(ans, j - n * n * n);
    }
  }
  cout << add + ans << '\n';
  return 0;
}


Measured memory_bytes: 102016
#include <iostream>
#include <math.h>
using namespace std;

int a[100000] ,n ;
int dp[100000] ;

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

int main()
{
    cin>>n ; 
    
    for(int i=0;i<n;i++)
     cin>>a[i] ; 
     
     cout<<jump() ; 
     
    return 0;
}


Measured memory_bytes: 1024
import unittest


class TestC(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(3), 1.0)

    def test_2(self):
        self.assertEqual(think(999), 36926037.0)


def solve():
    L = read()
    result = think(L)
    write(result)


def read():
    return read_int(1)[0]


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(L):
    edge = L / 3
    return edge ** 3


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 51308
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let h: usize = it.next().unwrap().parse().unwrap();
    let w: usize = it.next().unwrap().parse().unwrap();
    let a: Vec<Vec<usize>> = (0..h).map(|_| (0..w).map(|_| it.next().unwrap().parse().unwrap()).collect()).collect();
    let b: Vec<Vec<usize>> = (0..h).map(|_| (0..w).map(|_| it.next().unwrap().parse().unwrap()).collect()).collect();
    let m = 80 * (h + w);
    let mut dp = vec![vec![false; m + 1 + m]; w];
    dp[0][m] = true;
    for (a, b) in a.iter().zip(b.iter()) {
        let mut next = vec![vec![false; m + 1 + m]; w];
        for (i, (&a, &b)) in a.iter().zip(b.iter()).enumerate() {
            let d = std::cmp::max(a, b) - std::cmp::min(a, b);
            if i > 0 {
                for j in 0..(2 * m + 1 - d) {
                    next[i][j + d] |= next[i - 1][j];
                }
                for j in d..(2 * m + 1) {
                    next[i][j - d] |= next[i - 1][j];
                }
            }
            for j in 0..(2 * m + 1 - d) {
                next[i][j + d] |= dp[i][j];
            }
            for j in d..(2 * m + 1) {
                next[i][j - d] |= dp[i][j];
            }
        }
        dp = next;
    }
    let mut ans = 6400;
    for i in 0..(2 * m + 1) {
        if dp[w - 1][i] {
            ans = std::cmp::min(ans, std::cmp::max(m, i) - std::cmp::min(m, i));
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 10220
N = int(input())
X = list(map(int, input().split()))

x_min = min(X)
x_max = max(X)

ans = 10000**10

for i in range(x_min, x_max + 1):
    
    sum_ = 0
    for xi in X:
        sum_ += (xi - i) ** 2
    
    ans = min(ans, sum_)

print(ans)

Measured memory_bytes: 38896
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = list(map(int, input().split()))
c = list(map(int, input().split()))
c.sort()
cnt = 0
for i in b:
    cnt += bisect.bisect_left(a, i) * (n - bisect.bisect_right(c, i))
print(cnt)


Measured memory_bytes: 23360
#include<stdio.h>

int main(void)
{

 int n,d,x,a[100],i,j,c=0;

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

 for(i=0;i<n;i++)
 {
  scanf("%d",&a[i]);

  for(j=1;j<=d;j=j+a[i])
    c++;
 }

  printf("%d\n",c+x);
  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    string s;
    cin>>s;
    if(s[2] == s[3])
    {
        if(s[4] == s[5])
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}


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

int main() {
  string A;
  cin >> A;
  if(A[0] == A[1] && A[1] == A[2]){
	cout << "Yes" << endl;
  }else if(A[1] == A[2] && A[2] == A[3]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int mod = 1e9+7;

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

// int x[300000];

int main() {

  int n;
  cin >> n;
  vector<pair<int, int>> x(n);
  for(int i=0; i<n; i++){
    cin >> x[i].first;
    x[i].second = i;
  }

  sort(x.begin(), x.end());
  for(int i=0; i<n; i++){
    cerr << x[i].first << " " << x[i].second << endl;
  }

  vector<pair<int, int>> ans(n);

  for(int i=0; i<n; i++){
    if( i < n/2 ) ans[i].second = x[n/2].first;
    else ans[i].second = x[n/2-1].first;
    ans[i].first = x[i].second;
  }

  sort(ans.begin(), ans.end());
  for(int i=0; i<n; i++){
    cout << ans[i].second << endl;
  }



  return 0;
}






// EOF


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

signed main(){
  const int INF=1e9+7;
  int N;
  cin>>N;
  std::vector<int> a(N),b(N);
  for(int i=0;i<N;i++)cin>>a[i];
  for(int i=0;i<N;i++)cin>>b[i];
  typedef pair<int,int> P;
  std::vector<P> X(2*N);
  for(int i=0;i<N;i++)X[i]=P(a[i],0);
  for(int i=0;i<N;i++)X[i+N]=P(b[i],1);
  sort(X.begin(),X.end());
  int ans=1;
  int x,y;
  x=y=0;
  for(int i=0;i<N*2;i++){
    if(X[i].second){
      if(x)ans*=x--;
      else y++;
    }
    else{
      if(y)ans*=y--;
      else x++;
    }
    ans%=INF;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,k;
    cin >> a >> b >> k;
    vector<int> v(1,1);
    for(int i=2; i<=a; i++)
        if(a%i==0 && b%i==0)
            v.push_back(i);
    cout << v.at(v.size()-k) << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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


Measured memory_bytes: 3056
#!/usr/bin/env python3

import heapq
import sys


INF = sys.maxsize


def dijkstra(num_vertices, adj_list, source=0):
    dist = [INF for _ in range(num_vertices)]
    dist[source] = 0
    pq = [(dist[u], u) for u in range(num_vertices)]
    heapq.heapify(pq)
    while pq:
        _, u = heapq.heappop(pq)
        for v, cost in adj_list[u]:
            new_length = dist[u] + cost
            if new_length < dist[v]:
                dist[v] = new_length
                heapq.heappush(pq, (new_length, v))
    return dist


def main():
    n = int(input())
    adj_list = [set() for _ in range(n)]
    for _ in range(n - 1):
        a, b, c = (int(z) for z in input().split())
        a -= 1
        b -= 1
        adj_list[a].add((b, c))
        adj_list[b].add((a, c))
    q, k = (int(z) for z in input().split())
    k -= 1
    dist = dijkstra(n, adj_list, k)
    for _ in range(q):
        x, y = (int(z) - 1 for z in input().split())
        res = dist[x] + dist[y]
        print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 72676
/* *
 *
 * Author: Hamkor
 *
 * */
 
#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */
int gcd(int a, int b){return b == 0? a: gcd(b, a%b);}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m = 0; cin>>n;
	vector<int> a(n+2), l (n+2, 0), r(n+2, 0);
	for (int i=1; i<=n; ++i)cin>>a[i];
	for (int i=2; i<=n+1; i++)l[i] = gcd(l[i-1], a[i-1]);
	for (int i=n-1; i>=0; i--)r[i] = gcd(r[i+1], a[i+1]);
	for (int i=0; i<n+2; ++i) m = max(m, gcd(l[i], r[i]));
	cout<<m;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, k; cin>>n>>k;
    vector<int> v(n);
    for(int i=0; i<n; i++) cin>>v[i];

    int ans = 0;
    for(int i=0; i<=k; i++){
        for(int j=0; j<=k; j++){
            if(n < i + j) continue;
            if(k < i + j) continue;

            int rest = k - i - j;

            vector<int> v2;
            for(int l=0; l<i; l++){
                v2.eb(v[l]);
            }

            for(int r=n-1; r>n-1-j; r--){
                v2.eb(v[r]);
            }

            sort(v2.begin(), v2.end());

            int cnt = 0;
            int sum = 0;
            for(int l=0; l<v2.size(); l++){
                if(cnt < rest && v2[l] < 0) cnt++;
                else sum += v2[l];
            }

            chmax(ans, sum);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long

using namespace std;

int main() {
      cin.sync_with_stdio(0);
      string s;
      cin >> s;
      int n = s.back() - '0';
      if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon";
      else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon";
      else cout << "bon";
      return 0;
}

Measured memory_bytes: 3640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int i, month, date, day[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31}, buf=0;
	char name[7][16] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

	while(1){
		scanf("%d%d", &month, &date);
		if(month == 0)
			break;
		for(i=0; i<month; i++)
			buf += day[i];
		buf = buf + date + 3;
		buf = buf % 7;
		for(i=0; i<7; i++){
			if(buf == i){
				printf("%s\n", name[i]);
			}
		}
		buf=0;
	}
	return 0;
}

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

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int cnt = 1;
    for(int i = 0;i < N-1;++i){
        if(S[i] != S[i+1]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	cin >> N;
	int num[19][19] = {};
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		if (s.find('.') == s.npos) {
			s.push_back('.');
		}
		while (s.size() - s.find('.') < 10) {
			s.push_back('0');
		}
		s.erase(s.begin()+ s.find('.'));
		//cout << s << endl;
		M = stoll(s);
		while (s.front() == '0')s.erase(s.begin());
	//	cout << M << endl;
		int a = 0, b = 0;
		while (M % 2 == 0) {
			M /= 2;
			a++;
		}
		while (M % 5 == 0) {
			M /= 5;
			b++;
		}
		a = min(a, 18);
		b = min(b, 18);
		for (int j = 0; j <= 18; j++) {
			for (int k = 0; k <= 18; k++) {
				if (a + j >= 18 && b + k >= 18)ans += num[j][k];
			}
		}
		num[a][b]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3652
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int a, b;
    cin >> a >> b;
    int n = __gcd(a, b);
    int cnt = 1, i = 2;
    while (i * i <= n)
    {
        if (n % i == 0)
        {
            cnt++;
            while (n % i == 0)
                n /= i;
        }
        i++;
    }
    if (n != 1)
        cnt++;
    cout << cnt;

    return 0;
}


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

using namespace std;
int main(){
	string s;
	cin >> s;

	int best = 0;
	char ans;
	int cnt = 0, idx = 0;
	char prev = 'x';
	while(idx < s.size()){
		if(idx &&  s[idx] != prev){
			cnt++;
		}else{
			if(best < cnt){
				ans = prev;
				best = cnt;
			}
			cnt = 0;
		}
		prev = s[idx];
		idx += (s[idx]=='e'?3:7);
	}
	if(best < cnt){
		ans = prev;
		best = cnt;
	}
	cout << (ans=='e'?"egg":"chicken") << endl;


	return 0;
}

Measured memory_bytes: 1192
import java.util.Scanner;

public class Main {

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

//		double a = sc.nextDouble();
//		double b = sc.nextDouble();
//		double c = sc.nextDouble();

		// √a + √b < √c
		// a + 2√ab + b < c
		// 0 < (c -a -b)^2 - 4ab
//		BigDecimal result = new BigDecimal(c - a - b);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long result = c -a -b;

		if (result > 0 && 0 < (result * result) - (4 * a * b)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	n, k := oneInt(), oneInt()

	sss := oneStr()

	ans := calc(sss, n, k)
	fmt.Println(ans)

}

type runLength struct {
	cnt int
	s   string
}

func calc(sss string, n, k int) int {
	nums := []runLength{}

	tmp := ""
	for _, s := range sss {
		if tmp == "" {
			tmp = string(s)
			nums = append(nums, runLength{1, tmp})
		} else {
			if tmp == string(s) {
				nums[len(nums)-1].cnt++
			} else {
				tmp = string(s)
				nums = append(nums, runLength{1, tmp})
			}
		}
	}

	nums = append(nums, runLength{0, "1"})

	sums := []int{0}

	for i, n := range nums {
		sums = append(sums, sums[i]+n.cnt)
	}

	ans := -1
	right := 0

	for left := 0; left < len(sums)-1; left++ {
		right = min(len(sums)-1, left+2*k+1)
		if nums[left].s == "0" {
			right = min(len(sums)-1, left+2*k)
		}

		ans = max(ans, sums[right]-sums[left])
	}

	//fmt.Println(nums)
	//fmt.Println(sums)

	return ans
}

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}


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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e9;
const int MB = 30;
const int MOD = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	vector<bool> used(1e6 + 1);
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		mp[x]++;
	}
	int ans = 0;
	for (auto& p : mp) {
		if (!used[p.first]) {
			for (int i = p.first; i < used.size(); i += p.first) {
				used[i] = true;
			}
			if (p.second == 1) ans++;
		}
	}
	cout << ans;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 16096
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int A,B,C;

int main(){
    cin>>A>>B>>C;
    out((A^B^C));
}


Measured memory_bytes: 256