akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  // char c = '1';
  // int i = c - '0';
  // printf("%d", i); // 1
  string S;
  cin >> S;
  int sum = 0;
  for (int i = 0; i < S.length(); ++i) {
    string t;
    t = S[i];
    int tmp = stoi(t);
    sum += tmp;
  }
  // printf("%d\n", sum);
  if (sum % 9 == 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 3720
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int N;
  cin >> N;
  string S;
  cin >> S;
  signed int count = 0;
  int max = 0;
  int i;
 
  for(i=0;i<N;i++){
   if(S[i] == 'D'){
     count--;
   }else if(S[i] == 'I'){
     count++;
     if(max < count){
      max = count; 
     }
   }else{}
  }
  
  cout << max << endl;
  
return 0;
} 

Measured memory_bytes: 256
# include<bits/stdc++.h>
 
using namespace std;
 
# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 
# define S second
# define F first
# define kill(x) return(cout << x << endl, 0LL)
# define debug(x) cerr<< #x << " = " << x << endl
# define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
# define tdebug(x, y, z) cerr<< #x << " = " << x  << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)
# define MP make_pair
# define uop(x, y) pii(min(x, y), max(x, y))

const int MAXN = 100 * 1000 + 10;
vector <int> adj[MAXN], x[MAXN];
int cnt[MAXN], par[MAXN];

void dfs(int v)
{
	for (int u : adj[v])
		cnt[u] --;

	for (int u : adj[v])
		if (!cnt[u])
			x[v].PB(u);

	for (int u : x[v])
	{
		par[u] = v;
		dfs(u);
	}

}

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

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n + m - 1; i ++)
	{
		int u, v;
		cin >> u >> v;
		u --, v --;
		adj[u].PB(v);
		cnt[v] ++;
	}

	for (int i = 0; i < n; i ++)
		if (!cnt[i])
		{
			par[i] = -1;
			dfs(i);
			break;
		}

	for (int i = 0; i < n; i ++)
		cout << par[i] + 1 << "\n";


	return 0;
}
 



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

int main(){
    long long N, K;
    long long mod = 1e9+7;
    long long ans=0, tmp=0, tmp2=0, tmp3;
	
    cin >> N >> K;
    vector<int> a(N);
    
    for(int i=0; i<N; i++){
	cin >> a[i];
    }

    for(int i=0; i<N; i++){
	for(int j=i; j<N; j++){
	    if(a[i]>a[j])
		tmp++;
	}
    }
    
    for(int i=0; i<N; i++){
	for(int j=0; j<N; j++){
	    if(a[i]>a[j])
		tmp2++;		
	}
    }
    tmp3 = ((((K-1)*K)/2)%mod*tmp2)%mod;
    ans = tmp*K;
    ans %= mod;
    ans += tmp3;
    ans %= mod;
    cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int afrog(int *a,int n,int *dp){
    if(n == 0) return 0;
    if(n == 1) return 0;
    if(n == 2) return abs(a[1]-a[0]);
    if(dp[n-1] > -1) return dp[n-1];
    int option1 = 0, option2 = 0;
    option1 = abs(a[0]-a[1]) + afrog(a+1,n-1,dp);
    option2 = abs(a[0]-a[2]) + afrog(a+2,n-2,dp);
    return  dp[n-1]=min(option1,option2);
}
int main() 
{ 
    int n;
    cin>>n;
    int *a = new int[n];
    int dp[n];
    memset(dp, -1, sizeof(dp));
    for(int i=0;i<n;i++) cin>>a[i];
    cout<<afrog(a,n,dp)<<endl;
    return 0; 
}
/*#include<bits/stdc++.h>
using namespace std;
int recursive(int *a,int n,int *dp){
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++){
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    }
    return dp[n];
}
int main(){
  int n;
  cin>>n;
  int *a=new int[n+1];
  int *dp=new int[n+1];
  for(int i=1;i<=n;i++) {
      cin>>a[i];
  }
  
  cout<<recursive(a,n,dp)<<endl;
  //cout<<endl;
}*/


Measured memory_bytes: 10588
#include <deque>
#include <iostream>
#include <cmath>

using namespace std;

int main() {

	int i, j, l, n, x;
	deque<int> g;

	while(cin >> n) {
		j=0;
		x=0;
		for(i=9; ; i--) {
			l=pow((double)2, (double)i);
			if(l+x<=n) {
				x+=l;
				g.push_back(l);
				j++;
			}
			if(x==n)
				break;
		}
		for(j-=1; j>0; j--) {
			cout << g[j] << " ";
		}
		cout << g[j] << endl;
		g.clear();
	}

	return 0;

}

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

using namespace std;

using u32 = uint32_t;
using u64 = uint64_t;
using i64 = int64_t;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= a; i--)
#define RF0(i,b) RFO(i,0,b)
#define F first
#define S second
#define ADD(a,b) (((u64)a + b)%MOD)
#define MUL(a,b) (((u64)a * b)%MOD)

constexpr int MOD = 998244353;

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

  int N;
  cin >> N;

  string s(N, 'a');

  while(true) {
    cout << s << '\n';
    
    auto it = s.end() - 1;

    if (it == s.begin()) {
      break;
    }

    auto cmax = [](const string& s, string::iterator it) {
      char c = 0;
      while (--it > s.begin()) {
        c = max(c, *it);
      }
      c = max(c, *it);
      return c;
    };

    bool end = false;
    while (++ * it - cmax(s, it) > 1) {
      it--;
      if (it == s.begin()) {
        end = true;
        break;
      }
    }
    if (end) {
      break;
    }
    while (++it < s.end()) {
      *it = 'a';
    }
  }
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define il inline
#define re register
#define fo(i,j,k) for(register int i=j;i<=k;i++)
#define do(i,j,k) for(register int i=j;i>=k;i--) 
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read()
{
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f*x;	
}
int n; 
int main()
{
	cin>>n;
	int a=n/100,b=n/10%10,c=n%10;
	if(a==7||b==7||c==7) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll LINF = 6e18;
#define chmin(a,b) a=min(a,b);

ll a, b, c, d;
map<ll, ll> mp;

ll dfs(ll n) {
  if (!mp.count(n)) {
    if (n == 0) {
      mp[n] = 0;
    } else {
      ll res = LINF;
      if (n <= res / d) chmin(res, d * n);
      chmin(res, dfs(n / 2) + a + d * (n % 2));
      chmin(res, dfs(n / 3) + b + d * (n % 3));
      chmin(res, dfs(n / 5) + c + d * (n % 5));
      if (n > 1) {
        if (n > 2) chmin(res, dfs(1 + n / 2) + a + d * (2 - (n % 2)));
        chmin(res, dfs(1 + n / 3) + b + d * (3 - (n % 3)));
        chmin(res, dfs(1 + n / 5) + c + d * (5 - (n % 5)));
      }
      mp[n] = res;
    }
  }
  return mp[n];
}

int main(){
  int t;
  cin >> t;
  while (t--) {
    mp = {};
    ll n;
    cin >> n >> a >> b >> c >> d;
    cout << dfs(n) << endl;
  }
}

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

int main(){
    int w,h,n;
    cin>>w>>h>>n;
    int xmin=w,xmax=0,ymin=h,ymax=0;
    rep(i,n){
        int x,y,a;
        cin>>x>>y>>a;
        if(a==1) xmax = max(xmax,x);
        if(a==2) xmin = min(xmin,x);
        if(a==3) ymax = max(ymax,y);
        if(a==4) ymin = min(ymin,y);
    }
    if(ymin<=ymax || xmin <=xmax) cout << 0<< endl;
    else cout << (xmin-xmax)*(ymin-ymax) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;

//Union-Find tree
struct UnionFind
{
	vector<ll> par;
	vector<ll> rank;
	vector<ll> siz;

	UnionFind(ll n) : par(n), rank(n), siz(n)
	{
		for (ll i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
			siz[i] = 1;
		}
	}
	ll root(ll x)
	{
		if (par[x] == x) return x;
		else return par[x] = root(par[x]);
	}
	ll size(ll x)
	{
		return siz[root(x)];
	}
	void unite(ll x, ll y)
	{
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry)return;
		if (rank[rx] < rank[ry])swap(rx, ry);
		par[ry] = rx;
		siz[rx] += siz[ry];
		if (rank[rx] == rank[ry])rank[rx]++;
	}
	bool same(ll x, ll y)
	{
		return root(x) == root(y);
	}
};

void solve()
{
	ll n, m; cin >> n >> m;
	vector<ll> a(m), b(m);
	rep(i, m) 
	{
		cin >> a[i] >> b[i];
		a[i]--;b[i]--;
	}
	vector<ll> ans;
	ll ans_now = n*(n-1)/2;
	UnionFind uf(n);
	rrep(i, m)
	{
		ans.push_back(ans_now);
		if(!uf.same(a[i],b[i]))
		{
			ll s = uf.size(a[i]);
			ll t = uf.size(b[i]);
			ans_now -= s * t;
		}
		uf.unite(a[i],b[i]);
	}
	reverse(all(ans));
	for(auto e : ans)cout << e << endl;
	return;
}

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


Measured memory_bytes: 6132
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    ll N;
    cin >> N;
    ll f[N+5][10][5];
    ll p[N+5][15];
    ll i, j, k;
    
    for(i=0; i<N; i++) {
        for(j=0; j<5; j++) {
            cin >> f[i][j][0] >> f[i][j][1];
        }
    }
    
    for(i=0; i<N; i++) {
        for(j=0; j<=10; j++) {
            cin >> p[i][j];
        }
    }
    
    ll ans=-INF;
    for(i=1; i<1<<10; i++) {
        ll t=0;
        ll c[N+5];
        memset(c, 0, sizeof(c));
        for(j=0; j<10; j++) {
            if(i>>j&1) {
                for(k=0; k<N; k++) {
                    if(f[k][j%5][j/5]) {
                        c[k]++;
                    }
                }
            }
        }
        
        for(j=0; j<N; j++)
            t+=p[j][c[j]];
        
        chmax(ans, t);
    }
    
    
    pt(ans);
    
}




Measured memory_bytes: 256
X = int(input())

item_value = [100, 101, 102, 103, 104, 105]
dp = [0] * (100001)
for value in item_value:
    dp[value] = 1

for i in range(200, X + 1):
    for value in item_value:
        if dp[i - value] == 1:
            dp[i] = 1

print(dp[X])

Measured memory_bytes: 41196
#include <iostream>
#include <cstdio>
#define mod 1000000007
using namespace std;
unsigned long long a[1000005], cnt, sum;
int n;
int main()
{
	scanf ("%d", &n);
	for (int i = 1; i <= n; i ++)
	{
		cin >> a[i];
		sum = sum + a[i];
	}
	for (int i = 1; i <= n; i ++)
	{
		sum = sum - a[i];
		cnt = (cnt + (sum % mod * a[i]) % mod) % mod; 
	}
    cout << cnt << endl;
	return 0;
} 
/* 1 2 3 4 5
2 3 4 5 6 8 10 12 15 20
*/

Measured memory_bytes: 5212
n = gets.to_i
hash = Hash.new
n.times do
    word = gets.strip
    if hash.has_key?(word)
        hash[word] += 1
    else
        hash[word] = 1
    end
end
max = hash.values.max
words = []
hash.each do |k, v|
    if v == max
        words.push(k)
    end
end
words.sort!
puts words

Measured memory_bytes: 34536
#include <bits/stdc++.h>
#define ll long long int
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N=(int)1e5+5;
int main()
{
#ifdef ONLINE_JUDGE
    FAST;
#endif
    ll K,A,B,sum;
    cin>>K>>A>>B;
    if ((A>K)||(B-A<2))
        return cout<<(K+1)<<"\n",0;
    K-=(A-1);
    sum=A;
    while(K>=2)
    {
        ll mn=min((sum/A),(K/2));
        if (!mn)
            break;
        sum-=(mn*A);
        sum+=(mn*B);
        K-=(mn*2);
    }
    sum+=K;
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int V = sc.nextInt();
        int B = sc.nextInt();
        int W = sc.nextInt();
        int T = sc.nextInt();

        if (W >= V) {
            System.out.println("NO");
            return;
        }

        if (A < B) {
            System.out.println(A+(long)T*V >= B+(long)T*W ? "YES" : "NO");
        } else {
            System.out.println(A-(long)T*V <= B-(long)T*W ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 35844
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 1000

int top,let[N];

 void push(int);
 int pop();

int main(){
   char str[100];
   int n1,n2,x;
   top = 0;
 
   while(scanf("%s",str) != EOF){
     if(str[0]=='+'){
           n1 = pop();
           n2 = pop();
           push(n1+n2);
     }else if(str[0] =='-'){
           n1 = pop();
           n2 = pop();
           push(n2-n1);
     }else if(str[0] =='*'){
           n1 = pop();
           n2 = pop();
           push(n1*n2);
     }else{
       
      x = atoi(str);
      push(x);
     }

}

   printf("%d\n",pop());
   return 0;
 }

void push(int x){
  if(top == N-1){
    printf("Stack overflow\n");
    exit(2);
  }
    let[++top] = x;
}

int pop(){
  if(top == 0){
    printf("Stack is empty\n");
    exit(2);
  }
  top--;
  return let[top+1];

}





Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void mmax(T &m, const T q) { if (m < q) m = q; }
template<typename T> void mmin(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


int main()
{
    string X;
    cin >> X;
    int ans = 0, s = 0;
    for (auto c : X)
    {
        if (c == 'S') s++;
        else
        {
            if (s) s--;
            else ans++;
        }
    }
    cout << ans * 2 << endl;
    return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		double max = 0.0;
		double min = Double.MAX_VALUE;
		while (sc.hasNextDouble())
		{
			double x = sc.nextDouble();
			max = Math.max(max, x);
			min = Math.min(min, x);
		}
		System.out.printf("%.1f", max - min);
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int x,y;
    cin>>x>>y;
    for(int i=0;i<=x;i++){
        int trt = 2*i + 4*(x-i);
        if(trt==y){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define N 10000000
using namespace std;

int main(){
  while(1){
    int m,n;
    cin>>m>>n;
    if(!m&&!n) break;
    vector<bool> used(N);
    for(int i=0,cnt=0;cnt<n;i++)
      if(!used[m+i]){
	cnt++;
	for(int j=m+i;j<N;j+=m+i) used[j]=1;
      }
    int ans=m;
    while(used[ans])ans++;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 4324
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
#include <deque>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int main(void){
	int n;
	cin>>n;
	ll ans = 0;
	for(int i=1;i<=n;i++){
		if(i==1)ans+=n-1;
		else{
			ll r = n/i;
			if(n%i==0)r--;
			ans+=r;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int Q;
  string s;
  cin >> s >> Q;

  int a, b;
  string c;
  bool flag = true;
  REP(_, Q){
    cin >> a;
    if(a == 1){
      flag = !flag;
    }else{
      cin >> b >> c;
      if(flag){
        if(b == 1) s.insert(0, c);
        else s += c;
      }else{
        if(b == 2) s.insert(0, c);
        else s += c;
      }
    }
  }

  if(flag == false) reverse(ALL(s));
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 900
import itertools
n = int(input())
p = list(map(int, input().split()))
pp = "".join([str(i) for i in p])
q = list(map(int, input().split()))
qq = "".join([str(i) for i in q])
x = [i+1 for i in range(n)]
z = []
for v in itertools.permutations(x):
	y = "".join([str(i) for i in v])
	z.append(y)
a = z.index(pp)
b = z.index(qq)
print (abs(a-b))

Measured memory_bytes: 6040
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
    int x,y;
    cin >> x >> y;
    while(x != 0 || y != 0){
        if(x > y){
            swap(x,y);
        }
        cout << x << " " << y << endl;
        cin >> x >> y;
    }
}


Measured memory_bytes: 3004
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };

namespace {
    template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
    template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    int n = inp1;
    vector<ll> a = inp(n);

    bool zero = false;
    rep(i, n) if (a[i] == 0) {
        zero = true;
        break;
    }

    if (zero) {
        Cout(0);
        return 0;
    }

    double ma = 1.0;
    ll ans = 1LL;
    rep(i, n) {
        ma *= a[i];
        ans *= a[i];

        if (ma > 1e18 * 5.0) {
            Cout(-1);
            return 0;
        }
    }

    if (ans > 1000000000000000000) {
        Cout(-1);
    }
    else Cout(ans);

    return 0;
}


Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    string s;
    in>>n>>s;
    if(n&1) return cout<<"No"<<endl,0;
    fr(i,n/2) if(s[i]!=s[i+n/2]) return cout<<"No"<<endl,0;
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
ls = []
for i in range(5):
    ls.append(int(input()))
def roundup(n):
    if n % 10 <= 5:
        return round(n+5,-1)
    else:
        return round(n,-1)
import itertools
sum = []
for p in list(itertools.permutations(ls)):
    av = 0
    cnt = 0 

    for j in p:
        av += j
        cnt += 1

        if  cnt != 5 and av % 10 != 0:
            av = roundup(av)

    sum.append(av)
print(min(sum))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e15;

signed main(void) {
	int N;
	cin >> N;
	vector<vector<ll>> A(N, vector<ll>(N)), war(N, vector<ll>(N));
	for(int i=0;i<N;i++) {
		for(int j=0;j<N;j++) {
			cin >> A[i][j];
			war[i][j] = A[i][j];
		}
	}

	for(int i=0;i<N;i++) {
		for(int j=0;j<N;j++) {
			for(int k=0;k<N;k++) {
				war[j][k] = min(war[j][k], war[j][i] + war[i][k]);
			}
		}
	}

	ll ans = 0;
	for(int i=0;i<N;i++) {
		for(int j=i+1;j<N;j++) {
			if(war[i][j] == A[i][j]) {
				bool flag = true;
				for(int k=0;k<N;k++) {
					if(k != i and k != j and war[i][k] + war[k][j] == war[i][j]) {
						flag = false;
					}
				}
				if(flag) {
					ans += war[i][j];
				}
			} else {
				cout << -1 << endl;
				return 0;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e18
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

class UnionFind {
public:
	vector<int>par, rank, node;
	UnionFind(int n) :par(n), rank(n, 0),node(n,1) {
		for (int i = 0;i < n;i++)par[i] = i;
	}
	void init(int n) {
		for (int i = 0;i < n;i++) {
			par[i] = i;
			rank[i] = 0;
			node[i] = 1;
		}
	}
 
	int find(int x) {
		return par[x] == x ? x : par[x] = find(par[x]);
	}
 
	bool same(int x, int y) {
		return find(x) == find(y);
	}
 
	void unite_tree(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	int root_size(int x){
		return rank[find(x)];
	}
 
	int size(int x) {
		return node[find(x)];
	}
 
	void unite_node(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (size(x) < size(y))swap(x, y);
		node[x] += node[y];
		par[y] = par[x];
	}
};

int main(void){
	int n,m;
	cin>>n>>m;
	UnionFind uf = UnionFind(n);
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		uf.unite_node(a,b);
	}
	set<int>s;
	for(int i=0;i<n;i++){
		s.insert(uf.find(i));
	}
	if(s.size()==1)cout<<0<<endl;
	else cout<<s.size()-1<<endl;
	return 0;
}


Measured memory_bytes: 8276
#include<bits/stdc++.h>
using  namespace std;
int main()
{
 long long a,b,c,d,p,q,r,s,x,y;
 cin>>a>>b>>c>>d;
    p=a*c;
    q=a*d;
    r=b*c;
    s=b*d;
    x=max(p,q);
    y=max(r,s);
cout<<max(x,y);
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];
  
  sort(v.begin(), v.end());
  
  cout << v[2]*10+v[1]+v[0] << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,temp=0;
	while(cin>>a>>b>>c)
	{
		if(a>b)
		{temp=a;a=b;b=temp;
		}	   
			   
		if(a>c)
		{temp=a;a=c;c=temp; 
		}	     
		if(b>c)
        {temp=b;b=c;c=temp;
        }	   
		cout<<a<<" "<<b<<" "<<c<<endl;
	}
}

Measured memory_bytes: 1160
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

mod=10**9+7
s=int(input())
dp=[0]*(s+1)
dp[0]=1
for i in range(3,s+1):
    for j in range(3,s+1):
        if i<j:
            continue
        else:
            dp[i]+=dp[i-j]
            dp[i]%=mod
print(dp[s]%mod)

Measured memory_bytes: 66336
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
ls=[a,b,c]
ls.sort()
if ls[0]==ls[1]:
  if ls[1]==ls[2]:
    print("No")
  else:
    print("Yes")
else:
  if ls[1]==ls[2]:
    print("Yes")
  else:
    print("No")

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

int ans;
vector<int> uf(100000, -1);

int root(int n)
{
  return uf[n] < 0 ? n : uf[n] = root(uf[n]);
}

int unit_size(int n)
{
  return -1 * uf[root(n)];
}

bool same(int a, int b)
{
  return root(a) == root(b);
}

void unite(int a, int b)
{
  if (!same(a, b)) {
    if (unit_size(a) < unit_size(b)) swap(a, b);
    uf[root(a)] += uf[root(b)];
    uf[root(b)] = root(a);
    ans--;
  }
}

int main()
{
  int n, m;
  cin >> n >> m;
  ans = n;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--; y--;
    unite(x, y);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
function Main(input) {
	input = input.trim();
	input = input.trim().split("");
	//input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  	var output = 700;
  for(var i = 0; i < input.length; i++){
      if(input[i] == "o"){
         output += 100;
         }
    }
  console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
/*Bismillahir Rahmanir Rahim
->>Code by Ashraful Islam Paran
->>CUET,CSE
*/
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef unsigned long long ull;
typedef vector<int> vi;
const int MX=2e5+5;
#define f(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define endl "\n"
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

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

    string a,b;
    int c{0};
    cin>>a>>b;
    f(i,0,a.size())
    {
        if(a[i]!=b[i])
        {
            c++;
        }
    }
    cout<<c<<endl;

    return 0;
}



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

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

map<vector<int>, int> mp; // mp[パズルの状態] = その状態になるまでの手数

void bfs(vector<int> origin) {
  // キューを初期化
  queue<vector<int>> que;
  que.push(origin);
  // データを初期化
  mp[origin] = 0;

  while (que.size()) {
    vector<int> axis = que.front(); que.pop();

    // 0の位置を求める
    int zeroPos = 0;
    for (int i = 0; i < axis.size(); i++) {
      if (axis[i] == 0) zeroPos = i;
    }
    int y = zeroPos / 4, x = zeroPos % 4;
    int pos = y * 4 + x;

    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= 2 || nx < 0 || nx >= 4) continue;

      vector<int> next = axis;
      int npos = ny * 4 + nx;
      swap(next[pos], next[npos]);
      if (mp.count(next)) continue;

      mp[next] = mp[axis] + 1;
      que.push(next);
    }
  }
}

signed main() {
  // 前処理
  vector<int> origin(8);
  iota(origin.begin(), origin.end(), 0);
  bfs(origin);

  string s;
  while (getline(cin, s)) {
    // 文字列の入力を数値の配列にする
    vector<int> v;
    for (int i = 0; i < s.size(); i+=2) {
      v.push_back(s[i] - '0');
    }
    // 前計算の結果を出力するだけ
    cout << mp[v] << endl;
  }

  return 0;
}


Measured memory_bytes: 5552
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}

int main(){
	//freopen("wireless.in","r",stdin);
	//freopen("wireless.out","w",stdout);
	int n,m;
	cin>>n>>m;
	cout<<(n-1)*(m-1);
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
using ll=long long;
int main()
{
    int N,K;
    ll ans=9223372036854775807;
    cin>>N>>K;
    vector<vector<int>> v;
    REP(i,0,N) {
        int x,y;
        vector<int> t;
        cin>>x>>y;
        t.push_back(x);
        t.push_back(y);
        v.push_back(t);
    }
    if(K==2){
        REP(i,0,N)REP(j,i+1,N){
            ll ax=min(v[i][0],v[j][0]);
            ll ay=min(v[i][1],v[j][1]);
            ll bx=max(v[i][0],v[j][0]);
            ll by=max(v[i][1],v[j][1]);
            ll tmp=(bx-ax)*(by-ay);
            if(tmp<ans){
                ans=tmp;
            }
        }
    }else if(K==3){
        REP(i,0,N)REP(j,i+1,N)REP(k,j+1,N){
            ll ax=min(min(v[i][0],v[j][0]),v[k][0]);
            ll ay=min(min(v[i][1],v[j][1]),v[k][1]);
            ll bx=max(max(v[i][0],v[j][0]),v[k][0]);
            ll by=max(max(v[i][1],v[j][1]),v[k][1]);
            ll tmp=(bx-ax)*(by-ay);
            if(tmp<ans){
                ans=tmp;
            }
        }
    }else{
        REP(i,0,N)REP(j,i+1,N)REP(k,j+1,N)REP(l,k+1,N){
            ll ax=min(min(v[i][0],v[j][0]),min(v[k][0],v[l][0]));
            ll ay=min(min(v[i][1],v[j][1]),min(v[k][1],v[l][1]));
            ll bx=max(max(v[i][0],v[j][0]),max(v[k][0],v[l][0]));
            ll by=max(max(v[i][1],v[j][1]),max(v[k][1],v[l][1]));

            int c=0;
            for(int m=0;m<N;m++){
                if (ax<=v[m][0]&&v[m][0]<=bx&&ay<=v[m][1]&&v[m][1]<=by){
                    c++;
                }
            }
            if(c!=K)continue;

            ll tmp=(bx-ax)*(by-ay);
            if(tmp<ans){
                ans=tmp;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

int main(void){
	string s,ans;
	int K;
	
	cin >> s;
	scanf("%d",&K);
	vector<string> sV;
	for(int i=0; i< s.length();i++){
		if(i<=s.length()-K)sV.push_back(s.substr(i,K));
		else sV.push_back(s.substr(i,s.length()-i));
	}

	sort(sV.begin(),sV.end());
	
	if(sV[0].length() >= K){
		ans = sV[0];
		printf("%s\n",ans.c_str());
		fflush(stdout);
		return 0;
	}
	K-=sV[0].length();
	int j=0;
	bool dif;
	while(j<sV.size()-1){
		if(sV[j] != sV[j+1]){
			dif = false;
			for (int i=0;i<sV[j+1].length();i++){

				if(sV[j][i]!=sV[j+1][i])dif = true;
				if(K > 0  && dif){
					K -= 1;
					if(K==0){
						ans = sV[j+1].substr(0,i+1);
						break;
					}
				}
				
			}

		}
		j++;
	}
	printf("%s\n",ans.c_str());
	fflush(stdout);
	return 0;
}



Measured memory_bytes: 512
N = int(input())

A = 0
B = 0

result = 0
judg = 100000

for i in range(N-1):
    A = i + 1
    B = N - A
    for ii in range(len(str(A))):
        A_re = A % 10
        A = int(A / 10)
        result += A_re
    for iii in range(len(str(B))):    
        B_re = B % 10
        B = int(B / 10)
        result += B_re
    if judg>result:
        judg = result
    result = 0

print(judg)    




Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

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

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

std::vector<int> par;
std::vector<ll> rak; // number of the vertices

void init(int n) {
  par.resize(n+1);
  rak.resize(n+1, 1);
  for(int i=1; i<=n; i++) {
    par[i] = i;
  }
}

int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x==y) return;
  if (rak[x] < rak[y]) {
    rak[y] += rak[x];
    par[x] = y;
  } else {
    rak[x] += rak[y];
    par[y] = x;
  }
}

bool same(int x, int y) {
  return find(x) == find(y);
}

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

  ll n, m; cin >> n >> m;
  vector<P> vec(m);
  rep(i, m) {
    int a, b; cin >> a >> b;
    vec[i] = P(a, b);
  }
  reverse(vec.begin(), vec.end());
  vector<ll> ans(m);
  ans[0] = n*(n-1)/2;
  init(n);
  rep(i, m-1) {
    int p = find(vec[i].first);
    int q = find(vec[i].second);
    ll tmp = 0;
    if (!same(p, q)) {
      tmp = rak[p]*rak[q];
      unite(p, q);
    }
    ans[i+1] = ans[i] - tmp;
  }

  reverse(ans.begin(), ans.end());
  rep(i, m) cout << ans[i] << '\n';
}


Measured memory_bytes: 4864
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N;
int main() {
	cin >> N;
	if (N < 600) cout << 8;
	else if (N < 800) cout << 7;
	else if (N < 1000) cout << 6;
	else if (N < 1200) cout << 5;
	else if (N < 1400) cout << 4;
	else if (N < 1600) cout << 3;
	else if (N < 1800) cout << 2;
	else cout << 1;
}

Measured memory_bytes: 3620
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

main = putStrLn . solve . map read . tail . words =<< getContents

solve xs = if ans then "Yes" else "No" where
    (o, q, e) = foldl f (0, 0, 0) xs
    f (o, q, e) x | odd x        = (o + 1, q, e)
                  | mod x 4 == 0 = (o, q + 1, e)
                  | otherwise    = (o, q, e + 1)
    ans = (o == 0)
       || (q > 0 && e == 0 && q >= o - 1)
       || (q > 0 && e > 0 && q >= o)
    

Measured memory_bytes: 9596
// /Code by : Harry_Singh/
#include<bits/stdc++.h>
#define int long long 
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n" 
#define br break
#define N 100005
// directions
vector<int> G[N];

void we_have_choices()
{


int n,x,t;
cin>>n>>x>>t;
int one=0;
int make=0;
while(true)
{
	if(make<n)make+=x,one+=t;
	else break;
}
cout<<one;
tr;
}


int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int t=1;
    while (t--)we_have_choices();
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> one(n), zero(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++) {
            int x, y;
            cin >> x >> y;
            x--;
            if (y == 0) zero[i].push_back(x);
            else one[i].push_back(x);
        }
    }

    int ans = 0;
    for (int i = 0; i < 1 << n; i++) {
        // i: set of honest people
        bool ok = true;
        int num = 0;
        for (int j = 0; j < n; j++) {
            if (i >> j & 1) {
                num++;
                // if j-th person is honest
                for (int a : zero[j]) {
                    if (i >> a & 1) {
                        ok = false;
                    }
                }
                for (int a : one[j]) {
                    if ((i >> a & 1) == 0) {
                        ok = false;
                    }
                }
            }
        }
        if (ok) {
            ans = max(ans, num);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////
    int S;
    cin >> S;
    int former = S / 100;
    int latter = S % 100;

    if (1 <= former && former <= 12) {
        // former = MM
        if (1 <= latter && latter <= 12) {
            cout << "AMBIGUOUS" << endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else {
        // former = YY
        if (1 <= latter && latter <= 12) {
            cout << "YYMM" << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
struct pos {
  int row;
  int column;
};
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
struct Attack {
  int damage;
  int mahou;
};

int dp[1005][10005];

int main(void) {
  int H, N;
  vector<Attack> attacks;
  cin >> H >> N;
  attacks.resize(N);

  rep(i, N) { cin >> attacks[i].damage >> attacks[i].mahou; }
  rep(i, H + 1) { dp[0][i] = INF; }

  rep(i, N) {
    rep(w, H + 1) {
      if (attacks[i].damage >= w) {
        dp[i + 1][w] = min(dp[i][w], attacks[i].mahou);
      } else {
        dp[i + 1][w] =
            min(dp[i][w], dp[i + 1][w - attacks[i].damage] + attacks[i].mahou);
      }
    }
  }

  cout << dp[N][H] << endl;

  return 0;
}

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

vector<int> to[200005];
vector<int> ans;

void dfs(int v,int root=-1){
    for (auto &&p : to[v]){
        if (root==p) continue;
        ans[p]+=ans[v];
        dfs(p,v);
    }
    return;
}

int main() {
    int n,q;
    cin>>n>>q;
    int a,b;
    rep(i,n-1){
        cin>>a>>b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    int p,x;
    rep(i,q){
        cin>>p>>x;
        p--;
        ans[p] += x;
    }
    dfs(0);
    rep(i,n) cout<<ans[i]<<' ';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 23424
n,k=map(int,input().split())
prob=0.0
if n>=k:
  prob+=(n-k+1)/n
mn=min(n+1,k)
for i in range(1,mn):
  check=i
  count=0
  while True:
    check*=2
    count+=1
    if check>=k:
      break
  prob+=pow(0.5,count)/n
print(prob)


Measured memory_bytes: 3060
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  long long a,b;
  cin>>a>>b;
  if(a>=2&&b>=2) cout<<(a-2)*(b-2);
  else if((a==1&&b!=1)||(b==1&&a!=1))  cout<<a*b-2;
  else cout<<1;
    return 0;
}


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

class Solve {
private:
	std::string hashFunc;
	int password[4]{}, hash_value;

	int calcHash(int& s_i)
	{
		int ret{};
		if (hashFunc[s_i] == '[')
		{
			s_i++;
			char ope{hashFunc[s_i]};
			s_i++;
			int lhs{calcHash(s_i)};
			int rhs{calcHash(s_i)};
			if (ope == '+') ret =  lhs | rhs;
			else if (ope == '^') ret =  lhs ^ rhs;
			else ret = lhs & rhs;
			s_i++;
		}
		else
		{
			ret = password[hashFunc[s_i] - 'a'];
			s_i++;
		}
		return ret;
	}

	int rc(int index)
	{
		if (index == 4)
		{
			int s_i{};
			return calcHash(s_i) == hash_value;
		}
		int ret{};
		for (int i{}; i < 10; i++)
		{
			password[index] = i;
			ret += rc(index + 1);
		}
		return ret;
	}

public:
	bool is_last_query{};
	Solve()
	{
		std::cin >> hashFunc;
		if (hashFunc == ".")
		{
			is_last_query = true;
			return;
		}
		for (int i{}; i < 4; i++)
		{
			char tmp;
			scanf(" %c", &tmp);
			password[i] = tmp - '0';
		}
		int s_i{};
		hash_value = calcHash(s_i);
		printf("%d %d\n", hash_value, rc(0));
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  if(a==b) cout << "Draw" << endl;
  else if(a==1) cout << "Alice" << endl;
  else if(b==1) cout << "Bob" << endl;
  else if(a>b) cout << "Alice" << endl;
  else cout << "Bob" << endl;
}

Measured memory_bytes: 256