akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

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

    string t;
    vector<int> idx;
    REP(i, s.size()) {
        if(s[i] != 'x') {
            t += s[i];
            idx.push_back(i);
        }
    }

    REP(i, t.size()/2) {
        if(t[i] != t[t.size()-1-i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    //cout << t.size() << endl;
    //cout << idx[t.size()/2] << " " << idx[t.size() - 1 - t.size()/2] << endl;
    if(t.size() == 0) {
        cout << "0" << endl;
        return 0;
    }
    int kosu = 0;
    int id = 0, id2 = s.size()-1;
    if(t.size()%2 == 1) {
        while(1) {
            if(id == idx[t.size()/2] && id2 == idx[t.size() - 1 - t.size()/2]) break;
            if(s[id] != s[id2]) {
                if(s[id] != 'x') {
                    kosu++, id2--;
                } else if(s[id2] != 'x') {
                    kosu++, id++;
                }
            } else {
                id++, id2--;
            }
        }        
    } else {
        while(1) {
            if(id == idx[t.size()/2 - 1] && id2 == idx[t.size() - t.size()/2]) break;
            if(s[id] != s[id2]) {
                if(s[id] != 'x') {
                    kosu++, id2--;
                } else if(s[id2] != 'x') {
                    kosu++, id++;
                }
            } else {
                id++, id2--;
            }
        }        
    }


    cout << kosu << endl;
    return 0;
}

Measured memory_bytes: 1148
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, K;

  std::cin >> N >> K;

  std::vector<std::pair<int, int>> a(N);

  for (int i = 0; i < N; i ++)
    std::cin >> a[i].second >> a[i].first;

  std::sort(ALL(a));

  long long s = 0, sp = -1;

  std::map<int, std::vector<int>> map;

  for (int i = 0; i < K; i ++) {
    auto pair = a.back();

    a.pop_back();
    
    s += pair.first;

    map[pair.second].push_back(pair.first);
  }

  std::set<int> set;

  for (auto it = map.begin(); it != map.end(); ) {
    set.insert(it->first);
    
    if (it->second.size() == 1) {
      it = map.erase(it);
    }
    else {
      std::sort(ALL(it->second));

      it->second.pop_back();

      ++ it;
    }
  }

  std::vector<int> b;

  for (const auto& kv : map)
    for (const auto& i : kv.second)
      b.push_back(i);

  std::sort(ALL(b));

  long long t = set.size();

  sp = s + t * t;

  std::map<int, int> map2;

  for (const auto& pair : a) {
    if (set.count(pair.second))
      continue;

    if (map.count(pair.second)) {
      if (pair.first > map2[pair.second])
        map2[pair.second] = pair.first;
    }
    else {
      map2[pair.second] = pair.first;
    }
  }

  a.clear();

  for (const auto& kv : map2)
    a.emplace_back(kv.second, kv.first);

  std::sort(ALL(a));

  for (const auto& i : b) {
    if (a.empty())
      break;
    
    auto pair = a.back();

    a.pop_back();
    
    s -= i;
    s += pair.first;

    t ++;

    long long ss = s + t * t;

    if (ss > sp)
      sp = ss;
  }

  std::cout << sp << std::endl;

  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n+1;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
#define stringc(s) string s; cin >> s;
using namespace std;
int main() {
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d;
  e=c/b;
  f=a/d;
  if(c%b>0) e++;
  if(a%d>0) f++;
  string s="Yes";
  if (e>f) s="No";
  cout << s << endl;
}


Measured memory_bytes: 3596
# -*- coding: utf-8 -*-

from functools import reduce

N, M = map(int, input().split())

# 隣接行列
edges = [[False for j in range(N)] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    edges[a-1][b-1] = True
    edges[b-1][a-1] = True
# print(edges)

def DFS(v, N, visited):
    # 全て訪問済みかチェック
    all_visited = True
    for i in range(N):
        if not visited[i]:
            all_visited = False

    if all_visited:
        return 1

    ret = 0

    for i in range(N):
        if not edges[v][i]:
            continue
        if visited[i]:
            continue

        visited[i] = True
        ret += DFS(i, N, visited)
        visited[i] = False

    return ret

visited = [False for i in range(N)]
visited[0] = True
print(DFS(0, N, visited))


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

const int N = 5010, M = 210;
int n, m, w[N][M], l[N], r[N], tot;
ll dis[N], tmp[N], s[N];
struct node { int x, l, r, c; } a[N * M << 1];

inline int read() {
	int s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

inline bool mycmp(node a, node b) { return a.x < b.x; }

int main() {
	n = read(), m = read();
	for(int i = 2; i <= n; ++i)	dis[i] = dis[i - 1] + read();
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			w[i][j] = read();
	for(int j = 1; j <= m; ++j) {
		for(int i = 1; i <= n; ++i) {
			l[i] = i - 1;
			while(l[i] && w[l[i]][j] < w[i][j])	l[i] = l[l[i]];
		}
		for(int i = n; i >= 1; --i) {
			r[i] = i + 1;
			while(r[i] <= n && w[r[i]][j] <= w[i][j])	r[i] = r[r[i]];
		}
		for(int i = 1; i <= n; ++i) {
			a[++tot].x = l[i] + 1; a[tot].l = i;
			a[tot].r = r[i] - 1; a[tot].c = w[i][j];
			a[++tot].x = i + 1; a[tot].l = i;
			a[tot].r = r[i] - 1; a[tot].c = -w[i][j];
		}
	}
	sort(a + 1, a + tot + 1, mycmp);
	ll ans = 0;
	int now = 1;
	for(int i = 1; i <= n; ++i) {
		memset(tmp, 0, sizeof(tmp));
		while(now <= tot && a[now].x == i)	tmp[a[now].l] += a[now].c, tmp[a[now].r + 1] -= a[now].c, ++now;
		for (int j = 1; j <= n; ++j) tmp[j] += tmp[j - 1], s[j] += tmp[j], ans = j < i ? ans : max(ans, s[j] - dis[j] + dis[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 37376
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var s = ReadLine();
            for (int i = 0; i < s.Length; i++)
            {
                if (i % 2 == 0)
                {
                    if (s[i] != 'h')
                    {
                        WriteLine("No");
                        return;
                    }
                }
                else
                {
                    if (s[i] != 'i')
                    {
                        WriteLine("No");
                        return;
                    }
                }
            }
            if (s.Length % 2 == 1) WriteLine("No");
            if (s.Length % 2 == 1) return;
            WriteLine("Yes");
        }

        public class IO
        {
            #region Input
            public static int RInt => int.Parse(ReadLine());
            public static long RLong => long.Parse(ReadLine());
            public static double RDouble => double.Parse(ReadLine());

            public static string[] RSString => ReadLine().Split();
            public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
            public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
            #endregion

            #region Output
            public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
            public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
            public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
            #endregion
        }

        public class Mod
        {
            #region
            private readonly static long M = 1000000007;

            public static long Add(long a, long b) => (a * b) % M;
            public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
            public static long Multi(long a, long b) => (a * b) % M;
            #endregion
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
#define makefast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define comp(x) (lower_bound(vec.begin(), vec.end(), x) - vec.begin())
#define lc (v * 2)
#define rc (v * 2 + 1)
long long M = 1e9 + 7;
//>>>>>>>>>>>>>>>>>>>

const int N = 2e5 + 7;

vector <int> rd[N], bd[N];
int n, x, y;
int h[N], dp[N][20];

void dfs(int v, int p) {
	for (auto u: bd[v])
		if (u != p) {
			dp[u][0] = v;
			h[u] = h[v] + 1;
			dfs(u, v);
		}
}

int lca(int v, int u) {
	if (h[v] < h[u])
		swap(v, u);
	for (int i = 19; i >= 0; i--)
		if (h[v] - (1 << i) >= h[u])
			v = dp[v][i];
	if (v == u)
		return v;
	for (int i = 19; i >= 0; i--)
		if (dp[v][i] != dp[u][i]) {
			v = dp[v][i];
			u = dp[u][i];
		}
	return dp[v][0];
}

int dis(int v, int u) {
	return h[v] + h[u] - 2 * h[lca(v, u)];
}
bool inf[N];
int res = 0;

void get(int v, int t, int p = 0) {
//	cout << "get : " << v << " " << t << endl;
	res = max(res, h[v] * 2);
	if (inf[v]) {
		cout << -1;
		exit(0);	
	}
	for (auto u: rd[v])
		if (h[u] > t + 1 && u != p)
			get(u, t + 1, v);
}

int main() {
	makefast;
	cin >> n >> x >> y;
	for (int i = 1; i < n; i++) {
		int v, u;
		cin >> v >> u;
		rd[v].push_back(u);
		rd[u].push_back(v);
	}
	for (int i = 1; i < n; i++) {
		int v, u;
		cin >> v >> u;
		bd[v].push_back(u);
		bd[u].push_back(v);
	}
	dfs(y, 0);
	for (int j = 1; j < 20; j++)
		for (int i = 1; i <= n; i++)
			dp[i][j] = dp[dp[i][j - 1]][j - 1];
	for (int v = 1; v <= n; v++)
		for (auto u: rd[v]) {
			if (dis(u, v) > 2) {
				inf[v] = inf[u] = 1;
			}	
		}
/*	for (int i = 1; i <= n; i++)
		if (inf[i])
			cout << "inf : " << i << endl;*/
	get(x, 0);
	cout << res;

	return 0;
}


Measured memory_bytes: 53016
#include<stdio.h>
int main(){
  int x,y;
  do{
    scanf("%d %d",&x,&y);
    if(x == 0 && y == 0)
      break;
    if(x <= y){
      printf("%d %d\n",x,y);
    }
    if(y < x){
      printf("%d %d\n",y,x);
    }
  }while(0 <= x,y <=10000);
  return 0;
}

Measured memory_bytes: 600
import Data.List( sort, group)
primes = 2:f [3] [3,5..]
 where f (x:xs) ys =	let
			    (ps, qs) = span (< x*x) ys
			in
			    ps ++ f (xs++ps) [z | z<-qs, z`mod`x/=0]

rpf n = let ps = takeWhile ((<=n).(^2)) primes
	in  if n==1 then [1] else go n ps
    where
	go 1 _	= []
	go i []	= [i]
	go i pp@(p:ps) = case i`divMod`p of
			(d,0)	-> p:go d pp
			_	-> go i ps 

main = do
    n_ <- readLn::IO Int
    print $ let
		ps = concatMap rpf [n_, n_-1..2]
		v=product $ map (toInteger . (+1) . length) $
				    group . sort $ ps
	    in	
		v `mod` 1000000007

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

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

int main()
{
        long long n, m;
        cin >> n >> m;
        string s1, s2;
        cin >> s1 >> s2;
        long long lcm = (n * m) / gcd(n, m);
        map<long long, char> mp;
        int z = lcm / n;
        for(int i = 0; i < s1.length(); i++)
                mp[i * z] = s1[i];
        z = lcm / m;
        for(int i = 0; i < s2.length(); i++) {
                if(mp.find(i * z) == mp.end() || mp[i * z] == s2[i]) 
                        mp[i * z] = s2[i];
                else {
                        cout << "-1";
                        return 0;
                }
        }
        cout << lcm;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << ' ' << max(0LL, -(N - A - B)) << endl;
    return 0;
}


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

using namespace std;

int main() {
    int N; cin >> N;
    int cnt = 0;
    vector<int> data(N);

    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }

    for (int i = 1; i < N-1; i++) {
        
        if ((data.at(i-1) < data.at(i) && data.at(i) < data.at(i+1)) || (data.at(i-1) > data.at(i) && data.at(i) > data.at(i+1)))  {
            cnt++;
        }
    }
    
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
def gcd(a,b):
    if b % a == 0:
        return a
    else:
        return gcd(b % a,a)
        
ans = 0
k = int(input())
for l in range(1,k+1):
    for m in range(l,k+1):
        for n in range(m,k+1):
            if(l == m and m==n):
                ans += gcd(l,gcd(m,n))
            elif(l == m or m ==n):
                ans += gcd(l,gcd(m,n)) * 3
            else:
                ans += gcd(l,gcd(m,n)) * 6

print(ans)

Measured memory_bytes: 9204
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 1> { using type = vector<T>; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N;
  ll M;
  while (cin >> N >> M) {
    map<ll, ll> mp;
    mp[0] = 1;
    ll S = 0;
    for (int i = 0; i < N; i++) {
      ll A;
      cin >> A;
      S = (S + A) % M;
      ++mp[S];
    }
    ll res = 0;
    for (auto& e : mp) res += e.snd * (e.snd - 1) / 2;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n;
pair<string,int> a[105];
map<pair<string,int>,int> mp;
bool cmp(pair<string,int> a,pair<string,int> b)
{
	if(a.first!=b.first)
		return a.first<b.first;
	else
		return a.second>b.second;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i].first>>a[i].second,mp[a[i]]=i;
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
		cout<<mp[a[i]]<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> L;
  tools::read(L, 2 * N);

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

  i64 answer = 0;
  for (i64 i = 0; i < 2 * N; i += 2) {
    answer += L[i];
  }
  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 256
import heapq as hq

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
BC = [tuple(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)

hq.heapify(A)
for b, c in BC:
    for i in range(b):
        a = hq.heappop(A)
        if a < c:
            hq.heappush(A, c)
        else:
            hq.heappush(A, a)
            break

print(sum(A))

Measured memory_bytes: 22520
import bisect
import sys

n,k = map(int,input().split())
x = list(map(int,input().split()))

index = bisect.bisect_left(x,0)

if x[0] >= 0 :
  print(x[k-1])
  sys.exit()
  
if x[-1] <= 0 :
  print(x[n-k]*(-1))
  sys.exit()

ans = 10**9
if min(index+k,n) == index+k :
  ans = x[index+k-1]

if max(0,index-k) == index - k :
  ans = min(ans,x[index-k]*(-1))
  
c = 0
for i in range(index,min(index+k,n)) :
  c += 1
  if i <= n-1 and i-(k-1) <= n-1 and i-(k-1) >= 0 :
    ans = min(ans,x[i]*2+x[i-(k-1)]*(-1))

c = 0
for i in range(max(0,index-k),index) :
  c += 1
  if i <= n-1 and i+(k-1) <= n-1 :
    ans = min(ans,x[i]*(-1)*2+x[i+(k-1)])
  
print(ans)

Measured memory_bytes: 62576
import math
n = int(input())
x = []
y = []
for i in range(n):
    x1,y1 = map(int, input().split())
    x.append(x1)
    y.append(y1)
tankyori = 0
for j in range(n-1):
    for k in range(j,n):
        tankyori += math.sqrt((x[j] - x[k])**2 + (y[j]- y[k])**2)
print(tankyori*2/n)


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

int main(){
    int x, y;
    
    while(true){
        cin >> x >> y;
        if(x == 0 && y == 0) break;
        
        if(x > y) swap(x, y);
        printf("%d %d\n", x, y);        
    }
    
    return 0;
}

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

using namespace std;

typedef long long LL;

const int N = 110;
char s[N];

int main() {
    int n;
    scanf("%d%s", &n, s);
    int ans, x;
    ans = x = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import itertools
import numpy as np
import fractions
from itertools import combinations
from functools import reduce
from functools import lru_cache
import math
from collections import deque
import decimal
import bisect
import heapq
# ---*- start -*--- #
import math
import sys
sys.setrecursionlimit(10**9)



def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def solve(N,X,T):
    print(T*math.ceil(N/X))
    return

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
    X = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, X, T)



if __name__ == "__main__":
    main()


Measured memory_bytes: 27268
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,C,X;
    cin >> A >> B >> C >> X;
    ll ans = 0;
    rep(i,0,A+1){
        rep(j,0,B+1){
            rep(k,0,C+1){
                if(i*500+j*100+k*50 == X) ans++;
            }
        }
    }
    print(ans);

}

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

#define ll long long

const int mxN=300, M=1e9+7;
int n, c[3];
//ll iv[mxN+1], dp[mxN+1][mxN+1][mxN+1];
long double dp[mxN+1][mxN+1][mxN+1];

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

	cin >> n;
	for(int i=0; i<n; ++i) {
		int ai;
		cin >> ai;
		++c[ai-1];
	}
	for(int k=0; k<=c[2]; ++k) {
		for(int j=0; j<=n; ++j) {
			for(int i=0; i<=n; ++i) {
				int tc=i+j+k;
				if(!tc||tc>n)
					continue;
				dp[i][j][k]=1;
				if(i)
					dp[i][j][k]+=dp[i-1][j][k]*i/n;
				if(j)
					dp[i][j][k]+=dp[i+1][j-1][k]*j/n;
				if(k)
					dp[i][j][k]+=dp[i][j+1][k-1]*k/n;
				dp[i][j][k]*=(long double)n/tc;
			}
		}
	}
	cout << fixed << setprecision(16) <<  dp[c[0]][c[1]][c[2]];
}


Measured memory_bytes: 426240
from collections import deque
H,W,K = list(map(int, input().split()))
A = [[0] * W for _ in range(H)]
n = 1
P = []
B = []
for i in range(H):
    B.append(input())

for i in range(H):
    for j in range(W):
        if B[i][j] == "#":
            A[i][j] = n
            n += 1
            P.append([i,j])
def change(A,x,y,z):
    if y-1 >= 0:
        if A[x][y-1] == 0:
            A[x][y-1] = z
            change(A,x,y-1,z)
    if y + 1 <= (W-1):
        if A[x][y+1] == 0:
            A[x][y+1] = z
            change(A,x,y+1,z)
for i in P:
    change(A,i[0],i[1],A[i[0]][i[1]])
next_ = []
next_ = deque(next_)
for k in range(H):
    if 0 in A[k]:
        next_.append(k)
while len(next_) > 0:
    l = next_.popleft()
    if l == H-1:
        A[l] = A[l-1]
        if 0 in A[l]:
            next_.append(l)
    elif l == 0:
        A[l] = A[l+1]
        if 0 in A[l]:
            next_.append(l)
    else:
        if l+1 in next_ and l - 1 in next_:
            next_.append(l)
        elif l + 1 not in next_:
            A[l] = A[l + 1]
        else:
            A[l] = A[l - 1]
for w in range(H):
    print(*A[w])


Measured memory_bytes: 77656
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define For(i,a,b) for(i=(a);i<=(b);++i)
#define Forward(i,a,b) for(i=(a);i>=(b);--i)
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
#define Max(a,b) a>b?a:b
#define Min(a,b) a<b?a:b

using namespace std;
template<typename T>inline void read(T &x)
{
	T s=0,f=1;static char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())s=s*10+(c^48);
	x=s*f;
}
const int MAXN=2e5+7;

static int n,fa[MAXN],w[MAXN];

inline void init()
{
	read(n);
	Rep(i,2,n)read(fa[i]);
	Rep(i,1,n)read(w[i]);
}

static long long ans;

static int F[MAXN],one[MAXN],zer[MAXN];

inline int find(int x){return x==F[x]?x:F[x]=find(F[x]);}

struct node
{
	int pos;
	friend bool operator<(node a,node b)
	{
		return (long long)one[a.pos]*zer[b.pos]>(long long)one[b.pos]*zer[a.pos];
	}
};

__gnu_pbds::priority_queue<node>G;
__gnu_pbds::priority_queue<node>::point_iterator rts[MAXN];

inline void solve()
{
	Rep(i,1,n)rts[i]=G.push((node){i}),one[i]=(w[i]==1),zer[i]=(w[i]==0),F[i]=i;
	static int u,rt;
	while(!G.empty())
	{
		u=G.top().pos;
		G.pop();
		F[u]=rt=find(fa[u]);
		ans+=(long long)one[rt]*zer[u];
		one[rt]+=one[u];zer[rt]+=zer[u];
		if(rt)G.modify(rts[rt],(node){rt});
	}
	printf("%lld\n",ans);
}

int main()
{
	init();
	solve();
	return 0;
}



Measured memory_bytes: 15104
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

  
        signed main() {
     int h,w;
     cin>>h>>w;
     if(h==1||w==1)cout<<1;
    else  cout<<((h+1)/2)*((w+1)/2)+(h/2)*(w/2);
   
     
     
    

      
        


      }


        


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

#define M 100001

struct Node
{
  char mark;
  int num;
  int s;
};

int partition(struct Node *A, int n, int m)
{
  int i, j, a;
  struct Node tmp;
  a = A[m].num;
  i = n - 1;
  for(j = n; j <= m - 1;j++)
    {
      if(A[j].num <= a)
	{
	  i = i + 1;
	  tmp = A[i];
	  A[i] = A[j];
	  A[j] = tmp;
	}
    }
  tmp = A[i+1];
  A[i+1] = A[m];
  A[m] = tmp;
  return i+1;
}

void quicksort(struct Node *A, int n, int m)
{
  int a;
  if(n < m)
    {
      a = partition(A, n, m);
      quicksort(A, n, a-1);
      quicksort(A, a+1, m);
    }
}

int main()
{
  int n, i, f = 0;
  struct Node A[M];
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf(" %c%d", &A[i].mark, &A[i].num);
      A[i].s = i;
    }
  quicksort(A, 0, n-1);

  for(i = 0; i < n; i++)
    {
      if(A[i].num == A[i+1].num)
	{
	  if(A[i].s > A[i+1].s)
	    {
	      f = 1;
	    }
	}
    }
  if(f == 0)
    {
      printf("Stable\n");
    }
  else
    {
      printf("Not stable\n");
    }
  for(i = 0; i < n; i++)
    {
      printf("%c %d\n", A[i].mark, A[i].num);
    }
  return 0;
}



Measured memory_bytes: 2976
#include <vector>
#include <iostream>
#include <cmath>
#include <climits>

using namespace std;
using ll = long long;

ll solve(vector<ll>& v, int first) {
    ll cost = abs(first - v[0]);
    ll sum =  first;

    for (int i = 1; i < v.size(); ++i) {
        ll after = sum + v[i];
        if (after * sum < 0) {
            sum = after;
        } else {
            cost += abs(after) + 1;
            sum = sum > 0 ? -1 : 1;
        }
    }

    return cost;
}

int main() {
    int N;
    cin >> N;
    vector<ll> v(N);
    for (int i = 0; i < N; i++) cin >> v[i];

    ll ret = LONG_MAX;
    if (v[0] == 0) {
        ret = min(ret, solve(v, 1));
        ret = min(ret, solve(v, -1));
    } else {
        ret = min(ret, solve(v, v[0]));
        ret = min(ret, solve(v, v[0] > 0 ? -1 : 1));
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1024
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      a: usize,
      x: [usize; n]
   }
   let mut ps = vec![];
   let mut mn = vec![];
   let mut zero = 0;
   for x in x {
      if x > a {
         ps.push(x - a);
      } else if x < a {
         mn.push(a - x);
      } else {
         zero += 1;
      }
   }

   let mut dp1 = vec![0; 2501];
   let mut dp2 = vec![0; 2501];
   dp1[0] = 1;
   dp2[0] = 1;
   for i in 0..ps.len() {
      for j in (0..2500 - ps[i]).rev() {
         dp1[j + ps[i]] += dp1[j];
      }
   }
   for i in 0..mn.len() {
      for j in (0..2500 - mn[i]).rev() {
         dp2[j + mn[i]] += dp2[j];
      }
   }
   let mut ans: usize = 0;
   for i in 1..std::cmp::min(dp1.len(), dp2.len()) {
      ans += dp1[i] * dp2[i];
   }
   ans *= 1 << zero;
   ans += (1 << zero) - 1;
   println!("{}", ans);
}


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

int main() {
	// your code goes here
	int card[2][200];
	int n, m, k;
	
	cin >> n >> m;
	for(int i=0; i<2*n; i++){
		card[0][i] = i+1;
		card[1][i] = i+1;
	}
	
	for(int i=1; i<m+1; i++){
		cin >> k;
		if(k==0){
			for(int j=0; j<n; j++){
				card[i%2][2*j] = card[(i+1)%2][j];
				card[i%2][2*j+1] = card[(i+1)%2][n+j];
			}
		}
		else{
			for(int j=0; j<2*n; j++){
				card[i%2][j] = card[(i+1)%2][(j+k)%(2*n)];
			}
		}
	}
	
	for(int i=0; i<2*n; i++){
		cout << card[m%2][i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i, n) for (int i = 0; i < (n); ++i)

template<typename T>
T powint (const T& x, const T& y) {
  T ret = 1;
  for(int i=0; i<y; ++i) ret *= x;
  return ret;
}

ll factorial(ll X) {
  ll ans = 1;
  for(int i=1; i<X+1 ; ++i) ans *= i;
  return ans;
}

int main() {
  int N, K;
  cin >> N >> K;   
  int R, S, P;
  cin >> R >> S >> P;
  unordered_map<char, int> list;
  list.emplace('r', P);
  list.emplace('s', R);
  list.emplace('p', S);
  string T;
  cin >> T;

  ll score = 0;
  rep(i, N) {
    if (T[i] == 'r') score += P;
    if (T[i] == 's') score += R;
    if (T[i] == 'p') score += S;
  }

  for(int i = 0; i < N - K; ++i) {
    if(T[i] == T[i+K]) { 
      T[i+K] = 'x';
      score -= list[T[i]];
    }
  }
  cout << score << endl;
  return 0;
}

Measured memory_bytes: 512
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)


int main() {
    ll N,M;
    cin >> N >> M;
    vector<ll> a(M),b(M);
    rep(i,M){
        cin >> a[i] >> b[i];
    }

    vector<ll> ans(N,0);
    rep(i,M){
        ans[a[i]-1]++;
        ans[b[i]-1]++;
    }

    rep(i,N){
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 3628
#!/usr/bin/env pypy3 submit
import sys
from collections import deque
from itertools import *
 
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
 
x = LS()
 
for i,xx in enumerate(x):
    if xx == '0':
        print(i+1)
        exit() 

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

int main(){

    string N;
    cin >> N;
    int i = 0;
    int x,y;
  
    for(i=0; i<N.size(); i++){
      if(N[i]=='A'){
        x = i;
        break;
      }
    }

    for(i=x; i<N.size(); i++){
      if(N[i]=='Z'){
        y = i;
      }
    }
  
    cout << y-x+1 << endl;
}

Measured memory_bytes: 3756
n,m=map(int,input().split())
a=set()
dp=[0]*(n+1)
mo=10**9+7
for i in range(m):
    a.add(int(input()))

for i in range(n+1):
    if i==0:
        dp[i]=1
    elif i==1:
        if 1 not in a:
            dp[i]=1
    elif i not in a:
        dp[i]=dp[i-1]+dp[i-2]
        dp[i]%=mo
        

print(dp[n]%mo)


Measured memory_bytes: 50904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, vector<long long> T, vector<long long> A){
	rep(i, N-1) {
		ll b = max((T[i]-1)/T[i+1]+1, (A[i]-1)/A[i+1]+1);
		T[i+1] *= b;
		A[i+1] *= b; 
	}
	cout << T[N-1]+A[N-1] << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> T(N-1+1);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&T[i]);
		scanf("%lld",&A[i]);
	}
	solve(N, T, A);
	return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

def dfs(G, F, crr, pre, ret, st):
    F[crr] = False
    if crr < 10**5:
        ret[0] += 1
    else:
        ret[1] += 1
    for nxt in G[crr]:
        if nxt == pre:
            continue
        p, q = crr, nxt
        if q < p:
            p, q = q, p
        if not (p, q) in st:
            st.add((p, q))
            ret[2] += 1
        if F[nxt]:
            dfs(G, F, nxt, crr, ret, st)

def main():
    n = int(input())
    G = [[] for _ in range(2 * 10**5)]
    for _ in range(n):
        x, y = map(int, input().split())
        x, y = x-1, y-1 + 10**5
        G[x].append(y)
        G[y].append(x)
    F = [True]*(2* 10**5)
    ans = 0
    st = set()
    for i in range(2 * 10**5):
        if F[i] and len(G[i]) > 0:
            tmp = [0]*3
            dfs(G, F, i, -1, tmp, st)
            ans += tmp[0] * tmp[1] - tmp[2]
    print(ans)

if __name__ == "__main__":
    main()

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


    

int main(){
    int k;
    string s;
    cin >> k;
    cin >>s;
    if(s.length() <= k){
        cout << s <<endl;
    }
    else{
        cout << s.erase(k) << "..."<<endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
using namespace std;
int vx[4]={0,1,0,-1};
int vy[4]={1,0,-1,0};
bool map[30][30];
int get;
int N;
int M;
int x,y;

void init(){
	for(int i=0;i<30;i++){
		for(int j=0;j<30;j++){
			map[i][j]=0;
		}
	}
	N=M=get=0;
	y=x=10;
}

int vec(char c){
	if(c=='N'){
		return 0;
	}else if(c=='E'){
		return 1;
	}else if(c=='S'){
		return 2;
	}else{
		return 3;
	}
}

void solve(int v,int d){
	for(int i=0;i<d;i++){
		x+=vx[v];
		y+=vy[v];
		if(map[x][y]){
			map[x][y]=0;
			get++;
		}
	}
}



int main(){
	init();
	while(cin>>N,N!=0){
		//cout<<N<<endl;
		for(int i=0;i<N;i++){
			int a,b;
			cin>>a>>b;
			//cout<<a<<" "<<b<<" pos"<<endl;
			map[a][b]=1;
		}
		cin>>M;
		//cout<<M<<endl;
		//cout<<endl;
		for(int i=0;i<M;i++){
			char c;
			int d;
			scanf(" %c %d",&c,&d);
			//cout<<c<<endl;
			solve(vec(c),d);
		}
		
		if(get==N){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
		init();
	}
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int dp [10100][1100];
int main(){
  ll n;
  cin>>n;
  if(n%2!=0){
    cout<<0<<endl;
    return 0;
  }
  ll ans =0;
  ll mo = 10;
  while(mo<=n){
    ans+=n/mo;
    mo*=5;
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
while 1:
	H , W = map(int , raw_input().split())
	if H == 0 and W == 0:
		break
	print "#" * W
	for h in range(0,H-2):
		s = "#"
		for l in range(0,W-2):
			s += "."
		s += "#"
		print s

	print "#" * W
	print 

Measured memory_bytes: 4204
n,m,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.append(X)
y.append(Y)
x = max(x)
y = min(y)
if x >= y:
  print('War')
else:
  print('No War')

Measured memory_bytes: 38384
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define rev reverse
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define endl '\n'
#define ull unsigned long long
#define sz(x) (int)x.size()

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll inf = 1e9+7;
const ll N = 1e5+1;
const ll mod = 1e9+7;
const ll P = 31;

int main() {
//    freopen("floor4.in", "r", stdin);
//    freopen("floor4.out", "w", stdout);
    IOS
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main() {
    long int n, ans;cin>>n;
    ans= 1000 * (n/500);
    n %= 500;
    ans += 5 * (n/5);
    cout<<ans<<endl;



    return 0;
}


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

int main() {
    ios::sync_with_stdio(0);                                                                                                                               
    cin.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    ll res = 0;
    ll x = min(a, k);
    k -= x;
    res += x;
    x = min(b, k);
    k -= x;
    x = min(c, k);
    k -= x;
    res -= x;
    cout << res << '\n';
    return 0;   
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int N, K; cin >> N >> K;
    ll ans = 0;
    
    rep1(b,N+1) {
        int p = N / b;
        int r = N % b;
        if(K ==  0) ans += p * max(0, b - K) + max(0, r - K + 1) - 1;
        else ans += p * max(0, b - K) + max(0, r - K + 1);
        
    }
    cout << ans <<  endl;
    return 0;
}

Measured memory_bytes: 256
// <------------- Template -----------------------> //


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(2);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 
 
typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAX5]; ll visit[] = {};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, y, q, m;
string s, t, d;
ll sum = 0;
ll cou = 0;


// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> m >> x;
	vll a(n+1);
	for(ll i=0;i<m;i++) {
		cin >> y;
		a[y]=1;
	}
	ll cou1=0, cou2=0;
	for(ll i=x;i>=0;i--) cou1+=a[i];
	for(ll i=x;i<=n;i++) cou2+=a[i];
	cout<<min(cou1,cou2);
}

int main() {
	fastio; randomINT;
	//cin>>T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 5996
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    while(true){
        int n,m;
        int a[10000];
        cin>>n>>m;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int ans=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(a[i]+a[j]<=m){
                    if(i==j)continue;
                    ans = max(ans,a[i]+a[j]);
                }
            }
        }
        if(ans==0)cout<<"NONE"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;

const int MAXN=110000;
const int OO = INT_MAX;
int N;
int A[MAXN][3];
int sol[MAXN][3];
int main(){
	cin>>N;
	for(int i=0;i<N;i++)
		for(int j=0;j<3;j++){
			cin>>A[i][j];
			sol[i][j]=A[i][j];
		}
	for(int i=1;i<N;i++)
		for(int j=0;j<3;j++)
			sol[i][j] += max(sol[i-1][(j+1)%3],sol[i-1][(j+2)%3]);
	cout<<max(sol[N-1][0],max(sol[N-1][1],sol[N-1][2]));
}

Measured memory_bytes: 2560
//header file
#include <assert.h>
#include <complex.h>
#include <ctype.h>
#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <inttypes.h>
#include <iso646.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tgmath.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>

//type
typedef unsigned long long int uint64_g;
typedef long long int int64_g;
typedef unsigned long int uint32_g;
typedef long int int32_g;
typedef uint_fast64_t uint64;
typedef int_fast64_t int64;
typedef uint_fast32_t uint32;
typedef int_fast32_t int32;

//macro
#define PI M_PI
#define MOD 1000000007

//array
typedef struct {
    struct vectoruint64 *_prev_;
    uint64_g value;
    struct vectoruint64 *_next_;
    uint64_g _indices_;
} vectorUint64;

//print
void print_llu(uint64_g v) { printf("%llu\n", v); }

void print_lu(uint32_g v) { printf("%lu\n", v); }

void print_lli(int64_g v) { printf("%lld\n", v); }

void print_li(int32_g v) { printf("%ld\n", v); }

void print_string(char *v) { printf("%s\n", v); }

void print_int(int v) { printf("%d\n", v); }

void print_double(double v) { printf("%lf\n", v); }

#define print(v) _Generic((v)   \
    , uint64_g : print_llu      \
    , uint32_g : print_lu       \
    , int64_g  : print_lli      \
    , int32_g  : print_li       \
    , char *   : print_string   \
    , int      : print_int      \
    , double   : print_double   \
    , default  : print_double   \
)(v);

//gcd


//temp function


int main(int argc, char *argv[]) {
    char string[1010];
    char character = '\0';
    uint64 i = 0;
    scanf("%s", string);
    while (true){
        if(string[i] == '\0') break;
        character = string[i];
        i++;
    }
    if (character != 's'){
        string[i]='s';
        string[i+1]='\0';
    }else{
        string[i]='e';
        string[i+1]='s';
        string[i+2]='\0';
    }
    print(string)
    return 0;
}

Measured memory_bytes: 1656