akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x

        return True
    
    def same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.parents[self.root(x)]
    
    def members(self, x):
        x_root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == x_root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())


    

N, M, K = map(int, input().split())
uf = UnionFind(N)

friend = [0] * N
block = [[]*N for i in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    friend[a] += 1
    friend[b] += 1
    uf.unite(a, b)

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

for i in range(N):
    ans = uf.size(i) - 1
    ans -= friend[i]
    for br in block[i]:
        if uf.same(i, br):
            ans -= 1
    print(ans)



Measured memory_bytes: 112416
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

int main() {
	//ios::sync_with_stdio(false);
	cin >> N;
	int num[200001] = {};
	for (int i = 1; i <= N; i++) {
		cin >> num[i];
	}
	if (N % 2) {
		for (int i = N; i >= 1; i -= 2) {
			cout << num[i] << " ";
		}
		for (int i = 2; i < N; i += 2) {
			cout << num[i];
			if (i != N - 1)cout << " ";
			else cout << endl;
		}
		return 0;
	}
	for (int i = N; i >= 2; i -= 2) {
		cout << num[i] << " ";
	}
	for (int i = 1; i < N; i += 2) {
		cout << num[i];
		if (i != N - 1)cout << " ";
		else cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;
const int MAX_V = 610;

ll d[MAX_V][MAX_V];
int V;

void warshall_floyd() {
    for(int k = 0; k < V; k++) {
        for(int i = 0; i < V; i++) {
            for(int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}


int main(){
  cin >> V;
  vector<vector<ll> > a(V, vector<ll> (V , INF));
  rep(i,V){
    rep(j,V){
      cin >> a.at(i).at(j);
      d[i][j] = a.at(i).at(j);
    }
  }

  warshall_floyd();
  rep(i,V){
    rep(j,V){
      if(d[i][j] != a.at(i).at(j)){
        cout << -1 << endl;
        return 0;
      }
    }
  }

  ll ans = 0;
  rep(i,V){
    rep(j,V){
      rep(k,V){
        if(k == i or k == j) continue;
        if(d[i][j] == d[i][k] + d[k][j]){
          a.at(i).at(j) = 0;
        }
      }
    }
  }


  rep(i,V){
    rep(j,V){
      if(j > i) ans += a.at(i).at(j);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 2432
#include <iostream>
#include <cmath>
#include <iomanip>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>

#define int64 long long
using namespace std;

int main()
{
	int64 nn, mm;
	cin >> nn >> mm;
	int64 tmpa, tmpb, now, xx;
	vector<int64> memo[nn];
	int64 visited[nn];
	for(int64 ii = 0;ii < nn;ii++)
	{
		visited[ii] = -1;
	}
	for(int64 ii = 0;ii < mm;ii++)
	{
		cin >> tmpa >> tmpb;
		memo[tmpa - 1].push_back(tmpb - 1);
		memo[tmpb - 1].push_back(tmpa - 1);
	}
	queue<int64> que;
	que.push(0);
	while(!que.empty())
	{
		now = que.front();
		que.pop();
		for(int ii = 0;ii < memo[now].size();ii++)
		{
			xx = memo[now].at(ii);
			if(visited[xx] == -1)
			{
				visited[xx] = now;
				que.push(xx);
			}
		}
	}
	
	cout << "Yes\n";
	for(int64 ii = 1;ii < nn;ii++)
	{
		cout << (visited[ii] + 1) << '\n';
	}
	return 0;
}

Measured memory_bytes: 13064
#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;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;

    x = x % p;
    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    // cin >> tc;
    while (tc--)
    {
        int n,k;
        cin >> n >> k;
        map<int, int> mp;
        int a[n], f = 0;
        for (int i = 0; i < n;i++){
            cin >> a[i];
            
        }
       // sort(a, a + n);
        int sum = 0, mx = 0;
        for (int i = 0; i < k;i++){
            sum += a[i] + 1;
        }
        mx = sum;
        for (int i = k; i < n;i++){
            sum += a[i] + 1 -( a[i - k]+1);
            mx = max(mx, sum);
        }
            long double ans = 1.0 * mx / 2.0;
        cout << fixed<<setprecision(20)<<ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
signed main(){
    string S;
    cin>>S;
    bool ok=false;
    REP(i,S.size()-1){
        if(S[i]=='A'&&S[i+1]=='C')ok=true;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

typedef long long ll;

int main(){
  int N;
  cin >> N;
  int cnt = 0;
  ll ans = 0;
  ll tmpmin = 1000000000;
  for(int i = 0; i < N; i++){
    ll tmp;
    cin >> tmp;
    if(tmp < 0){
      cnt++;
      tmp = -tmp;
    }
    ans += tmp;
    if(tmp < tmpmin){
      tmpmin = tmp;
    }
  }
  
  if(cnt % 2 == 0){
    cout << ans << endl;
  } else { 
    cout << ans - 2*tmpmin << endl;
  } 
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
nums = [int(s) for s in input().split()]
for i in range(n -1):
  if nums[i] < nums[i + 1]:
    pass
  else:
    p = nums[i]
    nums[i] = min(nums[i + 1:])
    nums[np.argmin(nums[i + 1:]) + i + 1] = p
    break

if nums == [s + 1 for s in range(n)]:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 12504
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args)throws Exception {
        InputReader in = new InputReader (System.in);
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        // Code starts from here //
        int t = in.nextInt();
        if(t % 1000 == 0) pw.println(0);
        else {
            int mods = mod(t, 1000);
            int ans = 1000 - mods;
            pw.println(ans);
        }
        pw.close();
    }

    static int mod(int val, int m) {
        int x = val % m;
        if(x < 0) x += m;
        return x;
    }






    /****************************************
     ******* IO STUFF STARTS FROM HERE ******
     ****************************************/

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString
                (obj));
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new
                    InputStreamReader(stream));
            tokenizer = null;
        }

        //InputReader in = new InputReader(new FileReader("File_Name"));
        public InputReader(FileReader file) {
            reader = new BufferedReader(file);
            tokenizer = null;
        }

        public String next() {

            try {
                while (tokenizer == null || !
                        tokenizer.hasMoreTokens())
                    tokenizer = new StringTokenizer
                            (reader.readLine());
            } catch (IOException e) {
                return null;
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            String line = null;
            try {
                tokenizer = null;
                line =  reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public boolean hasNext(){
            try {
                while (tokenizer == null || !
                        tokenizer.hasMoreTokens())
                    tokenizer = new StringTokenizer
                            (reader.readLine());
            }
            catch (Exception e) {
                return false;
            }
            return true;
        }
    }
}

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

using namespace std;

#define N 1000
#define ll long long
#define dt 2000000000
#define inf 0x3f3f3f3f3f3f3f3f

ll n,cnt = 1,S,T,cm,fs;
ll head[2*N+10],last[2*N+10],cost[2*N+10],flow[2*N+10];
ll rx[2*N+10],rc[2*N+10],ry[2*N+10],bx[2*N+10],bc[2*N+10],by[2*N+10];
bool inq[2*N+10];
queue<ll>q;

struct edge{
	ll des,next,flow,cost;
}e[30005];

void addedge(ll a,ll b,ll f,ll c){
	cnt++;
	e[cnt].des = b;
	e[cnt].cost = c;
	e[cnt].flow = f;
	e[cnt].next = head[a];
	head[a] = cnt;
}

void add(ll a,ll b,ll f,ll c){
	addedge(a,b,f,c);
	addedge(b,a,0,-c);
}

inline ll read(){
	ll s = 0,w = 1;
	char ch = getchar();
	while(!isdigit(ch)){if(ch == '-')w = -1;ch = getchar();}
	while(isdigit(ch)){s = 10 * s + ch - '0';ch = getchar();}
	return s * w;
}

bool spfa(){
	ll i,u,v;
	memset(cost,0x3f,sizeof(cost));
	inq[S] = 1;
	cost[S] = 0;
	flow[S] = inf;
	q.push(S);
	while(!q.empty()){
		u = q.front();
		q.pop();
		inq[u] = 0;
		for(i = head[u];i;i = e[i].next){
			if(!e[i].flow)continue;
			v = e[i].des;
			if(cost[u] + e[i].cost < cost[v]){
				cost[v] = cost[u] + e[i].cost;
				last[v] = i;
				flow[v] = min(flow[u],e[i].flow);
				if(!inq[v]){
					q.push(v);
					inq[v] = 1;
				}
			}
		}
	}
	return cost[T] != inf;
}

void mcmf(){
	ll df,dc,u;
	while(spfa()){
		df = flow[T];
		dc = cost[T];
		fs += df,cm += df * dc;
		for(u = T;u != S;u = e[last[u] ^ 1].des){
			e[last[u]].flow -= df;
			e[last[u] ^ 1].flow += df;
		}
	}
}

int main(){
//	freopen("D.in","r",stdin);
//	freopen("D.out","w",stdout);
	n = read();
	ll i,j;
	ll s = 0;
	for(i = 1;i <= n;i++){
		rx[i] = read();ry[i] = read();rc[i] = read();
	}
	for(i = 1;i <= n;i++){
		bx[i] = read();by[i] = read();bc[i] = read();
	}
	S = 0,T = 2 * n + 5;
	for(i = 1;i <= n;i++)add(S,i,rc[i],0);
	for(i = 1;i <= n;i++)add(i+n+4,T,bc[i],0);
	for(i = 1;i <= n;i++){
		add(i,n+1,inf,rx[i]+ry[i]+dt);
		add(i,n+2,inf,rx[i]-ry[i]+dt);
		add(i,n+3,inf,-rx[i]+ry[i]+dt);
		add(i,n+4,inf,-rx[i]-ry[i]+dt);
		add(n+1,i+n+4,inf,-bx[i]-by[i]+dt);
		add(n+2,i+n+4,inf,-bx[i]+by[i]+dt);
		add(n+3,i+n+4,inf,bx[i]-by[i]+dt);
		add(n+4,i+n+4,inf,bx[i]+by[i]+dt);
	}
	mcmf();
/*for(int u = S;u <= T;u++){
cout<<"u="<<u<<endl;
	for(i = head[u];i;i = e[i].next){
		int v = e[i].des;
		cout<<"v="<<v<<" cost="<<e[i].cost<<" flow="<<e[i].flow<<endl;
	}
} */
//cout<<"cm="<<cm<<" fs="<<fs<<endl;
	cout << fs * 2 * dt - cm;
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
const int sqrtN = 512;
struct SqrtDecomposition {
  int N, K;
  vector<int> data;
  vector<int> bucketSum;
  vector<int> bucketAdd;
  SqrtDecomposition(int n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, 0);
    bucketSum.assign(K, 0);
    bucketAdd.assign(K, 0);
  }
  // [s, t)
  void add(int s, int t, int x) {
    for (int k = 0; k < K; ++k) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= s || t <= l)
        continue;
      if (s <= l && r <= t) {
        bucketAdd[k] += x;
      } else {
        for (int i = max(s, l); i < min(t, r); ++i) {
          data[i] += x;
          bucketSum[k] += x;
        }
      }
    }
  }
  // [s, t)
  int getSum(int s, int t) {
    int sum = 0;
    for (int k = 0; k < K; ++k) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= s || t <= l)
        continue;
      if (s <= l && r <= t) {
        sum += bucketSum[k] + bucketAdd[k] * sqrtN;
      } else {
        for (int i = max(s, l); i < min(t, r); ++i) {
          sum += data[i] + bucketAdd[k];
        }
      }
    }
    return sum;
  }
};
 
signed main() {
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  SqrtDecomposition decomp(N);
  while (Q--) {
    int c;
    cin >> c;
    if (c == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      decomp.add(s, t + 1, x);
    } else {
      int s, t;
      cin >> s >> t;
      cout << decomp.getSum(s, t + 1) << endl;
    }
  }
}

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

using namespace std;

int main() {
	string s;
	cin>>s;
	bool test = false;
	if(s[0] == 'y' || s[0] == 'Y')
		if(s[1] == 'a' || s[1] == 'A')
			if(s[2] == 'k' || s[2] == 'K')
				if(s[3] == 'i' || s[3] == 'I') test = true;
	if(test == true) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

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

ll lcm(ll a, ll b){
	return a / gcd(a, b) * b;
}

int main(void){

	int N;
	cin >> N;

	ll T[N];

	for(int i=0;i<N;i++){
		cin >> T[i];
	}
	ll ans = 1LL;
	for(int i=0;i<N;i++){
		ans = lcm(ans, T[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main(){
	int r,c,rwa,cwa,i,j;
	std::cin>>r>>c;
	if(c==0)return 1;
	int ans[r+1][c+1];
	//r*c????´??????????????????¨??????????¨????
	for(i=0;i<r;i++){
		cwa=0;
		for(j=0;j<c;j++){
			std::cin>>ans[i][j];
			cwa+=ans[i][j];
		}
		ans[i][j]=cwa;
	}	
	//?????????????¨????
	for(i=0;i<c+1;i++){
		rwa=0;
		for(j=0;j<r;j++){
			rwa+=ans[j][i];	
		}
		ans[j][i]=rwa;
	}
	//??????
	for(i=0;i<=r;i++){
		for(j=0;j<=c;j++){
			std::cout<<ans[i][j];
			if(j!=c)std::cout << " ";
		}
		std::cout<<std::endl;
	}	
	return 0;
}

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

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

    int n, m;
    cin >> n >> m;
    scc_graph graph(n);
    int a, b;
    rep(i, m) {
        cin >> a >> b;
        graph.add_edge(a, b);
    }
    auto ans = graph.scc();
    int k = ans.size();
    cout << k << endl;
    rep(i, k) {
        int l = ans[i].size();
        cout << l << " ";
        rep(j, l) cout << ans[i][j] << " ";
        cout << "\n";
    }
    return 0;
}

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

int main(){
  int N;
  int d[110];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> d[i];

  int num[110] = {0};
  for(int i = 0; i < N; i++ ){
    num[d[i]]++;
  }

  int res = 0;
  for(int i = 1; i <= 100; i++){
    if(num[i]){
      res++;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
def f(n):
  if(n % 2 == 0):
    return n // 2
  else:
    return (3 * n) + 1
N = int(input())
 
test = set([N])
before = N
for i in range(1, 10**6 + 1):
  current = f(before)
  if(current in test):
    print(i+1)
    exit()
  before = current
  test.add(before)


Measured memory_bytes: 2940
#include <cstdio>
#include <list>
#include <iostream>
using namespace std;

struct TreeNode{
  int parent;
  int right, left;
  TreeNode(){
    parent = -1;
    right  = -1;
    left   = -1;
  }
};

int n;
TreeNode tree[100000];

int whereRoot(void){
  for (int i=0;i<n;++i)
    if (tree[i].parent == -1) return i;
  return -1;
}

void printPreorder(int node){
  if (node == -1) return;
  cout << " " << node ;
  printPreorder(tree[node].left);
  printPreorder(tree[node].right);
}

void printInorder(int node){
  if (node == -1) return;
  printInorder(tree[node].left);
  cout << " " << node ;
  printInorder(tree[node].right);
}

void printPostorder(int node){
  if (node == -1) return;
  printPostorder(tree[node].left);
  printPostorder(tree[node].right);
  cout << " " << node ;
}

int main(){
  cin >> n;
  for (int i=0;i<n;++i){
    int id, left, right;
    cin >> id >> left >> right;
    tree[id].left  = left;
    tree[id].right = right;
    tree[left].parent = id;
    tree[right].parent = id;
  }

  int root = whereRoot();
  cout << "Preorder" << endl;
  printPreorder(root);
  cout << endl;
  cout << "Inorder"  << endl;
  printInorder(root);
  cout << endl;
  cout << "Postorder" << endl;
  printPostorder(root);
  cout << endl;
  return 0;

}



Measured memory_bytes: 4292
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	int vert = sc.nextInt();
      	int hori = sc.nextInt();
      	
      	System.out.println((vert * hori) -
                          ((vert + hori) - 1));
    }
}

Measured memory_bytes: 21844
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <cmath>
# include <functional>
# include <utility>
#include <iomanip>

# define MOD 1000000000+7
# define INF 2000000000
           
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
int main() {
	bool dp[101][10001];
	ll input[101];
	ll n = 0, sum = 0, ans = 0, w = 0, mini = 1000000000001;
	cin >> n;
	for (ll i = 1; i <= sqrt(n); i++) {
		if (n % i == 0) {
			w = n / i;
			mini = min(mini, i + w - 2);
		}
	}
	cout << mini << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, m[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u)
{
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for (v = 0; v < n; v++) {
    if (m[u][v] == 0) {
      continue;
    }
    if (color[v] == WHITE) {
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs()
{
  int u;
  for (u = 0; u < n; u++) {
    color[u] = WHITE;
  }
  tt = 0;
  
  for (u = 0; u < n; u++) {
    if (color[u] == WHITE) {
      dfs_visit(u);
    }
  }
  for (u = 0; u < n; u++) {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}

int main()
{
  int u, v, k, i, j;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      m[i][j] = 0;
    }
  }

  for (i = 0; i < n; i++) {
    scanf("%d %d", &u, &k);
    u--;
    for (j = 0; j < k; j++) {
      scanf("%d", &v);
      v--;
      m[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define SIZE 100000
const double PI  = 3.1415926535897932384626433832795028841971;
const long long int    INF = 10000000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
bool p[100000];
vector<ll> pr[3];
ll s[100000];
ll ama[100000];
int counter;
ll hiku;
unordered_map<ll,ll> m, num;
unordered_map<ll,ll>::iterator it;

void prime(){
	for(int i = 2; i < SIZE; i++){
		if(p[i]) continue;
		for(int j = i*2; j < SIZE; j += i) p[j] = true;
	}
	for(ll i = 2; i < SIZE; i++){
		if(!p[i]){
			pr[0].push_back(i);
			pr[1].push_back(i*i);
			pr[2].push_back(i*i*i);
		}
	}
}

int main(){
	prime();
	int n;
	cin >> n;
	rep(i,n){
		cin >> s[i];
		ll tmp = 1, ss = s[i];
		rep(j,pr[2].size()){
			if(ss < pr[2][j]) break;
			while(ss%pr[2][j] == 0){
				s[i] /= pr[2][j];
				ss /= pr[2][j];
			}
			if(ss%pr[1][j] == 0){
				tmp *= pr[0][j];
				ss /= pr[1][j];
			}
			if(ss%pr[0][j] == 0){
				tmp *= pr[1][j];
				ss /= pr[0][j];
			}
			if(tmp > INF){
				tmp = 0;
				break;
			}
		}
		if(tmp == 0) continue;
		int st = 0, en = pr[0].size(), mid;
		while(en-st>1){
			mid = (st+en)/2;
			if(pr[1][mid] > ss){
				en = mid;
			} else{
				st = mid;
			}
		}
		if(ss == pr[1][st]){
			tmp *= pr[0][st];
		} else{
			tmp *= ss*ss;
		}
		if(tmp > INF) continue;
		m[s[i]]++;
		num[s[i]] = tmp;
		//cout << s[i] << " " << num[s[i]] << endl;
	}
	for(it = m.begin(); it != m.end(); it++){
		ama[counter] = (*it).first;
		counter++;
	}
	sort(ama,ama+counter);
	for(it = m.begin(); it != m.end(); it++){
		ll f = (*it).first;
		ll tmp = num[f];
		if(tmp == 0) continue;
		if(f == 1){
			hiku = hiku+(m[f]-1)*2;
			continue;
		}
		
		int st = 0, en = counter, mid;
		while(en-st>1){
			mid = (st+en)/2;
			if(ama[mid] > tmp) en = mid;
			else st = mid;
		}
		if(ama[st] == tmp) hiku += min(m[f],m[tmp]);
		//cout << " " << hiku << endl;
	}
	cout << n-hiku/2 << endl;
}














Measured memory_bytes: 9288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a>k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
}

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

int C[500];
int S[500];
int F[500];
int time_set[500];

int main()
{
    int N;
    scanf("%d", &N);
    for (int i=0; i<N-1; i++){
        scanf("%d %d %d", &C[i], &S[i], &F[i]);
    }

    int loop_num = N - 1;

    for (int i=0; i<N; i++){
        if (i == N-1){
            time_set[i] = 0;
        }
        else{
            loop_num -= 1;
            int next_station = C[i] + S[i];
            int start_index = i;
            for (int l=0; l<loop_num; l++){
                int waiting_time = S[start_index + 1];
                while (waiting_time < next_station){
                    waiting_time += F[start_index + 1];
                }
                next_station = waiting_time + C[start_index + 1];
                start_index += 1;
            }
            time_set[i] = next_station;
        }
    }

    for (int n=0; n<N; n++){
        printf("%d\n", time_set[n]);
    }

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

typedef vector<ll> vec;
typedef vector<vec> mat;

mat operator*(const mat& a,const mat& b){
  int n=a.size();
  mat res(n,vec(n,0));
  rep(i,n)rep(j,n)rep(k,n){
    (res[i][j]+=(a[i][k]*b[k][j])%mod)%=mod;
  }
  return res;
}

mat mpow(mat a,ll m){
  ll n=a.size();
  mat res(n,vec(n,0));
  rep(i,n)res[i][i]=1;
  while(m){
    if(m&1)res=res*a;
    a=a*a;
    m>>=1;
  }
  return res;
}

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

  ll n,k;
  cin>>n>>k;

  mat dp(n,vec(n,0));
  rep(i,n)rep(j,n)cin>>dp[i][j];

  mat res=mpow(dp,k);
  ll sum=0;
  rep(i,n)rep(j,n)(sum+=res[i][j])%=mod;
  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();
        int k = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        sc.close();

        int ans = 0;

        if (n - k < 0) {
            ans = n * x;
        } else {
            ans = k * x + (n - k) * y;
        }

        System.out.println(ans);

    }
}

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

int main(){
	int n,k;
	cin>>n>>k;
	double ret=0;
	for(int i=1;i<=n;i++){
		double cur=1.0/n;
		int now=i;
		while(now<k)
			now*=2, cur/=2;
		ret+=cur;
	}
	cout<<setprecision(15)<<fixed<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main(void) {
    int x, y;
    std::scanf("%d %d", &x, &y);
    if (x % y == 0) {
        std::puts("-1");
        return 0;
    }
    for (int z = x; z <= 1000000000000000000; z += x) {
        if (z % y != 0) {
            std::printf("%d\n", z);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007;
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define tz(x) __builtin_ctz(x)
#define csb(x) __builtin_popcount(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;


int32_t main(){
   
int n,a,b;cin>>n>>a>>b;
int x=n/(a+b)*a+min(n%(a+b),a);
cout<<x<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A, B =0;
    int score =0;
    cin >> A >> B;
    for(int i=0; i<2; i++){
        if(A < B){
            score +=B;
            B -=1;
        }else if(B <= A){
            score +=A;
            A -=1;
        }
    }
    cout << score;
}

Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toInt()}
    val A = IntArray(n + 2)
    for(i in 1 .. n){
        A[i] = a[i - 1]
    }
    var sum = 0
    for(i in 0 .. n){
        sum += Math.abs(A[i + 1] - A[i])
    }
    val st = StringBuilder()
    for(i in 1 .. n){
        st.append(sum - Math.abs(A[i] - A[i - 1]) - Math.abs(A[i + 1] - A[i]) + Math.abs(A[i + 1] - A[i - 1]))
        st.append('\n')
    }
    print(st)
}


Measured memory_bytes: 55220
from typing import List, Set
import sys
sys.setrecursionlimit(1000000) # RecursionError: maximum recursion depth exceeded in comparison 対策

def dfs(current: int, prev: int) -> None:
	global timer
	# ノードcurrentを訪問した直後の処理
	prenum[current] = timer
	lowest[current] = timer
	timer += 1
	visited[current] = True
	for next_v in G[current]:
		if not visited[next_v]:
			# ノードcurrentからノードnext_vへ訪問する直前の処理
			parent[next_v] = current
			dfs(next_v, current)
			# ノードnext_vの探索が終了した直後の処理
			lowest[current] = min(lowest[current], lowest[next_v])
		elif next_v != prev:
			# エッジ(current -> next)がBack-edgeの場合の処理
			lowest[current] = min(lowest[current], prenum[next_v])

def art_points() -> Set[int]:
	# lowestの計算
	dfs(0, -1) # 0：root
	np: int = 0
	ap: Set[int] = set()
	for i in range(1, n):
		p = parent[i]
		if p == 0:
			np += 1
		elif prenum[p] <= lowest[i]:
			ap.add(p)
	if np > 1:
		ap.add(0)
	return ap


if __name__ == "__main__":
	n, m = map(int, input().split())
	G: List[List[int]] = [[] for _ in range(n)]
	prenum: List[int] = [0 for _ in range(n)]
	parent: List[int] = [-1 for _ in range(n)]
	lowest: List[int] = [0 for _ in range(n)]
	visited: List[bool] = [False for _ in range(n)]
	timer = 1
	for _ in range(m):
		s, t = map(int, input().split())
		G[s].append(t)
		G[t].append(s)
	ap = art_points()
	ap = sorted(ap)
	for p in ap:
		print(p)
	# print(prenum)
	# print(parent)
	# print(lowest)


Measured memory_bytes: 21144
#include <stdio.h>
#include <stdbool.h>

void Judgetriangle(int a, int b, int c);
void judge(int a, int b, int c);
int a, b, c;
bool flag = false;
int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        {
            flag = false;
            scanf("%d %d %d", &a, &b, &c);
            Judgetriangle(a, b, c);
        }
    return 0;
}

void Judgetriangle(int a, int b, int c)
{
    judge (a, b, c);
    judge (a, c, b);
    judge (b, c, a);
    if (flag == true) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}

void judge(int a, int b, int c)
{
    if (a * a + b * b == c * c) {
        flag = true;
    }
}
    

Measured memory_bytes: 1012
#include <iostream>
#include <iomanip>
using namespace std;
using ll = long long int;
int main() {
    double W, H, x, y;
    cin >> W >> H >> x >> y;


    cout << fixed << setprecision(10) << (W * H)/2.0 << " " << (x == (W / 2.0) && y == (H / 2.0)? 1 : 0) << endl;
}

Measured memory_bytes: 3780
var
	b:Longint;
	n,k,c:int64;
begin
	read(n,k);
	inc(n);
	for b:=k+1 to n-1 do begin
		inc(c,n div b*(b-k));
		if k=0 then dec(c);
		if n div b*b+k<n then inc(c,n-n div b*b-k);
	end;
	writeln(c);
end.


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

int main(){
int n,cnt=0;
cin >>n;
string s[n]={};
int t[n]={};
string name;
  
for(int i=0; i<n; i++){
cin >>s[i] >>t[i];
} 
  cin >>name; //寝落ちた時の曲名
for(int i=0; i<n; i++){
    if(s[i]==name){
      for(int j=i+1; j<=n-1; j++){
        cnt+=t[j];
      }
    }
}
cout <<cnt <<endl;
return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int x, y;
    cin >> x >> y;
    if(y % 2 == 1 ) {
        cout << "No" << endl;
        return 0;
    }
    for(int i = 0; i <= x; ++i) {
        if(i * 2 + (x - i) * 4 == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;//*/
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  ll n;
  cin >> n;
  vi v;
  v.push_back(1);
  ll six = 6;
  while(six<=n) {
    v.push_back(six);
    six *= (ll)6;
  }
  ll nine = 9;
  while(nine<=n) {
    v.push_back(nine);
    nine *= (ll)9;
  }
  ll dp[110000];
  dp[0] = 0;
  for(int i = 1; i<=n; i++) {
    dp[i] = i;
    rep(j,v.size()) {
      if(i-v[j]>=0) dp[i] = min(dp[i],1+dp[i-v[j]]);
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
C = tuple(map(int, input().split()))
assert len(A) == N
assert len(B) == N
assert len(C) == N - 1

score = sum([B[a-1] for a in A])
for A1,A2 in zip(A, A[1:]):
  if A2 == A1 + 1:
    score += C[A1-1]
print(score)

Measured memory_bytes: 61860
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int c = ni();
    int k = ni();
    int[] t = na(n);
    Arrays.sort(t);
    
    int last = t[0];
    long sum = 0;
    long ret = 0;
    for (int x : t) {
      
      if (sum >= c || x - last > k) {
        sum = 0;
        last = x;
        ret ++;
      }
      sum ++;
    }
    if (sum > 0) {
      ret ++;
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

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

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

int main(void){
    char s[101],t[101];
    int size_S,size_T;
    
    scanf("%s %s",s,t);
    size_S = strlen(s);
    size_T = strlen(t);
    
    qsort(s,size_S,sizeof(char),up);
    qsort(t,size_T,sizeof(char),down);
    
    if(strcmp(s,t) < 0)printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
signed main() {
	ll a, b;
	cin >> a >> b;
	cout << max({ a + b, a - b, a * b }) << endl;
	ggr
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define orep(i, n) for(int i = 1; i <= (n); i++)
#define srep(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define ru(a,b) ((a+b-1) / b)
#define rng(x) (x).begin(),(x).end()
#define P pair<int,int>

typedef long long ll;
#define vi vector<int>;
#define vvi vector<vi>;
using namespace std;

int main() {
  int n,x,t;
  cin >> n >> x >> t;
  cout << ru(n,x) * t << endl;


  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;


int main(){
    int n,m; cin >> n >> m;
    vector<int> x(m);
    rep(i,m) cin >> x[i];

    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    sort(all(x));
    vector<int> d(m-1);
    rep(i,m-1) d[i]=x[i+1]-x[i];
    sort(all(d));
    ll ans=0;
    rep(i,m-n) ans+=d[i];
    cout << ans << endl;
return 0;
}


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

def main():
    n = int(input())
    spi = []
    for i in range(n):
        s, p = input().split()
        spi.append((s, -int(p), i))
    spi = sorted(spi)
    for s, p, i in spi:
        print(i + 1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") 
  
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;


int main()
{
    int n, k, res = 0;
    cin >> n >> k;
    
    string s;
    cin >> s;
    
    for(int i = 0; i < n - 1; i ++)
    {
        res += (s[i] == s[i + 1]);
    }
    
    cout << min(n - 1, res + 2 * k);

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,dp[102][64000],k,p[64009],pi,pp[64009],ppi,sq,i,j,mod=1000000007,zx[64000];
map <long long, long long> m;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>k;
	sq=sqrt(a);
	for(b=1; b<=sq; b++){
		c=b;d=a/b;
		pi++;p[pi]=c;
		m[c]=pi;
		if(c!=d){
			ppi++;pp[ppi]=d;
		}
	}
	for(b=ppi; b>=1; b--){
		pi++;p[pi]=pp[b];
		m[pp[b]]=pi;
	}
	for(b=1; b<=pi; b++){
		zx[b]=m[a/p[b]];
	}
	for(i=1; i<=pi; i++) dp[0][i]=1;
	for(i=1; i<=k; i++){
		for(j=1; j<=pi; j++){
			dp[i][j]=dp[i-1][zx[j]];
		}
		for(j=1; j<=pi; j++){
			dp[i][j]=dp[i][j-1]+dp[i][j]*(p[j]-p[j-1]);
			dp[i][j]%=mod;
		}
	}
	cout<<dp[k][pi];
	return 0;
}

Measured memory_bytes: 55936
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
 
typedef long long ll;
int main() {
  int a, b, c = 1, ans = 0;
  cin >> a >> b;
  int i = 1;
  while(c < b) {
    c--;
    c += a;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def manhattanDist(p1, p2):
    (x1, y1) = p1
    (x2, y2) = p2
    return abs(x1-x2) + abs(y1-y2)

N = int(input())
ans = "Yes"
now = 0
(nx, ny) = (0, 0)
for _ in range(N):
    t, x, y = map(int, input().split())
    d = manhattanDist((nx, ny), (x, y))
    sa = t - now
    if d <= sa and (sa-d) % 2 == 0:
        ()
    else:
        ans = "No"
        break

    now = t
    nx = x
    ny = y

    
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int N;
vector<double> x, y;
vector<char> d;

double area(double t) {
    double xma = -INF, xmi = INF, yma = -INF, ymi = INF;
    for(int i=0; i<N; ++i) {
        double tx, ty;
        if(d[i] == 'L') tx = x[i] - t, ty = y[i];
        else if(d[i] == 'R') tx = x[i] + t, ty = y[i];
        else if(d[i] == 'D') tx = x[i], ty = y[i] - t;
        else tx = x[i], ty = y[i] + t;
        xma = max(xma, tx);
        xmi = min(xmi, tx);
        yma = max(yma, ty);
        ymi = min(ymi, ty);
    }
    return (xma - xmi) * (yma - ymi);
}

double solve() {
    vector<double> opt;
    opt.push_back(0);

    // x_min
    {
        double m1 = INF, m2 = INF, m3 = INF;
        for(int i=0; i<N; ++i) {
            if(d[i] == 'L') m1 = min(m1, x[i]);
            else if(d[i] == 'R') m2 = min(m2, x[i]);
            else m3 = min(m3, x[i]); 
        }
        if(m1 < INF && m2 < INF) opt.push_back(abs(m1 - m2) / 2.0);
        if(m1 < INF && m3 < INF) opt.push_back(abs(m1 - m3));
        if(m2 < INF && m3 < INF) opt.push_back(abs(m2 - m3));
    }

    // x_max
    {
        double m1 = -INF, m2 = -INF, m3 = -INF;
        for(int i=0; i<N; ++i) {
            if(d[i] == 'L') m1 = max(m1, x[i]);
            else if(d[i] == 'R') m2 = max(m2, x[i]);
            else m3 = max(m3, x[i]); 
        }
        if(m1 > -INF && m2 > -INF) opt.push_back(abs(m1 - m2) / 2.0);
        if(m1 > -INF && m3 > -INF) opt.push_back(abs(m1 - m3));
        if(m2 > -INF && m3 > -INF) opt.push_back(abs(m2 - m3));
    }

    // y_min
    {
        double m1 = INF, m2 = INF, m3 = INF;
        for(int i=0; i<N; ++i) {
            if(d[i] == 'D') m1 = min(m1, y[i]);
            else if(d[i] == 'U') m2 = min(m2, y[i]);
            else m3 = min(m3, y[i]); 
        }
        if(m1 < INF && m2 < INF) opt.push_back(abs(m1 - m2) / 2.0);
        if(m1 < INF && m3 < INF) opt.push_back(abs(m1 - m3));
        if(m2 < INF && m3 < INF) opt.push_back(abs(m2 - m3));
    }

    // y_max
    {
        double m1 = -INF, m2 = -INF, m3 = -INF;
        for(int i=0; i<N; ++i) {
            if(d[i] == 'D') m1 = max(m1, y[i]);
            else if(d[i] == 'U') m2 = max(m2, y[i]);
            else m3 = max(m3, y[i]); 
        }
        if(m1 > -INF && m2 > -INF) opt.push_back(abs(m1 - m2) / 2.0);
        if(m1 > -INF && m3 > -INF) opt.push_back(abs(m1 - m3));
        if(m2 > -INF && m3 > -INF) opt.push_back(abs(m2 - m3));
    }

    double res = INF;
    for(double t : opt) {
        res = min(res, area(t));
    }
    return res;
}

int main() {
    cin >> N;
    x.resize(N);
    y.resize(N);
    d.resize(N);
    for(int i=0; i<N; ++i) {
        cin >> x[i] >> y[i] >> d[i];
    }

    cout << fixed << setprecision(10) << solve() << endl;
}

Measured memory_bytes: 1920
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <set>
int read(){
	register int x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f ^= 1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
#define N 100005
int n, m, ans;
struct node{
	int x, y;
	bool operator < (const node &rhs) const {
		return y > rhs.y || (y == rhs.y && x < rhs.x);
	}
}a[N];
std :: set<int> S;
int main(){
	n = read(), m = read();
	for (register int i = 1; i <= n; ++i) a[i].x = read(), a[i].y = read();
	std :: sort(a + 1, a + 1 + n);
	for (register int i = 1; i <= m; ++i) S.insert(i);
	for (register int i = 1; i <= n; ++i){
		if (S.empty()) break;
		std :: set<int> :: iterator it = S.upper_bound(m - a[i].x + 1);
		if (it == S.begin()) continue;
		--it, S.erase(it), ans += a[i].y;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 5760
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        //入力
        long[] d = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long ans = 0;

        //条件を満たすB以下の個数
        //cで割り切れる数
        long tmp1 = d[1] / d[2];
        //dで割り切れる数
        long tmp2 = d[1] / d[3];
        //cdで割り切れる数
        var lcm = Lcm(d[2], d[3]);
        long tmp3 = d[1] / lcm;

        //条件を満たすA-1以下の個数
        //cで割り切れる数
        long tmp4 = (d[0] - 1) / d[2];
        //dで割り切れる数
        long tmp5 = (d[0] - 1) / d[3];
        //cdで割り切れる数
        long tmp6 = (d[0] - 1) / lcm;
        ans = (d[1] - tmp1 - tmp2 + tmp3) - ((d[0] - 1) - tmp4 - tmp5 + tmp6);

        //出力
        Console.WriteLine(ans);
    }

    // 最小公倍数
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
}


Measured memory_bytes: 13396