akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
import sys
sdin = sys.stdin.readline

class UnionFind:
    def __init__(self, node:int) -> None:
        self.n = node
        self.par = [i for i in range(self.n)]
        self.rank = [0 for i in range(self.n)]
        
    def find(self, x:int) -> int:
        if x == self.par[x]:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def unite(self, x:int, y:int) -> bool:
        if self.isSame(x,y):
            #print("x and y has already united")
            return False
        
        rx = self.find(x)
        ry = self.find(y)
        
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = self.par[ry]
        else:
            self.par[ry] = self.par[rx]
            
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1
                
        return True
    
    def isSame(self, x:int, y:int) -> bool:
        return self.find(x) == self.find(y)

    

        
N, M = map(int, sdin().split())
P = list(map(int, sdin().split()))
XY = []
for i in range(M):
    XY.append(list(map(int, sdin().split())))


root_node = defaultdict(list)

uf = UnionFind(N)
for x,y in XY:
    x -= 1
    y -= 1
    uf.unite(x,y)

for i in range(N):
    uf.find(i)
    
par = uf.par

for i,root in enumerate(par):
    root_node[root].append(i)
    
ans = 0
for node_list in root_node.values():
    num_list = []
    for i in node_list:
        num_list.append(P[i]-1)
    
    ans += len(set(node_list)&set(num_list))
            
print(ans)


Measured memory_bytes: 56228
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>a;
    sum+=a/2;
    if(a%2) sum++;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3644
program V802;
 var
  a,b,c:array[0..501,0..501] of char;
  i,j,m,n:longint;
 begin
  readln(n,m);
  for i:=1 to n do
   begin
    for j:=1 to m do
     read(a[i,j]);
    readln;
   end;
  for i:=1 to n do
   for j:=1 to m do
    if (i mod 2=0) and (j<>m) then b[i,j]:='#'
                              else b[i,j]:='.';
  for i:=1 to n do
   b[i,1]:='#';
  for i:=1 to n do
   for j:=1 to m do
    if (i mod 2=1) and (j<>1) then c[i,j]:='#'
                              else c[i,j]:='.';
  for i:=1 to n do
   c[i,m]:='#';
  for i:=1 to n do
   begin
    for j:=1 to m do
     if a[i,j]='#' then write(a[i,j])
                   else write(b[i,j]);
    writeln;
   end;
  writeln;
  for i:=1 to n do
   begin
    for j:=1 to m do
     if a[i,j]='#' then write(a[i,j])
                   else write(c[i,j]);
    writeln;
   end;
 end.


Measured memory_bytes: 1280
def main():
    R = int(input())
    G = int(input())

    for x in range(-9 * 10 ** 3, 9 * 10 ** 3 + 1):
        if R + x == G * 2:
            print(x)
            return

    print(-1)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  ll ans = min(X, Y) * 2 * C;
  int tmX = X - ans / 2 / C, tmY = Y - ans / 2 / C;
  ll ans1=ans + max(tmX, 0) * A + max(tmY, 0) * B;//併用
  ll ans2 = max(X, Y) * 2 * C;//全C
  ll ans3 = A * X + Y * B;//Cなし
  ans = 0;
  ans = min(ans1, ans2);
  ans = min(ans, ans3);
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

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

int main(){
	ll N,A,B; cin>>N>>A>>B;
  
  printf("%lld",min(N*A,B));
    
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t,i,j,k,l,m,n,a[200005],b[200005];
    char s[200005];
    long long count=0,sum=0,count1=0;
    map<long long,long long>mp;
    for(i=0;i<5;i++)
    cin>>a[i];
    int ans=1000;
    for(i=0;i<5;i++)
    {
        k=a[i]%10;
        if(k==0)
        continue;
        ans=min(k,(long long)ans);
    }
    if(ans==1000)
    {
        for(i=0;i<5;i++)
        {
            if(a[i]%10==0)
            sum=sum+a[i];
            else
            {
                j=a[i]%10;
                j=10-j;
                sum=sum+a[i]+j;
            }
        }
    }
    else
    {
        for(i=0;i<5;i++)
        {
            if(a[i]%10==0)
            sum=sum+a[i];
            else
            {
                j=a[i]%10;
                j=10-j;
                sum=sum+a[i]+j;
            }
        }
        sum=sum-(10-ans);
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	if n%2 == 1 {
		fmt.Println(0)
		return
	}

	ans := 0
	n /= 2
	for n > 0 {
		ans += n / 5
		n /= 5
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    rep(i, 6) {
        if (s[i] == '1') ans++;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3580
from collections import deque
import sys
input = lambda: sys.stdin.readline().rstrip()

H, W = map(int, input().split())

c_list = []

for i in range(10):
    c = list(map(int, input().split()))
    c_list.append(c)


for k in range(10):
    for i in range(10):
        for j in range(10):
            c_list[i][j] = min(c_list[i][j], c_list[i][k] + c_list[k][j])

ans = 0
for i in range(H):
    A = list(map(int, input().split()))
    for j in range(W):
        if A[j] != 1 and A[j] != -1:
            ans += c_list[A[j]][1]

print(ans)

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

        using namespace std;

        #define pb push_back
        #define mp make_pair
        #define fr first
        #define sc second

        typedef long long int lli;

        lli h, a, ans;

        int main(){
            cin>>h>>a;
            ans = h/a;
            if(h%a)
                ans++;
            cout<<ans<<endl;
            return 0;
        }


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

using Gragh = vector<vector<int>>;
using pint = pair<int,int>;

int N, M;
Gragh G;
int s, t;

long long solve(){
    vector<vector<long long>> dist(N, vector<long long>(3, -1));
    dist[s][0] = 0;
    queue<pint> que;
    que.push({s,0});
    while(!que.empty()){
        pint cur = que.front(); que.pop();
        int v = cur.first;
        int parity = cur.second;
        for(auto nv: G[v]){
            int np = (parity + 1) % 3;
            if(dist[nv][np] == -1){
                dist[nv][np] = dist[v][parity] + 1;
                que.push({nv, np});
            }
        }
    }
    if(dist[t][0] == -1) return -1;
    else return dist[t][0] / 3;
}

int main(){
    cin >> N >> M;
    G.assign(N, vector<int>());
    for(int i = 0; i < M; i++){
        int u, v; cin >> u >> v; --u, --v;
        G[u].push_back(v);
    }
    cin >> s >> t;
    --s, --t;
    cout << solve() << endl;
}

Measured memory_bytes: 11136
#A, Bの読みとり
num = input()
Num = num.split()
a = int(Num[0])
b = int(Num[1])

#郵便番号の読みとり
ad = input()
A = ad[:a]
s = ad[a]
B = ad[a+1:]

Alist = list(A)
Blist = list(B)

i = 0
j = 0
ca = "f"
cb = "f"
for i in range(10):
    for j in range(a):
        #print(i,Alist[j])
        if str(i) == Alist[j]:
            ca = "t"
            break
    if ca == "t":
        break
for i in range(10):
    for j in range(b):
        #print(i,Blist[j])
        if str(i) == Blist[j]:
            cb = "t"
            break
    if cb == "t":
        break

if ad[a] == "-" and ca == "t" and cb == "t":
    Al = len(A)
    Bl = len(B) 

    if a == Al and b == Bl :
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <map>

using namespace std;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	int a[n];
	map <int,int> mm;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mm[a[i]]++;
	}
	long long res = 0,fac,f2;
	for(map<int,int>::iterator it = mm.begin(); it!=mm.end();it++){
		fac = it->second;
		res = res + fac * (fac-1) /2;
	}
	for(int i=0;i<n;i++){
		fac = mm[a[i]];
		f2 = fac-1;
		fac = fac * (fac-1)/2;
		f2 = f2 * (f2-1) / 2;
		cout<<(res-fac+f2)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define vp vector <pi>
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1n(x,n) for(int x = 1; x <= n ;++ x)
#define forn1(x,n) for(int x = 1; x < n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize ("Ofast")
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int main(){
	IOS

	string s,t;
	cin>>s>>t;
	int c=0;
	forn(i,s.size())
		if(s[i]==t[i])
			c++;
	cout<<c;
 
	return 0;	
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();

        if(A<=C && C<=B){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			String a = in.next();
			char[] num = a.toCharArray();
			if(num[0] == '0')break;
			int A = 0,B = 0;
			for(int i = 1;i < num.length;i++){
				if(num[i] == 'A'){
					A++;
				}else{
					B++;
				}
			}
			if(A > B)A++;
			else B++;
			System.out.println(A+" "+B);
		}
	}
}

Measured memory_bytes: 17124
#include<stdio.h>
int main(){
  double s,l;
  int rs,rl,r;
  double S[]={35.5,37.5,40.0,43.0, 50.0, 55.0, 70.0};
  double L[]={71.0,77.0,83.0,89.0,105.0,116.0,148.0};
  while(scanf("%lf %lf",&s,&l)!=EOF){
    for(rs=0;rs<7;rs++){
      if(S[rs]>s)break;
    }
    for(rl=0;rl<7;rl++){
      if(L[rl]>l)break;
    }
    if(rs>rl)r=rs;
    else     r=rl;
    if(r==0)     printf("AAA\n");
    else if(r==1)printf("AA\n");
    else if(r==2)printf("A\n");
    else if(r==3)printf("B\n");
    else if(r==4)printf("C\n");
    else if(r==5)printf("D\n");
    else if(r==6)printf("E\n");
    else         printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 608
import java.util.*;
import java.util.Arrays;
import java.util.Set;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        if(N==1){
            System.out.println(1);
        }
        if((N>1)&&(N<4)){
            System.out.println(2);
        }
        if((N>3)&&(N<8)){
            System.out.println(4);
        }
        if((N>7)&&(N<16)){
            System.out.println(8);
        }
        if((N>15)&&(N<32)){
            System.out.println(16);
        }
        if((N>31)&&(N<64)){
            System.out.println(32);
        }if(N>63){
            System.out.println(64);
        }
        }
        
        
    }


Measured memory_bytes: 21844
import math
N,K=map(int, input().split())
p=20
count=0
ans=0
for i in range(N):
  if (i+1)>=K:
    count+=1
  else:
    for j in range(20):
      if (i+1)*math.pow(2,j)>=K:
        ans+=math.pow(1/2,j)
        break
    
  
if N<K:
    print(1/N*ans)
else:
    print(count/N+1/N*ans)

Measured memory_bytes: 3064
import sys
class Dice:
    def __init__(self, f):
        self.f = f[:]

    def roll(self, s):
        for f in s:
            n = self.f[:]
            if f == 'E':
                t = n[0]
                n[0] = n[3]
                n[3] = n[5]
                n[5] = n[2]
                n[2] = t
            elif f == 'W':
                t = n[0]
                n[0] = n[2]
                n[2] = n[5]
                n[5] = n[3]
                n[3] = t
            elif f == 'N':
                t = n[0]
                n[0] = n[1]
                n[1] = n[5]
                n[5] = n[4]
                n[4] = t
            else:
                t = n[0]
                n[0] = n[4]
                n[4] = n[5]
                n[5] = n[1]
                n[1] = t
            self.f = n

    def to_top(self, index):
        if index == 1:
            self.roll('N')
        elif index == 2:
            self.roll('W')
        elif index == 3:
            self.roll('E')
        elif index == 4:
            self.roll('S')
        elif index == 5:
            self.roll('NN')
        return self

    def side_roll(self):
        t  = self.f[1]
        self.f[1] = self.f[2]
        self.f[2] = self.f[4]
        self.f[4] = self.f[3]
        self.f[3] = t
        return self

    def all_face(self):
        faces = []
        for i in range(0,6):
            t = Dice(self.f[:])
            faces.append(t.to_top(i).f[:])
            for j in range(3):
                faces.append(t.side_roll().f[:])
        return faces

n = int(input())
ds = list(Dice(list(input().split())) for _ in range(n))
e = False
for i, d in enumerate(ds):
    for d2 in ds[i+1:]:
        if d.f in d2.all_face() : e = True 
print('No' if e else 'Yes')

Measured memory_bytes: 7860
N,W=map(int,input().split())
List=[list(map(int,input().split())) for i in range(N)]
w,v=zip(*List)
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
  for j in range(W+1):
    if j-w[i]>=0:
      dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
    dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(max(dp[N]))

Measured memory_bytes: 121068
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int N;
const int MAX_N = 2 * int(1e5);
ll a[MAX_N], dp[MAX_N];

void solve() {
    ll ans = ll(5) * INF;
    REP(i, N - 1) ans = min(ans, abs(dp[i] - (dp[N - 1] - dp[i])));
    cout << ans << endl;
}

int main() {
    cin >> N;
    REP(i, N) {
        cin >> a[i];
        if (i == 0) dp[0] = a[0];
        else dp[i] = dp[i - 1] + a[i];
    }
    solve();
    return 0;
}

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

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

const int MAXN = 2e5;

int n;
char s[MAXN+10];
ll ans;

int main()
{
    int i, j;

    scanf("%s", s+1);

    n=strlen(s+1);
    int cnt=0;
    i=1;
    while(i<=n)
    {
        if(s[i]=='A')
        {
            i++;
            cnt++;
        }
        else if(i!=n && s[i]=='B' && s[i+1]=='C')
        {
            i+=2;
            ans+=cnt;
        }
        else
        {
            i++;
            cnt=0;
        }
    }
    printf("%lld", ans);
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;
void extgcd(int a, int b, int& x, int& y) {
	if (b != 0) {
		extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else {
		x = 1;
		y = 0;
	}
}

int mod_inverse(int a, int p) {
	int x, y;
	extgcd(a, p, x, y);
	return (p + x % p) % p;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	map<int, int> mp;
	for (int i = 0; i < N; i++) {
		int t = A[i];
		for (int j = 2; j * j <= t; j++) {
			if (t % j == 0) {
				int cnt = 1;
				t /= j;
				while (t % j == 0) {
					t /= j;
					cnt++;
				}
				mp[j] = max(mp[j], cnt);
			}
		}
		if (t > 1) {
			mp[t] = max(mp[t], (int)1);
		}
	}
	int g = 1;
	for (auto m : mp) {
		for (int t = 0; t < m.second; t++) {
			g = (g * m.first) % MOD;
		}
	}
	for (int i = 0; i < N; i++) {
		res = (res + g * mod_inverse(A[i], MOD)) % MOD;
	}
	cout << res << endl;
}

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

template<class T> inline vector<pair<T, T> > primeFactorize(T n) {
    vector<pair<T, T> > res;
    for (T a = 2; a * a <= n; a++) {
        if (n % a != 0) continue ;
        T ex = 0;
        while (n % a == 0) {
            ++ex;
            n /= a;
        }
        res.push_back({a, ex});
    }
    if (n != 1) res.push_back({n, 1});
    return res;
}

int main() {
    cin.tie(0)->sync_with_stdio(false);

    ll n, p; cin >> n >> p;

    ll ans = 1;
    if (n == 1) ans = p;
    else {
        auto res = primeFactorize(p);
        for (auto x : res) {
            if (x.second >= n)
                ans *= pow(x.first, (x.second / n));
        }
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
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>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(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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(){
  ll H,W,N;
  cin>>H>>W>>N;
  ll A[N];
  REP(i,N) cin>>A[i];
  
  ll S[H*W],it=0;
  REP(i,N){
    while(A[i]>0){
      S[it]=i+1;
      it++;
      A[i]--;
    }
  }
  
  ll C[H][W];
  REP(i,H){
    REP(j,W){
      C[i][j]=S[i*W+j];
    }
  }
  
  REP(i,H){
    REP(j,W){
      if(i%2==0) cout<<C[i][j]<<" ";
      else cout<<C[i][W-1-j]<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
#define ll long long
#define     f           first
#define     s           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)

int n,m,ok[N];
set<int>v[N];
vector<int> temp;
void dfs(int x){
    int cnt=1;
    ok[x]=1;
    temp.pb(x);
    for(int u:v[x]) if(!ok[u]) dfs(u);
}
int main()
{
   cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        v[a].insert(b);
        v[b].insert(a);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(!ok[i])
        {
            temp.clear();
            dfs(i);
            int k=temp.size();
            ans=max(ans,k);
        }
    }
    cout<<ans;

 // getch();
    return 0;
}

Measured memory_bytes: 42428
n = int(input())
a = list(map(int, input().split()))
diff = []
for i, index in enumerate(a,1):
    diff.append(i-index)

diff.sort()
if n % 2 == 1:
    b = diff[n // 2]
    tmp = map(lambda x: x - b, diff)
    print(sum( map(abs,tmp )))
else:
    b1 = diff[n // 2 - 1]
    b2 = diff[n // 2]
    tmp1 = map(lambda x: x - b1, diff)
    tmp2 = map(lambda x: x - b2, diff)
    ans1 = sum( map(abs,tmp1 ))
    ans2 = sum( map(abs,tmp2 ))
    print(min(ans1,ans2))

Measured memory_bytes: 26020
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    string str;
    int ret=0;
    vector<pair<char,int> > v;
    cin >> str;

    int cnt=1;
    char tmp=str[0];
    for(int i=1;i<str.size();++i){
        if(str[i] == tmp){
            cnt++;
        }else{
            v.push_back(make_pair(tmp,cnt));
            cnt=1;
            tmp = str[i];
        }
    }
    v.push_back(make_pair(tmp,cnt));
    for(int i=0;v.size() >=3 && i<v.size()-2;++i){
        if(v[i].first == 'J' &&
           v[i+1].first == 'O' &&
           v[i+2].first == 'I'){
            if(v[i].second >= v[i+1].second &&
               v[i+2].second >= v[i+1].second){
                ret = max(ret, min(v[i].second, min(v[i+1].second,v[i+2].second)));
            }
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 9932
#include<iostream>

using namespace std;

int main(){
  long A,B,C,A2,B2,C2;
      cin>>A>>B;              //外部入力読み込み方法
   A2=A;
   B2=B;
   C=A%B;
  while (C!=0){
   
    A=B;
    B=C;
    C=A%B;
    
   }  
  
  C2=A2*B2/B;

  cout<<C2;
 return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();

        long ab = a+b;
        long tmp = n/ab;
        long tmp2 = n-ab*tmp;

        if (tmp2 >= a) System.out.println(a*tmp+a);
        else System.out.println(a*tmp+tmp2);
    }
}

Measured memory_bytes: 22612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] D = new int[3];
            D[0] = int.Parse(str[0]);
            D[1] = int.Parse(str[1]);
            D[2] = int.Parse(str[2]);
            int[] d = new int[3];

            int ans = 0;
            if(D[0] % 2 == 1 || D[1] % 2 == 1 || D[2] % 2 == 1)
            {
                Console.WriteLine("0");
            }
            else if (D[0] == D[1] && D[1] == D[2]) Console.WriteLine("-1");
            else
            {
                while (0 == (D[0] % 2 + D[1] % 2 + D[2] % 2))
                {
                    ans++;
                    d[0] = (D[1] + D[2]) / 2;
                    d[1] = (D[0] + D[2]) / 2;
                    d[2] = (D[0] + D[1]) / 2;
                    D[0] = d[0];
                    D[1] = d[1];
                    D[2] = d[2];
                }
                Console.WriteLine(ans);
            }
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>

int main(){
int n,t,a;
scanf("%d",&n);
scanf("%d %d",&t,&a);
int h[n];
double m[n],mi[n];
double min = 999;
int count,i;
for(i = 1;i < n + 1;i++){
scanf("%d",&h[i]);
m[i] = t - h[i] * 0.006;
if(m[i] > a)
	mi[i] = m[i] - a;
else
	mi[i] = a - m[i];
if(min > mi[i]){
	min = mi[i];
	count = i; 
}
}
printf("%d",count);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;


#define F0R(i, a) for (int i=0; i<(a); i++)
#define sz(x) (int)(x).size()
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    string S; cin >> S;

    int count[2];
    count[0] = 0;
    count[1] = 0;
    int lastPair = -1;
    char cur = 'R';
    int N = sz(S);
    int ans[N]; F0R(i, N) ans[i] = 0;
    F0R(i, N) {
        if (S[i] == cur) {
            count[i%2]++;
        } else {
            if (S[i] == 'L') {
                lastPair = i-1;
                ans[lastPair] += count[lastPair%2];
                ans[lastPair+1] += count[(lastPair+1)%2];
            } else {
                ans[lastPair] += count[lastPair%2];
                ans[lastPair+1] += count[(lastPair+1)%2];
            }
            count[0] = 0;
            count[1] = 0;
            count[i%2]++;
            cur = S[i];
        }

    }

    ans[lastPair] += count[lastPair%2];
    ans[lastPair+1] += count[(lastPair+1)%2];

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

    return 0;
}

Measured memory_bytes: 1104
nums = gets.split(' ')
f = 0;
s = 0;
nums.each {|n|
  if (n=='5')
      f = f+1
  end
  if(n =='7')
      s = s + 1;
  end
}

if f == 2 && s == 1
    puts 'YES'
else
    puts 'NO'
end

Measured memory_bytes: 1788
def main():

    n=int(input())
    p=list(map(int,input().split()))

    cnt=0
    for i in range(n-2):
        
        tmp=[p[i],p[i+1],p[i+2]]
        tmp.sort()
        if p[i+1]==tmp[1]:
            cnt+=1
    print(cnt)




if __name__=='__main__':
    main()

Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize);
    // let mut n = n - 1;
    let mut n = n;
    let mut ret = "".to_owned();
    while n > 0 {
        let ci = ((n - 1) % 26) as u8;
        let c: char = (b'a' + ci).into();
        ret = c.to_string() + &ret;
        n = (n - ci as usize) / 26;
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2128
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s = input()
n = len(s)
for i in range(n-1):
  for j in range(i,n):
    if s[0:i] + s[j:n] == "keyence":
      print("YES")
      exit()
print("NO")

Measured memory_bytes: 38640
#include <iostream>
#include <cmath>
#include <cstdio>

#define MAXN 200000
#define MAX 100000000000

using namespace std;

typedef long long ll;

int A[MAXN];
ll B[MAXN];
int N;

ll min4 ( ll P, ll R, ll Q, ll S )
{
  ll mmin = min(P,R);
  ll mmax = max(P,R);
  mmin = min(mmin,Q);
  mmax = max(mmax,Q);
  mmin = min(mmin,S);
  mmax = max(mmax,S);

  return abs(mmax-mmin);
}


int main()
{
  ll ans = MAX;
  int l, r;
  ll P,R,Q,S;
  ll min = MAX;

  cin >> N;
  for ( int i = 0; i < N; ++i ) scanf("%d", &A[i]);

  B[0] = A[0];
  for ( int i = 1; i < N; ++i ) B[i] = B[i-1]+A[i];
  l = 0;
  r = 2;
  for ( int i = 1; i < N-2; ++i ) {
    ll Lmin = MAX;
    ll Rmin = MAX;

    for ( int j = l; j < i; ++j ) {
      P = B[j];
      Q = B[i]-B[j];
      if ( abs(P-Q) < Lmin ) {
        Lmin = abs(P-Q);
        l = j;
      }
      if ( P >= Q ) break;
    }

    for ( int j = r; j < N-1; ++j ) {
      R = B[j]-B[i];
      S = B[N-1]-B[j];
      if ( abs(R-S) < Rmin ) {
        Rmin = abs(R-S);
        r = j;
      }
      if ( R >= S ) break;
    }

    P = B[l]; Q = B[i]-B[l];
    R = B[r]-B[i]; S = B[N-1]-B[r];
    ll tmp = min4(P,Q,R,S);
    if ( ans > tmp ) ans = tmp;
  }

  cout << ans << endl;


}


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

#define FI freopen("in.txt","r",stdin);
#define FO freopen("out.txt","w",stdout);

using namespace std;

int main()
{
    string s;

    while(cin>>s)
    {
        s[3]='8';

        cout<<s<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
local n = io.read("*n", "*l")
local str = io.read()
local t = {}
for i = 1, n do
  t[i] = str:sub(i, i) == "o"
end
local found = false
for c = 1, 4 do
  local res = {}
  res[1] = c <= 2
  res[2] = c % 2 == 1
  for i = 3, n do
    if res[i - 1] then
      if t[i - 1] then
        res[i] = res[i - 2]
      else
        res[i] = not res[i - 2]
      end
    else
      if t[i - 1] then
        res[i] = not res[i - 2]
      else
        res[i] = res[i - 2]
      end
    end
  end
  local cand1 = false
  if res[n] then
    if t[n] then
      cand1 = res[n - 1]
    else
      cand1 = not res[n - 1]
    end
  else
    if t[n] then
      cand1 = not res[n - 1]
    else
      cand1 = res[n - 1]
    end
  end
  local cand2 = false
  if res[1] then
    if t[1] then cand2 = res[n] else cand2 = not res[n] end
  else
    if t[1] then cand2 = not res[n] else cand2 = res[n] end
  end
  if res[1] == cand1 and res[2] == cand2 then
    for k = 1, n do
      io.write(res[k] and "S" or "W")
    end
    io.write("\n")
    found = true
    break
  end
end
if not found then print(-1) end


Measured memory_bytes: 5852
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var n = long.Parse(Console.ReadLine());

        var pf = PrimeFactorization(n);

        StringBuilder builder = new StringBuilder($"{n}:");
        foreach(var item in pf)
        {
            for (int i = 0; i < item.Value; i++)
                builder.Append($" {item.Key}");
        }

        Console.WriteLine(builder.ToString());
    }

    public static Dictionary<long, long> PrimeFactorization(long n)
    {
        var result = new Dictionary<long, long>();

        for(long i = 2; i * i <= n; i++)
        {
            if (n % i != 0) continue;
            long exponents = 0;

            // 割り続ける
            while (n % i == 0)
            {
                exponents++;
                n /= i;
            }

            result[i] = exponents;
        }

        // 素数が残っている場合
        if (n != 1) result[n] = 1;
        return result;
    }
}


Measured memory_bytes: 17964
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	LL n,m;
	int i,j,k;
	LL a,b,c;
	cin>>n;
	if(n%2==1){
		cout<<0<<endl;
		return 0;
	}
	for(a=0;n>0;){
		n/=5;
		a+=n/2;
	}
	cout<<a<<endl;
}

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

int main() {
	vector<vector<int>> c(3, vector<int>(3));
	for (vector<int>& i : c) {
		for (int& j : i) cin >> j;
	}
	int i;
	for (i = 1; i < 3; ++i) {
		if (c[0][i - 1] - c[0][i] != c[1][i - 1] - c[1][i] || c[1][i - 1] - c[1][i] != c[2][i - 1] - c[2][i]) break;
	}
	if (3 == i) {
		for (i = 1; i < 3; ++i) {
			if (c[i - 1][0] - c[i][0] != c[i - 1][1] - c[i][1] || c[i - 1][1] - c[i][1] != c[i - 1][2] - c[i][2]) break;
		}
		if (3 == i) cout << "Yes";
		else cout << "No";
	}
	else cout << "No";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    { 
        static void Main(string[] args)
        {
            string s =Console.ReadLine();

            int sec = int.Parse(s);

            int hour = sec / 3600;
            int min = (sec % 3600) / 60;
            int sec_out = sec % 60;

            Console.WriteLine(hour + ":" + min + ":" + sec_out);


        }
    }
}

Measured memory_bytes: 19944
import itertools
N = int(input())
xy = [tuple(map(int, input().split()))for i in range(N)]
ans = []
for p in itertools.permutations(range(N)):
    dist = 0
    for i, pi in enumerate(p):
        if i == 0:
            pre_x, pre_y = xy[pi]
            continue
        x, y = xy[pi]
        dist += ((pre_x - x)**2 + (pre_y - y) ** 2)**0.5
        pre_x, pre_y = x, y
    ans.append(dist)
print(sum(ans) / len(ans))

Measured memory_bytes: 43740
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

map<char, vector<int> > num;

int main()
{
	int N, ans = 0;
	vector<int>::iterator it1, it2;
	string S;

	cin >> N >> S;

	for (char c = '0'; c <= '9'; c++) num[c].resize(0);

	rep(i, N) {
		num[S[i]].push_back(i);
	}

	for (char i = '0'; i <= '9'; i++) {
		if (num[i].size() == 0) continue;
		for (char j = '0'; j <= '9'; j++) {
			if (num[j].size() == 0) continue;
			for (char k = '0'; k <= '9'; k++) {
				int in, jn;

				if (num[k].size() == 0) continue;

				in = num[i][0];

				it1 = upper_bound(num[j].begin(), num[j].end(), in);
				if (it1 == num[j].end()) continue;
				jn = *it1;

				it2 = upper_bound(num[k].begin(), num[k].end(), jn);
				if (it2 == num[k].end()) continue;

				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
import math
import itertools

N,D = (int(x) for x in input().split())

X_arr = []
for _ in range(N):
    X_arr.append([int(x) for x in input().split()])

ans = 0
for Y,Z in itertools.combinations(X_arr, 2):
    r2 = sum([(y-z)**2 for y,z in zip(Y,Z)])
    if round(math.sqrt(r2))**2 == r2:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
    GAME_OVER;
}

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

int n;
map <vector<int>,int> mp;
void permutation(vector <int> j,vector <int> k){
  if(j.size()==n)mp[j]=mp.size();
  else{
    rep(i,k.size()){
      //cout << "mp:" << mp.size() << endl;
      vector <int> jnext = j;
      jnext.push_back(k[i]);
      vector <int> knext = k;
      knext.erase(knext.begin()+i);
      permutation(jnext,knext);
    }
  }
}

int main(){
  cin >> n;
  vector <int> p(n);
  rep(i,n)cin >> p[i];
  vector<int> q(n);
  rep(i,n)cin >> q[i];
  vector<int> f(n,1);
  rep(i,n)f[i]+=i;
  permutation({},f);
  cout << abs(mp[p]-mp[q]) << endl;
}


Measured memory_bytes: 5248
from collections import defaultdict

N = int(input())
A = list(map(int,input().split()))

C = defaultdict(int)

ans = 0
sumA = 0
for a in [0]+A:
    sumA += a
    C[sumA] += 1
    if C[sumA] >=2:
        ans += C[sumA]-1
    
print(ans)

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

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

    cout<<min(c,b/a)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    int S, W;
    cin>>S>>W;
    if(S<=W) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}



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

ll t,l,h,x,y,p,q,mid;

ll chk(ll m)
{
	return (p*m>=x && q*m-p*m>=y-x);
		
}

int main()
{
	
	ll x;
	cin>>x;
	ll ans=0;
	ans+=1000*(x/500);
	ans+=((x%500)/5)*5;
	cout<<ans<<endl;

}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int x;
  cin >> x;
  if (x == 3 || x == 5 || x == 7) YESNO;
}
#endif


Measured memory_bytes: 3640
#include <algorithm>
#include <bitset>
#include <boost/algorithm/string/replace.hpp>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define OUT(s) cout << s << endl;
#define IN(a) cin >> a;
#define PACK(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define LIST(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cout << "[" << i << "] " << a[i] << endl;

int main() {
  // input
  int N;
  IN(N);
  int W[N];
  PACK(W, N);

  int S[N];
  S[0] = W[0];
  for (int i = 1; i < N; i++) {
    S[i] = S[i - 1] + W[i];
  }
  int sum = S[N - 1];
  int least = 100;
  for (int i = 0; i < N; i++) {
    least = min(least, abs((sum - S[i]) - S[i]));
  }

  // output
  OUT(least);
}

Measured memory_bytes: 256
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut a: Vec<usize> = sc.read_vec(n);
    a.sort();

    let mut low = 0;
    let mut high = n;
    while high - low > 1 {
        let mid = (low + high) / 2;
        let check = is_needed(&a, mid, k);
        if is_needed(&a, mid, k) {
            high = mid;
        } else {
            low = mid;
        }
    }

    if is_needed(&a, 0, k) {
        println!("0");
    } else {
        println!("{}", low + 1);
    }
}

fn is_needed(a: &Vec<usize>, mid: usize, k: usize) -> bool {
    if a[mid] >= k {
        return true;
    }

    let mut ok = vec![false; k + 1];
    ok[0] = true;

    for i in 0..a.len() {
        if i == mid {
            continue;
        }
        for j in (0..k).rev() {
            if j + a[i] > k {
                continue;
            }
            if ok[j] {
                ok[j + a[i]] = true;
            }
        }
    }

    for i in 0..k {
        if ok[i] && i + a[mid] >= k {
            return true;
        }
    }
    return false;
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
n = int(input())
a = list(map(int,input().split()))
b1 = a[::2]
b2 = a[1::2]
if n%2==1:
    for i in range(len(b1)):
        print(b1[-i-1],end=' ')
    for i in range(len(b2)):
        print(b2[i],end=' ')
    print('')
else:
    for i in range(len(b2)):
        print(b2[-i-1],end=' ')
    for i in range(len(b1)):
        print(b1[i],end=' ')
    print('')


Measured memory_bytes: 26180
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define dd double
using namespace std;
const ll MOD = 1e9 + 7; 
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n=5;
  int i;
  int a[n];
  for(i=0;i<n;i++){
  	cin>>a[i];
  }
  int b[n];
  for(i=0;i<n;i++){
  	if(a[i]%10!=0){
	  int p=(a[i]/10)*10+10;
	  int s=p-a[i];
	  b[i]=s;	
	  }
	 else{
	 	b[i]=0;
	 } 
	 
  }
  
  
 // for(i=0;i<n;i++){
  //	cout<<a[i]<<" ";
  //}
  
  //cout<<endl;
  //for(i=0;i<n;i++){
  	//cout<<b[i]<<" ";
  //}
  
  //cout<<endl;
  pair<int,int>p[n];
  for(i=0;i<n;i++){
  	p[i]=make_pair(b[i],a[i]);
  }
  
  //for(i=0;i<n;i++){
  	//cout<<p[i].first<<" "<<p[i].second<<endl;
  //}
  
  sort(p,p+n);
  //cout<<endl;
   //for(i=0;i<n;i++){
  	//cout<<p[i].first<<" "<<p[i].second<<endl;
  //}
  
  int s=0;
  for(i=0;i<n-1;i++){
  	s=s+p[i].first+p[i].second;
  	
  }
  
  s=s+p[n-1].second;
  cout<<s<<endl;
  
  
  return 0;
}

Measured memory_bytes: 3624