akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(void){
    int ValueA, ValueB, ValueC, Count;
    
    cin >> ValueA >> ValueB >> ValueC;
    cin >> Count;

    for(int i = 0; i < Count; i++){
        if(ValueA >= ValueB && ValueA >= ValueC){ ValueA = ValueA * 2; }
        else if(ValueB >= ValueA && ValueB >= ValueC) { ValueB = ValueB * 2; }
        else { ValueC = ValueC * 2; }
    }

    cout << ValueA + ValueB + ValueC << endl;
    
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //long start = System.currentTimeMillis();
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();

        for (int i = 0;i<k;++i)
        {
            if (a >= b) b *= 2;
            else if (b >= c) c *= 2;
            //else break;
        }

        if (a<b && b < c) System.out.println("Yes");
        else System.out.println("No");

        System.err.println(a+","+b+","+c);
        sc.close();
//        long end = System.currentTimeMillis();
//        System.err.println((end-start)+"ms");
    }
}

Measured memory_bytes: 39336
use std::str::FromStr;
use std::fmt::Debug;

fn read_line<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

fn main(){

	let x : Vec<u32> = read_line();
	
	if (x[0] < x[1]) && (x[1] < x[2]) {
		println!("Yes");
	} else {
		println!("No");
	}
}


Measured memory_bytes: 5020
#include <bits/stdc++.h>
#define inf (long long)1e17
using namespace std;

long long n, p[4], t[4];

void prepair();
void solve();

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

void prepair() {
  cin >> n;
  for(int i = 0; i < 4; ++i) cin >> p[i];
  for(int i = 0; i < 4; ++i) cin >> t[i];
}
void solve() {
  vector<vector<long long>> dp(
      5, vector<long long>(n + 1, inf));
  dp[0][0] = 0;
  for(int i = 0; i < 4; ++i) {
    for(int j = 0; j <= n; ++j) {
      dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
      dp[i + 1][min(n, j + t[i])] = min(
          dp[i + 1][min(n, j + t[i])], dp[i + 1][j] + p[i]);
    }
  }
  cout << dp[4][n] << endl;
}


Measured memory_bytes: 3172
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i;
	int len;
	char str[1024];
	
	fgets(str, 1024, stdin);
	
	len = strlen(str);
	for (i = 0; i < len; i++){
		if (strncmp(&str[i], "apple", 5) == 0){
			strncpy(&str[i], "peach", 5);
		}
		else if (strncmp(&str[i], "peach", 5) == 0){
			strncpy(&str[i], "apple", 5);
		}
	}
	printf("%s", str);
	
	return (0);
}

Measured memory_bytes: 944
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
using ulong = unsigned long;
using ll = long long;

int main(){
	string str;
	cin >> str;
	bool n = false, w = false, s = false, e = false;
	for(char c : str){
		switch(c){
			case 'N': n = true; break;
			case 'W': w = true; break;
			case 'S': s = true; break;
			case 'E': e = true; break;
		}
	}
	if(n == s && w == e){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define reset(x,n) memset((x),(n),sizeof(x))
#define all(n) (n).begin(),(n).end()
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0);
ll arr[105];
ll win[100005];
int n,k;

int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	for(int i=arr[1];i<=k;i++){
		//bool qq=1;
		for(int j=1;j<=n&&i-arr[j]>=0;j++){
			if(!win[i-arr[j]])win[i]=1;
		}
	}
	if(win[k])cout<<"First\n";
	else cout<<"Second\n";
}


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

int main(){
  int N,M,C;
  cin >> N >> M >> C;

  int B[40];
  vector<vector<int>> A(40,vector<int>(40));
  
  for(int i=0 ; i<M; i++){
    cin >> B[i];
  }
  
  for(int i=0; i<N; i++){
  for(int j=0; j<M; j++){
    cin >> A[i][j];
  }
  }

  
  int ans[N]={0};
  for(int i=0; i<N; i++){
    for(int j=0; j<M; j++){
    ans[i]=ans[i]+A[i][j]*B[j];
  }
  }

  int sum=0;
  
  for(int i=0; i<N; i++){
  if(ans[i]+C >0){
  sum ++;
  }
  } 
  
  cout << sum <<endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
int n;
void solve() {
    cin >> n;
    string s;
    cin >> s;
    s = '$' + s;
    map<char, int> cnt;
    for (auto &i: s) {
        cnt[i]++;
    }
    int ans = cnt['R'] * cnt['G'] * cnt['B'];
    string cmp = "RGB";
    sort(all(cmp));
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            int lol = j - i;
            int k = j + lol; 
            if (k <= n) {
                string other = "";
                other += s[i];
                other += s[j];
                other += s[k];
                sort(all(other));
                if (other == cmp)
                    --ans;
            }
        }
    }
    cout << ans;
}      


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

int main() {
  int n, k, d, tmp;
  scanf("%d %d\n", &n, &k);
  int member[n];
  for (int i = 0; i < n; i++) {
    member[i] = 0;
  }
  for (int i = 0; i < k; i++) {
    scanf("%d\n", &d);
    for (int j = 0; j < d; j++) {
      scanf("%d", &tmp);
      member[tmp - 1]++;
    }
  }
  int counter = 0;
  for (int i = 0; i < n; i++) {
    if (member[i] == 0) {
      counter++;
    }
  }
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e8;
typedef long long ll;
ll mod = 998244353;
long long fast_exp(long long a, long long b)
{
    if(b == 0)
	   return 1;
    else
    {
	   long long res = 1;
	   res = fast_exp(a,b/2);
	   res = (res*res)%mod;
	   if(b%2 == 1)
		  res = (res*a)%mod;
	   return res;
 
    }
}
const ll N = 1e6;




int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int n;
	cin>>n;
	int a[n+1] ;
	for(int i =1; i<=n ; i++)
		cin>>a[i];
	int b[n+1] , c[n+1];
	for(int i = 1; i<=n ; i++)
		cin>>b[i];
 	for(int i = 1; i<n ; i++)
 		cin>>c[i];

 	int sum = 0;
 	int prev = -2;
 	for(int i = 1; i<=n ; i++)
 	{
 		sum += b[a[i]];
 		if(prev == a[i]-1)
 			sum+=c[prev];
 		prev = a[i];
 	}

 	cout<<sum<<endl;

	return 0;
	
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define mor > muu & operator << (
#define R22(r) sim > typename \
  enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) {
sim > struct rge { c b, e; };
sim > rge<c> range(c h, c n) { return {h, n}; }
sim > auto dud(c* r) -> decltype(cerr << *r);
sim > char dud(...);
struct muu {
#ifdef LOCAL
stringstream a;
~muu() { cerr << a.str() << endl; }
R22(<) a << boolalpha << g; ris; }
R22(==) ris << range(begin(g), end(g)); }
sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; }
sim mor rge<c> u) {
  a << "[";
  for (c i = u.b; i != u.e; ++i)
    *this << ", " + 2 * (i == u.b) << *i;
  ris << "]";
}
#else
sim mor const c&) { ris; }
#endif
muu & operator()() { ris; }
};
#define imie(r...) "[" #r ": " << (r) << "] "
#define imask(r...) "[" #r ": " << bitset<8 * sizeof(r)>(r) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
#define arr2(a, i, j) "[" #a imie(i) imie(j) ": " << a[i][j] << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")

int n;
const int N = 1e5 + 7;
vector <int> G[N];
const int mod = 1e9 + 7;
int dp[N][2];

void dfs(int v, int p) {
    for (int u : G[v]) {
        if (u != p) dfs(u, v);
    }
    
    long long pom = 1;
    for (int u : G[v]) if (u != p) pom = (pom * dp[u][0]) % mod;
    dp[v][1] = pom;
    pom = 1;
    for (int u : G[v]) if (u != p) pom = (pom * (dp[u][0] + dp[u][1])) % mod;
    dp[v][0] = pom;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i < n; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(1, 0);
    long long res = dp[1][0] + dp[1][1];
    printf("%lld\n", res % mod);
    return 0;
}


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

int main()
{
    int n,a,b,c;
    cin >> n;
    int dp[n][3];

    cin >> a >> b >> c;
    dp[0][0] = a;
    dp[0][1] = b;
    dp[0][2] = c; 
    for(int i = 1; i < n; ++i)
    {
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i - 1][1],dp[i - 1][2]) + a;
        dp[i][1] = max(dp[i - 1][0],dp[i - 1][2]) + b;
        dp[i][2] = max(dp[i - 1][0],dp[i - 1][1]) + c;
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
    return 0;
}

Measured memory_bytes: 1408
import heapq


def dijkstra(adj: list, start, goal=None):
    """adj:隣接行列"""
    num = len(adj)          # グラフのノード数
    dist = [float('inf') for i in range(num)]  # 始点から各頂点までの最短距離を格納する
    prev = [float('inf') for i in range(num)]  # 最短経路における，その頂点の前の頂点のIDを格納する
    dist[start] = 0
    # プライオリティキュー．各要素は，(startからある頂点vまでの仮の距離, 頂点vのID)からなるタプル
    q = []
    heapq.heappush(q, (0, start))  # 始点をpush
    while q:
        prov_cost, src = heapq.heappop(q)  # pop
        # プライオリティキューに格納されている最短距離が，現在計算できている最短距離より大きければ，distの更新をする必要はない
        if dist[src] < prov_cost:
            continue
        # 他の頂点の探索
        for dest in range(num):
            cost = adj[src][dest]
            if cost != float('inf') and dist[dest] > dist[src] + cost:
                dist[dest] = dist[src] + cost  # distの更新
                # キューに新たな仮の距離の情報をpush
                heapq.heappush(q, (dist[dest], dest))
                prev[dest] = src                      # 前の頂点を記録
    return dist


INF = float('inf')
xs, ys, xt, yt = map(int, input().split())
n = int(input())
n += 2
li = [None] * n
li[0] = (xs, ys, 0)
li[n - 1] = (xt, yt, 0)
for i in range(n - 2):
    x, y, r = map(int, input().split())
    li[i + 1] = (x, y, r)
mat = [[INF] * n for _ in range(n)]
for i in range(n):
    mat[i][i] = 0
    for j in range(i + 1, n):
        x1, y1, r1 = li[i]
        x2, y2, r2 = li[j]
        d = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5
        res = max(d - r1 - r2, 0)
        mat[i][j] = res
        mat[j][i] = res
d = dijkstra(mat, 0)
print(d[n - 1])

Measured memory_bytes: 122204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	ll ch=true;
	for(ll i=1;i<=s.size();i++){
		if(i%2==0){
			if(s[i-1]=='R'){
				ch=false;
			}
		}
		else{
			if(s[i-1]=='L'){
				ch=false;
			}
		}
	}
	cout << (ch?"Yes":"No");
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,q,a[100010],rank[100010]={},cnt=1,l=0,dat[100010]={100010};
    vector<int> res;
    cin >> n >> m >> q;
    REP(i,q){
        cin >> a[i];
    }
    for(int i= q-1; i>=0;--i){
        if(rank[a[i]]==0){
            rank[a[i]]=cnt;
            ++cnt;
            res.push_back(a[i]);
        }
    }
    REPN(i,1,m){
        if(rank[i]==0){
            rank[i]=cnt;
            ++cnt;
            res.push_back(i);
        }
    }
    //OUT(l)
    for(int i=m-1;i>0;--i){
        if(res[i]<res[i-1]){
            l=i;
            break;
        }
    }

    for(int i= q-1; i>=0;--i){
        if(dat[rank[a[i]]]<dat[rank[a[i]]-1]){
        ++dat[rank[a[i]]];
        }
    }
    /*if(l==0){
        cout << "AAA" <<endl;
        return 0;
    }*/
    REPN(i,1,l){
        if(dat[i]<n){
            cout << "No" <<endl;
            return 0;
        }
    }
    cout << "Yes" <<endl;
    /*
    OUT(l)
    REP(i,m){
        OUT(res[i])
    }
    REP(i,m+1){
        OUT(dat[i])
    }
    //*/



    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll arr[100001];

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	ll n,k;
	cin>>n>>k;
	for(ll i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	
	ll dp[100001]={0};
	
	dp[1]=abs(arr[1]-arr[0]);
//	dp[2]=min(abs(arr[2]-arr[0]),abs(arr[2]-arr[1])+abs(arr[1]-arr[0]));
//	dp[3]=min(abs(arr[3]-arr[0]),abs(arr[3]-arr[2])+dp[2]);
	
	for(ll i=2;i<n;i++)
	{
	    ll mini=1e9;
	    for(ll j=1;j<=k;j++)
	    {
	        if(i-j>=0)
	        {
	        ll cost=dp[i-j]+abs(arr[i]-arr[i-j]);
	        if(cost<mini)
	        {
	            mini=cost;
	        }
	        }
	    }
	    
	    dp[i]=mini;
	}
	
	cout<<dp[n-1]<<"\n";
	
}


Measured memory_bytes: 1792
#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	int n,m;
	char convert[127],from[2],to[2],tmp[2];

	scanf("%d",&n);
	while(n != 0){

		for(int k=0;k<127;k++)convert[k] = 0;
		for(int i=0; i<n; i++){
			scanf("%s %s",from,to);
			convert[from[0]] = to[0];
		}
		scanf("%d",&m);
		for(int i=0; i<m; i++){
			scanf("%s",tmp);
			if(convert[tmp[0]] == 0)printf("%s",tmp);
			else{
				printf("%c",convert[tmp[0]]);
			}
		}
		printf("\n");
		scanf("%d",&n);
	}

	return 0;
}

Measured memory_bytes: 2612
use proconio::input;

fn main() {
    input! {
        mut n: u64,
    }
    let mut v = vec![];
    calc(n, &mut v);

    let mut r = 0;
    for e in v {
        r += get_count(e);
    }

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

fn calc(n: u64, v: &mut Vec<u64>) {
    let sub = |n: u64, m: u64| -> (u64, u64) {
        let mut c = 0;
        let mut r = n;
        while r % m == 0 {
            c += 1;
            r /= m;
        }
        (c, r)
    };

    let (c, n) = sub(n, 2);
    if c > 0 {
        v.push(c);
    }
    let mut m = 3;
    let mut r = n;
    while m * m <= r {
        let (c, n) = sub(r, m);
        if c > 0 {
            v.push(c);
        }
        r = n;
        m += 2;
    }
    if r > 1 {
        v.push(1);
    }
}

fn get_count(n: u64) -> u64 {
    if n <= 2 {
        1
    } else if n <= 2 + 3 {
        2
    } else if n <= 2 + 3 + 4 {
        3
    } else if n <= 2 + 3 + 4 + 5 {
        4
    } else if n <= 2 + 3 + 4 + 5 + 6 {
        5
    } else if n <= 2 + 3 + 4 + 5 + 6 + 7 {
        6
    } else if n <= 2 + 3 + 4 + 5 + 6 + 7 + 8 {
        7
    } else if n <= 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 {
        8
    } else {
        9
    }
}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
int w,h,n;
cin >> w >> h >> n;

int xmax = w;
int xmin = 0;
int ymax = h;
int ymin = 0;
int x,y,a;

for (int i = 0; i < n; i++)
{
  cin >> x >> y >> a;

  if(a == 1){
    xmin = max(xmin,x);
  }
  if(a == 2){
    xmax = min(xmax,x);
  }
  if(a == 3){
    ymin = max(ymin,y);
  }
  if(a == 4){
    ymax = min(ymax,y);
  }

}

int s = max((ymax-ymin),0) * max((xmax-xmin),0);

cout << s << endl;


}


Measured memory_bytes: 256
#include<stdio.h>
int s[6];
int main(){
	int a;
	scanf("%d",&a);
	for(;a--;){
		double b;
		scanf("%lf",&b);
		if(b<165.0)s[0]++;
		else if(b<170.0)s[1]++;
		else if(b<175.0)s[2]++;
		else if(b<180.0)s[3]++;
		else if(b<185.0)s[4]++;
		else s[5]++;
	}
	for(int i=0;i<6;i++){
		printf("%d:",i+1);
		for(;s[i]--;)printf("*");
		printf("\n");
	}
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		long[] X = new long [m];
		for(int i=0;i<m;i++) {
			X[i] = Long.parseLong(sc.next());
		}
		sc.close();
		Arrays.sort(X);
		if(n>=m) {
			System.out.println(0);
			return;
		}

		if(X[0]<0) {
			for(int i=m-1;0<=i;i--) {
				X[i] += Math.abs(X[0]);
			}
		}else {
			for(int i=m-1;m<=i;i--) {
				X[i] -= Math.abs(X[0]);
			}
		}

		//X[i+1]とX[i]の幅
		long[]widthX=new long [m-1];

		for(int i=0;i<m-1;i++) {
			widthX[i] = X[i+1]-X[i];
		}
		Arrays.sort(widthX);
		long tmp = 0;
		for(int i=0,j=widthX.length-1;i<j;i++,j--) {
			tmp = widthX[i];
			widthX[i]=widthX[j];
			widthX[j]=tmp;
		}

		long res = 0;

		for(int i=0;i<n-1;i++){
			res += widthX[i];
		}
		long sumwidthX = 0;
		for(int i=0;i<m-1;i++){
			sumwidthX += widthX[i];
		}
		res = sumwidthX-res;
		System.out.println(res);

	}

}


Measured memory_bytes: 47792
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n, l := nextInt(), nextInt()
	s := make([]string, n)
	res := make([]byte, n*l)

	for i := 0; i < n; i++ {
		s[i] = next()
	}

	sort.Strings(s)

	for i := 0; i < n; i++ {
		for j := 0; j < l; j++ {
			res[i*l+j] = s[i][j]
		}
	}

	fmt.Println(string(res))
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
typedef long long ll;
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ld long double
#define ss second
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384626
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

const int mod = 1'000'000'007;

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}
#define INFF 200

	
int main()
{
		fastio;
		ll ttt = 1;
		//cin >> t;
		rep(tt,1,ttt+1)
		{
			ll  d;
			string k;
			cin >> k >> d;
			//deb(k);
			vll dp(d), dp1(d), dp1old(d);
			dp[0] = 1; dp1old[0] = 1;
			ll now = 1;
			repr(i, k.size()-1, 0)
			{
				rep(j, 0, 10)
				{
					rep(ii, 0, d)
					{
						dp1[((j*now)%d + ii)%d] += dp1old[ii];
						dp1[((j*now)%d + ii)%d] %= mod;
					}
				}
				vll dpnew(d);
				rep(ii, 0, d)
				{
					ll val = k[i] - '0';
					dpnew[((val*now)%d + ii)%d] += dp[ii];
					dpnew[((val*now)%d + ii)%d] %= mod;
				}
				rep(j, 0, k[i]-'0')
				{
					rep(ii, 0, d)
					{
						dpnew[((j*now)%d + ii)%d] += dp1old[ii];
						dpnew[((j*now)%d + ii)%d] %= mod;
					}
				}
				dp1old = dp1;
				dp = dpnew;
				dp1 = vector<ll> (d, 0);
			}
			cout << (dp[0]-1+mod)%mod << endl;
		}
		return 0;
	}


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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vi32> g(n);
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<vi32> color(n, vi32(11, 0));
  int q;
  cin >> q;
  vi32 v(q), d(q), c(q);
  rep(i, q) {
    cin >> v[i] >> d[i] >> c[i];
    v[i]--;
  }
  auto dfs = [&](auto dfs, int u, int d, int c) -> void {
    if (color[u][d] != 0) return;
    color[u][d] = c;
    if (d == 0) return;
    dfs(dfs, u, d - 1, c);
    for (auto v : g[u]) {
      dfs(dfs, v, d - 1, c);
    }
  };
  rrep(i, q) {
    dfs(dfs, v[i], d[i], c[i]);
  }
  rep(i, n) {
    int ans = 0;
    repc(j, 10) if (color[i][j] != 0) {
      ans = color[i][j];
      break;
    }
    cout << ans << '\n';
  }
}


Measured memory_bytes: 16248
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	points := make([]Point, n*2)
	g := make([][]int, n*2)
	match := make([]int, n*2)
	for i := 0; i < n*2; i++ {
		g[i] = make([]int, 0)
	}
	for i := 0; i < n*2; i++ {
		points[i].x = getNextInt(scanner)
		points[i].y = getNextInt(scanner)
		match[i] = -1
	}
	for r := 0; r < n; r++ {
		for b := n; b < n*2; b++ {
			if points[r].x < points[b].x && points[r].y < points[b].y {
				g[r] = append(g[r], b)
				g[b] = append(g[b], r)
			}
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		if match[i] == 1 {
			continue
		}
		used := make([]int, n*2)
		if dfs(g, match, used, i) == true {
			ans++
		}
	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}

// Point ...
type Point struct {
	x, y int
}

func dfs(g [][]int, match []int, used []int, v int) bool {
	used[v] = 1
	l := len(g[v])
	for i := 0; i < l; i++ {
		u := g[v][i]
		w := match[u]
		if w >= 0 {
			if used[w] == 1 {
				continue
			}
			if dfs(g, match, used, w) == false {
				continue
			}
		}
		match[v] = u
		match[u] = v
		return true
	}

	return false
}


Measured memory_bytes: 896
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    Int N;
    cin >>N;
    int ans = 0;
    REP(i,1,10){
        N-= 111;
        if(N<=0){
            ans = i*100+i*10+i;
            break;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define N 8
#define FREE 1
#define NOT_FREE -1

bool Q[N][N];
int row[N];
int col[N];
int dpos[2*N-1];
int dneg[2*N-1];


void putQueen(int);
void printBoard(void);

void printBoard(){
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(Q[i][j] && row[i] != j) return;
    }
  }

  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(row[i] == j) cout << 'Q';
      else cout << '.';
    }
    cout << endl;
  }
}

void putQueen(int i){
  if(i == N){
    printBoard();
    return;
  }
  for(int j = 0; j < N; j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE){
      continue;
    }
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    putQueen(i+1);
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}
signed main(){
  int k,r,c;

  for(int i = 0; i < N; i++){
    row[i] = col[i] = FREE;
  }

  for(int i = 0; i < 2*N-1; i++){
    dpos[i] = dneg[i] = FREE;
  }

  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      Q[i][j] = false;
    }
  }

  cin >> k;
  for(int i = 0; i < k; i++){
    cin >> r >> c;
    Q[r][c] = true;
  }

  putQueen(0);
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
    #define N 231080
    #define ll long long
    #define For(i,x,y) for(int i=(x);i<=(y);++i)
    #define Rof(i,x,y) for(int i=(x);i>=(y);--i)
    #define Edge(x) for(int i=head[x];i;i=e[i].nxt)
    #define pii pair<ll,ll>
    #define mp make_pair
    #define fr first
    #define sd second
    #define mcpy(x,y) memcpy(x,y,sizeof(x))
    #define mset(x,y) memset(x,y,sizeof(x))
    using namespace std;
    int n,cnt[N];
    ll mn[N];
    vector<pii> a[N];
    vector<int> g[N];
    bool cmp1(const pii &x,const pii &y){ return x.fr<y.fr; }
    bool cmp2(const pii &x,const pii &y){ return x.sd<y.sd; }
    struct ed{ int v,w; }ch[N][2];
    void merge(vector<pii> &c,vector<pii> &aa,vector<pii> &bb,ll val){
    	//if(aa.size()<bb.size()) aa.swap(bb);
    	sort(aa.begin(),aa.end(),cmp2);
    	sort(bb.begin(),bb.end(),cmp1);
    	int _a=(int)aa.size(),_b=(int)bb.size();
    	int p=_a-1;
    	mn[0]=aa[0].fr;
    	For(i,1,_a-1) mn[i]=min(mn[i-1],aa[i].fr);
    	For(i,0,_b-1){
    		while(p>=0 && aa[p].sd+bb[i].fr>val) p--;
    		if(p>=0) c.push_back(mp(mn[p],bb[i].sd));
    	}p=_a-1;
    	sort(aa.begin(),aa.end(),cmp1);
    	sort(bb.begin(),bb.end(),cmp2);
    	mn[0]=aa[0].sd;
    	For(i,1,_a-1) mn[i]=min(mn[i-1],aa[i].sd);
    	For(i,0,_b-1){
    		while(p>=0 && aa[p].fr+bb[i].sd>val) p--;
    		if(p>=0) c.push_back(mp(bb[i].fr,mn[p]));
    	}
    }
    void dfs(int x,ll val){
    	if(!a[x].empty()) a[x].clear();
    	if(!cnt[x]){ a[x].push_back(mp(0,0));return; }
    	for(auto to:g[x]) dfs(to,val);
    	vector<pii> &ls=a[ch[x][0].v];
    	vector<pii> &rs=a[ch[x][1].v];
    	For(i,0,(int)ls.size()-1)ls[i].fr+=ch[x][0].w,ls[i].sd+=ch[x][0].w;
    	For(i,0,(int)rs.size()-1) rs[i].fr+=ch[x][1].w,rs[i].sd+=ch[x][1].w;
    	if(ls.size()<rs.size()) swap(ls,rs);
    	merge(a[x],ls,rs,val);
    	a[ch[x][0].v].clear();
    	a[ch[x][1].v].clear();
    }
    bool check(ll x){
    	dfs(1,x);
    	if(a[1].size()==0) return 0;
    	return 1;
    }
    int main(){
    	int x,v;ll ans;
    	ll l=0,r=0;
    	scanf("%d",&n);
    	For(i,2,n) scanf("%d%d",&x,&v),ch[x][cnt[x]++]=(ed){i,v},g[x].push_back(i),r+=v;
    	ans=r;
    	while(l<=r){
    		ll mid=(l+r)>>1;
    		if(check(mid)) r=mid-1,ans=mid;
    		else l=mid+1;
    	}
    	printf("%lld\n",ans);
    }

Measured memory_bytes: 39032
function Main(input) {
    input = input.split("\n");
    const tmp = input[0].split(" ");
    const x = parseInt(tmp[0], 10);
    const n = parseInt(tmp[1], 10);
    if(n === 0){
        console.log(x);
        return;
    }
    const p_str = input[1].split(" ");
    let p = [];
    for(let i = 0;i < n ; i++){
        p[i] = parseInt(p_str[i], 10);
    }

    p.sort(
        function(a,b){
            return (a < b ? -1 : 1);
        }
    );
 
    for(let i = 0;i < 100 ; i++){
        if( p.indexOf(x - i) === -1 ){
            console.log(x - i);
            return;
        }
        if( p.indexOf(x + i) === -1 ){
            console.log(x + i);
            return;
        }
             
    }
   

}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29504
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  ll X,K,D,m;
  cin>>X>>K>>D;
  ll f = abs(X)/X;
  if(abs(X)>abs(K*D)){cout << abs(X)-abs(K*D) << endl; return 0;}
  m = abs(X%D);
  K -= (X/D);
  if(K%2==0){ cout << m << endl;}
  else{cout << D-m << endl;}
}

Measured memory_bytes: 3628
import java.util.*;
import java.math.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}
class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		while(in.hasNext()){
			String s = in.next();
			if(s.equals(".")) return;
			System.out.println(calc(s, false));
		}
	}

	String calc(String s, boolean isrev){
		StringBuilder ret = new StringBuilder();

		int r = 0;
		char c = 'A';
		for(int i = 0; i < s.length(); i++){
			if(s.charAt(i) == '['){
				int k = i+1, rank = 1;
				while(rank>0){
					//if(k>=s.length()) break;
					if(s.charAt(k)=='[') rank++;
					else if(s.charAt(k)==']') rank--;
					k++;
				}
				//System.out.println("OK");
				ret.append(calc(s.substring(i + 1, k), true));
				i=k-1;
			}
			else if(s.charAt(i)==']') continue;
			else if(s.charAt(i)=='+') r++;
			else if(s.charAt(i)=='-') r--;
			else{
				if(s.charAt(i)=='?') c='A';
				else c = (char)('A'+(s.charAt(i)-'A'+r+26*100)%26);
				r = 0;
				ret.append(c);
			}
		}

		if(isrev) ret.reverse();
		return ret.toString();
	}
	
}

// while(in.hasNext()){
		// 	int n = in.nextInt();
		// 	if(n == 0) return;
			
		// }

Measured memory_bytes: 28052
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		doIt();
	}
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int k = 0; k < n; k++){
			int year = sc.nextInt();
			int month = sc.nextInt();
			int day = sc.nextInt();
			System.out.println(days(1000,1,1) - days(year,month,day));	
		}
	}
	
	public static int days(int year, int month, int day){
		int ret = 0;
		int y = 1;
		int m = 1;
		while(y < year){
			if(y % 3 != 0) ret += 19*5 + 20*5;
			else ret += 20*10;
			y++;
		}
		boolean bBig = false;
		if(year % 3 == 0) bBig = true;
		while(m < month){
			if(bBig) ret += 20;
			else
				if(m % 2 == 0) ret += 19;
				else ret += 20;
			m++;
		}	
		return ret + day;
	}
}

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

int main(){
    int N;  cin >> N;
    vector<int> a(N,0), pos(N+1,0);
    for(int i=0; i<N; i++){
        cin >> a[i];
        pos[a[i]] = i;
    }

    ll ans = 0;
    set<int> st;
    st.insert(-1);
    st.insert(N);
    for(ll i=1; i<=N; i++){
        auto itr = st.lower_bound(pos[i]);
        ll right = *itr;
        itr--;
        ll left = *itr;
        ans += i*(right-pos[i])*(pos[i]-left);
        st.insert(pos[i]);
    }
    cout << ans << endl;
}


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

using namespace std;
typedef long long int ll;
int main(){
	ll x;
	cin >> x;
	ll s = 100;
	int c = 0;
	while(s < x){
		s+=s/100;
		c++;
	}
	cout << c << "\n";
	return 0;
}


Measured memory_bytes: 3588
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dp = {}
    ans = 0
    for _ in range(N):
        str = ''.join(sorted(input().rstrip()))
        if str in dp:
            ans += dp[str]
            dp[str] += 1
        else:
            dp[str] = 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 18236
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,a;
	cin>>h>>a;
	cout<<ceil((double)h/a)<<endl;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()
A = INT()
B = INT()

print((X-A)%B)



Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;

int main(){
  int n,m;
  cin >> n >> m;
  
  vector<int> foodlike_amount(m, 0);
  for(int i = 0; i < n; i++){
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      int likenum;
      cin >> likenum;
      foodlike_amount[likenum - 1]++;
    }
  }
  
  int count = 0;
  for(int i = 0; i < m; i++){
    if(foodlike_amount[i] == n)
      count++;
  }
  cout << count << endl;
}

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

public class Solution
{
    public static void Main()
    {
        var s = Console.ReadLine();

        var list = new HashSet<char>();

        foreach (var c in s)
        {
            if (list.Contains(c))
            {
                Console.WriteLine("no");
                return;
            }
            list.Add(c);
        }
        Console.WriteLine("yes");
    }
}

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

int main() {
	int D;
	cin >> D;
	cout << "Christmas";
	while (++D <= 25) cout << " Eve";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

やるだけ
*/

Measured memory_bytes: 256
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
  		int[] p=new int[n];
    for(int c=0;c<n;c++){
    p[c]=sc.nextInt();
    }
  
    int ans=0;
    int c=p[0];
  
  for(int d=0; d<n-1; d++){
     if(c<p[d+1]){
       ans++; 
     }
    c=Math.min(c,p[d+1]);
    }
     
  
    System.out.println(n-ans);
    
    
   
    }
}

Measured memory_bytes: 66104
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto dn = readln.chomp.split.to!(int[]);
  if (dn[1] == 100) {
    dn[1]++;
  }
  auto a = 100 ^^ dn[0] * dn[1];
  writeln(a);
}


Measured memory_bytes: 256
# N, M = [int(_) for _ in input().split()]
N = int(input())
count = {"AC": 0, "WA": 0, "TLE": 0, "RE":0}
for i in range(N):
  S = input()
  count[S] += 1

print("AC x", count["AC"])
print("WA x", count["WA"])
print("TLE x", count["TLE"])
print("RE x", count["RE"])


Measured memory_bytes: 69860
#include <vector>
#include <stack>
using namespace std;

class scc {
public:
    scc(const vector<vector<int>> &edges) {
        V = edges.size();
        E.resize(V);
        rE.resize(V);
        for(int from = 0; from < V; ++from) {
            for(int to : edges[from]) {
                E[from].push_back(to);
                rE[to].push_back(from);
            }
        }
    }

    int build() {
        order.resize(V);
        used.resize(V, false);

        for(int i = 0; i < V; ++i) {
            if(!used[i]) dfs(i);
        }

        used.assign(V, false);
        int sccnum = 0;
        while(!number.empty()) {
            int cur = number.top();
            number.pop();
            if(!used[cur]) rdfs(cur, sccnum++);
        }

        return sccnum;
    }

    int operator[](int v) {
        return order[v];
    }

private:
    int V;
    vector<vector<int>> E;
    vector<vector<int>> rE;
    vector<int> order;
    vector<bool> used;
    stack<int> number;

    void dfs(int v) {
        used[v] = true;
        for(int to : E[v]) {
            if(!used[to]) dfs(to);
        }
        number.push(v);
    }

    void rdfs(int v, int k) {
        used[v] = true;
        order[v] = k;
        for(int to : rE[v]) {
            if(!used[to]) rdfs(to, k);
        }
    }
};


#include <iostream>
int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<int>> edges(V);
    while(E--) {
        int s, t;
        cin >> s >> t;
        edges[s].push_back(t);
    }

    scc comp(edges);
    comp.build();
    
    int Q;
    cin >> Q;
    while(Q--) {
        int u, v;
        cin >> u >> v;
        cout << (comp[u] == comp[v] ? 1 : 0) << endl;
    }
}


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

using namespace std;

const int N=1e5+5;

int n,u,v;
vector<int> adj[N];
int f[N],mxdp;
int hi[N],pp[N][20],dep[N];


bool dfs(int x,int pa)
{
	pp[x][0]=pa;
	for(int i=1;i<20;i++)
		pp[x][i]=pp[pp[x][i-1]][i-1];
	dep[x]=1;
	f[x]=(x==u);
	for(int i:adj[x])
	{
		if(i==pa)continue;
		hi[i]=hi[x]+1;
		f[x]|=dfs(i,x);
		dep[x]=max(dep[x],1+dep[i]);
	}
	mxdp=max(mxdp,dep[x]);
	return f[x];
}

int ispa(int x,int y)
{
	if(hi[x]<hi[y])
		swap(x,y);
	for(int i=19;i>=0;i--)
	{
		if(hi[x]-(1<<i)>=hi[y])
		{
			x=pp[x][i];
		}
	}
	if(x==y) return 1;
	return 0;
}

int main()
{
	cin >> n >> u >> v;
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(v,0);
	int ans=0;
	while(u!=v)
	{
		//cout << u << " " << v << endl;
		int mx=0,to=pp[u][0];
		for(int i:adj[u])
		{
			if(i==pp[u][0]) continue;
			if(dep[i]>mx)
			{
				mx=dep[i]; to=i;
			}
		}
		if(mx!=mxdp&&pp[u][0]!=v&&pp[pp[u][0]][0]!=v)
			u=pp[u][0];
		else
			u=to;

		if(u==v) break;
		ans++;
		for(int i:adj[v])
		{
			if(i==pp[v][0]) continue;
			if(ispa(u,i))
			{
				v=i; break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 19840
#include <iostream>
using namespace std;
typedef long long hyper;

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

int main() {
  hyper a, b;
  cin >> a >> b;
  hyper g = gcd(a, b);
  hyper ans = 0;
  for (hyper i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      while (g % i == 0) {
        g /= i;
      }
      ans++;
    }
  }
  if (g != 1) {
    ans++;
  }
  ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define itn int
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int n,m;
struct edge{int from,to,dir,st;};//st:spanning treeに用いられる辺
edge e[100010];
int dist[100010];
int deg[100010];
vector<int> list_d[100010];
int par[100010];
map<pair<int,int>,int> get_e;
vector<int > g[100010];
void dfs(int x,int d){
    dist[x] = d;
    list_d[d].pb(x);
    for(int i : g[x]){
        edge& ed = e[i];
        if(ed.from == x){
            if(dist[ed.to] == -1){
                ed.st = 1;
                par[ed.to] = x;
                dfs(ed.to,d + 1);
            }
        }else{
            if(dist[ed.from] == -1){
                ed.st = 1;
                par[ed.from] = x;
                dfs(ed.from,d + 1);
            }
        }
    }
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    
    cin >> n >> m;
    fill(dist,dist + n,-1);
    rep(i,m){
        int f,t;cin >> f >> t;
        e[i] = (edge){--f,--t,0,0};
        g[f].pb(i);
        g[t].pb(i);
        get_e[mp(f,t)] = i;
        get_e[mp(t,f)] = i;
    }
    //spanning tree
    dfs(0,0);
    rep(i,m){
        if(!e[i].st){
            deg[e[i].from]++;
        }
    }
    for(int d = n;d >= 0;d--){
        if(list_d[d].size() == 0)continue;
        if(d == 0){
            if(deg[0]%2 == 1){
                cout << -1 << '\n';
                return 0;
            }
            break;
        }
        for(auto i : list_d[d]){
            if(deg[i] %2 == 0){
                int p = par[i];
                //p -> i
                int id = get_e[mp(i,p)];
                e[id].dir = !(e[id].from == p);
                deg[p]++;
            }else{
                int p = par[i];
                int id = get_e[mp(i,p)];
                e[id].dir = (e[id].from == p);
                deg[i]++;
            }
        }
    }
    rep(i,m){
        if(e[i].dir == 0)cout << 1 + e[i].from << ' ' << 1 + e[i].to << '\n';
        else cout << 1 + e[i].to << ' ' << 1 + e[i].from << '\n';
    }
    return 0;
}


Measured memory_bytes: 32256
#include<bits/stdc++.h>
#define N 100005
#define int long long
using namespace std;

inline void rd(int &X){
    X=0;int w=0;char ch=0;
    while(!isdigit(ch))w|=ch=='-',ch=getchar();
    while( isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    X=w?-X:X;
}
int n,m,k;
int x[N],d[N],ans[N],t[N];
double a[N];

signed main()
{
    rd(n);
    for(int i=1;i<=n;i++)
        rd(x[i]),d[i]=i,ans[i]=i;
    rd(m);rd(k);
    for(int x,i=1;i<=m;i++)
        rd(x),swap(d[x],d[x+1]);
        while(k)
        {
            if(k&1)
            {
                for(int i=1;i<=n;++i)t[i]=ans[d[i]];
                for(int i=1;i<=n;++i)ans[i]=t[i];
            }
            for(int i=1;i<=n;++i)t[i]=d[d[i]];
            for(int i=1;i<=n;++i)d[i]=t[i];
            k>>=1;
        }
    for(int i=1;i<=n;i++)
        a[i]=x[ans[i]]-x[ans[i]-1];
    for(int i=1;i<=n;i++)
        printf("%.1f\n",a[i]+=a[i-1]);
}


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

int main() {
  int k,x;
  cin >> k >> x;
  int S=500*k;
  if (S>=x)cout << "Yes"<< endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (3010)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c) {
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
vector<int> G[N];
int n,a[N];
bool dfs(int u,int pre){
	for(int i=0;i<G[u].size();i++)
	if(G[u][i]!=pre&&a[u]>a[G[u][i]])
	if(dfs(G[u][i],u)==0)return 1; return 0;
} 
int main(){
	read(n); for(int i=1;i<=n;i++)read(a[i]);
	for(int i=1,x,y;i<n;i++)read(x),read(y),G[x].push_back(y),G[y].push_back(x); 
	for(int i=1;i<=n;i++)if(dfs(i,0))printf("%d ",i);
}

Measured memory_bytes: 2432