akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

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

  ll x,k,d;

  cin >> x >> k >> d;

  x = abs(x);
  ll biggercnt = min(x/d,k);
  if((k-biggercnt)%2 == 0){    
    cout << abs(x-biggercnt*d) << endl;
  }else{
    cout << abs(x-(biggercnt+1)*d) << endl;
  }  
  return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main (){
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  scanf("%d",&k);
  printf("%d\n",a[k-1]);
  return 0;
}

Measured memory_bytes: 128
n, m = gets.chomp.split(" ").map(&:to_i)
ans = Array.new(n, -1)
graph = Array.new(n).map{Array.new()}

m.times do
    a, b = gets.chomp.split(" ").map(&:to_i)
    graph[a-1] << b-1
    graph[b-1] << a-1
end

queue = [0]
ans[0] = 0

until queue.empty?
    v = queue.shift
    graph[v].each do |i|
        next if ans[i] != -1
        ans[i] = v
        queue << i
    end
end

ans.shift

if ans.include?(-1) then
    puts "No"
else
    puts "Yes"
    puts ans.map{|v| v + 1}.join("\n")
end

Measured memory_bytes: 34940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){

    
    int k = 0;
    int n = 0;
    while(cin >> k >> n)
    {
        int m=0;
        vector<int> v;
        int h=0;
        
        for(int i =0;i < n;i++)
        {
            cin >> h;
            v.push_back(h);
        }
        v.push_back(k+v[0]);
        for(int j=1;j<v.size();j++)
        {
            m =max(m,v[j] - v[j-1]);
        }
        cout << k - m << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>

using namespace std;

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

int sum[100001];
int n, m;

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

	sum[0] = 0;
	REP(i, n - 1) {
		int d;
		scanf("%d", &d);
		sum[i + 1] = sum[i] + d;
	}
	int ans = 0, pos = 0;
	REP(i, m) {
		int a;
		scanf("%d", &a);
		if (a > 0) ans += sum[pos + a] - sum[pos];
		else ans += sum[pos] - sum[pos + a];
		ans %= 100000;
		pos += a;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

int main(){
   string s;
   cin>>s;
   if(s == "SAT")cout<<1<<endl;
    if(s == "FRI")cout<<2<<endl;
    if(s == "THU")cout<<3<<endl;
    if(s == "WED")cout<<4<<endl;
    if(s == "TUE")cout<<5<<endl;
    if(s == "MON")cout<<6<<endl;
    if(s == "SUN")cout<<7<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> W(N);
    int totalW=0;
    for (int i=0;i<N;i++){
        cin >> W[i];
        totalW+=W[i];
    }
    int subtotal=0;
    int mins = 100*100+1;
    for (int i=0;i<N;i++){
        subtotal+=W[i];
        mins=min(mins,abs(subtotal-(totalW-subtotal)));
    }
    cout << mins;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

string s,t="CF";
int I=0;

int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]==t[I]) I++;
	}
	if(I==2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;

 
int main() {
	
	ll N,K;
	cin>>N>>K;
	ll g=N/K;
	if(K%2==0){
		ll gg=N/(K/2)-g;
		ce(g*g*g+gg*gg*gg)
	}else{
		
		ce(g*g*g)
	}
}

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

template<typename T> T GCD(T a, T b) {
    if (b == 0) return a;
    if (a % b == 0) return b;
    return (GCD(b, a % b));
}

int main() {
    long long a, b;
    cin >> a >> b;
    cout << GCD(a, b) << endl;
    return 0;
}


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

int main()
{
    int n,k,ans=0,j,q;
    scanf("%d",&n);
    int a[n],i;
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);

    for(i=0; i<n; i++)
    {
        for(j=i+1; j<n-1; j++)
        {
            if(a[j+1]>=a[i]+a[j])
                continue;
            if(a[n-1]<a[i]+a[j])
            {
                ans+=(n-1-j);
                continue;
            }
            int m,l=j+1,r=n-1,s=a[i]+a[j];
            for(q=1; q<=300; q++)
            {
                m=(l+r)/2;
                if(s>a[m])
                {
                    l=m;
                }
                else
                    r=m;
            }
            ans+=(m-j);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  vi a(5);

  rep(i,5){
    cin >> a[i];
  }
  int k;
  cin >> k;

  bool b = true;

  vsort(a);


  if(a[4] - a[0] <= k) cout << "Yay!";
  else
  {
    cout << ":(";
  }
  

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
 int a,b,c,d;
 cin >> a >> b >> c >> d;
 cout << max(a*b,c*d) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int s;
    cin>>s;
    int a[1000001]={};
    a[s]=1;
    int cnt=1;
    while(1){
        cnt++;
        if(s%2==0) s/=2;
        else s=s*3+1;
        if(a[s]==1) break;
        else a[s]=1;
    }
    
    cout<<cnt<<endl;
    return 0;
}



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

int main(){
	int n;
	bool b=false;
	cin>>n;
	if(n==1||n==2||n==3||n==4||n==5||n==6||n==7||n==8||n==9||n==10||n==12||n==14) b=true;
	if(n==15||n==16||n==18||n==20||n==21||n==24||n==25||n==27||n==28||n==30||n==32) b=true;
	if(n==35||n==36||n==40||n==42||n==45||n==48||n==49||n==54||n==56||n==63||n==64) b=true;
	if(n==72||n==81) b=true;
	if(b==true) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
count = 1
for i in range(int(n ** 0.5)):
    test = i + 1
    n2 = n
    if test == 1:
        continue
    while n2 % test == 0:
        n2 //= test
    else:
        n2 %= test
    if n2 == 1:
        count += 1
n3 = n - 1
a = []
for i in range(1, int(n3 ** 0.5) + 1):
    if n3 % i == 0:
        temp = n3 // i
        if temp > int(n ** 0.5):
            a.append(temp)
count += len(a)
print(count)

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

int main() {
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int ans;
  if (X>Y){
    ans=min(min(A*X+B*Y,C*2*Y+A*(X-Y)),C*2*X);
  }
  else {
    ans=min(min(A*X+B*Y,C*2*X+B*(Y-X)),C*2*Y);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<ll>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1e5 + 55, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
vi g[maxn];
int s, t;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int f, t, i = 0; i < m; i++) {
		cin >> f >> t;
		g[f].pb(t);
	}
	queue<pair<int, int>> q;
	vector<vi> dist(n+1, vi(3, 1<<30));
	cin >> s >> t;
	q.push({s, 0});
	dist[s][0] = 0;
	int u, r;
	while(!q.empty()) {
		tie(u, r) = q.front();
		q.pop();
		int nr = (r+1)%3;
		for(auto i : g[u]) {
			if(dist[i][nr]==1<<30) {
				dist[i][nr] = dist[u][r] + 1;
				q.push({i, nr});
			}
		}
	}
	if(dist[t][0]==1<<30) dist[t][0] = -3;
	cout << dist[t][0]/3;
}


Measured memory_bytes: 11264
#include <stdio.h>



int count=0;
int temp[500000];    

void MergeSort(int *,int,int);


int main(void)
{
  int i,n;
 
  int A[1000000];
 
  scanf("%d",&n);
  for (i = 0; i < n; i++)
    scanf("%d",&A[i]);

  MergeSort(A,0,n-1);

  /*出力*/
  
  for (i=0;i<n-1;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
  printf("%d\n",count);
  return 0;
}

/* left から right マージソート */
void MergeSort(int *A, int left, int right)
{
  int mid,i,j,k;
   /* 配列の要素が一つの場合 */
  if (left>=right)             
    return;                     

  
  mid=(left+right)/2;      
  MergeSort(A,left,mid);       
  MergeSort(A,mid+1,right);  

  /* left から mid*/
  for(i=left;i<=mid;i++)
    temp[i]=A[i];

  /* mid + 1からright */
  for(i=mid+1,j=right;i<=right;i++,j--)
    temp[i]=A[j];

  i=left;         
  j=right;       

  for(k=left;k<=right;k++){    
    if(temp[i]<=temp[j])      
      A[k]=temp[i++];
    
    else
      A[k]=temp[j--];

    count++;
  }
}



Measured memory_bytes: 6644
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pradyumn Agrawal coderbond007  PLEASE!! PLEASE!! HACK MY SOLUTION!!
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            long sum = 0;
            for (int i = 0; i < n; ++i) {
                int l = in.nextInt();
                int r = in.nextInt();
                sum += r - l + 1;
            }
            out.println(sum);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        private static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

int main(){
  int N,M;
  cin >> N;
  vector<string> s(110);
  for(int i=0;i<N;i++){cin >> s[i];}
  cin >> M;
  vector<string> t(110);
  for(int i=0;i<M;i++){cin >> t[i];}
  int ans=0; int count;
  for(int i=0;i<N;i++){
    count=0;
    for(int j=0;j<N;j++){if(s[i]==s[j])count++;}
    for(int j=0;j<M;j++){if(s[i]==t[j])count--;}
    ans=max(ans,count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

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

    int tt, ft, ot;
    tt = ft = ot = -1;

    for (int a = 0; a <= n; ++a){
        for (int b = 0; a + b <= n; ++b) {
            int c = n - (a + b);
            int total = a * 10000 + b * 5000 + c * 1000;
            if (total == y){
                tt = a;
                ft = b;
                ot = c;
            }
        }
    }
    cout << tt << " " << ft << " " << ot << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

template<class T>bool chmax(T &a, const T &b) { if( a < b ) { a = b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if( b < a ) { a = b; return 1; } return 0;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / (b))
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))
#define int long long int //dont forget to change int to signed

signed main() {
	int N, K;
	scanf("%lld %lld", &N, &K);
	int p;
	for (int i = 1; i <= N; i++) {
		int a;
		scanf("%lld", &a);
		if (a == 1) p = i;
	}
	int lans, rans;
	int t = ROUNDUP(p-1, K-1);
//	lans = t + ROUNDUP(N-t*(K-1), K-1);
	lans = t + ROUNDUP((N-(1+t*(K-1))),K-1);

	printf("%lld\n", lans);
	return 0;
}


	


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

int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
int primeCount[15];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < 15; i++)
    {
        primeCount[i] = 0;
        int u = primes[i];
        while (u < n)
        {
            primeCount[i] += n / u;
            u *= primes[i];
        }
    }
    int result = 0;
    for (int a = 0; a < 15; a++)
    {
        for (int b = a + 1; b < 15; b++)
        {
            for (int c = 0; c < 15; c++)
            {
                if (c != a && c != b && primeCount[a] >= 4 && primeCount[b] >= 4 && primeCount[c] >= 2)
                {
                    result++;
                }
            }
        }
    }
    for (int a = 0; a < 15; a++)
    {
        for (int b = 0; b < 15; b++)
        {
            if (a != b && primeCount[a] >= 14 && primeCount[b] >= 4)
            {
                result++;
            }
            if (a != b && primeCount[a] >= 24 && primeCount[b] >= 2)
            {
                result++;
            }
        }
    }
    for (int a = 0; a < 15; a++)
    {
        if (primeCount[a] >= 74) {result++;}
    }
    cout << result << endl;
}


Measured memory_bytes: 256
A_List_1 = list(map(int,input().split()))
A_List_2 = list(map(int,input().split()))
A_List_3 = list(map(int,input().split()))



N = int(input())
#B_List = []
for i in range(N):
    n = int(input())
    for j in range(3):
        if n == A_List_1[j]:
            A_List_1[j] = 0
        if n == A_List_2[j]:
            A_List_2[j] = 0
        if n == A_List_3[j]:
            A_List_3[j] = 0


sum_1 = A_List_1[0] + A_List_1[1] + A_List_1[2]
sum_2 = A_List_2[0] + A_List_2[1] + A_List_2[2]
sum_3 = A_List_3[0] + A_List_3[1] + A_List_3[2]
naname_1 = A_List_1[0] + A_List_2[1] + A_List_3[2]
naname_2 = A_List_1[2] + A_List_2[1] + A_List_3[0]
tate_0 = A_List_1[0] + A_List_2[0] + A_List_3[0]
tate_1 = A_List_1[1] + A_List_2[1] + A_List_3[1]
tate_2 = A_List_1[2] + A_List_2[2] + A_List_3[2]

if sum_1 == 0 or sum_2 == 0 or sum_3 == 0 or naname_1 == 0 or naname_2 == 0 or tate_0 == 0 or tate_1 == 0 or tate_2 == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
<?php
$L=trim(fgets(STDIN));

$p0=0;
$p1=0;

for($i=0;$i<$L;$i++){
  $C=explode(' ',trim(fgets(STDIN)));

  if($C[0]<$C[1]){$p1+=3;continue;}
  if($C[0]>$C[1]){$p0+=3;continue;}
  ++$p0;
  ++$p1;
}

echo $p0,' ',$p1;
?>

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

int main(){
    int x;
    int d1, d2, p;
    cin >> x;
    d1 = x / 500;
    x = x % 500;
    d2 = x / 5;
    p = (d1 * 1000) + (d2 * 5);
    cout << p << endl;

    return 0;
}

Measured memory_bytes: 256
/**

  @@@@@@@  @@@@  @@@@  @@@@  @@@@  @
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @@@@  @@@@  @@@@  @  @  @

**/
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define str string
#define pi pair
#define tup tuple
#define vec vector
#define temp template
#define tn typename

#define ff first
#define ss second
#define SZ(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rsz resize
#define ins insert
#define fr front
#define bc back
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk make_pair

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ROF(i, a, b) for (ll i = (a); i >= (b); i--)
#define trav(a, x) for (auto &a : x)
#define popcount __builtin_popcountll
#define ctz __builtin_ctzll
#define clz __builtin_clzll
#define gcd __gcd

#define max(a, b) max((ll) a, (ll) b)
#define min(a, b) min((ll) a, (ll) b)

// DEBUG
#define ts to_string
temp<tn A, tn B> str ts(pi<A, B> p);
temp<tn A, tn B, tn C> str ts(tup<A, B, C> p);
str ts(const str& s) { return '"' + s + '"'; }
str ts(const char* s) { return ts((str) s); }
str ts(bool b) { return (b ? "true" : "false"); }
str ts(vec<bool> v) { bool f = true; str res = "{";
FOR(i, 0, static_cast<ll>(v.size()) - 1)
{ if (!f) res += ", "; res += ts(v[i]);
f = false; } res += "}"; return res; }
temp<size_t N> str ts(bitset<N> v) { str res = "";
trav(a, v) { res += (char) ('0' + a); } return res; }
temp<tn A> str ts(A v) { bool f = true; str res = "{";
trav(x, v) { if (!f) res += ", "; res += ts(x);
f = false; } res += "}"; return res; }
temp<tn A, tn B> str ts(pi<A, B> p) {
  return "(" + ts(p.ff) + ", " + ts(p.ss) + ")"; }
temp<tn A, tn B, tn C> str ts(tup<A, B, C> t) {
  return "(" + ts(get<0>(t)) + ", " + ts(get<1>(t)) + ", " + ts(get<2>(t)) + ")"; }
void DBG() { cerr << endl; }
temp<tn H, tn... T> void DBG(H h, T... t) { cerr << " " << ts(h); DBG(t...); }
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", DBG(__VA_ARGS__);
#else
#define dbg(...) 42
#endif

// INPUT AND OUTPUT
temp<tn T> void re(T& x) { cin >> x; };
temp<tn H, tn... T> void re(H& h, T&... t) { re(h); re(t...); }
temp<tn T> void pr(T x) { cout << x; };
temp<tn H, tn... T> void pr(H h, T... t) { pr(h); pr(t...); }
temp<tn T> void pri(T x) { cout << x; cout << endl; }; // used for interactives
temp<tn H, tn... T> void pri(H h, T... t) { pri(h); pri(t...); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x, n;
  re(x, n);
  vec<ll> mark(102);
  FOR(i, 0, n - 1) {
  	ll y;
  	re(y);
  	mark[y] = 1;
	}
	ll ans = (ll) 9e18;
	ll what = -1;
	FOR(i, 0, 101) {
		if (mark[i]) {
			continue;
		}
		if (abs(x - i) < ans) {
			ans = abs(x - i);
			what = i;
		}
	}
	pr(what, '\n');
  return 0;
}




Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

// 素因数分解
/*
 * [2]-> 5, [3] -> 5のとき N = 2^5 * 3^5
 */
template<typename T>
map<T, long long> factorize(T x) {
  map<T, long long> res;
  for (long long i = 2; i * i <= x; ++i) {
    while (x % i == 0) {
      x /= i;
      res[i] += 1;
    }
  }
  if (x != 1) res[x]++;
  return res;
}

int main() {
  ll l,r;
  cin >> l >> r;
  ll sub1 = l / 2019;
  ll sub2 = r / 2019;
  
  if (sub1 != sub2) {
    cout << 0 << endl;
    return 0;
  } else {
    ll ans = INF;
    for (ll i = l; i < r; ++i) {
      for (ll j = i+1; j < r+1; ++j) {
        ll tmp = (i * j) % 2019;
        // cout << tmp << endl;
        ans = min(ans, tmp);
      }
    }
    cout << ans << endl;
  }

  
}


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

using namespace std;

//#define FILE_IO

const int mod = 1e9 + 7;

int N;
int dp[3005][3005], sum[3005][3005];
char s[3005];

/// dp[i][j] = nr perm de lungime i care respecta [1, i] si au j pe ultima pozitie

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    //freopen("1.out", "w", stdout);
    #endif

    scanf("%d\n", &N);
    scanf("%s", s + 1);

    dp[1][1] = 1;
    for(int i = 1; i <= N; i++) sum[1][i] = 1;
    for(int i = 2; i <= N; i++)
        for(int j = 1; j <= i; j++)
        {
            if(s[i - 1] == '<')
                dp[i][j] = sum[i - 1][j - 1];
            else if(s[i - 1] == '>')
                dp[i][j] = (sum[i - 1][i - 1] - sum[i - 1][j - 1] + mod) % mod;
            sum[i][j] = (sum[i][j - 1] + dp[i][j]) % mod;
        }

    cout << sum[N][N] << '\n';

    return 0;
}


Measured memory_bytes: 69504
#include <bits/stdc++.h>
using namespace std;
int main() {
  int r[9]={0},n,a,c=0; cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a/400<8) r[a/400]++;
    else r[8]++;
  }
  for(int i=0;i<8;i++) if(r[i]) c++;
  if(c) cout<<c<<" "<<c+r[8]<<endl;
  else cout<<1<<" "<<r[8]<<endl;
}

Measured memory_bytes: 3592
//  LINK ZADATKA: http://agc019.contest.atcoder.jp/tasks/agc019_a

#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <fstream>
#include <cstring>
#include <string>
#include <climits>

using namespace std;

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;


#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define INF 999999999
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define _gcd __gcd
#define eps 1e-9
ll a, b, c, d, n, sol;
const ll najveci = 110000000;
vector<ll> v;
int polje[4] = {1, 2, 4, 8};
 
int main(){
	
	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	
	scanf("%lld", &n);
	 
	ll litra, dvelitre;
	
	litra = min(min(min(a*4, b*2), c), (a*2+b));
	dvelitre = min(litra*2, d);
	if(n%2 == 0){
		if(dvelitre*(n/2) < litra*n) printf("%lld\n", dvelitre*(n/2));
		else printf("%lld", litra*n);
	}else{
		if((dvelitre*(n/2) + litra) < litra*n) printf("%lld\n", (dvelitre*(n/2))+litra);
		else printf("%lld\n", litra*n);
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  int ans = 0;
  int tmp;
  REP2(i,1,50000){
    tmp = (int)(i * 1.08);
    if(N== tmp) ans = i;
  }

  if(ans == 0) cout << ":(" << endl;
  else cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let sss: String = read();
    let mut res: i32 = 0;

    for s in sss.chars() {
        if s == '1' {
            res += 1;
        }
    }

    let out = stdout();
    let mut out = out.lock();
    writeln!(out, "{}\n", res.to_string()).unwrap();
}

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

class Dice{
private:
	int num[6];
public:
	Dice(int input[6]);
	~Dice(){};
	int getNum(int want);
	int getTop();
	void moveStep(char direction);
	int func1(int ue, int mae);
};

Dice::Dice(int input[6]){
	for(int i = 0; i < 6; i++){
		num[i] = input[i];
	}
}

int Dice::getNum(int want){
	return num[want - 1];
}

int Dice::getTop(){
	return num[0];
}

void Dice::moveStep(char direction){
	int temp[6];
	for(int i = 0; i < 6; i++){
		temp[i] = num[i];
	}
	switch(direction){
	case 'N':
		num[0] = temp[1];
		num[1] = temp[5];
		num[5] = temp[4];
		num[4] = temp[0];
		break;
	case 'E':
		num[0] = temp[3];
		num[3] = temp[5];
		num[5] = temp[2];
		num[2] = temp[0];
		break;
	case 'S':
		num[0] = temp[4];
		num[4] = temp[5];
		num[5] = temp[1];
		num[1] = temp[0];
		break;
	case 'W':
		num[0] = temp[2];
		num[2] = temp[5];
		num[5] = temp[3];
		num[3] = temp[0];
		break;
	}
}

int Dice::func1(int ue, int mae){
	if(num[0] == ue && num[1] == mae) return num[2];

	string str("NNNNENNNNENNNNENNNNENENNNEENNN");//??????????????´???????¶??????????????????°????????????
	for(unsigned int i = 0; i < str.length(); i++){
		moveStep(str[i]);
//		cout << num[0] << " " << num[1] << endl;
		if(num[0] == ue && num[1] == mae) return num[2];
	}

	return -1;
}

int main() {

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

	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		int ue, mae;
		cin >> ue >> mae;
		Dice dice1(in);
		cout << dice1.func1(ue, mae) << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a = n / 10;
    int b = n - (n / 10) * 10;
    // cout << a << b << endl;
    if (a == 9 || b == 9)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

int main() {
  string s;
  cin >> s;
  int a,z;
  for(int i=0;i<s.size();i++) {
    if(s[i]=='A') {
      a=i;
      break;
    }
  }
  for(int i=s.size()-1;i>=0;i--) {
    if(s[i]=='Z') {
      z=i;
      break;
    }
  }
  int max=z-a+1;
  cout << max << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

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

  vector<int> ans;

  if (k % 2 == 0) {
    ans = vector<int>(n, k);
    ans[0] = k / 2;
  } else {
    ans = vector<int>(n, (k+1)/2);
    for (int i = 0; i < n/2; i++) {
	  if (ans[ans.size()-1] == 1) {
	    ans.erase(ans.end() - 1);
	  } else {
	    ans[ans.size()-1] -= 1;
		while (ans.size() < n) {
		  ans.push_back(k);
		}
      }
	}
  }

  cout << ans[0];
  for (int i = 1; i < ans.size(); i++)
    cout << " " << ans[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 3456
#include <iostream>

int main()
{
	int d,w,h;
	int n;
	int r;
	while (true) {
		std::cin >> d >> w >> h;
		if (d==0 && w==0 && h==0) break;
		
		int a,b;
		if (d>w && d>h) {a = w; b = h;}
		else if (w>d && w>h) {a = d; b = h;}
		else {a = w; b = d;}
		
		std::cin >> n;
		for (int i=0; i<n; i++) {
			std::cin >> r;
			if (4*r*r > a*a + b*b) {
				std::cout << "OK" << std::endl;
			} else {
				std::cout << "NA" << std::endl;
			}
		}
	}

	return 0;
}




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

typedef long long ll;
ll max;

ll mabs(ll a)
{
    if (a < 0){
        return (-1 * a);
    }
    return (a);
}

ll dist(ll x1, ll y1, ll x2, ll y2)
{
    if (mabs(x2 - x1) + mabs(y2 - y1) > max){
        max = mabs(x2 - x1) + mabs(y2 - y1);
    }
    return (2 * (mabs(x2 - x1) + mabs(y2 - y1)));
}

int comp(const void *a, const void * b)
{
    ll x, y;
    
    x = *(ll *)a;
    y = *(ll *)b;
    
    return (x - y);
}

int main(void)
{
    static ll hx[100000], hy[100000];
    static ll mx[100000], my[100000];
    int i, j;
    int w, h, n;
    ll pivx[2], pivy[2];
    ll res, temp;
    ll ax, ay;
    
    scanf("%d%d", &w, &h);
    scanf("%d", &n);
    
    for (i = 0; i < n; i++){
        scanf("%lld%lld", &hx[i], &hy[i]);
    }
    
    memcpy(my, hy, sizeof(hy));
    memcpy(mx, hx, sizeof(hx));
    
    qsort(hx, n, sizeof(ll), comp);
    qsort(hy, n, sizeof(ll), comp);
    
    pivx[0] = hx[(n - 1) / 2];
    pivy[0] = hy[(n - 1) / 2];
    pivx[1] = hx[(n + 1) / 2];
    pivy[1] = hy[(n + 1) / 2];
    
    res = -1;
    for (i = 0; i < 4; i++){
        max = 0;
        temp = 0;
        for (j = 0; j < n; j++){
            temp += dist(pivx[i / 2], pivy[i % 2], mx[j], my[j]);
        }
        temp -= max;
        if (res == -1 || temp < res){
            res = temp;
            ax = pivx[i / 2];
            ay = pivy[i % 2];
        }
    }
    
    printf("%lld\n%lld %lld\n", res, ax, ay);
    
    return (0);
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
typedef long long ll;
int main() {
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(a >= k) {
        cout << k << '\n';
    } else if(a+b >= k && a < k) {
        cout << a << '\n';
    } else if(a+b+c >= k && a+b < k) {
        cout << a - (k-(a+b)) << '\n';
    } else {
        cout << a-b << '\n';
    }
}

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

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

#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 

int main()
{
    cout<<std::fixed<<std::setprecision(10);

    int N;
    cin >> N;

    vector<int> d(N);
    ll a_sum = 0, b_sum = 0, minus_sum = 0, d_minus = 0;
    rep(i, N) {
        cin >> d[i];
        a_sum += d[i];
    }
    rep(i, N) {
        int B; cin >> B;
        b_sum += B;
        d[i] -= B;
        if (d[i] < 0) {
            minus_sum += d[i];
            d_minus++;
        }
    }

    int ans = -1;
    if (a_sum >= b_sum) {
        if (d_minus == 0) {
            ans = 0;
        } else {
            sort(d.begin(), d.end(), greater<int>());
            for (int i = 0; i < N; i++) {
                minus_sum += d[i];
                if (minus_sum >= 0) {
                    ans = d_minus + i+1;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var HW = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (H, W) = (HW[0], HW[1]);
        var S = new bool[H][];
        for (int i = 0; i < H; i++)
            S[i] = ReadLine().Select(c => (c == '.')).ToArray();

        int BFS((int, int) start, (int, int) end)
        {
            var visited = new int[H, W];
            for (int i = 0; i < H; i++)
                for (int j = 0; j < W; j++)
                    visited[i, j] = -1;

            void Visit((int, int) v, int step) => visited[v.Item1, v.Item2] = step;
            bool Visited((int, int) v) => visited[v.Item1, v.Item2] != -1;
            int GetSteps((int, int) v) => visited[v.Item1, v.Item2];

            IEnumerable<(int, int)> GetNextV((int, int) v)
            {
                var (y, x) = v;

                if ((0 < x) && S[y][x - 1])
                    yield return (y, x - 1);
                if ((0 < y) && S[y - 1][x])
                    yield return (y - 1, x);
                if ((x < W - 1) && S[y][x + 1])
                    yield return (y, x + 1);
                if ((y < H - 1) && S[y + 1][x])
                    yield return (y + 1, x);
            }

            var q = new Queue<(int, int)>();

            Visit(start, 0);
            q.Enqueue(start);

            while(0 < q.Count)
            {
                var v = q.Dequeue();
                var steps = GetSteps(v);

                if (v == end)
                    return steps;

                foreach (var nextV in GetNextV(v))
                {
                    if(!Visited(nextV))
                    {
                        Visit(nextV, steps + 1);
                        q.Enqueue(nextV);
                    }
                }
            }

            return int.MaxValue;
        }

        IEnumerable<(int, int)> GetAllPoint()
        {
            for (int y = 0; y < H; y++)
                for (int x = 0; x < W; x++)
                    if (S[y][x])
                        yield return (y, x);
        }

        var allPoint = GetAllPoint().ToArray();

        bool Isolated((int, int) v)
        {
            var (y, x) = v;
            if (((0 < x) && S[y][x - 1]) &&
                ((0 < y) && S[y - 1][x]) &&
                ((x < W - 1) && S[y][x + 1]) &&
                ((y < H - 1) && S[y + 1][x]))
                return true;
            else
                return false;
        }

        var ans = -1;

        for (int i = 0; i < allPoint.Length; i++)
        {
            for (int j = i; j < allPoint.Length; j++)
            {
                var a = allPoint[i];
                var b = allPoint[j];

                if (Isolated(a) || Isolated(b))
                    continue;

                ans = Math.Max(ans, BFS(a, b));
            }
        }

        WriteLine(ans);
    }
}


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

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> L(N);
  for(int i = 0; i < N; ++i) cin >> L[i];
  int ans = 1;
  int d = 0;
  for(int i = 0; i < N; ++i){
    d += L[i];
    if(d <= X) ++ans;
    else break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using ull = unsigned long long;

// 2 で割り切れる回数を返す
int f(int x) {
 int res = 0;
 while (x % 2 == 0) {
   x /= 2;
   res++;
 }
 return res;
}


int main() {

	int N, M;
	cin >> N >> M;

	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[i] % 2 == 1) {
			cout << 0 << endl;
			return 0;
		}
		a[i] /= 2;
	}


 // 2 で割り切れる回数が a[0] から a[N - 1] まで、全部同じじゃないとダメ
 // 同じ場合は、2^t で割る
 int t = f(a[0]);
 for (int i = 0; i < N; i++) {
   if (f(a[i]) != t) {
     cout << 0 << endl;
     return 0;
   }
   // a[i] /= 2^t
   a[i] >>= t;
 }

 // M /= 2^t
 M >>= t;

 // 2^t で割った a[0] から a[N - 1] までの lcm を求める。
 // lcm が M を超えるとダメ
 long long lcm_ = 1;
 for (int i = 0; i < N; i++) {
   lcm_ =  boost::math::lcm((ull)lcm_, (ull)a[i]);
   if (M < lcm_) {
     cout << 0 << endl;
     return 0;
   }
 }

 // 2^t で割った M = lcm * answer を満たす必要があり、
 // answer は奇数じゃないとダメなので、奇数の個数が答えになる
 M /= lcm_;
 int answer = (M + 1) / 2;
 
 cout << answer << endl;
 
 return 0;

}

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)/3
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n,a,b,A[5002],dp[5002], prev_dp[5002], at[5002], co[5002];

int main()
{
	FAST
	cin>>n>>a>>b;
	for(ll i=1;i<=n;++i){cin>>A[i];at[A[i]]=i;}
	FOR(k,1,n+1) {
		mmst(dp,0);
		ll p = at[k];
		for(ll i=1;i<p;i++)  dp[i] = prev_dp[i];
		for(ll i=p;i<=n;i++) {
			dp[i] = min((i==p?LLINF:prev_dp[i]+a), prev_dp[p-1] + b * (co[i] - co[p]));
		}
		for(ll i=p;i<=n;i++) co[i] += 1;
		swap(dp,prev_dp);
	}
	cout<<prev_dp[n]<<'\n';
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n,k,a[110],dp[100010];
int main() {
	memset(dp,-1,sizeof(dp));
	scanf("%d%d",&n,&k);
	int i,j;
	for(i=0;i<n;i++) scanf("%d",a+i);
	for(i=0;i<=k;i++) {
		set<int> st;
		for(j=0;j<n;j++) {
			if(a[j]<=i) {
				st.insert(dp[i-a[j]]);
			}
		}
		int cur=0;
		auto it=st.begin();
		while(it!=st.end()&&cur==*it)cur++,it++;
		dp[i]=cur;
	}
	puts(dp[k]?"First":"Second");
	return 0;
}

Measured memory_bytes: 640
def func(n) :
    i = 1
    b = n
    while i*i <= n :
        if n % i == 0 :
            if max(len(str(i)), len(str(n//i))) < b :
                b = max(len(str(i)), len(str(n//i)))
        
        
        i += 1
    
    return print(b)        

n = int(input())
func(n)

Measured memory_bytes: 9156
#include <stdio.h>


int BubbleSort(int A[], int n)
{
  int i,j,t;
  int count=0;
  for(i=0;i<n;i++){
    for(j=n-1;i<j;j--){
      if (A[j]<A[j-1]){
        t=A[j];
        A[j]=A[j-1];
        A[j-1]=t;
        count++;
      }
    }
  }
  return count;
}

int main()
{
  int n,i;
  int data[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
  }

  int count=BubbleSort(data,n);

  for(i=0;i<n-1;i++){
    printf("%d ",data[i]);
  }
  printf("%d\n%d\n",data[n-1],count);
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    string s = "RGYB";
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int x = i+j+1000, y = i-j+1000;
            cout << s[(x%(2*d) >= d)+(y%(2*d) >= d)*2];
        }
        puts("");
    }
    return 0;
}

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

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i,j,k,l;
	
	scanf("%d",&i);
	
	while(i > 0){
		scanf("%d %d %d",&j,&k,&l);
		
		if(j > k && j > l){
			if(j*j == k*k + l*l){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
		else if(k > j && k > l){
			if(k*k == j*j + l*l){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
		else {
			if(l*l == k*k + j*j){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
		i--;
	}
	
	return(0);
	
}

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

using namespace std;

vector<int> color;

void dfs(vector<vector<pair<int,int>>> &g,int v,int cur = 0){
    for(int i = 0;i < g[v].size();i++){
        if(color[g[v][i].first] != -1)continue;
        if(g[v][i].second % 2 == 0){
            color[g[v][i].first] = cur;
            dfs(g,g[v][i].first,cur);
        }else{
            color[g[v][i].first] = 1-cur;
            dfs(g,g[v][i].first,1-cur);
        }
    }
}

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> graph(n);
    for(int i = 0;i < n-1;i++){
        int k;pair<int,int> p;
        cin >> k >> p.first >> p.second;
        k-=1;p.first -= 1;
        graph[k].push_back(p);
        swap(k,p.first);
        graph[k].push_back(p);
    }
    color.assign(n,-1);
    for(int v = 0;v < n;v++){
        if(color[v] != -1)continue;
        if(v == 0){
            dfs(graph,v);
            continue;
        }
        dfs(graph,v,color[v]);
    }
    for(auto a : color)cout << a << endl;
    return 0;
}


Measured memory_bytes: 8192
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define inRange(x,a,b) (a <= x && x < b)

bool visit[50][50][50][50];

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

typedef pair<pair<int,int>, pair<int,int>> P;

int main(){
    int w, h, tx, ty, hx, hy;
    while(cin >> w >> h, w){
        memset(visit, 0, sizeof(visit));
        cin >> tx >> ty >> hx >> hy;
        tx--, ty--, hx--, hy--;
        
        int mat[h][w];
        rep(i, h) rep(j, w) cin >> mat[i][j];

        queue<pair<P, int>> q;
        q.push({{{ty,tx},{hy,hx}}, 0});

        int ans = -1;
        while(!q.empty()){
            pair<P,int> p = q.front();  q.pop();
            if(p.second > 100)  break;
            int a = p.first.first.first, b = p.first.first.second;
            int c = p.first.second.first, d = p.first.second.second;
            if(a == c && b == d){
                ans = p.second;
                break;
            }
            if(visit[a][b][c][d])   continue;

            visit[a][b][c][d] = true;

            for(int k = 0; k < 4; k++){
                int na = a + dx[k], nb = b + dy[k];
                int nc = c + dx[(k+2)%4], nd = d + dy[(k+2)%4];
                /*
                cout << a << ", " << b << " -> " << na << ", " << nb << endl;
                cout << c << ", " << d << " -> " << nc << ", " << nd << endl;
*/
                if(!inRange(na,0,h) || !inRange(nb,0,w) || mat[na][nb] == 1){
                    na = a, nb = b;
                }
                if(!inRange(nc,0,h) || !inRange(nd,0,w) || mat[nc][nd] == 1){
                    nc = c, nd = d;
                }

                if(!visit[na][nb][nc][nd]){
                    q.push({{{na,nb},{nc,nd}}, p.second+1});
                }
            }
        }

        if(ans == -1)   cout << "NA" << endl;
        else            cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 9548