akhauriyash/Code-Regression huggingface dataset:
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(min(x//500, a)+1):
    for j in range(min((x-i*500)//100, b)+1):
        if x-i*500-j*100<=50*c:
            ans += 1
print(ans)

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

int num;
int Qdata;
int ans;
int k;
int i;
int j;
int data[2010] = {1};

int main(){
  scanf("%d",&num);

  for(i = 0;i < num;i++){
    scanf("%d",&ans);

    for(j = 2000;j >= 0;j--){
      if(j + ans < 2001 && data[j]){
        data[j + ans] = 1;
      }
    }
  }
    scanf("%d",&Qdata);

    for(i = 0;i < Qdata;i++){
      scanf("%d",&k);
      puts(data[k]?"yes":"no");
    }
  return 0;
}



Measured memory_bytes: 2052
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, S := ReadInt(), ReadString()
	if N%2 == 1 {
		fmt.Println("No")
		return
	}
	i := 0
	j := N / 2
	for j < N {
		if S[i] != S[j] {
			fmt.Println("No")
			return
		}
		i++
		j++
	}
	fmt.Println("Yes")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
n = gets.chomp.to_i

f = []
n.times do
    f << gets.chomp.split(" ").join.to_i(2)
end

p = []
n.times do
    p << gets.chomp.split(" ").map(&:to_i)
end

cnt = []
for i in 0..1023
    cnt << i.to_s(2).split("").count{|i| i == "1"}
end

ans = nil
for i in 1..1023
    sum = 0
    n.times do |j|
        sum += p[j][cnt[f[j] & i]]
    end
    ans = sum if ans == nil || ans < sum
end
puts ans



Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define MAX 105
#define int long long int
using namespace std;
double dp[3005][3005];

int32_t main()
{
    int n;
    cin>>n;
    double p[n];
    for(int i=0; i<n; i++)
        cin>>p[i];
    dp[0][0] = 1.0;
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<=i; j++)
        {
            if(j)
                dp[i][j]+=p[i-1]*dp[i-1][j-1];
            dp[i][j]+=(1-p[i-1])*(dp[i-1][j]);
        }
    }
    double ans = 0;
    for(int i=0; i<=n; i++)
        if(i>n-i)
            ans+=dp[n][i];
    printf("%.12f\n", ans);
    return 0;
}


Measured memory_bytes: 49952
n=int(input())
l=list(map(int,input().split()))
d=[0]*(10**5+1)
for i in l:
   d[i]+=1
s=list(set(l))
m=len(s)
k=0
for i in range(m):
    k=max(d[s[i]-1]+d[s[i]]+d[s[i]+1],k)
print(k)


Measured memory_bytes: 94384
def judge_include(w,h,x,y,r):
    if x - r < 0:
        return False
    if x + r > w:
        return False
    if y - r < 0:
        return False
    if y + r > h:
        return False
    return True


if __name__ == "__main__":
    w, h, x, y, r = map(int, input().split())
    if judge_include(w,h,x,y,r):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 5600
#include <stdio.h>
int c(char *p,int d){return ((26+*p-*(p+1))%26==d);}
int a(char *p){return((*p>'`')&&(*p<'{'));}
char *d(char *inbuf, int s) {
  char *p=inbuf-1;
  while (*++p){
    if(a(p)){
      //      int t = *p + s;
      *p+=s;
      if ((unsigned char)*p>'z') *p-=26;
      else if (*p<'a') *p+=26;
    }
  }
  return (inbuf);
}

main(s){
  char b[82];
  while(fgets(b,80,stdin)){
    char *p=b-1;s=0;
    while(*++p){
      if((c(p,12))&&((c(p+1,3)&&!a(p+3))||(c(p+1,7)&&c(p+2,7)&&!a(p+4))||(c(p+1\
,25)&&c(p+2,16)&&!a(p+4)))){s='t'-*p;p+=3;break;}
      else for(;a(p);p++);}
    printf("%s",d(b, s));
  }
}

Measured memory_bytes: 524
#include <stdio.h>
#include <map>
using namespace std;
int main(){
  int N;
  map<int, int> mii;
  scanf("%d", &N)+1;
  int tmp;
  for (int i=0; i<N; i++){
    scanf("%d", &tmp)+1;
    mii[tmp-1] = i+1;
  }
  for (int i=0; i<N; i++){
    printf("%d", mii[i]);
    if (i != N-1) printf(" ");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 5504
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();
        long[] list = new long[N];
        long min = Long.MAX_VALUE;
        long max = 0;
        for (int i = 0; i < N; i++) {
            list[i] = scanner.nextLong();
            min = Math.min(min, list[i]);
            max = Math.max(max, list[i]);
        }
        System.out.println(max - min);
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21460
#include<cstdio>
#include<cstring>

using namespace std;

int num[100010];
int main()
{
	int n, m;
	while(~scanf("%d%d", &n, &m))
	{
		memset(num, 0, sizeof num);
		for(int i=1;i<=m;i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			num[a]++;
			num[b]++;
		}
		bool flag = 1;
		for(int i=1;i<=n;i++)
		{
			if(num[i]%2 != 0)
			{
				flag = 0;
				break;
			}
		}
		if(flag)
		printf("YES\n");
		else 
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

void print(char s, int n){
    FOR(i, 0, n) cout << s;
}

int main(void){
    int sx, sy, tx, ty;
    cin>>sx>>sy>>tx>>ty;
    int dx = tx - sx;
    int dy = ty - sy;
    print('U', dy);
    print('R', dx);
    print('D', dy);
    print('L', dx+1);
    print('U', dy+1);
    print('R', dx+1);
    print('D', 1);
    print('R', 1);
    print('D', dy+1);
    print('L', dx+1);
    print('U', 1);
    cout << endl;
}

Measured memory_bytes: 256
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[] x = new int[n];
      for(int i = 0;i < n;i++)x[i]=sc.nextInt();
      int min = 1000000000;
      for(int i = 0;i <= n-k;i++){
      	int r = x[i+k-1];
        int l = x[i];
        min = Math.min(min,Math.min(Math.abs(r-l)+Math.abs(r),Math.abs(r-l)+Math.abs(l)));
      }
      System.out.println(min);
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}


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

typedef long long ll;

using namespace std;

const int maxn = 1e5 + 10, mod = 1e9 + 7;
ll dp[maxn][2], pd[maxn];
vector<int> adj[maxn];

void dfs(int u = 1, int p = 1)
{
    for (int v : adj[u])
        if (v != p)
            dfs(v, u), dp[u][0] = (dp[u][0] * (dp[v][1] + dp[v][0])) % mod,
                       dp[u][1] = (dp[u][1] * (dp[v][0] + pd[v])) % mod, pd[u] = (pd[u] * dp[v][0]) % mod;
}

int main()
{
    int n;
    cin >> n;

    for (int i = 1, u, v; i < n; i++)
        cin >> u >> v, adj[u].push_back(v), adj[v].push_back(u);

    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= 1; j++)
            dp[i][j] = 1;

    dfs();
    cout << (dp[1][0] + dp[1][1]) % mod;

    return 0;
}


Measured memory_bytes: 14976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  string s;
  cin >> s;
  
  rep(i,s.length()){
    if(i%2!=1){
      if(s[i]=='L'){
        cout << "No" << endl;
        return 0;
      }
    }
    else{
      if(s[i]=='R'){
        cout << "No" << endl;
        return 0;
    }
  }
  }
    cout << "Yes" << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,K; cin>>N>>K;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  vi cp(N+1),dp(N+1),bp(N+1),ap(N+1);
  rep(i,0,N) bp[i+1]=max(0ll,A[i])+bp[i];
  REP(i,1,N) cp[N-i]=max(0ll,A[N-i])+cp[N-i+1];
  rep(i,0,N) ap[i+1]=ap[i]+A[i];
  int ans=0;
  REP(i,K,N){
    int X=max(0ll,ap[i]-ap[i-K]);
    ans=max(ans,X+bp[i-K]+cp[i]);
  }
  cout<<ans<<endl;
  }



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

int main() {

  long long a,b,c,k;
  cin>>a>>b>>c>>k;
  int r;
      r=a+b;
      if(a>=k) {
        if(a>k) cout<<k<<endl;
        else
            cout<<k<<endl;
      }
    else if(r>=k){
           cout<<a<<endl;
      }
      else{
         r=k-r;
           cout<<a-r<<endl;
      }
  return 0;
}


Measured memory_bytes: 3596
n,a,b = input().split()
a,b = int(a),int(b)

n_len = len(n)

tmp=ttmp=sum=0

for i in range(1,int(n)+1):
    tmp_len = len(str(i))
    ttmp = 0

    for j in range(tmp_len):
        tmp = str(i)[j]
        ttmp = ttmp + int(tmp)

    if ttmp >= a and ttmp <=b : 
        sum = sum + i

print(sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
void YesNo(bool);
void YESNO(bool);


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


void YesNo(bool x){
    if (x) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

void YESNO(bool x){
    if (x) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    ll n, cnt = 0;
    string s,ans;
    cin >> n;
    vector<string>ab,a, b, o;
    rep(i, n) {
        cin >> s;
        rep(i, s.size() - 1)if (s.substr(i, 2) == "AB")cnt++;
        if (s[0] == 'B' && s[s.size() -1] == 'A')ab.push_back(s);
        else if (s[s.size() - 1] == 'A')a.push_back(s);
        else if (s[0] == 'B')b.push_back(s);
        else o.push_back(s);
    }
    if (ab.size() == 0)cout << cnt + min(a.size(), b.size()) << endl;
    else if (a.size() + b.size() == 0)cout << cnt + ab.size() - 1 << endl;
    else cout << cnt + min(a.size(), b.size()) + ab.size() << endl;
    return 0;
}

Measured memory_bytes: 768
#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>;

// i<j
// j-i = a[i]+a[j]
// a[i]+i = j-a[j]

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int,int>mp;
    ll ans = 0;
    rep(i,n) {
        int sa = i-a[i];
        int wa = a[i]+i;
        ans += mp[sa];
        mp[wa]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 21088
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	s = readline() |> chomp
    k = readline() |> parseInt
    l = length(s)
    z = Int[123-Int(s[i]) for i in 1:l]
    for i in 1:l
        if z[i] < 26 && k>=z[i]
            k -= z[i]
            z[i] = 26
        end
    end
    if k > 0
        z[l] = rem(z[l]-(k%26),26)
        if z[l] == 0
            z[l] = 26
        end
    end
    for i in 1:l
        print(Char(123-z[i]))
    end
    println("")
end
main()


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    cout << s.substr(0, 3) << endl;
    return 0;
}



Measured memory_bytes: 3572
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    flg = False
    for i in range(a, d):
        if s[i] == "#":
            if s[i + 1] == "#":
                print("No")
                break

        if b - 1 <= i:
            if i + 1 < n:
                if s[i - 1] == s[i] == s[i + 1] == ".":
                    flg = True
    else:
        if c < d:
            print("Yes")
        else:
            if flg:
                print("Yes")
            else:
                print("No")


if __name__ == '__main__':
    resolve()


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

int main(){
	int n,i,p,q,r,a=0,b=0,c=0;
  cin>>n;
  cin>>a>>b>>c;
  for(i=1;i<n;i++){
    cin>>p>>q>>r;
    p+=max(b,c);
    q+=max(a,c);
    r+=max(a,b);
    a=p;
    b=q;
    c=r;
  }
  cout<<max(a,max(b,c))<<"\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	int N;  cin >> N;
	PQG que;
	int ans = 0;
	REP(i, N){
			int input;  cin >> input;
			que.push(input);
			if(input == que.top())  ans += 1;
	}
	cout << ans << endl;

	return 0;
}

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



int main (){ 
    int N, M;
    cin>>N>>M;
    vector<pair<bool, int>> Q(N, pair<bool, int>(false, 0));
    for(int i=0; i<M; i++){
        int A;
        cin>>A;
        A --;
        string B;
        cin>>B;
        if(B=="AC"){
            if(!(Q.at(A).first)){
                Q.at(A).first=true;
            }
        }
        else{
            if(!(Q.at(A).first)){
                Q.at(A).second ++;
            }

        }
    }
    int ClearNum=0;
    int Penalty=0;
    for(int i=0; i<N; i++){
        if(Q.at(i).first){
            ClearNum ++;
            Penalty += Q.at(i).second;
        }
    }
    cout<<ClearNum<<" "<<Penalty;
}



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

#include <cmath>
#include <cstdlib>

using namespace std;

int main(void){
    //
    int n;
    cin >> n;
    if(n%2==0){
        cout << n << endl;
    }else{
        cout << 2 * n << endl;
    }
    return 0;
}

Measured memory_bytes: 888
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

//ll z[1000001]={0};

int main()
{
    /*
    #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    */
    fio;
    string s;
    cin>>s;
    ll e=0;
    forin(i,0,(s.length()-1)/2)
    {
        if(s[i]!=s[s.length()-1-i])
        {
            e++;
        }
    }
    cout<<e<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,s[100];
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>s[i];
        sum+=s[i];
    }
    if(sum%10==0){
        bool check=false;
        sort(s,s+n);
        for(int i=0;i<n;i++){
            if(s[i]%10){
                sum-=s[i];
                check=true;
                break;
            }
        }
        if(check==false)sum=0;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-03-07 21:06:41
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int ans = -1;
    int con = 1;
    for (int p = 1; con; p++) {
        int ta, tb;
        
        ta = 2*p/25;
        tb = p/10;

        if (a == ta && b == tb) {
            ans = p;
            con = 0;
        } else if (a < ta || b < tb) {
            con = 0;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 500;
int k, ans[N][N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> k;
  if(k <= N){
    cout << k << endl;
    FOR(i, 0, k)FOR(j, 0, k) cout << i+1 << (j==k-1 ? '\n' : ' ');
    return 0;
  }
  k -= N;
  cout << N << endl;
  FOR(i, 0, N)FOR(j, 0, N) ans[(i+j)%N][j] = (i<k && j&1) ? i+N : i;
  FOR(i, 0, N)FOR(j, 0, N) cout << ans[i][j]+1 << (j==N-1 ? '\n' : ' ');
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define inp 200005
#define check exit(0)
#define nl cout<<endl;
#define mod 1000000007 
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define deb(v) for(int i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; }
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace __gnu_pbds;
using namespace std;

// Pick yourself up, 'cause...

int main()
{
    jaldi
    
    int k;
    cin>>k;

    string s;
    cin>>s;

    int n=s.length();
    if(n<=k) cout<<s;
    else
    {
        string tmp=s.substr(0,k);
        cout<<tmp+"...";
    }
    

    return 0;
}


Measured memory_bytes: 3644
n=int(input())
ss = []
for i in range(n):
    aa=list(input())
    aa.sort()
    ss.append(aa)
ans = []
for i in range(26):
    ans.append(51)
for i in range(n):
    ans[0] = min(ans[0],ss[i].count('a'))
    ans[1] = min(ans[1],ss[i].count('b'))
    ans[2] = min(ans[2],ss[i].count('c'))
    ans[3] = min(ans[3],ss[i].count('d'))
    ans[4] = min(ans[4],ss[i].count('e'))
    ans[5] = min(ans[5],ss[i].count('f'))
    ans[6] = min(ans[6],ss[i].count('g'))
    ans[7] = min(ans[7],ss[i].count('h'))
    ans[8] = min(ans[8],ss[i].count('i'))
    ans[9] = min(ans[9],ss[i].count('j'))
    ans[10] = min(ans[10],ss[i].count('k'))
    ans[11] = min(ans[11],ss[i].count('l'))
    ans[12] = min(ans[12],ss[i].count('m'))
    ans[13] = min(ans[13],ss[i].count('n'))
    ans[14] = min(ans[14],ss[i].count('o'))
    ans[15] = min(ans[15],ss[i].count('p'))
    ans[16] = min(ans[16],ss[i].count('q'))
    ans[17] = min(ans[17],ss[i].count('r'))
    ans[18] = min(ans[18],ss[i].count('s'))
    ans[19] = min(ans[19],ss[i].count('t'))
    ans[20] = min(ans[20],ss[i].count('u'))
    ans[21] = min(ans[21],ss[i].count('v'))
    ans[22] = min(ans[22],ss[i].count('w'))
    ans[23] = min(ans[23],ss[i].count('x'))
    ans[24] = min(ans[24],ss[i].count('y'))
    ans[25] = min(ans[25],ss[i].count('z'))
ass = ''
ass += 'a'* ans[0]
ass += 'b'* ans[1]
ass += 'c'* ans[2]
ass += 'd'* ans[3]
ass += 'e'* ans[4]
ass += 'f'* ans[5]
ass += 'g'* ans[6]
ass += 'h'* ans[7]
ass += 'i'* ans[8]
ass += 'j'* ans[9]
ass += 'k'* ans[10]
ass += 'l'* ans[11]
ass += 'm'* ans[12]
ass += 'n'* ans[13]
ass += 'o'* ans[14]
ass += 'p'* ans[15]
ass += 'q'* ans[16]
ass += 'r'* ans[17]
ass += 's'* ans[18]
ass += 't'* ans[19]
ass += 'u'* ans[20]
ass += 'v'* ans[21]
ass += 'w'* ans[22]
ass += 'x'* ans[23]
ass += 'y'* ans[24]
ass += 'z'* ans[25]
print(ass)

Measured memory_bytes: 3320
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[][] grid = new int[h][w];
        List<int[]> que = new LinkedList<>(), next = new LinkedList<>();
        for (int i = 0 ; i < h ; i++) {
            char[] s = sc.next().toCharArray();
            for (int j = 0 ; j < w ; j++) {
                if (s[j] == '#') {
                    grid[i][j] = 1;
                    que.add(new int[] {i, j});
                }
            }
        }
        int step = 0;
        int[] dr = {1,0,-1,0};
        int[] dc = {0,1,0,-1};
        while (que.size() > 0) {
            for (int[] x : que) {
                for (int i = 0 ; i < 4 ; i++) {
                    int r = x[0] + dr[i];
                    int c = x[1] + dc[i];
                    if (r >= 0 && r < h && c >= 0 && c < w && grid[r][c] == 0) {
                        next.add(new int[] {r,c});
                        grid[r][c] = 1;
                    }
                }
            }
            step++;
            que = next;
            next = new LinkedList<>();
        }
        System.out.println(step - 1);

    }

}

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

int main(){
	long long int n;
	long long int i;
	long long int max;
	long long int sum[5000];
	long long int t;
	while(cin>>n,n){
		max=0;
		for(i=0;i<n;i++)cin>>sum[i];
		max=-100000;
		for(i=t=0;i<n;i++){
			if(t<0)t=sum[i];else t+=sum[i];
			if(max<t)max=t;
		}
		cout<<max<<endl;
	}
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

int GCD(long long a,long long b){
    if(a>b) swap(a,b);
    if(a==0) return b;
    return(GCD(b%a, a));
}

int main(){
    long long  N,M; cin >> N >> M;
    string S,T; cin >> S >> T;
    long long lens = S.size(); long long lent = T.size();
    long long g = GCD(lens, lent);
    long long ans = lens*lent/g;
    for(int i=0;i<g;i++){
        if(S[i*(lens/g)] != T[i*(lent/g)]) {ans = -1; break;}
    }
    cout << ans << endl;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
struct mint {
    ll x;
    mint(ll x = 0):x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
    // vector size : n + 1
    vector<mint> fact, ifact;
    // precaliculation O(n)
    combination(int n):fact(n+1), ifact(n+1) {
        assert(n < mod);
        // 0! = 1;
        fact[0] = 1;
        // 1! = 0! * 1 ... n! = (n-1)! * n
        for (int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
        // 1/n! = n!^(-1)
        ifact[n] = fact[n].inv();
        // (n-1)!^(-1) = n!^(-1) * n ... 0!^(-1) = 1!^(-1) * 1
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i] * i;
    }
    // combination O(1)
    // nCk = n! / (k! * (n-k)!)
    //     = n! * k!^(-1) * (n-k)!^(-1)
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n-k];
    }
};
/* global variables */
/* function */
/* main */
int main() {
    int n, k;
    cin >> n >> k;
    if (n > k) {
        cout << 0 << '\n';
        return 0;
    }
    mint ans = 1;
    combination c = combination(2000);
    ans = c(k, n);
    cout << ans << '\n';
}


Measured memory_bytes: 3128
#include<stdio.h>
int main(){
    int n;scanf("%d",&n);
    char s[50000];scanf("%s",s);

    int cnt=0,ans=0;
    for(int i=0;i<=9;i++){
        for(int j=0;j<=9;j++){
            for(int k=0;k<=9;k++){
                cnt=0;
                for(int l=0;l<n;l++){
                    switch(cnt){
                        case 0:
                            if(s[l]-'0'==i)cnt++;
                            break;
                        case 1:
                            if(s[l]-'0'==j)cnt++;
                            break;
                        case 2:
                            if(s[l]-'0'==k)cnt++;
                            break;
                    }
                    if(cnt==3)break;
                }
                if(cnt==3)ans++;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
s=input()
if s=='MON':
  print(6)
elif s=='TUE':
  print(5)
elif s=='WED':
  print(4)
elif s=='THU':
  print(3)
elif s=='FRI':
  print(2)
elif s=='SAT':
  print(1)
else:
  print(7)
        

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; for(auto s:S) os<<s<<" ";return os<<"}"; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) { os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}"; }
#ifdef LMAO
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | "; __f(comma+1, args...); }
#else
    #define trace(...) 42
#endif
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
#define all(x) x.begin(), x.end()
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAX = 1000010;
const int MOD2 = 998244353;
const int MOD = 1000000007; 
const int INF = 1e8;    
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)   
/*****************start************/
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed<<setprecision(25);cerr<<fixed<<setprecision(10);
    auto start = std::chrono::high_resolution_clock::now();
    vector<int> a(5);
    int ans=0;
    forn(i,5)
    {
        cin>>a[i];
        if(!a[i])
            ans=i+1;
    }
    cout<<ans<<endl;

    auto stop = std::chrono::high_resolution_clock::now(); 
    auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); 
    // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< endl;     
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <algorithm>


using namespace std;

int main(){

    int n;
    int cnt = 0;

    cin >> n;

    int a[n];

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

    map <int, int> m;

    for (int i = 0; i < n; i++) {
        m[a[i]] = m[a[i]] + 1;
    }



    for (auto it = m.begin(); it != m.end(); it++) {
        if (it->second != it->first) {
            if (it->second < it->first) {
                cnt += it->second;
            } else {
                cnt += it->second - it->first;
            }
        }
    }

    cout << cnt;

}



Measured memory_bytes: 5120
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, X;
  cin >> N >> X;
  vector<int64_t> BP(N + 1, 0);
  vector<int64_t> P(N + 1, 0);
  BP[0] = P[0] = 1;
  for (int i = 1; i <= N; ++i) {
    BP[i] = 2 * BP[i - 1] + 3;
    P[i] = 2 * P[i - 1] + 1;
  }

  int64_t answer = 0;
  while (true) {
    if (N == 0) {
      answer += (X <= 0) ? 0 : 1;
      break;
    }
    int64_t half = BP[N - 1] + 1;
    if (X <= half) {
      --X;
      --N;
    } else {
      answer += P[N - 1] + 1;
      X -= (BP[N - 1] + 2);
      --N;
    }
  }

  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }

template <typename T> T fact(T n) { return (n == 0 ? 1 : n * fact(n - 1)); }
template <typename T> T combi(T n, T r) {
  return (n == r || r == 0 && n != 0
              ? 1
              : (n * fact(n - 1)) / fact(n - 1) * fact(n - r));
}

const int MOD = 1e9 + 7;

signed main(void) {
  int n;
  cin >> n;
  vector<int> d(n);

  int M = 0;
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
    M = max(M, d[i]);
    ++c[d[i]];
  }

  if (d[0] != 0 || c[0] != 1) {
    cout << 0 << endl;
    return 0;
  }

  int num = 1;
  int mod = 998244353;
  for (int i = 1; i <= M; ++i) {
    // num *= (int)pow(c[i - 1], c[i]) % mod;
    for (int j = 0; j < c[i]; ++j) {
      num *= c[i - 1];
      num %= mod;
    }
    num %= mod;
  }

  cout << num << endl;
  return 0;
}


Measured memory_bytes: 1792
n,q=map(int,input().split())
s=str(input())
a=[0]
a*=n
for i in range(n-1):
    if s[i]=='A' and s[i+1]=='C':
        a[i+1]=a[i]+1
    else:
        a[i+1]=a[i]
#最初に余分な0が一つ入っているため番号はそのまま        
for i in range(q):
    li,ri=map(int,input().split())
    ans=a[ri-1]-a[li-1]
    print(ans)

Measured memory_bytes: 6060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

constexpr int INF = 1e9+7;
constexpr ll INFL = 9*1e18;

constexpr int dx[4] = { 1, 0, -1, 0 };
constexpr int dy[4] = { 0, 1, 0, -1 };

// constexpr int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// constexpr int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}


// TODO: write
int main() {
  int n,m;cin>>n>>m;
  vector<pair<int,int>> a(n);rep(i,n)cin>>a[i].fi>>a[i].se;
  sort(all(a),[](auto a1,auto a2){
    return a1.fi < a2.fi;
  });

  int now = 0;
  ll ans = 0;
  rep(i,n){
    int buy = min(m-now,a[i].se);
    ans += a[i].fi * (ll)buy;
    now += buy;
    if(now == m)break;
  }
  print(ans);

  return 0;
}

Measured memory_bytes: 4068
/*
 
@author
_      _          _                 _      _
\\    // /\    | | \  |     |    /\ \\    //     
 \\  // /__\   | |_/  |_____|   /__\ \\  //
  \\// /    \  | | \  |     |  /    \ \\//
   \/ /      \ | |_/  |     | /      \ \/
@ Indian Institute of Technology Bhilai
*/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define fr(i,start,end, inc) for(ll i=(start); i<(end); i+=inc)
#define rf(i,end,start, inc) for(ll i=(start-1); i>=(end); i-=inc)
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<n; i++)
#define pb push_back
#define pl pair<ll, ll>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define alla(arr,n) arr, arr+n
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define fsync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll maxx =  1e9+7;


bool compare(const pl &a, const pl &b){
    return a.fi<b.fi || (a.fi==b.fi && a.se<b.se);
}
ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}
inline vector<ll> allinv(ll n, ll p){
    vector<ll> arr(n);
    arr[1]=1;
    fr(i,2,n,1){
        arr[i] = (p - (p/i)*arr[p%i]%p)%p;
    }
    return arr;
}
vector<ll> inline allncr(ll n, ll p){
    vector<ll> nci(n+1);
    nci[0]=1;
    nci[n]=1;
    vector<ll> v = allinv(n,p);
    fr(i,1,n,1){
        nci[i]=(nci[i-1]*(n-i-1))%p;
    }
    return nci;
}

bool inline isPrime(ll n) { 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

template<class T>
void printv(T &v, ll n){
    if(n==-1)
        n = v.size();
    rep(i,n)
        cout << v[i] << " ";
    cout << "\n";
}
//------------fenwick--------------
/*vector<ll> f(maxn,0);
void fenwick_update(ll idx, ll val){
    while(idx <= maxn){
        f[idx]+=val;
        idx += (idx & -idx);
    }
}
ll read_fenwick(ll idx){
    ll sum = 0;
    while(idx > 0){
        sum += f[idx];
        idx -= (idx & -idx);
    }
    return sum;
}*/

void solve(){
    ll x;
    cin >> x;
    cout << (x/500)*1000 + ((x%500)/5)*5 << "\n";
}

int main(){
    fsync
    ll test=1;
    // cin >> test;
    while(test--){
        solve();

    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 2e5+5, M = 1e6+6, OO = 0x3f3f3f3f;
int tc;
int h, w, k;
string grid[M];
int dir[] = {-1,1,0,0};
int dic[] = {0,0,-1,1};
int dis[M], directions[M];
// vector<vector<ll> > dis, directions;
bool valid(int r, int c)
{
    return r >= 0 && r < h && c >= 0 && c < w && grid[r][c] != '@';
}


int main()
{
    int x1, x2, y1, y2;
    scanf("%d %d %d ", &h, &w, &k);
    scanf("%d %d %d %d ", &x1, &y1, &x2, &y2);

    for(int i = 0 ; i< h ;i++)
    {
        string s;
        getline(cin, s);
        grid[i] = s;
    }
    x1--; y1--; x2--; y2--;
    memset(dis, OO, sizeof dis);
    dis[x1 * w + y1] = 0;
    // directions[x1 * w + y1] = 15;
    queue<pair<ll, ll> > q;
    q.push({x1, y1});
    while(!q.empty())
    {
        ll ur = q.front().first, uc = q.front().second;
        // cout<<ur<<" "<<uc<<endl;
        q.pop();
        if(ur == x2 && uc == y2)
            break;
        int ncost = dis[ur*w + uc] + 1;
        // cout<<ur<<" "<<uc<<" "<<dis[ur*w + uc]<<endl;
        for(int i = 0 ; i< 4 ; i++)
        {
            int steps = 1, vr, vc;
            while(steps <=k)
            {
                vr = ur + (dir[i] * steps);
                vc = uc + (dic[i] * steps);
                int cell = vr * w + vc;
                if(valid(vr, vc))
                {
                    if(dis[cell] > ncost)
                    {
                        dis[cell] = ncost;
                        q.push({vr, vc});
                    }
                    else if (dis[cell] == ncost){
                        steps++;
                        continue;
                    }
                    else
                        break;
                }
                else
                    break;
                steps++;
            }
        }
    }
    printf("%d", dis[x2*w + y2] == OO ? -1 : dis[x2*w + y2] );
    return 0;
}


Measured memory_bytes: 41504
def run():
    n, a, b = map(int, input().split())
    l = [int(i) for i in input().split()]
    ans = 0
    for i in range(n - 1):
        ad = (l[i + 1] - l[i]) * a
        ans += min(ad, b)
    print(ans)

if __name__ == '__main__':
    run()


Measured memory_bytes: 20248
i = input().split()
a = int(i[0])
b = int(i[1])
c = int(i[2])
if a <= b <= c:
    print(a,b,c)
elif a <= c <= b:
    print(a,c,b)
elif b <= a <= c:
    print(b,a,c)
elif b <= c <= a:
    print(b,c,a)
elif c <= a <= b:
    print(c,a,b)
elif c <= b <= a:
    print(c,b,a)


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

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

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

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c;
    cin>>a>>b>>c;
    puta(c,a,b);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;

int main(){
    int d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
 int N,M;
 std::cin>>N>>M;
 std::vector<int> H(N);
 for(int i=0;i<N;i++){
  std::cin>>H[i];
 }
 std::vector<std::vector<int>> list(N);
 for(int i=0;i<M;i++){
  int a,b;
  std::cin>>a>>b;
  list[a-1].emplace_back(b-1);
  list[b-1].emplace_back(a-1);
 }

 int ans=0;
 for(int i=0;i<N;i++){
  bool flag=1;
  for(auto p:list[i]){
   if(H[i]<=H[p]){
    flag=0;
    break;
   }
  }
  if(flag){
   ans++;
  }
 }
 std::cout<<ans<<std::endl;
 return 0;
}

Measured memory_bytes: 8796
#include "bits/stdc++.h"
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/22  Problem: codefestival2017_qual_b B  / Link:   ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	LL x = 1;
	ans = 1;
	FOR(i, 0, N) {
		if (a[i] % 2 == 0)x *= 2;
		ans *= 3;
	}
	ans -= x;
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256