akhauriyash/Code-Regression huggingface dataset:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * Created by Xianda Xu on 2018/12/30.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map map = new HashMap<>();
        int N = scanner.nextInt();
        for(int i=0;i<N;i++){
            int key = scanner.nextInt();
            Integer o = (Integer)map.get(key);
            if(o==null){
                map.put(key,1);
            }else{
                map.put(key,o+1);
            }
        }
        int count=0;
        Set<Map.Entry> set = map.entrySet();
        for(Map.Entry entry : set){
            if((int)entry.getValue()%2==1){
                count++;
            }
        }
        System.out.println(count);
    }
}

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

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

  int h, w; cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<bool> row(h, false), column(w, false);

  rep(i, h) rep(j, w) {
    if(s[i][j]=='#') {
      row[i] = column[j] = true;
    }
  }
  rep(i, h) {
    if(row[i]) {
      rep(j, w) {
        if(column[j]) {
          cout << s[i][j];
        }
      }
      cout << '\n';
    }
  }
  return 0;
}


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

long long N, X, S, P = 0;

long long DFS(long long n, long long x) {
	if (n == 0) {
		if (x > 0) return 1;
		else return 0;
	}
	if (x <= 2 * pow(2, n) - 2) return DFS(n - 1, x - 1);
	return pow(2, n) + DFS(n - 1, x + 1 - 2 * pow(2, n));
}

int main() {
	cin >> N >> X;
	cout << DFS(N, X);
}

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

int main() {
  string S;
  cin >> S;
  if(S.size() == 2)
    cout << S << endl;
  else {
    reverse(S.begin(), S.end());
    cout << S << endl;
  }
}

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

int H, W, K;

vector<string> paint_row(vector<string> v, int h) {
  for (int i = 0; i < W; i++) {
    v.at(h).at(i) = '.';
  }
  return v;
}

vector<string> paint_column(vector<string> v, int w) {
  for (int i = 0; i < H; i++) {
    v.at(i).at(w) = '.';
  }
  return v;
}

int search_column(vector<string> v, int w) {
  // ベース処理
  if (w == W) {
    int sharp_count = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (v.at(i).at(j) == '#') {
          sharp_count++;
        }
      }
    }

    if (sharp_count == K) {
      return 1;
    } else {
      return 0;
    }
  }

  // w列目を塗る場合
  vector<string> v1 = v;
  v1 = paint_column(v1, w);
  int p1 = search_column(v1, w + 1);

  // w列目を塗らない場合
  vector<string> v2 = v;
  int p2 = search_column(v2, w + 1);

  return p1 + p2;
}

int search_row(vector<string> v, int h, int w) {
  // ベース処理
  if (h == H) {
    return search_column(v, w);
  }

  // 再帰処理
  // h行目を塗る場合
  vector<string> v1 = v;
  v1 = paint_row(v1, h);
  int p1 = search_row(v1, h + 1, w);

  // h行目を塗らない場合
  vector<string> v2 = v;
  int p2 = search_row(v2, h + 1, w);

  return p1 + p2;
}

int main() {
  cin >> H >> W >> K;

  vector<string> v;
  v.resize(H);
  for (int i = 0; i < H; i++) {
    cin >> v.at(i);
  }

  int ans = search_row(v, 0, 0);
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/
ll solve(string str){
    ll ret = 0; ll cnt = 0;
    rep(i,str.size()){
        cnt++;
        if(i==str.size()-1 || str[i]!=str[i+1]){
            ret += cnt/2;
            cnt = 0;
        }
    }
    return ret;
}

/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    string s; cin >> s;
    ll k; cin >> k;
    bool alsame = true;
    rep(i, s.size()-1){
        if(s[i]!=s[0]) alsame = false;
    }
    if(alsame){
        cout << (ll)(s.size()*k)/2 << '\n';
    }
    else{
        string s_2 = s+s;
        ll ans1 = solve(s);
        ll ans2 = solve(s_2);
        cout<< ans1 + (ans2 - ans1)*(k-1) << '\n'; 
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int wa(int n)
{
  int ans=0;
  while(n){
    ans+=n%10;
    n/=10;
  }
  return ans;
}
int main(void)
{
  int n,a,b,i;
  long long ans=0; 
  scanf("%d%d%d",&n,&a,&b);
  for(i=1;i<=n;i++){
    int j=i;
    int tmp=wa(j);
    if(tmp>=a&&tmp<=b){
      ans+=i;
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

using ll = long long;
const ll MOD = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    ll xsum = 0, ysum = 0, x, y;
    for(int k = 0; k < n; k++) {
        cin >> x;
        xsum += (2 * k - n + 1) * x % MOD;
        xsum %= MOD;
    }

    for(int k = 0; k < m; k++) {
        cin >> y;
        ysum += (2 * k - m + 1) * y % MOD;
        ysum %= MOD;
    }

    ll ans = xsum * ysum % MOD;

    cout << ans << endl;

    return 0;
}

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

int main() {
    int N,M,X;
    cin >> N >> M >> X;
    int A[M];
    rep(i,M){
        cin >> A[i];
    }
    int ans=0;
    rep(i,M){
        if(A[i]<X+1){
            ans++;
        }
    }
    ans=min(ans,M-ans);

    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
s = list(map(int, input().split()))
modulo = 1000000007
comb = 1
stack = [0,0,0]
for time in s:
  idx = -1
  rep = 0
  for i in range(3):
    if time == stack[i]:
      idx = i
      rep += 1
  stack[idx] += 1
  comb *= rep
  comb %= modulo
print(comb)
  
   
  

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 500000000
#define IOS ios_base::sync_with_stdio(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
bool check(int n,int p){return (1<<p)&n;}
vector<ll>v1,v2,v;
int main()
{
    IOS;
    ll n,m;cin>>n>>m;
    ll sq=sqrt(n);
    for(int i=1;i<=sq;i++)
        if(n%i==0)
        {
            v1.pb(i);
            if(i!=n/i)v1.pb(n/i);
        }
    sort(v1.begin(),v1.end());
//    cout<<"size = "<<v1.size()<<endl;
    sq=sqrt(m);
    for(int i=1;i<=sq;i++)
    {
        if(m%i==0)
        {
            if(binary_search(v1.begin(),v1.end(),i))
                v.pb(i);
            if(i==m/i)continue;
            if(binary_search(v1.begin(),v1.end(),m/i))
                v.pb(m/i);
        }
    }
    sort(alL(v));
//    prinT(v,v.size());
    ll res=1;
//    cout<<"ok "<<endl;
    for(int i=1;i<v.size();i++)
    {
        bool ok=1;
        for(int j=1;j<i;j++)
            if(v[i]%v[j]==0)ok=0;
        if(ok)
        {
            res++;
//            cout<<"div = "<<v[i]<<endl;
        }
    }
    cout<<res<<endl;
}








Measured memory_bytes: 384
import sys
from math import ceil
def input(): return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(K, N):
        if A[i] > A[i - K]:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 94240
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll> ;

int main(){
    int d;
    cin >> d;
    d = 25 - d;
    cout << "Christmas";
  	if(d != 0)cout << " ";
    rep(i, d){
        cout << "Eve";
        if(i != d - 1)cout << " ";
    }
    cout << endl;
}

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

signed main(){
  int N,K;
  cin>>N>>K;
  int ans=0,upr=0,low=0,MOD=1e9+7;
  for(int i=K;i<N+2;i++){
    low=(i-1)*i/2;
    upr=(2*N-i+1)*i/2;
    ans=ans+(upr-low+1);
  }
  cout<<ans%MOD<<endl;
}

Measured memory_bytes: 3592
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var S = input[1].split("");
  var alf = "abcdefghijklmnopqrstuvwxyz".split("");
  var l = new Array(26).fill(0);
  var mod = Math.pow(10,9)+7;
  for(var i=0;i<N;i++){
    for(var j=0;j<26;j++){
      if(S[i]==alf[j]){
        l[j]++;
        break;
      }
    }
  }
  for(var i=25;i>=0;i--){
    if(l[i]==0){
      l.splice(i,1);
    }
  }
  var x = new Array();
  var ans =1;
  for(var i=0;i<l.length;i++){
    ans=(ans*(l[i]+1))%mod;
  }

  if(S.length==1){
    ans=1;
  }else{
    ans-=1;
  }
  console.log('%s', ans);
  return ans;
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8268
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 1e5 + 5;
int obs[N];
map<pair<int, int>, int> segs;
vector<int> g[N];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> obs[i];
    }
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        if(x < y){
            swap(x, y);
        }
        g[x].PB(y);
        g[y].PB(x);
    }
    int good = 0;
    for(int i = 1; i <= n; i++){
        int pr = i;
        if(SZ(g[pr]) == 0){
            good++;
        }else{
            int cnt = 0, reach = 0;
            for(auto &child : g[pr]){
                int tmp = pr;
                int tmpc = child;
                if(tmp < tmpc){
                    swap(tmp, tmpc);
                }
                cnt += (obs[pr] > obs[child]);
            }
            if(cnt == SZ(g[pr])){
                good++;
            }
        }
    }
    cout << good;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 9160
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007

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

  ll X; cin>>X;

  ll res = 0;

  res += X/500 * 1000;
  X%=500;

  res += X/5 * 5;

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import deque
N, M = map(int, input().split())
nodes = [set() for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    nodes[a-1].add(b-1)
    nodes[b-1].add(a-1)
ans = [-1 for i in range(N)]
ans[0] = 0
q = deque([])
q.append(0)

cur = 0
done = set()
done.add(0)
while q:
    node = q.popleft()
    for x in nodes[node]:
        if x in done:
            continue
        q.append(x)
        done.add(x)
        ans[x] = node + 1
if -1 in ans:
    print('No')
else:
    print('Yes')
    for x in ans[1:]:
        print(x)

Measured memory_bytes: 71356
#include <iostream>
#include <fstream>
#include <climits>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <list>

#define FOR(i,n)    for(int i = 0 ; i < n ; i++)
#define FORrev(i,n) for(int i = n - 1 ; i >= 0 ; i--)
#define ALL(a)      a.begin(),a.end()

typedef long long int ll; 

using namespace std;

int main() {
	int count = 0;
	string s , t;
	cin>>s>>t;
	if(s[0] == t[0])
		count++;
	if(s[1] == t[1])
		count++;
	if(s[2] == t[2])
		count++;
	cout<<count;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	// your code goes here
	
	int R,G,Ans;
	
	scanf("%d",&R);
	scanf("%d",&G);
	
	//現在のレーティングR+次のレーティングAnsを2で割ったらGになるから
	//(R+Ans)/2=G  2G=R+Ans  Ans=2G-R
	Ans = 2*G - R;
	
	printf("%d\n",Ans);
	return 0;
}


Measured memory_bytes: 128
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, k = map(int, readline().split())
    res = dict()
    cnt = 0

    for i in range(1, 101):
        if a % i == 0 and b % i == 0:
            cnt += 1
            res[cnt] = i

    num = (cnt + 1) - k
    print(res[num])


if __name__ == '__main__':
    main()


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

#define EPS (1e-10)
#define equals(a,b) (fabs( (a)-(b) ) < EPS)

class Point{

public:
  double x,y;
  
  Point(double x=0,double y=0): x(x),y(y) {}
  
  Point operator + (Point p) { return Point(x+p.x,y+p.y); }
  Point operator - (Point p) { return Point(x-p.x,y-p.y); }
  Point operator * (double a) { return Point(a*x,a*y); }
  Point operator / (double a) { return Point(x/a,y/a); }

  double abs() { return sqrt(norm()); }
  double norm() { return x*x + y*y; }
  
  bool operator < (const Point &p) const{
    return x != p.x ? x<p.x : y<p.y;
  }
  
  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
  
};
typedef Point Vector;

double dot(Vector a,Vector b){
  return a.x*b.x + a.y*b.y;
}

double cross(Vector a,Vector b){
  return a.x*b.y - a.y*b.x;
}

Point project(Point p1,Point p2,Point p){
  Vector base = p2-p1;
  double r = dot(p-p1,base) / base.norm();
  return p1 + base * r;
}

int main(){
  int q;
  double x1,y1,x2,y2,x,y;
  Point p1,p2,p,pro;
  
  scanf("%lf %lf %lf %lf %d",&x1,&y1,&x2,&y2,&q);
  p1 = Point(x1,y1);
  p2 = Point(x2,y2);
  
  while(q--){
    scanf("%lf %lf",&x,&y);
    p = Point(x,y);
    pro = project(p1,p2,p);
    printf("%.10lf %.10lf\n",pro.x,pro.y);
  }

  return(0);
}



Measured memory_bytes: 3216
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

int check(int x){
	int ans = 0;
  	while(x%2==0){
		x /= 2;
      	ans++;
    }  
    return ans;
}

void Main()
{
	int N;
  	cin >> N;
  	vector<int> a(N);
  	rep(i,N) cin >> a[i];
  	
  	int ans = 0;
  	rep(i,N) ans += check(a[i]);
  	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string c[1000];
int chonghe(string a,string b)
{
	int ac=a.length();
	int ah=b.length();
	if(ac>ah)
	{
		int ans=0;
		for(int j=0;j<a.length()-b.length()+1;j++)
		{
			int max1=0;
			for(int i=0;i<b.length();i++)
	    {
		if(a[j+i]==b[i])
		{
		
		max1++;	
		}
	    }
	ans=max(max1,ans);
	
		}
		return b.length()-ans;
	}//A长 
    else 
    {
    		int ans=0;
		for(int j=0;j<b.length()-a.length()+1;j++)
		{
			int max1=0;
			for(int i=0;i<a.length();i++)
	    {
		if(b[j+i]==a[i])
		{
		
		max1++;	
		}
	    }
	ans=max(max1,ans);
	
		}
		return a.length()-ans;
		
    }

}
int main()
{
	string a;
	string b;
	cin>>a>>b;
cout<<chonghe(a,b);
} 

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

int main() {
  int X;
  cin >> X;
  int ans = 1;
  if(X == 1) { cout << 1; return 0; }
  for(int i = 2; i < 40; i++) {
    int a = i * i;
    for(int j = a; j <= X; j *= i) {
      if(ans < j) ans = j;
    }
  }

  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         long K=gl();
         long a=gl();
         long b=gl();

         if(a>=b-2 || K+1<a+2) {
        	 System.out.println(K+1);
        	 return;
         }

         long ans=a;
         long c=b-a;
         K-=a-1;
         if (K%2==0) {
             ans+=(K/2)*c;
         } else {
        	 ans+=((K-1)/2)*c+1;
         }

         System.out.println(ans);

     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 35320
#include <bits/stdc++.h>
using namespace std;
#define sz 100005
int n,a[sz],b[sz],c[sz];
int dp[sz][5];

int res(int ind,int ofStatus=0)
{
    if(ind==n)return 0;
    if(dp[ind][ofStatus]!=-1)return dp[ind][ofStatus];
    int r=INT_MIN;
    if(ofStatus!=1)
    {
        r=max(r,a[ind]+res(ind+1,1));
    }
    if(ofStatus!=2)
    {
        r=max(r,b[ind]+res(ind+1,2));
    }
    if(ofStatus!=3)
    {
        r=max(r,c[ind]+res(ind+1,3));
    }
    return dp[ind][ofStatus]=r;
}

int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];

    cout<<res(0)<<endl;

   return 0;
}


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

int main() {
  int W, H; char c; cin >> W >> H >> c;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i == H / 2 && j == W / 2) cout << c;
      else if ((!i && (!j || j == W - 1)) || (i == H - 1 && (!j || j == W - 1))) cout << "+";
      else if (!i || i == H - 1) cout << "-";
      else if (!j || j == W - 1) cout << "|";
      else cout << ".";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

#define MOD 1000000007

using namespace std;

typedef long long int64;

int main(void){
    int64 N,K;
    cin>>N>>K;
    int64 facA=1,facB=1;
    for(int64 i=1;i<=N-K+1;i++){
        facA*=i;
        facA%=MOD;
    }
    for(int64 i=1;i<=K-1;i++){
        facB*=i;
        facB%=MOD;
    }
    // cout<<facA<<" "<<facB<<endl;

    vector<int64> facinv(N+1),inv(N+1);
    facinv[0]=facinv[1]=1;
    inv[1]=1;
    for (int64 i=2;i<=N;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        facinv[i]=facinv[i-1]*inv[i]%MOD;
    }
    for(int64 i=1;i<=K;i++){
        if(N-K+1<i){
            cout<<0<<endl;
        }else{
            cout<<(facA*(facinv[i]*facinv[(N-K+1)-i]%MOD)%MOD)*(facB*(facinv[i-1]*facinv[(K-1)-(i-1)]%MOD)%MOD)%MOD<<endl;
        }
        
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

if A[0] > A[1]:
    max_1, max_2 = A[0],A[1]
else:
    max_1, max_2 = A[1],A[0]

dict = {}
for i, a in enumerate(A):
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1
    if i >= 2:
        if a > max_1:
            max_2 = max_1
            max_1 = a
        elif a > max_2:
            max_2 = a

for a in A:
    if a == max_1:
        if dict[a] >= 2:
            print(max_1)
        else:
            print(max_2)
    else:
        print(max_1)




Measured memory_bytes: 20264
INT_MAX = 10**8
h, n = map(int, input().split())
e = tuple(tuple(map(int, input().split())) for _ in range(n))

dp = [0] + [INT_MAX]* h
for i in range(1, h+1):
  v = INT_MAX
  for a, b in e:
    c = dp[max(0, i - a)] + b
    v = min(v, c)
  dp[i] = v
print(dp[h])

Measured memory_bytes: 43788
while True:
    try:
        a = map(int, raw_input().split())
        b = map(int, raw_input().split())
        hit = 0; brow = 0
        for i in range(len(b)) :
            brow += a.count(b[i])
            if a[i] == b[i] :
                hit += 1
                brow -= 1
        print hit, brow

    except:
        break

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

int main() {
  int n; cin>>n;
  vector<vector<pair<int,int>>> eviArr(n);
  for(int i=0; i<n; i++) {
    int eviNum; cin>>eviNum;
    for(int j=0; j<eviNum; j++) {
      int person,isHonest; cin>>person>>isHonest;
      eviArr[i].push_back({person-1,isHonest});
    }
  }
  int ans=0;
  // bit全探索
  for(int i=0; i<pow(2,n); i++) {
    bitset<15> bs(i);
    bool isFinished = true;
    for(int j=0; j<(int)bs.size(); j++) {
      if(bs[j]) {
        for(int k=0; k<(int)eviArr[j].size(); k++) {
          if(bs[eviArr[j][k].first]!=eviArr[j][k].second) isFinished=false;
          if(!isFinished) break;
        }
        if(!isFinished) break;
      }
    }
    if(!isFinished) continue;
    ans = max(ans,(int)bs.count());
  }
  cout << ans << endl;
}


Measured memory_bytes: 4016
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    m1: usize,
    d1: usize,
    m2: usize,
    d2: usize,
    }
    let ans = if m1 == m2 {0} else {1};
    println!("{}", ans);
}


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

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

using namespace std;

char S[64];
int sz;

int main(){
    string s;
    cin>>s;
    sz=0;
    REP(i,s.length()){
        if (s[i]=='B'){
            if (sz!=0){
                S[--sz]=0;
            }
        }else{
            S[sz++]=s[i];
        }
    }
    cout<<S<<endl;
    return 0;
}

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

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    ll sum = 0;
    rep(i,n)sum += a[i];
    set<ll> candidates;
    for(int i=1;i*i<= sum;i++){
        if(sum%i==0){
            candidates.insert(i);
            candidates.insert(sum/i);
        }
    }
    ll ans = 1;
    for(ll x: candidates){
        ll need;
        {//calc need
            vector<ll> r(n);
            rep(i,n)r[i] = a[i]%x;
            sort(ALL(r));
            ll B = 0;
            rep(i,n)B += x - r[i];
            ll A = 0;
            need = 1e18;
            rep(i,n){
                A += r[i];
                B -= x-r[i];
                need = min(need,max(A,B));
            }
        }
        if(need <= k)ans = max(ans,x);
    }
    cout << ans << endl;
}

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

bool pf[1000005];

int main() {
  pf[1] = true;
  for (int i = 2; i <= 1000; i++)
    for (int j = i * i; j <= 1000; j *= i)
      pf[j] = true;
  int x;
  cin >> x;
  for (int i = x; i >= 1; i--)
    if (pf[i]) {
      cout << i << endl;
      return 0;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
const int mod=998244353;
const int N=1000000;
int f[N+1], F[N+1], n, m, ans;
void inc(int &a,int b){ (a+=b)%=mod; }
int C(int n,int m){
	if(n<m||n<0||m<0)return 0;
	return 1LL*f[n]*F[m]%mod*F[n-m]%mod;
}
int mi(int a,int b){
	int s=1;
	for(;b;b>>=1,a=1LL*a*a%mod)
		if(b&1)s=1LL*s*a%mod;
	return s;
}
int main(){
	f[0] = 1;
	ref(i,1,N)f[i] = 1LL*f[i-1]*i%mod;
	F[N] = mi(f[N], mod-2);
	def(i,N,1)F[i-1] = 1LL*F[i]*i%mod;
	cin>>n>>m;
	if(n<m)swap(n,m);
	ref(i,1,m)inc(ans, 1LL*C(i*2,i)*C(n+m-i*2,m-i)%mod);
	ans=1LL*ans*mi(C(n+m,n),mod-2)%mod;
	ans=1LL*ans*mi(2,mod-2)%mod;
	inc(ans,n);
	cout<<ans<<endl;
}

Measured memory_bytes: 8064
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int H,W;

int main(){

	int maximum,map[10][10],tmp_sea_max,tmp_wall_min,tmp;

	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0)break;

		for(int i = 0; i < H; i++){
			for(int k = 0; k < W; k++)scanf("%d",&map[i][k]);
		}

		maximum = 0;

		for(int sea_left = 1; sea_left <= W-2; sea_left++){
			for(int sea_right = sea_left; sea_right <= W-2; sea_right++){
				for(int sea_top = 1; sea_top <= H-2; sea_top++){
					for(int sea_bottom = sea_top; sea_bottom <= H-2; sea_bottom++){

						tmp_sea_max = 0;
						for(int row = sea_top;row <= sea_bottom;row++){
							for(int col = sea_left; col <= sea_right; col++){
								tmp_sea_max = max(tmp_sea_max,map[row][col]);
							}
						}

						tmp_wall_min = 100;
						for(int col = sea_left-1;col <= sea_right+1; col++)tmp_wall_min = min(tmp_wall_min,map[sea_top-1][col]);
						for(int col = sea_left-1;col <= sea_right+1; col++)tmp_wall_min = min(tmp_wall_min,map[sea_bottom+1][col]);
						for(int row = sea_top-1; row <= sea_bottom+1;row++)tmp_wall_min = min(tmp_wall_min,map[row][sea_left-1]);
						for(int row = sea_top-1; row <= sea_bottom+1;row++)tmp_wall_min = min(tmp_wall_min,map[row][sea_right+1]);

						if(tmp_sea_max >= tmp_wall_min)continue;

						tmp = 0;
						for(int row = sea_top;row <= sea_bottom;row++){
							for(int col = sea_left; col <= sea_right; col++){
								tmp += tmp_wall_min-map[row][col];
							}
						}

						maximum = max(maximum,tmp);
					}
				}
			}
		}

		printf("%d\n",maximum);

	}

	return 0;
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	bool c = false;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'C')
			c = true;
		else if (c && s[i] == 'F')
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

#define DIV 2019 

vector<vector<int>> mul10_mod(DIV, vector<int>(9, -1));

int get_mul10_mod(int x, int y){
  if (mul10_mod[x][y-1] == -1) {
    mul10_mod[x][y-1] = (x * 10 + y) % DIV;
  }

  return mul10_mod[x][y-1];
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  READ(S);

  // main procedure
  size_t len_S = S.size();
  
  vector<int> digits_vec(len_S);
  for (size_t i = 0; i < len_S; ++i) {
    digits_vec[i] = S[i] - '0';
  }

  ll ans = 0;

  vector<ll> mod_count_vec(DIV, 0);
  for (size_t i = 0; i < len_S; ++i) {
    vector<ll> tmp_vec = mod_count_vec;
    mod_count_vec = vector<ll>(DIV, 0);

    for (size_t j = 0; j < DIV; ++j) {
      mod_count_vec[(j * 10 + digits_vec[i]) % DIV] += tmp_vec[j];
    }
    mod_count_vec[digits_vec[i]]++;

    ans += mod_count_vec[0];
  }
  
  // output
  WRITE_N(ans);

  return 0;
}


Measured memory_bytes: 4508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int x,y;
};
int h,w,sx,sy,ex,ey,k;
int mo[4][2]={1,0,-1,0,0,1,0,-1};
main(){
    cin>>h>>w>>k;
    cin>>sx>>sy>>ex>>ey;
    char g[h][w];
    int step[h][w],vis[h][w];
    memset(vis,0,sizeof(vis));
    memset(step,0,sizeof(step));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)
            cin>>g[i][j];
    }
    sx--,sy--,ex--,ey--;
    queue<node>q;
    node a,b;
    a.x=sx;a.y=sy;step[a.x][a.y]=0;vis[a.x][a.y]=1;
    q.push(a);
    int ans=1e9;
    while(!q.empty()){
        a=q.front();
        q.pop();
        if(a.x==ex && a.y==ey) ans=min(ans,step[a.x][a.y]);
        for(int i=0;i<4;i++){
            for(int j=1;j<=k;j++){
                b.x=a.x+mo[i][0]*j;
                b.y=a.y+mo[i][1]*j;
                if(b.x<0||b.x>=h||b.y<0||b.y>=w||(step[b.x][b.y]&&step[b.x][b.y]<=step[a.x][a.y])) break;
                else{
                    if(g[b.x][b.y]=='.'&&vis[b.x][b.y]==0){
                        vis[b.x][b.y]=1;
                        step[b.x][b.y]=step[a.x][a.y]+1;
                        q.push(b);
                    }
                    else if(g[b.x][b.y]=='@') break;
                }
            }
        }
    }
    ans==1e9?cout<<-1:cout<<ans;
}




Measured memory_bytes: 12876
N = int(input())
A = list(map(int, input().split())) 
sum = 0
sum1 = 0

for a in A:
    sum += a
check = sum / 2

for b in A:
    sum1 += b
    if check < sum1:
        sum2 = sum1 - b
        break
sum1_2 = sum - sum2
sum2_2 = sum - sum1
if (sum1_2 - sum2) > (sum1 - sum2_2):
    print(sum1 - sum2_2)
else:
    print(sum1_2 - sum2)


Measured memory_bytes: 25768
from sys import stdin
input = stdin.readline

n,t=map(int, input().split())
ti=list(map(int, input().split()))

ans=0
for i in range(1,n):
    if ti[i]-ti[i-1]>=t:
        ans+=t
    else:
        ans+=(ti[i]-ti[i-1])
ans+=t
print(ans)


Measured memory_bytes: 25744
#include<stdio.h>

int main(){
	int a,b;
	while(1){
		scanf("%d%d",&a,&b);
		if(!(a|b))return 0;
		int now=0;
		if(a<b){
			int c=a;
			a=b;
			b=c;
		}
		while(b!=0){
			a=a%b;
			int c=a;
			a=b;
			b=c;
			now++;
		}
		printf("%d %d\n",a,now);
	}
}

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

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

using namespace std;

bool fact(int n){
	int k = sqrt(n);
	if(n % 2 ==0) return false;
	else{
		for(int i = 3; i <= k; i = i+2){
			if(n % i == 0) return false;
		}
		return true;
	}
	return 0;
}

void factorize(int n){
	vector<int> fac;
	cout << n <<": ";
	if(fact(n) == true){
		cout << n << endl;
		return;
		//?´???°???????????????????????????
	}

	while(n % 2 ==0){
		n /= 2;
		fac.push_back(2);
	}

	if(n !=1){
		int i=3;
		while(n>1){
			if(n % i == 0){n /= i; fac.push_back(i);}
			else {i = i+2;}
		}
	}

	int m = fac.size();
	for(int i=0; i<m-1; i++){
		cout << fac[i] << " ";
	}
	cout << fac[m-1] << endl;
	return;
}
int main(){
	int n;
	cin >> n;
	factorize(n);
	return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define VALUES_PER_UNIT	0xFF
#define VOID_VAL	(-1)


typedef struct unit {
	struct unit *before, *after;
	int values[VALUES_PER_UNIT];
} unit;

int main(void) {
	char s[20];
	int index = 0, i, j, n, val;
	FILE *fp = fopen("ALDS1_3_C_in9.txt", "rb");
	unit *funit, *lunit, *u;
	funit = malloc(sizeof(unit));
	funit->before = funit->after = NULL;
	lunit = funit;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", s);
		if (strcmp(s, "insert") == 0) {
			scanf("%d", &val);
			lunit->values[index++] = val;
			if (index >= VALUES_PER_UNIT) {
				u = malloc(sizeof(unit));
				lunit->after = u;
				u->before = lunit;
				u->after = NULL;
				lunit = u;
				index = 0;
			}
		} else if (strcmp(s, "delete") == 0) {
			scanf("%d", &val);
			j = index;
			u = lunit;
			while (u != NULL) {
				while (--j >= 0) {
					if (u->values[j] == val) {
						u->values[j] = VOID_VAL;
						break;
					}
				}
				if (j >= 0) break;
				u = u->before;
				j = VALUES_PER_UNIT;
			}
		} else if(strcmp(s, "deleteFirst") == 0) {

			do {
				index--;
				if (index < 0) {
					if (lunit->before == NULL) break;
					u = lunit;
					lunit = lunit->before;
					lunit->after = NULL;
					free(u);
					index = VALUES_PER_UNIT - 1;
				}
			} while (lunit->values[index] == VOID_VAL);
		} else if(strcmp(s, "deleteLast") == 0) {
			j = 0;
			while (funit->values[j] == VOID_VAL) {
				if (++j >= VALUES_PER_UNIT) {
					if (funit->after == NULL) break;
					u = funit;
					funit = funit->after;
					funit->before = NULL;
					free(u);
					j = 0;
				}
			}
			if (j < VALUES_PER_UNIT) {
				funit->values[j] = VOID_VAL;
			}
		} else printf("invalid operation: %s\n", s);
	}
	i = 0;
	for (u = lunit; u != NULL; u = u->before) {
		while (--index >= 0) {
			if (u->values[index] != VOID_VAL) {
				if (i) {
					printf(" ");
				} else i++;
				printf("%d", u->values[index]);
			}
		}
		index = VALUES_PER_UNIT;
	}
	printf("\n");
}

Measured memory_bytes: 5564
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

int n, i;
ll X, Y, Z;
ll A[maxN], B[maxN], C[maxN];
ll sol, act, best;
ll le[maxN], ri[maxN];

vector<int> ord;
priority_queue<ll, vector<ll>, greater<ll> > H;

int main()
{
//    freopen("test.in","r",stdin);

    cin >> X >> Y >> Z;
    n = X + Y + Z;
    for (i = 1; i <= n; i++) {
        cin >> A[i] >> B[i] >> C[i];
        sol += C[i];
        A[i] -= C[i];
        B[i] -= C[i];
        C[i] = 0;

        ord.pb(i);
    }

    sort(ord.begin(), ord.end(), [](int a, int b)->bool {
        return A[a] - B[a] < A[b] - B[b];
    });

    ord.pb(0);
    for (i = n; i > 0; i--) ord[i] = ord[i - 1];

    while (!H.empty()) H.pop();
    for (i = 1; i < Y; i++) H.push(B[ord[i]]), act += B[ord[i]];
    for (i = Y; i <= n; i++) {
        H.push(B[ord[i]]);
        act += B[ord[i]];
        if (i != Y) {
            act -= H.top();
            H.pop();
        }

        le[i] = act;
    }

    act = 0;
    while (!H.empty()) H.pop();
    for (i = n; i > n - X + 1; i--) H.push(A[ord[i]]), act += A[ord[i]];
    for (i = n - X + 1; i >= 1; i--) {
        H.push(A[ord[i]]);
        act += A[ord[i]];
        if (i != n - X + 1) {
            act -= H.top();
            H.pop();
        }

        ri[i] = act;
    }

    best = -(1LL << 60);
    for (i = Y; i + X <= n; i++)
        best = max(best, le[i] + ri[i + 1]);

    cout << best + sol;


    return 0;
}


Measured memory_bytes: 4856
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll x;cin>>x;
    ll ans=0;
    ans+=(x/500)*1000;
    x%=500;
    ans+=(x/5)*5;
    cout<<ans<<Endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





























Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    
    int a, b, c, x;
    int ans = 0;
    cin >> a >> b >> c >> x;
    repeat_to (i, a) {
        repeat_to (j, b) {
            repeat_to (k, c) {
                if (500*i + 100*j + 50*k == x) ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
    
}

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

char s[10][10];
vector<pair<int, int>> v;


int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 0;i < n;i++) scanf("%s", s[i]);
	for(int i = 0;i < n;i++) 
		for(int j = 0;j < m;j++) if(s[i][j] == '#') v.push_back({i, j});
	sort(v.begin(), v.end());
	bool ret = true;
	//for(auto p: v) printf("%d, %d\n", p.first, p.second);
	if(v[0] != pair<int, int>(0, 0)) ret = false;
	for(int i = 1;i < v.size() and ret;i++) {
		auto pre = v[i - 1];
		if(v[i].first - pre.first >= 0 and v[i].second - pre.second >= 0) continue;
		ret = false;
	}
	puts(ret? "Possible": "Impossible");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	if(a>0&&b>0)printf("Positive\n");
	else if(a<0&&b<0&&(max(a,b)-min(a,b))%2==1)printf("Positive\n");
	else if((a>=0&&b<=0)||a<=0&&b>=0)printf("Zero\n");
	else if(a<0&&b<0)printf("Negative\n");	
	return 0;
}

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

#define 	ll				long long
#define 	vii				vector<int>
#define		rep(i,n) 		for(i=0;i<n;i++)
#define		repe(i,I1,I2) 	for(i=I1;i<I2;i++)
#define		INF  			1e9 + 7
#define		pb  			push_back
#define		mp  			make_pair
#define		endl			'\n'
#define 	mod				1000000007


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k,t,c=0,i,m=INT_MAX,l,l1;
	t=1;
	//cin>>t;
	
	while(t--)
	{
		cin>>n>>l;
		rep(i,n)
		{
			cin>>c>>l1;
			if(l1<=l)
				m=min(m,c);
		}
		if (m==INT_MAX)
		{
			cout<<"TLE";
		}
		else
			cout<<m;
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
L=[]
for i in range(M-1):
  L.append(X[i+1]-X[i])
L.sort()
ans=0
for i in range(len(L)-(N-1)):
  ans+=L[i]
print(ans)

Measured memory_bytes: 56744
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long n = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int[,] countA = new int[s.Length, 2];
			int[,] countC = new int[s.Length, 2];
			int c1 = 0, c2 = 0;
			for (int i = 0; i < s.Length; i++) {
				if (s[i] == 'A') {
					c1++;
				}
				if (s[i] == '?') {
					c2++;
				}
				countA[i, 0] = c1;
				countA[i, 1] = c2;
			}
			c1 = 0;
			c2 = 0;
			for (int i = s.Length - 1; i >= 0; i--) {
				if (s[i] == 'C') {
					c1++;
				}
				if (s[i] == '?') {
					c2++;
				}
				countC[i, 0] = c1;
				countC[i, 1] = c2;
			}

			long ans = 0;
			for (int i = 1; i < s.Length - 1; i++) {
				if (s[i] == 'B' || s[i] == '?') {
					//  a*3^q + q*3^(q-1)
					long a, c, q;
					q = countA[i - 1, 1];
					a = (long)countA[i - 1, 0] * Power3((int)q) % mod;
					a += q * Power3((int)q - 1) % mod;

					q = countC[i + 1, 1];
					c = (long)countC[i + 1, 0] * Power3((int)q) % mod;
					c += q * Power3((int)q - 1) % mod;

					ans += a * c % mod;
					ans %= mod;
				}
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}

		static List<int> _Power3 = new List<int>();
		static int Power3(int x)
		{
			if (x < 0) {
				return 0;
			}
			if (x < _Power3.Count) {
				return _Power3[x];
			}
			if (_Power3.Count == 0) {
				_Power3.Add(1);
			}
			int i = _Power3.Count;
			long result = _Power3[i - 1];
			while (i <= x) {
				result *= 3;
				result %= mod;
				_Power3.Add((int)result);
				i++;
			}
			return (int)result;
		}

	}
}


Measured memory_bytes: 13920
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#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...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 200 + 10;
char s[N][N], t[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  for (int i = 0; i < n * 2; ++i) {
    for (int j = 0; j < m; ++j) {
      t[j] = s[i / 2][j];
    }
    t[m] = 0;
    puts(t);
  }

  return 0;
}


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

int euclidean_gcd(int a, int b) {
    if (b==0) return a;
    else return euclidean_gcd(b, a%b);
}



int main(void)
{
    int n;
    cin >> n;
    
    int ans = 0;

    int g;
    for (int i = 1;i <= n;i++)
    {
        for (int j = 1;j <= n;j++)
        {
            for (int k = 1;k <= n;k++)
            {
                g = euclidean_gcd(euclidean_gcd(i,j),k);
                ans += g;
            }
        }
    }

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


Measured memory_bytes: 3636