akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

string four[4]={
"aabc",
"ddbc",
"efgg",
"efhh"};
string five[5]={
"aabbc",
"hii.c",
"h..jd",
"g..jd",
"gffee"};
string six[6]={
"aabxx.",
"d.b..y",
"dcc..y",
"xx.aab",
"..yd.b",
"..ydcc"};
string seven[7]={
"aabbcc.",
"ggh...d",
"j.h...d",
"jii...e",
"...gghe",
"...j.hf",
"...jiif"};

char a[1010][1010];
int main(){
    for(int i=0;i<=1000;i++){
        for(int j=0;j<=1000;j++){
            a[i][j] = '.';
        }
    }
    int n;
    cin >> n;
    if(n==2){
        cout << -1 << endl;
    }else if(n==3){
        cout << "aa." << endl;
        cout << "..b" << endl;
        cout << "..b" << endl;
    }else{
        int id = 0;
        int N = n;
        while(1){
            if(n > 7){
                for(int i=0;i<4;i++){
                    for(int j=0;j<4;j++){
                        a[id+i][id+j] = four[i][j];
                    }   
                }
                id += 4;
                n-=4;
            }else{
                if(n==4){
                    for(int i=0;i<4;i++){
                        for(int j=0;j<4;j++){
                            a[id+i][id+j] = four[i][j];
                        }   
                    }
                }else if(n==5){
                    for(int i=0;i<n;i++){
                        for(int j=0;j<n;j++){
                            a[id+i][id+j] = five[i][j];
                        }   
                    }
                }else if(n==6){
                    for(int i=0;i<n;i++){
                        for(int j=0;j<n;j++){
                            a[id+i][id+j] = six[i][j];
                        }   
                    }
                }else{
                    for(int i=0;i<n;i++){
                        for(int j=0;j<n;j++){
                            a[id+i][id+j] = seven[i][j];
                        }   
                    }
                }
                break;
            }
        }
        rep(i,N){
            rep(j,N){
                cout << a[i][j];
            }
            cout << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 2176
/**
 *  author: mahfuzz
 *  created: 03.05.2020
**/
 
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << #x << ':' << x << "\n"
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    int n; cin >> n;
    int arr[n + 1];
    vector<int> vec;
    
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        vec.push_back(x);
        
        arr[x] = i + 1;
    }
    
    sort(all(vec));
    
    for(int x : vec)
        cout << arr[x] << " ";
    cout << "\n";
        
    return 0;
}



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

n, a, b, c, d = map(int, input().split())
s = input()


def two_rocks(li):
    if "##" in li:
        return True
    else:
        return False


def three_spaces(li):
    if "..." in li:
        return True
    else:
        return False


def solve():
    if two_rocks(s[a-1:c-1]):
        return False
    if two_rocks(s[b-1:d-1]):
        return False
    if d < c:
        if three_spaces(s[b-2:d+1]):
            return True
        else:
            return False
    else:
        return True


ans = "Yes" if solve() else "No"
print(ans)


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

int main(){
  int max = 1000000;
  int prime[1000001] = {};
  for(int i = 0; i <= max; i++) prime[i] = 1;
  prime[0] = prime[1] = 0;
  for(int i = 2; i * i <= max; i++){
    if(prime[i]){
      for(int j = i; i * j < max; j++){
        prime[i*j] = 0;
      }
    }
  }
  int a, d, n;
  while(cin >> a >> d >> n, a | d | n){
    int idx = 0, cnt = 0;
    for(int i = 0; ; i++){
      idx = a + i * d;
      if(prime[idx]) cnt++;
      if(cnt == n) break;
    }
    cout << idx << endl;
  }
  return 0;
}



Measured memory_bytes: 6880
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn=1e6+7;

int main (){
    int a;
    cin>>a;
    printf ("%d\n",a+a*a+a*a*a);






}
/*
0 0 0 2 0 1
60 1
09:00 10:00
1
*/









Measured memory_bytes: 3188
a = list(map(int,input().split()))
b = int(input())

while(a[0] >= a[1]):
    a[1] *= 2
    b -= 1
    if b <= 0:
        break
while(a[1] >= a[2]):
    a[2] *= 2
    b -= 1
    if b <= 0:
        break
if a[0] < a[1] and a[1] < a[2] and b >= 0:
    print("Yes")
else:
    print("No")

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int x[9],y[9];

double jarak(int i, int j){
	double selisihx = abs(x[i] - x[j]);
	double selisihy = abs(y[i] - y[j]);
	return sqrt(selisihy*selisihy + selisihx*selisihx);
}

int main(){
	int n,i,j;
	scanf("%d",&n);
	
	for(i=0;i<n;i++){scanf("%d %d",&x[i],&y[i]);}
	int a[10];
	for(i=0;i<n;i++){a[i] = i;}
	double sum = 0;
	int cnt = 0;
	do{
		double tot = 0;
		for(i=0;i<n-1;i++){
			tot += jarak(a[i], a[i+1]);
		}
		sum += tot;
		cnt++;
	}while(next_permutation(a,a+n));
	printf("%.9lf\n",sum/(double)cnt);
	return 0;
};

Measured memory_bytes: 256
from statistics import mean

nCr = {}
def cmb(n, r):
    if n < r:
        return 0
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
  
n, a, b = [int(_) for _ in input().split()]
values = [int(v) for v in input().split()]
values.sort(reverse=True)
maximum_mean = mean(values[:a])
print(maximum_mean)

min_value = values[:a][-1]
accepted = values[:a].count(min_value)
full = values.count(min_value)

if min_value == maximum_mean:
    ans = 0
    for r in range(a, b+1):
        ans += cmb(full, r)
else:
    ans = cmb(full, accepted)

print(ans)


Measured memory_bytes: 5404
#[allow(unused_macros)]
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 ( 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 ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
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! {
        r: u64, g: u64, b: u64
    }
    println!("{}", if (r*100+g*10+b)%4==0 {"YES"} else {"NO"});
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#define MAX 10
#define PATTERN 1024 

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector <vector <int>> S(m, vector<int> (n, 0));
	vector <vector <int>> temp(m, vector<int>(n, 0));
	vector <int> p(m);




	int k, s;
	for (int i = 0; i < m; i++) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			S[i][s-1] = 1;
		}
	}




	for (int i = 0; i < m; i++) { cin >> p[i]; }
	
	bool on = true;
	int ans = 0;
	int all_on = 1 << n;
	for (int mask = 0; mask < all_on; mask++) {
		for (int i = 0; i < m; i++) {
			int count = 0;
			for (int shift = 0; shift < n; shift++) {
				int sel = (mask >> shift) & 1;
				count += sel * S[i][shift];
			}
			if (count % 2 != p[i]) {
				on = false;
				break;
			}
		}
		if (on) { ans++; }
		on = true;
	}

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

Measured memory_bytes: 3612
import Control.Applicative ((<$>))

diff begin end = end - begin

main :: IO ()
main = do
  [sx, sy, tx, ty] <- map read . words <$> getLine :: IO [Int]
  putStr (concat $ replicate (diff sy ty) "U")
  putStr (concat $ replicate (diff sx tx) "R")
  putStr (concat $ replicate (diff sy ty) "D")
  putStr (concat $ replicate (diff sx tx) "L")
  putStr "L"
  putStr (concat $ replicate ((diff sy ty) + 1) "U")
  putStr (concat $ replicate ((diff sx tx) + 1) "R")
  putStr "D"
  putStr "R"
  putStr (concat $ replicate ((diff sy ty) + 1) "D")
  putStr (concat $ replicate ((diff sx tx) + 1) "L")
  putStr "U"

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    // n+1個置けるなら答えは無し
    ll wait=0,cnt=0;
    vl ans(n,0);
    rep(i,n){
        if(wait){
            wait--;
            continue;
        }else if(s[i]=='o'){
            wait=c;
            cnt++;
            ans[i]++;
        }
    }
    if(cnt>=k+1) return 0;

    wait=0,cnt=0;
    rrep(i,n){
        if(wait){
            wait--;
            continue;
        }else if(s[i]=='o'){
            wait=c;
            cnt++;
            ans[i]++;
        }
    }
    rep(i,n)if(ans[i]==2)puta(i+1);
    return 0;
}

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

int main(){
    int N; cin >> N;
    vector<long long> L(N);
    for(int i=0; i<N; i++) cin >> L[i];
    sort(L.begin(), L.end());
    /*
    for(int i=0; i<N; i++) cout << L[i] << " ";
    cout << endl;
    */

    long long ans = 0;

    for(int i=N-1; i>0; i--){
        for(int j=i-1; j>0; j--){
            int limit = upper_bound(L.begin(), L.end(), L[i]-L[j])-L.begin();
            /*
            cout << "i = " << i << endl << "j = " << j << endl;
            cout << "L[i] = " << L[i] << endl;
            cout << "klimit = " << L[i]-L[j] << endl;
            cout << "limit = " << limit << endl;
            cout << "can make triangle = " << j - limit << endl;
            */
            ans += max(j - limit, 0);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,a[3],i;
    for(i=0;i<3;i++)
    {
        cin >> a[i];
    }
    sort(a,a+3,greater<int>());
    if(a[1]%2!=a[2]%2)
    {
        cout << ((a[0]-a[1])+(a[0]-a[2]))/2+2 << endl;
    }
    else
    {
        cout << ((a[0]-a[1])+(a[0]-a[2]))/2 << endl;
    }
    return 0;

}


Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	vector<int> S;
	int temp[100];

	int a, L, min, max;
	while (1){
		int ssize = 1;
		bool FLAG = false;
		cin >> a >> L;
		if (!a && !L) break;
		if (a == 0){
			cout << " " << a << " " << a << " " << a + 1 << endl;
			return 0;
		}
		temp[0] = a;
		for (int i = 0; i < 100; ++i){

			for (int l = 0; l < L; ++l){
				S.push_back(a % 10);
				a = a / 10;
			}
			sort(S.begin(), S.end());
			int digit = 1;
			min = 0;
			max = 0;
			for (int j = 0; j < L; ++j){
				max += S[j] * digit;
				min += S[L - j - 1] * digit;
				digit *= 10;
			}
			//cout << max << " " << min << endl;
			for (int m = 0; m < ssize; ++m){
				if (max - min == temp[m]){
					cout << m << " " << max - min << " " << i - m + 1 << endl;
					FLAG = true;
					break;
				}
			}
			if (FLAG)break;
			temp[ssize] = max - min;
			++ssize;
			a = max - min;
			//cout << "a" << a << endl;
			S.clear();
		}
		S.clear();
	}

	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007LL
typedef long long ll;

int n;
ll dp[21][51][51][28];
string str[51];

ll solve(int v,int f,int t,int lb){
	if(dp[v][f][t][lb]!=-1)return dp[v][f][t][lb];
	if(f==t)return 1;
	if(str[f].size()==v){
		if(lb==0){
			return solve(v,f+1,t,lb+1);
		}
		else return 0;
	}
	for(int i=f+1;i<t;i++){
		if(str[i].size()==v)return 0;
	}
	ll ans=0;
	for(int i=max(lb,1);i<27;i++){
		for(int j=f;j<t;j++){
			bool flag=true;
			for(int k=f;k<=j;k++){
				if(str[k][v]!='?' && (str[k][v]-'a')!=(i-1)){
					flag=false;
				}
			}
			if(flag){
				ans+=solve(v+1,f,j+1,0)*solve(v,j+1,t,i+1)%MOD;
				ans%=MOD;
			}
		}
	}
	dp[v][f][t][lb]=ans;
	return ans;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin >> str[i];
	}
	memset(dp,-1,sizeof(dp));
	printf("%lld\n",solve(0,0,n,0));
	return 0;
}

Measured memory_bytes: 15268
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int p,n,ans=0,a[1000000],b[1000000];
  cin>>p>>p>>n;
  r(i,n)cin>>a[i]>>b[i];
  for(int i=1;i<n;i++){
    if((a[i]>a[i-1]&&b[i]>b[i-1])||(a[i]<a[i-1]&&b[i]<b[i-1]))
      ans+=max(abs(a[i]-a[i-1]),abs(b[i]-b[i-1]));
    else ans+=abs(a[i]-a[i-1])+abs(b[i]-b[i-1]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3100
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

const int MX=2011,md=1000000007;

typedef long long LL;
int dp[MX][MX];
int n,k;
int fac[MX*MX],inv[MX*MX],facinv[MX*MX];

#define C(x,y) ((LL)fac[x]*facinv[y]%md*facinv[(x)-(y)]%md)

void ini(int m){
	inv[1]=1;for(int i=2;i<=m;i++)inv[i]=(LL)inv[md%i]*(md-md/i)%md;
	fac[0]=1;for(int i=1;i<=m;i++)fac[i]=(LL)fac[i-1]*i%md;
	facinv[0]=1;for(int i=1;i<=m;i++)facinv[i]=(LL)facinv[i-1]*inv[i]%md;
}
int main(){
	scanf("%d%d",&n,&k);
	if(k==1)return puts("1"),0;
	ini(n*k);--k;
	for(int i=0;i<=n;i++)
		for(int j=i;j<=n;j++){
			if(!i&&!j)dp[i][j]=1;
			else if(i==j)dp[i][j]=dp[i-1][j];
			else if(!i)dp[i][j]=(LL)dp[i][j-1]*C(j*k-1,k-1)%md;
			else dp[i][j]=((LL)dp[i-1][j]+(LL)dp[i][j-1]*C(j*k-1+i,k-1)%md)%md;
		}
	printf("%lld\n",(LL)fac[n]*dp[n][n]%md);
	return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    ll x;
    cin >> x;
    ll sum = 0;
    int i = x;
    rep(i, x + 1)
    {
        sum += i;
        if (sum >= x)
        {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,i,j,k,m=0;
  cin>>n;
  vector<int> a(n+1),b(n+1);
  for(i=1;i<=n;i++) cin>>a.at(i);
  for(i=n;i>0;i--){
    k=0;
    j=2;
    while(j*i<=n){
      k+=b.at(j*i);
      j++;
    }
    if((k+a.at(i))%2==1){
      m++;
      b.at(i)=1;
    }
  }
  cout<<m<<endl;
  j=0;
  for(i=1;i<=n;i++){
    if(b.at(i)==1){
      cout<<i;
      j++;
      if(j<m) cout<<' ';
      else{
        cout<<endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 2432
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
 
 
N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(N)]
R = [0 for i in range(N)]
T = [0 for i in range(N)]
 
for i in range(N):
    if i == 0:
        L[i] = 0
    else:
        L[i] = gcd(L[i-1], A[i-1])
for i in range(N-1, -1, -1):
    if i == N-1:
        R[i] = 0
    else:
        R[i] = gcd(R[i+1], A[i+1])
for i in range(N):
    T[i] = gcd(L[i], R[i])
 
print(max(T))

Measured memory_bytes: 14428
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
using namespace std;

int main(void)
{
    string s;
    cin >> s;
    if(s.find("AC") != -1){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 256
//g++ -std=c++11 -Wall test.cpp -o test -lm -g -O2
#include <bits/stdc++.h>
using namespace std;
#define sws                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define qi queue<int>
#define si stack<int>
#define s string
#define ll long long;
bool organiza(pair<int, int> a, pair<int, int> b)
{
    return a.ff < b.ff;
}
int main()
{
    sws;
    vector<pair<int, int>> options;
    int n, t, ans = -1;
    cin >> n >> t;
    while (n--)
    {
        int a, b;
        cin >> a >> b;
        options.push_back(make_pair(a, b));
    }
    sort(options.begin(), options.end(), organiza);
    for (auto x : options)
    {
        if (x.second <= t)
        {
            ans = x.first;
            break;
        }
    }
    if (ans != -1)
    {
        cout << ans << endl;
    }
    else
    {
        puts("TLE");
    }
}

Measured memory_bytes: 256
N = gets.to_i
S = (0...N).map{ gets.split("").map(&:ord) }
T = S.transpose
p (0...N).select{ |d|
  js = (0...N).map{ |j| (j+d)%N }
  (0...N-1).all?{ |i|
    ii = (i+d)%N
    si = S[i]
    tii = T[ii]
    (i+1...N).all?{ |j| tii[j] == si[js[j]] }
  }
}.size*N

Measured memory_bytes: 5884
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	// var a, b int
	// fmt.Scanf("%d %d", &a, &b)

	var ps []int
	for i := 0; i < n; i++ {
		var p int
		fmt.Scan(&p)
		ps = append(ps, p)
	}

	cnt := 0
	for i := 0; i < n; i++ {
		if ps[i] > i+1 {
			cnt++
			if cnt > 1 {
				fmt.Print("NO")
				return
			}
		}
	}
	fmt.Print("YES")
}


Measured memory_bytes: 512
import math
import sys
sys.setrecursionlimit(100000)

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
  
X = int(input())

def findPrime(x):
  if is_prime(x):
    return x
  else:
    return findPrime(x+1)

print(findPrime(X))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int a, b; scanf("%d%d", &a, &b);
	
	printf("%d\n", std::max({a + (a - 1), a + b, b + (b - 1)}));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define lcm(a,b)            (abs(a)/gcd(a,b))*abs(b)
#define PI      	        2*acos(0.0)
#define INF     	        1e9
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; 

const int N = 1e5+9;
int dp[N];
int ara[109];
int n, k;

int call(int rem)
{
    if (rem == 0){
        return 1;
    }
    if (dp[rem] != 0){
        return dp[rem];
    }
    for (int i = 0; i<n; i++){
        if (ara[i] <= rem){
            if (call(rem-ara[i]) == 1){
                return dp[rem] = 2;
            }
        }
    }
    return dp[rem] = 1;
}

int main ()
{
    #ifdef Lollipop
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    #endif

    cin >> n >> k;
    for (int i = 0; i<n; i++){
        cin >> ara[i];
    }
    int flag;
    for (int i = 0; i<n; i++){
        flag = call(k - ara[i]);
        if (flag == 1){
            break;
        }
    }
    if (flag == 1){
        cout << "First\n";
    }
    else{
        cout << "Second\n";
    }
    
    return 0;
}




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

int main()
{
    long long n,cap,i,j;
    cin>>n>>cap;
    long long dp[n+1][cap+1],v[n+5],w[n+2];
    memset(dp,0,sizeof(dp)) ;
    for(int i=1; i<=n; i++) cin>>w[i]>>v[i];

    for( i=1; i<=n; i++)
       for( j=1; j<=cap; j++)
    {
           if(j<w[i])  dp[i][j]=dp[i-1][j];
           else dp[i][j] = max(v[i]+dp[i-1][j-w[i]],dp[i-1][j]);
    }
     cout<<dp[n][cap]<<endl;
       return 0;
}


Measured memory_bytes: 82488
n = gets.to_i
a = gets.chomp.split.map &:to_i

right = 0
sum = 0
ans = 0
a.each_with_index do |aa,left|
  while right < n && (sum + a[right]) == (sum ^ a[right])
    sum += a[right]
    right += 1
  end
  ans += right - left
  if left == right
    right += 1
  else
    sum -= a[left]
  end
end

puts ans


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


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a <= c && b <= c) cout << a + b << endl;
  else if (a <= b && c <= b) cout << a + c << endl;
  else cout << b + c << endl;
}

Measured memory_bytes: 3632
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main()
    {
        const int NumOfAlp = 26;
        int n = int.Parse(Console.ReadLine());
        int[][] count = new int[NumOfAlp][];
        for(int i = 0; i < NumOfAlp; i++) count[i] = new int[n];
        for (int i = 0; i < n; i++)
        {
            string S = Console.ReadLine();
            for (int j = 0; j < S.Length; j++)
            {
                count[(int)(S[j] - 'a')][i]++;
            }
        }
        for (int i = 0; i < NumOfAlp; i++)
        {
            IEnumerable<char> result = Enumerable.Repeat((char)('a' + i), count[i].Min());
            foreach (char item in result)
            {
                Console.Write(item);
            }
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 13396
//#define _GLIBCXX_DEBUG    //空コンテナ操作禁止　Clang環境では#define _LIBCPP_DEBUG 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;

const int N_MAX = 510000;   // nCr ｎ≦510,000 とする
const int MOD = 1000000007;

ll fac[N_MAX], finv[N_MAX], inv[N_MAX];  // 階乗factorial(n!)、nの階乗の逆元(n!^-1)、nの逆元(n^-1)

ll Combi( int n, int k ){  // nCk＝n!/k!(n-k)! を返す
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;

  ll fac[n+1], finv[n+1], inv[n+1];
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < n+1; i++){
      fac[i] = fac[i - 1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
      finv[i] = finv[i - 1] * inv[i] % MOD;
  }
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll x, y;
  cin >> x >> y;
  
  ll ans = -1;
  if( (x+y)%3 != 0 ){
    ans = 0;
    cout << ans;
    return 0;
  }
  
  ll gen, n;
  gen = (x+y)/3+1;
  n = x-gen+2;
  ans = Combi( gen-1, n-1 );
  //printf( "Combi( %lld, %lld ) = %lld\n", gen-1, n-1, ans );
  cout << ans; 
  return 0;  
}


Measured memory_bytes: 15872
#include <cstdint>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;

int main() {
	int64_t result = 0;
	int n;
	vector<int> v;
	
	cin.sync_with_stdio(false);
	cin >> n;
	v.resize(3 * n);
	for (int i = 0; i < 3 * n; i++) {
		cin >> v[i];
	}
	
	sort(v.begin(), v.end(), greater<int>());
	
	for (int i = 0, j = 1; i < n; i++, j += 2) {
		result += v[j];
	}
	
	cout << result << "\n";
	
	return 0;
}


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

map<string,int> s;
struct node{
    string x;
    int f;
}xx[200005];
bool cmp(node a,node b){
    return a.x<b.x;
}

int main(){
    int n,mmax=0;
    string ss;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>xx[i].x;
        xx[i].f=1;
        s[xx[i].x]++;
        mmax=max(mmax,s[xx[i].x]);
    }
    sort(xx+1,xx+n+1,cmp);
    for(int i=1;i<=n;i++){
        if(s[xx[i].x]==mmax){
            s[xx[i].x]=-1;
            cout<<xx[i].x<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 28288
n=int(input())
say=[]
for i  in range(n):
    qq=[]
    for i in range(int(input())):
        qq.append(list(map(int,input().split())))
    say.append(qq)
ans=0
for bit in range(1<<n):
    plate=0
    L=[(bit>>i)&1 for i in range(n)]
    for i in range(n):
        if L[i]==0:continue
        for l in say[i]:
            if  L[l[0]-1] != l[1]:
                plate=1;break
        if plate:break
    else:
        ans=max(ans,sum(L))
print(ans)

Measured memory_bytes: 9096
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct range_edge_graph {
    int n;
    struct edge { int to; long long weight;};
    vector<vector<edge>> g;
    
    range_edge_graph(int n_) : n(2*n_) {
        g.resize(n<<2);
        for (int i = 1; i < n; ++i) {
            int c1 = i<<1|0, c2 = i<<1|1;
            g[i].push_back({c1, 0});
            g[i].push_back({c2, 0});
            g[c1+2*n].push_back({i+2*n, 0});
            g[c2+2*n].push_back({i+2*n, 0});
        }
        for (int i = n; i < 2*n; ++i)
            g[i].push_back({i+2*n, 0});
    }

    // from [l1, r1) to [l2, r2)
    void add_edge(int l1, int r1, int l2, int r2, long long w) {
        int id = g.size();
        l1 += n, r1 += n;
        while (l1 < r1) {
            if (l1 & 1) g[l1+2*n].push_back({id, 0}), l1++;
            if (r1 & 1) --r1, g[r1+2*n].push_back({id, 0});
            l1 >>= 1, r1 >>= 1;
        }
        vector<edge> node;
        l2 += n, r2 += n;
        while (l2 < r2) {
            if (l2 & 1) node.push_back({l2++, w});
            if (r2 & 1) node.push_back({--r2, w});
            l2 >>= 1, r2 >>= 1;
        }
        g.push_back(node);
    }

    vector<long long> dijkstra(int s) {
        s += n;
        vector<long long> dist(g.size(), numeric_limits<long long>::max());
        dist[s] = 0;
        using P = pair<long long, long long>;
        priority_queue<P, vector<P>, greater<P>> que;
        que.emplace(0, s);
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            for (edge& e : g[v]) {
                if (dist[e.to] > dist[v] + e.weight) {
                    dist[e.to] = dist[v] + e.weight;
                    que.emplace(dist[e.to], e.to);
                }
            }
        }
        vector<long long> res(dist.begin() + n, dist.begin() + 2*n);
        return res;
    }
};

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

    int n, m;
    cin >> n >> m;
    range_edge_graph g(n);

    for (int i = 0; i < m; ++i) {
        int l, r, c;
        cin >> l >> r >> c;
        l--; r--;
        g.add_edge(l, r+1, l, r+1, c);
    }
    auto dist = g.dijkstra(0);
    long long ans = dist[n-1];
    cout << (ans == numeric_limits<long long>::max() ? -1 : ans) << endl;
}

Measured memory_bytes: 114888
package main

import "fmt"

func Min(a []int) (min int) {
	for i, v := range a {
		if i == 0 {
			min = v
			continue
		}
		if min > v {
			min = v
		}
	}
	return
}

func Max(a []int) (max int) {
	for i, v := range a {
		if i == 0 {
			max = v
			continue
		}
		if max < v {
			max = v
		}
	}
	return
}

func main() {
	n := make([]int, 3)
	fmt.Scan(&n[0], &n[1], &n[2])
	fmt.Println(Min(n), Max(n))
}



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

int main(){
    
    long int n,a,b,c,d;
    cin >> n >> a >> b;

    c = a+b;

    if(a == 0){
        cout << 0 << endl;
    }else if(b == 0){
        cout << n << endl;
    }else if(n < c){
        if(a>n){
            cout << n << endl;
        }else{
            cout << a << endl;
        }
    }else{
        d = n - (c*(n/c));
        if(d > a){
            cout << (a*(n/c))+a << endl;
        }else{
            cout << (a*(n/c))+d << endl;
        }
        
    }
    return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int K, N;
    cin >> K >> N;
    int A[N];
    for(int i=0; i<N;i++){
        cin >> A[i];
    }
    int dist = A[0] + K - A[N-1];
    for(int i=0; i<N-1;i++){
        if(A[i+1] - A[i] > dist){
            dist = A[i+1] - A[i];
        }
    }
    cout << K - dist << "\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll n; cin>>n;
  ll a[n], b[n];
  rep(i, n) cin>>a[i];
  rep(i, n) {
    b[a[i]-1]=i;
  }
  rep(i, n) cout << b[i]+1 << " ";
}

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

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

	long long x[N], y[N], z[N], array[N], max = 0, tmp = 0;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}
	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < N; j++) {
			array[j] = (1 - 2 * (i / 4)) * x[j] + (1 - 2 * ((i / 2) % 2)) * y[j] + (1 - 2 * (i % 2)) * z[j];
		}
		sort(array, array + N);
		tmp = 0;
		for (int j = 0; j < M; j++) {
			tmp += array[N - 1 - j];
		}
		if (max < tmp) {
			max = tmp;
		}
	}
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,m = map(int, stdin.readline().rstrip().split())
h = list(map(int, stdin.readline().rstrip().split()))

#michi = [[0] * n for i in range(n)]

good = [1]*n

for i in range(m):
    a,b = map(int, stdin.readline().rstrip().split())
    if h[a-1] < h[b-1]:
        good[a-1] = 0
    elif h[a-1] > h[b-1]:
        good[b-1] = 0
    else:
        good[a-1] = good[b-1] = 0

print(good.count(1))


Measured memory_bytes: 20124
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(n){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n,m=get_i
a=array(n,n)
b=array(m,m)
n.times do|i|
  a[i]=get_nsp
end
m.times do|i|
  b[i]=get_nsp
end

def incl?(a,b,x,y,n,m)
  m.times do|i|
    m.times do|j|
      next_x=x+j
      next_y=y+i
      return false unless (i<m and j<m and next_x<n and next_y<n and a[next_y][next_x]==b[i][j])
    end
  end
  return true
end
flag=false
n.times do|i|
  n.times do|j|
    if a[i][j]==b[0][0]
      flag=incl?(a,b,j,i,n,m)
      if flag
        break
      end
    end
  end
  break if flag
end
puts yn_judge(flag)

Measured memory_bytes: 2044
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

#if __has_include("debug.hpp")
#include "debug.hpp"
#else
template<typename T>
void debug(T& obj) {}
#endif

//----------------------------------------------------------------------
void solve() {

	ll n;
	cin >> n;
	vector<ll> vec(n);
	rep(i,n) cin >> vec[i];

	bool flag = true;
	rep(i,n) {
		if (vec[i]%2==0 && (vec[i]%3!=0 && vec[i]%5!=0)) {
			flag = false;
			break;
		}
	}

	if (flag) {
		cout << "APPROVED";
	} else {
		cout << "DENIED";
	}
}
//----------------------------------------------------------------------

int main(int argc, char* argv[]) {
	solve();
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
 
  if ((a*b)%2 == 0 ) {
    cout << "Even" << endl;
  }

  else if ((a*b)%2 != 0){
    cout << "Odd" << endl;
  }
  
}

Measured memory_bytes: 256
#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 vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 pb push_back
#define pp 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;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int x,n;
    cin >> x >> n;
    vi p(n);
    rep(i,n){
        cin >> p[i];
    }
    int i=0;
    bool flg = false;
    while(true){
        int tmp = x+i;
        rep(i,n){
            if(p[i]==tmp){flg=true;break;}
        }
        if(!flg){cout << tmp << endl;return 0;}
        flg = false;
        i = abs(i);
        tmp =x+i;
        rep(i,n){
            if(p[i]==tmp){flg=true;break;}
        }
        if(!flg){cout << tmp << endl;return 0;}
        i = -1*i;
        i--;
        flg = false;
    }   


    return 0;
}

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

using namespace std;

int main(){
  cout << fixed << setprecision(12);
  int n;
  double x[100],y[100];
  double D1=0,D2=0,D3=0,Dm=0;

  cin >> n;

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

  for(int j=0;j < n;j++)
    {
      D1 += abs(x[j]-y[j]);
    }
  for(int j=0;j < n;j++)
    {
      D2 += pow((x[j]-y[j]),2);
    }
  for(int j=0;j < n;j++)
    {
      D3 += pow(abs(x[j]-y[j]),3);
    }
  Dm =0;
  for(int j=0;j < n;j++)
    {
      Dm = max(Dm,abs(x[j]-y[j]));
    }

  cout << D1 << endl;
  cout << sqrt(D2) << endl;
  cout << pow(D3,1.0/3) << endl;
  cout << Dm << endl;

  return 0;
}



Measured memory_bytes: 3360
#include <iostream>
#include <vector>
#include <unordered_set>
#include <set>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

using ll = long long;
const ll INF = 1e18 + 1;





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

    ll n;
    cin >> n;

    if (n%1000 == 0) {
        cout << 0 << endl;
    } else {
        cout << 1000 - n%1000 << endl;
    }
}

Measured memory_bytes: 3192
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     .      '                    Udit Gupta @luctivud         ,              
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            ##     ##  #######  # #  ######
                            ##     ##  ##   ##  ###    ##
                            ##     ##  ##    #  # #    ##
                            #########  #######  # #    ##
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

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

const long long int MODPRIME {1000000007};
const long long int BABYMOD  {998244353};
const long int MAXN = (long int) 1e6;

#define LUCILLE_IS_THIRSTY()       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define TESTCASES()                long long int TestCases; cin>>TestCases; while(TestCases--)
#define mems(arr,val)              memset((arr), val, sizeof((arr)))
#define endl                       "\n"

inline int readint() {
	int res = 0; char c = 0;
	while(!isdigit(c)) c = getchar();
	while(isdigit(c)) res = res*10+c-'0', c = getchar();
	return res;	
}
// /////////////////////////////////////////////////////////////////////////////////////////////
//                         : ALL THE HELPER FUNCTIONS USED IN THE PROGRAM :                   //
// /////////////////////////////////////////////////////////////////////////////////////////////


// /////////////////////////////////////////////////////////////////////////////////////////////
//                                     : MAIN STARTS HERE :                                   //
// /////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
    long long int x;
    cin >> x ;
    cout << ((x / 500) * 1000) + (((x % 500) / 5) * 5) ;
    cout << endl;
    return;
}

signed main() {
    LUCILLE_IS_THIRSTY();
    // TESTCASES()
        solve();
    return 0;
}
/*
THE LOGIC AND APPROACH IS BY ME @luctivud.
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
: DO NOT PLAGIARISE.
*/

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

int main(){
  int N,Alice=0,Bob=0,Answer=0;
  cin >> N;
  vector<int>a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0; i<N; i+=2){
    Alice += a.at(i);
    if(i+1<N)
   	 Bob += a.at(i+1);
  }
  Answer=Alice-Bob;
  cout << Answer << endl;
}

Measured memory_bytes: 256
s = input()
flag = True
if s != s[::-1]:
    flag =False

tmp=s[:(len(s)-1)//2:]
#print(tmp, tmp[::-1])
if flag and tmp == tmp[::-1]:
    pass
else:
    flag=False

tmp=s[(len(s)+3)//2-1::]
#print(tmp, tmp[::-1])
if flag and tmp == tmp[::-1]:
    pass
else:
    flag=False

if flag:
    print('Yes')
else:
    print('No')


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int ans = 700;
    REP(i,3){
        char c; cin >> c;
        if(c == 'o') ans += 100;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int arrNM[200];

int main()
{
    string s;
    string t;
    cin>>s>>t;
    int result=0;
    for(int i=0 ; i<s.size() ; i++)
    {
        if(s[i] != t[i])
            result++;
    }


    cout<<result;


    return 0;
}


Measured memory_bytes: 3784
/* ex 9_2
   hangan2020 */

#include <stdio.h>
#include <stdlib.h>
#define SIZE 1000001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
   //追加する分の領域を確保
   node *new = calloc(1, sizeof(node));
   if(new == NULL) exit(1);
   new->elem = elem;
   new->next = *first;
   *first = new;
}

//スタックからデータを取り出す
void pop(node **first){
   char elem;
   node *tmp = *first;
   if(tmp == NULL) exit(1);
   elem = tmp->elem;
   *first = tmp->next;
   //取り出したノードのメモリを解放
   free(tmp);
}

int main(void){
   char cube_input[SIZE]; 
   int i = 0;
   int remove_count = 0;
   node *first = NULL;

   scanf("%s", &cube_input);

   while(cube_input[i] != '\0'){
      // If cube stack is empty, push first cube
      if(first == NULL){
         push(&first, cube_input[i]);
         i++;
      }else{ 
         push(&first, cube_input[i]); 
         // While pushing cube, If the pushed cube is different from the top cube
         // Pop these two cubes
         if(first->elem != first->next->elem){
            pop(&first);
            pop(&first);
            remove_count++;
            remove_count++;
         }
         i++;
      }
   }

   printf("%d", remove_count);

   return 0;

}


Measured memory_bytes: 4884
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int n;
	string s;
	cin>>n>>s;
	
	vvi dp(n+1,vi(n+1,0));
	for(int i=n-1;i>=0;--i){
		for(int j=n-1;j>=0;--j){
			if(s[i]==s[j]) dp[i][j]=dp[i+1][j+1]+1;
		}
	}
	
	int ans=0;
	REP(i,n)REP(j,n) ans=max(ans,min(dp[i][j],abs(i-j)));
	
	cout<<ans<<endl;
}//refering to exp.

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int x;
    cin >> x;
    int res = 0;
    res += (x / 500)*1000;
    x %= 500;
    res += (x / 5) * 5;
    c(res);
}


Measured memory_bytes: 3616
t=int(input())
for count in range(t):
    n=int(input())
    h_list=[int(i) for i in input().split(" ")]
    delta_list=[]
    for i in range(n-1):
        delta_list.append(h_list[i+1]-h_list[i])

    if max(delta_list)>0:
        max_up=max(delta_list)
    else:
        max_up=0

    if min(delta_list)<0:
        max_down=min(delta_list)*(-1)
    else:
        max_down=0

    print("%d %d" %(max_up,max_down))
    

Measured memory_bytes: 7664
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}




int main(){
  int n;
  string s;
  cin >> n >>  s;
  rep(i,s.size()){
    if(s[i]-'A'+n>=26) cout << char(s[i]+(n-26));
    else cout << char(s[i]+n);
  }
  
}


Measured memory_bytes: 256