akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "C"
int n;
ll t[1001];
ll a[1001];
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    ll x=0;
    ll y=0;
    read(n);
    FOR(i, 1, n){
        read(t[i]);
        read(a[i]);
    }
    x=t[1];
    y=a[1];
    FOR(i, 2, n){
        ll z=max((x-1)/t[i]+1, (y-1)/a[i]+1);
        x=z*t[i];
        y=z*a[i];
    }
    writeln(x+y);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// constexpr int max_n = 200'000 + 5;
constexpr ll INF = 1000'000'000'000'000LL;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    int n; cin >> n;
    vector<ll> as(n);
    rep(i, n) {
        cin >> as[i];
    }

    // dp[i][j] = asの[0,i)から取る、j回「飛ばす」
    vector<vector<ll>> dp(n+1, vector<ll>(3));
    dp[0][1] = dp[0][2] = -INF;
    rep(i, n) {
        // dp[i+1]
        rep(j, 3) {
            // j を変えない場合 (飛ばさない場合)
            dp[i+1][j] = dp[i][j];
            if (i % 2 == j % 2) {
                dp[i+1][j] += as[i];
            }

            // jを増やす場合
            if (j == 0 || i % 2 != (j-1) % 2) { continue; }
            // j>=1 で j-1のときはiに置く ときしか考えない
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - 1]);
        }
    }

    ll res;
    if (n % 2 == 0) {
        res = max(dp[n][0], dp[n][1]);
    } else {
        res = max(dp[n][1], dp[n][2]);
    }

    cout << res << endl;

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l.at(i);
    ll count = 0;
    for (int i = 1; i < n; i++)
    {
        if (l.at(i-1) > l.at(i))
        {
            count += l.at(i-1) - l.at(i);
            l.at(i) = l.at(i-1);
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4048
N, M = map(int, input().split())
X = list(map(int, input().split()))
X = list(set(X))
X.sort()
M = len(X)
L = [X[i + 1] - X[i] for i in range(len(X) - 1)]
L.sort()
if N >= M:
    print("0")
else:
    print(sum(L[:M - N]))

Measured memory_bytes: 14712
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define For(i, a) for (int i=0; i<(a); i++)
#define FORR(i,a,b) for (int i = (b)-1; i >= a; i--)
#define Forr(i,a) for (int i = (a)-1; i >= 0; i--)
/////////////////////////// ..... ///////////////////////////
#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args){
cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }
/////////////////////////// ..... ///////////////////////////
#define int ll
#define pb(x) push_back(x)
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////
const int N = 2e5+10;
int a[N];
bool possible(int L, int k, int n){
	For(i,n){
		k -= (a[i]-1)/L;
	}
	return (k>=0?true:false);
}
/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	int n, k; cin >> n >> k;
	For(i,n)cin >> a[i];
	int low = 1, high = 1e9;
	int ans = -1;
	while(low <= high){
		int mid = low + (high-low)/2;
		if(possible(mid,k, n)){
			ans = mid;
			high = mid-1;
		}
		else{
			low = mid+1;
		}
	} 
	cout << ans <<"\n";

	
}

int32_t main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("TC", "r", stdin);
		//freopen("output.txt","w",stdout);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	for(int tt=1;tt<=t;tt++){
		//cout << "Case #"<<tt<<": ";
		solve();
	}
	#ifndef ONLINE_JUDGE
    	cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
    #endif
}


Measured memory_bytes: 5160
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <math.h>
using namespace std;

int main()
{
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back

#define INT 1.01

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

    int64_t X; // llと比較して実行時間が大幅に速い (2205ms->2ms)
    cin >> X;

    int64_t v = 100;
    int ret=0;
    while(true){ //while, for文では実行時間は変わらない
    //rep(ret, INF){
        if(X<=v){
            cout << ret << endl;
            break;
        }
        v *= INT; // 実行時間が2ms->6msへと伸びる
        //v += 0.01*v;
      ret++;
    }

    //cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3604
# coding: utf-8

L, R = map(int, input().split())


if R - L >= 2019:
    ans = 0
else:
    ans = 2020
    for i in range(L, R):
        for j in range(i+1, R+1):
            tmp = (i * j) % 2019
            if tmp < ans:
                ans = tmp
print(ans)


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    dic = {}
    for i in range(10):
        for j in range(10):
            dic[(i, j)] = 0
    for i in range(1, N+1):
        tmp = str(i)
        s, e = int(tmp[0]), int(tmp[-1])
        dic[(s, e)] += 1
    ans = 0
    for i in range(10):
        for j in range(10):
            ans += dic[(i, j)] * dic[(j, i)]
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import sys

N, K = map(int, input().split())

if not (K <= (N-1)*(N-2)//2):
    print('-1')
    sys.exit()

anss = []
for i in range(2, N+1):
    anss.append((1, i))

M = (N-1)*(N-2)//2
for i in range(2, N+1):
    for j in range(i+1, N+1):
        if M == K:
            break
        anss.append((i, j))
        M -= 1
    else:
        continue
    break

print(len(anss))
for i, j in anss:
    print(i, j)


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

using namespace std;

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

int cnt_digits(ll n) {
    int digits = 0;
    
    while (n > 0) {
        n /= 10;
        digits++;
    }
    
    return digits;
}


int main() {
    ll n;
    cin >> n;
    
    int ans = cnt_digits(n);
    
    for (ll i = 1LL; i * i <= n; i++) {
        if (n % i == 0) {
            ll b = n / i;
            int cur_digits = max(cnt_digits(i), cnt_digits(b));
            if (ans > cur_digits) {
                ans = cur_digits;
            }
        }
    }
    
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

import sys
input = sys.stdin.readline

A, B, K = map(int, input().split())

cnt = 0
for i in range(100, 0, -1):
    if A % i == 0 and B % i == 0:
        cnt += 1
    
    if cnt == K:
        print(i)
        break


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef long double ld;
typedef pair<ld, ll> P;

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

const ll INF=1001000000;
const ll mod=1000000007;

int main(){
  ll x,k,d;
  cin>>x>>k>>d;
  ll a=x%d;
  ll b=abs(x-a)/d;
  //cout<<b<<endl;
  if(b>k){
    if(x<0){
      cout<<abs(x+k*d)<<endl;
    }
    else{
      cout<<abs(x-k*d)<<endl;
    }
  }
  
  else if((k-b)%2==0){
    cout<<abs(a)<<endl;
  }
  else{
    if(a<0){
      cout<<abs(a+d)<<endl;
    }
    else{
      cout<<abs(a-d)<<endl;
    }
  }
}





Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main
{

	public static void main(String[]args)throws Throwable
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer arr[] = new Integer[n * 3];
		n *= 3;
		for(int i = 0 ; i < n ; ++i)
			arr[i] = sc.nextInt();
		Arrays.sort(arr);
		int l = 0;
		int r = n - 1;
		long sum = 0;
		while(l <= r)
		{
			l++;
			r--;
			sum += 1L*arr[r];
			r--;
		}
		System.out.println(sum);
		
	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;


		Scanner(InputStream s)  { br = new BufferedReader(new InputStreamReader(s)); }

		String next() throws IOException
		{

			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();

		}
		int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); }



	}
}


Measured memory_bytes: 59252
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k,m) for(auto k:m)
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000007
#define sz(a) ll((a).size())
#define pii 3.1415926535897
#define quick ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// stoll(s);
int main()
{
    quick
	ll t;t=1;
    // cin >> t;
	while(t--){
        int x,y; cin >>x>>y;
        if(y%2==1)cout<<"No";
        else if(y<2*x || y>4*x)cout<<"No";
        else cout<<"Yes";
    }
}

Measured memory_bytes: 3660
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<iosfwd>
#include<sstream>
#include<math.h>
#define N 100
using namespace std;
int main(void){
    string a;
    cin >> a;
    const char* x= a.c_str();
    int len= strlen(x);
    int cnt=0;
    for(int i=0; i<len; i++){
        // cout << i%2 << endl;
        if(x[i]-'0' != i%2) {
            cnt++;

            // cout << x[i] << i%2 << endl;
        }
    }
    
    cout << min(cnt, len-cnt) << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

typedef pair<ll, PI> PLPI;

/*
 * Union-Find tree
 * header requirement: vector
 */
class UnionFind {
private:
  std::vector<int> disj;
  std::vector<int> rank;
public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
	++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) {
    return root(x) == root(y);
  }
};


int main(void){
  int n, q;
  cin >> n >> q;
  VI a(q), b(q);
  VL c(q);
  REP(i, 0, q) {
    cin >> a[i] >> b[i] >> c[i];
  }
  VL perim(n, 1e17);
  REP(i, 0, q) {
    perim[a[i]] = min(perim[a[i]], c[i] + 1);
    perim[b[i]] = min(perim[b[i]], c[i] + 2);
  }

  REP(i, 0, 2 * n) {
    perim[(i + 1) % n] = min(perim[(i + 1) % n], perim[i % n] + 2);
  }
  
  UnionFind uf(n);
  vector<PLPI> pool;
  ll tot = 0;
  REP(i, 0, q) {
    pool.push_back(PLPI(c[i], PI(a[i], b[i])));
  }
  REP(i, 0, n) {
    pool.push_back(PLPI(perim[i], PI(i, (i + 1) % n)));
  }
  sort(pool.begin(), pool.end());
  REP(i, 0, pool.size()) {
    int u = pool[i].second.first;
    int v = pool[i].second.second;
    if (not uf.is_same_set(u, v)) {
      uf.unite(u, v);
      tot += pool[i].first;
    }
  }
  cout << tot << endl;
}


Measured memory_bytes: 14956
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define int long long
bool f(int p) {
	int q;
	q = p % 10;
	p /= 10;
	q *= 10;
	q += p % 10;
	p /= 10;
	p /= 10;
	return (p == q);
}
signed main() {
	int a, b; cin >> a >> b;
	int res = 0;
	for (int i = a; i <= b; i++)if (f(i))res++;
	cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){
    int n;
    cin >> n;
    int t = n%1000;
    cout << (1000-t)%1000 << endl;
    



    return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int Max = 0;

    for(int b = 1; b <= Math.sqrt(x); b++){
      int max = 0;
      int p = 2;
      while(Math.pow((double)b, (double)p) <= x){
        if(b == 1){max = 1; break;}
        max = (int)Math.pow((double)b, (double)p);
        p++;
      }
      Max = Math.max(Max, max);
    }

    System.out.println(Max);

  }
}

/*

int n = sc.nextInt();
String blank = sc.nextLine();
String s = sc.nextLine();
System.out.println();
System.exit(0)
*/


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/* priority_queue */
template<class T>
using pq = priority_queue<T>;
template<class T>
using greatpq = priority_queue<T,vector<T>,greater<T>>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define all(v) (v).begin(), (v).end()

int main(){
  int N,M;cin>>N>>M;
  vector<pll> XY;
  for(int i=0; i<N; i++){
    int a;cin>>a;
    XY.push_back({1,a});
  }
  for(int i=0; i<M; i++){
    int b,c;cin>>b>>c;
    XY.push_back({b,c});
  }
  sort(all(XY), [](pll a, pll b){
    return a.second>b.second;
  });

  ll ans = 0;
  for(pll x: XY){
    int times = x.first;
    if(times>N)times=N;
    ans += x.second*times;
    N-=times;
    if(N==0)break;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6384
#include<stdio.h>

int main (){
    int n;
    int t, a;
    scanf("%d%d%d", &n,&t,&a);
    int h[n];
    for(int i = 0; i < n;i++) scanf("%d", &h[i]);
    double T[n];
    for(int i = 0; i < n; i++){
        T[i] = t - h[i] * 0.006;
        if(T[i] > a)  T[i] = T[i] - a;
        else T[i] = a -T[i];
    }
    double min_t = 10000;
    int k;
    for(int  i = 0; i < n; i++ ){
        if(min_t > T[i]) {
            min_t = T[i];
            k = i;
        }
    }
    printf("%d", k + 1);
    return 0;

}

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

using namespace std;
using ll = long long;

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

int main() {
  int r, d, x;
  cin >> r >> d >> x;
  rep(i, 10) {
    int nx = r * x - d;
    x = nx;
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int ans = 100000000;

int main(){

    string s, t; cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.rbegin(), t.rend());
 
    if (s < t){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3556
#include <iostream>
#include <cmath>
#include <map>
#include <string>
#include <queue>

using namespace std;

static const int LIMIT = 100;
static const int N = 4;
static const char dir[4] = {'r', 'l', 'u', 'd'};
static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};

int MD[N*N][N*N];

class Puzzle {
 public:
  int v[N*N];
  int space_pos;
  int MD;
};

Puzzle state;
int limit;
int path[LIMIT];

bool isTarget(Puzzle& p) {
  for (int i = 0; i < N*N; i++) {
    if (state.v[i] != ((i+1) % (N*N))) {
      return false;
    }
  }
  return true;
}

int getAllMD(Puzzle& p) {
  int sum = 0;
  for (int i = 0; i < N*N; i++) {
    if (!p.v[i]) continue;
    sum += MD[p.v[i]-1][i];
  }
  return sum;
}

int dfs(int depth, int prev) {
  if (state.MD == 0) {
    return true;
  }
  if (depth + state.MD > limit) return false;
  for (int i = 0; i < 4; i++) {
    int sx = state.space_pos % N;
    int sy = state.space_pos / N;
    int tx = sx + dx[i];
    int ty = sy + dy[i];
    Puzzle tmp;
    if (tx >= 0 && tx < N &&
        ty >= 0 && ty < N &&
        max(prev, i) - min(prev, i) != 2) {
      tmp = state;
      state.MD -= MD[tx+ty*N][state.v[tx+ty*N]-1];
      state.MD += MD[sx+sy*N][state.v[tx+ty*N]-1];
      swap(state.v[sx+sy*N], state.v[tx+ty*N]);
      state.space_pos = tx+ty*N;
      if (dfs(depth+1, i)) {
        path[depth] = i;
        return true;
      }
      state = tmp;
    }
  }
  return false;
}

string iterative_deepening(Puzzle& in) {
  in.MD = getAllMD(in);

  for (limit = in.MD; limit <= LIMIT; limit++) {
    state = in;
    if (dfs(0, -100)) {
      string ans = "";
      for (int i = 0; i < limit; i++) {
        ans += dir[path[i]];
      }
      return ans;
    }
  }
}

int main() {
  for (int i = 0; i < N*N; i++) {
    for (int j = 0; j < N*N; j++) {
      MD[i][j] = abs(i/N - j/N) + abs(i%N - j%N);
    }
  }
  Puzzle p;
  for (int i = 0; i < N*N; i++) {
    cin >> p.v[i];
    if (!p.v[i]) p.space_pos = i;
  }
  cout << iterative_deepening(p).size() << endl;
  return 0;
}



Measured memory_bytes: 3228
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n; cin>>n;
	vint a(n);
	vint b(n);
	rep(i,n){
		int t; cin>>t;
		a[i] = t;
		b[i] = t;
	}
	sort(all(b));
	rep(i,n){
		if(a[i]==b[n-1])cout<<b[n-2]<<endl;
		else cout<<b[n-1]<<endl;
	}
	return 0;
}


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

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

	char X, Y;
	cin >> X >> Y;
	if (X < Y) {
		cout << "<";
		return 0;
	}
	if (X > Y) {
		cout << ">";
		return 0;
	}
	else cout << "=";
}

Measured memory_bytes: 256
#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);}

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

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


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	vl v={500,100,50,10,5,1};
	while(cin>>n,n){
		int c=0;
		n=1000-n;
		rep(i,6)if(n>=v[i]){
			c++;
			n-=v[i--];
		}
		puta(c);
	}
	return 0;
}


Measured memory_bytes: 3156
//============================================================================
// My word     : hakuna matata
// My wisdom   : وتحسب انك جرم صغير وفيك انطوى العالم الأكبر
//============================================================================
#include <bits/stdc++.h>
using namespace std;
void file()
{

    freopen("divisors.in", "r", stdin);
    //  freopen("out.txt", "w", stdout);

}
#define Star ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define mem(x,y)    memset(x,y,sizeof(x))
typedef long long ll;
const int maxsize=2e5+5,oo=0X3f3f3f3f;
ll n,c,ans,tot,arr[maxsize];





int main()
{
    Star;
    cin>>n>>c;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(int i=0;i<n-c;i++)
    {
        ans+=arr[i];
    
    }
    cout<<ans<<endl;
    














    return 0;
}


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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF INT_MAX;
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  int N;
  cin>>N;
  vector<int>a(N),b(N);
  for(int i=0;i<N;i++)cin>>a[i];
  for(int i=0;i<N;i++)cin>>b[i];
  ll sumA=0,sumB=0;
  for(int i=0;i<N;i++)sumA+=a[i],sumB+=b[i];
  ll n=sumB-sumA;
  if(n<0){
    cout<<"No"<<endl;
    return 0;
  }
  ll AB=0;
  for(int i=0;i<N;i++){
    if(a[i]<b[i])AB+=(b[i]-a[i])/2;
  }
  ll BA=0;
  for(int i=0;i<N;i++){
    if(a[i]>b[i])BA+=a[i]-b[i];
  }
  if(BA<=AB)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}




Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin >> n >> m;

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

    sort(a.begin(),a.end());

    priority_queue<ll> edge;

    for(int i = 1; i < m; i++){
        edge.push(a[i] - a[i-1]);
    }

    n--;

    while(n > 0 && !edge.empty()){
        n--;
        edge.pop();
    }

    ll ans = 0;

    while(!edge.empty()){
        ans += edge.top();
        edge.pop();
    }

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

Measured memory_bytes: 2168
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	x, y := scanInt(), scanInt()
	answer := isPossible(x, y)
	fmt.Println(answer)
}

func isPossible(x, y int) string {
	for i := 0; i <= x; i++ {
		y2 := 2*x + 2*i
		debug("y", y, "y2", y2, "i", i)
		if y2 == y {
			return "Yes"
		}
	}
	return "No"
}

func debug(a ...interface{}) {
	// fmt.Println(a...)
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,a,n) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
 
 
//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート
 
int main() {
  long long int n;
  cin >>n;
  
  
  long long int all,not0,not9,not09;
  all=1;
  not0=1;
  not9=1;
  not09=1;
  rep(i,0,n){
  all*=10;
  not0*=9;
  not9*=9;
  not09*=8;
  all%=MOD;
  not0%=MOD;
  not9%=MOD;
  not09%=MOD;
  }
  long long int ans;
  ans=all-not0-not9+not09;
  cout<<(ans+MOD+MOD)%MOD<<endl;
 return 0;
}

Measured memory_bytes: 3596
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn distance(a: &[f64], b: &[f64]) -> f64 {
    a.iter().zip(b.iter()).map(|(i,j)| {
        (i-j).powf(2.0)
    }).sum::<f64>().sqrt()
}

pub fn is_integer(f: f64) -> bool {
    f - f.floor() == 0.0
}

fn main() {
    input! {
        n: usize,
        d: usize,
        x: [[f64; d]; n],
    }
    let mut cnt = 0;
    for i in 0..n {
        for j in i+1..n {
            let dis = distance(&x[i], &x[j]);
            if is_integer(dis) { cnt+=1 }
        }
    }
    println!("{}", cnt);
}


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

int main() {
int x,a,b;
cin >> x >> a >> b;
int A = max(x,a) - min(x,a);
int B = max(x,b) - min(x,b);

if(A >B){
	cout << 'B' << endl;
}
else{
	cout << 'A' << endl;
}
}

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

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define pb push_back

const int INF = 100000000;
const int MAX_V = 100;


void solve() {

    while (true) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);

        if (!(a|b|c))
            break;

        int N;
        scanf("%d", &N);

        int num_items = a + b + c;
        vector<int> safe(num_items, 2);
        vector<vector<int>> fail;
        REP(i, N) {
            int ax, bx, cx, r;
            scanf("%d %d %d %d", &ax, &bx, &cx, &r);
            ax--; bx--; cx--;
            if (r == 1) {
                safe[ax] = safe[bx] = safe[cx] = 1;
            } else {
                fail.pb({ax, bx, cx});
            }
        }
        
        REP(i, fail.size()) {
            REP(j, 3) {
                if (safe[fail[i][j%3]] == 1 && safe[fail[i][(j+1)%3]] == 1) {
                    safe[fail[i][(j+2)%3]] = 0;
                    break;
                }
            }
        }

        REP(i, num_items) printf("%d\n", safe[i]);
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 2740
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import collections
count = 0
N = int(input())
c = collections.Counter(prime_factorize(N))

for i in c:
    p = i
    while (N%i==0):
        N /= i
        i *= p
        count += 1
#         print(N,i)
    if (N == 1):
        break
        
print(count)

Measured memory_bytes: 9528
#include <iostream>
#include <string>

using namespace std;

int main() {
	int H, W, N;
	cin >> H >> W >> N;
	int sr, sc;
	cin >> sr >> sc;
	string S, T;
	cin >> S;
	cin >> T;
	int AL=0, AR=0, AU=0, AD=0;
	int TL=0, TR=0, TU=0, TD=0;
	int BL=sc-1, BR=W-sc, BU=sr-1, BD=H-sr;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'L') AL++;
		if (S[i] == 'R') AR++;
		if (S[i] == 'U') AU++;
		if (S[i] == 'D') AD++;
		if (BL + TR < AL || BR + TL < AR || BU + TD < AU || BD + TU < AD) {
			cout << "NO" << endl;
			return 0;
		}
		if (T[i] == 'L' && BL + AR > TL) TL++;
		if (T[i] == 'R' && BR + AL > TR) TR++;
		if (T[i] == 'U' && BU + AD > TU) TU++;
		if (T[i] == 'D' && BD + AU > TD) TD++;
	}
	cout << "YES" << endl;
	return 0;
}

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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)


int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n,d,cnt=0,x,y;
        cin>>n>>d;
        while(n--)
        {
            cin>>x>>y;
            if(sq(x)+sq(y)<=sq(d)) cnt++;
        }
        cout<<cnt;

    }
    return 0;
}


Measured memory_bytes: 3652
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println(n * n * n);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 23764
import java.util.*;

public class Main {
    public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    
    int a,b,total;
    while(scan.hasNextInt()){
    a= scan.nextInt();
    b= scan.nextInt();
    total = a+b;
    int i=1;
    while(true){
        total = total /10;
        if (total == 0){
           System.out.println(i);
           break;
        }
        i++;
    }
    }
    
    
    }
}

Measured memory_bytes: 26460
library = """
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False
from libcpp cimport bool
cdef extern from "/opt/atcoder-stl/atcoder/dsu.hpp" namespace "atcoder":
    cdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
cdef extern from "/opt/atcoder-stl/atcoder/fenwicktree.hpp" namespace "atcoder":
    cdef cppclass fenwick_tree[T]:
        fenwick_tree(int n)
        void add(int p, T x)
        T sum(int l, int r)
cdef class DSU:
    cdef dsu *_thisptr
    def __cinit__(self, int n):
        self._thisptr = new dsu(n)
    def __dealloc__(self):
        del self._thisptr
    cpdef int merge(self, int a, int b):
        return self._thisptr.merge(a, b)
    cpdef bool same(self, int a, int b):
        return self._thisptr.same(a, b)
    cpdef int leader(self, int a):
        return self._thisptr.leader(a)
    cpdef int size(self, int a):
        return self._thisptr.size(a)
cdef class BIT:
    cdef fenwick_tree[long] *_thisptr
    def __cinit__(self, int n):
        self._thisptr = new fenwick_tree[long](n)  
    def __dealloc__(self):
        del self._thisptr
    cpdef void add(self, int p, long x):
        self._thisptr.add(p, x)
    cpdef long sum(self, int l, int r):
        return self._thisptr.sum(l, r)
"""
import os,sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('atcoder.pyx','w').write(library)
    os.system('cythonize -i -3 -b atcoder.pyx')

# ↑ここまでライブラリ↓ここから解法

import sys
import atcoder
input = sys.stdin.buffer.readline
n, q = map(int, input().split())
bit = atcoder.BIT(n)
*map(bit.add, range(n), map(int, input().split())),
res = []
for i in range(q):
    t, u, v = map(int, input().split())
    if t: res.append(bit.sum(u, v))
    else: bit.add(u, v)
print('\n'.join(map(str, res)))

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

int main(){
  int w,h,x,y;
  cin>>w>>h>>x>>y;
  if(x+x==w && y+y==h){
    cout<<fixed<<setprecision(15)<<(double)w*h*0.5<<" "<<1<<endl;
  }else{
    cout<<fixed<<setprecision(15)<<(double)w*h*0.5<<" "<<0<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,a,b;cin>>n>>a>>b;
    if(a%2==b%2){
        cout<<(b-a)/2<<endl;
        return 0;
    }
    ll f=n-b+1;
    f+=(b-a-1)/2;
    ll g=a;
    g+=(b-a-1)/2;
    cout<<min(f,g)<<endl;
}


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

int main(){
  int n, x;
  cin >> n >> x;
  int m[n];
  for(int j=0;j<n;j++){
    cin >> m[j];
  }

  int sum = x;

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

  int min_x = 10000;
  for(int k=0;k<n;k++){
    if(m[k] < min_x){
      min_x = m[k];
    }
  }

  cout << n + (sum / min_x) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    // N本の木がある
    int N;
    cin >> N;
    
    // 監視員はi+-Dの範囲を見守ることができる
    int D;
    cin >> D;
    
    // 監視員の数をWとして、Wの数を求める式
    
    int W;
    
    W = ( N / (D * 2 + 1) );
    if ( ( N % (D * 2 +1 ) ) == 0 ) {
    cout << W << endl;
    }
    else {
        cout << W + 1 << endl;
    }
    return 0;
}




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

int lcm(int a, int b){
	int v0 = a, v1 = b, v2;
	while((v2 = v0 % v1) != 0){
		v0 = v1;
		v1 = v2;
	}
	return a*b / v1;
}

int main(){
    int n, a[1000], ans = 1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans = lcm(ans,a[i]);
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
ll power(ll a,int n){
  if(n==0)
    return 1;
  if((n%2)==0)
    return (power((a*a)%mod,n/2))%mod;
  else
    return (a*(power((a*a)%mod,n/2))%mod)%mod;    
}
int main(){
FASTIO
ll n;
cin>>n;
cout<<((n/500)*1000)+(((n%500)/5)*5);
return 0;
}

Measured memory_bytes: 256
let () =
  let sum = ref 0 in
  let ans = ref 0 in
  Scanf.scanf "%d\n" @@ fun n ->
  for i = 0 to n - 1 do
    Scanf.scanf "%d " @@ fun d ->
    ans := (!ans + !sum * d) mod ((int_of_float(10. ** 9.)) + 7);
    sum := (!sum + d) mod ((int_of_float(10. ** 9.)) + 7)
  done;
  Printf.printf "%d\n" (!ans mod ((int_of_float(10. ** 9.)) + 7))

Measured memory_bytes: 6348
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

const int MAX_N = 105, MAX_K = 1e5 + 5, MOD = 1e9 + 7;
long long no_of_ways[MAX_N][MAX_K], sum_no_of_ways[MAX_N][MAX_K];

int main()
{
    int no_of_people, no_of_candies;
    cin >> no_of_people >> no_of_candies;

    vector <int> limit(no_of_people + 1);
    for(int i = 1; i <= no_of_people; i++)
        cin >> limit[i];

    //f(i, j) = f(i - 1, j) + f(i - 1, j - 1) + f(i - 1, j - 2) + f(i - 1, j - 3) + ... + f(i - 1, j - a_i);

    no_of_ways[0][0] = 1;
    for(int i = 1; i <= no_of_candies; i++)
        no_of_ways[0][i] = 0;

    for(int i = 1; i <= no_of_people; i++)
    {
        sum_no_of_ways[i - 1][0] = no_of_ways[i - 1][0];
        for(int j = 1; j <= no_of_candies; j++)
        {
            sum_no_of_ways[i - 1][j] = (sum_no_of_ways[i - 1][j - 1] + no_of_ways[i - 1][j])%MOD;
        }

        for(int j = 0; j <= no_of_candies; j++)
        {
            int left = j, right = (j - limit[i] - 1);

            no_of_ways[i][j] = sum_no_of_ways[i - 1][left];

            if(right >= 0)
            {
                no_of_ways[i][j] = (no_of_ways[i][j] - sum_no_of_ways[i - 1][right] + MOD)%MOD;
            }
        }
    }

    cout << no_of_ways[no_of_people][no_of_candies];
    return 0;
}


Measured memory_bytes: 160000
c = [list(map(int, input().split())) for _ in [0]*3]
a = [0]*3
b = [0]*3
for i in range(3):
    b[i] = c[0][i] - a[0]
for i in range(3):
    a[i] = c[i][0] - b[0]
for i in range(3):
    for j in range(3):
        if a[i] + b[j] != c[i][j]:
            print('No')
            exit()
print('Yes')

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

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

int main() {
  char d, a, b, c;
  cin >> a >> d >> d >> d >> b >> d >> d >> d >> c;
  cout << a << b << c << "\n";
}


Measured memory_bytes: 256
import copy

n = int(input())
x = list(map(int, input().split()))
y = copy.deepcopy(x)
y.sort()
a = y[n//2 -1]
b = y[n//2]
for i in range(n):
    if x[i]<=a:
        print(b)
    elif a<x[i]:
        print(a)


Measured memory_bytes: 26688
def main():
    n, m = list(map(int, input().split()))
    p = []
    s = []
    for i in range(m):
        a, b = input().split()
        p.append(int(a))
        s.append(b)
    buff = {}
    memo = set()
    wans = 0
    for i in range(m):
        
        if p[i] in memo:
            continue
        else:
            if s[i] == "AC":
                if p[i] in buff:
                    wans += buff[p[i]]
                memo.add(p[i])
            else:
                if p[i] in buff:
                    buff[p[i]] = buff[p[i]] + 1
                else:
                    buff[p[i]] = 1
    print(len(memo), wans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 66520
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include <numeric>
using namespace std;
int main(void) {
	int N,M,i,j,a,b,ok,okk,ans=0;
	int A[60];
	int B[60];
	
	scanf("%d %d", &N,&M);
	vector<int>v(N);

	for (i = 0; i < M; i++) {
		scanf("%d %d", &a, &b);
		A[i] = a;
		B[i] = b;
		A[i + M] = b;
		B[i + M] = a;
	}
	for (i = 0; i < N; i++) {
		v[i] = i + 1;
	}
	do {
		if (v[0] != 1) { break; }
		okk = 1;
		for (i = 1; i < N; i++) {
			ok = 0;
			for (j = 0; j < M*2; j++) {
				if (v[i - 1] == A[j] && v[i] == B[j]) {ok = 1; break;}
			}
			if (ok == 0) { okk = 0; break; }
		}
		if (okk == 1) { ans++; }

	} while (next_permutation(v.begin(), v.end()));     // 次の順列を生成
	printf("%d", ans);

	
	return 0;
}

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

typedef long long ll;
const int MOD = 1000000007;

int n, k, ans;
vector<int> fac, dp;

inline int pwr(int a, int b) {
	int c = 1;
	while (b) {
		if (b & 1) c = (ll)c * a % MOD;
		b >>= 1; a = (ll)a * a % MOD;
	}
	return c;
}
inline void add(int &x, int a) {
	x = (x + a >= MOD) ? x + a - MOD : x + a;
}
inline void sub(int &x, int a) {
	x = (x < a) ? x - a + MOD : x - a;
}

int main(void) {
	cin >> n >> k;
	int m = sqrt(n);
	for (int i = 1; i <= m; i++)
		if (n % i == 0) {
			fac.push_back(i);
			fac.push_back(n / i);
		}
	sort(fac.begin(), fac.end());
	fac.erase(unique(fac.begin(), fac.end()), fac.end());
	dp.resize(fac.size());
	for (int i = 0; i < fac.size(); i++) {
		dp[i] = pwr(k, (fac[i] + 1) / 2);
		for (int j = 0; j < i; j++)
			if (fac[i] % fac[j] == 0)
				sub(dp[i], dp[j]);
		if (fac[i] & 1) add(ans, (ll)dp[i] * fac[i] % MOD);
		else add(ans, (ll)dp[i] * fac[i] / 2 % MOD);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(),a.end());
  cout << abs(a[0]-a[1])+abs(a[1]-a[2]) << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

s = input()
t = input()

dicts = defaultdict(int)
dictt = defaultdict(int)

cs = []
ct = []

for i in range(len(s)):
    dicts[s[i]] += 1
    dictt[t[i]] += 1
    cs.append(dicts[s[i]])
    ct.append(dictt[t[i]])


if cs == ct:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 25408
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=2010;

int n,sum,A[maxn];

bitset<maxn*maxn> S;

int32_t main(){
    scanf("%d",&n);
    rep(i,0,n){
	scanf("%d",A+i);
	sum+=A[i];
    }
    S[0]=1;
    rep(i,0,n){
	S|=(S<<A[i]);
    }
    rep(i,sum/2,sum+1){
	if(i*2>=sum && S[i]){
	    printf("%d\n",i);
	    return 0;
	}
    }
}


Measured memory_bytes: 1792
h[201],w[201],d[201];main(n,i,j,r){for(;scanf("%d",&n),n;printf("%d\n",r)){
for(i=0;i<n;i++)scanf("%d%d",h+i,w+i);
for(scanf("%d",&r),n+=r;i<n;i++)scanf("%d%d",h+i,w+i);
for(i=0;i<n-1;i++)for(j=0;j<n-i-1;j++)if(h[j]>h[j+1])r=h[j],h[j]=h[j+1],h[j+1]=r,r=w[j],w[j]=w[j+1],w[j+1]=r;
for(memset(d,0,sizeof(d)),r=i=0;i<n;r=r>d[i]?r:d[i],i++)for(d[i]=1,j=0;j<i;j++)if(h[j]<h[i]&&w[j]<w[i])d[i]=d[j]>=d[i]?d[j]+1:d[i];
}exit(0);}

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

int main() {
    int A, B, C, X, Y;
    cin >> X >> Y >> A >> B >> C;
    vector<int> p(A), q(B), r(C);
    for (int i = 0; i < A; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < B; i++) {
        cin >> q[i];
    }
    for (int i = 0; i < C; i++) {
        cin >> r[i];
    }
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    for (int i = 0; i < X; i++) {
        r.push_back(p[i]);
    }
    for (int i = 0; i < Y; i++) {
        r.push_back(q[i]);
    }
    sort(r.rbegin(), r.rend());
    long long answer = 0;
    for (int i = 0; i < X + Y; i++) {
        answer += r[i];
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 2552
#include <iostream>
#include <string>

int main()
{
	using std::string;
	int a, b;
	std::cin >> a >> b;
	string str1(a, char(b + '0'));
	string str2(b, char(a + '0'));
	if (str1 < str2)
		std::cout << str1 << std::endl;
	else
		std::cout << str2 << std::endl;
	return 0;
}

Measured memory_bytes: 256