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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    string s,ans="NO";
    cin>>s;
    char sp[s.size()];
    for (int i = 0; i < s.size(); i++)sp[i]=s[i];
    if(s.size()>9)ans="NO";
    else if(strstr(sp,"KIHABAR")!=NULL||(strstr(sp,"KIHBAR")!=NULL&&s.size()<=8)||(strstr(sp,"KIHABR")!=NULL&&s.size()<=8)||(strstr(sp,"KIHBR")!=NULL&&s.size()<=7)){
        if(((sp[0]=='A'&&sp[1]=='K')||(sp[0]=='K'&&sp[1]=='I'))&&((sp[s.size()-1]=='R'&&(sp[s.size()-2]=='A'||sp[s.size()-2]=='B'))||(sp[s.size()-1]=='A'&&sp[s.size()-2]=='R')))ans="YES";
    }
    cout<<ans<<'\n';
}

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

int main()
{
    string s,t;
    cin>>s;
    cin>>t;
    int c=0;
    int l=s.size();
    for(int i=0;i<l;i++)
    {
        if(s[i]!=t[i])
        {
            c++;
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n, x;
  cin >> n;
  vector<int> b;
  rep(i, n) {
    cin >> x;
    x--;
    b.push_back(x);
  }
  int now, c;
  while(true){
    if(now == 1) {
      cout << c << endl;
      break;
    }
    if(c >= n){
      cout << -1 << endl;
      break;
    }
    now = b[now];
    c++;
  }
}


Measured memory_bytes: 3872
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    cout << max((ll)0, min(B, D) - max(A, C)) << endl;
    
    return 0;
}

Measured memory_bytes: 3512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll smod=998244353;
const ll INF = INT64_MAX;
typedef tuple<ll,ll,ll,ll> T;





ll i,j,k;


int main(){
  //オーバーフローに注意！
  int K;
  cin>>K;
  string S;
  cin>>S;
  if(S.length()<=K)cout<<S<<endl;
  else{
    rep(i,K)cout<<S[i];
    cout<<"...";
    cout<<endl;
  }

  

 
  
  
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    Int n, m;
    cin >> n >> m;
    vector<pair<Int, Int>> ab(n);
    for (int i = 0; i < n; i++) {
        cin >> ab[i].first >> ab[i].second;
    }

    sort(ab.begin(), ab.end());

    Int ans = 0, count = 0;
    for (int i = 0; i < n; i++) {
        if (ab[i].second + count < m) {
            count += ab[i].second;
            ans += ab[i].first * ab[i].second;
            continue;
        }

        ans += (m - count) * ab[i].first;
        break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC138_b solver = new ABC138_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC138_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            double Adash = 0;
            int i = 0;
            for (i = 0; i < N; i++) {
                double work = 1 / in.nextDouble();
                Adash += work;
            }
            out.println(1 / Adash);

//        int[] A = new int[N];

        }

    }
}



Measured memory_bytes: 23252
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    
    if temp != 1:
        arr.append([temp, 1])
    if not arr:
        arr.append([n, 1])
    
    return arr


def solve():
    N = int(rl())
    MOD = 10 ** 9 + 7
    
    counter = defaultdict(int)
    for i in range(2, N + 1):
        facts = factorization(i)
        for j, cnt in facts:
            counter[j] += cnt
    
    ans = 1
    for val in counter.values():
        ans = ans * (val + 1) % MOD
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 41708
#define MYDEBUG
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
#include <unordered_map>

#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	out << "[";
	size_t last = v.size() - 1;
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i];
		if (i != last)
			out << ",";
	}
	out << "]";
	return out;
}

int main() {
	int n;
	cin >> n;
	int mod = 1000000007;
	int MAXN = 1100;
	//素数リストisprime[]をつくる
	int isprime[MAXN] = { }; //1から1000までが素数か格納
	isprime[0] = isprime[1] = 1;
	for (int i = 2; i < MAXN; ++i) {
		//iの倍数を全部消す
		for (int j = i + i; j < MAXN; j = j + i) {
			isprime[j] = 1; //素数じゃない
		}
	}
	int ans = 1;
	//iが1からnまで
	for (int i = 2; i <= n; ++i) {
		//iが素数なら
		if (isprime[i] == 0) {
			//n!の中で素因数iは何乗か？
			int tot = 0;
			for (int j = i; j <= n; j *= i) { //2,4,8...
				tot += n / j; //12/2 + 12/4 + 12/8
			}
			//約数の個数*(tot+1)%modで更新
			ans = 1ll * ans * (tot + 1) % mod;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
"use strict";

function Main(input) {
	let num500 = input.split(' ')[0]*1;
  	let price = input.split(' ')[1]*1;
  	let ans = num500*500 >= price? "Yes" : "No";
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    dchar[] s;
    scan(s);
    s.sort();

    if (s == "abc") {
        writeln("Yes");
    }
    else {
        writeln("No");
    }
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int main() {
  double D, E;
  while (cin >> D >> E) {
    if (D == 0 && E == 0)
      break;
    double ans = 100000000000000;
    for (int i = 0; i < D; i++) {
      ans = min(ans, abs(pow(pow(i, 2) + pow(D - i, 2), 0.5) - E));
    }
    cout << shosu(12) << ans << endl;
  }
  return 0;
}

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

using namespace std;

const int number[] = { 0,2,5,5,4,5,6,3,7,6 };

int main() {
	int N, M;

	cin >> N >> M;

	vector<int> A(M);
	for (int i = 0; i < M; i++) {
		cin >> A[i];
	}

	//最大何桁作れるか
	vector<int> DP(N + 1, -100000000);
	DP[0] = 0;
	for (int i = 2; i <= N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			if (i - number[A[j]] >= 0) {
				DP[i] = max(DP[i], DP[i - number[A[j]]] + 1);
			}
		}
	}

	sort(A.begin(), A.end(), greater<int>());
	//最上位桁から降順に数字を選んでいく
	int sticks = N, digits = DP[N];
	string ans = "";
	while (digits > 1) {
		for (int i = 0; i < M; i++) {
			if (sticks - number[A[i]] >= 0 && DP[sticks - number[A[i]]] == digits - 1) {
				digits--;
				sticks -= number[A[i]];
				ans += A[i] + '0';
				break;
			}
		}
	}

	//最後の桁はちょうどマッチを使い切るように選ぶ
	for (int i = 0; i < M; i++) {
		if (sticks - number[A[i]] == 0) {
			ans += A[i] + '0';
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int ar1[50],ar2[50];
bool compare(int a[50],int b[50])
{
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i]) return false;

    }
    return true;
}
int main()
{

    cin>>n;

    for(int i=0;i<n;i++)
    {
        cin>>ar1[i];
        ar2[i]=ar1[i];
    }
    sort(ar2,ar2+n);
    if(compare(ar1,ar2)==true)
    {
          cout<<"YES"<<endl;
                    return 0;
    }
    else{
         for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            swap(ar1[i],ar1[j]);
            if(compare(ar1,ar2)==true) {
                    cout<<"YES"<<endl;
                    return 0;
            }
            else swap(ar1[i],ar1[j]);
        }
    }
    }

    cout<<"NO"<<endl;
    return 0;

}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/04  Problem: Nagoya_univ_contest_17_c  / Link: https://abc074.contest.atcoder.jp/tasks/abc074_b  ----- */
/* ------問題------

xy 平面上に N 個のボールがあります。このうち i 番目のボールの位置は (xi,i) です。 したがって、N 本の直線 y=1, y=2, …, y=N の上にそれぞれ 1 個ずつボールがあることになります。
すぬけ君は、これらのボールを回収するために、タイプ A, B のロボットを N 台ずつ用意しました。 さらに、タイプ A のロボットのうち i 台目のものを位置 (0,i) に、タイプ B のロボットのうち i 台目のものを位置 (K,i) に設置しました。 したがって、N 本の直線 y=1, y=2, …, y=N の上にそれぞれ 1 台のタイプ A のロボットと、1 台のタイプ B のロボットが設置されたことになります。
それぞれのタイプのロボットは起動されると以下のように動作します。
タイプ A のロボットは、位置 (0,a) で起動されると、直線 y=a 上にあるボールの位置まで移動し、ボールを回収してもとの位置 (0,a) に戻って停止する。そのようなボールが存在しない場合は何もせずに停止する。
タイプ B のロボットは、位置 (K,b) で起動されると、直線 y=b 上にあるボールの位置まで移動し、ボールを回収してもとの位置 (K,b) に戻って停止する。そのようなボールが存在しない場合は何もせずに停止する。
これら 2N 台のロボットのうちいくつかを起動してボールをすべて回収するとき、ロボットの移動距離の総和として考えられる値のうち最小のものを求めてください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N,K;

LL ans = 0LL;

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

	cin >> N>>K;
	FOR(i, 0, N) {
		int x; cin >> x;
		ans += min((int)abs(K-x),(int)x);
	}
	ans *= 2;
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}

int main() {
    string t;
    cin >> t;
    for(int i=2;i<t.size();i++){
        if(t.at(i-2)==t.at(i-1)&&t.at(i-1)==t.at(i)){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}
    



Measured memory_bytes: 3588
//#pragma GCC optimise("Ofast,unroll-loops,no-stack-protector,fast-math");
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")
          
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
          
using namespace std;
using namespace __gnu_pbds;
          
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
          
using matrix = vector<vector<ll>>;
template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
          
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
//#define int long long
 
void FAST_IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifndef _offline
    //freopen("chess.in", "r", stdin);
    //freopen("chess.out", "w", stdout);
    #endif
}

const int MAXN = 2e5 + 100;
int p[MAXN], mn[MAXN], mx[MAXN];
bool d[MAXN];

signed main() {
    FAST_IO();
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    set<int> setik;
    for (int i = 0; i < k; ++i) {
        setik.insert(p[i]);
    }
    for (int i = k - 1; i < n; ++i) {
        mn[i] = *setik.begin();
        setik.erase(p[i - k + 1]);
        if (i != n - 1) {
            setik.insert(p[i + 1]);
        }
    }
    setik.clear();
    for (int i = 0; i < k; ++i) {
        setik.insert(-p[i]);
    }
    for (int i = k - 1; i < n; ++i) {
        mx[i] = -(*setik.begin());
        setik.erase(-p[i - k + 1]);
        if (i != n - 1) {
            setik.insert(-p[i + 1]);
        }
    }
    int st = 0;
    for (int i = 1; i <= n; ++i) {
        if (i == n || p[i] < p[i - 1]) {
            int len = i - st;
            for (int j = st; j <= st + len - k; ++j) {
                d[j] = true;
            }
            st = i;
        }
    }
    int ans = 1;
    int kek = (d[0] ? 0 : -1);
    for (int i = 1; i <= n - k; ++i) {
        ans++;
        if (mn[i + k - 2] == p[i - 1] && mx[i + k - 1] == p[i + k - 1]) {
            ans--;
        }
        else if (d[i] && kek != -1 && kek + k - 1 < i) {
            ans--;
        }
        if (d[i] && kek == -1) {
            kek = i;
        }
    }
    cout << ans << '\n';
} 

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			if (h == 0 || w == 0) {
				sc.close();
				break;
			}
			printRectangle(h, w);
			System.out.println();
		}
	}
	
	public static void printRectangle(int h, int w) {
		char[] row = new char[w];
		Arrays.fill(row, '#');
		for (int i = 0; i < h; i++) {
			System.out.println(row);
		}
	}
}

Measured memory_bytes: 27292
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> l;
  l = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};
  vector<int> m;
  m.assign(1000000,0);
  for (int i = 0; i < n; i++) {
    int ai;
    cin >> ai;
    for (int j=0;j<168;j++){
      int li = l.at(j);
      if (ai%li == 0){
        m.at(li) += 1;
        while(ai%li==0){
          ai = ai/li;
        }
      }
    }
    if (ai > 1){
      m[ai] += 1;
    }
  }
  int mm = 0;
  for(int i=0;i<1000000;i++){
    if (mm < m.at(i)){
      mm = m.at(i);
    }
  }
  if (mm==n){
    cout << "not coprime" << endl;
  }else if (mm > 1){
    cout << "setwise coprime" << endl;
  }else{
    cout << "pairwise coprime" << endl;
  }
}

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

int main(){

    int n;
    cin>>n;
    vector<int> a(n);
    bool check=true;
    for(int i=0;i<n;i++){

        cin>>a.at(i);
        if(a.at(i)%2==0){

            if(!(a.at(i)%3==0 || a.at(i)%5==0)) check=false;
        }

    }

    if(check) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define rep(n) REP(i,n)


int main()
{
	int a,b; 

	while(cin>>a>>b)
	{
		int sum=a+b;
		int d=0;

		while(sum){ d++; sum/=10; }

		cout<<d<<endl;
	}

	return 0;
}

Measured memory_bytes: 1160
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll K;
    cin>>K;
    vector<vector<pair<ll,ll>>> G(K+1);

    REP(i,K+1){
        G[i].push_back(make_pair(1,(i+1)%K));
        if(i>=1) G[i].push_back(make_pair(0,(i*10)%K));
    }

    //ダイクストラ O(ElogV)
    // データ構造
    vector<ll> dist(K, INF); // 全頂点を「未訪問」に初期化
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> que;
    
    // 初期条件 (頂点 1を初期ノードとする)
    dist[1] = 0;
    que.push(make_pair(0,1));//1をスタート位置
    
     // 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        pair<ll,ll> p = que.top();
        que.pop();
        ll d=p.first;
        ll v=p.second;
        if(dist[v]<d) continue;
        for (auto nv : G[v]) {
            ll nd=d+nv.first;
    
            // 新たな頂点 nv について距離が短いなら更新
            if(nd<dist[nv.second]){
                dist[nv.second] = nd;
                que.push(make_pair(nd,nv.second));
            }
        }
    }
    cout<<dist[0]+1<<endl;

}

Measured memory_bytes: 12140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,N,first,mostdist=0,num1,num2;
  cin >> K >> N;
  cin >> first;
  num1 = first;
  for(int i=0;i < N-1;i++){
    cin >> num2;
    if((num2 - num1) > mostdist){
      mostdist = num2 - num1;
    }
    num1 = num2;
  }
  
  if(K - num2 + first > mostdist){
      mostdist = K - num2 + first;
  }
  cout << K - mostdist;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]


N, Q = map(int, input().split())

tree = {}
for i in range(1, N + 1):
    tree[i] = []
for i in range(N - 1):
    a, b = map(int, input().split())
    tree[a] += [b]

count = [0] * (N + 1)
for i in range(Q):
    p, x = map(int, input().split())
    count[p] += x

stack = [1]
while stack:
    label = stack.pop()
    if tree[label] != []:
        for next_label in tree[label]:
            count[next_label] += count[label]
        stack += tree[label]
ans = count[1:]

print(*ans)


Measured memory_bytes: 66528
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    int n,mm;
    cin >> n;
    vector< pair<int,int> > h(n);
    REP(i,n){
	cin >> h[i].first >> h[i].second;
    }
    int pn = n;
    cin >> n;
    REP(i,n){
	h.PB(pair<int,int>(0,0));
	cin >> h[i+pn].first >> h[i+pn].second;
    }
    sort(ALL(h));
    h.erase(unique(ALL(h)),h.end());
    vector<string> ans;
    REP(i,h.size()){
	string s = "";
	s += to_string(h[i].first);
	s += ":";
	if(h[i].second >= 10) s += to_string(h[i].second);
	else s += "0" + to_string(h[i].second);
	ans.PB(s);
    }
    cout << ans[0];
    FOR(i,1,h.size()){
	cout << " " << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

const ll inf=1e9+7;

ll mult(ll n,ll m){//n^m%infを求める
    if(m==1){
        return n%inf;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%inf;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%inf;
    }
}

typedef pair<int,int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    //先頭からx文字目までに何個の'AC'が存在するかを計算
    vector<int> sum(len(s),0);
    rep(i,len(s)-1){
        if(s[i]=='A' && s[i+1]=='C'){
            sum[i+1]=sum[i]+1;
        }else{
            sum[i+1]=sum[i];
        }
    }
    rep(i,q){
        int l,r;
        cin>>l>>r;
        cout<<sum[r-1]-sum[l-1]<<'\n';
    }
}

Measured memory_bytes: 1488
s_str = input()
t_str = input()
s = [s_str[i] for i in range(len(s_str))]
t = [t_str[i] for i in range(len(t_str))]
s.sort()
t.sort(reverse=True)
for i in range(min(len(s), len(t))):
    if s[i] > t[i]:
        print('No')
        exit()
    elif s[i] < t[i]:
        print('Yes')
        exit()
if len(s) < len(t):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <stdio.h>

main(){
  int a, b;
  int c;
  int ans;

  while(1){
    if(scanf("%d %d", &a, &b)==EOF) break;
    c=a+b;
    ans=1;
    while(1){
      if((c/10)<1) break;
      else{
	ans++;
	c/=10;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <queue>
#include <stack>
#include <cstring>
#include <ctime>
#include <cassert>


#define pb emplace_back
#define re return
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265359;


ll x, n;
pair <int, int> a[1000];
ll dp[10050];
ll solve(ll h)
{
    if (h <= 0)
        re 0;
    if (dp[h] != -1)
        re dp[h];
    ll ans = 1e18;
    for (int i = 0; i < n; i++)
        ans = min(ans, a[i].se + solve(h - a[i].fi));
    dp[h] = ans;
    re ans;
}
int main()
{
    //freopen("distance.in", "r", stdin);
    //freopen("distance.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> x >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i].fi >> a[i].se;
    memset(dp, -1, sizeof(dp));
    cout << solve(x);
}
/// ACTUAL CODE STARTS HERE:
//  I'm red in soul
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


Measured memory_bytes: 768
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(X: int):
    ans = 0
    ans += (X // 500)*1000
    X = X % 500
    ans += (X//5)*5
    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;
vector<int64_t> dp(100010);

int main() {
  int N;cin>>N;
  vector<int64_t> h(100010);
  for(int i=0;i<N;i++){
    cin>>h[i];
  }
  for(int i=0;i<100010;i++){
    dp[i]=INF;
  }
  
  dp[0]=0;
 
  for(int i=1;i<N;i++){
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
    if(i>1){chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));}
  }

 // for(int i=0;i<N;i++){
   // cout<<dp[i]<<" ";
  //}
  cout<<dp[N-1]<<endl;
  return 0;}

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

int main(){
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];

    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);

    for(int i=2;i<n;i++){
        dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
        dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
    }

    cout<<dp[n-1]<<endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <stack>
#include <math.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int, int> pii;
int main(){
int a,b;
cin>>a>>b;
if(2*b>=a){
  cout << 0<<endl;
  return 0;
}
cout << a-2*b<<endl;
return 0;









}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
  int n,l;
  cin>>n>>l;
  vector<string> s(n);
  int i=0;
  while(cin>>s[i])i++;
  //sort
  sort(s.begin(),s.end());
  i=0;
  for(auto i:s)cout<<i;
  cout<<"\n";
}

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

int main(){
  int N,i,j,c = 0,ch;
  int *A;

  scanf("%d",&N);
  A = (int *)malloc(sizeof(int) * N);
  for(i = 0;i < N;i++)
    scanf("%d",&A[i]);

  for(i = 0;i < N-1;i++)
    for(j = N-1;j > i;j--)
      if(A[j] < A[j-1]){
	ch = A[j];
	A[j] = A[j-1];
	A[j-1] = ch;
	c++;
      }

  for(i = 0;i < N;i++){
    printf("%d",A[i]);
    if(i < N-1)
      printf(" ");
  }
  printf("\n%d\n",c);
  
  free(A);
  return 0;
}



Measured memory_bytes: 2144
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

//The Two Men of the Japanese Alps
public class Main{

	int INF = 1<<29;
	Map<Integer, Double>[] map;
	
	double calc(double x1, double y1, double x2, double y2){
		return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		int[] xs = new int[100], ys = new int[100], y = new int[5000];
		double[] x = new double[5000];
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			Set<Integer> yset = new HashSet<Integer>();
			for(int i=0;i<n;i++){
				xs[i] = sc.nextInt();
				yset.add(ys[i]=sc.nextInt());
			}
			int[] Y = new int[yset.size()];
			int id = 0;
			for(int yy:yset)Y[id++]=yy;
			Arrays.sort(Y);
			id = 0;
			for(int i=0;i+1<n;i++){
				if(ys[i]==ys[i+1]){
					x[id] = xs[i];
					y[id++] = ys[i];
				}
				else if(ys[i]<ys[i+1]){
					for(int j=0;j<Y.length&&Y[j]<ys[i+1];j++){
						if(Y[j]<ys[i])continue;
						x[id] = (xs[i+1]-xs[i])*(Y[j]-ys[i]+0.)/(ys[i+1]-ys[i]) + xs[i];
						y[id++] = Y[j];
					}
				}
				else{
					for(int j=Y.length-1;j>=0&&Y[j]>ys[i+1];j--){
						if(Y[j]>ys[i])continue;
						x[id] = (xs[i+1]-xs[i])*(Y[j]-ys[i]+0.)/(ys[i+1]-ys[i]) + xs[i];
						y[id++] = Y[j];
					}
				}
			}
			x[id] = xs[n-1];
			y[id++] = 0;
			map = new Map[id];
			for(int i=0;i<id;i++)map[i]=new HashMap<Integer, Double>();
			map[0].put(id-1, 0.);
			PriorityQueue<int[]> q = new PriorityQueue<int[]>(id, new Comparator<int[]>() {
				public int compare(int[] o1, int[] o2) {
					return (int)Math.signum(map[o1[0]].get(o1[1]) - map[o2[0]].get(o2[1]));
				}
			});
			q.add(new int[]{0, id-1});
			double res = INF;
			while(!q.isEmpty()){
				int[] V = q.poll();
				int i = V[0], j = V[1];
				if(i==j){
					res = Math.min(res, map[i].get(j)); continue;
				}
				for(int di=-1;di<=1;di++){
					int ni = i+di;
					if(ni<0 || id<=ni)continue;
					for(int dj=-1;dj<=1;dj++){
						int nj = j+dj;
						if(nj<0 || id<=nj || nj < ni || y[ni]!=y[nj])continue;
						double w = map[i].get(j) + calc(x[i], y[i], x[ni], y[ni]) + calc(x[j], y[j], x[nj], y[nj]);
						if(!map[ni].containsKey(nj) || w < map[ni].get(nj)){
							map[ni].put(nj, w);
							q.add(new int[]{ni, nj});
						}
					}
				}
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 17000
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;

  if(a==b&&b==c){
    cout<<1<<endl;
  } else if( (a==b&&b!=c&&c!=a)||(a!=b&&b==c&&c!=a)||(a!=b&&b!=c&&c==a) ){
    cout<<2<<endl;
  } else {
    cout<<3<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
w, h, n = gets.split.map(&:to_i)
a = Array.new(n){gets.split.map(&:to_i)}
x0, y0, x1, y1 = 0, 0, w, h
n.times do |i|
  if a[i][2] == 1
    x0 = a[i][0] if x0 < a[i][0]
  elsif a[i][2] == 2
    x1 = a[i][0] if x1 > a[i][0]
  elsif a[i][2] == 3
    y0 = a[i][1] if y0 < a[i][1]
  elsif a[i][2] == 4
    y1 = a[i][1] if y1 > a[i][1]
  end
end
puts (x1 > x0 && y1 > y0 ? (x1 - x0) * (y1 - y0) : 0)

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

using namespace std;
typedef long long ll;

bool inline chmin(int &a, int b){ if( a > b){ swap(a,b); return true;} return false;}

vector<vector<int>> calcNext(const string &S){
  int n = S.size();
  vector<vector<int>> res(n+1,vector<int>(26,n));
  
  for(int i = n-1; i >= 0; i--){
    for(int j = 0; j < 26; j++){
      res[i][j] = res[i+1][j];
    }
    res[i][S[i]-'a'] = i;
  }
  
  return res;
}

int main(){ 
  string A; cin >> A;
  int n = A.size();
  
  vector<int> dp(n+1,n+1); //最短でも長さがn+1より短くなるということはない
  vector<pair<char,int>> recon(n+1,{'?',n});
  
  auto next = calcNext(A);
  
  for(int i = n-1; i >= 0; i--){
    for(int j = 0; j < 26; j++){
      
      if( next[i][j] == n){ //i以降で文字a+jが出ることはない
        
        if( dp[i] > 1){
          dp[i] = 1; recon[i] = {'a'+j,next[i][j]+1};
                             }
        }
        else if( chmin(dp[i], dp[next[i][j]+1]+1)){
          dp[i] = dp[next[i][j]+1]+1;
          recon[i] = {'a'+j,next[i][j]+1};
        }
      }
    }
    
    int index = 0;
    string res = "";
    while(index < n){
      auto p = recon[index];
      res += p.first;
      index = p.second;
    }
    
    cout << res << endl; return 0;
  }
          

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

int main(){
  int x;
  cin >> x;
  if (x == 0) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
ll a[10000000], d[10000000];

signed main() {

    ll i, j, k, l, n, b, c, test;
    cin >> n;
    k = 1;
    bool flag = 1;
    while (1) {
        if (k == n) {
            flag = 0;
            break;
        }
        if (k > n) break;
        k *= 2;
    }
    if (flag == 0) {
        cout << 2 * k - 1;
    }
    else {
        cout << k - 1;
    }
}

Measured memory_bytes: 256
L = [0] * 8
n = int(input())
A = list(map(int, input().split()))
t = 0


for i in A:
    if i < 3200:
        a = i//400
        L[a] += 1
    else:
        t += 1
 
c = 0
for i in L:
    if i!= 0:
        c += 1
max_num = max(c, 1)
min_num = c+t
print(max_num,min_num)

Measured memory_bytes: 38384
#include <stdio.h>

int main(void){
	int a, b, c;
	int n = 0;
	scanf("%d %d %d", &a, &b, &c);

	for (int i = a; i <= b; i++) {
		if (!(c % i)) n++;
	}
	
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 2692
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int calcAns(string s, string t) {
    int r = s.size() + 1;
    int c = t.size() + 1;

    int dp[r][c];
    rep(i, r)rep(j,c) dp[i][j] = 0;

    for(int i = 1; i < r; i++) {
        for(int j = 1; j < c; j++) {
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
        }
    }
    return dp[r-1][c-1];
}

int main(void)
{
    int q;
    cin >> q;

    rep(i, q) {
        string s, t;
        cin >> s >> t;
        int ans = calcAns(s, t);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 7028
import numpy as np

def convolve(a, b):
	n = 1
	n_a, n_b = len(a), len(b)
	while n < n_a + n_b - 1:
		n <<= 1
	A = np.fft.rfft(a, n)
	B = np.fft.rfft(b, n)

	C = A * B
	c = np.fft.irfft(C, n)
	c = np.rint(c).astype(np.int64)

	return c[:n_a + n_b - 1]

p = 200003
n = int(input())
b = list(map(int, input().split()))
a = [0 for _ in range(p-1)]
ref = [0 for _ in range(p)]
po = [0 for _ in range(p-1)]
y = 1
for i in range(p-1):
	ref[y] = i
	po[i] = y
	y = (y * 2) % p
ans = 0
for x in b:
	if x == 0:
		continue
	a[ref[x]] += 1
	ans -= (x*x) % p
conv = convolve(a, a)
for i in range(2*p-3):
	ans += po[i % (p-1)] * conv[i]
print(ans // 2)

Measured memory_bytes: 87384
#include<algorithm>
#include<vector>
 #include<cstring>
#include<string>
#include<iomanip>
#include<cstdio>
#include<stack>
#include<iostream>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
#define sf scanf
#define pf printf
#define mem(a,b) memset(a,b,sizeof(a));
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define mod 998244353
#define N 100020
#define M 400020
#define ULL unsigned long long
#define LL long long
#define inf 0x3f3f3f3f
map<ULL,LL>mp;
vector<int>g[N];
ULL dp[N];
LL ans;int n;
const ULL b=1000000007;
void dfs(int u,int fa){
    dp[u]=1;
    for(int i=0;i<g[u].size();++i){
        int v=g[u][i];
        if(v==fa)continue;
        dfs(v,u);
        dp[u]+=dp[v]*b;
    }
    ans+=mp[dp[u]];
    mp[dp[u]]++;
}
int main(){
    sf("%d",&n);
        ans=0;
        rep(i,1,n-1){
            int u,v;sf("%d%d",&u,&v);
            g[u].push_back(v);g[v].push_back(u);
        }
        dfs(1,1);
        cout<<ans<<'\n';
}

Measured memory_bytes: 23528
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int dx[16] = {1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1};
int dy[16] = {0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1};
template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    vector<ll> x(N),y(N),w(N);
    map<pll,ll> mp;
    for(int i = 0; i < N;i++){
        cin >> x[i] >> y[i] >> w[i];
        mp[pll(x[i],y[i])] += w[i];
    }
    for(int i = 0; i < N;i++){
        for(int k = 0; k < 8;k+=2){
            ll num = mp[pll(x[i],y[i])];
            
            for(int j = 0; j < 3;j++){
                int nx = x[i] + dx[k+j];
                int ny = y[i] + dy[k+j];
                num += mp[pll(nx,ny)];
            }
            res = max(res,num);
        }
    }
    
    cout << res << " / " << 1 << endl;
    return res;
}


int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0LL);
    // cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}




Measured memory_bytes: 61356
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
int N, M;

int main()
{
    cin >> N >> M;
    Graph G(N+1);
    int b[N];

    for (int i = 0; i < M; i++) {
        int from, to;
        cin >> from >> to;
        // 無向グラフ
        G[from].push_back(to);
        G[to].push_back(from);
    }
    for (int i = 0; i < N; i++) b[i] = i + 1;

    // すべての頂点の順列を探索
    int cnt = 0;
    int cv, nv;
    do {
        int i;
        if (b[0] != 1) continue;
        for (i = 0; i < N-1; i++) {
            cv = b[i];
            nv = b[i+1];
            auto exist = find(G[cv].begin(), G[cv].end(), nv);
            if (exist == G[cv].end()) break;
        }
        if (i == N-1) cnt++;
    } while (next_permutation(b, b + N));

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

char maze[52][52];
int visited[52][52];


bool is_in_field(int h, int w, pll now){
    if(now.first < 0 || now.first >= h){return false;}
    if(now.second < 0 || now.second >= w){return false;}
    return true;
}

int bfs(int h, int w, int stx, int sty){
    queue<pll> q;
    pll start = {sty,stx};
    pll d[4] = {{1,0},{-1,0},{0,1},{0,-1}};
    q.push(start);
    visited[start.first][start.second] = 0;
    while(!q.empty()){
        pll now = q.front();
        q.pop();

        for(int i = 0; i < 4; i++){
            pll next = {now.first + d[i].first, now.second + d[i].second};
            if(is_in_field(h, w, next)){
                char state = maze[next.first][next.second];
                if(state == '.'){
                    if(visited[next.first][next.second] == -1){
                        q.push(next);
                        visited[next.first][next.second] = visited[now.first][now.second] + 1;
                    }
                }
            }
        }


    }

    return -1;
}

int main(){
    int h, w, cnt = 0;
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> maze[i][j];
            if(maze[i][j] == '.'){cnt++;}
            visited[i][j] = -1;
        }
    }

    int ans = 0;
    for(int sy = 0; sy < h; sy++){
        for(int sx = 0; sx < w; sx++){
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    visited[i][j] = -1;
                }
            }

            if(maze[sy][sx] == '#'){continue;}

            int distance = 0;
            bfs(h, w, sx, sy);
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    distance = max(distance, visited[i][j]);
                }
            }
            ans = max(ans, distance);

        }
    }
    cout << ans << endl;

    return 0;
}


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

const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.14159265;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

#define cout cout << setprecision(12)

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void dbg(T a) { cout << a << ' '; }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main() {
    cin >> n >> m;
  	while(++ans) {
    	if ((int)(ans*0.08)==n&&(int)(ans*0.1)==m) {
        	cout << ans;
          return 0;
        }
    	if(ans>1200) {
        	dbg(-1);
          return 0;
        }
    }
}


Measured memory_bytes: 256
// Jai Mata Di
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
void solveTest(){
  int n, x, t;
  cin>>n>>x>>t;
  if(n%x==0){
    cout<<n/x * t<<"\n";
  }
  else{
    cout<<((n/x)+1)*t<<"\n";
  }
}
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t=1, i=1;
  //cin>>t;//Comment if only one test case
  while(i<=t){
    //cout<<"Case #"<<i<<": ";
    solveTest();
    i++;
  }
  return 0;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#define manx 150005
using namespace std;

typedef struct pp
{
    char name[100];
    int t;
}p;
p q[manx];//结构体数组

int tail ,head,n;
void push(p x)
{
    q[tail]=x;
    tail=(tail+1)%manx;
}

p pop()
{
    p x=q[head];
    head=(head+1)%manx;
    return x;
}

int mmin(int a,int b)
{
    return a<b?a:b;
}
int main()
{
    int sum=0,c;
    int i,r;
    p u;
    scanf("%d %d",&n,&r);
    for(i=0;i<n;i++)
    {
        scanf("%s",q[i].name);
        scanf("%d",&q[i].t);
    }
    head=0;tail=n;

    while(head!=tail)
    {
        u=pop();
        c=mmin(r,u.t);
        u.t-=c;
        sum+=c;
        if(u.t>0)
            push(u);
        else
            printf("%s %d\n",u.name,sum);
    }
    return 0;

}




Measured memory_bytes: 18384
#include<bits/stdc++.h>
using namespace std;
const long long Mod=1e9+7;
int n,m=2000,a[200010],b[200010];
long long f[4010][4010],fac[8010],inv[8010];
long long pw(long long x,long long y)
{
	long long res=1;
	while (y)
	{
		if (y&1)
		{
			res=res*x%Mod;
		}
		x=x*x%Mod;
		y>>=1;
	}
	return res;
}
long long c(int n,int m)
{
	if (m<0 || m>n)
	{
		return 0;
	}
	return fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		f[m-x][m-y]++;
		a[i]=x;
		b[i]=y;
	}
	fac[0]=1;
	for (int i=1;i<=8000;i++)
	{
		fac[i]=fac[i-1]*i%Mod;
	}
	inv[8000]=pw(fac[8000],Mod-2);
	for (int i=7999;i>=0;i--)
	{
		inv[i]=inv[i+1]*(i+1)%Mod;
	}
	for (int i=0;i<=4000;i++)
	{
		for (int j=0;j<=4000;j++)
		{
			if (i)
			{
				f[i][j]=(f[i][j]+f[i-1][j])%Mod;
			}
			if (j)
			{
				f[i][j]=(f[i][j]+f[i][j-1])%Mod;
			}
		}
	}
	long long ans=0;
	for (int i=0;i<n;i++)
	{
		ans=(ans+f[m+a[i]][m+b[i]])%Mod;
		ans=(ans-c(2*(a[i]+b[i]),2*a[i])+Mod)%Mod;
	}
	ans=ans*((Mod+1)/2)%Mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 127616