akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define fi first
#define se second

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( reinterpret_cast<T*>(array),
             reinterpret_cast<T*>(array+N),
             val );
}

// binary search
ll BSearch(ll ok, ll ng, bool (*f)(ll)){
  ll mid;
  while(abs(ok - ng) > 1LL) {
    mid =  (ok + ng) / 2LL;
    if(f(mid)) {
      debug("BSearch: f(%d) == true\n", mid);
      ok = mid;
    }
    else
    {
      debug("BSearch: f(%d) == false\n", mid);
      ng = mid;
    }
  }
  return ok;
}

ll NUM_TEST_CASE = 1;

ll N,M,K,A,B,C,D,E;
string S,T;
int dp[NMAX] = {};

vec v;

ll ans = INF;

void solve(){
  // main algorithm
  for (size_t i = 0; i < S.length() - T.size() + 1; i++)
  {
    ll sum = 0;
    for (size_t j = 0; j < T.size(); j++)
    {
      sum += (int)(S[i + j] != T[j]);
    }
    ans = min(ans, sum);
    
  }
  
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
void init(){
  // initialize for each test case
  // Fill(dp, -1);
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // cin >> NUM_TEST_CASE;

  for (int test_case = 0; test_case < NUM_TEST_CASE; ++test_case)
  {
    init();

    cin >> S >> T;
    solve();
    #ifdef DEBUG
    debug();
    #endif
    answer();
  }

  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<bool> dp(n); dp[0] = true;
    vector<int> cnt(n, 1);
    repeat (i,m) {
        int x, y; cin >> x >> y;
        -- x; -- y;
        -- cnt[x]; ++ cnt[y];
        if (dp[x]) dp[y] = true;
        if (cnt[x] == 0) dp[x] = false;
    }
    cout << whole(count, dp, true) << endl;
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int h,w;
    cin>>h>>w;
    vector<string> vs(h);
    rep(i,h)cin>>vs[i];
    
    rep(i,h){
        rep(k,2){
            rep(j,w){
                cout<<vs[i][j];
            }
            cout<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> D(n); rep(i, n) cin >> D[i];
  sort(all(D));
  vector<int> ans(n+1); ans[n] = 0;
  rep(i, n) {
    if(i%2==0) ans[i] = D[i];
    else       ans[i] = 24-D[i];
  }
  sort(all(ans));
  ll mn = 25;
  rep(i, n) chmin(mn, ans[i+1]-ans[i]);
  chmin(mn, 24-ans[n]);
  cout << mn << endk;
  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <cassert>

using namespace std;

bool isPrime[100011]; 
void computePrimes(int limit=100010) {
    assert(limit < 100011);                    // #include <cassert>
    fill(isPrime, isPrime + limit + 1, true);  //最初全部trueにしておく
    isPrime[0] = isPrime[1] = false;
    for (int i=2; i<=limit; i++)
        if (isPrime[i])
            for (int j = 2 * i; j <= limit; j += i)
                isPrime[j] = false;
}

int main() {
    computePrimes();
    int q;
    cin >> q;
    int rui[100010] = {0};
    for (int i=1; i<50004; i++) {
        rui[2*i - 1] = rui[2*i] = rui[2*i - 2] + (isPrime[i] && isPrime[2*i - 1]);
    }
    for (int i=0; i<q; i++) {
        int l, r;
        cin >> l >> r;
        cout << rui[r] - rui[l-1] << '\n';
    }
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<queue>
using namespace std;
int main() {

	//C
	int n;
	cin >> n;
	priority_queue<string> Q;
	string S;
	int i;
	for (i = 0; i < n; i++) {
		cin >> S;
		Q.push(S);
		//cout << S << endl;
	}
	
	int counter = 1;
	S = Q.top();
	Q.pop();
	for (i = 0; i < n-1; i++) {
		//cout << Q.top() << endl;
		if (S != Q.top()) {
			counter++;
			S = Q.top();
		}
		Q.pop();
	}
	cout << counter << endl;

	return 0;

	//B
	/*int a, b, c, d;
	cin >> a >> b >> c >> d;
	while ((a > 0) && (c > 0)) {
		c = c - b;
		if (c <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
		a = a - d;
		if (a <= 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	return 0;*/

	//A
	/*int s, w;
	cin >> s >> w;
	if (w >= s) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}
	return 0;*/
}

Measured memory_bytes: 11668
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("Yes\n")
#define no printf("No\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using ull=unsigned long long;
using vi=vector<int>;
using pint=pair<int,int>;

const int INF=1LL<<55;

int n;
string s;
int min_n = 1000000;
int ans;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    vi vec(n);
    cin>>s;

    rep(i,n){
        if(s[i] == 'W') vec[i]++;
    }
    REP(i,1,n){
        vec[i] +=vec[i-1];
    }

    //shows(vec);

    rep(i,n){
        ans = vec[i];
        if(s[i]=='W') ans--;
        ans += (n-1 - i) - (vec[n-1] - vec[i]);
        //show(ans);
        min_n = min(ans, min_n);
    }
    cout<<min_n<<endl;

    return 0;
}


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

int main(){
  int K, S;
  cin >> K >> S;
  int count = 0;
  for(int i = 0; i <= K; i++){
    for(int j = 0; j <= K; j++){
      if(0 <= S - i - j && S-i-j <= K){
        count++;
      }
    }
  }
  cout << count << endl;
}

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

int V[110][10010]; // V[i][c] 品物iまでの世界でコスト制限cでの価値最大値


int main() {
  int N, M;
  cin >> N >> M;
  int v[110];
  int w[110];
  for (auto i=0; i<N; i++) {
    cin >> v[i] >> w[i];
  }
  for (auto j=0; j<=M; j++) {
    int k = j/w[0];
    V[0][j] = k*v[0];
  }
  for (auto i=1; i<N; i++) {
    for (auto j=0; j<=M; j++) {
      V[i][j] = V[i-1][j];
      /* 次のように書くとTLEする。
      int k = 0;
      int tw;
      while ((tw = j - k*w[i]) >= 0) {
        V[i][j] = max(V[i][j], V[i-1][tw] + k*v[i]);
        k++;
      }
      これは、V[i][j-w[i]]を計算するときも、
      j方向に同じ計算をしていることになる。
      これに気づけば次のように書ける。
      */
      if (j - w[i] >= 0) {
        V[i][j] = max(V[i][j], V[i][j-w[i]] + v[i]);
      }
    }
  }
  cout << V[N-1][M] << endl;
}

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

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define MSET(m,v) memset((m),(v),sizeof(m))
#define UB(c,v) (upper_bound((c).begin(),(c).end(),(v)))
#define LB(c,v) (lower_bound((c).begin(),(c).end(),(v)))
#define INREP int TC;cin>>TC;while(TC--)
#define CPPIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

// SOLUTION

int main () {
	CPPIO;
    int a, b, x;
    cin >> a >> b >> x;
    if (x >= a && x <= a + b) cout << "YES";
    else cout << "NO";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define M 1000000007
using namespace std;
const int inf=4e18;
const double pi=3.14159265358979;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	double a,b,x,o;cin>>a>>b>>x;
	if(x>=(a*a*b)/2)
		o=atan(2*(a*a*b-x)/(a*a*a));
	else
		o=pi/2-atan((2*x)/(a*b*b));
	o=(double)180*o/pi;
	printf("%0.15lf\n",o);
}

Measured memory_bytes: 256
using System;
using System.Linq;
namespace Sample
{
	class Program
    {
    	static void Main()
        {
          	bool judge = false;
          	int a = 0;
          	var str1 = new int[6];
           	for(int i= 0;i<6;i++)
            {
            	str1[i] = Int32.Parse(Console.ReadLine());
            }
			for(int i=0;i<5;i++)
            {
            	for(int j=0;j<5;j++)
                {
                  	if(i<j)
                    {
                		a = str1[j] - str1[i] ;
                    }
                  	if(a>str1[5])
                    {
                    	judge = true;
                    }
                }
            }
          if(judge == true) Console.WriteLine(":(");
          else Console.WriteLine("Yay!");
        }
    }
}

Measured memory_bytes: 11092
def btn(n, l)
  a = [".", ",", "!", "?", " "] + [*"a".."z"]
  return case n
  when 1
    a[0 + l % 5]
  when 2
    a[5 + l % 3]
  when 3
    a[8 + l % 3]
  when 4
    a[11 + l % 3]
  when 5
    a[14 + l % 3]
  when 6
    a[17 + l % 3]
  when 7
    a[20 + l % 4]
  when 8
    a[24 + l % 3]
  when 9
    a[27 + l % 4]
  end
end

gets.to_i.times do
  arr, ans = gets.chomp.split(/0+/), ""
  
  arr.each do |str|
    ans += btn(str[0].to_i, str.length - 1) if str[0]
  end
  
  puts ans
end

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
#define MOD 1000000007
using namespace std;

int main(){
	int key, n;
	cin >> key >> n;
	if(n==0){
		cout << key << endl;
	}
	else{
		int ar[n];
		for(int i=0; i<n; i++)  cin >> ar[i];
		sort(ar,ar+n);
		int t = 0;
		bool success = false;
		while(!success){
			if((!binary_search(ar,ar+n,key-t))){
				cout << key-t << endl;
				success = true;
			}
			else if(!binary_search(ar,ar+n,key+t)){
				cout << key+t << endl;
				success = true;
 			}
 			else{
 				t++;
 			}
		}
	}
	return 0;
}

Measured memory_bytes: 3520
#include <iostream>
#include <bits/stdc++.h>
using namespace std; 
int main(){
  int a,b;
  cin>>a;
  cin>>b;
  if((a==1 && b==2) || (b==1 && a==2)){
    cout<<3;
    return 0;
  }
  if((a==1 && b==3) || (b==1 && a==3)){
    cout<<2;
    return 0;
  }
  if((b==2 && a==3) || (b==3 && a==2)){
    cout<<1;
  }
  return 0;
}

Measured memory_bytes: 256
import math
a, b, h, m = map(int,input().split())

#print(a, b, h, m)

pai = 3.141592653589
kaku = abs((360 * m / 60) - (30 * h + m * 30 /60))

cc = a*a + b*b - 2*a*b* math.cos(math.radians(kaku)) 
#math.cos(math.radians(kaku))
#c^2 = a^2 + b^2 − 2ab * cos γ

print(cc**0.5)


Measured memory_bytes: 9496
#include <bits/stdc++.h>
#define LSOne(S) ((S) & (-S))
using namespace std;

typedef long long ll;

const int MAXN = 2*1e5 + 10;

ll bit[MAXN],dp[MAXN];
ll h[MAXN],a[MAXN];
int N;

void update(int x, ll val){
	while(x <= N){
		bit[x] = max(bit[x],val);
		x += LSOne(x);
	}
}

ll query(int x){

	ll ans = 0;
	while(x > 0){
		ans = max(ans,bit[x]);
		x -= LSOne(x);
	}

	return ans;

}

int main(){

	scanf("%d",&N);

	for(int i = 1;i<=N;i++){
		scanf("%lld",&h[i]);
	}
	for(int i = 1;i<=N;i++){
		scanf("%lld",&a[i]);
	}

	for(int i = 1;i<=N;i++){
		dp[i] = query(h[i] - 1) + a[i];
		update(h[i],dp[i]);
	}

	ll best = 0;
	for(int i = 1;i<=N;i++) best = max(best,dp[i]);
	printf("%lld\n",best);

	return 0;

}

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

int main(){
    vector<int> A(3);
    for(int i=0;i<3;i++){
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    cout << abs(A.at(0)-A.at(1)) + abs(A.at(1)-A.at(2)) << '\n';
}

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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n){
        cin >> s[i];
    }
    int ans = 1;
    sort(s.begin(), s.end());
    rep(i, n-1){
        if(s[i] != s[i+1]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

	int N; cin >> N;
	vl A(N); rep(i,N) cin >> A[i];
	
	vl cnt(200005,0LL);

	rep(i,N) cnt[A[i]]++;

	ll ans = 0;
	rep(i,200005) {
		ans += (cnt[i] * (cnt[i]-1LL)) / 2;
	}

    rep(i,N) {
		cout << ans - cnt[A[i]] + 1 << endl;
	}
}

Measured memory_bytes: 5760
import scala.io.StdIn.readLine

class Dice(val d:Array[Int]) {

  def roll(dir:Char)  =
    dir match {
      case 'S' => Array(4,0,2,3,5,1)
      case 'N' => Array(1,5,2,3,0,4)
      case 'W' => Array(2,1,5,0,4,3)
      case 'E' => Array(3,1,0,5,4,2)
    }

  def getTopFace(a:Array[Int]):Array[Int] = a.map(d)
}

object Main extends App {
  val faces = readLine.split(" ").map(_.toInt)
  val dice = new Dice(faces)
  val rolls = readLine.foldLeft(Array(0,1,2,3,4,5)) { (x,y) => dice.roll(y).map(x) }

  println(dice.getTopFace(rolls)(0))
}

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

int main() {
	string t,p;
	cin>>t>>p;
	int ts=t.size(),ps=p.size();
	bool flag;
	for(int i=0;i<=ts-ps;i++)
	{
		flag=true;
		for(int j=0;j<ps;j++)
		{
			if(t[i+j]!=p[j])
			{
				flag=false;
				break;
			}
		}
		if(flag)cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 3168
from collections import defaultdict

H, W = map(int, input().split())

V = 10

dists = []

for _ in range(V):
    dists.append(list(map(int, input().split())))

count = defaultdict(int)

for _ in range(H):
    for i in map(int, input().split()):
        count[i] += 1

for k in range(V):
    for i in range(V):
        for j in range(V):
            dists[i][j] = min(dists[i][j], dists[i][k] + dists[k][j])


ans = 0

for k, v in count.items():
    if k == -1 or k == 1:
        continue
    ans += v * dists[k][1]
print(ans)



Measured memory_bytes: 9448
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 1LL << 60;
constexpr int inf = 1 << 30;

int main() {
    int N; cin >> N;
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int a; cin >> a;
        while (a > 0) {
            if (a % 2 == 0) {
                ++ans;
                a /= 2;
            }
            else break;
        }
    }
    cout << ans << endl;
}

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

int main(){
    string W, T;
    int count = 0;
    
    cin >> W;
    transform(W.begin(), W.end(), W.begin(), ::toupper); 
    
    while(1){
        cin >> T;
        if(T == "END_OF_TEXT"){
            break;
        }
        
        transform(T.begin(), T.end(), T.begin(), ::toupper); 
        if(T == W){
            count++;
        }
    }
    cout << count << endl;
   return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
vector<int>G[1<<17];
int dfs(int u)
{
	if(G[u].empty())return 0;
	vector<int>a;
	for(int i=0;i<G[u].size();i++)
	{
		a.push_back(dfs(G[u][i]));
	}
	sort(a.begin(),a.end());
	int g=a[a.size()-1];
	int c=0;
	for(int i=a.size()-1;i--;)
	{
		if(a[i+1]>a[i])c+=a[i+1]-a[i]-1;
		else
		{
			if(c)c--;
			else g++;
		}
	}
	return g+1;
}
main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int a;cin>>a;
		G[a].push_back(i+1);
	}
	cout<<dfs(1)<<endl;
}

Measured memory_bytes: 14208
/**
*   @Author : MeGaCrazy
*   @InitTime : Wed Jan 02 21:08:06 2019
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
   long long n;
   cin>>n;
   long long l=1,r=1e9;
   while((r-l)>1){
        long long mid=(l+r)>>1;
        if(mid*(mid+1)/2 >=n)r=mid;
        else l=mid+1;
   }
   while( (r-1)*(r)/2 >=n)r--;
   cout<<r<<endl;




}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
int x[100], y[100], ans = -1;
signed main() {
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> x[i] >> y[i];
	for (int i1 = 0; i1 < n; i1++) {
		for (int i2 = 0; i2 < n; i2++) {
			int xm = min(x[i1], x[i2]), xM = max(x[i1], x[i2]);
			for (int j1 = 0; j1 < n; j1++) {
				for (int j2 = 0; j2 < n; j2++) {
					int ym = min(y[j1], y[j2]), yM = max(y[j1], y[j2]);

					int cnt = 0;
					for (int i = 0; i < n; i++)if (xm <= x[i] && x[i] <= xM && ym <= y[i] && y[i] <= yM)cnt++;
					if (cnt >= k) {
						if (ans < 0)ans = (xM - xm)*(yM - ym);
						else ans = min(ans, (xM - xm)*(yM - ym));
					}
				}
			}
		}
	}
	cout << ans << endl;
}

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

typedef double f64;
typedef long long i64;
typedef int i32;
typedef pair<i32, i32> pi32;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef vector<i32> vi32;
typedef deque<i32> di32;

#define all(c) (c).begin(), (c).end()
#define REP(i, a, b) for (auto i = a; i < b; i++)
#define REPA(i, a, b, acc) for (auto i = a; i < b; i += acc)
#define PB push_back
#define PF push_front
#define PRINT(x) cout << #x ": " << (x) << endl;
#define TR(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); (it)++)
#define MAX_PRECISION cout << setprecision(numeric_limits<double>::max_digits10);

i32 main() {
  ios::sync_with_stdio(false);  // Makes IO faster, remove this line if C style scanf/printf needed.

  i32 a, b, t;
  cin >> a >> b >> t;
  cout << (t / a) * b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;

int main() {
  string s,t;cin>>s>>t;
  if(s==t.substr(0,s.size())&&s.size()+1==t.size())cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3616
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}



int main(){
	ll n,m;
  	cin >> n >> m;
  	vector<ll> a(n);
  	for(ll i=0;i<n;i++){
    	cin >> a[i];
    }
  	sort(a.begin(),a.end());
  	ll d;
  	while( (d=distance(lower_bound(a.begin(),a.end(),a.back()/2),a.end())) >=m){
      	if(m<=0) break;
    	for(int i=0;i<min(d,m);i++){
        	a[n-1-i]/=2;	
        }
      	m-=d;
      	sort(a.begin(),a.end());
    }

  	for(ll i=0;i<m;i++){
      	if(a.size()==0) break;
    	ll tmp=a.back()/2;
      	a.pop_back();
      	if(tmp>0){
      		auto itr = lower_bound(a.begin(),a.end(),tmp);
      		a.insert(itr,tmp);
        }
    }
  	ll sum=0;
  	if(a.size()!=0){
  		for(auto &e:a){
    		sum+=e;
    	}
    }
  	cout << sum << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    string s;
    int X, Y;
    cin >> s >> X >> Y;
    int pos = 0, len = s.length();
    vector<int> vx, vy;
    bool is_x = true;
    while (pos < len) {
        if (is_x) {
            if (s[pos] == 'T') {
                is_x = false;
                pos++;
            } else {
                int l = 0;
                while (pos < len && s[pos] == 'F') {
                    l++;
                    pos++;
                }
                vx.push_back(l);
            }
        } else {
            if (s[pos] == 'T') {
                is_x = true;
                pos++;
            }
            else {
                int l = 0;
                while (pos < len && s[pos] == 'F') {
                    l++;
                    pos++;
                }
                vy.push_back(l);
            }
        }
    }

    bool dpx[2*len+1], dpy[2*len+1], tmp[2*len+1];
    fill(dpx, dpx+2*len+1, false);

    dpx[len] = true;
    for (int i = 0; i < vx.size(); i++) {
        fill(tmp, tmp+2*len+1, false);
        for (int j = 0; j <= 2*len; j++) {
            if (dpx[j]) {
                tmp[j+vx[i]] = true;
                if (s[0] == 'T' || i != 0) tmp[j-vx[i]] = true;
            }
        }

        for (int j = 0; j <= 2*len; j++) {
            dpx[j] = tmp[j];
        }
    }

    fill(dpy, dpy+2*len+1, false);
    dpy[len] = true;
    for (int i = 0; i < vy.size(); i++) {
        fill(tmp, tmp+2*len+1, false);
        for (int j = 0; j <= 2*len; j++) {
            if (dpy[j]) {
                tmp[j+vy[i]] = true;
                tmp[j-vy[i]] = true;
            }
        }

        for (int j = 0; j <= 2*len; j++) {
            dpy[j] = tmp[j];
        }
    }

    if (dpx[len+X] && dpy[len+Y]) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------
ll N;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) {
    res[n]++;
  }
  return res;
}

int main() {
  cin >> N;
  map<ll, ll> mp;
  repe(i, 2, N) {
    auto fac = prime_factor(i);
    for (auto e : fac) {
      mp[e.first] += e.second;
    }
  }
  ll ans = 1;
  for (auto e : mp) {
    ans *= e.second + 1;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , A , B , X;
  cin >>  N >> A >> B ;
  X = N * A ;
  if ( X <= B ) {
    cout << X << endl ;
  }
  if( X > B) {
    cout << B << endl ;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n  = Integer.parseInt(br.readLine());
		Card[] cards = new Card[n];
		for(int i = 0 ; i < n ; i++){
			cards[i] = new Card(br.readLine(),i);
		}
		quickSort(cards,0,n - 1);

		StringBuilder sb = new StringBuilder();
		boolean flag = true;
		for(int i = 0 ; i < n ; i ++){
			if(flag){
				flag = isStable(cards,i);
			}
			sb.append(cards[i].getStr()).append("\n");
		}

		if(flag){
			sb.insert(0, "Stable" + "\n");
		}else{
			sb.insert(0, "Not stable" + "\n");
		}

		System.out.print(sb.toString());
	}

	private static void quickSort(Card[] cards,int begin,int end){

		//????????\???????????§???????????´????????????
		if(begin >= end){
			return;
		}

		int q = partition(cards,begin,end);

		//??????
		quickSort(cards,begin,q - 1);
		//??????
		quickSort(cards,q + 1,end);
	}

	private static int partition(Card[] cards,int begin,int end){

		//???????????????
		int standardNum  = cards[end].getNum();
		Card tmpCard;
		//?????????????°????????????§???index
		int x = begin;
		for(int i = begin ; i <  end ; i++){
			//?????????????°?????????´????????\?????????
			if(cards[i].getNum() <= standardNum){
				tmpCard = cards[i];
				cards[i] = cards[x];
				cards[x] = tmpCard;
				x++;
			}
		}

		//????????¨??????????????????????????¨????????????????????????????§??????????
		tmpCard = cards[end];
		cards[end] = cards[x];
		cards[x] = tmpCard;
		return x;
	}

	private  static boolean isStable(Card[] cards,int i){
		if(i == 0){
			return true;
		}else if(cards[i].getNum() == cards[i - 1].getNum()
				  &&
				  cards[i].getFirstIndex() < cards[i - 1].getFirstIndex()
				  )
		{
			return false;
		}else{
			return true;
		}
	}
}

class Card{
	private String str;
	private int num;
	private int firstIndex;

	Card(String str,int firstIndex){
		this.str = str;
		this.num = Integer.parseInt(str.substring(2));
		this.firstIndex = firstIndex;
	}

	public String getStr() {
		return str;
	}
	public int getNum() {
		return num;
	}
	public int getFirstIndex() {
		return firstIndex;
	}

}

Measured memory_bytes: 49304
#include <stdio.h>
#include <math.h>
int main(){
	int a,b,ans;
	char x;
	for(;;){
	scanf("%d %c %d",&a,&x,&b);
	if(x=='+'){
		ans=a+b;
		printf("%d\n",ans);
	}
	else if(x=='-'){
		ans=a-b;
		printf("%d\n",ans);
	}
	else if(x=='*'){
		ans=a*b;
		printf("%d\n",ans);
	}
	else if(x=='/'){
		ans=a/b;
		printf("%d\n",ans);
	}
	else if(x=='?'){
		break;
	}
}
	return 0 ;
}

Measured memory_bytes: 2672
// AOJ CGL_7_D Cross Points of a Circle and a Line
// 2018.5.3 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef struct { double x, y; } PP;
typedef struct { PP s, e; } SEG, LINE;
typedef struct { double x, y, r; } C;

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define INF 1e8
#define EPS 1e-8
#define EQ(a,b)		(fabs((a)-(b))<EPS)

int dcmp(double x) { if (fabs(x) < EPS) return 0; return x <= 0 ? -1 : 1; }
PP vset(double x, double y) { PP r; r.x = x, r.y = y; return r; }
PP vadd(PP p1, PP p2) { PP r; r.x = p1.x + p2.x, r.y = p1.y + p2.y; return r; }
PP vsub(PP p1, PP p2) { PP r; r.x = p1.x - p2.x, r.y = p1.y - p2.y; return r; }
PP vsmul(PP p, double k) { PP r; r.x = p.x * k, r.y = p.y * k; return r; }
double vabs(PP a) { return hypot(a.x, a.y); }
double dist(PP p1, PP p2) {	return vabs(vsub(p1, p2)); }
double cross(PP a, PP b) { return a.x * b.y - a.y * b.x; }
double dot(PP a, PP b) { return a.x * b.x + a.y * b.y; }
double norm(PP a) { return a.x * a.x + a.y * a.y; }

double distancePL(PP p, LINE ln)
{
	PP a = vsub(ln.e, ln.s);
	return fabs(cross(vsub(p, ln.s), a)) / vabs(a);
}

PP projection(PP p1, PP p2, PP p)
{
	PP p2p1 = vsub(p2, p1);
	PP pp1 = vsub(p, p1);
	return vadd(p1, vsmul(p2p1, dot(pp1, p2p1)/norm(p2p1)));
}

int cmp(PP *a, PP *b)
{
	if (EQ(a->x, b->x)) return dcmp(a->y - b->y);
	return dcmp(a->x - b->x);
}

int main()
{
	int q, i;
	C c;
	PP p[2], p0, c0;
	LINE line;
	double a, b;

	c.x = in(), c.y = in(), c.r = in();
	q = in();
	while (q--) {
		line.s.x = in(), line.s.y = in(), line.e.x = in(), line.e.y = in();
		c0 = vset(c.x, c.y);
		a = distancePL(c0, line), b = sqrt(c.r*c.r - a*a);
		p0 = projection(line.s, line.e, c0);
		p[0] = vadd(p0, vsmul(vsub(line.s, line.e), b/dist(line.s, line.e)));
		p[1] = vadd(p0, vsmul(vsub(line.e, line.s), b/dist(line.s, line.e)));
		qsort(p, 2, sizeof(PP), cmp);
		for (i = 0; i < 2; i++) {
			printf("%.10lf %.10lf", p[i].x, p[i].y);
			putchar(' ');
		}
		putchar('\n');
	}
	return 0;
}


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

int main()
{
  int N;
  cin >> N;
  int i;
  long int ans=1;
  for (i=1;i<=N;i++) {
    ans = ans * i;
    ans = ans % 1000000007;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int ans = 0;

		for(int i = a; i <= b; i++){
			if(c%i == 0){
			    ans++;
			}
		}

		System.out.println(ans);
	}
}





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

int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
  	cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  cout << A.at(N - 1) - A.at(0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

int a[100100];
int main() {
	int n;
	scanf("%d", &n);
	FOR(i,n) scanf("%d", &a[i]);
	ll lo = 2, hi = 2;
	for (int i=n-1; i>=0; i--) {
		lo = (lo+a[i]-1) / a[i] * a[i];
		hi = hi / a[i] * a[i];
		if (lo > hi) break;
		hi = hi + a[i] - 1;
	}
	if (lo > hi) {
		printf("-1\n");
	} else {
		printf("%lld %lld\n", lo, hi);
	}
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n;cin>>n;
    map<pll,ll>c,f;
    set<pll>e;
    int cnt=0;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        if(a!=0&&b!=0){
        ll GCD=gcd(abs(a),abs(b));
        a/=GCD;b/=GCD;}
        if(a*b>0){
            c[MP(abs(a),abs(b))]++;
            f[MP(abs(a),abs(b))]=1;
            f[MP(-abs(b),abs(a))]=1;
            e.insert(MP(abs(a),abs(b)));
        }
        else if(a*b<0){
            c[MP(-abs(a),abs(b))]++;
            f[MP(-abs(a),abs(b))]=1;
            f[MP(abs(b),abs(a))]=1;
            e.insert(MP(-abs(a),abs(b)));
        }
        else if(a==0&&b!=0){
            c[MP(0,1)]++;
            f[MP(0,1)]=1;
            f[MP(1,0)]=1;
            e.insert(MP(0,1));
        }
        else if(a!=0&&b==0){
            c[MP(1,0)]++;
            f[MP(1,0)]=1;
            f[MP(0,1)]=1;
            e.insert(MP(1,0));
        }
        else cnt++;
    }
    vl d(n+1);
    d[0]=1;
    rep(i,n){
        d[i+1]=d[i]*2;
        d[i+1]%=MOD;
    }
    ll ans=1;
    for(auto x : e){
        if(f[x]==1&&f[MP(-x.S,x.F)]==1&&x.F>0&&x.S>0){
          ans*=(d[c[x]]+d[c[MP(-x.S,x.F)]]-1);
          f[x]=0;f[MP(-x.S,x.F)]=0;}
        else if(f[x]==1&&f[MP(x.S,-x.F)]==1&&x.F<0&&x.S>0){
          ans*=(d[c[x]]+d[c[MP(x.S,-x.F)]]-1);
          f[x]=0;f[MP(x.S,-x.F)]=0;}
        else if((x.F==0||x.S==0)&&f[x]==1&&f[MP(x.S,x.F)]==1){
            ans*=(d[c[x]]+d[c[MP(x.S,x.F)]]-1);
            f[x]=0;
            f[MP(x.S,x.F)]=0;
        }
        ans%=MOD;
        while(ans<0)ans+=MOD;
    }
    ans+=cnt;
    ans--;
    while(ans<0)ans+=MOD;
    cout<<ans<<endl;
}


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

sample = {"AC":0,"WA":0,"TLE":0,"RE":0}

for i in range(N):
    Si = input()
    for j in sample:
        if Si == j:
            sample[j] += 1

print("AC x "+str(sample["AC"]))
print("WA x "+str(sample["WA"]))
print("TLE x "+str(sample["TLE"]))
print("RE x "+str(sample["RE"]))

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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define ll long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define inf 1e18
#define vll vector<ll>
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define flr(i,a,b) for(ll i=a;i>b;i--)
#define print(v) for(auto i=v.begin();i!=v.end();i++){cout<<*i<<" ";}cout<<"\n";
#define MOD 1000000007
const ll N = 2e5;

int main()
{
    speed;
    string s; cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
    return 0;
}


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

//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4"

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)2e5+100;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

int d, n,dp[10010][111][2];
string s;
int calc(int pos, int sum, int sp){
  if(pos==n)
    return bool(!sum);
  int &res=dp[pos][sum][sp];
  if(res!=-1)
    return res;
  res=0;
  if(sp){
    forn(i,0,s[pos]-'0')
      res=(res+calc(pos+1,(sum+i)%d,(i==s[pos]-'0')))%mod;
  }else{
    forn(i,0,9)
      res=(res+calc(pos+1,(sum+i)%d,0))%mod;
  }
  return res;
}
main () {
  cin>>s>>d;
  n=sz(s);
  memset(dp,-1,sizeof(dp));
  cout<<(calc(0,0,1)-1+mod)%mod;
}

Measured memory_bytes: 18560
#include<stdio.h>
int main(void)
{
	int a,b,x,s,min=0,i;
	scanf("%d%d",&a,&b);
	for(i=1;i<=b;i++){
		scanf("%d%d",&x,&s);
		min=x;
		if(min>s){
			min=s;
		}
		if(min>a-x){
			min=a-x+1;
		}
		if(min>a-s){
			min=a-s+1;
		}
		if(min%3==0) printf("3\n");
		else{
			printf("%d\n",min%3);
		}
	}
	return 0;
}

Measured memory_bytes: 2656
import math
A, B, C, D = map(int, input().split())
lcm = (C * D) // math.gcd(C, D)
waruC = B//C-(A-1)//C
waruD = B//D-(A-1)//D
waruCD = B//lcm-(A-1)//lcm
ans = B-A+1-(waruC+waruD-waruCD)
print(ans)


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
template <typename T> inline void read(T &x)
{
	int f = 1; x = 0; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
	x *= f;
}
const int N = 3e5 + 5;
int n, m, p, x[N], y[N];
pair <int, int> rsum[N], csum[N];
map < pair <int, int>, bool > H;
int main(){
	read(n); read(m); read(p);
	
	for (int i = 1; i <= n; i++) rsum[i].second = i;
	for (int i = 1; i <= m; i++) csum[i].second = i;
	
	for (int i = 1; i <= p; i++)
	{
		read(x[i]); read(y[i]);
		rsum[x[i]].first++;
		csum[y[i]].first++;
	}
	sort(rsum + 1, rsum + n + 1);
	sort(csum + 1, csum + m + 1);
	
	int Rpos = n, Cpos = m;
	int sum = rsum[n].first + csum[m].first;
	while (Rpos > 1 && rsum[Rpos - 1].first == rsum[n].first) Rpos--;
	while (Cpos > 1 && csum[Cpos - 1].first == csum[m].first) Cpos--;

	
	if ((LL) (n - Rpos + 1) * (m - Cpos + 1) <= p)
	{
		bool flag = 1;
		for (int i = 1; i <= p; i++) H[make_pair(x[i], y[i])] = 1;
		for (int i = Rpos; i <= n; i++)
		for (int j = Cpos; j <= m; j++)
		if (!H[make_pair(rsum[i].second, csum[j].second)])
		{
			flag = 0;
			break;
		}
		sum -= flag;
	}
	
	printf ("%d\n", sum);
  return 0;
}

Measured memory_bytes: 29540
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[10][110], h, w, k;
const ll mod = 1000000007;

ll fib(ll x){
    if (x == 1 || x == 0) return 1;
    else if (x == 2) return 2;
    else if (x == 3) return 3;
    else if (x == 4) return 5;
    else if (x == 5) return 8;
    else if (x == 6) return 13;
    else if (x == 7) return 21;
    else return 0;
}

int main(void){
    // Your code here!
    dp[1][0] = 1;
    cin >> h >> w >> k;
    for (ll i = 0; i < h; i++){
        for (ll j = 1; j <= w; j++){
            (dp[j][i + 1] += (dp[j][i] * fib(j - 1) * fib(w - j)) % mod) %= mod;
            if (j < w) (dp[j + 1][i + 1] += (dp[j][i] * fib(j - 1) * fib(w - j - 1)) % mod) %= mod;
            if (j > 1) (dp[j - 1][i + 1] += (dp[j][i] * fib(j - 2) * fib(w - j)) % mod) %= mod;
        }
    }
    cout << dp[k][h] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}

int dsum(int N){
  if(N == 0)
    return 0;
  else
    return N%10 + dsum(N/10);
}

int main()
{
  ll N,A[10000],res=9999999999;
  cin >> N;
  for(int i=0;i<N;i++)
    cin >> A[i];
  for(int i=0;i<N;i++){
    ll tmp=0;
    while(1){
      if(A[i] % 2 == 0){
        tmp++;
        A[i] = A[i]/2;
      }
      else
        break;
    }
    res = min(res,tmp);
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 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 = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
// #define INF 9223372036854775807
# define INF 1e9
using namespace std;

int main(){

  int N, M;
  cin >> N >> M;
  int like[M];
  fill(like, like+M, 0);

  for(int i=0; i< N; i++){
    int k;
    cin >> k;
    for(int j=0; j<k; j++){
      int a;
      cin >> a;
      like[a-1]++;
    }
  }

  int ans = 0;
  for(int i=0; i<M; i++){
    if(like[i] == N){
      ans++;
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


int main() {
	
	int n, r;
	cin >> n >> r;
	if (n >= 10) {
		cout << r << endl;
	}
	else {
		cout << r + (100 * (10 - n)) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF

#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}


int main(){
	ll a , b;
	cin >> a >> b;

	if( b - a < 10e3 ){
		ll tmp = a;
		for( ll i = a + 1 ; i <= b ; i++ ){
			tmp = tmp xor i;
		}
		cout << tmp << endl;

		ret 0;
	}

	ll tmp = a;
	//cout << "tmp:" << tmp << endl;
	for( ll i = a+1 ; 1 ; i++ ){
		//cout << "loop1 " << i << endl;
		tmp = tmp xor i;
		if( (i + 1) % 4 == 0 ) break;
	}

	//cout << "tmp:" << tmp << endl;

	ll start = b;
	while( (start + 1) % 4 != 0 ) start--;

	//cout << "start " << start << endl;

	//if( start == b ) cout << b << endl;


	for( ll i = start+1 ; i <= b ; i++ ){
		tmp = tmp xor i;
		//cout << "loop2 " << i << endl;
	}
	cout << tmp << endl;

	ret 0;
}

Measured memory_bytes: 256