akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<int> a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    set<ll> candidates;
    for(int i = 1; i*i <= sum; i++) {
        if(sum%i == 0) {
            candidates.insert(i);
            candidates.insert(sum/i);
        }
    }

    ll ans = 1LL;
    for(ll x : candidates) {
        ll need;
        {
            vector<ll> r(n);
            rep(i, n) {
                r[i] = a[i]%x;
            }
            sort(r.begin(), r.end());

            ll B = 0;
            rep(i, n) {
                B += x-r[i];
            }

            ll A = 0;
            need = 1e18;
            rep(i, n) {
                A += r[i];
                B -= x-r[i];
                need = min(need, max(A, B));
            }
        
        }
        if(need <= k) {
            ans = max(ans, x);
        }
    }

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

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

using namespace std;

using Int = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    int ans = 0;
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = 0; i < N; ++i) cin >> B[i], ans += B[i];
    for (int i = 0; i < N - 1; ++i) cin >> C[i];
    for (int i = 0; i < N - 1; ++i) {
        if (A[i] + 1 == A[i + 1]) ans += C[A[i] - 1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define mod 1000000007
#define PI acos(-1)
int main()
{
	IOS
	int n;
	cin>>n;
	int dp[10004]={0};
	int x,y,z;
	for(x=1;x<=100;x++)
	{
		for(y=1;y<=100;y++)
		{
			for(z=1;z<=100;z++)
			{
				int val=x*x+y*y+z*z+x*y+y*z+z*x;
				if(val<=10000)
				dp[val]++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	cout<<dp[i]<<"\n";
}

Measured memory_bytes: 3596
class dice:
    def roll(self,direction):
        if direction=="N":
            self.face=[self.face[1],self.face[5],self.face[2],self.face[3],self.face[0],self.face[4]]
        if direction=="E":
            self.face=[self.face[3],self.face[1],self.face[0],self.face[5],self.face[4],self.face[2]]
        if direction=="W":
            self.face=[self.face[2],self.face[1],self.face[5],self.face[0],self.face[4],self.face[3]]
        if direction=="S":
            self.face=[self.face[4],self.face[0],self.face[2],self.face[3],self.face[5],self.face[1]]
dice1=dice()
dice1.face=list(map(int,input().split()))
for i in input():
    dice1.roll(i)
print(dice1.face[0])


Measured memory_bytes: 5604
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum = 0;
		int temp = n;
		while(temp != 0) {
			sum += temp % 10;
			temp /= 10;
		}
		if(n % sum == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22356
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())

flag = False
for i in range(n):
  b = int(input())
  for i in range(3):
    if a1[i] == b:
      a1[i] = 0
      flag = True
    if a2[i] == b:
      a2[i] = 0
      flag = True
    if a3[i] == b:
      a3[i] = 0
      flag = True

if flag == False:
  print('No')
else:
  if a1[0] == a2[0] == a3[0] == 0 or a1[1] == a2[1] == a3[1] == 0 or a1[2] == a2[2] == a3[2] == 0 or a1[0] == a1[1] == a1[2] == 0 or a2[0] == a2[1] == a2[2] == 0 or a3[0] == a3[1] == a3[2] == 0 or a1[0] == a2[1] == a3[2] == 0 or a3[0] == a2[1] == a1[2] == 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;

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


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

int main() {
  double W,H,x,y;
  cin>>W>>H>>x>>y;
  
  cout<<W*H/2<<endl;
  
 if(x==W/2&&y==H/2)
  {cout<<1<<endl;}
  
  else{cout<<0<<endl;}
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll h,w;
vvl dp(50,vl(50,0));
ll dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
vector<vector<char>> s(50,vector<char>(50,'0'));
ll bfs(){
  queue<P> q;
  rep(i,h){
    rep(j,w){
      dp[i][j]=-1;
    }
  }
  dp[0][0]=1;
  q.push(P(0,0));
  while(q.size()){
    P p=q.front();
    q.pop();
    if(p.first==h-1&&p.second==w-1)
      break;
    rep(i,4){
      ll nx=p.first+dx[i],ny=p.second+dy[i];
      if(0<=nx&&0<=ny&&nx<h&&ny<w&&dp[nx][ny]==-1&&s[nx][ny]=='.'){
        q.push(P(nx,ny));
        dp[nx][ny]=dp[p.first][p.second]+1;
      }
    }
  }
  return dp[h-1][w-1];
}
int main() {
  cin >> h >> w;
  ll cnt=0;
  rep(i,h){
    rep(j,w){
      cin >> s[i][j];
      if(s[i][j]=='.'){
        cnt++;
      }
    }
  }
  ll a=bfs();
  if(a!=-1)
    cout << cnt-a << endl;
  else
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105,mod=1e9+7;
ll a[N];

int main(){
	ll n,s=1000;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
		
	int k=1,i=1;
	while(i<=n && k<=n){
		while(k<n && a[k]>=a[k+1]) k++;
		i=k;
		while(i<n && a[i]<=a[i+1]) i++;
		s+=1ll*(a[i]-a[k])*(s/a[k]);
		//cout<<a[k]<<" "<<a[i]<<endl;
		k=i+1;
	}
	
	printf("%lld\n",s);
    return 0;
}

Measured memory_bytes: 3804
import java.util.*;

import static java.lang.System.*;

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

        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        Arrays.sort(h);
        int min = h[0];
        int max = h[K-1];
        int diff = max - min;

        for (int i = K; i < N; i++) {
            min = h[i-K+1];
            max = h[i];
            diff = Math.min(diff, max - min);
        }

        out.println(diff);
    }
}


Measured memory_bytes: 50220
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

int main() {
	int ans = 0;
	char c;
	r(i,4){
		cin >> c;
		if(c == '+'){
			ans++;
		}else{
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

vector<ll>adj[200005];
ll update[200005];
ll ans[200005];

int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    int base = 1; 
  
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) { 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
  
    return dec_value; 
} 

bool isPerfectSquare(long double x) 
{   
  // Find floating point value of  
  // square root of x. 
  long double sr = sqrt(x); 
  
  // If square root is an integer 
  return ((sr - floor(sr)) == 0); 
}

int main()
{
    int n, k;

    cin >> n >> k;

    ll a[n+1];
    for(int i=1;i<=n;i++)
        cin >> a[i];

    ll dp[n+1]={0};
    dp[1] = 0;
    dp[2] = abs(a[2]-a[1]);

    for(int i=3;i<=n;i++)
    {
        dp[i] = INF;
        for(int j=max(i-k, 1);j<=i;j++)
        {
            // if(i-k < 1) continue;
            dp[i] = min(dp[j]+abs(a[i]-a[j]), dp[i]);
        }
    }

    cout << dp[n] << "\n";
}




Measured memory_bytes: 7552
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge { ll to, cost; };
ll inf = 1e18;

ll V, E, r;
vector<P> G[100010];
ll d[100010];

void dijkstra(ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, inf);
    d[s] = 0;
    que.push(P(0, s));
    
    while (!que.empty()) {
        P p = que.top();  que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            P e = G[v][i];
            if (d[e.first] > d[v] + e.second) {
                d[e.first] = d[v] + e.second;
                que.push(P(d[e.first], e.first));
            }
        }
    }
}

int main(void){
    cin >> V >> E >> r;
    for (int i = 0; i < E; i++) {
        ll s, t, d;
        cin >> s >> t >> d;
        G[s].push_back(P(t, d));
        //G[t].emplace_back(s, d);
    }
    
    dijkstra(r);
    for (int i = 0; i < V; i++) {
        if (d[i] == 1e18) cout << "INF" << endl;
        else cout << d[i] << endl;
    }
    
    
    
}



Measured memory_bytes: 19388
#include <cstdio>
#include <cctype>

int main()
{
    char ch;

    while(1){
        scanf("%c", &ch);
        if ( isalpha(ch)) {
            if ( islower(ch)) printf("%c", toupper(ch));
            else printf("%c", tolower(ch));
        } else printf("%c", ch);

        if (ch == '\n') break;
    }

    return 0;
}


Measured memory_bytes: 2584
#include <iostream>
using namespace std;
int main(){
  int a, b;
  char op;
  while(1){
    cin >> a >> op >> b;
    if (op=='?') break;
    if (op=='+') cout << a+b << endl;
    else if (op=='-') cout << a-b << endl;
    else if (op=='*') cout << a*b << endl;
    else cout << a/b << endl;
  }
}


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

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	
	vector<int> a(q), b(q), c(q), d(q);
	for (int i = 0; i < q; ++i) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}

	vector<int> v(n, 1);

	int ret = 0;
	int lst = 1 << m;
	while(1)
	{
		int sum = 0;
		for (int j = 0; j < q; ++j) {
			if ((v[b[j] - 1] - v[a[j] - 1]) == c[j]) {
				sum += d[j];
			}
		}

		ret = max(ret, sum);

		int cur = n - 1;
		while (0 <= cur) {
			++v[cur];
			if (v[cur] <= m) {
				break;
			}
			else {
				v[cur] = 1;
				--cur;
			}
		}
		if (cur < 0) {
			break;
		}

		for (int i = 1; i < n; ++i) {
			if (v[i - 1] > v[i]) {
				v[i] = v[i - 1];
			}
		}
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005,mod=1e9+7;
int f[N],s[N],nxt[N],las[N][3],sum[N][3];
int n,flag,ans=1;
char st[N];

void add(int &x,int y){
	x=(x+y>=mod?x+y-mod:x+y);
}

int main(){
	scanf("%s",st+1);
	n=strlen(st+1);
	rep(i,1,n){
		s[i]=(s[i-1]+1+(st[i]=='b'))%3;
	}
	per(i,n,1){
		if(st[i]==st[i+1])nxt[i]=i+1;
		else nxt[i]=nxt[i+1];
		REP(t,3) las[i][t]=las[i+1][t];
		las[i][s[i]]=i;
	}
	f[0]=1;
	rep(i,1,n){
		add(f[i],f[i-1]);
		int p=nxt[i];
		if(p){
			add(sum[p][s[i-1]],f[i-1]);
			p=las[p][(2*s[i-1]+3-s[i])%3];
			add(f[p],f[i-1]);
		}
		REP(t,3){
			add(sum[i][t],sum[i-1][t]);
			int tmp=(s[i]-t+3)%3;
			if(tmp&&tmp!=(s[i]-s[i-1]+3)%3){
				add(ans,sum[i][t]);
				//printf("%d %d   %d\n",i,t,sum[i][t]);
			}
		}
		if(!flag&&st[i]==st[i-1])
			flag=1,ans+=(i-2)/2;
		if(!s[i-1]&&flag)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3840
def main():
    import sys
    input = sys.stdin.readline

    # comb init
    mod = 1000000007
    nmax = 2 * 10 ** 5 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    N = int(input())
    adj = [[] for _ in range(N+1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        adj[a].append(b)
        adj[b].append(a)

    """ここから変更"""
    # op: 普通に根を固定した木DPで子の情報を親に集めるときの演算
    def op(a, b):
        return (((a[0] * b[0])%mod * comb(a[1]+b[1]+1, a[1]))%mod, a[1]+b[1]+1)
    ident_op = (1, -1)

    # cum_merge: 累積opどうしをマージするときの演算
    def cum_merge(a, b):
        return (((a[0] * b[0])%mod * comb(a[1]+b[1], a[1]))%mod, a[1]+b[1])
    # 単位元(cum_merge(ident, x) = x)
    ident_cum_merge = (1, 0)
    """ここまで変更"""

    # root=1でまず普通に木DPをする
    # 並行して各頂点につき、子の値の累積opを左右から求めておく
    # その後根から順番に、親からの寄与を求めていく(from_par)
    def Rerooting(adj):
        N = len(adj) - 1
        st = [1]
        seen = [0] * (N + 1)
        seen[1] = 1
        par = [0] * (N + 1)
        child = [[] for _ in range(N + 1)]
        seq = []
        while st:
            v = st.pop()
            seq.append(v)
            for u in adj[v]:
                if not seen[u]:
                    seen[u] = 1
                    par[u] = v
                    child[v].append(u)
                    st.append(u)
        seq.reverse()
        dp = [ident_op] * (N + 1)
        left = [ident_cum_merge] * (N + 1)
        right = [ident_cum_merge] * (N + 1)
        for v in seq:
            tmp = ident_cum_merge
            for u in child[v]:
                left[u] = tmp
                tmp = op(tmp, dp[u])
            tmp = ident_cum_merge
            for u in reversed(child[v]):
                right[u] = tmp
                tmp = op(tmp, dp[u])
            dp[v] = tmp

        seq.reverse()
        from_par = [ident_op] * (N + 1)
        for v in seq:
            if v == 1:
                continue
            from_par[v] = op(cum_merge(left[v], right[v]), from_par[par[v]])
            dp[v] = op(dp[v], from_par[v])

        return dp

    dp = Rerooting(adj)
    for v in range(1, N+1):
        print(dp[v][0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 126736
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

const int N = 2e5 + 7, INF = 1e15;

int a[N];

void solve() {
    int k, n;
    cin >> k >> n;
    loop(i, n)
        cin >> a[i];
    int sum = 0, cr = 0;
    loop1(i, n - 1) {
        sum += a[i] - a[i - 1];
        cr = max(cr, a[i] - a[i - 1]);
    }
    sum += a[0] + k - a[n - 1];
    cr = max(cr, a[0] + k - a[n - 1]);
    cout << sum - cr;
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;

  vector<int> a(n);
  map<int, int> fre;

  int mn = INT_MAX, mx = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mn = min(a[i], mn);
    mx = max(mx, a[i] - mn);
    fre[a[i]]++;
  }

  long long ans = 0;
  mn = INT_MAX;
  for (int i = 0; i < n; ++i) {
    mn = min(mn, a[i]);
    if (a[i] - mn == mx)  {
      ans += min(fre[a[i]], fre[mn]);
      fre[a[i]] = 0;
      fre[mn] = 0;
    }
  } 

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


Measured memory_bytes: 5376
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

from math import pi
print(int(input().rstrip())*2*pi)

Measured memory_bytes: 9100
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    if n==2:
        ans=1
    else:
        ans=2
    for i in range(2,int(n**.5)+1):
        if n%i==0:
            k1=i
            k2=n//i
            N=n
            while N%k1==0:
                N//=k1
            if N%k1==1:
                ans+=1
            if k2!=k1:
                N=n
                while N%k2==0:
                    N//=k2
                if N%k2==1:
                    ans+=1
    n-=1
    for i in range(2,int(n**.5)+1):
        if n%i==0:
            if i==n//i:
            	ans+=1
            else:
                ans+=2
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 39024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i <= (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  int n,k;
  cin>>n>>k;
  int x=-1,y,z;
  rep(i,n){
    rep(j,n){
      int c=k-1000*i-5000*j;
      
      if(c>=0 && c%10000==0 && c/10000+i+j==n){
        x=i;y=j;z=c/10000;
      }
    }
  }
  if(x==-1){
    x=-1;
    y=-1;
    z=-1;
  }
  cout<<z<<" "<<y<<" "<<x<<endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstring>

long long mod = 1000000007;
long long dp[1005][1005];
char matrix[1005][1005];
int h;
int w;

long long countPaths(int row, int col) {
    //std :: cerr << row << ' ' << col << '\n';
    if(row == h || col == w) return 0;
    if(matrix[row][col] == '#') return 0;
    if(dp[row][col] > -1) return dp[row][col] % mod;

    dp[row][col] = (countPaths(row + 1, col) + countPaths(row, col + 1)) % mod;

    //std :: cerr << row << ' ' << col << '\n';
    return dp[row][col] % mod;
}

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

    memset(dp, -1, sizeof(dp));

    for(int i = 0 ; i < h ; i++) {
        scanf("%s", matrix[i]);
    }

    dp[h - 1][w - 1] = 1;

    auto ret = countPaths(0 , 0);

    printf("%lld", ret);
}

Measured memory_bytes: 12152
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;
int c(char v) {
	return (v == 'o') ? 100 : 0;
}
int main() {
	string s;
	cin >> s;
	cout << (700 + c(s[0]) + c(s[1]) + c(s[2]));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string A,B;
    cin >> A >> B;
    if(A.size() > B.size()) cout << "GREATER" << endl;
    else if(A.size() < B.size()) cout << "LESS" << endl;
    else{
        for(int i = 0; i < A.size(); i++){
            int a = A[i] - '0';
            int b = B[i] - '0';
            if(a > b){
                cout << "GREATER" << endl;
                return 0;
            }
            else if(a < b){
                cout << "LESS" << endl;
                return 0;
        }
        }
        cout << "EQUAL" << endl;
        }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d,e,i,j,k=0,l;
cin>>a>>b>>c;
l=0;
for(i=1;i<=100;i++)
{
  l+=a;
if(l%b==c)k=1;
}
if(k==1)cout<<"YES\n";
else cout<<"NO\n";
}

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

int atoi2(char a){
    int ans;
    if(a=='0'){
        ans=0;
    }else if(a=='1'){
        ans=1;
    }else if(a=='2'){
        ans=2;
    }else if(a=='3'){
        ans=3;
    }else if(a=='4'){
        ans=4;
    }else if(a=='5'){
        ans=5;
    }else if(a=='6'){
        ans=6;
    }else if(a=='7'){
        ans=7;
    }else if(a=='8'){
        ans=8;
    }else if(a=='9'){
        ans=9;
    }else{
        fprintf(stderr,"エラーじゃん\n");
        exit(1);
    }

    return ans;
}



int main(void){
    char N[200005];
    int i,sum;
    scanf("%s",N);

    i=0;
    sum=0;
    while(N[i]!='\0'){
        sum=sum+atoi2(N[i]);
        i++;
    }

    if(sum%9==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;


}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
  rep (i, v.size()) is >> v[i];
  return is;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  string s0 = "deficient number";
  string s1 = "perfect number";
  string s2 = "abundant number";

  loop {
    int m; cin >> m;
    if (not m) break;
    int k = 0;
    rep (i, m) {
      if (i == 0) continue;
      if (i*i > m) break;
      if (m%i==0) {
        k += i;
        if (i*i < m)
          k += m/i;
      }
    }
    if (k == 2*m) {
      cout << s1 << endl;
    } else if ( k < 2*m) {
      cout << s0 << endl;
    } else {
      cout << s2 << endl;
    }
  }

  return 0;
}

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

typedef long long ll;


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

    int N;

    cin >> N;

    vector<int> W(N);

    int left = 0;
    int right = 0;

    for(int i = 0; i < N; i++) {
        cin >> W[i];
        right += W[i];
    }

    int min = abs(left - right);

    for(int i = 0; i < N; i++) {
        left += W[i];
        right -= W[i];
        if(abs(left - right) < min) {
            min = abs(left - right);
        }
    }

    cout << min << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long P = 10^^9+7;
long[10^^5+50] F, RF;

void init()
{
    F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long comb(N)(N n, N k)
{
    auto n_b = F[n];    // n!
    auto nk_b = RF[n-k]; // 1 / (n-k)!
    auto k_b = RF[k];    // 1 / k!

    auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!

    return (n_b * nk_b_k_b) % P;  // n! / (n-k)!k!
}

int[2][] prime_division(int m)
{
    int[2][] r;
    for (int x = 2; x^^2 <= m; ++x) {
        int cnt;
        while (m % x == 0) {
            ++cnt;
            m /= x;
        }
        if (cnt) r ~= [x, cnt];
    }
    if (m != 1) r ~= [m, 1];
    return r;
}

void main()
{
    init();
    auto nm = readln.split.to!(int[]);
    long N = nm[0];
    auto M = nm[1];

    long r = 1;
    foreach (p; prime_division(M)) {
        r = (r * comb(N+p[1]-1, p[1])) % P;
    }
    writeln(r);
}

Measured memory_bytes: 1792
import java.util.*
import java.math.*

fun main(args: Array<String>) {
//    var (N,L) = readLine()!!.split(" ").map { it.toInt() }
    var N = readLine()!!.toInt()
//    val S = readLine()!!.toInt()
    val d = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    var ans = 0
    for (i in 0 until N-1){
        for (j in i+1 until N)
            ans += d[i]*d[j]
    }

    println(ans)
}



Measured memory_bytes: 37872
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
vector<int> ans[110];
int main(){
    int a[110];
    int id=0;
    int c[110]={};
    while(cin>>a[id]){
        c[a[id]]++;
        id++;
    }
    for(int i=1;i<=100;i++){
        ans[c[i]].push_back(i);
    }
    for(int i=100;i>=1;i--){
        if(ans[i].size()!=0){
            for(int j=0;j<ans[i].size();j++){
                cout<<ans[i][j]<<endl;
            }
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3024
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<assert.h>
#include<stdlib.h>
#include<stack>
using namespace std;
/*********************Contest Template***********************/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<int,int> Cord;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(0);
struct S{
    int a,b; S(){}S(int _a,int _b){
        a=_a;
        b=_b;
    }
    const bool operator<(const S &o) const{
        return a<o.a;
    }
};
priority_queue<int,vector<int>,greater<int>> mpq;
#define SPACE 0
#define NL 1
inline void showAll(vector<int> &v,int NL_or_space){ 
    //0 is space, 1 is NL
    for(int &here:v){
        printf("%d",here);
        printf("%c",(NL_or_space)?'\n':' ');
    }
}
/*********************Contest Template***********************/
const int SIZE= 21;

int arr[SIZE];

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

	for(int i=1 ; i<=n ; i++)
		scanf("%d",&arr[i]);

	int ans=1;
	for(int i=2 ; i<=n ; i++){
		for(int j=1 ; j<i ; j++){
			if(arr[j]>arr[i]){
				break;
			}
			if(j==i-1) ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100005
#define inf 1e18L + 5
#define ll long long
#define MOD 1000000007
using namespace std;

ll n;
ll tree[maxn][2]; // tree[i][0] is the no of ways ith node can be white &
                //tree[i][1] is the no of ways ith node can be black if we consider subtree rooted at i

vector<ll>vec[maxn];

ll dfs(ll u, ll p){
    tree[u][0] = 1;
    tree[u][1] = 1; // single node can be anything
    for(ll i = 0; i < vec[u].size(); i++){
        ll v = vec[u][i];
        if(p != v){
            dfs(v, u);
            // u can be white for any cases
            // but u can be black if all its children are white
            tree[u][0] = (tree[u][0] * (tree[v][0] + tree[v][1])%MOD)%MOD;
            tree[u][1] = (tree[u][1] * tree[v][0])%MOD;
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(ll i =0;i<n-1;i++){
        ll x, y;
        cin >> x >> y;
        vec[x].push_back(y);
        vec[y].push_back(x);
    }
    dfs(1,0);
    cout << (tree[1][0] + tree[1][1])%MOD << endl;
}


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

int main() {
  int N;
  cin>>N;
  long long int res=1;
  for(int i=0;i<N;i++){
    long long int t;
    cin>>t;
    res=res/__gcd(res,t) * t;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    try(Scanner sc = new Scanner(System.in)){
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      int term = a * b;
      if((term % 2) == 0){
        System.out.println("Even");
      }else{
        System.out.println("Odd");
      }
    }
  }
}
      
    

Measured memory_bytes: 23380
# https://atcoder.jp/contests/abc133/submissions/6316420
# 参考にさせていただきました。

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

n, q = map(int, input().split())
edges = [[] for i in range(n)]
for i in range(n-1):
    a,b,c,d = map(int, input().split())
    a -= 1
    b -= 1
    c -= 1
    edges[a].append((b,c,d))
    edges[b].append((a,c,d))

# ここで前処理
# LCAができるようにしておく
dep=[0]*n
par=[[-1]*n for i in range(18)]
# ついでに距離も持っておく
dis=[0]*n

# parent, now_point, depth, dist

def dfs(p,v,d,dd):
    dep[v]=d
    par[0][v]=p
    dis[v]=dd
    for w, _, dist in edges[v]:
        if w!=p:
            dfs(v,w,d+1, dd+dist)

def lca(a,b):
    if dep[a]>dep[b]:
        a,b=b,a
    for i in range(18):
        if (dep[b]-dep[a]) & 1<<i:
            b=par[i][b]
    if a==b:
        return a
    for i in range(18)[::-1]:
        if par[i][a]!=par[i][b]:
            a=par[i][a]
            b=par[i][b]
    return par[0][a]

dfs(-1,0,0,0)

for i in range(17):
    for j in range(n):
        par[i+1][j]=par[i][par[i][j]]

# LCAの準備が完了

ans = [0]*q
v_need = [[] for i in range(n)]
for i in range(q):
    x,y,u,v = map(int, input().split())
    x -= 1
    u -= 1
    v -= 1
    l = lca(u, v)
    # 色の情報がほしいのは u, v, lの3点
    # どのクエリに属するか, どの色を変えるか、距離はいくつにするか, 係数
    v_need[u].append((i, x, y, 1))
    v_need[v].append((i, x, y, 1))
    v_need[l].append((i, x, y, -2))

# 色が何回出たか
color = [0]*n
# その点までの各色の距離の総和
cdist = [0]*n

def dfs2(cur, par):
    for i, x, y, k in v_need[cur]:
        ans[i] += k*(dis[cur] - cdist[x] + y*color[x])
    for to, x, y, in edges[cur]:
        if to == par:
            continue
        color[x] += 1
        cdist[x] += y
        dfs2(to, cur)
        # オイラーツアーのように、戻ってきたら引く
        # これによって、a→b→c→b→dと移動した時a→b→dとみなせる
        color[x] -= 1
        cdist[x] -= y
dfs2(0, -1)

for i in ans:
    print(i)

Measured memory_bytes: 178876
N = int(input())
a = list(map(int,input().split()))

ans = 'No'

cnt4 = 0
cnt2 = 0

for aa in a:
    if aa%4 == 0:
        cnt4 += 1
    elif aa%4 == 2:
        cnt2 += 1

if 2*cnt4 + 1 >= N:
    ans = 'Yes'
else:
    res = N - 2*cnt4
    if res <= cnt2:
        ans = 'Yes'
        
print(ans)

Measured memory_bytes: 14252
import numpy as np
from scipy.sparse.csgraph import dijkstra
from collections import defaultdict

import sys
input = sys.stdin.readline

[H,W]= [int(x) for x in input().split()]
c=np.array([[int(x) for x in input().split()] for _ in range(10)])

A=[]
for _ in range(H):
  A+=[int(x) for x in input().split()] 

dd = defaultdict(int)
for key in A:
  if key!=1 and key!=-1:
    dd[key] += 1

res=0
for k, v in dd.items():
  res+= v*int(dijkstra(c,indices = k)[1])
print(res)

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
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; }

int h, w;
vector<vector<char>> s;
vector<vector<int>> g;
vector<pint> dyx = {make_pair(-1,0),make_pair(0,1),make_pair(0,-1),make_pair(1,0)};

void bfs(int ch, int cw) {
    deque<pint> q;
    q.push_front(make_pair(ch,cw));

    g[ch][cw] = 0;
    pint u;
    int ux, uy, nx, ny, nny, nnx;
    while(!q.empty()) {
        u = q.front(); q.pop_front();
        uy = u.first;
        ux = u.second;
        // cout << uy << ux << endl;
        for(auto idyx:dyx) {
            ny = uy + idyx.first;
            nx = ux + idyx.second;
            if(ny<0||ny>=h||nx<0||nx>=w) continue;
            if(s[ny][nx]=='#') continue;
            if(g[ny][nx]==-1) {
                g[ny][nx] = g[uy][ux];
                q.push_front(make_pair(ny, nx));
            }
            else if(chmin(g[ny][nx], g[uy][ux])) {
                q.push_front(make_pair(ny, nx));
            }
            else ;
        }
        for(int nny=uy-2;nny<=uy+2;++nny) {
            for(int nnx=ux-2;nnx<=ux+2;++nnx) {
                if(nny==uy&&nnx==ux) continue;
                if(nny<0||nny>=h||nnx<0||nnx>=w) continue;
                if(s[nny][nnx]=='#') continue;
                if(g[nny][nnx]==-1) {
                    g[nny][nnx] = g[uy][ux] + 1;
                    q.push_back(make_pair(nny, nnx));
                }
                else if(chmin(g[nny][nnx], g[uy][ux] + 1)) {
                    q.push_back(make_pair(nny, nnx));
                }
                else ;
            }
        }
    }
}

int main(void) {
    cin >> h >> w;
    s.resize(h, vector<char>(w));
    g.resize(h, vector<int>(w, -1));

    int ch, cw, dh, dw;
    cin >> ch >> cw; ch--; cw--;
    cin >> dh >> dw; dh--; dw--;
    for(int ih=0;ih<h;++ih) {
        for(int iw=0;iw<w;++iw) {
            cin >> s[ih][iw];
        }
    }

    bfs(ch, cw);
    
    // for(int ih=0;ih<h;++ih) {
    //     for(int iw=0;iw<w;++iw) {
    //         cout << g[ih][iw];
    //     }
    //     cout << endl;
    // }
    cout << g[dh][dw] << endl;
    return 0;
}


Measured memory_bytes: 8676
#include <bits/stdc++.h>
#define ll long long
#define SZ(vvv) ((int)vvv.size())
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 1e5 + 5, M = 5e4 + 9, INF = 1e9, MOD = 1e9 + 7;

int mul(int x, int y) {
	return (1ll * x * y) % MOD;
}

int add(ll x, int y) {
	x += y;
	while(x >= MOD) x -= MOD;
	while(x < 0) x += MOD;
	return x;
}

int sub(int x, int y) {
	return (x - y + MOD) % MOD;
}

int fastpow(int x, int pow) {
	int ret = 1;
	while(pow) {
		if(pow & 1)
			ret = mul(ret, x);
		pow /= 2;
		x = mul(x, x);
	}
	return ret;
}

int ans[N];

void runtestcase() {
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; ++i) {
		int allpos = fastpow(k / i, n);
		ans[i] = allpos;
	}
	for (int i = k; i > 0; --i) {
		int sum = 0;
		for (int j = i + i; j <= k; j += i)
			sum = add(sum, ans[j]);
		ans[i] = sub(ans[i], sum);
	}
	int total = 0;
	for (int i = 1; i <= k; ++i)
		total = add(total, mul(i, ans[i]));
	cout << total;
}


int main() {
    fastIO;
#ifdef LOCAL
    freopen("input.in", "rt", stdin);
//    freopen("cache.out", "wt", stdout);
#endif
  int t = 1, tt = 1;
//	cin >> t;
  while(t) {
//		cout << "Case #" << tt << ':' << ' ';
    runtestcase();
		cout << '\n';
    --t, ++tt;
  }
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

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

ll bu[100000];

int main() {
    ll n; cin >> n;
    Rep(x, 1, 105){
        Rep(y, 1, 105){
            Rep(z, 1, 105){
                ll a = x*x + y*y + z*z + x*y + y*z + z*x;
                bu[a]++;
            }
        }
    }

    Rep(i, 1, n){
        co(bu[i]);
    }

    return 0;
}




Measured memory_bytes: 4136
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let mut buffer = String::new();
    stdin.lock().read_line(&mut buffer).unwrap();

    let nums = buffer.chars();
    let mut c = 0;
    for char in nums {
        if char == '1' { c += 1; }
    }

    println!("{}", c);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long X){
  ll ans=0;
  ans+=X/500*1000;
  X%=500;
  ans+=X/5*5;
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
n, k = map(int, read().split())


def count(digit, k):
    if digit < k:
        return 0
    elif k == 0:
        return 1
    elif k == 1:
        return digit
    elif k == 2:
        return digit * (digit - 1) // 2
    else:
        return digit * (digit - 1) * (digit - 2) // 6


def solve(n, k):

    if k == 0:
        return 1
    digit = len(str(n))
    res = 0
    if digit > k:
        res += count(digit - 1, k) * (9 ** k)
    pow10 = 10 ** (digit - 1)
    d, mod = n // pow10, n % pow10
    res += count(digit - 1, k - 1) * (9 ** (k - 1)) * (d - 1)
    res += solve(mod, k - 1)
    return res


print(solve(n, k))

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }


ll n;
void solve() {
    cin >> n;

    ll sqt = (ll)sqrt(n);
    ll ans = inf;
    reps(i, sqt) {
        if (n % i == 0)
            mins(ans, i + n / i);
    }

    cout << ans - 2 << endn;
}

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


Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    S = list(input())
    N = len(S)
    A = [1] * N
    for i in range(N - 1):
        if S[i] == 'R' and S[i + 1] == 'R':
            A[i + 2] += A[i]
            A[i] = 0
    for i in range(N - 1, 0, -1):
        if S[i] == 'L' and S[i - 1] == 'L':
            A[i - 2] += A[i]
            A[i] = 0
    print(*A)


resolve()

Measured memory_bytes: 51064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  string s;
  cin >> n >> s;
  vint W(n);
  vint B(n);
  int count = 0;
  rep(i,n){
    if(s[i] == '#') count++;
    W[i] = count;
  }
  count = 0;
  for(int i = n-1;i >= 0;i--){
    if(s[i] == '.') count++;
    B[i] = count;
  }
  int ans = INF;
  rep(i,n-1){
    ans = min(ans,W[i]+B[i+1]);
  }
  ans = min(ans,B[0]);
  ans = min(ans,W[n-1]);
  cout << ans << endl;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  vector<string> s(n + 1);

  cout << 0 << endl;
  cin >> s[0];
  if (s[0] == "Vacant") return 0;

  int left = 0;
  int right = n;

  s[n] = s[0];

  if ((n - 0) % 2 == 0) return 0;

  while (true) {
    int mid = (left + right) / 2;

    cout << mid << endl;
    cin >> s[mid];
    
    if (s[mid] == "Vacant") return 0;

    // if left part is valid, then right part must be
    // if right part is valid, then left part must be
    // (same, even), or, (diff, odd)
    if ((s[mid] == s[left]) ^ ((mid - left) % 2 == 1)) left = mid;
    else right = mid;
  }

  return 0;
}


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


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

string a="";
string b="";
//string temp= to_string(n);
for(int i=0;i<m;i++){
    a+=to_string(n);
}

//string temp= to_string(m);
for(int i=0;i<n;i++){
    b+=to_string(m);
}

if(a<b){
    cout<<a;
}
else{
    cout<<b;
}

  return 0;
}

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

using namespace std;

//#define int long long

const int maxr = 12800;

void solve() {
    int h, w;
    cin >> h >> w;
    int a[h][w], b[h][w];
    vector <vector <vector <int> > > dp(h, vector <vector <int> > (w, vector <int> (maxr)));
    for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) cin >> a[i][j];
    for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) cin >> b[i][j];
    //for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) for (int k = 0; k < maxr; ++k) dp[i][j][k] = 0;
    dp[0][0][abs(a[0][0] - b[0][0])] = 1;
    for (int val = 0; val < h * w; ++val) {
        int i = val / w, j = val % w;
        if (i) {
            for (int val = 0; val < maxr; ++val) {
                if (dp[i - 1][j][val]) {
                    if (abs(val - (a[i][j] - b[i][j])) < maxr) {
                        //cout << i << ' ' << j << ' ' << val << ' ' << abs(val - a[i][j] + b)
                        dp[i][j][abs(val - a[i][j] + b[i][j])] = 1;
                    }
                    if (abs(val - (b[i][j] - a[i][j])) < maxr) dp[i][j][abs(val - b[i][j] + a[i][j])] = 1;
                }
            }
        }
        if (j) {
            for (int val = 0; val < maxr; ++val) {
                if (dp[i][j - 1][val]) {
                    if (abs(val - (a[i][j] - b[i][j])) < maxr) dp[i][j][abs(val - a[i][j] + b[i][j])] = 1;
                    if (abs(val - (b[i][j] - a[i][j])) < maxr) dp[i][j][abs(val - b[i][j] + a[i][j])] = 1;
                }
            }
        }
    }
    int ans = maxr;
    for (int i = 0; i < maxr; ++i) {
        if (dp[h - 1][w - 1][i]) {
            ans = i;
            break;
        }
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 326656
s = int(input())

def f(i):
    if i % 2 == 0:
        v = i // 2
    else:
        v = 3 * i + 1
    return v

if s in (1, 2):
    res = 4
else:
    ai = s
    cnt = 1
    while ai != 4:
        ai = f(ai)
        cnt += 1

    res = cnt + 3

print(res)



Measured memory_bytes: 2940
N,M = map(int,input().split())
s1 = set()
e1 = set()
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        s1.add(b)
    if b == N:
        e1.add(a)
if len(s1 & e1) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 18936