akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>

using namespace std;

int main(int argc, char** argv)
{
    int X, N;
    std::vector<int> pList;
    std::unordered_set<int> valueExists;
    cin >> X >> N;
    pList.resize(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> pList[i];
        valueExists.insert(pList[i]);
    }

    if (N == 0)
    {
        cout << X << endl;
        return 0;
    }

    std::sort(pList.begin(), pList.end());

    //auto lowerIt = std::lower_bound(pList.begin(), pList.end(), X);
    //auto upperIt = std::upper_bound(pList.begin(), pList.end(), X);

    //if (lowerIt == pList.end())
    //{
    //    // X is bigger than all the numbers
    //    cout << X << endl;
    //    return 0;
    //}

    //if (upperIt == pList.begin())
    //{
    //    // XはPの最小の値以下
    //    // X is smaller than all the numbers
    //    if (X != pList[0])
    //    {
    //        cout << X << endl;
    //    }
    //    else
    //    {
    //        cout << X - 1 << endl;
    //    }
    //    return 0;
    //}

    //if (upperIt == pList.end())
    //{
    //    // XがP内のどれよりも大きい
    //    // [p..., pN, X)
    //    if (pList[N - 1] == X)
    //    {
    //        if (N == 1)
    //        {
    //            cout << X - 1 << endl;
    //        }
    //        else
    //        {
    //            if (pList[N - 2] == X - 1)
    //            {
    //                // p(N-1) = X-1
    //                // P(N) = X
    //                // 下のほうに下って行った時の一番近いのは少なくとも距離2以上なのでありえない
    //                cout << X + 1 << endl;
    //            }
    //            else
    //            {
    //                // p(N-1) != X-1  なのでX-1はPに入っていない→最小はこれ
    //                cout << X - 1 << endl;
    //            }
    //        }
    //    }
    //    else
    //    {
    //        cout << X << endl;
    //    }
    //    return 0;
    //}

    // 普通に探す
    for (int diff = 0; ; ++diff)
    {
        int v1 = X - diff;
        int v2 = X + diff;

        if (valueExists.find(v1) == valueExists.end())
        {
            cout << v1 << endl;
            break;
        }
        if (valueExists.find(v2) == valueExists.end())
        {
            cout << v2 << endl;
            break;
        }
    }

    return 0;
}

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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

int main() {
  int N;

  cin >> N;
  vector< pair< pair< int, int >, int > > st(N);
  for(int i = 0; i < N; i++) {
    cin >> st[i].first.second >> st[i].first.first >> st[i].second;
  }
  sort(begin(st), end(st), [&](auto x, auto y) {
    return (x.first.first - y.first.second < y.first.first - x.first.second);
  });


  vector< int64 > dp(10002);
  int ret = 0;
  for(int i = 0; i < N; i++) {
    for(int j = st[i].first.first; j >= 0; j--) {
      int idx = min(j + st[i].first.second, 10001);
      dp[idx] = max(dp[idx], dp[j] + st[i].second);
    }
  }


  cout << *max_element(begin(dp), end(dp)) << endl;
}


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

int main(){
	long long  n ; cin >> n ;
 	set<long long> s ;
	for(long long i=0;i<n;i++){
		long long x ; cin >> x ;
		if(s.count(x)){
			cout << "NO" << endl ;
			return 0 ;
		}else{
			s.insert(x) ;
		}
	}
	cout << "YES" << endl ;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node{
  int key;
  struct node *prev;
  struct node *left;
  struct node *right;
};
typedef struct node *NodePointer;
void insert(NodePointer);
NodePointer makenode(int);
void InorderPrint(NodePointer);
void PreorderPrint(NodePointer);
NodePointer Node; 
int m;
NodePointer root = NULL;

int main()
{
  int i, key;
  char order[7];
  NodePointer NewNode;
  
  scanf("%d",&m);

  for(i = 0 ; i < m ; i++){
    scanf("%s",order);
    
    if(strcmp(order,"insert") == 0){
      scanf("%d",&key);
      NewNode = makenode(key);
      insert(NewNode); }
    if(strcmp(order,"print") == 0){
      InorderPrint(root);
      printf("\n");
      PreorderPrint(root);
      printf("\n"); }
  }
  
  return 0;
}

void insert(NodePointer z)
{
  NodePointer y, x;
    
  y = NULL; /* xの親 */
  x = root;

  while(x != NULL){   
    y = x; /* 親を設定 */
    if(z->key < x->key) x = x->left;
    else x = x->right; }

  z->prev = y;

  if(y == NULL) root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
    
}

NodePointer makenode(int key)
{
  NodePointer NewNode;

  NewNode = (NodePointer)malloc(sizeof(struct node));

  NewNode->key = key;
  NewNode->left = NULL;
  NewNode->right = NULL;
  
  return NewNode;
}

void InorderPrint(NodePointer u)
{
  if(u == NULL) return; 

  InorderPrint(u->left);
  printf(" %d",u->key);
  InorderPrint(u->right);
}

void PreorderPrint(NodePointer u)
{
  if(u == NULL) return;
  
  printf(" %d",u->key);

  PreorderPrint(u->left);
  PreorderPrint(u->right);
}



Measured memory_bytes: 25144
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pob pop_back
#define ft first
#define ftt ft.ft
#define ftc ft.sc
#define sc second
#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define ctz __builtin_ctz
typedef pair<int, int> pii;
typedef pair<ll ,ll> pll;
const int maxn = 1e6 + 120;
 


int a ,b ,c;

int main(){FAST;
    cin >> a >> b >> c;
    int x = b / a;
    x >= c ? cout << c : cout << x;
   return 0;
}
 












Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#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(x) (x).begin(),(x).end()
int main(){
    vi d(3);
    REP(i,3)cin>>d[i];
    sort(all(d));
    if(d[0]==d[1])cout<<d[2]<<endl;
    else cout<<d[0]<<endl;
    return 0;
}

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

using namespace std;

bool contains(const std::string& str1,const std::string& str2) {
    std::string::size_type pos = str1.find(str2);
    if(pos==std::string::npos)
    {
        return false;
    }
    return true;
}

bool isin(int n, string* d, int k) {
    string s = to_string(n);
    for (int i = 0; i < k; ++i) {
        if (contains(s, d[i])) {
            return true;
        }
    }
    return false;
}

int main() {
    int n, k;
    string d[10];
    cin >> n >> k;
    for (int i = 0; i < k; ++i) {
        int t;
        cin >> t;
        d[i] = to_string(t);
    }
    int j;
    for (j = n;; ++j) {
        if (!isin(j, d, k)) {
            break;
        }
    }
    cout << j << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
  long n,a,b;
  scanf("%ld", &n);
  a=(long)sqrt((double)n);
  while(a>1){
    if(n%a==0){
      printf("%ld\n",a+(n/a)-2);
      return 0;
    }
    a--;
  }
  printf("%ld\n",n-1);
  return 0;
}


Measured memory_bytes: 128
object Main extends App {
  val List(n,m) = io.StdIn.readLine.split(" ").toList.map(_.toInt)
  val a_sum = io.StdIn.readLine.split(" ").toList.map(_.toInt).sum
  
  val t = n - a_sum
  if(t<0){
    println(-1)
  }else{
    println(t)
  }
}

Measured memory_bytes: 54968
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int h;
        cin >> h;
        if(h>=k){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

typedef vector<ll> vecll;
typedef vector<ld> vecld;
typedef vector<bool> vecbl;
typedef vector<vector<ll> > matll;
typedef vector<vector<ld> > matld;
typedef vector<vector<bool> > matbl;
#define mp make_pair;

const ll prime = 1000000000 + 7;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

bool my_comp(pll a, pll b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}

	return a.second < b.second;
}

// nのk乗(mod p = prime)
ll power(ll n, ll k) {
	ll p = prime;
	if (k == 1) {
		return n;
	}
	ll m = n * n;
	m %= p;
	if (k % 2 == 0) {
		return power(m, k / 2);
	}
	m = power(m, k / 2);
	m *= n;
	m %= p;
	return m;
}

// nCk(mod p = prime)
ll com(ll n, ll k) {
	// nCk
	ll p = prime;

	ll ans = 1;
	for (ll i = 1; i <= n; i++)
	{
		ans *= i;
		ans %= p;
	}

	for (ll i = 2; i <= k; i++)
	{
		ans *= power(i, p - 2);
		ans %= p;
	}

	for (ll i = 2; i <= n-k; i++)
	{
		ans *= power(i, p - 2);
		ans %= p;
	}

	return ans;
}



ll rec(ll k, ll length, ll cnt, vecll nums, ll index) {
	ll ans;
	if (length == index) {
		if (k - cnt == 1) {
			// nums is answer
			ans = 0;
			for (ll i = 0; i < length; i++)
			{
				ans += nums[length - 1 - i] * pow(10, i);
			}
			return -ans;
		}
		else {
			return cnt + 1;
		}
	}
	else {
		ll pre = nums[index - 1];
		if (pre != 0) {
			// pre-1 dainyuu
			nums[index] = pre - 1;
			cnt = rec(k, length, cnt, nums, index + 1);

			if (cnt < 0) {
				return cnt;
			}
		}
		nums[index] = pre;
		cnt = rec(k, length, cnt, nums, index + 1);

		if (cnt < 0) {
			return cnt;
		}

		if (pre != 9) {
			nums[index] = pre + 1;
			cnt = rec(k, length, cnt, nums, index + 1);

			if (cnt < 0) {
				return cnt;
			}
		}

		return cnt;
	}
}

int main() {

	ll k, ans, index;
	ll cnt = 0;
	vecll nums;
	cin >> k;
	ll length = 1;
	if (k < 10) {
		cout << k << endl;
		return 0;
	}

	while (true) {
		nums = vecll(length);
		for (ll i = 1; i < 10; i++)
		{
			// 1ketame
			nums = vecll(length);
			index = 0;

			nums[0] = i;
			index++;

			ans = rec(k, length, cnt, nums, index);
			if (ans < 0) {
				cout << -ans << endl;
				return 0;
			}
			cnt = ans;
		}
		length++;
	}

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 200005
using namespace std;
lo int n,k,A[li],pre[li],fe[li+1005],cev;
vector< pair<lo int,lo int> > v;
void update(int x){
	for(int i=x;i<=n+1;i+=(i&-i)) fe[i]++; 
}
lo int que(lo int x){
	lo int res=0;
	for(int i=x;i>=1;i-=(i&-i)) res+=fe[i];
	return res;
}
int main(){
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=n;i++) {scanf("%lld",&A[i]);A[i]-=k;}
	for(int i=1;i<=n;i++) pre[i]=pre[i-1]+A[i];
	v.pb(mp(0,0));
	for(int i=1;i<=n;i++){
		v.pb(mp(pre[i],i));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<(int)v.size();i++){
		update(v[i].se+1);
		if(v[i].se==0) continue;
		cev+=que(v[i].se);
	}
	printf("%lld\n",cev);
	return 0;
}


Measured memory_bytes: 9328
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     ll           long long int
#define     int          ll
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     makep        make_pair
#define     maket        make_tuple
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const ld pi=acos(-1);
const int inf=1e18,M=1e9+7;
const int N=1;

int nc2(int n)
{
    int res=(n*(n-1))/2;
    return res;
}

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

    map<int,int> mp;
    vector<int> v(n);
    for(int i=0;i<n;++i)
    {
        cin>>v[i];
        ++mp[v[i]];
    }

    int ans=0;
    for(auto& c:mp)
    {
        ans+=(c.S*(c.S-1))/2;
    }

    for(int i=0;i<n;++i)
    {
        ans-=nc2(mp[v[i]]);
        --mp[v[i]];
        ans+=nc2(mp[v[i]]);
        cout<<ans<<"\n";
        ans-=nc2(mp[v[i]]);
        ++mp[v[i]];
        ans+=nc2(mp[v[i]]);
    }
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}





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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

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

  int a, b;
  cin >> a >> b;

  int x = b - a;

  int sum = 0;
  repi(i, 2, x + 1) {
    sum += i;
  }

  int ans = sum + 1 - b;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

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


Measured memory_bytes: 3068
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(){
    int A,B,T;
    cin>>A>>B>>T;
    int num_bisc=0;
    int i=1;
    while(1){
        if(T>=i*A){
            num_bisc+=B;
            i++;
        }else{
            break;
        }
    }
    cout<<num_bisc<<endl;
}

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

int main(){
    int count[26] = {0};
    string S; cin >> S;

    for (char c : S) count[c - 'A']++;

    int cnt = 0;
    rep(i, 26) {
        if (count[i] == 2) cnt++;
        else if (count[i]!=0) {
            cout << "No" << endl;
            return 0;
        }
    }


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


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, W: "List[int]"):
    w_left = 0
    w_right = sum(W)

    res = 10001
    for w in W:
        w_left += w
        w_right -= w
        res = min(res, abs(w_left - w_right))
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      
      int A =  sc.nextInt();
      int B =  sc.nextInt();
      
      if(A + B < 24){
      System.out.println(A + B);
      }else{
      System.out.println((A + B)- 24);
      }
    }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  ll n, k;
  cin >> n >> k;
  vl h(n);
  re(i, n) cin >> h[i];

  sort(all(h));
  ll m = INF;
  re(i, n-k+1) {
    ll s = h[i+k-1] - h[i];
    m = min(m, s);
  }
  cout << m << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
using ll = long long;

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

  set<char> alpha;
  for(int i=0;i<26;i++) alpha.insert('a'+i);

  for(int i=0;i<S.size();i++){
    alpha.erase(S.at(i));
    if(alpha.empty()){
      cout << "None" << endl;
      return 0;
    }
  }

  cout << *begin(alpha) << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
#define MOD 1000000007
#define MSG(a) cout << #a << " " << a << endl;
#define print(a) cout << a << endl;
template <class T, class C>
void chmax(T &a, C b)
{
    if (a <= b)
        a = b;
}
template <class T, class C>
void chmin(T &a, C b)
{
    if (a >= b)
        a = b;
}

template <class T>
T sum(const vector<T> &v)
{
    T res = 0;
    for (size_t i = 0; i < v.size(); ++i)
        res += v[i];
    return res;
}
// vector の出力
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v)
{
    size_t last = v.size() - 1;
    for (size_t i = 0; i < v.size(); ++i)
    {
        out << v[i];
        if (i != last)
            out << " ";
    }
    return out;
}

void f(const vector<vector<int>> &edges, vector<int> &costs, int c)
{
    for (auto u : edges[c])
    {
        // int u = edges[c][i];
        if (costs[u] >= 0)
            continue;
        costs[u] = costs[c] + 1;
        f(edges, costs, u);
    }
}

template <typename T> // T: type of cost
struct base_tree
{
    int n;
    vector<vector<int>> to; // edge
    vector<vector<T>> co;   // cost
    vector<T> cost1;        // cost
    vector<T> cost2;        // cost
    base_tree(int n) : n(n), to(n), co(n), cost1(n), cost2(n)
    {
        rep(i, n)
        {
            cost1[i] = -1;
            cost2[i] = -1;
        }
    }

    void addEdge(int a, int b, T c = 0)
    {
        to[a].push_back(b);
        co[a].push_back(c);
        to[b].push_back(a);
        co[b].push_back(c);
    }
    void dfs(int v, vector<T> &cost, int d = 0)
    {
        if(cost[v]>=0)return;
        cost[v]=d;
        for (int i = 0; i < to[v].size(); ++i)
        {
            int u = to[v][i];
            if (cost[u] >= 0)
                continue;
            dfs(u, cost, d + 1);
        }
    }
    void run()
    {
        dfs(1, cost1);
        dfs(n - 1, cost2);
    }
};

int main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //////////////////////////////////////////

    int n;
    cin >> n;
    base_tree<ll> tree(n + 1);

    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        tree.addEdge(a, b);
    }
    tree.run();
    int ans = 0;
    rep(i, n)
    {
        if (tree.cost1[i + 1] <= tree.cost2[i + 1])
            ans += 1;
        else
            ans -= 1;
    }
    if (ans <= 0)
    {
        print("Snuke");
    }
    else
    {
        print("Fennec")
    };

    return 0;
}


Measured memory_bytes: 20248
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{

    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

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

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    ll max = -INF;
    chmax(max, a);
    chmax(max, b);
    chmax(max, c);
    ll sa;
    sa = max * 3 - a - b - c;
    while (sa % 2)
    {
        sa += 3;
    }
    cout << sa / 2 << endl;
}


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

typedef pair<int64_t, int64_t> Pair;

void fail(){
    cout << -1 << endl;
    exit(0);
}

int main(){
    int i, j, k;
    int N;
    cin >> N;
    vector<Pair> D(N);

    for(i=0; i<N; i++){
        int64_t d;
        cin >> d;
        D.push_back({d, i});
    }
    sort(D.rbegin(), D.rend());

    map<int64_t, int64_t> mp;
    for(i=0; i<N; i++) mp[D[i].first] = i;

    vector<Pair> ans;
    vector<int64_t> dist_sub(N, 0);
    vector<int> num_sub(N, 1);

    for(i=0; i<N-1; i++){
        int64_t diff = N - 2*num_sub[i];
        int64_t pd = D[i].first - diff;
        if(mp.count(pd)){
            int p = mp[pd];
            ans.push_back({D[i].second+1, D[p].second+1});
            num_sub[p] += num_sub[i];
            dist_sub[p] += dist_sub[i] + num_sub[i];
        }else{
            fail();
        }
    }
    if(dist_sub[N-1] != D[N-1].first) fail();

    for(auto&& e : ans){
        cout << e.first << " " << e.second << endl;
    }
    return 0;
}

Measured memory_bytes: 17508
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

const int maxn = 1e5 + 5;

int n;
int len;
int son[maxn];
bool flag;
int cnt;
std::vector<int> G[maxn];
int par[maxn];

void dfs(int u, int fa, int d) {
    par[u] = fa;
    if (u == n) {
        len = d;
        flag = true;
        return;
    }
    for (int v : G[u]) if (v != fa) {
        dfs(v, u, d + 1);
        if (flag) {
            son[u] = v;
            break;
        }
    }
}

void dfs2(int u, int fa) {
    // cout << u << endl;
    cnt ++;
    for (int v : G[u]) if (v != fa && v != son[u]) {
        dfs2(v, u);
    }
}

int main(int argc, char const *argv[]) {
    
    cin >> n;

    memset(son, -1, sizeof(son));
    for (int i = 1; i < n; i ++) {
        int u, v;
        scanf("%d%d", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
    }

    dfs(1, -1, 0);
    len = len / 2 + 1;
    cnt = 0;
    int root = 1;
    while (root != -1 && len) {
        dfs2(root, par[root]);
        len --;
        root = son[root];
    }

    int res = n - cnt;
    // cout << cnt << " " << res << endl;
    if (cnt > res) puts("Fennec");
    else puts("Snuke");    

    return 0;
}

Measured memory_bytes: 14336
//
// Created on 2018/12/02.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<(n);++i)
#define RFOR(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define PB push_back
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    string n;
    cin >> n;

    int fav = 753;
    int comp;
    int best = INF;

    REP(i,(int)n.size()-2){
        comp = stoi(n.substr(i,3));
        //cout << i << ": " << comp << endl;
        best = min(best,abs(fav-comp));
    }

    cout << best << endl;


    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int H, W;
	scanf("%d%d", &H, &W);
	char a[H + 2][W + 2];
	int i = 1;
	int j;
	while (i <= H)
	{
		scanf("%s", a[i]);
		i++;
	}
	i = 0;
	while (i <= H + 1)
	{
		j = -1;
		while (j <= W)
		{
			if (i == 0 || i == H + 1)
				printf("#");
			else if (j >= 0 && j < W)
				printf("%c", a[i][j]);
			else if (j == -1 || j == W)
				printf("#");
			j++;
		}
		printf("\n");
		i++;
	}
	return (0);
}

Measured memory_bytes: 128
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x  
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;


int n=55555;
bool  p[55559];

void  seive(){
    p[0]=p[1]=true;
    for (int i=4;i<=n;i+=2) p[i]=true;
    for (int i=3;i*i <= n;i += 2){
        if (p[i] == false)
        for (int j=i*i;j<=n;j+= i*2)
                p[j] = true;
    }
}


inline void solve(){
    seive();
    int n,s=28; cin>>n; 
    for (int i=10;i<=55555 and n>0;i++){
        if (p[i] == false and i%5==2){
            cout << i << " ";
            n--;
        }
    }
    cout << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3588
/*
    Ujjawal Pabreja [cuber_coder]
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define ld              long double
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define in              insert
#define ff              first
#define ss              second
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define rev             reverse
#define Y				"YES"
#define N 				"NO"
#define endl            "\n"
#define debug(x)        cout << #x << " : " << x << endl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

inline ll add(ll a,ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a,ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a,ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x,ll n){
    if(n == 0){
        return 1;
    }
    if(n&1){
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    } else {
        return pwr(mul(x, x), n / 2);
    }
}
ll modInv(ll n){ 
    return pwr(n, mod - 2); 
}
ll gcd(ll a,ll b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
// ====== Useful functions end ======
 
// ====== Global Variables begin ======

// ====== Global Variables end ======

void speed_solve(){
    ll n, k, d;
    cin >> n >> k >> d;
    n = abs(n);
        ll moves = min(n / d, k);
        ll val = n - moves * d;
        k -= moves;
        cout << (k&1 ? min(abs(val + d), abs(val - d)) : val);
}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

Measured memory_bytes: 3660
K, A, B = map(int, input().split())

if A + 2 >= B:
    print(K + 1)
else:
    if K < A + 1:
        print(K + 1)
    else:
        m = (K - (A - 1)) // 2
        r = (K - (A - 1))  - 2 * m
        print(m * (B - A) + r + A - 1 + 1)


Measured memory_bytes: 3060
process.stdin.resume();
process.stdin.setEncoding();
process.stdin.on('data',function(chunk){


var line=chunk.split(" ").map(Number);
var a = line[0];
var b = line[1];

var d=Math.floor(a/b);
var r=a%b;
var f=(a/b).toFixed(5);

 
 console.log(d+" "+r+" "+f);


});

Measured memory_bytes: 15792
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pb push_back
#define vl vector<ll>
#define vs vector<string>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define vii vector<pii>
#define F first
#define S second
using namespace std;
ll dfs(ll h)
{
	if(h==1)return 1;
	else return dfs(h/2)*2+1;
}
ll h;
signed main()
{
	std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>h;
	cout<<dfs(h);
	return 0;
}

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

using namespace std;

int main() {
  string w;
  cin >> w;
  int ws[130] = {0};

  for (string::iterator it = w.begin(); it != w.end(); it++) {
    ws[*it]++;
  }
  int a = (int)'a';
  int z = (int)'z';
  bool ok = true;
  for (int i = a; i <= z; i++) {
    if (ws[i] % 2 == 1) {
      ok = false;
      break;
    }
  }
  if (ok) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3160
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=105;
int n,m,F[maxn][maxn];
char mp[maxn][maxn];
bool to[maxn][maxn];
inline int read(){
	int ret=0;bool f=0;char ch=getchar();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=getchar();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
	return f?-ret:ret;
}
int main(){
	n=read(),m=read();
	for (int i=1;i<=n;i++) scanf("%s",mp[i]+1);
	memset(F,63,sizeof F);F[1][1]=0;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++){
		for (int ii=i;ii<=n;ii++)
		for (int jj=j;jj<=m;jj++){
			to[ii][jj]=ii==i&&jj==j;
			if(mp[ii][jj]!=mp[i][j]) continue;
			if(ii>i&&to[ii-1][jj]) to[ii][jj]=1;
			if(jj>j&&to[ii][jj-1]) to[ii][jj]=1;
			if(to[ii][jj])
			F[ii+1][jj]=min(F[ii+1][jj],F[i][j]+(mp[i][j]=='#')),
			F[ii][jj+1]=min(F[ii][jj+1],F[i][j]+(mp[i][j]=='#'));
		}
	}
	printf("%d\n",F[n][m+1]);
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
using ll = long long int;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int solve_testcase() {
    int N; cin >> N;
    if(N == 0) return 1;

    const int M = 55440 * 2;
    vector<int> rec(M);
    vector< vector<int> > sum(25, vector<int>(25));
    for(int i=0; i<N; i++) {
        int K, T; cin >> K >> T;

        if(K == 13 or K == 17 or K == 19 or K == 23) {
            for(int j=0; j<K; j++) {
                int v; cin >> v;
                sum[K][(j-T+K)%K] += v;
            }
        }
        else {
            for(int j=0; j<K; j++) {
                int v; cin >> v;
                for(int t=j-T; t<M; t+=K) {
                    if(t < 0) continue;
                    rec[t] += v;
                }
            }
        }
    }

    int ans = *max_element(rec.begin(), rec.end());
    for(int i=0; i<25; i++) {
        ans += *max_element(sum[i].begin(), sum[i].end());
    }
    cout << ans << endl;
    return 0;
}

int main() {
    while(!solve_testcase());

    if(false) {   
        ll l = 1;
        for(int i=1; i<=24; i++) {
            if(i == 13 or i == 17 or i == 19 or i == 23) continue;
            l = lcm(l, i);
            fprintf(stderr, "i = %d, lcm = %lld\n", i, l);
        }
    }
    return 0;
}



Measured memory_bytes: 3440
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
ll dam[40000],t[40000],inf=1e9;
vector<PP> ord;
bool comp(const PP& x,const PP& y){
	return x.sc.fs*y.sc.sc>x.sc.sc*y.sc.fs;
}
vector<int> uses;
int main(){
	int N;
	ll H,A,D,S,turn=0,sum=0;
	cin>>N;
	cin>>H>>A>>D>>S;
	rep(i,N){
		ll h,a,d,s;
		cin>>h>>a>>d>>s;
		dam[i]=max((ll)0,a-D);
		if(A-d>0){
			t[i]=(h-1)/(A-d)+1;
			turn+=t[i];
		} else t[i]=-1;
		if(S<s) sum+=dam[i];
	}
	rep(i,N){
		if(!dam[i]) continue;
		if(t[i]<0){
			puts("-1");
			return 0;
		}
		uses.pb(i);
	}
	for(int i:uses) ord.pb(PP(i,P(dam[i],t[i])));
	sort(all(ord),comp);
	rep(i,ord.size()) dam[i]=ord[i].sc.fs,t[i]=ord[i].sc.sc;
	ll tmp=-1;
	rep(i,ord.size()){
//		show(t[i]);
//		show(dam[i]);
		tmp+=t[i];
		sum+=dam[i]*tmp;
		if(H-sum<=0){
			puts("-1");
			return 0;
		}
	}
	cout<<sum<<endl;
}

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

int main() {

  // input
  int n, K; cin >> n >> K;
  int sum_b = 0;
  int sum_r = 0;

  vector<int> a(n);
  vector<int> acc(n + 1, 0);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    acc[i + 1] = a[i];
    acc[i + 1] += acc[i];
  }
  vector<int> r(K);
  for(int i = 0; i < K; i++){
    cin >> r[i];
    sum_r += r[i];
  }
  vector<int> b(K);
  for(int i = 0; i < K; i++){
    cin >> b[i];
    sum_b += b[i];
  }
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(r.rbegin(), r.rend());

  int inf = 10101010;
  vector<vector<vector<int>>> dp(n + 1, vector<vector<int>> (K + 1, vector<int> (sum_r + 1, inf)));
  dp[0][0][0] = 0;

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < K; j++) {
      for(int k = 0; k < sum_r; k++) {
        if(dp[i][j][k] == inf) continue;


        int l = i - j;
        int used_r = k;
        int used_b = acc[i] - used_r;

        // use red
        int nxt_used_r = used_r + a[i];
        int nxt_cost = max(0, a[i] - r[j]);
        if(nxt_used_r <= sum_r) dp[i + 1][j + 1][nxt_used_r] = min(dp[i + 1][j + 1][nxt_used_r], dp[i][j][k] + nxt_cost);


        // use blue
        int nxt_used_b = used_b + a[i];
        if(l >= K) continue;
        nxt_cost = max(0, a[i] - b[l]);
        if(nxt_used_b <= sum_b) dp[i + 1][j][used_r] = min(dp[i + 1][j][used_r], dp[i][j][k] + nxt_cost);

      }
    }
  }

  int ans = inf;
  for(int j = 0; j <= K; j++)
    for(int k = 0; k <= sum_r; k++)
      ans = min(ans, dp[n][j][k]);

  if(ans == inf) ans = -1;

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



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

using namespace std;

struct point {
    int left, right, block, id;
};

bool cmp(const point &lhs, const point &rhs) {
    if (lhs.block < rhs.block)
        return true;
    else if (lhs.block > rhs.block)
        return false;
    else
        return lhs.right < rhs.right;
}

int main(){
    int n, q;
    scanf("%d", &n);
    scanf("%d", &q);
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);

    int block_size = sqrt(n);

    
    vector<point> query(q);
    for (int i = 0; i < q; i++) {
        scanf("%d %d", &query[i].left, &query[i].right);
        query[i].left--, query[i].right--;
        query[i].block = query[i].left / block_size;
        query[i].id = i;
    }

    sort(query.begin(), query.end(), cmp);

    vector<int> solution(q);
    vector<int> hash(1000100);

    int left = 0, right = 0, answer = 1;
    hash[A[0]] = 1;

    for (const point &task : query) {
        while (left < task.left) {
            hash[A[left]]--;
            answer -= (hash[A[left]] == 0);
            left++;
        }
        while (left > task.left) {
            left--;
            hash[A[left]]++;
            answer += (hash[A[left]] == 1);
        }
        while (right < task.right) {
            right++;
            hash[A[right]]++;
            answer += (hash[A[right]] == 1);
        }
        while (right > task.right) {
            hash[A[right]]--;
            answer -= (hash[A[right]] == 0);
            right--;
        }
        solution[task.id] = answer;
    }

    for (int answer : solution)
        printf("%d\n", answer);

    return 0;
}


Measured memory_bytes: 19296
n,y = map(int, input().split())
ten = -1
five = -1
one = -1

for i in range(n + 1):
  for j in range(n + 1):
    tmp = i * 10000 + j * 5000
    left = y - tmp
    if left < 0:
      continue
    cnt = left // 1000
    if i + j + cnt == n:
      ten = i
      five = j
      one = cnt
      break

print(ten, five, one)

Measured memory_bytes: 9100
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 100000;

int D[MAXN + 1];
void radixSort(const int *A, const int *B, int *C, int N, int M) {
	int i;
	for (i = 0; i <= M; i++) D[i] = 0;
	for (i = 0; i < N; i++) D[B[A[i]]]++;
	for (i = 1; i <= M; i++) D[i] += D[i - 1];
	for (i = N; i--; C[--D[B[A[i]]]] = A[i]);
}

int B[MAXN + 1];
int T[MAXN];
void suffixArray(const char *A, int *C, int N) {
	int i, j, k, l;
	for (i = 0; i < N; i++) {
		B[i] = A[i];
		T[i] = i;
	}
	radixSort(T, B, C, N, 128);
	for (i = k = 1; i < N && k < N; i <<= 1) {
		for (k = 0; k < i; k++) T[k] = k - i + N;
		for (j = 0; j < N; j++) if (C[j] >= i) T[k++] = C[j] - i;
		radixSort(T, B, C, N, N);
		T[C[0]] = k = 1;
		for (j = 1; j < N; j++) {
			if (B[C[j]] != B[C[j - 1]] || B[C[j] + i] != B[C[j - 1] + i]) k++;
			T[C[j]] = k;
		}
		for (j = 0; j < N; j++) B[j] = T[j];
	}
}

char S[100001];
int R[100001];

int main() {
	int LL, RR, MM;
	int i, j, n, m;
	scanf("%d%s", &m, S);
	n = strlen(S);
	suffixArray(S, R, n);
	for (i = 0; i < n; i++) T[R[i]] = i;
	if (n % (m + 1) == 0) {
		j = 0;
		for (i = 1; i <= m; i++) if (T[i * (n / (m + 1))] > T[j]) j = i * (n / (m + 1));
		S[j + (n / (m + 1))] = 0;
		puts(S + j);
		return 0;
	}
	LL = 0;
	RR = n - 1;
	while (LL < RR) {
		MM = LL + RR >> 1;
		D[0] = 0;
		for (i = 1; i <= n; i++) D[i] = 1e9;
		for (i = 0; i < n; i++) {
			if (i + n / (m + 1) <= n) D[i + n / (m + 1)] = min(D[i + n / (m + 1)], D[i] + 1);
			if (i + n / (m + 1) + 1 <= n && T[i] <= MM) D[i + n / (m + 1) + 1] = min(D[i + n / (m + 1) + 1], D[i] + 1);
		}
		if (D[n] <= m + 1) RR = MM;
		else LL = MM + 1;
	}
	S[R[LL] + n / (m + 1) + 1] = 0;
	puts(S + R[LL]);
}


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

using namespace std;

int main() {
   int n;
   cin >> n;
   vector<int> p(n);
   for (int &x : p) {
      cin >> x;
   }
   int cnt = 0;
   for (int i = 1; i + 1 < n; ++i) {
      if (p[i] > p[i - 1] && p[i] < p[i + 1]) {
         cnt++;
      } else if (p[i] < p[i - 1] && p[i] > p[i + 1]) {
         cnt++;
      }
   }
   cout << cnt;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}
template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}
template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}


int main()
{
	ll h,w;
	cin >> h >> w;
	if(h == 1 || w == 1){
		cout << 1 << endl;
		return 0;
	}
	cout << (h * w + 1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int top,s[1000];

void push(int x){
    s[++top] = x;
}

int pop(){
    top--;
    return s[top+1];
}

int main(){
    int a,b;
    char c[100];
    	while(cin>>c){
		if(c[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}
		else if(c[0]=='-'){
			a=pop();
			b=pop();
			push(b-a);
		}
		else if(c[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}
		else{
			push(atoi(c));
		}
	}
	cout<<pop()<<endl;
    
	return 0;
}



Measured memory_bytes: 3120
#include <stdio.h>
int main()
{
    int k,x;
    scanf("%d%d",&k,&x);
    int res1= x-k+1;
    int res2= x+k-1;
    for(int i=res1;i<=res2;i++)
        printf("%d ",i);
    printf("\n");
  	return 0;
}

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

bool hasBomb(vector<string> &s, int i, int j) {
	if (i < 0 || i >= s.size()) {
		return false;
	}
	if (j < 0 || j >= s.at(i).size()) {
		return false;
	}
	if (s.at(i).at(j) == '#') {
		return true;
	}
	else {
		return false;
	}
}

int countBomb(vector<string> &s,int i,int j) {
	int count = 0;
	if (hasBomb(s, i - 1, j - 1)) {
		count++;
	}
	if (hasBomb(s, i - 1, j )) {
		count++;
	}
	if (hasBomb(s, i - 1, j + 1)) {
		count++;
	}
	if (hasBomb(s, i  , j - 1)) {
		count++;
	}
	if (hasBomb(s, i  , j + 1)) {
		count++;
	}
	if (hasBomb(s, i + 1, j - 1)) {
		count++;
	}
	if (hasBomb(s, i + 1, j )) {
		count++;
	}
	if (hasBomb(s, i + 1, j + 1)) {
		count++;
	}
	return count;
}

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; i++) {
		cin >> s.at(i);
	}
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s.at(i).at(j) == '.') {
				s.at(i).at(j) = countBomb(s, i, j) +'0';
			}
		}
	}

	for (int i = 0; i < h; i++) {
		cout << s.at(i)<<endl;
	}

}

Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (sx, sy, tx, ty) = nextIntList()
    val dx = tx - sx
    val dy = ty - sy
    val cx = if (dx > 0) "R" else "L"
    val cy = if (dy > 0) "U" else "D"
    val cxr = if (dx > 0) "L" else "R"
    val cyr = if (dy > 0) "D" else "U"
    print(cx.repeat(dx) + cy.repeat(dy) + cxr.repeat(dx) + cyr.repeat(dy))
    print(cyr + cx.repeat(dx + 1) + cy.repeat(dy + 1) + cxr + cy + cxr.repeat(dx + 1) + cyr.repeat(dy + 1) + cx)
    println()
}


Measured memory_bytes: 37672
# 32bit整数
INT_MAX = 2147483647
UINT_MAX = 4294967295
# 64bit整数
LONGLONG_MAX = 9223372036854775807
ULONGLONG_MAX = 18446744073709551615

class Solver
  def main
    n, k = gets.split.map(&:to_i)

    # 区間（キャンドル本数）固定して全探索
    min_dist = ULONGLONG_MAX
    candles = gets.split.map(&:to_i)
    (k-1).upto(n-1) do |i|
      r_pos = candles[i]
      l_pos = candles[i - (k - 1)]
      r_dist = r_pos.abs
      l_dist = l_pos.abs

      if r_pos <= 0
        # 全部負の位置
        min_dist = l_dist if l_dist < min_dist
      elsif 0 <= l_pos
        # 全部正の位置
        min_dist = r_dist if r_dist < min_dist
      else
        # 0またぎ
        if 0 < r_pos + l_pos
          # 右のほうが遠い
          d = l_dist * 2 + r_dist
        else
          # 左のほうが遠い
          d = r_dist * 2 + l_dist
        end
        min_dist = d if d < min_dist
      end
    end

    puts min_dist
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 8452
# coding: utf-8
# Your code here!
A = list(map(int,input().split()))
N = A[0]
K = A[1]

  
s = list(input())

for i in range(N):
    if i + 1 == K:
        print(s[i].lower(),end = "")
    else:
        print(s[i],end = "")


Measured memory_bytes: 2940
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {

	S := oneInt()
	W := oneInt()
  
  if S - W > 0 {
    fmt.Print("safe")
    return
  }
  fmt.Print("unsafe")
}

func exp(val int) float64 {
	var temp float64
	for index := 1; index <= val; index++ {
		temp += float64(index)
	}
	return temp / float64(val)
}

func searchAbove(slice []int, target int, index int) int {
	for i := index + 1; i < len(slice); i++ {
		v := slice[i]
		if v >= target {
			return i
		}
	}
	return -1
}

var sc = bufio.NewScanner(os.Stdin)

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

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

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
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


Measured memory_bytes: 1760
#include <cstdio>

int main()
{
	int m, n;
	int total = 0, ave = 0, row = 0;
	while(~scanf("%d,%dn", &m, &n)){
		total += m * n;
		ave += n;
		row++;
	}
	printf("%d\n%d\n", total, (int)(ave / (double)row + 0.5));
	return 0;
}

Measured memory_bytes: 0