akhauriyash/Code-Regression huggingface dataset:
def intMap(): return map(int,input().split())
def intList(): return list(map(int, input().split())) #横並びの場合
#def intListVertical(N) [int(input()) for _ in range(N)] #縦並びの場合

a = intList()

for i in range(5):
    if a[i] == 0:
        print(i + 1)


Measured memory_bytes: 9036
#include<stdio.h>
int main()
{
    int b,n,k;
    double a,c;
    scanf("%d",&n);
    k=n;
    if(n%2!=0)
     {
        n=n+1;
     }
    c=n/2;
    a=c/k;
    printf("%.10lf\n",a);
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
const ll mod = 1000000007;

ll pow(ll n, ll k) {
  if(k == 0) {
    return 1LL;
  }
  if(k % 2 == 1) {
    return pow(n, k - 1) * n % mod;
  }
  ll m = pow(n, k >> 1);
  return m * m % mod;
}

ll inv(ll n) {
  return pow(n, mod - 2);
}

int main(void) {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  if(k == 1) {
    cout << 0 << endl;
    return 0;
  }
  sort(a.begin(), a.end());
  ll max = 0, min = 0;
  ll comb = 1;
  rep(i, n - k + 1) {
    if(i != 0) {
      comb = (comb * (k - 1 + i)) % mod;
      comb = (comb * inv(i)) % mod;
    }
    int idxmin = n - k - i;
    ll pmin = a[idxmin] * comb % mod;
    min = (min + pmin) % mod;

    int idxmax = k - 1 + i;
    ll pmax = a[idxmax] * comb % mod;
    max = (max + pmax) % mod;
  }
  ll ans = (max - min) % mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


//変数







//サブ関数
//入力
void input()
{

}


//計算
bool calc(const string s)
{
	vector<int> v;
	for (auto c : s)v.push_back(c - 'A');
	REP(i, (int)s.size() - 1) {
		//同一は除外
		if (v[i] == v[i + 1])return false;
		//→
		if (v[i] % 3 != 2 && v[i] + 1 == v[i + 1])continue;
		//左
		if (v[i] % 3 != 0 && v[i] - 1 == v[i + 1])continue;
		//上
		if (3 <= v[i] && v[i] - 3 == v[i + 1])continue;
		//↓
		if (v[i] < 6 && v[i] + 3 == v[i + 1])continue;
		return false;
	}
	return true;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	REP(i, 1000) {
		string s;
		cin >> s;
		if (calc(s))cout << s << endl;
	}
	output();
	debug();
	
	return 0;
}



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

#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0);
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define V(x) vector<x>
#define P(x,y) pair<x,y>
#define UMP(x,y) unordered_map<x,y>
#define MP(x,y) map<x,y>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define inf 1e18
#define endl "\n"
#define coutd(n) cout << fixed << setprecision(n)
#define watch(x) cout<<#x<<" = "<<x<<endl;
typedef double db;
typedef long double ld;	
const int mod = 1000000007;

using namespace std;

int32_t main(){
    fast
   
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	if(h == 12)
		h = 0;
	double mm= m/5.0;
	mm*=30;
	double hh = m/60;
	hh = (hh + h)*30;
	double angle = min(abs(hh-mm),360-abs(hh-mm));
    coutd(20)<<sqrt(a*a + b*b - 2*a*b*cos(M_PI*angle/180.0));
    return 0;
}

Measured memory_bytes: 4204
s = input()
sr = s[::-1]
s1 = s[:int((len(s)-1) / 2)]
s1r = s1[::-1]
s2 = s[int((len(s)+1) / 2):]
s2r = s2[::-1]
if s1 == s1r and s2 == s2r and s == sr:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=collections.Counter(a)
li=c.most_common()
if len(li)<=k:
  print(0)
  exit()
li=li[k:]
ans=0
for i in li:
  ans+=i[1]
print(ans)

Measured memory_bytes: 39344
import math
a, b, x = map(int, input().split())

if a*a*b / 2 > x:
    h = x / b * 2 / a
    deg = math.atan(h/b)
    deg = math.degrees(deg)
    deg = 90 - deg
else:
    x = a*a*b - x
    h = x / a * 2 / a
    deg = math.atan(h/a)
    deg = math.degrees(deg)
print(deg)

Measured memory_bytes: 9240
n = int(input())
R = []

for i in range(n):
    R.append(int(input()))

R_distance_max = -1000000000
R_min = R[0]

for i in range(1,n):
    R_distance_max = max(R_distance_max,R[i]-R_min)
    R_min = min(R_min,R[i])

print(R_distance_max)


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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n+1);
	rep(i,n) scanf("%lld",&a[i+1]);
	n++;

	priority_queue<pair<lint,int>> Q;
	rep(i,n) Q.emplace(a[i],-i);

	vector<lint> ans(n);
	int cnt=0;
	while(1){
		int i=-Q.top().second; Q.pop();

		if(i==0) break;

		int j;
		vector<int> I={i};
		while(1){
			j=-Q.top().second;
			if(j<i) break;
			Q.pop();
			I.emplace_back(j);
		}

		ans[i]+=(a[i]-a[j])*cnt;
		for(int k:I){
			ans[i]+=a[k]-a[j];
		}
		cnt+=I.size();
	}

	rep(i,n-1) printf("%lld\n",ans[i+1]);

	return 0;
}


Measured memory_bytes: 4464
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  int k;
  cin>>k;
  long long int sum=0;
  for(int a=1;a<=k;a++){
    for(int b=1;b<=k;b++){
      for(int c=1;c<=k;c++){    
        sum+=__gcd(a,__gcd(b,c));
      }
    }
  }
  cout<<sum<<"\n";  
 
  
  return 0;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#define db(x) cout << "> " << #x << " = " \
	<< (x) << '\n'
#define db2(x, y) cout << "> " << #x << " = " \
	<< (x) << ", " << #y << " = " << (y) << '\n'
#define db3(x, y, z) cout << "> " << #x << \
	" = " << (x) << ", " << #y << " = " << \
	(y) << ", " << #z << " = " << (z) << '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mii;
typedef set<int> si;

ll A, B, C, D;

ll f(ll x) {
	return B / x - (A - 1) / x;
}

ll GCD(ll a, ll b){
  return b ? GCD(b, a % b) : a;
}
ll LCM(ll a, ll b){
  return a / GCD(a, b) * b;
}

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin >> A >> B >> C >> D;
	//db3(f(C), f(D), f(LCM(C, D)));
	cout << B - A + 1 - (f(C) + f(D) - f(LCM(C, D))) << '\n';
	return 0;
}


Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())
ok = False
count = 0
while not ok:
    ok = True
    for i in range(N - 1):
        j = N - 1 - i
        if A[j - 1] > A[j]:
            A[j - 1], A[j] = A[j], A[j - 1]
            count += 1
            ok = False
print(*A)
print(count)



Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	string s;
	cin >> s;
	if (s[0] == s[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


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

const long long mod = (long long)(1e9 + 7);
vector<long long> fac(100001, 1);


long long mul(long long a, long long b){
	return ((a%mod)*(b%mod))%mod;
}

void fact(){
	for(long long i=1;i<=100000;i++) fac[i] = mul(fac[i-1], i);
}

long long add(long long a, long long b){
	return (a%mod+b%mod)%mod;
}

long long sub(long long a, long long b){
	return (a%mod-b%mod)%mod;
}
long long pw(long long a, long long b){
	//base case
	if(b == 0) return 1; 
	if(b == 1) return a;
	long long cmp = pw(a, b/2);
	if(b%2) return mul(mul(cmp, a), cmp);
	else return mul(cmp, cmp);
}

long long mulc_inv(long long num){
	return pw(num, mod-2);
}

long long comb(long long n, long long k){
	if(n < k) return 0;
	else{
		long long ans = 1;
		ans = mul(fac[n], mulc_inv(mul(fac[k],fac[n-k])));
		return ans;
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin >> n >> k;
	vector<long long> a(n);
	for(auto &x:a) cin >> x;
	sort(a.rbegin(), a.rend());
	long long ans = 0;
	fact();
	for(int i=0;i<n;i++)
	 ans = add(ans, sub(mul(a[i],comb(n-i-1, k-1)),mul(a[n-i-1], comb(n-i-1, k-1))));
	if(ans < 0) ans += mod;
	cout << ans << "\n";
	//cout << mul(mulc_inv(100),100) << "\n";
	//cout << comb(34738,3434) << "\n";
	//cout << mul(fac[], mulc_inv(k))
	//cout << fac[5] << "\n";
	return 0;
}


Measured memory_bytes: 1792
n = gets.to_i
x, y, h = n.times.map{ gets.split.map(&:to_i) }.select{|_, _, h| h > 0}.transpose
m = x.size

answers = []
[*0..100].product([*0..100]) do |cx, cy|
  ch = m.times.map{|i| h[i] + (x[i] - cx).abs + (y[i] - cy).abs}.uniq
  answers << [cx, cy, *ch] if ch.size == 1
end

puts answers.sort_by{|_, _, h| h}.first.join(" ")

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

constexpr int INF = 2e9;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  int sum = accumulate(a.begin(), a.begin() + n - 1, 0);
  if (a[n - 1] < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
} 

Measured memory_bytes: 256
#import math.sqrt as sqrt

#S = list(map(int, input().split()))
#B = list(map(int, input().split()))

S = list(input())
count = [0, 0, 0]

for i in range(len(S)-1):
    for j in range(i+1, len(S)):
        if S[i] == S[j]:
            count[i] += 1

       # print(S[j]+" "+S[i])

#print(count)

if (count[0]==1 and count[1]==1) or (count[1]==1 and count[2]==1) or (count[2]==1 and count[0]==1):
    print("Yes")
else:
    print("No")


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a + b == c + d) {
    cout << "Balanced" << endl;
  }else if(a + b > c + d) {
    cout << "Left" << endl;
  }else if(a + b < c + d) {
    cout << "Right" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    ios::sync_with_stdio(false);
    vector<Int> res;
    while (true) {
        Int n;
        cin >> n;
        vector<Int> a(n);
        if (n == 0) break;
        for (Int i = 0; i < n; i++) cin >> a[i];
        sort(a.begin(), a.end());
        Int mi = 1e9;
        for (Int i = 0; i < n - 1; i++) mi = min(mi, a[i + 1] - a[i]);
        res.emplace_back(mi);
    }
    for (Int i = 0; i < (Int)res.size(); i++) dump(res[i]);
    return 0;
} 



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N=S.size();
  bool P=true;
  for(int i=0;i<(N-1)/2;i++){
    if(S.at(i)!=S.at(N-1-i)){
      cout << "No" << endl;
      P=false;
      break;
    }
  }
  if(P){
    for(int i=0;i<((N-1)/2)/2;i++){
      if(S.at(i)!=S.at((N-1)/2-1-i)){
        cout << "No" <<endl;
        P=false;
        break;
      }
    }
  }
  if(P){
    cout << "Yes" << endl;
  }
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define hell                         1000000007
#define hell2                        998244353
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define all(v)                       v.begin(),v.end()
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'
 
const ll MAX=200005;
const ll SQN=330;
const ll LG=22;
const double PI=atan(1)*4;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    string s;
    cin >> s;
    if(s=="ABC") ret("ARC");
    ret("ABC");
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

// 文字列から数値へ変換して key を生成する
long long getKey(char str[]) {
  long long sum =0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) %M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str); // より高速なscanfを使用
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 17064
#include <stdio.h>
#include <stdlib.h>
int main() {
  int *a,n,j,i,minj;
  int count=0,tmp=0;
  scanf("%d",&n);
  a=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
      scanf("%d",&a[i]);
  }
  for (i = 0; i < n-1; i++) {
    minj=i;
    for (j = i ; j <n ; j++) {
      if (a[minj]>a[j]) {
        minj=j;}}
        tmp=a[i];
        a[i]=a[minj];
        a[minj]=tmp;
        if (i!=minj) count++;
  }
    for(i=0;i<n;i++){
      if (i!=n-1) printf("%d ",a[i]);
      else printf("%d\n",a[i]);
    }
    printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 2128
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(len(a)):
    count = 0
    while(True):
        if a[i] % 2 == 0:
            count += 1
            a[i] /= 2
        else:
            break
    ans += count


print(ans)


Measured memory_bytes: 4148
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long long X, D, K;
    cin >> X >> K >> D;
    X = abs(X);

    // if K is too small
    if (X / D >= K)
    {
        cout << abs(X - K * D) << endl;
        return 0;
    }

    // if ans is 0 or D
    if (X % D == 0)
    {
        if (abs(X / D - K) % 2 == 0)
        {
            cout << 0 << endl;
            return 0;
        }
        else
        {
            cout << D << endl;
            return 0;
        }
    }

    // if K is large enough

    if (abs(K - X / D) % 2 == 0)
    {
        cout << abs(X - D * (X / D)) << endl;
        return 0;
    }
    if (abs(K - X / D) % 2 == 1)
    {
        cout << abs(X - D * (X / D + 1)) << endl;
        return 0;
    }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll x;
  cin >> x;
  ll n;
  cin >> n;
  vector<bool> exists(102, false);
  REP(i, n) {
    ll p;
    cin >> p;
    exists[p] = true;
  }

  ll ans = -1, diff = 1e18;
  REP(i, 102) {
    if (exists[i]) {
      continue;
    }
    if (abs(i - x) < diff) {
      diff = abs(i - x);
      ans = i;
    }
  }
  cout << ans << endl;
}

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

#define pb push_back
#define ff first
#define ss second

const int MAXN = 2e5 + 21, inf = 1e9 + 10;

int n;
int a[MAXN];
vector <int> b[MAXN];
int now, cnt;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[a[i]].pb(i);
    }

    for (int i = 1; i <= n; i++)
        b[i].pb(inf);

    if (b[1][0] == inf)
        return cout << -1 << '\n', 0;
    
    for (int i = 1; i <= n; i++) {
        int x = lower_bound(b[i].begin(), b[i].end(), now) - b[i].begin();
        if (b[i][x] != inf && b[i][x] > now) {
            cnt++;        
            now = b[i][x];
        }
        else
            break;
    }
    if (cnt == 0)
        return cout << -1 << '\n', 0;
    cout << n - cnt << '\n';
	return 0;
}

Measured memory_bytes: 12788
#include <bits/stdc++.h>
typedef long long TYPE;
const TYPE mod=1E9+7;
const int MAXN=1E3+10;
const int INF=~0U>>1;
const int ud[4]={0,1,0,-1};
const int lr[4]={1,0,-1,0};
int input() {
	int x;scanf("%d",&x);
	return x;
}
int vis[MAXN][MAXN];
int dis[MAXN][MAXN];
char mp[MAXN][MAXN];
struct pair{
	int x,y;
	pair(int a=0,int b=0) {
		x=a;y=b;
	}
};
int main() {
	int N=input();
	int M=input();
	for(int i=1;i<=N;++i) {
		scanf("%s",mp[i]+1);
	}
	memset(dis,63,sizeof dis);
	std::queue<pair>q;
	for(int i=1;i<=N;++i) {
		for(int j=1;j<=M;++j) {
			if(mp[i][j]=='#') {
				q.push(pair(i,j));
				vis[i][j]=1;
				dis[i][j]=0;
			}
		}
	}
	while(!q.empty()) {
		pair o=q.front();q.pop();
		int x=o.x,y=o.y;vis[x][y]=0;
		for(int id=0;id<4;++id) {
			int xx=x+ud[id];
			int yy=y+lr[id];
			if(xx<1||xx>N||yy<1||yy>M)continue;
			if(dis[xx][yy]>dis[x][y]+1) {
				dis[xx][yy]=dis[x][y]+1;
				if(!vis[xx][yy]) {
					vis[xx][yy]=1;
					q.push(pair(xx,yy));
				}
			}
		}
	}
	int ans=0;
	for(int i=1;i<=N;++i) {
		for(int j=1;j<=M;++j) {
			ans=std::max(ans,dis[i][j]);
		}
	}printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 17296
#include <bits/stdc++.h>
using namespace std;
int main () {
    long long n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long ans = 0;
    long long p = 1000000007;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (a[i] > a[j]) ans+=k;
            ans %= p;
        }
    }
    sort(a.begin(), a.end());
    int r = 0;
    for (int i = 1; i < n; i++) {
        if (a[i-1] != a[i]) {
            r = i;
        }
        ans += r * ((((k-1) + 0) * k / 2) % p);
        ans %= p;
    }
    cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d.at(i);
    }
    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());
    int ans = 0;
    int sign = 1;
    for (int i = 0; i < n; ++i) {
        ans += d.at(i) * sign;
        sign *= -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php
	$result = [];
	$i = 0;

	while(true) {
		$stdin = explode(" ", trim(fgets(STDIN)));
		if ($stdin[0] == 0 && $stdin[1] == 0) {
			break;
		}

		$result[$i] = $stdin;
		$i++;
	}

	foreach($result as $value) {
		drawRectangle($value[0], $value[1]);
	}

	function drawRectangle($height, $width) {
		for($i=0; $i<$height; $i++) {
			for($j=0; $j<$width; $j++) {
				echo "#";
			}
			echo PHP_EOL;
		}
		echo PHP_EOL;
	}

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

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

    int64_t ans = 0;
    for(int d=1; d<N; d++){
        int p1 = 0, p2 = N-1;
        int64_t res = 0;
        while(true){
            p1 += d;
            if(p1 == p2) break;
            p2 -= d;
            if(p1 == p2) break;
            if(p1+d > N-1 || p2-d < 0) break;
            res += A[p1] + A[p2];
            ans = max(ans, res);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#define N 25052
#define p 1000000007
#define ll long long
inline int mod(int x){return x<p?x:x-p;}
int a[N],b[N],c[N],i,j,k,m,n,s,t,u,v,x;
inline void _b()
{
    for(memset(b+1,0,k<<2),u=1;!b[a[u]]++;u++);
    for(memset(b+1,0,k<<2),v=m;!b[a[v]]++;v--);
    for(memset(a+1,0,k<<2),memset(b+1,0,k<<2),a[--u]=1,i=0;i<=n-m;i++)for(j=k,s=0;--j;s=mod(s+a[j]),a[j+1]=(a[j+1]+(ll)a[j]*(k-j))%p,a[j]=s)b[i]=mod(b[i]+a[j]);
    for(memset(a+1,0,k<<2),a[v=m-v]=1,i=0;i<=n-m;i++)for(j=k,s=0;--j;s=mod(s+a[j]),a[j+1]=(a[j+1]+(ll)a[j]*(k-j))%p,a[j]=s)c[i]=mod(c[i]+a[j]);
    for(i=0;i<=n-m;i++)x=(x+(ll)(p-b[i])*c[n-m-i])%p;
}
inline void _a()
{
    for(memset(a+1,0,k<<2),memset(b+1,0,k<<2),*a=1,i=0;i<=n;*a=*b=0,i++)for(j=k,s=t=0;j--;s=mod(s+a[j]),t=mod(t+b[j]),a[j+1]=(a[j+1]+(ll)a[j]*(k-j))%p,b[j+1]=(b[j+1]+(ll)b[j]*(k-j))%p,a[j]=s,b[j]=t)if(m<=j)b[j]=mod(a[j]+b[j]);
    for(c[1]=1,i=2;i<=k;i++)c[i]=(ll)(p-p/i)*c[p%i]%p;
    for(i=0;i<m;i++)t=(ll)t*c[k-i]%p;
    x=mod(p+x-t);
}
int main()
{
    scanf("%d%d%d",&n,&k,&m);
    for(i=0,x=n-m+1;i<n-m;i++)x=(ll)x*k%p;
    for(i=1;i<=m;i++)scanf("%d",a+i);
    for(i=1;i<=m;i++)if(s+=!b[a[i]]++,k<i?s-=!--b[a[i-k]]:0,s==k)return 0&printf("%d\n",x);
    for(i=1,memset(b+1,0,k<<2);i<=m&&++b[a[i]]<2;i++);
    return 0&(m<i?_a():_b(),printf("%d\n",x));
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <cstdlib>
using namespace std;
#define pii pair<int,int>
#define ft first
#define sc second
#define INF 1000000006
#define INFLL 4000000000000000006ll
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define gc getchar_unlocked
#define gi(x) while((_c=gc())<'0'); x=_c-'0'; while((_c=gc())>='0') x=x*10+_c-'0';
#define LL long long
#define DB double
#define PARAM int id, int l, int r
#define _L id*2,l,mid
#define _R id*2+1,mid+1,r
#define PREP int mid = (l+r)/2
#define MEMSET(x,y) memset(x,y,sizeof(x));
#define ALL(x) x.begin(),x.end()
#define REP(i,x,y) for(int i = x; i < y; i++ )

int n, m;
int arr[305][305], ptr[305], num[305], use[305];

int main(){
	char _c;
	gi(n) gi(m)
	for(int i = 0; i < n; i++ ){
		for(int j = 0; j < m; j++ ){
			gi(arr[i][j]); arr[i][j]--;
		}
	}
	for(int i = 0; i < n; i++ ) num[arr[i][0]]++;
	int ans = 1000000006;
	while(1){
		// cari yg max
		int mx = 0, mxid = -1;
		for(int i = 0; i < m; i++ ){
			if(use[i]) continue;
			if(num[i] >= mx){
				mx = num[i], mxid = i;
			}
		}
		// printf("now mx %d %d\n",mx,mxid);
		if(mxid==-1) break;
		ans = min(ans,mx);
		// disable mxid
		use[mxid] = 1;
		for(int i = 0; i < n; i++ ){
			while(ptr[i]<m && use[arr[i][ptr[i]]]){
				ptr[i]++;
				if(ptr[i]<m) num[arr[i][ptr[i]]]++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var H,W,h,w int
    fmt.Scan(&H,&W,&h,&w)
    ans := H*W - h*W - w*H + h*w
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

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

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int sum = 0;
		int[] l = new int[N];
		for(int i = 0;i < N;i ++) {
			l[i] = sc.nextInt();
		}
		int x;
		for(int i = 0;i < N;i ++) {
			for(int k = i + 1;k < N;k ++) {
				if(l[i] < l[k]) {
					x = l[i];
					l[i] = l[k];
					l[k] = x;
				}
			}
		}
		for(int i = 0;i < K;i ++) {
			sum = sum + l[i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21972
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j;
            cin>>n;

            int ar[n+1],ar2[n+1],ar3[n+1],x,z,a,b,ans[n+1];
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
            }
            if(n==2)
            {
                cout<<ar[2]<<" "<<ar[1]<<endl;
                return 0;
            }
            ar3[0]=0;
            for(i=1;i<=n;++i)
            {
                if(i%2==0)
                {
                    ar2[i]=ar[i]^ar[i-1];
                }
                else
                {
                    ar2[i]=0;
                }
                ar3[i]=ar3[i-1]^ar2[i];
                // cout<<i<<" "<<ar3[i]<<" "<<ar3[i-1]<<" "<<ar2[i]<<endl;
            }
            for(i=1;i<=n;i=i+2)
            {
                x=0,z=0;
                x=ar3[i-1];
                if(i+1<=n)
                {
                    z=ar3[n]^ar3[i+1];
                }
                // cout<<i<<" "<<x<<" "<<z<<" "<<ar3[i+2]<<" "<<ar3[i+1]<<endl;
                ans[i]=(ar[i+1]^(x^z));
                ans[i+1]=(ar[i]^(x^z));
            }
            for(i=1;i<=n;++i)
                cout<<ans[i]<<" ";
            cout<<endl;
        }
        return 0;
    }


Measured memory_bytes: 6752
s = input()

ans = 0

l, r = 0, len(s)-1
if len(s) != 1:
    while l < r:
        # print("l", l, "r", r)
        if s[l] == s[r]:
            l += 1
            r -= 1
        else:
            if s[l] == "x":
                l += 1
                ans += 1
            elif s[r] == "x":
                r -= 1
                ans += 1
            else:
                ans = -1
                break

print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<28
#define MAX_V 500
struct edge { int to,cap,rev; };

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int> que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e = G[v][i];
      if(e.cap>0&&level[e.to]<0){
	level[e.to]=level[v]+1;
	que.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v==t) return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  for(;;){
    bfs(s);
    if(level[t]<0) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}

int main(){
  int v,e,a,b,c,i;
  cin>>v>>e;
  for(i=0;i<e;i++){
    cin>>a>>b>>c;
    add_edge(a,b,c);
  }
  cout << max_flow(0,v-1) << endl;
  return 0;
}

Measured memory_bytes: 3168
#include<stdio.h>
long max(long*);
long min(long*);
long sum(long*);
int n;
int main(void){
  static long data[10000];
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&data[i]);
  }
  printf("%ld %ld %ld\n",min(data),max(data),sum(data));
  return 0;
}

long max(long *data){
  long a = data[0];
  int i;
  for(i=1;i<n;i++){
    if(a < data[i]){
      a = data[i];
    }
  }
  return a;
}
long min(long *data){
  long a = data[0];
  int i;
  for(i=1;i<n;i++){
    if(a > data[i]){
      a = data[i];
    }
  }
  return a;
}
long sum(long *data){
  int i;
  long s=0;
  for(i=0;i<n;i++){
    s += data[i];
  }
  return s;
}



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
	int x3=x2+y1-y2,y3=y2+x2-x1,x4=x3+y2-y3,y4=y3+x3-x2;
	cout<<x3<<" "s<<y3<<" "s<<x4<<" "s<<y4<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n) for(int i=0;i<(int)(n);i++)
#define repd(i,n) for(int i=(int)(n);i>=0;i--)

int main()
{
    long A,B;
    cin >> A >> B;
    repi(i,1000000001){
        if(abs(A-i) == abs(B-i)){
            cout << i << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" <<endl;
    return 0;
}

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

int main(){
  int N;
  cin>>N;
  
  vector<int> a(N+1);
  for(int i=1;i<=N;i++){
    cin>>a.at(i);
  }
  
  int b=1;
  int j=1;
  while(j<=N){
    b=a.at(b);
    if(b==2){
      cout << j << endl;
      break;
    }
    j++;
  }
  if(j==N+1){
    cout << -1 << endl;
  }
}


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

n = int(input())

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

score = 0
for i in range(n):
    j = a[i]
    score += b[j-1]
    if i >=1 and a[i] - a[i-1] == 1:
        score += c[j-2]
print(score)



Measured memory_bytes: 3064
#include <stdio.h>
#include<stdlib.h>
#include<ctype.h>

typedef long ELEM;
#define STACK_SIZE 100
ELEM stack[STACK_SIZE];
int n;


void init(){
	n = 0;
}

void push(ELEM x){
	stack[n++]=x;
}

ELEM pop(){
	return stack[--n];
}

int empty(){
	return n==0;
}
int main(void) {
	long a,b,x;
	long c;
	
	while((c =getchar())!=EOF){
		if(isdigit(c)){
			ungetc(c,stdin);
			scanf("%ld",&x);
			push(x);
		}else{
		switch(c){
			case'+':
			b=pop();a=pop();
			push(a+b);
			break;
			
			case'-':
			b=pop();a=pop();
			push(a-b);
			break;
			
			case'*':
			b=pop();a=pop();

			push(a*b);
			break;
			
			case'/':
			b =pop();a=pop();
			push(a/b);
			break;
			
			case'\n':
			if(!empty())
			a=pop();
			printf("%ld\n",a);
		
			
			break;
			
			case' ':
			break;
		}
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

struct edge{int to, cost;};

class Graph
{
public:
    int V;
    vector<vector<edge>> G;

    Graph(int V): V(V){
        G = vector<vector<edge>>(V, vector<edge>(0));
    }

    void add_edge(int from, int to, int cost){
        G[from].push_back(edge({to, cost}));
    }

    void add_edge2(int v1, int v2, int cost){
        add_edge(v1, v2, cost);
        add_edge(v2, v1, cost);
    }

    mat waeshall_floyd(){
        mat d2(V, vec(V));
        REP(i, V){
            REP(j, V){
                if(i == j){
                    d2[i][j] = 0;
                }else{
                    d2[i][j] = INF;
                }
            }
        }
        REP(v, V){
            REP(i, G[v].size()){
                edge e = G[v][i];
                d2[v][e.to] = e.cost;
            }
        }
        REP(k, V){
            REP(i, V){
                REP(j, V){
                    d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
                }
            }
        }
        return d2;
    }

};

signed main(){

    int N, M; cin >> N >> M;
    Graph G(N);
    vec a(M), b(M), c(M);
    REP(i, M){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        G.add_edge2(a[i], b[i], c[i]);
    }
    mat d = G.waeshall_floyd();
    int ans = 0;
    REP(i, M){
        if(d[a[i]][b[i]] < c[i]) ans++;
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define int long long

using namespace std;


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


const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

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

	return ans;
}




signed main() {
	int N, M;
	string S, T;
	cin >> N >> M;
	cin >> S >> T;

	int g = gcd(N, M);
	int a = N / g;
	int b = M / g;
	bool ok = true;
	if (a >= b) {
		REP(i, M / b) {
			if (S[a*i] != T[b*i]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			cout << a * b*g << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
	if (a < b) {
		REP(i, N / a) {
			if (S[a*i] != T[b*i]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			cout << a * b*g << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
	return 0;
}




Measured memory_bytes: 512
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<iomanip>
using namespace std;

int main() {

	double r, a, b;

	cin >> r;

	a = r*r*M_PI;
	b = (double)2 * r*M_PI;

	cout <<fixed << setprecision(6) << a <<fixed <<setprecision(6)<< " " << b << endl;

}

Measured memory_bytes: 3256
def main():
  X = int(input())
  ans = 0
  while True:
    if 0 <= X - 500:
      X = X - 500
      ans += 1000
    elif 0 <= X - 5:
      X = X - 5
      ans += 5
    else:
      break
  print(ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 38384
n=int(input())
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  edge[a].append((b,c))
  edge[b].append((a,c))
from heapq import heappop,heappush
def dijkstra(s,n,edge):
  inf=10**20
  ans=[inf]*n
  ans[s]=0
  root=[-1]*n
  h=[[0,s]]
  while h:
    c,v=heappop(h)
    if ans[v]<c:continue
    for u,t in edge[v]:
      if c+t<ans[u]:
        ans[u]=c+t
        root[u]=v
        heappush(h,[c+t,u])
  return ans
q,k=map(int,input().split())
xy=[list(map(int,input().split()))for _ in range(q)]
d=dijkstra(k-1,n,edge)
for x,y in xy:
  print(d[x-1]+d[y-1])

Measured memory_bytes: 74316
//submitted by Himj
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;

const int mxn=2e5+1;
vector<int> graph[mxn];
int vis[mxn];
int dfs(int u)
{
  if(vis[u])
    return vis[u];
  vis[u]=1;
  int mx=0;
  for(auto v:graph[u])
    mx=max(mx,dfs(v));
  return vis[u]=mx+1;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

  int t=1;
  //cin>>t;
    while(t--){
      ms(vis,0);
      int n,m,i,u,v;
      cin>>n>>m;
      fr(i,0,m)
      {
        cin>>u>>v;
        graph[u].pb(v);
       
    }
    int ans=0;
    fr(i,1,n+1)
    {
      if(vis[i]==0)
      ans=max(ans,dfs(i));
      }
      cout<<ans-1;
    }
  return 0;
  }



Measured memory_bytes: 10880
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_set>
using namespace std;

int k;
double r, l , p, e, t;

double calc(int n, double lb, double ub) {
	if (n == k) {
		if (abs(t-(lb+ub)/2) <= e) return 1.0;
		else return 0.0;
	}
	if (ub < t-e or t+e < lb) return 0.0;
	if (t-e <= lb and ub <= t+e) return 1.0;
	double res = 0.0;
	double h = (lb + ub) / 2;
	if (h >= t) {
		res += (1-p)*calc(n+1, lb, h);
		res += p*calc(n+1, h, ub);
	} else {
		res += p*calc(n+1, lb, h);
		res += (1-p)*calc(n+1, h, ub);
	}
	return res;
}

int main() {
	cin >> k; cin >> r; cin >> l; cin >> p; cin >> e; cin >> t;
	printf("%.14f\n", calc(0, r, l));
}

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

void Main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> points(N, vector<int>(D));
  for (int i=0; i<N; ++i) {
    for (int j=0; j<D; ++j) cin >> points[i][j];
  }

  int ans = 0;
  for (int i=0; i<N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      int d = 0;
      for (int x = 0; x<D; ++x) {
        int p = (points[i][x] - points[j][x]);
        d += p*p;
      }
      if (sqrt(d) == floor(sqrt(d))) ++ans;
    }
  }
  cout << ans << "\n";
}

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


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

using mint = modint998244353;
using vm = vector<mint>;

void out(vm a) {
  rep(i,a.size()) printf("%d ", a[i].val());
  puts("");
}

int main() {
  int n;
  cin >> n;
  int n2 = n*2;
  vector<int> a;
  {
    map<int,int> mp;
    rep(i,n2) {
      int h;
      cin >> h;
      mp[h]++;
    }
    for (P p : mp) a.push_back(p.second);
  }
  
  vm f(n2+1);
  vm invf(n2+1);
  vm f2(n+1);
  {
    f[0] = 1;
    rep(i,n2) f[i+1] = f[i]*(i+1);
    invf[n2] = 1/f[n2];
    for (int i = n2; i >= 1; --i) invf[i-1] = invf[i]*i;
    f2[0] = 1;
    rep(i,n) f2[i+1] = f2[i]*(i*2+1);
  }

  int m = a.size();
  vector<vm> d(m);
  rep(i,m) {
    int na = a[i];
    int e = na/2;
    d[i] = vm(e+1);
    rep(j,e+1) {
      d[i][j] = f[na]*invf[j*2]*invf[na-j*2]*f2[j];
    }
    // out(d[i]);
  }

  while (d.size() > 1) {
    vector<vm> p;
    swap(d,p);
    for (int i = 0; i < p.size(); i += 2) {
      int j = i+1;
      if (j >= p.size()) {
        d.emplace_back(p[i]);
        break;
      }

      d.emplace_back(convolution(p[i],p[j]));
    }
  }

  mint ans;
  rep(i,d[0].size()) {
    mint now = d[0][i]*f2[n-i];
    if (i%2 == 1) ans -= now;
    else ans += now;
  }
  cout << ans.val() << endl;
  return 0;
}

Measured memory_bytes: 12688
#include <iostream>
#include <vector>
#include <climits>
#include <functional>
#include <map>
#include <algorithm>
using namespace std;

using ll = long long;
template<class T> using vec = vector<T>;

template<typename Monoid>
class SegmentTree{
private:
    using F = function<Monoid(Monoid,Monoid)>;
    int sz;
    vector<Monoid> seg;
    const F op;//演算
    const Monoid e;//単位元
public:
    SegmentTree(){}
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    //代入
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    //前計算(?)
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] = max(seg[k],x);
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
};

struct Q{
    ll l,r,col;
    bool operator<(const Q& q)const{
        if(l!=q.l) return l<q.l;
        else if(r!=q.r) return r<q.r;
        else return col<q.col;
    }
};

struct Compress{
    map<ll,int> idx;
    map<int,ll> value;
    vector<ll> cmp;
    int N;
    Compress(vector<ll> v){
        for(auto& x:v) cmp.push_back(x);
        sort(cmp.begin(),cmp.end());
        cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
        N = cmp.size();
        for(int i=0;i<N;i++) idx[cmp[i]] = i;
    }
    int id(ll val){return idx[val];}
    ll val(int id){return cmp[id];}
};

int main(){
    ll N,M,X,Y;
    cin >> N >> M >> X >> Y;
    vec<Q> q(M);
    for(int i=0;i<M;i++){
        ll l,r,c;
        cin >> c >> l >> r;
        c--;
        q[i] = {l,r,c};
    }
    sort(q.begin(),q.end());
    vec<ll> v = {0};
    for(auto& x:q){
        v.push_back(x.l); v.push_back(x.r);
    }
    Compress cmp(v);
    int n = cmp.N;
    ll inf = 1e18;
    SegmentTree<ll> seg(n,[](ll a,ll b){return max(a,b);},-inf);
    vec<SegmentTree<ll>> segs;
    for(int i=0;i<7;i++){
        segs.push_back(seg);
        if(i==6) segs[i].set(0,0);
        segs[i].build();
    }
    ll ans = 0;
    for(auto& x:q){
        int l = cmp.id(x.l),r = cmp.id(x.r);
        ll val = segs[6].query(0,l)+(x.r-x.l+1)*X;
        for(int c=0;c<3;c++){
            if(x.col==c) continue;
            val = max(val,segs[c].query(l,r)+(x.l+x.r-1)*X+(x.l-1)*Y);
        }
        val = max(val,segs[x.col+3].query(l,r)+x.r*X);
        ans = max(ans,val);
        segs[6].update(r,val);
        segs[x.col].update(r,val-x.r*(2*X+Y));
        segs[x.col+3].update(r,val-x.r*X);
    }
    cout << ans << endl;
}


Measured memory_bytes: 120844
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=="?":break
    if op=="+":
        print(int(a+b))
    elif op=="-":
        print(int(a-b))
    elif op=="*":
        print(int(a*b))
    elif op=="/":
        print(int(a/b))




Measured memory_bytes: 5596
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Scanner;
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Collection;


 
public class Main{
	
        static final Scanner sc=new Scanner(System.in);
        
        
        
        
        
        
        public static void main(String[]args){
                int A=sc.nextInt();
                int B=sc.nextInt();
                if((A%2==0)||(B%2==0)){
                        System.out.println("No");
                }else{
                        System.out.println("Yes");
                }
                
                
                


                
        }
        
        
        

		
	
}


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

int main(){
  int N;
  cin >> N;
  int ans = 0;
  vector<int> A(N);
  vector<int> B(N - 1);
  for(int i = 0; i < N - 1; i++){
    cin >> B.at(i);
  }
  for(int i = 0; i < N; i++){
    if(i == 0){
      A.at(i) = B.at(i);
      ans += A.at(i);
    }
    else if(i == N - 1){
      A.at(i) = B.at(i - 1);
      ans += A.at(i);
    }
    else{
      A.at(i) = min(B.at(i), B.at(i - 1));
      ans += A.at(i);
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

	IO; 

	string s;
	cin >> s;
	
	ll x=0;
	for (int i = 0; i < (int) s.size(); ++i) {
		x += s[i] -'0';
	}
	
	if (x%9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

/*
int tt;
	cin >> tt;
	while (tt--) {
	
		
	}
*/


Measured memory_bytes: 3736