akhauriyash/Code-Regression huggingface dataset:
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	ll n; cin >> n;
	ll a[5]; cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
	ll mi = min({ a[0],a[1],a[2],a[3],a[4] });
	cout << (n + mi - 1) / mi + 4 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int ans = 0, m, d;
	cin >> m >> d;
	int dO, dT;

	for (int i = 2; i <= m; i++) {
		for (int j = 22; j <= d; j++) {
			dO = j % 10;
			dT = j / 10;
			if (dO >= 2 && dT >= 2 && dO*dT == i) {
				ans++;
			}
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
B=[]
flag=False
for y in range(H):
  if y%2==0:
    w=range(W)
  else:
    w=reversed(range(W))
  for x in w:
    if flag:
      B.append([by+1,bx+1,y+1,x+1])
    if A[y][x]%2==1:
      flag=not flag
    by=y
    bx=x
print(len(B))
for a,b,c,d in B:
  print(a,b,c,d)

Measured memory_bytes: 30324
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<double > a(n);
    for (int i = 0; i<n; i++){
        cin >> a[i];
    }

    double res = 0;
    for (double d : a){
        res += (1/d);
    }
    cout << fixed;
    cout << setprecision(6) <<  1/res << endl;
    
    return 0;
}


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

struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
  }
  int top() {
    return s[0];
  }
};

int side(int s,int s1,int s2,int s4,int s3){
    if(s1==s)return s2;
    else if(s2==s)return s4;
    else if(s4==s)return s3;
    else if(s3==s)return s1;
    return 0;
}

int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  int n,q[2];
  cin>>n;
  bool skip;
  
  for(int i=0;i<n;i++){
      skip=false;
      cin>>q[0]>>q[1];
      if(d.s[0]==q[0]){
          cout<<side(q[1],d.s[1],d.s[2],d.s[4],d.s[3])<<endl;
          continue;
      }
      for(int i=0;i<3;i++){
        d.roll('E');
        if(d.s[0]==q[0]){
          cout<<side(q[1],d.s[1],d.s[2],d.s[4],d.s[3])<<endl;
          skip=true;
          break;
        }
      }
    if(!skip){
          for(int i=0;i<3;i++){
        d.roll('N');
        if(d.s[0]==q[0]){
          cout<<side(q[1],d.s[1],d.s[2],d.s[4],d.s[3])<<endl;
          break;
    }
    
  }
    }
      }
  
  return 0;
}




Measured memory_bytes: 3072
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
#import numpy as np
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())

S = str(input())
Q = int(input())
#query = [["" for _ in range(3)] for _ in range(Q)]

sl = [] #先頭リスト
el = [] #末尾リスト
f = True #反転正負
for _ in range(Q) :
  stmp = input().split()
  #print (stmp)
  
  if stmp[0] == "1" :
    f = not f
    tl = sl
    sl = el
    el = tl
    
  else :
    if stmp[1] == '1' :
      sl.append(stmp[2])
    else :
      el.append(stmp[2])

ans = ""
for i in range(len(sl)-1, -1, -1) :
  ans += sl[i]
if f :
  ans += S
else :
  ans += S[::-1]
for i in range(len(el)) :
  ans += el[i]
  
print (ans)
  
  
  

Measured memory_bytes: 6200
# frozen_string_literal: true

h, w, k = gets.split.map(&:to_i)

dp = Array.new(h + 1).map { Array.new(w + 1, 0) }
fib = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 0, 0, 0]
dp[0][0] = 1

0.upto(h - 1) do |i|
  0.upto(w - 1) do |j|
    dp[i + 1][j] = dp[i][j] * [fib[j - 1], 1].max * [fib[w - j - 2], 1].max +
      dp[i][j - 1] * ([fib[j - 2], 1].max * [fib[w - j - 2], 1].max) +
      dp[i][j + 1] * [fib[j - 1], 1].max * [fib[w - j - 3], 1].max
  end
end

puts dp[h][k - 1] % 1_000_000_007


Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
#include <sstream>
using namespace std;
const constexpr int INF = 1e9;
#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
struct Less{
   bool operator()(const pair<string, int>&a, const pair<string, int>&b){
        if(a.first==b.first){
            return a.second < b.second;
        }
       return a.first < b.first;
    }
};

ll extGCD(ll a, ll b, ll& x, ll& y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}
ll GCD(ll a, ll b){
    if(a<b) swap(a, b);
    if(b==0) return a;
    return GCD(b, a%b);
}
int par[100010], rr[100010];
void init(){
    for(int i=0; i<100010; ++i){
        par[i]=i;
        rr[i]=0;
    }
}
int root(int x){
    return par[x] == x ? x:par[x] = root(par[x]);
}
bool same(int x, int y){
    return root(x)==root(y);
}
void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x==y) return ;
    
    if(rr[x]<rr[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(rr[x]==rr[y]) rr[x]++;
    }
}

ll pow_mod(ll x, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res*x%MOD;
        }
        x = x*x%MOD;
        n>>=1;
    }
    return res;
}
int t[200010];
int main() {
    ll N, T; cin >> N >> T;
    REP(i, N) cin >> t[i];
    int te=0;
    ll ans=0;
    for(int i=1; i<N; ++i){
        if(te+T>t[i]){
            ans += (t[i]-t[i-1]);
        }else{
            ans += T;
        }
        te = t[i];
    }
    ans += T;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
<?php
  const DIRS = "RDLU";
  $h[] = "000000";
  $v[] = "0000000";
  for($i=0;$i<4;$i++) {
      $h[] = "0".trim(fgets(STDIN))."0";
      $v[] = "0".trim(fgets(STDIN))."0";
  }
  $h[] = "0".trim(fgets(STDIN))."0";
  $v[] = $v[0];
  $h[] = $h[0];

  $p = array(2,1,0);
  $path = array('R');
  $stepx =  array(1,0,-1,0);
  $stepy = array(0,1,0,-1);

  function check($x,$y,$j,$v,$h) {
    return ($j==0 && $v[$y-1][$x]) || ($j==1 && $h[$y][$x]) ||
      ($j==2 && $v[$y][$x]) || ($j==3 && $h[$y][$x-1]);
  }

  while(!($p[0]==1 && $p[1]==1)) {
    for($i=0;$i<4;$i++) {
      $d = ($p[2]+$i)%4;
      if(check($p[0],$p[1],$d,$v,$h)==1) {
        $p[0] += $stepx[($d+3)%4];
        $p[1] += $stepy[($d+3)%4];
        $p[2] = ($d+3)%4;
        break;
      }
    }
    $path[] = DIRS[$p[2]];
  }

  echo implode('',$path).PHP_EOL;

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

int main(){
    int N;
    cin>>N;
    for(int i=0; i<N; i++){
        string S;
        cin>>S;
        set<string> data;

        for(int j=1; j<S.size(); j++){
            string A="",B="";
            string cpa,cpb;
            for(int k=0; k<j; k++){
                A += S[k];
            }
            for(int k=j; k<S.size(); k++){
                B += S[k];
            }

            cpa = A;
            cpb = B;

            data.insert(A+B);
            data.insert(B+A);
            reverse(A.begin(),A.end());
            data.insert(A+B);
            data.insert(B+A);
            reverse(B.begin(),B.end());
            data.insert(A+B);
            data.insert(B+A);
            data.insert(B+cpa);
            data.insert(cpa+B);
        }             

        cout<<data.size()<<endl;  
    }

    return 0;
}


Measured memory_bytes: 3288
import java.io.*;
import java.util.*;

public class Main {
    private static final int MOD = 1000000007;

    private long pow(long a, int n) {
        long ret = 1;
        long base = a;
        while (n > 0) {
            if ((n & 1) > 0) {
                ret = (ret * base) % MOD;
            }
            n >>= 1;
            base = (base * base) % MOD;
        }
        return ret;
    }

    private void solve() {
        int N = sc.nextInt();
        int K = sc.nextInt();

        long ans = 0;
        long cnt = 0;
        long[] fn = new long[K + 1];
        for (int i = K; i > 1; --i) {
            long v = K / i;
            v = (pow(v, N) - fn[i] + MOD) % MOD;
            int j = 2;
            while ((long)j * j <= i) {
                if (i % j == 0) {
                    fn[j] = (fn[j] + v) % MOD;
                    int k = i / j;
                    if (k != j && k != i) {
                        fn[k] = (fn[k] + v) % MOD;
                    }
                }
                ++j;
            }
            cnt = (cnt + v) % MOD;
            ans = (ans + (v * i)) % MOD;
        }
        ans = (ans + (pow(K, N) - cnt + MOD) % MOD) % MOD;
        out.println(ans);
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}


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

int main(){
    int N,H[20];
    cin>>N;
    for(int i=0; i<N; i++){
        cin>>H[i];
    }

    int height=0;
    int number_buildings_can_see_sea=0;
    for(int i=0; i<N; i++){
        if(height<=H[i]){
            number_buildings_can_see_sea += 1;
            height=H[i];
        }
    }
    cout<<number_buildings_can_see_sea<<endl;
}

Measured memory_bytes: 256
from collections import deque
from itertools import product

H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x)-1, input().split())
Dh, Dw = map(lambda x: int(x)-1, input().split())
maze = [list(input()) for _ in range(H)]
walkFrom = deque([(Ch, Cw)]) # 歩く出発地点の候補集
warpFrom = deque() # ワープ出発地点の候補集
WalkRange = [(1, 0), (-1, 0), (0, 1), (0, -1)]
WarpRange = list(filter(lambda x: x != (0, 0), product(range(-2, 3), repeat=2)))
warpCount = 0

def move(h_from, w_from, moveRange):
  for h, w in moveRange:
    h_to, w_to = h_from + h, w_from + w
    if 0 <= h_to < H and 0 <= w_to < W and maze[h_to][w_to] == '.':
      maze[h_to][w_to] = warpCount
      walkFrom.append((h_to, w_to))


while walkFrom:
  # 歩ける範囲をすべて歩く
  while walkFrom:
    h, w = walkFrom.popleft()
    warpFrom.append((h, w))
    move(h, w, WalkRange)
  # ワープする
  warpCount += 1
  while warpFrom:
    h, w = warpFrom.popleft()
    move(h, w, WarpRange)

goal = maze[Dh][Dw]
print(goal) if not goal in ['.', '#'] else print('-1')


Measured memory_bytes: 176368
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main( void )
{
    long long N, M;
    cin >> N >> M;

    int left = 1;
    int right = N;
    for(int i=0;i<M;i++){
        int tmpL, tmpR;
        cin >> tmpL >> tmpR;
        if(tmpL > left){
            left = tmpL;
        }
        if(tmpR < right){
            right = tmpR;
        }
    }

    if(right >= left){
        cout << right - (left - 1) << "\n";
    }else{
        cout << 0 << "\n";
    }

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
#define endl             "\n"
// -----------------<Container manipulation / traversal macros>------------------
#define mp                 make_pair
#define pb                 push_back
#define ff                 first
#define ss                 second
#define sz(x)             ((int)((x).size()))
#define all(x)             (x).begin(),(x).end()
#define rep(i,n)         for(ll (i)=0;(i)<(n);(i)++)
#define forn(i,a,b)     for(ll (i)=(a);(i)<=(b);(i)++)
#define fill(l,a)        memset((l) , (a) , sizeof(l))
// -----------------<Some common useful functions>------------------
#define maX(a,b)        ( (a) > (b) ? (a) : (b))
#define miN(a,b)        ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)   ( (n >> b) & 1)
#define INDEX(arr,i)      ( lower_bound(all(arr),i)-arr.begin())
#define in(b,a)         ( (b).find(a) != (b).end())
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector< std::vector<ll> > matrix;
typedef map<ll,ll> mii;
typedef vector<pii> vpii;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
ll lcm(ll a,ll b)
{
    return(a/gcd(a,b)*b);
}
/*ll power(ll a,ll b,ll p)
{
    ll res=1;
    a%=p;
    while(b>0)
    {
        if(b&1)
        res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return(res);
}
ll modInverse(ll a, ll m)
{
    ll g = gcd(a, m);
    return(power(a,m-2,m));
}*/
/*ll b_search(ll arr[],ll n,ll s)
{
    ll l=0,r=n-1;
    while(l<=r)
    {
        ll mid=l+(r-l)/2;
        if(arr[mid]==s)
        return(mid);
        if(arr[mid]<s)
        l=mid+1;
        else
        r=mid-1;
    }
    return(-1);
}*/
bool isprime(ll x)
{
    if(x==1)
        return(false);
    for(ll i=2;i*i<=x;i++)
    {
        if(x%i==0)
            return(false);
    }
    return(true);
}
//vector<ll> v[100005];
void solve()
{
    ll n,m;
    cin>>n>>m;
    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    bool vis[n+1]={false};
    ll c1,c2;
    ll ans=0;
    for(ll i=0;i<m;i++)
    {
        cin>>c1>>c2;
        if(arr[c1-1]<=arr[c2-1])
            vis[c1]=true;
        if(arr[c2-1]<=arr[c1-1])
            vis[c2]=true;
    }
    for(ll i=1;i<=n;i++)
    {
        if(vis[i]==false)
            ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


Measured memory_bytes: 4524
N,K =list(map(int,input().split()))
S = input()
S2 = [(1 if S[i]+S[i+1]== 'LR' else -1) if S[i]!= S[i+1] else 0 for i in range(N-1)]
score = sum([1 if S[i]==S[i+1] else 0 for i in range(N-1)])
S3 = min(S2.count(1),S2.count(-1))
if S3 >= K:
    score += K*2
else:
    if S2.count(1) == S2.count(-1):
        score += S3*2
    else:
        score += S3*2+1
print(score)   

Measured memory_bytes: 4980
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        int[] upper_sizes = new int[n];
        int[] middle_sizes = new int[n];
        int[] lower_sizes = new int[n];
        for(int i=0; i<n; i++){
            upper_sizes[i] = Integer.parseInt(sc.next());
        }
        for(int i=0; i<n; i++){
            middle_sizes[i] = Integer.parseInt(sc.next());
        }
        for(int i=0; i<n; i++){
            lower_sizes[i] = Integer.parseInt(sc.next());
        }
        Arrays.parallelSort(upper_sizes);
        Arrays.parallelSort(middle_sizes);
        Arrays.parallelSort(lower_sizes);
        
        long[] middle_patterns = new long[n];
        middle_patterns[0] = binarySearchMax(upper_sizes, middle_sizes[0]-1);
        for(int i=1; i<n; i++){
            middle_patterns[i] = middle_patterns[i-1] + binarySearchMax(upper_sizes, middle_sizes[i]-1);
        }
        
        long sum = 0;
        int a=0;
        for(int i=0; i<n; i++){
            a = binarySearchMax(middle_sizes, lower_sizes[i]-1);
            if(a>0) sum += middle_patterns[a-1];
        }
        
        System.out.println(sum);
    }
    public static int binarySearchMax(int[] dt, int target){
        int left=-1, right=dt.length;
        int mid=-1;
        
        while((right-left)>1){
            mid = left + (right-left)/2;
            
            if(dt[mid] <= target){
                left=mid;
            }else{
                right=mid;
            }
        }
        return left+1;
    }
}

Measured memory_bytes: 64540
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;

int main()
{
	int n;

	while (cin >> n, n)
	{
		map<int, vector<string> > tn;
		vector<string> names;
		for (int i = 0; i < n; ++i)
		{
			string name;
			int m;
			cin >> name >> m;
			names.push_back(name);
			while (m--)
			{
				int d;
				cin >> d;
				tn[d].push_back(name);
			}
		}
		sort(names.begin(), names.end());

		map<string, int> point;
		for (int i = 0; i < 30; ++i)
		{
			vector<string> c;
			vector<string>& w = tn[i];
			for (int j = 0; j < w.size(); ++j)
				c.push_back(w[j]);

			int p = n - w.size() + 1;
			for (int j = 0; j < w.size(); ++j)
				point[w[j]] += p;
		}

		int mini = 1111111111;
		string akari;
		for (int i = 0; i < names.size(); ++i)
		{
			if (point[names[i]] < mini)
			{
				mini = point[names[i]];

				akari = names[i];
			}
		}
		cout << mini << " " << akari << endl;
	}

	return 0;
}

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

int main() {
	int N = 0;
	int pflag = 0;
	int wflag = 0;
	int gflag = 0;
	int yflag = 0;
	int colornum = 0;

	std::cin >> N;

	std::vector<char> color(N, '\0');

	for (int i = 0; i < N; i++) {
		std::cin >> color.at(i);
	}
  
	for (int i = 0; i < N; i++) {
		switch (color.at(i)) {
		case 'P':
			if (pflag == 0) {
				pflag = 1;
			}
			break;
		case 'W':
			if (wflag == 0) {
				wflag = 1;
			}
			break;
		case 'G':
			if (gflag == 0) {
				gflag = 1;
			}
			break;
		case 'Y':
			if (yflag == 0) {
				yflag = 1;
			}
			break;
		}
	}

	colornum = pflag + wflag + gflag + yflag;

	switch (colornum) {
	case 3:
		std::cout << "Three";
		break;
	case 4:
		std::cout << "Four";
		break;
	}
	return 0;
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n, ans=0, sum=0;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    rep(i,n){
        sum -= a[i];
        ans += sum%mod*a[i];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i=0;i<tx-sx;i++)cout << "R";
    for(int i=0;i<ty-sy;i++)cout << "U";
    for(int i=0;i<tx-sx;i++)cout << "L";
    for(int i=0;i<ty-sy;i++)cout << "D";
    cout << "D";
    for(int i=0;i<tx-sx+1;i++)cout << "R";
    for(int i=0;i<ty-sy+1;i++)cout << "U";
    cout << "L";
    cout << "U";
    for(int i=0;i<tx-sx+1;i++)cout << "L";
    for(int i=0;i<ty-sy+1;i++)cout << "D";
    cout << "R" << endl;
    return 0;  
}

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

using namespace std;

typedef long long ll;

struct Data {
  int t; ll d;
  Data(int a, ll b) : t(a), d(b) {}
};

bool cmp1(Data x, Data y) {
  return x.d > y.d;
}

bool cmp2(Data x, Data y) {
  return x.d < y.d;
}

vector<Data> all, A, B;
map<int, int> ok;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int t, d;
    cin >> t >> d;
    all.push_back(Data(t, d));
  }
  sort(all.begin(), all.end(), cmp1);
  int c = 0; ll ans = 0, bonus = 0;
  for (int i = 0; i < n; i++) {
    if (c == k) {
      B.push_back(all[i]);
    } else {
      A.push_back(all[i]);
      ans += all[i].d;
      if (!ok[all[i].t]) {
        bonus++;
      }
      ok[all[i].t]++;
      c++;
    }
  }
  sort(A.begin(), A.end(), cmp1);
  sort(B.begin(), B.end(), cmp2);
  ll fans = ans + bonus * bonus;
  while (!B.empty()) {
    Data u = B[B.size() - 1];
    B.pop_back();
    if (ok[u.t] != 0) continue;
    while (!A.empty()) {
      if (ok[A[A.size() - 1].t] - 1 == 0) {
        A.pop_back();
      } else {
        break;
      }
    }
    if (A.empty()) break;
    Data v = A[A.size() - 1];
    A.pop_back();
    if (v.t == u.t) continue;
    ok[v.t]--;
    ok[u.t]++;
    bonus++;
    ans -= v.d;
    ans += u.d;
    //cout << fans << " " << ans + bonus * bonus << endl;
    fans = max(fans, ans + bonus * bonus);
  }
  cout << fans << endl;
  return 0;
}



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

const int N = 405;

int a[N];
long long dp[N][N];
long long psum[N];
int n;

void read() {
  scanf("%d", &n);
  for (int i = 1 ; i <= n ; i++)
    scanf("%d", &a[i]);
}

long long solve(int l, int r) {
  if (l == r) return 0;

  long long &ret = dp[l][r];
  if (ret != -1) return ret;

  ret = 4e18;
  for (int i = l ; i < r ; i++) {
    ret = min(ret, solve(l, i) + solve(i+1, r));
  }
  ret += (psum[r] - psum[l-1]);
  return ret;
}

long long work() {
  for (int i = 1 ; i <= n ; i++)
    psum[i] = a[i] + psum[i-1];
  memset(dp, -1, sizeof dp);

  return solve(1, n);
}

int main() {
  read();
  cout << work() << endl;
  return 0;
}

Measured memory_bytes: 1536
//
// Created by Myabu on 2020/01/23.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int X,Y,Z;

    cin>>X>>Y>>Z;

    int ans = 0;

    int temp = 0;
    temp += Z;
    while(true){
        if(temp > X)break;
        
        temp += Y+Z;
        
        
        if(temp <= X){
            ans++;
        }
        
    }

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

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

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end(), greater<int>());
    int alice = 0, bob = 0;
    for (int i = 0; i < n; i += 2) {
        alice += a.at(i);
    }
    for (int i = 1; i < n; i += 2) {
        bob += a.at(i);
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  long long A, B, X;
  cin >> X;
  for (int i = 0; i < 1000; ++i) {
    long long x = X;
    A = pow(i, 5);
    x = X - A;
    for (int j = -1000; j < 1000; ++j) {
      B = pow(j, 5) * -1;
      if (x == B) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 4100
n,m=map(int,input().split())
edge=[[]for _ in range(n)]
for _ in range(n+m-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
from collections import deque
def find_loop(n,e,flag):
  x=[0]*n
  d=deque()
  t=[]
  c=0
  for i in range(n):
    for j in e[i]:x[j]+=1
  for i in range(n):
    if x[i]==0:
      d.append(i)
      t.append(i)
      c+=1
  while d:
    i=d.popleft()
    for j in e[i]:
      x[j]-=1
      if x[j]==0:
        d.append(j)
        t.append(j)
        c+=1
  if flag==0:return c==n
  else:return t
top=find_loop(n,edge,1)
d=[0]*n
for i in range(n):
  for j in edge[top[i]]:d[j]=d[top[i]]+1
ans=[-1]*n
ans[d.index(0)]=0
for i in range(n):
  for j in edge[i]:
    if d[i]+1==d[j]:ans[j]=i+1
print(*ans)

Measured memory_bytes: 29432
import java.util.*;
 
public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        String S = sc.next();
        sc.close();
        int max = 0;
        for(int i  = 1; i < N; i++){
            String X = S.substring(0, i);
            String Y = S.substring(i);
            Map<String, Integer>map = new HashMap<>();
            for(int j = 0; j < X.length(); j++){
                map.put(String.valueOf(X.charAt(j)), 1);
            }
            for(int j = 0; j < Y.length(); j++){
                if(map.containsKey(String.valueOf(Y.charAt(j)))){
                    map.put(String.valueOf(Y.charAt(j)), 2);
                }
            }
            int count = 0;
            for(String key: map.keySet()){
                if(map.get(key) == 2)
                    count++;
            }
            max = Math.max(max, count);
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 23892
ss = input()
s = int(ss)

ue = s // 100
sita = s % 100
if ue > 12:
    if sita <= 12 and sita != 0:
        print("YYMM")
    else:
        print("NA")
elif ue == 0:
    if sita <= 12 and sita != 0:
        print("YYMM")
    else:
        print("NA")
else:
    if sita <= 12 and sita != 0:
        print("AMBIGUOUS")
    else:
        print("MMYY")

Measured memory_bytes: 3064
import math

X = list(map(int, input().split()))
N = X[0]
D = X[1]
distance = []
sum = 0
for i in range(N):
    Y = list(map(int, input().split()))
    distance.append(math.sqrt(Y[0]**2 + Y[1]**2))
    if distance[i] <= D:
        sum += 1

print(sum)

Measured memory_bytes: 17068
S = str(input())
s0=0
s1=0
for i in range(len(S)):
    if i%2==0 and S[i]=="0":
        s1+=1
    elif i%2==0 and S[i]=="1" :
        s0+=1
    elif i%2==1 and S[i]=="0":
        s0+=1

    elif i%2==1 and S[i]=="1":
        s1+=1

print(min(s0,s1))

Measured memory_bytes: 3188
import random
def dice_move(a,s):
    if s=="E":
        return [a[3],a[1],a[0],a[5],a[4],a[2]]
    elif s=="S":
        return [a[4],a[0],a[2],a[3],a[5],a[1]]
    elif s=="W":
        return [a[2],a[1],a[5],a[0],a[4],a[3]]
    elif s=="N":
        return [a[1],a[5],a[2],a[3],a[0],a[4]]
    
a=list(map(int,input().split()))
b=list(map(int,input().split()))
h=("N","W","S","E")
for i in range(20000):
    num=random.randrange(4)
    a=dice_move(a,h[num])
    if a==b:
        print("Yes")
        exit()
print("No")


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

int main(){
  char ch;
  int cnt[26] = {};
  while(scanf("%c", &ch) != EOF){
    if('a' <= ch && ch <= 'z'){
      cnt[ch - 'a']++;
    }
    else if('A' <= ch && ch <= 'Z'){
      cnt[ch - 'A']++;
    }
  }
  for(int i = 0; i < 26; i++){
    printf("%c : %d\n", 'a' + i, cnt[i]);
  }
}



Measured memory_bytes: 3224
/**
 *    Author: "Robin Singh" !!
 *    rob_in_1
**/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
  bool first = true; 
  string res = "{";
  for (const auto &x : v) {
    if (!first) res += ", ";
    first = false;
    res += to_string(x);
  }
  res += "}"; 
  return res;
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", dbg_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

const long double eps = 1e-9;
const int mod = 1e9+7;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

//===================================================================================================!!

const int nn = 2e5+5;

void solve(){
  int n;
  cin >> n;
  vi a(n);
  fr(i, 0, n) cin >> a[i];
  bool ok = 1;
  fr(i, 0, n-1){
    if(a[i] > a[i+1]) ok = 0;
  }
  if(ok){
    cout << "YES";
    return;
  }
  
  fr(i, 0, n){
    fr(j, i+1, n){
      vi v = a;
      swap(v[i], v[j]);
      bool ok = 1;
      fr(k, 0, n-1){
        if(v[k] > v[k+1]) ok = 0;
      }
      if(ok){
        cout  << "YES";
        return;
      }
    }
  }
  cout << "NO";
}

int32_t main(){
  #ifdef LOCAL 
    // freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
  #endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

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

const int N = 55;

int n, t[N], ans = 0;
string str[N], s;
bool flag = false;

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) cin >> str[i] >> t[i];
	cin >> s;

	for (int i = 1; i <= n; i++) {
		if (flag) ans += t[i];
		if (str[i] == s) flag = true;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var (
		N int
		S string
	)

	fmt.Scanf("%d", &N)
	fmt.Scanf("%s", &S)

	ans := 0
	for i := 0; i < N-2; i++ {
		if S[i:i+3] == "ABC" {
			ans++
		}
	}
	fmt.Println(ans)
}


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

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

    vector<int> v(5);
    int ans = 0, tmp = 0;
    for (int i = 0; i < 5; i++) {
        int x; cin >> x;
        if (x % 10) tmp = max(tmp, 10 - x % 10);
        ans += (x + 9) / 10 * 10;
    }
    cout << ans - tmp << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
  cout<<fixed<<setprecision(12);
  double x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  double X=pow(x1-x2,2);
  double Y=pow(y1-y2,2);
  cout<<sqrt(X+Y)<<endl;
  return 0;
}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    double x, ans = 0;
    string u;

    rep(i, N) {
        cin >> x >> u;
        ans += (u == "JPY") ? x : x * 380000.0;
    }

    cout << fixed << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

V, E = map(int, input().split())
INF = 10**9
G = [[] for _ in range(V)]
for _ in range(E):
    s, t, d = map(int, input().split())
    G[t].append((s, d))
def rec(bit, v):
    if dp[bit][v] != INF: return dp[bit][v]
    before = bit^(1<<v)
    for u, d in G[v]:
        if before&(1<<u):
            dp[bit][v] = min(dp[bit][v], rec(before, u)+d)
        if before == 0 and u == 0:
            dp[bit][v] = min(dp[bit][v], d)
    return dp[bit][v]
# dp[S][v]: 集合Sの中でvが最後になる時の最短距離
dp = [[INF]*V for _ in range(1<<V)]
ans = INF
ans = min(ans, rec((1<<V)-1, 0))
if ans != INF:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 15448
import sys

def S(): return sys.stdin.readline().rstrip()

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

# Mは、a1,…,aNの最大公約数の倍数になることに注意

divisor = []  # Mの約数

for i in range(1,int(M**.5)+1):
    if M % i == 0:
        divisor.append(i)
        if i != M//i:
            divisor.append(M//i)

ANS = []

for d in divisor:
    if d >= N:
        ANS.append(M//d)

print(max(ANS))

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int max_n = max({a, b, c});
  int sum = a + b + c;
  int x = (max_n - a) + (max_n - b) + (max_n - c);
  if (x % 2 == 0) {
    cout << x / 2 << endl;
  } else {
    cout << x / 2 + 2 << endl;
  }
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a[5],k;
    for(int i=0;i<5;i++) cin>>a[i];
    cin>>k;
    if(a[4]-a[0]>k) {
        cout<<":("<<endl;
        return 0;
    }
    cout<<"Yay!"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using ll = long long;
using namespace std;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int cs[12] = {};
  int as[12][12] = {{}};
  rep(i, n) {
    cin >> cs[i];
    rep(j, m) { cin >> as[i][j]; }
  }
  int mmmoney = 100000000;
  for (int bit = 1; bit < (1 << n); bit++) {
    int money = 0;
    int totals[m];
    rep(i, m) { totals[i] = 0; }
    rep(i, n) {
      if (bit & (1 << i)) {
        rep(j, m) { totals[j] += as[i][j]; }
        money += cs[i];
      }
    }
    bool c = true;
    rep(i, m) {
      if (totals[i] < x) {
        c = false;
      }
    }
    if (c) {
      mmmoney = min(mmmoney, money);
    }
  }
  if (mmmoney == 100000000) {
    mmmoney = -1;
  }
  cout << mmmoney << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    rep(i, -118, 120)
    {
        rep(j, -119, 119)
        {
            ll tmp = i - j;
            if (pow(i, 5) - pow(j, 5) == x)
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}


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

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int A, B, C, X; cin >> A >> B >> C >> X;
	vector<pair<int, int>> items = {{500, A}, {100, B}, {50, C}};
	vector<ll> dp(X+1);
	dp[0] = 1;
	for (auto item : items) {
		int w, c; tie(w, c) = item;
		vector<ll> ndp(X+1);
		for (int u = 0; u <= c; u++) {
			for (int i = 0; i + u * w <= X; i++) {
				ndp[i + u * w] += dp[i];
			}
		}
		swap(dp, ndp);
	}
	cout << dp[X] << endl;

	return 0;
}


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

using namespace std;

int main(){
  int a,b,k,i,j,l=0;
  vector <int> v;
  
  cin>>a>>b>>k;
  
  for(i=a;i<a+k;i++){
    v.push_back(i);
  }
  for(i=b-k+1;i<=b;i++){
    l=0;
    for(j=0;j<k;j++){
      if(v[j]==i)
        l++;
    }
    if(l>0){
      continue;}
    v.push_back(i);
  }
  for(i=0;i<k*2;i++){
    if(v[i]<a||v[i]>b)
      continue;
    if(v[i]==0)
      continue;
    cout<<v[i]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a,b,c;
    cin >> a >> b >> c;
    intl ans;
    if(a == b)ans = c;
    else if(a == c)ans = b;
    else ans = a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def m():
    N = int(input())
    XL = [list(map(int, input().split())) for _ in range(N)]
    ST = [[xl[0] - xl[1], xl[0] + xl[1]] for xl in XL]
    ST.sort(key=lambda x: x[1])
    ans = 1
    right = ST[0][1]
    for i in range(1, N):
        if right <= ST[i][0]:
            right = ST[i][1]
            ans += 1
    return ans


print(m())


Measured memory_bytes: 42744
//
import java.math.*;
import java.util.*;
import java.io.*;
  
public class Main { 
  
    static BufferedReader in;
    static PrintWriter out = new PrintWriter(System.out);
    static String file = "../in";
    static int test = 10; // 0 for local testing, 1 for std input
    static int inf = 1_000_000, mod = 1_000_000_007;



    void swap(int[]ary, int i, int j)
    {
        int t = ary[i];
        ary[i] = ary[j];
        ary[j] = t;
    }
    
    String[] split() throws Exception
    {
        return in.readLine().split(" ");
    }

    int readInt() throws Exception
    {
        return Integer.valueOf(in.readLine());
    }

    long[] toLongArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        long[] ary = new long[n];
        for(int i = 0; i < n; i++) ary[i] = Long.valueOf(sp[i]);
        return ary;
    }

    int[] toIntArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) ary[i] = Integer.valueOf(sp[i]);
        return ary;
    }

    String reverse(String str)
    {
        return new StringBuilder(str).reverse().toString();
    }


    long pow(long a, int pow)
    {
        long res = 1;
        while(pow > 0)
        {
            if(pow % 2 != 0) {
                res *= a;
                res %= mod;
            }
            a = a * a;
            a %= mod;
            pow /= 2;
        }

        return res;
    }

    public static void main(String[] args) throws Exception
    {
        int _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");
        char[] gg = in.readLine().toCharArray();}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
        // System.out.println((-100 + 0) / 2);

        
        new Main().b();        
        out.flush();
    }

    void b() throws Exception
    {
        int x = readInt();
        long hp = (x / 500) * 1000;
        x %= 500;
        hp += (x / 5) * 5;
        out.println(hp);
    }

    void a() throws Exception
    {
        char[] chs = in.readLine().toCharArray();
        if(chs[2] == chs[3] && chs[4] == chs[5]) 
        {
            out.println("Yes");
        }
        else out.println("No");
    }
}

Measured memory_bytes: 22484
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// NextPermutation generates the next permutation of the
// sortable collection x in lexical order.  It returns false
// if the permutations are exhausted.
//
// Knuth, Donald (2011), "Section 7.2.1.2: Generating All Permutations",
// The Art of Computer Programming, volume 4A.
func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// NextPermutationを使わない場合
func f(s string) {
	pos := -1
	m := make([]int, 26)
	v := byte(0)
L0:
	for i := len(s) - 1; i >= 0; i-- {
		c := int(s[i] - 'a')
		// out(c, m)
		for j := c; j < 26; j++ {
			if m[j] == 1 {
				v = byte(j + 'a')
				pos = i
				break L0
			}
		}
		m[c]++
	}

	if pos == -1 {
		out(-1)
		return
	}

	out(s[:pos] + string(v))

	return
}

func f2(s string) {
	if s == "zyxwvutsrqponmlkjihgfedcba" {
		out(-1)
		return
	}
	x := make([]int, 26)
	for i := 0; i < 26; i++ {
		x[i] = int(s[i])
	}

	NextPermutation(sort.IntSlice(x))

	for i := 0; i < 26; i++ {
		c := byte(x[i])
		if s[i] == c {
			fmt.Printf("%c", c)
		} else {
			fmt.Printf("%c", c)
			break
		}
	}
	out("")
}

func main() {
	sc.Split(bufio.ScanWords)
	s := getString()
	m := make([]int, 26)
	for _, v := range s {
		m[int(v-'a')]++
	}
	c := -1
	for i := 0; i < 26; i++ {
		if m[i] == 0 {
			c = i
			break
		}
	}
	if c == -1 {
		f2(s)
		return
	}
	out(s + string(byte(c+'a')))
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
#include <algorithm>
#include <iomanip>
using namespace std;
int main(void){
    std::cout<<std::fixed<<std::setprecision(10);
    long double n,k; cin >> n>> k;
    long double i = 1;
    long double ans = 0;
    while (i <= n) {
        long double count = 0;
        long double score = i;
        while (score < k) {
            score = score * 2;
            count++;
        }
        int j = 1;
        long double tmp = 0.5 * pow(10,10);
        while (j < count) {
            tmp = tmp * 0.5;
            j++;
        }
        if (i < k) ans += 1 / n * tmp / pow(10, 10);
        else ans += 1 / n;
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3756
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;


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

    int N;
    cin >> N;
    vi a(N), b(N), c(N);

    REP(i, N) cin >> a[i];
    REP(i, N) cin >> b[i];
    REP(i, N) cin >> c[i];

    sort(ALL(a));
    sort(ALL(c));

    ll ans = 0;
    REP(i, N){
        ll ue = distance(a.begin(), lower_bound(ALL(a),b[i]));
        ll sita = distance(upper_bound(ALL(c),b[i]), c.end());
        
        ans += ue * sita;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
vector<string>v;
string a="a",b="b";

void genr(int n,int i,string &s,int maxi)
{
	if(i==n)
	{
		v.push_back(s);
		return;
	}
	if(i==0)
	{
		s=s+a;
		genr(n,i+1,s,1);
	}
	else
	{
		for(int j=0; j<maxi+1; j++)
		{
			s.push_back(char(97+j));
			genr(n,i+1,s,max(maxi,j+1));
			s=s.substr(0,i);
		}
	}
}

int main()
{
	int n;
	cin>>n;
	string s="";
	genr(n,0,s,0);
	sort(v.begin(),v.end());
	for(int i=0; i<v.size(); i++)
		cout<<v[i]<<endl;
	return 0;
}


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

int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  cout<<10*((a+9)/10+(b+9)/10+(c+9)/10+(d+9)/10+(e+9)/10-1)+min((a+9)%10,min((b+9)%10,min((c+9)%10,min((d+9)%10,(e+9)%10))))+1;
}

Measured memory_bytes: 256
n, m = input().split()

n = int(n)
m = int(m)

if n > 1 and m > 1:
    print((n-2)*(m-2))
elif n==1 and m > 1:
    print(m-2)
elif n>1 and m==1:
    print(n-2)
else:
    print(1)
    


Measured memory_bytes: 2940